Added a shuffle method based on the current battle seed. Standardized other RNG.
This commit is contained in:
parent
e40967fb5c
commit
1aa5e8293f
|
@ -1049,6 +1049,23 @@ export default class BattleScene extends SceneBase {
|
|||
return this.currentBattle?.randSeedInt(this, range, min);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffles an array based on the current battle's seed.
|
||||
* @param {array} items a list of items
|
||||
* @returns a new randomly shuffled array
|
||||
*/
|
||||
randBattleSeedShuffle(items: any[]): any[] {
|
||||
if (items.length <= 1) {
|
||||
return items;
|
||||
}
|
||||
const newArray = items.slice(0);
|
||||
for (let i = items.length - 1; i > 0; i--) {
|
||||
const j = this.currentBattle?.randSeedInt(this, i);
|
||||
[ newArray[i], newArray[j] ] = [ newArray[j], newArray[i] ];
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
reset(clearScene: boolean = false, clearData: boolean = false, reloadI18n: boolean = false): void {
|
||||
if (clearData) {
|
||||
this.gameData = new GameData(this);
|
||||
|
|
|
@ -318,7 +318,7 @@ export const AbsoluteAvariceEncounter: MysteryEncounter =
|
|||
if (returnedBerryCount > 0) {
|
||||
for (let i = 0; i < returnedBerryCount; i++) {
|
||||
// Shuffle remaining berry types and pop
|
||||
Phaser.Math.RND.shuffle(berryTypesAsArray);
|
||||
pokemon.randSeedShuffle(berryTypesAsArray);
|
||||
const randBerryType = berryTypesAsArray.pop();
|
||||
|
||||
const berryModType = generateModifierType(scene, modifierTypes.BERRY, [ randBerryType ]) as BerryModifierType;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import BattleScene from "#app/battle-scene";
|
||||
import i18next from "i18next";
|
||||
import { isNullOrUndefined, randSeedInt } from "#app/utils";
|
||||
import { isNullOrUndefined, randSeedInt, randSeedShuffle } from "#app/utils";
|
||||
import { PokemonHeldItemModifier } from "#app/modifier/modifier";
|
||||
import Pokemon, { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon";
|
||||
import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor } from "#app/data/pokeball";
|
||||
|
@ -241,7 +241,7 @@ export function getRandomSpeciesByStarterTier(starterTiers: number | [number, nu
|
|||
|
||||
if (tryFilterStarterTiers.length > 0) {
|
||||
const index = randSeedInt(tryFilterStarterTiers.length);
|
||||
return Phaser.Math.RND.shuffle(tryFilterStarterTiers)[index][0].speciesId;
|
||||
return randSeedShuffle(tryFilterStarterTiers)[index][0].speciesId;
|
||||
}
|
||||
|
||||
return Species.BULBASAUR;
|
||||
|
|
|
@ -4044,6 +4044,15 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||
return this.randSeedInt((max - min) + 1, min);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffles an array using the current battle's seed, or the global seed if `this.scene.currentBattle` is falsy.
|
||||
* @param {array} items an array of items
|
||||
* @returns {array} a new shuffled array of items
|
||||
*/
|
||||
randSeedShuffle(items: any[]): any[] {
|
||||
return this.scene.currentBattle ? this.scene.randBattleSeedShuffle(items) : Utils.randSeedShuffle(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes a Pokemon to leave the field (such as in preparation for a switch out/escape).
|
||||
* @param clearEffects Indicates if effects should be cleared (true) or passed
|
||||
|
|
Loading…
Reference in New Issue