Jofthomas's picture
Jofthomas HF staff
Upload 4781 files
5c2ed06 verified
{
"version": 3,
"sources": ["../../../../data/mods/gen9ssb/scripts.ts"],
"sourcesContent": ["import type { SSBSet } from \"./random-teams\";\nimport type { ChosenAction } from '../../../sim/side';\nimport { FS } from '../../../lib';\nimport { toID } from '../../../sim/dex-data';\nimport { type SwitchAction } from \"../../../sim/battle-queue\";\n\n// Similar to User.usergroups. Cannot import here due to users.ts requiring Chat\n// This also acts as a cache, meaning ranks will only update when a hotpatch/restart occurs\nconst usergroups: { [userid: string]: string } = {};\nconst usergroupData = FS('config/usergroups.csv').readIfExistsSync().split('\\n');\nfor (const row of usergroupData) {\n\tif (!toID(row)) continue;\n\n\tconst cells = row.split(',');\n\tif (cells.length > 3) throw new Error(`Invalid entry when parsing usergroups.csv`);\n\tusergroups[toID(cells[0])] = cells[1].trim() || ' ';\n}\n\nconst roomauth: { [roomid: string]: { [userid: string]: string } } = {};\n/**\n * Given a username and room, returns the auth they have in that room. Used for some conditional messages/effects.\n * Each room is cached on the first call until the process is restarted.\n */\nexport function getRoomauth(name: string, room: string) {\n\tconst userid = toID(name);\n\tconst roomid = toID(room);\n\tif (roomauth[roomid]) return roomauth[roomid][userid] || null;\n\tconst roomsList: any[] = JSON.parse(FS('config/chatrooms.json').readIfExistsSync() || '[]');\n\tconst roomData = roomsList.find(r => toID(r.title) === roomid);\n\tif (!roomData) return null;\n\troomauth[roomid] = roomData.auth;\n\treturn roomauth[roomid][userid] || null;\n}\n\nexport function getName(name: string): string {\n\tconst userid = toID(name);\n\tif (!userid) throw new Error('No/Invalid name passed to getSymbol');\n\n\tlet group = usergroups[userid] || ' ';\n\tif (name === 'Artemis') group = '@';\n\tif (name === 'Jeopard-E' || name === 'Ice Kyubs') group = '*';\n\treturn `${Math.floor(Date.now() / 1000)}|${group}${name}`;\n}\n\nexport function enemyStaff(pokemon: Pokemon): string {\n\tconst foePokemon = pokemon.side.foe.active[0];\n\tif (foePokemon.illusion) return foePokemon.illusion.name;\n\treturn foePokemon.name;\n}\n\n/** TODO: What happened to make this work weird?\n * Assigns a new set to a Pok\u00E9mon\n * @param pokemon the Pokemon to assign the set to\n * @param newSet the SSBSet to assign\n */\nexport function changeSet(context: Battle, pokemon: Pokemon, newSet: SSBSet, changeAbility = false) {\n\tif (pokemon.transformed) return;\n\tconst evs: StatsTable = {\n\t\thp: newSet.evs?.hp || 0,\n\t\tatk: newSet.evs?.atk || 0,\n\t\tdef: newSet.evs?.def || 0,\n\t\tspa: newSet.evs?.spa || 0,\n\t\tspd: newSet.evs?.spd || 0,\n\t\tspe: newSet.evs?.spe || 0,\n\t};\n\tconst ivs: StatsTable = {\n\t\thp: newSet.ivs?.hp || 31,\n\t\tatk: newSet.ivs?.atk || 31,\n\t\tdef: newSet.ivs?.def || 31,\n\t\tspa: newSet.ivs?.spa || 31,\n\t\tspd: newSet.ivs?.spd || 31,\n\t\tspe: newSet.ivs?.spe || 31,\n\t};\n\tpokemon.set.evs = evs;\n\tpokemon.set.ivs = ivs;\n\tif (newSet.nature) pokemon.set.nature = Array.isArray(newSet.nature) ? context.sample(newSet.nature) : newSet.nature;\n\tconst oldGender = pokemon.set.gender;\n\tif ((pokemon.set.gender !== newSet.gender) && !Array.isArray(newSet.gender)) {\n\t\tpokemon.set.gender = newSet.gender;\n\t\t// @ts-expect-error Shut up sharp_claw wanted this\n\t\tpokemon.gender = newSet.gender;\n\t}\n\tconst oldShiny = pokemon.set.shiny;\n\tpokemon.set.shiny = (typeof newSet.shiny === 'number') ? context.randomChance(1, newSet.shiny) : !!newSet.shiny;\n\tlet percent = (pokemon.hp / pokemon.baseMaxhp);\n\tif (newSet.species === 'Shedinja') percent = 1;\n\tpokemon.formeChange(newSet.species, context.effect, true);\n\tif (!pokemon.terastallized && newSet.teraType) {\n\t\tconst allTypes = context.dex.types.names();\n\t\tpokemon.teraType = newSet.teraType === 'Any' ? context.sample(allTypes) :\n\t\t\tArray.isArray(newSet.teraType) ? context.sample(newSet.teraType) : newSet.teraType;\n\t}\n\tconst details = pokemon.getUpdatedDetails();\n\tif (oldShiny !== pokemon.set.shiny || oldGender !== pokemon.gender) context.add('replace', pokemon, details);\n\tif (changeAbility) pokemon.setAbility(newSet.ability as string, undefined, true);\n\n\tpokemon.baseMaxhp = pokemon.species.name === 'Shedinja' ? 1 : Math.floor(Math.floor(\n\t\t2 * pokemon.species.baseStats.hp + pokemon.set.ivs.hp + Math.floor(pokemon.set.evs.hp / 4) + 100\n\t) * pokemon.level / 100 + 10);\n\tconst newMaxHP = pokemon.baseMaxhp;\n\tpokemon.hp = Math.round(newMaxHP * percent);\n\tpokemon.maxhp = newMaxHP;\n\tcontext.add('-heal', pokemon, pokemon.getHealth, '[silent]');\n\tif (pokemon.item) {\n\t\tlet item = newSet.item;\n\t\tif (typeof item !== 'string') item = item[context.random(item.length)];\n\t\tif (context.toID(item) !== (pokemon.item || pokemon.lastItem)) pokemon.setItem(item);\n\t}\n\tif (!pokemon.m.datacorrupt) {\n\t\tconst newMoves = changeMoves(context, pokemon, newSet.moves.concat(newSet.signatureMove));\n\t\tpokemon.moveSlots = newMoves;\n\t\t// Necessary so pokemon doesn't get 8 moves\n\t\t(pokemon as any).baseMoveSlots = newMoves;\n\t}\n\tpokemon.canMegaEvo = context.actions.canMegaEvo(pokemon);\n\tpokemon.canUltraBurst = context.actions.canUltraBurst(pokemon);\n\tpokemon.canTerastallize = (pokemon.canTerastallize === null) ? null : context.actions.canTerastallize(pokemon);\n\tcontext.add('message', `${pokemon.name} changed form!`);\n}\n\nexport const PSEUDO_WEATHERS = [\n\t// Normal pseudo weathers\n\t'fairylock', 'gravity', 'iondeluge', 'magicroom', 'mudsport', 'trickroom', 'watersport', 'wonderroom',\n\t// SSB pseudo weathers\n\t'anfieldatmosphere',\n];\n\n/**\n * Assigns new moves to a Pokemon\n * @param pokemon The Pokemon whose moveset is to be modified\n * @param newSet The set whose moves should be assigned\n */\nexport function changeMoves(context: Battle, pokemon: Pokemon, newMoves: (string | string[])[]) {\n\tconst carryOver = pokemon.moveSlots.slice().map(m => m.pp / m.maxpp);\n\t// In case there are ever less than 4 moves\n\twhile (carryOver.length < 4) {\n\t\tcarryOver.push(1);\n\t}\n\tconst result = [];\n\tlet slot = 0;\n\tfor (const newMove of newMoves) {\n\t\tconst moveName = Array.isArray(newMove) ? newMove[context.random(newMove.length)] : newMove;\n\t\tconst move = context.dex.moves.get(context.toID(moveName));\n\t\tif (!move.id) continue;\n\t\tconst moveSlot = {\n\t\t\tmove: move.name,\n\t\t\tid: move.id,\n\t\t\tpp: Math.floor((move.noPPBoosts ? move.pp : move.pp * 8 / 5) * carryOver[slot]),\n\t\t\tmaxpp: (move.noPPBoosts ? move.pp : move.pp * 8 / 5),\n\t\t\ttarget: move.target,\n\t\t\tdisabled: false,\n\t\t\tdisabledSource: '',\n\t\t\tused: false,\n\t\t};\n\t\tresult.push(moveSlot);\n\t\tslot++;\n\t}\n\treturn result;\n}\n\nexport const Scripts: ModdedBattleScriptsData = {\n\tgen: 9,\n\tinherit: 'gen9',\n\tboost(boost, target, source, effect, isSecondary, isSelf) {\n\t\tif (this.event) {\n\t\t\tif (!target) target = this.event.target;\n\t\t\tif (!source) source = this.event.source;\n\t\t\tif (!effect) effect = this.effect;\n\t\t}\n\t\tif (!target?.hp) return 0;\n\t\tif (!target.isActive) return false;\n\t\tif (this.gen > 5 && !target.side.foePokemonLeft()) return false;\n\t\tboost = this.runEvent('ChangeBoost', target, source, effect, { ...boost });\n\t\tboost = target.getCappedBoost(boost);\n\t\tboost = this.runEvent('TryBoost', target, source, effect, { ...boost });\n\t\tlet success = null;\n\t\tlet boosted = isSecondary;\n\t\tlet boostName: BoostID;\n\t\tif (target.set.name === 'phoopes') {\n\t\t\tif (boost.spa) {\n\t\t\t\tboost.spd = boost.spa;\n\t\t\t}\n\t\t\tif (boost.spd) {\n\t\t\t\tboost.spa = boost.spd;\n\t\t\t}\n\t\t}\n\t\tfor (boostName in boost) {\n\t\t\tconst currentBoost: SparseBoostsTable = {\n\t\t\t\t[boostName]: boost[boostName],\n\t\t\t};\n\t\t\tlet boostBy = target.boostBy(currentBoost);\n\t\t\tlet msg = '-boost';\n\t\t\tif (boost[boostName]! < 0 || target.boosts[boostName] === -6) {\n\t\t\t\tmsg = '-unboost';\n\t\t\t\tboostBy = -boostBy;\n\t\t\t}\n\t\t\tif (boostBy) {\n\t\t\t\tsuccess = true;\n\t\t\t\tswitch (effect?.id) {\n\t\t\t\tcase 'bellydrum': case 'angerpoint':\n\t\t\t\t\tthis.add('-setboost', target, 'atk', target.boosts['atk'], '[from] ' + effect.fullname);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'bellydrum2':\n\t\t\t\t\tthis.add(msg, target, boostName, boostBy, '[silent]');\n\t\t\t\t\tthis.hint(\"In Gen 2, Belly Drum boosts by 2 when it fails.\");\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'zpower':\n\t\t\t\t\tthis.add(msg, target, boostName, boostBy, '[zeffect]');\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tif (!effect) break;\n\t\t\t\t\tif (effect.effectType === 'Move') {\n\t\t\t\t\t\tthis.add(msg, target, boostName, boostBy);\n\t\t\t\t\t} else if (effect.effectType === 'Item') {\n\t\t\t\t\t\tthis.add(msg, target, boostName, boostBy, '[from] item: ' + effect.name);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (effect.effectType === 'Ability' && !boosted) {\n\t\t\t\t\t\t\tthis.add('-ability', target, effect.name, 'boost');\n\t\t\t\t\t\t\tboosted = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.add(msg, target, boostName, boostBy);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.runEvent('AfterEachBoost', target, source, effect, currentBoost);\n\t\t\t} else if (effect?.effectType === 'Ability') {\n\t\t\t\tif (isSecondary || isSelf) this.add(msg, target, boostName, boostBy);\n\t\t\t} else if (!isSecondary && !isSelf) {\n\t\t\t\tthis.add(msg, target, boostName, boostBy);\n\t\t\t}\n\t\t}\n\t\tthis.runEvent('AfterBoost', target, source, effect, boost);\n\t\tif (success) {\n\t\t\tif (Object.values(boost).some(x => x > 0)) target.statsRaisedThisTurn = true;\n\t\t\tif (Object.values(boost).some(x => x < 0)) target.statsLoweredThisTurn = true;\n\t\t}\n\t\treturn success;\n\t},\n\tgetActionSpeed(action) {\n\t\tif (action.choice === 'move') {\n\t\t\tlet move = action.move;\n\t\t\tif (action.zmove) {\n\t\t\t\tconst zMoveName = this.actions.getZMove(action.move, action.pokemon, true);\n\t\t\t\tif (zMoveName) {\n\t\t\t\t\tconst zMove = this.dex.getActiveMove(zMoveName);\n\t\t\t\t\tif (zMove.exists && zMove.isZ) {\n\t\t\t\t\t\tmove = zMove;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (action.maxMove) {\n\t\t\t\tconst maxMoveName = this.actions.getMaxMove(action.maxMove, action.pokemon);\n\t\t\t\tif (maxMoveName) {\n\t\t\t\t\tconst maxMove = this.actions.getActiveMaxMove(action.move, action.pokemon);\n\t\t\t\t\tif (maxMove.exists && maxMove.isMax) {\n\t\t\t\t\t\tmove = maxMove;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t// WHY DOES onModifyPriority TAKE A TARGET ARG WHEN IT IS ALWAYS NULL?????\n\t\t\tconst target = this.getTarget(action.pokemon, action.move, action.targetLoc);\n\t\t\t// take priority from the base move, so abilities like Prankster only apply once\n\t\t\t// (instead of compounding every time `getActionSpeed` is called)\n\t\t\tlet priority = this.dex.moves.get(move.id).priority;\n\t\t\t// Grassy Glide priority\n\t\t\tpriority = this.singleEvent('ModifyPriority', move, null, action.pokemon, target, null, priority);\n\t\t\tpriority = this.runEvent('ModifyPriority', action.pokemon, target, move, priority);\n\t\t\taction.priority = priority + action.fractionalPriority;\n\t\t\t// In Gen 6, Quick Guard blocks moves with artificially enhanced priority.\n\t\t\tif (this.gen > 5) action.move.priority = priority;\n\t\t}\n\n\t\tif (!action.pokemon) {\n\t\t\taction.speed = 1;\n\t\t} else {\n\t\t\taction.speed = action.pokemon.getActionSpeed();\n\t\t}\n\t},\n\t// For some god forsaken reason removing the boolean declarations causes the \"battles dont end automatically\" bug\n\t// I don't know why but in any case please don't touch this unless you know how to fix this\n\tfaintMessages(lastFirst = false, forceCheck = false, checkWin = true) {\n\t\tif (this.ended) return;\n\t\tconst length = this.faintQueue.length;\n\t\tif (!length) {\n\t\t\tif (forceCheck && this.checkWin()) return true;\n\t\t\treturn false;\n\t\t}\n\t\tif (lastFirst) {\n\t\t\tthis.faintQueue.unshift(this.faintQueue[this.faintQueue.length - 1]);\n\t\t\tthis.faintQueue.pop();\n\t\t}\n\t\tlet faintQueueLeft, faintData;\n\t\twhile (this.faintQueue.length) {\n\t\t\tfaintQueueLeft = this.faintQueue.length;\n\t\t\tfaintData = this.faintQueue.shift()!;\n\t\t\tconst pokemon: Pokemon = faintData.target;\n\t\t\tif (!pokemon.fainted &&\n\t\t\t\tthis.runEvent('BeforeFaint', pokemon, faintData.source, faintData.effect)) {\n\t\t\t\tif (!pokemon.isActive) {\n\t\t\t\t\tthis.add('message', `${pokemon.name} was killed by ${pokemon.side.name}!`);\n\t\t\t\t\t// TODO: Custom Protocol needed for teambar update\n\t\t\t\t} else {\n\t\t\t\t\tthis.add('faint', pokemon);\n\t\t\t\t}\n\t\t\t\tif (pokemon.side.pokemonLeft) pokemon.side.pokemonLeft--;\n\t\t\t\tif (pokemon.side.totalFainted < 100) pokemon.side.totalFainted++;\n\t\t\t\tthis.runEvent('Faint', pokemon, faintData.source, faintData.effect);\n\t\t\t\tthis.singleEvent('End', pokemon.getAbility(), pokemon.abilityState, pokemon);\n\t\t\t\tpokemon.clearVolatile(false);\n\t\t\t\tpokemon.fainted = true;\n\t\t\t\tpokemon.illusion = null;\n\t\t\t\tpokemon.isActive = false;\n\t\t\t\tpokemon.isStarted = false;\n\t\t\t\tdelete pokemon.terastallized;\n\t\t\t\tpokemon.side.faintedThisTurn = pokemon;\n\t\t\t\tif (this.faintQueue.length >= faintQueueLeft) checkWin = true;\n\t\t\t}\n\t\t}\n\n\t\tif (this.gen <= 1) {\n\t\t\t// in gen 1, fainting skips the rest of the turn\n\t\t\t// residuals don't exist in gen 1\n\t\t\tthis.queue.clear();\n\t\t\t// Fainting clears accumulated Bide damage\n\t\t\tfor (const pokemon of this.getAllActive()) {\n\t\t\t\tif (pokemon.volatiles['bide']?.damage) {\n\t\t\t\t\tpokemon.volatiles['bide'].damage = 0;\n\t\t\t\t\tthis.hint(\"Desync Clause Mod activated!\");\n\t\t\t\t\tthis.hint(\"In Gen 1, Bide's accumulated damage is reset to 0 when a Pokemon faints.\");\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.gen <= 3 && this.gameType === 'singles') {\n\t\t\t// in gen 3 or earlier, fainting in singles skips to residuals\n\t\t\tfor (const pokemon of this.getAllActive()) {\n\t\t\t\tif (this.gen <= 2) {\n\t\t\t\t\t// in gen 2, fainting skips moves only\n\t\t\t\t\tthis.queue.cancelMove(pokemon);\n\t\t\t\t} else {\n\t\t\t\t\t// in gen 3, fainting skips all moves and switches\n\t\t\t\t\tthis.queue.cancelAction(pokemon);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (checkWin && this.checkWin(faintData)) return true;\n\n\t\tif (faintData && length) {\n\t\t\tthis.runEvent('AfterFaint', faintData.target, faintData.source, faintData.effect, length);\n\t\t}\n\t\treturn false;\n\t},\n\tcheckMoveMakesContact(move, attacker, defender, announcePads) {\n\t\tif (move.flags['contact'] && attacker.hasItem('protectivepads')) {\n\t\t\tif (announcePads) {\n\t\t\t\tthis.add('-activate', defender, this.effect.fullname);\n\t\t\t\tthis.add('-activate', attacker, 'item: Protective Pads');\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (move.id === 'wonderwing') return false;\n\t\treturn !!move.flags['contact'];\n\t},\n\t// Fake switch needed for HiZo's Scapegoat\n\trunAction(action) {\n\t\tconst pokemonOriginalHP = action.pokemon?.hp;\n\t\tlet residualPokemon: (readonly [Pokemon, number])[] = [];\n\t\t// returns whether or not we ended in a callback\n\t\tswitch (action.choice) {\n\t\tcase 'start': {\n\t\t\tfor (const side of this.sides) {\n\t\t\t\tif (side.pokemonLeft) side.pokemonLeft = side.pokemon.length;\n\t\t\t}\n\n\t\t\tthis.add('start');\n\n\t\t\t// Change Zacian/Zamazenta into their Crowned formes\n\t\t\tfor (const pokemon of this.getAllPokemon()) {\n\t\t\t\tlet rawSpecies: Species | null = null;\n\t\t\t\tif (pokemon.species.id === 'zacian' && pokemon.item === 'rustedsword') {\n\t\t\t\t\trawSpecies = this.dex.species.get('Zacian-Crowned');\n\t\t\t\t} else if (pokemon.species.id === 'zamazenta' && pokemon.item === 'rustedshield') {\n\t\t\t\t\trawSpecies = this.dex.species.get('Zamazenta-Crowned');\n\t\t\t\t}\n\t\t\t\tif (!rawSpecies) continue;\n\t\t\t\tconst species = pokemon.setSpecies(rawSpecies);\n\t\t\t\tif (!species) continue;\n\t\t\t\tpokemon.baseSpecies = rawSpecies;\n\t\t\t\tpokemon.details = pokemon.getUpdatedDetails();\n\t\t\t\t// pokemon.setAbility(species.abilities['0'], null, true);\n\t\t\t\t// pokemon.baseAbility = pokemon.ability;\n\n\t\t\t\tconst behemothMove: { [k: string]: string } = {\n\t\t\t\t\t'Zacian-Crowned': 'behemothblade', 'Zamazenta-Crowned': 'behemothbash',\n\t\t\t\t};\n\t\t\t\tconst ironHead = pokemon.baseMoves.indexOf('ironhead');\n\t\t\t\tif (ironHead >= 0) {\n\t\t\t\t\tconst move = this.dex.moves.get(behemothMove[rawSpecies.name]);\n\t\t\t\t\tpokemon.baseMoveSlots[ironHead] = {\n\t\t\t\t\t\tmove: move.name,\n\t\t\t\t\t\tid: move.id,\n\t\t\t\t\t\tpp: move.noPPBoosts ? move.pp : move.pp * 8 / 5,\n\t\t\t\t\t\tmaxpp: move.noPPBoosts ? move.pp : move.pp * 8 / 5,\n\t\t\t\t\t\ttarget: move.target,\n\t\t\t\t\t\tdisabled: false,\n\t\t\t\t\t\tdisabledSource: '',\n\t\t\t\t\t\tused: false,\n\t\t\t\t\t};\n\t\t\t\t\tpokemon.moveSlots = pokemon.baseMoveSlots.slice();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.format.onBattleStart) this.format.onBattleStart.call(this);\n\t\t\tfor (const rule of this.ruleTable.keys()) {\n\t\t\t\tif ('+*-!'.includes(rule.charAt(0))) continue;\n\t\t\t\tconst subFormat = this.dex.formats.get(rule);\n\t\t\t\tif (subFormat.onBattleStart) subFormat.onBattleStart.call(this);\n\t\t\t}\n\n\t\t\tfor (const side of this.sides) {\n\t\t\t\tfor (let i = 0; i < side.active.length; i++) {\n\t\t\t\t\tif (!side.pokemonLeft) {\n\t\t\t\t\t\t// forfeited before starting\n\t\t\t\t\t\tside.active[i] = side.pokemon[i];\n\t\t\t\t\t\tside.active[i].fainted = true;\n\t\t\t\t\t\tside.active[i].hp = 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.actions.switchIn(side.pokemon[i], i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const pokemon of this.getAllPokemon()) {\n\t\t\t\tthis.singleEvent('Start', this.dex.conditions.getByID(pokemon.species.id), pokemon.speciesState, pokemon);\n\t\t\t}\n\t\t\tthis.midTurn = true;\n\t\t\tbreak;\n\t\t}\n\n\t\tcase 'move':\n\t\t\tif (!action.pokemon.isActive) return false;\n\t\t\tif (action.pokemon.fainted) return false;\n\t\t\tthis.actions.runMove(action.move, action.pokemon, action.targetLoc, {\n\t\t\t\tsourceEffect: action.sourceEffect, zMove: action.zmove,\n\t\t\t\tmaxMove: action.maxMove, originalTarget: action.originalTarget,\n\t\t\t});\n\t\t\tbreak;\n\t\tcase 'megaEvo':\n\t\t\tthis.actions.runMegaEvo(action.pokemon);\n\t\t\tbreak;\n\t\tcase 'runDynamax':\n\t\t\taction.pokemon.addVolatile('dynamax');\n\t\t\taction.pokemon.side.dynamaxUsed = true;\n\t\t\tif (action.pokemon.side.allySide) action.pokemon.side.allySide.dynamaxUsed = true;\n\t\t\tbreak;\n\t\tcase 'terastallize':\n\t\t\tthis.actions.terastallize(action.pokemon);\n\t\t\tbreak;\n\t\tcase 'beforeTurnMove':\n\t\t\tif (!action.pokemon.isActive) return false;\n\t\t\tif (action.pokemon.fainted) return false;\n\t\t\tthis.debug('before turn callback: ' + action.move.id);\n\t\t\tconst target = this.getTarget(action.pokemon, action.move, action.targetLoc);\n\t\t\tif (!target) return false;\n\t\t\tif (!action.move.beforeTurnCallback) throw new Error(`beforeTurnMove has no beforeTurnCallback`);\n\t\t\taction.move.beforeTurnCallback.call(this, action.pokemon, target);\n\t\t\tbreak;\n\t\tcase 'priorityChargeMove':\n\t\t\tif (!action.pokemon.isActive) return false;\n\t\t\tif (action.pokemon.fainted) return false;\n\t\t\tthis.debug('priority charge callback: ' + action.move.id);\n\t\t\tif (!action.move.priorityChargeCallback) throw new Error(`priorityChargeMove has no priorityChargeCallback`);\n\t\t\taction.move.priorityChargeCallback.call(this, action.pokemon);\n\t\t\tbreak;\n\n\t\tcase 'event':\n\t\t\tthis.runEvent(action.event!, action.pokemon);\n\t\t\tbreak;\n\t\tcase 'team':\n\t\t\tif (action.index === 0) {\n\t\t\t\taction.pokemon.side.pokemon = [];\n\t\t\t}\n\t\t\taction.pokemon.side.pokemon.push(action.pokemon);\n\t\t\taction.pokemon.position = action.index;\n\t\t\t// we return here because the update event would crash since there are no active pokemon yet\n\t\t\treturn;\n\n\t\tcase 'pass':\n\t\t\treturn;\n\t\tcase 'instaswitch':\n\t\tcase 'switch':\n\t\t\tif (action.choice === 'switch' && action.pokemon.status) {\n\t\t\t\tthis.singleEvent('CheckShow', this.dex.abilities.getByID('naturalcure' as ID), null, action.pokemon);\n\t\t\t}\n\t\t\tif (this.actions.switchIn(action.target, action.pokemon.position, action.sourceEffect) === 'pursuitfaint') {\n\t\t\t\t// a pokemon fainted from Pursuit before it could switch\n\t\t\t\tif (this.gen <= 4) {\n\t\t\t\t\t// in gen 2-4, the switch still happens\n\t\t\t\t\tthis.hint(\"Previously chosen switches continue in Gen 2-4 after a Pursuit target faints.\");\n\t\t\t\t\taction.priority = -101;\n\t\t\t\t\tthis.queue.unshift(action);\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\t// in gen 5+, the switch is cancelled\n\t\t\t\t\tthis.hint(\"A Pokemon can't switch between when it runs out of HP and when it faints\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'revivalblessing':\n\t\t\taction.pokemon.side.pokemonLeft++;\n\t\t\tif (action.target.position < action.pokemon.side.active.length) {\n\t\t\t\tthis.queue.addChoice({\n\t\t\t\t\tchoice: 'instaswitch',\n\t\t\t\t\tpokemon: action.target,\n\t\t\t\t\ttarget: action.target,\n\t\t\t\t});\n\t\t\t}\n\t\t\taction.target.fainted = false;\n\t\t\taction.target.faintQueued = false;\n\t\t\taction.target.subFainted = false;\n\t\t\taction.target.status = '';\n\t\t\taction.target.hp = 1; // Needed so hp functions works\n\t\t\taction.target.sethp(action.target.maxhp / 2);\n\t\t\tthis.add('-heal', action.target, action.target.getHealth, '[from] move: Revival Blessing');\n\t\t\taction.pokemon.side.removeSlotCondition(action.pokemon, 'revivalblessing');\n\t\t\tbreak;\n\t\t// @ts-expect-error I'm sorry but it takes a lot\n\t\tcase 'scapegoat':\n\t\t\taction = action as SwitchAction;\n\t\t\tconst percent = (action.target.hp / action.target.baseMaxhp) * 100;\n\t\t\t// TODO: Client support for custom faint\n\t\t\taction.target.faint();\n\t\t\tif (percent > 66) {\n\t\t\t\tthis.add('message', `Your courage will be greatly rewarded.`);\n\t\t\t\tthis.boost({ atk: 3, spa: 3, spe: 3 }, action.pokemon, action.pokemon, this.dex.moves.get('scapegoat') as any);\n\t\t\t} else if (percent > 33) {\n\t\t\t\tthis.add('message', `Your offering was accepted.`);\n\t\t\t\tthis.boost({ atk: 2, spa: 2, spe: 2 }, action.pokemon, action.pokemon, this.dex.moves.get('scapegoat') as any);\n\t\t\t} else {\n\t\t\t\tthis.add('message', `Coward.`);\n\t\t\t\tthis.boost({ atk: 1, spa: 1, spe: 1 }, action.pokemon, action.pokemon, this.dex.moves.get('scapegoat') as any);\n\t\t\t}\n\t\t\tthis.add(`c:|${getName((action.pokemon.illusion || action.pokemon).name)}|Don't worry, if this plan fails we can just blame ${action.target.name}`);\n\t\t\taction.pokemon.side.removeSlotCondition(action.pokemon, 'scapegoat');\n\t\t\tbreak;\n\t\tcase 'runSwitch':\n\t\t\tthis.actions.runSwitch(action.pokemon);\n\t\t\tbreak;\n\t\tcase 'shift':\n\t\t\tif (!action.pokemon.isActive) return false;\n\t\t\tif (action.pokemon.fainted) return false;\n\t\t\tthis.swapPosition(action.pokemon, 1);\n\t\t\tbreak;\n\n\t\tcase 'beforeTurn':\n\t\t\tthis.eachEvent('BeforeTurn');\n\t\t\tbreak;\n\t\tcase 'residual':\n\t\t\tthis.add('');\n\t\t\tthis.clearActiveMove(true);\n\t\t\tthis.updateSpeed();\n\t\t\tresidualPokemon = this.getAllActive().map(pokemon => [pokemon, pokemon.getUndynamaxedHP()] as const);\n\t\t\tthis.fieldEvent('Residual');\n\t\t\tthis.add('upkeep');\n\t\t\tbreak;\n\t\t}\n\n\t\t// phazing (Roar, etc)\n\t\tfor (const side of this.sides) {\n\t\t\tfor (const pokemon of side.active) {\n\t\t\t\tif (pokemon.forceSwitchFlag) {\n\t\t\t\t\tif (pokemon.hp) this.actions.dragIn(pokemon.side, pokemon.position);\n\t\t\t\t\tpokemon.forceSwitchFlag = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.clearActiveMove();\n\n\t\t// fainting\n\n\t\tthis.faintMessages();\n\t\tif (this.ended) return true;\n\n\t\t// switching (fainted pokemon, U-turn, Baton Pass, etc)\n\n\t\tif (!this.queue.peek() || (this.gen <= 3 && ['move', 'residual'].includes(this.queue.peek()!.choice))) {\n\t\t\t// in gen 3 or earlier, switching in fainted pokemon is done after\n\t\t\t// every move, rather than only at the end of the turn.\n\t\t\tthis.checkFainted();\n\t\t} else if (action.choice === 'megaEvo' && this.gen === 7) {\n\t\t\tthis.eachEvent('Update');\n\t\t\t// In Gen 7, the action order is recalculated for a Pok\u00E9mon that mega evolves.\n\t\t\tfor (const [i, queuedAction] of this.queue.list.entries()) {\n\t\t\t\tif (queuedAction.pokemon === action.pokemon && queuedAction.choice === 'move') {\n\t\t\t\t\tthis.queue.list.splice(i, 1);\n\t\t\t\t\tqueuedAction.mega = 'done';\n\t\t\t\t\tthis.queue.insertChoice(queuedAction, true);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t} else if (this.queue.peek()?.choice === 'instaswitch') {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.gen >= 5 && action.choice !== 'start') {\n\t\t\tthis.eachEvent('Update');\n\t\t\tfor (const [pokemon, originalHP] of residualPokemon) {\n\t\t\t\tconst maxhp = pokemon.getUndynamaxedHP(pokemon.maxhp);\n\t\t\t\tif (pokemon.hp && pokemon.getUndynamaxedHP() <= maxhp / 2 && originalHP > maxhp / 2) {\n\t\t\t\t\tthis.runEvent('EmergencyExit', pokemon);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (action.choice === 'runSwitch') {\n\t\t\tconst pokemon = action.pokemon;\n\t\t\tif (pokemon.hp && pokemon.hp <= pokemon.maxhp / 2 && pokemonOriginalHP! > pokemon.maxhp / 2) {\n\t\t\t\tthis.runEvent('EmergencyExit', pokemon);\n\t\t\t}\n\t\t}\n\n\t\tconst switches = this.sides.map(\n\t\t\tside => side.active.some(pokemon => pokemon && !!pokemon.switchFlag)\n\t\t);\n\n\t\tfor (let i = 0; i < this.sides.length; i++) {\n\t\t\tlet reviveSwitch = false; // Used to ignore the fake switch for Revival Blessing\n\t\t\tif (switches[i] && !this.canSwitch(this.sides[i])) {\n\t\t\t\tfor (const pokemon of this.sides[i].active) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.sides[i].slotConditions[pokemon.position]['revivalblessing'] ||\n\t\t\t\t\t\tthis.sides[i].slotConditions[pokemon.position]['scapegoat']\n\t\t\t\t\t) {\n\t\t\t\t\t\treviveSwitch = true;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tpokemon.switchFlag = false;\n\t\t\t\t}\n\t\t\t\tif (!reviveSwitch) switches[i] = false;\n\t\t\t} else if (switches[i]) {\n\t\t\t\tfor (const pokemon of this.sides[i].active) {\n\t\t\t\t\tif (pokemon.hp && pokemon.switchFlag && pokemon.switchFlag !== 'revivalblessing' &&\n\t\t\t\t\t\tpokemon.switchFlag !== 'scapegoat' && !pokemon.skipBeforeSwitchOutEventFlag) {\n\t\t\t\t\t\tthis.runEvent('BeforeSwitchOut', pokemon);\n\t\t\t\t\t\tpokemon.skipBeforeSwitchOutEventFlag = true;\n\t\t\t\t\t\tthis.faintMessages(); // Pokemon may have fainted in BeforeSwitchOut\n\t\t\t\t\t\tif (this.ended) return true;\n\t\t\t\t\t\tif (pokemon.fainted) {\n\t\t\t\t\t\t\tswitches[i] = this.sides[i].active.some(sidePokemon => sidePokemon && !!sidePokemon.switchFlag);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const playerSwitch of switches) {\n\t\t\tif (playerSwitch) {\n\t\t\t\tthis.makeRequest('switch');\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tif (this.gen < 5) this.eachEvent('Update');\n\n\t\tif (this.gen >= 8 && (this.queue.peek()?.choice === 'move' || this.queue.peek()?.choice === 'runDynamax')) {\n\t\t\t// In gen 8, speed is updated dynamically so update the queue's speed properties and sort it.\n\t\t\tthis.updateSpeed();\n\t\t\tfor (const queueAction of this.queue.list) {\n\t\t\t\tif (queueAction.pokemon) this.getActionSpeed(queueAction);\n\t\t\t}\n\t\t\tthis.queue.sort();\n\t\t}\n\n\t\treturn false;\n\t},\n\tactions: {\n\t\tterastallize(pokemon) {\n\t\t\tif (pokemon.illusion && ['Ogerpon', 'Terapagos'].includes(pokemon.illusion.species.baseSpecies)) {\n\t\t\t\tthis.battle.singleEvent('End', this.dex.abilities.get('Illusion'), pokemon.abilityState, pokemon);\n\t\t\t}\n\n\t\t\tconst type = pokemon.teraType;\n\t\t\tthis.battle.add('-terastallize', pokemon, type);\n\t\t\tpokemon.terastallized = type;\n\t\t\tfor (const ally of pokemon.side.pokemon) {\n\t\t\t\tally.canTerastallize = null;\n\t\t\t}\n\t\t\tpokemon.addedType = '';\n\t\t\tpokemon.knownType = true;\n\t\t\tpokemon.apparentType = type;\n\t\t\tif (pokemon.species.baseSpecies === 'Ogerpon') {\n\t\t\t\tconst tera = pokemon.species.id === 'ogerpon' ? 'tealtera' : 'tera';\n\t\t\t\tpokemon.formeChange(pokemon.species.id + tera, null, true);\n\t\t\t}\n\t\t\tif (pokemon.species.name === 'Terapagos-Terastal' && type === 'Stellar') {\n\t\t\t\tpokemon.formeChange('Terapagos-Stellar', null, true);\n\t\t\t\tpokemon.baseMaxhp = Math.floor(Math.floor(\n\t\t\t\t\t2 * pokemon.species.baseStats['hp'] + pokemon.set.ivs['hp'] + Math.floor(pokemon.set.evs['hp'] / 4) + 100\n\t\t\t\t) * pokemon.level / 100 + 10);\n\t\t\t\tconst newMaxHP = pokemon.baseMaxhp;\n\t\t\t\tpokemon.hp = newMaxHP - (pokemon.maxhp - pokemon.hp);\n\t\t\t\tpokemon.maxhp = newMaxHP;\n\t\t\t\tthis.battle.add('-heal', pokemon, pokemon.getHealth, '[silent]');\n\t\t\t}\n\t\t\tif (!pokemon.illusion && pokemon.name === 'Neko') {\n\t\t\t\tthis.battle.add(`c:|${getName('Neko')}|Possible thermal failure if operation continues (Meow on fire ?)`);\n\t\t\t}\n\t\t\tthis.battle.runEvent('AfterTerastallization', pokemon);\n\t\t},\n\t\tmodifyDamage(baseDamage, pokemon, target, move, suppressMessages) {\n\t\t\tconst tr = this.battle.trunc;\n\t\t\tif (!move.type) move.type = '???';\n\t\t\tconst type = move.type;\n\n\t\t\tbaseDamage += 2;\n\n\t\t\tif (move.spreadHit) {\n\t\t\t\t// multi-target modifier (doubles only)\n\t\t\t\tconst spreadModifier = move.spreadModifier || (this.battle.gameType === 'freeforall' ? 0.5 : 0.75);\n\t\t\t\tthis.battle.debug(`Spread modifier: ${spreadModifier}`);\n\t\t\t\tbaseDamage = this.battle.modify(baseDamage, spreadModifier);\n\t\t\t} else if (move.multihitType === 'parentalbond' && move.hit > 1) {\n\t\t\t\t// Parental Bond modifier\n\t\t\t\tconst bondModifier = this.battle.gen > 6 && !pokemon.hasAbility('Almost Frosty') ? 0.25 : 0.5;\n\t\t\t\tthis.battle.debug(`Parental Bond modifier: ${bondModifier}`);\n\t\t\t\tbaseDamage = this.battle.modify(baseDamage, bondModifier);\n\t\t\t}\n\n\t\t\t// weather modifier\n\t\t\tbaseDamage = this.battle.runEvent('WeatherModifyDamage', pokemon, target, move, baseDamage);\n\n\t\t\t// crit - not a modifier\n\t\t\tconst isCrit = target.getMoveHitData(move).crit;\n\t\t\tif (isCrit) {\n\t\t\t\tbaseDamage = tr(baseDamage * (move.critModifier || (this.battle.gen >= 6 ? 1.5 : 2)));\n\t\t\t} else {\n\t\t\t\tif (move.id === 'megidolaon') delete move.volatileStatus;\n\t\t\t}\n\n\t\t\t// random factor - also not a modifier\n\t\t\tbaseDamage = this.battle.randomizer(baseDamage);\n\n\t\t\t// STAB\n\t\t\t// The \"???\" type never gets STAB\n\t\t\t// Not even if you Roost in Gen 4 and somehow manage to use\n\t\t\t// Struggle in the same turn.\n\t\t\t// (On second thought, it might be easier to get a MissingNo.)\n\t\t\tif (type !== '???') {\n\t\t\t\tlet stab: number | [number, number] = 1;\n\n\t\t\t\tconst isSTAB = move.forceSTAB || pokemon.hasType(type) || pokemon.getTypes(false, true).includes(type);\n\t\t\t\tif (isSTAB) {\n\t\t\t\t\tstab = 1.5;\n\t\t\t\t}\n\n\t\t\t\t// The Stellar tera type makes this incredibly confusing\n\t\t\t\t// If the move's type does not match one of the user's base types,\n\t\t\t\t// the Stellar tera type applies a one-time 1.2x damage boost for that type.\n\t\t\t\t//\n\t\t\t\t// If the move's type does match one of the user's base types,\n\t\t\t\t// then the Stellar tera type applies a one-time 2x STAB boost for that type,\n\t\t\t\t// and then goes back to using the regular 1.5x STAB boost for those types.\n\t\t\t\tif (pokemon.terastallized === 'Stellar') {\n\t\t\t\t\tif (!pokemon.stellarBoostedTypes.includes(type)) {\n\t\t\t\t\t\tstab = isSTAB ? 2 : [4915, 4096];\n\t\t\t\t\t\tif (!(pokemon.species.name === 'Terapagos-Stellar' || pokemon.species.baseSpecies === 'Meloetta')) {\n\t\t\t\t\t\t\tpokemon.stellarBoostedTypes.push(type);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (pokemon.terastallized === type && pokemon.getTypes(false, true).includes(type)) {\n\t\t\t\t\t\tstab = 2;\n\t\t\t\t\t}\n\t\t\t\t\tstab = this.battle.runEvent('ModifySTAB', pokemon, target, move, stab);\n\t\t\t\t}\n\n\t\t\t\tbaseDamage = this.battle.modify(baseDamage, stab);\n\t\t\t}\n\n\t\t\t// types\n\t\t\tlet typeMod = target.runEffectiveness(move);\n\t\t\ttypeMod = this.battle.clampIntRange(typeMod, -6, 6);\n\t\t\ttarget.getMoveHitData(move).typeMod = typeMod;\n\t\t\tif (typeMod > 0) {\n\t\t\t\tif (!suppressMessages) this.battle.add('-supereffective', target);\n\n\t\t\t\tfor (let i = 0; i < typeMod; i++) {\n\t\t\t\t\tbaseDamage *= 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeMod < 0) {\n\t\t\t\tif (!suppressMessages) this.battle.add('-resisted', target);\n\n\t\t\t\tfor (let i = 0; i > typeMod; i--) {\n\t\t\t\t\tbaseDamage = tr(baseDamage / 2);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isCrit && !suppressMessages) this.battle.add('-crit', target);\n\n\t\t\tif (pokemon.status === 'brn' && move.category === 'Physical' &&\n\t\t\t\t!pokemon.hasAbility(['guts', 'fortifiedmetal'])) {\n\t\t\t\tif (this.battle.gen < 6 || move.id !== 'facade') {\n\t\t\t\t\tbaseDamage = this.battle.modify(baseDamage, 0.5);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Generation 5, but nothing later, sets damage to 1 before the final damage modifiers\n\t\t\tif (this.battle.gen === 5 && !baseDamage) baseDamage = 1;\n\n\t\t\t// Final modifier. Modifiers that modify damage after min damage check, such as Life Orb.\n\t\t\tbaseDamage = this.battle.runEvent('ModifyDamage', pokemon, target, move, baseDamage);\n\n\t\t\tif (move.isZOrMaxPowered && target.getMoveHitData(move).zBrokeProtect) {\n\t\t\t\tbaseDamage = this.battle.modify(baseDamage, 0.25);\n\t\t\t\tthis.battle.add('-zbroken', target);\n\t\t\t}\n\n\t\t\t// Generation 6-7 moves the check for minimum 1 damage after the final modifier...\n\t\t\tif (this.battle.gen !== 5 && !baseDamage) return 1;\n\n\t\t\t// ...but 16-bit truncation happens even later, and can truncate to 0\n\t\t\treturn tr(baseDamage, 16);\n\t\t},\n\t\tswitchIn(pokemon, pos, sourceEffect, isDrag) {\n\t\t\tif (!pokemon || pokemon.isActive) {\n\t\t\t\tthis.battle.hint(\"A switch failed because the Pok\u00E9mon trying to switch in is already in.\");\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst side = pokemon.side;\n\t\t\tif (pos >= side.active.length) {\n\t\t\t\tthrow new Error(`Invalid switch position ${pos} / ${side.active.length}`);\n\t\t\t}\n\t\t\tconst oldActive = side.active[pos];\n\t\t\tconst unfaintedActive = oldActive?.hp ? oldActive : null;\n\t\t\tif (unfaintedActive) {\n\t\t\t\toldActive.beingCalledBack = true;\n\t\t\t\tlet switchCopyFlag: 'copyvolatile' | 'shedtail' | boolean = false;\n\t\t\t\tif (sourceEffect && typeof (sourceEffect as Move).selfSwitch === 'string') {\n\t\t\t\t\tswitchCopyFlag = (sourceEffect as Move).selfSwitch!;\n\t\t\t\t}\n\t\t\t\tif (!oldActive.skipBeforeSwitchOutEventFlag && !isDrag) {\n\t\t\t\t\tthis.battle.runEvent('BeforeSwitchOut', oldActive);\n\t\t\t\t\tif (this.battle.gen >= 5) {\n\t\t\t\t\t\tthis.battle.eachEvent('Update');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\toldActive.skipBeforeSwitchOutEventFlag = false;\n\t\t\t\tif (!this.battle.runEvent('SwitchOut', oldActive)) {\n\t\t\t\t\t// Warning: DO NOT interrupt a switch-out if you just want to trap a pokemon.\n\t\t\t\t\t// To trap a pokemon and prevent it from switching out, (e.g. Mean Look, Magnet Pull)\n\t\t\t\t\t// use the 'trapped' flag instead.\n\n\t\t\t\t\t// Note: Nothing in the real games can interrupt a switch-out (except Pursuit KOing,\n\t\t\t\t\t// which is handled elsewhere); this is just for custom formats.\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (!oldActive.hp) {\n\t\t\t\t\t// a pokemon fainted from Pursuit before it could switch\n\t\t\t\t\treturn 'pursuitfaint';\n\t\t\t\t}\n\n\t\t\t\t// will definitely switch out at this point\n\n\t\t\t\toldActive.illusion = null;\n\t\t\t\tthis.battle.singleEvent('End', oldActive.getAbility(), oldActive.abilityState, oldActive);\n\n\t\t\t\t// if a pokemon is forced out by Whirlwind/etc or Eject Button/Pack, it can't use its chosen move\n\t\t\t\tthis.battle.queue.cancelAction(oldActive);\n\n\t\t\t\tlet newMove = null;\n\t\t\t\tif (this.battle.gen === 4 && sourceEffect) {\n\t\t\t\t\tnewMove = oldActive.lastMove;\n\t\t\t\t}\n\t\t\t\tif (switchCopyFlag) {\n\t\t\t\t\tpokemon.copyVolatileFrom(oldActive, switchCopyFlag);\n\t\t\t\t}\n\t\t\t\tif (newMove) pokemon.lastMove = newMove;\n\t\t\t\toldActive.clearVolatile();\n\t\t\t}\n\t\t\tif (oldActive) {\n\t\t\t\toldActive.isActive = false;\n\t\t\t\toldActive.isStarted = false;\n\t\t\t\toldActive.usedItemThisTurn = false;\n\t\t\t\toldActive.statsRaisedThisTurn = false;\n\t\t\t\toldActive.statsLoweredThisTurn = false;\n\t\t\t\t// ptoad\n\t\t\t\tdelete oldActive.m.usedPleek;\n\t\t\t\tdelete oldActive.m.usedPlagiarism;\n\t\t\t\toldActive.position = pokemon.position;\n\t\t\t\tpokemon.position = pos;\n\t\t\t\tside.pokemon[pokemon.position] = pokemon;\n\t\t\t\tside.pokemon[oldActive.position] = oldActive;\n\t\t\t}\n\t\t\tpokemon.isActive = true;\n\t\t\tside.active[pos] = pokemon;\n\t\t\tpokemon.activeTurns = 0;\n\t\t\tpokemon.activeMoveActions = 0;\n\t\t\tfor (const moveSlot of pokemon.moveSlots) {\n\t\t\t\tmoveSlot.used = false;\n\t\t\t}\n\t\t\tthis.battle.runEvent('BeforeSwitchIn', pokemon);\n\t\t\tif (sourceEffect) {\n\t\t\t\tthis.battle.add(isDrag ? 'drag' : 'switch', pokemon, pokemon.getFullDetails, `[from] ${sourceEffect}`);\n\t\t\t} else {\n\t\t\t\tthis.battle.add(isDrag ? 'drag' : 'switch', pokemon, pokemon.getFullDetails);\n\t\t\t}\n\t\t\tpokemon.abilityState.effectOrder = this.battle.effectOrder++;\n\t\t\tpokemon.itemState.effectOrder = this.battle.effectOrder++;\n\t\t\tif (isDrag && this.battle.gen === 2) pokemon.draggedIn = this.battle.turn;\n\t\t\tpokemon.previouslySwitchedIn++;\n\n\t\t\tif (isDrag && this.battle.gen >= 5) {\n\t\t\t\t// runSwitch happens immediately so that Mold Breaker can make hazards bypass Clear Body and Levitate\n\t\t\t\tthis.runSwitch(pokemon);\n\t\t\t} else {\n\t\t\t\tthis.battle.queue.insertChoice({ choice: 'runSwitch', pokemon });\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t\tcanTerastallize(pokemon) {\n\t\t\tif (\n\t\t\t\tpokemon.terastallized || pokemon.species.isMega || pokemon.species.isPrimal || pokemon.species.forme === \"Ultra\" ||\n\t\t\t\tpokemon.getItem().zMove || pokemon.canMegaEvo || pokemon.side.canDynamaxNow() || this.dex.gen !== 9\n\t\t\t) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (pokemon.baseSpecies.id === 'arceus') return null;\n\t\t\treturn pokemon.teraType;\n\t\t},\n\t\t// 1 mega per pokemon\n\t\trunMegaEvo(pokemon) {\n\t\t\tconst speciesid = pokemon.canMegaEvo || pokemon.canUltraBurst;\n\t\t\tif (!speciesid) return false;\n\n\t\t\tif (speciesid === 'Trapinch' && pokemon.name === 'Arya') {\n\t\t\t\tthis.battle.add(`c:|${getName('Arya')}|Oh yeaaaaah!!!!! Finally??!! I can finally Mega-Evolve!!! Vamossss`);\n\t\t\t}\n\n\t\t\tpokemon.formeChange(speciesid, pokemon.getItem(), true);\n\t\t\tif (pokemon.canMegaEvo) {\n\t\t\t\tpokemon.canMegaEvo = null;\n\t\t\t} else {\n\t\t\t\tpokemon.canUltraBurst = null;\n\t\t\t}\n\n\t\t\tthis.battle.runEvent('AfterMega', pokemon);\n\n\t\t\t// Visual mega type changes here\n\t\t\tif (['Arya'].includes(pokemon.name) && !pokemon.illusion) {\n\t\t\t\tthis.battle.add('-start', pokemon, 'typechange', pokemon.getTypes(true).join('/'), '[silent]');\n\t\t\t}\n\n\t\t\tthis.battle.add('-ability', pokemon, `${pokemon.getAbility().name}`);\n\n\t\t\treturn true;\n\t\t},\n\n\t\t// Modded for Mega Rayquaza\n\t\tcanMegaEvo(pokemon) {\n\t\t\tconst species = pokemon.baseSpecies;\n\t\t\tconst altForme = species.otherFormes && this.dex.species.get(species.otherFormes[0]);\n\t\t\tconst item = pokemon.getItem();\n\t\t\t// Mega Rayquaza\n\t\t\tif (altForme?.isMega && altForme?.requiredMove &&\n\t\t\t\tpokemon.baseMoves.includes(this.battle.toID(altForme.requiredMove)) && !item.zMove) {\n\t\t\t\treturn altForme.name;\n\t\t\t}\n\t\t\t// a hacked-in Megazard X can mega evolve into Megazard Y, but not into Megazard X\n\t\t\tif (item.megaEvolves === species.baseSpecies && item.megaStone !== species.name) {\n\t\t\t\treturn item.megaStone;\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\n\t\t// 1 Z per pokemon\n\t\tcanZMove(pokemon) {\n\t\t\tif (pokemon.m.zMoveUsed ||\n\t\t\t\t(pokemon.transformed &&\n\t\t\t\t\t(pokemon.species.isMega || pokemon.species.isPrimal || pokemon.species.forme === \"Ultra\"))\n\t\t\t) return;\n\t\t\tconst item = pokemon.getItem();\n\t\t\tif (!item.zMove) return;\n\t\t\tif (item.itemUser && !item.itemUser.includes(pokemon.species.name)) return;\n\t\t\tlet atLeastOne = false;\n\t\t\tlet mustStruggle = true;\n\t\t\tconst zMoves: ZMoveOptions = [];\n\t\t\tfor (const moveSlot of pokemon.moveSlots) {\n\t\t\t\tif (moveSlot.pp <= 0) {\n\t\t\t\t\tzMoves.push(null);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!moveSlot.disabled) {\n\t\t\t\t\tmustStruggle = false;\n\t\t\t\t}\n\t\t\t\tconst move = this.dex.moves.get(moveSlot.move);\n\t\t\t\tlet zMoveName = this.getZMove(move, pokemon, true) || '';\n\t\t\t\tif (zMoveName) {\n\t\t\t\t\tconst zMove = this.dex.moves.get(zMoveName);\n\t\t\t\t\tif (!zMove.isZ && zMove.category === 'Status') zMoveName = \"Z-\" + zMoveName;\n\t\t\t\t\tzMoves.push({ move: zMoveName, target: zMove.target });\n\t\t\t\t} else {\n\t\t\t\t\tzMoves.push(null);\n\t\t\t\t}\n\t\t\t\tif (zMoveName) atLeastOne = true;\n\t\t\t}\n\t\t\tif (atLeastOne && !mustStruggle) return zMoves;\n\t\t},\n\n\t\tgetZMove(move, pokemon, skipChecks) {\n\t\t\tconst item = pokemon.getItem();\n\t\t\tif (!skipChecks) {\n\t\t\t\tif (pokemon.m.zMoveUsed) return;\n\t\t\t\tif (!item.zMove) return;\n\t\t\t\tif (item.itemUser && !item.itemUser.includes(pokemon.species.name)) return;\n\t\t\t\tconst moveData = pokemon.getMoveData(move);\n\t\t\t\t// Draining the PP of the base move prevents the corresponding Z-move from being used.\n\t\t\t\tif (!moveData?.pp) return;\n\t\t\t}\n\n\t\t\tif (move.name === item.zMoveFrom) {\n\t\t\t\treturn item.zMove as string;\n\t\t\t} else if (item.zMove === true && move.type === item.zMoveType) {\n\t\t\t\tif (move.category === \"Status\") {\n\t\t\t\t\treturn move.name;\n\t\t\t\t} else if (move.zMove?.basePower) {\n\t\t\t\t\treturn this.Z_MOVES[move.type];\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\thitStepAccuracy(targets: Pokemon[], pokemon: Pokemon, move: ActiveMove) {\n\t\t\tconst hitResults = [];\n\t\t\tfor (const [i, target] of targets.entries()) {\n\t\t\t\tthis.battle.activeTarget = target;\n\t\t\t\t// calculate true accuracy\n\t\t\t\tlet accuracy = move.accuracy;\n\t\t\t\tif (move.ohko) { // bypasses accuracy modifiers\n\t\t\t\t\tif (!target.isSemiInvulnerable()) {\n\t\t\t\t\t\taccuracy = 30;\n\t\t\t\t\t\tif (move.ohko === 'Ice' && this.battle.gen >= 7 && !pokemon.hasType('Ice')) {\n\t\t\t\t\t\t\taccuracy = 20;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!target.volatiles['dynamax'] && pokemon.level >= target.level &&\n\t\t\t\t\t\t\t(move.ohko === true || !target.hasType(move.ohko))) {\n\t\t\t\t\t\t\taccuracy += (pokemon.level - target.level);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.battle.add('-immune', target, '[ohko]');\n\t\t\t\t\t\t\thitResults[i] = false;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\taccuracy = this.battle.runEvent('ModifyAccuracy', target, pokemon, move, accuracy);\n\t\t\t\t\tif (accuracy !== true) {\n\t\t\t\t\t\tlet boost = 0;\n\t\t\t\t\t\tif (!move.ignoreAccuracy) {\n\t\t\t\t\t\t\tconst boosts = this.battle.runEvent('ModifyBoost', pokemon, null, null, { ...pokemon.boosts });\n\t\t\t\t\t\t\tboost = this.battle.clampIntRange(boosts['accuracy'], -6, 6);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!move.ignoreEvasion) {\n\t\t\t\t\t\t\tconst boosts = this.battle.runEvent('ModifyBoost', target, null, null, { ...target.boosts });\n\t\t\t\t\t\t\tboost = this.battle.clampIntRange(boost - boosts['evasion'], -6, 6);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (boost > 0) {\n\t\t\t\t\t\t\taccuracy = this.battle.trunc(accuracy * (3 + boost) / 3);\n\t\t\t\t\t\t} else if (boost < 0) {\n\t\t\t\t\t\t\taccuracy = this.battle.trunc(accuracy * 3 / (3 - boost));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (move.alwaysHit || (move.id === 'toxic' && this.battle.gen >= 8 && pokemon.hasType('Poison')) ||\n\t\t\t\t\t(move.target === 'self' && move.category === 'Status' && !target.isSemiInvulnerable())) {\n\t\t\t\t\taccuracy = true; // bypasses ohko accuracy modifiers\n\t\t\t\t} else {\n\t\t\t\t\taccuracy = this.battle.runEvent('Accuracy', target, pokemon, move, accuracy);\n\t\t\t\t}\n\t\t\t\tif (accuracy !== true && !this.battle.randomChance(accuracy, 100)) {\n\t\t\t\t\tif (move.smartTarget) {\n\t\t\t\t\t\tmove.smartTarget = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (pokemon.hasAbility('misspelled')) {\n\t\t\t\t\t\t\t// Custom miss for HoeenHero\n\t\t\t\t\t\t\t// Typo the move\n\t\t\t\t\t\t\tconst typoedMove = move.name.charAt(0) + move.name.charAt(2) + move.name.charAt(1) + move.name.slice(3);\n\n\t\t\t\t\t\t\t// Modify the used move to be typoed.\n\t\t\t\t\t\t\tconst logEntries = this.battle.log[this.battle.lastMoveLine].split('|');\n\t\t\t\t\t\t\tlogEntries[3] = typoedMove;\n\t\t\t\t\t\t\tthis.battle.log[this.battle.lastMoveLine] = logEntries.join('|');\n\n\t\t\t\t\t\t\tthis.battle.attrLastMove('[still]');\n\t\t\t\t\t\t\tthis.battle.add('-message', `But it was misspelled!`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (!move.spreadHit) this.battle.attrLastMove('[miss]');\n\t\t\t\t\t\t\tthis.battle.add('-miss', pokemon, target);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!move.ohko && pokemon.hasItem('blunderpolicy') && pokemon.useItem()) {\n\t\t\t\t\t\tthis.battle.boost({ spe: 2 }, pokemon);\n\t\t\t\t\t}\n\t\t\t\t\thitResults[i] = false;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\thitResults[i] = true;\n\t\t\t}\n\t\t\treturn hitResults;\n\t\t},\n\n\t\trunMove(moveOrMoveName, pokemon, targetLoc, options) {\n\t\t\tpokemon.activeMoveActions++;\n\t\t\tconst zMove = options?.zMove;\n\t\t\tconst maxMove = options?.maxMove;\n\t\t\tconst externalMove = options?.externalMove;\n\t\t\tconst originalTarget = options?.originalTarget;\n\t\t\tlet sourceEffect = options?.sourceEffect;\n\t\t\tlet target = this.battle.getTarget(pokemon, maxMove || zMove || moveOrMoveName, targetLoc, originalTarget);\n\t\t\tlet baseMove = this.dex.getActiveMove(moveOrMoveName);\n\t\t\tconst priority = baseMove.priority;\n\t\t\tconst pranksterBoosted = baseMove.pranksterBoosted;\n\t\t\tif (baseMove.id !== 'struggle' && !zMove && !maxMove && !externalMove) {\n\t\t\t\tconst changedMove = this.battle.runEvent('OverrideAction', pokemon, target, baseMove);\n\t\t\t\tif (changedMove && changedMove !== true) {\n\t\t\t\t\tbaseMove = this.dex.getActiveMove(changedMove);\n\t\t\t\t\tbaseMove.priority = priority;\n\t\t\t\t\tif (pranksterBoosted) baseMove.pranksterBoosted = pranksterBoosted;\n\t\t\t\t\ttarget = this.battle.getRandomTarget(pokemon, baseMove);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet move = baseMove;\n\t\t\tif (zMove) {\n\t\t\t\tmove = this.getActiveZMove(baseMove, pokemon);\n\t\t\t} else if (maxMove) {\n\t\t\t\tmove = this.getActiveMaxMove(baseMove, pokemon);\n\t\t\t}\n\n\t\t\tmove.isExternal = externalMove;\n\n\t\t\tthis.battle.setActiveMove(move, pokemon, target);\n\n\t\t\t/* if (pokemon.moveThisTurn) {\n\t\t\t\t// THIS IS PURELY A SANITY CHECK\n\t\t\t\t// DO NOT TAKE ADVANTAGE OF THIS TO PREVENT A POKEMON FROM MOVING;\n\t\t\t\t// USE this.battle.queue.cancelMove INSTEAD\n\t\t\t\tthis.battle.debug(`${pokemon.id} INCONSISTENT STATE, ALREADY MOVED: ${pokemon.moveThisTurn}`);\n\t\t\t\tthis.battle.clearActiveMove(true);\n\t\t\t\treturn;\n\t\t\t} */\n\t\t\tconst willTryMove = this.battle.runEvent('BeforeMove', pokemon, target, move);\n\t\t\tif (!willTryMove) {\n\t\t\t\tthis.battle.runEvent('MoveAborted', pokemon, target, move);\n\t\t\t\tthis.battle.clearActiveMove(true);\n\t\t\t\t// The event 'BeforeMove' could have returned false or null\n\t\t\t\t// false indicates that this counts as a move failing for the purpose of calculating Stomping Tantrum's base power\n\t\t\t\t// null indicates the opposite, as the Pokemon didn't have an option to choose anything\n\t\t\t\tpokemon.moveThisTurnResult = willTryMove;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (move.beforeMoveCallback) {\n\t\t\t\tif (move.beforeMoveCallback.call(this.battle, pokemon, target, move)) {\n\t\t\t\t\tthis.battle.clearActiveMove(true);\n\t\t\t\t\tpokemon.moveThisTurnResult = false;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpokemon.lastDamage = 0;\n\t\t\tlet lockedMove;\n\t\t\tif (!externalMove) {\n\t\t\t\tlockedMove = this.battle.runEvent('LockMove', pokemon);\n\t\t\t\tif (lockedMove === true) lockedMove = false;\n\t\t\t\tif (!lockedMove) {\n\t\t\t\t\tif (!pokemon.deductPP(baseMove, null, target) && (move.id !== 'struggle')) {\n\t\t\t\t\t\tthis.battle.add('cant', pokemon, 'nopp', move);\n\t\t\t\t\t\tthis.battle.clearActiveMove(true);\n\t\t\t\t\t\tpokemon.moveThisTurnResult = false;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tsourceEffect = this.dex.conditions.get('lockedmove');\n\t\t\t\t}\n\t\t\t\tpokemon.moveUsed(move, targetLoc);\n\t\t\t}\n\n\t\t\t// Dancer Petal Dance hack\n\t\t\t// TODO: implement properly\n\t\t\tconst noLock = externalMove && !pokemon.volatiles['lockedmove'];\n\n\t\t\tif (zMove) {\n\t\t\t\tif (pokemon.illusion) {\n\t\t\t\t\tthis.battle.singleEvent('End', this.dex.abilities.get('Illusion'), pokemon.abilityState, pokemon);\n\t\t\t\t}\n\t\t\t\tthis.battle.add('-zpower', pokemon);\n\t\t\t\t// 1 z move per poke\n\t\t\t\tpokemon.m.zMoveUsed = true;\n\t\t\t}\n\n\t\t\tconst oldActiveMove = move;\n\n\t\t\tconst moveDidSomething = this.useMove(baseMove, pokemon, { target, sourceEffect, zMove, maxMove });\n\t\t\tthis.battle.lastSuccessfulMoveThisTurn = moveDidSomething ? this.battle.activeMove && this.battle.activeMove.id : null;\n\t\t\tif (this.battle.activeMove) move = this.battle.activeMove;\n\t\t\tthis.battle.singleEvent('AfterMove', move, null, pokemon, target, move);\n\t\t\tthis.battle.runEvent('AfterMove', pokemon, target, move);\n\n\t\t\t// Dancer's activation order is completely different from any other event, so it's handled separately\n\t\t\tif (move.flags['dance'] && moveDidSomething && !move.isExternal) {\n\t\t\t\tconst dancers = [];\n\t\t\t\tfor (const currentPoke of this.battle.getAllActive()) {\n\t\t\t\t\tif (pokemon === currentPoke) continue;\n\t\t\t\t\tif (currentPoke.hasAbility(['dancer', 'virtualidol']) && !currentPoke.isSemiInvulnerable()) {\n\t\t\t\t\t\tdancers.push(currentPoke);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Dancer activates in order of lowest speed stat to highest\n\t\t\t\t// Note that the speed stat used is after any volatile replacements like Speed Swap,\n\t\t\t\t// but before any multipliers like Agility or Choice Scarf\n\t\t\t\t// Ties go to whichever Pokemon has had the ability for the least amount of time\n\t\t\t\tdancers.sort(\n\t\t\t\t\t(a, b) => -(b.storedStats['spe'] - a.storedStats['spe']) || b.abilityState.effectOrder - a.abilityState.effectOrder\n\t\t\t\t);\n\t\t\t\tconst targetOf1stDance = this.battle.activeTarget!;\n\t\t\t\tfor (const dancer of dancers) {\n\t\t\t\t\tif (this.battle.faintMessages()) break;\n\t\t\t\t\tif (dancer.fainted) continue;\n\t\t\t\t\tthis.battle.add('-activate', dancer, 'ability: ' + dancer.getAbility().name);\n\t\t\t\t\tconst dancersTarget = !targetOf1stDance.isAlly(dancer) && pokemon.isAlly(dancer) ?\n\t\t\t\t\t\ttargetOf1stDance :\n\t\t\t\t\t\tpokemon;\n\t\t\t\t\tconst dancersTargetLoc = dancer.getLocOf(dancersTarget);\n\t\t\t\t\tthis.runMove(move.id, dancer, dancersTargetLoc, { sourceEffect: dancer.getAbility(), externalMove: true });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (noLock && pokemon.volatiles['lockedmove']) delete pokemon.volatiles['lockedmove'];\n\t\t\tthis.battle.faintMessages();\n\t\t\tthis.battle.checkWin();\n\n\t\t\tif (this.battle.gen <= 4) {\n\t\t\t\t// In gen 4, the outermost move is considered the last move for Copycat\n\t\t\t\tthis.battle.activeMove = oldActiveMove;\n\t\t\t}\n\t\t},\n\t\tuseMoveInner(moveOrMoveName, pokemon, options) {\n\t\t\tlet target = options?.target;\n\t\t\tlet sourceEffect = options?.sourceEffect;\n\t\t\tconst zMove = options?.zMove;\n\t\t\tconst maxMove = options?.maxMove;\n\t\t\tif (!sourceEffect && this.battle.effect.id) sourceEffect = this.battle.effect;\n\t\t\tif (sourceEffect && ['instruct', 'custapberry'].includes(sourceEffect.id)) sourceEffect = null;\n\n\t\t\tlet move = this.dex.getActiveMove(moveOrMoveName);\n\t\t\tpokemon.lastMoveUsed = move;\n\t\t\tif (move.id === 'weatherball' && zMove) {\n\t\t\t\t// Z-Weather Ball only changes types if it's used directly,\n\t\t\t\t// not if it's called by Z-Sleep Talk or something.\n\t\t\t\tthis.battle.singleEvent('ModifyType', move, null, pokemon, target, move, move);\n\t\t\t\tif (move.type !== 'Normal') sourceEffect = move;\n\t\t\t}\n\t\t\tif (zMove || (move.category !== 'Status' && sourceEffect && (sourceEffect as ActiveMove).isZ)) {\n\t\t\t\tmove = this.getActiveZMove(move, pokemon);\n\t\t\t}\n\t\t\tif (maxMove && move.category !== 'Status') {\n\t\t\t\t// Max move outcome is dependent on the move type after type modifications from ability and the move itself\n\t\t\t\tthis.battle.singleEvent('ModifyType', move, null, pokemon, target, move, move);\n\t\t\t\tthis.battle.runEvent('ModifyType', pokemon, target, move, move);\n\t\t\t}\n\t\t\tif (maxMove || (move.category !== 'Status' && sourceEffect && (sourceEffect as ActiveMove).isMax)) {\n\t\t\t\tmove = this.getActiveMaxMove(move, pokemon);\n\t\t\t}\n\n\t\t\tif (this.battle.activeMove) {\n\t\t\t\tmove.priority = this.battle.activeMove.priority;\n\t\t\t\tif (!move.hasBounced) move.pranksterBoosted = this.battle.activeMove.pranksterBoosted;\n\t\t\t}\n\t\t\tconst baseTarget = move.target;\n\t\t\tlet targetRelayVar = { target };\n\t\t\ttargetRelayVar = this.battle.runEvent('ModifyTarget', pokemon, target, move, targetRelayVar, true);\n\t\t\tif (targetRelayVar.target !== undefined) target = targetRelayVar.target;\n\t\t\tif (target === undefined) target = this.battle.getRandomTarget(pokemon, move);\n\t\t\tif (move.target === 'self' || move.target === 'allies') {\n\t\t\t\ttarget = pokemon;\n\t\t\t}\n\t\t\tif (sourceEffect) {\n\t\t\t\tmove.sourceEffect = sourceEffect.id;\n\t\t\t\tmove.ignoreAbility = (sourceEffect as ActiveMove).ignoreAbility;\n\t\t\t}\n\t\t\tlet moveResult = false;\n\n\t\t\tthis.battle.setActiveMove(move, pokemon, target);\n\n\t\t\tthis.battle.singleEvent('ModifyType', move, null, pokemon, target, move, move);\n\t\t\tthis.battle.singleEvent('ModifyMove', move, null, pokemon, target, move, move);\n\t\t\tif (baseTarget !== move.target) {\n\t\t\t\t// Target changed in ModifyMove, so we must adjust it here\n\t\t\t\t// Adjust before the next event so the correct target is passed to the\n\t\t\t\t// event\n\t\t\t\ttarget = this.battle.getRandomTarget(pokemon, move);\n\t\t\t}\n\t\t\tmove = this.battle.runEvent('ModifyType', pokemon, target, move, move);\n\t\t\tmove = this.battle.runEvent('ModifyMove', pokemon, target, move, move);\n\t\t\tif (baseTarget !== move.target) {\n\t\t\t\t// Adjust again\n\t\t\t\ttarget = this.battle.getRandomTarget(pokemon, move);\n\t\t\t}\n\t\t\tif (!move || pokemon.fainted) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet attrs = '';\n\n\t\t\tlet movename = move.name;\n\t\t\tif (move.id === 'hiddenpower') movename = 'Hidden Power';\n\t\t\tif (sourceEffect) attrs += `|[from]${sourceEffect.fullname}`;\n\t\t\tif (zMove && move.isZ === true) {\n\t\t\t\tattrs = '|[anim]' + movename + attrs;\n\t\t\t\tmovename = 'Z-' + movename;\n\t\t\t}\n\t\t\tthis.battle.addMove('move', pokemon, movename, `${target}${attrs}`);\n\n\t\t\tif (zMove) this.runZPower(move, pokemon);\n\n\t\t\tif (!target) {\n\t\t\t\tthis.battle.attrLastMove('[notarget]');\n\t\t\t\tthis.battle.add(this.battle.gen >= 5 ? '-fail' : '-notarget', pokemon);\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst { targets, pressureTargets } = pokemon.getMoveTargets(move, target);\n\t\t\tif (targets.length) {\n\t\t\t\ttarget = targets[targets.length - 1]; // in case of redirection\n\t\t\t}\n\n\t\t\t// Pursuit Clones support\n\t\t\tconst pursuitClones = ['pursuit', 'trivialpursuit', 'attackofopportunity'];\n\t\t\tconst callerMoveForPressure = sourceEffect && (sourceEffect as ActiveMove).pp ? sourceEffect as ActiveMove : null;\n\t\t\tif (!sourceEffect || callerMoveForPressure || pursuitClones.includes(sourceEffect.id)) {\n\t\t\t\tlet extraPP = 0;\n\t\t\t\tfor (const source of pressureTargets) {\n\t\t\t\t\tconst ppDrop = this.battle.runEvent('DeductPP', source, pokemon, move);\n\t\t\t\t\tif (ppDrop !== true) {\n\t\t\t\t\t\textraPP += ppDrop || 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (extraPP > 0) {\n\t\t\t\t\tpokemon.deductPP(callerMoveForPressure || moveOrMoveName, extraPP);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!this.battle.singleEvent('TryMove', move, null, pokemon, target, move) ||\n\t\t\t\t!this.battle.runEvent('TryMove', pokemon, target, move)) {\n\t\t\t\tmove.mindBlownRecoil = false;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tthis.battle.singleEvent('UseMoveMessage', move, null, pokemon, target, move);\n\n\t\t\tif (move.ignoreImmunity === undefined) {\n\t\t\t\tmove.ignoreImmunity = (move.category === 'Status');\n\t\t\t}\n\n\t\t\tif (this.battle.gen !== 4 && move.selfdestruct === 'always') {\n\t\t\t\tthis.battle.faint(pokemon, pokemon, move);\n\t\t\t}\n\n\t\t\tlet damage: number | false | undefined | '' = false;\n\t\t\tif (move.target === 'all' || move.target === 'foeSide' || move.target === 'allySide' || move.target === 'allyTeam') {\n\t\t\t\tdamage = this.tryMoveHit(targets, pokemon, move);\n\t\t\t\tif (damage === this.battle.NOT_FAIL) pokemon.moveThisTurnResult = null;\n\t\t\t\tif (damage || damage === 0 || damage === undefined) moveResult = true;\n\t\t\t} else {\n\t\t\t\tif (!targets.length) {\n\t\t\t\t\tthis.battle.attrLastMove('[notarget]');\n\t\t\t\t\tthis.battle.add(this.battle.gen >= 5 ? '-fail' : '-notarget', pokemon);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (this.battle.gen === 4 && move.selfdestruct === 'always') {\n\t\t\t\t\tthis.battle.faint(pokemon, pokemon, move);\n\t\t\t\t}\n\t\t\t\tmoveResult = this.trySpreadMoveHit(targets, pokemon, move);\n\t\t\t}\n\t\t\tif (move.selfBoost && moveResult) this.moveHit(pokemon, pokemon, move, move.selfBoost, false, true);\n\t\t\tif (!pokemon.hp) {\n\t\t\t\tthis.battle.faint(pokemon, pokemon, move);\n\t\t\t}\n\n\t\t\tif (!moveResult) {\n\t\t\t\tthis.battle.singleEvent('MoveFail', move, null, target, pokemon, move);\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\t!move.negateSecondary &&\n\t\t\t\t!(move.hasSheerForce && pokemon.hasAbility('sheerforce')) &&\n\t\t\t\t!move.flags['futuremove']\n\t\t\t) {\n\t\t\t\tconst originalHp = pokemon.hp;\n\t\t\t\tthis.battle.singleEvent('AfterMoveSecondarySelf', move, null, pokemon, target, move);\n\t\t\t\tthis.battle.runEvent('AfterMoveSecondarySelf', pokemon, target, move);\n\t\t\t\tif (pokemon && pokemon !== target && move.category !== 'Status') {\n\t\t\t\t\tif (pokemon.hp <= pokemon.maxhp / 2 && originalHp > pokemon.maxhp / 2) {\n\t\t\t\t\t\tthis.battle.runEvent('EmergencyExit', pokemon, pokemon);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t\thitStepMoveHitLoop(targets, pokemon, move) { // Temporary name\n\t\t\tlet damage: (number | boolean | undefined)[] = [];\n\t\t\tfor (const i of targets.keys()) {\n\t\t\t\tdamage[i] = 0;\n\t\t\t}\n\t\t\tmove.totalDamage = 0;\n\t\t\tpokemon.lastDamage = 0;\n\t\t\tlet targetHits = move.multihit || 1;\n\t\t\tif (Array.isArray(targetHits)) {\n\t\t\t\t// yes, it's hardcoded... meh\n\t\t\t\tif (targetHits[0] === 2 && targetHits[1] === 5) {\n\t\t\t\t\tif (this.battle.gen >= 5) {\n\t\t\t\t\t\t// 35-35-15-15 out of 100 for 2-3-4-5 hits\n\t\t\t\t\t\ttargetHits = this.battle.sample([2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5]);\n\t\t\t\t\t\tif (targetHits < 4 && pokemon.hasItem('loadeddice')) {\n\t\t\t\t\t\t\ttargetHits = 5 - this.battle.random(2);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttargetHits = this.battle.sample([2, 2, 2, 3, 3, 3, 4, 5]);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttargetHits = this.battle.random(targetHits[0], targetHits[1] + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (targetHits === 10 && pokemon.hasItem('loadeddice')) targetHits -= this.battle.random(7);\n\t\t\ttargetHits = Math.floor(targetHits);\n\t\t\tlet nullDamage = true;\n\t\t\tlet moveDamage: (number | boolean | undefined)[] = [];\n\t\t\t// There is no need to recursively check the \u00B4sleepUsable\u00B4 flag as Sleep Talk can only be used while asleep.\n\t\t\tconst isSleepUsable = move.sleepUsable || this.dex.moves.get(move.sourceEffect).sleepUsable;\n\n\t\t\tlet targetsCopy: (Pokemon | false | null)[] = targets.slice(0);\n\t\t\tlet hit: number;\n\t\t\tfor (hit = 1; hit <= targetHits; hit++) {\n\t\t\t\tif (damage.includes(false)) break;\n\t\t\t\tif (hit > 1 && pokemon.status === 'slp' && (!isSleepUsable || this.battle.gen === 4)) break;\n\t\t\t\tif (targets.every(target => !target?.hp)) break;\n\t\t\t\tmove.hit = hit;\n\t\t\t\tif (move.smartTarget && targets.length > 1) {\n\t\t\t\t\ttargetsCopy = [targets[hit - 1]];\n\t\t\t\t\tdamage = [damage[hit - 1]];\n\t\t\t\t} else {\n\t\t\t\t\ttargetsCopy = targets.slice(0);\n\t\t\t\t}\n\t\t\t\tconst target = targetsCopy[0]; // some relevant-to-single-target-moves-only things are hardcoded\n\t\t\t\tif (target && typeof move.smartTarget === 'boolean') {\n\t\t\t\t\tif (hit > 1) {\n\t\t\t\t\t\tthis.battle.addMove('-anim', pokemon, move.name, target);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.battle.retargetLastMove(target);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// like this (Triple Kick)\n\t\t\t\tif (target && move.multiaccuracy && hit > 1) {\n\t\t\t\t\tlet accuracy = move.accuracy;\n\t\t\t\t\tconst boostTable = [1, 4 / 3, 5 / 3, 2, 7 / 3, 8 / 3, 3];\n\t\t\t\t\tif (accuracy !== true) {\n\t\t\t\t\t\tif (!move.ignoreAccuracy) {\n\t\t\t\t\t\t\tconst boosts = this.battle.runEvent('ModifyBoost', pokemon, null, null, { ...pokemon.boosts });\n\t\t\t\t\t\t\tconst boost = this.battle.clampIntRange(boosts['accuracy'], -6, 6);\n\t\t\t\t\t\t\tif (boost > 0) {\n\t\t\t\t\t\t\t\taccuracy *= boostTable[boost];\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\taccuracy /= boostTable[-boost];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!move.ignoreEvasion) {\n\t\t\t\t\t\t\tconst boosts = this.battle.runEvent('ModifyBoost', target, null, null, { ...target.boosts });\n\t\t\t\t\t\t\tconst boost = this.battle.clampIntRange(boosts['evasion'], -6, 6);\n\t\t\t\t\t\t\tif (boost > 0) {\n\t\t\t\t\t\t\t\taccuracy /= boostTable[boost];\n\t\t\t\t\t\t\t} else if (boost < 0) {\n\t\t\t\t\t\t\t\taccuracy *= boostTable[-boost];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\taccuracy = this.battle.runEvent('ModifyAccuracy', target, pokemon, move, accuracy);\n\t\t\t\t\tif (!move.alwaysHit) {\n\t\t\t\t\t\taccuracy = this.battle.runEvent('Accuracy', target, pokemon, move, accuracy);\n\t\t\t\t\t\tif (accuracy !== true && !this.battle.randomChance(accuracy, 100)) break;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst moveData = move;\n\t\t\t\tif (!moveData.flags) moveData.flags = {};\n\n\t\t\t\tlet moveDamageThisHit;\n\t\t\t\t// Modifies targetsCopy (which is why it's a copy)\n\t\t\t\t[moveDamageThisHit, targetsCopy] = this.spreadMoveHit(targetsCopy, pokemon, move, moveData);\n\t\t\t\t// When Dragon Darts targets two different pokemon, targetsCopy is a length 1 array each hit\n\t\t\t\t// so spreadMoveHit returns a length 1 damage array\n\t\t\t\tif (move.smartTarget) {\n\t\t\t\t\tmoveDamage.push(...moveDamageThisHit);\n\t\t\t\t} else {\n\t\t\t\t\tmoveDamage = moveDamageThisHit;\n\t\t\t\t}\n\n\t\t\t\tif (!moveDamage.some(val => val !== false)) break;\n\t\t\t\tnullDamage = false;\n\n\t\t\t\tfor (const [i, md] of moveDamage.entries()) {\n\t\t\t\t\tif (move.smartTarget && i !== hit - 1) continue;\n\t\t\t\t\t// Damage from each hit is individually counted for the\n\t\t\t\t\t// purposes of Counter, Metal Burst, and Mirror Coat.\n\t\t\t\t\tdamage[i] = md === true || !md ? 0 : md;\n\t\t\t\t\t// Total damage dealt is accumulated for the purposes of recoil (Parental Bond).\n\t\t\t\t\tmove.totalDamage += damage[i];\n\t\t\t\t}\n\t\t\t\tif (move.mindBlownRecoil) {\n\t\t\t\t\tconst hpBeforeRecoil = pokemon.hp;\n\t\t\t\t\tthis.battle.damage(Math.round(pokemon.maxhp / 2), pokemon, pokemon, this.dex.conditions.get(move.id), true);\n\t\t\t\t\tmove.mindBlownRecoil = false;\n\t\t\t\t\tif (pokemon.hp <= pokemon.maxhp / 2 && hpBeforeRecoil > pokemon.maxhp / 2) {\n\t\t\t\t\t\tthis.battle.runEvent('EmergencyExit', pokemon, pokemon);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.battle.eachEvent('Update');\n\t\t\t\tif (!pokemon.hp && targets.length === 1) {\n\t\t\t\t\thit++; // report the correct number of hits for multihit moves\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// hit is 1 higher than the actual hit count\n\t\t\tif (hit === 1) return damage.fill(false);\n\t\t\tif (nullDamage) damage.fill(false);\n\t\t\tthis.battle.faintMessages(false, false, !pokemon.hp);\n\t\t\tif (move.multihit && typeof move.smartTarget !== 'boolean') {\n\t\t\t\tthis.battle.add('-hitcount', targets[0], hit - 1);\n\t\t\t}\n\n\t\t\tif ((move.recoil || move.id === 'chloroblast') && move.totalDamage) {\n\t\t\t\tconst hpBeforeRecoil = pokemon.hp;\n\t\t\t\tthis.battle.damage(this.calcRecoilDamage(move.totalDamage, move, pokemon), pokemon, pokemon, 'recoil');\n\t\t\t\tif (pokemon.hp <= pokemon.maxhp / 2 && hpBeforeRecoil > pokemon.maxhp / 2) {\n\t\t\t\t\tthis.battle.runEvent('EmergencyExit', pokemon, pokemon);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (move.struggleRecoil) {\n\t\t\t\tconst hpBeforeRecoil = pokemon.hp;\n\t\t\t\tlet recoilDamage;\n\t\t\t\tif (this.dex.gen >= 5) {\n\t\t\t\t\trecoilDamage = this.battle.clampIntRange(Math.round(pokemon.baseMaxhp / 4), 1);\n\t\t\t\t} else {\n\t\t\t\t\trecoilDamage = this.battle.clampIntRange(this.battle.trunc(pokemon.maxhp / 4), 1);\n\t\t\t\t}\n\t\t\t\tthis.battle.directDamage(recoilDamage, pokemon, pokemon, { id: 'strugglerecoil' } as Condition);\n\t\t\t\tif (pokemon.hp <= pokemon.maxhp / 2 && hpBeforeRecoil > pokemon.maxhp / 2) {\n\t\t\t\t\tthis.battle.runEvent('EmergencyExit', pokemon, pokemon);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// smartTarget messes up targetsCopy, but smartTarget should in theory ensure that targets will never fail, anyway\n\t\t\tif (move.smartTarget) {\n\t\t\t\ttargetsCopy = targets.slice(0);\n\t\t\t}\n\n\t\t\tfor (const [i, target] of targetsCopy.entries()) {\n\t\t\t\tif (target && pokemon !== target) {\n\t\t\t\t\ttarget.gotAttacked(move, moveDamage[i] as number | false | undefined, pokemon);\n\t\t\t\t\tif (typeof moveDamage[i] === 'number') {\n\t\t\t\t\t\ttarget.timesAttacked += move.smartTarget ? 1 : hit - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (move.ohko && !targets[0].hp) this.battle.add('-ohko');\n\n\t\t\tif (!damage.some(val => !!val || val === 0)) return damage;\n\n\t\t\tthis.battle.eachEvent('Update');\n\n\t\t\tthis.afterMoveSecondaryEvent(targetsCopy.filter(val => !!val), pokemon, move);\n\n\t\t\tif (!move.negateSecondary && !(move.hasSheerForce && pokemon.hasAbility('sheerforce'))) {\n\t\t\t\tfor (const [i, d] of damage.entries()) {\n\t\t\t\t\t// There are no multihit spread moves, so it's safe to use move.totalDamage for multihit moves\n\t\t\t\t\t// The previous check was for `move.multihit`, but that fails for Dragon Darts\n\t\t\t\t\tconst curDamage = targets.length === 1 ? move.totalDamage : d;\n\t\t\t\t\tif (typeof curDamage === 'number' && targets[i].hp) {\n\t\t\t\t\t\tconst targetHPBeforeDamage = (targets[i].hurtThisTurn || 0) + curDamage;\n\t\t\t\t\t\tif (targets[i].hp <= targets[i].maxhp / 2 && targetHPBeforeDamage > targets[i].maxhp / 2) {\n\t\t\t\t\t\t\tthis.battle.runEvent('EmergencyExit', targets[i], pokemon);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn damage;\n\t\t},\n\t\thitStepTryImmunity(targets, pokemon, move) {\n\t\t\tconst hitResults = [];\n\t\t\tfor (const [i, target] of targets.entries()) {\n\t\t\t\tif (this.battle.gen >= 6 && move.flags['powder'] && target !== pokemon && !this.dex.getImmunity('powder', target)) {\n\t\t\t\t\tthis.battle.debug('natural powder immunity');\n\t\t\t\t\tthis.battle.add('-immune', target);\n\t\t\t\t\thitResults[i] = false;\n\t\t\t\t} else if (!this.battle.singleEvent('TryImmunity', move, {}, target, pokemon, move)) {\n\t\t\t\t\tthis.battle.add('-immune', target);\n\t\t\t\t\thitResults[i] = false;\n\t\t\t\t} else if (\n\t\t\t\t\tthis.battle.gen >= 7 && move.pranksterBoosted &&\n\t\t\t\t\t// Prankster Clone immunity\n\t\t\t\t\t(pokemon.hasAbility('prankster') || pokemon.hasAbility('youkaiofthedusk') ||\n\t\t\t\t\t\tpokemon.volatiles['irpachuza'] || pokemon.hasAbility('neverendingfhunt')) &&\n\t\t\t\t\t\t!targets[i].isAlly(pokemon) && !this.dex.getImmunity('prankster', target)\n\t\t\t\t) {\n\t\t\t\t\tthis.battle.debug('natural prankster immunity');\n\t\t\t\t\tif (!target.illusion) this.battle.hint(\"Since gen 7, Dark is immune to Prankster moves.\");\n\t\t\t\t\tthis.battle.add('-immune', target);\n\t\t\t\t\thitResults[i] = false;\n\t\t\t\t} else {\n\t\t\t\t\thitResults[i] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn hitResults;\n\t\t},\n\t\tspreadMoveHit(targets, pokemon, moveOrMoveName, hitEffect, isSecondary, isSelf) {\n\t\t\t// Hardcoded for single-target purposes\n\t\t\t// (no spread moves have any kind of onTryHit handler)\n\t\t\tconst target = targets[0];\n\t\t\tlet damage: (number | boolean | undefined)[] = [];\n\t\t\tfor (const i of targets.keys()) {\n\t\t\t\tdamage[i] = true;\n\t\t\t}\n\t\t\tconst move = this.dex.getActiveMove(moveOrMoveName);\n\t\t\tlet hitResult: boolean | number | null = true;\n\t\t\tconst moveData = hitEffect || move;\n\t\t\tif (!moveData.flags) moveData.flags = {};\n\t\t\tif (move.target === 'all' && !isSelf) {\n\t\t\t\thitResult = this.battle.singleEvent('TryHitField', moveData, {}, target || null, pokemon, move);\n\t\t\t} else if ((move.target === 'foeSide' || move.target === 'allySide' || move.target === 'allyTeam') && !isSelf) {\n\t\t\t\thitResult = this.battle.singleEvent('TryHitSide', moveData, {}, target || null, pokemon, move);\n\t\t\t} else if (target) {\n\t\t\t\thitResult = this.battle.singleEvent('TryHit', moveData, {}, target, pokemon, move);\n\t\t\t}\n\t\t\tif (!hitResult) {\n\t\t\t\tif (hitResult === false) {\n\t\t\t\t\tthis.battle.add('-fail', pokemon);\n\t\t\t\t\tthis.battle.attrLastMove('[still]');\n\t\t\t\t}\n\t\t\t\treturn [[false], targets]; // single-target only\n\t\t\t}\n\n\t\t\t// 0. check for substitute\n\t\t\tif (!isSecondary && !isSelf) {\n\t\t\t\tif (move.target !== 'all' && move.target !== 'allyTeam' && move.target !== 'allySide' && move.target !== 'foeSide') {\n\t\t\t\t\tdamage = this.tryPrimaryHitEvent(damage, targets, pokemon, move, moveData, isSecondary);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const i of targets.keys()) {\n\t\t\t\tif (damage[i] === this.battle.HIT_SUBSTITUTE) {\n\t\t\t\t\tdamage[i] = true;\n\t\t\t\t\ttargets[i] = null;\n\t\t\t\t}\n\t\t\t\tif (targets[i] && isSecondary && !moveData.self) {\n\t\t\t\t\tdamage[i] = true;\n\t\t\t\t}\n\t\t\t\tif (!damage[i]) targets[i] = false;\n\t\t\t}\n\t\t\t// 1. call to this.battle.getDamage\n\t\t\tdamage = this.getSpreadDamage(damage, targets, pokemon, move, moveData, isSecondary, isSelf);\n\n\t\t\tfor (const i of targets.keys()) {\n\t\t\t\tif (damage[i] === false) targets[i] = false;\n\t\t\t}\n\n\t\t\t// 2. call to this.battle.spreadDamage\n\t\t\tdamage = this.battle.spreadDamage(damage, targets, pokemon, move);\n\n\t\t\tfor (const i of targets.keys()) {\n\t\t\t\tif (damage[i] === false) targets[i] = false;\n\t\t\t}\n\n\t\t\t// 3. onHit event happens here\n\t\t\tdamage = this.runMoveEffects(damage, targets, pokemon, move, moveData, isSecondary, isSelf);\n\n\t\t\tfor (const i of targets.keys()) {\n\t\t\t\tif (!damage[i] && damage[i] !== 0) targets[i] = false;\n\t\t\t}\n\n\t\t\t// steps 4 and 5 can mess with this.battle.activeTarget, which needs to be preserved for Dancer\n\t\t\tconst activeTarget = this.battle.activeTarget;\n\n\t\t\t// 4. self drops (start checking for targets[i] === false here)\n\t\t\tif (moveData.self && !move.selfDropped) this.selfDrops(targets, pokemon, move, moveData, isSecondary);\n\n\t\t\t// 5. secondary effects\n\t\t\tif (moveData.secondaries) this.secondaries(targets, pokemon, move, moveData, isSelf);\n\n\t\t\tthis.battle.activeTarget = activeTarget;\n\n\t\t\t// 6. force switch\n\t\t\tif (moveData.forceSwitch) damage = this.forceSwitch(damage, targets, pokemon, move);\n\n\t\t\tfor (const i of targets.keys()) {\n\t\t\t\tif (!damage[i] && damage[i] !== 0) targets[i] = false;\n\t\t\t}\n\n\t\t\tconst damagedTargets: Pokemon[] = [];\n\t\t\tconst damagedDamage = [];\n\t\t\tfor (const [i, t] of targets.entries()) {\n\t\t\t\tif (typeof damage[i] === 'number' && t) {\n\t\t\t\t\tdamagedTargets.push(t);\n\t\t\t\t\tdamagedDamage.push(damage[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst pokemonOriginalHP = pokemon.hp;\n\t\t\tif (damagedDamage.length && !isSecondary && !isSelf) {\n\t\t\t\tthis.battle.runEvent('DamagingHit', damagedTargets, pokemon, move, damagedDamage);\n\t\t\t\tif (moveData.onAfterHit) {\n\t\t\t\t\tfor (const t of damagedTargets) {\n\t\t\t\t\t\tthis.battle.singleEvent('AfterHit', moveData, {}, t, pokemon, move);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (pokemon.hp && pokemon.hp <= pokemon.maxhp / 2 && pokemonOriginalHP > pokemon.maxhp / 2) {\n\t\t\t\t\tthis.battle.runEvent('EmergencyExit', pokemon);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn [damage, targets];\n\t\t},\n\t},\n\tpokemon: {\n\t\tisGrounded(negateImmunity) {\n\t\t\tif ('gravity' in this.battle.field.pseudoWeather) return true;\n\t\t\tif ('ingrain' in this.volatiles && this.battle.gen >= 4) return true;\n\t\t\tif ('smackdown' in this.volatiles) return true;\n\t\t\tconst item = (this.ignoringItem() ? '' : this.item);\n\t\t\tif (item === 'ironball') return true;\n\t\t\t// If a Fire/Flying type uses Burn Up and Roost, it becomes ???/Flying-type, but it's still grounded.\n\t\t\tif (!negateImmunity && this.hasType('Flying') && !(this.hasType('???') && 'roost' in this.volatiles)) return false;\n\t\t\tif (this.hasAbility('levitate') && !this.battle.suppressingAbility(this)) return null;\n\t\t\tif ('magnetrise' in this.volatiles) return false;\n\t\t\tif ('riseabove' in this.volatiles) return false;\n\t\t\tif ('telekinesis' in this.volatiles) return false;\n\t\t\treturn item !== 'airballoon';\n\t\t},\n\t\teffectiveWeather() {\n\t\t\tconst weather = this.battle.field.effectiveWeather();\n\t\t\tswitch (weather) {\n\t\t\tcase 'sunnyday':\n\t\t\tcase 'raindance':\n\t\t\tcase 'desolateland':\n\t\t\tcase 'primordialsea':\n\t\t\tcase 'stormsurge':\n\t\t\t\tif (this.hasItem('utilityumbrella')) return '';\n\t\t\t}\n\t\t\treturn weather;\n\t\t},\n\t\tgetMoveTargets(move, target) {\n\t\t\tlet targets: Pokemon[] = [];\n\n\t\t\tswitch (move.target) {\n\t\t\tcase 'all':\n\t\t\tcase 'foeSide':\n\t\t\tcase 'allySide':\n\t\t\tcase 'allyTeam':\n\t\t\t\tif (!move.target.startsWith('foe')) {\n\t\t\t\t\ttargets.push(...this.alliesAndSelf());\n\t\t\t\t}\n\t\t\t\tif (!move.target.startsWith('ally')) {\n\t\t\t\t\ttargets.push(...this.foes(true));\n\t\t\t\t}\n\t\t\t\tif (targets.length && !targets.includes(target)) {\n\t\t\t\t\tthis.battle.retargetLastMove(targets[targets.length - 1]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'allAdjacent':\n\t\t\t\ttargets.push(...this.adjacentAllies());\n\t\t\t\t// falls through\n\t\t\tcase 'allAdjacentFoes':\n\t\t\t\ttargets.push(...this.adjacentFoes());\n\t\t\t\tif (targets.length && !targets.includes(target)) {\n\t\t\t\t\tthis.battle.retargetLastMove(targets[targets.length - 1]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'allies':\n\t\t\t\ttargets = this.alliesAndSelf();\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tconst selectedTarget = target;\n\t\t\t\tif (!target || (target.fainted && !target.isAlly(this)) && this.battle.gameType !== 'freeforall') {\n\t\t\t\t\t// If a targeted foe faints, the move is retargeted\n\t\t\t\t\tconst possibleTarget = this.battle.getRandomTarget(this, move);\n\t\t\t\t\tif (!possibleTarget) return { targets: [], pressureTargets: [] };\n\t\t\t\t\ttarget = possibleTarget;\n\t\t\t\t}\n\t\t\t\tif (this.battle.activePerHalf > 1 && !move.tracksTarget) {\n\t\t\t\t\tconst isCharging = move.flags['charge'] && !this.volatiles['twoturnmove'] &&\n\t\t\t\t\t\t!(move.id.startsWith('solarb') && ['sunnyday', 'desolateland'].includes(this.effectiveWeather())) &&\n\t\t\t\t\t\t!(move.id === 'fruitfullongbow' && ['sunnyday', 'desolateland'].includes(this.effectiveWeather())) &&\n\t\t\t\t\t\t!(move.id === 'praisethemoon' && this.battle.field.getPseudoWeather('gravity')) &&\n\t\t\t\t\t\t!(move.id === 'electroshot' && ['stormsurge', 'raindance', 'primordialsea'].includes(this.effectiveWeather())) &&\n\t\t\t\t\t\t!(this.hasItem('powerherb') && move.id !== 'skydrop');\n\t\t\t\t\tif (!isCharging) {\n\t\t\t\t\t\ttarget = this.battle.priorityEvent('RedirectTarget', this, this, move, target);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (move.smartTarget) {\n\t\t\t\t\ttargets = this.getSmartTargets(target, move);\n\t\t\t\t\ttarget = targets[0];\n\t\t\t\t} else {\n\t\t\t\t\ttargets.push(target);\n\t\t\t\t}\n\t\t\t\tif (target.fainted && !move.flags['futuremove']) {\n\t\t\t\t\treturn { targets: [], pressureTargets: [] };\n\t\t\t\t}\n\t\t\t\tif (selectedTarget !== target) {\n\t\t\t\t\tthis.battle.retargetLastMove(target);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Resolve apparent targets for Pressure.\n\t\t\tlet pressureTargets = targets;\n\t\t\tif (move.target === 'foeSide') {\n\t\t\t\tpressureTargets = [];\n\t\t\t}\n\t\t\tif (move.flags['mustpressure']) {\n\t\t\t\tpressureTargets = this.foes();\n\t\t\t}\n\n\t\t\treturn { targets, pressureTargets };\n\t\t},\n\t},\n\tside: {\n\t\tgetChoice() {\n\t\t\tif (this.choice.actions.length > 1 && this.choice.actions.every(action => action.choice === 'team')) {\n\t\t\t\treturn `team ` + this.choice.actions.map(action => action.pokemon!.position + 1).join(', ');\n\t\t\t}\n\t\t\treturn this.choice.actions.map(action => {\n\t\t\t\tswitch (action.choice) {\n\t\t\t\tcase 'move':\n\t\t\t\t\tlet details = ``;\n\t\t\t\t\tif (action.targetLoc && this.active.length > 1) details += ` ${action.targetLoc > 0 ? '+' : ''}${action.targetLoc}`;\n\t\t\t\t\tif (action.mega) details += (action.pokemon!.item === 'ultranecroziumz' ? ` ultra` : ` mega`);\n\t\t\t\t\tif (action.zmove) details += ` zmove`;\n\t\t\t\t\tif (action.maxMove) details += ` dynamax`;\n\t\t\t\t\tif (action.terastallize) details += ` terastallize`;\n\t\t\t\t\treturn `move ${action.moveid}${details}`;\n\t\t\t\tcase 'switch':\n\t\t\t\tcase 'instaswitch':\n\t\t\t\tcase 'revivalblessing':\n\t\t\t\t// @ts-expect-error custom status falls through\n\t\t\t\tcase 'scapegoat':\n\t\t\t\t\treturn `switch ${action.target!.position + 1}`;\n\t\t\t\tcase 'team':\n\t\t\t\t\treturn `team ${action.pokemon!.position + 1}`;\n\t\t\t\tdefault:\n\t\t\t\t\treturn action.choice;\n\t\t\t\t}\n\t\t\t}).join(', ');\n\t\t},\n\n\t\tchooseSwitch(slotText) {\n\t\t\tif (this.requestState !== 'move' && this.requestState !== 'switch') {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You need a ${this.requestState} response`);\n\t\t\t}\n\t\t\tconst index = this.getChoiceIndex();\n\t\t\tif (index >= this.active.length) {\n\t\t\t\tif (this.requestState === 'switch') {\n\t\t\t\t\treturn this.emitChoiceError(`Can't switch: You sent more switches than Pok\u00E9mon that need to switch`);\n\t\t\t\t}\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You sent more choices than unfainted Pok\u00E9mon`);\n\t\t\t}\n\t\t\tconst pokemon = this.active[index];\n\t\t\tlet slot;\n\t\t\tif (!slotText) {\n\t\t\t\tif (this.requestState !== 'switch') {\n\t\t\t\t\treturn this.emitChoiceError(`Can't switch: You need to select a Pok\u00E9mon to switch in`);\n\t\t\t\t}\n\t\t\t\tif (this.slotConditions[pokemon.position]['revivalblessing']) {\n\t\t\t\t\tslot = 0;\n\t\t\t\t\twhile (!this.pokemon[slot].fainted) slot++;\n\t\t\t\t} else {\n\t\t\t\t\tif (!this.choice.forcedSwitchesLeft) return this.choosePass();\n\t\t\t\t\tslot = this.active.length;\n\t\t\t\t\twhile (this.choice.switchIns.has(slot) || this.pokemon[slot].fainted) slot++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tslot = parseInt(slotText) - 1;\n\t\t\t}\n\t\t\tif (isNaN(slot) || slot < 0) {\n\t\t\t\t// maybe it's a name/species id!\n\t\t\t\tslot = -1;\n\t\t\t\tfor (const [i, mon] of this.pokemon.entries()) {\n\t\t\t\t\tif (slotText!.toLowerCase() === mon.name.toLowerCase() || toID(slotText) === mon.species.id) {\n\t\t\t\t\t\tslot = i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (slot < 0) {\n\t\t\t\t\treturn this.emitChoiceError(`Can't switch: You do not have a Pok\u00E9mon named \"${slotText}\" to switch to`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (slot >= this.pokemon.length) {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You do not have a Pok\u00E9mon in slot ${slot + 1} to switch to`);\n\t\t\t} else if (slot < this.active.length && !this.slotConditions[pokemon.position]['revivalblessing']) {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You can't switch to an active Pok\u00E9mon`);\n\t\t\t} else if (this.choice.switchIns.has(slot)) {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: The Pok\u00E9mon in slot ${slot + 1} can only switch in once`);\n\t\t\t}\n\t\t\tconst targetPokemon = this.pokemon[slot];\n\n\t\t\tif (this.slotConditions[pokemon.position]['revivalblessing']) {\n\t\t\t\tif (!targetPokemon.fainted) {\n\t\t\t\t\treturn this.emitChoiceError(`Can't switch: You have to pass to a fainted Pok\u00E9mon`);\n\t\t\t\t}\n\t\t\t\t// Should always subtract, but stop at 0 to prevent errors.\n\t\t\t\tthis.choice.forcedSwitchesLeft = this.battle.clampIntRange(this.choice.forcedSwitchesLeft - 1, 0);\n\t\t\t\tpokemon.switchFlag = false;\n\t\t\t\tthis.choice.actions.push({\n\t\t\t\t\tchoice: 'revivalblessing',\n\t\t\t\t\tpokemon,\n\t\t\t\t\ttarget: targetPokemon,\n\t\t\t\t} as ChosenAction);\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tif (targetPokemon.fainted) {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You can't switch to a fainted Pok\u00E9mon`);\n\t\t\t}\n\n\t\t\tif (this.slotConditions[pokemon.position]['scapegoat']) {\n\t\t\t\t// Should always subtract, but stop at 0 to prevent errors.\n\t\t\t\tthis.choice.forcedSwitchesLeft = this.battle.clampIntRange(this.choice.forcedSwitchesLeft - 1, 0);\n\t\t\t\tpokemon.switchFlag = false;\n\t\t\t\t// @ts-expect-error custom request\n\t\t\t\tthis.choice.actions.push({\n\t\t\t\t\tchoice: 'scapegoat',\n\t\t\t\t\tpokemon,\n\t\t\t\t\ttarget: targetPokemon,\n\t\t\t\t} as ChosenAction);\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tif (this.requestState === 'move') {\n\t\t\t\tif (pokemon.trapped) {\n\t\t\t\t\tconst includeRequest = this.updateRequestForPokemon(pokemon, req => {\n\t\t\t\t\t\tlet updated = false;\n\t\t\t\t\t\tif (req.maybeTrapped) {\n\t\t\t\t\t\t\tdelete req.maybeTrapped;\n\t\t\t\t\t\t\tupdated = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!req.trapped) {\n\t\t\t\t\t\t\treq.trapped = true;\n\t\t\t\t\t\t\tupdated = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn updated;\n\t\t\t\t\t});\n\t\t\t\t\tconst status = this.emitChoiceError(`Can't switch: The active Pok\u00E9mon is trapped`, includeRequest);\n\t\t\t\t\tif (includeRequest) this.emitRequest(this.activeRequest!);\n\t\t\t\t\treturn status;\n\t\t\t\t} else if (pokemon.maybeTrapped) {\n\t\t\t\t\tthis.choice.cantUndo = this.choice.cantUndo || pokemon.isLastActive();\n\t\t\t\t}\n\t\t\t} else if (this.requestState === 'switch') {\n\t\t\t\tif (!this.choice.forcedSwitchesLeft) {\n\t\t\t\t\tthrow new Error(`Player somehow switched too many Pokemon`);\n\t\t\t\t}\n\t\t\t\tthis.choice.forcedSwitchesLeft--;\n\t\t\t}\n\n\t\t\tthis.choice.switchIns.add(slot);\n\n\t\t\tthis.choice.actions.push({\n\t\t\t\tchoice: (this.requestState === 'switch' ? 'instaswitch' : 'switch'),\n\t\t\t\tpokemon,\n\t\t\t\ttarget: targetPokemon,\n\t\t\t} as ChosenAction);\n\n\t\t\treturn true;\n\t\t},\n\t},\n\tqueue: {\n\t\tresolveAction(action, midTurn) {\n\t\t\tif (!action) throw new Error(`Action not passed to resolveAction`);\n\t\t\tif (action.choice === 'pass') return [];\n\t\t\tconst actions = [action];\n\n\t\t\tif (!action.side && action.pokemon) action.side = action.pokemon.side;\n\t\t\tif (!action.move && action.moveid) action.move = this.battle.dex.getActiveMove(action.moveid);\n\t\t\tif (!action.order) {\n\t\t\t\tconst orders: { [choice: string]: number } = {\n\t\t\t\t\tteam: 1,\n\t\t\t\t\tstart: 2,\n\t\t\t\t\tinstaswitch: 3,\n\t\t\t\t\tbeforeTurn: 4,\n\t\t\t\t\tbeforeTurnMove: 5,\n\t\t\t\t\trevivalblessing: 6,\n\t\t\t\t\tscapegoat: 7,\n\n\t\t\t\t\trunUnnerve: 100,\n\t\t\t\t\trunSwitch: 101,\n\t\t\t\t\t// runPrimal: 102,\n\t\t\t\t\tswitch: 103,\n\t\t\t\t\tmegaEvo: 104,\n\t\t\t\t\trunDynamax: 105,\n\t\t\t\t\tterastallize: 106,\n\t\t\t\t\tpriorityChargeMove: 107,\n\n\t\t\t\t\tshift: 200,\n\t\t\t\t\t// default is 200 (for moves)\n\n\t\t\t\t\tresidual: 300,\n\t\t\t\t};\n\t\t\t\tif (action.choice in orders) {\n\t\t\t\t\taction.order = orders[action.choice];\n\t\t\t\t} else {\n\t\t\t\t\taction.order = 200;\n\t\t\t\t\tif (!['move', 'event'].includes(action.choice)) {\n\t\t\t\t\t\tthrow new Error(`Unexpected orderless action ${action.choice}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!midTurn) {\n\t\t\t\tif (action.choice === 'move') {\n\t\t\t\t\tif (!action.maxMove && !action.zmove && action.move.beforeTurnCallback) {\n\t\t\t\t\t\tactions.unshift(...this.resolveAction({\n\t\t\t\t\t\t\tchoice: 'beforeTurnMove', pokemon: action.pokemon, move: action.move, targetLoc: action.targetLoc,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tif (action.mega && !action.pokemon.isSkyDropped()) {\n\t\t\t\t\t\tactions.unshift(...this.resolveAction({\n\t\t\t\t\t\t\tchoice: 'megaEvo',\n\t\t\t\t\t\t\tpokemon: action.pokemon,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tif (action.terastallize && !action.pokemon.terastallized) {\n\t\t\t\t\t\tactions.unshift(...this.resolveAction({\n\t\t\t\t\t\t\tchoice: 'terastallize',\n\t\t\t\t\t\t\tpokemon: action.pokemon,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tif (action.maxMove && !action.pokemon.volatiles['dynamax']) {\n\t\t\t\t\t\tactions.unshift(...this.resolveAction({\n\t\t\t\t\t\t\tchoice: 'runDynamax',\n\t\t\t\t\t\t\tpokemon: action.pokemon,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tif (!action.maxMove && !action.zmove && action.move.priorityChargeCallback) {\n\t\t\t\t\t\tactions.unshift(...this.resolveAction({\n\t\t\t\t\t\t\tchoice: 'priorityChargeMove',\n\t\t\t\t\t\t\tpokemon: action.pokemon,\n\t\t\t\t\t\t\tmove: action.move,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\taction.fractionalPriority = this.battle.runEvent('FractionalPriority', action.pokemon, null, action.move, 0);\n\t\t\t\t} else if (['switch', 'instaswitch'].includes(action.choice)) {\n\t\t\t\t\tif (typeof action.pokemon.switchFlag === 'string') {\n\t\t\t\t\t\taction.sourceEffect = this.battle.dex.moves.get(action.pokemon.switchFlag as ID) as any;\n\t\t\t\t\t}\n\t\t\t\t\taction.pokemon.switchFlag = false;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst deferPriority = this.battle.gen === 7 && action.mega && action.mega !== 'done';\n\t\t\tif (action.move) {\n\t\t\t\tlet target = null;\n\t\t\t\taction.move = this.battle.dex.getActiveMove(action.move);\n\n\t\t\t\tif (!action.targetLoc) {\n\t\t\t\t\ttarget = this.battle.getRandomTarget(action.pokemon, action.move);\n\t\t\t\t\t// TODO: what actually happens here?\n\t\t\t\t\tif (target) action.targetLoc = action.pokemon.getLocOf(target);\n\t\t\t\t}\n\t\t\t\taction.originalTarget = action.pokemon.getAtLoc(action.targetLoc);\n\t\t\t}\n\t\t\tif (!deferPriority) this.battle.getActionSpeed(action);\n\t\t\treturn actions as any;\n\t\t},\n\t},\n};\n"],
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAmB;AACnB,sBAAqB;AAKrB,MAAM,aAA2C,CAAC;AAClD,MAAM,oBAAgB,eAAG,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,IAAI;AAC/E,WAAW,OAAO,eAAe;AAChC,MAAI,KAAC,sBAAK,GAAG;AAAG;AAEhB,QAAM,QAAQ,IAAI,MAAM,GAAG;AAC3B,MAAI,MAAM,SAAS;AAAG,UAAM,IAAI,MAAM,2CAA2C;AACjF,iBAAW,sBAAK,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,KAAK,KAAK;AACjD;AAEA,MAAM,WAA+D,CAAC;AAK/D,SAAS,YAAY,MAAc,MAAc;AACvD,QAAM,aAAS,sBAAK,IAAI;AACxB,QAAM,aAAS,sBAAK,IAAI;AACxB,MAAI,SAAS,MAAM;AAAG,WAAO,SAAS,MAAM,EAAE,MAAM,KAAK;AACzD,QAAM,YAAmB,KAAK,UAAM,eAAG,uBAAuB,EAAE,iBAAiB,KAAK,IAAI;AAC1F,QAAM,WAAW,UAAU,KAAK,WAAK,sBAAK,EAAE,KAAK,MAAM,MAAM;AAC7D,MAAI,CAAC;AAAU,WAAO;AACtB,WAAS,MAAM,IAAI,SAAS;AAC5B,SAAO,SAAS,MAAM,EAAE,MAAM,KAAK;AACpC;AAEO,SAAS,QAAQ,MAAsB;AAC7C,QAAM,aAAS,sBAAK,IAAI;AACxB,MAAI,CAAC;AAAQ,UAAM,IAAI,MAAM,qCAAqC;AAElE,MAAI,QAAQ,WAAW,MAAM,KAAK;AAClC,MAAI,SAAS;AAAW,Y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