Merge pull request #210 from ultima-soul/battle_engine

Implement Leaf Guard.
This commit is contained in:
DizzyEggg 2019-12-23 17:15:51 +01:00 committed by GitHub
commit e4a9a228c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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];

View File

@ -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;

View File

@ -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;