From 3e65888ff1e8650232353aa3bb05e2fd24e3ad1f Mon Sep 17 00:00:00 2001 From: RedstonewolfX <108761527+RedstonewolfX@users.noreply.github.com> Date: Tue, 27 Aug 2024 17:54:09 -0400 Subject: [PATCH] Update overrides Relocated the "isUnlocked" function to gameData since it requires a reference to it in order to run Removed unnecessary override that disables unlocked items (and its associated overridesHelper statement) --- src/modifier/modifier-type.ts | 6 +++--- src/overrides.ts | 2 -- src/phases/title-phase.ts | 6 +++--- src/system/game-data.ts | 6 ++++++ src/system/unlockables.ts | 12 ------------ src/test/daily_mode.test.ts | 12 ++++++++---- src/test/utils/helpers/overridesHelper.ts | 6 ------ 7 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 993ff652321..ec4814a56a6 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -10,7 +10,7 @@ import PartyUiHandler, { PokemonMoveSelectFilter, PokemonSelectFilter } from ".. import * as Utils from "../utils"; import { TempBattleStat, getTempBattleStatBoosterItemName, getTempBattleStatName } from "../data/temp-battle-stat"; import { getBerryEffectDescription, getBerryName } from "../data/berry"; -import { isUnlocked, Unlockables } from "../system/unlockables"; +import { Unlockables } from "../system/unlockables"; import { StatusEffect, getStatusEffectDescriptor } from "../data/status-effect"; import { SpeciesFormKey } from "../data/pokemon-species"; import BattleScene from "../battle-scene"; @@ -1597,7 +1597,7 @@ const modifierPool: ModifierPool = { new WeightedModifierType(modifierTypes.AMULET_COIN, skipInLastClassicWaveOrDefault(3)), new WeightedModifierType(modifierTypes.EVIOLITE, (party: Pokemon[]) => { const { gameMode, gameData } = party[0].scene; - if (gameMode.isDaily || (!gameMode.isFreshStartChallenge() && isUnlocked(Unlockables.EVIOLITE, gameData))) { + if (gameMode.isDaily || (!gameMode.isFreshStartChallenge() && gameData.isUnlocked(Unlockables.EVIOLITE))) { return party.some(p => ((p.getSpeciesForm(true).speciesId in pokemonEvolutions) || (p.isFusion() && (p.getFusionSpeciesForm(true).speciesId in pokemonEvolutions))) && !p.getHeldItems().some(i => i instanceof Modifiers.EvolutionStatBoosterModifier)) ? 10 : 0; } return 0; @@ -1675,7 +1675,7 @@ const modifierPool: ModifierPool = { new WeightedModifierType(modifierTypes.MULTI_LENS, 18), new WeightedModifierType(modifierTypes.VOUCHER_PREMIUM, (party: Pokemon[], rerollCount: integer) => !party[0].scene.gameMode.isDaily && !party[0].scene.gameMode.isEndless && !party[0].scene.gameMode.isSplicedOnly ? Math.max(5 - rerollCount * 2, 0) : 0, 5), new WeightedModifierType(modifierTypes.DNA_SPLICERS, (party: Pokemon[]) => !party[0].scene.gameMode.isSplicedOnly && party.filter(p => !p.fusionSpecies).length > 1 ? 24 : 0, 24), - new WeightedModifierType(modifierTypes.MINI_BLACK_HOLE, (party: Pokemon[]) => (party[0].scene.gameMode.isDaily || (!party[0].scene.gameMode.isFreshStartChallenge() && isUnlocked(Unlockables.MINI_BLACK_HOLE, party[0].scene.gameData))) ? 1 : 0, 1), + new WeightedModifierType(modifierTypes.MINI_BLACK_HOLE, (party: Pokemon[]) => (party[0].scene.gameMode.isDaily || (!party[0].scene.gameMode.isFreshStartChallenge() && party[0].scene.gameData.isUnlocked(Unlockables.MINI_BLACK_HOLE))) ? 1 : 0, 1), ].map(m => { m.setTier(ModifierTier.MASTER); return m; }) diff --git a/src/overrides.ts b/src/overrides.ts index 811461a3c60..ed1af8ab35e 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -72,8 +72,6 @@ class DefaultOverrides { }; /** Forces an item to be UNLOCKED */ readonly UNLOCK_OVERRIDE: Unlockables[] = []; - /** Forces an item to be NOT UNLOCKED */ - readonly DISABLE_UNLOCK_OVERRIDE: Unlockables[] = []; // ---------------- // PLAYER OVERRIDES diff --git a/src/phases/title-phase.ts b/src/phases/title-phase.ts index 023fd382558..55879e52bdb 100644 --- a/src/phases/title-phase.ts +++ b/src/phases/title-phase.ts @@ -8,7 +8,7 @@ import { GameModes, GameMode, getGameMode } from "#app/game-mode.js"; import { regenerateModifierPoolThresholds, ModifierPoolType, modifierTypes, getDailyRunStarterModifiers } from "#app/modifier/modifier-type.js"; import { Phase } from "#app/phase.js"; import { SessionSaveData } from "#app/system/game-data.js"; -import { isUnlocked, Unlockables } from "#app/system/unlockables.js"; +import { Unlockables } from "#app/system/unlockables.js"; import { vouchers } from "#app/system/voucher.js"; import { OptionSelectItem, OptionSelectConfig } from "#app/ui/abstact-option-select-ui-handler.js"; import { SaveSlotUiMode } from "#app/ui/save-slot-select-ui-handler.js"; @@ -76,7 +76,7 @@ export class TitlePhase extends Phase { this.scene.ui.clearText(); this.end(); }; - if (isUnlocked(Unlockables.ENDLESS_MODE, this.scene.gameData)) { + if (this.scene.gameData.isUnlocked(Unlockables.ENDLESS_MODE)) { const options: OptionSelectItem[] = [ { label: GameMode.getModeName(GameModes.CLASSIC), @@ -100,7 +100,7 @@ export class TitlePhase extends Phase { } } ]; - if (isUnlocked(Unlockables.SPLICED_ENDLESS_MODE, this.scene.gameData)) { + if (this.scene.gameData.isUnlocked(Unlockables.SPLICED_ENDLESS_MODE)) { options.push({ label: GameMode.getModeName(GameModes.SPLICED_ENDLESS), handler: () => { diff --git a/src/system/game-data.ts b/src/system/game-data.ts index e7bc85d9037..90b80c87415 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -364,6 +364,12 @@ export class GameData { unlockPity: this.unlockPity.slice(0) }; } + public isUnlocked(unlockable: Unlockables): boolean { + if (Overrides.UNLOCK_OVERRIDE.includes(unlockable)) { + return true; + } + return this.unlocks[unlockable]; + } public saveSystem(): Promise { return new Promise(resolve => { diff --git a/src/system/unlockables.ts b/src/system/unlockables.ts index 80a12e2df11..983909373fd 100644 --- a/src/system/unlockables.ts +++ b/src/system/unlockables.ts @@ -1,7 +1,5 @@ import i18next from "i18next"; import { GameMode, GameModes } from "../game-mode"; -import Overrides from "#app/overrides"; -import { GameData } from "./game-data"; export enum Unlockables { ENDLESS_MODE, @@ -10,16 +8,6 @@ export enum Unlockables { EVIOLITE } -export function isUnlocked(unlockable: Unlockables, gameData: GameData): boolean { - if (Overrides.UNLOCK_OVERRIDE.includes(unlockable)) { - return true; - } - if (Overrides.DISABLE_UNLOCK_OVERRIDE.includes(unlockable)) { - return false; - } - return gameData.unlocks[unlockable]; -} - export function getUnlockableName(unlockable: Unlockables) { switch (unlockable) { case Unlockables.ENDLESS_MODE: diff --git a/src/test/daily_mode.test.ts b/src/test/daily_mode.test.ts index 6ddabae3285..e1e9b6ace95 100644 --- a/src/test/daily_mode.test.ts +++ b/src/test/daily_mode.test.ts @@ -4,8 +4,8 @@ import { MapModifier } from "#app/modifier/modifier.js"; import { SelectModifierPhase } from "../phases/select-modifier-phase"; import { Moves } from "#app/enums/moves.js"; import { Abilities } from "#app/enums/abilities.js"; -import { Unlockables } from "#app/system/unlockables.js"; import { poolHasEviolite, poolHasBlackHole } from "#app/modifier/modifier-type.js"; +import { TitlePhase } from "#app/phases/title-phase.js"; describe("Daily Mode", () => { let phaserGame: Phaser.Game; @@ -45,14 +45,15 @@ describe("Daily Mode", () => { .battleType("single") .startingLevel(200) .moveset([Moves.SURF]) - .enemyAbility(Abilities.BALL_FETCH) - .startingModifier([{ name: "LOCK_CAPSULE" }]) - .lockUnlockable([Unlockables.MINI_BLACK_HOLE, Unlockables.EVIOLITE]); + .enemyAbility(Abilities.BALL_FETCH); }); afterEach(() => { game.phaseInterceptor.restoreOg(); }); it("should only allow Mini Black Hole and Eviolite outside of Daily if unlocked", async () => { + const titlePhase = new TitlePhase(game.scene); + game.scene.unshiftPhase(titlePhase); + await game.phaseInterceptor.run(TitlePhase); await game.classicMode.runToSummon(); await game.startBattle(); @@ -62,6 +63,9 @@ describe("Daily Mode", () => { expect(poolHasBlackHole).toBeFalsy(); }); it("should allow Eviolite and Mini Black Hole in shop when in Daily Run", async () => { + const titlePhase = new TitlePhase(game.scene); + game.scene.unshiftPhase(titlePhase); + await game.phaseInterceptor.run(TitlePhase); await game.dailyMode.runToSummon(); await game.startBattle(); diff --git a/src/test/utils/helpers/overridesHelper.ts b/src/test/utils/helpers/overridesHelper.ts index 505641e7e06..cbae9d1ead1 100644 --- a/src/test/utils/helpers/overridesHelper.ts +++ b/src/test/utils/helpers/overridesHelper.ts @@ -288,12 +288,6 @@ export class OverridesHelper extends GameManagerHelper { return this; } - lockUnlockable(unlockable: Unlockables[]) { - vi.spyOn(Overrides, "DISABLE_UNLOCK_OVERRIDE", "get").mockReturnValue(unlockable); - this.log("Temporarily re-locked the following content: ", unlockable); - return this; - } - private log(...params: any[]) { console.log("Overrides:", ...params); }