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.
This commit is contained in:
LOuroboros 2023-04-19 01:52:23 -03:00
parent 787c0a159a
commit b09ab5a3ee
5 changed files with 57 additions and 46 deletions

View File

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

View File

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

View File

@ -3803,50 +3803,25 @@ 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
{
if (randomLowerDefenseChance)
else if (randomLowerDefenseChance)
{
BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = BattleScript_DefDown;
}
else if (randomFlinchChance)
else if (randomFlinchChance && battlerAbility != ABILITY_INNER_FOCUS && GetBattlerTurnOrderNum(gEffectBattler) > gCurrentTurnActionNumber)
{
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++;
}
}
}
}
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)

View File

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

View File

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