Skip to content

Commit

Permalink
Fixes weather abilities not activating when Cloud Nine user leaves th… (
Browse files Browse the repository at this point in the history
rh-hideout#5209)

* Fixes weather abilities not activating when Cloud Nine user leaves the field

* parametrize
  • Loading branch information
AlexOn1ine authored Aug 20, 2024
1 parent a111ac4 commit bde6982
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
4 changes: 2 additions & 2 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -7150,7 +7150,7 @@ BattleScript_TargetFormChangeWithStringNoPopup::

BattleScript_BattlerFormChangeWithStringEnd3::
pause 5
call BattleScript_AbilityPopUp
call BattleScript_AbilityPopUpScripting
flushtextbox
handleformchange BS_SCRIPTING, 0
handleformchange BS_SCRIPTING, 1
Expand Down Expand Up @@ -8010,7 +8010,7 @@ BattleScript_DeltaStreamActivates::
end3

BattleScript_ProtosynthesisActivates::
call BattleScript_AbilityPopUp
call BattleScript_AbilityPopUpScripting
printstring STRINGID_SUNLIGHTACTIVATEDABILITY
waitmessage B_WAIT_TIME_MED
printstring STRINGID_STATWASHEIGHTENED
Expand Down
29 changes: 21 additions & 8 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -7292,19 +7292,32 @@ static bool32 DoSwitchInEffectsForBattler(u32 battler)

gDisableStructs[battler].truantSwitchInHack = 0;

for (i = 0; i < gBattlersCount; i++)
{
if (i != battler
&& GetBattlerAbility(i) == ABILITY_TRACE
&& AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, i, 0, 0, 0))
return TRUE;
}

if (DoSwitchInAbilities(battler) || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, battler, FALSE))
return TRUE;
else if (AbilityBattleEffects(ABILITYEFFECT_OPPORTUNIST, battler, 0, 0, 0))
return TRUE;

for (i = 0; i < gBattlersCount; i++)
{
if (i == battler)
continue;

switch (GetBattlerAbility(i))
{
case ABILITY_TRACE:
if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, i, 0, 0, 0))
return TRUE;
break;
case ABILITY_FORECAST:
case ABILITY_FLOWER_GIFT:
case ABILITY_ICE_FACE:
case ABILITY_PROTOSYNTHESIS:
if (AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, i, 0, 0, 0))
return TRUE;
break;
}
}

gDisableStructs[battler].stickyWebDone = FALSE;
gDisableStructs[battler].spikesDone = FALSE;
gDisableStructs[battler].toxicSpikesDone = FALSE;
Expand Down
13 changes: 7 additions & 6 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4767,7 +4767,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
}
break;
case ABILITY_WIND_RIDER:
if (!gSpecialStatuses[battler].switchInAbilityDone
if (!gSpecialStatuses[battler].switchInAbilityDone
&& CompareStat(battler, STAT_ATK, MAX_STAT_STAGE, CMP_LESS_THAN)
&& gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_TAILWIND)
{
Expand Down Expand Up @@ -6269,17 +6269,17 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
}
break;
case ABILITYEFFECT_ON_WEATHER: // For ability effects that activate when the battle weather changes.
battler = gBattlerAbility = gBattleScripting.battler;
gLastUsedAbility = GetBattlerAbility(battler);
switch (gLastUsedAbility)
{
case ABILITY_FORECAST:
case ABILITY_FLOWER_GIFT:
if ((IsBattlerWeatherAffected(battler, gBattleWeather)
|| gBattleWeather == B_WEATHER_NONE
|| !WEATHER_HAS_EFFECT) // Air Lock active
&& TryBattleFormChange(battler, FORM_CHANGE_BATTLE_WEATHER))
|| gBattleWeather == B_WEATHER_NONE
|| !WEATHER_HAS_EFFECT) // Air Lock active
&& TryBattleFormChange(battler, FORM_CHANGE_BATTLE_WEATHER))
{
gBattleScripting.battler = battler;
BattleScriptPushCursorAndCallback(BattleScript_BattlerFormChangeWithStringEnd3);
effect++;
}
Expand All @@ -6290,6 +6290,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
&& !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED))
{
// TODO: Convert this to a proper FORM_CHANGE type.
gBattleScripting.battler = battler;
gBattleMons[battler].species = SPECIES_EISCUE_ICE_FACE;
BattleScriptPushCursorAndCallback(BattleScript_BattlerFormChangeWithStringEnd3);
effect++;
Expand All @@ -6300,7 +6301,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
{
gDisableStructs[battler].weatherAbilityDone = TRUE;
PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler));
gBattlerAbility = gBattleScripting.battler = battler;
gBattleScripting.battler = battler;
BattleScriptPushCursorAndCallback(BattleScript_ProtosynthesisActivates);
effect++;
}
Expand Down
22 changes: 22 additions & 0 deletions test/battle/ability/forecast.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,25 @@ SINGLE_BATTLE_TEST("Forecast transforms Castform back when it uses a move that f
EXPECT_EQ(GetMonData(&gPlayerParty[0], MON_DATA_SPECIES), SPECIES_CASTFORM);
}
}

SINGLE_BATTLE_TEST("Forecast transforms Castform when Cloud Nine ability user leaves the field")
{
u32 species = 0, ability = 0;
PARAMETRIZE { species = SPECIES_PSYDUCK; ability = ABILITY_CLOUD_NINE; }
PARAMETRIZE { species = SPECIES_RAYQUAZA; ability = ABILITY_AIR_LOCK; }

GIVEN {
PLAYER(SPECIES_CASTFORM) { Ability(ABILITY_FORECAST); }
OPPONENT(species) { Ability(ability); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_SUNNY_DAY); MOVE(opponent, MOVE_CELEBRATE); }
TURN { SWITCH(opponent, 1); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_SUNNY_DAY, player);
ANIMATION(ANIM_TYPE_MOVE, MOVE_CELEBRATE, opponent);
MESSAGE("2 sent out Wobbuffet!");
ABILITY_POPUP(player, ABILITY_FORECAST);
MESSAGE("Castform transformed!");
}
}

0 comments on commit bde6982

Please sign in to comment.