diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 5a0bd8a17..98729fa7a 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -9278,11 +9278,15 @@ BattleScript_BerryStatRaiseRet_Anim: BattleScript_BerryStatRaiseRet_End: return -BattleScript_BerryFocusEnergyEnd2:: - playanimation BS_ATTACKER, B_ANIM_HELD_ITEM_EFFECT +BattleScript_BerryFocusEnergyRet:: + playanimation BS_SCRIPTING, B_ANIM_HELD_ITEM_EFFECT printstring STRINGID_PKMNUSEDXTOGETPUMPED waitmessage B_WAIT_TIME_LONG - removeitem BS_ATTACKER + removeitem BS_SCRIPTING + return + +BattleScript_BerryFocusEnergyEnd2:: + call BattleScript_BerryFocusEnergyRet end2 BattleScript_ActionSelectionItemsCantBeUsed:: diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 9f8e456ea..23f18e3be 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -216,6 +216,7 @@ extern const u8 BattleScript_BerryConfuseHealEnd2[]; extern const u8 BattleScript_BerryConfuseHealRet[]; extern const u8 BattleScript_BerryStatRaiseEnd2[]; extern const u8 BattleScript_BerryStatRaiseRet[]; +extern const u8 BattleScript_BerryFocusEnergyRet[]; extern const u8 BattleScript_BerryFocusEnergyEnd2[]; extern const u8 BattleScript_ActionSelectionItemsCantBeUsed[]; extern const u8 BattleScript_ArenaTurnBeginning[]; diff --git a/src/battle_debug.c b/src/battle_debug.c index 4450fe0cb..568b9a96e 100644 --- a/src/battle_debug.c +++ b/src/battle_debug.c @@ -271,6 +271,7 @@ static const struct BitfieldInfo sStatus2Bitfield[] = {/*Multiple Turns*/ 1, 12}, // Wrap bits are omitted. Done in various. // In Love bits are omitted. Done in various. + {/*(Focus Energy*/ 1, 20}, {/*Transformed*/ 1, 21}, {/*Recharge*/ 1, 22}, {/*Rage*/ 1, 23}, diff --git a/src/battle_util.c b/src/battle_util.c index 88ca3842d..4b07a6691 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -60,6 +60,7 @@ static bool32 TryRemoveScreens(u8 battler); static bool32 IsUnnerveAbilityOnOpposingSide(u8 battlerId); static u8 GetFlingPowerFromItemId(u16 itemId); static void SetRandomMultiHitCounter(); +static u32 GetBattlerItemHoldEffectParam(u8 battlerId, u16 item); extern const u8 *const gBattleScriptsForMoveEffects[]; extern const u8 *const gBattlescriptsForRunningByItem[]; @@ -6397,7 +6398,7 @@ static u8 HealConfuseBerry(u32 battlerId, u32 itemId, u8 flavorId, bool32 end2) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, flavorId); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / GetBattlerHoldEffectParam(battlerId); + gBattleMoveDamage = gBattleMons[battlerId].maxHP / GetBattlerItemHoldEffectParam(battlerId, itemId); if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; gBattleMoveDamage *= -1; @@ -6433,7 +6434,7 @@ static u8 HealConfuseBerry(u32 battlerId, u32 itemId, u8 flavorId, bool32 end2) static u8 StatRaiseBerry(u32 battlerId, u32 itemId, u32 statId, bool32 end2) { - if (CompareStat(battlerId, statId, MAX_STAT_STAGE, CMP_LESS_THAN) && HasEnoughHpToEatBerry(battlerId, GetBattlerHoldEffectParam(battlerId), itemId)) + if (CompareStat(battlerId, statId, MAX_STAT_STAGE, CMP_LESS_THAN) && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, itemId), itemId)) { BufferStatChange(battlerId, statId, STRINGID_STATROSE); gEffectBattler = battlerId; @@ -6469,7 +6470,7 @@ static u8 RandomStatRaiseBerry(u32 battlerId, u32 itemId, bool32 end2) if (CompareStat(battlerId, STAT_ATK + i, MAX_STAT_STAGE, CMP_LESS_THAN)) break; } - if (i != NUM_STATS - 1 && HasEnoughHpToEatBerry(battlerId, GetBattlerHoldEffectParam(battlerId), itemId)) + if (i != NUM_STATS - 1 && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, itemId), itemId)) { u16 battlerAbility = GetBattlerAbility(battlerId); do @@ -6588,9 +6589,9 @@ static u8 ItemHealHp(u32 battlerId, u32 itemId, bool32 end2, bool32 percentHeal) && HasEnoughHpToEatBerry(battlerId, 2, itemId)) { if (percentHeal) - gBattleMoveDamage = (gBattleMons[battlerId].maxHP * GetBattlerHoldEffectParam(battlerId) / 100) * -1; + gBattleMoveDamage = (gBattleMons[battlerId].maxHP * GetBattlerItemHoldEffectParam(battlerId, itemId) / 100) * -1; else - gBattleMoveDamage = GetBattlerHoldEffectParam(battlerId) * -1; + gBattleMoveDamage = GetBattlerItemHoldEffectParam(battlerId, itemId) * -1; // check ripen if (ItemId_GetPocket(itemId) == POCKET_BERRIES && GetBattlerAbility(battlerId) == ABILITY_RIPEN) @@ -6841,6 +6842,19 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) return effect; } break; + case HOLD_EFFECT_CRITICAL_UP: // lansat berry + if (B_BERRIES_INSTANT >= GEN_4 + && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY) + && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, gLastUsedItem), gLastUsedItem)) + { + gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; + gBattleScripting.battler = battlerId; + gPotentialItemEffectBattler = battlerId; + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_BerryFocusEnergyRet; + effect = ITEM_EFFECT_OTHER; + } + break; } return effect; @@ -6927,9 +6941,10 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPDEF, TRUE); break; case HOLD_EFFECT_CRITICAL_UP: - if (!(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY) && HasEnoughHpToEatBerry(battlerId, GetBattlerHoldEffectParam(battlerId), gLastUsedItem)) + if (!(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY) && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, gLastUsedItem), gLastUsedItem)) { gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; + gBattleScripting.battler = battlerId; BattleScriptExecute(BattleScript_BerryFocusEnergyEnd2); effect = ITEM_EFFECT_OTHER; } @@ -7243,9 +7258,10 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) break; case HOLD_EFFECT_CRITICAL_UP: if (!moveTurn && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY) - && HasEnoughHpToEatBerry(battlerId, GetBattlerHoldEffectParam(battlerId), gLastUsedItem)) + && HasEnoughHpToEatBerry(battlerId, GetBattlerItemHoldEffectParam(battlerId, gLastUsedItem), gLastUsedItem)) { gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; + gBattleScripting.battler = battlerId; BattleScriptExecute(BattleScript_BerryFocusEnergyEnd2); effect = ITEM_EFFECT_OTHER; } @@ -7975,6 +7991,15 @@ u32 GetBattlerHoldEffect(u8 battlerId, bool32 checkNegating) return ItemId_GetHoldEffect(gBattleMons[battlerId].item); } +// +static u32 GetBattlerItemHoldEffectParam(u8 battlerId, u16 item) +{ + if (item == ITEM_ENIGMA_BERRY) + return gEnigmaBerries[battlerId].holdEffectParam; + else + return ItemId_GetHoldEffectParam(item); +} + u32 GetBattlerHoldEffectParam(u8 battlerId) { if (gBattleMons[battlerId].item == ITEM_ENIGMA_BERRY)