From 10317033092d3b42dd9c8280563a50ddecd6add6 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Wed, 6 Oct 2021 16:00:02 -0400 Subject: [PATCH 1/2] magician base functionality --- data/battle_scripts_1.s | 6 ++++++ include/battle_scripts.h | 1 + src/battle_script_commands.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 0615e1239..8118c4ff5 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -8426,3 +8426,9 @@ BattleScript_DarkTypePreventsPrankster:: waitmessage B_WAIT_TIME_LONG orhalfword gMoveResultFlags, MOVE_RESULT_NO_EFFECT goto BattleScript_MoveEnd + +BattleScript_MagicianActivates:: + call BattleScript_AbilityPopUp + call BattleScript_ItemSteal + return + diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 203be6519..9e4c058eb 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -389,5 +389,6 @@ extern const u8 BattleScript_DarkTypePreventsPrankster[]; extern const u8 BattleScript_GulpMissileGorging[]; extern const u8 BattleScript_GulpMissileGulping[]; extern const u8 BattleScript_BattleBondActivatesOnMoveEndAttacker[]; +extern const u8 BattleScript_MagicianActivates[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 12f7763e3..04d636426 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5071,6 +5071,26 @@ static void Cmd_moveend(void) } gBattleScripting.moveendState++; break; + case MOVEEND_MAGICIAN: + if (GetBattlerAbility(gBattlerAttacker) == ABILITY_MAGICIAN + && gCurrentMove != MOVE_FLING && gCurrentMove != MOVE_NATURAL_GIFT + && gBattleMons[gBattlerAttacker].item == ITEM_NONE + && IsBattlerAlive(gBattlerAttacker) + && TARGET_TURN_DAMAGED + && CanStealItem(gBattlerAttacker, gBattlerTarget, gBattleMons[gBattlerTarget].item) + && !DoesSubstituteBlockMove(gBattlerAttacker, gBattlerTarget, gCurrentMove) + && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) + && (GetBattlerAbility(gBattlerTarget) != ABILITY_STICKY_HOLD || !IsBattlerAlive(gBattlerTarget))) + { + StealTargetItem(gBattlerAttacker, gBattlerTarget); + gBattleScripting.battler = gBattlerAbility = gBattlerAttacker; + gEffectBattler = gBattlerTarget; + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_MagicianActivates; + effect = TRUE; + } + gBattleScripting.moveendState++; + break; case MOVEEND_NEXT_TARGET: // For moves hitting two opposing Pokemon. // Set a flag if move hits either target (for throat spray that can't check damage) if (!(gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) From 9a4e0cf75744b4dba85a78ec3f4dac529bb387ea Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Thu, 7 Oct 2021 17:37:47 -0400 Subject: [PATCH 2/2] magician fixes, handle edge cases --- data/battle_scripts_1.s | 1 + include/constants/battle_script_commands.h | 19 ++++++++++--------- src/battle_script_commands.c | 3 +++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 8118c4ff5..c1efe80d6 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -1249,6 +1249,7 @@ BattleScript_EffectHitSwitchTarget: resultmessage waitmessage B_WAIT_TIME_LONG tryfaintmon BS_TARGET, FALSE, NULL + moveendcase MOVEEND_MAGICIAN @ possibly others? jumpifability BS_TARGET, ABILITY_SUCTION_CUPS, BattleScript_AbilityPreventsPhasingOut jumpifstatus3 BS_TARGET, STATUS3_ROOTED, BattleScript_PrintMonIsRooted tryhitswitchtarget BattleScript_EffectHitSwitchTargetMoveEnd diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 1f0db2a73..a8e61ad10 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -243,15 +243,16 @@ #define MOVEEND_UPDATE_LAST_MOVES 18 #define MOVEEND_MIRROR_MOVE 19 #define MOVEEND_NEXT_TARGET 20 // Everything up until here is handled for each strike of a multi-hit move -#define MOVEEND_EJECT_BUTTON 21 -#define MOVEEND_RED_CARD 22 -#define MOVEEND_EJECT_PACK 23 -#define MOVEEND_LIFEORB_SHELLBELL 24 // Includes shell bell, throat spray, etc -#define MOVEEND_PICKPOCKET 25 -#define MOVEEND_DANCER 26 -#define MOVEEND_EMERGENCY_EXIT 27 -#define MOVEEND_CLEAR_BITS 28 -#define MOVEEND_COUNT 29 +#define MOVEEND_MAGICIAN 21 // Occurs after final multi-hit strike, and after other items/abilities would activate +#define MOVEEND_EJECT_BUTTON 22 +#define MOVEEND_RED_CARD 23 +#define MOVEEND_EJECT_PACK 24 +#define MOVEEND_LIFEORB_SHELLBELL 25 // Includes shell bell, throat spray, etc +#define MOVEEND_PICKPOCKET 26 +#define MOVEEND_DANCER 27 +#define MOVEEND_EMERGENCY_EXIT 28 +#define MOVEEND_CLEAR_BITS 29 +#define MOVEEND_COUNT 30 // switch cases #define B_SWITCH_NORMAL 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 04d636426..9f836f264 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5075,9 +5075,12 @@ static void Cmd_moveend(void) if (GetBattlerAbility(gBattlerAttacker) == ABILITY_MAGICIAN && gCurrentMove != MOVE_FLING && gCurrentMove != MOVE_NATURAL_GIFT && gBattleMons[gBattlerAttacker].item == ITEM_NONE + && gBattleMons[gBattlerTarget].item != ITEM_NONE && IsBattlerAlive(gBattlerAttacker) && TARGET_TURN_DAMAGED && CanStealItem(gBattlerAttacker, gBattlerTarget, gBattleMons[gBattlerTarget].item) + && !gSpecialStatuses[gBattlerAttacker].gemBoost // In base game, gems are consumed after magician would activate. + && !(gWishFutureKnock.knockedOffMons[GetBattlerSide(gBattlerTarget)] & gBitTable[gBattlerPartyIndexes[gBattlerTarget]]) && !DoesSubstituteBlockMove(gBattlerAttacker, gBattlerTarget, gCurrentMove) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) && (GetBattlerAbility(gBattlerTarget) != ABILITY_STICKY_HOLD || !IsBattlerAlive(gBattlerTarget)))