From 37767799cdd608608d77bd8ae33c5fcd11d6fdff Mon Sep 17 00:00:00 2001 From: Tiago Rodrigues Date: Sun, 8 Jun 2025 17:52:48 +0100 Subject: [PATCH] [Bug] Gorilla Tactics now activates on protect and miss (#5567) * [Bug] Fix #5112: Gorilla Tactics only registers succesful moves as move usage * Apply small fixes from code review Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/data/abilities/ability.ts | 82 ++++++++++++++------------ src/phases/move-effect-phase.ts | 3 + test/abilities/gorilla_tactics.test.ts | 29 +++++++++ 3 files changed, 76 insertions(+), 38 deletions(-) diff --git a/src/data/abilities/ability.ts b/src/data/abilities/ability.ts index a79e2206348..34ae8be78b6 100644 --- a/src/data/abilities/ability.ts +++ b/src/data/abilities/ability.ts @@ -2534,48 +2534,38 @@ export class AllyStatMultiplierAbAttr extends AbAttr { } /** - * Ability attribute for Gorilla Tactics - * @extends PostAttackAbAttr + * Takes effect whenever a move succesfully executes, such as gorilla tactics' move-locking. + * (More specifically, whenever a move is pushed to the move history) + * @extends AbAttr */ -export class GorillaTacticsAbAttr extends PostAttackAbAttr { - constructor() { - super((_user, _target, _move) => true, false); - } - - override canApplyPostAttack( - pokemon: Pokemon, - passive: boolean, - simulated: boolean, - defender: Pokemon, - move: Move, - hitResult: HitResult | null, - args: any[], +export class ExecutedMoveAbAttr extends AbAttr { + canApplyExecutedMove( + _pokemon: Pokemon, + _simulated: boolean, ): boolean { - return ( - (super.canApplyPostAttack(pokemon, passive, simulated, defender, move, hitResult, args) && simulated) || - !pokemon.getTag(BattlerTagType.GORILLA_TACTICS) - ); + return true; } - /** - * - * @param {Pokemon} pokemon the {@linkcode Pokemon} with this ability - * @param _passive n/a - * @param simulated whether the ability is being simulated - * @param _defender n/a - * @param _move n/a - * @param _hitResult n/a - * @param _args n/a - */ - override applyPostAttack( - pokemon: Pokemon, - _passive: boolean, - simulated: boolean, - _defender: Pokemon, - _move: Move, - _hitResult: HitResult | null, - _args: any[], - ): void { + applyExecutedMove( + _pokemon: Pokemon, + _simulated: boolean, + ): void {} +} + +/** + * Ability attribute for Gorilla Tactics + * @extends ExecutedMoveAbAttr + */ +export class GorillaTacticsAbAttr extends ExecutedMoveAbAttr { + constructor(showAbility: boolean = false) { + super(showAbility); + } + + override canApplyExecutedMove(pokemon: Pokemon, simulated: boolean): boolean { + return simulated || !pokemon.getTag(BattlerTagType.GORILLA_TACTICS); + } + + override applyExecutedMove(pokemon: Pokemon, simulated: boolean): void { if (!simulated) { pokemon.addTag(BattlerTagType.GORILLA_TACTICS); } @@ -7792,6 +7782,22 @@ export function applyPreAttackAbAttrs( ); } +export function applyExecutedMoveAbAttrs( + attrType: Constructor, + pokemon: Pokemon, + simulated: boolean = false, + ...args: any[] +): void { + applyAbAttrsInternal( + attrType, + pokemon, + attr => attr.applyExecutedMove(pokemon, simulated), + attr => attr.canApplyExecutedMove(pokemon, simulated), + args, + simulated, + ); +} + export function applyPostAttackAbAttrs( attrType: Constructor, pokemon: Pokemon, diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index e0fa381447b..84072b393f1 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -3,10 +3,12 @@ import { globalScene } from "#app/global-scene"; import { AddSecondStrikeAbAttr, AlwaysHitAbAttr, + applyExecutedMoveAbAttrs, applyPostAttackAbAttrs, applyPostDamageAbAttrs, applyPostDefendAbAttrs, applyPreAttackAbAttrs, + ExecutedMoveAbAttr, IgnoreMoveEffectsAbAttr, MaxMultiHitAbAttr, PostAttackAbAttr, @@ -380,6 +382,7 @@ export class MoveEffectPhase extends PokemonPhase { // Add to the move history entry if (this.firstHit) { user.pushMoveHistory(this.moveHistoryEntry); + applyExecutedMoveAbAttrs(ExecutedMoveAbAttr, user); } try { diff --git a/test/abilities/gorilla_tactics.test.ts b/test/abilities/gorilla_tactics.test.ts index 55b8a4addcd..3ad138749a8 100644 --- a/test/abilities/gorilla_tactics.test.ts +++ b/test/abilities/gorilla_tactics.test.ts @@ -73,9 +73,38 @@ describe("Abilities - Gorilla Tactics", () => { await game.toNextTurn(); game.move.select(MoveId.TACKLE); + await game.move.forceEnemyMove(MoveId.SPLASH); //prevent protect from being used by the enemy await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]); await game.phaseInterceptor.to("MoveEndPhase"); expect(darmanitan.hp).toBeLessThan(darmanitan.getMaxHp()); }); + + it("should activate when the opponenet protects", async () => { + await game.classicMode.startBattle([SpeciesId.GALAR_DARMANITAN]); + + const darmanitan = game.field.getPlayerPokemon(); + + game.move.select(MoveId.TACKLE); + await game.move.selectEnemyMove(MoveId.PROTECT); + + await game.toEndOfTurn(); + expect(darmanitan.isMoveRestricted(MoveId.SPLASH)).toBe(true); + expect(darmanitan.isMoveRestricted(MoveId.TACKLE)).toBe(false); + }); + + it("should activate when a move is succesfully executed but misses", async () => { + await game.classicMode.startBattle([SpeciesId.GALAR_DARMANITAN]); + + const darmanitan = game.field.getPlayerPokemon(); + + game.move.select(MoveId.TACKLE); + await game.move.selectEnemyMove(MoveId.SPLASH); + await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]); + await game.move.forceMiss(); + await game.toEndOfTurn(); + + expect(darmanitan.isMoveRestricted(MoveId.SPLASH)).toBe(true); + expect(darmanitan.isMoveRestricted(MoveId.TACKLE)).toBe(false); + }); });