From 27c32f1d36ed249490b0738fb56a17bb6f1f1bdc Mon Sep 17 00:00:00 2001 From: Nephrite Date: Thu, 23 Nov 2023 13:16:52 +0900 Subject: [PATCH] Fixed compatibilty with current move effect system and other moves --- src/battle_script_commands.c | 60 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 5fad096362..b60c8be94e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3624,22 +3624,44 @@ static void Cmd_seteffectwithchance(void) u8 i; u32 percentChance = CalcSecondaryEffectChance(gBattlerAttacker, gBattleMoves[gCurrentMove].secondaryEffectChance); - if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) - && gBattleScripting.moveEffect) + if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) { - if (gBattleScripting.moveEffect & MOVE_EFFECT_CERTAIN - || percentChance >= 100) + if (gBattleScripting.moveEffect) { - gBattleScripting.moveEffect &= ~MOVE_EFFECT_CERTAIN; - SetMoveEffect(FALSE, MOVE_EFFECT_CERTAIN); - } - else if (RandomPercentage(RNG_SECONDARY_EFFECT, percentChance)) - { - SetMoveEffect(FALSE, 0); + if (gBattleScripting.moveEffect & MOVE_EFFECT_CERTAIN + || percentChance >= 100) + { + gBattleScripting.moveEffect &= ~MOVE_EFFECT_CERTAIN; + SetMoveEffect(FALSE, MOVE_EFFECT_CERTAIN); + } + else if (RandomPercentage(RNG_SECONDARY_EFFECT, percentChance)) + { + SetMoveEffect(FALSE, 0); + } + else + { + gBattlescriptCurrInstr = cmd->nextInstr; + } } else { - gBattlescriptCurrInstr = cmd->nextInstr; + bool32 effectHappened = FALSE; + for (i = gBattleMoves[gCurrentMove].numAdditionalEffects; i > 0; i--) + { + percentChance = CalcSecondaryEffectChance( + gBattlerAttacker, + gBattleMoves[gCurrentMove].additionalEffects[i - 1].chance + ); + if ((percentChance == 0) || RandomPercentage(RNG_SECONDARY_EFFECT + i - 1, percentChance)) + { + effectHappened = TRUE; + gBattleScripting.moveEffect = gBattleMoves[gCurrentMove].additionalEffects[i - 1].moveEffect + | MOVE_EFFECT_AFFECTS_USER * (gBattleMoves[gCurrentMove].additionalEffects[i - 1].self); + SetMoveEffect((percentChance == 0), gBattleMoves[gCurrentMove].additionalEffects[i - 1].chance == 100); + } + } + if (effectHappened == FALSE) + gBattlescriptCurrInstr = cmd->nextInstr; } } else @@ -3649,22 +3671,6 @@ static void Cmd_seteffectwithchance(void) gBattleScripting.moveEffect = 0; gBattleScripting.multihitMoveEffect = 0; - - // Set any move effects in this move's ADDITIONAL_EFFECTS - // In reverse array order so that effects are applied in correct order - for (i = gBattleMoves[gCurrentMove].numAdditionalEffects; i > 0; i--) - { - percentChance = CalcSecondaryEffectChance( - gBattlerAttacker, - gBattleMoves[gCurrentMove].additionalEffects[i - 1].chance - ); - // Each effect needs its own RNG_SECONDARY_EFFECT tag - if ((percentChance == 0) || RandomPercentage(RNG_SECONDARY_EFFECT + i - 1, percentChance)) - { - gBattleScripting.moveEffect = gBattleMoves[gCurrentMove].additionalEffects[i - 1].moveEffect; - SetMoveEffect((percentChance == 0), gBattleMoves[gCurrentMove].additionalEffects[i - 1].chance == 100); - } - } } static void Cmd_seteffectprimary(void)