From 69b42de0d9b054617a946cfa37064749b43c5013 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Sat, 30 Oct 2021 20:40:05 -0300 Subject: [PATCH 1/5] Implemented Mimicry Thanks to AsparagusEduardo for helping me optimize RestoreBattlerOriginalTypes. --- asm/macros/battle_script.inc | 5 ++ data/battle_scripts_1.s | 23 ++++++++ include/battle_scripts.h | 2 + include/battle_util.h | 2 + include/constants/battle_script_commands.h | 1 + include/constants/battle_string_ids.h | 3 +- src/battle_message.c | 2 + src/battle_script_commands.c | 16 ++++++ src/battle_util.c | 62 +++++++++++++++++++++- 9 files changed, 114 insertions(+), 2 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 8fd760634..f288cfeaf 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1874,6 +1874,11 @@ .4byte \ptr .endm + .macro trytoapplymimicry battler:req, ptr:req + various \battler, VARIOUS_TRY_TO_APPLY_MIMICRY + .4byte \ptr + .endm + @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index df0048ad9..8c3e744c1 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -1908,8 +1908,25 @@ BattleScript_EffectPsychicTerrain: waitmessage B_WAIT_TIME_LONG playanimation BS_SCRIPTING, B_ANIM_RESTORE_BG, NULL call BattleScript_TerrainSeedLoop + jumpifabilitypresent ABILITY_MIMICRY, BattleScript_ApplyMimicry goto BattleScript_MoveEnd +BattleScript_ApplyMimicry:: + savetarget + setbyte gBattlerTarget, 0 +BattleScript_MimicryLoopIter: + copybyte sBATTLER, gBattlerTarget + trytoapplymimicry BS_TARGET, BattleScript_MimicryLoop_NextBattler + copybyte gBattlerAbility, sBATTLER + call BattleScript_AbilityPopUp + printstring STRINGID_BATTLERTYPECHANGEDTO + waitmessage B_WAIT_TIME_LONG +BattleScript_MimicryLoop_NextBattler: + addbyte gBattlerTarget, 0x1 + jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_MimicryLoopIter + restoretarget + end + BattleScript_EffectTopsyTurvy: attackcanceler attackstring @@ -7957,6 +7974,12 @@ BattleScript_ColorChangeActivates:: waitmessage B_WAIT_TIME_LONG return +BattleScript_MimicryActivatesEnd3:: + call BattleScript_AbilityPopUp + printstring STRINGID_BATTLERTYPECHANGEDTO + waitmessage B_WAIT_TIME_LONG + end3 + BattleScript_ProteanActivates:: call BattleScript_AbilityPopUp printstring STRINGID_PKMNCHANGEDTYPE diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 403af9515..537d9cb81 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -404,5 +404,7 @@ extern const u8 BattleScript_PrimalReversion[]; extern const u8 BattleScript_HyperspaceFuryRemoveProtect[]; extern const u8 BattleScript_SelectingNotAllowedMoveGorillaTactics[]; extern const u8 BattleScript_WanderingSpiritActivates[]; +extern const u8 BattleScript_MimicryActivatesEnd3[]; +extern const u8 BattleScript_ApplyMimicry[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/include/battle_util.h b/include/battle_util.h index 7f267308d..62a7e1db6 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -157,6 +157,8 @@ void DoBurmyFormChange(u32 monId); bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 checkTarget); u16 GetUsedHeldItem(u8 battler); bool32 IsBattlerWeatherAffected(u8 battlerId, u32 weatherFlags); +void TryToApplyMimicry(u8 battlerId, bool8 various); +void RestoreBattlerOriginalTypes(u8 battlerId); // ability checks bool32 IsRolePlayBannedAbilityAtk(u16 ability); diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index fb1142f48..ee6cd4c7f 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -197,6 +197,7 @@ #define VARIOUS_UPDATE_ABILITY_POPUP 124 #define VARIOUS_JUMP_IF_WEATHER_AFFECTED 125 #define VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED 126 +#define VARIOUS_TRY_TO_APPLY_MIMICRY 127 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/include/constants/battle_string_ids.h b/include/constants/battle_string_ids.h index 27b39475a..c4161c68f 100644 --- a/include/constants/battle_string_ids.h +++ b/include/constants/battle_string_ids.h @@ -599,8 +599,9 @@ #define STRINGID_BROKETHROUGHPROTECTION 596 #define STRINGID_ABILITYALLOWSONLYMOVE 597 #define STRINGID_SWAPPEDABILITIES 598 +#define STRINGID_BATTLERTYPECHANGEDTO 599 -#define BATTLESTRINGS_COUNT 599 +#define BATTLESTRINGS_COUNT 600 // The below IDs are all indexes into battle message tables, // used to determine which of a set of messages to print. diff --git a/src/battle_message.c b/src/battle_message.c index 37919ddca..30a8670ac 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -725,9 +725,11 @@ static const u8 sText_ButHoopaCantUseIt[] = _("But Hoopa can't use it\nthe way i static const u8 sText_BrokeThroughProtection[] = _("It broke through the\n{B_DEF_NAME_WITH_PREFIX}'s protection!"); static const u8 sText_AbilityAllowsOnlyMove[] = _("{B_ATK_ABILITY} allows the\nuse of only {B_CURRENT_MOVE}!\p"); static const u8 sText_SwappedAbilities[] = _("{B_DEF_NAME_WITH_PREFIX} swapped Abilities\nwith its target!"); +static const u8 sText_BattlerTypeChangedTo[] = _("{B_BUFF1}'s type\nchanged to {B_BUFF2}!"); const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = { + [STRINGID_BATTLERTYPECHANGEDTO - 12] = sText_BattlerTypeChangedTo, [STRINGID_SWAPPEDABILITIES - 12] = sText_SwappedAbilities, [STRINGID_ABILITYALLOWSONLYMOVE - 12] = sText_AbilityAllowsOnlyMove, [STRINGID_BROKETHROUGHPROTECTION - 12] = sText_BrokeThroughProtection, diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9e779da1b..2f4e8c46b 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -54,6 +54,7 @@ #include "constants/rgb.h" #include "data.h" #include "constants/party_menu.h" +#include "battle_util.h" extern struct MusicPlayerInfo gMPlayInfo_BGM; extern struct Evolution gEvolutionTable[][EVOS_PER_MON]; @@ -9004,6 +9005,21 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 7; } return; + case VARIOUS_TRY_TO_APPLY_MIMICRY: + { + bool8 isMimicryDone = FALSE; + + if (GetBattlerAbility(gActiveBattler) == ABILITY_MIMICRY) + { + TryToApplyMimicry(gActiveBattler, TRUE); + isMimicryDone = TRUE; + } + if (!isMimicryDone) + gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); + else + gBattlescriptCurrInstr += 7; + return; + } } gBattlescriptCurrInstr += 3; diff --git a/src/battle_util.c b/src/battle_util.c index 224cb1af1..00e323d20 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1894,6 +1894,46 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move) return imprisonedMoves; } +void RestoreBattlerOriginalTypes(u8 battlerId) +{ + gBattleMons[battlerId].type1 = gBaseStats[gBattleMons[battlerId].species].type1; + gBattleMons[battlerId].type2 = gBaseStats[gBattleMons[battlerId].species].type2; +} + +void TryToApplyMimicry(u8 battlerId, bool8 various) +{ + u32 moveType, move; + + GET_MOVE_TYPE(move, moveType); + switch (gFieldStatuses) + { + case STATUS_FIELD_ELECTRIC_TERRAIN: + moveType = TYPE_ELECTRIC; + break; + case STATUS_FIELD_MISTY_TERRAIN: + moveType = TYPE_FAIRY; + break; + case STATUS_FIELD_GRASSY_TERRAIN: + moveType = TYPE_GRASS; + break; + case STATUS_FIELD_PSYCHIC_TERRAIN: + moveType = TYPE_PSYCHIC; + break; + default: + moveType = 0; + break; + } + + if (moveType != 0 && !IS_BATTLER_OF_TYPE(battlerId, moveType)) + { + SET_BATTLER_TYPE(battlerId, moveType); + PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, battlerId, gBattlerPartyIndexes[battlerId]) + PREPARE_TYPE_BUFFER(gBattleTextBuff2, moveType); + if (!various) + BattleScriptPushCursorAndCallback(BattleScript_MimicryActivatesEnd3); + } +} + enum { ENDTURN_ORDER, @@ -2278,6 +2318,9 @@ u8 DoFieldEndTurnEffects(void) && (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.electricTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT); + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RestoreBattlerOriginalTypes(i); BattleScriptExecute(BattleScript_ElectricTerrainEnds); effect++; } @@ -2288,6 +2331,9 @@ u8 DoFieldEndTurnEffects(void) && (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.mistyTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_MISTY_TERRAIN); + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RestoreBattlerOriginalTypes(i); BattleScriptExecute(BattleScript_MistyTerrainEnds); effect++; } @@ -2298,8 +2344,12 @@ u8 DoFieldEndTurnEffects(void) { if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && (gFieldTimers.grassyTerrainTimer == 0 || --gFieldTimers.grassyTerrainTimer == 0)) + { gFieldStatuses &= ~(STATUS_FIELD_GRASSY_TERRAIN); - + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RestoreBattlerOriginalTypes(i); + } BattleScriptExecute(BattleScript_GrassyTerrainHeals); effect++; } @@ -2310,6 +2360,9 @@ u8 DoFieldEndTurnEffects(void) && (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.psychicTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_PSYCHIC_TERRAIN); + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RestoreBattlerOriginalTypes(i); BattleScriptExecute(BattleScript_PsychicTerrainEnds); effect++; } @@ -4380,6 +4433,13 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move effect++; } break; + case ABILITY_MIMICRY: + if (gBattleMons[battler].hp != 0 && gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) + { + TryToApplyMimicry(battler, FALSE); + effect++; + } + break; } break; case ABILITYEFFECT_ENDTURN: // 1 From f0d7c75ec899bf3962794eb19f2be9b1f8099222 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 3 Nov 2021 17:48:04 -0300 Subject: [PATCH 2/5] Syntax corrections --- data/battle_scripts_1.s | 2 +- src/battle_util.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 8c3e744c1..aa6c10bcb 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -1925,7 +1925,7 @@ BattleScript_MimicryLoop_NextBattler: addbyte gBattlerTarget, 0x1 jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_MimicryLoopIter restoretarget - end + goto BattleScript_MoveEnd BattleScript_EffectTopsyTurvy: attackcanceler diff --git a/src/battle_util.c b/src/battle_util.c index 00e323d20..45cba507b 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2319,8 +2319,10 @@ u8 DoFieldEndTurnEffects(void) { gFieldStatuses &= ~(STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT); for (i = 0; i < MAX_BATTLERS_COUNT; i++) + { if (GetBattlerAbility(i) == ABILITY_MIMICRY) RestoreBattlerOriginalTypes(i); + } BattleScriptExecute(BattleScript_ElectricTerrainEnds); effect++; } @@ -2332,8 +2334,10 @@ u8 DoFieldEndTurnEffects(void) { gFieldStatuses &= ~(STATUS_FIELD_MISTY_TERRAIN); for (i = 0; i < MAX_BATTLERS_COUNT; i++) + { if (GetBattlerAbility(i) == ABILITY_MIMICRY) RestoreBattlerOriginalTypes(i); + } BattleScriptExecute(BattleScript_MistyTerrainEnds); effect++; } @@ -2347,8 +2351,10 @@ u8 DoFieldEndTurnEffects(void) { gFieldStatuses &= ~(STATUS_FIELD_GRASSY_TERRAIN); for (i = 0; i < MAX_BATTLERS_COUNT; i++) + { if (GetBattlerAbility(i) == ABILITY_MIMICRY) RestoreBattlerOriginalTypes(i); + } } BattleScriptExecute(BattleScript_GrassyTerrainHeals); effect++; @@ -2361,8 +2367,10 @@ u8 DoFieldEndTurnEffects(void) { gFieldStatuses &= ~(STATUS_FIELD_PSYCHIC_TERRAIN); for (i = 0; i < MAX_BATTLERS_COUNT; i++) + { if (GetBattlerAbility(i) == ABILITY_MIMICRY) RestoreBattlerOriginalTypes(i); + } BattleScriptExecute(BattleScript_PsychicTerrainEnds); effect++; } From b931e341728e4b4e70c24f4a33d9d1ab4b7c07f8 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 3 Nov 2021 21:04:34 -0300 Subject: [PATCH 3/5] Handled Mimicry's interaction with Steel Roller's effect --- asm/macros/battle_script.inc | 4 ++++ data/battle_scripts_1.s | 1 + include/constants/battle_script_commands.h | 1 + src/battle_script_commands.c | 7 +++++++ 4 files changed, 13 insertions(+) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index b7a60dbbb..1625fe41c 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1883,6 +1883,10 @@ .4byte \ptr .endm + .macro trytorevertmimicry + various BS_ATTACKER, VARIOUS_TRY_TO_REVERT_MIMICRY + .endm + @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index ac2d9a1a6..88d89ec3f 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -660,6 +660,7 @@ BattleScript_EffectRemoveTerrain: resultmessage waitmessage B_WAIT_TIME_LONG removeterrain + trytorevertmimicry jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, 4, BattleScript_MoveEnd printfromtable gTerrainEndingStringIds waitmessage B_WAIT_TIME_LONG diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 50db28028..3d7dfbc2b 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -199,6 +199,7 @@ #define VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED 126 #define VARIOUS_SET_ATTACKER_STICKY_WEB_USER 127 #define VARIOUS_TRY_TO_APPLY_MIMICRY 128 +#define VARIOUS_TRY_TO_REVERT_MIMICRY 129 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 3bfa227bc..74d52dbb6 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9039,6 +9039,13 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 7; return; } + case VARIOUS_TRY_TO_REVERT_MIMICRY: + for (i = 0; i < gBattlersCount; i++) + { + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RestoreBattlerOriginalTypes(i); + } + break; } gBattlescriptCurrInstr += 3; From 4f251e6ec2b8cd4cb9339dec7a825e7c5d5f9100 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 4 Nov 2021 12:13:55 -0300 Subject: [PATCH 4/5] Moved VARIOUS_TRY_TO_REVERT_MIMICRY to VARIOUS_REMOVE_TERRAIN --- asm/macros/battle_script.inc | 4 ---- data/battle_scripts_1.s | 1 - include/constants/battle_script_commands.h | 1 - src/battle_script_commands.c | 12 +++++------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 1625fe41c..b7a60dbbb 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1883,10 +1883,6 @@ .4byte \ptr .endm - .macro trytorevertmimicry - various BS_ATTACKER, VARIOUS_TRY_TO_REVERT_MIMICRY - .endm - @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 88d89ec3f..ac2d9a1a6 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -660,7 +660,6 @@ BattleScript_EffectRemoveTerrain: resultmessage waitmessage B_WAIT_TIME_LONG removeterrain - trytorevertmimicry jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, 4, BattleScript_MoveEnd printfromtable gTerrainEndingStringIds waitmessage B_WAIT_TIME_LONG diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 3d7dfbc2b..50db28028 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -199,7 +199,6 @@ #define VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED 126 #define VARIOUS_SET_ATTACKER_STICKY_WEB_USER 127 #define VARIOUS_TRY_TO_APPLY_MIMICRY 128 -#define VARIOUS_TRY_TO_REVERT_MIMICRY 129 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 74d52dbb6..d615e0b35 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8865,6 +8865,11 @@ static void Cmd_various(void) break; } gFieldStatuses &= ~STATUS_FIELD_TERRAIN_ANY; // remove the terrain + for (i = 0; i < gBattlersCount; i++) // restore the types of Pokémon with Mimicry + { + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RestoreBattlerOriginalTypes(i); + } break; case VARIOUS_JUMP_IF_PRANKSTER_BLOCKED: if (BlocksPrankster(gCurrentMove, gBattlerAttacker, gActiveBattler, TRUE)) @@ -9039,13 +9044,6 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 7; return; } - case VARIOUS_TRY_TO_REVERT_MIMICRY: - for (i = 0; i < gBattlersCount; i++) - { - if (GetBattlerAbility(i) == ABILITY_MIMICRY) - RestoreBattlerOriginalTypes(i); - } - break; } gBattlescriptCurrInstr += 3; From b64d506809c2b84e9a6ae1e91b9d081b5b37b71e Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 4 Nov 2021 12:20:31 -0300 Subject: [PATCH 5/5] Made a function to lift Mimicry's effect --- include/battle_util.h | 1 + src/battle_script_commands.c | 6 +----- src/battle_util.c | 35 +++++++++++++++-------------------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index 62a7e1db6..cb196519e 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -158,6 +158,7 @@ bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 chec u16 GetUsedHeldItem(u8 battler); bool32 IsBattlerWeatherAffected(u8 battlerId, u32 weatherFlags); void TryToApplyMimicry(u8 battlerId, bool8 various); +void TryToRevertMimicry(void); void RestoreBattlerOriginalTypes(u8 battlerId); // ability checks diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index d615e0b35..d056bfa5a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8865,11 +8865,7 @@ static void Cmd_various(void) break; } gFieldStatuses &= ~STATUS_FIELD_TERRAIN_ANY; // remove the terrain - for (i = 0; i < gBattlersCount; i++) // restore the types of Pokémon with Mimicry - { - if (GetBattlerAbility(i) == ABILITY_MIMICRY) - RestoreBattlerOriginalTypes(i); - } + TryToRevertMimicry(); // restore the types of Pokémon with Mimicry break; case VARIOUS_JUMP_IF_PRANKSTER_BLOCKED: if (BlocksPrankster(gCurrentMove, gBattlerAttacker, gActiveBattler, TRUE)) diff --git a/src/battle_util.c b/src/battle_util.c index a924722eb..b3cf60819 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1934,6 +1934,17 @@ void TryToApplyMimicry(u8 battlerId, bool8 various) } } +void TryToRevertMimicry(void) +{ + s32 i; + + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + { + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RestoreBattlerOriginalTypes(i); + } +} + enum { ENDTURN_ORDER, @@ -2318,11 +2329,7 @@ u8 DoFieldEndTurnEffects(void) && (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.electricTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT); - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - { - if (GetBattlerAbility(i) == ABILITY_MIMICRY) - RestoreBattlerOriginalTypes(i); - } + TryToRevertMimicry(); BattleScriptExecute(BattleScript_ElectricTerrainEnds); effect++; } @@ -2333,11 +2340,7 @@ u8 DoFieldEndTurnEffects(void) && (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.mistyTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_MISTY_TERRAIN); - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - { - if (GetBattlerAbility(i) == ABILITY_MIMICRY) - RestoreBattlerOriginalTypes(i); - } + TryToRevertMimicry(); BattleScriptExecute(BattleScript_MistyTerrainEnds); effect++; } @@ -2350,11 +2353,7 @@ u8 DoFieldEndTurnEffects(void) && (gFieldTimers.grassyTerrainTimer == 0 || --gFieldTimers.grassyTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_GRASSY_TERRAIN); - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - { - if (GetBattlerAbility(i) == ABILITY_MIMICRY) - RestoreBattlerOriginalTypes(i); - } + TryToRevertMimicry(); } BattleScriptExecute(BattleScript_GrassyTerrainHeals); effect++; @@ -2366,11 +2365,7 @@ u8 DoFieldEndTurnEffects(void) && (!(gFieldStatuses & STATUS_FIELD_TERRAIN_PERMANENT) && --gFieldTimers.psychicTerrainTimer == 0)) { gFieldStatuses &= ~(STATUS_FIELD_PSYCHIC_TERRAIN); - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - { - if (GetBattlerAbility(i) == ABILITY_MIMICRY) - RestoreBattlerOriginalTypes(i); - } + TryToRevertMimicry(); BattleScriptExecute(BattleScript_PsychicTerrainEnds); effect++; }