{ "version": 3, "sources": ["../../sim/dex-items.ts"], "sourcesContent": ["import type { PokemonEventMethods, ConditionData } from './dex-conditions';\nimport { assignMissingFields, BasicEffect, toID } from './dex-data';\nimport { Utils } from '../lib/utils';\n\ninterface FlingData {\n\tbasePower: number;\n\tstatus?: string;\n\tvolatileStatus?: string;\n\teffect?: CommonHandlers['ResultMove'];\n}\n\nexport interface ItemData extends Partial, PokemonEventMethods {\n\tname: string;\n}\n\nexport type ModdedItemData = ItemData | Partial> & {\n\tinherit: true,\n\tonCustap?: (this: Battle, pokemon: Pokemon) => void,\n};\n\nexport interface ItemDataTable { [itemid: IDEntry]: ItemData }\nexport interface ModdedItemDataTable { [itemid: IDEntry]: ModdedItemData }\n\nexport class Item extends BasicEffect implements Readonly {\n\tdeclare readonly effectType: 'Item';\n\n\t/** just controls location on the item spritesheet */\n\tdeclare readonly num: number;\n\n\t/**\n\t * A Move-like object depicting what happens when Fling is used on\n\t * this item.\n\t */\n\treadonly fling?: FlingData;\n\t/**\n\t * If this is a Drive: The type it turns Techno Blast into.\n\t * undefined, if not a Drive.\n\t */\n\treadonly onDrive?: string;\n\t/**\n\t * If this is a Memory: The type it turns Multi-Attack into.\n\t * undefined, if not a Memory.\n\t */\n\treadonly onMemory?: string;\n\t/**\n\t * If this is a mega stone: The name (e.g. Charizard-Mega-X) of the\n\t * forme this allows transformation into.\n\t * undefined, if not a mega stone.\n\t */\n\treadonly megaStone?: string;\n\t/**\n\t * If this is a mega stone: The name (e.g. Charizard) of the\n\t * forme this allows transformation from.\n\t * undefined, if not a mega stone.\n\t */\n\treadonly megaEvolves?: string;\n\t/**\n\t * If this is a Z crystal: true if the Z Crystal is generic\n\t * (e.g. Firium Z). If species-specific, the name\n\t * (e.g. Inferno Overdrive) of the Z Move this crystal allows\n\t * the use of.\n\t * undefined, if not a Z crystal.\n\t */\n\treadonly zMove?: true | string;\n\t/**\n\t * If this is a generic Z crystal: The type (e.g. Fire) of the\n\t * Z Move this crystal allows the use of (e.g. Fire)\n\t * undefined, if not a generic Z crystal\n\t */\n\treadonly zMoveType?: string;\n\t/**\n\t * If this is a species-specific Z crystal: The name\n\t * (e.g. Play Rough) of the move this crystal requires its\n\t * holder to know to use its Z move.\n\t * undefined, if not a species-specific Z crystal\n\t */\n\treadonly zMoveFrom?: string;\n\t/**\n\t * If this is a species-specific Z crystal: An array of the\n\t * species of Pokemon that can use this crystal's Z move.\n\t * Note that these are the full names, e.g. 'Mimikyu-Busted'\n\t * undefined, if not a species-specific Z crystal\n\t */\n\treadonly itemUser?: string[];\n\t/** Is this item a Berry? */\n\treadonly isBerry: boolean;\n\t/** Whether or not this item ignores the Klutz ability. */\n\treadonly ignoreKlutz: boolean;\n\t/** The type the holder will change into if it is an Arceus. */\n\treadonly onPlate?: string;\n\t/** Is this item a Gem? */\n\treadonly isGem: boolean;\n\t/** Is this item a Pokeball? */\n\treadonly isPokeball: boolean;\n\t/** Is this item a Red or Blue Orb? */\n\treadonly isPrimalOrb: boolean;\n\n\tdeclare readonly condition?: ConditionData;\n\tdeclare readonly forcedForme?: string;\n\tdeclare readonly isChoice?: boolean;\n\tdeclare readonly naturalGift?: { basePower: number, type: string };\n\tdeclare readonly spritenum?: number;\n\tdeclare readonly boosts?: SparseBoostsTable | false;\n\n\tdeclare readonly onEat?: ((this: Battle, pokemon: Pokemon) => void) | false;\n\tdeclare readonly onUse?: ((this: Battle, pokemon: Pokemon) => void) | false;\n\tdeclare readonly onStart?: (this: Battle, target: Pokemon) => void;\n\tdeclare readonly onEnd?: (this: Battle, target: Pokemon) => void;\n\n\tconstructor(data: AnyObject) {\n\t\tsuper(data);\n\n\t\tthis.fullname = `item: ${this.name}`;\n\t\tthis.effectType = 'Item';\n\t\tthis.fling = data.fling || undefined;\n\t\tthis.onDrive = data.onDrive || undefined;\n\t\tthis.onMemory = data.onMemory || undefined;\n\t\tthis.megaStone = data.megaStone || undefined;\n\t\tthis.megaEvolves = data.megaEvolves || undefined;\n\t\tthis.zMove = data.zMove || undefined;\n\t\tthis.zMoveType = data.zMoveType || undefined;\n\t\tthis.zMoveFrom = data.zMoveFrom || undefined;\n\t\tthis.itemUser = data.itemUser || undefined;\n\t\tthis.isBerry = !!data.isBerry;\n\t\tthis.ignoreKlutz = !!data.ignoreKlutz;\n\t\tthis.onPlate = data.onPlate || undefined;\n\t\tthis.isGem = !!data.isGem;\n\t\tthis.isPokeball = !!data.isPokeball;\n\t\tthis.isPrimalOrb = !!data.isPrimalOrb;\n\n\t\tif (!this.gen) {\n\t\t\tif (this.num >= 1124) {\n\t\t\t\tthis.gen = 9;\n\t\t\t} else if (this.num >= 927) {\n\t\t\t\tthis.gen = 8;\n\t\t\t} else if (this.num >= 689) {\n\t\t\t\tthis.gen = 7;\n\t\t\t} else if (this.num >= 577) {\n\t\t\t\tthis.gen = 6;\n\t\t\t} else if (this.num >= 537) {\n\t\t\t\tthis.gen = 5;\n\t\t\t} else if (this.num >= 377) {\n\t\t\t\tthis.gen = 4;\n\t\t\t} else {\n\t\t\t\tthis.gen = 3;\n\t\t\t}\n\t\t\t// Due to difference in gen 2 item numbering, gen 2 items must be\n\t\t\t// specified manually\n\t\t}\n\n\t\tif (this.isBerry) this.fling = { basePower: 10 };\n\t\tif (this.id.endsWith('plate')) this.fling = { basePower: 90 };\n\t\tif (this.onDrive) this.fling = { basePower: 70 };\n\t\tif (this.megaStone) this.fling = { basePower: 80 };\n\t\tif (this.onMemory) this.fling = { basePower: 50 };\n\n\t\tassignMissingFields(this, data);\n\t}\n}\n\nconst EMPTY_ITEM = Utils.deepFreeze(new Item({ name: '', exists: false }));\n\nexport class DexItems {\n\treadonly dex: ModdedDex;\n\treadonly itemCache = new Map();\n\tallCache: readonly Item[] | null = null;\n\n\tconstructor(dex: ModdedDex) {\n\t\tthis.dex = dex;\n\t}\n\n\tget(name?: string | Item): Item {\n\t\tif (name && typeof name !== 'string') return name;\n\t\tconst id = name ? toID(name.trim()) : '' as ID;\n\t\treturn this.getByID(id);\n\t}\n\n\tgetByID(id: ID): Item {\n\t\tif (id === '') return EMPTY_ITEM;\n\t\tlet item = this.itemCache.get(id);\n\t\tif (item) return item;\n\t\tif (this.dex.data.Aliases.hasOwnProperty(id)) {\n\t\t\titem = this.get(this.dex.data.Aliases[id]);\n\t\t\tif (item.exists) {\n\t\t\t\tthis.itemCache.set(id, item);\n\t\t\t}\n\t\t\treturn item;\n\t\t}\n\t\tif (id && !this.dex.data.Items[id] && this.dex.data.Items[id + 'berry']) {\n\t\t\titem = this.getByID(id + 'berry' as ID);\n\t\t\tthis.itemCache.set(id, item);\n\t\t\treturn item;\n\t\t}\n\t\tif (id && this.dex.data.Items.hasOwnProperty(id)) {\n\t\t\tconst itemData = this.dex.data.Items[id] as any;\n\t\t\tconst itemTextData = this.dex.getDescs('Items', id, itemData);\n\t\t\titem = new Item({\n\t\t\t\tname: id,\n\t\t\t\t...itemData,\n\t\t\t\t...itemTextData,\n\t\t\t});\n\t\t\tif (item.gen > this.dex.gen) {\n\t\t\t\t(item as any).isNonstandard = 'Future';\n\t\t\t}\n\t\t\tif (this.dex.parentMod) {\n\t\t\t\t// If this item is exactly identical to parentMod's item, reuse parentMod's copy\n\t\t\t\tconst parent = this.dex.mod(this.dex.parentMod);\n\t\t\t\tif (itemData === parent.data.Items[id]) {\n\t\t\t\t\tconst parentItem = parent.items.getByID(id);\n\t\t\t\t\tif (\n\t\t\t\t\t\titem.isNonstandard === parentItem.isNonstandard &&\n\t\t\t\t\t\titem.desc === parentItem.desc &&\n\t\t\t\t\t\titem.shortDesc === parentItem.shortDesc\n\t\t\t\t\t) {\n\t\t\t\t\t\titem = parentItem;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\titem = new Item({ name: id, exists: false });\n\t\t}\n\n\t\tif (item.exists) this.itemCache.set(id, this.dex.deepFreeze(item));\n\t\treturn item;\n\t}\n\n\tall(): readonly Item[] {\n\t\tif (this.allCache) return this.allCache;\n\t\tconst items = [];\n\t\tfor (const id in this.dex.data.Items) {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