From afc4b4cdee2d5596a6262084bd795281f887d7b9 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Tue, 28 Mar 2023 15:07:37 -0400 Subject: [PATCH] add mirror herb --- data/battle_scripts_1.s | 29 ++++++++++++++++++++++----- include/battle.h | 1 + include/battle_scripts.h | 2 ++ include/constants/battle_string_ids.h | 3 ++- src/battle_message.c | 2 ++ src/battle_script_commands.c | 14 +++++++++++++ src/battle_util.c | 26 ++++++++++++++++++++++++ 7 files changed, 71 insertions(+), 6 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 200a04461..c8bd53735 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -9980,23 +9980,42 @@ BattleScript_PrintPlayerForfeitedLinkBattle:: end2 BattleScript_TotemFlaredToLife:: - playanimation BS_ATTACKER, B_ANIM_TOTEM_FLARE + playanimation BS_ATTACKER, B_ANIM_TOTEM_FLARE, NULL printstring STRINGID_AURAFLAREDTOLIFE waitmessage B_WAIT_TIME_LONG - goto BattleScript_ApplyTotemVarBoost + call BattleScript_ApplyTotemVarBoost + end2 + +@ remove the mirror herb, do totem loop +BattleScript_MirrorHerbCopyStatChangeEnd2:: + call BattleScript_MirrorHerbCopyStatChange + end2 + +BattleScript_MirrorHerbCopyStatChange:: + playanimation BS_SCRIPTING, B_ANIM_HELD_ITEM_EFFECT, NULL + printstring STRINGID_MIRRORHERBCOPIED + waitmessage B_WAIT_TIME_LONG + removeitem BS_SCRIPTING + call BattleScript_TotemVar_Ret + copybyte gBattlerAttacker, sSAVED_BATTLER @ restore the original attacker just to be safe + return BattleScript_TotemVar:: + call BattleScript_TotemVar_Ret + end2 + +BattleScript_TotemVar_Ret:: gettotemboost BattleScript_ApplyTotemVarBoost BattleScript_TotemVarEnd: - end2 + return BattleScript_ApplyTotemVarBoost: statbuffchange STAT_CHANGE_ALLOW_PTR, BattleScript_TotemVarEnd setgraphicalstatchangevalues playanimation BS_SCRIPTING, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 -BattleScript_TotemVarPrintStatMsg: printfromtable gStatUpStringIds waitmessage B_WAIT_TIME_LONG - goto BattleScript_TotemVar @loop until stats bitfield is empty + goto BattleScript_TotemVar_Ret @loop until stats bitfield is empty + BattleScript_AnnounceAirLockCloudNine:: call BattleScript_AbilityPopUp diff --git a/include/battle.h b/include/battle.h index 491273b80..f1818d583 100644 --- a/include/battle.h +++ b/include/battle.h @@ -145,6 +145,7 @@ struct ProtectStruct u16 quash:1; u16 shellTrap:1; u16 silkTrapped:1; + u16 eatMirrorHerb:1; u32 physicalDmg; u32 specialDmg; u8 physicalBattlerId; diff --git a/include/battle_scripts.h b/include/battle_scripts.h index c78fcafe4..248f28119 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -1,6 +1,8 @@ #ifndef GUARD_BATTLE_SCRIPTS_H #define GUARD_BATTLE_SCRIPTS_H +extern const u8 BattleScript_MirrorHerbCopyStatChange[]; +extern const u8 BattleScript_MirrorHerbCopyStatChangeEnd2[]; extern const u8 BattleScript_NotAffected[]; extern const u8 BattleScript_HitFromCritCalc[]; extern const u8 BattleScript_MoveEnd[]; diff --git a/include/constants/battle_string_ids.h b/include/constants/battle_string_ids.h index b94176334..4051a3a6d 100644 --- a/include/constants/battle_string_ids.h +++ b/include/constants/battle_string_ids.h @@ -647,8 +647,9 @@ #define STRINGID_STEALTHROCKDISAPPEAREDFROMTEAM 645 #define STRINGID_COULDNTFULLYPROTECT 646 #define STRINGID_STOCKPILEDEFFECTWOREOFF 647 +#define STRINGID_MIRRORHERBCOPIED 648 -#define BATTLESTRINGS_COUNT 648 +#define BATTLESTRINGS_COUNT 649 // This is the string id that gBattleStringsTable starts with. // String ids before this (e.g. STRINGID_INTROMSG) are not in the table, diff --git a/src/battle_message.c b/src/battle_message.c index 2ecfac0c7..9ab40cd4e 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -782,9 +782,11 @@ static const u8 sText_PrepareShellTrap[] = _("{B_ATK_NAME_WITH_PREFIX} set a she static const u8 sText_ShellTrapDidntWork[] = _("{B_ATK_NAME_WITH_PREFIX}'s shell trap didn't work!"); static const u8 sText_CouldntFullyProtect[] = _("{B_DEF_NAME_WITH_PREFIX} couldn't fully protect\nitself and got hurt!"); static const u8 sText_StockpiledEffectWoreOff[] = _("{B_ATK_NAME_WITH_PREFIX}'s stockpiled\neffect wore off!"); +static const u8 sText_MirrorHerbCopied[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s used its {B_LAST_ITEM}\nto mirror its opponent's stat changes!"); const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = { + [STRINGID_MIRRORHERBCOPIED - BATTLESTRINGS_TABLE_START] = sText_MirrorHerbCopied, [STRINGID_STOCKPILEDEFFECTWOREOFF - BATTLESTRINGS_TABLE_START] = sText_StockpiledEffectWoreOff, [STRINGID_COULDNTFULLYPROTECT - BATTLESTRINGS_TABLE_START] = sText_CouldntFullyProtect, [STRINGID_ATTACKERGAINEDSTRENGTHFROMTHEFALLEN - BATTLESTRINGS_TABLE_START] = sText_AttackerGainedStrengthFromTheFallen, diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 28bf60c39..72a332af9 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -12080,6 +12080,20 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr { gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == gActiveBattler); gProtectStructs[gActiveBattler].statRaised = TRUE; + + // check mirror herb + for (index = 0; index < gBattlersCount; index++) + { + if (GetBattlerSide(index) == GetBattlerSide(gActiveBattler)) + continue; // Only triggers on opposing side + if (GetBattlerHoldEffect(index, TRUE) == HOLD_EFFECT_MIRROR_HERB + && gBattleMons[index].statStages[statId] < MAX_STAT_STAGE) + { + gProtectStructs[index].eatMirrorHerb = 1; + gTotemBoosts[index].stats |= (1 << (statId - 1)); // -1 to start at atk + gTotemBoosts[index].statChanges[statId - 1] = statValue; + } + } } } diff --git a/src/battle_util.c b/src/battle_util.c index dea28b5d8..e92ccfdbd 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -6877,6 +6877,26 @@ static bool32 GetMentalHerbEffect(u8 battlerId) return ret; } +static u8 TryConsumeMirrorHerb(u8 battlerId, bool32 execute) +{ + u8 effect = 0; + + if (gProtectStructs[battlerId].eatMirrorHerb) { + gLastUsedItem = gBattleMons[battlerId].item; + gBattleScripting.savedBattler = gBattlerAttacker; + gBattleScripting.battler = gBattlerAttacker = battlerId; + gProtectStructs[battlerId].eatMirrorHerb = 0; + if (execute) { + BattleScriptExecute(BattleScript_MirrorHerbCopyStatChangeEnd2); + } else { + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_MirrorHerbCopyStatChange; + } + effect = ITEM_STATS_CHANGE; + } + return effect; +} + static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) { u8 effect = 0; @@ -7058,6 +7078,9 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect) effect = ITEM_EFFECT_OTHER; } break; + case HOLD_EFFECT_MIRROR_HERB: + effect = TryConsumeMirrorHerb(battlerId, FALSE); + break; } return effect; @@ -7580,6 +7603,9 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) if (!moveTurn) effect = TrySetMicleBerry(battlerId, gLastUsedItem, TRUE); break; + case HOLD_EFFECT_MIRROR_HERB: + effect = TryConsumeMirrorHerb(battlerId, TRUE); + break; } if (effect != 0)