From 855c956aad0f33f1b8d7f9a8074299348d0574e4 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Fri, 6 Jun 2025 10:41:34 -0500 Subject: [PATCH] Update with Bertie's comments Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com> --- src/phases/command-phase.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/phases/command-phase.ts b/src/phases/command-phase.ts index b51952b791c..66c7dbb0c82 100644 --- a/src/phases/command-phase.ts +++ b/src/phases/command-phase.ts @@ -224,7 +224,8 @@ export class CommandPhase extends FieldPhase { ); } - /** Helper method for {@linkcode handleFightCommand} that returns the moveID for the phase + /** + * Helper method for {@linkcode handleFightCommand} that returns the moveID for the phase * based on the move passed in or the cursor. * * Does not check if the move is usable or not, that should be handled by the caller. @@ -234,10 +235,16 @@ export class CommandPhase extends FieldPhase { } /** - * Handle fight logic + * Process the logic for executing a fight-related command + * + * @remarks + * - Validates whether the move can be used, using struggle if not + * - Constructs the turn command and inserts it into the battle's turn commands + * * @param command - The command to handle (FIGHT or TERA) * @param cursor - The index that the cursor is placed on, or -1 if no move can be selected. - * @param args - Any additional arguments to pass to the command + * @param ignorePP - Whether to ignore PP when checking if the move can be used. + * @param move - The move to force the command to use, if any. */ private handleFightCommand( command: Command.FIGHT | Command.TERA, @@ -248,7 +255,6 @@ export class CommandPhase extends FieldPhase { const playerPokemon = this.getPokemon(); const ignorePP = isIgnorePP(useMode); - let canUse = cursor === -1 || playerPokemon.trySelectMove(cursor, ignorePP); let canUse = cursor === -1 || playerPokemon.trySelectMove(cursor, ignorePP); // Ternary here ensures we don't compute struggle conditions unless necessary @@ -256,7 +262,9 @@ export class CommandPhase extends FieldPhase { ? false : cursor > -1 && !playerPokemon.getMoveset().some(m => m.isUsable(playerPokemon)); - if (!canUse && !useStruggle) { + canUse ||= useStruggle; + + if (!canUse) { this.queueFightErrorMessage(playerPokemon, cursor); return false; } @@ -283,7 +291,7 @@ export class CommandPhase extends FieldPhase { multiple: move.targets.length > 1, }; - if (moveId === Moves.NONE) { + if (moveId === MoveId.NONE) { turnCommand.targets = [this.fieldIndex]; }