Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buggy pokemon anims with Illusion #2639

Merged
merged 3 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void UndoMegaEvolution(u32 monId);
void UndoFormChange(u32 monId, u32 side, bool32 isSwitchingOut);
bool32 DoBattlersShareType(u32 battler1, u32 battler2);
bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId);
u32 GetIllusionMonSpecies(u32 battlerId);
struct Pokemon *GetIllusionMonPtr(u32 battlerId);
void ClearIllusionMon(u32 battlerId);
bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId);
Expand Down
4 changes: 3 additions & 1 deletion src/battle_controller_link_opponent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,9 @@ static void StartSendOutAnim(u8 battlerId, bool8 dontClearSubstituteBit)

ClearTemporarySpeciesSpriteData(battlerId, dontClearSubstituteBit);
gBattlerPartyIndexes[battlerId] = gBattleResources->bufferA[battlerId][1];
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);
species = GetIllusionMonSpecies(battlerId);
if (species == SPECIES_NONE)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);
gBattleControllerData[battlerId] = CreateInvisibleSpriteWithCallback(SpriteCB_WaitForBattlerBallReleaseAnim);
BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId);
SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId));
Expand Down
4 changes: 3 additions & 1 deletion src/battle_controller_opponent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,9 @@ static void StartSendOutAnim(u8 battlerId, bool8 dontClearSubstituteBit)

ClearTemporarySpeciesSpriteData(battlerId, dontClearSubstituteBit);
gBattlerPartyIndexes[battlerId] = gBattleResources->bufferA[battlerId][1];
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);
species = GetIllusionMonSpecies(battlerId);
if (species == SPECIES_NONE)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);
gBattleControllerData[battlerId] = CreateInvisibleSpriteWithCallback(SpriteCB_WaitForBattlerBallReleaseAnim);
BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId);
SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId));
Expand Down
26 changes: 17 additions & 9 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3814,7 +3814,7 @@ u8 AtkCanceller_UnableToUseMove(void)
{
SetRandomMultiHitCounter();
}

PREPARE_BYTE_NUMBER_BUFFER(gBattleScripting.multihitString, 1, 0)
}
else if (gBattleMoves[gCurrentMove].flags & FLAG_TWO_STRIKES)
Expand All @@ -3841,7 +3841,7 @@ u8 AtkCanceller_UnableToUseMove(void)
party = gPlayerParty;
else
party = gEnemyParty;

for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&party[i], MON_DATA_HP)
Expand Down Expand Up @@ -5487,7 +5487,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
RecordItemEffectBattle(gBattlerAttacker, HOLD_EFFECT_ABILITY_SHIELD);
break;
}

gLastUsedAbility = gBattleMons[gBattlerAttacker].ability;
gBattleMons[gBattlerAttacker].ability = gBattleStruct->overwrittenAbilities[gBattlerAttacker] = gBattleMons[gBattlerTarget].ability;
gBattleMons[gBattlerTarget].ability = gBattleStruct->overwrittenAbilities[gBattlerTarget] = gLastUsedAbility;
Expand Down Expand Up @@ -6858,7 +6858,7 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect)
{
u8 effect = 0;
u32 i;

switch (holdEffect)
{
#if B_HP_BERRIES >= GEN_4
Expand Down Expand Up @@ -7027,7 +7027,7 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect)
&& !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY)
&& HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, gLastUsedItem), gLastUsedItem))
{
gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY;
gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY;
gBattleScripting.battler = battlerId;
gPotentialItemEffectBattler = battlerId;
BattleScriptPushCursor();
Expand All @@ -7036,7 +7036,7 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect)
}
break;
}

return effect;
}

Expand All @@ -7053,7 +7053,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn)
gLastUsedItem = gBattleMons[battlerId].item;
battlerHoldEffect = GetBattlerHoldEffect(battlerId, TRUE);
}

atkItem = gBattleMons[gBattlerAttacker].item;
atkHoldEffect = GetBattlerHoldEffect(gBattlerAttacker, TRUE);
atkHoldEffectParam = GetBattlerHoldEffectParam(gBattlerAttacker);
Expand Down Expand Up @@ -8184,7 +8184,7 @@ u32 GetBattlerHoldEffect(u8 battlerId, bool32 checkNegating)
return ItemId_GetHoldEffect(gBattleMons[battlerId].item);
}

//
//
static u32 GetBattlerItemHoldEffectParam(u8 battlerId, u16 item)
{
if (item == ITEM_ENIGMA_BERRY)
Expand Down Expand Up @@ -8234,7 +8234,7 @@ bool32 IsBattlerProtected(u8 battlerId, u16 move)
else if (gProtectStructs[battlerId].protected)
return FALSE;
}

if (move == MOVE_TEATIME)
{
return FALSE;
Expand Down Expand Up @@ -10266,6 +10266,14 @@ void ClearIllusionMon(u32 battlerId)
memset(&gBattleStruct->illusion[battlerId], 0, sizeof(gBattleStruct->illusion[battlerId]));
}

u32 GetIllusionMonSpecies(u32 battlerId)
{
struct Pokemon *illusionMon = GetIllusionMonPtr(battlerId);
if (illusionMon != NULL)
return GetMonData(illusionMon, MON_DATA_SPECIES);
return SPECIES_NONE;
}

bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId)
{
struct Pokemon *party, *partnerMon;
Expand Down