[Misc] Shiny overrides can now force Pokemon to not be shiny (#4699)

Also fixes random shinies breaking tests
This commit is contained in:
NightKev 2024-10-21 08:00:58 -07:00 committed by GitHub
parent f51814467a
commit 966b07f62b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 69 additions and 18 deletions

View File

@ -3982,10 +3982,14 @@ export class PlayerPokemon extends Pokemon {
if (Overrides.SHINY_OVERRIDE) { if (Overrides.SHINY_OVERRIDE) {
this.shiny = true; this.shiny = true;
this.initShinySparkle(); this.initShinySparkle();
if (Overrides.VARIANT_OVERRIDE) { } else if (Overrides.SHINY_OVERRIDE === false) {
this.variant = Overrides.VARIANT_OVERRIDE; this.shiny = false;
}
} }
if (Overrides.VARIANT_OVERRIDE !== null && this.shiny) {
this.variant = Overrides.VARIANT_OVERRIDE;
}
if (!dataSource) { if (!dataSource) {
if (this.scene.gameMode.isDaily) { if (this.scene.gameMode.isDaily) {
this.generateAndPopulateMoveset(); this.generateAndPopulateMoveset();
@ -4474,10 +4478,13 @@ export class EnemyPokemon extends Pokemon {
if (Overrides.OPP_SHINY_OVERRIDE) { if (Overrides.OPP_SHINY_OVERRIDE) {
this.shiny = true; this.shiny = true;
this.initShinySparkle(); this.initShinySparkle();
} else if (Overrides.OPP_SHINY_OVERRIDE === false) {
this.shiny = false;
} }
if (this.shiny) { if (this.shiny) {
this.variant = this.generateVariant(); this.variant = this.generateVariant();
if (Overrides.OPP_VARIANT_OVERRIDE) { if (Overrides.OPP_VARIANT_OVERRIDE !== null) {
this.variant = Overrides.OPP_VARIANT_OVERRIDE; this.variant = Overrides.OPP_VARIANT_OVERRIDE;
} }
} }

View File

@ -113,8 +113,8 @@ class DefaultOverrides {
readonly STATUS_OVERRIDE: StatusEffect = StatusEffect.NONE; readonly STATUS_OVERRIDE: StatusEffect = StatusEffect.NONE;
readonly GENDER_OVERRIDE: Gender | null = null; readonly GENDER_OVERRIDE: Gender | null = null;
readonly MOVESET_OVERRIDE: Moves | Array<Moves> = []; readonly MOVESET_OVERRIDE: Moves | Array<Moves> = [];
readonly SHINY_OVERRIDE: boolean = false; readonly SHINY_OVERRIDE: boolean | null = null;
readonly VARIANT_OVERRIDE: Variant = 0; readonly VARIANT_OVERRIDE: Variant | null = null;
// -------------------------- // --------------------------
// OPPONENT / ENEMY OVERRIDES // OPPONENT / ENEMY OVERRIDES
@ -134,8 +134,8 @@ class DefaultOverrides {
readonly OPP_STATUS_OVERRIDE: StatusEffect = StatusEffect.NONE; readonly OPP_STATUS_OVERRIDE: StatusEffect = StatusEffect.NONE;
readonly OPP_GENDER_OVERRIDE: Gender | null = null; readonly OPP_GENDER_OVERRIDE: Gender | null = null;
readonly OPP_MOVESET_OVERRIDE: Moves | Array<Moves> = []; readonly OPP_MOVESET_OVERRIDE: Moves | Array<Moves> = [];
readonly OPP_SHINY_OVERRIDE: boolean = false; readonly OPP_SHINY_OVERRIDE: boolean | null = null;
readonly OPP_VARIANT_OVERRIDE: Variant = 0; readonly OPP_VARIANT_OVERRIDE: Variant | null = null;
readonly OPP_IVS_OVERRIDE: number | number[] = []; readonly OPP_IVS_OVERRIDE: number | number[] = [];
readonly OPP_FORM_OVERRIDES: Partial<Record<Species, number>> = {}; readonly OPP_FORM_OVERRIDES: Partial<Record<Species, number>> = {};
/** /**

View File

@ -38,6 +38,10 @@ export class ChallengeModeHelper extends GameManagerHelper {
async runToSummon(species?: Species[]) { async runToSummon(species?: Species[]) {
await this.game.runToTitle(); await this.game.runToTitle();
if (this.game.override.disableShinies) {
this.game.override.shiny(false).enemyShiny(false);
}
this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => { this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => {
this.game.scene.gameMode.challenges = this.challenges; this.game.scene.gameMode.challenges = this.challenges;
const starters = generateStarter(this.game.scene, species); const starters = generateStarter(this.game.scene, species);
@ -47,7 +51,7 @@ export class ChallengeModeHelper extends GameManagerHelper {
}); });
await this.game.phaseInterceptor.run(EncounterPhase); await this.game.phaseInterceptor.run(EncounterPhase);
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) { if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0 && this.game.override.removeEnemyStartingItems) {
this.game.removeEnemyHeldItems(); this.game.removeEnemyHeldItems();
} }
} }

View File

@ -20,9 +20,13 @@ export class ClassicModeHelper extends GameManagerHelper {
* @param species - Optional array of species to summon. * @param species - Optional array of species to summon.
* @returns A promise that resolves when the summon phase is reached. * @returns A promise that resolves when the summon phase is reached.
*/ */
async runToSummon(species?: Species[]) { async runToSummon(species?: Species[]): Promise<void> {
await this.game.runToTitle(); await this.game.runToTitle();
if (this.game.override.disableShinies) {
this.game.override.shiny(false).enemyShiny(false);
}
this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => { this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => {
this.game.scene.gameMode = getGameMode(GameModes.CLASSIC); this.game.scene.gameMode = getGameMode(GameModes.CLASSIC);
const starters = generateStarter(this.game.scene, species); const starters = generateStarter(this.game.scene, species);
@ -32,7 +36,7 @@ export class ClassicModeHelper extends GameManagerHelper {
}); });
await this.game.phaseInterceptor.run(EncounterPhase); await this.game.phaseInterceptor.run(EncounterPhase);
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) { if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0 && this.game.override.removeEnemyStartingItems) {
this.game.removeEnemyHeldItems(); this.game.removeEnemyHeldItems();
} }
} }
@ -42,7 +46,7 @@ export class ClassicModeHelper extends GameManagerHelper {
* @param species - Optional array of species to start the battle with. * @param species - Optional array of species to start the battle with.
* @returns A promise that resolves when the battle is started. * @returns A promise that resolves when the battle is started.
*/ */
async startBattle(species?: Species[]) { async startBattle(species?: Species[]): Promise<void> {
await this.runToSummon(species); await this.runToSummon(species);
if (this.game.scene.battleStyle === BattleStyle.SWITCH) { if (this.game.scene.battleStyle === BattleStyle.SWITCH) {

View File

@ -21,6 +21,10 @@ export class DailyModeHelper extends GameManagerHelper {
async runToSummon() { async runToSummon() {
await this.game.runToTitle(); await this.game.runToTitle();
if (this.game.override.disableShinies) {
this.game.override.shiny(false).enemyShiny(false);
}
this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => { this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => {
const titlePhase = new TitlePhase(this.game.scene); const titlePhase = new TitlePhase(this.game.scene);
titlePhase.initDailyRun(); titlePhase.initDailyRun();
@ -33,7 +37,7 @@ export class DailyModeHelper extends GameManagerHelper {
await this.game.phaseInterceptor.to(EncounterPhase); await this.game.phaseInterceptor.to(EncounterPhase);
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) { if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0 && this.game.override.removeEnemyStartingItems) {
this.game.removeEnemyHeldItems(); this.game.removeEnemyHeldItems();
} }
} }

View File

@ -19,6 +19,11 @@ import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
* Helper to handle overrides in tests * Helper to handle overrides in tests
*/ */
export class OverridesHelper extends GameManagerHelper { export class OverridesHelper extends GameManagerHelper {
/** If `true`, removes the starting items from enemies at the start of each test; default `true` */
public removeEnemyStartingItems: boolean = true;
/** If `true`, sets the shiny overrides to disable shinies at the start of each test; default `true` */
public disableShinies: boolean = true;
/** /**
* Override the starting biome * Override the starting biome
* @warning Any event listeners that are attached to [NewArenaEvent](events\battle-scene.ts) may need to be handled down the line * @warning Any event listeners that are attached to [NewArenaEvent](events\battle-scene.ts) may need to be handled down the line
@ -368,23 +373,50 @@ export class OverridesHelper extends GameManagerHelper {
/** /**
* Override player shininess * Override player shininess
* @param shininess Whether the player's Pokemon should be shiny. * @param shininess - `true` or `false` to force the player's pokemon to be shiny or not shiny,
* `null` to disable the override and re-enable RNG shinies.
*/ */
shinyLevel(shininess: boolean): this { shiny(shininess: boolean | null): this {
vi.spyOn(Overrides, "SHINY_OVERRIDE", "get").mockReturnValue(shininess); vi.spyOn(Overrides, "SHINY_OVERRIDE", "get").mockReturnValue(shininess);
this.log(`Set player Pokemon as ${shininess ? "" : "not "}shiny!`); if (shininess === null) {
this.log("Disabled player Pokemon shiny override!");
} else {
this.log(`Set player Pokemon to be ${shininess ? "" : "not "}shiny!`);
}
return this; return this;
} }
/** /**
* Override player shiny variant * Override player shiny variant
* @param variant The player's shiny variant. * @param variant - The player's shiny variant.
*/ */
variantLevel(variant: Variant): this { shinyVariant(variant: Variant): this {
vi.spyOn(Overrides, "VARIANT_OVERRIDE", "get").mockReturnValue(variant); vi.spyOn(Overrides, "VARIANT_OVERRIDE", "get").mockReturnValue(variant);
this.log(`Set player Pokemon's shiny variant to ${variant}!`); this.log(`Set player Pokemon's shiny variant to ${variant}!`);
return this; return this;
} }
/**
* Override enemy shininess
* @param shininess - `true` or `false` to force the enemy's pokemon to be shiny or not shiny,
* `null` to disable the override and re-enable RNG shinies.
* @param variant - (Optional) The enemy's shiny {@linkcode Variant}.
*/
enemyShiny(shininess: boolean | null, variant?: Variant): this {
vi.spyOn(Overrides, "OPP_SHINY_OVERRIDE", "get").mockReturnValue(shininess);
if (shininess === null) {
this.log("Disabled enemy Pokemon shiny override!");
} else {
this.log(`Set enemy Pokemon to be ${shininess ? "" : "not "}shiny!`);
}
if (variant !== undefined) {
vi.spyOn(Overrides, "OPP_VARIANT_OVERRIDE", "get").mockReturnValue(variant);
this.log(`Set enemy shiny variant to be ${variant}!`);
}
return this;
}
/** /**
* Override the enemy (Pokemon) to have the given amount of health segments * Override the enemy (Pokemon) to have the given amount of health segments
* @param healthSegments the number of segments to give * @param healthSegments the number of segments to give