From 9d30299148134f02b69852b1191792d56afd76af Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Tue, 31 Dec 2024 00:38:01 +0100 Subject: [PATCH] Fixes Stance Change, Sleep Talk interaction (#5909) --- include/battle_util.h | 2 ++ src/battle_script_commands.c | 17 ----------------- src/battle_util.c | 23 +++++++++++++++++++++++ test/battle/ability/stance_change.c | 1 - 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index 82f4ed2ce126..fc3840e800a6 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -101,6 +101,7 @@ enum { CANCELLER_FLAGS, CANCELLER_SKY_DROP, + CANCELLER_STANCE_CHANGE_1, CANCELLER_ASLEEP, CANCELLER_FROZEN, CANCELLER_OBEDIENCE, @@ -117,6 +118,7 @@ enum CANCELLER_IN_LOVE, CANCELLER_BIDE, CANCELLER_THAW, + CANCELLER_STANCE_CHANGE_2, CANCELLER_POWDER_MOVE, CANCELLER_POWDER_STATUS, CANCELLER_THROAT_CHOP, diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 40f9db64c615..055f9e9c3b2d 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1125,19 +1125,6 @@ static bool32 NoTargetPresent(u8 battler, u32 move) return FALSE; } -static bool32 TryFormChangeBeforeMove(void) -{ - bool32 result = TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_BEFORE_MOVE); - if (!result) - result = TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_BEFORE_MOVE_CATEGORY); - if (!result) - return FALSE; - - BattleScriptPushCursor(); - gBattlescriptCurrInstr = BattleScript_AttackerFormChange; - return TRUE; -} - bool32 ProteanTryChangeType(u32 battler, u32 ability, u32 move, u32 moveType) { if ((ability == ABILITY_PROTEAN || ability == ABILITY_LIBERO) @@ -1206,8 +1193,6 @@ static void Cmd_attackcanceler(void) gBattlescriptCurrInstr = BattleScript_MoveEnd; return; } - if (B_STANCE_CHANGE_FAIL < GEN_7 && TryFormChangeBeforeMove()) - return; if (AtkCanceller_UnableToUseMove(moveType)) return; @@ -1267,8 +1252,6 @@ static void Cmd_attackcanceler(void) gMoveResultFlags |= MOVE_RESULT_MISSED; return; } - if (B_STANCE_CHANGE_FAIL >= GEN_7 && TryFormChangeBeforeMove()) - return; gHitMarker &= ~HITMARKER_ALLOW_NO_PP; diff --git a/src/battle_util.c b/src/battle_util.c index 66e219fff5aa..535c026145af 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -3209,6 +3209,19 @@ void SetAtkCancellerForCalledMove(void) gBattleStruct->isAtkCancelerForCalledMove = TRUE; } +static inline bool32 TryFormChangeBeforeMove(void) +{ + bool32 result = TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_BEFORE_MOVE); + if (!result) + result = TryBattleFormChange(gBattlerAttacker, FORM_CHANGE_BATTLE_BEFORE_MOVE_CATEGORY); + if (!result) + return FALSE; + + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_AttackerFormChange; + return TRUE; +} + u8 AtkCanceller_UnableToUseMove(u32 moveType) { u32 effect = 0; @@ -3233,6 +3246,11 @@ u8 AtkCanceller_UnableToUseMove(u32 moveType) } gBattleStruct->atkCancellerTracker++; break; + case CANCELLER_STANCE_CHANGE_1: + if (B_STANCE_CHANGE_FAIL < GEN_7 && TryFormChangeBeforeMove()) + effect = 1; + gBattleStruct->atkCancellerTracker++; + break; case CANCELLER_ASLEEP: // check being asleep if (gBattleMons[gBattlerAttacker].status1 & STATUS1_SLEEP) { @@ -3573,6 +3591,11 @@ u8 AtkCanceller_UnableToUseMove(u32 moveType) } gBattleStruct->atkCancellerTracker++; break; + case CANCELLER_STANCE_CHANGE_2: + if (B_STANCE_CHANGE_FAIL >= GEN_7 && TryFormChangeBeforeMove()) + effect = 1; + gBattleStruct->atkCancellerTracker++; + break; case CANCELLER_POWDER_MOVE: if ((gMovesInfo[gCurrentMove].powderMove) && (gBattlerAttacker != gBattlerTarget)) { diff --git a/test/battle/ability/stance_change.c b/test/battle/ability/stance_change.c index 8221e16385b4..f8a0c70b3e48 100644 --- a/test/battle/ability/stance_change.c +++ b/test/battle/ability/stance_change.c @@ -63,7 +63,6 @@ SINGLE_BATTLE_TEST("Stance Change changes Aegislash from Blade to Shield when us SINGLE_BATTLE_TEST("Stance Change doesn't change Aegislash to Shield if King's Shield is called by a different move - Sleep Talk") { - KNOWN_FAILING; // Currently does change form GIVEN { ASSUME(gMovesInfo[MOVE_SLEEP_TALK].effect == EFFECT_SLEEP_TALK); PLAYER(SPECIES_AEGISLASH_BLADE) { Moves(MOVE_KINGS_SHIELD, MOVE_SLEEP_TALK); Status1(STATUS1_SLEEP_TURN(3)); }