From 2e05a421b0949e163eabb50572c269e4e7f65a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bastos=20Dias?= <80102738+andrebastosdias@users.noreply.github.com> Date: Tue, 23 Dec 2025 19:01:20 +0000 Subject: [PATCH 1/5] =?UTF-8?q?Check=20for=20the=20commanding=20volatile?= =?UTF-8?q?=20to=20determine=20the=20last=20active=20Pok=C3=A9mon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sim/pokemon.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sim/pokemon.ts b/sim/pokemon.ts index ba51b073a0..04bb7f9586 100644 --- a/sim/pokemon.ts +++ b/sim/pokemon.ts @@ -1161,7 +1161,9 @@ export class Pokemon { if (!this.isActive) return false; const allyActive = this.side.active; for (let i = this.position + 1; i < allyActive.length; i++) { - if (allyActive[i] && !allyActive[i].fainted) return false; + if (allyActive[i] && !allyActive[i].fainted && !allyActive[i].volatiles['commanding']) { + return false; + } } return true; } From 6c4052843a6a68a48bbd971fa421fe95a8a2b989 Mon Sep 17 00:00:00 2001 From: andrebastosdias Date: Mon, 30 Mar 2026 16:40:43 +0100 Subject: [PATCH 2/5] Also check for hard-locked --- sim/pokemon.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sim/pokemon.ts b/sim/pokemon.ts index f1b83c1a58..1a205feab6 100644 --- a/sim/pokemon.ts +++ b/sim/pokemon.ts @@ -1068,6 +1068,7 @@ export class Pokemon { getMoveRequestData() { let lockedMove = this.maybeLocked ? null : this.getLockedMove(); + const hardLocked = !!lockedMove; // Information should be restricted for the last active Pokémon const isLastActive = this.isLastActive(); @@ -1091,7 +1092,12 @@ export class Pokemon { }; if (isLastActive) { - this.maybeDisabled = this.maybeDisabled && !lockedMove; + if (hardLocked) { + // if it is hardLocked, maybe flags don't matter + this.maybeDisabled = false; + this.maybeLocked = false; + this.maybeTrapped = false; + } this.maybeLocked = this.maybeLocked || this.maybeDisabled; if (this.maybeDisabled) { data.maybeDisabled = this.maybeDisabled; @@ -1175,7 +1181,7 @@ export class Pokemon { if (!this.isActive) return false; const allyActive = this.side.active; for (let i = this.position + 1; i < allyActive.length; i++) { - if (allyActive[i] && !allyActive[i].fainted && !allyActive[i].volatiles['commanding']) { + if (allyActive[i] && !allyActive[i].fainted && !allyActive[i].getLockedMove() && !allyActive[i].volatiles['commanding']) { return false; } } From 716509cbf40d620588dc936ed0bc23b1c2828263 Mon Sep 17 00:00:00 2001 From: andrebastosdias Date: Mon, 30 Mar 2026 16:46:40 +0100 Subject: [PATCH 3/5] Lint --- sim/pokemon.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sim/pokemon.ts b/sim/pokemon.ts index 1a205feab6..c5fe2479ee 100644 --- a/sim/pokemon.ts +++ b/sim/pokemon.ts @@ -1181,7 +1181,8 @@ export class Pokemon { if (!this.isActive) return false; const allyActive = this.side.active; for (let i = this.position + 1; i < allyActive.length; i++) { - if (allyActive[i] && !allyActive[i].fainted && !allyActive[i].getLockedMove() && !allyActive[i].volatiles['commanding']) { + const ally = allyActive[i]; + if (ally && !ally.fainted && !ally.getLockedMove() && !ally.volatiles['commanding']) { return false; } } From f1447eb3f1f9ad294b15719d6a7dd1a5280d9570 Mon Sep 17 00:00:00 2001 From: andrebastosdias Date: Mon, 30 Mar 2026 16:58:01 +0100 Subject: [PATCH 4/5] Refactor to cleaner code --- sim/pokemon.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/sim/pokemon.ts b/sim/pokemon.ts index c5fe2479ee..e4f4c9827c 100644 --- a/sim/pokemon.ts +++ b/sim/pokemon.ts @@ -949,7 +949,6 @@ export class Pokemon { getMoves(lockedMove?: ID | null, restrictData?: boolean): MoveRequestData[] { if (lockedMove) { lockedMove = toID(lockedMove); - this.trapped = true; if (lockedMove === 'recharge') { return [{ move: 'Recharge', @@ -1069,6 +1068,7 @@ export class Pokemon { getMoveRequestData() { let lockedMove = this.maybeLocked ? null : this.getLockedMove(); const hardLocked = !!lockedMove; + if (hardLocked) this.trapped = true; // Information should be restricted for the last active Pokémon const isLastActive = this.isLastActive(); @@ -1091,13 +1091,15 @@ export class Pokemon { moves, }; - if (isLastActive) { - if (hardLocked) { - // if it is hardLocked, maybe flags don't matter - this.maybeDisabled = false; - this.maybeLocked = false; - this.maybeTrapped = false; + if (hardLocked || !isLastActive) { + this.maybeDisabled = false; + this.maybeLocked = false; + this.maybeTrapped = false; + if (hardLocked || canSwitchIn) { + // Discovered by selecting a valid Pokémon as a switch target and cancelling. + if (this.trapped) data.trapped = true; } + } else { this.maybeLocked = this.maybeLocked || this.maybeDisabled; if (this.maybeDisabled) { data.maybeDisabled = this.maybeDisabled; @@ -1112,14 +1114,6 @@ export class Pokemon { data.maybeTrapped = true; } } - } else { - this.maybeDisabled = false; - this.maybeLocked = false; - if (canSwitchIn) { - // Discovered by selecting a valid Pokémon as a switch target and cancelling. - if (this.trapped) data.trapped = true; - } - this.maybeTrapped = false; } if (!lockedMove) { From 6f4173e614dd2e65eb2eba1253fab0bab5129db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bastos=20Dias?= Date: Tue, 31 Mar 2026 15:00:57 +0100 Subject: [PATCH 5/5] Fix test --- sim/side.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sim/side.ts b/sim/side.ts index 37cc3e3c66..7ac9367099 100644 --- a/sim/side.ts +++ b/sim/side.ts @@ -1237,7 +1237,7 @@ export class Side { if (!this.chooseMove(data, targetLoc, event)) return false; break; case 'switch': - this.chooseSwitch(data); + if (!this.chooseSwitch(data)) return false; break; case 'shift': if (data) return this.emitChoiceError(`Unrecognized data after "shift": ${data}`); @@ -1253,7 +1253,7 @@ export class Side { break; case 'auto': case 'default': - this.autoChoose(); + if (!this.autoChoose()) return false; break; default: this.emitChoiceError(`Unrecognized choice: ${choiceString}`);