From 0cd0e0b00567c87f649ba9111f0092d6bb5fd9ea Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:24:38 +0100 Subject: [PATCH] Fixes Blunder Policy (#5722) --- src/battle_script_commands.c | 9 +++- test/battle/hold_effect/blunder_policy.c | 67 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 test/battle/hold_effect/blunder_policy.c diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 2ca3cd52f8..7a9409d4d4 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -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 @@ -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 diff --git a/test/battle/hold_effect/blunder_policy.c b/test/battle/hold_effect/blunder_policy.c new file mode 100644 index 0000000000..552ad2f6fb --- /dev/null +++ b/test/battle/hold_effect/blunder_policy.c @@ -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); + } +}