From 029ab67ff413fd70ecaefa759b5d333ea92f9012 Mon Sep 17 00:00:00 2001 From: ultima-soul Date: Mon, 16 Dec 2019 00:29:20 -0800 Subject: [PATCH] Implement Leaf Guard. --- asm/macros/battle_script.inc | 6 ++++++ data/battle_scripts_1.s | 18 ++++++++++++++++++ include/battle_script_commands.h | 1 + src/battle_script_commands.c | 31 +++++++++++++++++++++++++------ src/battle_util.c | 7 ++++++- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 92f8f416f..8a8303673 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1782,3 +1782,9 @@ goto \jumpptr .endm + .macro jumpifleafguard jumpptr:req + jumpifhalfword CMP_NO_COMMON_BITS, gBattleWeather, WEATHER_SUN_ANY, 1f + jumpifability BS_TARGET, ABILITY_LEAF_GUARD, \jumpptr + 1: + .endm + diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 7591d81a0..e8b65db65 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2002,6 +2002,7 @@ BattleScript_EffectSleep:: jumpifcantmakeasleep BattleScript_CantMakeAsleep jumpifflowerveil BattleScript_FlowerVeilProtects jumpifability BS_TARGET_SIDE, ABILITY_SWEET_VEIL, BattleScript_SweetVeilProtects + jumpifleafguard BattleScript_LeafGuardProtects jumpifstatus BS_TARGET, STATUS1_ANY, BattleScript_ButItFailed accuracycheck BattleScript_ButItFailed, ACC_CURR_MOVE jumpifsideaffecting BS_TARGET, SIDE_STATUS_SAFEGUARD, BattleScript_SafeguardProtected @@ -2047,6 +2048,18 @@ BattleScript_AromaVeilProtects: orhalfword gMoveResultFlags, MOVE_RESULT_FAILED goto BattleScript_MoveEnd +BattleScript_LeafGuardProtectsRet:: + pause 0x20 + call BattleScript_AbilityPopUp + printstring STRINGID_ITDOESNTAFFECT + waitmessage 0x40 + return + +BattleScript_LeafGuardProtects: + call BattleScript_LeafGuardProtectsRet + orhalfword gMoveResultFlags, MOVE_RESULT_FAILED + goto BattleScript_MoveEnd + BattleScript_AlreadyAsleep:: setalreadystatusedmoveattempt BS_ATTACKER pause 0x20 @@ -2487,6 +2500,7 @@ BattleScript_EffectToxic:: ppreduce jumpifability BS_TARGET, ABILITY_IMMUNITY, BattleScript_ImmunityProtected jumpifflowerveil BattleScript_FlowerVeilProtects + jumpifleafguard BattleScript_LeafGuardProtects jumpifsubstituteblocks BattleScript_ButItFailed jumpifstatus BS_TARGET, STATUS1_POISON | STATUS1_TOXIC_POISON, BattleScript_AlreadyPoisoned jumpifstatus BS_TARGET, STATUS1_ANY, BattleScript_ButItFailed @@ -2813,6 +2827,7 @@ BattleScript_EffectPoison:: ppreduce jumpifability BS_TARGET, ABILITY_IMMUNITY, BattleScript_ImmunityProtected jumpifflowerveil BattleScript_FlowerVeilProtects + jumpifleafguard BattleScript_LeafGuardProtects jumpifsubstituteblocks BattleScript_ButItFailed jumpifstatus BS_TARGET, STATUS1_POISON, BattleScript_AlreadyPoisoned jumpifstatus BS_TARGET, STATUS1_TOXIC_POISON, BattleScript_AlreadyPoisoned @@ -2835,6 +2850,7 @@ BattleScript_EffectParalyze: ppreduce jumpifability BS_TARGET, ABILITY_LIMBER, BattleScript_LimberProtected jumpifflowerveil BattleScript_FlowerVeilProtects + jumpifleafguard BattleScript_LeafGuardProtects jumpifsubstituteblocks BattleScript_ButItFailed typecalc jumpifmovehadnoeffect BattleScript_ButItFailed @@ -4064,6 +4080,7 @@ BattleScript_EffectWillOWisp:: jumpiftype BS_TARGET, TYPE_FIRE, BattleScript_NotAffected jumpifability BS_TARGET, ABILITY_WATER_VEIL, BattleScript_WaterVeilPrevents jumpifflowerveil BattleScript_FlowerVeilProtects + jumpifleafguard BattleScript_LeafGuardProtects jumpifstatus BS_TARGET, STATUS1_ANY, BattleScript_ButItFailed accuracycheck BattleScript_ButItFailed, ACC_CURR_MOVE jumpifsideaffecting BS_TARGET, SIDE_STATUS_SAFEGUARD, BattleScript_SafeguardProtected @@ -4327,6 +4344,7 @@ BattleScript_EffectYawn:: jumpifability BS_TARGET, ABILITY_VITAL_SPIRIT, BattleScript_PrintBankAbilityMadeIneffective jumpifability BS_TARGET, ABILITY_INSOMNIA, BattleScript_PrintBankAbilityMadeIneffective jumpifflowerveil BattleScript_FlowerVeilProtects + jumpifleafguard BattleScript_LeafGuardProtects jumpifsubstituteblocks BattleScript_ButItFailed jumpifsideaffecting BS_TARGET, SIDE_STATUS_SAFEGUARD, BattleScript_SafeguardProtected accuracycheck BattleScript_ButItFailed, NO_ACC_CALC_CHECK_LOCK_ON diff --git a/include/battle_script_commands.h b/include/battle_script_commands.h index 72f04323a..8bd94150a 100644 --- a/include/battle_script_commands.h +++ b/include/battle_script_commands.h @@ -16,6 +16,7 @@ bool8 UproarWakeUpCheck(u8 battlerId); bool32 DoesSubstituteBlockMove(u8 battlerAtk, u8 battlerDef, u32 move); bool32 CanUseLastResort(u8 battlerId); u32 IsFlowerVeilProtected(u32 battler); +u32 IsLeafGuardProtected(u32 battler); extern void (* const gBattleScriptingCommandsTable[])(void); extern const u8 gUnknown_0831C494[][4]; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index eb95ea07e..63de3510c 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2151,7 +2151,8 @@ void SetMoveEffect(bool32 primary, u32 certain) if (GetBattlerAbility(gEffectBattler) == ABILITY_VITAL_SPIRIT || GetBattlerAbility(gEffectBattler) == ABILITY_INSOMNIA || IsAbilityOnSide(gEffectBattler, ABILITY_SWEET_VEIL) - || IsFlowerVeilProtected(gEffectBattler)) + || IsFlowerVeilProtected(gEffectBattler) + || IsLeafGuardProtected(gEffectBattler)) break; CancelMultiTurnMoves(gEffectBattler); @@ -2194,7 +2195,9 @@ void SetMoveEffect(bool32 primary, u32 certain) break; if (gBattleMons[gEffectBattler].status1) break; - if (GetBattlerAbility(gEffectBattler) == ABILITY_IMMUNITY || IsFlowerVeilProtected(gEffectBattler)) + if (GetBattlerAbility(gEffectBattler) == ABILITY_IMMUNITY + || IsFlowerVeilProtected(gEffectBattler) + || IsLeafGuardProtected(gEffectBattler)) break; statusChanged = TRUE; @@ -2231,7 +2234,9 @@ void SetMoveEffect(bool32 primary, u32 certain) } if (IS_BATTLER_OF_TYPE(gEffectBattler, TYPE_FIRE)) break; - if (GetBattlerAbility(gEffectBattler) == ABILITY_WATER_VEIL || IsFlowerVeilProtected(gEffectBattler)) + if (GetBattlerAbility(gEffectBattler) == ABILITY_WATER_VEIL + || IsFlowerVeilProtected(gEffectBattler) + || IsLeafGuardProtected(gEffectBattler)) break; if (gBattleMons[gEffectBattler].status1) break; @@ -2247,7 +2252,9 @@ void SetMoveEffect(bool32 primary, u32 certain) break; if (noSunCanFreeze == 0) break; - if (GetBattlerAbility(gEffectBattler) == ABILITY_MAGMA_ARMOR || IsFlowerVeilProtected(gEffectBattler)) + if (GetBattlerAbility(gEffectBattler) == ABILITY_MAGMA_ARMOR + || IsFlowerVeilProtected(gEffectBattler) + || IsLeafGuardProtected(gEffectBattler)) break; CancelMultiTurnMoves(gEffectBattler); @@ -2290,7 +2297,9 @@ void SetMoveEffect(bool32 primary, u32 certain) } if (IS_BATTLER_OF_TYPE(gEffectBattler, TYPE_ELECTRIC)) break; - if (GetBattlerAbility(gEffectBattler) == ABILITY_LIMBER || IsFlowerVeilProtected(gEffectBattler)) + if (GetBattlerAbility(gEffectBattler) == ABILITY_LIMBER + || IsFlowerVeilProtected(gEffectBattler) + || IsLeafGuardProtected(gEffectBattler)) break; if (gBattleMons[gEffectBattler].status1) break; @@ -2331,7 +2340,9 @@ void SetMoveEffect(bool32 primary, u32 certain) break; if (!IS_BATTLER_OF_TYPE(gEffectBattler, TYPE_POISON) && !IS_BATTLER_OF_TYPE(gEffectBattler, TYPE_STEEL)) { - if (GetBattlerAbility(gEffectBattler) == ABILITY_IMMUNITY || IsFlowerVeilProtected(gEffectBattler)) + if (GetBattlerAbility(gEffectBattler) == ABILITY_IMMUNITY + || IsFlowerVeilProtected(gEffectBattler) + || IsLeafGuardProtected(gEffectBattler)) break; // It's redundant, because at this point we know the status1 value is 0. @@ -6632,6 +6643,14 @@ u32 IsFlowerVeilProtected(u32 battler) return 0; } +u32 IsLeafGuardProtected(u32 battler) +{ + if (WEATHER_HAS_EFFECT && (gBattleWeather & WEATHER_SUN_ANY)) + return GetBattlerAbility(battler) == ABILITY_LEAF_GUARD; + else + return 0; +} + static void Cmd_various(void) { struct Pokemon *mon; diff --git a/src/battle_util.c b/src/battle_util.c index 32492410e..a9619d296 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1731,7 +1731,8 @@ u8 DoBattlerEndTurnEffects(void) gStatuses3[gActiveBattler] -= 0x800; if (!(gStatuses3[gActiveBattler] & STATUS3_YAWN) && !(gBattleMons[gActiveBattler].status1 & STATUS1_ANY) && gBattleMons[gActiveBattler].ability != ABILITY_VITAL_SPIRIT - && gBattleMons[gActiveBattler].ability != ABILITY_INSOMNIA && !UproarWakeUpCheck(gActiveBattler)) + && gBattleMons[gActiveBattler].ability != ABILITY_INSOMNIA && !UproarWakeUpCheck(gActiveBattler) + && !IsLeafGuardProtected(gActiveBattler)) { CancelMultiTurnMoves(gActiveBattler); gBattleMons[gActiveBattler].status1 |= (Random() & 3) + 2; @@ -3346,6 +3347,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA && GetBattlerAbility(gBattlerAttacker) != ABILITY_VITAL_SPIRIT && !(gBattleMons[gBattlerAttacker].status1 & STATUS1_ANY) && !IsFlowerVeilProtected(gBattlerAttacker) + && !IsLeafGuardProtected(gBattlerAttacker) && (gBattleMoves[move].flags & FLAG_MAKES_CONTACT) && (Random() % 3) == 0) { @@ -3369,6 +3371,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA && GetBattlerAbility(gBattlerAttacker) != ABILITY_IMMUNITY && !(gBattleMons[gBattlerAttacker].status1 & STATUS1_ANY) && !IsFlowerVeilProtected(gBattlerAttacker) + && !IsLeafGuardProtected(gBattlerAttacker) && (gBattleMoves[move].flags & FLAG_MAKES_CONTACT) && (Random() % 3) == 0) { @@ -3390,6 +3393,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA && GetBattlerAbility(gBattlerAttacker) != ABILITY_LIMBER && !(gBattleMons[gBattlerAttacker].status1 & STATUS1_ANY) && !IsFlowerVeilProtected(gBattlerAttacker) + && !IsLeafGuardProtected(gBattlerAttacker) && (gBattleMoves[move].flags & FLAG_MAKES_CONTACT) && (Random() % 3) == 0) { @@ -3410,6 +3414,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA && GetBattlerAbility(gBattlerAttacker) != ABILITY_WATER_VEIL && !(gBattleMons[gBattlerAttacker].status1 & STATUS1_ANY) && !IsFlowerVeilProtected(gBattlerAttacker) + && !IsLeafGuardProtected(gBattlerAttacker) && (Random() % 3) == 0) { gBattleScripting.moveEffect = MOVE_EFFECT_AFFECTS_USER | MOVE_EFFECT_BURN;