From 65b316625f843ef752cbe1279d02fbf0f9e6858b Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Wed, 13 Aug 2025 15:00:04 +0200 Subject: [PATCH] Fixes Knock Off still activating when there is no Item (#7496) --- src/battle_script_commands.c | 8 +++++--- test/battle/hold_effect/eject_pack.c | 2 +- test/battle/hold_effect/red_card.c | 2 +- test/battle/move_effect/future_sight.c | 2 +- test/battle/move_effect/knock_off.c | 16 ++++++++++++++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index e74bb4c60a..d9900c26a1 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2756,7 +2756,7 @@ static void Cmd_datahpupdate(void) if (GetMoveEffect(gCurrentMove) == EFFECT_KNOCK_OFF && IsBattlerTurnDamaged(gBattlerTarget) - && gBattleMons[gBattlerTarget].item != 0 + && gBattleMons[gBattlerTarget].item != ITEM_NONE && !DoesSubstituteBlockMove(gBattlerAttacker, battler, gCurrentMove) && CanBattlerGetOrLoseItem(gBattlerTarget, gBattleMons[gBattlerTarget].item) && !NoAliveMonsForEitherParty()) @@ -6260,7 +6260,9 @@ static bool32 HandleMoveEndMoveBlock(u32 moveEffect) switch (moveEffect) { case EFFECT_KNOCK_OFF: - if (gBattleStruct->battlerState[gBattlerTarget].itemCanBeKnockedOff && IsBattlerAlive(gBattlerAttacker)) + if (gBattleStruct->battlerState[gBattlerTarget].itemCanBeKnockedOff + && gBattleMons[gBattlerTarget].item != ITEM_NONE + && IsBattlerAlive(gBattlerAttacker)) { u32 side = GetBattlerSide(gBattlerTarget); gLastUsedItem = gBattleMons[gBattlerTarget].item; @@ -6280,11 +6282,11 @@ static bool32 HandleMoveEndMoveBlock(u32 moveEffect) gWishFutureKnock.knockedOffMons[side] |= 1u << gBattlerPartyIndexes[gBattlerTarget]; } - gBattleStruct->battlerState[gBattlerTarget].itemCanBeKnockedOff = FALSE; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_KnockedOff; effect = TRUE; } + gBattleStruct->battlerState[gBattlerTarget].itemCanBeKnockedOff = FALSE; break; case EFFECT_STEAL_ITEM: if (!CanStealItem(gBattlerAttacker, gBattlerTarget, gBattleMons[gBattlerTarget].item) diff --git a/test/battle/hold_effect/eject_pack.c b/test/battle/hold_effect/eject_pack.c index f33a59de21..208d656362 100644 --- a/test/battle/hold_effect/eject_pack.c +++ b/test/battle/hold_effect/eject_pack.c @@ -21,7 +21,7 @@ SINGLE_BATTLE_TEST("Eject Pack does not cause the new Pokémon to lose HP due to ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player); MESSAGE("Wobbuffet is switched out with the Eject Pack!"); SEND_IN_MESSAGE("Wynaut"); - NOT MESSAGE("Wynaut was hurt by its Life Orb!"); + NOT HP_BAR(player); ANIMATION(ANIM_TYPE_MOVE, MOVE_CELEBRATE, opponent); } } diff --git a/test/battle/hold_effect/red_card.c b/test/battle/hold_effect/red_card.c index a21318d246..6b5e08c450 100644 --- a/test/battle/hold_effect/red_card.c +++ b/test/battle/hold_effect/red_card.c @@ -455,7 +455,7 @@ SINGLE_BATTLE_TEST("Red Card does not cause the dragged out mon to lose hp due t ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, opponent); MESSAGE("The opposing Wobbuffet held up its Red Card against Wobbuffet!"); MESSAGE("Wynaut was dragged out!"); - NOT MESSAGE("Wynaut was hurt by its Life Orb!"); + NOT HP_BAR(player); } } diff --git a/test/battle/move_effect/future_sight.c b/test/battle/move_effect/future_sight.c index 3995e8479f..71e3aa7378 100644 --- a/test/battle/move_effect/future_sight.c +++ b/test/battle/move_effect/future_sight.c @@ -60,7 +60,7 @@ SINGLE_BATTLE_TEST("Future Sight is not boosted by Life Orb is original user if ANIMATION(ANIM_TYPE_MOVE, MOVE_FUTURE_SIGHT, player); MESSAGE("The opposing Regice took the Future Sight attack!"); HP_BAR(opponent, captureDamage: &futureSightDmg); - NOT MESSAGE("Raichu was hurt by its Life Orb!"); + NOT HP_BAR(player); } THEN { EXPECT_EQ(seedFlareDmg, futureSightDmg); } diff --git a/test/battle/move_effect/knock_off.c b/test/battle/move_effect/knock_off.c index 60be862c4c..eca09a33a6 100644 --- a/test/battle/move_effect/knock_off.c +++ b/test/battle/move_effect/knock_off.c @@ -394,3 +394,19 @@ SINGLE_BATTLE_TEST("Knock Off doesn't remove item if it's prevented by Sticky Ho ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, opponent); } } + +SINGLE_BATTLE_TEST("Knock Off does not activate if the item was previously consumed") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WOBBUFFET) { Item(ITEM_AIR_BALLOON); } + } WHEN { + TURN { MOVE(player, MOVE_KNOCK_OFF); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_KNOCK_OFF, player); + MESSAGE("The opposing Wobbuffet's Air Balloon popped!"); + NOT MESSAGE("Wobbuffet knocked off the opposing Wobbuffet's Air Balloon!"); + } THEN { + EXPECT(opponent->item == ITEM_NONE); + } +}