From 36b52eb0634111ca0a3ae65c5524ca4ad8d0e78b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 28 Apr 2020 11:14:20 +0200 Subject: [PATCH] Shed Shell --- include/battle_util.h | 1 + src/battle_main.c | 13 ++++--------- src/battle_script_commands.c | 4 +--- src/battle_util.c | 8 ++++++++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index c9f05cf8a..71a485d35 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -84,6 +84,7 @@ u32 IsAbilityOnOpposingSide(u32 battlerId, u32 ability); u32 IsAbilityOnField(u32 ability); u32 IsAbilityOnFieldExcept(u32 battlerId, u32 ability); u32 IsAbilityPreventingEscape(u32 battlerId); +bool32 CanBattlerEscape(u32 battlerId); // no ability check void BattleScriptExecute(const u8* BS_ptr); void BattleScriptPushCursorAndCallback(const u8* BS_ptr); u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn); diff --git a/src/battle_main.c b/src/battle_main.c index 571695095..a8bea64d9 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3690,9 +3690,7 @@ u8 IsRunningFromBattleImpossible(void) return 2; } - if ((gBattleMons[gActiveBattler].status2 & (STATUS2_ESCAPE_PREVENTION | STATUS2_WRAPPED)) - || (gStatuses3[gActiveBattler] & STATUS3_ROOTED) - || gFieldStatuses & STATUS_FIELD_FAIRY_LOCK) + if (!CanBattlerEscape(gActiveBattler)) { gBattleCommunication[MULTISTRING_CHOOSER] = 0; return 1; @@ -3868,10 +3866,8 @@ static void HandleTurnActionSelectionState(void) break; case B_ACTION_SWITCH: *(gBattleStruct->field_58 + gActiveBattler) = gBattlerPartyIndexes[gActiveBattler]; - if (gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION) - || gBattleTypeFlags & BATTLE_TYPE_ARENA - || gFieldStatuses & STATUS_FIELD_FAIRY_LOCK - || gStatuses3[gActiveBattler] & STATUS3_ROOTED) + if (gBattleTypeFlags & BATTLE_TYPE_ARENA + || !CanBattlerEscape(gActiveBattler)) { BtlController_EmitChoosePokemon(0, PARTY_ACTION_CANT_SWITCH, PARTY_SIZE, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); } @@ -5553,8 +5549,7 @@ static void HandleAction_Run(void) } else { - if (gBattleMons[gBattlerAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION) - || gFieldStatuses & STATUS_FIELD_FAIRY_LOCK) + if (!CanBattlerEscape(gBattlerAttacker)) { gBattleCommunication[MULTISTRING_CHOOSER] = 4; gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index e4d8ed6bc..d9e87774a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5115,9 +5115,7 @@ static void Cmd_jumpifcantswitch(void) gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1] & ~(SWITCH_IGNORE_ESCAPE_PREVENTION)); if (!(gBattlescriptCurrInstr[1] & SWITCH_IGNORE_ESCAPE_PREVENTION) - && ((gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) - || (gFieldStatuses & STATUS_FIELD_FAIRY_LOCK) - || (gStatuses3[gActiveBattler] & STATUS3_ROOTED))) + && !CanBattlerEscape(gActiveBattler)) { gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); } diff --git a/src/battle_util.c b/src/battle_util.c index c48473a50..1d17249bb 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4077,6 +4077,14 @@ u32 IsAbilityPreventingEscape(u32 battlerId) return 0; } +bool32 CanBattlerEscape(u32 battlerId) // no ability check +{ + return (GetBattlerHoldEffect(battlerId, TRUE) == HOLD_EFFECT_SHED_SHELL + || !((gBattleMons[battlerId].status2 & (STATUS2_ESCAPE_PREVENTION | STATUS2_WRAPPED)) + || (gStatuses3[battlerId] & STATUS3_ROOTED) + || gFieldStatuses & STATUS_FIELD_FAIRY_LOCK)); +} + void BattleScriptExecute(const u8 *BS_ptr) { gBattlescriptCurrInstr = BS_ptr;