From 9f3944a03e002c98cdf4c38cb38255f3a8478977 Mon Sep 17 00:00:00 2001 From: KyleLaporte Date: Fri, 8 Nov 2024 16:24:10 -0500 Subject: [PATCH 1/7] Gen 7+ Destiny Bond --- asm/macros/battle_script.inc | 3 ++- data/battle_scripts_1.s | 2 +- include/battle.h | 1 + src/battle_ai_main.c | 2 ++ src/battle_script_commands.c | 22 ++++++++++++++++------ test/battle/move_effect/destiny_bond.c | 22 ++++++++++++++++++++++ 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index c63c2de5426f..810b386cc0de 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -930,8 +930,9 @@ .4byte \failInstr .endm - .macro setdestinybond + .macro trysetdestinybond failInstr:req .byte 0xaa + .4byte \failInstr .endm .macro trysetdestinybondtohappen diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 19328b7189e6..f68ed53f79a8 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -4063,7 +4063,7 @@ BattleScript_EffectDestinyBond:: attackcanceler attackstring ppreduce - setdestinybond + trysetdestinybond BattleScript_ButItFailed attackanimation waitanimation printstring STRINGID_PKMNTRYINGTOTAKEFOE diff --git a/include/battle.h b/include/battle.h index f7b41b3dce8b..2e47f2dd2fa6 100644 --- a/include/battle.h +++ b/include/battle.h @@ -152,6 +152,7 @@ struct DisableStruct u8 weatherAbilityDone:1; u8 terrainAbilityDone:1; u8 usedProteanLibero:1; + u8 usedDestinyBond:1; }; struct ProtectStruct diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 3c031de092c7..b75ac579b02c 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -1873,6 +1873,8 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score) ADJUST_SCORE(-10); break; case EFFECT_DESTINY_BOND: + if (B_UPDATED_MOVE_DATA >= GEN_7 && gDisableStructs[battlerAtk].usedDestinyBond) + ADJUST_SCORE(-10); if (gBattleMons[battlerDef].status2 & STATUS2_DESTINY_BOND) ADJUST_SCORE(-10); else if (GetActiveGimmick(battlerDef) == GIMMICK_DYNAMAX) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9ea2920bb930..eab5cee51524 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -508,7 +508,7 @@ static void Cmd_settypetorandomresistance(void); static void Cmd_setalwayshitflag(void); static void Cmd_copymovepermanently(void); static void Cmd_trychoosesleeptalkmove(void); -static void Cmd_setdestinybond(void); +static void Cmd_trysetdestinybond(void); static void Cmd_trysetdestinybondtohappen(void); static void Cmd_settailwind(void); static void Cmd_tryspiteppreduce(void); @@ -767,7 +767,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_setalwayshitflag, //0xA7 Cmd_copymovepermanently, //0xA8 Cmd_trychoosesleeptalkmove, //0xA9 - Cmd_setdestinybond, //0xAA + Cmd_trysetdestinybond, //0xAA Cmd_trysetdestinybondtohappen, //0xAB Cmd_settailwind, //0xAC Cmd_tryspiteppreduce, //0xAD @@ -13144,12 +13144,22 @@ static void Cmd_trychoosesleeptalkmove(void) } } -static void Cmd_setdestinybond(void) +static void Cmd_trysetdestinybond(void) { - CMD_ARGS(); + CMD_ARGS(const u8 *failInstr); - gBattleMons[gBattlerAttacker].status2 |= STATUS2_DESTINY_BOND; - gBattlescriptCurrInstr = cmd->nextInstr; + if (B_UPDATED_MOVE_DATA >= GEN_7 && gDisableStructs[gBattlerAttacker].usedDestinyBond) + { + gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; + gBattlescriptCurrInstr = cmd->failInstr; + } + else + { + if (B_UPDATED_MOVE_DATA >= GEN_7) + gDisableStructs[gBattlerAttacker].usedDestinyBond = TRUE; + gBattleMons[gBattlerAttacker].status2 |= STATUS2_DESTINY_BOND; + gBattlescriptCurrInstr = cmd->nextInstr; + } } static void TrySetDestinyBondToHappen(void) diff --git a/test/battle/move_effect/destiny_bond.c b/test/battle/move_effect/destiny_bond.c index ba49e0ec431a..2cb008bac731 100644 --- a/test/battle/move_effect/destiny_bond.c +++ b/test/battle/move_effect/destiny_bond.c @@ -1,6 +1,10 @@ #include "global.h" #include "test/battle.h" +ASSUMPTIONS { + gMovesInfo[MOVE_DESTINY_BOND].effect == EFFECT_DESTINY_BOND; +} + SINGLE_BATTLE_TEST("Destiny Bond faints the opposing mon if it fainted from the attack") { GIVEN { @@ -15,3 +19,21 @@ SINGLE_BATTLE_TEST("Destiny Bond faints the opposing mon if it fainted from the MESSAGE("The opposing Wobbuffet fainted!"); } } + +SINGLE_BATTLE_TEST("Destiny Bond fails if used sequentially in Gen 7+") +{ + GIVEN { + ASSUME(B_UPDATED_MOVE_DATA >= GEN_7); + PLAYER(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + } WHEN { + TURN { MOVE(player, MOVE_DESTINY_BOND); } + TURN { MOVE(player, MOVE_DESTINY_BOND); SWITCH(opponent, 1); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); + MESSAGE("2 sent out Zigzagoon!"); + NOT { ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); } + MESSAGE("But it failed!"); + } +} From e45b389f891c4be68f5ed60ee40c08a46d2954b4 Mon Sep 17 00:00:00 2001 From: KyleLaporte Date: Fri, 8 Nov 2024 16:33:20 -0500 Subject: [PATCH 2/7] Fix ASSUME --- test/battle/move_effect/destiny_bond.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/battle/move_effect/destiny_bond.c b/test/battle/move_effect/destiny_bond.c index 2cb008bac731..ed08ad4d084d 100644 --- a/test/battle/move_effect/destiny_bond.c +++ b/test/battle/move_effect/destiny_bond.c @@ -1,8 +1,9 @@ #include "global.h" #include "test/battle.h" -ASSUMPTIONS { - gMovesInfo[MOVE_DESTINY_BOND].effect == EFFECT_DESTINY_BOND; +ASSUMPTIONS +{ + ASSUME(gMovesInfo[MOVE_DESTINY_BOND].effect == EFFECT_DESTINY_BOND); } SINGLE_BATTLE_TEST("Destiny Bond faints the opposing mon if it fainted from the attack") From bd6573bb093e32f2a8b842f0cabad0e1ccfa67bf Mon Sep 17 00:00:00 2001 From: KyleLaporte Date: Fri, 8 Nov 2024 16:38:09 -0500 Subject: [PATCH 3/7] Specific config --- include/config/battle.h | 1 + src/battle_ai_main.c | 2 +- src/battle_script_commands.c | 4 ++-- test/battle/move_effect/destiny_bond.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/config/battle.h b/include/config/battle.h index 7467bd47f110..9466bfcb62d3 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -125,6 +125,7 @@ #define B_POWDER_RAIN GEN_LATEST // In Gen7+, Powder doesn't damage the user of a Fire type move in heavy rain. #define B_AFTER_YOU_TURN_ORDER GEN_LATEST // In Gen8+, After You doesn't fail if the turn order wouldn't change after use. #define B_QUASH_TURN_ORDER GEN_LATEST // In Gen8+, Quash-affected battlers move according to speed order. Before Gen8, Quash-affected battlers move in the order they were affected by Quash. +#define B_DESTINY_BOND_FAIL GEN_LATEST // In Gen7+, Destiny Bond fails if used repeatedly. // Ability settings #define B_ABILITY_WEATHER GEN_LATEST // In Gen6+, ability-induced weather lasts 5 turns. Before, it lasted until the battle ended or until it was changed by a move or a different weather-affecting ability. diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index b75ac579b02c..6d0829b6b2c7 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -1873,7 +1873,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score) ADJUST_SCORE(-10); break; case EFFECT_DESTINY_BOND: - if (B_UPDATED_MOVE_DATA >= GEN_7 && gDisableStructs[battlerAtk].usedDestinyBond) + if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[battlerAtk].usedDestinyBond) ADJUST_SCORE(-10); if (gBattleMons[battlerDef].status2 & STATUS2_DESTINY_BOND) ADJUST_SCORE(-10); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index eab5cee51524..c1f885c5b1e5 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13148,14 +13148,14 @@ static void Cmd_trysetdestinybond(void) { CMD_ARGS(const u8 *failInstr); - if (B_UPDATED_MOVE_DATA >= GEN_7 && gDisableStructs[gBattlerAttacker].usedDestinyBond) + if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[gBattlerAttacker].usedDestinyBond) { gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; gBattlescriptCurrInstr = cmd->failInstr; } else { - if (B_UPDATED_MOVE_DATA >= GEN_7) + if (B_DESTINY_BOND_FAIL >= GEN_7) gDisableStructs[gBattlerAttacker].usedDestinyBond = TRUE; gBattleMons[gBattlerAttacker].status2 |= STATUS2_DESTINY_BOND; gBattlescriptCurrInstr = cmd->nextInstr; diff --git a/test/battle/move_effect/destiny_bond.c b/test/battle/move_effect/destiny_bond.c index ed08ad4d084d..cd9afbbda9bf 100644 --- a/test/battle/move_effect/destiny_bond.c +++ b/test/battle/move_effect/destiny_bond.c @@ -24,7 +24,7 @@ SINGLE_BATTLE_TEST("Destiny Bond faints the opposing mon if it fainted from the SINGLE_BATTLE_TEST("Destiny Bond fails if used sequentially in Gen 7+") { GIVEN { - ASSUME(B_UPDATED_MOVE_DATA >= GEN_7); + ASSUME(B_DESTINY_BOND_FAIL >= GEN_7); PLAYER(SPECIES_ZIGZAGOON); OPPONENT(SPECIES_ZIGZAGOON); OPPONENT(SPECIES_ZIGZAGOON); From e97776cc91eb01938a65358ea86671f252d45288 Mon Sep 17 00:00:00 2001 From: KyleLaporte Date: Fri, 8 Nov 2024 20:53:01 -0500 Subject: [PATCH 4/7] Fix alternating moves --- include/battle.h | 1 - src/battle_ai_main.c | 2 +- src/battle_script_commands.c | 5 +---- test/battle/move_effect/destiny_bond.c | 19 +++++++++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/battle.h b/include/battle.h index 2e47f2dd2fa6..f7b41b3dce8b 100644 --- a/include/battle.h +++ b/include/battle.h @@ -152,7 +152,6 @@ struct DisableStruct u8 weatherAbilityDone:1; u8 terrainAbilityDone:1; u8 usedProteanLibero:1; - u8 usedDestinyBond:1; }; struct ProtectStruct diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 6d0829b6b2c7..36cb434fa4f6 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -1873,7 +1873,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score) ADJUST_SCORE(-10); break; case EFFECT_DESTINY_BOND: - if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[battlerAtk].usedDestinyBond) + if (B_DESTINY_BOND_FAIL >= GEN_7 && gMovesInfo[gLastResultingMoves[battlerAtk]].effect == EFFECT_DESTINY_BOND) ADJUST_SCORE(-10); if (gBattleMons[battlerDef].status2 & STATUS2_DESTINY_BOND) ADJUST_SCORE(-10); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c1f885c5b1e5..9a4dcba322e0 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13148,15 +13148,12 @@ static void Cmd_trysetdestinybond(void) { CMD_ARGS(const u8 *failInstr); - if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[gBattlerAttacker].usedDestinyBond) + if (B_DESTINY_BOND_FAIL >= GEN_7 && gMovesInfo[gLastResultingMoves[gBattlerAttacker]].effect == EFFECT_DESTINY_BOND) { - gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; gBattlescriptCurrInstr = cmd->failInstr; } else { - if (B_DESTINY_BOND_FAIL >= GEN_7) - gDisableStructs[gBattlerAttacker].usedDestinyBond = TRUE; gBattleMons[gBattlerAttacker].status2 |= STATUS2_DESTINY_BOND; gBattlescriptCurrInstr = cmd->nextInstr; } diff --git a/test/battle/move_effect/destiny_bond.c b/test/battle/move_effect/destiny_bond.c index cd9afbbda9bf..3a116f7c3fca 100644 --- a/test/battle/move_effect/destiny_bond.c +++ b/test/battle/move_effect/destiny_bond.c @@ -38,3 +38,22 @@ SINGLE_BATTLE_TEST("Destiny Bond fails if used sequentially in Gen 7+") MESSAGE("But it failed!"); } } + +SINGLE_BATTLE_TEST("Destiny Bond does not fail if used repeatedly separated by other moves in Gen 7+") +{ + GIVEN { + ASSUME(B_DESTINY_BOND_FAIL >= GEN_7); + PLAYER(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + } WHEN { + TURN { MOVE(player, MOVE_DESTINY_BOND); } + TURN { MOVE(player, MOVE_GROWL); SWITCH(opponent, 1); } + TURN { MOVE(player, MOVE_DESTINY_BOND); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); + MESSAGE("2 sent out Zigzagoon!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); + NOT { MESSAGE("But it failed!"); } + } +} From ee81babff9bba79a63c7e248a01239ae93b9b0f8 Mon Sep 17 00:00:00 2001 From: KyleLaporte Date: Sat, 9 Nov 2024 00:01:52 -0500 Subject: [PATCH 5/7] Revert "Fix alternating moves" This reverts commit e97776cc91eb01938a65358ea86671f252d45288. --- include/battle.h | 1 + src/battle_ai_main.c | 2 +- src/battle_script_commands.c | 5 ++++- test/battle/move_effect/destiny_bond.c | 19 ------------------- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/include/battle.h b/include/battle.h index f7b41b3dce8b..2e47f2dd2fa6 100644 --- a/include/battle.h +++ b/include/battle.h @@ -152,6 +152,7 @@ struct DisableStruct u8 weatherAbilityDone:1; u8 terrainAbilityDone:1; u8 usedProteanLibero:1; + u8 usedDestinyBond:1; }; struct ProtectStruct diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 36cb434fa4f6..6d0829b6b2c7 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -1873,7 +1873,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score) ADJUST_SCORE(-10); break; case EFFECT_DESTINY_BOND: - if (B_DESTINY_BOND_FAIL >= GEN_7 && gMovesInfo[gLastResultingMoves[battlerAtk]].effect == EFFECT_DESTINY_BOND) + if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[battlerAtk].usedDestinyBond) ADJUST_SCORE(-10); if (gBattleMons[battlerDef].status2 & STATUS2_DESTINY_BOND) ADJUST_SCORE(-10); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9a4dcba322e0..c1f885c5b1e5 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13148,12 +13148,15 @@ static void Cmd_trysetdestinybond(void) { CMD_ARGS(const u8 *failInstr); - if (B_DESTINY_BOND_FAIL >= GEN_7 && gMovesInfo[gLastResultingMoves[gBattlerAttacker]].effect == EFFECT_DESTINY_BOND) + if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[gBattlerAttacker].usedDestinyBond) { + gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; gBattlescriptCurrInstr = cmd->failInstr; } else { + if (B_DESTINY_BOND_FAIL >= GEN_7) + gDisableStructs[gBattlerAttacker].usedDestinyBond = TRUE; gBattleMons[gBattlerAttacker].status2 |= STATUS2_DESTINY_BOND; gBattlescriptCurrInstr = cmd->nextInstr; } diff --git a/test/battle/move_effect/destiny_bond.c b/test/battle/move_effect/destiny_bond.c index 3a116f7c3fca..cd9afbbda9bf 100644 --- a/test/battle/move_effect/destiny_bond.c +++ b/test/battle/move_effect/destiny_bond.c @@ -38,22 +38,3 @@ SINGLE_BATTLE_TEST("Destiny Bond fails if used sequentially in Gen 7+") MESSAGE("But it failed!"); } } - -SINGLE_BATTLE_TEST("Destiny Bond does not fail if used repeatedly separated by other moves in Gen 7+") -{ - GIVEN { - ASSUME(B_DESTINY_BOND_FAIL >= GEN_7); - PLAYER(SPECIES_ZIGZAGOON); - OPPONENT(SPECIES_ZIGZAGOON); - OPPONENT(SPECIES_ZIGZAGOON); - } WHEN { - TURN { MOVE(player, MOVE_DESTINY_BOND); } - TURN { MOVE(player, MOVE_GROWL); SWITCH(opponent, 1); } - TURN { MOVE(player, MOVE_DESTINY_BOND); } - } SCENE { - ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); - MESSAGE("2 sent out Zigzagoon!"); - ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); - NOT { MESSAGE("But it failed!"); } - } -} From 57a569d26d44b08283b3d823563f6298bef0dee0 Mon Sep 17 00:00:00 2001 From: KyleLaporte Date: Sat, 9 Nov 2024 00:22:07 -0500 Subject: [PATCH 6/7] Fix repeated use bug --- src/battle_script_commands.c | 3 ++ test/battle/move_effect/destiny_bond.c | 39 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c1f885c5b1e5..a93d5d0893fd 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13148,6 +13148,9 @@ static void Cmd_trysetdestinybond(void) { CMD_ARGS(const u8 *failInstr); + if (gMovesInfo[gLastResultingMoves[gBattlerAttacker]].effect != EFFECT_DESTINY_BOND) + gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; + if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[gBattlerAttacker].usedDestinyBond) { gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; diff --git a/test/battle/move_effect/destiny_bond.c b/test/battle/move_effect/destiny_bond.c index cd9afbbda9bf..7291fe7fb3e4 100644 --- a/test/battle/move_effect/destiny_bond.c +++ b/test/battle/move_effect/destiny_bond.c @@ -38,3 +38,42 @@ SINGLE_BATTLE_TEST("Destiny Bond fails if used sequentially in Gen 7+") MESSAGE("But it failed!"); } } + +SINGLE_BATTLE_TEST("Destiny Bond does not fail if used repeatedly separated by other moves in Gen 7+") +{ + GIVEN { + ASSUME(B_DESTINY_BOND_FAIL >= GEN_7); + PLAYER(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + } WHEN { + TURN { MOVE(player, MOVE_DESTINY_BOND); } + TURN { MOVE(player, MOVE_GROWL); SWITCH(opponent, 1); } + TURN { MOVE(player, MOVE_DESTINY_BOND); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); + MESSAGE("2 sent out Zigzagoon!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); + NOT { MESSAGE("But it failed!"); } + } +} + +SINGLE_BATTLE_TEST("Destiny Bond does not fail if used after failing in Gen 7+") +{ + GIVEN { + ASSUME(B_DESTINY_BOND_FAIL >= GEN_7); + PLAYER(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + OPPONENT(SPECIES_ZIGZAGOON); + } WHEN { + TURN { MOVE(player, MOVE_DESTINY_BOND); } + TURN { MOVE(player, MOVE_DESTINY_BOND); SWITCH(opponent, 1); } + TURN { MOVE(player, MOVE_DESTINY_BOND); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); + MESSAGE("2 sent out Zigzagoon!"); + NOT { ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); } + MESSAGE("But it failed!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_DESTINY_BOND, player); + } +} From 2ee98356bbb69b4b3f94c34979ae85b64fef35a7 Mon Sep 17 00:00:00 2001 From: KyleLaporte Date: Sat, 9 Nov 2024 13:05:52 -0500 Subject: [PATCH 7/7] use lastMoveFailed --- include/battle.h | 1 - include/battle_util.h | 1 + src/battle_ai_main.c | 2 +- src/battle_script_commands.c | 9 +-------- src/battle_util.c | 9 +++++++++ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/battle.h b/include/battle.h index 2e47f2dd2fa6..f7b41b3dce8b 100644 --- a/include/battle.h +++ b/include/battle.h @@ -152,7 +152,6 @@ struct DisableStruct u8 weatherAbilityDone:1; u8 terrainAbilityDone:1; u8 usedProteanLibero:1; - u8 usedDestinyBond:1; }; struct ProtectStruct diff --git a/include/battle_util.h b/include/battle_util.h index e2dd9ac826d1..2e9653793e0e 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -312,5 +312,6 @@ bool8 CanMonParticipateInSkyBattle(struct Pokemon *mon); bool8 IsMonBannedFromSkyBattles(u16 species); void RemoveBattlerType(u32 battler, u8 type); u32 GetMoveType(u32 move); +u32 DoesDestinyBondFail(u32 battler); #endif // GUARD_BATTLE_UTIL_H diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 6d0829b6b2c7..6c2723504309 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -1873,7 +1873,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score) ADJUST_SCORE(-10); break; case EFFECT_DESTINY_BOND: - if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[battlerAtk].usedDestinyBond) + if (DoesDestinyBondFail(battlerAtk)) ADJUST_SCORE(-10); if (gBattleMons[battlerDef].status2 & STATUS2_DESTINY_BOND) ADJUST_SCORE(-10); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index a93d5d0893fd..43816bfb9334 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -13147,19 +13147,12 @@ static void Cmd_trychoosesleeptalkmove(void) static void Cmd_trysetdestinybond(void) { CMD_ARGS(const u8 *failInstr); - - if (gMovesInfo[gLastResultingMoves[gBattlerAttacker]].effect != EFFECT_DESTINY_BOND) - gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; - - if (B_DESTINY_BOND_FAIL >= GEN_7 && gDisableStructs[gBattlerAttacker].usedDestinyBond) + if (DoesDestinyBondFail(gBattlerAttacker)) { - gDisableStructs[gBattlerAttacker].usedDestinyBond = FALSE; gBattlescriptCurrInstr = cmd->failInstr; } else { - if (B_DESTINY_BOND_FAIL >= GEN_7) - gDisableStructs[gBattlerAttacker].usedDestinyBond = TRUE; gBattleMons[gBattlerAttacker].status2 |= STATUS2_DESTINY_BOND; gBattlescriptCurrInstr = cmd->nextInstr; } diff --git a/src/battle_util.c b/src/battle_util.c index 1e5f809c52f0..9d576415b790 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -11923,3 +11923,12 @@ u32 GetMoveType(u32 move) return TYPE_MYSTERY; return gMovesInfo[move].type; } + +bool32 DoesDestinyBondFail(u32 battler) +{ + if (B_DESTINY_BOND_FAIL >= GEN_7 + && gMovesInfo[gLastResultingMoves[battler]].effect == EFFECT_DESTINY_BOND + && !(gBattleStruct->lastMoveFailed & (1u << battler))) + return TRUE; + return FALSE; +}