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