From 4ca6d76160b01738d9fcd326643a89828a045b61 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Sun, 25 Jul 2021 14:55:52 -0600 Subject: [PATCH] add bug bite --- asm/macros/battle_script.inc | 5 ++++ data/battle_scripts_1.s | 5 ++++ include/battle.h | 1 + include/battle_util.h | 1 + include/constants/battle_script_commands.h | 2 ++ src/battle_script_commands.c | 31 ++++++++++++++++++++-- src/battle_util.c | 5 ++++ 7 files changed, 48 insertions(+), 2 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 9fa3fe0c32..953180d91d 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1768,6 +1768,11 @@ .macro tryactivategrimneigh, battler:req various \battler, VARIOUS_TRY_ACTIVATE_GRIM_NEIGH .endm + + .macro consumeberry battler:req, restoreItem=FALSE + various \battler, VARIOUS_CONSUME_BERRY + .byte \restoreItem + .endm @ helpful macros .macro setstatchanger stat:req, stages:req, down:req diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 522ffb7014..d48076e489 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -508,6 +508,11 @@ BattleScript_MoveEffectIncinerate:: BattleScript_MoveEffectBugBite:: printstring STRINGID_BUGBITE waitmessage B_WAIT_TIME_LONG + orword gHitMarker, HITMARKER_NO_ANIMATIONS + setbyte sBERRY_OVERRIDE, TRUE @ override the requirements for eating berries + consumeberry BS_ATTACKER, TRUE @ consume the berry, then restore the item from changedItems + bicword gHitMarker, HITMARKER_NO_ANIMATIONS + setbyte sBERRY_OVERRIDE, FALSE return BattleScript_EffectCoreEnforcer: diff --git a/include/battle.h b/include/battle.h index b51a3d71b1..e822537473 100644 --- a/include/battle.h +++ b/include/battle.h @@ -659,6 +659,7 @@ struct BattleScripting u8 illusionNickHack; // To properly display nick in STRINGID_ENEMYABOUTTOSWITCHPKMN. bool8 fixedPopup; // force ability popup to stick until manually called back u16 abilityPopupOverwrite; + u8 overrideBerryRequirements; }; // rom_80A5C6C diff --git a/include/battle_util.h b/include/battle_util.h index e10305e564..bea6af8480 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -31,6 +31,7 @@ #define ITEMEFFECT_KINGSROCK_SHELLBELL 0x4 #define ITEMEFFECT_TARGET 0x5 #define ITEMEFFECT_ORBS 0x6 +#define ITEMEFFECT_BATTLER_MOVE_END 0x7 // move end effects for just the battler, not whole field #define WEATHER_HAS_EFFECT ((!IsAbilityOnField(ABILITY_CLOUD_NINE) && !IsAbilityOnField(ABILITY_AIR_LOCK))) diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index faaf8f17e0..881bb82e0d 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -37,6 +37,7 @@ #define sILLUSION_NICK_HACK gBattleScripting + 0x32 #define sFIXED_ABILITY_POPUP gBattleScripting + 0x33 #define sABILITY_OVERWRITE gBattleScripting + 0x34 +#define sBERRY_OVERRIDE gBattleScripting + 0x36 #define cMULTISTRING_CHOOSER gBattleCommunication + 5 #define cMISS_TYPE gBattleCommunication + 6 @@ -173,6 +174,7 @@ #define VARIOUS_DESTROY_ABILITY_POPUP 102 #define VARIOUS_TOTEM_BOOST 103 #define VARIOUS_TRY_ACTIVATE_GRIM_NEIGH 104 +#define VARIOUS_CONSUME_BERRY 105 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index de7105a270..067d0b62e2 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3284,16 +3284,22 @@ void SetMoveEffect(bool32 primary, u32 certain) } break; case MOVE_EFFECT_BUG_BITE: - if ((gBattleMons[gEffectBattler].item >= FIRST_BERRY_INDEX && gBattleMons[gEffectBattler].item <= LAST_BERRY_INDEX) + if (ItemId_GetPocket(gBattleMons[gEffectBattler].item) == POCKET_BERRIES && GetBattlerAbility(gEffectBattler) != ABILITY_STICKY_HOLD) { + // target loses their berry gLastUsedItem = gBattleMons[gEffectBattler].item; gBattleMons[gEffectBattler].item = 0; CheckSetUnburden(gEffectBattler); - gActiveBattler = gEffectBattler; + BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gEffectBattler].item); MarkBattlerForControllerExec(gActiveBattler); + + // attacker temporarily gains their item + gBattleStruct->changedItems[gBattlerAttacker] = gBattleMons[gBattlerAttacker].item; + gBattleMons[gBattlerAttacker].item = gLastUsedItem; + BattleScriptPush(gBattlescriptCurrInstr + 1); gBattlescriptCurrInstr = BattleScript_MoveEffectBugBite; } @@ -8422,6 +8428,27 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 7; // exit if loop failed (failsafe) } return; + case VARIOUS_CONSUME_BERRY: + if (ItemId_GetHoldEffect(gBattleMons[gActiveBattler].item) == HOLD_EFFECT_NONE) + { + gBattlescriptCurrInstr += 4; + return; + } + + gBattleScripting.battler = gEffectBattler = gBattlerTarget = gActiveBattler; // cover all berry effect battlerId cases. e.g. ChangeStatBuffs uses target ID + // do move end berry effects for just a single battler, instead of looping through all battlers + if (ItemBattleEffects(ITEMEFFECT_BATTLER_MOVE_END, gActiveBattler, FALSE)) + return; + + if (gBattlescriptCurrInstr[3]) + { + gBattleMons[gActiveBattler].item = gBattleStruct->changedItems[gActiveBattler]; + gBattleStruct->changedItems[gActiveBattler] = ITEM_NONE; + gBattleResources->flags->flags[gActiveBattler] &= ~(RESOURCE_FLAG_UNBURDEN); + } + + gBattlescriptCurrInstr += 4; + return; } gBattlescriptCurrInstr += 3; diff --git a/src/battle_util.c b/src/battle_util.c index 7deebd25e3..6c9e141875 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -5385,6 +5385,8 @@ bool32 HasEnoughHpToEatBerry(u32 battlerId, u32 hpFraction, u32 itemId) if (gBattleMons[battlerId].hp == 0) return FALSE; + if (gBattleScripting.overrideBerryRequirements) + return TRUE; // Unnerve prevents consumption of opponents' berries. if (isBerry && IsUnnerveAbilityOnOpposingSide(battlerId)) return FALSE; @@ -6095,11 +6097,14 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } } break; + case ITEMEFFECT_BATTLER_MOVE_END: + goto DO_ITEMEFFECT_MOVE_END; // this hurts a bit to do, but is an easy solution case ITEMEFFECT_MOVE_END: for (battlerId = 0; battlerId < gBattlersCount; battlerId++) { gLastUsedItem = gBattleMons[battlerId].item; battlerHoldEffect = GetBattlerHoldEffect(battlerId, TRUE); + DO_ITEMEFFECT_MOVE_END: switch (battlerHoldEffect) { case HOLD_EFFECT_MICLE_BERRY: