From fad1ce51618607c005e0b7a8cec1a27d500a6448 Mon Sep 17 00:00:00 2001 From: Isaac Rivera Date: Sat, 19 Oct 2024 01:26:10 -0400 Subject: [PATCH] add handling for gaining insomnia/vital spirit, wake up slap, uproar, transforming --- src/battle_script_commands.c | 39 ++++++++++++++++++++++++++++++++++++ src/battle_util.c | 11 ++++++++++ test/battle/sleep_clause.c | 23 ++++++++++++++++----- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9a7528f43e2..aa1a50bb2b7 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5717,6 +5717,11 @@ static void Cmd_moveend(void) gBattlescriptCurrInstr = BattleScript_TargetPRLZHeal; break; case STATUS1_SLEEP: + if (B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerTarget)] && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerTarget)][gBattlerPartyIndexes[gBattlerTarget]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerTarget)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerTarget)][gBattlerPartyIndexes[gBattlerTarget]] = FALSE; + } gBattlescriptCurrInstr = BattleScript_TargetWokeUp; break; case STATUS1_BURN: @@ -13185,6 +13190,7 @@ static void Cmd_healpartystatus(void) u32 zero = 0; u32 partner = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker))); u8 toHeal = 0; + bool32 isStatusSleep = (gBattleMons[gBattlerAttacker].status1 & STATUS1_SLEEP); if (gCurrentMove == MOVE_HEAL_BELL) { @@ -13198,6 +13204,13 @@ static void Cmd_healpartystatus(void) { gBattleMons[gBattlerAttacker].status1 = 0; gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; + if(B_SLEEP_CLAUSE && isStatusSleep + && gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] + && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]] = FALSE; + } } else { @@ -13211,8 +13224,16 @@ static void Cmd_healpartystatus(void) { if (GetBattlerAbility(partner) != ABILITY_SOUNDPROOF || B_HEAL_BELL_SOUNDPROOF == GEN_5) { + isStatusSleep = (gBattleMons[partner].status1 & STATUS1_SLEEP); gBattleMons[partner].status1 = 0; gBattleMons[partner].status2 &= ~STATUS2_NIGHTMARE; + if(B_SLEEP_CLAUSE && isStatusSleep + && gBattleStruct->sleepClause.isActive[GetBattlerSide(partner)] + && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(partner)][gBattlerPartyIndexes[partner]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(partner)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(partner)][gBattlerPartyIndexes[partner]] = FALSE; + } } else { @@ -13268,6 +13289,23 @@ static void Cmd_healpartystatus(void) gBattleMons[gBattlerAttacker].status1 = 0; gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; + if(B_SLEEP_CLAUSE && isStatusSleep) + { + if(gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] + && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]] = FALSE; + } + + else if(gBattleStruct->sleepClause.isActive[GetBattlerSide(partner)] + && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(partner)][gBattlerPartyIndexes[partner]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(partner)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(partner)][gBattlerPartyIndexes[partner]] = FALSE; + } + } + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && !(gAbsentBattlerFlags & gBitTable[partner])) { @@ -14635,6 +14673,7 @@ static void Cmd_switchoutabilities(void) { switch (GetBattlerAbility(battler)) { + //todo sleep clause here natural cure case ABILITY_NATURAL_CURE: gBattleMons[battler].status1 = 0; BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, diff --git a/src/battle_util.c b/src/battle_util.c index 872f82281a9..50059842edf 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -3273,6 +3273,12 @@ u8 AtkCanceller_UnableToUseMove(u32 moveType) { if (UproarWakeUpCheck(gBattlerAttacker)) { + if (B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] && gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]]) + { + gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] = FALSE; + gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]] = FALSE; + } + gBattleMons[gBattlerAttacker].status1 &= ~STATUS1_SLEEP; gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE; BattleScriptPushCursor(); @@ -6119,6 +6125,11 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 case ABILITY_VITAL_SPIRIT: if (gBattleMons[battler].status1 & STATUS1_SLEEP) { + 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; + } gBattleMons[battler].status2 &= ~STATUS2_NIGHTMARE; StringCopy(gBattleTextBuff1, gStatusConditionString_SleepJpn); effect = 1; diff --git a/test/battle/sleep_clause.c b/test/battle/sleep_clause.c index b3ba9370019..d79d5d787f5 100644 --- a/test/battle/sleep_clause.c +++ b/test/battle/sleep_clause.c @@ -317,6 +317,7 @@ DOUBLE_BATTLE_TEST("Sleep Clause: G-Max Befuddle can only sleep one opposing mon //honestly some of these are probably covered by just normal sleep tests // also possible that these should be done in doubles since its kinda just a nomral "mon woke up" test +// ADDED HANDLING FOR THIS TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon wakes up"); // something like: // player has wob @@ -371,6 +372,8 @@ TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon // AI switches, player uses spore, it fails // AI switches back to sleeping wob, player uses wake-up-slap/uproar, which wakes up enemy wob // AI switches AGAIN, player uses spore, it succeeds + // fun fact, uproar and wake-up slap are handled in 2 different places, so probably each require a test + // added handling for both though // this feels like a horribly complicated scenario that would probably not happen in a million runs but unfortunately i thought of it so i will // write it down @@ -378,33 +381,43 @@ TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon // replace psycho shift with the following moves: // jungle healing, lunar blessing, refresh, purify (maybe?), take heart + +// ADDED HANDLING FOR THIS TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by the ability hydration in the rain"); TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by the ability natural cure"); +// ADDED HANDLING FOR THIS TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by the ability shed skin"); TO_DO_BATTLE_TEST("DOUBLES TEST: Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by the ability healer"); +// ADDED HANDLING FOR THIS TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by the item awakening"); // replace awakening with the following items: // blue flute, chesto berry, big malasada, casteliacone, full heal, full restore, heal powder, lava cookie, lum berry // lumiose galett, miracle berry?, old gateau, pewter Crunchies, rage candy bar, shalour sable // idk wtf half these items even are and id imagine a lot of them share effects so i doubt a test will be needed for all of them +// ADDED HANDLING FOR THIS TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by gaining the ability Insomnia"); +// ADDED HANDLING FOR THIS TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by gaining the ability Vital Spirit"); +// ADDED HANDLING FOR THIS TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon faints"); -TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping uses sleep talk -> explosion"); // holy fuck if this requires special handling im uninstalling +TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon uses sleep talk -> explosion"); // holy fuck if this requires special handling im uninstalling -TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping uses sleep talk -> move that KOs a mon that has used destiny bond"); +TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon uses sleep talk -> move that KOs a mon that has used destiny bond"); -TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping uses sleep talk -> role play/skill swap"); +// ADDED HANDLING FOR THIS +TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is sent out, has trace, and traces insomnia/vital spirit"); +// ADDED HANDLING FOR THIS +TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by a held item, like chesto"); -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"); +// ADDED HANDLING FOR THIS +TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is sent out and transforms into a mon with insomnia/vital spirit");