Skip to content

Commit

Permalink
add handling for psycho shift and healbell/aromatherapy
Browse files Browse the repository at this point in the history
  • Loading branch information
iriv24 committed Oct 21, 2024
1 parent 5e26d03 commit bc8120f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
94 changes: 48 additions & 46 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -10019,11 +10019,26 @@ static void Cmd_various(void)
BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1);
MarkBattlerForControllerExec(battler);
gBattlescriptCurrInstr = cmd->nextInstr;
if (B_SLEEP_CLAUSE)
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(battler)] = TRUE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]] = TRUE;
}
return;
}
case VARIOUS_CURE_STATUS:
{
VARIOUS_ARGS();

if (B_SLEEP_CLAUSE
&& (gBattleMons[battler].status1 & STATUS1_SLEEP)
&& 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].status1 = 0;
BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1);
MarkBattlerForControllerExec(battler);
Expand Down Expand Up @@ -13184,13 +13199,11 @@ static void Cmd_tryspiteppreduce(void)

static void Cmd_healpartystatus(void)
{
// TODO sleep clause: bug when the mon in the right slot in a double battle uses heal bell/aromatherapy, sleep clause is not deactivated
CMD_ARGS();

u32 zero = 0;
u32 partner = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker)));
u8 toHeal = 0;
bool32 isStatusSleep = (gBattleMons[gBattlerAttacker].status1 & STATUS1_SLEEP);
struct Pokemon *party = GetBattlerParty(gBattlerAttacker);
s32 i;

Expand All @@ -13203,13 +13216,6 @@ 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
{
Expand All @@ -13223,16 +13229,8 @@ 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(gBattlerAttacker)]
&& gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[partner]])
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[partner]] = FALSE;
}
}
else
{
Expand Down Expand Up @@ -13276,7 +13274,25 @@ static void Cmd_healpartystatus(void)
}

if (ability != ABILITY_SOUNDPROOF)
{
toHeal |= (1 << i);

if (B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i])
{
gBattleStruct->sleepClause.isActive[gBattlerAttacker] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i] = FALSE;
}

if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE
&& !(gAbsentBattlerFlags & gBitTable[partner]))
{
if (B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isCausingSleepClause[partner][i])
{
gBattleStruct->sleepClause.isActive[partner] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[partner][i] = FALSE;
}
}
}
}
}
}
Expand All @@ -13285,29 +13301,28 @@ static void Cmd_healpartystatus(void)
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SOOTHING_AROMA;
toHeal = (1 << PARTY_SIZE) - 1;

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]])
if (B_SLEEP_CLAUSE)
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]] = FALSE;
gBattleStruct->sleepClause.isActive[gBattlerAttacker] = FALSE;
for (i = 0; i < PARTY_SIZE; i++)
{
gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i] = FALSE;
}
}

gBattleMons[gBattlerAttacker].status1 = 0;
gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_NIGHTMARE;

if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE
&& !(gAbsentBattlerFlags & gBitTable[partner]))
{
isStatusSleep = (gBattleMons[partner].status1 & STATUS1_SLEEP);
if(B_SLEEP_CLAUSE
&& isStatusSleep
&& gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)]
&& gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[partner]])
if (B_SLEEP_CLAUSE)
{
gBattleStruct->sleepClause.isActive[GetBattlerSide(gBattlerAttacker)] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[partner]] = FALSE;
gBattleStruct->sleepClause.isActive[partner] = FALSE;
for (i = 0; i < PARTY_SIZE; i++)
{
gBattleStruct->sleepClause.isCausingSleepClause[partner][i] = FALSE;
}
}
gBattleMons[partner].status1 = 0;
gBattleMons[partner].status2 &= ~STATUS2_NIGHTMARE;
Expand All @@ -13317,19 +13332,6 @@ static void Cmd_healpartystatus(void)

if (toHeal)
{
if(B_SLEEP_CLAUSE && gBattleStruct->sleepClause.isActive[gBattlerAttacker])
{
for (i = 0; i < PARTY_SIZE; i++)
{
if ((GetMonData(&party[i], MON_DATA_STATUS, 0) & STATUS1_SLEEP) && gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i])
{
gBattleStruct->sleepClause.isActive[gBattlerAttacker] = FALSE;
gBattleStruct->sleepClause.isCausingSleepClause[gBattlerAttacker][i] = FALSE;
break;
}
}
}

BtlController_EmitSetMonData(gBattlerAttacker, BUFFER_A, REQUEST_STATUS_BATTLE, toHeal, sizeof(zero), &zero);
MarkBattlerForControllerExec(gBattlerAttacker);
}
Expand Down
3 changes: 1 addition & 2 deletions test/battle/sleep_clause.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon

// 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
//ADDED HANDLING FOR THIS
TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon is woken up by using sleep talk into psycho shift");
// replace psycho shift with the following moves:
// jungle healing, lunar blessing, refresh, purify (maybe?), take heart
Expand Down Expand Up @@ -421,6 +422,4 @@ TO_DO_BATTLE_TEST("Sleep Clause: sleep clause is deactivated when a sleeping mon
// 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");

//TODO bug when the mon in the right slot in a double battle uses heal bell/aromatherapy, sleep clause is not deactivated

//TODO treat falling asleep from disobeying the same as rest

0 comments on commit bc8120f

Please sign in to comment.