diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index cc06b4bf41..35455fdc96 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -93,7 +93,9 @@ .endm .macro seteffectwithchance + 1: .byte 0x15 + jumpifhalfword CMP_EQUAL, sMOVE_EFFECT, MOVE_EFFECT_CONTINUE, 1b .endm .macro seteffectprimary diff --git a/include/battle.h b/include/battle.h index 1578e1e53b..5d26ad6556 100644 --- a/include/battle.h +++ b/include/battle.h @@ -581,6 +581,7 @@ struct BattleStruct u32 expValue; u8 expGettersOrder[PARTY_SIZE]; // First battlers which were sent out, then via exp-share u8 expGetterMonId; + u8 additionalEffectsCounter:2; u8 expOrderId:3; u8 expGetterBattlerId:2; u8 teamGotExpMsgPrinted:1; // The 'Rest of your team got msg' has been printed. diff --git a/include/constants/battle.h b/include/constants/battle.h index 1beb9f490c..4d19f12348 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -389,8 +389,9 @@ #define NUM_MOVE_EFFECTS 78 -#define MOVE_EFFECT_AFFECTS_USER 0x4000 -#define MOVE_EFFECT_CERTAIN 0x8000 +#define MOVE_EFFECT_AFFECTS_USER 0x2000 +#define MOVE_EFFECT_CERTAIN 0x4000 +#define MOVE_EFFECT_CONTINUE 0x8000 // Battle terrain defines for gBattleTerrain. #define BATTLE_TERRAIN_GRASS 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index b60c8be94e..75bb978747 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3621,13 +3621,11 @@ static void Cmd_seteffectwithchance(void) { CMD_ARGS(); - u8 i; - u32 percentChance = CalcSecondaryEffectChance(gBattlerAttacker, gBattleMoves[gCurrentMove].secondaryEffectChance); - if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) { - if (gBattleScripting.moveEffect) + if (gBattleScripting.moveEffect &= ~(MOVE_EFFECT_CONTINUE)) { + u32 percentChance = CalcSecondaryEffectChance(gBattlerAttacker, gBattleMoves[gCurrentMove].secondaryEffectChance); if (gBattleScripting.moveEffect & MOVE_EFFECT_CERTAIN || percentChance >= 100) { @@ -3642,34 +3640,50 @@ static void Cmd_seteffectwithchance(void) { gBattlescriptCurrInstr = cmd->nextInstr; } + gBattleScripting.moveEffect = 0; + } + else if (gBattleMoves[gCurrentMove].numAdditionalEffects > 0) + { + u32 percentChance = CalcSecondaryEffectChance( + gBattlerAttacker, + gBattleMoves[gCurrentMove].additionalEffects[gBattleStruct->additionalEffectsCounter].chance + ); + + // Activate effect if it's primary (chance == 0) or if RNGesus says so + if ((percentChance == 0) || RandomPercentage(RNG_SECONDARY_EFFECT + gBattleStruct->additionalEffectsCounter, percentChance)) + { + gBattleScripting.moveEffect = gBattleMoves[gCurrentMove].additionalEffects[gBattleStruct->additionalEffectsCounter].moveEffect + | (MOVE_EFFECT_AFFECTS_USER * (gBattleMoves[gCurrentMove].additionalEffects[gBattleStruct->additionalEffectsCounter].self)); + + SetMoveEffect( + percentChance == 0, // a primary effect + percentChance == 100 // certain to happen + ); + } + else + gBattlescriptCurrInstr = cmd->nextInstr; + + // Call seteffectwithchance again in the case of a move with multiple effects + if (gBattleMoves[gCurrentMove].numAdditionalEffects - 1 > gBattleStruct->additionalEffectsCounter) + { + gBattleStruct->additionalEffectsCounter++; + gBattleScripting.moveEffect = MOVE_EFFECT_CONTINUE; + } + else + gBattleStruct->additionalEffectsCounter = gBattleScripting.moveEffect = 0; } else { - 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; + gBattleScripting.moveEffect = 0; + gBattlescriptCurrInstr = cmd->nextInstr; } } else { + gBattleScripting.moveEffect = 0; gBattlescriptCurrInstr = cmd->nextInstr; } - gBattleScripting.moveEffect = 0; gBattleScripting.multihitMoveEffect = 0; }