From 76a7513dcdb792cfbf83b5363c68bb37cdeae511 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 17 Dec 2023 19:50:43 +0100 Subject: [PATCH] Fix Magician Life orb recoil when stealing (#3753) * Fix Magician Life orb recoil * get rid of unneeded assume --- include/battle.h | 1 + src/battle_script_commands.c | 2 ++ src/battle_util.c | 1 + test/battle/ability/magician.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 test/battle/ability/magician.c diff --git a/include/battle.h b/include/battle.h index ca9236d29ab3..c124da98f290 100644 --- a/include/battle.h +++ b/include/battle.h @@ -197,6 +197,7 @@ struct SpecialStatus // End of byte u8 emergencyExited:1; u8 afterYou:1; + u8 magicianStolen:1; // So that Life Orb doesn't activate after Magician steals it. }; struct SideTimer diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 1deaedaf165f..8e6fab8dfc15 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5719,6 +5719,7 @@ static void Cmd_moveend(void) gEffectBattler = gBattlerTarget; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_MagicianActivates; + gSpecialStatuses[gBattlerAttacker].magicianStolen = TRUE; effect = TRUE; } gBattleScripting.moveendState++; @@ -6081,6 +6082,7 @@ static void Cmd_moveend(void) gStatuses3[gBattlerAttacker] &= ~STATUS3_ME_FIRST; gSpecialStatuses[gBattlerAttacker].gemBoost = FALSE; gSpecialStatuses[gBattlerAttacker].damagedMons = 0; + gSpecialStatuses[gBattlerAttacker].magicianStolen = 0; gSpecialStatuses[gBattlerTarget].berryReduced = FALSE; gBattleScripting.moveEffect = 0; // clear attacker z move data diff --git a/src/battle_util.c b/src/battle_util.c index 71809c86a180..1d45ccc660ca 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -7697,6 +7697,7 @@ u8 ItemBattleEffects(u8 caseID, u32 battler, bool32 moveTurn) if (IsBattlerAlive(gBattlerAttacker) && !(TestSheerForceFlag(gBattlerAttacker, gCurrentMove)) && GetBattlerAbility(gBattlerAttacker) != ABILITY_MAGIC_GUARD + && !gSpecialStatuses[gBattlerAttacker].magicianStolen && gSpecialStatuses[gBattlerAttacker].damagedMons) { gBattleMoveDamage = gBattleMons[gBattlerAttacker].maxHP / 10; diff --git a/test/battle/ability/magician.c b/test/battle/ability/magician.c new file mode 100644 index 000000000000..388c91dccfad --- /dev/null +++ b/test/battle/ability/magician.c @@ -0,0 +1,29 @@ +#include "global.h" +#include "test/battle.h" + +SINGLE_BATTLE_TEST("Magician does not get self-damage recoil after stealing Life Orb") +{ + GIVEN { + ASSUME(gItems[ITEM_LIFE_ORB].holdEffect == HOLD_EFFECT_LIFE_ORB); + ASSUME(gBattleMoves[MOVE_TACKLE].power != 0); + PLAYER(SPECIES_DELPHOX) { Ability(ABILITY_MAGICIAN); Item(ITEM_NONE); } + OPPONENT(SPECIES_WOBBUFFET) { Item(ITEM_LIFE_ORB); } + } WHEN { + TURN { MOVE(player, MOVE_TACKLE); } + TURN { MOVE(player, MOVE_TACKLE); } + } SCENE { + // 1st turn + MESSAGE("Delphox used Tackle!"); + ABILITY_POPUP(player, ABILITY_MAGICIAN); + MESSAGE("Delphox stole Foe Wobbuffet's Life Orb!"); + NONE_OF { + HP_BAR(player); + MESSAGE("Delphox was hurt by its Life Orb!"); + } + // 2nd turn - Life Orb recoil happens now + MESSAGE("Delphox used Tackle!"); + HP_BAR(player); + MESSAGE("Delphox was hurt by its Life Orb!"); + } +} +