From ca9e78410269c66a0980b80387f4f5fa11f9dbc9 Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:31:20 +0200 Subject: [PATCH] Fixes Toxic Debris + CanTargetFaintAi index issue (#3306) * Fixes Toxic Debris + CanTargetFaintAi index issue * swap macro --- data/battle_scripts_1.s | 3 + src/battle_ai_util.c | 2 +- src/battle_util.c | 4 +- test/battle/ability/toxic_debris.c | 96 ++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 test/battle/ability/toxic_debris.c diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 9ef768530..405ad3d10 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -7333,6 +7333,9 @@ BattleScript_ToxicDebrisActivates:: printstring STRINGID_POISONSPIKESSCATTERED waitmessage B_WAIT_TIME_LONG BattleScript_ToxicDebrisRet: + copybyte sBATTLER, gBattlerTarget + copybyte gBattlerTarget, gBattlerAttacker + copybyte gBattlerAttacker, sBATTLER return BattleScript_EarthEaterActivates:: diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index d7e32a452..aff8ba91a 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -1154,7 +1154,7 @@ bool32 CanTargetFaintAi(u8 battlerDef, u8 battlerAtk) for (i = 0; i < MAX_MON_MOVES; i++) { if (moves[i] != MOVE_NONE && moves[i] != 0xFFFF && !(unusable & gBitTable[i]) - && AI_DATA->simulatedDmg[battlerDef][battlerAtk][moves[i]] >= gBattleMons[battlerAtk].hp) + && AI_DATA->simulatedDmg[battlerDef][battlerAtk][i] >= gBattleMons[battlerAtk].hp) { return TRUE; } diff --git a/src/battle_util.c b/src/battle_util.c index 1ff0a762e..32bbce974 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -5710,10 +5710,10 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move && !gProtectStructs[gBattlerAttacker].confusionSelfDmg && IS_MOVE_PHYSICAL(gCurrentMove) && TARGET_TURN_DAMAGED - && !(gSideStatuses[GetBattlerSide(gBattlerAttacker)] & SIDE_STATUS_TOXIC_SPIKES) + && (gSideTimers[gBattlerAttacker].toxicSpikesAmount != 2) && IsBattlerAlive(gBattlerTarget)) { - gBattlerTarget = gBattlerAttacker; + SWAP(gBattlerAttacker, gBattlerTarget, i); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_ToxicDebrisActivates; effect++; diff --git a/test/battle/ability/toxic_debris.c b/test/battle/ability/toxic_debris.c new file mode 100644 index 000000000..95749358a --- /dev/null +++ b/test/battle/ability/toxic_debris.c @@ -0,0 +1,96 @@ +#include "global.h" +#include "test/battle.h" + +SINGLE_BATTLE_TEST("Toxic Debris sets Toxic Spikes on the opposing side if hit by a physical attack") +{ + u32 move; + + PARAMETRIZE { move = MOVE_TACKLE;} + PARAMETRIZE { move = MOVE_SWIFT;} + + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_TOXIC_DEBRIS); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, move); } + } SCENE { + if (move == MOVE_TACKLE) { + ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + } + else { + NOT ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + NOT MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + } + } +} + +SINGLE_BATTLE_TEST("Toxic Debris does not activate if two layers of Toxic Spikes are already up") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_TOXIC_DEBRIS); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); } + TURN { MOVE(opponent, MOVE_TACKLE); } + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + NOT ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + NOT MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + } +} + +SINGLE_BATTLE_TEST("If a Substitute is hit, Toxic Debris does not set Toxic Spikes") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_TOXIC_DEBRIS); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_SUBSTITUTE); } + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_SUBSTITUTE, player); + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + NOT ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + NOT MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + } +} + +SINGLE_BATTLE_TEST("Each hit of a Multi Hit move activates Toxic Debris") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_TOXIC_DEBRIS); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_FURY_SWIPES); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_FURY_SWIPES, opponent); + ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + ANIMATION(ANIM_TYPE_MOVE, MOVE_FURY_SWIPES, opponent); + ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + } +} + +SINGLE_BATTLE_TEST("Air Balloon is popped after Toxic Debris activates") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Ability(ABILITY_TOXIC_DEBRIS); Item(ITEM_AIR_BALLOON); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_TACKLE); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + ABILITY_POPUP(player, ABILITY_TOXIC_DEBRIS); + MESSAGE("Poison Spikes were scattered all around the opposing team's feet!"); + MESSAGE("Wobbuffet's Air Balloon popped!"); + } +}