Skip to content

Commit

Permalink
Fixes Blunder Policy (#5722)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexOn1ine authored Nov 28, 2024
1 parent 88cdd8b commit 0cd0e0b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1767,8 +1767,6 @@ static void AccuracyCheck(bool32 recalcDragonDarts, const u8 *nextInstr, const u
if (!RandomPercentage(RNG_ACCURACY, accuracy))
{
gMoveResultFlags |= MOVE_RESULT_MISSED;
if (holdEffectAtk == HOLD_EFFECT_BLUNDER_POLICY)
gBattleStruct->blunderPolicy = TRUE; // Only activates from missing through acc/evasion checks

if (gMovesInfo[gCurrentMove].effect == EFFECT_DRAGON_DARTS
&& !recalcDragonDarts // So we don't jump back and forth between targets
Expand Down Expand Up @@ -2532,6 +2530,13 @@ static void Cmd_resultmessage(void)
return;
}

if (gMoveResultFlags & MOVE_RESULT_MISSED && !(gMoveResultFlags & (MOVE_RESULT_DOESNT_AFFECT_FOE | MOVE_RESULT_FAILED)))
{
if (GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_BLUNDER_POLICY
&& !IsBattlerProtected(gBattlerAttacker, gBattlerTarget, gCurrentMove))
gBattleStruct->blunderPolicy = TRUE; // Only activates from missing through acc/evasion checks
}

if (gMoveResultFlags & MOVE_RESULT_MISSED && (!(gMoveResultFlags & MOVE_RESULT_DOESNT_AFFECT_FOE) || gBattleCommunication[MISS_TYPE] > B_MSG_AVOIDED_ATK))
{
if (gBattleCommunication[MISS_TYPE] > B_MSG_AVOIDED_ATK) // Wonder Guard or Levitate - show the ability pop-up
Expand Down
67 changes: 67 additions & 0 deletions test/battle/hold_effect/blunder_policy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "global.h"
#include "test/battle.h"

ASSUMPTIONS
{
ASSUME(gItemsInfo[ITEM_BLUNDER_POLICY].holdEffect == HOLD_EFFECT_BLUNDER_POLICY);
}

SINGLE_BATTLE_TEST("Blunder Policy raises the users speed by 2 stages if the user misses")
{
PASSES_RANDOMLY(3, 10, RNG_ACCURACY);
GIVEN {
ASSUME(gMovesInfo[MOVE_FOCUS_BLAST].accuracy == 70);
PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_BLUNDER_POLICY); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_FOCUS_BLAST); }
} SCENE {
NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_FOCUS_BLAST, player);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
} THEN {
EXPECT(player->item == ITEM_NONE);
EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE + 2);
}
}


SINGLE_BATTLE_TEST("Blunder Policy will never trigger if the move fails due to an immunity")
{
PASSES_RANDOMLY(10, 10, RNG_ACCURACY);
GIVEN {
ASSUME(gMovesInfo[MOVE_FOCUS_BLAST].accuracy == 70);
PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_BLUNDER_POLICY); }
OPPONENT(SPECIES_GASTLY);
} WHEN {
TURN { MOVE(player, MOVE_FOCUS_BLAST); }
} SCENE {
NONE_OF {
ANIMATION(ANIM_TYPE_MOVE, MOVE_FOCUS_BLAST, player);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
}
} THEN {
EXPECT(player->item == ITEM_BLUNDER_POLICY);
EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE);
}
}

SINGLE_BATTLE_TEST("Blunder Policy will never trigger if the move fails due to Protect")
{
PASSES_RANDOMLY(10, 10, RNG_ACCURACY);
GIVEN {
ASSUME(gMovesInfo[MOVE_FOCUS_BLAST].accuracy == 70);
PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_BLUNDER_POLICY); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(opponent, MOVE_PROTECT); MOVE(player, MOVE_FOCUS_BLAST); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_PROTECT, opponent);
NONE_OF {
ANIMATION(ANIM_TYPE_MOVE, MOVE_FOCUS_BLAST, player);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
}
} THEN {
EXPECT(player->item == ITEM_BLUNDER_POLICY);
EXPECT_EQ(player->statStages[STAT_SPEED], DEFAULT_STAT_STAGE);
}
}

0 comments on commit 0cd0e0b

Please sign in to comment.