From b93976c980bcf833b26fb953f3611ce2465a9aec Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Sun, 23 Mar 2025 23:34:24 +0100 Subject: [PATCH] Fixes Cheek Pouch mutating damage (#6466) --- include/battle.h | 3 ++- src/battle_script_commands.c | 14 ++++++++++++++ test/battle/ability/cheeck_pouch.c | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/battle/ability/cheeck_pouch.c diff --git a/include/battle.h b/include/battle.h index a6ba6d92e5..267abdc7f2 100644 --- a/include/battle.h +++ b/include/battle.h @@ -815,7 +815,8 @@ struct BattleStruct u8 monCausingSleepClause[NUM_BATTLE_SIDES]; // Stores which pokemon on a given side is causing Sleep Clause to be active as the mon's index in the party u8 additionalEffectsCounter:4; // A counter for the additionalEffects applied by the current move in Cmd_setadditionaleffects u8 redCardActivates:1; - u8 padding2:2; // padding in the middle so pursuit fields are together + u8 cheekPouchActivated:1; + u8 padding2:1; // padding in the middle so pursuit fields are together u8 pursuitStoredSwitch; // Stored id for the Pursuit target's switch s32 battlerExpReward; u16 prevTurnSpecies[MAX_BATTLERS_COUNT]; // Stores species the AI has in play at start of turn diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 7c6b95352d..62ae2184ee 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -345,6 +345,7 @@ static u32 GetNextTarget(u32 moveTarget, bool32 excludeCurrent); static void TryUpdateEvolutionTracker(u32 evolutionMethod, u32 upAmount, u16 usedMove); static void AccuracyCheck(bool32 recalcDragonDarts, const u8 *nextInstr, const u8 *failInstr, u16 move); static void ResetValuesForCalledMove(void); +static void TryRestoreDamageAfterCheeckPouch(u32 battler); static void Cmd_attackcanceler(void); static void Cmd_accuracycheck(void); @@ -2669,6 +2670,7 @@ static void Cmd_datahpupdate(void) } } + TryRestoreDamageAfterCheeckPouch(battler); gBattlescriptCurrInstr = cmd->nextInstr; } @@ -8929,6 +8931,8 @@ static bool32 TryCheekPouch(u32 battler, u32 itemId) && gBattleStruct->ateBerry[GetBattlerSide(battler)] & (1u << gBattlerPartyIndexes[battler]) && !IsBattlerAtMaxHp(battler)) { + gBattleStruct->cheekPouchActivated = TRUE; + gBattleScripting.savedDmg = gBattleStruct->moveDamage[battler]; gBattleStruct->moveDamage[battler] = GetNonDynamaxMaxHP(battler) / 3; if (gBattleStruct->moveDamage[battler] == 0) gBattleStruct->moveDamage[battler] = 1; @@ -8941,6 +8945,16 @@ static bool32 TryCheekPouch(u32 battler, u32 itemId) return FALSE; } +// When Cheek Pouch activates mid-battle it overwrites the current damage, so restore it +static void TryRestoreDamageAfterCheeckPouch(u32 battler) +{ + if (gBattleStruct->cheekPouchActivated) + { + gBattleStruct->moveDamage[battler] = gBattleScripting.savedDmg; + gBattleStruct->cheekPouchActivated = FALSE; + } +} + // Used by Bestow and Symbiosis to take an item from one battler and give to another. static void BestowItem(u32 battlerAtk, u32 battlerDef) { diff --git a/test/battle/ability/cheeck_pouch.c b/test/battle/ability/cheeck_pouch.c new file mode 100644 index 0000000000..3c932c4aa1 --- /dev/null +++ b/test/battle/ability/cheeck_pouch.c @@ -0,0 +1,21 @@ +#include "global.h" +#include "test/battle.h" + +SINGLE_BATTLE_TEST("Cheek Pouch activation doesn't mutate damage when restoring HP mid battle") +{ + s16 damage; + s16 healing; + + GIVEN { + PLAYER(SPECIES_GREEDENT) { Ability(ABILITY_CHEEK_POUCH); Item(ITEM_CHOPLE_BERRY); HP(100); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_KARATE_CHOP); } + ABILITY_POPUP(player, ABILITY_CHEEK_POUCH); + HP_BAR(player, captureDamage: &healing); + HP_BAR(player, captureDamage: &damage); + } THEN { + EXPECT_LT(healing, 0); + EXPECT_GT(damage, 0); + } +}