Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes spread damage in double battles #5064

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -8531,12 +8531,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:
Expand Down Expand Up @@ -9653,7 +9653,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);
}
Expand Down
34 changes: 34 additions & 0 deletions test/battle/damage_formula.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Loading