From b09ab5a3ee4ba3ec9b0d925c73fec317f6933ff1 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 19 Apr 2023 01:52:23 -0300 Subject: [PATCH] Updated Triple Arrows' effect's code and tests yet again Also added a function to get a move's secondaryEffectChance, meant to handle abilities, side statuses and the like that modify it. --- data/battle_scripts_1.s | 7 +++-- include/battle_util.h | 1 + src/battle_script_commands.c | 52 +++++++------------------------- src/battle_util.c | 8 +++++ test/move_effect_triple_arrows.c | 35 +++++++++++++++++++-- 5 files changed, 57 insertions(+), 46 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index af141c297..73dc7e79b 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -1553,11 +1553,12 @@ BattleScript_DefDown_Ret: return BattleScript_ReduceDefenseAndFlinch:: - modifybattlerstatstage BS_TARGET, STAT_DEF, DECREASE, 1, BattleScript_DefDown_Ret, ANIM_ON - jumpifability BS_TARGET, ABILITY_INNER_FOCUS, BattleScript_FlinchPrevention + modifybattlerstatstage BS_TARGET, STAT_DEF, DECREASE, 1, BattleScript_DefDownAndFlinch_Ret, ANIM_ON + jumpifability BS_TARGET, ABILITY_INNER_FOCUS, BattleScript_DefDownAndFlinch_Ret setmoveeffect MOVE_EFFECT_FLINCH seteffectprimary - goto BattleScript_MoveEnd +BattleScript_DefDownAndFlinch_Ret: + return BattleScript_EffectPurify: attackcanceler diff --git a/include/battle_util.h b/include/battle_util.h index 0661081e4..0b25cabdd 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -234,5 +234,6 @@ u32 GetBattlerFriendshipScore(u8 battlerId); u32 CountBattlerStatIncreases(u8 battlerId, bool32 countEvasionAcc); bool32 IsMyceliumMightOnField(void); bool8 ChangeTypeBasedOnTerrain(u8 battlerId); +u32 GetMoveSecondaryEffectChance(u8 battlerId, u8 secondaryEffectChance); #endif // GUARD_BATTLE_UTIL_H diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index f69ddf395..c79a76d7a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3803,48 +3803,23 @@ void SetMoveEffect(bool32 primary, u32 certain) break; case MOVE_EFFECT_TRIPLE_ARROWS: { - u8 randomLowerDefenseChance; - u8 randomFlinchChance; - - if (GetBattlerAbility(gBattlerAttacker) == ABILITY_SERENE_GRACE) - { - randomLowerDefenseChance = RandomPercentage(RNG_TRIPLE_ARROWS_DEFENSE_DOWN, 100); - randomFlinchChance = RandomPercentage(RNG_TRIPLE_ARROWS_FLINCH, 60); - } - else - { - randomLowerDefenseChance = RandomPercentage(RNG_TRIPLE_ARROWS_DEFENSE_DOWN, 50); - randomFlinchChance = RandomPercentage(RNG_TRIPLE_ARROWS_FLINCH, 30); - } + u8 randomLowerDefenseChance = RandomPercentage(RNG_TRIPLE_ARROWS_DEFENSE_DOWN, GetMoveSecondaryEffectChance(gBattlerAttacker, 50)); + u8 randomFlinchChance = RandomPercentage(RNG_TRIPLE_ARROWS_FLINCH, GetMoveSecondaryEffectChance(gBattlerAttacker, 30)); if (randomLowerDefenseChance && randomFlinchChance) { BattleScriptPush(gBattlescriptCurrInstr + 1); gBattlescriptCurrInstr = BattleScript_ReduceDefenseAndFlinch; } - else + else if (randomLowerDefenseChance) { - if (randomLowerDefenseChance) - { - BattleScriptPush(gBattlescriptCurrInstr + 1); - gBattlescriptCurrInstr = BattleScript_DefDown; - } - else if (randomFlinchChance) - { - if (battlerAbility == ABILITY_INNER_FOCUS) - { - gLastUsedAbility = ABILITY_INNER_FOCUS; - gBattlerAbility = gEffectBattler; - RecordAbilityBattle(gEffectBattler, ABILITY_INNER_FOCUS); - gBattlescriptCurrInstr = BattleScript_FlinchPrevention; - } - else - { - if (GetBattlerTurnOrderNum(gEffectBattler) > gCurrentTurnActionNumber) - gBattleMons[gEffectBattler].status2 |= sStatusFlagsForMoveEffects[MOVE_EFFECT_FLINCH]; - gBattlescriptCurrInstr++; - } - } + BattleScriptPush(gBattlescriptCurrInstr + 1); + gBattlescriptCurrInstr = BattleScript_DefDown; + } + else if (randomFlinchChance && battlerAbility != ABILITY_INNER_FOCUS && GetBattlerTurnOrderNum(gEffectBattler) > gCurrentTurnActionNumber) + { + gBattleMons[gEffectBattler].status2 |= sStatusFlagsForMoveEffects[MOVE_EFFECT_FLINCH]; + gBattlescriptCurrInstr++; } } break; @@ -3859,12 +3834,7 @@ static void Cmd_seteffectwithchance(void) { CMD_ARGS(); - u32 percentChance; - - if (GetBattlerAbility(gBattlerAttacker) == ABILITY_SERENE_GRACE) - percentChance = gBattleMoves[gCurrentMove].secondaryEffectChance * 2; - else - percentChance = gBattleMoves[gCurrentMove].secondaryEffectChance; + u32 percentChance = GetMoveSecondaryEffectChance(gBattlerAttacker, gBattleMoves[gCurrentMove].secondaryEffectChance); if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) && gBattleScripting.moveEffect) diff --git a/src/battle_util.c b/src/battle_util.c index f23272b46..a2e179094 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10859,3 +10859,11 @@ static void SetRandomMultiHitCounter() gMultiHitCounter = 5 - (Random() & 1); } } + +u32 GetMoveSecondaryEffectChance(u8 battlerId, u8 secondaryEffectChance) +{ + if (GetBattlerAbility(battlerId) == ABILITY_SERENE_GRACE) + return (secondaryEffectChance * 2); + + return secondaryEffectChance; +} diff --git a/test/move_effect_triple_arrows.c b/test/move_effect_triple_arrows.c index 07a818603..e7f48e0d0 100644 --- a/test/move_effect_triple_arrows.c +++ b/test/move_effect_triple_arrows.c @@ -6,7 +6,7 @@ ASSUMPTIONS ASSUME(gBattleMoves[MOVE_TRIPLE_ARROWS].effect == EFFECT_TRIPLE_ARROWS); } -SINGLE_BATTLE_TEST("Triple Arrows lower's defense by one stage") +SINGLE_BATTLE_TEST("Triple Arrows lowers Defense by one stage") { u32 ability; u32 chance; @@ -25,7 +25,7 @@ SINGLE_BATTLE_TEST("Triple Arrows lower's defense by one stage") } } -SINGLE_BATTLE_TEST("Triple Arrows flinch 30% of the time") +SINGLE_BATTLE_TEST("Triple Arrows make the foe flinch 30% of the time") { u32 ability; u32 chance; @@ -58,3 +58,34 @@ SINGLE_BATTLE_TEST("Triple Arrows lands a critical hit") MESSAGE("A critical hit!"); } } + +SINGLE_BATTLE_TEST("Triple Arrows can lower Defense and cause flinch at the time") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_TRIPLE_ARROWS); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TRIPLE_ARROWS, player); + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent); + MESSAGE("Foe Wobbuffet's defense fell!"); + MESSAGE("Foe Wobbuffet flinched!"); + } +} + +SINGLE_BATTLE_TEST("Triple Arrows's flinching is prevented by Inner Focus") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_RIOLU) { Ability(ABILITY_INNER_FOCUS); } + } WHEN { + TURN { MOVE(player, MOVE_TRIPLE_ARROWS); + MOVE(opponent, MOVE_TACKLE); + } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_TRIPLE_ARROWS, player); + NONE_OF { MESSAGE("Foe Wobbuffet flinched!"); } + ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, opponent); + } +}