From 996301d5d33072407fe9143811d27eb31e07e201 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Tue, 12 Oct 2021 18:04:34 -0400 Subject: [PATCH 1/5] add mirror armor --- asm/macros/battle_script.inc | 4 ++ data/battle_scripts_1.s | 36 +++++++++++++++ include/battle_scripts.h | 2 + include/constants/battle_script_commands.h | 1 + src/battle_script_commands.c | 51 +++++++++++++++++----- src/battle_util.c | 7 +-- 6 files changed, 86 insertions(+), 15 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 4d8fe0365..f00e580f0 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1824,6 +1824,10 @@ .macro trytoclearprimalweather various BS_ATTACKER, VARIOUS_TRY_TO_CLEAR_PRIMAL_WEATHER .endm + + .macro getrandommirrorarmortarget + various BS_TARGET, VARIOUS_GET_RANDOM_MIRROR_ARMOR_TARGET + .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 e1fb47930..5979f4c67 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2645,6 +2645,33 @@ BattleScript_StatDownPrintString:: BattleScript_StatDownEnd:: goto BattleScript_MoveEnd +BattleScript_MirrorArmorReflect:: + pause B_WAIT_TIME_SHORT + call BattleScript_AbilityPopUp + jumpifsubstituteblocks BattleScript_AbilityNoSpecificStatLoss +BattleScript_MirrorArmorReflectStatLoss: + statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_BUFF_NOT_PROTECT_AFFECTED, BattleScript_MirrorArmorReflectWontFall + jumpifbyte CMP_LESS_THAN, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_DECREASE, BattleScript_MirrorArmorReflectAnim + goto BattleScript_MirrorArmorReflectWontFall +BattleScript_MirrorArmorReflectAnim: + setgraphicalstatchangevalues + playanimation BS_ATTACKER, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 +BattleScript_MirrorArmorReflectPrintString: + printfromtable gStatDownStringIds + waitmessage B_WAIT_TIME_LONG +BattleScript_MirrorArmorReflectEnd: + return + +BattleScript_MirrorArmorReflectWontFall: + copybyte gBattlerTarget, gBattlerAttacker @ STRINGID_STATSWONTDECREASE uses target + goto BattleScript_MirrorArmorReflectPrintString + +BattleScript_MirrorArmorReflectStickyWeb: + call BattleScript_AbilityPopUp + getrandommirrorarmortarget + jumpifbyteequal gBattlerTarget, gBattlerAttacker, BattleScript_AbilityNoSpecificStatLossPrint + goto BattleScript_MirrorArmorReflectStatLoss + BattleScript_StatDown:: playanimation BS_EFFECT_BATTLER, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 printfromtable gStatDownStringIds @@ -6099,6 +6126,7 @@ BattleScript_StickyWebOnSwitchIn:: copybyte gBattlerTarget, sBATTLER printstring STRINGID_STICKYWEBSWITCHIN waitmessage B_WAIT_TIME_LONG + jumpifability BS_TARGET, ABILITY_MIRROR_ARMOR, BattleScript_MirrorArmorReflectStickyWeb statbuffchange STAT_BUFF_ALLOW_PTR, BattleScript_StickyWebOnSwitchInEnd jumpifbyte CMP_LESS_THAN, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_DECREASE, BattleScript_StickyWebOnSwitchInStatAnim jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_STAT_FELL_EMPTY, BattleScript_StickyWebOnSwitchInEnd @@ -7639,6 +7667,7 @@ BattleScript_GrassyTerrainHealEnd: BattleScript_AbilityNoSpecificStatLoss:: pause B_WAIT_TIME_SHORT call BattleScript_AbilityPopUp +BattleScript_AbilityNoSpecificStatLossPrint: printstring STRINGID_PKMNSXPREVENTSYLOSS waitmessage B_WAIT_TIME_LONG setbyte cMULTISTRING_CHOOSER, B_MSG_STAT_FELL_EMPTY @@ -7885,6 +7914,13 @@ BattleScript_CuteCharmActivates:: call BattleScript_TryDestinyKnotTarget return +BattleScript_GooeyActivates:: + waitstate + call BattleScript_AbilityPopUp + swapattackerwithtarget @ for defiant, mirror armor + seteffectsecondary + return + BattleScript_AbilityStatusEffect:: waitstate call BattleScript_AbilityPopUp diff --git a/include/battle_scripts.h b/include/battle_scripts.h index cd4600543..4e5568c75 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -398,5 +398,7 @@ extern const u8 BattleScript_MysteriousAirCurrentBlowsOn[]; extern const u8 BattleScript_AttackWeakenedByStrongWinds[]; extern const u8 BattleScript_BlockedByPrimalWeatherEnd3[]; extern const u8 BattleScript_BlockedByPrimalWeatherRet[]; +extern const u8 BattleScript_MirrorArmorReflect[]; +extern const u8 BattleScript_GooeyActivates[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index d61eabbf8..bbf5714e9 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -185,6 +185,7 @@ #define VARIOUS_REMOVE_TERRAIN 113 #define VARIOUS_JUMP_IF_PRANKSTER_BLOCKED 114 #define VARIOUS_TRY_TO_CLEAR_PRIMAL_WEATHER 115 +#define VARIOUS_GET_RANDOM_MIRROR_ARMOR_TARGET 116 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 2c017b2df..9c0b4ec37 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2582,6 +2582,8 @@ void SetMoveEffect(bool32 primary, u32 certain) { s32 i, byTwo, affectsUser = 0; bool32 statusChanged = FALSE; + bool32 mirrorArmorReflected = (GetBattlerAbility(gBattlerTarget) == ABILITY_MIRROR_ARMOR); + u32 flags; switch (gBattleScripting.moveEffect) // Set move effects which happen later on { @@ -3012,11 +3014,18 @@ void SetMoveEffect(bool32 primary, u32 certain) case MOVE_EFFECT_SP_DEF_MINUS_1: case MOVE_EFFECT_ACC_MINUS_1: case MOVE_EFFECT_EVS_MINUS_1: - if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(1) | STAT_BUFF_NEGATIVE, - gBattleScripting.moveEffect - MOVE_EFFECT_ATK_MINUS_1 + 1, - affectsUser, 0)) + flags = affectsUser | certain; + if (mirrorArmorReflected && !affectsUser) { - gBattlescriptCurrInstr++; + flags |= STAT_BUFF_ALLOW_PTR; + } + + if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(1) | STAT_BUFF_NEGATIVE, + gBattleScripting.moveEffect - MOVE_EFFECT_ATK_MINUS_1 + 1, + flags, gBattlescriptCurrInstr + 1)) + { + if (!mirrorArmorReflected) + gBattlescriptCurrInstr++; } else { @@ -8822,6 +8831,25 @@ static void Cmd_various(void) } break; } + case VARIOUS_GET_RANDOM_MIRROR_ARMOR_TARGET: + i = BATTLE_OPPOSITE(gActiveBattler); + gBattlerAttacker = gBattlerTarget; + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + { + if (IsBattlerAlive(i) + && !(gBattleMons[i].status2 & STATUS2_SUBSTITUTE)) + gBattlerAttacker = i; + else if (IsBattlerAlive(BATTLE_PARTNER(i)) + && !(gBattleMons[BATTLE_PARTNER(i)].status2 & STATUS2_SUBSTITUTE)) + gBattlerAttacker = BATTLE_PARTNER(i); + } + else + { + if (IsBattlerAlive(i) && !(gBattleMons[i].status2 & STATUS2_SUBSTITUTE)) + gBattlerAttacker = i; + } + SET_STATCHANGER(STAT_SPEED, 1, TRUE); + break; } gBattlescriptCurrInstr += 3; @@ -9355,8 +9383,9 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr bool32 certain = FALSE; bool32 notProtectAffected = FALSE; u32 index; + bool32 affectsUser = flags & MOVE_EFFECT_AFFECTS_USER; - if (flags & MOVE_EFFECT_AFFECTS_USER) + if (affectsUser) gActiveBattler = gBattlerAttacker; else gActiveBattler = gBattlerTarget; @@ -9457,8 +9486,9 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr } return STAT_CHANGE_DIDNT_WORK; } - else if (GetBattlerAbility(gActiveBattler) == ABILITY_KEEN_EYE - && !certain && statId == STAT_ACC) + else if (!certain + && ((GetBattlerAbility(gActiveBattler) == ABILITY_KEEN_EYE && statId == STAT_ACC) + || (GetBattlerAbility(gActiveBattler) == ABILITY_HYPER_CUTTER && statId == STAT_ATK))) { if (flags == STAT_BUFF_ALLOW_PTR) { @@ -9471,17 +9501,14 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr } return STAT_CHANGE_DIDNT_WORK; } - else if (GetBattlerAbility(gActiveBattler) == ABILITY_HYPER_CUTTER - && !certain && statId == STAT_ATK) + else if (GetBattlerAbility(gActiveBattler) == ABILITY_MIRROR_ARMOR && !affectsUser && gBattlerAttacker != gBattlerTarget && gActiveBattler == gBattlerTarget) { if (flags == STAT_BUFF_ALLOW_PTR) { BattleScriptPush(BS_ptr); gBattleScripting.battler = gActiveBattler; gBattlerAbility = gActiveBattler; - gBattlescriptCurrInstr = BattleScript_AbilityNoSpecificStatLoss; - gLastUsedAbility = GetBattlerAbility(gActiveBattler); - RecordAbilityBattle(gActiveBattler, gLastUsedAbility); + gBattlescriptCurrInstr = BattleScript_MirrorArmorReflect; } return STAT_CHANGE_DIDNT_WORK; } diff --git a/src/battle_util.c b/src/battle_util.c index 68e787698..37cc17644 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4835,15 +4835,16 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move case ABILITY_TANGLING_HAIR: if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) && gBattleMons[gBattlerAttacker].hp != 0 - && CompareStat(gBattlerAttacker, STAT_SPEED, MIN_STAT_STAGE, CMP_GREATER_THAN) + && (CompareStat(gBattlerAttacker, STAT_SPEED, MIN_STAT_STAGE, CMP_GREATER_THAN) || GetBattlerAbility(gBattlerAttacker) == ABILITY_MIRROR_ARMOR) && !gProtectStructs[gBattlerAttacker].confusionSelfDmg && TARGET_TURN_DAMAGED && IsMoveMakingContact(move, gBattlerAttacker)) { - gBattleScripting.moveEffect = MOVE_EFFECT_AFFECTS_USER | MOVE_EFFECT_SPD_MINUS_1; + SET_STATCHANGER(STAT_SPEED, 1, TRUE); + gBattleScripting.moveEffect = MOVE_EFFECT_SPD_MINUS_1; PREPARE_ABILITY_BUFFER(gBattleTextBuff1, gLastUsedAbility); BattleScriptPushCursor(); - gBattlescriptCurrInstr = BattleScript_AbilityStatusEffect; + gBattlescriptCurrInstr = BattleScript_GooeyActivates; gHitMarker |= HITMARKER_IGNORE_SAFEGUARD; effect++; } From f9272a89fa3fade69f26a37462cc2fe93e9abc15 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Tue, 12 Oct 2021 21:09:27 -0400 Subject: [PATCH 2/5] add mirror armor check to two-stage stat decrease effects --- src/battle_script_commands.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9c0b4ec37..253f87c1c 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3016,9 +3016,7 @@ void SetMoveEffect(bool32 primary, u32 certain) case MOVE_EFFECT_EVS_MINUS_1: flags = affectsUser | certain; if (mirrorArmorReflected && !affectsUser) - { flags |= STAT_BUFF_ALLOW_PTR; - } if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(1) | STAT_BUFF_NEGATIVE, gBattleScripting.moveEffect - MOVE_EFFECT_ATK_MINUS_1 + 1, @@ -3063,11 +3061,15 @@ void SetMoveEffect(bool32 primary, u32 certain) case MOVE_EFFECT_SP_DEF_MINUS_2: case MOVE_EFFECT_ACC_MINUS_2: case MOVE_EFFECT_EVS_MINUS_2: + flags = affectsUser | certain; + if (mirrorArmorReflected && !affectsUser) + flags |= STAT_BUFF_ALLOW_PTR; if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(2) | STAT_BUFF_NEGATIVE, gBattleScripting.moveEffect - MOVE_EFFECT_ATK_MINUS_2 + 1, - affectsUser, 0)) + flags, gBattlescriptCurrInstr + 1)) { - gBattlescriptCurrInstr++; + if (!mirrorArmorReflected) + gBattlescriptCurrInstr++; } else { From 592a1dab63d3b8eb97679cbdc9161ade8f762d90 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Tue, 2 Nov 2021 12:02:58 -0400 Subject: [PATCH 3/5] fix mirror armor setstatchanger, handle reflected stat blockage --- data/battle_scripts_1.s | 2 +- src/battle_script_commands.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index b72140a11..eb80a41d5 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2894,7 +2894,7 @@ BattleScript_MirrorArmorReflect:: call BattleScript_AbilityPopUp jumpifsubstituteblocks BattleScript_AbilityNoSpecificStatLoss BattleScript_MirrorArmorReflectStatLoss: - statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_BUFF_NOT_PROTECT_AFFECTED, BattleScript_MirrorArmorReflectWontFall + statbuffchange MOVE_EFFECT_AFFECTS_USER | STAT_BUFF_NOT_PROTECT_AFFECTED | STAT_BUFF_ALLOW_PTR, BattleScript_MirrorArmorReflectEnd jumpifbyte CMP_LESS_THAN, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_DECREASE, BattleScript_MirrorArmorReflectAnim goto BattleScript_MirrorArmorReflectWontFall BattleScript_MirrorArmorReflectAnim: diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 28cab4af3..2ee80557f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9689,10 +9689,12 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr { if (flags == STAT_BUFF_ALLOW_PTR) { + SET_STATCHANGER(statId, GET_STAT_BUFF_VALUE(statValue) | STAT_BUFF_NEGATIVE, TRUE); BattleScriptPush(BS_ptr); gBattleScripting.battler = gActiveBattler; gBattlerAbility = gActiveBattler; gBattlescriptCurrInstr = BattleScript_MirrorArmorReflect; + RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); } return STAT_CHANGE_DIDNT_WORK; } From 7e6e23005be4bbfbffda03be99c5db0c64ae892d Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Wed, 3 Nov 2021 13:59:26 -0400 Subject: [PATCH 4/5] fix clear body --- src/battle_script_commands.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 2ee80557f..500b7cab0 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2586,7 +2586,7 @@ void SetMoveEffect(bool32 primary, u32 certain) s32 i, byTwo, affectsUser = 0; bool32 statusChanged = FALSE; bool32 mirrorArmorReflected = (GetBattlerAbility(gBattlerTarget) == ABILITY_MIRROR_ARMOR); - u32 flags; + u32 flags = 0; switch (gBattleScripting.moveEffect) // Set move effects which happen later on { @@ -3017,7 +3017,7 @@ void SetMoveEffect(bool32 primary, u32 certain) case MOVE_EFFECT_SP_DEF_MINUS_1: case MOVE_EFFECT_ACC_MINUS_1: case MOVE_EFFECT_EVS_MINUS_1: - flags = affectsUser | certain; + flags = affectsUser; if (mirrorArmorReflected && !affectsUser) flags |= STAT_BUFF_ALLOW_PTR; @@ -3064,7 +3064,7 @@ void SetMoveEffect(bool32 primary, u32 certain) case MOVE_EFFECT_SP_DEF_MINUS_2: case MOVE_EFFECT_ACC_MINUS_2: case MOVE_EFFECT_EVS_MINUS_2: - flags = affectsUser | certain; + flags = affectsUser; if (mirrorArmorReflected && !affectsUser) flags |= STAT_BUFF_ALLOW_PTR; if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(2) | STAT_BUFF_NEGATIVE, @@ -9567,7 +9567,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr bool32 certain = FALSE; bool32 notProtectAffected = FALSE; u32 index; - bool32 affectsUser = flags & MOVE_EFFECT_AFFECTS_USER; + bool32 affectsUser = (flags & MOVE_EFFECT_AFFECTS_USER); if (affectsUser) gActiveBattler = gBattlerAttacker; From 48c29a9cd823ea7d9b000c493ef52e925c467aba Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Wed, 3 Nov 2021 15:05:52 -0400 Subject: [PATCH 5/5] proper mirror armor sticky web targeting --- asm/macros/battle_script.inc | 4 ++-- data/battle_scripts_1.s | 5 +++-- include/battle.h | 1 + include/constants/battle_script_commands.h | 2 +- src/battle_main.c | 8 ++++++++ src/battle_script_commands.c | 24 +++++++--------------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 6b2c248db..328780f53 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1839,8 +1839,8 @@ various BS_ATTACKER, VARIOUS_TRY_TO_CLEAR_PRIMAL_WEATHER .endm - .macro getrandommirrorarmortarget - various BS_TARGET, VARIOUS_GET_RANDOM_MIRROR_ARMOR_TARGET + .macro setattackertostickywebuser + various BS_TARGET, VARIOUS_SET_ATTACKER_STICKY_WEB_USER .endm .macro getrototillertargets ptr:req diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index eb80a41d5..36ae4d967 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2910,10 +2910,11 @@ BattleScript_MirrorArmorReflectWontFall: copybyte gBattlerTarget, gBattlerAttacker @ STRINGID_STATSWONTDECREASE uses target goto BattleScript_MirrorArmorReflectPrintString +@ gBattlerTarget is battler with Mirror Armor BattleScript_MirrorArmorReflectStickyWeb: call BattleScript_AbilityPopUp - getrandommirrorarmortarget - jumpifbyteequal gBattlerTarget, gBattlerAttacker, BattleScript_AbilityNoSpecificStatLossPrint + setattackertostickywebuser + jumpifbyteequal gBattlerAttacker, gBattlerTarget, BattleScript_StickyWebOnSwitchInEnd @ Sticky web user not on field -> no stat loss goto BattleScript_MirrorArmorReflectStatLoss BattleScript_StatDown:: diff --git a/include/battle.h b/include/battle.h index 5e5aa2479..770d826a5 100644 --- a/include/battle.h +++ b/include/battle.h @@ -612,6 +612,7 @@ struct BattleStruct struct StolenItem itemStolen[PARTY_SIZE]; // Player's team that had items stolen (two bytes per party member) u8 blunderPolicy:1; // should blunder policy activate u8 ballSpriteIds[2]; // item gfx, window gfx + u8 stickyWebUser; }; #define GET_MOVE_TYPE(move, typeArg) \ diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 5034c4f56..3b4495208 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -197,7 +197,7 @@ #define VARIOUS_UPDATE_ABILITY_POPUP 124 #define VARIOUS_JUMP_IF_WEATHER_AFFECTED 125 #define VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED 126 -#define VARIOUS_GET_RANDOM_MIRROR_ARMOR_TARGET 127 +#define VARIOUS_SET_ATTACKER_STICKY_WEB_USER 127 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_main.c b/src/battle_main.c index ad02854bd..f1adb1bfb 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2933,6 +2933,8 @@ static void BattleStartClearSetData(void) gBattleStruct->mega.triggerSpriteId = 0xFF; + gBattleStruct->stickyWebUser = 0xFF; + for (i = 0; i < PARTY_SIZE; i++) { gBattleStruct->usedHeldItems[i][0] = 0; @@ -3030,6 +3032,9 @@ void SwitchInClearSetData(void) gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; gBattleStruct->lastMoveFailed &= ~(gBitTable[gActiveBattler]); gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); + + if (gActiveBattler == gBattleStruct->stickyWebUser) + gBattleStruct->stickyWebUser = 0xFF; // Switched into sticky web user slot so reset it for (i = 0; i < gBattlersCount; i++) { @@ -3127,6 +3132,9 @@ void FaintClearSetData(void) gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); + + if (gActiveBattler == gBattleStruct->stickyWebUser) + gBattleStruct->stickyWebUser = 0xFF; // User of sticky web fainted, so reset the stored battler ID for (i = 0; i < gBattlersCount; i++) { diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 500b7cab0..3d5786b35 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9015,24 +9015,13 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 7; } return; - case VARIOUS_GET_RANDOM_MIRROR_ARMOR_TARGET: - i = BATTLE_OPPOSITE(gActiveBattler); - gBattlerAttacker = gBattlerTarget; - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - { - if (IsBattlerAlive(i) - && !(gBattleMons[i].status2 & STATUS2_SUBSTITUTE)) - gBattlerAttacker = i; - else if (IsBattlerAlive(BATTLE_PARTNER(i)) - && !(gBattleMons[BATTLE_PARTNER(i)].status2 & STATUS2_SUBSTITUTE)) - gBattlerAttacker = BATTLE_PARTNER(i); - } - else - { - if (IsBattlerAlive(i) && !(gBattleMons[i].status2 & STATUS2_SUBSTITUTE)) - gBattlerAttacker = i; - } + case VARIOUS_SET_ATTACKER_STICKY_WEB_USER: + // For Mirror Armor: "If the Pokémon with this Ability is affected by Sticky Web, the effect is reflected back to the Pokémon which set it up. + // If Pokémon which set up Sticky Web is not on the field, no Pokémon have their Speed lowered." + gBattlerAttacker = gBattlerTarget; // Initialize 'fail' condition SET_STATCHANGER(STAT_SPEED, 1, TRUE); + if (gBattleStruct->stickyWebUser != 0xFF) + gBattlerAttacker = gBattleStruct->stickyWebUser; break; } @@ -11590,6 +11579,7 @@ static void Cmd_setstickyweb(void) { gSideStatuses[targetSide] |= SIDE_STATUS_STICKY_WEB; gSideTimers[targetSide].stickyWebAmount = 1; + gBattleStruct->stickyWebUser = gBattlerAttacker; // For Mirror Armor gBattlescriptCurrInstr += 5; } }