Fix Megas gaining abilities after fainting (#4873)

This commit is contained in:
DizzyEggg 2024-06-26 23:44:01 +02:00 committed by GitHub
parent 566ad6d869
commit cd5a862b95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 5 deletions

View File

@ -190,7 +190,7 @@ bool32 IsBattlerMegaEvolved(u32 battler);
bool32 IsBattlerPrimalReverted(u32 battler);
bool32 IsBattlerUltraBursted(u32 battler);
u16 GetBattleFormChangeTargetSpecies(u32 battler, u16 method);
bool32 TryBattleFormChange(u32 battler, u16 method);
bool32 TryBattleFormChange(u32 battler, u32 method);
bool32 DoBattlersShareType(u32 battler1, u32 battler2);
bool32 CanBattlerGetOrLoseItem(u32 battler, u16 itemId);
u32 GetIllusionMonSpecies(u32 battler);

View File

@ -10568,12 +10568,12 @@ bool32 CanBattlerFormChange(u32 battler, u16 method)
return DoesSpeciesHaveFormChangeMethod(gBattleMons[battler].species, method);
}
bool32 TryBattleFormChange(u32 battler, u16 method)
bool32 TryBattleFormChange(u32 battler, u32 method)
{
u8 monId = gBattlerPartyIndexes[battler];
u8 side = GetBattlerSide(battler);
u32 monId = gBattlerPartyIndexes[battler];
u32 side = GetBattlerSide(battler);
struct Pokemon *party = GetBattlerParty(battler);
u16 targetSpecies;
u32 targetSpecies;
if (!CanBattlerFormChange(battler, method))
return FALSE;
@ -10611,10 +10611,14 @@ bool32 TryBattleFormChange(u32 battler, u16 method)
if (restoreSpecies)
{
u32 abilityForm = gBattleMons[battler].ability;
// Reverts the original species
TryToSetBattleFormChangeMoves(&party[monId], method);
SetMonData(&party[monId], MON_DATA_SPECIES, &gBattleStruct->changedSpecies[side][monId]);
RecalcBattlerStats(battler, &party[monId]);
// Battler data is not updated with regular form's ability, not doing so could cause wrong ability activation.
if (method == FORM_CHANGE_FAINT)
gBattleMons[battler].ability = abilityForm;
return TRUE;
}
}

View File

@ -153,3 +153,26 @@ SINGLE_BATTLE_TEST("Regular Mega Evolution and Fervent Wish Mega Evolution can h
EXPECT_EQ(opponent->species, SPECIES_GARDEVOIR_MEGA);
}
}
SINGLE_BATTLE_TEST("Mega Evolved Pokemon do not change abilities after fainting")
{
GIVEN {
ASSUME(gMovesInfo[MOVE_CRUNCH].makesContact == TRUE);
ASSUME(gSpeciesInfo[SPECIES_GARCHOMP_MEGA].abilities[0] != ABILITY_ROUGH_SKIN);
ASSUME(gSpeciesInfo[SPECIES_GARCHOMP_MEGA].abilities[1] != ABILITY_ROUGH_SKIN);
ASSUME(gSpeciesInfo[SPECIES_GARCHOMP_MEGA].abilities[2] != ABILITY_ROUGH_SKIN);
PLAYER(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_GARCHOMP) { Ability(ABILITY_ROUGH_SKIN); Item(ITEM_GARCHOMPITE); HP(1); }
} WHEN {
TURN { MOVE(player, MOVE_CRUNCH); MOVE(opponent, MOVE_CELEBRATE, megaEvolve: TRUE); }
} SCENE {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_MEGA_EVOLUTION, opponent);
ANIMATION(ANIM_TYPE_MOVE, MOVE_CRUNCH, player);
MESSAGE("Foe Garchomp fainted!");
NONE_OF {
ABILITY_POPUP(opponent, ABILITY_ROUGH_SKIN);
MESSAGE("Wobbuffet was hurt by Foe Garchomp's Rough Skin!");
HP_BAR(player);
}
}
}