From afc7795afc65e08fff59e2d8b171459c555aa810 Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:48:23 +0100 Subject: [PATCH] Removes duplicate Booster Energy code (#5656) --- src/battle_util.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/battle_util.c b/src/battle_util.c index 4a16b235c6..3ee127f389 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -7069,6 +7069,24 @@ static u8 TryConsumeMirrorHerb(u32 battler, bool32 execute) return effect; } +static inline u32 TryBoosterEnergy(u32 battler) +{ + if (gBattleStruct->boosterEnergyActivates & gBitTable[battler] || gBattleMons[battler].status2 & STATUS2_TRANSFORMED) + return ITEM_NO_EFFECT; + + if (((GetBattlerAbility(battler) == ABILITY_PROTOSYNTHESIS) && !((gBattleWeather & B_WEATHER_SUN) && WEATHER_HAS_EFFECT)) + || ((GetBattlerAbility(battler) == ABILITY_QUARK_DRIVE) && !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN))) + { + PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); + gBattlerAbility = gBattleScripting.battler = battler; + gBattleStruct->boosterEnergyActivates |= gBitTable[battler]; + BattleScriptExecute(BattleScript_BoosterEnergyEnd2); + return ITEM_EFFECT_OTHER; + } + + return ITEM_NO_EFFECT; +} + static u32 RestoreWhiteHerbStats(u32 battler) { u32 i, effect = 0; @@ -7585,17 +7603,7 @@ u8 ItemBattleEffects(u8 caseID, u32 battler, bool32 moveTurn) effect = TryConsumeMirrorHerb(battler, TRUE); break; case HOLD_EFFECT_BOOSTER_ENERGY: - if (!(gBattleStruct->boosterEnergyActivates & gBitTable[battler]) - && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED) - && (((GetBattlerAbility(battler) == ABILITY_PROTOSYNTHESIS) && !((gBattleWeather & B_WEATHER_SUN) && WEATHER_HAS_EFFECT)) - || ((GetBattlerAbility(battler) == ABILITY_QUARK_DRIVE) && !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN)))) - { - PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); - gBattleScripting.battler = battler; - gBattleStruct->boosterEnergyActivates |= gBitTable[battler]; - BattleScriptExecute(BattleScript_BoosterEnergyEnd2); - effect = ITEM_EFFECT_OTHER; - } + effect = TryBoosterEnergy(battler); break; } if (effect != 0) @@ -7853,17 +7861,7 @@ u8 ItemBattleEffects(u8 caseID, u32 battler, bool32 moveTurn) effect = TryConsumeMirrorHerb(battler, TRUE); break; case HOLD_EFFECT_BOOSTER_ENERGY: - if (!(gBattleStruct->boosterEnergyActivates & gBitTable[battler]) - && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED) - && (((GetBattlerAbility(battler) == ABILITY_PROTOSYNTHESIS) && !((gBattleWeather & B_WEATHER_SUN) && WEATHER_HAS_EFFECT)) - || ((GetBattlerAbility(battler) == ABILITY_QUARK_DRIVE) && !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN)))) - { - PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); - gBattlerAbility = gBattleScripting.battler = battler; - gBattleStruct->boosterEnergyActivates |= gBitTable[battler]; - BattleScriptExecute(BattleScript_BoosterEnergyEnd2); - effect = ITEM_EFFECT_OTHER; - } + effect = TryBoosterEnergy(battler); break; }