From 0bbbd1e7a9c91614c2d073a1585f67ccf83bf83a Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Thu, 12 Aug 2021 14:08:41 -0600 Subject: [PATCH] fix electric/misty yawn/rest interactions --- data/battle_scripts_1.s | 10 +++++++++- include/battle_scripts.h | 1 + src/battle_util.c | 24 ++++++++++++++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 07d0c9143e..39fbdab174 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2154,6 +2154,12 @@ BattleScript_EffectSleep:: seteffectprimary goto BattleScript_MoveEnd +BattleScript_TerrainPreventsEnd2:: + pause 0x20 + printfromtable gTerrainPreventsStringIds + waitmessage 0x40 + end2 + BattleScript_ElectricTerrainPrevents: pause 0x20 printstring STRINGID_ELECTRICTERRAINPREVENTS @@ -2733,11 +2739,11 @@ BattleScript_EffectRest:: attackcanceler attackstring ppreduce - jumpifterrainaffected BS_ATTACKER, (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_MISTY_TERRAIN), BattleScript_ButItFailed jumpifstatus BS_ATTACKER, STATUS1_SLEEP, BattleScript_RestIsAlreadyAsleep jumpifability BS_ATTACKER, ABILITY_COMATOSE, BattleScript_RestIsAlreadyAsleep jumpifcantmakeasleep BattleScript_RestCantSleep trysetrest BattleScript_AlreadyAtFullHp + jumpifterrainaffected BS_ATTACKER, (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_MISTY_TERRAIN), BattleScript_ButItFailed pause B_WAIT_TIME_SHORT printfromtable gRestUsedStringIds waitmessage B_WAIT_TIME_LONG @@ -4630,6 +4636,8 @@ BattleScript_EffectYawn:: jumpifability BS_TARGET, ABILITY_VITAL_SPIRIT, BattleScript_PrintBankAbilityMadeIneffective jumpifability BS_TARGET, ABILITY_INSOMNIA, BattleScript_PrintBankAbilityMadeIneffective jumpifability BS_TARGET, ABILITY_COMATOSE, BattleScript_PrintBankAbilityMadeIneffective + jumpifterrainaffected BS_TARGET, STATUS_FIELD_ELECTRIC_TERRAIN, BattleScript_ElectricTerrainPrevents + jumpifterrainaffected BS_TARGET, STATUS_FIELD_MISTY_TERRAIN, BattleScript_MistyTerrainPrevents jumpifflowerveil BattleScript_FlowerVeilProtects jumpifleafguard BattleScript_LeafGuardProtects jumpifshieldsdown BS_TARGET, BattleScript_LeafGuardProtects diff --git a/include/battle_scripts.h b/include/battle_scripts.h index f0712fc435..e48e4f12ba 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -369,5 +369,6 @@ extern const u8 BattleScript_JabocaRowapBerryActivates[]; extern const u8 BattleScript_NotAffectedAbilityPopUp[]; extern const u8 BattleScript_BattlerShookOffTaunt[]; extern const u8 BattleScript_BattlerGotOverItsInfatuation[]; +extern const u8 BattleScript_TerrainPreventsEnd2[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/src/battle_util.c b/src/battle_util.c index b7c6424c82..9900990e84 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2724,15 +2724,27 @@ u8 DoBattlerEndTurnEffects(void) if (!(gStatuses3[gActiveBattler] & STATUS3_YAWN) && !(gBattleMons[gActiveBattler].status1 & STATUS1_ANY) && gBattleMons[gActiveBattler].ability != ABILITY_VITAL_SPIRIT && gBattleMons[gActiveBattler].ability != ABILITY_INSOMNIA && !UproarWakeUpCheck(gActiveBattler) - && !IsLeafGuardProtected(gActiveBattler) - && !(gFieldStatuses & (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_MISTY_TERRAIN))) + && !IsLeafGuardProtected(gActiveBattler)) { CancelMultiTurnMoves(gActiveBattler); - gBattleMons[gActiveBattler].status1 |= (Random() & 3) + 2; - BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); - MarkBattlerForControllerExec(gActiveBattler); gEffectBattler = gActiveBattler; - BattleScriptExecute(BattleScript_YawnMakesAsleep); + if (IsBattlerTerrainAffected(gActiveBattler, STATUS_FIELD_ELECTRIC_TERRAIN)) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 1; + BattleScriptExecute(BattleScript_TerrainPreventsEnd2); + } + else if (IsBattlerTerrainAffected(gActiveBattler, STATUS_FIELD_MISTY_TERRAIN)) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + BattleScriptExecute(BattleScript_TerrainPreventsEnd2); + } + else + { + gBattleMons[gActiveBattler].status1 |= (Random() & 3) + 2; + BtlController_EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBattler].status1); + MarkBattlerForControllerExec(gActiveBattler); + BattleScriptExecute(BattleScript_YawnMakesAsleep); + } effect++; } }