From 42bc12a6d59ebb517b16bb64346b5d883e5eca9e Mon Sep 17 00:00:00 2001 From: Isaac Rivera Date: Sun, 6 Oct 2024 00:19:41 -0400 Subject: [PATCH] handle deactivating sleep clause when being awoken by a held item --- src/battle_util.c | 15 +++++++++++++++ src/pokemon.c | 2 ++ test/battle/sleep_clause.c | 2 ++ 3 files changed, 19 insertions(+) diff --git a/src/battle_util.c b/src/battle_util.c index d71e6a642e50..f8f96e3b3583 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -7222,6 +7222,11 @@ static u8 ItemEffectMoveEnd(u32 battler, u16 holdEffect) BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BerryCureSlpRet; effect = ITEM_STATUS_CHANGE; + if (B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = FALSE; + } } break; case HOLD_EFFECT_CURE_CONFUSION: @@ -7463,6 +7468,11 @@ u8 ItemBattleEffects(u8 caseID, u32 battler, bool32 moveTurn) gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; BattleScriptExecute(BattleScript_BerryCureSlpEnd2); effect = ITEM_STATUS_CHANGE; + if (B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = FALSE; + } } break; case HOLD_EFFECT_CURE_STATUS: @@ -7769,6 +7779,11 @@ u8 ItemBattleEffects(u8 caseID, u32 battler, bool32 moveTurn) gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; BattleScriptExecute(BattleScript_BerryCureSlpEnd2); effect = ITEM_STATUS_CHANGE; + if (B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = FALSE; + } } break; case HOLD_EFFECT_CURE_CONFUSION: diff --git a/src/pokemon.c b/src/pokemon.c index 51c44b82144c..fe13010ed186 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4186,6 +4186,7 @@ bool8 HealStatusConditions(struct Pokemon *mon, u32 healMask, u8 battlerId) u32 status = GetMonData(mon, MON_DATA_STATUS, 0); u32 i = 0; u32 battlerSide = GetBattlerSide(battlerId); + if (status & healMask) { status &= ~healMask; @@ -4207,6 +4208,7 @@ bool8 HealStatusConditions(struct Pokemon *mon, u32 healMask, u8 battlerId) { gBattleStruct->sleepClause.isActive[battlerSide] = FALSE; gBattleStruct->sleepClause.isCausingSleepClause[battlerSide][i] = FALSE; + break; } } } diff --git a/test/battle/sleep_clause.c b/test/battle/sleep_clause.c index 662c9d33c4c8..b3ba93700197 100644 --- a/test/battle/sleep_clause.c +++ b/test/battle/sleep_clause.c @@ -406,3 +406,5 @@ TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping use TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping is sent out, has trace, and traces insomnia/vital spirit"); + +TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by a held item, like chesto");