{ "version": 3, "sources": ["../../sim/side.ts"], "sourcesContent": ["/**\n * Simulator Side\n * Pokemon Showdown - http://pokemonshowdown.com/\n *\n * There's a lot of ambiguity between the terms \"player\", \"side\", \"team\",\n * and \"half-field\", which I'll try to explain here:\n *\n * These terms usually all mean the same thing. The exceptions are:\n *\n * - Multi-battle: there are 2 half-fields, 2 teams, 4 sides\n *\n * - Free-for-all: there are 2 half-fields, 4 teams, 4 sides\n *\n * \"Half-field\" is usually abbreviated to \"half\".\n *\n * Function naming will be very careful about which term to use. Pay attention\n * if it's relevant to your code.\n *\n * @license MIT\n */\n\nimport { Utils } from '../lib/utils';\nimport type { RequestState } from './battle';\nimport { Pokemon, type EffectState } from './pokemon';\nimport { State } from './state';\nimport { toID } from './dex';\n\n/** A single action that can be chosen. Choices will have one Action for each pokemon. */\nexport interface ChosenAction {\n\tchoice: 'move' | 'switch' | 'instaswitch' | 'revivalblessing' | 'team' | 'shift' | 'pass';// action type\n\tpokemon?: Pokemon; // the pokemon doing the action\n\ttargetLoc?: number; // relative location of the target to pokemon (move action only)\n\tmoveid: string; // a move to use (move action only)\n\tmove?: ActiveMove; // the active move corresponding to moveid (move action only)\n\ttarget?: Pokemon; // the target of the action\n\tindex?: number; // the chosen index in Team Preview\n\tside?: Side; // the action's side\n\tmega?: boolean | null; // true if megaing or ultra bursting\n\tmegax?: boolean | null; // true if megaing x\n\tmegay?: boolean | null; // true if megaing y\n\tzmove?: string; // if zmoving, the name of the zmove\n\tmaxMove?: string; // if dynamaxed, the name of the max move\n\tterastallize?: string; // if terastallizing, tera type\n\tpriority?: number; // priority of the action\n}\n\n/** One single turn's choice for one single player. */\nexport interface Choice {\n\tcantUndo: boolean; // true if the choice can't be cancelled because of the maybeTrapped issue\n\terror: string; // contains error text in the case of a choice error\n\tactions: ChosenAction[]; // array of chosen actions\n\tforcedSwitchesLeft: number; // number of switches left that need to be performed\n\tforcedPassesLeft: number; // number of passes left that need to be performed\n\tswitchIns: Set; // indexes of pokemon chosen to switch in\n\tzMove: boolean; // true if a Z-move has already been selected\n\tmega: boolean; // true if a mega evolution has already been selected\n\tultra: boolean; // true if an ultra burst has already been selected\n\tdynamax: boolean; // true if a dynamax has already been selected\n\tterastallize: boolean; // true if a terastallization has already been inputted\n}\n\nexport interface PokemonSwitchRequestData {\n\t/**\n\t * `` `${sideid}: ${name}` ``\n\t * @see {Pokemon#fullname}\n\t */\n\tident: string;\n\t/**\n\t * Details string.\n\t * @see {Pokemon#details}\n\t */\n\tdetails: string;\n\tcondition: string;\n\tactive: boolean;\n\tstats: StatsExceptHPTable;\n\t/**\n\t * Move IDs for choosable moves. Also includes Hidden Power Type, Frustration/Return power.\n\t */\n\tmoves: ID[];\n\t/** Permanent ability (the one applied on switch-in). */\n\tbaseAbility: ID;\n\titem: ID;\n\tpokeball: ID;\n\t/** Current ability. Only sent in Gen 7+. */\n\tability?: ID;\n\t/** @see https://dex.pokemonshowdown.com/abilities/commander */\n\tcommanding?: boolean;\n\t/** @see https://dex.pokemonshowdown.com/moves/revivalblessing */\n\treviving?: boolean;\n\tteraType?: string;\n\tterastallized?: string;\n}\nexport interface PokemonMoveRequestData {\n\tmoves: { move: string, id: ID, target?: string, disabled?: string | boolean }[];\n\tmaybeDisabled?: boolean;\n\ttrapped?: boolean;\n\tmaybeTrapped?: boolean;\n\tcanMegaEvo?: boolean;\n\tcanMegaEvoX?: boolean;\n\tcanMegaEvoY?: boolean;\n\tcanUltraBurst?: boolean;\n\tcanZMove?: AnyObject | null;\n\tcanDynamax?: boolean;\n\tmaxMoves?: DynamaxOptions;\n\tcanTerastallize?: string;\n}\nexport interface DynamaxOptions {\n\tmaxMoves: ({ move: string, target: MoveTarget, disabled?: boolean })[];\n\tgigantamax?: string;\n}\nexport interface SideRequestData {\n\tname: string;\n\t/** Side ID (`p1`, `p2`, `p3`, or `p4`), not the ID of the side's name. */\n\tid: SideID;\n\tpokemon: PokemonSwitchRequestData[];\n\tnoCancel?: boolean;\n}\nexport interface SwitchRequest {\n\twait?: undefined;\n\tteamPreview?: undefined;\n\tforceSwitch: boolean[];\n\tside: SideRequestData;\n\tnoCancel?: boolean;\n}\nexport interface TeamPreviewRequest {\n\twait?: undefined;\n\tteamPreview: true;\n\tforceSwitch?: undefined;\n\tmaxChosenTeamSize?: number;\n\tside: SideRequestData;\n\tnoCancel?: boolean;\n}\nexport interface MoveRequest {\n\twait?: undefined;\n\tteamPreview?: undefined;\n\tforceSwitch?: undefined;\n\tactive: PokemonMoveRequestData[];\n\tside: SideRequestData;\n\tally?: SideRequestData;\n\tnoCancel?: boolean;\n}\nexport interface WaitRequest {\n\twait: true;\n\tteamPreview?: undefined;\n\tforceSwitch?: undefined;\n\tside: SideRequestData;\n\tnoCancel?: boolean;\n}\nexport type ChoiceRequest = SwitchRequest | TeamPreviewRequest | MoveRequest | WaitRequest;\n\nexport class Side {\n\treadonly battle: Battle;\n\treadonly id: SideID;\n\t/** Index in `battle.sides`: `battle.sides[side.n] === side` */\n\treadonly n: number;\n\n\tname: string;\n\tavatar: string;\n\tfoe: Side = null!; // set in battle.start()\n\t/** Only exists in multi battle, for the allied side */\n\tallySide: Side | null = null; // set in battle.start()\n\tteam: PokemonSet[];\n\tpokemon: Pokemon[];\n\tactive: Pokemon[];\n\n\tpokemonLeft: number;\n\tzMoveUsed: boolean;\n\t/**\n\t * This will be true in any gen before 8 or if the player (or their battle partner) has dynamaxed once already\n\t *\n\t * Use Side.canDynamaxNow() to check if a side can dynamax instead of this property because only one\n\t * player per team can dynamax on any given turn of a gen 8 Multi Battle.\n\t */\n\tdynamaxUsed: boolean;\n\n\tfaintedLastTurn: Pokemon | null;\n\tfaintedThisTurn: Pokemon | null;\n\ttotalFainted: number;\n\t/** only used by Gen 1 Counter */\n\tlastSelectedMove: ID = '';\n\n\t/** these point to the same object as the ally's, in multi battles */\n\tsideConditions: { [id: string]: EffectState };\n\tslotConditions: { [id: string]: EffectState }[];\n\n\tactiveRequest: ChoiceRequest | null;\n\tchoice: Choice;\n\n\t/**\n\t * In gen 1, all lastMove stuff is tracked on Side rather than Pokemon\n\t * (this is for Counter and Mirror Move)\n\t * This is also used for checking Self-KO clause in Pokemon Stadium 2.\n\t */\n\tlastMove: Move | null;\n\n\tconstructor(name: string, battle: Battle, sideNum: number, team: PokemonSet[]) {\n\t\tconst sideScripts = battle.dex.data.Scripts.side;\n\t\tif (sideScripts) Object.assign(this, sideScripts);\n\n\t\tthis.battle = battle;\n\t\tif (this.battle.format.side) Object.assign(this, this.battle.format.side);\n\t\tthis.id = ['p1', 'p2', 'p3', 'p4'][sideNum] as SideID;\n\t\tthis.n = sideNum;\n\n\t\tthis.name = name;\n\t\tthis.avatar = '';\n\n\t\tthis.team = team;\n\t\tthis.pokemon = [];\n\t\tfor (const set of this.team) {\n\t\t\t// console.log(\"NEW POKEMON: \" + (this.team[i] ? this.team[i].name : '[unidentified]'));\n\t\t\tthis.addPokemon(set);\n\t\t}\n\n\t\tswitch (this.battle.gameType) {\n\t\tcase 'doubles':\n\t\t\tthis.active = [null!, null!];\n\t\t\tbreak;\n\t\tcase 'triples': case 'rotation':\n\t\t\tthis.active = [null!, null!, null!];\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthis.active = [null!];\n\t\t}\n\n\t\tthis.pokemonLeft = this.pokemon.length;\n\t\tthis.faintedLastTurn = null;\n\t\tthis.faintedThisTurn = null;\n\t\tthis.totalFainted = 0;\n\t\tthis.zMoveUsed = false;\n\t\tthis.dynamaxUsed = this.battle.gen !== 8;\n\n\t\tthis.sideConditions = {};\n\t\tthis.slotConditions = [];\n\t\t// Array#fill doesn't work for this\n\t\tfor (let i = 0; i < this.active.length; i++) this.slotConditions[i] = {};\n\n\t\tthis.activeRequest = null;\n\t\tthis.choice = {\n\t\t\tcantUndo: false,\n\t\t\terror: ``,\n\t\t\tactions: [],\n\t\t\tforcedSwitchesLeft: 0,\n\t\t\tforcedPassesLeft: 0,\n\t\t\tswitchIns: new Set(),\n\t\t\tzMove: false,\n\t\t\tmega: false,\n\t\t\tultra: false,\n\t\t\tdynamax: false,\n\t\t\tterastallize: false,\n\t\t};\n\n\t\t// old-gens\n\t\tthis.lastMove = null;\n\t}\n\n\ttoJSON(): AnyObject {\n\t\treturn State.serializeSide(this);\n\t}\n\n\tget requestState(): RequestState {\n\t\tif (!this.activeRequest || this.activeRequest.wait) return '';\n\t\tif (this.activeRequest.teamPreview) return 'teampreview';\n\t\tif (this.activeRequest.forceSwitch) return 'switch';\n\t\treturn 'move';\n\t}\n\n\taddPokemon(set: PokemonSet) {\n\t\tif (this.pokemon.length >= 24) return null;\n\t\tconst newPokemon = new Pokemon(set, this);\n\t\tnewPokemon.position = this.pokemon.length;\n\t\tthis.pokemon.push(newPokemon);\n\t\tthis.pokemonLeft++;\n\t\treturn newPokemon;\n\t}\n\n\tcanDynamaxNow(): boolean {\n\t\tif (this.battle.gen !== 8) return false;\n\t\t// In multi battles, players on a team are alternatingly given the option to dynamax each turn\n\t\t// On turn 1, the players on their team's respective left have the first chance (p1 and p2)\n\t\tif (this.battle.gameType === 'multi' && this.battle.turn % 2 !== [1, 1, 0, 0][this.n]) return false;\n\t\t// if (this.battle.gameType === 'multitriples' && this.battle.turn % 3 !== [1, 1, 2, 2, 0, 0][this.side.n]) {\n\t\t//\t\treturn false;\n\t\t// }\n\t\treturn !this.dynamaxUsed;\n\t}\n\n\t/** convert a Choice into a choice string */\n\tgetChoice() {\n\t\tif (this.choice.actions.length > 1 && this.choice.actions.every(action => action.choice === 'team')) {\n\t\t\treturn `team ` + this.choice.actions.map(action => action.pokemon!.position + 1).join(', ');\n\t\t}\n\t\treturn this.choice.actions.map(action => {\n\t\t\tswitch (action.choice) {\n\t\t\tcase 'move':\n\t\t\t\tlet details = ``;\n\t\t\t\tif (action.targetLoc && this.active.length > 1) details += ` ${action.targetLoc > 0 ? '+' : ''}${action.targetLoc}`;\n\t\t\t\tif (action.mega) details += (action.pokemon!.item === 'ultranecroziumz' ? ` ultra` : ` mega`);\n\t\t\t\tif (action.zmove) details += ` zmove`;\n\t\t\t\tif (action.maxMove) details += ` dynamax`;\n\t\t\t\tif (action.terastallize) details += ` terastallize`;\n\t\t\t\treturn `move ${action.moveid}${details}`;\n\t\t\tcase 'switch':\n\t\t\tcase 'instaswitch':\n\t\t\tcase 'revivalblessing':\n\t\t\t\treturn `switch ${action.target!.position + 1}`;\n\t\t\tcase 'team':\n\t\t\t\treturn `team ${action.pokemon!.position + 1}`;\n\t\t\tdefault:\n\t\t\t\treturn action.choice;\n\t\t\t}\n\t\t}).join(', ');\n\t}\n\n\ttoString() {\n\t\treturn `${this.id}: ${this.name}`;\n\t}\n\n\tgetRequestData(forAlly?: boolean): SideRequestData {\n\t\tconst data: SideRequestData = {\n\t\t\tname: this.name,\n\t\t\tid: this.id,\n\t\t\tpokemon: [] as PokemonSwitchRequestData[],\n\t\t};\n\t\tfor (const pokemon of this.pokemon) {\n\t\t\tdata.pokemon.push(pokemon.getSwitchRequestData(forAlly));\n\t\t}\n\t\treturn data;\n\t}\n\n\trandomFoe() {\n\t\tconst actives = this.foes();\n\t\tif (!actives.length) return null;\n\t\treturn this.battle.sample(actives);\n\t}\n\n\t/** Intended as a way to iterate through all foe side conditions - do not use for anything else. */\n\tfoeSidesWithConditions() {\n\t\tif (this.battle.gameType === 'freeforall') return this.battle.sides.filter(side => side !== this);\n\n\t\treturn [this.foe];\n\t}\n\tfoePokemonLeft() {\n\t\tif (this.battle.gameType === 'freeforall') {\n\t\t\treturn this.battle.sides.filter(side => side !== this).map(side => side.pokemonLeft).reduce((a, b) => a + b);\n\t\t}\n\n\t\tif (this.foe.allySide) return this.foe.pokemonLeft + this.foe.allySide.pokemonLeft;\n\n\t\treturn this.foe.pokemonLeft;\n\t}\n\tallies(all?: boolean) {\n\t\t// called during the first switch-in, so `active` can still contain nulls at this point\n\t\tlet allies = this.activeTeam().filter(ally => ally);\n\t\tif (!all) allies = allies.filter(ally => !!ally.hp);\n\n\t\treturn allies;\n\t}\n\tfoes(all?: boolean) {\n\t\tif (this.battle.gameType === 'freeforall') {\n\t\t\treturn this.battle.sides.map(side => side.active[0])\n\t\t\t\t.filter(pokemon => pokemon && pokemon.side !== this && (all || !!pokemon.hp));\n\t\t}\n\t\treturn this.foe.allies(all);\n\t}\n\tactiveTeam() {\n\t\tif (this.battle.gameType !== 'multi') return this.active;\n\n\t\treturn this.battle.sides[this.n % 2].active.concat(this.battle.sides[this.n % 2 + 2].active);\n\t}\n\thasAlly(pokemon: Pokemon) {\n\t\treturn pokemon.side === this || pokemon.side === this.allySide;\n\t}\n\n\taddSideCondition(\n\t\tstatus: string | Condition, source: Pokemon | 'debug' | null = null, sourceEffect: Effect | null = null\n\t): boolean {\n\t\tif (!source && this.battle.event?.target) source = this.battle.event.target;\n\t\tif (source === 'debug') source = this.active[0];\n\t\tif (!source) throw new Error(`setting sidecond without a source`);\n\t\tif (!source.getSlot) source = (source as any as Side).active[0];\n\n\t\tstatus = this.battle.dex.conditions.get(status);\n\t\tif (this.sideConditions[status.id]) {\n\t\t\tif (!(status as any).onSideRestart) return false;\n\t\t\treturn this.battle.singleEvent('SideRestart', status, this.sideConditions[status.id], this, source, sourceEffect);\n\t\t}\n\t\tthis.sideConditions[status.id] = this.battle.initEffectState({\n\t\t\tid: status.id,\n\t\t\ttarget: this,\n\t\t\tsource,\n\t\t\tsourceSlot: source.getSlot(),\n\t\t\tduration: status.duration,\n\t\t});\n\t\tif (status.durationCallback) {\n\t\t\tthis.sideConditions[status.id].duration =\n\t\t\t\tstatus.durationCallback.call(this.battle, this.active[0], source, sourceEffect);\n\t\t}\n\t\tif (!this.battle.singleEvent('SideStart', status, this.sideConditions[status.id], this, source, sourceEffect)) {\n\t\t\tdelete this.sideConditions[status.id];\n\t\t\treturn false;\n\t\t}\n\t\tthis.battle.runEvent('SideConditionStart', source, source, status);\n\t\treturn true;\n\t}\n\n\tgetSideCondition(status: string | Effect): Effect | null {\n\t\tstatus = this.battle.dex.conditions.get(status) as Effect;\n\t\tif (!this.sideConditions[status.id]) return null;\n\t\treturn status;\n\t}\n\n\tgetSideConditionData(status: string | Effect): AnyObject {\n\t\tstatus = this.battle.dex.conditions.get(status) as Effect;\n\t\treturn this.sideConditions[status.id] || null;\n\t}\n\n\tremoveSideCondition(status: string | Effect): boolean {\n\t\tstatus = this.battle.dex.conditions.get(status) as Effect;\n\t\tif (!this.sideConditions[status.id]) return false;\n\t\tthis.battle.singleEvent('SideEnd', status, this.sideConditions[status.id], this);\n\t\tdelete this.sideConditions[status.id];\n\t\treturn true;\n\t}\n\n\taddSlotCondition(\n\t\ttarget: Pokemon | number, status: string | Condition, source: Pokemon | 'debug' | null = null,\n\t\tsourceEffect: Effect | null = null\n\t) {\n\t\tsource ??= this.battle.event?.target || null;\n\t\tif (source === 'debug') source = this.active[0];\n\t\tif (target instanceof Pokemon) target = target.position;\n\t\tif (!source) throw new Error(`setting sidecond without a source`);\n\n\t\tstatus = this.battle.dex.conditions.get(status);\n\t\tif (this.slotConditions[target][status.id]) {\n\t\t\tif (!status.onRestart) return false;\n\t\t\treturn this.battle.singleEvent('Restart', status, this.slotConditions[target][status.id], this, source, sourceEffect);\n\t\t}\n\t\tconst conditionState = this.slotConditions[target][status.id] = this.battle.initEffectState({\n\t\t\tid: status.id,\n\t\t\ttarget: this,\n\t\t\tsource,\n\t\t\tsourceSlot: source.getSlot(),\n\t\t\tisSlotCondition: true,\n\t\t\tduration: status.duration,\n\t\t});\n\t\tif (status.durationCallback) {\n\t\t\tconditionState.duration =\n\t\t\t\tstatus.durationCallback.call(this.battle, this.active[0], source, sourceEffect);\n\t\t}\n\t\tif (!this.battle.singleEvent('Start', status, conditionState, this.active[target], source, sourceEffect)) {\n\t\t\tdelete this.slotConditions[target][status.id];\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tgetSlotCondition(target: Pokemon | number, status: string | Effect) {\n\t\tif (target instanceof Pokemon) target = target.position;\n\t\tstatus = this.battle.dex.conditions.get(status) as Effect;\n\t\tif (!this.slotConditions[target][status.id]) return null;\n\t\treturn status;\n\t}\n\n\tremoveSlotCondition(target: Pokemon | number, status: string | Effect) {\n\t\tif (target instanceof Pokemon) target = target.position;\n\t\tstatus = this.battle.dex.conditions.get(status) as Effect;\n\t\tif (!this.slotConditions[target][status.id]) return false;\n\t\tthis.battle.singleEvent('End', status, this.slotConditions[target][status.id], this.active[target]);\n\t\tdelete this.slotConditions[target][status.id];\n\t\treturn true;\n\t}\n\n\tsend(...parts: (string | number | Function | AnyObject)[]) {\n\t\tconst sideUpdate = '|' + parts.map(part => {\n\t\t\tif (typeof part !== 'function') return part;\n\t\t\treturn part(this);\n\t\t}).join('|');\n\t\tthis.battle.send('sideupdate', `${this.id}\\n${sideUpdate}`);\n\t}\n\n\temitRequest(update: ChoiceRequest) {\n\t\tthis.battle.send('sideupdate', `${this.id}\\n|request|${JSON.stringify(update)}`);\n\t\tthis.activeRequest = update;\n\t}\n\n\temitChoiceError(message: string, unavailable?: boolean) {\n\t\tthis.choice.error = message;\n\t\tconst type = `[${unavailable ? 'Unavailable' : 'Invalid'} choice]`;\n\t\tthis.battle.send('sideupdate', `${this.id}\\n|error|${type} ${message}`);\n\t\tif (this.battle.strictChoices) throw new Error(`${type} ${message}`);\n\t\treturn false;\n\t}\n\n\tisChoiceDone() {\n\t\tif (!this.requestState) return true;\n\t\tif (this.choice.forcedSwitchesLeft) return false;\n\n\t\tif (this.requestState === 'teampreview') {\n\t\t\treturn this.choice.actions.length >= this.pickedTeamSize();\n\t\t}\n\n\t\t// current request is move/switch\n\t\tthis.getChoiceIndex(); // auto-pass\n\t\treturn this.choice.actions.length >= this.active.length;\n\t}\n\n\tchooseMove(\n\t\tmoveText?: string | number,\n\t\ttargetLoc = 0,\n\t\tevent: 'mega' | 'megax' | 'megay' | 'zmove' | 'ultra' | 'dynamax' | 'terastallize' | '' = ''\n\t) {\n\t\tif (this.requestState !== 'move') {\n\t\t\treturn this.emitChoiceError(`Can't move: You need a ${this.requestState} response`);\n\t\t}\n\t\tconst index = this.getChoiceIndex();\n\t\tif (index >= this.active.length) {\n\t\t\treturn this.emitChoiceError(`Can't move: You sent more choices than unfainted Pok\u00E9mon.`);\n\t\t}\n\t\tconst autoChoose = !moveText;\n\t\tconst pokemon: Pokemon = this.active[index];\n\n\t\t// Parse moveText (name or index)\n\t\t// If the move is not found, the action is invalid without requiring further inspection.\n\n\t\tconst request = pokemon.getMoveRequestData();\n\t\tlet moveid = '';\n\t\tlet targetType = '';\n\t\tif (autoChoose) moveText = 1;\n\t\tif (typeof moveText === 'number' || (moveText && /^[0-9]+$/.test(moveText))) {\n\t\t\t// Parse a one-based move index.\n\t\t\tconst moveIndex = Number(moveText) - 1;\n\t\t\tif (moveIndex < 0 || moveIndex >= request.moves.length || !request.moves[moveIndex]) {\n\t\t\t\treturn this.emitChoiceError(`Can't move: Your ${pokemon.name} doesn't have a move ${moveIndex + 1}`);\n\t\t\t}\n\t\t\tmoveid = request.moves[moveIndex].id;\n\t\t\ttargetType = request.moves[moveIndex].target!;\n\t\t} else {\n\t\t\t// Parse a move ID.\n\t\t\t// Move names are also allowed, but may cause ambiguity (see client issue #167).\n\t\t\tmoveid = toID(moveText);\n\t\t\tif (moveid.startsWith('hiddenpower')) {\n\t\t\t\tmoveid = 'hiddenpower';\n\t\t\t}\n\t\t\tfor (const move of request.moves) {\n\t\t\t\tif (move.id !== moveid) continue;\n\t\t\t\ttargetType = move.target || 'normal';\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!targetType && ['', 'dynamax'].includes(event) && request.maxMoves) {\n\t\t\t\tfor (const [i, moveRequest] of request.maxMoves.maxMoves.entries()) {\n\t\t\t\t\tif (moveid === moveRequest.move) {\n\t\t\t\t\t\tmoveid = request.moves[i].id;\n\t\t\t\t\t\ttargetType = moveRequest.target;\n\t\t\t\t\t\tevent = 'dynamax';\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!targetType && ['', 'zmove'].includes(event) && request.canZMove) {\n\t\t\t\tfor (const [i, moveRequest] of request.canZMove.entries()) {\n\t\t\t\t\tif (!moveRequest) continue;\n\t\t\t\t\tif (moveid === toID(moveRequest.move)) {\n\t\t\t\t\t\tmoveid = request.moves[i].id;\n\t\t\t\t\t\ttargetType = moveRequest.target;\n\t\t\t\t\t\tevent = 'zmove';\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!targetType) {\n\t\t\t\treturn this.emitChoiceError(`Can't move: Your ${pokemon.name} doesn't have a move matching ${moveid}`);\n\t\t\t}\n\t\t}\n\n\t\tconst moves = pokemon.getMoves();\n\t\tif (autoChoose) {\n\t\t\tfor (const [i, move] of request.moves.entries()) {\n\t\t\t\tif (move.disabled) continue;\n\t\t\t\tif (i < moves.length && move.id === moves[i].id && moves[i].disabled) continue;\n\t\t\t\tmoveid = move.id;\n\t\t\t\ttargetType = move.target!;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tconst move = this.battle.dex.moves.get(moveid);\n\n\t\t// Z-move\n\n\t\tconst zMove = event === 'zmove' ? this.battle.actions.getZMove(move, pokemon) : undefined;\n\t\tif (event === 'zmove' && !zMove) {\n\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't use ${move.name} as a Z-move`);\n\t\t}\n\t\tif (zMove && this.choice.zMove) {\n\t\t\treturn this.emitChoiceError(`Can't move: You can't Z-move more than once per battle`);\n\t\t}\n\n\t\tif (zMove) targetType = this.battle.dex.moves.get(zMove).target;\n\n\t\t// Dynamax\n\t\t// Is dynamaxed or will dynamax this turn.\n\t\tconst maxMove = (event === 'dynamax' || pokemon.volatiles['dynamax']) ?\n\t\t\tthis.battle.actions.getMaxMove(move, pokemon) : undefined;\n\t\tif (event === 'dynamax' && !maxMove) {\n\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't use ${move.name} as a Max Move`);\n\t\t}\n\n\t\tif (maxMove) targetType = this.battle.dex.moves.get(maxMove).target;\n\n\t\t// Validate targetting\n\n\t\tif (autoChoose) {\n\t\t\ttargetLoc = 0;\n\t\t} else if (this.battle.actions.targetTypeChoices(targetType)) {\n\t\t\tif (!targetLoc && this.active.length >= 2) {\n\t\t\t\treturn this.emitChoiceError(`Can't move: ${move.name} needs a target`);\n\t\t\t}\n\t\t\tif (!this.battle.validTargetLoc(targetLoc, pokemon, targetType)) {\n\t\t\t\treturn this.emitChoiceError(`Can't move: Invalid target for ${move.name}`);\n\t\t\t}\n\t\t} else {\n\t\t\tif (targetLoc) {\n\t\t\t\treturn this.emitChoiceError(`Can't move: You can't choose a target for ${move.name}`);\n\t\t\t}\n\t\t}\n\n\t\tconst lockedMove = pokemon.getLockedMove();\n\t\tif (lockedMove) {\n\t\t\tlet lockedMoveTargetLoc = pokemon.lastMoveTargetLoc || 0;\n\t\t\tconst lockedMoveID = toID(lockedMove);\n\t\t\tif (pokemon.volatiles[lockedMoveID]?.targetLoc) {\n\t\t\t\tlockedMoveTargetLoc = pokemon.volatiles[lockedMoveID].targetLoc;\n\t\t\t}\n\t\t\tthis.choice.actions.push({\n\t\t\t\tchoice: 'move',\n\t\t\t\tpokemon,\n\t\t\t\ttargetLoc: lockedMoveTargetLoc,\n\t\t\t\tmoveid: lockedMoveID,\n\t\t\t});\n\t\t\treturn true;\n\t\t} else if (!moves.length && !zMove) {\n\t\t\t// Override action and use Struggle if there are no enabled moves with PP\n\t\t\t// Gen 4 and earlier announce a Pokemon has no moves left before the turn begins, and only to that player's side.\n\t\t\tif (this.battle.gen <= 4) this.send('-activate', pokemon, 'move: Struggle');\n\t\t\tmoveid = 'struggle';\n\t\t} else if (maxMove) {\n\t\t\t// Dynamaxed; only Taunt and Assault Vest disable Max Guard, but the base move must have PP remaining\n\t\t\tif (pokemon.maxMoveDisabled(move)) {\n\t\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name}'s ${maxMove.name} is disabled`);\n\t\t\t}\n\t\t} else if (!zMove) {\n\t\t\t// Check for disabled moves\n\t\t\tlet isEnabled = false;\n\t\t\tlet disabledSource = '';\n\t\t\tfor (const m of moves) {\n\t\t\t\tif (m.id !== moveid) continue;\n\t\t\t\tif (!m.disabled) {\n\t\t\t\t\tisEnabled = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (m.disabledSource) {\n\t\t\t\t\tdisabledSource = m.disabledSource;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!isEnabled) {\n\t\t\t\t// Request a different choice\n\t\t\t\tif (autoChoose) throw new Error(`autoChoose chose a disabled move`);\n\t\t\t\tconst includeRequest = this.updateRequestForPokemon(pokemon, req => {\n\t\t\t\t\tlet updated = false;\n\t\t\t\t\tfor (const m of req.moves) {\n\t\t\t\t\t\tif (m.id === moveid) {\n\t\t\t\t\t\t\tif (!m.disabled) {\n\t\t\t\t\t\t\t\tm.disabled = true;\n\t\t\t\t\t\t\t\tupdated = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (m.disabledSource !== disabledSource) {\n\t\t\t\t\t\t\t\tm.disabledSource = disabledSource;\n\t\t\t\t\t\t\t\tupdated = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn updated;\n\t\t\t\t});\n\t\t\t\tconst status = this.emitChoiceError(`Can't move: ${pokemon.name}'s ${move.name} is disabled`, includeRequest);\n\t\t\t\tif (includeRequest) this.emitRequest(this.activeRequest!);\n\t\t\t\treturn status;\n\t\t\t}\n\t\t\t// The chosen move is valid yay\n\t\t}\n\n\t\t// Mega evolution\n\n\t\tconst mixandmega = this.battle.format.mod === 'mixandmega';\n\t\tconst mega = (event === 'mega');\n\t\tconst megax = (event === 'megax');\n\t\tconst megay = (event === 'megay');\n\t\tif (mega && !pokemon.canMegaEvo) {\n\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't mega evolve`);\n\t\t}\n\t\tif (megax && !pokemon.canMegaEvoX) {\n\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't mega evolve X`);\n\t\t}\n\t\tif (megay && !pokemon.canMegaEvoY) {\n\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't mega evolve Y`);\n\t\t}\n\t\tif ((mega || megax || megay) && this.choice.mega && !mixandmega) {\n\t\t\treturn this.emitChoiceError(`Can't move: You can only mega-evolve once per battle`);\n\t\t}\n\t\tconst ultra = (event === 'ultra');\n\t\tif (ultra && !pokemon.canUltraBurst) {\n\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't ultra burst`);\n\t\t}\n\t\tif (ultra && this.choice.ultra && !mixandmega) {\n\t\t\treturn this.emitChoiceError(`Can't move: You can only ultra burst once per battle`);\n\t\t}\n\t\tlet dynamax = (event === 'dynamax');\n\t\tconst canDynamax = (this.activeRequest as MoveRequest)?.active[this.active.indexOf(pokemon)].canDynamax;\n\t\tif (dynamax && (this.choice.dynamax || !canDynamax)) {\n\t\t\tif (pokemon.volatiles['dynamax']) {\n\t\t\t\tdynamax = false;\n\t\t\t} else {\n\t\t\t\tif (this.battle.gen !== 8) {\n\t\t\t\t\treturn this.emitChoiceError(`Can't move: Dynamaxing doesn't outside of Gen 8.`);\n\t\t\t\t} else if (pokemon.side.canDynamaxNow()) {\n\t\t\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't Dynamax now.`);\n\t\t\t\t} else if (pokemon.side.allySide?.canDynamaxNow()) {\n\t\t\t\t\treturn this.emitChoiceError(`Can't move: It's your partner's turn to Dynamax.`);\n\t\t\t\t}\n\t\t\t\treturn this.emitChoiceError(`Can't move: You can only Dynamax once per battle.`);\n\t\t\t}\n\t\t}\n\t\tconst terastallize = (event === 'terastallize');\n\t\tif (terastallize && !pokemon.canTerastallize) {\n\t\t\t// Make this work properly\n\t\t\treturn this.emitChoiceError(`Can't move: ${pokemon.name} can't Terastallize.`);\n\t\t}\n\t\tif (terastallize && this.choice.terastallize) {\n\t\t\treturn this.emitChoiceError(`Can't move: You can only Terastallize once per battle.`);\n\t\t}\n\t\tif (terastallize && this.battle.gen !== 9) {\n\t\t\t// Make this work properly\n\t\t\treturn this.emitChoiceError(`Can't move: You can only Terastallize in Gen 9.`);\n\t\t}\n\n\t\tthis.choice.actions.push({\n\t\t\tchoice: 'move',\n\t\t\tpokemon,\n\t\t\ttargetLoc,\n\t\t\tmoveid,\n\t\t\tmega: mega || ultra,\n\t\t\tmegax,\n\t\t\tmegay,\n\t\t\tzmove: zMove,\n\t\t\tmaxMove: maxMove ? maxMove.id : undefined,\n\t\t\tterastallize: terastallize ? pokemon.teraType : undefined,\n\t\t});\n\n\t\tif (pokemon.maybeDisabled) {\n\t\t\tthis.choice.cantUndo = this.choice.cantUndo || pokemon.isLastActive();\n\t\t}\n\n\t\tif (mega || megax || megay) this.choice.mega = true;\n\t\tif (ultra) this.choice.ultra = true;\n\t\tif (zMove) this.choice.zMove = true;\n\t\tif (dynamax) this.choice.dynamax = true;\n\t\tif (terastallize) this.choice.terastallize = true;\n\n\t\treturn true;\n\t}\n\n\tupdateRequestForPokemon(pokemon: Pokemon, update: (req: AnyObject) => boolean) {\n\t\tif (!(this.activeRequest as MoveRequest)?.active) {\n\t\t\tthrow new Error(`Can't update a request without active Pokemon`);\n\t\t}\n\t\tconst req = (this.activeRequest as MoveRequest).active[pokemon.position];\n\t\tif (!req) throw new Error(`Pokemon not found in request's active field`);\n\t\treturn update(req);\n\t}\n\n\tchooseSwitch(slotText?: string) {\n\t\tif (this.requestState !== 'move' && this.requestState !== 'switch') {\n\t\t\treturn this.emitChoiceError(`Can't switch: You need a ${this.requestState} response`);\n\t\t}\n\t\tconst index = this.getChoiceIndex();\n\t\tif (index >= this.active.length) {\n\t\t\tif (this.requestState === 'switch') {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You sent more switches than Pok\u00E9mon that need to switch`);\n\t\t\t}\n\t\t\treturn this.emitChoiceError(`Can't switch: You sent more choices than unfainted Pok\u00E9mon`);\n\t\t}\n\t\tconst pokemon = this.active[index];\n\t\tlet slot;\n\t\tif (!slotText) {\n\t\t\tif (this.requestState !== 'switch') {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You need to select a Pok\u00E9mon to switch in`);\n\t\t\t}\n\t\t\tif (this.slotConditions[pokemon.position]['revivalblessing']) {\n\t\t\t\tslot = 0;\n\t\t\t\twhile (!this.pokemon[slot].fainted) slot++;\n\t\t\t} else {\n\t\t\t\tif (!this.choice.forcedSwitchesLeft) return this.choosePass();\n\t\t\t\tslot = this.active.length;\n\t\t\t\twhile (this.choice.switchIns.has(slot) || this.pokemon[slot].fainted) slot++;\n\t\t\t}\n\t\t} else {\n\t\t\tslot = parseInt(slotText) - 1;\n\t\t}\n\t\tif (isNaN(slot) || slot < 0) {\n\t\t\t// maybe it's a name/species id!\n\t\t\tslot = -1;\n\t\t\tfor (const [i, mon] of this.pokemon.entries()) {\n\t\t\t\tif (slotText!.toLowerCase() === mon.name.toLowerCase() || toID(slotText) === mon.species.id) {\n\t\t\t\t\tslot = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (slot < 0) {\n\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}\n\t\t}\n\t\tif (slot >= this.pokemon.length) {\n\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} else if (slot < this.active.length && !this.slotConditions[pokemon.position]['revivalblessing']) {\n\t\t\treturn this.emitChoiceError(`Can't switch: You can't switch to an active Pok\u00E9mon`);\n\t\t} else if (this.choice.switchIns.has(slot)) {\n\t\t\treturn this.emitChoiceError(`Can't switch: The Pok\u00E9mon in slot ${slot + 1} can only switch in once`);\n\t\t}\n\t\tconst targetPokemon = this.pokemon[slot];\n\n\t\tif (this.slotConditions[pokemon.position]['revivalblessing']) {\n\t\t\tif (!targetPokemon.fainted) {\n\t\t\t\treturn this.emitChoiceError(`Can't switch: You have to pass to a fainted Pok\u00E9mon`);\n\t\t\t}\n\t\t\t// Should always subtract, but stop at 0 to prevent errors.\n\t\t\tthis.choice.forcedSwitchesLeft = this.battle.clampIntRange(this.choice.forcedSwitchesLeft - 1, 0);\n\t\t\tpokemon.switchFlag = false;\n\t\t\tthis.choice.actions.push({\n\t\t\t\tchoice: 'revivalblessing',\n\t\t\t\tpokemon,\n\t\t\t\ttarget: targetPokemon,\n\t\t\t} as ChosenAction);\n\t\t\treturn true;\n\t\t}\n\n\t\tif (targetPokemon.fainted) {\n\t\t\treturn this.emitChoiceError(`Can't switch: You can't switch to a fainted Pok\u00E9mon`);\n\t\t}\n\n\t\tif (this.requestState === 'move') {\n\t\t\tif (pokemon.trapped) {\n\t\t\t\tconst includeRequest = this.updateRequestForPokemon(pokemon, req => {\n\t\t\t\t\tlet updated = false;\n\t\t\t\t\tif (req.maybeTrapped) {\n\t\t\t\t\t\tdelete req.maybeTrapped;\n\t\t\t\t\t\tupdated = true;\n\t\t\t\t\t}\n\t\t\t\t\tif (!req.trapped) {\n\t\t\t\t\t\treq.trapped = true;\n\t\t\t\t\t\tupdated = true;\n\t\t\t\t\t}\n\t\t\t\t\treturn updated;\n\t\t\t\t});\n\t\t\t\tconst status = this.emitChoiceError(`Can't switch: The active Pok\u00E9mon is trapped`, includeRequest);\n\t\t\t\tif (includeRequest) this.emitRequest(this.activeRequest!);\n\t\t\t\treturn status;\n\t\t\t} else if (pokemon.maybeTrapped) {\n\t\t\t\tthis.choice.cantUndo = this.choice.cantUndo || pokemon.isLastActive();\n\t\t\t}\n\t\t} else if (this.requestState === 'switch') {\n\t\t\tif (!this.choice.forcedSwitchesLeft) {\n\t\t\t\tthrow new Error(`Player somehow switched too many Pokemon`);\n\t\t\t}\n\t\t\tthis.choice.forcedSwitchesLeft--;\n\t\t}\n\n\t\tthis.choice.switchIns.add(slot);\n\n\t\tthis.choice.actions.push({\n\t\t\tchoice: (this.requestState === 'switch' ? 'instaswitch' : 'switch'),\n\t\t\tpokemon,\n\t\t\ttarget: targetPokemon,\n\t\t} as ChosenAction);\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * The number of pokemon you must choose in Team Preview.\n\t *\n\t * Note that PS doesn't support choosing fewer than this number of pokemon.\n\t * In the games, it is sometimes possible to bring fewer than this, but\n\t * since that's nearly always a mistake, we haven't gotten around to\n\t * supporting it.\n\t */\n\tpickedTeamSize() {\n\t\treturn Math.min(this.pokemon.length, this.battle.ruleTable.pickedTeamSize || Infinity);\n\t}\n\n\tchooseTeam(data = '') {\n\t\tif (this.requestState !== 'teampreview') {\n\t\t\treturn this.emitChoiceError(`Can't choose for Team Preview: You're not in a Team Preview phase`);\n\t\t}\n\n\t\tconst ruleTable = this.battle.ruleTable;\n\t\tlet positions = data.split(data.includes(',') ? ',' : '')\n\t\t\t.map(datum => parseInt(datum) - 1);\n\t\tconst pickedTeamSize = this.pickedTeamSize();\n\n\t\t// make sure positions is exactly of length pickedTeamSize\n\t\t// - If too big: the client automatically sends a full list, so we just trim it down to size\n\t\tpositions.splice(pickedTeamSize);\n\t\t// - If too small: we intentionally support only sending leads and having the sim fill in the rest\n\t\tif (positions.length === 0) {\n\t\t\tfor (let i = 0; i < pickedTeamSize; i++) positions.push(i);\n\t\t} else if (positions.length < pickedTeamSize) {\n\t\t\tfor (let i = 0; i < pickedTeamSize; i++) {\n\t\t\t\tif (!positions.includes(i)) positions.push(i);\n\t\t\t\t// duplicate in input, let the rest of the code handle the error message\n\t\t\t\tif (positions.length >= pickedTeamSize) break;\n\t\t\t}\n\t\t}\n\n\t\tfor (const [index, pos] of positions.entries()) {\n\t\t\tif (isNaN(pos) || pos < 0 || pos >= this.pokemon.length) {\n\t\t\t\treturn this.emitChoiceError(`Can't choose for Team Preview: You do not have a Pok\u00E9mon in slot ${pos + 1}`);\n\t\t\t}\n\t\t\tif (positions.indexOf(pos) !== index) {\n\t\t\t\treturn this.emitChoiceError(`Can't choose for Team Preview: The Pok\u00E9mon in slot ${pos + 1} can only switch in once`);\n\t\t\t}\n\t\t}\n\t\tif (ruleTable.maxTotalLevel) {\n\t\t\tlet totalLevel = 0;\n\t\t\tfor (const pos of positions) totalLevel += this.pokemon[pos].level;\n\n\t\t\tif (totalLevel > ruleTable.maxTotalLevel) {\n\t\t\t\tif (!data) {\n\t\t\t\t\t// autoChoose\n\t\t\t\t\tpositions = [...this.pokemon.keys()].sort((a, b) => (this.pokemon[a].level - this.pokemon[b].level))\n\t\t\t\t\t\t.slice(0, pickedTeamSize);\n\t\t\t\t} else {\n\t\t\t\t\treturn this.emitChoiceError(`Your selected team has a total level of ${totalLevel}, but it can't be above ${ruleTable.maxTotalLevel}; please select a valid team of ${pickedTeamSize} Pok\u00E9mon`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (ruleTable.valueRules.has('forceselect')) {\n\t\t\tconst species = this.battle.dex.species.get(ruleTable.valueRules.get('forceselect'));\n\t\t\tif (!data) {\n\t\t\t\t// autoChoose\n\t\t\t\tpositions = [...this.pokemon.keys()].filter(pos => this.pokemon[pos].species.name === species.name)\n\t\t\t\t\t.concat([...this.pokemon.keys()].filter(pos => this.pokemon[pos].species.name !== species.name))\n\t\t\t\t\t.slice(0, pickedTeamSize);\n\t\t\t} else {\n\t\t\t\tlet hasSelection = false;\n\t\t\t\tfor (const pos of positions) {\n\t\t\t\t\tif (this.pokemon[pos].species.name === species.name) {\n\t\t\t\t\t\thasSelection = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!hasSelection) {\n\t\t\t\t\treturn this.emitChoiceError(`You must bring ${species.name} to the battle.`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const [index, pos] of positions.entries()) {\n\t\t\tthis.choice.switchIns.add(pos);\n\t\t\tthis.choice.actions.push({\n\t\t\t\tchoice: 'team',\n\t\t\t\tindex,\n\t\t\t\tpokemon: this.pokemon[pos],\n\t\t\t\tpriority: -index,\n\t\t\t} as ChosenAction);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tchooseShift() {\n\t\tconst index = this.getChoiceIndex();\n\t\tif (index >= this.active.length) {\n\t\t\treturn this.emitChoiceError(`Can't shift: You do not have a Pok\u00E9mon in slot ${index + 1}`);\n\t\t} else if (this.requestState !== 'move') {\n\t\t\treturn this.emitChoiceError(`Can't shift: You can only shift during a move phase`);\n\t\t} else if (this.battle.gameType !== 'triples') {\n\t\t\treturn this.emitChoiceError(`Can't shift: You can only shift to the center in triples`);\n\t\t} else if (index === 1) {\n\t\t\treturn this.emitChoiceError(`Can't shift: You can only shift from the edge to the center`);\n\t\t}\n\t\tconst pokemon: Pokemon = this.active[index];\n\n\t\tthis.choice.actions.push({\n\t\t\tchoice: 'shift',\n\t\t\tpokemon,\n\t\t} as ChosenAction);\n\n\t\treturn true;\n\t}\n\n\tclearChoice() {\n\t\tlet forcedSwitches = 0;\n\t\tlet forcedPasses = 0;\n\t\tif (this.battle.requestState === 'switch') {\n\t\t\tconst canSwitchOut = this.active.filter(pokemon => pokemon?.switchFlag).length;\n\t\t\tconst canSwitchIn = this.pokemon.slice(this.active.length).filter(pokemon => pokemon && !pokemon.fainted).length;\n\t\t\tforcedSwitches = Math.min(canSwitchOut, canSwitchIn);\n\t\t\tforcedPasses = canSwitchOut - forcedSwitches;\n\t\t}\n\t\tthis.choice = {\n\t\t\tcantUndo: false,\n\t\t\terror: ``,\n\t\t\tactions: [],\n\t\t\tforcedSwitchesLeft: forcedSwitches,\n\t\t\tforcedPassesLeft: forcedPasses,\n\t\t\tswitchIns: new Set(),\n\t\t\tzMove: false,\n\t\t\tmega: false,\n\t\t\tultra: false,\n\t\t\tdynamax: false,\n\t\t\tterastallize: false,\n\t\t};\n\t}\n\n\tchoose(input: string) {\n\t\tif (!this.requestState) {\n\t\t\treturn this.emitChoiceError(\n\t\t\t\tthis.battle.ended ? `Can't do anything: The game is over` : `Can't do anything: It's not your turn`\n\t\t\t);\n\t\t}\n\n\t\tif (this.choice.cantUndo) {\n\t\t\treturn this.emitChoiceError(`Can't undo: A trapping/disabling effect would cause undo to leak information`);\n\t\t}\n\n\t\tthis.clearChoice();\n\n\t\tconst choiceStrings = (input.startsWith('team ') ? [input] : input.split(','));\n\n\t\tif (choiceStrings.length > this.active.length) {\n\t\t\treturn this.emitChoiceError(\n\t\t\t\t`Can't make choices: You sent choices for ${choiceStrings.length} Pok\u00E9mon, but this is a ${this.battle.gameType} game!`\n\t\t\t);\n\t\t}\n\n\t\tfor (const choiceString of choiceStrings) {\n\t\t\tlet [choiceType, data] = Utils.splitFirst(choiceString.trim(), ' ');\n\t\t\tdata = data.trim();\n\n\t\t\tswitch (choiceType) {\n\t\t\tcase 'move':\n\t\t\t\tconst original = data;\n\t\t\t\tconst error = () => this.emitChoiceError(`Conflicting arguments for \"move\": ${original}`);\n\t\t\t\tlet targetLoc: number | undefined;\n\t\t\t\tlet event: 'mega' | 'megax' | 'megay' | 'zmove' | 'ultra' | 'dynamax' | 'terastallize' | '' = '';\n\t\t\t\twhile (true) {\n\t\t\t\t\t// If data ends with a number, treat it as a target location.\n\t\t\t\t\t// We need to special case 'Conversion 2' so it doesn't get\n\t\t\t\t\t// confused with 'Conversion' erroneously sent with the target\n\t\t\t\t\t// '2' (since Conversion targets 'self', targetLoc can't be 2).\n\t\t\t\t\tif (/\\s(?:-|\\+)?[1-3]$/.test(data) && toID(data) !== 'conversion2') {\n\t\t\t\t\t\tif (targetLoc !== undefined) return error();\n\t\t\t\t\t\ttargetLoc = parseInt(data.slice(-2));\n\t\t\t\t\t\tdata = data.slice(0, -2).trim();\n\t\t\t\t\t} else if (data.endsWith(' mega')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'mega';\n\t\t\t\t\t\tdata = data.slice(0, -5);\n\t\t\t\t\t} else if (data.endsWith(' megax')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'megax';\n\t\t\t\t\t\tdata = data.slice(0, -6);\n\t\t\t\t\t} else if (data.endsWith(' megay')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'megay';\n\t\t\t\t\t\tdata = data.slice(0, -6);\n\t\t\t\t\t} else if (data.endsWith(' zmove')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'zmove';\n\t\t\t\t\t\tdata = data.slice(0, -6);\n\t\t\t\t\t} else if (data.endsWith(' ultra')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'ultra';\n\t\t\t\t\t\tdata = data.slice(0, -6);\n\t\t\t\t\t} else if (data.endsWith(' dynamax')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'dynamax';\n\t\t\t\t\t\tdata = data.slice(0, -8);\n\t\t\t\t\t} else if (data.endsWith(' gigantamax')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'dynamax';\n\t\t\t\t\t\tdata = data.slice(0, -11);\n\t\t\t\t\t} else if (data.endsWith(' max')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'dynamax';\n\t\t\t\t\t\tdata = data.slice(0, -4);\n\t\t\t\t\t} else if (data.endsWith(' terastal')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'terastallize';\n\t\t\t\t\t\tdata = data.slice(0, -9);\n\t\t\t\t\t} else if (data.endsWith(' terastallize')) {\n\t\t\t\t\t\tif (event) return error();\n\t\t\t\t\t\tevent = 'terastallize';\n\t\t\t\t\t\tdata = data.slice(0, -13);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!this.chooseMove(data, targetLoc, event)) return false;\n\t\t\t\tbreak;\n\t\t\tcase 'switch':\n\t\t\t\tthis.chooseSwitch(data);\n\t\t\t\tbreak;\n\t\t\tcase 'shift':\n\t\t\t\tif (data) return this.emitChoiceError(`Unrecognized data after \"shift\": ${data}`);\n\t\t\t\tif (!this.chooseShift()) return false;\n\t\t\t\tbreak;\n\t\t\tcase 'team':\n\t\t\t\tif (!this.chooseTeam(data)) return false;\n\t\t\t\tbreak;\n\t\t\tcase 'pass':\n\t\t\tcase 'skip':\n\t\t\t\tif (data) return this.emitChoiceError(`Unrecognized data after \"pass\": ${data}`);\n\t\t\t\tif (!this.choosePass()) return false;\n\t\t\t\tbreak;\n\t\t\tcase 'auto':\n\t\t\tcase 'default':\n\t\t\t\tthis.autoChoose();\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.emitChoiceError(`Unrecognized choice: ${choiceString}`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn !this.choice.error;\n\t}\n\n\tgetChoiceIndex(isPass?: boolean) {\n\t\tlet index = this.choice.actions.length;\n\n\t\tif (!isPass) {\n\t\t\tswitch (this.requestState) {\n\t\t\tcase 'move':\n\t\t\t\t// auto-pass\n\t\t\t\twhile (\n\t\t\t\t\tindex < this.active.length &&\n\t\t\t\t\t(this.active[index].fainted || this.active[index].volatiles['commanding'])\n\t\t\t\t) {\n\t\t\t\t\tthis.choosePass();\n\t\t\t\t\tindex++;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'switch':\n\t\t\t\twhile (index < this.active.length && !this.active[index].switchFlag) {\n\t\t\t\t\tthis.choosePass();\n\t\t\t\t\tindex++;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn index;\n\t}\n\n\tchoosePass(): boolean | Side {\n\t\tconst index = this.getChoiceIndex(true);\n\t\tif (index >= this.active.length) return false;\n\t\tconst pokemon: Pokemon = this.active[index];\n\n\t\tswitch (this.requestState) {\n\t\tcase 'switch':\n\t\t\tif (pokemon.switchFlag) { // This condition will always happen if called by Battle#choose()\n\t\t\t\tif (!this.choice.forcedPassesLeft) {\n\t\t\t\t\treturn this.emitChoiceError(`Can't pass: You need to switch in a Pok\u00E9mon to replace ${pokemon.name}`);\n\t\t\t\t}\n\t\t\t\tthis.choice.forcedPassesLeft--;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'move':\n\t\t\tif (!pokemon.fainted && !pokemon.volatiles['commanding']) {\n\t\t\t\treturn this.emitChoiceError(`Can't pass: Your ${pokemon.name} must make a move (or switch)`);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn this.emitChoiceError(`Can't pass: Not a move or switch request`);\n\t\t}\n\n\t\tthis.choice.actions.push({\n\t\t\tchoice: 'pass',\n\t\t} as ChosenAction);\n\t\treturn true;\n\t}\n\n\t/** Automatically finish a choice if not currently complete. */\n\tautoChoose() {\n\t\tif (this.requestState === 'teampreview') {\n\t\t\tif (!this.isChoiceDone()) this.chooseTeam();\n\t\t} else if (this.requestState === 'switch') {\n\t\t\tlet i = 0;\n\t\t\twhile (!this.isChoiceDone()) {\n\t\t\t\tif (!this.chooseSwitch()) throw new Error(`autoChoose switch crashed: ${this.choice.error}`);\n\t\t\t\ti++;\n\t\t\t\tif (i > 10) throw new Error(`autoChoose failed: infinite looping`);\n\t\t\t}\n\t\t} else if (this.requestState === 'move') {\n\t\t\tlet i = 0;\n\t\t\twhile (!this.isChoiceDone()) {\n\t\t\t\tif (!this.chooseMove()) throw new Error(`autoChoose crashed: ${this.choice.error}`);\n\t\t\t\ti++;\n\t\t\t\tif (i > 10) throw new Error(`autoChoose failed: infinite looping`);\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tdestroy() {\n\t\t// deallocate ourself\n\n\t\t// deallocate children and get rid of references to them\n\t\tfor (const pokemon of this.pokemon) {\n\t\t\tif (pokemon) pokemon.destroy();\n\t\t}\n\n\t\tfor (const action of this.choice.actions) {\n\t\t\tdelete action.side;\n\t\t\tdelete action.pokemon;\n\t\t\tdelete action.target;\n\t\t}\n\t\tthis.choice.actions = [];\n\n\t\t// get rid of some possibly-circular references\n\t\tthis.pokemon = [];\n\t\tthis.active = [];\n\t\tthis.foe = null!;\n\t\t(this as any).battle = null!;\n\t}\n}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