From d2ffc12d6519c1fbe052c74b14b6d015bd7cf402 Mon Sep 17 00:00:00 2001 From: AJ Fontaine <36677462+Fontbane@users.noreply.github.com> Date: Sun, 30 Mar 2025 02:18:18 -0400 Subject: [PATCH] [Refactor] Remove game mode param from applyChallenges (#5585) --- src/data/challenge.ts | 66 +++++------------------------ src/data/moves/move.ts | 2 +- src/field/pokemon.ts | 5 --- src/game-mode.ts | 4 +- src/phases/select-starter-phase.ts | 2 +- src/system/game-data.ts | 2 +- src/ui/party-ui-handler.ts | 2 +- src/ui/starter-select-ui-handler.ts | 2 +- 8 files changed, 18 insertions(+), 67 deletions(-) diff --git a/src/data/challenge.ts b/src/data/challenge.ts index 1387732a773..455421ffefd 100644 --- a/src/data/challenge.ts +++ b/src/data/challenge.ts @@ -10,7 +10,6 @@ import { PokemonMove } from "#app/field/pokemon"; import type { FixedBattleConfig } from "#app/battle"; import { ClassicFixedBossWaves, BattleType, getRandomTrainerFunc } from "#app/battle"; import Trainer, { TrainerVariant } from "#app/field/trainer"; -import type { GameMode } from "#app/game-mode"; import { PokemonType } from "#enums/pokemon-type"; import { Challenges } from "#enums/challenges"; import { Species } from "#enums/species"; @@ -383,10 +382,9 @@ export abstract class Challenge { /** * An apply function for GAME_MODE_MODIFY challenges. Derived classes should alter this. - * @param gameMode {@link GameMode} The current game mode. * @returns {@link boolean} Whether this function did anything. */ - applyGameModeModify(_gameMode: GameMode): boolean { + applyGameModeModify(): boolean { return false; } @@ -974,7 +972,6 @@ export class LowerStarterPointsChallenge extends Challenge { /** * Apply all challenges that modify starter choice. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.STARTER_CHOICE * @param pokemon {@link PokemonSpecies} The pokemon to check the validity of. * @param valid {@link Utils.BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. @@ -982,7 +979,6 @@ export class LowerStarterPointsChallenge extends Challenge { * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.STARTER_CHOICE, pokemon: PokemonSpecies, valid: Utils.BooleanHolder, @@ -990,85 +986,66 @@ export function applyChallenges( ): boolean; /** * Apply all challenges that modify available total starter points. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.STARTER_POINTS * @param points {@link Utils.NumberHolder} The amount of points you have available. * @returns True if any challenge was successfully applied. */ -export function applyChallenges( - gameMode: GameMode, - challengeType: ChallengeType.STARTER_POINTS, - points: Utils.NumberHolder, -): boolean; +export function applyChallenges(challengeType: ChallengeType.STARTER_POINTS, points: Utils.NumberHolder): boolean; /** * Apply all challenges that modify the cost of a starter. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.STARTER_COST * @param species {@link Species} The pokemon to change the cost of. * @param points {@link Utils.NumberHolder} The cost of the pokemon. * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.STARTER_COST, species: Species, cost: Utils.NumberHolder, ): boolean; /** * Apply all challenges that modify a starter after selection. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.STARTER_MODIFY * @param pokemon {@link Pokemon} The starter pokemon to modify. * @returns True if any challenge was successfully applied. */ -export function applyChallenges( - gameMode: GameMode, - challengeType: ChallengeType.STARTER_MODIFY, - pokemon: Pokemon, -): boolean; +export function applyChallenges(challengeType: ChallengeType.STARTER_MODIFY, pokemon: Pokemon): boolean; /** * Apply all challenges that what pokemon you can have in battle. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.POKEMON_IN_BATTLE * @param pokemon {@link Pokemon} The pokemon to check the validity of. * @param valid {@link Utils.BooleanHolder} A BooleanHolder, the value gets set to false if the pokemon isn't allowed. * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.POKEMON_IN_BATTLE, pokemon: Pokemon, valid: Utils.BooleanHolder, ): boolean; /** * Apply all challenges that modify what fixed battles there are. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.FIXED_BATTLES * @param waveIndex {@link Number} The current wave index. * @param battleConfig {@link FixedBattleConfig} The battle config to modify. * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.FIXED_BATTLES, waveIndex: number, battleConfig: FixedBattleConfig, ): boolean; /** * Apply all challenges that modify type effectiveness. - * @param gameMode {@linkcode GameMode} The current gameMode * @param challengeType {@linkcode ChallengeType} ChallengeType.TYPE_EFFECTIVENESS * @param effectiveness {@linkcode Utils.NumberHolder} The current effectiveness of the move. * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.TYPE_EFFECTIVENESS, effectiveness: Utils.NumberHolder, ): boolean; /** * Apply all challenges that modify what level AI are. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.AI_LEVEL * @param level {@link Utils.NumberHolder} The generated level of the pokemon. * @param levelCap {@link Number} The maximum level cap for the current wave. @@ -1077,7 +1054,6 @@ export function applyChallenges( * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.AI_LEVEL, level: Utils.NumberHolder, levelCap: number, @@ -1086,42 +1062,36 @@ export function applyChallenges( ): boolean; /** * Apply all challenges that modify how many move slots the AI has. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.AI_MOVE_SLOTS * @param pokemon {@link Pokemon} The pokemon being considered. * @param moveSlots {@link Utils.NumberHolder} The amount of move slots. * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.AI_MOVE_SLOTS, pokemon: Pokemon, moveSlots: Utils.NumberHolder, ): boolean; /** * Apply all challenges that modify whether a pokemon has its passive. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.PASSIVE_ACCESS * @param pokemon {@link Pokemon} The pokemon to modify. * @param hasPassive {@link Utils.BooleanHolder} Whether it has its passive. * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.PASSIVE_ACCESS, pokemon: Pokemon, hasPassive: Utils.BooleanHolder, ): boolean; /** * Apply all challenges that modify the game modes settings. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.GAME_MODE_MODIFY * @returns True if any challenge was successfully applied. */ -export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType.GAME_MODE_MODIFY): boolean; +export function applyChallenges(challengeType: ChallengeType.GAME_MODE_MODIFY): boolean; /** * Apply all challenges that modify what level a pokemon can access a move. - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.MOVE_ACCESS * @param pokemon {@link Pokemon} What pokemon would learn the move. * @param moveSource {@link MoveSourceType} What source the pokemon would get the move from. @@ -1130,7 +1100,6 @@ export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.MOVE_ACCESS, pokemon: Pokemon, moveSource: MoveSourceType, @@ -1139,7 +1108,6 @@ export function applyChallenges( ): boolean; /** * Apply all challenges that modify what weight a pokemon gives to move generation - * @param gameMode {@link GameMode} The current gameMode * @param challengeType {@link ChallengeType} ChallengeType.MOVE_WEIGHT * @param pokemon {@link Pokemon} What pokemon would learn the move. * @param moveSource {@link MoveSourceType} What source the pokemon would get the move from. @@ -1148,7 +1116,6 @@ export function applyChallenges( * @returns True if any challenge was successfully applied. */ export function applyChallenges( - gameMode: GameMode, challengeType: ChallengeType.MOVE_WEIGHT, pokemon: Pokemon, moveSource: MoveSourceType, @@ -1156,16 +1123,11 @@ export function applyChallenges( weight: Utils.NumberHolder, ): boolean; -export function applyChallenges( - gameMode: GameMode, - challengeType: ChallengeType.FLIP_STAT, - pokemon: Pokemon, - baseStats: number[], -): boolean; +export function applyChallenges(challengeType: ChallengeType.FLIP_STAT, pokemon: Pokemon, baseStats: number[]): boolean; -export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType, ...args: any[]): boolean { +export function applyChallenges(challengeType: ChallengeType, ...args: any[]): boolean { let ret = false; - gameMode.challenges.forEach(c => { + globalScene.gameMode.challenges.forEach(c => { if (c.value !== 0) { switch (challengeType) { case ChallengeType.STARTER_CHOICE: @@ -1199,7 +1161,7 @@ export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType ret ||= c.applyPassiveAccess(args[0], args[1]); break; case ChallengeType.GAME_MODE_MODIFY: - ret ||= c.applyGameModeModify(gameMode); + ret ||= c.applyGameModeModify(); break; case ChallengeType.MOVE_ACCESS: ret ||= c.applyMoveAccessLevel(args[0], args[1], args[2], args[3]); @@ -1264,7 +1226,7 @@ export function initChallenges() { export function checkStarterValidForChallenge(species: PokemonSpecies, props: DexAttrProps, soft: boolean) { if (!soft) { const isValidForChallenge = new Utils.BooleanHolder(true); - applyChallenges(globalScene.gameMode, ChallengeType.STARTER_CHOICE, species, isValidForChallenge, props); + applyChallenges(ChallengeType.STARTER_CHOICE, species, isValidForChallenge, props); return isValidForChallenge.value; } // We check the validity of every evolution and form change, and require that at least one is valid @@ -1302,7 +1264,7 @@ export function checkStarterValidForChallenge(species: PokemonSpecies, props: De */ function checkSpeciesValidForChallenge(species: PokemonSpecies, props: DexAttrProps, soft: boolean) { const isValidForChallenge = new Utils.BooleanHolder(true); - applyChallenges(globalScene.gameMode, ChallengeType.STARTER_CHOICE, species, isValidForChallenge, props); + applyChallenges(ChallengeType.STARTER_CHOICE, species, isValidForChallenge, props); if (!soft || !pokemonFormChanges.hasOwnProperty(species.speciesId)) { return isValidForChallenge.value; } @@ -1321,13 +1283,7 @@ function checkSpeciesValidForChallenge(species: PokemonSpecies, props: DexAttrPr const formProps = { ...props }; formProps.formIndex = formIndex; const isFormValidForChallenge = new Utils.BooleanHolder(true); - applyChallenges( - globalScene.gameMode, - ChallengeType.STARTER_CHOICE, - species, - isFormValidForChallenge, - formProps, - ); + applyChallenges(ChallengeType.STARTER_CHOICE, species, isFormValidForChallenge, formProps); if (isFormValidForChallenge.value) { return true; } diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index efef4372f8f..6fb2f5b7c50 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -8110,7 +8110,7 @@ export class ResistLastMoveTypeAttr extends MoveEffectAttr { for (let i = 0; i < Object.keys(PokemonType).length; i++) { const multiplier = new NumberHolder(1); multiplier.value = getTypeDamageMultiplier(type, i); - applyChallenges(gameMode, ChallengeType.TYPE_EFFECTIVENESS, multiplier); + applyChallenges(ChallengeType.TYPE_EFFECTIVENESS, multiplier); if (multiplier.value < 1) { typeResistances.push(i); } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 98aa51c6050..b595d516f53 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -634,7 +634,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { public isAllowedInChallenge(): boolean { const challengeAllowed = new Utils.BooleanHolder(true); applyChallenges( - globalScene.gameMode, ChallengeType.POKEMON_IN_BATTLE, this, challengeAllowed, @@ -1598,7 +1597,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { calculateBaseStats(): number[] { const baseStats = this.getSpeciesForm(true).baseStats.slice(0); applyChallenges( - globalScene.gameMode, ChallengeType.FLIP_STAT, this, baseStats, @@ -1620,7 +1618,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (this.isFusion()) { const fusionBaseStats = this.getFusionSpeciesForm(true).baseStats; applyChallenges( - globalScene.gameMode, ChallengeType.FLIP_STAT, this, fusionBaseStats, @@ -2594,7 +2591,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { getTypeDamageMultiplier(moveType, defType), ); applyChallenges( - globalScene.gameMode, ChallengeType.TYPE_EFFECTIVENESS, multiplier, ); @@ -2646,7 +2642,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { getTypeDamageMultiplier(moveType, PokemonType.FLYING), ); applyChallenges( - globalScene.gameMode, ChallengeType.TYPE_EFFECTIVENESS, typeMultiplierAgainstFlying, ); diff --git a/src/game-mode.ts b/src/game-mode.ts index 9ab1674bcce..5e27c32f015 100644 --- a/src/game-mode.ts +++ b/src/game-mode.ts @@ -285,7 +285,7 @@ export class GameMode implements GameModeConfig { const dummyConfig = new FixedBattleConfig(); return ( this.battleConfig.hasOwnProperty(waveIndex) || - applyChallenges(this, ChallengeType.FIXED_BATTLES, waveIndex, dummyConfig) + applyChallenges(ChallengeType.FIXED_BATTLES, waveIndex, dummyConfig) ); } @@ -296,7 +296,7 @@ export class GameMode implements GameModeConfig { */ getFixedBattle(waveIndex: number): FixedBattleConfig { const challengeConfig = new FixedBattleConfig(); - if (applyChallenges(this, ChallengeType.FIXED_BATTLES, waveIndex, challengeConfig)) { + if (applyChallenges(ChallengeType.FIXED_BATTLES, waveIndex, challengeConfig)) { return challengeConfig; } return this.battleConfig[waveIndex]; diff --git a/src/phases/select-starter-phase.ts b/src/phases/select-starter-phase.ts index 0f4360b0af6..b3ebe6731c9 100644 --- a/src/phases/select-starter-phase.ts +++ b/src/phases/select-starter-phase.ts @@ -101,7 +101,7 @@ export class SelectStarterPhase extends Phase { starterPokemon.generateFusionSpecies(true); } starterPokemon.setVisible(false); - applyChallenges(globalScene.gameMode, ChallengeType.STARTER_MODIFY, starterPokemon); + applyChallenges(ChallengeType.STARTER_MODIFY, starterPokemon); party.push(starterPokemon); loadPokemonAssets.push(starterPokemon.loadAssets()); }); diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 3a098a55a56..2388918dca2 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -2183,7 +2183,7 @@ export class GameData { } const cost = new Utils.NumberHolder(value); - applyChallenges(globalScene.gameMode, ChallengeType.STARTER_COST, speciesId, cost); + applyChallenges(ChallengeType.STARTER_COST, speciesId, cost); return cost.value; } diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 3c04692ea31..caddd64cd28 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -216,7 +216,7 @@ export default class PartyUiHandler extends MessageUiHandler { */ private FilterChallengeLegal = (pokemon: PlayerPokemon) => { const challengeAllowed = new Utils.BooleanHolder(true); - applyChallenges(globalScene.gameMode, ChallengeType.POKEMON_IN_BATTLE, pokemon, challengeAllowed); + applyChallenges(ChallengeType.POKEMON_IN_BATTLE, pokemon, challengeAllowed); if (!challengeAllowed.value) { return i18next.t("partyUiHandler:cantBeUsed", { pokemonName: getPokemonNameWithAffix(pokemon), diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index c1e2b2ac568..7d8e29d8091 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -2956,7 +2956,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { valueLimit.value = 10; } - Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_POINTS, valueLimit); + Challenge.applyChallenges(Challenge.ChallengeType.STARTER_POINTS, valueLimit); return valueLimit.value; }