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