From 45d063dcf80a255a59ede5dbb231789b2c0bcbef Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Sat, 2 Nov 2024 13:38:29 +0100 Subject: [PATCH] Fixes Dragon Tail using the effect twice during a Parental Bond attack (#5630) Co-authored-by: Eduardo Quezada --- asm/macros/battle_script.inc | 10 +- include/constants/battle_script_commands.h | 191 ++++++++++----------- src/battle_script_commands.c | 40 +++-- test/battle/ability/parental_bond.c | 20 +++ 4 files changed, 141 insertions(+), 120 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index c9f9b28bef..986d373c6b 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1685,6 +1685,11 @@ .4byte \failInstr .endm + .macro tryhitswitchtarget failInstr:req + callnative BS_TryHitSwitchTarget + .4byte \failInstr + .endm + @ various command changed to more readable macros .macro cancelmultiturnmoves battler:req various \battler, VARIOUS_CANCEL_MULTI_TURN_MOVES @@ -1916,11 +1921,6 @@ various BS_ATTACKER, VARIOUS_SET_ARG_TO_BATTLE_DAMAGE .endm - .macro tryhitswitchtarget failInstr:req - various BS_ATTACKER, VARIOUS_TRY_HIT_SWITCH_TARGET - .4byte \failInstr - .endm - .macro tryautotomize battler:req, failInstr:req various \battler, VARIOUS_TRY_AUTOTOMIZE .4byte \failInstr diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 901a76c1a8..32e9ec23ee 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -138,102 +138,101 @@ #define VARIOUS_HANDLE_MEGA_EVO 46 #define VARIOUS_TRY_LAST_RESORT 47 #define VARIOUS_SET_ARG_TO_BATTLE_DAMAGE 48 -#define VARIOUS_TRY_HIT_SWITCH_TARGET 49 -#define VARIOUS_TRY_AUTOTOMIZE 50 -#define VARIOUS_ABILITY_POPUP 51 -#define VARIOUS_JUMP_IF_TARGET_ALLY 52 -#define VARIOUS_TRY_SYNCHRONOISE 53 -#define VARIOUS_PSYCHO_SHIFT 54 -#define VARIOUS_CURE_STATUS 55 -#define VARIOUS_POWER_TRICK 56 -#define VARIOUS_AFTER_YOU 57 -#define VARIOUS_BESTOW 58 -#define VARIOUS_JUMP_IF_NOT_GROUNDED 59 -#define VARIOUS_HANDLE_TRAINER_SLIDE_MSG 60 -#define VARIOUS_TRY_TRAINER_SLIDE_MSG_FIRST_OFF 61 -#define VARIOUS_TRY_TRAINER_SLIDE_MSG_LAST_ON 62 -#define VARIOUS_SET_AURORA_VEIL 63 -#define VARIOUS_TRY_THIRD_TYPE 64 -#define VARIOUS_ACUPRESSURE 65 -#define VARIOUS_SET_POWDER 66 -#define VARIOUS_SPECTRAL_THIEF 67 -#define VARIOUS_GRAVITY_ON_AIRBORNE_MONS 68 -#define VARIOUS_CHECK_IF_GRASSY_TERRAIN_HEALS 69 -#define VARIOUS_JUMP_IF_ROAR_FAILS 70 -#define VARIOUS_TRY_INSTRUCT 71 -#define VARIOUS_JUMP_IF_NOT_BERRY 72 -#define VARIOUS_TRACE_ABILITY 73 -#define VARIOUS_UPDATE_NICK 74 -#define VARIOUS_TRY_ILLUSION_OFF 75 -#define VARIOUS_SET_SPRITEIGNORE0HP 76 -#define VARIOUS_HANDLE_FORM_CHANGE 77 -#define VARIOUS_GET_STAT_VALUE 78 -#define VARIOUS_JUMP_IF_FULL_HP 79 -#define VARIOUS_LOSE_TYPE 80 -#define VARIOUS_TRY_ACTIVATE_SOULHEART 81 -#define VARIOUS_TRY_ACTIVATE_RECEIVER 82 -#define VARIOUS_TRY_ACTIVATE_BEAST_BOOST 83 -#define VARIOUS_TRY_FRISK 84 -#define VARIOUS_JUMP_IF_SHIELDS_DOWN_PROTECTED 85 -#define VARIOUS_TRY_FAIRY_LOCK 86 -#define VARIOUS_JUMP_IF_NO_ALLY 87 -#define VARIOUS_POISON_TYPE_IMMUNITY 88 -#define VARIOUS_JUMP_IF_HOLD_EFFECT 89 -#define VARIOUS_INFATUATE_WITH_BATTLER 90 -#define VARIOUS_SET_LAST_USED_ITEM 91 -#define VARIOUS_PARALYZE_TYPE_IMMUNITY 92 -#define VARIOUS_JUMP_IF_ABSENT 93 -#define VARIOUS_DESTROY_ABILITY_POPUP 94 -#define VARIOUS_TOTEM_BOOST 95 -#define VARIOUS_TRY_ACTIVATE_GRIM_NEIGH 96 -#define VARIOUS_MOVEEND_ITEM_EFFECTS 97 -#define VARIOUS_TERRAIN_SEED 98 -#define VARIOUS_MAKE_INVISIBLE 99 -#define VARIOUS_ROOM_SERVICE 100 -#define VARIOUS_EERIE_SPELL_PP_REDUCE 101 -#define VARIOUS_JUMP_IF_TEAM_HEALTHY 102 -#define VARIOUS_TRY_HEAL_QUARTER_HP 103 -#define VARIOUS_REMOVE_TERRAIN 104 -#define VARIOUS_JUMP_IF_PRANKSTER_BLOCKED 105 -#define VARIOUS_TRY_TO_CLEAR_PRIMAL_WEATHER 106 -#define VARIOUS_GET_ROTOTILLER_TARGETS 107 -#define VARIOUS_JUMP_IF_NOT_ROTOTILLER_AFFECTED 108 -#define VARIOUS_TRY_ACTIVATE_BATTLE_BOND 109 -#define VARIOUS_CONSUME_BERRY 110 -#define VARIOUS_JUMP_IF_CANT_REVERT_TO_PRIMAL 111 -#define VARIOUS_JUMP_IF_SPECIES 112 -#define VARIOUS_UPDATE_ABILITY_POPUP 113 -#define VARIOUS_JUMP_IF_WEATHER_AFFECTED 114 -#define VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED 115 -#define VARIOUS_SET_ATTACKER_STICKY_WEB_USER 116 -#define VARIOUS_TRY_NO_RETREAT 117 -#define VARIOUS_TRY_TAR_SHOT 118 -#define VARIOUS_CAN_TAR_SHOT_WORK 119 -#define VARIOUS_CHECK_POLTERGEIST 120 -#define VARIOUS_CUT_1_3_HP_RAISE_STATS 121 -#define VARIOUS_TRY_END_NEUTRALIZING_GAS 122 -#define VARIOUS_JUMP_IF_UNDER_200 123 -#define VARIOUS_SET_SKY_DROP 124 -#define VARIOUS_CLEAR_SKY_DROP 125 -#define VARIOUS_SKY_DROP_YAWN 126 -#define VARIOUS_CURE_CERTAIN_STATUSES 127 -#define VARIOUS_TRY_RESET_NEGATIVE_STAT_STAGES 128 -#define VARIOUS_JUMP_IF_LAST_USED_ITEM_BERRY 129 -#define VARIOUS_JUMP_IF_LAST_USED_ITEM_HOLD_EFFECT 130 -#define VARIOUS_SAVE_BATTLER_ITEM 131 -#define VARIOUS_RESTORE_BATTLER_ITEM 132 -#define VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM 133 -#define VARIOUS_SET_BEAK_BLAST 134 -#define VARIOUS_SWAP_SIDE_STATUSES 135 -#define VARIOUS_SWAP_STATS 136 -#define VARIOUS_TEATIME_INVUL 137 -#define VARIOUS_TEATIME_TARGETS 138 -#define VARIOUS_TRY_WIND_RIDER_POWER 139 -#define VARIOUS_ACTIVATE_WEATHER_CHANGE_ABILITIES 140 -#define VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES 141 -#define VARIOUS_STORE_HEALING_WISH 142 -#define VARIOUS_HIT_SWITCH_TARGET_FAILED 143 -#define VARIOUS_TRY_REVIVAL_BLESSING 144 +#define VARIOUS_TRY_AUTOTOMIZE 49 +#define VARIOUS_ABILITY_POPUP 50 +#define VARIOUS_JUMP_IF_TARGET_ALLY 51 +#define VARIOUS_TRY_SYNCHRONOISE 52 +#define VARIOUS_PSYCHO_SHIFT 53 +#define VARIOUS_CURE_STATUS 54 +#define VARIOUS_POWER_TRICK 55 +#define VARIOUS_AFTER_YOU 56 +#define VARIOUS_BESTOW 57 +#define VARIOUS_JUMP_IF_NOT_GROUNDED 58 +#define VARIOUS_HANDLE_TRAINER_SLIDE_MSG 59 +#define VARIOUS_TRY_TRAINER_SLIDE_MSG_FIRST_OFF 60 +#define VARIOUS_TRY_TRAINER_SLIDE_MSG_LAST_ON 61 +#define VARIOUS_SET_AURORA_VEIL 62 +#define VARIOUS_TRY_THIRD_TYPE 63 +#define VARIOUS_ACUPRESSURE 64 +#define VARIOUS_SET_POWDER 65 +#define VARIOUS_SPECTRAL_THIEF 66 +#define VARIOUS_GRAVITY_ON_AIRBORNE_MONS 67 +#define VARIOUS_CHECK_IF_GRASSY_TERRAIN_HEALS 68 +#define VARIOUS_JUMP_IF_ROAR_FAILS 69 +#define VARIOUS_TRY_INSTRUCT 70 +#define VARIOUS_JUMP_IF_NOT_BERRY 71 +#define VARIOUS_TRACE_ABILITY 72 +#define VARIOUS_UPDATE_NICK 73 +#define VARIOUS_TRY_ILLUSION_OFF 74 +#define VARIOUS_SET_SPRITEIGNORE0HP 75 +#define VARIOUS_HANDLE_FORM_CHANGE 76 +#define VARIOUS_GET_STAT_VALUE 77 +#define VARIOUS_JUMP_IF_FULL_HP 78 +#define VARIOUS_LOSE_TYPE 79 +#define VARIOUS_TRY_ACTIVATE_SOULHEART 80 +#define VARIOUS_TRY_ACTIVATE_RECEIVER 81 +#define VARIOUS_TRY_ACTIVATE_BEAST_BOOST 82 +#define VARIOUS_TRY_FRISK 83 +#define VARIOUS_JUMP_IF_SHIELDS_DOWN_PROTECTED 84 +#define VARIOUS_TRY_FAIRY_LOCK 85 +#define VARIOUS_JUMP_IF_NO_ALLY 86 +#define VARIOUS_POISON_TYPE_IMMUNITY 87 +#define VARIOUS_JUMP_IF_HOLD_EFFECT 88 +#define VARIOUS_INFATUATE_WITH_BATTLER 89 +#define VARIOUS_SET_LAST_USED_ITEM 90 +#define VARIOUS_PARALYZE_TYPE_IMMUNITY 91 +#define VARIOUS_JUMP_IF_ABSENT 92 +#define VARIOUS_DESTROY_ABILITY_POPUP 93 +#define VARIOUS_TOTEM_BOOST 94 +#define VARIOUS_TRY_ACTIVATE_GRIM_NEIGH 95 +#define VARIOUS_MOVEEND_ITEM_EFFECTS 96 +#define VARIOUS_TERRAIN_SEED 97 +#define VARIOUS_MAKE_INVISIBLE 98 +#define VARIOUS_ROOM_SERVICE 99 +#define VARIOUS_EERIE_SPELL_PP_REDUCE 100 +#define VARIOUS_JUMP_IF_TEAM_HEALTHY 101 +#define VARIOUS_TRY_HEAL_QUARTER_HP 102 +#define VARIOUS_REMOVE_TERRAIN 103 +#define VARIOUS_JUMP_IF_PRANKSTER_BLOCKED 104 +#define VARIOUS_TRY_TO_CLEAR_PRIMAL_WEATHER 105 +#define VARIOUS_GET_ROTOTILLER_TARGETS 106 +#define VARIOUS_JUMP_IF_NOT_ROTOTILLER_AFFECTED 107 +#define VARIOUS_TRY_ACTIVATE_BATTLE_BOND 108 +#define VARIOUS_CONSUME_BERRY 109 +#define VARIOUS_JUMP_IF_CANT_REVERT_TO_PRIMAL 110 +#define VARIOUS_JUMP_IF_SPECIES 111 +#define VARIOUS_UPDATE_ABILITY_POPUP 112 +#define VARIOUS_JUMP_IF_WEATHER_AFFECTED 113 +#define VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED 114 +#define VARIOUS_SET_ATTACKER_STICKY_WEB_USER 115 +#define VARIOUS_TRY_NO_RETREAT 116 +#define VARIOUS_TRY_TAR_SHOT 117 +#define VARIOUS_CAN_TAR_SHOT_WORK 118 +#define VARIOUS_CHECK_POLTERGEIST 119 +#define VARIOUS_CUT_1_3_HP_RAISE_STATS 120 +#define VARIOUS_TRY_END_NEUTRALIZING_GAS 121 +#define VARIOUS_JUMP_IF_UNDER_200 122 +#define VARIOUS_SET_SKY_DROP 123 +#define VARIOUS_CLEAR_SKY_DROP 124 +#define VARIOUS_SKY_DROP_YAWN 125 +#define VARIOUS_CURE_CERTAIN_STATUSES 126 +#define VARIOUS_TRY_RESET_NEGATIVE_STAT_STAGES 127 +#define VARIOUS_JUMP_IF_LAST_USED_ITEM_BERRY 128 +#define VARIOUS_JUMP_IF_LAST_USED_ITEM_HOLD_EFFECT 129 +#define VARIOUS_SAVE_BATTLER_ITEM 130 +#define VARIOUS_RESTORE_BATTLER_ITEM 131 +#define VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM 132 +#define VARIOUS_SET_BEAK_BLAST 133 +#define VARIOUS_SWAP_SIDE_STATUSES 134 +#define VARIOUS_SWAP_STATS 135 +#define VARIOUS_TEATIME_INVUL 136 +#define VARIOUS_TEATIME_TARGETS 137 +#define VARIOUS_TRY_WIND_RIDER_POWER 138 +#define VARIOUS_ACTIVATE_WEATHER_CHANGE_ABILITIES 139 +#define VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES 140 +#define VARIOUS_STORE_HEALING_WISH 141 +#define VARIOUS_HIT_SWITCH_TARGET_FAILED 142 +#define VARIOUS_TRY_REVIVAL_BLESSING 143 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index e9c82c5b36..183141228f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8788,7 +8788,7 @@ u32 GetHighestStatId(u32 battler) } if (gBattleMons[battler].speed > highestStat) highestId = STAT_SPEED; - + return highestId; } @@ -9947,24 +9947,6 @@ static void Cmd_various(void) gBattleMoveDamage = gMovesInfo[gCurrentMove].argument; break; } - case VARIOUS_TRY_HIT_SWITCH_TARGET: - { - VARIOUS_ARGS(const u8 *failInstr); - if (IsBattlerAlive(gBattlerAttacker) - && IsBattlerAlive(gBattlerTarget) - && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) - && TARGET_TURN_DAMAGED - && GetBattlerAbility(gBattlerTarget) != ABILITY_GUARD_DOG) - { - gBattleScripting.switchCase = B_SWITCH_HIT; - gBattlescriptCurrInstr = cmd->nextInstr; - } - else - { - gBattlescriptCurrInstr = cmd->failInstr; - } - return; - } case VARIOUS_TRY_AUTOTOMIZE: { VARIOUS_ARGS(const u8 *failInstr); @@ -17333,3 +17315,23 @@ void BS_JumpIfBlockedBySoundproof(void) gBattlescriptCurrInstr = cmd->nextInstr; } } + +void BS_TryHitSwitchTarget(void) +{ + NATIVE_ARGS(const u8 *failInstr); + + if (IsBattlerAlive(gBattlerAttacker) + && IsBattlerAlive(gBattlerTarget) + && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) + && TARGET_TURN_DAMAGED + && gSpecialStatuses[gBattlerAttacker].parentalBondState != PARENTAL_BOND_1ST_HIT + && GetBattlerAbility(gBattlerTarget) != ABILITY_GUARD_DOG) + { + gBattleScripting.switchCase = B_SWITCH_HIT; + gBattlescriptCurrInstr = cmd->nextInstr; + } + else + { + gBattlescriptCurrInstr = cmd->failInstr; + } +} diff --git a/test/battle/ability/parental_bond.c b/test/battle/ability/parental_bond.c index 3ee942e789..fa236e4191 100644 --- a/test/battle/ability/parental_bond.c +++ b/test/battle/ability/parental_bond.c @@ -286,6 +286,26 @@ SINGLE_BATTLE_TEST("Parental Bond Snore strikes twice while asleep") } } +SINGLE_BATTLE_TEST("Parental Bond only triggers Dragon Tail's target switch out on the second hit") +{ + GIVEN { + ASSUME(gMovesInfo[MOVE_DRAGON_TAIL].effect == EFFECT_HIT_SWITCH_TARGET); + PLAYER(SPECIES_KANGASKHAN) { Item(ITEM_KANGASKHANITE); } + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_CELEBRATE); MOVE(player, MOVE_DRAGON_TAIL, gimmick: GIMMICK_MEGA); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DRAGON_TAIL, player); + HP_BAR(opponent); + HP_BAR(opponent); + MESSAGE("Foe Wynaut was dragged out!"); + } + THEN { + EXPECT_EQ(player->species, SPECIES_KANGASKHAN_MEGA); + } +} + TO_DO_BATTLE_TEST("Parental Bond tests"); // Temporary TODO: Convert Bulbapedia description into tests.