diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 8a9fd526594..06c0ecee096 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -961,7 +961,16 @@ export default class BattleScene extends SceneBase { this.offsetGym = this.gameMode.isClassic && this.getGeneratedOffsetGym(); } - // What is the purpose of this function? Why not just use Battle.randSeedInt() directly? + /** + * Generates a random number using the current battle's seed + * + * This calls {@linkcode Battle.randSeedInt}(`scene`, {@linkcode range}, {@linkcode min}) in `src/battle.ts` + * which calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` + * + * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} + * @param min The minimum integer to pick, default `0` + * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) + */ randBattleSeedInt(range: integer, min: integer = 0): integer { return this.currentBattle?.randSeedInt(this, range, min); } diff --git a/src/battle.ts b/src/battle.ts index c4961b8c78c..9f2600dbac6 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -367,6 +367,12 @@ export default class Battle { return null; } + /** + * Generates a random number using the current battle's seed. Calls {@linkcode Utils.randSeedInt} + * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} + * @param min The minimum integer to pick, default `0` + * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) + */ randSeedInt(scene: BattleScene, range: integer, min: integer = 0): integer { if (range <= 1) { return min; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 52c20f5f512..450f254d0ea 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -3425,12 +3425,29 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { fusionCanvas.remove(); } + /** + * Generates a random number using the current battle's seed, or the global seed if `this.scene.currentBattle` is falsy + * + * This calls either {@linkcode BattleScene.randBattleSeedInt}({@linkcode range}, {@linkcode min}) in `src/battle-scene.ts` + * which calls {@linkcode Battle.randSeedInt}(`scene`, {@linkcode range}, {@linkcode min}) in `src/battle.ts` + * which calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts`, + * or it directly calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` if there is no current battle + * + * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} + * @param min The minimum integer to pick, default `0` + * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) + */ randSeedInt(range: integer, min: integer = 0): integer { return this.scene.currentBattle ? this.scene.randBattleSeedInt(range, min) : Utils.randSeedInt(range, min); } + /** + * @param min The minimum integer to generate + * @param max The maximum integer to generate + * @returns a random integer between {@linkcode min} and {@linkcode max} inclusive + */ randSeedIntRange(min: integer, max: integer): integer { return this.randSeedInt((max - min) + 1, min); } diff --git a/src/utils.ts b/src/utils.ts index e4649b096e9..fd5430d7276 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ -import i18next from "i18next"; import { MoneyFormat } from "#enums/money-format"; +import i18next from "i18next"; export const MissingTextureKey = "__MISSING"; @@ -82,13 +82,18 @@ export function randInt(range: integer, min: integer = 0): integer { return Math.floor(Math.random() * range) + min; } -// Is this only seeded if called via `Battle:randSeedInt()`? +/** + * Generates a random number using the global seed, or the current battle's seed if called via `Battle.randSeedInt` + * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} + * @param min The minimum integer to pick, default `0` + * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) + */ export function randSeedInt(range: integer, min: integer = 0): integer { if (range <= 1) { return min; } return Phaser.Math.RND.integerInRange(min, (range - 1) + min); -} // +} /** * Returns a random integer between min and max (non-inclusive)