mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-15 06:15:20 +01:00
* Update trainer-config.ts * Update trainer-config.ts * Revert "Update trainer-config.ts" This reverts commit6243592913. * Revert "Update trainer-config.ts" This reverts commit6243592913. * Update Admins, Add Admin 3 * Update Admins, Add Admin 3 * Update trainer-config.ts * Update trainer-config.ts * Initial Pool Updates * Initial Pool Updates * allow evil team admins to use subpools * allow evil team admins to use subpools * Remove trainer pool tier stairs * freedom motif * Remove trainer pool tier stairs * freedom motif * fix: missing import in trainer-config.ts * Fix incorrect Starmobile forms * Pool Updates + Boss additions * Misc Changes * Reorder p functions in Trainer Config This let move gen properly account for Boss Health, Form Changes, and Abilities for future functions * Ensure evil admins are uniquely selected in different fights * Ensure evil admins are uniquely selected in different fights * Implement evil team admin instant tera for slot 4 * Revert Starmobile Changes * Minor Grunt Pool Changes * Champion Adjustments * Update trainer-config.ts * Update trainer-config.ts * Update challenge.ts --------- Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Co-authored-by: Madmadness65 <blaze.the.fireman@gmail.com>
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2025 Pagefault Games
|
|
* SPDX-FileContributor: SirzBenjie
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
/**
|
|
* A collection of utility methods for working with the game's RNG
|
|
* @module
|
|
*/
|
|
|
|
import { globalScene } from "#app/global-scene";
|
|
import type { Mutable } from "#types/type-helpers";
|
|
import { randSeedItem } from "#utils/common";
|
|
|
|
/**
|
|
* Select a random element using an offset such that the chosen element is
|
|
* guaranteed to be unique from the last `seedOffset` selections.
|
|
*
|
|
* @remarks
|
|
* If the seed offset is greater than the number of choices, this will just choose a random element
|
|
*
|
|
* @param arr - The array of items to choose from
|
|
* @param scene - (default {@linkcode globalScene}); The scene to use for random seeding
|
|
* @returns A random item from the array that is guaranteed to be different from the
|
|
* @typeParam T - The type of items in the array
|
|
*
|
|
* @example
|
|
* ```
|
|
* const choices = ['a', 'b', 'c', 'd'];
|
|
* const choice1 = randSeedUniqueItem(choices, 0);
|
|
* const choice2 = randSeedUniqueItem(choices, 1);
|
|
* const choice3 = randSeedUniqueItem(choices, 2);
|
|
* assert(choice2 !== choice1);
|
|
* assert(choice3 !== choice1);
|
|
* assert(choice3 !== choice2);
|
|
* ```
|
|
*/
|
|
export function randSeedUniqueItem<T>(choices: readonly T[], seedOffset: number, scene = globalScene): T {
|
|
if (seedOffset === 0 || choices.length <= seedOffset) {
|
|
// cast to mutable is safe because randSeedItem does not actually modify the array
|
|
return randSeedItem(choices as Mutable<typeof choices>);
|
|
}
|
|
|
|
// TODO: Refactor `excuteWithSeedOffset` and pull it into this module
|
|
let choice: T;
|
|
|
|
scene.executeWithSeedOffset(() => {
|
|
const curChoices = choices.slice();
|
|
for (let i = 0; i < seedOffset; i++) {
|
|
const previousChoice = randSeedItem(curChoices);
|
|
curChoices.splice(curChoices.indexOf(previousChoice), 1);
|
|
}
|
|
choice = randSeedItem(curChoices);
|
|
}, seedOffset);
|
|
|
|
// Bang is safe since there are at least `seedOffset` choices, so the method above is guaranteed to set `choice`
|
|
return choice!;
|
|
}
|