Fix Anger Shell activation (#3508)

This commit is contained in:
DizzyEggg 2023-11-01 14:55:50 +01:00 committed by GitHub
parent 7eb1b12224
commit 47341f3f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 5 deletions

View File

@ -645,7 +645,7 @@ struct BattleStruct
u8 lastMoveFailed; // as bits for each battler, for the sake of Stomping Tantrum u8 lastMoveFailed; // as bits for each battler, for the sake of Stomping Tantrum
u8 lastMoveTarget[MAX_BATTLERS_COUNT]; // The last target on which each mon used a move, for the sake of Instruct u8 lastMoveTarget[MAX_BATTLERS_COUNT]; // The last target on which each mon used a move, for the sake of Instruct
u16 tracedAbility[MAX_BATTLERS_COUNT]; u16 tracedAbility[MAX_BATTLERS_COUNT];
u16 hpBefore[MAX_BATTLERS_COUNT]; // Hp of battlers before using a move. For Berserk u16 hpBefore[MAX_BATTLERS_COUNT]; // Hp of battlers before using a move. For Berserk and Anger Shell.
bool8 spriteIgnore0Hp; bool8 spriteIgnore0Hp;
struct Illusion illusion[MAX_BATTLERS_COUNT]; struct Illusion illusion[MAX_BATTLERS_COUNT];
s32 aiFinalScore[MAX_BATTLERS_COUNT][MAX_BATTLERS_COUNT][MAX_MON_MOVES]; // AI, target, moves to make debugging easier s32 aiFinalScore[MAX_BATTLERS_COUNT][MAX_BATTLERS_COUNT][MAX_MON_MOVES]; // AI, target, moves to make debugging easier

View File

@ -4161,6 +4161,13 @@ static uq4_12_t GetSupremeOverlordModifier(u32 battler)
return modifier; return modifier;
} }
static bool32 HadMoreThanHalfHpNowHasLess(u32 battler)
{
// Had more than half of hp before, now has less
return (gBattleStruct->hpBefore[battler] >= gBattleMons[battler].maxHP / 2
&& gBattleMons[battler].hp < gBattleMons[battler].maxHP / 2);
}
u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 moveArg) u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 moveArg)
{ {
u32 effect = 0; u32 effect = 0;
@ -5192,9 +5199,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)
&& TARGET_TURN_DAMAGED && TARGET_TURN_DAMAGED
&& IsBattlerAlive(battler) && IsBattlerAlive(battler)
// Had more than half of hp before, now has less && HadMoreThanHalfHpNowHasLess(battler)
&& gBattleStruct->hpBefore[battler] >= gBattleMons[battler].maxHP / 2
&& gBattleMons[battler].hp < gBattleMons[battler].maxHP / 2
&& (gMultiHitCounter == 0 || gMultiHitCounter == 1) && (gMultiHitCounter == 0 || gMultiHitCounter == 1)
&& !(TestSheerForceFlag(gBattlerAttacker, gCurrentMove)) && !(TestSheerForceFlag(gBattlerAttacker, gCurrentMove))
&& CompareStat(battler, STAT_SPATK, MAX_STAT_STAGE, CMP_LESS_THAN)) && CompareStat(battler, STAT_SPATK, MAX_STAT_STAGE, CMP_LESS_THAN))
@ -5673,8 +5678,9 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)
&& !gProtectStructs[gBattlerAttacker].confusionSelfDmg && !gProtectStructs[gBattlerAttacker].confusionSelfDmg
&& TARGET_TURN_DAMAGED && TARGET_TURN_DAMAGED
&& (gMultiHitCounter == 0 || gMultiHitCounter == 1) // Activates after all hits from a multi-hit move.
&& IsBattlerAlive(gBattlerTarget) && IsBattlerAlive(gBattlerTarget)
&& (gBattleMons[gBattlerTarget].hp <= gBattleMons[gBattlerTarget].maxHP / 2) && HadMoreThanHalfHpNowHasLess(gBattlerTarget)
&& !(TestSheerForceFlag(gBattlerAttacker, gCurrentMove))) && !(TestSheerForceFlag(gBattlerAttacker, gCurrentMove)))
{ {
gBattlerAttacker = gBattlerTarget; gBattlerAttacker = gBattlerTarget;

View File

@ -0,0 +1,95 @@
#include "global.h"
#include "test/battle.h"
SINGLE_BATTLE_TEST("Anger Shell activates only if the target had more than 50% of its hp")
{
bool32 activates = FALSE;
u16 maxHp = 500, hp = 0;
PARAMETRIZE { hp = 249; activates = FALSE; }
PARAMETRIZE { hp = 100; activates = FALSE; }
PARAMETRIZE { hp = 50; activates = FALSE; }
PARAMETRIZE { hp = 251; activates = TRUE; }
PARAMETRIZE { hp = 255; activates = TRUE; }
GIVEN {
ASSUME(gBattleMoves[MOVE_TACKLE].power != 0);
PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_ANGER_SHELL); MaxHP(maxHp); HP(hp); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(opponent, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent);
if (activates) {
ABILITY_POPUP(player, ABILITY_ANGER_SHELL);
} else {
NOT ABILITY_POPUP(player, ABILITY_ANGER_SHELL);
}
} THEN {
if (activates) {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE - 1);
EXPECT_EQ(player->statStages[STAT_SPDEF], DEFAULT_STAT_STAGE - 1);
EXPECT_EQ(player->statStages[STAT_ATK], DEFAULT_STAT_STAGE + 1);
EXPECT_EQ(player->statStages[STAT_SPATK], DEFAULT_STAT_STAGE + 1);
EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE + 1);
}
}
}
SINGLE_BATTLE_TEST("Anger Shell lowers Def/Sp.Def by 1 and raises Atk/Sp.Atk/Spd by 1")
{
u16 maxHp = 500;
GIVEN {
ASSUME(gBattleMoves[MOVE_TACKLE].power != 0);
PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_ANGER_SHELL); MaxHP(maxHp); HP(maxHp / 2 + 1); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(opponent, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent);
ABILITY_POPUP(player, ABILITY_ANGER_SHELL);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, player);
MESSAGE("Wobbuffet's Defense fell!");
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, player);
MESSAGE("Wobbuffet's Sp. Def fell!");
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, player);
MESSAGE("Wobbuffet's Attack rose!");
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, player);
MESSAGE("Wobbuffet's Sp. Atk rose!");
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, player);
MESSAGE("Wobbuffet's Speed rose!");
} THEN {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE - 1);
EXPECT_EQ(player->statStages[STAT_SPDEF], DEFAULT_STAT_STAGE - 1);
EXPECT_EQ(player->statStages[STAT_ATK], DEFAULT_STAT_STAGE + 1);
EXPECT_EQ(player->statStages[STAT_SPATK], DEFAULT_STAT_STAGE + 1);
EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE + 1);
}
}
SINGLE_BATTLE_TEST("Anger Shell activates after all hits from a multi-hit move")
{
u32 j;
u16 maxHp = 500;
GIVEN {
ASSUME(gBattleMoves[MOVE_DOUBLE_SLAP].effect == EFFECT_MULTI_HIT);
PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_ANGER_SHELL); MaxHP(maxHp); HP(maxHp / 2 + 1); }
OPPONENT(SPECIES_SHELLDER) { Ability(ABILITY_SKILL_LINK); } // Always hits 5 times.
} WHEN {
TURN { MOVE(opponent, MOVE_DOUBLE_SLAP); }
} SCENE {
for (j = 0; j < 4; j++)
{
ANIMATION(ANIM_TYPE_MOVE, MOVE_DOUBLE_SLAP, opponent);
NOT ABILITY_POPUP(player, ABILITY_ANGER_SHELL);
}
ANIMATION(ANIM_TYPE_MOVE, MOVE_DOUBLE_SLAP, opponent);
ABILITY_POPUP(player, ABILITY_ANGER_SHELL);
} THEN {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE - 1);
EXPECT_EQ(player->statStages[STAT_SPDEF], DEFAULT_STAT_STAGE - 1);
EXPECT_EQ(player->statStages[STAT_ATK], DEFAULT_STAT_STAGE + 1);
EXPECT_EQ(player->statStages[STAT_SPATK], DEFAULT_STAT_STAGE + 1);
EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE + 1);
}
}