From 9823d2bdf1706b1a8a9f35073721d899515d3dfc Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 5 Aug 2019 12:15:15 +0200 Subject: [PATCH] Fix mega evo indicator priority on lvl-up-box --- src/battle_script_commands.c | 13 +++++++++++++ src/battle_util.c | 10 ++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index f9ccb4638..af5982f44 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6045,6 +6045,17 @@ static void atk6B_atknameinbuff1(void) gBattlescriptCurrInstr++; } +// Because the indicator must have priority 0 to be properly displayed on healthbox, it needs to be temporarily changed while displaying lvl-up-box. +static void ChangeMegaIndicatorsPriority(u32 priority) +{ + s32 i; + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + { + if (gBattleStruct->mega.indicatorSpriteIds[i] != 0xFF) + gSprites[gBattleStruct->mega.indicatorSpriteIds[i]].oam.priority = priority; + } +} + static void atk6C_drawlvlupbox(void) { if (gBattleScripting.atk6C_state == 0) @@ -6075,6 +6086,7 @@ static void atk6C_drawlvlupbox(void) SetBgAttribute(1, BG_ATTR_PRIORITY, 0); ShowBg(0); ShowBg(1); + ChangeMegaIndicatorsPriority(1); HandleBattleWindow(0x12, 7, 0x1D, 0x13, WINDOW_x80); gBattleScripting.atk6C_state = 4; break; @@ -6127,6 +6139,7 @@ static void atk6C_drawlvlupbox(void) case 10: if (!IsDma3ManagerBusyWithBgCopy()) { + ChangeMegaIndicatorsPriority(0); SetBgAttribute(0, BG_ATTR_PRIORITY, 0); SetBgAttribute(1, BG_ATTR_PRIORITY, 1); ShowBg(0); diff --git a/src/battle_util.c b/src/battle_util.c index 8846107c2..4e0164bd2 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -5750,7 +5750,7 @@ static u32 CalcDefenseStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType, } // sandstorm sp.def boost for rock types - if (WEATHER_HAS_EFFECT && gBattleWeather & WEATHER_SANDSTORM_ANY && IS_BATTLER_OF_TYPE(battlerDef, TYPE_ROCK) && !usesDefStat) + if (IS_BATTLER_OF_TYPE(battlerDef, TYPE_ROCK) && WEATHER_HAS_EFFECT && gBattleWeather & WEATHER_SANDSTORM_ANY && !usesDefStat) MulModifier(&modifier, UQ_4_12(1.5)); return ApplyModifier(modifier, defStat); @@ -6170,10 +6170,12 @@ bool32 CanMegaEvolve(u8 battlerId) mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]]; itemId = GetMonData(mon, MON_DATA_HELD_ITEM); - if (itemId != ITEM_ENIGMA_BERRY) - holdEffect = ItemId_GetHoldEffect(itemId); - else + if (USE_BATTLE_DEBUG && gBattleStruct->debugHoldEffects[battlerId]) + holdEffect = gBattleStruct->debugHoldEffects[battlerId]; + else if (itemId == ITEM_ENIGMA_BERRY) holdEffect = gEnigmaBerries[battlerId].holdEffect; + else + holdEffect = ItemId_GetHoldEffect(itemId); if (holdEffect != HOLD_EFFECT_MEGA_STONE) return FALSE;