diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index a55c4edcf4e..56e81746be1 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -342,9 +342,19 @@ export class DoubleBattleChanceBoosterModifier extends LapsingPersistentModifier return [ this.battlesLeft ]; } + /** + * Modifies the chance of a double battle occurring + * @param args A single element array containing the double battle chance as a NumberHolder + * @returns {boolean} Returns true if the modifier was applied + */ apply(args: any[]): boolean { + // Use Math.max to ensure no dividing by 0 + const chanceMultiplier = 2 * Math.max(1, this.getStackCount()); + const doubleBattleChance = args[0] as Utils.NumberHolder; - doubleBattleChance.value = Math.ceil(doubleBattleChance.value / 2); + // This is divided because the chance is generated as a number from 0 to doubleBattleChance.value using Utils.randSeedInt + // A double battle will initiate if the generated number is 0 + doubleBattleChance.value = Math.ceil(doubleBattleChance.value / chanceMultiplier); return true; }