From e6175b5b84ad206d65dff5c1c323c90cba125af1 Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:20:57 +0200 Subject: [PATCH] Fixes spread damage in double battles (#5064) * Fixes spread move damage in doubles * add DoubleBattle check * add additional check to test * restore trainer party --- src/battle_util.c | 12 ++++++------ test/battle/damage_formula.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/battle_util.c b/src/battle_util.c index ff9e34469f..d39392d267 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -8532,12 +8532,12 @@ u32 GetMoveTargetCount(u32 move, u32 battlerAtk, u32 battlerDef) switch (GetBattlerMoveTargetType(gBattlerAttacker, move)) { case MOVE_TARGET_BOTH: - return IsBattlerAlive(battlerDef) - + IsBattlerAlive(BATTLE_PARTNER(battlerDef)); + return !(gAbsentBattlerFlags & gBitTable[battlerDef]) + + !(gAbsentBattlerFlags & gBitTable[BATTLE_PARTNER(battlerDef)]); case MOVE_TARGET_FOES_AND_ALLY: - return IsBattlerAlive(battlerDef) - + IsBattlerAlive(BATTLE_PARTNER(battlerDef)) - + IsBattlerAlive(BATTLE_PARTNER(battlerAtk)); + return !(gAbsentBattlerFlags & gBitTable[battlerDef]) + + !(gAbsentBattlerFlags & gBitTable[BATTLE_PARTNER(battlerDef)]) + + !(gAbsentBattlerFlags & gBitTable[BATTLE_PARTNER(battlerAtk)]); case MOVE_TARGET_OPPONENTS_FIELD: return 1; case MOVE_TARGET_DEPENDS: @@ -9654,7 +9654,7 @@ static inline s32 CalculateBaseDamage(u32 power, u32 userFinalAttack, u32 level, static inline uq4_12_t GetTargetDamageModifier(u32 move, u32 battlerAtk, u32 battlerDef) { - if (GetMoveTargetCount(move, battlerAtk, battlerDef) >= 2) + if (IsDoubleBattle() && GetMoveTargetCount(move, battlerAtk, battlerDef) >= 2) return B_MULTIPLE_TARGETS_DMG >= GEN_4 ? UQ_4_12(0.75) : UQ_4_12(0.5); return UQ_4_12(1.0); } diff --git a/test/battle/damage_formula.c b/test/battle/damage_formula.c index 2fdb9bed0f..3a58f69d90 100644 --- a/test/battle/damage_formula.c +++ b/test/battle/damage_formula.c @@ -116,3 +116,37 @@ SINGLE_BATTLE_TEST("Damage calculation matches Gen5+ (Marshadow vs Mawile)") EXPECT_EQ(expectedDamage, dmg); } } + +DOUBLE_BATTLE_TEST("A spread move will do correct damage to the second mon if the first target faints from first hit of the spread move") +{ + s16 damage[6]; + GIVEN { + PLAYER(SPECIES_REGIROCK); + PLAYER(SPECIES_REGIROCK); + OPPONENT(SPECIES_WOBBUFFET) { HP(200); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(playerLeft, MOVE_ROCK_SLIDE); } + TURN { MOVE(playerLeft, MOVE_ROCK_SLIDE); MOVE(playerRight, MOVE_ROCK_SLIDE); } + TURN { MOVE(playerLeft, MOVE_ROCK_SLIDE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_ROCK_SLIDE, playerLeft); + HP_BAR(opponentLeft, captureDamage: &damage[0]); + HP_BAR(opponentRight, captureDamage: &damage[1]); + + ANIMATION(ANIM_TYPE_MOVE, MOVE_ROCK_SLIDE, playerLeft); + HP_BAR(opponentLeft, captureDamage: &damage[2]); + HP_BAR(opponentRight, captureDamage: &damage[3]); + + ANIMATION(ANIM_TYPE_MOVE, MOVE_ROCK_SLIDE, playerRight); + HP_BAR(opponentRight, captureDamage: &damage[4]); + + ANIMATION(ANIM_TYPE_MOVE, MOVE_ROCK_SLIDE, playerLeft); + HP_BAR(opponentRight, captureDamage: &damage[5]); + } THEN { + EXPECT_EQ(damage[0], damage[1]); + EXPECT_EQ(damage[1], damage[3]); + EXPECT_MUL_EQ(damage[5], UQ_4_12(0.75), damage[3]); + EXPECT_EQ(damage[4], damage[5]); + } +}