From 29c64c82f329c45131c7e31e7e48ad69ae3fdb97 Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Tue, 21 Feb 2023 10:44:58 +0000 Subject: [PATCH] Test Red Card Dragon Tail activates Red Card if the target does not switch. --- asm/macros/battle_script.inc | 4 + data/battle_scripts_1.s | 7 +- include/battle.h | 1 + include/constants/battle_script_commands.h | 1 + src/battle_script_commands.c | 10 +- test/hold_effect_red_card.c | 378 +++++++++++++++++++++ 6 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 test/hold_effect_red_card.c diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 6c985e3cd..7c94f06ff 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -2247,3 +2247,7 @@ various \battler, VARIOUS_JUMP_IF_EMERGENCY_EXITED .4byte \jumpInstr .endm + + .macro hitswitchtargetfailed + various 0, VARIOUS_HIT_SWITCH_TARGET_FAILED + .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 53925b578..239d22109 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2129,7 +2129,12 @@ BattleScript_EffectHitSwitchTarget: jumpifability BS_TARGET, ABILITY_SUCTION_CUPS, BattleScript_AbilityPreventsPhasingOut jumpifstatus3 BS_TARGET, STATUS3_ROOTED, BattleScript_PrintMonIsRooted tryhitswitchtarget BattleScript_MoveEnd - forcerandomswitch BattleScript_MoveEnd + forcerandomswitch BattleScript_HitSwitchTargetForceRandomSwitchFailed + goto BattleScript_MoveEnd + +BattleScript_HitSwitchTargetForceRandomSwitchFailed: + hitswitchtargetfailed + setbyte sSWITCH_CASE, B_SWITCH_NORMAL goto BattleScript_MoveEnd BattleScript_EffectClearSmog: diff --git a/include/battle.h b/include/battle.h index 2c16887bf..c3281174d 100644 --- a/include/battle.h +++ b/include/battle.h @@ -651,6 +651,7 @@ struct BattleStruct // When using a move which hits multiple opponents which is then bounced by a target, we need to make sure, the move hits both opponents, the one with bounce, and the one without. u8 attackerBeforeBounce:2; u8 beatUpSlot:3; + bool8 hitSwitchTargetFailed:1; u8 targetsDone[MAX_BATTLERS_COUNT]; // Each battler as a bit. u16 overwrittenAbilities[MAX_BATTLERS_COUNT]; // abilities overwritten during battle (keep separate from battle history in case of switching) bool8 allowedToChangeFormInWeather[PARTY_SIZE][2]; // For each party member and side, used by Ice Face. diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 9f18455a8..0b71c22db 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -258,6 +258,7 @@ #define VARIOUS_JUMP_IF_NO_VALID_TARGETS 166 #define VARIOUS_JUMP_IF_EMERGENCY_EXITED 167 #define VARIOUS_STORE_HEALING_WISH 168 +#define VARIOUS_HIT_SWITCH_TARGET_FAILED 169 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index fdd3d4f07..5667beb4a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5968,7 +5968,7 @@ static void Cmd_moveend(void) gBattleScripting.moveendState++; break; case MOVEEND_RED_CARD: - if (gBattleMoves[gCurrentMove].effect != EFFECT_HIT_SWITCH_TARGET + if ((gBattleMoves[gCurrentMove].effect != EFFECT_HIT_SWITCH_TARGET || gBattleStruct->hitSwitchTargetFailed) && IsBattlerAlive(gBattlerAttacker) && !TestSheerForceFlag(gBattlerAttacker, gCurrentMove) && GetBattlerAbility(gBattlerAttacker) != ABILITY_GUARD_DOG) @@ -6199,6 +6199,7 @@ static void Cmd_moveend(void) gBattleStruct->zmove.active = FALSE; gBattleStruct->zmove.toBeUsed[gBattlerAttacker] = MOVE_NONE; gBattleStruct->zmove.effect = EFFECT_HIT; + gBattleStruct->hitSwitchTargetFailed = FALSE; gBattleScripting.moveendState++; break; case MOVEEND_COUNT: @@ -11067,6 +11068,13 @@ static void Cmd_various(void) gBattleStruct->storedHealingWish |= gBitTable[gActiveBattler]; break; } + case VARIOUS_HIT_SWITCH_TARGET_FAILED: + { + VARIOUS_ARGS(); + gBattleStruct->hitSwitchTargetFailed = TRUE; + gBattlescriptCurrInstr = cmd->nextInstr; + return; + } } // End of switch (cmd->id) gBattlescriptCurrInstr = cmd->nextInstr; diff --git a/test/hold_effect_red_card.c b/test/hold_effect_red_card.c new file mode 100644 index 000000000..c32c489d5 --- /dev/null +++ b/test/hold_effect_red_card.c @@ -0,0 +1,378 @@ +#include "global.h" +#include "test_battle.h" + +ASSUMPTIONS +{ + ASSUME(gItems[ITEM_RED_CARD].holdEffect == HOLD_EFFECT_RED_CARD); +} + +SINGLE_BATTLE_TEST("Red Card switches the attacker with a random non-fainted replacement") +{ + PASSES_RANDOMLY(1, 2); + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_BULBASAUR); + OPPONENT(SPECIES_CHARMANDER); + OPPONENT(SPECIES_SQUIRTLE) { HP(0); } + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + MESSAGE("Foe Bulbasaur was dragged out!"); + } +} + +DOUBLE_BATTLE_TEST("Red Card switches the target with a random non-battler, non-fainted replacement") +{ + PASSES_RANDOMLY(1, 2); + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_BULBASAUR); + OPPONENT(SPECIES_CHARMANDER); + OPPONENT(SPECIES_SQUIRTLE) { HP(0); } + } WHEN { + TURN { MOVE(opponentLeft, MOVE_TACKLE, target: playerLeft); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponentLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerLeft); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + MESSAGE("Foe Bulbasaur was dragged out!"); + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if holder faints") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { HP(1); Item(ITEM_RED_CARD); } + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); SEND_OUT(player, 1); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if target is behind a Substitute") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(player, MOVE_SUBSTITUTE); MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } + } +} + +SINGLE_BATTLE_TEST("Red Card activates after the last hit of a multi-hit move") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_DOUBLE_KICK); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DOUBLE_KICK, opponent); + HP_BAR(player); + HP_BAR(player); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if no replacements") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if replacements fainted") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT) { HP(0); } + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if knocked off") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_KNOCK_OFF); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_KNOCK_OFF, opponent); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if stolen by a move") +{ + u32 item; + bool32 activate; + PARAMETRIZE { item = ITEM_NONE; activate = FALSE; } + PARAMETRIZE { item = ITEM_POTION; activate = TRUE; } + ASSUME(gBattleMoves[MOVE_THIEF].effect == EFFECT_THIEF); + + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET) { Item(item); } + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_THIEF); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_THIEF, opponent); + if (activate) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } else { + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } + } + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if stolen by Magician") +{ + u32 item; + bool32 activate; + PARAMETRIZE { item = ITEM_NONE; activate = FALSE; } + PARAMETRIZE { item = ITEM_POTION; activate = TRUE; } + + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_FENNEKIN) { Ability(ABILITY_MAGICIAN); Item(item); } + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + if (activate) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Fennekin!"); + } else { + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Fennekin!"); + } + } + } +} + +DOUBLE_BATTLE_TEST("Red Card activates for only the fastest target") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Speed(3); Item(ITEM_RED_CARD); } + PLAYER(SPECIES_WYNAUT) { Speed(2); Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET) { Speed(5); } + OPPONENT(SPECIES_WYNAUT) { Speed(4); } + OPPONENT(SPECIES_UNOWN) { Speed(1); } + } WHEN { + TURN { + MOVE(opponentLeft, MOVE_ROCK_SLIDE); + MOVE(opponentRight, MOVE_TACKLE, target: playerRight); + } + } SCENE { + // Fastest target's Red Card activates. + ANIMATION(ANIM_TYPE_MOVE, MOVE_ROCK_SLIDE, opponentLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerLeft); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + MESSAGE("Foe Unown was dragged out!"); + + // Slower target's Red Card still able to activate on other battler. + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponentRight); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerRight); + MESSAGE("Wynaut held up its Red Card against Foe Wynaut!"); + MESSAGE("Foe Wobbuffet was dragged out!"); + } +} + +DOUBLE_BATTLE_TEST("Red Card activates but fails if the attacker is rooted") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_UNOWN); + } WHEN { + TURN { MOVE(opponentLeft, MOVE_INGRAIN); } + TURN { + MOVE(opponentLeft, MOVE_TACKLE, target: playerLeft); + MOVE(opponentRight, MOVE_TACKLE, target: playerLeft); + } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponentLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerLeft); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + MESSAGE("Foe Wobbuffet anchored itself with its roots!"); + + // Red Card already consumed so cannot activate. + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponentRight); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerRight); + MESSAGE("Wynaut held up its Red Card against Foe Wynaut!"); + } + } +} + +DOUBLE_BATTLE_TEST("Red Card activates but fails if the attacker has Suction Cups") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_OCTILLERY) { Ability(ABILITY_SUCTION_CUPS); } + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_UNOWN); + } WHEN { + TURN { + MOVE(opponentLeft, MOVE_TACKLE, target: playerLeft); + MOVE(opponentRight, MOVE_TACKLE, target: playerLeft); + } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponentLeft); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerLeft); + MESSAGE("Wobbuffet held up its Red Card against Foe Octillery!"); + MESSAGE("Foe Octillery anchors itself with Suction Cups!"); + + // Red Card already consumed so cannot activate. + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponentRight); + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, playerRight); + MESSAGE("Wynaut held up its Red Card against Foe Wynaut!"); + } + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if switched by Dragon Tail") +{ + bool32 hasWynaut, activate; + PARAMETRIZE { hasWynaut = TRUE; activate = FALSE; } + PARAMETRIZE { hasWynaut = FALSE; activate = TRUE; } + + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + if (hasWynaut) PLAYER(SPECIES_WYNAUT); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_DRAGON_TAIL); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DRAGON_TAIL, opponent); + if (activate) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } else { + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } + } + } +} + +SINGLE_BATTLE_TEST("Red Card activates and overrides U-turn") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_U_TURN); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_U_TURN, opponent); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Wobbuffet!"); + } +} + +SINGLE_BATTLE_TEST("Red Card does not activate if attacker's Sheer Force applied") +{ + u32 move; + bool32 activate; + PARAMETRIZE { move = MOVE_TACKLE; activate = TRUE; } + PARAMETRIZE { move = MOVE_STOMP; activate = FALSE; } + + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_RED_CARD); } + OPPONENT(SPECIES_TAUROS) { Ability(ABILITY_SHEER_FORCE); } + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, move); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, move, opponent); + if (activate) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Tauros!"); + } else { + NONE_OF { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Wobbuffet held up its Red Card against Foe Tauros!"); + } + } + } +} + +SINGLE_BATTLE_TEST("Red Card activates before Emergency Exit") +{ + GIVEN { + PLAYER(SPECIES_GOLISOPOD) { MaxHP(100); HP(51); Item(ITEM_RED_CARD); } + PLAYER(SPECIES_WIMPOD); + OPPONENT(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); SEND_OUT(player, 1); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); + MESSAGE("Golisopod held up its Red Card against Foe Wobbuffet!"); + ABILITY_POPUP(player, ABILITY_EMERGENCY_EXIT); + MESSAGE("Go! Wimpod!"); + } +} + +// SINGLE_BATTLE_TEST("Red Card activates but fails if the attacker has Dynamaxed")