diff --git a/src/@types/common.ts b/src/@types/common.ts index fcd946656dcc..93d88a3b6809 100644 --- a/src/@types/common.ts +++ b/src/@types/common.ts @@ -1,3 +1 @@ -import BattleScene from "#app/battle-scene"; - -export type ConditionFn = (scene: BattleScene, args?: any[]) => boolean; +export type ConditionFn = (args?: any[]) => boolean; diff --git a/src/battle-scene.ts b/src/battle-scene.ts index c430a12ae3eb..d958d81cb846 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -100,6 +100,7 @@ import { ExpGainsSpeed } from "#enums/exp-gains-speed"; import { BattlerTagType } from "#enums/battler-tag-type"; import { FRIENDSHIP_GAIN_FROM_BATTLE } from "#app/data/balance/starters"; import { StatusEffect } from "#enums/status-effect"; +import { globalScene, initGlobalScene } from "#app/global-scene"; export const bypassLogin = import.meta.env.VITE_BYPASS_LOGIN === "1"; @@ -329,6 +330,7 @@ export default class BattleScene extends SceneBase { this.nextCommandPhaseQueue = []; this.eventManager = new TimedEventManager(); this.updateGameInfo(); + initGlobalScene(this); } loadPokemonAtlas(key: string, atlasPath: string, experimental?: boolean) { @@ -374,14 +376,13 @@ export default class BattleScene extends SceneBase { async preload() { if (DEBUG_RNG) { - const scene = this; const originalRealInRange = Phaser.Math.RND.realInRange; Phaser.Math.RND.realInRange = function (min: number, max: number): number { const ret = originalRealInRange.apply(this, [ min, max ]); - const args = [ "RNG", ++scene.rngCounter, ret / (max - min), `min: ${min} / max: ${max}` ]; - args.push(`seed: ${scene.rngSeedOverride || scene.waveSeed || scene.seed}`); - if (scene.rngOffset) { - args.push(`offset: ${scene.rngOffset}`); + const args = [ "RNG", ++globalScene.rngCounter, ret / (max - min), `min: ${min} / max: ${max}` ]; + args.push(`seed: ${globalScene.rngSeedOverride || globalScene.waveSeed || globalScene.seed}`); + if (globalScene.rngOffset) { + args.push(`offset: ${globalScene.rngOffset}`); } console.log(...args); return ret; @@ -394,14 +395,14 @@ export default class BattleScene extends SceneBase { } create() { - this.scene.remove(LoadingScene.KEY); + globalScene.scene.remove(LoadingScene.KEY); initGameSpeed.apply(this); - this.inputController = new InputsController(this); - this.uiInputs = new UiInputs(this, this.inputController); + this.inputController = new InputsController(); + this.uiInputs = new UiInputs(this.inputController); - this.gameData = new GameData(this); + this.gameData = new GameData(); - addUiThemeOverrides(this); + addUiThemeOverrides(); this.load.setBaseURL(); @@ -488,76 +489,76 @@ export default class BattleScene extends SceneBase { this.modifiers = []; this.enemyModifiers = []; - this.modifierBar = new ModifierBar(this); + this.modifierBar = new ModifierBar(); this.modifierBar.setName("modifier-bar"); this.add.existing(this.modifierBar); uiContainer.add(this.modifierBar); - this.enemyModifierBar = new ModifierBar(this, true); + this.enemyModifierBar = new ModifierBar(true); this.enemyModifierBar.setName("enemy-modifier-bar"); this.add.existing(this.enemyModifierBar); uiContainer.add(this.enemyModifierBar); - this.charSprite = new CharSprite(this); + this.charSprite = new CharSprite(); this.charSprite.setName("sprite-char"); this.charSprite.setup(); this.fieldUI.add(this.charSprite); - this.pbTray = new PokeballTray(this, true); + this.pbTray = new PokeballTray(true); this.pbTray.setName("pb-tray"); this.pbTray.setup(); - this.pbTrayEnemy = new PokeballTray(this, false); + this.pbTrayEnemy = new PokeballTray(false); this.pbTrayEnemy.setName("enemy-pb-tray"); this.pbTrayEnemy.setup(); this.fieldUI.add(this.pbTray); this.fieldUI.add(this.pbTrayEnemy); - this.abilityBar = new AbilityBar(this); + this.abilityBar = new AbilityBar(); this.abilityBar.setName("ability-bar"); this.abilityBar.setup(); this.fieldUI.add(this.abilityBar); - this.partyExpBar = new PartyExpBar(this); + this.partyExpBar = new PartyExpBar(); this.partyExpBar.setName("party-exp-bar"); this.partyExpBar.setup(); this.fieldUI.add(this.partyExpBar); - this.candyBar = new CandyBar(this); + this.candyBar = new CandyBar(); this.candyBar.setName("candy-bar"); this.candyBar.setup(); this.fieldUI.add(this.candyBar); - this.biomeWaveText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, startingWave.toString(), TextStyle.BATTLE_INFO); + this.biomeWaveText = addTextObject((this.game.canvas.width / 6) - 2, 0, startingWave.toString(), TextStyle.BATTLE_INFO); this.biomeWaveText.setName("text-biome-wave"); this.biomeWaveText.setOrigin(1, 0.5); this.fieldUI.add(this.biomeWaveText); - this.moneyText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, "", TextStyle.MONEY); + this.moneyText = addTextObject((this.game.canvas.width / 6) - 2, 0, "", TextStyle.MONEY); this.moneyText.setName("text-money"); this.moneyText.setOrigin(1, 0.5); this.fieldUI.add(this.moneyText); - this.scoreText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, "", TextStyle.PARTY, { fontSize: "54px" }); + this.scoreText = addTextObject((this.game.canvas.width / 6) - 2, 0, "", TextStyle.PARTY, { fontSize: "54px" }); this.scoreText.setName("text-score"); this.scoreText.setOrigin(1, 0.5); this.fieldUI.add(this.scoreText); - this.luckText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, "", TextStyle.PARTY, { fontSize: "54px" }); + this.luckText = addTextObject((this.game.canvas.width / 6) - 2, 0, "", TextStyle.PARTY, { fontSize: "54px" }); this.luckText.setName("text-luck"); this.luckText.setOrigin(1, 0.5); this.luckText.setVisible(false); this.fieldUI.add(this.luckText); - this.luckLabelText = addTextObject(this, (this.game.canvas.width / 6) - 2, 0, i18next.t("common:luckIndicator"), TextStyle.PARTY, { fontSize: "54px" }); + this.luckLabelText = addTextObject((this.game.canvas.width / 6) - 2, 0, i18next.t("common:luckIndicator"), TextStyle.PARTY, { fontSize: "54px" }); this.luckLabelText.setName("text-luck-label"); this.luckLabelText.setOrigin(1, 0.5); this.luckLabelText.setVisible(false); this.fieldUI.add(this.luckLabelText); - this.arenaFlyout = new ArenaFlyout(this); + this.arenaFlyout = new ArenaFlyout(); this.fieldUI.add(this.arenaFlyout); this.fieldUI.moveBelow(this.arenaFlyout, this.fieldOverlay); @@ -566,9 +567,9 @@ export default class BattleScene extends SceneBase { this.damageNumberHandler = new DamageNumberHandler(); this.spriteSparkleHandler = new PokemonSpriteSparkleHandler(); - this.spriteSparkleHandler.setup(this); + this.spriteSparkleHandler.setup(); - this.pokemonInfoContainer = new PokemonInfoContainer(this, (this.game.canvas.width / 6) + 52, -(this.game.canvas.height / 6) + 66); + this.pokemonInfoContainer = new PokemonInfoContainer((this.game.canvas.width / 6) + 52, -(this.game.canvas.height / 6) + 66); this.pokemonInfoContainer.setup(); this.fieldUI.add(this.pokemonInfoContainer); @@ -577,13 +578,13 @@ export default class BattleScene extends SceneBase { const loadPokemonAssets = []; - this.arenaPlayer = new ArenaBase(this, true); + this.arenaPlayer = new ArenaBase(true); this.arenaPlayer.setName("arena-player"); - this.arenaPlayerTransition = new ArenaBase(this, true); + this.arenaPlayerTransition = new ArenaBase(true); this.arenaPlayerTransition.setName("arena-player-transition"); - this.arenaEnemy = new ArenaBase(this, false); + this.arenaEnemy = new ArenaBase(false); this.arenaEnemy.setName("arena-enemy"); - this.arenaNextEnemy = new ArenaBase(this, false); + this.arenaNextEnemy = new ArenaBase(false); this.arenaNextEnemy.setName("arena-next-enemy"); this.arenaBgTransition.setVisible(false); @@ -624,7 +625,7 @@ export default class BattleScene extends SceneBase { this.reset(false, false, true); - const ui = new UI(this); + const ui = new UI(); this.uiContainer.add(ui); this.ui = ui; @@ -635,12 +636,12 @@ export default class BattleScene extends SceneBase { Promise.all([ Promise.all(loadPokemonAssets), - initCommonAnims(this).then(() => loadCommonAnimAssets(this, true)), - Promise.all([ Moves.TACKLE, Moves.TAIL_WHIP, Moves.FOCUS_ENERGY, Moves.STRUGGLE ].map(m => initMoveAnim(this, m))).then(() => loadMoveAnimAssets(this, defaultMoves, true)), + initCommonAnims().then(() => loadCommonAnimAssets(true)), + Promise.all([ Moves.TACKLE, Moves.TAIL_WHIP, Moves.FOCUS_ENERGY, Moves.STRUGGLE ].map(m => initMoveAnim(m))).then(() => loadMoveAnimAssets(defaultMoves, true)), this.initStarterColors() ]).then(() => { - this.pushPhase(new LoginPhase(this)); - this.pushPhase(new TitlePhase(this)); + this.pushPhase(new LoginPhase()); + this.pushPhase(new TitlePhase()); this.shiftPhase(); }); @@ -910,7 +911,7 @@ export default class BattleScene extends SceneBase { } addPlayerPokemon(species: PokemonSpecies, level: integer, abilityIndex?: integer, formIndex?: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData, postProcess?: (playerPokemon: PlayerPokemon) => void): PlayerPokemon { - const pokemon = new PlayerPokemon(this, species, level, abilityIndex, formIndex, gender, shiny, variant, ivs, nature, dataSource); + const pokemon = new PlayerPokemon(species, level, abilityIndex, formIndex, gender, shiny, variant, ivs, nature, dataSource); if (postProcess) { postProcess(pokemon); } @@ -928,7 +929,7 @@ export default class BattleScene extends SceneBase { boss = this.getEncounterBossSegments(this.currentBattle.waveIndex, level, species) > 1; } - const pokemon = new EnemyPokemon(this, species, level, trainerSlot, boss, shinyLock, dataSource); + const pokemon = new EnemyPokemon(species, level, trainerSlot, boss, shinyLock, dataSource); if (Overrides.OPP_FUSION_OVERRIDE) { pokemon.generateFusionSpecies(); } @@ -1063,7 +1064,7 @@ export default class BattleScene extends SceneBase { /** * Generates a random number using the current battle's seed * - * This calls {@linkcode Battle.randSeedInt}(`scene`, {@linkcode range}, {@linkcode min}) in `src/battle.ts` + * This calls {@linkcode Battle.randSeedInt}({@linkcode range}, {@linkcode min}) in `src/battle.ts` * which calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` * * @param range How large of a range of random numbers to choose from. If {@linkcode range} <= 1, returns {@linkcode min} @@ -1071,12 +1072,12 @@ export default class BattleScene extends SceneBase { * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) */ randBattleSeedInt(range: integer, min: integer = 0): integer { - return this.currentBattle?.randSeedInt(this, range, min); + return this.currentBattle?.randSeedInt(range, min); } reset(clearScene: boolean = false, clearData: boolean = false, reloadI18n: boolean = false): void { if (clearData) { - this.gameData = new GameData(this); + this.gameData = new GameData(); } this.gameMode = getGameMode(GameModes.CLASSIC); @@ -1209,7 +1210,7 @@ export default class BattleScene extends SceneBase { battleConfig = this.gameMode.getFixedBattle(newWaveIndex); newDouble = battleConfig.double; newBattleType = battleConfig.battleType; - this.executeWithSeedOffset(() => newTrainer = battleConfig?.getTrainer(this), (battleConfig.seedOffsetWaveIndex || newWaveIndex) << 8); + this.executeWithSeedOffset(() => newTrainer = battleConfig?.getTrainer(), (battleConfig.seedOffsetWaveIndex || newWaveIndex) << 8); if (newTrainer) { this.field.add(newTrainer); } @@ -1235,7 +1236,7 @@ export default class BattleScene extends SceneBase { } } const variant = doubleTrainer ? TrainerVariant.DOUBLE : (Utils.randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT); - newTrainer = trainerData !== undefined ? trainerData.toTrainer(this) : new Trainer(this, trainerType, variant); + newTrainer = trainerData !== undefined ? trainerData.toTrainer() : new Trainer(trainerType, variant); this.field.add(newTrainer); } @@ -1313,7 +1314,7 @@ export default class BattleScene extends SceneBase { this.executeWithSeedOffset(() => { this.currentBattle = new Battle(this.gameMode, newWaveIndex, newBattleType, newTrainer, newDouble); }, newWaveIndex << 3, this.waveSeed); - this.currentBattle.incrementTurn(this); + this.currentBattle.incrementTurn(); if (newBattleType === BattleType.MYSTERY_ENCOUNTER) { // Will generate the actual Mystery Encounter during NextEncounterPhase, to ensure it uses proper biome @@ -1341,7 +1342,7 @@ export default class BattleScene extends SceneBase { playerField.forEach((pokemon, p) => { if (pokemon.isOnField()) { - this.pushPhase(new ReturnPhase(this, p)); + this.pushPhase(new ReturnPhase(p)); } }); @@ -1351,7 +1352,7 @@ export default class BattleScene extends SceneBase { } if (!this.trainer.visible) { - this.pushPhase(new ShowTrainerPhase(this)); + this.pushPhase(new ShowTrainerPhase()); } } @@ -1360,14 +1361,14 @@ export default class BattleScene extends SceneBase { } if (!this.gameMode.hasRandomBiomes && !isNewBiome) { - this.pushPhase(new NextEncounterPhase(this)); + this.pushPhase(new NextEncounterPhase()); } else { - this.pushPhase(new SelectBiomePhase(this)); - this.pushPhase(new NewBiomeEncounterPhase(this)); + this.pushPhase(new SelectBiomePhase()); + this.pushPhase(new NewBiomeEncounterPhase()); const newMaxExpLevel = this.getMaxExpLevel(); if (newMaxExpLevel > maxExpLevel) { - this.pushPhase(new LevelCapPhase(this)); + this.pushPhase(new LevelCapPhase()); } } } @@ -1376,7 +1377,7 @@ export default class BattleScene extends SceneBase { } newArena(biome: Biome): Arena { - this.arena = new Arena(this, biome, Biome[biome].toLowerCase()); + this.arena = new Arena(biome, Biome[biome].toLowerCase()); this.eventTarget.dispatchEvent(new NewArenaEvent()); this.arenaBg.pipelineData = { terrainColorRatio: this.arena.getBgTerrainColorRatioForBiome() }; @@ -1790,7 +1791,7 @@ export default class BattleScene extends SceneBase { } updateUIPositions(): void { - const enemyModifierCount = this.enemyModifiers.filter(m => m.isIconVisible(this)).length; + const enemyModifierCount = this.enemyModifiers.filter(m => m.isIconVisible()).length; const biomeWaveTextHeight = this.biomeWaveText.getBottomLeft().y - this.biomeWaveText.getTopLeft().y; this.biomeWaveText.setY( -(this.game.canvas.height / 6) + (enemyModifierCount ? enemyModifierCount <= 12 ? 15 : 24 : 0) + (biomeWaveTextHeight / 2) @@ -1877,7 +1878,7 @@ export default class BattleScene extends SceneBase { playBgm(bgmName?: string, fadeOut?: boolean): void { if (bgmName === undefined) { - bgmName = this.currentBattle?.getBgmOverride(this) || this.arena?.bgm; + bgmName = this.currentBattle?.getBgmOverride() || this.arena?.bgm; } if (this.bgm && bgmName === this.bgm.key) { if (!this.bgm.isPlaying) { @@ -2496,7 +2497,7 @@ export default class BattleScene extends SceneBase { * @param defer boolean for which queue to add it to, false -> add to PhaseQueuePrepend, true -> nextCommandPhaseQueue */ queueMessage(message: string, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null, defer?: boolean | null) { - const phase = new MessagePhase(this, message, callbackDelay, prompt, promptDelay); + const phase = new MessagePhase(message, callbackDelay, prompt, promptDelay); if (!defer) { // adds to the end of PhaseQueuePrepend this.unshiftPhase(phase); @@ -2514,7 +2515,7 @@ export default class BattleScene extends SceneBase { this.phaseQueue.push(...this.nextCommandPhaseQueue); this.nextCommandPhaseQueue.splice(0, this.nextCommandPhaseQueue.length); } - this.phaseQueue.push(new TurnInitPhase(this)); + this.phaseQueue.push(new TurnInitPhase()); } addMoney(amount: integer): void { @@ -2545,7 +2546,7 @@ export default class BattleScene extends SceneBase { if (modifier instanceof TerastallizeModifier) { modifiersToRemove.push(...(this.findModifiers(m => m instanceof TerastallizeModifier && m.pokemonId === modifier.pokemonId))); } - if ((modifier as PersistentModifier).add(this.modifiers, !!virtual, this)) { + if ((modifier as PersistentModifier).add(this.modifiers, !!virtual)) { if (modifier instanceof PokemonFormChangeItemModifier || modifier instanceof TerastallizeModifier) { const pokemon = this.getPokemonById(modifier.pokemonId); if (pokemon) { @@ -2626,7 +2627,7 @@ export default class BattleScene extends SceneBase { if (modifier instanceof TerastallizeModifier) { modifiersToRemove.push(...(this.findModifiers(m => m instanceof TerastallizeModifier && m.pokemonId === modifier.pokemonId, false))); } - if ((modifier as PersistentModifier).add(this.enemyModifiers, false, this)) { + if ((modifier as PersistentModifier).add(this.enemyModifiers, false)) { if (modifier instanceof PokemonFormChangeItemModifier || modifier instanceof TerastallizeModifier) { const pokemon = this.getPokemonById(modifier.pokemonId); if (pokemon) { @@ -2661,7 +2662,7 @@ export default class BattleScene extends SceneBase { */ tryTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, playSound: boolean, transferQuantity: number = 1, instant?: boolean, ignoreUpdate?: boolean, itemLost: boolean = true): Promise { return new Promise(resolve => { - const source = itemModifier.pokemonId ? itemModifier.getPokemon(target.scene) : null; + const source = itemModifier.pokemonId ? itemModifier.getPokemon() : null; const cancelled = new Utils.BooleanHolder(false); Utils.executeIf(!!source && source.isPlayer() !== target.isPlayer(), () => applyAbAttrs(BlockItemTheftAbAttr, source! /* checked in condition*/, cancelled)).then(() => { if (cancelled.value) { @@ -2669,11 +2670,11 @@ export default class BattleScene extends SceneBase { } const newItemModifier = itemModifier.clone() as PokemonHeldItemModifier; newItemModifier.pokemonId = target.id; - const matchingModifier = target.scene.findModifier(m => m instanceof PokemonHeldItemModifier + const matchingModifier = this.findModifier(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).matchType(itemModifier) && m.pokemonId === target.id, target.isPlayer()) as PokemonHeldItemModifier; let removeOld = true; if (matchingModifier) { - const maxStackCount = matchingModifier.getMaxStackCount(target.scene); + const maxStackCount = matchingModifier.getMaxStackCount(); if (matchingModifier.stackCount >= maxStackCount) { return resolve(false); } @@ -2790,7 +2791,7 @@ export default class BattleScene extends SceneBase { count = Math.max(count, Math.floor(chances / 2)); } getEnemyModifierTypesForWave(difficultyWaveIndex, count, [ enemyPokemon ], this.currentBattle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD, upgradeChance) - .map(mt => mt.newModifier(enemyPokemon).add(this.enemyModifiers, false, this)); + .map(mt => mt.newModifier(enemyPokemon).add(this.enemyModifiers, false)); } return true; }); @@ -2814,7 +2815,7 @@ export default class BattleScene extends SceneBase { * @param pokemon - If specified, only removes held items from that {@linkcode Pokemon} */ clearEnemyHeldItemModifiers(pokemon?: Pokemon): void { - const modifiersToRemove = this.enemyModifiers.filter(m => m instanceof PokemonHeldItemModifier && (!pokemon || m.getPokemon(this) === pokemon)); + const modifiersToRemove = this.enemyModifiers.filter(m => m instanceof PokemonHeldItemModifier && (!pokemon || m.getPokemon() === pokemon)); for (const m of modifiersToRemove) { this.enemyModifiers.splice(this.enemyModifiers.indexOf(m), 1); } @@ -2863,9 +2864,7 @@ export default class BattleScene extends SceneBase { updatePartyForModifiers(party: Pokemon[], instant?: boolean): Promise { return new Promise(resolve => { Promise.allSettled(party.map(p => { - if (p.scene) { - p.calculateStats(); - } + p.calculateStats(); return p.updateInfo(instant); })).then(() => resolve()); }); @@ -2928,15 +2927,14 @@ export default class BattleScene extends SceneBase { /** * Apply all modifiers that match `modifierType` in a random order - * @param scene {@linkcode BattleScene} used to randomize the order of modifiers * @param modifierType The type of modifier to apply; must extend {@linkcode PersistentModifier} * @param player Whether to search the player (`true`) or the enemy (`false`); Defaults to `true` * @param ...args The list of arguments needed to invoke `modifierType.apply` * @returns the list of all modifiers that matched `modifierType` and were applied. */ - applyShuffledModifiers(scene: BattleScene, modifierType: Constructor, player: boolean = true, ...args: Parameters): T[] { + applyShuffledModifiers(modifierType: Constructor, player: boolean = true, ...args: Parameters): T[] { let modifiers = (player ? this.modifiers : this.enemyModifiers).filter((m): m is T => m instanceof modifierType && m.shouldApply(...args)); - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const shuffleModifiers = mods => { if (mods.length < 1) { return mods; @@ -2945,7 +2943,7 @@ export default class BattleScene extends SceneBase { return [ mods[rand], ...shuffleModifiers(mods.filter((_, i) => i !== rand)) ]; }; modifiers = shuffleModifiers(modifiers); - }, scene.currentBattle.turn << 4, scene.waveSeed); + }, globalScene.currentBattle.turn << 4, globalScene.waveSeed); return this.applyModifiersInternal(modifiers, player, args); } @@ -3015,9 +3013,9 @@ export default class BattleScene extends SceneBase { if (matchingFormChange) { let phase: Phase; if (pokemon instanceof PlayerPokemon && !matchingFormChange.quiet) { - phase = new FormChangePhase(this, pokemon, matchingFormChange, modal); + phase = new FormChangePhase(pokemon, matchingFormChange, modal); } else { - phase = new QuietFormChangePhase(this, pokemon, matchingFormChange); + phase = new QuietFormChangePhase(pokemon, matchingFormChange); } if (pokemon instanceof PlayerPokemon && !matchingFormChange.quiet && modal) { this.overridePhase(phase); @@ -3034,7 +3032,7 @@ export default class BattleScene extends SceneBase { } triggerPokemonBattleAnim(pokemon: Pokemon, battleAnimType: PokemonAnimType, fieldAssets?: Phaser.GameObjects.Sprite[], delayed: boolean = false): boolean { - const phase: Phase = new PokemonAnimPhase(this, battleAnimType, pokemon, fieldAssets); + const phase: Phase = new PokemonAnimPhase(battleAnimType, pokemon, fieldAssets); if (delayed) { this.pushPhase(phase); } else { @@ -3052,7 +3050,7 @@ export default class BattleScene extends SceneBase { validateAchv(achv: Achv, args?: unknown[]): boolean { if ((!this.gameData.achvUnlocks.hasOwnProperty(achv.id) || Overrides.ACHIEVEMENTS_REUNLOCK_OVERRIDE) - && achv.validate(this, args)) { + && achv.validate(args)) { this.gameData.achvUnlocks[achv.id] = new Date().getTime(); this.ui.achvBar.showAchv(achv); if (vouchers.hasOwnProperty(achv.id)) { @@ -3065,7 +3063,7 @@ export default class BattleScene extends SceneBase { } validateVoucher(voucher: Voucher, args?: unknown[]): boolean { - if (!this.gameData.voucherUnlocks.hasOwnProperty(voucher.id) && voucher.validate(this, args)) { + if (!this.gameData.voucherUnlocks.hasOwnProperty(voucher.id) && voucher.validate(args)) { this.gameData.voucherUnlocks[voucher.id] = new Date().getTime(); this.ui.achvBar.showAchv(voucher); this.gameData.voucherCounts[voucher.voucherType]++; @@ -3138,9 +3136,9 @@ export default class BattleScene extends SceneBase { this.currentBattle.double = true; const availablePartyMembers = this.getPlayerParty().filter((p) => p.isAllowedInBattle()); if (availablePartyMembers.length > 1) { - this.pushPhase(new ToggleDoublePositionPhase(this, true)); + this.pushPhase(new ToggleDoublePositionPhase(true)); if (!availablePartyMembers[1].isOnField()) { - this.pushPhase(new SummonPhase(this, 1)); + this.pushPhase(new SummonPhase(1)); } } @@ -3185,7 +3183,7 @@ export default class BattleScene extends SceneBase { if (participated && pokemonDefeated) { partyMember.addFriendship(FRIENDSHIP_GAIN_FROM_BATTLE); const machoBraceModifier = partyMember.getHeldItems().find(m => m instanceof PokemonIncrementingStatModifier); - if (machoBraceModifier && machoBraceModifier.stackCount < machoBraceModifier.getMaxStackCount(this)) { + if (machoBraceModifier && machoBraceModifier.stackCount < machoBraceModifier.getMaxStackCount()) { machoBraceModifier.stackCount++; this.updateModifiers(true, true); partyMember.updateInfo(); @@ -3247,7 +3245,7 @@ export default class BattleScene extends SceneBase { if (exp) { const partyMemberIndex = party.indexOf(expPartyMembers[pm]); - this.unshiftPhase(expPartyMembers[pm].isOnField() ? new ExpPhase(this, partyMemberIndex, exp) : new ShowPartyExpBarPhase(this, partyMemberIndex, exp)); + this.unshiftPhase(expPartyMembers[pm].isOnField() ? new ExpPhase(partyMemberIndex, exp) : new ShowPartyExpBarPhase(partyMemberIndex, exp)); } } } @@ -3339,7 +3337,7 @@ export default class BattleScene extends SceneBase { if (encounter) { encounter = new MysteryEncounter(encounter); - encounter.populateDialogueTokensFromRequirements(this); + encounter.populateDialogueTokensFromRequirements(); return encounter; } @@ -3367,8 +3365,9 @@ export default class BattleScene extends SceneBase { } let availableEncounters: MysteryEncounter[] = []; - // New encounter should never be the same as the most recent encounter - const previousEncounter = this.mysteryEncounterSaveData.encounteredEvents.length > 0 ? this.mysteryEncounterSaveData.encounteredEvents[this.mysteryEncounterSaveData.encounteredEvents.length - 1].type : null; + const previousEncounter = this.mysteryEncounterSaveData.encounteredEvents.length > 0 ? + this.mysteryEncounterSaveData.encounteredEvents[this.mysteryEncounterSaveData.encounteredEvents.length - 1].type + : null; const biomeMysteryEncounters = mysteryEncountersByBiome.get(this.arena.biomeType) ?? []; // If no valid encounters exist at tier, checks next tier down, continuing until there are some encounters available while (availableEncounters.length === 0 && tier !== null) { @@ -3378,27 +3377,27 @@ export default class BattleScene extends SceneBase { if (!encounterCandidate) { return false; } - if (encounterCandidate.encounterTier !== tier) { // Encounter is in tier + if (encounterCandidate.encounterTier !== tier) { return false; } const disallowedGameModes = encounterCandidate.disallowedGameModes; if (disallowedGameModes && disallowedGameModes.length > 0 - && disallowedGameModes.includes(this.gameMode.modeId)) { // Encounter is enabled for game mode + && disallowedGameModes.includes(this.gameMode.modeId)) { return false; } - if (this.gameMode.modeId === GameModes.CHALLENGE) { // Encounter is enabled for challenges + if (this.gameMode.modeId === GameModes.CHALLENGE) { const disallowedChallenges = encounterCandidate.disallowedChallenges; if (disallowedChallenges && disallowedChallenges.length > 0 && this.gameMode.challenges.some(challenge => disallowedChallenges.includes(challenge.id))) { return false; } } - if (!encounterCandidate.meetsRequirements(this)) { // Meets encounter requirements + if (!encounterCandidate.meetsRequirements()) { return false; } - if (previousEncounter !== null && encounterType === previousEncounter) { // Previous encounter was not this one + if (previousEncounter !== null && encounterType === previousEncounter) { return false; } - if (this.mysteryEncounterSaveData.encounteredEvents.length > 0 && // Encounter has not exceeded max allowed encounters + if (this.mysteryEncounterSaveData.encounteredEvents.length > 0 && (encounterCandidate.maxAllowedEncounters && encounterCandidate.maxAllowedEncounters > 0) && this.mysteryEncounterSaveData.encounteredEvents.filter(e => e.type === encounterType).length >= encounterCandidate.maxAllowedEncounters) { return false; @@ -3426,7 +3425,7 @@ export default class BattleScene extends SceneBase { encounter = availableEncounters[Utils.randSeedInt(availableEncounters.length)]; // New encounter object to not dirty flags encounter = new MysteryEncounter(encounter); - encounter.populateDialogueTokensFromRequirements(this); + encounter.populateDialogueTokensFromRequirements(); return encounter; } } diff --git a/src/battle.ts b/src/battle.ts index 75f0dff25341..c0914ae5ec4a 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -1,4 +1,4 @@ -import BattleScene from "./battle-scene"; +import { globalScene } from "#app/global-scene"; import { Command } from "./ui/command-ui-handler"; import * as Utils from "./utils"; import Trainer, { TrainerVariant } from "./field/trainer"; @@ -154,7 +154,7 @@ export default class Battle { return this.double ? 2 : 1; } - incrementTurn(scene: BattleScene): void { + incrementTurn(): void { this.turn++; this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [ bt, null ])); this.battleSeedState = null; @@ -169,7 +169,7 @@ export default class Battle { } addPostBattleLoot(enemyPokemon: EnemyPokemon): void { - this.postBattleLoot.push(...enemyPokemon.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === enemyPokemon.id && m.isTransferable, false).map(i => { + this.postBattleLoot.push(...globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === enemyPokemon.id && m.isTransferable, false).map(i => { const ret = i as PokemonHeldItemModifier; //@ts-ignore - this is awful to fix/change ret.pokemonId = null; @@ -177,43 +177,43 @@ export default class Battle { })); } - pickUpScatteredMoney(scene: BattleScene): void { - const moneyAmount = new Utils.IntegerHolder(scene.currentBattle.moneyScattered); - scene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); + pickUpScatteredMoney(): void { + const moneyAmount = new Utils.IntegerHolder(globalScene.currentBattle.moneyScattered); + globalScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); - if (scene.arena.getTag(ArenaTagType.HAPPY_HOUR)) { + if (globalScene.arena.getTag(ArenaTagType.HAPPY_HOUR)) { moneyAmount.value *= 2; } - scene.addMoney(moneyAmount.value); + globalScene.addMoney(moneyAmount.value); const userLocale = navigator.language || "en-US"; const formattedMoneyAmount = moneyAmount.value.toLocaleString(userLocale); const message = i18next.t("battle:moneyPickedUp", { moneyAmount: formattedMoneyAmount }); - scene.queueMessage(message, undefined, true); + globalScene.queueMessage(message, undefined, true); - scene.currentBattle.moneyScattered = 0; + globalScene.currentBattle.moneyScattered = 0; } - addBattleScore(scene: BattleScene): void { - let partyMemberTurnMultiplier = scene.getEnemyParty().length / 2 + 0.5; + addBattleScore(): void { + let partyMemberTurnMultiplier = globalScene.getEnemyParty().length / 2 + 0.5; if (this.double) { partyMemberTurnMultiplier /= 1.5; } - for (const p of scene.getEnemyParty()) { + for (const p of globalScene.getEnemyParty()) { if (p.isBoss()) { - partyMemberTurnMultiplier *= (p.bossSegments / 1.5) / scene.getEnemyParty().length; + partyMemberTurnMultiplier *= (p.bossSegments / 1.5) / globalScene.getEnemyParty().length; } } const turnMultiplier = Phaser.Tweens.Builders.GetEaseFunction("Sine.easeIn")(1 - Math.min(this.turn - 2, 10 * partyMemberTurnMultiplier) / (10 * partyMemberTurnMultiplier)); const finalBattleScore = Math.ceil(this.battleScore * turnMultiplier); - scene.score += finalBattleScore; + globalScene.score += finalBattleScore; console.log(`Battle Score: ${finalBattleScore} (${this.turn - 1} Turns x${Math.floor(turnMultiplier * 100) / 100})`); - console.log(`Total Score: ${scene.score}`); - scene.updateScoreText(); + console.log(`Total Score: ${globalScene.score}`); + globalScene.updateScoreText(); } - getBgmOverride(scene: BattleScene): string | null { + getBgmOverride(): string | null { if (this.isBattleMysteryEncounter() && this.mysteryEncounter?.encounterMode === MysteryEncounterMode.DEFAULT) { // Music is overridden for MEs during ME onInit() // Should not use any BGM overrides before swapping from DEFAULT mode @@ -222,7 +222,7 @@ export default class Battle { if (!this.started && this.trainer?.config.encounterBgm && this.trainer?.getEncounterMessages()?.length) { return `encounter_${this.trainer?.getEncounterBgm()}`; } - if (scene.musicPreference === MusicPreference.CONSISTENT) { + if (globalScene.musicPreference === MusicPreference.CONSISTENT) { return this.trainer?.getBattleBgm() ?? null; } else { return this.trainer?.getMixedBattleBgm() ?? null; @@ -230,7 +230,7 @@ export default class Battle { } else if (this.gameMode.isClassic && this.waveIndex > 195 && this.battleSpec !== BattleSpec.FINAL_BOSS) { return "end_summit"; } - const wildOpponents = scene.getEnemyParty(); + const wildOpponents = globalScene.getEnemyParty(); for (const pokemon of wildOpponents) { if (this.battleSpec === BattleSpec.FINAL_BOSS) { if (pokemon.species.getFormSpriteKey(pokemon.formIndex) === SpeciesFormKey.ETERNAMAX) { @@ -239,7 +239,7 @@ export default class Battle { return "battle_final_encounter"; } if (pokemon.species.legendary || pokemon.species.subLegendary || pokemon.species.mythical) { - if (scene.musicPreference === MusicPreference.CONSISTENT) { + if (globalScene.musicPreference === MusicPreference.CONSISTENT) { switch (pokemon.species.speciesId) { case Species.REGIROCK: case Species.REGICE: @@ -256,7 +256,7 @@ export default class Battle { } return "battle_legendary_unova"; } - } else if (scene.musicPreference === MusicPreference.MIXED) { + } else if (globalScene.musicPreference === MusicPreference.MIXED) { switch (pokemon.species.speciesId) { case Species.ARTICUNO: case Species.ZAPDOS: @@ -396,7 +396,7 @@ export default class Battle { } } - if (scene.gameMode.isClassic && this.waveIndex <= 4) { + if (globalScene.gameMode.isClassic && this.waveIndex <= 4) { return "battle_wild"; } @@ -409,12 +409,12 @@ export default class Battle { * @param min The minimum integer to pick, default `0` * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) */ - randSeedInt(scene: BattleScene, range: number, min: number = 0): number { + randSeedInt(range: number, min: number = 0): number { if (range <= 1) { return min; } - const tempRngCounter = scene.rngCounter; - const tempSeedOverride = scene.rngSeedOverride; + const tempRngCounter = globalScene.rngCounter; + const tempSeedOverride = globalScene.rngSeedOverride; const state = Phaser.Math.RND.state(); if (this.battleSeedState) { Phaser.Math.RND.state(this.battleSeedState); @@ -422,13 +422,13 @@ export default class Battle { Phaser.Math.RND.sow([ Utils.shiftCharCodes(this.battleSeed, this.turn << 6) ]); console.log("Battle Seed:", this.battleSeed); } - scene.rngCounter = this.rngCounter++; - scene.rngSeedOverride = this.battleSeed; + globalScene.rngCounter = this.rngCounter++; + globalScene.rngSeedOverride = this.battleSeed; const ret = Utils.randSeedInt(range, min); this.battleSeedState = Phaser.Math.RND.state(); Phaser.Math.RND.state(state); - scene.rngCounter = tempRngCounter; - scene.rngSeedOverride = tempSeedOverride; + globalScene.rngCounter = tempRngCounter; + globalScene.rngSeedOverride = tempSeedOverride; return ret; } @@ -441,16 +441,16 @@ export default class Battle { } export class FixedBattle extends Battle { - constructor(scene: BattleScene, waveIndex: number, config: FixedBattleConfig) { - super(scene.gameMode, waveIndex, config.battleType, config.battleType === BattleType.TRAINER ? config.getTrainer(scene) : undefined, config.double); + constructor(waveIndex: number, config: FixedBattleConfig) { + super(globalScene.gameMode, waveIndex, config.battleType, config.battleType === BattleType.TRAINER ? config.getTrainer() : undefined, config.double); if (config.getEnemyParty) { - this.enemyParty = config.getEnemyParty(scene); + this.enemyParty = config.getEnemyParty(); } } } -type GetTrainerFunc = (scene: BattleScene) => Trainer; -type GetEnemyPartyFunc = (scene: BattleScene) => EnemyPokemon[]; +type GetTrainerFunc = () => Trainer; +type GetEnemyPartyFunc = () => EnemyPokemon[]; export class FixedBattleConfig { public battleType: BattleType; @@ -500,11 +500,11 @@ export class FixedBattleConfig { * @returns the generated trainer */ function getRandomTrainerFunc(trainerPool: (TrainerType | TrainerType[])[], randomGender: boolean = false, seedOffset: number = 0): GetTrainerFunc { - return (scene: BattleScene) => { + return () => { const rand = Utils.randSeedInt(trainerPool.length); const trainerTypes: TrainerType[] = []; - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { for (const trainerPoolEntry of trainerPool) { const trainerType = Array.isArray(trainerPoolEntry) ? Utils.randSeedItem(trainerPoolEntry) @@ -523,10 +523,10 @@ function getRandomTrainerFunc(trainerPool: (TrainerType | TrainerType[])[], rand const isEvilTeamGrunt = evilTeamGrunts.includes(trainerTypes[rand]); if (trainerConfigs[trainerTypes[rand]].hasDouble && isEvilTeamGrunt) { - return new Trainer(scene, trainerTypes[rand], (Utils.randInt(3) === 0) ? TrainerVariant.DOUBLE : trainerGender); + return new Trainer(trainerTypes[rand], (Utils.randInt(3) === 0) ? TrainerVariant.DOUBLE : trainerGender); } - return new Trainer(scene, trainerTypes[rand], trainerGender); + return new Trainer(trainerTypes[rand], trainerGender); }; } @@ -544,16 +544,16 @@ export interface FixedBattleConfigs { */ export const classicFixedBattles: FixedBattleConfigs = { [5]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) - .setGetTrainerFunc(scene => new Trainer(scene, TrainerType.YOUNGSTER, Utils.randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)), + .setGetTrainerFunc(() => new Trainer(TrainerType.YOUNGSTER, Utils.randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)), [8]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) - .setGetTrainerFunc(scene => new Trainer(scene, TrainerType.RIVAL, scene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)), + .setGetTrainerFunc(() => new Trainer(TrainerType.RIVAL, globalScene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)), [25]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) - .setGetTrainerFunc(scene => new Trainer(scene, TrainerType.RIVAL_2, scene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) + .setGetTrainerFunc(() => new Trainer(TrainerType.RIVAL_2, globalScene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) .setCustomModifierRewards({ guaranteedModifierTiers: [ ModifierTier.ULTRA, ModifierTier.GREAT, ModifierTier.GREAT ], allowLuckUpgrades: false }), [35]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) .setGetTrainerFunc(getRandomTrainerFunc([ TrainerType.ROCKET_GRUNT, TrainerType.MAGMA_GRUNT, TrainerType.AQUA_GRUNT, TrainerType.GALACTIC_GRUNT, TrainerType.PLASMA_GRUNT, TrainerType.FLARE_GRUNT, TrainerType.AETHER_GRUNT, TrainerType.SKULL_GRUNT, TrainerType.MACRO_GRUNT, TrainerType.STAR_GRUNT ], true)), [55]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) - .setGetTrainerFunc(scene => new Trainer(scene, TrainerType.RIVAL_3, scene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) + .setGetTrainerFunc(() => new Trainer(TrainerType.RIVAL_3, globalScene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) .setCustomModifierRewards({ guaranteedModifierTiers: [ ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.GREAT, ModifierTier.GREAT ], allowLuckUpgrades: false }), [62]: new FixedBattleConfig().setBattleType(BattleType.TRAINER).setSeedOffsetWave(35) .setGetTrainerFunc(getRandomTrainerFunc([ TrainerType.ROCKET_GRUNT, TrainerType.MAGMA_GRUNT, TrainerType.AQUA_GRUNT, TrainerType.GALACTIC_GRUNT, TrainerType.PLASMA_GRUNT, TrainerType.FLARE_GRUNT, TrainerType.AETHER_GRUNT, TrainerType.SKULL_GRUNT, TrainerType.MACRO_GRUNT, TrainerType.STAR_GRUNT ], true)), @@ -562,7 +562,7 @@ export const classicFixedBattles: FixedBattleConfigs = { [66]: new FixedBattleConfig().setBattleType(BattleType.TRAINER).setSeedOffsetWave(35) .setGetTrainerFunc(getRandomTrainerFunc([[ TrainerType.ARCHER, TrainerType.ARIANA, TrainerType.PROTON, TrainerType.PETREL ], [ TrainerType.TABITHA, TrainerType.COURTNEY ], [ TrainerType.MATT, TrainerType.SHELLY ], [ TrainerType.JUPITER, TrainerType.MARS, TrainerType.SATURN ], [ TrainerType.ZINZOLIN, TrainerType.ROOD ], [ TrainerType.XEROSIC, TrainerType.BRYONY ], TrainerType.FABA, TrainerType.PLUMERIA, TrainerType.OLEANA, [ TrainerType.GIACOMO, TrainerType.MELA, TrainerType.ATTICUS, TrainerType.ORTEGA, TrainerType.ERI ]], true)), [95]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) - .setGetTrainerFunc(scene => new Trainer(scene, TrainerType.RIVAL_4, scene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) + .setGetTrainerFunc(() => new Trainer(TrainerType.RIVAL_4, globalScene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) .setCustomModifierRewards({ guaranteedModifierTiers: [ ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.ULTRA ], allowLuckUpgrades: false }), [112]: new FixedBattleConfig().setBattleType(BattleType.TRAINER).setSeedOffsetWave(35) .setGetTrainerFunc(getRandomTrainerFunc([ TrainerType.ROCKET_GRUNT, TrainerType.MAGMA_GRUNT, TrainerType.AQUA_GRUNT, TrainerType.GALACTIC_GRUNT, TrainerType.PLASMA_GRUNT, TrainerType.FLARE_GRUNT, TrainerType.AETHER_GRUNT, TrainerType.SKULL_GRUNT, TrainerType.MACRO_GRUNT, TrainerType.STAR_GRUNT ], true)), @@ -572,7 +572,7 @@ export const classicFixedBattles: FixedBattleConfigs = { .setGetTrainerFunc(getRandomTrainerFunc([ TrainerType.ROCKET_BOSS_GIOVANNI_1, TrainerType.MAXIE, TrainerType.ARCHIE, TrainerType.CYRUS, TrainerType.GHETSIS, TrainerType.LYSANDRE, TrainerType.LUSAMINE, TrainerType.GUZMA, TrainerType.ROSE, TrainerType.PENNY ])) .setCustomModifierRewards({ guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.ULTRA ], allowLuckUpgrades: false }), [145]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) - .setGetTrainerFunc(scene => new Trainer(scene, TrainerType.RIVAL_5, scene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) + .setGetTrainerFunc(() => new Trainer(TrainerType.RIVAL_5, globalScene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) .setCustomModifierRewards({ guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.ULTRA ], allowLuckUpgrades: false }), [ClassicFixedBossWaves.EVIL_BOSS_2]: new FixedBattleConfig().setBattleType(BattleType.TRAINER).setSeedOffsetWave(35) .setGetTrainerFunc(getRandomTrainerFunc([ TrainerType.ROCKET_BOSS_GIOVANNI_2, TrainerType.MAXIE_2, TrainerType.ARCHIE_2, TrainerType.CYRUS_2, TrainerType.GHETSIS_2, TrainerType.LYSANDRE_2, TrainerType.LUSAMINE_2, TrainerType.GUZMA_2, TrainerType.ROSE_2, TrainerType.PENNY_2 ])) @@ -588,6 +588,6 @@ export const classicFixedBattles: FixedBattleConfigs = { [190]: new FixedBattleConfig().setBattleType(BattleType.TRAINER).setSeedOffsetWave(182) .setGetTrainerFunc(getRandomTrainerFunc([ TrainerType.BLUE, [ TrainerType.RED, TrainerType.LANCE_CHAMPION ], [ TrainerType.STEVEN, TrainerType.WALLACE ], TrainerType.CYNTHIA, [ TrainerType.ALDER, TrainerType.IRIS ], TrainerType.DIANTHA, TrainerType.HAU, TrainerType.LEON, [ TrainerType.GEETA, TrainerType.NEMONA ], TrainerType.KIERAN ])), [195]: new FixedBattleConfig().setBattleType(BattleType.TRAINER) - .setGetTrainerFunc(scene => new Trainer(scene, TrainerType.RIVAL_6, scene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) + .setGetTrainerFunc(() => new Trainer(TrainerType.RIVAL_6, globalScene.gameData.gender === PlayerGender.MALE ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT)) .setCustomModifierRewards({ guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.GREAT, ModifierTier.GREAT ], allowLuckUpgrades: false }) }; diff --git a/src/data/ability.ts b/src/data/ability.ts index 7fa046e2369e..37db29a006e8 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -28,7 +28,7 @@ import { MovePhase } from "#app/phases/move-phase"; import { PokemonHealPhase } from "#app/phases/pokemon-heal-phase"; import { ShowAbilityPhase } from "#app/phases/show-ability-phase"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { SwitchType } from "#app/enums/switch-type"; import { SwitchPhase } from "#app/phases/switch-phase"; import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; @@ -226,7 +226,7 @@ export class PostBattleInitFormChangeAbAttr extends PostBattleInitAbAttr { applyPostBattleInit(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const formIndex = this.formFunc(pokemon); if (formIndex !== pokemon.formIndex && !simulated) { - return pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); + return globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); } return false; @@ -251,18 +251,18 @@ export class PostBattleInitStatStageChangeAbAttr extends PostBattleInitAbAttr { if (!simulated) { if (this.selfTarget) { - statStageChangePhases.push(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.stages)); + statStageChangePhases.push(new StatStageChangePhase(pokemon.getBattlerIndex(), true, this.stats, this.stages)); } else { for (const opponent of pokemon.getOpponents()) { - statStageChangePhases.push(new StatStageChangePhase(pokemon.scene, opponent.getBattlerIndex(), false, this.stats, this.stages)); + statStageChangePhases.push(new StatStageChangePhase(opponent.getBattlerIndex(), false, this.stats, this.stages)); } } for (const statStageChangePhase of statStageChangePhases) { if (!this.selfTarget && !statStageChangePhase.getPokemon()?.summonData) { - pokemon.scene.pushPhase(statStageChangePhase); + globalScene.pushPhase(statStageChangePhase); } else { // TODO: This causes the ability bar to be shown at the wrong time - pokemon.scene.unshiftPhase(statStageChangePhase); + globalScene.unshiftPhase(statStageChangePhase); } } } @@ -447,7 +447,7 @@ export class TypeImmunityHealAbAttr extends TypeImmunityAbAttr { if (ret) { if (!pokemon.isFullHp() && !simulated) { const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; - pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), Utils.toDmgValue(pokemon.getMaxHp() / 4), i18next.t("abilityTriggers:typeImmunityHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); cancelled.value = true; // Suppresses "No Effect" message } @@ -475,7 +475,7 @@ class TypeImmunityStatStageChangeAbAttr extends TypeImmunityAbAttr { if (ret) { cancelled.value = true; // Suppresses "No Effect" message if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ this.stat ], this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ this.stat ], this.stages)); } } @@ -658,7 +658,7 @@ export class MoveImmunityStatStageChangeAbAttr extends MoveImmunityAbAttr { applyPreDefend(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): boolean { const ret = super.applyPreDefend(pokemon, passive, simulated, attacker, move, cancelled, args); if (ret && !simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ this.stat ], this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ this.stat ], this.stages)); } return ret; @@ -685,7 +685,7 @@ export class ReverseDrainAbAttr extends PostDefendAbAttr { override applyPostDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, _hitResult: HitResult, _args: any[]): boolean { if (move.hasAttr(HitHealAttr) && !move.hitsSubstitute(attacker, pokemon)) { if (!simulated) { - pokemon.scene.queueMessage(i18next.t("abilityTriggers:reverseDrain", { pokemonNameWithAffix: getPokemonNameWithAffix(attacker) })); + globalScene.queueMessage(i18next.t("abilityTriggers:reverseDrain", { pokemonNameWithAffix: getPokemonNameWithAffix(attacker) })); } return true; } @@ -719,11 +719,11 @@ export class PostDefendStatStageChangeAbAttr extends PostDefendAbAttr { if (this.allOthers) { const otherPokemon = pokemon.getAlly() ? pokemon.getOpponents().concat([ pokemon.getAlly() ]) : pokemon.getOpponents(); for (const other of otherPokemon) { - other.scene.unshiftPhase(new StatStageChangePhase(other.scene, (other).getBattlerIndex(), false, [ this.stat ], this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase((other).getBattlerIndex(), false, [ this.stat ], this.stages)); } return true; } - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, (this.selfTarget ? pokemon : attacker).getBattlerIndex(), this.selfTarget, [ this.stat ], this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase((this.selfTarget ? pokemon : attacker).getBattlerIndex(), this.selfTarget, [ this.stat ], this.stages)); return true; } @@ -755,7 +755,7 @@ export class PostDefendHpGatedStatStageChangeAbAttr extends PostDefendAbAttr { if (this.condition(pokemon, attacker, move) && (pokemon.hp <= hpGateFlat && (pokemon.hp + damageReceived) > hpGateFlat) && !move.hitsSubstitute(attacker, pokemon)) { if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, (this.selfTarget ? pokemon : attacker).getBattlerIndex(), true, this.stats, this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase((this.selfTarget ? pokemon : attacker).getBattlerIndex(), true, this.stats, this.stages)); } return true; } @@ -777,10 +777,10 @@ export class PostDefendApplyArenaTrapTagAbAttr extends PostDefendAbAttr { override applyPostDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, _hitResult: HitResult, _args: any[]): boolean { if (this.condition(pokemon, attacker, move) && !move.hitsSubstitute(attacker, pokemon)) { - const tag = pokemon.scene.arena.getTag(this.tagType) as ArenaTrapTag; - if (!pokemon.scene.arena.getTag(this.tagType) || tag.layers < tag.maxLayers) { + const tag = globalScene.arena.getTag(this.tagType) as ArenaTrapTag; + if (!globalScene.arena.getTag(this.tagType) || tag.layers < tag.maxLayers) { if (!simulated) { - pokemon.scene.arena.addTag(this.tagType, 0, undefined, pokemon.id, pokemon.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); + globalScene.arena.addTag(this.tagType, 0, undefined, pokemon.id, pokemon.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); } return true; } @@ -803,7 +803,7 @@ export class PostDefendApplyBattlerTagAbAttr extends PostDefendAbAttr { if (this.condition(pokemon, attacker, move) && !move.hitsSubstitute(attacker, pokemon)) { if (!pokemon.getTag(this.tagType) && !simulated) { pokemon.addTag(this.tagType, undefined, undefined, pokemon.id); - pokemon.scene.queueMessage(i18next.t("abilityTriggers:windPowerCharged", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: move.name })); + globalScene.queueMessage(i18next.t("abilityTriggers:windPowerCharged", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: move.name })); } return true; } @@ -849,9 +849,9 @@ export class PostDefendTerrainChangeAbAttr extends PostDefendAbAttr { override applyPostDefend(pokemon: Pokemon, _passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, hitResult: HitResult, _args: any[]): boolean { if (hitResult < HitResult.NO_EFFECT && !move.hitsSubstitute(attacker, pokemon)) { if (simulated) { - return pokemon.scene.arena.terrain?.terrainType !== (this.terrainType || undefined); + return globalScene.arena.terrain?.terrainType !== (this.terrainType || undefined); } else { - return pokemon.scene.arena.trySetTerrain(this.terrainType, true); + return globalScene.arena.trySetTerrain(this.terrainType, true); } } @@ -941,7 +941,7 @@ export class PostDefendCritStatStageChangeAbAttr extends PostDefendAbAttr { } if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ this.stat ], this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ this.stat ], this.stages)); } return true; @@ -1030,11 +1030,11 @@ export class PostDefendWeatherChangeAbAttr extends PostDefendAbAttr { if (this.condition && !this.condition(pokemon, attacker, move) || move.hitsSubstitute(attacker, pokemon)) { return false; } - if (!pokemon.scene.arena.weather?.isImmutable()) { + if (!globalScene.arena.weather?.isImmutable()) { if (simulated) { - return pokemon.scene.arena.weather?.weatherType !== this.weatherType; + return globalScene.arena.weather?.weatherType !== this.weatherType; } - return pokemon.scene.arena.trySetWeather(this.weatherType, true); + return globalScene.arena.trySetWeather(this.weatherType, true); } return false; @@ -1138,7 +1138,7 @@ export class PostStatStageChangeStatStageChangeAbAttr extends PostStatStageChang applyPostStatStageChange(pokemon: Pokemon, simulated: boolean, statStagesChanged: BattleStat[], stagesChanged: number, selfTarget: boolean, args: any[]): boolean { if (this.condition(pokemon, statStagesChanged, stagesChanged) && !selfTarget) { if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, (pokemon).getBattlerIndex(), true, this.statsToChange, this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase((pokemon).getBattlerIndex(), true, this.statsToChange, this.stages)); } return true; } @@ -1661,9 +1661,9 @@ export class PostAttackStealHeldItemAbAttr extends PostAttackAbAttr { const heldItems = this.getTargetHeldItems(defender).filter(i => i.isTransferable); if (heldItems.length) { const stolenItem = heldItems[pokemon.randSeedInt(heldItems.length)]; - pokemon.scene.tryTransferHeldItemModifier(stolenItem, pokemon, false).then(success => { + globalScene.tryTransferHeldItemModifier(stolenItem, pokemon, false).then(success => { if (success) { - pokemon.scene.queueMessage(i18next.t("abilityTriggers:postAttackStealHeldItem", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), defenderName: defender.name, stolenItemType: stolenItem.type.name })); + globalScene.queueMessage(i18next.t("abilityTriggers:postAttackStealHeldItem", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), defenderName: defender.name, stolenItemType: stolenItem.type.name })); } resolve(success); }); @@ -1675,7 +1675,7 @@ export class PostAttackStealHeldItemAbAttr extends PostAttackAbAttr { } getTargetHeldItems(target: Pokemon): PokemonHeldItemModifier[] { - return target.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + return globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === target.id, target.isPlayer()) as PokemonHeldItemModifier[]; } } @@ -1754,9 +1754,9 @@ export class PostDefendStealHeldItemAbAttr extends PostDefendAbAttr { const heldItems = this.getTargetHeldItems(attacker).filter(i => i.isTransferable); if (heldItems.length) { const stolenItem = heldItems[pokemon.randSeedInt(heldItems.length)]; - pokemon.scene.tryTransferHeldItemModifier(stolenItem, pokemon, false).then(success => { + globalScene.tryTransferHeldItemModifier(stolenItem, pokemon, false).then(success => { if (success) { - pokemon.scene.queueMessage(i18next.t("abilityTriggers:postDefendStealHeldItem", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), attackerName: attacker.name, stolenItemType: stolenItem.type.name })); + globalScene.queueMessage(i18next.t("abilityTriggers:postDefendStealHeldItem", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), attackerName: attacker.name, stolenItemType: stolenItem.type.name })); } resolve(success); }); @@ -1768,7 +1768,7 @@ export class PostDefendStealHeldItemAbAttr extends PostDefendAbAttr { } getTargetHeldItems(target: Pokemon): PokemonHeldItemModifier[] { - return target.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + return globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === target.id, target.isPlayer()) as PokemonHeldItemModifier[]; } } @@ -1850,7 +1850,7 @@ class PostVictoryStatStageChangeAbAttr extends PostVictoryAbAttr { ? this.stat(pokemon) : this.stat; if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ stat ], this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ stat ], this.stages)); } return true; } @@ -1869,7 +1869,7 @@ export class PostVictoryFormChangeAbAttr extends PostVictoryAbAttr { const formIndex = this.formFunc(pokemon); if (formIndex !== pokemon.formIndex) { if (!simulated) { - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); } return true; } @@ -1900,7 +1900,7 @@ export class PostKnockOutStatStageChangeAbAttr extends PostKnockOutAbAttr { ? this.stat(pokemon) : this.stat; if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ stat ], this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ stat ], this.stages)); } return true; } @@ -1915,7 +1915,7 @@ export class CopyFaintedAllyAbilityAbAttr extends PostKnockOutAbAttr { if (pokemon.isPlayer() === knockedOut.isPlayer() && !knockedOut.getAbility().hasAttr(UncopiableAbilityAbAttr)) { if (!simulated) { pokemon.summonData.ability = knockedOut.getAbility().id; - pokemon.scene.queueMessage(i18next.t("abilityTriggers:copyFaintedAllyAbility", { pokemonNameWithAffix: getPokemonNameWithAffix(knockedOut), abilityName: allAbilities[knockedOut.getAbility().id].name })); + globalScene.queueMessage(i18next.t("abilityTriggers:copyFaintedAllyAbility", { pokemonNameWithAffix: getPokemonNameWithAffix(knockedOut), abilityName: allAbilities[knockedOut.getAbility().id].name })); } return true; } @@ -1987,7 +1987,7 @@ export class PostIntimidateStatStageChangeAbAttr extends AbAttr { apply(pokemon: Pokemon, passive: boolean, simulated:boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { if (!simulated) { - pokemon.scene.pushPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, this.stats, this.stages)); + globalScene.pushPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), false, this.stats, this.stages)); } cancelled.value = this.overwrites; return true; @@ -2029,7 +2029,7 @@ export class PostSummonRemoveArenaTagAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise { if (!simulated) { for (const arenaTag of this.arenaTags) { - pokemon.scene.arena.removeTag(arenaTag); + globalScene.arena.removeTag(arenaTag); } } return true; @@ -2047,7 +2047,7 @@ export class PostSummonMessageAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if (!simulated) { - pokemon.scene.queueMessage(this.messageFunc(pokemon)); + globalScene.queueMessage(this.messageFunc(pokemon)); } return true; @@ -2066,7 +2066,7 @@ export class PostSummonUnnamedMessageAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if (!simulated) { - pokemon.scene.queueMessage(this.message); + globalScene.queueMessage(this.message); } return true; @@ -2117,7 +2117,7 @@ export class PostSummonStatStageChangeAbAttr extends PostSummonAbAttr { if (this.selfTarget) { // we unshift the StatStageChangePhase to put it right after the showAbility and not at the end of the // phase list (which could be after CommandPhase for example) - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, this.stats, this.stages)); return true; } for (const opponent of pokemon.getOpponents()) { @@ -2131,7 +2131,7 @@ export class PostSummonStatStageChangeAbAttr extends PostSummonAbAttr { } } if (!cancelled.value) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, opponent.getBattlerIndex(), false, this.stats, this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(opponent.getBattlerIndex(), false, this.stats, this.stages)); } } return true; @@ -2153,7 +2153,7 @@ export class PostSummonAllyHealAbAttr extends PostSummonAbAttr { const target = pokemon.getAlly(); if (target?.isActive(true)) { if (!simulated) { - target.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(target.getBattlerIndex(), Utils.toDmgValue(pokemon.getMaxHp() / this.healRatio), i18next.t("abilityTriggers:postSummonAllyHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(target), pokemonName: pokemon.name }), true, !this.showAnim)); } @@ -2185,7 +2185,7 @@ export class PostSummonClearAllyStatStagesAbAttr extends PostSummonAbAttr { target.setStatStage(s, 0); } - target.scene.queueMessage(i18next.t("abilityTriggers:postSummonClearAllyStats", { pokemonNameWithAffix: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("abilityTriggers:postSummonClearAllyStats", { pokemonNameWithAffix: getPokemonNameWithAffix(target) })); } return true; @@ -2237,7 +2237,7 @@ export class DownloadAbAttr extends PostSummonAbAttr { if (this.enemyDef > 0 && this.enemySpDef > 0) { // only activate if there's actually an enemy to download from if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, this.stats, 1)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), false, this.stats, 1)); } return true; } @@ -2258,11 +2258,11 @@ export class PostSummonWeatherChangeAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if ((this.weatherType === WeatherType.HEAVY_RAIN || this.weatherType === WeatherType.HARSH_SUN || - this.weatherType === WeatherType.STRONG_WINDS) || !pokemon.scene.arena.weather?.isImmutable()) { + this.weatherType === WeatherType.STRONG_WINDS) || !globalScene.arena.weather?.isImmutable()) { if (simulated) { - return pokemon.scene.arena.weather?.weatherType !== this.weatherType; + return globalScene.arena.weather?.weatherType !== this.weatherType; } else { - return pokemon.scene.arena.trySetWeather(this.weatherType, true); + return globalScene.arena.trySetWeather(this.weatherType, true); } } @@ -2281,9 +2281,9 @@ export class PostSummonTerrainChangeAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if (simulated) { - return pokemon.scene.arena.terrain?.terrainType !== this.terrainType; + return globalScene.arena.terrain?.terrainType !== this.terrainType; } else { - return pokemon.scene.arena.trySetTerrain(this.terrainType, true); + return globalScene.arena.trySetTerrain(this.terrainType, true); } } } @@ -2300,7 +2300,7 @@ export class PostSummonFormChangeAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const formIndex = this.formFunc(pokemon); if (formIndex !== pokemon.formIndex) { - return simulated || pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); + return simulated || globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); } return false; @@ -2320,7 +2320,7 @@ export class PostSummonCopyAbilityAbAttr extends PostSummonAbAttr { let target: Pokemon; if (targets.length > 1) { - pokemon.scene.executeWithSeedOffset(() => target = Utils.randSeedItem(targets), pokemon.scene.currentBattle.waveIndex); + globalScene.executeWithSeedOffset(() => target = Utils.randSeedItem(targets), globalScene.currentBattle.waveIndex); } else { target = targets[0]; } @@ -2377,7 +2377,7 @@ export class PostSummonUserFieldRemoveStatusEffectAbAttr extends PostSummonAbAtt * @returns A boolean or a promise that resolves to a boolean indicating the result of the ability application. */ applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise { - const party = pokemon instanceof PlayerPokemon ? pokemon.scene.getPlayerField() : pokemon.scene.getEnemyField(); + const party = pokemon instanceof PlayerPokemon ? globalScene.getPlayerField() : globalScene.getEnemyField(); const allowedParty = party.filter(p => p.isAllowedInBattle()); if (allowedParty.length < 1) { @@ -2387,7 +2387,7 @@ export class PostSummonUserFieldRemoveStatusEffectAbAttr extends PostSummonAbAtt if (!simulated) { for (const pokemon of allowedParty) { if (pokemon.status && this.statusEffect.includes(pokemon.status.effect)) { - pokemon.scene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); + globalScene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); pokemon.resetStatus(false); pokemon.updateInfo(); } @@ -2401,7 +2401,7 @@ export class PostSummonUserFieldRemoveStatusEffectAbAttr extends PostSummonAbAtt /** Attempt to copy the stat changes on an ally pokemon */ export class PostSummonCopyAllyStatsAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - if (!pokemon.scene.currentBattle.double) { + if (!globalScene.currentBattle.double) { return false; } @@ -2445,7 +2445,7 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { let target: Pokemon; if (targets.length > 1) { - pokemon.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { // in a double battle, if one of the opposing pokemon is fused the other one will be chosen // if both are fused, then Imposter will fail below if (targets[0].fusionSpecies) { @@ -2456,7 +2456,7 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { return; } target = Utils.randSeedItem(targets); - }, pokemon.scene.currentBattle.waveIndex); + }, globalScene.currentBattle.waveIndex); } else { target = targets[0]; } @@ -2493,8 +2493,8 @@ export class PostSummonTransformAbAttr extends PostSummonAbAttr { pokemon.summonData.types = target.getTypes(); promises.push(pokemon.updateInfo()); - pokemon.scene.queueMessage(i18next.t("abilityTriggers:postSummonTransform", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), targetName: target.name, })); - pokemon.scene.playSound("battle_anims/PRSFX- Transform"); + globalScene.queueMessage(i18next.t("abilityTriggers:postSummonTransform", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), targetName: target.name, })); + globalScene.playSound("battle_anims/PRSFX- Transform"); promises.push(pokemon.loadAssets(false).then(() => { pokemon.playAnim(); pokemon.updateInfo(); @@ -2520,14 +2520,14 @@ export class PostSummonWeatherSuppressedFormChangeAbAttr extends PostSummonAbAtt * @returns whether a Pokemon was reverted to its normal form */ applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]) { - const pokemonToTransform = getPokemonWithWeatherBasedForms(pokemon.scene); + const pokemonToTransform = getPokemonWithWeatherBasedForms(); if (pokemonToTransform.length < 1) { return false; } if (!simulated) { - pokemon.scene.arena.triggerWeatherBasedFormChangesToNormal(); + globalScene.arena.triggerWeatherBasedFormChangesToNormal(); } return true; @@ -2567,8 +2567,8 @@ export class PostSummonFormChangeByWeatherAbAttr extends PostSummonAbAttr { return simulated; } - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeWeatherTrigger); - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeRevertWeatherFormTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeWeatherTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeRevertWeatherFormTrigger); queueShowAbility(pokemon, passive); return true; } @@ -2589,7 +2589,7 @@ export class CommanderAbAttr extends AbAttr { override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: null, args: any[]): boolean { // TODO: Should this work with X + Dondozo fusions? - if (pokemon.scene.currentBattle?.double && pokemon.getAlly()?.species.speciesId === Species.DONDOZO) { + if (globalScene.currentBattle?.double && pokemon.getAlly()?.species.speciesId === Species.DONDOZO) { // If the ally Dondozo is fainted or was previously "commanded" by // another Pokemon, this effect cannot apply. if (pokemon.getAlly().isFainted() || pokemon.getAlly().getTag(BattlerTagType.COMMANDED)) { @@ -2600,11 +2600,11 @@ export class CommanderAbAttr extends AbAttr { // Lapse the source's semi-invulnerable tags (to avoid visual inconsistencies) pokemon.lapseTags(BattlerTagLapseType.MOVE_EFFECT); // Play an animation of the source jumping into the ally Dondozo's mouth - pokemon.scene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.COMMANDER_APPLY); + globalScene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.COMMANDER_APPLY); // Apply boosts from this effect to the ally Dondozo pokemon.getAlly().addTag(BattlerTagType.COMMANDED, 0, Moves.NONE, pokemon.id); // Cancel the source Pokemon's next move (if a move is queued) - pokemon.scene.tryRemovePhase((phase) => phase instanceof MovePhase && phase.pokemon === pokemon); + globalScene.tryRemovePhase((phase) => phase instanceof MovePhase && phase.pokemon === pokemon); } return true; } @@ -2649,26 +2649,26 @@ export class PreSwitchOutClearWeatherAbAttr extends PreSwitchOutAbAttr { * @returns {boolean} Returns true if the weather clears, otherwise false. */ applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise { - const weatherType = pokemon.scene.arena.weather?.weatherType; + const weatherType = globalScene.arena.weather?.weatherType; let turnOffWeather = false; // Clear weather only if user's ability matches the weather and no other pokemon has the ability. switch (weatherType) { case (WeatherType.HARSH_SUN): if (pokemon.hasAbility(Abilities.DESOLATE_LAND) - && pokemon.scene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DESOLATE_LAND)).length === 0) { + && globalScene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DESOLATE_LAND)).length === 0) { turnOffWeather = true; } break; case (WeatherType.HEAVY_RAIN): if (pokemon.hasAbility(Abilities.PRIMORDIAL_SEA) - && pokemon.scene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.PRIMORDIAL_SEA)).length === 0) { + && globalScene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.PRIMORDIAL_SEA)).length === 0) { turnOffWeather = true; } break; case (WeatherType.STRONG_WINDS): if (pokemon.hasAbility(Abilities.DELTA_STREAM) - && pokemon.scene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) { + && globalScene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) { turnOffWeather = true; } break; @@ -2679,7 +2679,7 @@ export class PreSwitchOutClearWeatherAbAttr extends PreSwitchOutAbAttr { } if (turnOffWeather) { - pokemon.scene.arena.trySetWeather(WeatherType.NONE, false); + globalScene.arena.trySetWeather(WeatherType.NONE, false); return true; } @@ -2728,7 +2728,7 @@ export class PreSwitchOutFormChangeAbAttr extends PreSwitchOutAbAttr { const formIndex = this.formFunc(pokemon); if (formIndex !== pokemon.formIndex) { if (!simulated) { - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); } return true; } @@ -3159,14 +3159,14 @@ function getSheerForceHitDisableAbCondition(): AbAttrCondition { } function getWeatherCondition(...weatherTypes: WeatherType[]): AbAttrCondition { - return (pokemon: Pokemon) => { - if (!pokemon.scene?.arena) { + return () => { + if (!globalScene?.arena) { return false; } - if (pokemon.scene.arena.weather?.isEffectSuppressed(pokemon.scene)) { + if (globalScene.arena.weather?.isEffectSuppressed()) { return false; } - const weatherType = pokemon.scene.arena.weather?.weatherType; + const weatherType = globalScene.arena.weather?.weatherType; return !!weatherType && weatherTypes.indexOf(weatherType) > -1; }; } @@ -3255,7 +3255,7 @@ export class ForewarnAbAttr extends PostSummonAbAttr { } } if (!simulated) { - pokemon.scene.queueMessage(i18next.t("abilityTriggers:forewarn", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: maxMove })); + globalScene.queueMessage(i18next.t("abilityTriggers:forewarn", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: maxMove })); } return true; } @@ -3269,7 +3269,7 @@ export class FriskAbAttr extends PostSummonAbAttr { applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if (!simulated) { for (const opponent of pokemon.getOpponents()) { - pokemon.scene.queueMessage(i18next.t("abilityTriggers:frisk", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), opponentName: opponent.name, opponentAbilityName: opponent.getAbility().name })); + globalScene.queueMessage(i18next.t("abilityTriggers:frisk", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), opponentName: opponent.name, opponentAbilityName: opponent.getAbility().name })); setAbilityRevealed(opponent); } } @@ -3317,12 +3317,12 @@ export class PostWeatherChangeFormChangeAbAttr extends PostWeatherChangeAbAttr { return simulated; } - const weatherType = pokemon.scene.arena.weather?.weatherType; + const weatherType = globalScene.arena.weather?.weatherType; if (weatherType && this.formRevertingWeathers.includes(weatherType)) { - pokemon.scene.arena.triggerWeatherBasedFormChangesToNormal(); + globalScene.arena.triggerWeatherBasedFormChangesToNormal(); } else { - pokemon.scene.arena.triggerWeatherBasedFormChanges(); + globalScene.arena.triggerWeatherBasedFormChanges(); } return true; } @@ -3386,10 +3386,9 @@ export class PostWeatherLapseHealAbAttr extends PostWeatherLapseAbAttr { applyPostWeatherLapse(pokemon: Pokemon, passive: boolean, simulated: boolean, weather: Weather, args: any[]): boolean { if (!pokemon.isFullHp()) { - const scene = pokemon.scene; const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; if (!simulated) { - scene.unshiftPhase(new PokemonHealPhase(scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), Utils.toDmgValue(pokemon.getMaxHp() / (16 / this.healFactor)), i18next.t("abilityTriggers:postWeatherLapseHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); } return true; @@ -3409,14 +3408,13 @@ export class PostWeatherLapseDamageAbAttr extends PostWeatherLapseAbAttr { } applyPostWeatherLapse(pokemon: Pokemon, passive: boolean, simulated: boolean, weather: Weather, args: any[]): boolean { - const scene = pokemon.scene; if (pokemon.hasAbilityWithAttr(BlockNonDirectDamageAbAttr)) { return false; } if (!simulated) { const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; - scene.queueMessage(i18next.t("abilityTriggers:postWeatherLapseDamage", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName })); + globalScene.queueMessage(i18next.t("abilityTriggers:postWeatherLapseDamage", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName })); pokemon.damageAndUpdate(Utils.toDmgValue(pokemon.getMaxHp() / (16 / this.damageFactor)), HitResult.OTHER); } @@ -3458,7 +3456,7 @@ export class PostTerrainChangeAddBattlerTagAttr extends PostTerrainChangeAbAttr function getTerrainCondition(...terrainTypes: TerrainType[]): AbAttrCondition { return (pokemon: Pokemon) => { - const terrainType = pokemon.scene.arena.terrain?.terrainType; + const terrainType = globalScene.arena.terrain?.terrainType; return !!terrainType && terrainTypes.indexOf(terrainType) > -1; }; } @@ -3494,9 +3492,8 @@ export class PostTurnStatusHealAbAttr extends PostTurnAbAttr { if (pokemon.status && this.effects.includes(pokemon.status.effect)) { if (!pokemon.isFullHp()) { if (!simulated) { - const scene = pokemon.scene; const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; - scene.unshiftPhase(new PokemonHealPhase(scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), Utils.toDmgValue(pokemon.getMaxHp() / 8), i18next.t("abilityTriggers:poisonHeal", { pokemonName: getPokemonNameWithAffix(pokemon), abilityName }), true)); } return true; @@ -3527,7 +3524,7 @@ export class PostTurnResetStatusAbAttr extends PostTurnAbAttr { } if (this.target?.status) { if (!simulated) { - this.target.scene.queueMessage(getStatusEffectHealText(this.target.status?.effect, getPokemonNameWithAffix(this.target))); + globalScene.queueMessage(getStatusEffectHealText(this.target.status?.effect, getPokemonNameWithAffix(this.target))); this.target.resetStatus(false); this.target.updateInfo(); } @@ -3592,7 +3589,7 @@ export class PostTurnLootAbAttr extends PostTurnAbAttr { const chosenBerry = new BerryModifierType(chosenBerryType); berriesEaten.splice(randomIdx); // Remove berry from memory - const berryModifier = pokemon.scene.findModifier( + const berryModifier = globalScene.findModifier( (m) => m instanceof BerryModifier && m.berryType === chosenBerryType, pokemon.isPlayer() ) as BerryModifier | undefined; @@ -3600,16 +3597,16 @@ export class PostTurnLootAbAttr extends PostTurnAbAttr { if (!berryModifier) { const newBerry = new BerryModifier(chosenBerry, pokemon.id, chosenBerryType, 1); if (pokemon.isPlayer()) { - pokemon.scene.addModifier(newBerry); + globalScene.addModifier(newBerry); } else { - pokemon.scene.addEnemyModifier(newBerry); + globalScene.addEnemyModifier(newBerry); } } else if (berryModifier.stackCount < berryModifier.getMaxHeldItemCount(pokemon)) { berryModifier.stackCount++; } - pokemon.scene.queueMessage(i18next.t("abilityTriggers:postTurnLootCreateEatenBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), berryName: chosenBerry.name })); - pokemon.scene.updateModifiers(pokemon.isPlayer()); + globalScene.queueMessage(i18next.t("abilityTriggers:postTurnLootCreateEatenBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), berryName: chosenBerry.name })); + globalScene.updateModifiers(pokemon.isPlayer()); return true; } @@ -3642,11 +3639,11 @@ export class MoodyAbAttr extends PostTurnAbAttr { if (canRaise.length > 0) { const raisedStat = canRaise[pokemon.randSeedInt(canRaise.length)]; canLower = canRaise.filter(s => s !== raisedStat); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ raisedStat ], 2)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ raisedStat ], 2)); } if (canLower.length > 0) { const loweredStat = canLower[pokemon.randSeedInt(canLower.length)]; - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ loweredStat ], -1)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ loweredStat ], -1)); } } @@ -3663,7 +3660,7 @@ export class SpeedBoostAbAttr extends PostTurnAbAttr { applyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if (!simulated) { if (!pokemon.turnData.switchedInThisTurn && !pokemon.turnData.failedRunAway) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.SPD ], 1)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.SPD ], 1)); } else { return false; } @@ -3676,9 +3673,8 @@ export class PostTurnHealAbAttr extends PostTurnAbAttr { applyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if (!pokemon.isFullHp()) { if (!simulated) { - const scene = pokemon.scene; const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; - scene.unshiftPhase(new PokemonHealPhase(scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), Utils.toDmgValue(pokemon.getMaxHp() / 16), i18next.t("abilityTriggers:postTurnHeal", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), true)); } @@ -3702,7 +3698,7 @@ export class PostTurnFormChangeAbAttr extends PostTurnAbAttr { const formIndex = this.formFunc(pokemon); if (formIndex !== pokemon.formIndex) { if (!simulated) { - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); } return true; @@ -3732,7 +3728,7 @@ export class PostTurnHurtIfSleepingAbAttr extends PostTurnAbAttr { if ((opp.status?.effect === StatusEffect.SLEEP || opp.hasAbility(Abilities.COMATOSE)) && !opp.hasAbilityWithAttr(BlockNonDirectDamageAbAttr) && !opp.switchOutStatus) { if (!simulated) { opp.damageAndUpdate(Utils.toDmgValue(opp.getMaxHp() / 8), HitResult.OTHER); - pokemon.scene.queueMessage(i18next.t("abilityTriggers:badDreams", { pokemonName: getPokemonNameWithAffix(opp) })); + globalScene.queueMessage(i18next.t("abilityTriggers:badDreams", { pokemonName: getPokemonNameWithAffix(opp) })); } hadEffect = true; } @@ -3762,11 +3758,11 @@ export class FetchBallAbAttr extends PostTurnAbAttr { if (simulated) { return false; } - const lastUsed = pokemon.scene.currentBattle.lastUsedPokeball; + const lastUsed = globalScene.currentBattle.lastUsedPokeball; if (lastUsed !== null && !!pokemon.isPlayer) { - pokemon.scene.pokeballCounts[lastUsed]++; - pokemon.scene.currentBattle.lastUsedPokeball = null; - pokemon.scene.queueMessage(i18next.t("abilityTriggers:fetchBall", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), pokeballName: getPokeballName(lastUsed) })); + globalScene.pokeballCounts[lastUsed]++; + globalScene.currentBattle.lastUsedPokeball = null; + globalScene.queueMessage(i18next.t("abilityTriggers:fetchBall", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), pokeballName: getPokeballName(lastUsed) })); return true; } return false; @@ -3785,11 +3781,11 @@ export class PostBiomeChangeWeatherChangeAbAttr extends PostBiomeChangeAbAttr { } apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { - if (!pokemon.scene.arena.weather?.isImmutable()) { + if (!globalScene.arena.weather?.isImmutable()) { if (simulated) { - return pokemon.scene.arena.weather?.weatherType !== this.weatherType; + return globalScene.arena.weather?.weatherType !== this.weatherType; } else { - return pokemon.scene.arena.trySetWeather(this.weatherType, true); + return globalScene.arena.trySetWeather(this.weatherType, true); } } @@ -3808,9 +3804,9 @@ export class PostBiomeChangeTerrainChangeAbAttr extends PostBiomeChangeAbAttr { apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { if (simulated) { - return pokemon.scene.arena.terrain?.terrainType !== this.terrainType; + return globalScene.arena.terrain?.terrainType !== this.terrainType; } else { - return pokemon.scene.arena.trySetTerrain(this.terrainType, true); + return globalScene.arena.trySetTerrain(this.terrainType, true); } } } @@ -3852,10 +3848,10 @@ export class PostDancingMoveAbAttr extends PostMoveUsedAbAttr { // If the move is an AttackMove or a StatusMove the Dancer must replicate the move on the source of the Dance if (move.getMove() instanceof AttackMove || move.getMove() instanceof StatusMove) { const target = this.getTarget(dancer, source, targets); - dancer.scene.unshiftPhase(new MovePhase(dancer.scene, dancer, target, move, true, true)); + globalScene.unshiftPhase(new MovePhase(dancer, target, move, true, true)); } else if (move.getMove() instanceof SelfStatusMove) { // If the move is a SelfStatusMove (ie. Swords Dance) the Dancer should replicate it on itself - dancer.scene.unshiftPhase(new MovePhase(dancer.scene, dancer, [ dancer.getBattlerIndex() ], move, true, true)); + globalScene.unshiftPhase(new MovePhase(dancer, [ dancer.getBattlerIndex() ], move, true, true)); } } return true; @@ -3932,7 +3928,7 @@ export class StatStageChangeMultiplierAbAttr extends AbAttr { export class StatStageChangeCopyAbAttr extends AbAttr { apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean | Promise { if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, (args[0] as BattleStat[]), (args[1] as number), true, false, false)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, (args[0] as BattleStat[]), (args[1] as number), true, false, false)); } return true; } @@ -4009,9 +4005,8 @@ export class HealFromBerryUseAbAttr extends AbAttr { apply(pokemon: Pokemon, passive: boolean, simulated: boolean, ...args: [Utils.BooleanHolder, any[]]): boolean { const { name: abilityName } = passive ? pokemon.getPassiveAbility() : pokemon.getAbility(); if (!simulated) { - pokemon.scene.unshiftPhase( + globalScene.unshiftPhase( new PokemonHealPhase( - pokemon.scene, pokemon.getBattlerIndex(), Utils.toDmgValue(pokemon.getMaxHp() * this.healPercent), i18next.t("abilityTriggers:healFromBerryUse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName }), @@ -4117,13 +4112,13 @@ export class PostBattleLootAbAttr extends PostBattleAbAttr { * @returns `true` if successful */ applyPostBattle(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { - const postBattleLoot = pokemon.scene.currentBattle.postBattleLoot; + const postBattleLoot = globalScene.currentBattle.postBattleLoot; if (!simulated && postBattleLoot.length && args[0]) { const randItem = Utils.randSeedItem(postBattleLoot); //@ts-ignore - TODO see below - if (pokemon.scene.tryTransferHeldItemModifier(randItem, pokemon, true, 1, true, undefined, false)) { // TODO: fix. This is a promise!? + if (globalScene.tryTransferHeldItemModifier(randItem, pokemon, true, 1, true, undefined, false)) { // TODO: fix. This is a promise!? postBattleLoot.splice(postBattleLoot.indexOf(randItem), 1); - pokemon.scene.queueMessage(i18next.t("abilityTriggers:postBattleLoot", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), itemName: randItem.type.name })); + globalScene.queueMessage(i18next.t("abilityTriggers:postBattleLoot", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), itemName: randItem.type.name })); return true; } } @@ -4156,14 +4151,14 @@ export class PostFaintUnsuppressedWeatherFormChangeAbAttr extends PostFaintAbAtt * @returns whether the form change was triggered */ applyPostFaint(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker: Pokemon, move: Move, hitResult: HitResult, args: any[]): boolean { - const pokemonToTransform = getPokemonWithWeatherBasedForms(pokemon.scene); + const pokemonToTransform = getPokemonWithWeatherBasedForms(); if (pokemonToTransform.length < 1) { return false; } if (!simulated) { - pokemon.scene.arena.triggerWeatherBasedFormChanges(); + globalScene.arena.triggerWeatherBasedFormChanges(); } return true; @@ -4185,26 +4180,26 @@ export class PostFaintClearWeatherAbAttr extends PostFaintAbAttr { * @returns {boolean} Returns true if the weather clears, otherwise false. */ applyPostFaint(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker?: Pokemon, move?: Move, hitResult?: HitResult, ...args: any[]): boolean { - const weatherType = pokemon.scene.arena.weather?.weatherType; + const weatherType = globalScene.arena.weather?.weatherType; let turnOffWeather = false; // Clear weather only if user's ability matches the weather and no other pokemon has the ability. switch (weatherType) { case (WeatherType.HARSH_SUN): if (pokemon.hasAbility(Abilities.DESOLATE_LAND) - && pokemon.scene.getField(true).filter(p => p.hasAbility(Abilities.DESOLATE_LAND)).length === 0) { + && globalScene.getField(true).filter(p => p.hasAbility(Abilities.DESOLATE_LAND)).length === 0) { turnOffWeather = true; } break; case (WeatherType.HEAVY_RAIN): if (pokemon.hasAbility(Abilities.PRIMORDIAL_SEA) - && pokemon.scene.getField(true).filter(p => p.hasAbility(Abilities.PRIMORDIAL_SEA)).length === 0) { + && globalScene.getField(true).filter(p => p.hasAbility(Abilities.PRIMORDIAL_SEA)).length === 0) { turnOffWeather = true; } break; case (WeatherType.STRONG_WINDS): if (pokemon.hasAbility(Abilities.DELTA_STREAM) - && pokemon.scene.getField(true).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) { + && globalScene.getField(true).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) { turnOffWeather = true; } break; @@ -4215,7 +4210,7 @@ export class PostFaintClearWeatherAbAttr extends PostFaintAbAttr { } if (turnOffWeather) { - pokemon.scene.arena.trySetWeather(WeatherType.NONE, false); + globalScene.arena.trySetWeather(WeatherType.NONE, false); return true; } @@ -4235,7 +4230,7 @@ export class PostFaintContactDamageAbAttr extends PostFaintAbAttr { applyPostFaint(pokemon: Pokemon, passive: boolean, simulated: boolean, attacker?: Pokemon, move?: Move, hitResult?: HitResult, ...args: any[]): boolean { if (move !== undefined && attacker !== undefined && move.checkFlag(MoveFlags.MAKES_CONTACT, attacker, pokemon)) { //If the mon didn't die to indirect damage const cancelled = new Utils.BooleanHolder(false); - pokemon.scene.getField(true).map(p => applyAbAttrs(FieldPreventExplosiveMovesAbAttr, p, cancelled, simulated)); + globalScene.getField(true).map(p => applyAbAttrs(FieldPreventExplosiveMovesAbAttr, p, cancelled, simulated)); if (cancelled.value || attacker.hasAbilityWithAttr(BlockNonDirectDamageAbAttr)) { return false; } @@ -4366,7 +4361,7 @@ export class FlinchStatStageChangeAbAttr extends FlinchEffectAbAttr { apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { if (!simulated) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.stages)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, this.stats, this.stages)); } return true; } @@ -4584,7 +4579,7 @@ export class MoneyAbAttr extends PostBattleAbAttr { */ applyPostBattle(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { if (!simulated && args[0]) { - pokemon.scene.currentBattle.moneyScattered += pokemon.scene.getWaveMoneyAmount(0.2); + globalScene.currentBattle.moneyScattered += globalScene.getWaveMoneyAmount(0.2); return true; } return false; @@ -4627,7 +4622,7 @@ export class PostSummonStatStageChangeOnArenaAbAttr extends PostSummonStatStageC applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { const side = pokemon.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - if (pokemon.scene.arena.getTagOnSide(this.tagType, side)) { + if (globalScene.arena.getTagOnSide(this.tagType, side)) { return super.applyPostSummon(pokemon, passive, simulated, args); } return false; @@ -4725,7 +4720,7 @@ export class BypassSpeedChanceAbAttr extends AbAttr { if (!bypassSpeed.value && pokemon.randSeedInt(100) < this.chance) { const turnCommand = - pokemon.scene.currentBattle.turnCommands[pokemon.getBattlerIndex()]; + globalScene.currentBattle.turnCommands[pokemon.getBattlerIndex()]; const isCommandFight = turnCommand?.command === Command.FIGHT; const move = turnCommand?.move?.move ? allMoves[turnCommand.move.move] : null; const isDamageMove = move?.category === MoveCategory.PHYSICAL || move?.category === MoveCategory.SPECIAL; @@ -4767,7 +4762,7 @@ export class PreventBypassSpeedChanceAbAttr extends AbAttr { const bypassSpeed = args[0] as Utils.BooleanHolder; const canCheckHeldItems = args[1] as Utils.BooleanHolder; - const turnCommand = pokemon.scene.currentBattle.turnCommands[pokemon.getBattlerIndex()]; + const turnCommand = globalScene.currentBattle.turnCommands[pokemon.getBattlerIndex()]; const isCommandFight = turnCommand?.command === Command.FIGHT; const move = turnCommand?.move?.move ? allMoves[turnCommand.move.move] : null; if (this.condition(pokemon, move!) && isCommandFight) { @@ -4792,7 +4787,7 @@ export class TerrainEventTypeChangeAbAttr extends PostSummonAbAttr { if (pokemon.isTerastallized()) { return false; } - const currentTerrain = pokemon.scene.arena.getTerrainType(); + const currentTerrain = globalScene.arena.getTerrainType(); const typeChange: Type[] = this.determineTypeChange(pokemon, currentTerrain); if (typeChange.length !== 0) { if (pokemon.summonData.addedType && typeChange.includes(pokemon.summonData.addedType)) { @@ -4839,14 +4834,14 @@ export class TerrainEventTypeChangeAbAttr extends PostSummonAbAttr { * @returns `true` if there is an active terrain requiring a type change | `false` if not */ override applyPostSummon(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise { - if (pokemon.scene.arena.getTerrainType() !== TerrainType.NONE) { + if (globalScene.arena.getTerrainType() !== TerrainType.NONE) { return this.apply(pokemon, passive, simulated, new Utils.BooleanHolder(false), []); } return false; } override getTriggerMessage(pokemon: Pokemon, abilityName: string, ...args: any[]) { - const currentTerrain = pokemon.scene.arena.getTerrainType(); + const currentTerrain = globalScene.arena.getTerrainType(); const pokemonNameWithAffix = getPokemonNameWithAffix(pokemon); if (currentTerrain === TerrainType.NONE) { return i18next.t("abilityTriggers:pokemonTypeChangeRevert", { pokemonNameWithAffix }); @@ -4878,7 +4873,7 @@ async function applyAbAttrsInternal( continue; } - pokemon.scene.setPhaseQueueSplice(); + globalScene.setPhaseQueueSplice(); let result = applyFunc(attr, passive); // TODO Remove this when promises get reworked @@ -4894,7 +4889,7 @@ async function applyAbAttrsInternal( } if (attr.showAbility && !simulated) { if (showAbilityInstant) { - pokemon.scene.abilityBar.showAbility(pokemon, passive); + globalScene.abilityBar.showAbility(pokemon, passive); } else { queueShowAbility(pokemon, passive); } @@ -4902,13 +4897,13 @@ async function applyAbAttrsInternal( const message = attr.getTriggerMessage(pokemon, ability.name, args); if (message) { if (!simulated) { - pokemon.scene.queueMessage(message); + globalScene.queueMessage(message); } } messages.push(message!); } } - pokemon.scene.clearPhaseQueueSplice(); + globalScene.clearPhaseQueueSplice(); } } @@ -4929,28 +4924,27 @@ class ForceSwitchOutHelper { * - If the Pokémon is still alive (hp > 0), and if so, it leaves the field and a new SwitchPhase is initiated. */ if (switchOutTarget instanceof PlayerPokemon) { - if (switchOutTarget.scene.getPlayerParty().filter((p) => p.isAllowedInBattle() && !p.isOnField()).length < 1) { + if (globalScene.getPlayerParty().filter((p) => p.isAllowedInBattle() && !p.isOnField()).length < 1) { return false; } if (switchOutTarget.hp > 0) { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); - pokemon.scene.prependToPhase(new SwitchPhase(pokemon.scene, this.switchType, switchOutTarget.getFieldIndex(), true, true), MoveEndPhase); + globalScene.prependToPhase(new SwitchPhase(this.switchType, switchOutTarget.getFieldIndex(), true, true), MoveEndPhase); return true; } /** * For non-wild battles, it checks if the opposing party has any available Pokémon to switch in. * If yes, the Pokémon leaves the field and a new SwitchSummonPhase is initiated. */ - } else if (pokemon.scene.currentBattle.battleType !== BattleType.WILD) { - if (switchOutTarget.scene.getEnemyParty().filter((p) => p.isAllowedInBattle() && !p.isOnField()).length < 1) { + } else if (globalScene.currentBattle.battleType !== BattleType.WILD) { + if (globalScene.getEnemyParty().filter((p) => p.isAllowedInBattle() && !p.isOnField()).length < 1) { return false; } if (switchOutTarget.hp > 0) { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); - pokemon.scene.prependToPhase(new SwitchSummonPhase(pokemon.scene, this.switchType, switchOutTarget.getFieldIndex(), - (pokemon.scene.currentBattle.trainer ? pokemon.scene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot) : 0), - false, false), MoveEndPhase); + const summonIndex = (globalScene.currentBattle.trainer ? globalScene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot) : 0); + globalScene.prependToPhase(new SwitchSummonPhase(this.switchType, switchOutTarget.getFieldIndex(), summonIndex, false, false), MoveEndPhase); return true; } /** @@ -4958,26 +4952,26 @@ class ForceSwitchOutHelper { * It will not flee if it is a Mystery Encounter with fleeing disabled (checked in `getSwitchOutCondition()`) or if it is a wave 10x wild boss */ } else { - if (!pokemon.scene.currentBattle.waveIndex || pokemon.scene.currentBattle.waveIndex % 10 === 0) { + if (!globalScene.currentBattle.waveIndex || globalScene.currentBattle.waveIndex % 10 === 0) { return false; } if (switchOutTarget.hp > 0) { switchOutTarget.leaveField(false); - pokemon.scene.queueMessage(i18next.t("moveTriggers:fled", { pokemonName: getPokemonNameWithAffix(switchOutTarget) }), null, true, 500); + globalScene.queueMessage(i18next.t("moveTriggers:fled", { pokemonName: getPokemonNameWithAffix(switchOutTarget) }), null, true, 500); - if (switchOutTarget.scene.currentBattle.double) { + if (globalScene.currentBattle.double) { const allyPokemon = switchOutTarget.getAlly(); - switchOutTarget.scene.redirectPokemonMoves(switchOutTarget, allyPokemon); + globalScene.redirectPokemonMoves(switchOutTarget, allyPokemon); } } if (!switchOutTarget.getAlly()?.isActive(true)) { - pokemon.scene.clearEnemyHeldItemModifiers(); + globalScene.clearEnemyHeldItemModifiers(); if (switchOutTarget.hp) { - pokemon.scene.pushPhase(new BattleEndPhase(pokemon.scene, false)); - pokemon.scene.pushPhase(new NewBattlePhase(pokemon.scene)); + globalScene.pushPhase(new BattleEndPhase(false)); + globalScene.pushPhase(new NewBattlePhase()); } } } @@ -5001,20 +4995,20 @@ class ForceSwitchOutHelper { return !blockedByAbility.value; } - if (!player && pokemon.scene.currentBattle.battleType === BattleType.WILD) { - if (!pokemon.scene.currentBattle.waveIndex && pokemon.scene.currentBattle.waveIndex % 10 === 0) { + if (!player && globalScene.currentBattle.battleType === BattleType.WILD) { + if (!globalScene.currentBattle.waveIndex && globalScene.currentBattle.waveIndex % 10 === 0) { return false; } } - if (!player && pokemon.scene.currentBattle.isBattleMysteryEncounter() && !pokemon.scene.currentBattle.mysteryEncounter?.fleeAllowed) { + if (!player && globalScene.currentBattle.isBattleMysteryEncounter() && !globalScene.currentBattle.mysteryEncounter?.fleeAllowed) { return false; } - const party = player ? pokemon.scene.getPlayerParty() : pokemon.scene.getEnemyParty(); - return (!player && pokemon.scene.currentBattle.battleType === BattleType.WILD) + const party = player ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); + return (!player && globalScene.currentBattle.battleType === BattleType.WILD) || party.filter(p => p.isAllowedInBattle() - && (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > pokemon.scene.currentBattle.getBattlerCount(); + && (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > globalScene.currentBattle.getBattlerCount(); } /** @@ -5295,8 +5289,8 @@ export function applyPostItemLostAbAttrs(attrType: Constructor +function getPokemonWithWeatherBasedForms() { + return globalScene.getField(true).filter(p => (p.hasAbility(Abilities.FORECAST) && p.species.speciesId === Species.CASTFORM) || (p.hasAbility(Abilities.FLOWER_GIFT) && p.species.speciesId === Species.CHERRIM) ); @@ -5412,7 +5405,7 @@ export function initAbilities() { .attr(UnswappableAbilityAbAttr) .ignorable(), new Ability(Abilities.LEVITATE, 3) - .attr(AttackTypeImmunityAbAttr, Type.GROUND, (pokemon: Pokemon) => !pokemon.getTag(GroundedTag) && !pokemon.scene.arena.getTag(ArenaTagType.GRAVITY)) + .attr(AttackTypeImmunityAbAttr, Type.GROUND, (pokemon: Pokemon) => !pokemon.getTag(GroundedTag) && !globalScene.arena.getTag(ArenaTagType.GRAVITY)) .ignorable(), new Ability(Abilities.EFFECT_SPORE, 3) .attr(EffectSporeAbAttr), @@ -5504,9 +5497,9 @@ export function initAbilities() { new Ability(Abilities.CUTE_CHARM, 3) .attr(PostDefendContactApplyTagChanceAbAttr, 30, BattlerTagType.INFATUATED), new Ability(Abilities.PLUS, 3) - .conditionalAttr(p => p.scene.currentBattle.double && [ Abilities.PLUS, Abilities.MINUS ].some(a => p.getAlly().hasAbility(a)), StatMultiplierAbAttr, Stat.SPATK, 1.5), + .conditionalAttr(p => globalScene.currentBattle.double && [ Abilities.PLUS, Abilities.MINUS ].some(a => p.getAlly().hasAbility(a)), StatMultiplierAbAttr, Stat.SPATK, 1.5), new Ability(Abilities.MINUS, 3) - .conditionalAttr(p => p.scene.currentBattle.double && [ Abilities.PLUS, Abilities.MINUS ].some(a => p.getAlly().hasAbility(a)), StatMultiplierAbAttr, Stat.SPATK, 1.5), + .conditionalAttr(p => globalScene.currentBattle.double && [ Abilities.PLUS, Abilities.MINUS ].some(a => p.getAlly().hasAbility(a)), StatMultiplierAbAttr, Stat.SPATK, 1.5), new Ability(Abilities.FORECAST, 3) .attr(UncopiableAbilityAbAttr) .attr(NoFusionAbilityAbAttr) @@ -5782,7 +5775,7 @@ export function initAbilities() { .ignorable(), new Ability(Abilities.ANALYTIC, 5) .attr(MovePowerBoostAbAttr, (user, target, move) => { - const movePhase = user?.scene.findPhase((phase) => phase instanceof MovePhase && phase.pokemon.id !== user.id); + const movePhase = globalScene.findPhase((phase) => phase instanceof MovePhase && phase.pokemon.id !== user?.id); return Utils.isNullOrUndefined(movePhase); }, 1.3), new Ability(Abilities.ILLUSION, 5) @@ -5906,9 +5899,9 @@ export function initAbilities() { .attr(FieldMoveTypePowerBoostAbAttr, Type.FAIRY, 4 / 3), new Ability(Abilities.AURA_BREAK, 6) .ignorable() - .conditionalAttr(pokemon => pokemon.scene.getField(true).some(p => p.hasAbility(Abilities.DARK_AURA)), FieldMoveTypePowerBoostAbAttr, Type.DARK, 9 / 16) - .conditionalAttr(pokemon => pokemon.scene.getField(true).some(p => p.hasAbility(Abilities.FAIRY_AURA)), FieldMoveTypePowerBoostAbAttr, Type.FAIRY, 9 / 16) - .conditionalAttr(pokemon => pokemon.scene.getField(true).some(p => p.hasAbility(Abilities.DARK_AURA) || p.hasAbility(Abilities.FAIRY_AURA)), + .conditionalAttr(pokemon => globalScene.getField(true).some(p => p.hasAbility(Abilities.DARK_AURA)), FieldMoveTypePowerBoostAbAttr, Type.DARK, 9 / 16) + .conditionalAttr(pokemon => globalScene.getField(true).some(p => p.hasAbility(Abilities.FAIRY_AURA)), FieldMoveTypePowerBoostAbAttr, Type.FAIRY, 9 / 16) + .conditionalAttr(pokemon => globalScene.getField(true).some(p => p.hasAbility(Abilities.DARK_AURA) || p.hasAbility(Abilities.FAIRY_AURA)), PostSummonMessageAbAttr, (pokemon: Pokemon) => i18next.t("abilityTriggers:postSummonAuraBreak", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })), new Ability(Abilities.PRIMORDIAL_SEA, 6) .attr(PostSummonWeatherChangeAbAttr, WeatherType.HEAVY_RAIN) @@ -6320,7 +6313,7 @@ export function initAbilities() { new Ability(Abilities.SHARPNESS, 9) .attr(MovePowerBoostAbAttr, (user, target, move) => move.hasFlag(MoveFlags.SLICING_MOVE), 1.5), new Ability(Abilities.SUPREME_OVERLORD, 9) - .attr(VariableMovePowerBoostAbAttr, (user, target, move) => 1 + 0.1 * Math.min(user.isPlayer() ? user.scene.currentBattle.playerFaints : user.scene.currentBattle.enemyFaints, 5)) + .attr(VariableMovePowerBoostAbAttr, (user, target, move) => 1 + 0.1 * Math.min(user.isPlayer() ? globalScene.currentBattle.playerFaints : globalScene.currentBattle.enemyFaints, 5)) .partial(), // Counter resets every wave instead of on arena reset new Ability(Abilities.COSTAR, 9) .attr(PostSummonCopyAllyStatsAbAttr), diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index 8bb74d29a4ea..79de11b8d401 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -1,5 +1,5 @@ +import { globalScene } from "#app/global-scene"; import { Arena } from "#app/field/arena"; -import BattleScene from "#app/battle-scene"; import { Type } from "#enums/type"; import { BooleanHolder, NumberHolder, toDmgValue } from "#app/utils"; import { MoveCategory, allMoves, MoveTarget } from "#app/data/move"; @@ -44,7 +44,7 @@ export abstract class ArenaTag { onRemove(arena: Arena, quiet: boolean = false): void { if (!quiet) { - arena.scene.queueMessage(i18next.t(`arenaTag:arenaOnRemove${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`, { moveName: this.getMoveName() })); + globalScene.queueMessage(i18next.t(`arenaTag:arenaOnRemove${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`, { moveName: this.getMoveName() })); } } @@ -74,27 +74,25 @@ export abstract class ArenaTag { /** * Helper function that retrieves the source Pokemon - * @param scene medium to retrieve the source Pokemon * @returns The source {@linkcode Pokemon} or `null` if none is found */ - public getSourcePokemon(scene: BattleScene): Pokemon | null { - return this.sourceId ? scene.getPokemonById(this.sourceId) : null; + public getSourcePokemon(): Pokemon | null { + return this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; } /** * Helper function that retrieves the Pokemon affected - * @param scene - medium to retrieve the involved Pokemon * @returns list of PlayerPokemon or EnemyPokemon on the field */ - public getAffectedPokemon(scene: BattleScene): Pokemon[] { + public getAffectedPokemon(): Pokemon[] { switch (this.side) { case ArenaTagSide.PLAYER: - return scene.getPlayerField() ?? []; + return globalScene.getPlayerField() ?? []; case ArenaTagSide.ENEMY: - return scene.getEnemyField() ?? []; + return globalScene.getEnemyField() ?? []; case ArenaTagSide.BOTH: default: - return scene.getField(true) ?? []; + return globalScene.getField(true) ?? []; } } } @@ -112,10 +110,10 @@ export class MistTag extends ArenaTag { super.onAdd(arena); if (this.sourceId) { - const source = arena.scene.getPokemonById(this.sourceId); + const source = globalScene.getPokemonById(this.sourceId); if (!quiet && source) { - arena.scene.queueMessage(i18next.t("arenaTag:mistOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); + globalScene.queueMessage(i18next.t("arenaTag:mistOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); } else if (!quiet) { console.warn("Failed to get source for MistTag onAdd"); } @@ -146,7 +144,7 @@ export class MistTag extends ArenaTag { cancelled.value = true; if (!simulated) { - arena.scene.queueMessage(i18next.t("arenaTag:mistApply")); + globalScene.queueMessage(i18next.t("arenaTag:mistApply")); } return true; @@ -193,7 +191,7 @@ export class WeakenMoveScreenTag extends ArenaTag { if (bypassed.value) { return false; } - damageMultiplier.value = arena.scene.currentBattle.double ? 2732 / 4096 : 0.5; + damageMultiplier.value = globalScene.currentBattle.double ? 2732 / 4096 : 0.5; return true; } return false; @@ -211,7 +209,7 @@ class ReflectTag extends WeakenMoveScreenTag { onAdd(arena: Arena, quiet: boolean = false): void { if (!quiet) { - arena.scene.queueMessage(i18next.t(`arenaTag:reflectOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:reflectOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } } } @@ -227,7 +225,7 @@ class LightScreenTag extends WeakenMoveScreenTag { onAdd(arena: Arena, quiet: boolean = false): void { if (!quiet) { - arena.scene.queueMessage(i18next.t(`arenaTag:lightScreenOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:lightScreenOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } } } @@ -243,7 +241,7 @@ class AuroraVeilTag extends WeakenMoveScreenTag { onAdd(arena: Arena, quiet: boolean = false): void { if (!quiet) { - arena.scene.queueMessage(i18next.t(`arenaTag:auroraVeilOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:auroraVeilOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } } } @@ -268,7 +266,7 @@ export class ConditionalProtectTag extends ArenaTag { } onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t(`arenaTag:conditionalProtectOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`, { moveName: super.getMoveName() })); + globalScene.queueMessage(i18next.t(`arenaTag:conditionalProtectOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`, { moveName: super.getMoveName() })); } // Removes default message for effect removal @@ -296,8 +294,8 @@ export class ConditionalProtectTag extends ArenaTag { if (!simulated) { attacker.stopMultiHit(defender); - new CommonBattleAnim(CommonAnim.PROTECT, defender).play(arena.scene); - arena.scene.queueMessage(i18next.t("arenaTag:conditionalProtectApply", { moveName: super.getMoveName(), pokemonNameWithAffix: getPokemonNameWithAffix(defender) })); + new CommonBattleAnim(CommonAnim.PROTECT, defender).play(); + globalScene.queueMessage(i18next.t("arenaTag:conditionalProtectApply", { moveName: super.getMoveName(), pokemonNameWithAffix: getPokemonNameWithAffix(defender) })); } } @@ -318,7 +316,7 @@ export class ConditionalProtectTag extends ArenaTag { */ const QuickGuardConditionFunc: ProtectConditionFunc = (arena, moveId) => { const move = allMoves[moveId]; - const effectPhase = arena.scene.getCurrentPhase(); + const effectPhase = globalScene.getCurrentPhase(); if (effectPhase instanceof MoveEffectPhase) { const attacker = effectPhase.getUserPokemon(); @@ -393,9 +391,9 @@ class MatBlockTag extends ConditionalProtectTag { onAdd(arena: Arena) { if (this.sourceId) { - const source = arena.scene.getPokemonById(this.sourceId); + const source = globalScene.getPokemonById(this.sourceId); if (source) { - arena.scene.queueMessage(i18next.t("arenaTag:matBlockOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); + globalScene.queueMessage(i18next.t("arenaTag:matBlockOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); } else { console.warn("Failed to get source for MatBlockTag onAdd"); } @@ -448,15 +446,15 @@ export class NoCritTag extends ArenaTag { /** Queues a message upon adding this effect to the field */ onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t(`arenaTag:noCritOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : "Enemy"}`, { + globalScene.queueMessage(i18next.t(`arenaTag:noCritOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : "Enemy"}`, { moveName: this.getMoveName() })); } /** Queues a message upon removing this effect from the field */ onRemove(arena: Arena): void { - const source = arena.scene.getPokemonById(this.sourceId!); // TODO: is this bang correct? - arena.scene.queueMessage(i18next.t("arenaTag:noCritOnRemove", { + const source = globalScene.getPokemonById(this.sourceId!); // TODO: is this bang correct? + globalScene.queueMessage(i18next.t("arenaTag:noCritOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(source ?? undefined), moveName: this.getMoveName() })); @@ -478,7 +476,7 @@ class WishTag extends ArenaTag { onAdd(arena: Arena): void { if (this.sourceId) { - const user = arena.scene.getPokemonById(this.sourceId); + const user = globalScene.getPokemonById(this.sourceId); if (user) { this.battlerIndex = user.getBattlerIndex(); this.triggerMessage = i18next.t("arenaTag:wishTagOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(user) }); @@ -490,10 +488,10 @@ class WishTag extends ArenaTag { } onRemove(arena: Arena): void { - const target = arena.scene.getField()[this.battlerIndex]; + const target = globalScene.getField()[this.battlerIndex]; if (target?.isActive(true)) { - arena.scene.queueMessage(this.triggerMessage); - arena.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(), this.healHp, null, true, false)); + globalScene.queueMessage(this.triggerMessage); + globalScene.unshiftPhase(new PokemonHealPhase(target.getBattlerIndex(), this.healHp, null, true, false)); } } } @@ -546,11 +544,11 @@ class MudSportTag extends WeakenMoveTypeTag { } onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:mudSportOnAdd")); + globalScene.queueMessage(i18next.t("arenaTag:mudSportOnAdd")); } onRemove(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:mudSportOnRemove")); + globalScene.queueMessage(i18next.t("arenaTag:mudSportOnRemove")); } } @@ -564,11 +562,11 @@ class WaterSportTag extends WeakenMoveTypeTag { } onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:waterSportOnAdd")); + globalScene.queueMessage(i18next.t("arenaTag:waterSportOnAdd")); } onRemove(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:waterSportOnRemove")); + globalScene.queueMessage(i18next.t("arenaTag:waterSportOnRemove")); } } @@ -584,7 +582,7 @@ export class IonDelugeTag extends ArenaTag { /** Queues an on-add message */ onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:plasmaFistsOnAdd")); + globalScene.queueMessage(i18next.t("arenaTag:plasmaFistsOnAdd")); } onRemove(arena: Arena): void { } // Removes default on-remove message @@ -679,9 +677,9 @@ class SpikesTag extends ArenaTrapTag { onAdd(arena: Arena, quiet: boolean = false): void { super.onAdd(arena); - const source = this.sourceId ? arena.scene.getPokemonById(this.sourceId) : null; + const source = this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; if (!quiet && source) { - arena.scene.queueMessage(i18next.t("arenaTag:spikesOnAdd", { moveName: this.getMoveName(), opponentDesc: source.getOpponentDescriptor() })); + globalScene.queueMessage(i18next.t("arenaTag:spikesOnAdd", { moveName: this.getMoveName(), opponentDesc: source.getOpponentDescriptor() })); } } @@ -698,7 +696,7 @@ class SpikesTag extends ArenaTrapTag { const damageHpRatio = 1 / (10 - 2 * this.layers); const damage = toDmgValue(pokemon.getMaxHp() * damageHpRatio); - pokemon.scene.queueMessage(i18next.t("arenaTag:spikesActivateTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("arenaTag:spikesActivateTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); pokemon.damageAndUpdate(damage, HitResult.OTHER); if (pokemon.turnData) { pokemon.turnData.damageTaken += damage; @@ -728,9 +726,9 @@ class ToxicSpikesTag extends ArenaTrapTag { onAdd(arena: Arena, quiet: boolean = false): void { super.onAdd(arena); - const source = this.sourceId ? arena.scene.getPokemonById(this.sourceId) : null; + const source = this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; if (!quiet && source) { - arena.scene.queueMessage(i18next.t("arenaTag:toxicSpikesOnAdd", { moveName: this.getMoveName(), opponentDesc: source.getOpponentDescriptor() })); + globalScene.queueMessage(i18next.t("arenaTag:toxicSpikesOnAdd", { moveName: this.getMoveName(), opponentDesc: source.getOpponentDescriptor() })); } } @@ -747,8 +745,8 @@ class ToxicSpikesTag extends ArenaTrapTag { } if (pokemon.isOfType(Type.POISON)) { this.neutralized = true; - if (pokemon.scene.arena.removeTag(this.tagType)) { - pokemon.scene.queueMessage(i18next.t("arenaTag:toxicSpikesActivateTrapPoison", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: this.getMoveName() })); + if (globalScene.arena.removeTag(this.tagType)) { + globalScene.queueMessage(i18next.t("arenaTag:toxicSpikesActivateTrapPoison", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: this.getMoveName() })); return true; } } else if (!pokemon.status) { @@ -792,7 +790,7 @@ export class DelayedAttackTag extends ArenaTag { const ret = super.lapse(arena); if (!ret) { - arena.scene.unshiftPhase(new MoveEffectPhase(arena.scene, this.sourceId!, [ this.targetIndex ], new PokemonMove(this.sourceMove!, 0, 0, true))); // TODO: are those bangs correct? + globalScene.unshiftPhase(new MoveEffectPhase(this.sourceId!, [ this.targetIndex ], new PokemonMove(this.sourceMove!, 0, 0, true))); // TODO: are those bangs correct? } return ret; @@ -814,9 +812,9 @@ class StealthRockTag extends ArenaTrapTag { onAdd(arena: Arena, quiet: boolean = false): void { super.onAdd(arena); - const source = this.sourceId ? arena.scene.getPokemonById(this.sourceId) : null; + const source = this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; if (!quiet && source) { - arena.scene.queueMessage(i18next.t("arenaTag:stealthRockOnAdd", { opponentDesc: source.getOpponentDescriptor() })); + globalScene.queueMessage(i18next.t("arenaTag:stealthRockOnAdd", { opponentDesc: source.getOpponentDescriptor() })); } } @@ -864,7 +862,7 @@ class StealthRockTag extends ArenaTrapTag { return true; } const damage = toDmgValue(pokemon.getMaxHp() * damageHpRatio); - pokemon.scene.queueMessage(i18next.t("arenaTag:stealthRockActivateTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("arenaTag:stealthRockActivateTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); pokemon.damageAndUpdate(damage, HitResult.OTHER); if (pokemon.turnData) { pokemon.turnData.damageTaken += damage; @@ -893,9 +891,9 @@ class StickyWebTag extends ArenaTrapTag { onAdd(arena: Arena, quiet: boolean = false): void { super.onAdd(arena); - const source = this.sourceId ? arena.scene.getPokemonById(this.sourceId) : null; + const source = this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; if (!quiet && source) { - arena.scene.queueMessage(i18next.t("arenaTag:stickyWebOnAdd", { moveName: this.getMoveName(), opponentDesc: source.getOpponentDescriptor() })); + globalScene.queueMessage(i18next.t("arenaTag:stickyWebOnAdd", { moveName: this.getMoveName(), opponentDesc: source.getOpponentDescriptor() })); } } @@ -909,9 +907,9 @@ class StickyWebTag extends ArenaTrapTag { } if (!cancelled.value) { - pokemon.scene.queueMessage(i18next.t("arenaTag:stickyWebActivateTrap", { pokemonName: pokemon.getNameToRender() })); + globalScene.queueMessage(i18next.t("arenaTag:stickyWebActivateTrap", { pokemonName: pokemon.getNameToRender() })); const stages = new NumberHolder(-1); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, [ Stat.SPD ], stages.value)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), false, [ Stat.SPD ], stages.value)); return true; } } @@ -945,14 +943,14 @@ export class TrickRoomTag extends ArenaTag { } onAdd(arena: Arena): void { - const source = this.sourceId ? arena.scene.getPokemonById(this.sourceId) : null; + const source = this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; if (source) { - arena.scene.queueMessage(i18next.t("arenaTag:trickRoomOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); + globalScene.queueMessage(i18next.t("arenaTag:trickRoomOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); } } onRemove(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:trickRoomOnRemove")); + globalScene.queueMessage(i18next.t("arenaTag:trickRoomOnRemove")); } } @@ -967,8 +965,8 @@ export class GravityTag extends ArenaTag { } onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:gravityOnAdd")); - arena.scene.getField(true).forEach((pokemon) => { + globalScene.queueMessage(i18next.t("arenaTag:gravityOnAdd")); + globalScene.getField(true).forEach((pokemon) => { if (pokemon !== null) { pokemon.removeTag(BattlerTagType.FLOATING); pokemon.removeTag(BattlerTagType.TELEKINESIS); @@ -980,7 +978,7 @@ export class GravityTag extends ArenaTag { } onRemove(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:gravityOnRemove")); + globalScene.queueMessage(i18next.t("arenaTag:gravityOnRemove")); } } @@ -996,29 +994,29 @@ class TailwindTag extends ArenaTag { onAdd(arena: Arena, quiet: boolean = false): void { if (!quiet) { - arena.scene.queueMessage(i18next.t(`arenaTag:tailwindOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:tailwindOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } - const source = arena.scene.getPokemonById(this.sourceId!); //TODO: this bang is questionable! - const party = (source?.isPlayer() ? source.scene.getPlayerField() : source?.scene.getEnemyField()) ?? []; + const source = globalScene.getPokemonById(this.sourceId!); //TODO: this bang is questionable! + const party = (source?.isPlayer() ? globalScene.getPlayerField() : globalScene.getEnemyField()) ?? []; for (const pokemon of party) { // Apply the CHARGED tag to party members with the WIND_POWER ability if (pokemon.hasAbility(Abilities.WIND_POWER) && !pokemon.getTag(BattlerTagType.CHARGED)) { pokemon.addTag(BattlerTagType.CHARGED); - pokemon.scene.queueMessage(i18next.t("abilityTriggers:windPowerCharged", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: this.getMoveName() })); + globalScene.queueMessage(i18next.t("abilityTriggers:windPowerCharged", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: this.getMoveName() })); } // Raise attack by one stage if party member has WIND_RIDER ability if (pokemon.hasAbility(Abilities.WIND_RIDER)) { - pokemon.scene.unshiftPhase(new ShowAbilityPhase(pokemon.scene, pokemon.getBattlerIndex())); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.ATK ], 1, true)); + globalScene.unshiftPhase(new ShowAbilityPhase(pokemon.getBattlerIndex())); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.ATK ], 1, true)); } } } onRemove(arena: Arena, quiet: boolean = false): void { if (!quiet) { - arena.scene.queueMessage(i18next.t(`arenaTag:tailwindOnRemove${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:tailwindOnRemove${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } } } @@ -1033,11 +1031,11 @@ class HappyHourTag extends ArenaTag { } onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:happyHourOnAdd")); + globalScene.queueMessage(i18next.t("arenaTag:happyHourOnAdd")); } onRemove(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:happyHourOnRemove")); + globalScene.queueMessage(i18next.t("arenaTag:happyHourOnRemove")); } } @@ -1047,11 +1045,11 @@ class SafeguardTag extends ArenaTag { } onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t(`arenaTag:safeguardOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:safeguardOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } onRemove(arena: Arena): void { - arena.scene.queueMessage(i18next.t(`arenaTag:safeguardOnRemove${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:safeguardOnRemove${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } } @@ -1074,16 +1072,16 @@ class ImprisonTag extends ArenaTrapTag { * This function applies the effects of Imprison to the opposing Pokemon already present on the field. * @param arena */ - override onAdd({ scene }: Arena) { - const source = this.getSourcePokemon(scene); + override onAdd() { + const source = this.getSourcePokemon(); if (source) { - const party = this.getAffectedPokemon(scene); + const party = this.getAffectedPokemon(); party?.forEach((p: Pokemon ) => { if (p.isAllowedInBattle()) { p.addTag(BattlerTagType.IMPRISON, 1, Moves.IMPRISON, this.sourceId); } }); - scene.queueMessage(i18next.t("battlerTags:imprisonOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); + globalScene.queueMessage(i18next.t("battlerTags:imprisonOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(source) })); } } @@ -1092,8 +1090,8 @@ class ImprisonTag extends ArenaTrapTag { * @param _arena * @returns `true` if the source of the tag is still active on the field | `false` if not */ - override lapse({ scene }: Arena): boolean { - const source = this.getSourcePokemon(scene); + override lapse(): boolean { + const source = this.getSourcePokemon(); return source ? source.isActive(true) : false; } @@ -1103,7 +1101,7 @@ class ImprisonTag extends ArenaTrapTag { * @returns `true` */ override activateTrap(pokemon: Pokemon): boolean { - const source = this.getSourcePokemon(pokemon.scene); + const source = this.getSourcePokemon(); if (source && source.isActive(true) && pokemon.isAllowedInBattle()) { pokemon.addTag(BattlerTagType.IMPRISON, 1, Moves.IMPRISON, this.sourceId); } @@ -1114,8 +1112,8 @@ class ImprisonTag extends ArenaTrapTag { * When the arena tag is removed, it also attempts to remove any related Battler Tags if they haven't already been removed from the affected Pokemon * @param arena */ - override onRemove({ scene }: Arena): void { - const party = this.getAffectedPokemon(scene); + override onRemove(): void { + const party = this.getAffectedPokemon(); party?.forEach((p: Pokemon) => { p.removeTag(BattlerTagType.IMPRISON); }); @@ -1136,19 +1134,19 @@ class FireGrassPledgeTag extends ArenaTag { override onAdd(arena: Arena): void { // "A sea of fire enveloped your/the opposing team!" - arena.scene.queueMessage(i18next.t(`arenaTag:fireGrassPledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:fireGrassPledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } override lapse(arena: Arena): boolean { const field: Pokemon[] = (this.side === ArenaTagSide.PLAYER) - ? arena.scene.getPlayerField() - : arena.scene.getEnemyField(); + ? globalScene.getPlayerField() + : globalScene.getEnemyField(); field.filter(pokemon => !pokemon.isOfType(Type.FIRE) && !pokemon.switchOutStatus).forEach(pokemon => { // "{pokemonNameWithAffix} was hurt by the sea of fire!" - pokemon.scene.queueMessage(i18next.t("arenaTag:fireGrassPledgeLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("arenaTag:fireGrassPledgeLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); // TODO: Replace this with a proper animation - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.MAGMA_STORM)); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.MAGMA_STORM)); pokemon.damageAndUpdate(toDmgValue(pokemon.getMaxHp() / 8)); }); @@ -1170,7 +1168,7 @@ class WaterFirePledgeTag extends ArenaTag { override onAdd(arena: Arena): void { // "A rainbow appeared in the sky on your/the opposing team's side!" - arena.scene.queueMessage(i18next.t(`arenaTag:waterFirePledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:waterFirePledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } /** @@ -1200,7 +1198,7 @@ class GrassWaterPledgeTag extends ArenaTag { override onAdd(arena: Arena): void { // "A swamp enveloped your/the opposing team!" - arena.scene.queueMessage(i18next.t(`arenaTag:grassWaterPledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); + globalScene.queueMessage(i18next.t(`arenaTag:grassWaterPledgeOnAdd${this.side === ArenaTagSide.PLAYER ? "Player" : this.side === ArenaTagSide.ENEMY ? "Enemy" : ""}`)); } } @@ -1217,7 +1215,7 @@ export class FairyLockTag extends ArenaTag { } onAdd(arena: Arena): void { - arena.scene.queueMessage(i18next.t("arenaTag:fairyLockOnAdd")); + globalScene.queueMessage(i18next.t("arenaTag:fairyLockOnAdd")); } } diff --git a/src/data/balance/pokemon-evolutions.ts b/src/data/balance/pokemon-evolutions.ts index 9e86ea7397bb..1f69dbe25633 100644 --- a/src/data/balance/pokemon-evolutions.ts +++ b/src/data/balance/pokemon-evolutions.ts @@ -1,3 +1,4 @@ +import { globalScene } from "#app/global-scene"; import { Gender } from "#app/data/gender"; import { PokeballType } from "#enums/pokeball"; import Pokemon from "#app/field/pokemon"; @@ -266,8 +267,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.ELECTRODE, 30, null, null) ], [Species.CUBONE]: [ - new SpeciesEvolution(Species.ALOLA_MAROWAK, 28, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.MAROWAK, 28, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.ALOLA_MAROWAK, 28, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.MAROWAK, 28, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.TYROGUE]: [ /** @@ -287,8 +288,8 @@ export const pokemonEvolutions: PokemonEvolutions = { )), ], [Species.KOFFING]: [ - new SpeciesEvolution(Species.GALAR_WEEZING, 35, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.WEEZING, 35, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.GALAR_WEEZING, 35, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.WEEZING, 35, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.RHYHORN]: [ new SpeciesEvolution(Species.RHYDON, 42, null, null) @@ -333,8 +334,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.QUILAVA, 14, null, null) ], [Species.QUILAVA]: [ - new SpeciesEvolution(Species.HISUI_TYPHLOSION, 36, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.TYPHLOSION, 36, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.HISUI_TYPHLOSION, 36, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.TYPHLOSION, 36, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.TOTODILE]: [ new SpeciesEvolution(Species.CROCONAW, 18, null, null) @@ -436,8 +437,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.LINOONE, 20, null, null) ], [Species.WURMPLE]: [ - new SpeciesEvolution(Species.SILCOON, 7, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)), - new SpeciesEvolution(Species.CASCOON, 7, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) + new SpeciesEvolution(Species.SILCOON, 7, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)), + new SpeciesEvolution(Species.CASCOON, 7, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) ], [Species.SILCOON]: [ new SpeciesEvolution(Species.BEAUTIFLY, 10, null, null) @@ -478,7 +479,7 @@ export const pokemonEvolutions: PokemonEvolutions = { ], [Species.NINCADA]: [ new SpeciesEvolution(Species.NINJASK, 20, null, null), - new SpeciesEvolution(Species.SHEDINJA, 20, null, new SpeciesEvolutionCondition(p => p.scene.getPlayerParty().length < 6 && p.scene.pokeballCounts[PokeballType.POKEBALL] > 0)) + new SpeciesEvolution(Species.SHEDINJA, 20, null, new SpeciesEvolutionCondition(p => globalScene.getPlayerParty().length < 6 && globalScene.pokeballCounts[PokeballType.POKEBALL] > 0)) ], [Species.WHISMUR]: [ new SpeciesEvolution(Species.LOUDRED, 20, null, null) @@ -660,7 +661,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.LUMINEON, 31, null, null) ], [Species.MANTYKE]: [ - new SpeciesEvolution(Species.MANTINE, 32, null, new SpeciesEvolutionCondition(p => !!p.scene.gameData.dexData[Species.REMORAID].caughtAttr), SpeciesWildEvolutionDelay.MEDIUM) + new SpeciesEvolution(Species.MANTINE, 32, null, new SpeciesEvolutionCondition(p => !!globalScene.gameData.dexData[Species.REMORAID].caughtAttr), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.SNOVER]: [ new SpeciesEvolution(Species.ABOMASNOW, 40, null, null) @@ -681,8 +682,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.DEWOTT, 17, null, null) ], [Species.DEWOTT]: [ - new SpeciesEvolution(Species.HISUI_SAMUROTT, 36, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.SAMUROTT, 36, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.HISUI_SAMUROTT, 36, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.SAMUROTT, 36, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.PATRAT]: [ new SpeciesEvolution(Species.WATCHOG, 20, null, null) @@ -832,8 +833,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.KINGAMBIT, 1, EvolutionItem.LEADERS_CREST, null, SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.RUFFLET]: [ - new SpeciesEvolution(Species.HISUI_BRAVIARY, 54, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.BRAVIARY, 54, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.HISUI_BRAVIARY, 54, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.BRAVIARY, 54, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.VULLABY]: [ new SpeciesEvolution(Species.MANDIBUZZ, 54, null, null) @@ -890,7 +891,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.GOGOAT, 32, null, null) ], [Species.PANCHAM]: [ - new SpeciesEvolution(Species.PANGORO, 32, null, new SpeciesEvolutionCondition(p => !!p.scene.getPlayerParty().find(p => p.getTypes(false, false, true).indexOf(Type.DARK) > -1)), SpeciesWildEvolutionDelay.MEDIUM) + new SpeciesEvolution(Species.PANGORO, 32, null, new SpeciesEvolutionCondition(p => !!globalScene.getPlayerParty().find(p => p.getTypes(false, false, true).indexOf(Type.DARK) > -1)), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.ESPURR]: [ new SpeciesFormEvolution(Species.MEOWSTIC, "", "female", 25, null, new SpeciesEvolutionCondition(p => p.gender === Gender.FEMALE, p => p.gender = Gender.FEMALE)), @@ -912,21 +913,21 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.CLAWITZER, 37, null, null) ], [Species.TYRUNT]: [ - new SpeciesEvolution(Species.TYRANTRUM, 39, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.TYRANTRUM, 39, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.AMAURA]: [ - new SpeciesEvolution(Species.AURORUS, 39, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) + new SpeciesEvolution(Species.AURORUS, 39, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) ], [Species.GOOMY]: [ - new SpeciesEvolution(Species.HISUI_SLIGGOO, 40, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.SLIGGOO, 40, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.HISUI_SLIGGOO, 40, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.SLIGGOO, 40, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.SLIGGOO]: [ - new SpeciesEvolution(Species.GOODRA, 50, null, new SpeciesEvolutionCondition(p => [ WeatherType.RAIN, WeatherType.FOG, WeatherType.HEAVY_RAIN ].indexOf(p.scene.arena.weather?.weatherType || WeatherType.NONE) > -1), SpeciesWildEvolutionDelay.LONG) + new SpeciesEvolution(Species.GOODRA, 50, null, new SpeciesEvolutionCondition(p => [ WeatherType.RAIN, WeatherType.FOG, WeatherType.HEAVY_RAIN ].indexOf(globalScene.arena.weather?.weatherType || WeatherType.NONE) > -1), SpeciesWildEvolutionDelay.LONG) ], [Species.BERGMITE]: [ - new SpeciesEvolution(Species.HISUI_AVALUGG, 37, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.AVALUGG, 37, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.HISUI_AVALUGG, 37, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.AVALUGG, 37, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.NOIBAT]: [ new SpeciesEvolution(Species.NOIVERN, 48, null, null) @@ -935,8 +936,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.DARTRIX, 17, null, null) ], [Species.DARTRIX]: [ - new SpeciesEvolution(Species.HISUI_DECIDUEYE, 36, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), - new SpeciesEvolution(Species.DECIDUEYE, 34, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.HISUI_DECIDUEYE, 36, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), + new SpeciesEvolution(Species.DECIDUEYE, 34, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.LITTEN]: [ new SpeciesEvolution(Species.TORRACAT, 17, null, null) @@ -957,7 +958,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.TOUCANNON, 28, null, null) ], [Species.YUNGOOS]: [ - new SpeciesEvolution(Species.GUMSHOOS, 20, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.GUMSHOOS, 20, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.GRUBBIN]: [ new SpeciesEvolution(Species.CHARJABUG, 20, null, null) @@ -975,7 +976,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.ARAQUANID, 22, null, null) ], [Species.FOMANTIS]: [ - new SpeciesEvolution(Species.LURANTIS, 34, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)) + new SpeciesEvolution(Species.LURANTIS, 34, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)) ], [Species.MORELULL]: [ new SpeciesEvolution(Species.SHIINOTIC, 24, null, null) @@ -1012,7 +1013,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.MELMETAL, 48, null, null) ], [Species.ALOLA_RATTATA]: [ - new SpeciesEvolution(Species.ALOLA_RATICATE, 20, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) + new SpeciesEvolution(Species.ALOLA_RATICATE, 20, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) ], [Species.ALOLA_DIGLETT]: [ new SpeciesEvolution(Species.ALOLA_DUGTRIO, 26, null, null) @@ -1135,7 +1136,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.GALAR_LINOONE, 20, null, null) ], [Species.GALAR_LINOONE]: [ - new SpeciesEvolution(Species.OBSTAGOON, 35, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) + new SpeciesEvolution(Species.OBSTAGOON, 35, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) ], [Species.GALAR_YAMASK]: [ new SpeciesEvolution(Species.RUNERIGUS, 34, null, null) @@ -1144,7 +1145,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.HISUI_ZOROARK, 30, null, null) ], [Species.HISUI_SLIGGOO]: [ - new SpeciesEvolution(Species.HISUI_GOODRA, 50, null, new SpeciesEvolutionCondition(p => [ WeatherType.RAIN, WeatherType.FOG, WeatherType.HEAVY_RAIN ].indexOf(p.scene.arena.weather?.weatherType || WeatherType.NONE) > -1), SpeciesWildEvolutionDelay.LONG) + new SpeciesEvolution(Species.HISUI_GOODRA, 50, null, new SpeciesEvolutionCondition(p => [ WeatherType.RAIN, WeatherType.FOG, WeatherType.HEAVY_RAIN ].indexOf(globalScene.arena.weather?.weatherType || WeatherType.NONE) > -1), SpeciesWildEvolutionDelay.LONG) ], [Species.SPRIGATITO]: [ new SpeciesEvolution(Species.FLORAGATO, 16, null, null) @@ -1183,7 +1184,7 @@ export const pokemonEvolutions: PokemonEvolutions = { [Species.TANDEMAUS]: [ new SpeciesFormEvolution(Species.MAUSHOLD, "", "three", 25, null, new SpeciesEvolutionCondition(p => { let ret = false; - p.scene.executeWithSeedOffset(() => ret = !Utils.randSeedInt(4), p.id); + globalScene.executeWithSeedOffset(() => ret = !Utils.randSeedInt(4), p.id); return ret; })), new SpeciesEvolution(Species.MAUSHOLD, 25, null, null) @@ -1243,7 +1244,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.GLIMMORA, 35, null, null) ], [Species.GREAVARD]: [ - new SpeciesEvolution(Species.HOUNDSTONE, 30, null, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) + new SpeciesEvolution(Species.HOUNDSTONE, 30, null, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)) ], [Species.FRIGIBAX]: [ new SpeciesEvolution(Species.ARCTIBAX, 35, null, null) @@ -1311,10 +1312,10 @@ export const pokemonEvolutions: PokemonEvolutions = { [Species.EEVEE]: [ new SpeciesFormEvolution(Species.SYLVEON, "", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => !!p.getMoveset().find(m => m?.getMove().type === Type.FAIRY)), SpeciesWildEvolutionDelay.LONG), new SpeciesFormEvolution(Species.SYLVEON, "partner", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => !!p.getMoveset().find(m => m?.getMove().type === Type.FAIRY)), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ESPEON, "", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ESPEON, "partner", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.UMBREON, "", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.UMBREON, "partner", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ESPEON, "", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ESPEON, "partner", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.UMBREON, "", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.UMBREON, "partner", "", 1, null, new SpeciesFriendshipEvolutionCondition(120, p => globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.LONG), new SpeciesFormEvolution(Species.VAPOREON, "", "", 1, EvolutionItem.WATER_STONE, null, SpeciesWildEvolutionDelay.LONG), new SpeciesFormEvolution(Species.VAPOREON, "partner", "", 1, EvolutionItem.WATER_STONE, null, SpeciesWildEvolutionDelay.LONG), new SpeciesFormEvolution(Species.JOLTEON, "", "", 1, EvolutionItem.THUNDER_STONE, null, SpeciesWildEvolutionDelay.LONG), @@ -1351,17 +1352,17 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesFormEvolution(Species.DUDUNSPARCE, "", "three-segment", 32, null, new SpeciesEvolutionCondition(p => { let ret = false; if (p.moveset.filter(m => m?.moveId === Moves.HYPER_DRILL).length > 0) { - p.scene.executeWithSeedOffset(() => ret = !Utils.randSeedInt(4), p.id); + globalScene.executeWithSeedOffset(() => ret = !Utils.randSeedInt(4), p.id); } return ret; }), SpeciesWildEvolutionDelay.LONG), new SpeciesEvolution(Species.DUDUNSPARCE, 32, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.HYPER_DRILL).length > 0), SpeciesWildEvolutionDelay.LONG) ], [Species.GLIGAR]: [ - new SpeciesEvolution(Species.GLISCOR, 1, EvolutionItem.RAZOR_FANG, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT /* Razor fang at night*/), SpeciesWildEvolutionDelay.VERY_LONG) + new SpeciesEvolution(Species.GLISCOR, 1, EvolutionItem.RAZOR_FANG, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT /* Razor fang at night*/), SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.SNEASEL]: [ - new SpeciesEvolution(Species.WEAVILE, 1, EvolutionItem.RAZOR_CLAW, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT /* Razor claw at night*/), SpeciesWildEvolutionDelay.VERY_LONG) + new SpeciesEvolution(Species.WEAVILE, 1, EvolutionItem.RAZOR_CLAW, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT /* Razor claw at night*/), SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.URSARING]: [ new SpeciesEvolution(Species.URSALUNA, 1, EvolutionItem.PEAT_BLOCK, null, SpeciesWildEvolutionDelay.VERY_LONG) //Ursaring does not evolve into Bloodmoon Ursaluna @@ -1391,8 +1392,8 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.SUDOWOODO, 1, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.MIMIC).length > 0), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.MIME_JR]: [ - new SpeciesEvolution(Species.GALAR_MR_MIME, 1, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.MIMIC).length > 0 && (p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), SpeciesWildEvolutionDelay.MEDIUM), - new SpeciesEvolution(Species.MR_MIME, 1, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.MIMIC).length > 0 && (p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY)), SpeciesWildEvolutionDelay.MEDIUM) + new SpeciesEvolution(Species.GALAR_MR_MIME, 1, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.MIMIC).length > 0 && (globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT)), SpeciesWildEvolutionDelay.MEDIUM), + new SpeciesEvolution(Species.MR_MIME, 1, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.MIMIC).length > 0 && (globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY)), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.PANSAGE]: [ new SpeciesEvolution(Species.SIMISAGE, 1, EvolutionItem.LEAF_STONE, null, SpeciesWildEvolutionDelay.LONG) @@ -1442,9 +1443,9 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.CRABOMINABLE, 1, EvolutionItem.ICE_STONE, null, SpeciesWildEvolutionDelay.LONG) ], [Species.ROCKRUFF]: [ - new SpeciesFormEvolution(Species.LYCANROC, "", "midday", 25, null, new SpeciesEvolutionCondition(p => (p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY) && (p.formIndex === 0))), + new SpeciesFormEvolution(Species.LYCANROC, "", "midday", 25, null, new SpeciesEvolutionCondition(p => (globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY) && (p.formIndex === 0))), new SpeciesFormEvolution(Species.LYCANROC, "own-tempo", "dusk", 25, null, new SpeciesEvolutionCondition(p => p.formIndex === 1)), - new SpeciesFormEvolution(Species.LYCANROC, "", "midnight", 25, null, new SpeciesEvolutionCondition(p => (p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT) && (p.formIndex === 0))) + new SpeciesFormEvolution(Species.LYCANROC, "", "midnight", 25, null, new SpeciesEvolutionCondition(p => (globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT) && (p.formIndex === 0))) ], [Species.STEENEE]: [ new SpeciesEvolution(Species.TSAREENA, 28, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.STOMP).length > 0), SpeciesWildEvolutionDelay.LONG) @@ -1471,15 +1472,15 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesFormEvolution(Species.POLTEAGEIST, "antique", "antique", 1, EvolutionItem.CHIPPED_POT, null, SpeciesWildEvolutionDelay.LONG) ], [Species.MILCERY]: [ - new SpeciesFormEvolution(Species.ALCREMIE, "", "vanilla-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.TOWN || p.scene.arena.biomeType === Biome.PLAINS || p.scene.arena.biomeType === Biome.GRASS || p.scene.arena.biomeType === Biome.TALL_GRASS || p.scene.arena.biomeType === Biome.METROPOLIS), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "ruby-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.BADLANDS || p.scene.arena.biomeType === Biome.VOLCANO || p.scene.arena.biomeType === Biome.GRAVEYARD || p.scene.arena.biomeType === Biome.FACTORY || p.scene.arena.biomeType === Biome.SLUM), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "matcha-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.FOREST || p.scene.arena.biomeType === Biome.SWAMP || p.scene.arena.biomeType === Biome.MEADOW || p.scene.arena.biomeType === Biome.JUNGLE), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "mint-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.SEA || p.scene.arena.biomeType === Biome.BEACH || p.scene.arena.biomeType === Biome.LAKE || p.scene.arena.biomeType === Biome.SEABED), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "lemon-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.DESERT || p.scene.arena.biomeType === Biome.POWER_PLANT || p.scene.arena.biomeType === Biome.DOJO || p.scene.arena.biomeType === Biome.RUINS || p.scene.arena.biomeType === Biome.CONSTRUCTION_SITE), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "salted-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.MOUNTAIN || p.scene.arena.biomeType === Biome.CAVE || p.scene.arena.biomeType === Biome.ICE_CAVE || p.scene.arena.biomeType === Biome.FAIRY_CAVE || p.scene.arena.biomeType === Biome.SNOWY_FOREST), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "ruby-swirl", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.WASTELAND || p.scene.arena.biomeType === Biome.LABORATORY), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "caramel-swirl", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.TEMPLE || p.scene.arena.biomeType === Biome.ISLAND), SpeciesWildEvolutionDelay.LONG), - new SpeciesFormEvolution(Species.ALCREMIE, "", "rainbow-swirl", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => p.scene.arena.biomeType === Biome.ABYSS || p.scene.arena.biomeType === Biome.SPACE || p.scene.arena.biomeType === Biome.END), SpeciesWildEvolutionDelay.LONG) + new SpeciesFormEvolution(Species.ALCREMIE, "", "vanilla-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.TOWN || globalScene.arena.biomeType === Biome.PLAINS || globalScene.arena.biomeType === Biome.GRASS || globalScene.arena.biomeType === Biome.TALL_GRASS || globalScene.arena.biomeType === Biome.METROPOLIS), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "ruby-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.BADLANDS || globalScene.arena.biomeType === Biome.VOLCANO || globalScene.arena.biomeType === Biome.GRAVEYARD || globalScene.arena.biomeType === Biome.FACTORY || globalScene.arena.biomeType === Biome.SLUM), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "matcha-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.FOREST || globalScene.arena.biomeType === Biome.SWAMP || globalScene.arena.biomeType === Biome.MEADOW || globalScene.arena.biomeType === Biome.JUNGLE), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "mint-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.SEA || globalScene.arena.biomeType === Biome.BEACH || globalScene.arena.biomeType === Biome.LAKE || globalScene.arena.biomeType === Biome.SEABED), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "lemon-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.DESERT || globalScene.arena.biomeType === Biome.POWER_PLANT || globalScene.arena.biomeType === Biome.DOJO || globalScene.arena.biomeType === Biome.RUINS || globalScene.arena.biomeType === Biome.CONSTRUCTION_SITE), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "salted-cream", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.MOUNTAIN || globalScene.arena.biomeType === Biome.CAVE || globalScene.arena.biomeType === Biome.ICE_CAVE || globalScene.arena.biomeType === Biome.FAIRY_CAVE || globalScene.arena.biomeType === Biome.SNOWY_FOREST), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "ruby-swirl", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.WASTELAND || globalScene.arena.biomeType === Biome.LABORATORY), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "caramel-swirl", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.TEMPLE || globalScene.arena.biomeType === Biome.ISLAND), SpeciesWildEvolutionDelay.LONG), + new SpeciesFormEvolution(Species.ALCREMIE, "", "rainbow-swirl", 1, EvolutionItem.STRAWBERRY_SWEET, new SpeciesEvolutionCondition(p => globalScene.arena.biomeType === Biome.ABYSS || globalScene.arena.biomeType === Biome.SPACE || globalScene.arena.biomeType === Biome.END), SpeciesWildEvolutionDelay.LONG) ], [Species.DURALUDON]: [ new SpeciesFormEvolution(Species.ARCHALUDON, "", "", 1, EvolutionItem.METAL_ALLOY, null, SpeciesWildEvolutionDelay.VERY_LONG) @@ -1501,7 +1502,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.OVERQWIL, 28, null, new SpeciesEvolutionCondition(p => p.moveset.filter(m => m?.moveId === Moves.BARB_BARRAGE).length > 0), SpeciesWildEvolutionDelay.LONG) ], [Species.HISUI_SNEASEL]: [ - new SpeciesEvolution(Species.SNEASLER, 1, EvolutionItem.RAZOR_CLAW, new SpeciesEvolutionCondition(p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY /* Razor claw at day*/), SpeciesWildEvolutionDelay.VERY_LONG) + new SpeciesEvolution(Species.SNEASLER, 1, EvolutionItem.RAZOR_CLAW, new SpeciesEvolutionCondition(p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY /* Razor claw at day*/), SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.CHARCADET]: [ new SpeciesEvolution(Species.ARMAROUGE, 1, EvolutionItem.AUSPICIOUS_ARMOR, null, SpeciesWildEvolutionDelay.LONG), @@ -1581,10 +1582,10 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.CONKELDURR, 1, EvolutionItem.LINKING_CORD, null, SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.KARRABLAST]: [ - new SpeciesEvolution(Species.ESCAVALIER, 1, EvolutionItem.LINKING_CORD, new SpeciesEvolutionCondition(p => !!p.scene.gameData.dexData[Species.SHELMET].caughtAttr), SpeciesWildEvolutionDelay.VERY_LONG) + new SpeciesEvolution(Species.ESCAVALIER, 1, EvolutionItem.LINKING_CORD, new SpeciesEvolutionCondition(p => !!globalScene.gameData.dexData[Species.SHELMET].caughtAttr), SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.SHELMET]: [ - new SpeciesEvolution(Species.ACCELGOR, 1, EvolutionItem.LINKING_CORD, new SpeciesEvolutionCondition(p => !!p.scene.gameData.dexData[Species.KARRABLAST].caughtAttr), SpeciesWildEvolutionDelay.VERY_LONG) + new SpeciesEvolution(Species.ACCELGOR, 1, EvolutionItem.LINKING_CORD, new SpeciesEvolutionCondition(p => !!globalScene.gameData.dexData[Species.KARRABLAST].caughtAttr), SpeciesWildEvolutionDelay.VERY_LONG) ], [Species.SPRITZEE]: [ new SpeciesEvolution(Species.AROMATISSE, 1, EvolutionItem.SACHET, null, SpeciesWildEvolutionDelay.VERY_LONG) @@ -1627,13 +1628,13 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.MARILL, 1, null, new SpeciesFriendshipEvolutionCondition(70), SpeciesWildEvolutionDelay.SHORT) ], [Species.BUDEW]: [ - new SpeciesEvolution(Species.ROSELIA, 1, null, new SpeciesFriendshipEvolutionCondition(70, p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.SHORT) + new SpeciesEvolution(Species.ROSELIA, 1, null, new SpeciesFriendshipEvolutionCondition(70, p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.SHORT) ], [Species.BUNEARY]: [ new SpeciesEvolution(Species.LOPUNNY, 1, null, new SpeciesFriendshipEvolutionCondition(70), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.CHINGLING]: [ - new SpeciesEvolution(Species.CHIMECHO, 1, null, new SpeciesFriendshipEvolutionCondition(90, p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.MEDIUM) + new SpeciesEvolution(Species.CHIMECHO, 1, null, new SpeciesFriendshipEvolutionCondition(90, p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.HAPPINY]: [ new SpeciesEvolution(Species.CHANSEY, 1, null, new SpeciesFriendshipEvolutionCondition(160), SpeciesWildEvolutionDelay.SHORT) @@ -1642,7 +1643,7 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.SNORLAX, 1, null, new SpeciesFriendshipEvolutionCondition(120), SpeciesWildEvolutionDelay.LONG) ], [Species.RIOLU]: [ - new SpeciesEvolution(Species.LUCARIO, 1, null, new SpeciesFriendshipEvolutionCondition(120, p => p.scene.arena.getTimeOfDay() === TimeOfDay.DAWN || p.scene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.LONG) + new SpeciesEvolution(Species.LUCARIO, 1, null, new SpeciesFriendshipEvolutionCondition(120, p => globalScene.arena.getTimeOfDay() === TimeOfDay.DAWN || globalScene.arena.getTimeOfDay() === TimeOfDay.DAY), SpeciesWildEvolutionDelay.LONG) ], [Species.WOOBAT]: [ new SpeciesEvolution(Species.SWOOBAT, 1, null, new SpeciesFriendshipEvolutionCondition(90), SpeciesWildEvolutionDelay.MEDIUM) @@ -1657,16 +1658,16 @@ export const pokemonEvolutions: PokemonEvolutions = { new SpeciesEvolution(Species.ALOLA_PERSIAN, 1, null, new SpeciesFriendshipEvolutionCondition(120), SpeciesWildEvolutionDelay.LONG) ], [Species.SNOM]: [ - new SpeciesEvolution(Species.FROSMOTH, 1, null, new SpeciesFriendshipEvolutionCondition(90, p => p.scene.arena.getTimeOfDay() === TimeOfDay.DUSK || p.scene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.MEDIUM) + new SpeciesEvolution(Species.FROSMOTH, 1, null, new SpeciesFriendshipEvolutionCondition(90, p => globalScene.arena.getTimeOfDay() === TimeOfDay.DUSK || globalScene.arena.getTimeOfDay() === TimeOfDay.NIGHT), SpeciesWildEvolutionDelay.MEDIUM) ], [Species.GIMMIGHOUL]: [ new SpeciesFormEvolution(Species.GHOLDENGO, "chest", "", 1, null, new SpeciesEvolutionCondition(p => p.evoCounter + p.getHeldItems().filter(m => m instanceof DamageMoneyRewardModifier).length - + p.scene.findModifiers(m => m instanceof MoneyMultiplierModifier + + globalScene.findModifiers(m => m instanceof MoneyMultiplierModifier || m instanceof ExtraModifierModifier || m instanceof TempExtraModifierModifier).length > 9), SpeciesWildEvolutionDelay.VERY_LONG), new SpeciesFormEvolution(Species.GHOLDENGO, "roaming", "", 1, null, new SpeciesEvolutionCondition(p => p.evoCounter + p.getHeldItems().filter(m => m instanceof DamageMoneyRewardModifier).length - + p.scene.findModifiers(m => m instanceof MoneyMultiplierModifier + + globalScene.findModifiers(m => m instanceof MoneyMultiplierModifier || m instanceof ExtraModifierModifier || m instanceof TempExtraModifierModifier).length > 9), SpeciesWildEvolutionDelay.VERY_LONG) ] }; diff --git a/src/data/battle-anims.ts b/src/data/battle-anims.ts index 26ad65bd9b01..45737b22fd4b 100644 --- a/src/data/battle-anims.ts +++ b/src/data/battle-anims.ts @@ -1,5 +1,4 @@ -//import { battleAnimRawData } from "./battle-anim-raw-data"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { AttackMove, BeakBlastHeaderAttr, DelayedAttackAttr, MoveFlags, SelfStatusMove, allMoves } from "./move"; import Pokemon from "../field/pokemon"; import * as Utils from "../utils"; @@ -10,7 +9,6 @@ import { SubstituteTag } from "./battler-tags"; import { isNullOrUndefined } from "../utils"; import Phaser from "phaser"; import { EncounterAnim } from "#enums/encounter-anims"; -//import fs from 'vite-plugin-fs/browser'; export enum AnimFrameTarget { USER, @@ -308,7 +306,7 @@ abstract class AnimTimedEvent { this.resourceName = resourceName; } - abstract execute(scene: BattleScene, battleAnim: BattleAnim, priority?: number): integer; + abstract execute(battleAnim: BattleAnim, priority?: number): integer; abstract getEventType(): string; } @@ -326,15 +324,15 @@ class AnimTimedSoundEvent extends AnimTimedEvent { } } - execute(scene: BattleScene, battleAnim: BattleAnim, priority?: number): integer { + execute(battleAnim: BattleAnim, priority?: number): integer { const soundConfig = { rate: (this.pitch * 0.01), volume: (this.volume * 0.01) }; if (this.resourceName) { try { - scene.playSound(`battle_anims/${this.resourceName}`, soundConfig); + globalScene.playSound(`battle_anims/${this.resourceName}`, soundConfig); } catch (err) { console.error(err); } - return Math.ceil((scene.sound.get(`battle_anims/${this.resourceName}`).totalDuration * 1000) / 33.33); + return Math.ceil((globalScene.sound.get(`battle_anims/${this.resourceName}`).totalDuration * 1000) / 33.33); } else { return Math.ceil((battleAnim.user!.cry(soundConfig).totalDuration * 1000) / 33.33); // TODO: is the bang behind user correct? } @@ -388,7 +386,7 @@ class AnimTimedUpdateBgEvent extends AnimTimedBgEvent { super(frameIndex, resourceName, source); } - execute(scene: BattleScene, moveAnim: MoveAnim, priority?: number): integer { + execute(moveAnim: MoveAnim, priority?: number): integer { const tweenProps = {}; if (this.bgX !== undefined) { tweenProps["x"] = (this.bgX * 0.5) - 320; @@ -400,7 +398,7 @@ class AnimTimedUpdateBgEvent extends AnimTimedBgEvent { tweenProps["alpha"] = (this.opacity || 0) / 255; } if (Object.keys(tweenProps).length) { - scene.tweens.add(Object.assign({ + globalScene.tweens.add(Object.assign({ targets: moveAnim.bgSprite, duration: Utils.getFrameMs(this.duration * 3) }, tweenProps)); @@ -418,25 +416,25 @@ class AnimTimedAddBgEvent extends AnimTimedBgEvent { super(frameIndex, resourceName, source); } - execute(scene: BattleScene, moveAnim: MoveAnim, priority?: number): integer { + execute(moveAnim: MoveAnim, priority?: number): integer { if (moveAnim.bgSprite) { moveAnim.bgSprite.destroy(); } moveAnim.bgSprite = this.resourceName - ? scene.add.tileSprite(this.bgX - 320, this.bgY - 284, 896, 576, this.resourceName) - : scene.add.rectangle(this.bgX - 320, this.bgY - 284, 896, 576, 0); + ? globalScene.add.tileSprite(this.bgX - 320, this.bgY - 284, 896, 576, this.resourceName) + : globalScene.add.rectangle(this.bgX - 320, this.bgY - 284, 896, 576, 0); moveAnim.bgSprite.setOrigin(0, 0); moveAnim.bgSprite.setScale(1.25); moveAnim.bgSprite.setAlpha(this.opacity / 255); - scene.field.add(moveAnim.bgSprite); - const fieldPokemon = scene.getEnemyPokemon(false) ?? scene.getPlayerPokemon(false); + globalScene.field.add(moveAnim.bgSprite); + const fieldPokemon = globalScene.getEnemyPokemon(false) ?? globalScene.getPlayerPokemon(false); if (!isNullOrUndefined(priority)) { - scene.field.moveTo(moveAnim.bgSprite as Phaser.GameObjects.GameObject, priority); + globalScene.field.moveTo(moveAnim.bgSprite as Phaser.GameObjects.GameObject, priority); } else if (fieldPokemon?.isOnField()) { - scene.field.moveBelow(moveAnim.bgSprite as Phaser.GameObjects.GameObject, fieldPokemon); + globalScene.field.moveBelow(moveAnim.bgSprite as Phaser.GameObjects.GameObject, fieldPokemon); } - scene.tweens.add({ + globalScene.tweens.add({ targets: moveAnim.bgSprite, duration: Utils.getFrameMs(this.duration * 3) }); @@ -454,14 +452,14 @@ export const chargeAnims = new Map(); export const encounterAnims = new Map(); -export function initCommonAnims(scene: BattleScene): Promise { +export function initCommonAnims(): Promise { return new Promise(resolve => { const commonAnimNames = Utils.getEnumKeys(CommonAnim); const commonAnimIds = Utils.getEnumValues(CommonAnim); const commonAnimFetches: Promise>[] = []; for (let ca = 0; ca < commonAnimIds.length; ca++) { const commonAnimId = commonAnimIds[ca]; - commonAnimFetches.push(scene.cachedFetch(`./battle-anims/common-${commonAnimNames[ca].toLowerCase().replace(/\_/g, "-")}.json`) + commonAnimFetches.push(globalScene.cachedFetch(`./battle-anims/common-${commonAnimNames[ca].toLowerCase().replace(/\_/g, "-")}.json`) .then(response => response.json()) .then(cas => commonAnims.set(commonAnimId, new AnimConfig(cas)))); } @@ -469,7 +467,7 @@ export function initCommonAnims(scene: BattleScene): Promise { }); } -export function initMoveAnim(scene: BattleScene, move: Moves): Promise { +export function initMoveAnim(move: Moves): Promise { return new Promise(resolve => { if (moveAnims.has(move)) { if (moveAnims.get(move) !== null) { @@ -494,7 +492,7 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise { const defaultMoveAnim = allMoves[move] instanceof AttackMove ? Moves.TACKLE : allMoves[move] instanceof SelfStatusMove ? Moves.FOCUS_ENERGY : Moves.TAIL_WHIP; const fetchAnimAndResolve = (move: Moves) => { - scene.cachedFetch(`./battle-anims/${Utils.animationFileName(move)}.json`) + globalScene.cachedFetch(`./battle-anims/${Utils.animationFileName(move)}.json`) .then(response => { const contentType = response.headers.get("content-type"); if (!response.ok || contentType?.indexOf("application/json") === -1) { @@ -516,7 +514,7 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise { : (allMoves[move].getAttrs(DelayedAttackAttr)[0] ?? allMoves[move].getAttrs(BeakBlastHeaderAttr)[0]); if (chargeAnimSource) { - initMoveChargeAnim(scene, chargeAnimSource.chargeAnim).then(() => resolve()); + initMoveChargeAnim(chargeAnimSource.chargeAnim).then(() => resolve()); } else { resolve(); } @@ -557,10 +555,9 @@ function logMissingMoveAnim(move: Moves, ...optionalParams: any[]) { /** * Fetches animation configs to be used in a Mystery Encounter - * @param scene * @param encounterAnim one or more animations to fetch */ -export async function initEncounterAnims(scene: BattleScene, encounterAnim: EncounterAnim | EncounterAnim[]): Promise { +export async function initEncounterAnims(encounterAnim: EncounterAnim | EncounterAnim[]): Promise { const anims = Array.isArray(encounterAnim) ? encounterAnim : [ encounterAnim ]; const encounterAnimNames = Utils.getEnumKeys(EncounterAnim); const encounterAnimFetches: Promise>[] = []; @@ -568,14 +565,14 @@ export async function initEncounterAnims(scene: BattleScene, encounterAnim: Enco if (encounterAnims.has(anim) && !isNullOrUndefined(encounterAnims.get(anim))) { continue; } - encounterAnimFetches.push(scene.cachedFetch(`./battle-anims/encounter-${encounterAnimNames[anim].toLowerCase().replace(/\_/g, "-")}.json`) + encounterAnimFetches.push(globalScene.cachedFetch(`./battle-anims/encounter-${encounterAnimNames[anim].toLowerCase().replace(/\_/g, "-")}.json`) .then(response => response.json()) .then(cas => encounterAnims.set(anim, new AnimConfig(cas)))); } await Promise.allSettled(encounterAnimFetches); } -export function initMoveChargeAnim(scene: BattleScene, chargeAnim: ChargeAnim): Promise { +export function initMoveChargeAnim(chargeAnim: ChargeAnim): Promise { return new Promise(resolve => { if (chargeAnims.has(chargeAnim)) { if (chargeAnims.get(chargeAnim) !== null) { @@ -590,7 +587,7 @@ export function initMoveChargeAnim(scene: BattleScene, chargeAnim: ChargeAnim): } } else { chargeAnims.set(chargeAnim, null); - scene.cachedFetch(`./battle-anims/${ChargeAnim[chargeAnim].toLowerCase().replace(/\_/g, "-")}.json`) + globalScene.cachedFetch(`./battle-anims/${ChargeAnim[chargeAnim].toLowerCase().replace(/\_/g, "-")}.json`) .then(response => response.json()) .then(ca => { if (Array.isArray(ca)) { @@ -623,23 +620,22 @@ function populateMoveChargeAnim(chargeAnim: ChargeAnim, animSource: any) { chargeAnims.set(chargeAnim, [ chargeAnims.get(chargeAnim) as AnimConfig, moveChargeAnim ]); } -export function loadCommonAnimAssets(scene: BattleScene, startLoad?: boolean): Promise { +export function loadCommonAnimAssets(startLoad?: boolean): Promise { return new Promise(resolve => { - loadAnimAssets(scene, Array.from(commonAnims.values()), startLoad).then(() => resolve()); + loadAnimAssets(Array.from(commonAnims.values()), startLoad).then(() => resolve()); }); } /** * Loads encounter animation assets to scene * MUST be called after {@linkcode initEncounterAnims()} to load all required animations properly - * @param scene * @param startLoad */ -export async function loadEncounterAnimAssets(scene: BattleScene, startLoad?: boolean): Promise { - await loadAnimAssets(scene, Array.from(encounterAnims.values()), startLoad); +export async function loadEncounterAnimAssets(startLoad?: boolean): Promise { + await loadAnimAssets(Array.from(encounterAnims.values()), startLoad); } -export function loadMoveAnimAssets(scene: BattleScene, moveIds: Moves[], startLoad?: boolean): Promise { +export function loadMoveAnimAssets(moveIds: Moves[], startLoad?: boolean): Promise { return new Promise(resolve => { const moveAnimations = moveIds.map(m => moveAnims.get(m) as AnimConfig).flat(); for (const moveId of moveIds) { @@ -655,11 +651,11 @@ export function loadMoveAnimAssets(scene: BattleScene, moveIds: Moves[], startLo } } } - loadAnimAssets(scene, moveAnimations, startLoad).then(() => resolve()); + loadAnimAssets(moveAnimations, startLoad).then(() => resolve()); }); } -function loadAnimAssets(scene: BattleScene, anims: AnimConfig[], startLoad?: boolean): Promise { +function loadAnimAssets(anims: AnimConfig[], startLoad?: boolean): Promise { return new Promise(resolve => { const backgrounds = new Set(); const sounds = new Set(); @@ -676,19 +672,19 @@ function loadAnimAssets(scene: BattleScene, anims: AnimConfig[], startLoad?: boo backgrounds.add(abg); } if (a.graphic) { - scene.loadSpritesheet(a.graphic, "battle_anims", 96); + globalScene.loadSpritesheet(a.graphic, "battle_anims", 96); } } for (const bg of backgrounds) { - scene.loadImage(bg, "battle_anims"); + globalScene.loadImage(bg, "battle_anims"); } for (const s of sounds) { - scene.loadSe(s, "battle_anims", s); + globalScene.loadSe(s, "battle_anims", s); } if (startLoad) { - scene.load.once(Phaser.Loader.Events.COMPLETE, () => resolve()); - if (!scene.load.isLoading()) { - scene.load.start(); + globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => resolve()); + if (!globalScene.load.isLoading()) { + globalScene.load.start(); } } else { resolve(); @@ -778,7 +774,7 @@ export abstract class BattleAnim { return false; } - private getGraphicFrameData(scene: BattleScene, frames: AnimFrame[], onSubstitute?: boolean): Map> { + private getGraphicFrameData(frames: AnimFrame[], onSubstitute?: boolean): Map> { const ret: Map> = new Map([ [ AnimFrameTarget.GRAPHIC, new Map() ], [ AnimFrameTarget.USER, new Map() ], @@ -835,7 +831,7 @@ export abstract class BattleAnim { return ret; } - play(scene: BattleScene, onSubstitute?: boolean, callback?: Function) { + play(onSubstitute?: boolean, callback?: Function) { const isOppAnim = this.isOppAnim(); const user = !isOppAnim ? this.user! : this.target!; // TODO: are those bangs correct? const target = !isOppAnim ? this.target! : this.user!; @@ -907,7 +903,7 @@ export abstract class BattleAnim { } }; - if (!scene.moveAnimations && !this.playRegardlessOfIssues) { + if (!globalScene.moveAnimations && !this.playRegardlessOfIssues) { return cleanUpAndComplete(); } @@ -924,7 +920,7 @@ export abstract class BattleAnim { let r = anim?.frames.length ?? 0; let f = 0; - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: Utils.getFrameMs(3), repeat: anim?.frames.length ?? 0, onRepeat: () => { @@ -934,7 +930,7 @@ export abstract class BattleAnim { } const spriteFrames = anim!.frames[f]; // TODO: is the bang correcT? - const frameData = this.getGraphicFrameData(scene, anim!.frames[f], onSubstitute); // TODO: is the bang correct? + const frameData = this.getGraphicFrameData(anim!.frames[f], onSubstitute); // TODO: is the bang correct? let u = 0; let t = 0; let g = 0; @@ -950,19 +946,19 @@ export abstract class BattleAnim { const spriteSource = isUser ? userSprite : targetSprite; if ((isUser ? u : t) === sprites.length) { if (isUser || !targetSubstitute) { - const sprite = scene.addPokemonSprite(isUser ? user! : target, 0, 0, spriteSource!.texture, spriteSource!.frame.name, true); // TODO: are those bangs correct? + const sprite = globalScene.addPokemonSprite(isUser ? user! : target, 0, 0, spriteSource!.texture, spriteSource!.frame.name, true); // TODO: are those bangs correct? [ "spriteColors", "fusionSpriteColors" ].map(k => sprite.pipelineData[k] = (isUser ? user! : target).getSprite().pipelineData[k]); // TODO: are those bangs correct? sprite.setPipelineData("spriteKey", (isUser ? user! : target).getBattleSpriteKey()); sprite.setPipelineData("shiny", (isUser ? user : target).shiny); sprite.setPipelineData("variant", (isUser ? user : target).variant); sprite.setPipelineData("ignoreFieldPos", true); spriteSource.on("animationupdate", (_anim, frame) => sprite.setFrame(frame.textureFrame)); - scene.field.add(sprite); + globalScene.field.add(sprite); sprites.push(sprite); } else { - const sprite = scene.addFieldSprite(spriteSource.x, spriteSource.y, spriteSource.texture); + const sprite = globalScene.addFieldSprite(spriteSource.x, spriteSource.y, spriteSource.texture); spriteSource.on("animationupdate", (_anim, frame) => sprite.setFrame(frame.textureFrame)); - scene.field.add(sprite); + globalScene.field.add(sprite); sprites.push(sprite); } } @@ -987,9 +983,9 @@ export abstract class BattleAnim { } else { const sprites = spriteCache[AnimFrameTarget.GRAPHIC]; if (g === sprites.length) { - const newSprite: Phaser.GameObjects.Sprite = scene.addFieldSprite(0, 0, anim!.graphic, 1); // TODO: is the bang correct? + const newSprite: Phaser.GameObjects.Sprite = globalScene.addFieldSprite(0, 0, anim!.graphic, 1); // TODO: is the bang correct? sprites.push(newSprite); - scene.field.add(newSprite); + globalScene.field.add(newSprite); spritePriorities.push(1); } @@ -1000,22 +996,22 @@ export abstract class BattleAnim { const setSpritePriority = (priority: integer) => { switch (priority) { case 0: - scene.field.moveBelow(moveSprite as Phaser.GameObjects.GameObject, scene.getEnemyPokemon(false) ?? scene.getPlayerPokemon(false)!); // TODO: is this bang correct? + globalScene.field.moveBelow(moveSprite as Phaser.GameObjects.GameObject, globalScene.getEnemyPokemon(false) ?? globalScene.getPlayerPokemon(false)!); // TODO: is this bang correct? break; case 1: - scene.field.moveTo(moveSprite, scene.field.getAll().length - 1); + globalScene.field.moveTo(moveSprite, globalScene.field.getAll().length - 1); break; case 2: switch (frame.focus) { case AnimFocus.USER: if (this.bgSprite) { - scene.field.moveAbove(moveSprite as Phaser.GameObjects.GameObject, this.bgSprite); + globalScene.field.moveAbove(moveSprite as Phaser.GameObjects.GameObject, this.bgSprite); } else { - scene.field.moveBelow(moveSprite as Phaser.GameObjects.GameObject, this.user!); // TODO: is this bang correct? + globalScene.field.moveBelow(moveSprite as Phaser.GameObjects.GameObject, this.user!); // TODO: is this bang correct? } break; case AnimFocus.TARGET: - scene.field.moveBelow(moveSprite as Phaser.GameObjects.GameObject, this.target!); // TODO: is this bang correct? + globalScene.field.moveBelow(moveSprite as Phaser.GameObjects.GameObject, this.target!); // TODO: is this bang correct? break; default: setSpritePriority(1); @@ -1025,10 +1021,10 @@ export abstract class BattleAnim { case 3: switch (frame.focus) { case AnimFocus.USER: - scene.field.moveAbove(moveSprite as Phaser.GameObjects.GameObject, this.user!); // TODO: is this bang correct? + globalScene.field.moveAbove(moveSprite as Phaser.GameObjects.GameObject, this.user!); // TODO: is this bang correct? break; case AnimFocus.TARGET: - scene.field.moveAbove(moveSprite as Phaser.GameObjects.GameObject, this.target!); // TODO: is this bang correct? + globalScene.field.moveAbove(moveSprite as Phaser.GameObjects.GameObject, this.target!); // TODO: is this bang correct? break; default: setSpritePriority(1); @@ -1056,7 +1052,7 @@ export abstract class BattleAnim { } if (anim?.frameTimedEvents.has(f)) { for (const event of anim.frameTimedEvents.get(f)!) { // TODO: is this bang correct? - r = Math.max((anim.frames.length - f) + event.execute(scene, this), r); + r = Math.max((anim.frames.length - f) + event.execute(this), r); } } const targets = Utils.getEnumValues(AnimFrameTarget); @@ -1086,7 +1082,7 @@ export abstract class BattleAnim { } } if (r) { - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: Utils.getFrameMs(r), onComplete: () => cleanUpAndComplete() }); @@ -1123,8 +1119,6 @@ export abstract class BattleAnim { } /** - * - * @param scene * @param targetInitialX * @param targetInitialY * @param frameTimeMult @@ -1135,7 +1129,7 @@ export abstract class BattleAnim { * - 5 is on top of player sprite * @param callback */ - playWithoutTargets(scene: BattleScene, targetInitialX: number, targetInitialY: number, frameTimeMult: number, frameTimedEventPriority?: 0 | 1 | 3 | 5, callback?: Function) { + playWithoutTargets(targetInitialX: number, targetInitialY: number, frameTimeMult: number, frameTimedEventPriority?: 0 | 1 | 3 | 5, callback?: Function) { const spriteCache: SpriteCache = { [AnimFrameTarget.GRAPHIC]: [], [AnimFrameTarget.USER]: [], @@ -1156,7 +1150,7 @@ export abstract class BattleAnim { } }; - if (!scene.moveAnimations && !this.playRegardlessOfIssues) { + if (!globalScene.moveAnimations && !this.playRegardlessOfIssues) { return cleanUpAndComplete(); } @@ -1168,13 +1162,13 @@ export abstract class BattleAnim { let totalFrames = anim!.frames.length; let frameCount = 0; - let existingFieldSprites = scene.field.getAll().slice(0); + let existingFieldSprites = globalScene.field.getAll().slice(0); - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: Utils.getFrameMs(3) * frameTimeMult, repeat: anim!.frames.length, onRepeat: () => { - existingFieldSprites = scene.field.getAll().slice(0); + existingFieldSprites = globalScene.field.getAll().slice(0); const spriteFrames = anim!.frames[frameCount]; const frameData = this.getGraphicFrameDataWithoutTarget(anim!.frames[frameCount], targetInitialX, targetInitialY); let graphicFrameCount = 0; @@ -1186,9 +1180,9 @@ export abstract class BattleAnim { const sprites = spriteCache[AnimFrameTarget.GRAPHIC]; if (graphicFrameCount === sprites.length) { - const newSprite: Phaser.GameObjects.Sprite = scene.addFieldSprite(0, 0, anim!.graphic, 1); + const newSprite: Phaser.GameObjects.Sprite = globalScene.addFieldSprite(0, 0, anim!.graphic, 1); sprites.push(newSprite); - scene.field.add(newSprite); + globalScene.field.add(newSprite); } const graphicIndex = graphicFrameCount++; @@ -1197,11 +1191,11 @@ export abstract class BattleAnim { const setSpritePriority = (priority: integer) => { if (existingFieldSprites.length > priority) { // Move to specified priority index - const index = scene.field.getIndex(existingFieldSprites[priority]); - scene.field.moveTo(moveSprite, index); + const index = globalScene.field.getIndex(existingFieldSprites[priority]); + globalScene.field.moveTo(moveSprite, index); } else { // Move to top of scene - scene.field.moveTo(moveSprite, scene.field.getAll().length - 1); + globalScene.field.moveTo(moveSprite, globalScene.field.getAll().length - 1); } }; setSpritePriority(frame.priority); @@ -1221,7 +1215,7 @@ export abstract class BattleAnim { } if (anim?.frameTimedEvents.get(frameCount)) { for (const event of anim.frameTimedEvents.get(frameCount)!) { - totalFrames = Math.max((anim.frames.length - frameCount) + event.execute(scene, this, frameTimedEventPriority), totalFrames); + totalFrames = Math.max((anim.frames.length - frameCount) + event.execute(this, frameTimedEventPriority), totalFrames); } } const targets = Utils.getEnumValues(AnimFrameTarget); @@ -1248,7 +1242,7 @@ export abstract class BattleAnim { } } if (totalFrames) { - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: Utils.getFrameMs(totalFrames), onComplete: () => cleanUpAndComplete() }); @@ -1282,7 +1276,7 @@ export class MoveAnim extends BattleAnim { public move: Moves; constructor(move: Moves, user: Pokemon, target: BattlerIndex, playOnEmptyField: boolean = false) { - super(user, user.scene.getField()[target], playOnEmptyField); + super(user, globalScene.getField()[target], playOnEmptyField); this.move = move; } diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index 0c0b8e9e0349..6e9376adabf9 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { allAbilities, applyAbAttrs, @@ -110,11 +110,10 @@ export class BattlerTag { /** * Helper function that retrieves the source Pokemon object - * @param scene medium to retrieve the source Pokemon * @returns The source {@linkcode Pokemon} or `null` if none is found */ - public getSourcePokemon(scene: BattleScene): Pokemon | null { - return this.sourceId ? scene.getPokemonById(this.sourceId) : null; + public getSourcePokemon(): Pokemon | null { + return this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; } } @@ -143,12 +142,12 @@ export abstract class MoveRestrictionBattlerTag extends BattlerTag { override lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { if (lapseType === BattlerTagLapseType.PRE_MOVE) { // Cancel the affected pokemon's selected move - const phase = pokemon.scene.getCurrentPhase() as MovePhase; + const phase = globalScene.getCurrentPhase() as MovePhase; const move = phase.move; if (this.isMoveRestricted(move.moveId, pokemon)) { if (this.interruptedText(pokemon, move.moveId)) { - pokemon.scene.queueMessage(this.interruptedText(pokemon, move.moveId)); + globalScene.queueMessage(this.interruptedText(pokemon, move.moveId)); } phase.cancel(); } @@ -280,14 +279,14 @@ export class DisabledTag extends MoveRestrictionBattlerTag { this.moveId = move.move; - pokemon.scene.queueMessage(i18next.t("battlerTags:disabledOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: allMoves[this.moveId].name })); + globalScene.queueMessage(i18next.t("battlerTags:disabledOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: allMoves[this.moveId].name })); } /** @override */ override onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:disabledLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: allMoves[this.moveId].name })); + globalScene.queueMessage(i18next.t("battlerTags:disabledLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: allMoves[this.moveId].name })); } /** @override */ @@ -406,8 +405,8 @@ export class RechargingTag extends BattlerTag { /** Cancels the source's move this turn and queues a "__ must recharge!" message */ lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { if (lapseType === BattlerTagLapseType.PRE_MOVE) { - pokemon.scene.queueMessage(i18next.t("battlerTags:rechargingLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - (pokemon.scene.getCurrentPhase() as MovePhase).cancel(); + globalScene.queueMessage(i18next.t("battlerTags:rechargingLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + (globalScene.getCurrentPhase() as MovePhase).cancel(); pokemon.getMoveQueue().shift(); } return super.lapse(pokemon, lapseType); @@ -426,10 +425,10 @@ export class BeakBlastChargingTag extends BattlerTag { onAdd(pokemon: Pokemon): void { // Play Beak Blast's charging animation - new MoveChargeAnim(ChargeAnim.BEAK_BLAST_CHARGING, this.sourceMove, pokemon).play(pokemon.scene); + new MoveChargeAnim(ChargeAnim.BEAK_BLAST_CHARGING, this.sourceMove, pokemon).play(); // Queue Beak Blast's header message - pokemon.scene.queueMessage(i18next.t("moveTriggers:startedHeatingUpBeak", { pokemonName: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("moveTriggers:startedHeatingUpBeak", { pokemonName: getPokemonNameWithAffix(pokemon) })); } /** @@ -464,7 +463,7 @@ export class ShellTrapTag extends BattlerTag { } onAdd(pokemon: Pokemon): void { - pokemon.scene.queueMessage(i18next.t("moveTriggers:setUpShellTrap", { pokemonName: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("moveTriggers:setUpShellTrap", { pokemonName: getPokemonNameWithAffix(pokemon) })); } /** @@ -479,17 +478,17 @@ export class ShellTrapTag extends BattlerTag { // Trap should only be triggered by opponent's Physical moves if (phaseData?.move.category === MoveCategory.PHYSICAL && pokemon.isOpponent(phaseData.attacker)) { - const shellTrapPhaseIndex = pokemon.scene.phaseQueue.findIndex( + const shellTrapPhaseIndex = globalScene.phaseQueue.findIndex( phase => phase instanceof MovePhase && phase.pokemon === pokemon ); - const firstMovePhaseIndex = pokemon.scene.phaseQueue.findIndex( + const firstMovePhaseIndex = globalScene.phaseQueue.findIndex( phase => phase instanceof MovePhase ); // Only shift MovePhase timing if it's not already next up if (shellTrapPhaseIndex !== -1 && shellTrapPhaseIndex !== firstMovePhaseIndex) { - const shellTrapMovePhase = pokemon.scene.phaseQueue.splice(shellTrapPhaseIndex, 1)[0]; - pokemon.scene.prependToPhase(shellTrapMovePhase, MovePhase); + const shellTrapMovePhase = globalScene.phaseQueue.splice(shellTrapPhaseIndex, 1)[0]; + globalScene.prependToPhase(shellTrapMovePhase, MovePhase); } this.activated = true; @@ -508,7 +507,7 @@ export class TrappedTag extends BattlerTag { } canAdd(pokemon: Pokemon): boolean { - const source = pokemon.scene.getPokemonById(this.sourceId!)!; + const source = globalScene.getPokemonById(this.sourceId!)!; const move = allMoves[this.sourceMove]; const isGhost = pokemon.isOfType(Type.GHOST); @@ -521,13 +520,13 @@ export class TrappedTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(this.getTrapMessage(pokemon)); + globalScene.queueMessage(this.getTrapMessage(pokemon)); } onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:trappedOnRemove", { + globalScene.queueMessage(i18next.t("battlerTags:trappedOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: this.getMoveName() })); @@ -585,8 +584,8 @@ export class FlinchedTag extends BattlerTag { */ lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { if (lapseType === BattlerTagLapseType.PRE_MOVE) { - (pokemon.scene.getCurrentPhase() as MovePhase).cancel(); - pokemon.scene.queueMessage(i18next.t("battlerTags:flinchedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + (globalScene.getCurrentPhase() as MovePhase).cancel(); + globalScene.queueMessage(i18next.t("battlerTags:flinchedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } return super.lapse(pokemon, lapseType); @@ -614,7 +613,7 @@ export class InterruptedTag extends BattlerTag { } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { - (pokemon.scene.getCurrentPhase() as MovePhase).cancel(); + (globalScene.getCurrentPhase() as MovePhase).cancel(); return super.lapse(pokemon, lapseType); } } @@ -628,44 +627,44 @@ export class ConfusedTag extends BattlerTag { } canAdd(pokemon: Pokemon): boolean { - return pokemon.scene.arena.terrain?.terrainType !== TerrainType.MISTY || !pokemon.isGrounded(); + return globalScene.arena.terrain?.terrainType !== TerrainType.MISTY || !pokemon.isGrounded(); } onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), undefined, CommonAnim.CONFUSION)); - pokemon.scene.queueMessage(i18next.t("battlerTags:confusedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), undefined, CommonAnim.CONFUSION)); + globalScene.queueMessage(i18next.t("battlerTags:confusedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:confusedOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:confusedOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } onOverlap(pokemon: Pokemon): void { super.onOverlap(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:confusedOnOverlap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:confusedOnOverlap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = lapseType !== BattlerTagLapseType.CUSTOM && super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.queueMessage(i18next.t("battlerTags:confusedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), undefined, CommonAnim.CONFUSION)); + globalScene.queueMessage(i18next.t("battlerTags:confusedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), undefined, CommonAnim.CONFUSION)); // 1/3 chance of hitting self with a 40 base power move if (pokemon.randSeedInt(3) === 0) { const atk = pokemon.getEffectiveStat(Stat.ATK); const def = pokemon.getEffectiveStat(Stat.DEF); const damage = toDmgValue(((((2 * pokemon.level / 5 + 2) * 40 * atk / def) / 50) + 2) * (pokemon.randSeedIntRange(85, 100) / 100)); - pokemon.scene.queueMessage(i18next.t("battlerTags:confusedLapseHurtItself")); + globalScene.queueMessage(i18next.t("battlerTags:confusedLapseHurtItself")); pokemon.damageAndUpdate(damage); pokemon.battleData.hitCount++; - (pokemon.scene.getCurrentPhase() as MovePhase).cancel(); + (globalScene.getCurrentPhase() as MovePhase).cancel(); } } @@ -700,7 +699,7 @@ export class DestinyBondTag extends BattlerTag { if (lapseType !== BattlerTagLapseType.CUSTOM) { return super.lapse(pokemon, lapseType); } - const source = this.sourceId ? pokemon.scene.getPokemonById(this.sourceId) : null; + const source = this.sourceId ? globalScene.getPokemonById(this.sourceId) : null; if (!source?.isFainted()) { return true; } @@ -710,11 +709,11 @@ export class DestinyBondTag extends BattlerTag { } if (pokemon.isBossImmune()) { - pokemon.scene.queueMessage(i18next.t("battlerTags:destinyBondLapseIsBoss", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:destinyBondLapseIsBoss", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); return false; } - pokemon.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:destinyBondLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(source), pokemonNameWithAffix2: getPokemonNameWithAffix(pokemon) @@ -732,7 +731,7 @@ export class InfatuatedTag extends BattlerTag { canAdd(pokemon: Pokemon): boolean { if (this.sourceId) { - const pkm = pokemon.scene.getPokemonById(this.sourceId); + const pkm = globalScene.getPokemonById(this.sourceId); if (pkm) { return pokemon.isOppositeGender(pkm); @@ -749,10 +748,10 @@ export class InfatuatedTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:infatuatedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), - sourcePokemonName: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined) // TODO: is that bang correct? + sourcePokemonName: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined) // TODO: is that bang correct? }) ); } @@ -760,24 +759,24 @@ export class InfatuatedTag extends BattlerTag { onOverlap(pokemon: Pokemon): void { super.onOverlap(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:infatuatedOnOverlap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:infatuatedOnOverlap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:infatuatedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), - sourcePokemonName: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined) // TODO: is that bang correct? + sourcePokemonName: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined) // TODO: is that bang correct? }) ); - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), undefined, CommonAnim.ATTRACT)); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), undefined, CommonAnim.ATTRACT)); if (pokemon.randSeedInt(2)) { - pokemon.scene.queueMessage(i18next.t("battlerTags:infatuatedLapseImmobilize", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - (pokemon.scene.getCurrentPhase() as MovePhase).cancel(); + globalScene.queueMessage(i18next.t("battlerTags:infatuatedLapseImmobilize", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + (globalScene.getCurrentPhase() as MovePhase).cancel(); } } @@ -787,7 +786,7 @@ export class InfatuatedTag extends BattlerTag { onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:infatuatedOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:infatuatedOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } isSourceLinked(): boolean { @@ -822,8 +821,8 @@ export class SeedTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:seededOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - this.sourceIndex = pokemon.scene.getPokemonById(this.sourceId!)!.getBattlerIndex(); // TODO: are those bangs correct? + globalScene.queueMessage(i18next.t("battlerTags:seededOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + this.sourceIndex = globalScene.getPokemonById(this.sourceId!)!.getBattlerIndex(); // TODO: are those bangs correct? } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { @@ -836,11 +835,11 @@ export class SeedTag extends BattlerTag { applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled); if (!cancelled.value) { - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, source.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.LEECH_SEED)); + globalScene.unshiftPhase(new CommonAnimPhase(source.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.LEECH_SEED)); const damage = pokemon.damageAndUpdate(toDmgValue(pokemon.getMaxHp() / 8)); const reverseDrain = pokemon.hasAbilityWithAttr(ReverseDrainAbAttr, false); - pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, source.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(source.getBattlerIndex(), !reverseDrain ? damage : damage * -1, !reverseDrain ? i18next.t("battlerTags:seededLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }) : i18next.t("battlerTags:seededLapseShed", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), false, true)); @@ -870,7 +869,7 @@ export class PowderTag extends BattlerTag { super.onAdd(pokemon); // "{Pokemon} is covered in powder!" - pokemon.scene.queueMessage(i18next.t("battlerTags:powderOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:powderOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } /** @@ -882,15 +881,15 @@ export class PowderTag extends BattlerTag { */ lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { if (lapseType === BattlerTagLapseType.PRE_MOVE) { - const movePhase = pokemon.scene.getCurrentPhase(); + const movePhase = globalScene.getCurrentPhase(); if (movePhase instanceof MovePhase) { const move = movePhase.move.getMove(); - const weather = pokemon.scene.arena.weather; - if (pokemon.getMoveType(move) === Type.FIRE && !(weather && weather.weatherType === WeatherType.HEAVY_RAIN && !weather.isEffectSuppressed(pokemon.scene))) { + const weather = globalScene.arena.weather; + if (pokemon.getMoveType(move) === Type.FIRE && !(weather && weather.weatherType === WeatherType.HEAVY_RAIN && !weather.isEffectSuppressed())) { movePhase.fail(); movePhase.showMoveText(); - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.POWDER)); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.POWDER)); const cancelDamage = new BooleanHolder(false); applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelDamage); @@ -899,7 +898,7 @@ export class PowderTag extends BattlerTag { } // "When the flame touched the powder\non the Pokémon, it exploded!" - pokemon.scene.queueMessage(i18next.t("battlerTags:powderLapse", { moveName: move.name })); + globalScene.queueMessage(i18next.t("battlerTags:powderLapse", { moveName: move.name })); } } return true; @@ -917,21 +916,21 @@ export class NightmareTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:nightmareOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:nightmareOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } onOverlap(pokemon: Pokemon): void { super.onOverlap(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:nightmareOnOverlap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:nightmareOnOverlap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.queueMessage(i18next.t("battlerTags:nightmareLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), undefined, CommonAnim.CURSE)); // TODO: Update animation type + globalScene.queueMessage(i18next.t("battlerTags:nightmareLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), undefined, CommonAnim.CURSE)); // TODO: Update animation type const cancelled = new BooleanHolder(false); applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled); @@ -1014,15 +1013,15 @@ export class EncoreTag extends MoveRestrictionBattlerTag { onAdd(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:encoreOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:encoreOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - const movePhase = pokemon.scene.findPhase(m => m instanceof MovePhase && m.pokemon === pokemon); + const movePhase = globalScene.findPhase(m => m instanceof MovePhase && m.pokemon === pokemon); if (movePhase) { const movesetMove = pokemon.getMoveset().find(m => m!.moveId === this.moveId); // TODO: is this bang correct? if (movesetMove) { const lastMove = pokemon.getLastXMoves(1)[0]; - pokemon.scene.tryReplacePhase((m => m instanceof MovePhase && m.pokemon === pokemon), - new MovePhase(pokemon.scene, pokemon, lastMove.targets!, movesetMove)); // TODO: is this bang correct? + globalScene.tryReplacePhase((m => m instanceof MovePhase && m.pokemon === pokemon), + new MovePhase(pokemon, lastMove.targets!, movesetMove)); // TODO: is this bang correct? } } } @@ -1063,7 +1062,7 @@ export class EncoreTag extends MoveRestrictionBattlerTag { onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:encoreOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:encoreOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -1073,9 +1072,9 @@ export class HelpingHandTag extends BattlerTag { } onAdd(pokemon: Pokemon): void { - pokemon.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:helpingHandOnAdd", { - pokemonNameWithAffix: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? + pokemonNameWithAffix: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? pokemonName: getPokemonNameWithAffix(pokemon) }) ); @@ -1106,9 +1105,8 @@ export class IngrainTag extends TrappedTag { const ret = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.unshiftPhase( + globalScene.unshiftPhase( new PokemonHealPhase( - pokemon.scene, pokemon.getBattlerIndex(), toDmgValue(pokemon.getMaxHp() / 16), i18next.t("battlerTags:ingrainLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), @@ -1142,7 +1140,7 @@ export class OctolockTag extends TrappedTag { const shouldLapse = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (shouldLapse) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), false, [ Stat.DEF, Stat.SPDEF ], -1)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), false, [ Stat.DEF, Stat.SPDEF ], -1)); return true; } @@ -1158,16 +1156,15 @@ export class AquaRingTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:aquaRingOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:aquaRingOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.unshiftPhase( + globalScene.unshiftPhase( new PokemonHealPhase( - pokemon.scene, pokemon.getBattlerIndex(), toDmgValue(pokemon.getMaxHp() / 16), i18next.t("battlerTags:aquaRingLapse", { @@ -1206,13 +1203,13 @@ export class DrowsyTag extends BattlerTag { } canAdd(pokemon: Pokemon): boolean { - return pokemon.scene.arena.terrain?.terrainType !== TerrainType.ELECTRIC || !pokemon.isGrounded(); + return globalScene.arena.terrain?.terrainType !== TerrainType.ELECTRIC || !pokemon.isGrounded(); } onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:drowsyOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:drowsyOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { @@ -1255,13 +1252,13 @@ export abstract class DamagingTrapTag extends TrappedTag { const ret = super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:damagingTrapLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: this.getMoveName() }) ); - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), undefined, this.commonAnim)); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), undefined, this.commonAnim)); const cancelled = new BooleanHolder(false); applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled); @@ -1283,7 +1280,7 @@ export class BindTag extends DamagingTrapTag { getTrapMessage(pokemon: Pokemon): string { return i18next.t("battlerTags:bindOnTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), - sourcePokemonName: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? + sourcePokemonName: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? moveName: this.getMoveName() }); } @@ -1297,7 +1294,7 @@ export class WrapTag extends DamagingTrapTag { getTrapMessage(pokemon: Pokemon): string { return i18next.t("battlerTags:wrapOnTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), - sourcePokemonName: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? + sourcePokemonName: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? }); } } @@ -1331,7 +1328,7 @@ export class ClampTag extends DamagingTrapTag { getTrapMessage(pokemon: Pokemon): string { return i18next.t("battlerTags:clampOnTrap", { - sourcePokemonNameWithAffix: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? + sourcePokemonNameWithAffix: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? pokemonName: getPokemonNameWithAffix(pokemon), }); } @@ -1378,7 +1375,7 @@ export class ThunderCageTag extends DamagingTrapTag { getTrapMessage(pokemon: Pokemon): string { return i18next.t("battlerTags:thunderCageOnTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), - sourcePokemonNameWithAffix: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? + sourcePokemonNameWithAffix: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? }); } } @@ -1391,7 +1388,7 @@ export class InfestationTag extends DamagingTrapTag { getTrapMessage(pokemon: Pokemon): string { return i18next.t("battlerTags:infestationOnTrap", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), - sourcePokemonNameWithAffix: getPokemonNameWithAffix(pokemon.scene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? + sourcePokemonNameWithAffix: getPokemonNameWithAffix(globalScene.getPokemonById(this.sourceId!) ?? undefined), // TODO: is that bang correct? }); } } @@ -1405,16 +1402,16 @@ export class ProtectedTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:protectedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:protectedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { if (lapseType === BattlerTagLapseType.CUSTOM) { - new CommonBattleAnim(CommonAnim.PROTECT, pokemon).play(pokemon.scene); - pokemon.scene.queueMessage(i18next.t("battlerTags:protectedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + new CommonBattleAnim(CommonAnim.PROTECT, pokemon).play(); + globalScene.queueMessage(i18next.t("battlerTags:protectedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); // Stop multi-hit moves early - const effectPhase = pokemon.scene.getCurrentPhase(); + const effectPhase = globalScene.getCurrentPhase(); if (effectPhase instanceof MoveEffectPhase) { effectPhase.stopMultiHit(pokemon); } @@ -1454,7 +1451,7 @@ export class ContactDamageProtectedTag extends ProtectedTag { const ret = super.lapse(pokemon, lapseType); if (lapseType === BattlerTagLapseType.CUSTOM) { - const effectPhase = pokemon.scene.getCurrentPhase(); + const effectPhase = globalScene.getCurrentPhase(); if (effectPhase instanceof MoveEffectPhase && effectPhase.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT)) { const attacker = effectPhase.getPokemon(); if (!attacker.hasAbilityWithAttr(BlockNonDirectDamageAbAttr)) { @@ -1496,10 +1493,10 @@ export class ContactStatStageChangeProtectedTag extends DamageProtectedTag { const ret = super.lapse(pokemon, lapseType); if (lapseType === BattlerTagLapseType.CUSTOM) { - const effectPhase = pokemon.scene.getCurrentPhase(); + const effectPhase = globalScene.getCurrentPhase(); if (effectPhase instanceof MoveEffectPhase && effectPhase.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT)) { const attacker = effectPhase.getPokemon(); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, attacker.getBattlerIndex(), false, [ this.stat ], this.levels)); + globalScene.unshiftPhase(new StatStageChangePhase(attacker.getBattlerIndex(), false, [ this.stat ], this.levels)); } } @@ -1516,7 +1513,7 @@ export class ContactPoisonProtectedTag extends ProtectedTag { const ret = super.lapse(pokemon, lapseType); if (lapseType === BattlerTagLapseType.CUSTOM) { - const effectPhase = pokemon.scene.getCurrentPhase(); + const effectPhase = globalScene.getCurrentPhase(); if (effectPhase instanceof MoveEffectPhase && effectPhase.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT)) { const attacker = effectPhase.getPokemon(); attacker.trySetStatus(StatusEffect.POISON, true, pokemon); @@ -1540,7 +1537,7 @@ export class ContactBurnProtectedTag extends DamageProtectedTag { const ret = super.lapse(pokemon, lapseType); if (lapseType === BattlerTagLapseType.CUSTOM) { - const effectPhase = pokemon.scene.getCurrentPhase(); + const effectPhase = globalScene.getCurrentPhase(); if (effectPhase instanceof MoveEffectPhase && effectPhase.move.getMove().hasFlag(MoveFlags.MAKES_CONTACT)) { const attacker = effectPhase.getPokemon(); attacker.trySetStatus(StatusEffect.BURN, true); @@ -1564,12 +1561,12 @@ export class EnduringTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:enduringOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:enduringOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { if (lapseType === BattlerTagLapseType.CUSTOM) { - pokemon.scene.queueMessage(i18next.t("battlerTags:enduringLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:enduringLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); return true; } @@ -1584,7 +1581,7 @@ export class SturdyTag extends BattlerTag { lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { if (lapseType === BattlerTagLapseType.CUSTOM) { - pokemon.scene.queueMessage(i18next.t("battlerTags:sturdyLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:sturdyLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); return true; } @@ -1605,7 +1602,7 @@ export class PerishSongTag extends BattlerTag { const ret = super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:perishSongLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), turnCount: this.turnCount @@ -1634,7 +1631,7 @@ export class CenterOfAttentionTag extends BattlerTag { /** "Center of Attention" can't be added if an ally is already the Center of Attention. */ canAdd(pokemon: Pokemon): boolean { - const activeTeam = pokemon.isPlayer() ? pokemon.scene.getPlayerField() : pokemon.scene.getEnemyField(); + const activeTeam = pokemon.isPlayer() ? globalScene.getPlayerField() : globalScene.getEnemyField(); return !activeTeam.find(p => p.getTag(BattlerTagType.CENTER_OF_ATTENTION)); } @@ -1642,7 +1639,7 @@ export class CenterOfAttentionTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:centerOfAttentionOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:centerOfAttentionOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -1695,9 +1692,9 @@ export class TruantTag extends AbilityBattlerTag { const lastMove = pokemon.getLastXMoves().find(() => true); if (lastMove && lastMove.move !== Moves.NONE) { - (pokemon.scene.getCurrentPhase() as MovePhase).cancel(); - pokemon.scene.unshiftPhase(new ShowAbilityPhase(pokemon.scene, pokemon.id, passive)); - pokemon.scene.queueMessage(i18next.t("battlerTags:truantLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + (globalScene.getCurrentPhase() as MovePhase).cancel(); + globalScene.unshiftPhase(new ShowAbilityPhase(pokemon.id, passive)); + globalScene.queueMessage(i18next.t("battlerTags:truantLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } return true; @@ -1712,7 +1709,7 @@ export class SlowStartTag extends AbilityBattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:slowStartOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null, true); + globalScene.queueMessage(i18next.t("battlerTags:slowStartOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null, true); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { @@ -1726,7 +1723,7 @@ export class SlowStartTag extends AbilityBattlerTag { onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:slowStartOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null); + globalScene.queueMessage(i18next.t("battlerTags:slowStartOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null); } } @@ -1772,13 +1769,13 @@ export class HighestStatBoostTag extends AbilityBattlerTag { break; } - pokemon.scene.queueMessage(i18next.t("battlerTags:highestStatBoostOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), statName: i18next.t(getStatKey(highestStat)) }), null, false, null, true); + globalScene.queueMessage(i18next.t("battlerTags:highestStatBoostOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), statName: i18next.t(getStatKey(highestStat)) }), null, false, null, true); } onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:highestStatBoostOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName: allAbilities[this.ability].name })); + globalScene.queueMessage(i18next.t("battlerTags:highestStatBoostOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), abilityName: allAbilities[this.ability].name })); } } @@ -1831,7 +1828,7 @@ export class SemiInvulnerableTag extends BattlerTag { onRemove(pokemon: Pokemon): void { // Wait 2 frames before setting visible for battle animations that don't immediately show the sprite invisible - pokemon.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: getFrameMs(2), onComplete: () => pokemon.setVisible(true) }); @@ -1871,7 +1868,7 @@ export class FloatingTag extends TypeImmuneTag { super.onAdd(pokemon); if (this.sourceMove === Moves.MAGNET_RISE) { - pokemon.scene.queueMessage(i18next.t("battlerTags:magnetRisenOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:magnetRisenOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -1879,7 +1876,7 @@ export class FloatingTag extends TypeImmuneTag { onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); if (this.sourceMove === Moves.MAGNET_RISE) { - pokemon.scene.queueMessage(i18next.t("battlerTags:magnetRisenOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:magnetRisenOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } } @@ -1921,7 +1918,7 @@ export class CritBoostTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:critBoostOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:critBoostOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { @@ -1931,7 +1928,7 @@ export class CritBoostTag extends BattlerTag { onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:critBoostOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:critBoostOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -1973,15 +1970,15 @@ export class SaltCuredTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:saltCuredOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - this.sourceIndex = pokemon.scene.getPokemonById(this.sourceId!)!.getBattlerIndex(); // TODO: are those bangs correct? + globalScene.queueMessage(i18next.t("battlerTags:saltCuredOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + this.sourceIndex = globalScene.getPokemonById(this.sourceId!)!.getBattlerIndex(); // TODO: are those bangs correct? } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.SALT_CURE)); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.SALT_CURE)); const cancelled = new BooleanHolder(false); applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled); @@ -1990,7 +1987,7 @@ export class SaltCuredTag extends BattlerTag { const pokemonSteelOrWater = pokemon.isOfType(Type.STEEL) || pokemon.isOfType(Type.WATER); pokemon.damageAndUpdate(toDmgValue(pokemonSteelOrWater ? pokemon.getMaxHp() / 4 : pokemon.getMaxHp() / 8)); - pokemon.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:saltCuredLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: this.getMoveName() @@ -2021,21 +2018,21 @@ export class CursedTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - this.sourceIndex = pokemon.scene.getPokemonById(this.sourceId!)!.getBattlerIndex(); // TODO: are those bangs correct? + this.sourceIndex = globalScene.getPokemonById(this.sourceId!)!.getBattlerIndex(); // TODO: are those bangs correct? } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); if (ret) { - pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.SALT_CURE)); + globalScene.unshiftPhase(new CommonAnimPhase(pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.SALT_CURE)); const cancelled = new BooleanHolder(false); applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled); if (!cancelled.value) { pokemon.damageAndUpdate(toDmgValue(pokemon.getMaxHp() / 4)); - pokemon.scene.queueMessage(i18next.t("battlerTags:cursedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:cursedLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -2149,7 +2146,7 @@ export class FormBlockDamageTag extends BattlerTag { super.onAdd(pokemon); if (pokemon.formIndex !== 0) { - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); } } @@ -2161,7 +2158,7 @@ export class FormBlockDamageTag extends BattlerTag { onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); } } /** Provides the additional weather-based effects of the Ice Face ability */ @@ -2176,7 +2173,7 @@ export class IceFaceBlockDamageTag extends FormBlockDamageTag { * @returns {boolean} True if the tag can be added, false otherwise. */ canAdd(pokemon: Pokemon): boolean { - const weatherType = pokemon.scene.arena.weather?.weatherType; + const weatherType = globalScene.arena.weather?.weatherType; const isWeatherSnowOrHail = weatherType === WeatherType.HAIL || weatherType === WeatherType.SNOW; return super.canAdd(pokemon) || isWeatherSnowOrHail; @@ -2200,16 +2197,14 @@ export class CommandedTag extends BattlerTag { /** Caches the Tatsugiri's form key and sharply boosts the tagged Pokemon's stats */ override onAdd(pokemon: Pokemon): void { - this._tatsugiriFormKey = this.getSourcePokemon(pokemon.scene)?.getFormKey() ?? "curly"; - pokemon.scene.unshiftPhase(new StatStageChangePhase( - pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD ], 2 - )); + this._tatsugiriFormKey = this.getSourcePokemon()?.getFormKey() ?? "curly"; + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD ], 2)); } /** Triggers an {@linkcode PokemonAnimType | animation} of the tagged Pokemon "spitting out" Tatsugiri */ override onRemove(pokemon: Pokemon): void { - if (this.getSourcePokemon(pokemon.scene)?.isActive(true)) { - pokemon.scene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.COMMANDER_REMOVE); + if (this.getSourcePokemon()?.isActive(true)) { + globalScene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.COMMANDER_REMOVE); } } @@ -2271,14 +2266,14 @@ export class StockpilingTag extends BattlerTag { if (this.stockpiledCount < 3) { this.stockpiledCount++; - pokemon.scene.queueMessage(i18next.t("battlerTags:stockpilingOnAdd", { + globalScene.queueMessage(i18next.t("battlerTags:stockpilingOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), stockpiledCount: this.stockpiledCount })); // Attempt to increase DEF and SPDEF by one stage, keeping track of successful changes. - pokemon.scene.unshiftPhase(new StatStageChangePhase( - pokemon.scene, pokemon.getBattlerIndex(), true, + globalScene.unshiftPhase(new StatStageChangePhase( + pokemon.getBattlerIndex(), true, [ Stat.SPDEF, Stat.DEF ], 1, true, false, true, this.onStatStagesChanged )); } @@ -2297,11 +2292,11 @@ export class StockpilingTag extends BattlerTag { const spDefChange = this.statChangeCounts[Stat.SPDEF]; if (defChange) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.DEF ], -defChange, true, false, true)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.DEF ], -defChange, true, false, true)); } if (spDefChange) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.SPDEF ], -spDefChange, true, false, true)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.SPDEF ], -spDefChange, true, false, true)); } } } @@ -2320,7 +2315,7 @@ export class GulpMissileTag extends BattlerTag { return true; } - const moveEffectPhase = pokemon.scene.getCurrentPhase(); + const moveEffectPhase = globalScene.getCurrentPhase(); if (moveEffectPhase instanceof MoveEffectPhase) { const attacker = moveEffectPhase.getUserPokemon(); @@ -2340,7 +2335,7 @@ export class GulpMissileTag extends BattlerTag { } if (this.tagType === BattlerTagType.GULP_MISSILE_ARROKUDA) { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, attacker.getBattlerIndex(), false, [ Stat.DEF ], -1)); + globalScene.unshiftPhase(new StatStageChangePhase(attacker.getBattlerIndex(), false, [ Stat.DEF ], -1)); } else { attacker.trySetStatus(StatusEffect.PARALYSIS, true, pokemon); } @@ -2363,12 +2358,12 @@ export class GulpMissileTag extends BattlerTag { onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); } onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); } } @@ -2476,7 +2471,7 @@ export class HealBlockTag extends MoveRestrictionBattlerTag { override onRemove(pokemon: Pokemon): void { super.onRemove(pokemon); - pokemon.scene.queueMessage(i18next.t("battle:battlerTagsHealBlockOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null); + globalScene.queueMessage(i18next.t("battle:battlerTagsHealBlockOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, false, null); } } @@ -2499,7 +2494,7 @@ export class TarShotTag extends BattlerTag { } override onAdd(pokemon: Pokemon): void { - pokemon.scene.queueMessage(i18next.t("battlerTags:tarShotOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:tarShotOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -2514,7 +2509,7 @@ export class ElectrifiedTag extends BattlerTag { override onAdd(pokemon: Pokemon): void { // "{pokemonNameWithAffix}'s moves have been electrified!" - pokemon.scene.queueMessage(i18next.t("battlerTags:electrifiedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:electrifiedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -2536,7 +2531,7 @@ export class AutotomizedTag extends BattlerTag { onAdd(pokemon: Pokemon): void { const minWeight = 0.1; if (pokemon.getWeight() > minWeight) { - pokemon.scene.queueMessage(i18next.t("battlerTags:autotomizeOnAdd", { + globalScene.queueMessage(i18next.t("battlerTags:autotomizeOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } @@ -2567,15 +2562,15 @@ export class SubstituteTag extends BattlerTag { /** Sets the Substitute's HP and queues an on-add battle animation that initializes the Substitute's sprite. */ onAdd(pokemon: Pokemon): void { - this.hp = Math.floor(pokemon.scene.getPokemonById(this.sourceId!)!.getMaxHp() / 4); + this.hp = Math.floor(globalScene.getPokemonById(this.sourceId!)!.getMaxHp() / 4); this.sourceInFocus = false; // Queue battle animation and message - pokemon.scene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_ADD); + globalScene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_ADD); if (this.sourceMove === Moves.SHED_TAIL) { - pokemon.scene.queueMessage(i18next.t("battlerTags:shedTailOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); + globalScene.queueMessage(i18next.t("battlerTags:shedTailOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); } else { - pokemon.scene.queueMessage(i18next.t("battlerTags:substituteOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); + globalScene.queueMessage(i18next.t("battlerTags:substituteOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); } // Remove any binding effects from the user @@ -2586,11 +2581,11 @@ export class SubstituteTag extends BattlerTag { onRemove(pokemon: Pokemon): void { // Only play the animation if the cause of removal isn't from the source's own move if (!this.sourceInFocus) { - pokemon.scene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_REMOVE, [ this.sprite ]); + globalScene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_REMOVE, [ this.sprite ]); } else { this.sprite.destroy(); } - pokemon.scene.queueMessage(i18next.t("battlerTags:substituteOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:substituteOnRemove", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { @@ -2610,19 +2605,19 @@ export class SubstituteTag extends BattlerTag { /** Triggers an animation that brings the Pokemon into focus before it uses a move */ onPreMove(pokemon: Pokemon): void { - pokemon.scene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_PRE_MOVE, [ this.sprite ]); + globalScene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_PRE_MOVE, [ this.sprite ]); this.sourceInFocus = true; } /** Triggers an animation that brings the Pokemon out of focus after it uses a move */ onAfterMove(pokemon: Pokemon): void { - pokemon.scene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_POST_MOVE, [ this.sprite ]); + globalScene.triggerPokemonBattleAnim(pokemon, PokemonAnimType.SUBSTITUTE_POST_MOVE, [ this.sprite ]); this.sourceInFocus = false; } /** If the Substitute redirects damage, queue a message to indicate it. */ onHit(pokemon: Pokemon): void { - const moveEffectPhase = pokemon.scene.getCurrentPhase(); + const moveEffectPhase = globalScene.getCurrentPhase(); if (moveEffectPhase instanceof MoveEffectPhase) { const attacker = moveEffectPhase.getUserPokemon(); if (!attacker) { @@ -2632,7 +2627,7 @@ export class SubstituteTag extends BattlerTag { const firstHit = (attacker.turnData.hitCount === attacker.turnData.hitsLeft); if (firstHit && move.hitsSubstitute(attacker, pokemon)) { - pokemon.scene.queueMessage(i18next.t("battlerTags:substituteOnHit", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:substituteOnHit", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } } @@ -2704,7 +2699,7 @@ export class TormentTag extends MoveRestrictionBattlerTag { */ override onAdd(pokemon: Pokemon) { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:tormentOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); + globalScene.queueMessage(i18next.t("battlerTags:tormentOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); } /** @@ -2758,7 +2753,7 @@ export class TauntTag extends MoveRestrictionBattlerTag { override onAdd(pokemon: Pokemon) { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:tauntOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); + globalScene.queueMessage(i18next.t("battlerTags:tauntOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), 1500); } /** @@ -2796,7 +2791,7 @@ export class ImprisonTag extends MoveRestrictionBattlerTag { * @returns `true` if the source is still active */ public override lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { - const source = this.getSourcePokemon(pokemon.scene); + const source = this.getSourcePokemon(); if (source) { if (lapseType === BattlerTagLapseType.PRE_MOVE) { return super.lapse(pokemon, lapseType) && source.isActive(true); @@ -2814,7 +2809,7 @@ export class ImprisonTag extends MoveRestrictionBattlerTag { * @returns `false` if either condition is not met */ public override isMoveRestricted(move: Moves, user: Pokemon): boolean { - const source = this.getSourcePokemon(user.scene); + const source = this.getSourcePokemon(); if (source) { const sourceMoveset = source.getMoveset().map(m => m!.moveId); return sourceMoveset?.includes(move) && source.isActive(true); @@ -2847,7 +2842,7 @@ export class SyrupBombTag extends BattlerTag { */ override onAdd(pokemon: Pokemon) { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:syrupBombOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:syrupBombOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } /** @@ -2857,13 +2852,13 @@ export class SyrupBombTag extends BattlerTag { * @returns `true` if the `turnCount` is still greater than `0`; `false` if the `turnCount` is `0` or the target or source Pokemon has been removed from the field */ override lapse(pokemon: Pokemon, _lapseType: BattlerTagLapseType): boolean { - if (this.sourceId && !pokemon.scene.getPokemonById(this.sourceId)?.isActive(true)) { + if (this.sourceId && !globalScene.getPokemonById(this.sourceId)?.isActive(true)) { return false; } // Custom message in lieu of an animation in mainline - pokemon.scene.queueMessage(i18next.t("battlerTags:syrupBombLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); - pokemon.scene.unshiftPhase(new StatStageChangePhase( - pokemon.scene, pokemon.getBattlerIndex(), true, + globalScene.queueMessage(i18next.t("battlerTags:syrupBombLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.unshiftPhase(new StatStageChangePhase( + pokemon.getBattlerIndex(), true, [ Stat.SPD ], -1, true, false, true )); return --this.turnCount > 0; @@ -2882,7 +2877,7 @@ export class TelekinesisTag extends BattlerTag { } override onAdd(pokemon: Pokemon) { - pokemon.scene.queueMessage(i18next.t("battlerTags:telekinesisOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:telekinesisOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } } @@ -2897,12 +2892,12 @@ export class PowerTrickTag extends BattlerTag { onAdd(pokemon: Pokemon): void { this.swapStat(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:powerTrickActive", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:powerTrickActive", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } onRemove(pokemon: Pokemon): void { this.swapStat(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:powerTrickActive", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:powerTrickActive", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } /** @@ -2936,7 +2931,7 @@ export class GrudgeTag extends BattlerTag { onAdd(pokemon: Pokemon) { super.onAdd(pokemon); - pokemon.scene.queueMessage(i18next.t("battlerTags:grudgeOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("battlerTags:grudgeOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } /** @@ -2953,7 +2948,7 @@ export class GrudgeTag extends BattlerTag { const lastMoveData = sourcePokemon.getMoveset().find(m => m?.moveId === lastMove.move); if (lastMoveData && lastMove.move !== Moves.STRUGGLE) { lastMoveData.ppUsed = lastMoveData.getMovePp(); - pokemon.scene.queueMessage(i18next.t("battlerTags:grudgeLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: lastMoveData.getName() })); + globalScene.queueMessage(i18next.t("battlerTags:grudgeLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: lastMoveData.getName() })); } } return false; @@ -2977,7 +2972,7 @@ export class PsychoShiftTag extends BattlerTag { */ override lapse(pokemon: Pokemon, _lapseType: BattlerTagLapseType): boolean { if (pokemon.status && pokemon.isActive(true)) { - pokemon.scene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); + globalScene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); pokemon.resetStatus(); pokemon.updateInfo(); } @@ -3199,7 +3194,7 @@ export function loadBattlerTag(source: BattlerTag | any): BattlerTag { * corresponding {@linkcode Move} and user {@linkcode Pokemon} */ function getMoveEffectPhaseData(pokemon: Pokemon): {phase: MoveEffectPhase, attacker: Pokemon, move: Move} | null { - const phase = pokemon.scene.getCurrentPhase(); + const phase = globalScene.getCurrentPhase(); if (phase instanceof MoveEffectPhase) { return { phase : phase, diff --git a/src/data/berry.ts b/src/data/berry.ts index dfd6a7ddcf08..2876511758c7 100644 --- a/src/data/berry.ts +++ b/src/data/berry.ts @@ -9,6 +9,7 @@ import { BerryType } from "#enums/berry-type"; import { Stat, type BattleStat } from "#app/enums/stat"; import { PokemonHealPhase } from "#app/phases/pokemon-heal-phase"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; +import { globalScene } from "#app/global-scene"; export function getBerryName(berryType: BerryType): string { return i18next.t(`berry:${BerryType[berryType]}.name`); @@ -73,7 +74,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { } const hpHealed = new Utils.NumberHolder(Utils.toDmgValue(pokemon.getMaxHp() / 4)); applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, hpHealed); - pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), hpHealed.value, i18next.t("battle:hpHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), berryName: getBerryName(berryType) }), true)); applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false); }; @@ -83,7 +84,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { pokemon.battleData.berriesEaten.push(berryType); } if (pokemon.status) { - pokemon.scene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); + globalScene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); } pokemon.resetStatus(true, true); pokemon.updateInfo(); @@ -102,7 +103,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { const stat: BattleStat = berryType - BerryType.ENIGMA; const statStages = new Utils.NumberHolder(1); applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, statStages); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ stat ], statStages.value)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ stat ], statStages.value)); applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false); }; case BerryType.LANSAT: @@ -121,7 +122,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { const randStat = Utils.randSeedInt(Stat.SPD, Stat.ATK); const stages = new Utils.NumberHolder(2); applyAbAttrs(DoubleBerryEffectAbAttr, pokemon, null, false, stages); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ randStat ], stages.value)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ randStat ], stages.value)); applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false); }; case BerryType.LEPPA: @@ -132,7 +133,7 @@ export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { const ppRestoreMove = pokemon.getMoveset().find(m => !m?.getPpRatio()) ? pokemon.getMoveset().find(m => !m?.getPpRatio()) : pokemon.getMoveset().find(m => m!.getPpRatio() < 1); // TODO: is this bang correct? if (ppRestoreMove !== undefined) { ppRestoreMove!.ppUsed = Math.max(ppRestoreMove!.ppUsed - 10, 0); - pokemon.scene.queueMessage(i18next.t("battle:ppHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: ppRestoreMove!.getName(), berryName: getBerryName(berryType) })); + globalScene.queueMessage(i18next.t("battle:ppHealBerry", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), moveName: ppRestoreMove!.getName(), berryName: getBerryName(berryType) })); applyPostItemLostAbAttrs(PostItemLostAbAttr, berryOwner ?? pokemon, false); } }; diff --git a/src/data/challenge.ts b/src/data/challenge.ts index 4301ea7b3758..bf5d33ef0aca 100644 --- a/src/data/challenge.ts +++ b/src/data/challenge.ts @@ -467,7 +467,7 @@ export class SingleGenerationChallenge extends Challenge { if (trainerTypes.length === 0) { return false; } else { - battleConfig.setBattleType(BattleType.TRAINER).setGetTrainerFunc(scene => new Trainer(scene, trainerTypes[this.value - 1], TrainerVariant.DEFAULT)); + battleConfig.setBattleType(BattleType.TRAINER).setGetTrainerFunc(() => new Trainer(trainerTypes[this.value - 1], TrainerVariant.DEFAULT)); return true; } } diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index 506ea0471c68..f1433d4b252c 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -1,6 +1,6 @@ import { PartyMemberStrength } from "#enums/party-member-strength"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { PlayerPokemon } from "#app/field/pokemon"; import { Starter } from "#app/ui/starter-select-ui-handler"; import * as Utils from "#app/utils"; @@ -21,17 +21,17 @@ export function fetchDailyRunSeed(): Promise { }); } -export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] { +export function getDailyRunStarters(seed: string): Starter[] { const starters: Starter[] = []; - scene.executeWithSeedOffset(() => { - const startingLevel = scene.gameMode.getStartingLevel(); + globalScene.executeWithSeedOffset(() => { + const startingLevel = globalScene.gameMode.getStartingLevel(); if (/\d{18}$/.test(seed)) { for (let s = 0; s < 3; s++) { const offset = 6 + s * 6; const starterSpeciesForm = getPokemonSpeciesForm(parseInt(seed.slice(offset, offset + 4)) as Species, parseInt(seed.slice(offset + 4, offset + 6))); - starters.push(getDailyRunStarter(scene, starterSpeciesForm, startingLevel)); + starters.push(getDailyRunStarter(starterSpeciesForm, startingLevel)); } return; } @@ -48,17 +48,17 @@ export function getDailyRunStarters(scene: BattleScene, seed: string): Starter[] .filter(s => speciesStarterCosts[s] === cost); const randPkmSpecies = getPokemonSpecies(Utils.randSeedItem(costSpecies)); const starterSpecies = getPokemonSpecies(randPkmSpecies.getTrainerSpeciesForLevel(startingLevel, true, PartyMemberStrength.STRONGER)); - starters.push(getDailyRunStarter(scene, starterSpecies, startingLevel)); + starters.push(getDailyRunStarter(starterSpecies, startingLevel)); } }, 0, seed); return starters; } -function getDailyRunStarter(scene: BattleScene, starterSpeciesForm: PokemonSpeciesForm, startingLevel: integer): Starter { +function getDailyRunStarter(starterSpeciesForm: PokemonSpeciesForm, startingLevel: integer): Starter { const starterSpecies = starterSpeciesForm instanceof PokemonSpecies ? starterSpeciesForm : getPokemonSpecies(starterSpeciesForm.speciesId); const formIndex = starterSpeciesForm instanceof PokemonSpecies ? undefined : starterSpeciesForm.formIndex; - const pokemon = new PlayerPokemon(scene, starterSpecies, startingLevel, undefined, formIndex, undefined, undefined, undefined, undefined, undefined, undefined); + const pokemon = new PlayerPokemon(starterSpecies, startingLevel, undefined, formIndex, undefined, undefined, undefined, undefined, undefined, undefined); const starter: Starter = { species: starterSpecies, dexAttr: pokemon.getDexAttr(), diff --git a/src/data/egg-hatch-data.ts b/src/data/egg-hatch-data.ts index ba553b55c4f3..c8f33eccb780 100644 --- a/src/data/egg-hatch-data.ts +++ b/src/data/egg-hatch-data.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { PlayerPokemon } from "#app/field/pokemon"; import { DexEntry, StarterDataEntry } from "#app/system/game-data"; @@ -17,11 +17,8 @@ export class EggHatchData { public dexEntryBeforeUpdate: DexEntry; /** stored copy of the hatched pokemon's starter entry before it was updated due to hatch */ public starterDataEntryBeforeUpdate: StarterDataEntry; - /** reference to the battle scene to get gamedata and update dex */ - private scene: BattleScene; - constructor(scene: BattleScene, pokemon: PlayerPokemon, eggMoveIndex: number) { - this.scene = scene; + constructor(pokemon: PlayerPokemon, eggMoveIndex: number) { this.pokemon = pokemon; this.eggMoveIndex = eggMoveIndex; } @@ -39,8 +36,8 @@ export class EggHatchData { * Used before updating the dex, so comparing the pokemon to these entries will show the new attributes */ setDex() { - const currDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId]; - const currStarterDataEntry = this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId()]; + const currDexEntry = globalScene.gameData.dexData[this.pokemon.species.speciesId]; + const currStarterDataEntry = globalScene.gameData.starterData[this.pokemon.species.getRootSpeciesId()]; this.dexEntryBeforeUpdate = { seenAttr: currDexEntry.seenAttr, caughtAttr: currDexEntry.caughtAttr, @@ -86,9 +83,9 @@ export class EggHatchData { */ updatePokemon(showMessage : boolean = false) { return new Promise(resolve => { - this.scene.gameData.setPokemonCaught(this.pokemon, true, true, showMessage).then(() => { - this.scene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs); - this.scene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex, showMessage).then((value) => { + globalScene.gameData.setPokemonCaught(this.pokemon, true, true, showMessage).then(() => { + globalScene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs); + globalScene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex, showMessage).then((value) => { this.setEggMoveUnlocked(value); resolve(); }); diff --git a/src/data/egg.ts b/src/data/egg.ts index 7f1deecc63f5..6ae7c9f968ac 100644 --- a/src/data/egg.ts +++ b/src/data/egg.ts @@ -1,4 +1,5 @@ import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import PokemonSpecies, { getPokemonSpecies } from "#app/data/pokemon-species"; import { speciesStarterCosts } from "#app/data/balance/starters"; import { VariantTier } from "#enums/variant-tier"; @@ -22,9 +23,8 @@ export interface IEggOptions { /** Timestamp when this egg got created */ timestamp?: number; /** - * Defines if the egg got pulled from a gacha or not. If true, egg pity and pull statistics will be applyed. + * Defines if the egg got pulled from a gacha or not. If true, egg pity and pull statistics will be applied. * Egg will be automaticly added to the game data. - * NEEDS `scene` `eggOption` to work. */ pulled?: boolean; /** @@ -32,7 +32,7 @@ export interface IEggOptions { * Will also define the text displayed in the egg list. */ sourceType?: EggSourceType; - /** Needs to be defined if `eggOption` pulled is defined or if no species or `isShiny` is defined since this will be needed to generate them. */ + /** Legacy field, kept for backwards-compatibility */ scene?: BattleScene; /** * Sets the tier of the egg. Only species of this tier can be hatched from this egg. @@ -41,10 +41,7 @@ export interface IEggOptions { tier?: EggTier; /** Sets how many waves it will take till this egg hatches. */ hatchWaves?: number; - /** - * Sets the exact species that will hatch from this egg. - * Needs `scene` `eggOption` if not provided. - */ + /** Sets the exact species that will hatch from this egg. */ species?: Species; /** Defines if the hatched pokemon will be a shiny. */ isShiny?: boolean; @@ -56,8 +53,7 @@ export interface IEggOptions { * Defines if the egg will hatch with the hidden ability of this species. * If no hidden ability exist, a random one will get choosen. */ - overrideHiddenAbility?: boolean, - + overrideHiddenAbility?: boolean; /** Can customize the message displayed for where the egg was obtained */ eggDescriptor?: string; } @@ -148,7 +144,7 @@ export class Egg { // If egg was pulled, check if egg pity needs to override the egg tier if (eggOptions?.pulled) { // Needs this._tier and this._sourceType to work - this.checkForPityTierOverrides(eggOptions.scene!); // TODO: is this bang correct? + this.checkForPityTierOverrides(); } this._id = eggOptions?.id ?? Utils.randInt(EGG_SEED, EGG_SEED * this._tier); @@ -160,7 +156,7 @@ export class Egg { // First roll shiny and variant so we can filter if species with an variant exist this._isShiny = eggOptions?.isShiny ?? (Overrides.EGG_SHINY_OVERRIDE || this.rollShiny()); this._variantTier = eggOptions?.variantTier ?? (Overrides.EGG_VARIANT_OVERRIDE ?? this.rollVariant()); - this._species = eggOptions?.species ?? this.rollSpecies(eggOptions!.scene!)!; // TODO: Are those bangs correct? + this._species = eggOptions?.species ?? this.rollSpecies()!; // TODO: Is this bang correct? this._overrideHiddenAbility = eggOptions?.overrideHiddenAbility ?? false; @@ -178,19 +174,15 @@ export class Egg { // Needs this._tier so it needs to be generated afer the tier override if bought from same species this._eggMoveIndex = eggOptions?.eggMoveIndex ?? this.rollEggMoveIndex(); if (eggOptions?.pulled) { - this.increasePullStatistic(eggOptions.scene!); // TODO: is this bang correct? - this.addEggToGameData(eggOptions.scene!); // TODO: is this bang correct? + this.increasePullStatistic(); + this.addEggToGameData(); } }; - if (eggOptions?.scene) { - const seedOverride = Utils.randomString(24); - eggOptions?.scene.executeWithSeedOffset(() => { - generateEggProperties(eggOptions); - }, 0, seedOverride); - } else { // For legacy eggs without scene + const seedOverride = Utils.randomString(24); + globalScene.executeWithSeedOffset(() => { generateEggProperties(eggOptions); - } + }, 0, seedOverride); this._eggDescriptor = eggOptions?.eggDescriptor; } @@ -212,14 +204,14 @@ export class Egg { } // Generates a PlayerPokemon from an egg - public generatePlayerPokemon(scene: BattleScene): PlayerPokemon { + public generatePlayerPokemon(): PlayerPokemon { let ret: PlayerPokemon; - const generatePlayerPokemonHelper = (scene: BattleScene) => { + const generatePlayerPokemonHelper = () => { // Legacy egg wants to hatch. Generate missing properties if (!this._species) { this._isShiny = this.rollShiny(); - this._species = this.rollSpecies(scene!)!; // TODO: are these bangs correct? + this._species = this.rollSpecies()!; // TODO: is this bang correct? } let pokemonSpecies = getPokemonSpecies(this._species); @@ -238,7 +230,7 @@ export class Egg { } // This function has way to many optional parameters - ret = scene.addPlayerPokemon(pokemonSpecies, 1, abilityIndex, undefined, undefined, false); + ret = globalScene.addPlayerPokemon(pokemonSpecies, 1, abilityIndex, undefined, undefined, false); ret.shiny = this._isShiny; ret.variant = this._variantTier; @@ -250,16 +242,16 @@ export class Egg { }; ret = ret!; // Tell TS compiler it's defined now - scene.executeWithSeedOffset(() => { - generatePlayerPokemonHelper(scene); + globalScene.executeWithSeedOffset(() => { + generatePlayerPokemonHelper(); }, this._id, EGG_SEED.toString()); return ret; } // Doesn't need to be called if the egg got pulled by a gacha machiene - public addEggToGameData(scene: BattleScene): void { - scene.gameData.eggs.push(this); + public addEggToGameData(): void { + globalScene.gameData.eggs.push(this); } public getEggDescriptor(): string { @@ -291,12 +283,12 @@ export class Egg { return i18next.t("egg:hatchWavesMessageLongTime"); } - public getEggTypeDescriptor(scene: BattleScene): string { + public getEggTypeDescriptor(): string { switch (this.sourceType) { case EggSourceType.SAME_SPECIES_EGG: return this._eggDescriptor ?? i18next.t("egg:sameSpeciesEgg", { species: getPokemonSpecies(this._species).getName() }); case EggSourceType.GACHA_LEGENDARY: - return this._eggDescriptor ?? `${i18next.t("egg:gachaTypeLegendary")} (${getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(scene, this.timestamp)).getName()})`; + return this._eggDescriptor ?? `${i18next.t("egg:gachaTypeLegendary")} (${getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(this.timestamp)).getName()})`; case EggSourceType.GACHA_SHINY: return this._eggDescriptor ?? i18next.t("egg:gachaTypeShiny"); case EggSourceType.GACHA_MOVE: @@ -356,8 +348,8 @@ export class Egg { return tierValue >= GACHA_DEFAULT_COMMON_EGG_THRESHOLD + tierValueOffset ? EggTier.COMMON : tierValue >= GACHA_DEFAULT_RARE_EGG_THRESHOLD + tierValueOffset ? EggTier.RARE : tierValue >= GACHA_DEFAULT_EPIC_EGG_THRESHOLD + tierValueOffset ? EggTier.EPIC : EggTier.LEGENDARY; } - private rollSpecies(scene: BattleScene): Species | null { - if (!scene) { + private rollSpecies(): Species | null { + if (!globalScene) { return null; } /** @@ -376,7 +368,7 @@ export class Egg { } else if (this.tier === EggTier.LEGENDARY && this._sourceType === EggSourceType.GACHA_LEGENDARY) { if (!Utils.randSeedInt(2)) { - return getLegendaryGachaSpeciesForTimestamp(scene, this.timestamp); + return getLegendaryGachaSpeciesForTimestamp(this.timestamp); } } @@ -410,8 +402,8 @@ export class Egg { .filter(s => !pokemonPrevolutions.hasOwnProperty(s) && getPokemonSpecies(s).isObtainable() && ignoredSpecies.indexOf(s) === -1); // If this is the 10th egg without unlocking something new, attempt to force it. - if (scene.gameData.unlockPity[this.tier] >= 9) { - const lockedPool = speciesPool.filter(s => !scene.gameData.dexData[s].caughtAttr && !scene.gameData.eggs.some(e => e.species === s)); + if (globalScene.gameData.unlockPity[this.tier] >= 9) { + const lockedPool = speciesPool.filter(s => !globalScene.gameData.dexData[s].caughtAttr && !globalScene.gameData.eggs.some(e => e.species === s)); if (lockedPool.length) { // Skip this if everything is unlocked speciesPool = lockedPool; } @@ -454,10 +446,10 @@ export class Egg { } species = species!; // tell TS compiled it's defined now! - if (!!scene.gameData.dexData[species].caughtAttr || scene.gameData.eggs.some(e => e.species === species)) { - scene.gameData.unlockPity[this.tier] = Math.min(scene.gameData.unlockPity[this.tier] + 1, 10); + if (globalScene.gameData.dexData[species].caughtAttr || globalScene.gameData.eggs.some(e => e.species === species)) { + globalScene.gameData.unlockPity[this.tier] = Math.min(globalScene.gameData.unlockPity[this.tier] + 1, 10); } else { - scene.gameData.unlockPity[this.tier] = 0; + globalScene.gameData.unlockPity[this.tier] = 0; } return species; @@ -465,7 +457,7 @@ export class Egg { /** * Rolls whether the egg is shiny or not. - * @returns True if the egg is shiny + * @returns `true` if the egg is shiny **/ private rollShiny(): boolean { let shinyChance = GACHA_DEFAULT_SHINY_RATE; @@ -485,6 +477,7 @@ export class Egg { // Uses the same logic as pokemon.generateVariant(). I would like to only have this logic in one // place but I don't want to touch the pokemon class. + // TODO: Remove this or replace the one in the Pokemon class. private rollVariant(): VariantTier { if (!this.isShiny) { return VariantTier.STANDARD; @@ -500,38 +493,38 @@ export class Egg { } } - private checkForPityTierOverrides(scene: BattleScene): void { + private checkForPityTierOverrides(): void { const tierValueOffset = this._sourceType === EggSourceType.GACHA_LEGENDARY ? GACHA_LEGENDARY_UP_THRESHOLD_OFFSET : 0; - scene.gameData.eggPity[EggTier.RARE] += 1; - scene.gameData.eggPity[EggTier.EPIC] += 1; - scene.gameData.eggPity[EggTier.LEGENDARY] += 1 + tierValueOffset; + globalScene.gameData.eggPity[EggTier.RARE] += 1; + globalScene.gameData.eggPity[EggTier.EPIC] += 1; + globalScene.gameData.eggPity[EggTier.LEGENDARY] += 1 + tierValueOffset; // These numbers are roughly the 80% mark. That is, 80% of the time you'll get an egg before this gets triggered. - if (scene.gameData.eggPity[EggTier.LEGENDARY] >= EGG_PITY_LEGENDARY_THRESHOLD && this._tier === EggTier.COMMON) { + if (globalScene.gameData.eggPity[EggTier.LEGENDARY] >= EGG_PITY_LEGENDARY_THRESHOLD && this._tier === EggTier.COMMON) { this._tier = EggTier.LEGENDARY; - } else if (scene.gameData.eggPity[EggTier.EPIC] >= EGG_PITY_EPIC_THRESHOLD && this._tier === EggTier.COMMON) { + } else if (globalScene.gameData.eggPity[EggTier.EPIC] >= EGG_PITY_EPIC_THRESHOLD && this._tier === EggTier.COMMON) { this._tier = EggTier.EPIC; - } else if (scene.gameData.eggPity[EggTier.RARE] >= EGG_PITY_RARE_THRESHOLD && this._tier === EggTier.COMMON) { + } else if (globalScene.gameData.eggPity[EggTier.RARE] >= EGG_PITY_RARE_THRESHOLD && this._tier === EggTier.COMMON) { this._tier = EggTier.RARE; } - scene.gameData.eggPity[this._tier] = 0; + globalScene.gameData.eggPity[this._tier] = 0; } - private increasePullStatistic(scene: BattleScene): void { - scene.gameData.gameStats.eggsPulled++; + private increasePullStatistic(): void { + globalScene.gameData.gameStats.eggsPulled++; if (this.isManaphyEgg()) { - scene.gameData.gameStats.manaphyEggsPulled++; + globalScene.gameData.gameStats.manaphyEggsPulled++; this._hatchWaves = this.getEggTierDefaultHatchWaves(EggTier.EPIC); return; } switch (this.tier) { case EggTier.RARE: - scene.gameData.gameStats.rareEggsPulled++; + globalScene.gameData.gameStats.rareEggsPulled++; break; case EggTier.EPIC: - scene.gameData.gameStats.epicEggsPulled++; + globalScene.gameData.gameStats.epicEggsPulled++; break; case EggTier.LEGENDARY: - scene.gameData.gameStats.legendaryEggsPulled++; + globalScene.gameData.gameStats.legendaryEggsPulled++; break; } } @@ -552,7 +545,7 @@ export function getValidLegendaryGachaSpecies() : Species[] { .filter(s => getPokemonSpecies(s).isObtainable() && s !== Species.ETERNATUS); } -export function getLegendaryGachaSpeciesForTimestamp(scene: BattleScene, timestamp: number): Species { +export function getLegendaryGachaSpeciesForTimestamp(timestamp: number): Species { const legendarySpecies = getValidLegendaryGachaSpecies(); let ret: Species; @@ -563,7 +556,7 @@ export function getLegendaryGachaSpeciesForTimestamp(scene: BattleScene, timesta const offset = Math.floor(Math.floor(dayTimestamp / 86400000) / legendarySpecies.length); // Cycle number const index = Math.floor(dayTimestamp / 86400000) % legendarySpecies.length; // Index within cycle - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { ret = Phaser.Math.RND.shuffle(legendarySpecies)[index]; }, offset, EGG_SEED.toString()); ret = ret!; // tell TS compiler it's diff --git a/src/data/move.ts b/src/data/move.ts index 7a6f08a53725..e92ff54bf21b 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -40,6 +40,7 @@ import { GameMode } from "#app/game-mode"; import { applyChallenges, ChallengeType } from "./challenge"; import { SwitchType } from "#enums/switch-type"; import { StatusEffect } from "enums/status-effect"; +import { globalScene } from "#app/global-scene"; export enum MoveCategory { PHYSICAL, @@ -716,7 +717,7 @@ export default class Move implements Localizable { getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { let score = 0; - if (target.getAlly()?.getTag(BattlerTagType.COMMANDED)?.getSourcePokemon(target.scene) === target) { + if (target.getAlly()?.getTag(BattlerTagType.COMMANDED)?.getSourcePokemon() === target) { return 20 * (target.isPlayer() === user.isPlayer() ? -1 : 1); // always -20 with how the AI handles this score } @@ -748,10 +749,10 @@ export default class Move implements Localizable { const isOhko = this.hasAttr(OneHitKOAccuracyAttr); if (!isOhko) { - user.scene.applyModifiers(PokemonMoveAccuracyBoosterModifier, user.isPlayer(), user, moveAccuracy); + globalScene.applyModifiers(PokemonMoveAccuracyBoosterModifier, user.isPlayer(), user, moveAccuracy); } - if (user.scene.arena.weather?.weatherType === WeatherType.FOG) { + if (globalScene.arena.weather?.weatherType === WeatherType.FOG) { /** * The 0.9 multiplier is PokeRogue-only implementation, Bulbapedia uses 3/5 * See Fog {@link https://bulbapedia.bulbagarden.net/wiki/Fog} @@ -759,7 +760,7 @@ export default class Move implements Localizable { moveAccuracy.value = Math.floor(moveAccuracy.value * 0.9); } - if (!isOhko && user.scene.arena.getTag(ArenaTagType.GRAVITY)) { + if (!isOhko && globalScene.arena.getTag(ArenaTagType.GRAVITY)) { moveAccuracy.value = Math.floor(moveAccuracy.value * 1.67); } @@ -784,7 +785,7 @@ export default class Move implements Localizable { applyPreAttackAbAttrs(MoveTypeChangeAbAttr, source, target, this, true, null, typeChangeMovePowerMultiplier); const sourceTeraType = source.getTeraType(); - if (sourceTeraType !== Type.UNKNOWN && sourceTeraType === this.type && power.value < 60 && this.priority <= 0 && !this.hasAttr(MultiHitAttr) && !source.scene.findModifier(m => m instanceof PokemonMultiHitModifier && m.pokemonId === source.id)) { + if (sourceTeraType !== Type.UNKNOWN && sourceTeraType === this.type && power.value < 60 && this.priority <= 0 && !this.hasAttr(MultiHitAttr) && !globalScene.findModifier(m => m instanceof PokemonMultiHitModifier && m.pokemonId === source.id)) { power.value = 60; } @@ -795,7 +796,7 @@ export default class Move implements Localizable { } const fieldAuras = new Set( - source.scene.getField(true) + globalScene.getField(true) .map((p) => p.getAbilityAttrs(FieldMoveTypePowerBoostAbAttr).filter(attr => { const condition = attr.getCondition(); return (!condition || condition(p)); @@ -806,7 +807,7 @@ export default class Move implements Localizable { aura.applyPreAttack(source, null, simulated, target, this, [ power ]); } - const alliedField: Pokemon[] = source instanceof PlayerPokemon ? source.scene.getPlayerField() : source.scene.getEnemyField(); + const alliedField: Pokemon[] = source instanceof PlayerPokemon ? globalScene.getPlayerField() : globalScene.getEnemyField(); alliedField.forEach(p => applyPreAttackAbAttrs(UserFieldMoveTypePowerBoostAbAttr, p, target, this, simulated, power)); power.value *= typeChangeMovePowerMultiplier.value; @@ -819,8 +820,8 @@ export default class Move implements Localizable { applyMoveAttrs(VariablePowerAttr, source, target, this, power); if (!this.hasAttr(TypelessAttr)) { - source.scene.arena.applyTags(WeakenMoveTypeTag, simulated, this.type, power); - source.scene.applyModifiers(AttackTypeBoosterModifier, source.isPlayer(), source, this.type, power); + globalScene.arena.applyTags(WeakenMoveTypeTag, simulated, this.type, power); + globalScene.applyModifiers(AttackTypeBoosterModifier, source.isPlayer(), source, this.type, power); } if (source.getTag(HelpingHandTag)) { @@ -982,7 +983,7 @@ function ChargeMove(Base: TBase) { * @param target the {@linkcode Pokemon} targeted by this move (optional) */ showChargeText(user: Pokemon, target?: Pokemon): void { - user.scene.queueMessage(this._chargeText + globalScene.queueMessage(this._chargeText .replace("{USER}", getPokemonNameWithAffix(user)) .replace("{TARGET}", getPokemonNameWithAffix(target)) ); @@ -1213,7 +1214,7 @@ export class MoveEffectAttr extends MoveAttr { if ((!move.hasAttr(FlinchAttr) || moveChance.value <= move.chance) && !move.hasAttr(SecretPowerAttr)) { const userSide = user.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - user.scene.arena.applyTagsForSide(ArenaTagType.WATER_FIRE_PLEDGE, userSide, false, moveChance); + globalScene.arena.applyTagsForSide(ArenaTagType.WATER_FIRE_PLEDGE, userSide, false, moveChance); } if (!selfEffect) { @@ -1253,7 +1254,7 @@ export class MessageHeaderAttr extends MoveHeaderAttr { : this.message(user, move); if (message) { - user.scene.queueMessage(message); + globalScene.queueMessage(message); return true; } return false; @@ -1306,7 +1307,7 @@ export class PreMoveMessageAttr extends MoveAttr { ? this.message as string : this.message(user, target, move); if (message) { - user.scene.queueMessage(message, 500); + globalScene.queueMessage(message, 500); return true; } return false; @@ -1562,7 +1563,7 @@ export class RecoilAttr extends MoveEffectAttr { } user.damageAndUpdate(recoilDamage, HitResult.OTHER, false, true, true); - user.scene.queueMessage(i18next.t("moveTriggers:hitWithRecoil", { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t("moveTriggers:hitWithRecoil", { pokemonName: getPokemonNameWithAffix(user) })); user.turnData.damageTaken += recoilDamage; return true; @@ -1674,7 +1675,7 @@ export class HalfSacrificialAttr extends MoveEffectAttr { applyAbAttrs(BlockNonDirectDamageAbAttr, user, cancelled); if (!cancelled.value) { user.damageAndUpdate(Utils.toDmgValue(user.getMaxHp() / 2), HitResult.OTHER, false, true, true); - user.scene.queueMessage(i18next.t("moveTriggers:cutHpPowerUpMove", { pokemonName: getPokemonNameWithAffix(user) })); // Queue recoil message + globalScene.queueMessage(i18next.t("moveTriggers:cutHpPowerUpMove", { pokemonName: getPokemonNameWithAffix(user) })); // Queue recoil message } return true; } @@ -1779,7 +1780,7 @@ export class HealAttr extends MoveEffectAttr { * This heals the target and shows the appropriate message. */ addHealPhase(target: Pokemon, healRatio: number) { - target.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(target.getBattlerIndex(), Utils.toDmgValue(target.getMaxHp() * healRatio), i18next.t("moveTriggers:healHp", { pokemonName: getPokemonNameWithAffix(target) }), true, !this.showAnim)); } @@ -1819,11 +1820,11 @@ export class PartyStatusCureAttr extends MoveEffectAttr { if (!this.canApply(user, target, move, args)) { return false; } - const partyPokemon = user.isPlayer() ? user.scene.getPlayerParty() : user.scene.getEnemyParty(); + const partyPokemon = user.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); partyPokemon.forEach(p => this.cureStatus(p, user.id)); if (this.message) { - user.scene.queueMessage(this.message); + globalScene.queueMessage(this.message); } return true; @@ -1842,7 +1843,7 @@ export class PartyStatusCureAttr extends MoveEffectAttr { pokemon.resetStatus(); pokemon.updateInfo(); } else { - pokemon.scene.unshiftPhase(new ShowAbilityPhase(pokemon.scene, pokemon.id, pokemon.getPassiveAbility()?.id === this.abilityCondition)); + globalScene.unshiftPhase(new ShowAbilityPhase(pokemon.id, pokemon.getPassiveAbility()?.id === this.abilityCondition)); } } } @@ -1897,11 +1898,10 @@ export class SacrificialFullRestoreAttr extends SacrificialAttr { } // We don't know which party member will be chosen, so pick the highest max HP in the party - const maxPartyMemberHp = user.scene.getPlayerParty().map(p => p.getMaxHp()).reduce((maxHp: integer, hp: integer) => Math.max(hp, maxHp), 0); + const maxPartyMemberHp = globalScene.getPlayerParty().map(p => p.getMaxHp()).reduce((maxHp: integer, hp: integer) => Math.max(hp, maxHp), 0); - user.scene.pushPhase( + globalScene.pushPhase( new PokemonHealPhase( - user.scene, user.getBattlerIndex(), maxPartyMemberHp, i18next.t(this.moveMessage, { pokemonName: getPokemonNameWithAffix(user) }), @@ -1921,7 +1921,7 @@ export class SacrificialFullRestoreAttr extends SacrificialAttr { } getCondition(): MoveConditionFunc { - return (user, _target, _move) => user.scene.getPlayerParty().filter(p => p.isActive()).length > user.scene.currentBattle.getBattlerCount(); + return (user, _target, _move) => globalScene.getPlayerParty().filter(p => p.isActive()).length > globalScene.currentBattle.getBattlerCount(); } } @@ -1950,7 +1950,7 @@ export class IgnoreWeatherTypeDebuffAttr extends MoveAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const weatherModifier = args[0] as Utils.NumberHolder; //If the type-based attack power modifier due to weather (e.g. Water moves in Sun) is below 1, set it to 1 - if (user.scene.arena.weather?.weatherType === this.weather) { + if (globalScene.arena.weather?.weatherType === this.weather) { weatherModifier.value = Math.max(weatherModifier.value, 1); } return true; @@ -1964,8 +1964,8 @@ export abstract class WeatherHealAttr extends HealAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { let healRatio = 0.5; - if (!user.scene.arena.weather?.isEffectSuppressed(user.scene)) { - const weatherType = user.scene.arena.weather?.weatherType || WeatherType.NONE; + if (!globalScene.arena.weather?.isEffectSuppressed()) { + const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; healRatio = this.getWeatherHealRatio(weatherType); } this.addHealPhase(user, healRatio); @@ -2112,7 +2112,7 @@ export class HitHealAttr extends MoveEffectAttr { message = ""; } } - user.scene.unshiftPhase(new PokemonHealPhase(user.scene, user.getBattlerIndex(), healAmount, message, false, true)); + globalScene.unshiftPhase(new PokemonHealPhase(user.getBattlerIndex(), healAmount, message, false, true)); return true; } @@ -2251,7 +2251,7 @@ export class MultiHitAttr extends MoveAttr { case MultiHitType._10: return 10; case MultiHitType.BEAT_UP: - const party = user.isPlayer() ? user.scene.getPlayerParty() : user.scene.getEnemyParty(); + const party = user.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); // No status means the ally pokemon can contribute to Beat Up return party.reduce((total, pokemon) => { return total + (pokemon.id === user.id ? 1 : pokemon?.status && pokemon.status.effect !== StatusEffect.NONE ? 0 : 1); @@ -2309,7 +2309,7 @@ export class StatusEffectAttr extends MoveEffectAttr { if (user !== target && target.isSafeguarded(user)) { if (move.category === MoveCategory.STATUS) { - user.scene.queueMessage(i18next.t("moveTriggers:safeguard", { targetName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:safeguard", { targetName: getPokemonNameWithAffix(target) })); } return false; } @@ -2414,9 +2414,9 @@ export class StealHeldItemChanceAttr extends MoveEffectAttr { const highestItemTier = heldItems.map(m => m.type.getOrInferTier(poolType)).reduce((highestTier, tier) => Math.max(tier!, highestTier), 0); // TODO: is the bang after tier correct? const tierHeldItems = heldItems.filter(m => m.type.getOrInferTier(poolType) === highestItemTier); const stolenItem = tierHeldItems[user.randSeedInt(tierHeldItems.length)]; - user.scene.tryTransferHeldItemModifier(stolenItem, user, false).then(success => { + globalScene.tryTransferHeldItemModifier(stolenItem, user, false).then(success => { if (success) { - user.scene.queueMessage(i18next.t("moveTriggers:stoleItem", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), itemName: stolenItem.type.name })); + globalScene.queueMessage(i18next.t("moveTriggers:stoleItem", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), itemName: stolenItem.type.name })); } resolve(success); }); @@ -2428,7 +2428,7 @@ export class StealHeldItemChanceAttr extends MoveEffectAttr { } getTargetHeldItems(target: Pokemon): PokemonHeldItemModifier[] { - return target.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + return globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === target.id, target.isPlayer()) as PokemonHeldItemModifier[]; } @@ -2496,13 +2496,13 @@ export class RemoveHeldItemAttr extends MoveEffectAttr { // Decrease item amount and update icon target.loseHeldItem(removedItem); - target.scene.updateModifiers(target.isPlayer()); + globalScene.updateModifiers(target.isPlayer()); if (this.berriesOnly) { - user.scene.queueMessage(i18next.t("moveTriggers:incineratedItem", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), itemName: removedItem.type.name })); + globalScene.queueMessage(i18next.t("moveTriggers:incineratedItem", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), itemName: removedItem.type.name })); } else { - user.scene.queueMessage(i18next.t("moveTriggers:knockedOffItem", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), itemName: removedItem.type.name })); + globalScene.queueMessage(i18next.t("moveTriggers:knockedOffItem", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), itemName: removedItem.type.name })); } } @@ -2510,7 +2510,7 @@ export class RemoveHeldItemAttr extends MoveEffectAttr { } getTargetHeldItems(target: Pokemon): PokemonHeldItemModifier[] { - return target.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + return globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === target.id, target.isPlayer()) as PokemonHeldItemModifier[]; } @@ -2552,7 +2552,7 @@ export class EatBerryAttr extends MoveEffectAttr { } this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)]; const preserve = new Utils.BooleanHolder(false); - target.scene.applyModifiers(PreserveBerryModifier, target.isPlayer(), target, preserve); // check for berry pouch preservation + globalScene.applyModifiers(PreserveBerryModifier, target.isPlayer(), target, preserve); // check for berry pouch preservation if (!preserve.value) { this.reduceBerryModifier(target); } @@ -2561,7 +2561,7 @@ export class EatBerryAttr extends MoveEffectAttr { } getTargetHeldBerries(target: Pokemon): BerryModifier[] { - return target.scene.findModifiers(m => m instanceof BerryModifier + return globalScene.findModifiers(m => m instanceof BerryModifier && (m as BerryModifier).pokemonId === target.id, target.isPlayer()) as BerryModifier[]; } @@ -2569,7 +2569,7 @@ export class EatBerryAttr extends MoveEffectAttr { if (this.chosenBerry) { target.loseHeldItem(this.chosenBerry); } - target.scene.updateModifiers(target.isPlayer()); + globalScene.updateModifiers(target.isPlayer()); } eatBerry(consumer: Pokemon, berryOwner?: Pokemon) { @@ -2612,7 +2612,7 @@ export class StealEatBerryAttr extends EatBerryAttr { this.chosenBerry = heldBerries[user.randSeedInt(heldBerries.length)]; applyPostItemLostAbAttrs(PostItemLostAbAttr, target, false); const message = i18next.t("battle:stealEatBerry", { pokemonName: user.name, targetName: target.name, berryName: this.chosenBerry.type.name }); - user.scene.queueMessage(message); + globalScene.queueMessage(message); this.reduceBerryModifier(target); this.eatBerry(user, target); return true; @@ -2660,7 +2660,7 @@ export class HealStatusEffectAttr extends MoveEffectAttr { const pokemon = this.selfTarget ? user : target; if (pokemon.status && this.effects.includes(pokemon.status.effect)) { - pokemon.scene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); + globalScene.queueMessage(getStatusEffectHealText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); pokemon.resetStatus(); pokemon.updateInfo(); @@ -2731,11 +2731,11 @@ export class WeatherChangeAttr extends MoveEffectAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - return user.scene.arena.trySetWeather(this.weatherType, true); + return globalScene.arena.trySetWeather(this.weatherType, true); } getCondition(): MoveConditionFunc { - return (user, target, move) => !user.scene.arena.weather || (user.scene.arena.weather.weatherType !== this.weatherType && !user.scene.arena.weather.isImmutable()); + return (user, target, move) => !globalScene.arena.weather || (globalScene.arena.weather.weatherType !== this.weatherType && !globalScene.arena.weather.isImmutable()); } } @@ -2749,8 +2749,8 @@ export class ClearWeatherAttr extends MoveEffectAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - if (user.scene.arena.weather?.weatherType === this.weatherType) { - return user.scene.arena.trySetWeather(WeatherType.NONE, true); + if (globalScene.arena.weather?.weatherType === this.weatherType) { + return globalScene.arena.trySetWeather(WeatherType.NONE, true); } return false; @@ -2767,16 +2767,16 @@ export class TerrainChangeAttr extends MoveEffectAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - return user.scene.arena.trySetTerrain(this.terrainType, true, true); + return globalScene.arena.trySetTerrain(this.terrainType, true, true); } getCondition(): MoveConditionFunc { - return (user, target, move) => !user.scene.arena.terrain || (user.scene.arena.terrain.terrainType !== this.terrainType); + return (user, target, move) => !globalScene.arena.terrain || (globalScene.arena.terrain.terrainType !== this.terrainType); } getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): number { // TODO: Expand on this - return user.scene.arena.terrain ? 0 : 6; + return globalScene.arena.terrain ? 0 : 6; } } @@ -2786,7 +2786,7 @@ export class ClearTerrainAttr extends MoveEffectAttr { } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - return user.scene.arena.trySetTerrain(TerrainType.NONE, true, true); + return globalScene.arena.trySetTerrain(TerrainType.NONE, true, true); } } @@ -2855,12 +2855,12 @@ export class InstantChargeAttr extends MoveAttr { export class WeatherInstantChargeAttr extends InstantChargeAttr { constructor(weatherTypes: WeatherType[]) { super((user, move) => { - const currentWeather = user.scene.arena.weather; + const currentWeather = globalScene.arena.weather; if (Utils.isNullOrUndefined(currentWeather?.weatherType)) { return false; } else { - return !currentWeather?.isEffectSuppressed(user.scene) + return !currentWeather?.isEffectSuppressed() && weatherTypes.includes(currentWeather?.weatherType); } }); @@ -2904,16 +2904,16 @@ export class DelayedAttackAttr extends OverrideMoveEffectAttr { const side = target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; return new Promise(resolve => { if (args.length < 2 || !args[1]) { - new MoveChargeAnim(this.chargeAnim, move.id, user).play(user.scene, false, () => { + new MoveChargeAnim(this.chargeAnim, move.id, user).play(false, () => { (args[0] as Utils.BooleanHolder).value = true; - user.scene.queueMessage(this.chargeText.replace("{TARGET}", getPokemonNameWithAffix(target)).replace("{USER}", getPokemonNameWithAffix(user))); + globalScene.queueMessage(this.chargeText.replace("{TARGET}", getPokemonNameWithAffix(target)).replace("{USER}", getPokemonNameWithAffix(user))); user.pushMoveHistory({ move: move.id, targets: [ target.getBattlerIndex() ], result: MoveResult.OTHER }); - user.scene.arena.addTag(this.tagType, 3, move.id, user.id, side, false, target.getBattlerIndex()); + globalScene.arena.addTag(this.tagType, 3, move.id, user.id, side, false, target.getBattlerIndex()); resolve(true); }); } else { - user.scene.ui.showText(i18next.t("moveTriggers:tookMoveAttack", { pokemonName: getPokemonNameWithAffix(user.scene.getPokemonById(target.id) ?? undefined), moveName: move.name }), null, () => resolve(true)); + globalScene.ui.showText(i18next.t("moveTriggers:tookMoveAttack", { pokemonName: getPokemonNameWithAffix(globalScene.getPokemonById(target.id) ?? undefined), moveName: move.name }), null, () => resolve(true)); } }); } @@ -2942,29 +2942,29 @@ export class AwaitCombinedPledgeAttr extends OverrideMoveEffectAttr { override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (user.turnData.combiningPledge) { // "The two moves have become one!\nIt's a combined move!" - user.scene.queueMessage(i18next.t("moveTriggers:combiningPledge")); + globalScene.queueMessage(i18next.t("moveTriggers:combiningPledge")); return false; } const overridden = args[0] as Utils.BooleanHolder; - const allyMovePhase = user.scene.findPhase((phase) => phase instanceof MovePhase && phase.pokemon.isPlayer() === user.isPlayer()); + const allyMovePhase = globalScene.findPhase((phase) => phase instanceof MovePhase && phase.pokemon.isPlayer() === user.isPlayer()); if (allyMovePhase) { const allyMove = allyMovePhase.move.getMove(); if (allyMove !== move && allyMove.hasAttr(AwaitCombinedPledgeAttr)) { [ user, allyMovePhase.pokemon ].forEach((p) => p.turnData.combiningPledge = move.id); // "{userPokemonName} is waiting for {allyPokemonName}'s move..." - user.scene.queueMessage(i18next.t("moveTriggers:awaitingPledge", { + globalScene.queueMessage(i18next.t("moveTriggers:awaitingPledge", { userPokemonName: getPokemonNameWithAffix(user), allyPokemonName: getPokemonNameWithAffix(allyMovePhase.pokemon) })); // Move the ally's MovePhase (if needed) so that the ally moves next - const allyMovePhaseIndex = user.scene.phaseQueue.indexOf(allyMovePhase); - const firstMovePhaseIndex = user.scene.phaseQueue.findIndex((phase) => phase instanceof MovePhase); + const allyMovePhaseIndex = globalScene.phaseQueue.indexOf(allyMovePhase); + const firstMovePhaseIndex = globalScene.phaseQueue.findIndex((phase) => phase instanceof MovePhase); if (allyMovePhaseIndex !== firstMovePhaseIndex) { - user.scene.prependToPhase(user.scene.phaseQueue.splice(allyMovePhaseIndex, 1)[0], MovePhase); + globalScene.prependToPhase(globalScene.phaseQueue.splice(allyMovePhaseIndex, 1)[0], MovePhase); } overridden.value = true; @@ -3058,7 +3058,7 @@ export class StatStageChangeAttr extends MoveEffectAttr { const moveChance = this.getMoveChance(user, target, move, this.selfTarget, true); if (moveChance < 0 || moveChance === 100 || user.randSeedInt(100) < moveChance) { const stages = this.getLevels(user); - user.scene.unshiftPhase(new StatStageChangePhase(user.scene, (this.selfTarget ? user : target).getBattlerIndex(), this.selfTarget, this.stats, stages, this.showMessage)); + globalScene.unshiftPhase(new StatStageChangePhase((this.selfTarget ? user : target).getBattlerIndex(), this.selfTarget, this.stats, stages, this.showMessage)); return true; } @@ -3129,11 +3129,11 @@ export class SecretPowerAttr extends MoveEffectAttr { return false; } let secondaryEffect: MoveEffectAttr; - const terrain = user.scene.arena.getTerrainType(); + const terrain = globalScene.arena.getTerrainType(); if (terrain !== TerrainType.NONE) { secondaryEffect = this.determineTerrainEffect(terrain); } else { - const biome = user.scene.arena.biomeType; + const biome = globalScene.arena.biomeType; secondaryEffect = this.determineBiomeEffect(biome); } return secondaryEffect.apply(user, target, move, []); @@ -3283,7 +3283,7 @@ export class AcupressureStatStageChangeAttr extends MoveEffectAttr { const randStats = BATTLE_STATS.filter(s => target.getStatStage(s) < 6); if (randStats.length > 0) { const boostStat = [ randStats[user.randSeedInt(randStats.length)] ]; - user.scene.unshiftPhase(new StatStageChangePhase(user.scene, target.getBattlerIndex(), this.selfTarget, boostStat, 2)); + globalScene.unshiftPhase(new StatStageChangePhase(target.getBattlerIndex(), this.selfTarget, boostStat, 2)); return true; } return false; @@ -3296,8 +3296,8 @@ export class GrowthStatStageChangeAttr extends StatStageChangeAttr { } getLevels(user: Pokemon): number { - if (!user.scene.arena.weather?.isEffectSuppressed(user.scene)) { - const weatherType = user.scene.arena.weather?.weatherType; + if (!globalScene.arena.weather?.isEffectSuppressed()) { + const weatherType = globalScene.arena.weather?.weatherType; if (weatherType === WeatherType.SUNNY || weatherType === WeatherType.HARSH_SUN) { return this.stages + 1; } @@ -3365,7 +3365,7 @@ export class OrderUpStatBoostAttr extends MoveEffectAttr { break; } - user.scene.unshiftPhase(new StatStageChangePhase(user.scene, user.getBattlerIndex(), this.selfTarget, [ increasedStat ], 1)); + globalScene.unshiftPhase(new StatStageChangePhase(user.getBattlerIndex(), this.selfTarget, [ increasedStat ], 1)); return true; } } @@ -3388,7 +3388,7 @@ export class CopyStatsAttr extends MoveEffectAttr { } target.updateInfo(); user.updateInfo(); - target.scene.queueMessage(i18next.t("moveTriggers:copiedStatChanges", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:copiedStatChanges", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })); return true; } @@ -3407,7 +3407,7 @@ export class InvertStatsAttr extends MoveEffectAttr { target.updateInfo(); user.updateInfo(); - target.scene.queueMessage(i18next.t("moveTriggers:invertStats", { pokemonName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:invertStats", { pokemonName: getPokemonNameWithAffix(target) })); return true; } @@ -3422,13 +3422,13 @@ export class ResetStatsAttr extends MoveEffectAttr { async apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise { const promises: Promise[] = []; if (this.targetAllPokemon) { // Target all pokemon on the field when Freezy Frost or Haze are used - const activePokemon = user.scene.getField(true); + const activePokemon = globalScene.getField(true); activePokemon.forEach(p => promises.push(this.resetStats(p))); - target.scene.queueMessage(i18next.t("moveTriggers:statEliminated")); + globalScene.queueMessage(i18next.t("moveTriggers:statEliminated")); } else { // Affects only the single target when Clear Smog is used if (!move.hitsSubstitute(user, target)) { promises.push(this.resetStats(target)); - target.scene.queueMessage(i18next.t("moveTriggers:resetStats", { pokemonName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:resetStats", { pokemonName: getPokemonNameWithAffix(target) })); } } @@ -3481,9 +3481,9 @@ export class SwapStatStagesAttr extends MoveEffectAttr { user.updateInfo(); if (this.stats.length === 7) { - user.scene.queueMessage(i18next.t("moveTriggers:switchedStatChanges", { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t("moveTriggers:switchedStatChanges", { pokemonName: getPokemonNameWithAffix(user) })); } else if (this.stats.length === 2) { - user.scene.queueMessage(i18next.t("moveTriggers:switchedTwoStatChanges", { + globalScene.queueMessage(i18next.t("moveTriggers:switchedTwoStatChanges", { pokemonName: getPokemonNameWithAffix(user), firstStat: i18next.t(getStatKey(this.stats[0])), secondStat: i18next.t(getStatKey(this.stats[1])) @@ -3508,12 +3508,12 @@ export class HpSplitAttr extends MoveEffectAttr { if (user.hp < hpValue) { const healing = user.heal(hpValue - user.hp); if (healing) { - user.scene.damageNumberHandler.add(user, healing, HitResult.HEAL); + globalScene.damageNumberHandler.add(user, healing, HitResult.HEAL); } } else if (user.hp > hpValue) { const damage = user.damage(user.hp - hpValue, true); if (damage) { - user.scene.damageNumberHandler.add(user, damage); + globalScene.damageNumberHandler.add(user, damage); } } infoUpdates.push(user.updateInfo()); @@ -3521,12 +3521,12 @@ export class HpSplitAttr extends MoveEffectAttr { if (target.hp < hpValue) { const healing = target.heal(hpValue - target.hp); if (healing) { - user.scene.damageNumberHandler.add(user, healing, HitResult.HEAL); + globalScene.damageNumberHandler.add(user, healing, HitResult.HEAL); } } else if (target.hp > hpValue) { const damage = target.damage(target.hp - hpValue, true); if (damage) { - target.scene.damageNumberHandler.add(target, damage); + globalScene.damageNumberHandler.add(target, damage); } } infoUpdates.push(target.updateInfo()); @@ -3609,7 +3609,7 @@ export class MovePowerMultiplierAttr extends VariablePowerAttr { * @returns The base power of the Beat Up hit. */ const beatUpFunc = (user: Pokemon, allyIndex: number): number => { - const party = user.isPlayer() ? user.scene.getPlayerParty() : user.scene.getEnemyParty(); + const party = user.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); for (let i = allyIndex; i < party.length; i++) { const pokemon = party[i]; @@ -3637,7 +3637,7 @@ export class BeatUpAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const power = args[0] as Utils.NumberHolder; - const party = user.isPlayer() ? user.scene.getPlayerParty() : user.scene.getEnemyParty(); + const party = user.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); const allyCount = party.filter(pokemon => { return pokemon.id === user.id || !pokemon.status?.effect; }).length; @@ -3649,19 +3649,19 @@ export class BeatUpAttr extends VariablePowerAttr { const doublePowerChanceMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => { let message: string = ""; - user.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const rand = Utils.randSeedInt(100); if (rand < move.chance) { message = i18next.t("moveTriggers:goingAllOutForAttack", { pokemonName: getPokemonNameWithAffix(user) }); } - }, user.scene.currentBattle.turn << 6, user.scene.waveSeed); + }, globalScene.currentBattle.turn << 6, globalScene.waveSeed); return message; }; export class DoublePowerChanceAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { let rand: integer; - user.scene.executeWithSeedOffset(() => rand = Utils.randSeedInt(100), user.scene.currentBattle.turn << 6, user.scene.waveSeed); + globalScene.executeWithSeedOffset(() => rand = Utils.randSeedInt(100), globalScene.currentBattle.turn << 6, globalScene.waveSeed); if (rand! < move.chance) { const power = args[0] as Utils.NumberHolder; power.value *= 2; @@ -3895,8 +3895,8 @@ export class OpponentHighHpPowerAttr extends VariablePowerAttr { export class FirstAttackDoublePowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - console.log(target.getLastXMoves(1), target.scene.currentBattle.turn); - if (!target.getLastXMoves(1).find(m => m.turn === target.scene.currentBattle.turn)) { + console.log(target.getLastXMoves(1), globalScene.currentBattle.turn); + if (!target.getLastXMoves(1).find(m => m.turn === globalScene.currentBattle.turn)) { (args[0] as Utils.NumberHolder).value *= 2; return true; } @@ -3919,7 +3919,7 @@ export class TurnDamagedDoublePowerAttr extends VariablePowerAttr { const magnitudeMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => { let message: string; - user.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const magnitudeThresholds = [ 5, 15, 35, 65, 75, 95 ]; const rand = Utils.randSeedInt(100); @@ -3932,7 +3932,7 @@ const magnitudeMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => { } message = i18next.t("moveTriggers:magnitudeMessage", { magnitude: m + 4 }); - }, user.scene.currentBattle.turn << 6, user.scene.waveSeed); + }, globalScene.currentBattle.turn << 6, globalScene.waveSeed); return message!; }; @@ -3945,7 +3945,7 @@ export class MagnitudePowerAttr extends VariablePowerAttr { let rand: integer; - user.scene.executeWithSeedOffset(() => rand = Utils.randSeedInt(100), user.scene.currentBattle.turn << 6, user.scene.waveSeed); + globalScene.executeWithSeedOffset(() => rand = Utils.randSeedInt(100), globalScene.currentBattle.turn << 6, globalScene.waveSeed); let m = 0; for (; m < magnitudeThresholds.length; m++) { @@ -3962,9 +3962,9 @@ export class MagnitudePowerAttr extends VariablePowerAttr { export class AntiSunlightPowerDecreaseAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - if (!user.scene.arena.weather?.isEffectSuppressed(user.scene)) { + if (!globalScene.arena.weather?.isEffectSuppressed()) { const power = args[0] as Utils.NumberHolder; - const weatherType = user.scene.arena.weather?.weatherType || WeatherType.NONE; + const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; switch (weatherType) { case WeatherType.RAIN: case WeatherType.SANDSTORM: @@ -4080,7 +4080,7 @@ export class PresentPowerAttr extends VariablePowerAttr { } else if (80 < powerSeed && powerSeed <= 100) { // If this move is multi-hit, disable all other hits user.stopMultiHit(); - target.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(target.getBattlerIndex(), Utils.toDmgValue(target.getMaxHp() / 4), i18next.t("moveTriggers:regainedHealth", { pokemonName: getPokemonNameWithAffix(target) }), true)); } @@ -4230,7 +4230,7 @@ export class LastMoveDoublePowerAttr extends VariablePowerAttr { pokemonActed.push(enemy); } - if (user.scene.currentBattle.double) { + if (globalScene.currentBattle.double) { const userAlly = user.getAlly(); const enemyAlly = enemy?.getAlly(); @@ -4332,7 +4332,7 @@ export class CueNextRoundAttr extends MoveEffectAttr { } override apply(user: Pokemon, target: Pokemon, move: Move, args?: any[]): boolean { - const nextRoundPhase = user.scene.findPhase(phase => + const nextRoundPhase = globalScene.findPhase(phase => phase instanceof MovePhase && phase.move.moveId === Moves.ROUND ); @@ -4341,10 +4341,10 @@ export class CueNextRoundAttr extends MoveEffectAttr { } // Update the phase queue so that the next Pokemon using Round moves next - const nextRoundIndex = user.scene.phaseQueue.indexOf(nextRoundPhase); - const nextMoveIndex = user.scene.phaseQueue.findIndex(phase => phase instanceof MovePhase); + const nextRoundIndex = globalScene.phaseQueue.indexOf(nextRoundPhase); + const nextMoveIndex = globalScene.phaseQueue.findIndex(phase => phase instanceof MovePhase); if (nextRoundIndex !== nextMoveIndex) { - user.scene.prependToPhase(user.scene.phaseQueue.splice(nextRoundIndex, 1)[0], MovePhase); + globalScene.prependToPhase(globalScene.phaseQueue.splice(nextRoundIndex, 1)[0], MovePhase); } // Mark the corresponding Pokemon as having "joined the Round" (for doubling power later) @@ -4419,9 +4419,9 @@ export class VariableAccuracyAttr extends MoveAttr { */ export class ThunderAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - if (!user.scene.arena.weather?.isEffectSuppressed(user.scene)) { + if (!globalScene.arena.weather?.isEffectSuppressed()) { const accuracy = args[0] as Utils.NumberHolder; - const weatherType = user.scene.arena.weather?.weatherType || WeatherType.NONE; + const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; switch (weatherType) { case WeatherType.SUNNY: case WeatherType.HARSH_SUN: @@ -4445,9 +4445,9 @@ export class ThunderAccuracyAttr extends VariableAccuracyAttr { */ export class StormAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - if (!user.scene.arena.weather?.isEffectSuppressed(user.scene)) { + if (!globalScene.arena.weather?.isEffectSuppressed()) { const accuracy = args[0] as Utils.NumberHolder; - const weatherType = user.scene.arena.weather?.weatherType || WeatherType.NONE; + const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; switch (weatherType) { case WeatherType.RAIN: case WeatherType.HEAVY_RAIN: @@ -4501,9 +4501,9 @@ export class ToxicAccuracyAttr extends VariableAccuracyAttr { export class BlizzardAccuracyAttr extends VariableAccuracyAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - if (!user.scene.arena.weather?.isEffectSuppressed(user.scene)) { + if (!globalScene.arena.weather?.isEffectSuppressed()) { const accuracy = args[0] as Utils.NumberHolder; - const weatherType = user.scene.arena.weather?.weatherType || WeatherType.NONE; + const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE; if (weatherType === WeatherType.HAIL || weatherType === WeatherType.SNOW) { accuracy.value = -1; return true; @@ -4800,8 +4800,8 @@ export class WeatherBallTypeAttr extends VariableMoveTypeAttr { return false; } - if (!user.scene.arena.weather?.isEffectSuppressed(user.scene)) { - switch (user.scene.arena.weather?.weatherType) { + if (!globalScene.arena.weather?.isEffectSuppressed()) { + switch (globalScene.arena.weather?.weatherType) { case WeatherType.SUNNY: case WeatherType.HARSH_SUN: moveType.value = Type.FIRE; @@ -4851,7 +4851,7 @@ export class TerrainPulseTypeAttr extends VariableMoveTypeAttr { return false; } - const currentTerrain = user.scene.arena.getTerrainType(); + const currentTerrain = globalScene.arena.getTerrainType(); switch (currentTerrain) { case TerrainType.MISTY: moveType.value = Type.FAIRY; @@ -5146,7 +5146,7 @@ const crashDamageFunc = (user: Pokemon, move: Move) => { } user.damageAndUpdate(Utils.toDmgValue(user.getMaxHp() / 2), HitResult.OTHER, false, true); - user.scene.queueMessage(i18next.t("moveTriggers:keptGoingAndCrashed", { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t("moveTriggers:keptGoingAndCrashed", { pokemonName: getPokemonNameWithAffix(user) })); user.turnData.damageTaken += Utils.toDmgValue(user.getMaxHp() / 2); return true; @@ -5436,12 +5436,12 @@ export class CurseAttr extends MoveEffectAttr { apply(user: Pokemon, target: Pokemon, move:Move, args: any[]): boolean { if (user.getTypes(true).includes(Type.GHOST)) { if (target.getTag(BattlerTagType.CURSED)) { - user.scene.queueMessage(i18next.t("battle:attackFailed")); + globalScene.queueMessage(i18next.t("battle:attackFailed")); return false; } const curseRecoilDamage = Math.max(1, Math.floor(user.getMaxHp() / 2)); user.damageAndUpdate(curseRecoilDamage, HitResult.OTHER, false, true, true); - user.scene.queueMessage( + globalScene.queueMessage( i18next.t("battlerTags:cursedOnAdd", { pokemonNameWithAffix: getPokemonNameWithAffix(user), pokemonName: getPokemonNameWithAffix(target) @@ -5451,8 +5451,8 @@ export class CurseAttr extends MoveEffectAttr { target.addTag(BattlerTagType.CURSED, 0, move.id, user.id); return true; } else { - user.scene.unshiftPhase(new StatStageChangePhase(user.scene, user.getBattlerIndex(), true, [ Stat.ATK, Stat.DEF ], 1)); - user.scene.unshiftPhase(new StatStageChangePhase(user.scene, user.getBattlerIndex(), true, [ Stat.SPD ], -1)); + globalScene.unshiftPhase(new StatStageChangePhase(user.getBattlerIndex(), true, [ Stat.ATK, Stat.DEF ], 1)); + globalScene.unshiftPhase(new StatStageChangePhase(user.getBattlerIndex(), true, [ Stat.SPD ], -1)); return true; } } @@ -5523,7 +5523,7 @@ export class ConfuseAttr extends AddBattlerTagAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { if (!this.selfTarget && target.isSafeguarded(user)) { if (move.category === MoveCategory.STATUS) { - user.scene.queueMessage(i18next.t("moveTriggers:safeguard", { targetName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:safeguard", { targetName: getPokemonNameWithAffix(target) })); } return false; } @@ -5583,7 +5583,7 @@ export class IgnoreAccuracyAttr extends AddBattlerTagAttr { return false; } - user.scene.queueMessage(i18next.t("moveTriggers:tookAimAtTarget", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:tookAimAtTarget", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })); return true; } @@ -5599,7 +5599,7 @@ export class FaintCountdownAttr extends AddBattlerTagAttr { return false; } - user.scene.queueMessage(i18next.t("moveTriggers:faintCountdown", { pokemonName: getPokemonNameWithAffix(target), turnCount: this.turnCountMin - 1 })); + globalScene.queueMessage(i18next.t("moveTriggers:faintCountdown", { pokemonName: getPokemonNameWithAffix(target), turnCount: this.turnCountMin - 1 })); return true; } @@ -5629,7 +5629,7 @@ export class RemoveAllSubstitutesAttr extends MoveEffectAttr { return false; } - user.scene.getField(true).forEach(pokemon => + globalScene.getField(true).forEach(pokemon => pokemon.findAndRemoveTags(tag => tag.tagType === BattlerTagType.SUBSTITUTE)); return true; } @@ -5692,7 +5692,7 @@ export class AddArenaTagAttr extends MoveEffectAttr { if ((move.chance < 0 || move.chance === 100 || user.randSeedInt(100) < move.chance) && user.getLastXMoves(1)[0]?.result === MoveResult.SUCCESS) { const side = (this.selfSideTarget ? user : target).isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - user.scene.arena.addTag(this.tagType, this.turnCount, move.id, user.id, side); + globalScene.arena.addTag(this.tagType, this.turnCount, move.id, user.id, side); return true; } @@ -5701,7 +5701,7 @@ export class AddArenaTagAttr extends MoveEffectAttr { getCondition(): MoveConditionFunc | null { return this.failOnOverlap - ? (user, target, move) => !user.scene.arena.getTagOnSide(this.tagType, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY) + ? (user, target, move) => !globalScene.arena.getTagOnSide(this.tagType, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY) : null; } } @@ -5730,7 +5730,7 @@ export class RemoveArenaTagsAttr extends MoveEffectAttr { const side = (this.selfSideTarget ? user : target).isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; for (const tagType of this.tagTypes) { - user.scene.arena.removeTagOnSide(tagType, side); + globalScene.arena.removeTagOnSide(tagType, side); } return true; @@ -5741,7 +5741,7 @@ export class AddArenaTrapTagAttr extends AddArenaTagAttr { getCondition(): MoveConditionFunc { return (user, target, move) => { const side = (this.selfSideTarget ? user : target).isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - const tag = user.scene.arena.getTagOnSide(this.tagType, side) as ArenaTrapTag; + const tag = globalScene.arena.getTagOnSide(this.tagType, side) as ArenaTrapTag; if (!tag) { return true; } @@ -5765,9 +5765,9 @@ export class AddArenaTrapTagHitAttr extends AddArenaTagAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const moveChance = this.getMoveChance(user, target, move, this.selfTarget, true); const side = (this.selfSideTarget ? user : target).isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - const tag = user.scene.arena.getTagOnSide(this.tagType, side) as ArenaTrapTag; + const tag = globalScene.arena.getTagOnSide(this.tagType, side) as ArenaTrapTag; if ((moveChance < 0 || moveChance === 100 || user.randSeedInt(100) < moveChance) && user.getLastXMoves(1)[0]?.result === MoveResult.SUCCESS) { - user.scene.arena.addTag(this.tagType, 0, move.id, user.id, side); + globalScene.arena.addTag(this.tagType, 0, move.id, user.id, side); if (!tag) { return true; } @@ -5793,20 +5793,20 @@ export class RemoveArenaTrapAttr extends MoveEffectAttr { } if (this.targetBothSides) { - user.scene.arena.removeTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, ArenaTagSide.PLAYER); - - user.scene.arena.removeTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.ENEMY); - user.scene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.ENEMY); - user.scene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.ENEMY); - user.scene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, ArenaTagSide.PLAYER); + + globalScene.arena.removeTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, ArenaTagSide.ENEMY); } else { - user.scene.arena.removeTagOnSide(ArenaTagType.SPIKES, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.SPIKES, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER); } return true; @@ -5829,17 +5829,17 @@ export class RemoveScreensAttr extends MoveEffectAttr { } if (this.targetBothSides) { - user.scene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.PLAYER); + globalScene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.PLAYER); - user.scene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.ENEMY); - user.scene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.ENEMY); - user.scene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.ENEMY); } else { - user.scene.arena.removeTagOnSide(ArenaTagType.REFLECT, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY); - user.scene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY); - user.scene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.REFLECT, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY); + globalScene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY); } return true; @@ -5865,25 +5865,25 @@ export class SwapArenaTagsAttr extends MoveEffectAttr { return false; } - const tagPlayerTemp = user.scene.arena.findTagsOnSide((t => this.SwapTags.includes(t.tagType)), ArenaTagSide.PLAYER); - const tagEnemyTemp = user.scene.arena.findTagsOnSide((t => this.SwapTags.includes(t.tagType)), ArenaTagSide.ENEMY); + const tagPlayerTemp = globalScene.arena.findTagsOnSide((t => this.SwapTags.includes(t.tagType)), ArenaTagSide.PLAYER); + const tagEnemyTemp = globalScene.arena.findTagsOnSide((t => this.SwapTags.includes(t.tagType)), ArenaTagSide.ENEMY); if (tagPlayerTemp) { for (const swapTagsType of tagPlayerTemp) { - user.scene.arena.removeTagOnSide(swapTagsType.tagType, ArenaTagSide.PLAYER, true); - user.scene.arena.addTag(swapTagsType.tagType, swapTagsType.turnCount, swapTagsType.sourceMove, swapTagsType.sourceId!, ArenaTagSide.ENEMY, true); // TODO: is the bang correct? + globalScene.arena.removeTagOnSide(swapTagsType.tagType, ArenaTagSide.PLAYER, true); + globalScene.arena.addTag(swapTagsType.tagType, swapTagsType.turnCount, swapTagsType.sourceMove, swapTagsType.sourceId!, ArenaTagSide.ENEMY, true); // TODO: is the bang correct? } } if (tagEnemyTemp) { for (const swapTagsType of tagEnemyTemp) { - user.scene.arena.removeTagOnSide(swapTagsType.tagType, ArenaTagSide.ENEMY, true); - user.scene.arena.addTag(swapTagsType.tagType, swapTagsType.turnCount, swapTagsType.sourceMove, swapTagsType.sourceId!, ArenaTagSide.PLAYER, true); // TODO: is the bang correct? + globalScene.arena.removeTagOnSide(swapTagsType.tagType, ArenaTagSide.ENEMY, true); + globalScene.arena.addTag(swapTagsType.tagType, swapTagsType.turnCount, swapTagsType.sourceMove, swapTagsType.sourceId!, ArenaTagSide.PLAYER, true); // TODO: is the bang correct? } } - user.scene.queueMessage(i18next.t("moveTriggers:swapArenaTags", { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t("moveTriggers:swapArenaTags", { pokemonName: getPokemonNameWithAffix(user) })); return true; } } @@ -5936,40 +5936,40 @@ export class RevivalBlessingAttr extends MoveEffectAttr { return new Promise(resolve => { // If user is player, checks if the user has fainted pokemon if (user instanceof PlayerPokemon - && user.scene.getPlayerParty().findIndex(p => p.isFainted()) > -1) { + && globalScene.getPlayerParty().findIndex(p => p.isFainted()) > -1) { (user as PlayerPokemon).revivalBlessing().then(() => { resolve(true); }); // If user is enemy, checks that it is a trainer, and it has fainted non-boss pokemon in party } else if (user instanceof EnemyPokemon && user.hasTrainer() - && user.scene.getEnemyParty().findIndex(p => p.isFainted() && !p.isBoss()) > -1) { + && globalScene.getEnemyParty().findIndex(p => p.isFainted() && !p.isBoss()) > -1) { // Selects a random fainted pokemon - const faintedPokemon = user.scene.getEnemyParty().filter(p => p.isFainted() && !p.isBoss()); + const faintedPokemon = globalScene.getEnemyParty().filter(p => p.isFainted() && !p.isBoss()); const pokemon = faintedPokemon[user.randSeedInt(faintedPokemon.length)]; - const slotIndex = user.scene.getEnemyParty().findIndex(p => pokemon.id === p.id); + const slotIndex = globalScene.getEnemyParty().findIndex(p => pokemon.id === p.id); pokemon.resetStatus(); pokemon.heal(Math.min(Utils.toDmgValue(0.5 * pokemon.getMaxHp()), pokemon.getMaxHp())); - user.scene.queueMessage(i18next.t("moveTriggers:revivalBlessing", { pokemonName: getPokemonNameWithAffix(pokemon) }), 0, true); + globalScene.queueMessage(i18next.t("moveTriggers:revivalBlessing", { pokemonName: getPokemonNameWithAffix(pokemon) }), 0, true); - if (user.scene.currentBattle.double && user.scene.getEnemyParty().length > 1) { + if (globalScene.currentBattle.double && globalScene.getEnemyParty().length > 1) { const allyPokemon = user.getAlly(); if (slotIndex <= 1) { - user.scene.unshiftPhase(new SwitchSummonPhase(user.scene, SwitchType.SWITCH, pokemon.getFieldIndex(), slotIndex, false, false)); + globalScene.unshiftPhase(new SwitchSummonPhase(SwitchType.SWITCH, pokemon.getFieldIndex(), slotIndex, false, false)); } else if (allyPokemon.isFainted()) { - user.scene.unshiftPhase(new SwitchSummonPhase(user.scene, SwitchType.SWITCH, allyPokemon.getFieldIndex(), slotIndex, false, false)); + globalScene.unshiftPhase(new SwitchSummonPhase(SwitchType.SWITCH, allyPokemon.getFieldIndex(), slotIndex, false, false)); } } resolve(true); } else { - user.scene.queueMessage(i18next.t("battle:attackFailed")); + globalScene.queueMessage(i18next.t("battle:attackFailed")); resolve(false); } }); } getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { - if (user.hasTrainer() && user.scene.getEnemyParty().findIndex(p => p.isFainted() && !p.isBoss()) > -1) { + if (user.hasTrainer() && globalScene.getEnemyParty().findIndex(p => p.isFainted() && !p.isBoss()) > -1) { return 20; } @@ -6018,7 +6018,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { // Find indices of off-field Pokemon that are eligible to be switched into const eligibleNewIndices: number[] = []; - switchOutTarget.scene.getPlayerParty().forEach((pokemon, index) => { + globalScene.getPlayerParty().forEach((pokemon, index) => { if (pokemon.isAllowedInBattle() && !pokemon.isOnField()) { eligibleNewIndices.push(index); } @@ -6032,9 +6032,8 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { if (this.switchType === SwitchType.FORCE_SWITCH) { switchOutTarget.leaveField(true); const slotIndex = eligibleNewIndices[user.randSeedInt(eligibleNewIndices.length)]; - user.scene.prependToPhase( + globalScene.prependToPhase( new SwitchSummonPhase( - user.scene, this.switchType, switchOutTarget.getFieldIndex(), slotIndex, @@ -6045,9 +6044,8 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { ); } else { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); - user.scene.prependToPhase( + globalScene.prependToPhase( new SwitchPhase( - user.scene, this.switchType, switchOutTarget.getFieldIndex(), true, @@ -6059,10 +6057,10 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { } } return false; - } else if (user.scene.currentBattle.battleType !== BattleType.WILD) { // Switch out logic for enemy trainers + } else if (globalScene.currentBattle.battleType !== BattleType.WILD) { // Switch out logic for enemy trainers // Find indices of off-field Pokemon that are eligible to be switched into const eligibleNewIndices: number[] = []; - switchOutTarget.scene.getEnemyParty().forEach((pokemon, index) => { + globalScene.getEnemyParty().forEach((pokemon, index) => { if (pokemon.isAllowedInBattle() && !pokemon.isOnField()) { eligibleNewIndices.push(index); } @@ -6076,9 +6074,8 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { if (this.switchType === SwitchType.FORCE_SWITCH) { switchOutTarget.leaveField(true); const slotIndex = eligibleNewIndices[user.randSeedInt(eligibleNewIndices.length)]; - user.scene.prependToPhase( + globalScene.prependToPhase( new SwitchSummonPhase( - user.scene, this.switchType, switchOutTarget.getFieldIndex(), slotIndex, @@ -6089,12 +6086,11 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { ); } else { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); - user.scene.prependToPhase( + globalScene.prependToPhase( new SwitchSummonPhase( - user.scene, this.switchType, switchOutTarget.getFieldIndex(), - (user.scene.currentBattle.trainer ? user.scene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot) : 0), + (globalScene.currentBattle.trainer ? globalScene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot) : 0), false, false ), @@ -6115,7 +6111,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { } } - if (user.scene.currentBattle.waveIndex % 10 === 0) { + if (globalScene.currentBattle.waveIndex % 10 === 0) { return false; } @@ -6126,21 +6122,21 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { if (switchOutTarget.hp > 0) { switchOutTarget.leaveField(false); - user.scene.queueMessage(i18next.t("moveTriggers:fled", { pokemonName: getPokemonNameWithAffix(switchOutTarget) }), null, true, 500); + globalScene.queueMessage(i18next.t("moveTriggers:fled", { pokemonName: getPokemonNameWithAffix(switchOutTarget) }), null, true, 500); // in double battles redirect potential moves off fled pokemon - if (switchOutTarget.scene.currentBattle.double) { + if (globalScene.currentBattle.double) { const allyPokemon = switchOutTarget.getAlly(); - switchOutTarget.scene.redirectPokemonMoves(switchOutTarget, allyPokemon); + globalScene.redirectPokemonMoves(switchOutTarget, allyPokemon); } } if (!switchOutTarget.getAlly()?.isActive(true)) { - user.scene.clearEnemyHeldItemModifiers(); + globalScene.clearEnemyHeldItemModifiers(); if (switchOutTarget.hp) { - user.scene.pushPhase(new BattleEndPhase(user.scene, false)); - user.scene.pushPhase(new NewBattlePhase(user.scene)); + globalScene.pushPhase(new BattleEndPhase(false)); + globalScene.pushPhase(new NewBattlePhase()); } } } @@ -6170,11 +6166,11 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { // Dondozo with an allied Tatsugiri in its mouth cannot be forced out const commandedTag = switchOutTarget.getTag(BattlerTagType.COMMANDED); - if (commandedTag?.getSourcePokemon(switchOutTarget.scene)?.isActive(true)) { + if (commandedTag?.getSourcePokemon()?.isActive(true)) { return false; } - if (!player && user.scene.currentBattle.isBattleMysteryEncounter() && !user.scene.currentBattle.mysteryEncounter?.fleeAllowed) { + if (!player && globalScene.currentBattle.isBattleMysteryEncounter() && !globalScene.currentBattle.mysteryEncounter?.fleeAllowed) { // Don't allow wild opponents to be force switched during MEs with flee disabled return false; } @@ -6184,25 +6180,25 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { return !blockedByAbility.value; } - if (!player && user.scene.currentBattle.battleType === BattleType.WILD) { + if (!player && globalScene.currentBattle.battleType === BattleType.WILD) { if (this.isBatonPass()) { return false; } // Don't allow wild opponents to flee on the boss stage since it can ruin a run early on - if (user.scene.currentBattle.waveIndex % 10 === 0) { + if (globalScene.currentBattle.waveIndex % 10 === 0) { return false; } } - const party = player ? user.scene.getPlayerParty() : user.scene.getEnemyParty(); - return (!player && !user.scene.currentBattle.battleType) + const party = player ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); + return (!player && !globalScene.currentBattle.battleType) || party.filter(p => p.isAllowedInBattle() - && (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > user.scene.currentBattle.getBattlerCount(); + && (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > globalScene.currentBattle.getBattlerCount(); }; } getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { - if (!user.scene.getEnemyParty().find(p => p.isActive() && !p.isOnField())) { + if (!globalScene.getEnemyParty().find(p => p.isActive() && !p.isOnField())) { return -20; } let ret = this.selfSwitch ? Math.floor((1 - user.getHpRatio()) * 20) : super.getUserBenefitScore(user, target, move); @@ -6231,13 +6227,13 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { export class ChillyReceptionAttr extends ForceSwitchOutAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - user.scene.arena.trySetWeather(WeatherType.SNOW, true); + globalScene.arena.trySetWeather(WeatherType.SNOW, true); return super.apply(user, target, move, args); } getCondition(): MoveConditionFunc { // chilly reception move will go through if the weather is change-able to snow, or the user can switch out, else move will fail - return (user, target, move) => user.scene.arena.weather?.weatherType !== WeatherType.SNOW || super.getSwitchOutCondition()(user, target, move); + return (user, target, move) => globalScene.arena.weather?.weatherType !== WeatherType.SNOW || super.getSwitchOutCondition()(user, target, move); } } export class RemoveTypeAttr extends MoveEffectAttr { @@ -6295,7 +6291,7 @@ export class CopyTypeAttr extends MoveEffectAttr { user.summonData.types = targetTypes; user.updateInfo(); - user.scene.queueMessage(i18next.t("moveTriggers:copyType", { pokemonName: getPokemonNameWithAffix(user), targetPokemonName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:copyType", { pokemonName: getPokemonNameWithAffix(user), targetPokemonName: getPokemonNameWithAffix(target) })); return true; } @@ -6315,18 +6311,18 @@ export class CopyBiomeTypeAttr extends MoveEffectAttr { return false; } - const terrainType = user.scene.arena.getTerrainType(); + const terrainType = globalScene.arena.getTerrainType(); let typeChange: Type; if (terrainType !== TerrainType.NONE) { - typeChange = this.getTypeForTerrain(user.scene.arena.getTerrainType()); + typeChange = this.getTypeForTerrain(globalScene.arena.getTerrainType()); } else { - typeChange = this.getTypeForBiome(user.scene.arena.biomeType); + typeChange = this.getTypeForBiome(globalScene.arena.biomeType); } user.summonData.types = [ typeChange ]; user.updateInfo(); - user.scene.queueMessage(i18next.t("moveTriggers:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), typeName: i18next.t(`pokemonInfo:Type.${Type[typeChange]}`) })); + globalScene.queueMessage(i18next.t("moveTriggers:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), typeName: i18next.t(`pokemonInfo:Type.${Type[typeChange]}`) })); return true; } @@ -6431,7 +6427,7 @@ export class ChangeTypeAttr extends MoveEffectAttr { target.summonData.types = [ this.type ]; target.updateInfo(); - user.scene.queueMessage(i18next.t("moveTriggers:transformedIntoType", { pokemonName: getPokemonNameWithAffix(target), typeName: i18next.t(`pokemonInfo:Type.${Type[this.type]}`) })); + globalScene.queueMessage(i18next.t("moveTriggers:transformedIntoType", { pokemonName: getPokemonNameWithAffix(target), typeName: i18next.t(`pokemonInfo:Type.${Type[this.type]}`) })); return true; } @@ -6454,7 +6450,7 @@ export class AddTypeAttr extends MoveEffectAttr { target.summonData.addedType = this.type; target.updateInfo(); - user.scene.queueMessage(i18next.t("moveTriggers:addType", { typeName: i18next.t(`pokemonInfo:Type.${Type[this.type]}`), pokemonName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:addType", { typeName: i18next.t(`pokemonInfo:Type.${Type[this.type]}`), pokemonName: getPokemonNameWithAffix(target) })); return true; } @@ -6476,7 +6472,7 @@ export class FirstMoveTypeAttr extends MoveEffectAttr { const firstMoveType = target.getMoveset()[0]?.getMove().type!; // TODO: is this bang correct? user.summonData.types = [ firstMoveType ]; - user.scene.queueMessage(i18next.t("battle:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), type: i18next.t(`pokemonInfo:Type.${Type[firstMoveType]}`) })); + globalScene.queueMessage(i18next.t("battle:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), type: i18next.t(`pokemonInfo:Type.${Type[firstMoveType]}`) })); return true; } @@ -6519,7 +6515,7 @@ export class RandomMovesetMoveAttr extends OverrideMoveEffectAttr { } const targets = selectTargets; user.getMoveQueue().push({ move: move?.moveId!, targets: targets, ignorePP: true }); // TODO: is this bang correct? - user.scene.unshiftPhase(new MovePhase(user.scene, user, targets, moveset[moveIndex]!, true)); // There's a PR to re-do the move(s) that use this Attr, gonna put `!` for now + globalScene.unshiftPhase(new MovePhase(user, targets, moveset[moveIndex]!, true)); // There's a PR to re-do the move(s) that use this Attr, gonna put `!` for now return true; } @@ -6551,9 +6547,9 @@ export class RandomMoveAttr extends OverrideMoveEffectAttr { ? [ target.getBattlerIndex() ] : [ moveTargets.targets[user.randSeedInt(moveTargets.targets.length)] ]; user.getMoveQueue().push({ move: moveId, targets: targets, ignorePP: true }); - user.scene.unshiftPhase(new MovePhase(user.scene, user, targets, new PokemonMove(moveId, 0, 0, true), true)); - initMoveAnim(user.scene, moveId).then(() => { - loadMoveAnimAssets(user.scene, [ moveId ], true) + globalScene.unshiftPhase(new MovePhase(user, targets, new PokemonMove(moveId, 0, 0, true), true)); + initMoveAnim(moveId).then(() => { + loadMoveAnimAssets([ moveId ], true) .then(() => resolve(true)); }); }); @@ -6564,10 +6560,10 @@ export class NaturePowerAttr extends OverrideMoveEffectAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise { return new Promise(resolve => { let moveId; - switch (user.scene.arena.getTerrainType()) { + switch (globalScene.arena.getTerrainType()) { // this allows terrains to 'override' the biome move case TerrainType.NONE: - switch (user.scene.arena.biomeType) { + switch (globalScene.arena.biomeType) { case Biome.TOWN: moveId = Moves.ROUND; break; @@ -6694,9 +6690,9 @@ export class NaturePowerAttr extends OverrideMoveEffectAttr { } user.getMoveQueue().push({ move: moveId, targets: [ target.getBattlerIndex() ], ignorePP: true }); - user.scene.unshiftPhase(new MovePhase(user.scene, user, [ target.getBattlerIndex() ], new PokemonMove(moveId, 0, 0, true), true)); - initMoveAnim(user.scene, moveId).then(() => { - loadMoveAnimAssets(user.scene, [ moveId ], true) + globalScene.unshiftPhase(new MovePhase(user, [ target.getBattlerIndex() ], new PokemonMove(moveId, 0, 0, true), true)); + initMoveAnim(moveId).then(() => { + loadMoveAnimAssets([ moveId ], true) .then(() => resolve(true)); }); }); @@ -6704,7 +6700,7 @@ export class NaturePowerAttr extends OverrideMoveEffectAttr { } const lastMoveCopiableCondition: MoveConditionFunc = (user, target, move) => { - const copiableMove = user.scene.currentBattle.lastMove; + const copiableMove = globalScene.currentBattle.lastMove; if (!copiableMove) { return false; @@ -6721,7 +6717,7 @@ const lastMoveCopiableCondition: MoveConditionFunc = (user, target, move) => { export class CopyMoveAttr extends OverrideMoveEffectAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - const lastMove = user.scene.currentBattle.lastMove; + const lastMove = globalScene.currentBattle.lastMove; const moveTargets = getMoveTargets(user, lastMove); if (!moveTargets.targets.length) { @@ -6735,7 +6731,7 @@ export class CopyMoveAttr extends OverrideMoveEffectAttr { : [ moveTargets.targets[user.randSeedInt(moveTargets.targets.length)] ]; user.getMoveQueue().push({ move: lastMove, targets: targets, ignorePP: true }); - user.scene.unshiftPhase(new MovePhase(user.scene, user as PlayerPokemon, targets, new PokemonMove(lastMove, 0, 0, true), true)); + globalScene.unshiftPhase(new MovePhase(user as PlayerPokemon, targets, new PokemonMove(lastMove, 0, 0, true), true)); return true; } @@ -6770,13 +6766,13 @@ export class RepeatMoveAttr extends MoveEffectAttr { const movesetMove = target.getMoveset().find(m => m?.moveId === lastMove.move)!; const moveTargets = lastMove.targets ?? []; - user.scene.queueMessage(i18next.t("moveTriggers:instructingMove", { + globalScene.queueMessage(i18next.t("moveTriggers:instructingMove", { userPokemonName: getPokemonNameWithAffix(user), targetPokemonName: getPokemonNameWithAffix(target) })); target.getMoveQueue().unshift({ move: lastMove.move, targets: moveTargets, ignorePP: false }); target.turnData.extraTurns++; - target.scene.appendToPhase(new MovePhase(target.scene, target, moveTargets, movesetMove), MoveEndPhase); + globalScene.appendToPhase(new MovePhase(target, moveTargets, movesetMove), MoveEndPhase); return true; } @@ -6893,8 +6889,8 @@ export class ReducePpMoveAttr extends MoveEffectAttr { movesetMove!.ppUsed = Math.min((movesetMove?.ppUsed!) + this.reduction, movesetMove?.getMovePp()!); // TODO: is the bang correct? const message = i18next.t("battle:ppReduced", { targetName: getPokemonNameWithAffix(target), moveName: movesetMove?.getName(), reduction: (movesetMove?.ppUsed!) - lastPpUsed }); // TODO: is the bang correct? - user.scene.eventTarget.dispatchEvent(new MoveUsedEvent(target?.id, movesetMove?.getMove()!, movesetMove?.ppUsed!)); // TODO: are these bangs correct? - user.scene.queueMessage(message); + globalScene.eventTarget.dispatchEvent(new MoveUsedEvent(target?.id, movesetMove?.getMove()!, movesetMove?.ppUsed!)); // TODO: are these bangs correct? + globalScene.queueMessage(message); return true; } @@ -7005,7 +7001,7 @@ export class MovesetCopyMoveAttr extends OverrideMoveEffectAttr { user.summonData.moveset = user.getMoveset().slice(0); user.summonData.moveset[thisMoveIndex] = new PokemonMove(copiedMove.id, 0, 0); - user.scene.queueMessage(i18next.t("moveTriggers:copiedMove", { pokemonName: getPokemonNameWithAffix(user), moveName: copiedMove.name })); + globalScene.queueMessage(i18next.t("moveTriggers:copiedMove", { pokemonName: getPokemonNameWithAffix(user), moveName: copiedMove.name })); return true; } @@ -7055,7 +7051,7 @@ export class SketchAttr extends MoveEffectAttr { user.setMove(sketchIndex, sketchedMove.id); - user.scene.queueMessage(i18next.t("moveTriggers:sketchedMove", { pokemonName: getPokemonNameWithAffix(user), moveName: sketchedMove.name })); + globalScene.queueMessage(i18next.t("moveTriggers:sketchedMove", { pokemonName: getPokemonNameWithAffix(user), moveName: sketchedMove.name })); return true; } @@ -7113,9 +7109,9 @@ export class AbilityChangeAttr extends MoveEffectAttr { const moveTarget = this.selfTarget ? user : target; moveTarget.summonData.ability = this.ability; - user.scene.triggerPokemonFormChange(moveTarget, SpeciesFormChangeRevertWeatherFormTrigger); + globalScene.triggerPokemonFormChange(moveTarget, SpeciesFormChangeRevertWeatherFormTrigger); - user.scene.queueMessage(i18next.t("moveTriggers:acquiredAbility", { pokemonName: getPokemonNameWithAffix((this.selfTarget ? user : target)), abilityName: allAbilities[this.ability].name })); + globalScene.queueMessage(i18next.t("moveTriggers:acquiredAbility", { pokemonName: getPokemonNameWithAffix((this.selfTarget ? user : target)), abilityName: allAbilities[this.ability].name })); return true; } @@ -7141,11 +7137,11 @@ export class AbilityCopyAttr extends MoveEffectAttr { user.summonData.ability = target.getAbility().id; - user.scene.queueMessage(i18next.t("moveTriggers:copiedTargetAbility", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), abilityName: allAbilities[target.getAbility().id].name })); + globalScene.queueMessage(i18next.t("moveTriggers:copiedTargetAbility", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target), abilityName: allAbilities[target.getAbility().id].name })); - if (this.copyToPartner && user.scene.currentBattle?.double && user.getAlly().hp) { + if (this.copyToPartner && globalScene.currentBattle?.double && user.getAlly().hp) { user.getAlly().summonData.ability = target.getAbility().id; - user.getAlly().scene.queueMessage(i18next.t("moveTriggers:copiedTargetAbility", { pokemonName: getPokemonNameWithAffix(user.getAlly()), targetName: getPokemonNameWithAffix(target), abilityName: allAbilities[target.getAbility().id].name })); + globalScene.queueMessage(i18next.t("moveTriggers:copiedTargetAbility", { pokemonName: getPokemonNameWithAffix(user.getAlly()), targetName: getPokemonNameWithAffix(target), abilityName: allAbilities[target.getAbility().id].name })); } return true; @@ -7154,7 +7150,7 @@ export class AbilityCopyAttr extends MoveEffectAttr { getCondition(): MoveConditionFunc { return (user, target, move) => { let ret = !target.getAbility().hasAttr(UncopiableAbilityAbAttr) && !user.getAbility().hasAttr(UnsuppressableAbilityAbAttr); - if (this.copyToPartner && user.scene.currentBattle?.double) { + if (this.copyToPartner && globalScene.currentBattle?.double) { ret = ret && (!user.getAlly().hp || !user.getAlly().getAbility().hasAttr(UnsuppressableAbilityAbAttr)); } else { ret = ret && user.getAbility().id !== target.getAbility().id; @@ -7178,7 +7174,7 @@ export class AbilityGiveAttr extends MoveEffectAttr { target.summonData.ability = user.getAbility().id; - user.scene.queueMessage(i18next.t("moveTriggers:acquiredAbility", { pokemonName: getPokemonNameWithAffix(target), abilityName: allAbilities[user.getAbility().id].name })); + globalScene.queueMessage(i18next.t("moveTriggers:acquiredAbility", { pokemonName: getPokemonNameWithAffix(target), abilityName: allAbilities[user.getAbility().id].name })); return true; } @@ -7198,11 +7194,11 @@ export class SwitchAbilitiesAttr extends MoveEffectAttr { user.summonData.ability = target.getAbility().id; target.summonData.ability = tempAbilityId; - user.scene.queueMessage(i18next.t("moveTriggers:swappedAbilitiesWithTarget", { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t("moveTriggers:swappedAbilitiesWithTarget", { pokemonName: getPokemonNameWithAffix(user) })); // Swaps Forecast/Flower Gift from Castform/Cherrim - user.scene.arena.triggerWeatherBasedFormChangesToNormal(); + globalScene.arena.triggerWeatherBasedFormChangesToNormal(); // Swaps Forecast/Flower Gift to Castform/Cherrim (edge case) - user.scene.arena.triggerWeatherBasedFormChanges(); + globalScene.arena.triggerWeatherBasedFormChanges(); return true; } @@ -7228,9 +7224,9 @@ export class SuppressAbilitiesAttr extends MoveEffectAttr { } target.summonData.abilitySuppressed = true; - target.scene.arena.triggerWeatherBasedFormChangesToNormal(); + globalScene.arena.triggerWeatherBasedFormChangesToNormal(); - target.scene.queueMessage(i18next.t("moveTriggers:suppressAbilities", { pokemonName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:suppressAbilities", { pokemonName: getPokemonNameWithAffix(target) })); return true; } @@ -7309,7 +7305,7 @@ export class TransformAttr extends MoveEffectAttr { user.summonData.types = target.getTypes(); promises.push(user.updateInfo()); - user.scene.queueMessage(i18next.t("moveTriggers:transformedIntoTarget", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:transformedIntoTarget", { pokemonName: getPokemonNameWithAffix(user), targetName: getPokemonNameWithAffix(target) })); promises.push(user.loadAssets(false).then(() => { user.playAnim(); @@ -7352,7 +7348,7 @@ export class SwapStatAttr extends MoveEffectAttr { user.setStat(this.stat, target.getStat(this.stat, false), false); target.setStat(this.stat, temp, false); - user.scene.queueMessage(i18next.t("moveTriggers:switchedStat", { + globalScene.queueMessage(i18next.t("moveTriggers:switchedStat", { pokemonName: getPokemonNameWithAffix(user), stat: i18next.t(getStatKey(this.stat)), })); @@ -7398,7 +7394,7 @@ export class ShiftStatAttr extends MoveEffectAttr { user.setStat(this.statToSwitch, secondStat, false); user.setStat(this.statToSwitchWith, firstStat, false); - user.scene.queueMessage(i18next.t("moveTriggers:shiftedStats", { + globalScene.queueMessage(i18next.t("moveTriggers:shiftedStats", { pokemonName: getPokemonNameWithAffix(user), statToSwitch: i18next.t(getStatKey(this.statToSwitch)), statToSwitchWith: i18next.t(getStatKey(this.statToSwitchWith)) @@ -7457,7 +7453,7 @@ export class AverageStatsAttr extends MoveEffectAttr { target.setStat(s, avg, false); } - user.scene.queueMessage(i18next.t(this.msgKey, { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t(this.msgKey, { pokemonName: getPokemonNameWithAffix(user) })); return true; } @@ -7485,8 +7481,8 @@ export class MoneyAttr extends MoveEffectAttr { } apply(user: Pokemon, target: Pokemon, move: Move): boolean { - user.scene.currentBattle.moneyScattered += user.scene.getWaveMoneyAmount(0.2); - user.scene.queueMessage(i18next.t("moveTriggers:coinsScatteredEverywhere")); + globalScene.currentBattle.moneyScattered += globalScene.getWaveMoneyAmount(0.2); + globalScene.queueMessage(i18next.t("moveTriggers:coinsScatteredEverywhere")); return true; } } @@ -7510,7 +7506,7 @@ export class DestinyBondAttr extends MoveEffectAttr { * @returns true */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - user.scene.queueMessage(`${i18next.t("moveTriggers:tryingToTakeFoeDown", { pokemonName: getPokemonNameWithAffix(user) })}`); + globalScene.queueMessage(`${i18next.t("moveTriggers:tryingToTakeFoeDown", { pokemonName: getPokemonNameWithAffix(user) })}`); user.addTag(BattlerTagType.DESTINY_BOND, undefined, move.id, user.id); return true; } @@ -7600,7 +7596,7 @@ export class AttackedByItemAttr extends MoveAttr { } const itemName = heldItems[0]?.type?.name ?? "item"; - target.scene.queueMessage(i18next.t("moveTriggers:attackedByItem", { pokemonName: getPokemonNameWithAffix(target), itemName: itemName })); + globalScene.queueMessage(i18next.t("moveTriggers:attackedByItem", { pokemonName: getPokemonNameWithAffix(target), itemName: itemName })); return true; }; @@ -7639,30 +7635,30 @@ export class AfterYouAttr extends MoveEffectAttr { * @returns true */ override apply(user: Pokemon, target: Pokemon, _move: Move, _args: any[]): boolean { - user.scene.queueMessage(i18next.t("moveTriggers:afterYou", { targetName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:afterYou", { targetName: getPokemonNameWithAffix(target) })); //Will find next acting phase of the targeted pokémon, delete it and queue it next on successful delete. - const nextAttackPhase = target.scene.findPhase((phase) => phase.pokemon === target); - if (nextAttackPhase && target.scene.tryRemovePhase((phase: MovePhase) => phase.pokemon === target)) { - target.scene.prependToPhase(new MovePhase(target.scene, target, [ ...nextAttackPhase.targets ], nextAttackPhase.move), MovePhase); + const nextAttackPhase = globalScene.findPhase((phase) => phase.pokemon === target); + if (nextAttackPhase && globalScene.tryRemovePhase((phase: MovePhase) => phase.pokemon === target)) { + globalScene.prependToPhase(new MovePhase(target, [ ...nextAttackPhase.targets ], nextAttackPhase.move), MovePhase); } return true; } } -const failOnGravityCondition: MoveConditionFunc = (user, target, move) => !user.scene.arena.getTag(ArenaTagType.GRAVITY); +const failOnGravityCondition: MoveConditionFunc = (user, target, move) => !globalScene.arena.getTag(ArenaTagType.GRAVITY); const failOnBossCondition: MoveConditionFunc = (user, target, move) => !target.isBossImmune(); -const failIfSingleBattle: MoveConditionFunc = (user, target, move) => user.scene.currentBattle.double; +const failIfSingleBattle: MoveConditionFunc = (user, target, move) => globalScene.currentBattle.double; const failIfDampCondition: MoveConditionFunc = (user, target, move) => { const cancelled = new Utils.BooleanHolder(false); - user.scene.getField(true).map(p=>applyAbAttrs(FieldPreventExplosiveMovesAbAttr, p, cancelled)); + globalScene.getField(true).map(p=>applyAbAttrs(FieldPreventExplosiveMovesAbAttr, p, cancelled)); // Queue a message if an ability prevented usage of the move if (cancelled.value) { - user.scene.queueMessage(i18next.t("moveTriggers:cannotUseMove", { pokemonName: getPokemonNameWithAffix(user), moveName: move.name })); + globalScene.queueMessage(i18next.t("moveTriggers:cannotUseMove", { pokemonName: getPokemonNameWithAffix(user), moveName: move.name })); } return !cancelled.value; }; @@ -7671,10 +7667,10 @@ const userSleptOrComatoseCondition: MoveConditionFunc = (user: Pokemon, target: const targetSleptOrComatoseCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => target.status?.effect === StatusEffect.SLEEP || target.hasAbility(Abilities.COMATOSE); -const failIfLastCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => user.scene.phaseQueue.find(phase => phase instanceof MovePhase) !== undefined; +const failIfLastCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => globalScene.phaseQueue.find(phase => phase instanceof MovePhase) !== undefined; const failIfLastInPartyCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => { - const party: Pokemon[] = user.isPlayer() ? user.scene.getPlayerParty() : user.scene.getEnemyParty(); + const party: Pokemon[] = user.isPlayer() ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); return party.some(pokemon => pokemon.isActive() && !pokemon.isOnField()); }; @@ -7757,7 +7753,7 @@ export class FirstMoveCondition extends MoveCondition { export class UpperHandCondition extends MoveCondition { constructor() { super((user, target, move) => { - const targetCommand = user.scene.currentBattle.turnCommands[target.getBattlerIndex()]; + const targetCommand = globalScene.currentBattle.turnCommands[target.getBattlerIndex()]; return !!targetCommand && targetCommand.command === Command.FIGHT @@ -7816,13 +7812,13 @@ export class ResistLastMoveTypeAttr extends MoveEffectAttr { return false; } const userTypes = user.getTypes(); - const validTypes = this.getTypeResistances(user.scene.gameMode, moveData.type).filter(t => !userTypes.includes(t)); // valid types are ones that are not already the user's types + const validTypes = this.getTypeResistances(globalScene.gameMode, moveData.type).filter(t => !userTypes.includes(t)); // valid types are ones that are not already the user's types if (!validTypes.length) { return false; } const type = validTypes[user.randSeedInt(validTypes.length)]; user.summonData.types = [ type ]; - user.scene.queueMessage(i18next.t("battle:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), type: Utils.toReadableString(Type[type]) })); + globalScene.queueMessage(i18next.t("battle:transformedIntoType", { pokemonName: getPokemonNameWithAffix(user), type: Utils.toReadableString(Type[type]) })); user.updateInfo(); return true; @@ -7881,7 +7877,7 @@ export class ExposedMoveAttr extends AddBattlerTagAttr { return false; } - user.scene.queueMessage(i18next.t("moveTriggers:exposedMove", { pokemonName: getPokemonNameWithAffix(user), targetPokemonName: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("moveTriggers:exposedMove", { pokemonName: getPokemonNameWithAffix(user), targetPokemonName: getPokemonNameWithAffix(target) })); return true; } @@ -8200,7 +8196,7 @@ export function initMoves() { .makesContact(false), new AttackMove(Moves.EARTHQUAKE, Type.GROUND, MoveCategory.PHYSICAL, 100, 100, 10, -1, 0, 1) .attr(HitsTagForDoubleDamageAttr, BattlerTagType.UNDERGROUND) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.GRASSY && target.isGrounded() ? 0.5 : 1) + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.GRASSY && target.isGrounded() ? 0.5 : 1) .makesContact(false) .target(MoveTarget.ALL_NEAR_OTHERS), new AttackMove(Moves.FISSURE, Type.GROUND, MoveCategory.PHYSICAL, 200, 30, 5, -1, 0, 1) @@ -8479,7 +8475,7 @@ export function initMoves() { .attr(ConfuseAttr), new SelfStatusMove(Moves.BELLY_DRUM, Type.NORMAL, -1, 10, -1, 0, 2) .attr(CutHpStatStageBoostAttr, [ Stat.ATK ], 12, 2, (user) => { - user.scene.queueMessage(i18next.t("moveTriggers:cutOwnHpAndMaximizedStat", { pokemonName: getPokemonNameWithAffix(user), statName: i18next.t(getStatKey(Stat.ATK)) })); + globalScene.queueMessage(i18next.t("moveTriggers:cutOwnHpAndMaximizedStat", { pokemonName: getPokemonNameWithAffix(user), statName: i18next.t(getStatKey(Stat.ATK)) })); }), new AttackMove(Moves.SLUDGE_BOMB, Type.POISON, MoveCategory.SPECIAL, 90, 100, 10, 30, 0, 2) .attr(StatusEffectAttr, StatusEffect.POISON) @@ -8599,7 +8595,7 @@ export function initMoves() { new AttackMove(Moves.MAGNITUDE, Type.GROUND, MoveCategory.PHYSICAL, -1, 100, 30, -1, 0, 2) .attr(PreMoveMessageAttr, magnitudeMessageFunc) .attr(MagnitudePowerAttr) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.GRASSY && target.isGrounded() ? 0.5 : 1) + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.GRASSY && target.isGrounded() ? 0.5 : 1) .attr(HitsTagForDoubleDamageAttr, BattlerTagType.UNDERGROUND) .makesContact(false) .target(MoveTarget.ALL_NEAR_OTHERS), @@ -8875,7 +8871,7 @@ export function initMoves() { .attr(FlinchAttr), new AttackMove(Moves.WEATHER_BALL, Type.NORMAL, MoveCategory.SPECIAL, 50, 100, 10, -1, 0, 3) .attr(WeatherBallTypeAttr) - .attr(MovePowerMultiplierAttr, (user, target, move) => [ WeatherType.SUNNY, WeatherType.RAIN, WeatherType.SANDSTORM, WeatherType.HAIL, WeatherType.SNOW, WeatherType.FOG, WeatherType.HEAVY_RAIN, WeatherType.HARSH_SUN ].includes(user.scene.arena.weather?.weatherType!) && !user.scene.arena.weather?.isEffectSuppressed(user.scene) ? 2 : 1) // TODO: is this bang correct? + .attr(MovePowerMultiplierAttr, (user, target, move) => [ WeatherType.SUNNY, WeatherType.RAIN, WeatherType.SANDSTORM, WeatherType.HAIL, WeatherType.SNOW, WeatherType.FOG, WeatherType.HEAVY_RAIN, WeatherType.HARSH_SUN ].includes(globalScene.arena.weather?.weatherType!) && !globalScene.arena.weather?.isEffectSuppressed() ? 2 : 1) // TODO: is this bang correct? .ballBombMove(), new StatusMove(Moves.AROMATHERAPY, Type.GRASS, -1, 5, -1, 0, 3) .attr(PartyStatusCureAttr, i18next.t("moveTriggers:soothingAromaWaftedThroughArea"), Abilities.SAP_SIPPER) @@ -9050,7 +9046,7 @@ export function initMoves() { new AttackMove(Moves.CLOSE_COMBAT, Type.FIGHTING, MoveCategory.PHYSICAL, 120, 100, 5, -1, 0, 4) .attr(StatStageChangeAttr, [ Stat.DEF, Stat.SPDEF ], -1, true), new AttackMove(Moves.PAYBACK, Type.DARK, MoveCategory.PHYSICAL, 50, 100, 10, -1, 0, 4) - .attr(MovePowerMultiplierAttr, (user, target, move) => target.getLastXMoves(1).find(m => m.turn === target.scene.currentBattle.turn) || user.scene.currentBattle.turnCommands[target.getBattlerIndex()]?.command === Command.BALL ? 2 : 1), + .attr(MovePowerMultiplierAttr, (user, target, move) => target.getLastXMoves(1).find(m => m.turn === globalScene.currentBattle.turn) || globalScene.currentBattle.turnCommands[target.getBattlerIndex()]?.command === Command.BALL ? 2 : 1), new AttackMove(Moves.ASSURANCE, Type.DARK, MoveCategory.PHYSICAL, 60, 100, 10, -1, 0, 4) .attr(MovePowerMultiplierAttr, (user, target, move) => target.turnData.damageTaken > 0 ? 2 : 1), new StatusMove(Moves.EMBARGO, Type.DARK, 100, 15, -1, 0, 4) @@ -9106,7 +9102,7 @@ export function initMoves() { new StatusMove(Moves.WORRY_SEED, Type.GRASS, 100, 10, -1, 0, 4) .attr(AbilityChangeAttr, Abilities.INSOMNIA), new AttackMove(Moves.SUCKER_PUNCH, Type.DARK, MoveCategory.PHYSICAL, 70, 100, 5, -1, 1, 4) - .condition((user, target, move) => user.scene.currentBattle.turnCommands[target.getBattlerIndex()]?.command === Command.FIGHT && !target.turnData.acted && allMoves[user.scene.currentBattle.turnCommands[target.getBattlerIndex()]?.move?.move!].category !== MoveCategory.STATUS), // TODO: is this bang correct? + .condition((user, target, move) => globalScene.currentBattle.turnCommands[target.getBattlerIndex()]?.command === Command.FIGHT && !target.turnData.acted && allMoves[globalScene.currentBattle.turnCommands[target.getBattlerIndex()]?.move?.move!].category !== MoveCategory.STATUS), // TODO: is this bang correct? new StatusMove(Moves.TOXIC_SPIKES, Type.POISON, -1, 20, -1, 0, 4) .attr(AddArenaTrapTagAttr, ArenaTagType.TOXIC_SPIKES) .target(MoveTarget.ENEMY_SIDE), @@ -9117,7 +9113,7 @@ export function initMoves() { .attr(AddBattlerTagAttr, BattlerTagType.AQUA_RING, true, true), new SelfStatusMove(Moves.MAGNET_RISE, Type.ELECTRIC, -1, 10, -1, 0, 4) .attr(AddBattlerTagAttr, BattlerTagType.FLOATING, true, true, 5) - .condition((user, target, move) => !user.scene.arena.getTag(ArenaTagType.GRAVITY) && [ BattlerTagType.FLOATING, BattlerTagType.IGNORE_FLYING, BattlerTagType.INGRAIN ].every((tag) => !user.getTag(tag))), + .condition((user, target, move) => !globalScene.arena.getTag(ArenaTagType.GRAVITY) && [ BattlerTagType.FLOATING, BattlerTagType.IGNORE_FLYING, BattlerTagType.INGRAIN ].every((tag) => !user.getTag(tag))), new AttackMove(Moves.FLARE_BLITZ, Type.FIRE, MoveCategory.PHYSICAL, 120, 100, 15, 10, 0, 4) .attr(RecoilAttr, false, 0.33) .attr(HealStatusEffectAttr, true, StatusEffect.FREEZE) @@ -9463,9 +9459,9 @@ export function initMoves() { .attr(CopyTypeAttr), new AttackMove(Moves.RETALIATE, Type.NORMAL, MoveCategory.PHYSICAL, 70, 100, 5, -1, 0, 5) .attr(MovePowerMultiplierAttr, (user, target, move) => { - const turn = user.scene.currentBattle.turn; - const lastPlayerFaint = user.scene.currentBattle.playerFaintsHistory[user.scene.currentBattle.playerFaintsHistory.length - 1]; - const lastEnemyFaint = user.scene.currentBattle.enemyFaintsHistory[user.scene.currentBattle.enemyFaintsHistory.length - 1]; + const turn = globalScene.currentBattle.turn; + const lastPlayerFaint = globalScene.currentBattle.playerFaintsHistory[globalScene.currentBattle.playerFaintsHistory.length - 1]; + const lastEnemyFaint = globalScene.currentBattle.enemyFaintsHistory[globalScene.currentBattle.enemyFaintsHistory.length - 1]; return ( (lastPlayerFaint !== undefined && turn - lastPlayerFaint.turn === 1 && user.isPlayer()) || (lastEnemyFaint !== undefined && turn - lastEnemyFaint.turn === 1 && !user.isPlayer()) @@ -9511,7 +9507,7 @@ export function initMoves() { .target(MoveTarget.ALL_NEAR_ENEMIES), new AttackMove(Moves.BULLDOZE, Type.GROUND, MoveCategory.PHYSICAL, 60, 100, 20, 100, 0, 5) .attr(StatStageChangeAttr, [ Stat.SPD ], -1) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.GRASSY && target.isGrounded() ? 0.5 : 1) + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.GRASSY && target.isGrounded() ? 0.5 : 1) .makesContact(false) .target(MoveTarget.ALL_NEAR_OTHERS), new AttackMove(Moves.FROST_BREATH, Type.ICE, MoveCategory.SPECIAL, 60, 90, 10, 100, 0, 5) @@ -9632,7 +9628,7 @@ export function initMoves() { .target(MoveTarget.ALL) .condition((user, target, move) => { // If any fielded pokémon is grass-type and grounded. - return [ ...user.scene.getEnemyParty(), ...user.scene.getPlayerParty() ].some((poke) => poke.isOfType(Type.GRASS) && poke.isGrounded()); + return [ ...globalScene.getEnemyParty(), ...globalScene.getPlayerParty() ].some((poke) => poke.isOfType(Type.GRASS) && poke.isGrounded()); }) .attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPATK ], 1, false, { condition: (user, target, move) => target.isOfType(Type.GRASS) && target.isGrounded() }), new StatusMove(Moves.STICKY_WEB, Type.BUG, -1, 20, -1, 0, 6) @@ -9953,7 +9949,7 @@ export function initMoves() { .attr(StatStageChangeAttr, [ Stat.SPD ], -1, true) .punchingMove(), new StatusMove(Moves.FLORAL_HEALING, Type.FAIRY, -1, 10, -1, 0, 7) - .attr(BoostHealAttr, 0.5, 2 / 3, true, false, (user, target, move) => user.scene.arena.terrain?.terrainType === TerrainType.GRASSY) + .attr(BoostHealAttr, 0.5, 2 / 3, true, false, (user, target, move) => globalScene.arena.terrain?.terrainType === TerrainType.GRASSY) .triageMove(), new AttackMove(Moves.HIGH_HORSEPOWER, Type.GROUND, MoveCategory.PHYSICAL, 95, 95, 10, -1, 0, 7), new StatusMove(Moves.STRENGTH_SAP, Type.GRASS, 100, 10, -1, 0, 7) @@ -10006,7 +10002,7 @@ export function initMoves() { .attr(HealStatusEffectAttr, true, StatusEffect.FREEZE) .attr(AddBattlerTagAttr, BattlerTagType.BURNED_UP, true, false) .attr(RemoveTypeAttr, Type.FIRE, (user) => { - user.scene.queueMessage(i18next.t("moveTriggers:burnedItselfOut", { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t("moveTriggers:burnedItselfOut", { pokemonName: getPokemonNameWithAffix(user) })); }), new StatusMove(Moves.SPEED_SWAP, Type.PSYCHIC, -1, 10, -1, 0, 7) .attr(SwapStatAttr, Stat.SPD) @@ -10042,7 +10038,7 @@ export function initMoves() { new AttackMove(Moves.BRUTAL_SWING, Type.DARK, MoveCategory.PHYSICAL, 60, 100, 20, -1, 0, 7) .target(MoveTarget.ALL_NEAR_OTHERS), new StatusMove(Moves.AURORA_VEIL, Type.ICE, -1, 20, -1, 0, 7) - .condition((user, target, move) => (user.scene.arena.weather?.weatherType === WeatherType.HAIL || user.scene.arena.weather?.weatherType === WeatherType.SNOW) && !user.scene.arena.weather?.isEffectSuppressed(user.scene)) + .condition((user, target, move) => (globalScene.arena.weather?.weatherType === WeatherType.HAIL || globalScene.arena.weather?.weatherType === WeatherType.SNOW) && !globalScene.arena.weather?.isEffectSuppressed()) .attr(AddArenaTagAttr, ArenaTagType.AURORA_VEIL, 5, true) .target(MoveTarget.USER_SIDE), /* Unused */ @@ -10195,10 +10191,10 @@ export function initMoves() { new AttackMove(Moves.DYNAMAX_CANNON, Type.DRAGON, MoveCategory.SPECIAL, 100, 100, 5, -1, 0, 8) .attr(MovePowerMultiplierAttr, (user, target, move) => { // Move is only stronger against overleveled foes. - if (target.level > target.scene.getMaxExpLevel()) { + if (target.level > globalScene.getMaxExpLevel()) { const dynamaxCannonPercentMarginBeforeFullDamage = 0.05; // How much % above MaxExpLevel of wave will the target need to be to take full damage. // The move's power scales as the margin is approached, reaching double power when it does or goes over it. - return 1 + Math.min(1, (target.level - target.scene.getMaxExpLevel()) / (target.scene.getMaxExpLevel() * dynamaxCannonPercentMarginBeforeFullDamage)); + return 1 + Math.min(1, (target.level - globalScene.getMaxExpLevel()) / (globalScene.getMaxExpLevel() * dynamaxCannonPercentMarginBeforeFullDamage)); } else { return 1; } @@ -10216,7 +10212,7 @@ export function initMoves() { .attr(EatBerryAttr) .attr(StatStageChangeAttr, [ Stat.DEF ], 2, true) .condition((user) => { - const userBerries = user.scene.findModifiers(m => m instanceof BerryModifier, user.isPlayer()); + const userBerries = globalScene.findModifiers(m => m instanceof BerryModifier, user.isPlayer()); return userBerries.length > 0; }) .edgeCase(), // Stuff Cheeks should not be selectable when the user does not have a berry, see wiki @@ -10357,7 +10353,7 @@ export function initMoves() { .attr(StatStageChangeAttr, [ Stat.SPDEF ], -1), new AttackMove(Moves.GRAV_APPLE, Type.GRASS, MoveCategory.PHYSICAL, 80, 100, 10, 100, 0, 8) .attr(StatStageChangeAttr, [ Stat.DEF ], -1) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTag(ArenaTagType.GRAVITY) ? 1.5 : 1) + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTag(ArenaTagType.GRAVITY) ? 1.5 : 1) .makesContact(false), new AttackMove(Moves.SPIRIT_BREAK, Type.FAIRY, MoveCategory.PHYSICAL, 75, 100, 15, 100, 0, 8) .attr(StatStageChangeAttr, [ Stat.SPATK ], -1), @@ -10379,11 +10375,11 @@ export function initMoves() { new AttackMove(Moves.STEEL_BEAM, Type.STEEL, MoveCategory.SPECIAL, 140, 95, 5, -1, 0, 8) .attr(HalfSacrificialAttr), new AttackMove(Moves.EXPANDING_FORCE, Type.PSYCHIC, MoveCategory.SPECIAL, 80, 100, 10, -1, 0, 8) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.PSYCHIC && user.isGrounded() ? 1.5 : 1) - .attr(VariableTargetAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.PSYCHIC && user.isGrounded() ? MoveTarget.ALL_NEAR_ENEMIES : MoveTarget.NEAR_OTHER), + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.PSYCHIC && user.isGrounded() ? 1.5 : 1) + .attr(VariableTargetAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.PSYCHIC && user.isGrounded() ? MoveTarget.ALL_NEAR_ENEMIES : MoveTarget.NEAR_OTHER), new AttackMove(Moves.STEEL_ROLLER, Type.STEEL, MoveCategory.PHYSICAL, 130, 100, 5, -1, 0, 8) .attr(ClearTerrainAttr) - .condition((user, target, move) => !!user.scene.arena.terrain), + .condition((user, target, move) => !!globalScene.arena.terrain), new AttackMove(Moves.SCALE_SHOT, Type.DRAGON, MoveCategory.PHYSICAL, 25, 90, 20, -1, 0, 8) .attr(StatStageChangeAttr, [ Stat.SPD ], 1, true, { lastHitOnly: true }) .attr(StatStageChangeAttr, [ Stat.DEF ], -1, true, { lastHitOnly: true }) @@ -10400,16 +10396,16 @@ export function initMoves() { new AttackMove(Moves.MISTY_EXPLOSION, Type.FAIRY, MoveCategory.SPECIAL, 100, 100, 5, -1, 0, 8) .attr(SacrificialAttr) .target(MoveTarget.ALL_NEAR_OTHERS) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.MISTY && user.isGrounded() ? 1.5 : 1) + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.MISTY && user.isGrounded() ? 1.5 : 1) .condition(failIfDampCondition) .makesContact(false), new AttackMove(Moves.GRASSY_GLIDE, Type.GRASS, MoveCategory.PHYSICAL, 55, 100, 20, -1, 0, 8) - .attr(IncrementMovePriorityAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.GRASSY && user.isGrounded()), + .attr(IncrementMovePriorityAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.GRASSY && user.isGrounded()), new AttackMove(Moves.RISING_VOLTAGE, Type.ELECTRIC, MoveCategory.SPECIAL, 70, 100, 20, -1, 0, 8) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.ELECTRIC && target.isGrounded() ? 2 : 1), + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.ELECTRIC && target.isGrounded() ? 2 : 1), new AttackMove(Moves.TERRAIN_PULSE, Type.NORMAL, MoveCategory.SPECIAL, 50, 100, 10, -1, 0, 8) .attr(TerrainPulseTypeAttr) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() !== TerrainType.NONE && user.isGrounded() ? 2 : 1) + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() !== TerrainType.NONE && user.isGrounded() ? 2 : 1) .pulseMove(), new AttackMove(Moves.SKITTER_SMACK, Type.BUG, MoveCategory.PHYSICAL, 70, 90, 10, 100, 0, 8) .attr(StatStageChangeAttr, [ Stat.SPATK ], -1), @@ -10669,7 +10665,7 @@ export function initMoves() { .recklessMove(), new AttackMove(Moves.LAST_RESPECTS, Type.GHOST, MoveCategory.PHYSICAL, 50, 100, 10, -1, 0, 9) .partial() // Counter resets every wave instead of on arena reset - .attr(MovePowerMultiplierAttr, (user, target, move) => 1 + Math.min(user.isPlayer() ? user.scene.currentBattle.playerFaints : user.scene.currentBattle.enemyFaints, 100)) + .attr(MovePowerMultiplierAttr, (user, target, move) => 1 + Math.min(user.isPlayer() ? globalScene.currentBattle.playerFaints : globalScene.currentBattle.enemyFaints, 100)) .makesContact(false), new AttackMove(Moves.LUMINA_CRASH, Type.PSYCHIC, MoveCategory.SPECIAL, 80, 100, 10, 100, 0, 9) .attr(StatStageChangeAttr, [ Stat.SPDEF ], -2), @@ -10693,7 +10689,7 @@ export function initMoves() { .attr(AddBattlerTagAttr, BattlerTagType.ALWAYS_GET_HIT, true, false, 0, 0, true) .attr(AddBattlerTagAttr, BattlerTagType.RECEIVE_DOUBLE_DAMAGE, true, false, 0, 0, true) .condition((user, target, move) => { - return !(target.getTag(BattlerTagType.PROTECTED)?.tagType === "PROTECTED" || target.scene.arena.getTag(ArenaTagType.MAT_BLOCK)?.tagType === "MAT_BLOCK"); + return !(target.getTag(BattlerTagType.PROTECTED)?.tagType === "PROTECTED" || globalScene.arena.getTag(ArenaTagType.MAT_BLOCK)?.tagType === "MAT_BLOCK"); }), new StatusMove(Moves.REVIVAL_BLESSING, Type.NORMAL, -1, 1, -1, 0, 9) .triageMove() @@ -10744,11 +10740,11 @@ export function initMoves() { .attr(StatStageChangeAttr, [ Stat.SPATK ], -1, true, { firstTargetOnly: true }) .target(MoveTarget.ALL_NEAR_ENEMIES), new AttackMove(Moves.PSYBLADE, Type.PSYCHIC, MoveCategory.PHYSICAL, 80, 100, 15, -1, 0, 9) - .attr(MovePowerMultiplierAttr, (user, target, move) => user.scene.arena.getTerrainType() === TerrainType.ELECTRIC && user.isGrounded() ? 1.5 : 1) + .attr(MovePowerMultiplierAttr, (user, target, move) => globalScene.arena.getTerrainType() === TerrainType.ELECTRIC && user.isGrounded() ? 1.5 : 1) .slicingMove(), new AttackMove(Moves.HYDRO_STEAM, Type.WATER, MoveCategory.SPECIAL, 80, 100, 15, -1, 0, 9) .attr(IgnoreWeatherTypeDebuffAttr, WeatherType.SUNNY) - .attr(MovePowerMultiplierAttr, (user, target, move) => [ WeatherType.SUNNY, WeatherType.HARSH_SUN ].includes(user.scene.arena.weather?.weatherType!) && !user.scene.arena.weather?.isEffectSuppressed(user.scene) ? 1.5 : 1), // TODO: is this bang correct? + .attr(MovePowerMultiplierAttr, (user, target, move) => [ WeatherType.SUNNY, WeatherType.HARSH_SUN ].includes(globalScene.arena.weather?.weatherType!) && !globalScene.arena.weather?.isEffectSuppressed() ? 1.5 : 1), // TODO: is this bang correct? new AttackMove(Moves.RUINATION, Type.DARK, MoveCategory.SPECIAL, -1, 90, 10, -1, 0, 9) .attr(TargetHalfHpDamageAttr), new AttackMove(Moves.COLLISION_COURSE, Type.FIGHTING, MoveCategory.PHYSICAL, 100, 100, 5, -1, 0, 9) @@ -10797,7 +10793,7 @@ export function initMoves() { }) .attr(AddBattlerTagAttr, BattlerTagType.DOUBLE_SHOCKED, true, false) .attr(RemoveTypeAttr, Type.ELECTRIC, (user) => { - user.scene.queueMessage(i18next.t("moveTriggers:usedUpAllElectricity", { pokemonName: getPokemonNameWithAffix(user) })); + globalScene.queueMessage(i18next.t("moveTriggers:usedUpAllElectricity", { pokemonName: getPokemonNameWithAffix(user) })); }), new AttackMove(Moves.GIGATON_HAMMER, Type.STEEL, MoveCategory.PHYSICAL, 160, 100, 5, -1, 0, 9) .makesContact(false) @@ -10864,7 +10860,7 @@ export function initMoves() { .attr(ProtectAttr, BattlerTagType.BURNING_BULWARK) .condition(failIfLastCondition), new AttackMove(Moves.THUNDERCLAP, Type.ELECTRIC, MoveCategory.SPECIAL, 70, 100, 5, -1, 1, 9) - .condition((user, target, move) => user.scene.currentBattle.turnCommands[target.getBattlerIndex()]?.command === Command.FIGHT && !target.turnData.acted && allMoves[user.scene.currentBattle.turnCommands[target.getBattlerIndex()]?.move?.move!].category !== MoveCategory.STATUS), // TODO: is this bang correct? + .condition((user, target, move) => globalScene.currentBattle.turnCommands[target.getBattlerIndex()]?.command === Command.FIGHT && !target.turnData.acted && allMoves[globalScene.currentBattle.turnCommands[target.getBattlerIndex()]?.move?.move!].category !== MoveCategory.STATUS), // TODO: is this bang correct? new AttackMove(Moves.MIGHTY_CLEAVE, Type.ROCK, MoveCategory.PHYSICAL, 95, 100, 5, -1, 0, 9) .slicingMove() .ignoresProtect(), diff --git a/src/data/mystery-encounters/encounters/a-trainers-test-encounter.ts b/src/data/mystery-encounters/encounters/a-trainers-test-encounter.ts index f0155b4f2a44..f8d7e18501d7 100644 --- a/src/data/mystery-encounters/encounters/a-trainers-test-encounter.ts +++ b/src/data/mystery-encounters/encounters/a-trainers-test-encounter.ts @@ -1,7 +1,7 @@ +import { globalScene } from "#app/global-scene"; import { EnemyPartyConfig, initBattleWithEnemyConfig, leaveEncounterWithoutBattle, setEncounterRewards, transitionMysteryEncounterIntroVisuals, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { trainerConfigs, } from "#app/data/trainer-config"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { TrainerType } from "#enums/trainer-type"; @@ -36,8 +36,8 @@ export const ATrainersTestEncounter: MysteryEncounter = }, ]) .withAutoHideIntroVisuals(false) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Randomly pick from 1 of the 5 stat trainers to spawn let trainerType: TrainerType; @@ -138,23 +138,22 @@ export const ATrainersTestEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.1.label`, buttonTooltip: `${namespace}:option.1.tooltip` }, - async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Battle the stat trainer for an Egg and great rewards const config: EnemyPartyConfig = encounter.enemyPartyConfigs[0]; - await transitionMysteryEncounterIntroVisuals(scene); + await transitionMysteryEncounterIntroVisuals(); const eggOptions: IEggOptions = { - scene, pulled: false, sourceType: EggSourceType.EVENT, eggDescriptor: encounter.misc.trainerEggDescription, tier: EggTier.EPIC }; encounter.setDialogueToken("eggType", i18next.t(`${namespace}:eggTypes.epic`)); - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.SACRED_ASH ], guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ULTRA ], fillRemaining: true }, [ eggOptions ]); - await initBattleWithEnemyConfig(scene, config); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.SACRED_ASH ], guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ULTRA ], fillRemaining: true }, [ eggOptions ]); + await initBattleWithEnemyConfig(config); } ) .withSimpleOption( @@ -162,21 +161,20 @@ export const ATrainersTestEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.2.label`, buttonTooltip: `${namespace}:option.2.tooltip` }, - async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Full heal party - scene.unshiftPhase(new PartyHealPhase(scene, true)); + globalScene.unshiftPhase(new PartyHealPhase(true)); const eggOptions: IEggOptions = { - scene, pulled: false, sourceType: EggSourceType.EVENT, eggDescriptor: encounter.misc.trainerEggDescription, tier: EggTier.RARE }; encounter.setDialogueToken("eggType", i18next.t(`${namespace}:eggTypes.rare`)); - setEncounterRewards(scene, { fillRemaining: false, rerollMultiplier: -1 }, [ eggOptions ]); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ fillRemaining: false, rerollMultiplier: -1 }, [ eggOptions ]); + leaveEncounterWithoutBattle(); } ) .withOutroDialogue([ diff --git a/src/data/mystery-encounters/encounters/absolute-avarice-encounter.ts b/src/data/mystery-encounters/encounters/absolute-avarice-encounter.ts index 6b0f239d28dd..654fa5a2956f 100644 --- a/src/data/mystery-encounters/encounters/absolute-avarice-encounter.ts +++ b/src/data/mystery-encounters/encounters/absolute-avarice-encounter.ts @@ -3,7 +3,7 @@ import Pokemon, { EnemyPokemon, PokemonMove } from "#app/field/pokemon"; import { BerryModifierType, modifierTypes, PokemonHeldItemModifierType } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { PersistentModifierRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; @@ -170,18 +170,18 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; - scene.loadSe("PRSFX- Bug Bite", "battle_anims", "PRSFX- Bug Bite.wav"); - scene.loadSe("Follow Me", "battle_anims", "Follow Me.mp3"); + globalScene.loadSe("PRSFX- Bug Bite", "battle_anims", "PRSFX- Bug Bite.wav"); + globalScene.loadSe("Follow Me", "battle_anims", "Follow Me.mp3"); // Get all player berry items, remove from party, and store reference - const berryItems = scene.findModifiers(m => m instanceof BerryModifier) as BerryModifier[]; + const berryItems = globalScene.findModifiers(m => m instanceof BerryModifier) as BerryModifier[]; // Sort berries by party member ID to more easily re-add later if necessary const berryItemsMap = new Map(); - scene.getPlayerParty().forEach(pokemon => { + globalScene.getPlayerParty().forEach(pokemon => { const pokemonBerries = berryItems.filter(b => b.pokemonId === pokemon.id); if (pokemonBerries?.length > 0) { berryItemsMap.set(pokemon.id, pokemonBerries); @@ -196,7 +196,7 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = // Can't define stack count on a ModifierType, have to just create separate instances for each stack // Overflow berries will be "lost" on the boss, but it's un-catchable anyway for (let i = 0; i < berryMod.stackCount; i++) { - const modifierType = generateModifierType(scene, modifierTypes.BERRY, [ berryMod.berryType ]) as PokemonHeldItemModifierType; + const modifierType = generateModifierType(modifierTypes.BERRY, [ berryMod.berryType ]) as PokemonHeldItemModifierType; bossModifierConfigs.push({ modifier: modifierType }); } }); @@ -204,7 +204,7 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = // Do NOT remove the real berries yet or else it will be persisted in the session data // SpDef buff below wave 50, +1 to all stats otherwise - const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = scene.currentBattle.waveIndex < 50 ? + const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = globalScene.currentBattle.waveIndex < 50 ? [ Stat.SPDEF ] : [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD ]; @@ -221,8 +221,8 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = modifierConfigs: bossModifierConfigs, tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - queueEncounterMessage(pokemon.scene, `${namespace}:option.1.boss_enraged`); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); + queueEncounterMessage(`${namespace}:option.1.boss_enraged`); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); } } ], @@ -233,18 +233,18 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = return true; }) - .withOnVisualsStart((scene: BattleScene) => { - doGreedentSpriteSteal(scene); - doBerrySpritePile(scene); + .withOnVisualsStart(() => { + doGreedentSpriteSteal(); + doBerrySpritePile(); // Remove the berries from the party // Session has been safely saved at this point, so data won't be lost - const berryItems = scene.findModifiers(m => m instanceof BerryModifier) as BerryModifier[]; + const berryItems = globalScene.findModifiers(m => m instanceof BerryModifier) as BerryModifier[]; berryItems.forEach(berryMod => { - scene.removeModifier(berryMod); + globalScene.removeModifier(berryMod); }); - scene.updateModifiers(true); + globalScene.updateModifiers(true); return true; }) @@ -260,26 +260,26 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Pick battle - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; // Provides 1x Reviver Seed to each party member at end of battle - const revSeed = generateModifierType(scene, modifierTypes.REVIVER_SEED); + const revSeed = generateModifierType(modifierTypes.REVIVER_SEED); encounter.setDialogueToken("foodReward", revSeed?.name ?? i18next.t("modifierType:ModifierType.REVIVER_SEED.name")); const givePartyPokemonReviverSeeds = () => { - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); party.forEach(p => { const heldItems = p.getHeldItems(); if (revSeed && !heldItems.some(item => item instanceof PokemonInstantReviveModifier)) { const seedModifier = revSeed.newModifier(p); - scene.addModifier(seedModifier, false, false, false, true); + globalScene.addModifier(seedModifier, false, false, false, true); } }); - queueEncounterMessage(scene, `${namespace}:option.1.food_stash`); + queueEncounterMessage(`${namespace}:option.1.food_stash`); }; - setEncounterRewards(scene, { fillRemaining: true }, undefined, givePartyPokemonReviverSeeds); + setEncounterRewards({ fillRemaining: true }, undefined, givePartyPokemonReviverSeeds); encounter.startOfBattleEffects.push({ sourceBattlerIndex: BattlerIndex.ENEMY, targets: [ BattlerIndex.ENEMY ], @@ -287,8 +287,8 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = ignorePp: true }); - await transitionMysteryEncounterIntroVisuals(scene, true, true, 500); - await initBattleWithEnemyConfig(scene, encounter.enemyPartyConfigs[0]); + await transitionMysteryEncounterIntroVisuals(true, true, 500); + await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); }) .build() ) @@ -304,12 +304,12 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const berryMap = encounter.misc.berryItemsMap; // Returns 2/5 of the berries stolen to each Pokemon - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); party.forEach(pokemon => { const stolenBerries: BerryModifier[] = berryMap.get(pokemon.id); const berryTypesAsArray: BerryType[] = []; @@ -322,15 +322,15 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = Phaser.Math.RND.shuffle(berryTypesAsArray); const randBerryType = berryTypesAsArray.pop(); - const berryModType = generateModifierType(scene, modifierTypes.BERRY, [ randBerryType ]) as BerryModifierType; - applyModifierTypeToPlayerPokemon(scene, pokemon, berryModType); + const berryModType = generateModifierType(modifierTypes.BERRY, [ randBerryType ]) as BerryModifierType; + applyModifierTypeToPlayerPokemon(pokemon, berryModType); } } }); - await scene.updateModifiers(true); + await globalScene.updateModifiers(true); - await transitionMysteryEncounterIntroVisuals(scene, true, true, 500); - leaveEncounterWithoutBattle(scene, true); + await transitionMysteryEncounterIntroVisuals(true, true, 500); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -346,36 +346,36 @@ export const AbsoluteAvariceEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Animate berries being eaten - doGreedentEatBerries(scene); - doBerrySpritePile(scene, true); + doGreedentEatBerries(); + doBerrySpritePile(true); return true; }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Let it have the food // Greedent joins the team, level equal to 2 below highest party member (shiny locked) - const level = getHighestLevelPlayerPokemon(scene, false, true).level - 2; - const greedent = new EnemyPokemon(scene, getPokemonSpecies(Species.GREEDENT), level, TrainerSlot.NONE, false, true); + const level = getHighestLevelPlayerPokemon(false, true).level - 2; + const greedent = new EnemyPokemon(getPokemonSpecies(Species.GREEDENT), level, TrainerSlot.NONE, false, true); greedent.moveset = [ new PokemonMove(Moves.THRASH), new PokemonMove(Moves.BODY_PRESS), new PokemonMove(Moves.STUFF_CHEEKS), new PokemonMove(Moves.SLACK_OFF) ]; greedent.passive = true; - await transitionMysteryEncounterIntroVisuals(scene, true, true, 500); - await catchPokemon(scene, greedent, null, PokeballType.POKEBALL, false); - leaveEncounterWithoutBattle(scene, true); + await transitionMysteryEncounterIntroVisuals(true, true, 500); + await catchPokemon(greedent, null, PokeballType.POKEBALL, false); + leaveEncounterWithoutBattle(true); }) .build() ) .build(); -function doGreedentSpriteSteal(scene: BattleScene) { +function doGreedentSpriteSteal() { const shakeDelay = 50; const slideDelay = 500; - const greedentSprites = scene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(1); + const greedentSprites = globalScene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(1); - scene.playSound("battle_anims/Follow Me"); - scene.tweens.chain({ + globalScene.playSound("battle_anims/Follow Me"); + globalScene.tweens.chain({ targets: greedentSprites, tweens: [ { // Slide Greedent diagonally @@ -445,10 +445,10 @@ function doGreedentSpriteSteal(scene: BattleScene) { }); } -function doGreedentEatBerries(scene: BattleScene) { - const greedentSprites = scene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(1); +function doGreedentEatBerries() { + const greedentSprites = globalScene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(1); let index = 1; - scene.tweens.add({ + globalScene.tweens.add({ targets: greedentSprites, duration: 150, ease: "Cubic.easeOut", @@ -456,11 +456,11 @@ function doGreedentEatBerries(scene: BattleScene) { y: "-=8", loop: 5, onStart: () => { - scene.playSound("battle_anims/PRSFX- Bug Bite"); + globalScene.playSound("battle_anims/PRSFX- Bug Bite"); }, onLoop: () => { if (index % 2 === 0) { - scene.playSound("battle_anims/PRSFX- Bug Bite"); + globalScene.playSound("battle_anims/PRSFX- Bug Bite"); } index++; } @@ -468,17 +468,15 @@ function doGreedentEatBerries(scene: BattleScene) { } /** - * - * @param scene * @param isEat Default false. Will "create" pile when false, and remove pile when true. */ -function doBerrySpritePile(scene: BattleScene, isEat: boolean = false) { +function doBerrySpritePile(isEat: boolean = false) { const berryAddDelay = 150; let animationOrder = [ "starf", "sitrus", "lansat", "salac", "apicot", "enigma", "liechi", "ganlon", "lum", "petaya", "leppa" ]; if (isEat) { animationOrder = animationOrder.reverse(); } - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; animationOrder.forEach((berry, i) => { const introVisualsIndex = encounter.spriteConfigs.findIndex(config => config.spriteKey?.includes(berry)); let sprite: Phaser.GameObjects.Sprite, tintSprite: Phaser.GameObjects.Sprite; @@ -487,7 +485,7 @@ function doBerrySpritePile(scene: BattleScene, isEat: boolean = false) { sprite = sprites[0]; tintSprite = sprites[1]; } - scene.time.delayedCall(berryAddDelay * i + 400, () => { + globalScene.time.delayedCall(berryAddDelay * i + 400, () => { if (sprite) { sprite.setVisible(!isEat); } @@ -497,20 +495,20 @@ function doBerrySpritePile(scene: BattleScene, isEat: boolean = false) { // Animate Petaya berry falling off the pile if (berry === "petaya" && sprite && tintSprite && !isEat) { - scene.time.delayedCall(200, () => { - doBerryBounce(scene, [ sprite, tintSprite ], 30, 500); + globalScene.time.delayedCall(200, () => { + doBerryBounce([ sprite, tintSprite ], 30, 500); }); } }); }); } -function doBerryBounce(scene: BattleScene, berrySprites: Phaser.GameObjects.Sprite[], yd: number, baseBounceDuration: number) { +function doBerryBounce(berrySprites: Phaser.GameObjects.Sprite[], yd: number, baseBounceDuration: number) { let bouncePower = 1; let bounceYOffset = yd; const doBounce = () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: berrySprites, y: "+=" + bounceYOffset, x: { value: "+=" + (bouncePower * bouncePower * 10), ease: "Linear" }, @@ -522,7 +520,7 @@ function doBerryBounce(scene: BattleScene, berrySprites: Phaser.GameObjects.Spri if (bouncePower) { bounceYOffset = bounceYOffset * bouncePower; - scene.tweens.add({ + globalScene.tweens.add({ targets: berrySprites, y: "-=" + bounceYOffset, x: { value: "+=" + (bouncePower * bouncePower * 10), ease: "Linear" }, diff --git a/src/data/mystery-encounters/encounters/an-offer-you-cant-refuse-encounter.ts b/src/data/mystery-encounters/encounters/an-offer-you-cant-refuse-encounter.ts index 1e20b73e3516..084363cd86ee 100644 --- a/src/data/mystery-encounters/encounters/an-offer-you-cant-refuse-encounter.ts +++ b/src/data/mystery-encounters/encounters/an-offer-you-cant-refuse-encounter.ts @@ -2,7 +2,7 @@ import { generateModifierType, leaveEncounterWithoutBattle, setEncounterExp, upd import { modifierTypes } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { AbilityRequirement, CombinationPokemonRequirement, MoveRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; @@ -69,14 +69,14 @@ export const AnOfferYouCantRefuseEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; - const pokemon = getHighestStatTotalPlayerPokemon(scene, true, true); + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; + const pokemon = getHighestStatTotalPlayerPokemon(true, true); const baseSpecies = pokemon.getSpeciesForm().getRootSpeciesId(); const starterValue: number = speciesStarterCosts[baseSpecies] ?? 1; const multiplier = Math.max(MONEY_MAXIMUM_MULTIPLIER / 10 * starterValue, MONEY_MINIMUM_MULTIPLIER); - const price = scene.getWaveMoneyAmount(multiplier); + const price = globalScene.getWaveMoneyAmount(multiplier); encounter.setDialogueToken("strongestPokemon", pokemon.getNameToRender()); encounter.setDialogueToken("price", price.toString()); @@ -89,7 +89,7 @@ export const AnOfferYouCantRefuseEncounter: MysteryEncounter = // If player meets the combo OR requirements for option 2, populate the token const opt2Req = encounter.options[1].primaryPokemonRequirements[0]; - if (opt2Req.meetsRequirement(scene)) { + if (opt2Req.meetsRequirement()) { const abilityToken = encounter.dialogueTokens["option2PrimaryAbility"]; const moveToken = encounter.dialogueTokens["option2PrimaryMove"]; if (abilityToken) { @@ -99,7 +99,7 @@ export const AnOfferYouCantRefuseEncounter: MysteryEncounter = } } - const shinyCharm = generateModifierType(scene, modifierTypes.SHINY_CHARM); + const shinyCharm = generateModifierType(modifierTypes.SHINY_CHARM); encounter.setDialogueToken("itemName", shinyCharm?.name ?? i18next.t("modifierType:ModifierType.SHINY_CHARM.name")); encounter.setDialogueToken("liepardName", getPokemonSpecies(Species.LIEPARD).getName()); @@ -118,17 +118,17 @@ export const AnOfferYouCantRefuseEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Update money and remove pokemon from party - updatePlayerMoney(scene, encounter.misc.price); - scene.removePokemonFromPlayerParty(encounter.misc.pokemon); + updatePlayerMoney(encounter.misc.price); + globalScene.removePokemonFromPlayerParty(encounter.misc.pokemon); return true; }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Give the player a Shiny Charm - scene.unshiftPhase(new ModifierRewardPhase(scene, modifierTypes.SHINY_CHARM)); - leaveEncounterWithoutBattle(scene, true); + globalScene.unshiftPhase(new ModifierRewardPhase(modifierTypes.SHINY_CHARM)); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -152,15 +152,15 @@ export const AnOfferYouCantRefuseEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Extort the rich kid for money - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; // Update money and remove pokemon from party - updatePlayerMoney(scene, encounter.misc.price); + updatePlayerMoney(encounter.misc.price); - setEncounterExp(scene, encounter.options[1].primaryPokemon!.id, getPokemonSpecies(Species.LIEPARD).baseExp, true); + setEncounterExp(encounter.options[1].primaryPokemon!.id, getPokemonSpecies(Species.LIEPARD).baseExp, true); - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -175,9 +175,9 @@ export const AnOfferYouCantRefuseEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) diff --git a/src/data/mystery-encounters/encounters/berries-abound-encounter.ts b/src/data/mystery-encounters/encounters/berries-abound-encounter.ts index 786ca3e8fc06..7fd012d31caa 100644 --- a/src/data/mystery-encounters/encounters/berries-abound-encounter.ts +++ b/src/data/mystery-encounters/encounters/berries-abound-encounter.ts @@ -1,8 +1,11 @@ import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { - EnemyPartyConfig, generateModifierType, generateModifierTypeOption, + EnemyPartyConfig, + generateModifierType, + generateModifierTypeOption, initBattleWithEnemyConfig, - leaveEncounterWithoutBattle, setEncounterExp, + leaveEncounterWithoutBattle, + setEncounterExp, setEncounterRewards } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import Pokemon, { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; @@ -10,13 +13,14 @@ import { BerryModifierType, getPartyLuckValue, ModifierPoolType, - ModifierTypeOption, modifierTypes, + ModifierTypeOption, + modifierTypes, regenerateModifierPoolThresholds, } from "#app/modifier/modifier-type"; import { randSeedInt } from "#app/utils"; import { BattlerTagType } from "#enums/battler-tag-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { queueEncounterMessage, showEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils"; import { getPokemonNameWithAffix } from "#app/messages"; @@ -53,13 +57,13 @@ export const BerriesAboundEncounter: MysteryEncounter = text: `${namespace}:intro`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate boss mon - const level = getEncounterPokemonLevelForWave(scene, STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); - const bossSpecies = scene.arena.randomSpecies(scene.currentBattle.waveIndex, level, 0, getPartyLuckValue(scene.getPlayerParty()), true); - const bossPokemon = new EnemyPokemon(scene, bossSpecies, level, TrainerSlot.NONE, true); + const level = getEncounterPokemonLevelForWave(STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); + const bossSpecies = globalScene.arena.randomSpecies(globalScene.currentBattle.waveIndex, level, 0, getPartyLuckValue(globalScene.getPlayerParty()), true); + const bossPokemon = new EnemyPokemon(bossSpecies, level, TrainerSlot.NONE, true); encounter.setDialogueToken("enemyPokemon", getPokemonNameWithAffix(bossPokemon)); const config: EnemyPartyConfig = { pokemonConfigs: [{ @@ -74,10 +78,10 @@ export const BerriesAboundEncounter: MysteryEncounter = // Calculate the number of extra berries that player receives // 10-40: 2, 40-120: 4, 120-160: 5, 160-180: 7 const numBerries = - scene.currentBattle.waveIndex > 160 ? 7 - : scene.currentBattle.waveIndex > 120 ? 5 - : scene.currentBattle.waveIndex > 40 ? 4 : 2; - regenerateModifierPoolThresholds(scene.getPlayerParty(), ModifierPoolType.PLAYER, 0); + globalScene.currentBattle.waveIndex > 160 ? 7 + : globalScene.currentBattle.waveIndex > 120 ? 5 + : globalScene.currentBattle.waveIndex > 40 ? 4 : 2; + regenerateModifierPoolThresholds(globalScene.getPlayerParty(), ModifierPoolType.PLAYER, 0); encounter.misc = { numBerries }; const { spriteKey, fileRoot } = getSpriteKeysFromPokemon(bossPokemon); @@ -105,7 +109,7 @@ export const BerriesAboundEncounter: MysteryEncounter = ]; // Get fastest party pokemon for option 2 - const fastestPokemon = getHighestStatPlayerPokemon(scene, PERMANENT_STATS[Stat.SPD], true, false); + const fastestPokemon = getHighestStatPlayerPokemon(PERMANENT_STATS[Stat.SPD], true, false); encounter.misc.fastestPokemon = fastestPokemon; encounter.misc.enemySpeed = bossPokemon.getStat(Stat.SPD); encounter.setDialogueToken("fastestPokemon", fastestPokemon.getNameToRender()); @@ -126,34 +130,34 @@ export const BerriesAboundEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Pick battle - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const numBerries = encounter.misc.numBerries; const doBerryRewards = () => { const berryText = i18next.t(`${namespace}:berries`); - scene.playSound("item_fanfare"); - queueEncounterMessage(scene, i18next.t("battle:rewardGainCount", { modifierName: berryText, count: numBerries })); + globalScene.playSound("item_fanfare"); + queueEncounterMessage(i18next.t("battle:rewardGainCount", { modifierName: berryText, count: numBerries })); // Generate a random berry and give it to the first Pokemon with room for it for (let i = 0; i < numBerries; i++) { - tryGiveBerry(scene); + tryGiveBerry(); } }; const shopOptions: ModifierTypeOption[] = []; for (let i = 0; i < 5; i++) { // Generate shop berries - const mod = generateModifierTypeOption(scene, modifierTypes.BERRY); + const mod = generateModifierTypeOption(modifierTypes.BERRY); if (mod) { shopOptions.push(mod); } } - setEncounterRewards(scene, { guaranteedModifierTypeOptions: shopOptions, fillRemaining: false }, undefined, doBerryRewards); - await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]); + setEncounterRewards({ guaranteedModifierTypeOptions: shopOptions, fillRemaining: false }, undefined, doBerryRewards); + await initBattleWithEnemyConfig(globalScene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]); } ) .withOption( @@ -163,9 +167,9 @@ export const BerriesAboundEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.2.label`, buttonTooltip: `${namespace}:option.2.tooltip` }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Pick race for berries - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const fastestPokemon: PlayerPokemon = encounter.misc.fastestPokemon; const enemySpeed: number = encounter.misc.enemySpeed; const speedDiff = fastestPokemon.getStat(Stat.SPD) / (enemySpeed * 1.1); @@ -174,7 +178,7 @@ export const BerriesAboundEncounter: MysteryEncounter = const shopOptions: ModifierTypeOption[] = []; for (let i = 0; i < 5; i++) { // Generate shop berries - const mod = generateModifierTypeOption(scene, modifierTypes.BERRY); + const mod = generateModifierTypeOption(modifierTypes.BERRY); if (mod) { shopOptions.push(mod); } @@ -185,29 +189,29 @@ export const BerriesAboundEncounter: MysteryEncounter = const doBerryRewards = () => { const berryText = i18next.t(`${namespace}:berries`); - scene.playSound("item_fanfare"); - queueEncounterMessage(scene, i18next.t("battle:rewardGainCount", { modifierName: berryText, count: numBerries })); + globalScene.playSound("item_fanfare"); + queueEncounterMessage(i18next.t("battle:rewardGainCount", { modifierName: berryText, count: numBerries })); // Generate a random berry and give it to the first Pokemon with room for it for (let i = 0; i < numBerries; i++) { - tryGiveBerry(scene); + tryGiveBerry(); } }; // Defense/Spd buffs below wave 50, +1 to all stats otherwise - const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = scene.currentBattle.waveIndex < 50 ? + const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = globalScene.currentBattle.waveIndex < 50 ? [ Stat.DEF, Stat.SPDEF, Stat.SPD ] : [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD ]; - const config = scene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]; + const config = globalScene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]; config.pokemonConfigs![0].tags = [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ]; config.pokemonConfigs![0].mysteryEncounterBattleEffects = (pokemon: Pokemon) => { - queueEncounterMessage(pokemon.scene, `${namespace}:option.2.boss_enraged`); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); + queueEncounterMessage(`${namespace}:option.2.boss_enraged`); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); }; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: shopOptions, fillRemaining: false }, undefined, doBerryRewards); - await showEncounterText(scene, `${namespace}:option.2.selected_bad`); - await initBattleWithEnemyConfig(scene, config); + setEncounterRewards({ guaranteedModifierTypeOptions: shopOptions, fillRemaining: false }, undefined, doBerryRewards); + await showEncounterText(`${namespace}:option.2.selected_bad`); + await initBattleWithEnemyConfig(config); return; } else { // Gains 1 berry for every 10% faster the player's pokemon is than the enemy, up to a max of numBerries, minimum of 2 @@ -216,19 +220,19 @@ export const BerriesAboundEncounter: MysteryEncounter = const doFasterBerryRewards = () => { const berryText = i18next.t(`${namespace}:berries`); - scene.playSound("item_fanfare"); - queueEncounterMessage(scene, i18next.t("battle:rewardGainCount", { modifierName: berryText, count: numBerriesGrabbed })); + globalScene.playSound("item_fanfare"); + queueEncounterMessage(i18next.t("battle:rewardGainCount", { modifierName: berryText, count: numBerriesGrabbed })); // Generate a random berry and give it to the first Pokemon with room for it (trying to give to fastest first) for (let i = 0; i < numBerriesGrabbed; i++) { - tryGiveBerry(scene, fastestPokemon); + tryGiveBerry(fastestPokemon); } }; - setEncounterExp(scene, fastestPokemon.id, encounter.enemyPartyConfigs[0].pokemonConfigs![0].species.baseExp); - setEncounterRewards(scene, { guaranteedModifierTypeOptions: shopOptions, fillRemaining: false }, undefined, doFasterBerryRewards); - await showEncounterText(scene, `${namespace}:option.2.selected`); - leaveEncounterWithoutBattle(scene); + setEncounterExp(fastestPokemon.id, encounter.enemyPartyConfigs[0].pokemonConfigs![0].species.baseExp); + setEncounterRewards({ guaranteedModifierTypeOptions: shopOptions, fillRemaining: false }, undefined, doFasterBerryRewards); + await showEncounterText(`${namespace}:option.2.selected`); + leaveEncounterWithoutBattle(); } }) .build() @@ -243,38 +247,38 @@ export const BerriesAboundEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) .build(); -function tryGiveBerry(scene: BattleScene, prioritizedPokemon?: PlayerPokemon) { +function tryGiveBerry(prioritizedPokemon?: PlayerPokemon) { const berryType = randSeedInt(Object.keys(BerryType).filter(s => !isNaN(Number(s))).length) as BerryType; - const berry = generateModifierType(scene, modifierTypes.BERRY, [ berryType ]) as BerryModifierType; + const berry = generateModifierType(modifierTypes.BERRY, [ berryType ]) as BerryModifierType; - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); // Will try to apply to prioritized pokemon first, then do normal application method if it fails if (prioritizedPokemon) { - const heldBerriesOfType = scene.findModifier(m => m instanceof BerryModifier + const heldBerriesOfType = globalScene.findModifier(m => m instanceof BerryModifier && m.pokemonId === prioritizedPokemon.id && (m as BerryModifier).berryType === berryType, true) as BerryModifier; - if (!heldBerriesOfType || heldBerriesOfType.getStackCount() < heldBerriesOfType.getMaxStackCount(scene)) { - applyModifierTypeToPlayerPokemon(scene, prioritizedPokemon, berry); + if (!heldBerriesOfType || heldBerriesOfType.getStackCount() < heldBerriesOfType.getMaxStackCount()) { + applyModifierTypeToPlayerPokemon(prioritizedPokemon, berry); return; } } // Iterate over the party until berry was successfully given for (const pokemon of party) { - const heldBerriesOfType = scene.findModifier(m => m instanceof BerryModifier + const heldBerriesOfType = globalScene.findModifier(m => m instanceof BerryModifier && m.pokemonId === pokemon.id && (m as BerryModifier).berryType === berryType, true) as BerryModifier; - if (!heldBerriesOfType || heldBerriesOfType.getStackCount() < heldBerriesOfType.getMaxStackCount(scene)) { - applyModifierTypeToPlayerPokemon(scene, pokemon, berry); + if (!heldBerriesOfType || heldBerriesOfType.getStackCount() < heldBerriesOfType.getMaxStackCount()) { + applyModifierTypeToPlayerPokemon(pokemon, berry); return; } } diff --git a/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts b/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts index ecd6972902b6..88efd7a7ca0d 100644 --- a/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts +++ b/src/data/mystery-encounters/encounters/bug-type-superfan-encounter.ts @@ -1,5 +1,6 @@ import { - EnemyPartyConfig, generateModifierType, + EnemyPartyConfig, + generateModifierType, generateModifierTypeOption, initBattleWithEnemyConfig, leaveEncounterWithoutBattle, @@ -17,7 +18,7 @@ import { } from "#app/data/trainer-config"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { PartyMemberStrength } from "#enums/party-member-strength"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { isNullOrUndefined, randSeedInt, randSeedShuffle } from "#app/utils"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -214,12 +215,12 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = text: `${namespace}:intro_dialogue`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculates what trainers are available for battle in the encounter // Bug type superfan trainer config - const config = getTrainerConfigForWave(scene.currentBattle.waveIndex); + const config = getTrainerConfigForWave(globalScene.currentBattle.waveIndex); const spriteKey = config.getSpriteKey(); encounter.enemyPartyConfigs.push({ trainerConfig: config, @@ -227,7 +228,7 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = }); let beedrillKeys: { spriteKey: string, fileRoot: string }, butterfreeKeys: { spriteKey: string, fileRoot: string }; - if (scene.currentBattle.waveIndex < WAVE_LEVEL_BREAKPOINTS[3]) { + if (globalScene.currentBattle.waveIndex < WAVE_LEVEL_BREAKPOINTS[3]) { beedrillKeys = getSpriteKeysFromSpecies(Species.BEEDRILL, false); butterfreeKeys = getSpriteKeysFromSpecies(Species.BUTTERFREE, false); } else { @@ -270,9 +271,9 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = ]; const requiredItems = [ - generateModifierType(scene, modifierTypes.QUICK_CLAW), - generateModifierType(scene, modifierTypes.GRIP_CLAW), - generateModifierType(scene, modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.BUG ]), + generateModifierType(modifierTypes.QUICK_CLAW), + generateModifierType(modifierTypes.GRIP_CLAW), + generateModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.BUG ]), ]; const requiredItemString = requiredItems.map(m => m?.name ?? "unknown").join("/"); @@ -295,9 +296,9 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Select battle the bug trainer - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const config: EnemyPartyConfig = encounter.enemyPartyConfigs[0]; // Init the moves available for tutor @@ -313,9 +314,9 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = // Assigns callback that teaches move before continuing to rewards encounter.onRewards = doBugTypeMoveTutor; - setEncounterRewards(scene, { fillRemaining: true }); - await transitionMysteryEncounterIntroVisuals(scene, true, true); - await initBattleWithEnemyConfig(scene, config); + setEncounterRewards({ fillRemaining: true }); + await transitionMysteryEncounterIntroVisuals(true, true); + await initBattleWithEnemyConfig(config); } ) .withOption(MysteryEncounterOptionBuilder @@ -326,17 +327,17 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = buttonTooltip: `${namespace}:option.2.tooltip`, disabledButtonTooltip: `${namespace}:option.2.disabled_tooltip` }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Player shows off their bug types - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; // Player gets different rewards depending on the number of bug types they have - const numBugTypes = scene.getPlayerParty().filter(p => p.isOfType(Type.BUG, true)).length; + const numBugTypes = globalScene.getPlayerParty().filter(p => p.isOfType(Type.BUG, true)).length; const numBugTypesText = i18next.t(`${namespace}:numBugTypes`, { count: numBugTypes }); encounter.setDialogueToken("numBugTypes", numBugTypesText); if (numBugTypes < 2) { - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.SUPER_LURE, modifierTypes.GREAT_BALL ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.SUPER_LURE, modifierTypes.GREAT_BALL ], fillRemaining: false }); encounter.selectedOption!.dialogue!.selected = [ { speaker: `${namespace}:speaker`, @@ -344,7 +345,7 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = }, ]; } else if (numBugTypes < 4) { - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.QUICK_CLAW, modifierTypes.MAX_LURE, modifierTypes.ULTRA_BALL ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.QUICK_CLAW, modifierTypes.MAX_LURE, modifierTypes.ULTRA_BALL ], fillRemaining: false }); encounter.selectedOption!.dialogue!.selected = [ { speaker: `${namespace}:speaker`, @@ -352,7 +353,7 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = }, ]; } else if (numBugTypes < 6) { - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.GRIP_CLAW, modifierTypes.MAX_LURE, modifierTypes.ROGUE_BALL ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.GRIP_CLAW, modifierTypes.MAX_LURE, modifierTypes.ROGUE_BALL ], fillRemaining: false }); encounter.selectedOption!.dialogue!.selected = [ { speaker: `${namespace}:speaker`, @@ -362,28 +363,28 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = } else { // If the player has any evolution/form change items that are valid for their party, // spawn one of those items in addition to Dynamax Band, Mega Band, and Master Ball - const modifierOptions: ModifierTypeOption[] = [ generateModifierTypeOption(scene, modifierTypes.MASTER_BALL)! ]; + const modifierOptions: ModifierTypeOption[] = [ generateModifierTypeOption(modifierTypes.MASTER_BALL)! ]; const specialOptions: ModifierTypeOption[] = []; - if (!scene.findModifier(m => m instanceof MegaEvolutionAccessModifier)) { - modifierOptions.push(generateModifierTypeOption(scene, modifierTypes.MEGA_BRACELET)!); + if (!globalScene.findModifier(m => m instanceof MegaEvolutionAccessModifier)) { + modifierOptions.push(generateModifierTypeOption(modifierTypes.MEGA_BRACELET)!); } - if (!scene.findModifier(m => m instanceof GigantamaxAccessModifier)) { - modifierOptions.push(generateModifierTypeOption(scene, modifierTypes.DYNAMAX_BAND)!); + if (!globalScene.findModifier(m => m instanceof GigantamaxAccessModifier)) { + modifierOptions.push(generateModifierTypeOption(modifierTypes.DYNAMAX_BAND)!); } - const nonRareEvolutionModifier = generateModifierTypeOption(scene, modifierTypes.EVOLUTION_ITEM); + const nonRareEvolutionModifier = generateModifierTypeOption(modifierTypes.EVOLUTION_ITEM); if (nonRareEvolutionModifier) { specialOptions.push(nonRareEvolutionModifier); } - const rareEvolutionModifier = generateModifierTypeOption(scene, modifierTypes.RARE_EVOLUTION_ITEM); + const rareEvolutionModifier = generateModifierTypeOption(modifierTypes.RARE_EVOLUTION_ITEM); if (rareEvolutionModifier) { specialOptions.push(rareEvolutionModifier); } - const formChangeModifier = generateModifierTypeOption(scene, modifierTypes.FORM_CHANGE_ITEM); + const formChangeModifier = generateModifierTypeOption(modifierTypes.FORM_CHANGE_ITEM); if (formChangeModifier) { specialOptions.push(formChangeModifier); } - const rareFormChangeModifier = generateModifierTypeOption(scene, modifierTypes.RARE_FORM_CHANGE_ITEM); + const rareFormChangeModifier = generateModifierTypeOption(modifierTypes.RARE_FORM_CHANGE_ITEM); if (rareFormChangeModifier) { specialOptions.push(rareFormChangeModifier); } @@ -391,7 +392,7 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = modifierOptions.push(specialOptions[randSeedInt(specialOptions.length)]); } - setEncounterRewards(scene, { guaranteedModifierTypeOptions: modifierOptions, fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeOptions: modifierOptions, fillRemaining: false }); encounter.selectedOption!.dialogue!.selected = [ { speaker: `${namespace}:speaker`, @@ -400,9 +401,9 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = ]; } }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Player shows off their bug types - leaveEncounterWithoutBattle(scene); + leaveEncounterWithoutBattle(); }) .build()) .withOption(MysteryEncounterOptionBuilder @@ -429,8 +430,8 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = ], secondOptionPrompt: `${namespace}:option.3.select_prompt`, }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Get Pokemon held items and filter for valid ones @@ -466,27 +467,27 @@ export const BugTypeSuperfanEncounter: MysteryEncounter = (item instanceof AttackTypeBoosterModifier && (item.type as AttackTypeBoosterModifierType).moveType === Type.BUG); }); if (!hasValidItem) { - return getEncounterText(scene, `${namespace}:option.3.invalid_selection`) ?? null; + return getEncounterText(`${namespace}:option.3.invalid_selection`) ?? null; } return null; }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const modifier = encounter.misc.chosenModifier; const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon; chosenPokemon.loseHeldItem(modifier, false); - scene.updateModifiers(true, true); + globalScene.updateModifiers(true, true); - const bugNet = generateModifierTypeOption(scene, modifierTypes.MYSTERY_ENCOUNTER_GOLDEN_BUG_NET)!; + const bugNet = generateModifierTypeOption(modifierTypes.MYSTERY_ENCOUNTER_GOLDEN_BUG_NET)!; bugNet.type.tier = ModifierTier.ROGUE; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: [ bugNet ], guaranteedModifierTypeFuncs: [ modifierTypes.REVIVER_SEED ], fillRemaining: false }); - leaveEncounterWithoutBattle(scene, true); + setEncounterRewards({ guaranteedModifierTypeOptions: [ bugNet ], guaranteedModifierTypeFuncs: [ modifierTypes.REVIVER_SEED ], fillRemaining: false }); + leaveEncounterWithoutBattle(true); }) .build()) .withOutroDialogue([ @@ -642,22 +643,22 @@ function getTrainerConfigForWave(waveIndex: number) { return config; } -function doBugTypeMoveTutor(scene: BattleScene): Promise { +function doBugTypeMoveTutor(): Promise { return new Promise(async resolve => { - const moveOptions = scene.currentBattle.mysteryEncounter!.misc.moveTutorOptions; - await showEncounterDialogue(scene, `${namespace}:battle_won`, `${namespace}:speaker`); + const moveOptions = globalScene.currentBattle.mysteryEncounter!.misc.moveTutorOptions; + await showEncounterDialogue(`${namespace}:battle_won`, `${namespace}:speaker`); const overlayScale = 1; - const moveInfoOverlay = new MoveInfoOverlay(scene, { + const moveInfoOverlay = new MoveInfoOverlay({ delayVisibility: false, scale: overlayScale, onSide: true, right: true, x: 1, y: -MoveInfoOverlay.getHeight(overlayScale, true) - 1, - width: (scene.game.canvas.width / 6) - 2, + width: (globalScene.game.canvas.width / 6) - 2, }); - scene.ui.add(moveInfoOverlay); + globalScene.ui.add(moveInfoOverlay); const optionSelectItems = moveOptions.map((move: PokemonMove) => { const option: OptionSelectItem = { @@ -680,7 +681,7 @@ function doBugTypeMoveTutor(scene: BattleScene): Promise { moveInfoOverlay.setVisible(false); }; - const result = await selectOptionThenPokemon(scene, optionSelectItems, `${namespace}:teach_move_prompt`, undefined, onHoverOverCancel); + const result = await selectOptionThenPokemon(optionSelectItems, `${namespace}:teach_move_prompt`, undefined, onHoverOverCancel); // let forceExit = !!result; if (!result) { moveInfoOverlay.active = false; @@ -691,7 +692,7 @@ function doBugTypeMoveTutor(scene: BattleScene): Promise { // Option select complete, handle if they are learning a move if (result && result.selectedOptionIndex < moveOptions.length) { - scene.unshiftPhase(new LearnMovePhase(scene, result.selectedPokemonIndex, moveOptions[result.selectedOptionIndex].moveId)); + globalScene.unshiftPhase(new LearnMovePhase(result.selectedPokemonIndex, moveOptions[result.selectedOptionIndex].moveId)); } // Complete battle and go to rewards diff --git a/src/data/mystery-encounters/encounters/clowning-around-encounter.ts b/src/data/mystery-encounters/encounters/clowning-around-encounter.ts index 6bd6856604b0..e154b61507a2 100644 --- a/src/data/mystery-encounters/encounters/clowning-around-encounter.ts +++ b/src/data/mystery-encounters/encounters/clowning-around-encounter.ts @@ -4,7 +4,7 @@ import { ModifierTier } from "#app/modifier/modifier-tier"; import { ModifierPoolType, modifierTypes, PokemonHeldItemModifierType } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { PartyMemberStrength } from "#enums/party-member-strength"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { Species } from "#enums/species"; @@ -105,8 +105,8 @@ export const ClowningAroundEncounter: MysteryEncounter = speaker: `${namespace}:speaker` }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const clownTrainerType = TrainerType.HARLEQUIN; const clownConfig = trainerConfigs[clownTrainerType].clone(); @@ -142,7 +142,7 @@ export const ClowningAroundEncounter: MysteryEncounter = }); // Load animations/sfx for start of fight moves - loadCustomMovesForEncounter(scene, [ Moves.ROLE_PLAY, Moves.TAUNT ]); + loadCustomMovesForEncounter([ Moves.ROLE_PLAY, Moves.TAUNT ]); encounter.setDialogueToken("blacephalonName", getPokemonSpecies(Species.BLACEPHALON).getName()); @@ -165,12 +165,12 @@ export const ClowningAroundEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Spawn battle const config: EnemyPartyConfig = encounter.enemyPartyConfigs[0]; - setEncounterRewards(scene, { fillRemaining: true }); + setEncounterRewards({ fillRemaining: true }); // TODO: when Magic Room and Wonder Room are implemented, add those to start of battle encounter.startOfBattleEffects.push( @@ -193,28 +193,28 @@ export const ClowningAroundEncounter: MysteryEncounter = ignorePp: true }); - await transitionMysteryEncounterIntroVisuals(scene); - await initBattleWithEnemyConfig(scene, config); + await transitionMysteryEncounterIntroVisuals(); + await initBattleWithEnemyConfig(config); }) - .withPostOptionPhase(async (scene: BattleScene): Promise => { + .withPostOptionPhase(async (): Promise => { // After the battle, offer the player the opportunity to permanently swap ability - const abilityWasSwapped = await handleSwapAbility(scene); + const abilityWasSwapped = await handleSwapAbility(); if (abilityWasSwapped) { - await showEncounterText(scene, `${namespace}:option.1.ability_gained`); + await showEncounterText(`${namespace}:option.1.ability_gained`); } // Play animations once ability swap is complete // Trainer sprite that is shown at end of battle is not the same as mystery encounter intro visuals - scene.tweens.add({ - targets: scene.currentBattle.trainer, + globalScene.tweens.add({ + targets: globalScene.currentBattle.trainer, x: "+=16", y: "-=16", alpha: 0, ease: "Sine.easeInOut", duration: 250 }); - const background = new EncounterBattleAnim(EncounterAnim.SMOKESCREEN, scene.getPlayerPokemon()!, scene.getPlayerPokemon()); - background.playWithoutTargets(scene, 230, 40, 2); + const background = new EncounterBattleAnim(EncounterAnim.SMOKESCREEN, globalScene.getPlayerPokemon()!, globalScene.getPlayerPokemon()); + background.playWithoutTargets(230, 40, 2); return true; }) .build() @@ -239,13 +239,13 @@ export const ClowningAroundEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Swap player's items on pokemon with the most items // Item comparisons look at whichever Pokemon has the greatest number of TRANSFERABLE, non-berry items // So Vitamins, form change items, etc. are not included - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); let mostHeldItemsPokemon = party[0]; let count = mostHeldItemsPokemon.getHeldItems() .filter(m => m.isTransferable && !(m instanceof BerryModifier)) @@ -270,10 +270,10 @@ export const ClowningAroundEncounter: MysteryEncounter = items.filter(m => m instanceof BerryModifier) .forEach(m => { numBerries += m.stackCount; - scene.removeModifier(m); + globalScene.removeModifier(m); }); - generateItemsOfTier(scene, mostHeldItemsPokemon, numBerries, "Berries"); + generateItemsOfTier(mostHeldItemsPokemon, numBerries, "Berries"); // Shuffle Transferable held items in the same tier (only shuffles Ultra and Rogue atm) // For the purpose of this ME, Soothe Bells and Lucky Eggs are counted as Ultra tier @@ -286,24 +286,24 @@ export const ClowningAroundEncounter: MysteryEncounter = const tier = type.tier ?? ModifierTier.ULTRA; if (type.id === "GOLDEN_EGG" || tier === ModifierTier.ROGUE) { numRogue += m.stackCount; - scene.removeModifier(m); + globalScene.removeModifier(m); } else if (type.id === "LUCKY_EGG" || type.id === "SOOTHE_BELL" || tier === ModifierTier.ULTRA) { numUltra += m.stackCount; - scene.removeModifier(m); + globalScene.removeModifier(m); } }); - generateItemsOfTier(scene, mostHeldItemsPokemon, numUltra, ModifierTier.ULTRA); - generateItemsOfTier(scene, mostHeldItemsPokemon, numRogue, ModifierTier.ROGUE); + generateItemsOfTier(mostHeldItemsPokemon, numUltra, ModifierTier.ULTRA); + generateItemsOfTier(mostHeldItemsPokemon, numRogue, ModifierTier.ROGUE); }) - .withOptionPhase(async (scene: BattleScene) => { - leaveEncounterWithoutBattle(scene, true); + .withOptionPhase(async () => { + leaveEncounterWithoutBattle(true); }) - .withPostOptionPhase(async (scene: BattleScene) => { + .withPostOptionPhase(async () => { // Play animations - const background = new EncounterBattleAnim(EncounterAnim.SMOKESCREEN, scene.getPlayerPokemon()!, scene.getPlayerPokemon()); - background.playWithoutTargets(scene, 230, 40, 2); - await transitionMysteryEncounterIntroVisuals(scene, true, true, 200); + const background = new EncounterBattleAnim(EncounterAnim.SMOKESCREEN, globalScene.getPlayerPokemon()!, globalScene.getPlayerPokemon()); + background.playWithoutTargets(230, 40, 2); + await transitionMysteryEncounterIntroVisuals(true, true, 200); }) .build() ) @@ -327,10 +327,10 @@ export const ClowningAroundEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Randomize the second type of all player's pokemon // If the pokemon does not normally have a second type, it will gain 1 - for (const pokemon of scene.getPlayerParty()) { + for (const pokemon of globalScene.getPlayerParty()) { const originalTypes = pokemon.getTypes(false, false, true); // If the Pokemon has non-status moves that don't match the Pokemon's type, prioritizes those as the new type @@ -367,14 +367,14 @@ export const ClowningAroundEncounter: MysteryEncounter = } } }) - .withOptionPhase(async (scene: BattleScene) => { - leaveEncounterWithoutBattle(scene, true); + .withOptionPhase(async () => { + leaveEncounterWithoutBattle(true); }) - .withPostOptionPhase(async (scene: BattleScene) => { + .withPostOptionPhase(async () => { // Play animations - const background = new EncounterBattleAnim(EncounterAnim.SMOKESCREEN, scene.getPlayerPokemon()!, scene.getPlayerPokemon()); - background.playWithoutTargets(scene, 230, 40, 2); - await transitionMysteryEncounterIntroVisuals(scene, true, true, 200); + const background = new EncounterBattleAnim(EncounterAnim.SMOKESCREEN, globalScene.getPlayerPokemon()!, globalScene.getPlayerPokemon()); + background.playWithoutTargets(230, 40, 2); + await transitionMysteryEncounterIntroVisuals(true, true, 200); }) .build() ) @@ -385,24 +385,24 @@ export const ClowningAroundEncounter: MysteryEncounter = ]) .build(); -async function handleSwapAbility(scene: BattleScene) { +async function handleSwapAbility() { return new Promise(async resolve => { - await showEncounterDialogue(scene, `${namespace}:option.1.apply_ability_dialogue`, `${namespace}:speaker`); - await showEncounterText(scene, `${namespace}:option.1.apply_ability_message`); + await showEncounterDialogue(`${namespace}:option.1.apply_ability_dialogue`, `${namespace}:speaker`); + await showEncounterText(`${namespace}:option.1.apply_ability_message`); - scene.ui.setMode(Mode.MESSAGE).then(() => { - displayYesNoOptions(scene, resolve); + globalScene.ui.setMode(Mode.MESSAGE).then(() => { + displayYesNoOptions(resolve); }); }); } -function displayYesNoOptions(scene: BattleScene, resolve) { - showEncounterText(scene, `${namespace}:option.1.ability_prompt`, null, 500, false); +function displayYesNoOptions(resolve) { + showEncounterText(`${namespace}:option.1.ability_prompt`, null, 500, false); const fullOptions = [ { label: i18next.t("menu:yes"), handler: () => { - onYesAbilitySwap(scene, resolve); + onYesAbilitySwap(resolve); return true; } }, @@ -420,29 +420,29 @@ function displayYesNoOptions(scene: BattleScene, resolve) { maxOptions: 7, yOffset: 0 }; - scene.ui.setModeWithoutClear(Mode.OPTION_SELECT, config, null, true); + globalScene.ui.setModeWithoutClear(Mode.OPTION_SELECT, config, null, true); } -function onYesAbilitySwap(scene: BattleScene, resolve) { +function onYesAbilitySwap(resolve) { const onPokemonSelected = (pokemon: PlayerPokemon) => { // Do ability swap - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; applyAbilityOverrideToPokemon(pokemon, encounter.misc.ability); encounter.setDialogueToken("chosenPokemon", pokemon.getNameToRender()); - scene.ui.setMode(Mode.MESSAGE).then(() => resolve(true)); + globalScene.ui.setMode(Mode.MESSAGE).then(() => resolve(true)); }; const onPokemonNotSelected = () => { - scene.ui.setMode(Mode.MESSAGE).then(() => { - displayYesNoOptions(scene, resolve); + globalScene.ui.setMode(Mode.MESSAGE).then(() => { + displayYesNoOptions(resolve); }); }; - selectPokemonForOption(scene, onPokemonSelected, onPokemonNotSelected); + selectPokemonForOption(onPokemonSelected, onPokemonNotSelected); } -function generateItemsOfTier(scene: BattleScene, pokemon: PlayerPokemon, numItems: number, tier: ModifierTier | "Berries") { +function generateItemsOfTier(pokemon: PlayerPokemon, numItems: number, tier: ModifierTier | "Berries") { // These pools have to be defined at runtime so that modifierTypes exist // Pools have instances of the modifier type equal to the max stacks that modifier can be applied to any one pokemon // This is to prevent "over-generating" a random item of a certain type during item swaps @@ -495,11 +495,11 @@ function generateItemsOfTier(scene: BattleScene, pokemon: PlayerPokemon, numItem const newItemType = pool[randIndex]; let newMod: PokemonHeldItemModifierType; if (tier === "Berries") { - newMod = generateModifierType(scene, modifierTypes.BERRY, [ newItemType[0] ]) as PokemonHeldItemModifierType; + newMod = generateModifierType(modifierTypes.BERRY, [ newItemType[0] ]) as PokemonHeldItemModifierType; } else { - newMod = generateModifierType(scene, newItemType[0]) as PokemonHeldItemModifierType; + newMod = generateModifierType(newItemType[0]) as PokemonHeldItemModifierType; } - applyModifierTypeToPlayerPokemon(scene, pokemon, newMod); + applyModifierTypeToPlayerPokemon(pokemon, newMod); // Decrement max stacks and remove from pool if at max newItemType[1]--; if (newItemType[1] <= 0) { diff --git a/src/data/mystery-encounters/encounters/dancing-lessons-encounter.ts b/src/data/mystery-encounters/encounters/dancing-lessons-encounter.ts index 841aadd7c360..4b2efad9a5f9 100644 --- a/src/data/mystery-encounters/encounters/dancing-lessons-encounter.ts +++ b/src/data/mystery-encounters/encounters/dancing-lessons-encounter.ts @@ -1,5 +1,5 @@ import { BattlerIndex } from "#app/battle"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { EncounterBattleAnim } from "#app/data/battle-anims"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; @@ -91,10 +91,10 @@ export const DancingLessonsEncounter: MysteryEncounter = .withAutoHideIntroVisuals(false) .withCatchAllowed(true) .withFleeAllowed(false) - .withOnVisualsStart((scene: BattleScene) => { - const oricorio = scene.getEnemyPokemon()!; - const danceAnim = new EncounterBattleAnim(EncounterAnim.DANCE, oricorio, scene.getPlayerPokemon()!); - danceAnim.play(scene, false, () => { + .withOnVisualsStart(() => { + const oricorio = globalScene.getEnemyPokemon()!; + const danceAnim = new EncounterBattleAnim(EncounterAnim.DANCE, oricorio, globalScene.getPlayerPokemon()!); + danceAnim.play(false, () => { if (oricorio.shiny) { oricorio.sparkle(); } @@ -110,12 +110,12 @@ export const DancingLessonsEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const species = getPokemonSpecies(Species.ORICORIO); - const level = getEncounterPokemonLevelForWave(scene, STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); - const enemyPokemon = new EnemyPokemon(scene, species, level, TrainerSlot.NONE, false); + const level = getEncounterPokemonLevelForWave(STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); + const enemyPokemon = new EnemyPokemon(species, level, TrainerSlot.NONE, false); if (!enemyPokemon.moveset.some(m => m && m.getMove().id === Moves.REVELATION_DANCE)) { if (enemyPokemon.moveset.length < 4) { enemyPokemon.moveset.push(new PokemonMove(Moves.REVELATION_DANCE)); @@ -126,7 +126,7 @@ export const DancingLessonsEncounter: MysteryEncounter = // Set the form index based on the biome // Defaults to Baile style if somehow nothing matches - const currentBiome = scene.arena.biomeType; + const currentBiome = globalScene.arena.biomeType; if (BAILE_STYLE_BIOMES.includes(currentBiome)) { enemyPokemon.formIndex = 0; } else if (POM_POM_STYLE_BIOMES.includes(currentBiome)) { @@ -140,14 +140,14 @@ export const DancingLessonsEncounter: MysteryEncounter = } const oricorioData = new PokemonData(enemyPokemon); - const oricorio = scene.addEnemyPokemon(species, level, TrainerSlot.NONE, false, false, oricorioData); + const oricorio = globalScene.addEnemyPokemon(species, level, TrainerSlot.NONE, false, false, oricorioData); // Adds a real Pokemon sprite to the field (required for the animation) - scene.getEnemyParty().forEach(enemyPokemon => { - scene.field.remove(enemyPokemon, true); + globalScene.getEnemyParty().forEach(enemyPokemon => { + globalScene.field.remove(enemyPokemon, true); }); - scene.currentBattle.enemyParty = [ oricorio ]; - scene.field.add(oricorio); + globalScene.currentBattle.enemyParty = [ oricorio ]; + globalScene.field.add(oricorio); // Spawns on offscreen field oricorio.x -= 300; encounter.loadAssets.push(oricorio.loadAssets()); @@ -160,8 +160,8 @@ export const DancingLessonsEncounter: MysteryEncounter = // Gets +1 to all stats except SPD on battle start tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - queueEncounterMessage(pokemon.scene, `${namespace}:option.1.boss_enraged`); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF ], 1)); + queueEncounterMessage(`${namespace}:option.1.boss_enraged`); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF ], 1)); } }], }; @@ -186,9 +186,9 @@ export const DancingLessonsEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Pick battle - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.startOfBattleEffects.push({ sourceBattlerIndex: BattlerIndex.ENEMY, @@ -197,9 +197,9 @@ export const DancingLessonsEncounter: MysteryEncounter = ignorePp: true }); - await hideOricorioPokemon(scene); - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.BATON ], fillRemaining: true }); - await initBattleWithEnemyConfig(scene, encounter.enemyPartyConfigs[0]); + await hideOricorioPokemon(); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.BATON ], fillRemaining: true }); + await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); }) .build() ) @@ -215,25 +215,25 @@ export const DancingLessonsEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Learn its Dance - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { encounter.setDialogueToken("selectedPokemon", pokemon.getNameToRender()); - scene.unshiftPhase(new LearnMovePhase(scene, scene.getPlayerParty().indexOf(pokemon), Moves.REVELATION_DANCE)); + globalScene.unshiftPhase(new LearnMovePhase(globalScene.getPlayerParty().indexOf(pokemon), Moves.REVELATION_DANCE)); // Play animation again to "learn" the dance - const danceAnim = new EncounterBattleAnim(EncounterAnim.DANCE, scene.getEnemyPokemon()!, scene.getPlayerPokemon()); - danceAnim.play(scene); + const danceAnim = new EncounterBattleAnim(EncounterAnim.DANCE, globalScene.getEnemyPokemon()!, globalScene.getPlayerPokemon()); + danceAnim.play(); }; - return selectPokemonForOption(scene, onPokemonSelected); + return selectPokemonForOption(onPokemonSelected); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Learn its Dance - await hideOricorioPokemon(scene); - leaveEncounterWithoutBattle(scene, true); + await hideOricorioPokemon(); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -252,9 +252,9 @@ export const DancingLessonsEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Open menu for selecting pokemon with a Dancing move - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Return the options for nature selection return pokemon.moveset @@ -281,20 +281,20 @@ export const DancingLessonsEncounter: MysteryEncounter = if (!pokemon.isAllowedInBattle()) { return i18next.t("partyUiHandler:cantBeUsed", { pokemonName: pokemon.getNameToRender() }) ?? null; } - const meetsReqs = encounter.options[2].pokemonMeetsPrimaryRequirements(scene, pokemon); + const meetsReqs = encounter.options[2].pokemonMeetsPrimaryRequirements(pokemon); if (!meetsReqs) { - return getEncounterText(scene, `${namespace}:invalid_selection`) ?? null; + return getEncounterText(`${namespace}:invalid_selection`) ?? null; } return null; }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Show the Oricorio a dance, and recruit it - const encounter = scene.currentBattle.mysteryEncounter!; - const oricorio = encounter.misc.oricorioData.toPokemon(scene); + const encounter = globalScene.currentBattle.mysteryEncounter!; + const oricorio = encounter.misc.oricorioData.toPokemon(); oricorio.passive = true; // Ensure the Oricorio's moveset gains the Dance move the player used @@ -307,18 +307,18 @@ export const DancingLessonsEncounter: MysteryEncounter = } } - await hideOricorioPokemon(scene); - await catchPokemon(scene, oricorio, null, PokeballType.POKEBALL, false); - leaveEncounterWithoutBattle(scene, true); + await hideOricorioPokemon(); + await catchPokemon(oricorio, null, PokeballType.POKEBALL, false); + leaveEncounterWithoutBattle(true); }) .build() ) .build(); -function hideOricorioPokemon(scene: BattleScene) { +function hideOricorioPokemon() { return new Promise(resolve => { - const oricorioSprite = scene.getEnemyParty()[0]; - scene.tweens.add({ + const oricorioSprite = globalScene.getEnemyParty()[0]; + globalScene.tweens.add({ targets: oricorioSprite, x: "+=16", y: "-=16", @@ -326,7 +326,7 @@ function hideOricorioPokemon(scene: BattleScene) { ease: "Sine.easeInOut", duration: 750, onComplete: () => { - scene.field.remove(oricorioSprite, true); + globalScene.field.remove(oricorioSprite, true); resolve(); } }); diff --git a/src/data/mystery-encounters/encounters/dark-deal-encounter.ts b/src/data/mystery-encounters/encounters/dark-deal-encounter.ts index 05d6501f256c..c008b1957933 100644 --- a/src/data/mystery-encounters/encounters/dark-deal-encounter.ts +++ b/src/data/mystery-encounters/encounters/dark-deal-encounter.ts @@ -2,7 +2,7 @@ import { Type } from "#enums/type"; import { isNullOrUndefined, randSeedInt } from "#app/utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { modifierTypes } from "#app/modifier/modifier-type"; import { getPokemonSpecies } from "#app/data/pokemon-species"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; @@ -138,16 +138,16 @@ export const DarkDealEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Removes random pokemon (including fainted) from party and adds name to dialogue data tokens // Will never return last battle able mon and instead pick fainted/unable to battle - const removedPokemon = getRandomPlayerPokemon(scene, true, false, true); + const removedPokemon = getRandomPlayerPokemon(true, false, true); // Get all the pokemon's held items const modifiers = removedPokemon.getHeldItems().filter(m => !(m instanceof PokemonFormChangeItemModifier)); - scene.removePokemonFromPlayerParty(removedPokemon); + globalScene.removePokemonFromPlayerParty(removedPokemon); - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.setDialogueToken("pokeName", removedPokemon.getNameToRender()); // Store removed pokemon types @@ -156,16 +156,16 @@ export const DarkDealEncounter: MysteryEncounter = modifiers }; }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Give the player 5 Rogue Balls - const encounter = scene.currentBattle.mysteryEncounter!; - scene.unshiftPhase(new ModifierRewardPhase(scene, modifierTypes.ROGUE_BALL)); + const encounter = globalScene.currentBattle.mysteryEncounter!; + globalScene.unshiftPhase(new ModifierRewardPhase(modifierTypes.ROGUE_BALL)); // Start encounter with random legendary (7-10 starter strength) that has level additive // If this is a mono-type challenge, always ensure the required type is filtered for let bossTypes: Type[] = encounter.misc.removedTypes; - const singleTypeChallenges = scene.gameMode.challenges.filter(c => c.value && c.id === Challenges.SINGLE_TYPE); - if (scene.gameMode.isChallenge && singleTypeChallenges.length > 0) { + const singleTypeChallenges = globalScene.gameMode.challenges.filter(c => c.value && c.id === Challenges.SINGLE_TYPE); + if (globalScene.gameMode.isChallenge && singleTypeChallenges.length > 0) { bossTypes = singleTypeChallenges.map(c => (c.value - 1) as Type); } @@ -191,7 +191,7 @@ export const DarkDealEncounter: MysteryEncounter = const config: EnemyPartyConfig = { pokemonConfigs: [ pokemonConfig ], }; - await initBattleWithEnemyConfig(scene, config); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -206,9 +206,9 @@ export const DarkDealEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) diff --git a/src/data/mystery-encounters/encounters/delibirdy-encounter.ts b/src/data/mystery-encounters/encounters/delibirdy-encounter.ts index a3a97a012387..08dca167d616 100644 --- a/src/data/mystery-encounters/encounters/delibirdy-encounter.ts +++ b/src/data/mystery-encounters/encounters/delibirdy-encounter.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { CombinationPokemonRequirement, HeldItemRequirement, MoneyRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; @@ -96,15 +96,15 @@ export const DelibirdyEncounter: MysteryEncounter = text: `${namespace}:outro`, } ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.setDialogueToken("delibirdName", getPokemonSpecies(Species.DELIBIRD).getName()); - scene.loadBgm("mystery_encounter_delibirdy", "mystery_encounter_delibirdy.mp3"); + globalScene.loadBgm("mystery_encounter_delibirdy", "mystery_encounter_delibirdy.mp3"); return true; }) - .withOnVisualsStart((scene: BattleScene) => { - scene.fadeAndSwitchBgm("mystery_encounter_delibirdy"); + .withOnVisualsStart(() => { + globalScene.fadeAndSwitchBgm("mystery_encounter_delibirdy"); return true; }) .withOption( @@ -120,27 +120,27 @@ export const DelibirdyEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; - updatePlayerMoney(scene, -(encounter.options[0].requirements[0] as MoneyRequirement).requiredMoney, true, false); + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; + updatePlayerMoney(-(encounter.options[0].requirements[0] as MoneyRequirement).requiredMoney, true, false); return true; }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Give the player an Amulet Coin // Check if the player has max stacks of that item already - const existing = scene.findModifier(m => m instanceof MoneyMultiplierModifier) as MoneyMultiplierModifier; + const existing = globalScene.findModifier(m => m instanceof MoneyMultiplierModifier) as MoneyMultiplierModifier; - if (existing && existing.getStackCount() >= existing.getMaxStackCount(scene)) { + if (existing && existing.getStackCount() >= existing.getMaxStackCount()) { // At max stacks, give the first party pokemon a Shell Bell instead - const shellBell = generateModifierType(scene, modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; - await applyModifierTypeToPlayerPokemon(scene, scene.getPlayerPokemon()!, shellBell); - scene.playSound("item_fanfare"); - await showEncounterText(scene, i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); + const shellBell = generateModifierType(modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; + await applyModifierTypeToPlayerPokemon(globalScene.getPlayerPokemon()!, shellBell); + globalScene.playSound("item_fanfare"); + await showEncounterText(i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); } else { - scene.unshiftPhase(new ModifierRewardPhase(scene, modifierTypes.AMULET_COIN)); + globalScene.unshiftPhase(new ModifierRewardPhase(modifierTypes.AMULET_COIN)); } - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -158,8 +158,8 @@ export const DelibirdyEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Get Pokemon held items and filter for valid ones const validItems = pokemon.getHeldItems().filter((it) => { @@ -185,53 +185,53 @@ export const DelibirdyEncounter: MysteryEncounter = const selectableFilter = (pokemon: Pokemon) => { // If pokemon has valid item, it can be selected - const meetsReqs = encounter.options[1].pokemonMeetsPrimaryRequirements(scene, pokemon); + const meetsReqs = encounter.options[1].pokemonMeetsPrimaryRequirements(pokemon); if (!meetsReqs) { - return getEncounterText(scene, `${namespace}:invalid_selection`) ?? null; + return getEncounterText(`${namespace}:invalid_selection`) ?? null; } return null; }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const modifier: BerryModifier | PokemonInstantReviveModifier = encounter.misc.chosenModifier; const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon; // Give the player a Candy Jar if they gave a Berry, and a Berry Pouch for Reviver Seed if (modifier instanceof BerryModifier) { // Check if the player has max stacks of that Candy Jar already - const existing = scene.findModifier(m => m instanceof LevelIncrementBoosterModifier) as LevelIncrementBoosterModifier; + const existing = globalScene.findModifier(m => m instanceof LevelIncrementBoosterModifier) as LevelIncrementBoosterModifier; - if (existing && existing.getStackCount() >= existing.getMaxStackCount(scene)) { + if (existing && existing.getStackCount() >= existing.getMaxStackCount()) { // At max stacks, give the first party pokemon a Shell Bell instead - const shellBell = generateModifierType(scene, modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; - await applyModifierTypeToPlayerPokemon(scene, scene.getPlayerPokemon()!, shellBell); - scene.playSound("item_fanfare"); - await showEncounterText(scene, i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); + const shellBell = generateModifierType(modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; + await applyModifierTypeToPlayerPokemon(globalScene.getPlayerPokemon()!, shellBell); + globalScene.playSound("item_fanfare"); + await showEncounterText(i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); } else { - scene.unshiftPhase(new ModifierRewardPhase(scene, modifierTypes.CANDY_JAR)); + globalScene.unshiftPhase(new ModifierRewardPhase(modifierTypes.CANDY_JAR)); } } else { // Check if the player has max stacks of that Berry Pouch already - const existing = scene.findModifier(m => m instanceof PreserveBerryModifier) as PreserveBerryModifier; + const existing = globalScene.findModifier(m => m instanceof PreserveBerryModifier) as PreserveBerryModifier; - if (existing && existing.getStackCount() >= existing.getMaxStackCount(scene)) { + if (existing && existing.getStackCount() >= existing.getMaxStackCount()) { // At max stacks, give the first party pokemon a Shell Bell instead - const shellBell = generateModifierType(scene, modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; - await applyModifierTypeToPlayerPokemon(scene, scene.getPlayerPokemon()!, shellBell); - scene.playSound("item_fanfare"); - await showEncounterText(scene, i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); + const shellBell = generateModifierType(modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; + await applyModifierTypeToPlayerPokemon(globalScene.getPlayerPokemon()!, shellBell); + globalScene.playSound("item_fanfare"); + await showEncounterText(i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); } else { - scene.unshiftPhase(new ModifierRewardPhase(scene, modifierTypes.BERRY_POUCH)); + globalScene.unshiftPhase(new ModifierRewardPhase(modifierTypes.BERRY_POUCH)); } } chosenPokemon.loseHeldItem(modifier, false); - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -249,8 +249,8 @@ export const DelibirdyEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Get Pokemon held items and filter for valid ones const validItems = pokemon.getHeldItems().filter((it) => { @@ -276,37 +276,37 @@ export const DelibirdyEncounter: MysteryEncounter = const selectableFilter = (pokemon: Pokemon) => { // If pokemon has valid item, it can be selected - const meetsReqs = encounter.options[2].pokemonMeetsPrimaryRequirements(scene, pokemon); + const meetsReqs = encounter.options[2].pokemonMeetsPrimaryRequirements(pokemon); if (!meetsReqs) { - return getEncounterText(scene, `${namespace}:invalid_selection`) ?? null; + return getEncounterText(`${namespace}:invalid_selection`) ?? null; } return null; }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const modifier = encounter.misc.chosenModifier; const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon; // Check if the player has max stacks of Healing Charm already - const existing = scene.findModifier(m => m instanceof HealingBoosterModifier) as HealingBoosterModifier; + const existing = globalScene.findModifier(m => m instanceof HealingBoosterModifier) as HealingBoosterModifier; - if (existing && existing.getStackCount() >= existing.getMaxStackCount(scene)) { + if (existing && existing.getStackCount() >= existing.getMaxStackCount()) { // At max stacks, give the first party pokemon a Shell Bell instead - const shellBell = generateModifierType(scene, modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; - await applyModifierTypeToPlayerPokemon(scene, scene.getPlayerParty()[0], shellBell); - scene.playSound("item_fanfare"); - await showEncounterText(scene, i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); + const shellBell = generateModifierType(modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; + await applyModifierTypeToPlayerPokemon(globalScene.getPlayerParty()[0], shellBell); + globalScene.playSound("item_fanfare"); + await showEncounterText(i18next.t("battle:rewardGain", { modifierName: shellBell.name }), null, undefined, true); } else { - scene.unshiftPhase(new ModifierRewardPhase(scene, modifierTypes.HEALING_CHARM)); + globalScene.unshiftPhase(new ModifierRewardPhase(modifierTypes.HEALING_CHARM)); } chosenPokemon.loseHeldItem(modifier, false); - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) diff --git a/src/data/mystery-encounters/encounters/department-store-sale-encounter.ts b/src/data/mystery-encounters/encounters/department-store-sale-encounter.ts index 10034d192638..977a52f6b398 100644 --- a/src/data/mystery-encounters/encounters/department-store-sale-encounter.ts +++ b/src/data/mystery-encounters/encounters/department-store-sale-encounter.ts @@ -6,7 +6,6 @@ import { ModifierTypeFunc, modifierTypes } from "#app/modifier/modifier-type"; import { randSeedInt } from "#app/utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; import MysteryEncounter, { MysteryEncounterBuilder, } from "#app/data/mystery-encounters/mystery-encounter"; @@ -60,7 +59,7 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.1.label`, buttonTooltip: `${namespace}:option.1.tooltip`, }, - async (scene: BattleScene) => { + async () => { // Choose TMs const modifiers: ModifierTypeFunc[] = []; let i = 0; @@ -77,8 +76,8 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = i++; } - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); + leaveEncounterWithoutBattle(); } ) .withSimpleOption( @@ -86,7 +85,7 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.2.label`, buttonTooltip: `${namespace}:option.2.tooltip`, }, - async (scene: BattleScene) => { + async () => { // Choose Vitamins const modifiers: ModifierTypeFunc[] = []; let i = 0; @@ -101,8 +100,8 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = i++; } - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); + leaveEncounterWithoutBattle(); } ) .withSimpleOption( @@ -110,7 +109,7 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.3.label`, buttonTooltip: `${namespace}:option.3.tooltip`, }, - async (scene: BattleScene) => { + async () => { // Choose X Items const modifiers: ModifierTypeFunc[] = []; let i = 0; @@ -125,8 +124,8 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = i++; } - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); + leaveEncounterWithoutBattle(); } ) .withSimpleOption( @@ -134,7 +133,7 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.4.label`, buttonTooltip: `${namespace}:option.4.tooltip`, }, - async (scene: BattleScene) => { + async () => { // Choose Pokeballs const modifiers: ModifierTypeFunc[] = []; let i = 0; @@ -153,8 +152,8 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = i++; } - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ guaranteedModifierTypeFuncs: modifiers, fillRemaining: false, }); + leaveEncounterWithoutBattle(); } ) .withOutroDialogue([ diff --git a/src/data/mystery-encounters/encounters/field-trip-encounter.ts b/src/data/mystery-encounters/encounters/field-trip-encounter.ts index 1c26df0cf714..87e476a30eec 100644 --- a/src/data/mystery-encounters/encounters/field-trip-encounter.ts +++ b/src/data/mystery-encounters/encounters/field-trip-encounter.ts @@ -5,7 +5,7 @@ import { PlayerPokemon, PokemonMove } from "#app/field/pokemon"; import { modifierTypes } from "#app/modifier/modifier-type"; import { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode"; @@ -64,8 +64,8 @@ export const FieldTripEncounter: MysteryEncounter = buttonTooltip: `${namespace}:option.1.tooltip`, secondOptionPrompt: `${namespace}:second_option_prompt`, }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Return the options for Pokemon move valid for this option return pokemon.moveset.map((move: PokemonMove) => { @@ -74,7 +74,7 @@ export const FieldTripEncounter: MysteryEncounter = handler: () => { // Pokemon and move selected encounter.setDialogueToken("moveCategory", i18next.t(`${namespace}:physical`)); - pokemonAndMoveChosen(scene, pokemon, move, MoveCategory.PHYSICAL); + pokemonAndMoveChosen(pokemon, move, MoveCategory.PHYSICAL); return true; }, }; @@ -82,23 +82,23 @@ export const FieldTripEncounter: MysteryEncounter = }); }; - return selectPokemonForOption(scene, onPokemonSelected); + return selectPokemonForOption(onPokemonSelected); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; if (encounter.misc.correctMove) { const modifiers = [ - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.ATK ])!, - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.DEF ])!, - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPD ])!, - generateModifierTypeOption(scene, modifierTypes.DIRE_HIT)!, - generateModifierTypeOption(scene, modifierTypes.RARER_CANDY)!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.ATK ])!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.DEF ])!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPD ])!, + generateModifierTypeOption(modifierTypes.DIRE_HIT)!, + generateModifierTypeOption(modifierTypes.RARER_CANDY)!, ]; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: modifiers, fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeOptions: modifiers, fillRemaining: false }); } - leaveEncounterWithoutBattle(scene, !encounter.misc.correctMove); + leaveEncounterWithoutBattle(!encounter.misc.correctMove); }) .build() ) @@ -110,8 +110,8 @@ export const FieldTripEncounter: MysteryEncounter = buttonTooltip: `${namespace}:option.2.tooltip`, secondOptionPrompt: `${namespace}:second_option_prompt`, }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Return the options for Pokemon move valid for this option return pokemon.moveset.map((move: PokemonMove) => { @@ -120,7 +120,7 @@ export const FieldTripEncounter: MysteryEncounter = handler: () => { // Pokemon and move selected encounter.setDialogueToken("moveCategory", i18next.t(`${namespace}:special`)); - pokemonAndMoveChosen(scene, pokemon, move, MoveCategory.SPECIAL); + pokemonAndMoveChosen(pokemon, move, MoveCategory.SPECIAL); return true; }, }; @@ -128,23 +128,23 @@ export const FieldTripEncounter: MysteryEncounter = }); }; - return selectPokemonForOption(scene, onPokemonSelected); + return selectPokemonForOption(onPokemonSelected); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; if (encounter.misc.correctMove) { const modifiers = [ - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPATK ])!, - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPDEF ])!, - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPD ])!, - generateModifierTypeOption(scene, modifierTypes.DIRE_HIT)!, - generateModifierTypeOption(scene, modifierTypes.RARER_CANDY)!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPATK ])!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPDEF ])!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPD ])!, + generateModifierTypeOption(modifierTypes.DIRE_HIT)!, + generateModifierTypeOption(modifierTypes.RARER_CANDY)!, ]; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: modifiers, fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeOptions: modifiers, fillRemaining: false }); } - leaveEncounterWithoutBattle(scene, !encounter.misc.correctMove); + leaveEncounterWithoutBattle(!encounter.misc.correctMove); }) .build() ) @@ -156,8 +156,8 @@ export const FieldTripEncounter: MysteryEncounter = buttonTooltip: `${namespace}:option.3.tooltip`, secondOptionPrompt: `${namespace}:second_option_prompt`, }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Return the options for Pokemon move valid for this option return pokemon.moveset.map((move: PokemonMove) => { @@ -166,7 +166,7 @@ export const FieldTripEncounter: MysteryEncounter = handler: () => { // Pokemon and move selected encounter.setDialogueToken("moveCategory", i18next.t(`${namespace}:status`)); - pokemonAndMoveChosen(scene, pokemon, move, MoveCategory.STATUS); + pokemonAndMoveChosen(pokemon, move, MoveCategory.STATUS); return true; }, }; @@ -174,30 +174,30 @@ export const FieldTripEncounter: MysteryEncounter = }); }; - return selectPokemonForOption(scene, onPokemonSelected); + return selectPokemonForOption(onPokemonSelected); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; if (encounter.misc.correctMove) { const modifiers = [ - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.ACC ])!, - generateModifierTypeOption(scene, modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPD ])!, - generateModifierTypeOption(scene, modifierTypes.GREAT_BALL)!, - generateModifierTypeOption(scene, modifierTypes.IV_SCANNER)!, - generateModifierTypeOption(scene, modifierTypes.RARER_CANDY)!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.ACC ])!, + generateModifierTypeOption(modifierTypes.TEMP_STAT_STAGE_BOOSTER, [ Stat.SPD ])!, + generateModifierTypeOption(modifierTypes.GREAT_BALL)!, + generateModifierTypeOption(modifierTypes.IV_SCANNER)!, + generateModifierTypeOption(modifierTypes.RARER_CANDY)!, ]; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: modifiers, fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeOptions: modifiers, fillRemaining: false }); } - leaveEncounterWithoutBattle(scene, !encounter.misc.correctMove); + leaveEncounterWithoutBattle(!encounter.misc.correctMove); }) .build() ) .build(); -function pokemonAndMoveChosen(scene: BattleScene, pokemon: PlayerPokemon, move: PokemonMove, correctMoveCategory: MoveCategory) { - const encounter = scene.currentBattle.mysteryEncounter!; +function pokemonAndMoveChosen(pokemon: PlayerPokemon, move: PokemonMove, correctMoveCategory: MoveCategory) { + const encounter = globalScene.currentBattle.mysteryEncounter!; const correctMove = move.getMove().category === correctMoveCategory; encounter.setDialogueToken("pokeName", pokemon.getNameToRender()); encounter.setDialogueToken("move", move.getName()); @@ -214,7 +214,7 @@ function pokemonAndMoveChosen(scene: BattleScene, pokemon: PlayerPokemon, move: text: `${namespace}:incorrect_exp`, }, ]; - setEncounterExp(scene, scene.getPlayerParty().map((p) => p.id), 50); + setEncounterExp(globalScene.getPlayerParty().map((p) => p.id), 50); } else { encounter.selectedOption!.dialogue!.selected = [ { @@ -228,7 +228,7 @@ function pokemonAndMoveChosen(scene: BattleScene, pokemon: PlayerPokemon, move: text: `${namespace}:correct_exp`, }, ]; - setEncounterExp(scene, [ pokemon.id ], 100); + setEncounterExp([ pokemon.id ], 100); } encounter.misc = { correctMove: correctMove, diff --git a/src/data/mystery-encounters/encounters/fiery-fallout-encounter.ts b/src/data/mystery-encounters/encounters/fiery-fallout-encounter.ts index bbc979e844e8..d53fcf4a4c2e 100644 --- a/src/data/mystery-encounters/encounters/fiery-fallout-encounter.ts +++ b/src/data/mystery-encounters/encounters/fiery-fallout-encounter.ts @@ -2,7 +2,7 @@ import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/myst import { EnemyPartyConfig, initBattleWithEnemyConfig, loadCustomMovesForEncounter, leaveEncounterWithoutBattle, setEncounterExp, setEncounterRewards, transitionMysteryEncounterIntroVisuals, generateModifierType } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { AttackTypeBoosterModifierType, modifierTypes, } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { AbilityRequirement, CombinationPokemonRequirement, TypeRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; import { Species } from "#enums/species"; @@ -58,8 +58,8 @@ export const FieryFalloutEncounter: MysteryEncounter = text: `${namespace}:intro`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate boss mons const volcaronaSpecies = getPokemonSpecies(Species.VOLCARONA); @@ -71,7 +71,7 @@ export const FieryFalloutEncounter: MysteryEncounter = gender: Gender.MALE, tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.SPDEF, Stat.SPD ], 1)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.SPDEF, Stat.SPD ], 1)); } }, { @@ -80,7 +80,7 @@ export const FieryFalloutEncounter: MysteryEncounter = gender: Gender.FEMALE, tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.SPDEF, Stat.SPD ], 1)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.SPDEF, Stat.SPD ], 1)); } } ], @@ -113,25 +113,25 @@ export const FieryFalloutEncounter: MysteryEncounter = ]; // Load animations/sfx for Volcarona moves - loadCustomMovesForEncounter(scene, [ Moves.FIRE_SPIN, Moves.QUIVER_DANCE ]); + loadCustomMovesForEncounter([ Moves.FIRE_SPIN, Moves.QUIVER_DANCE ]); - scene.arena.trySetWeather(WeatherType.SUNNY, true); + globalScene.arena.trySetWeather(WeatherType.SUNNY, true); encounter.setDialogueToken("volcaronaName", getPokemonSpecies(Species.VOLCARONA).getName()); return true; }) - .withOnVisualsStart((scene: BattleScene) => { + .withOnVisualsStart(() => { // Play animations - const background = new EncounterBattleAnim(EncounterAnim.MAGMA_BG, scene.getPlayerPokemon()!, scene.getPlayerPokemon()); - background.playWithoutTargets(scene, 200, 70, 2, 3); - const animation = new EncounterBattleAnim(EncounterAnim.MAGMA_SPOUT, scene.getPlayerPokemon()!, scene.getPlayerPokemon()); - animation.playWithoutTargets(scene, 80, 100, 2); - scene.time.delayedCall(600, () => { - animation.playWithoutTargets(scene, -20, 100, 2); + const background = new EncounterBattleAnim(EncounterAnim.MAGMA_BG, globalScene.getPlayerPokemon()!, globalScene.getPlayerPokemon()); + background.playWithoutTargets(200, 70, 2, 3); + const animation = new EncounterBattleAnim(EncounterAnim.MAGMA_SPOUT, globalScene.getPlayerPokemon()!, globalScene.getPlayerPokemon()); + animation.playWithoutTargets(80, 100, 2); + globalScene.time.delayedCall(600, () => { + animation.playWithoutTargets(-20, 100, 2); }); - scene.time.delayedCall(1200, () => { - animation.playWithoutTargets(scene, 140, 150, 2); + globalScene.time.delayedCall(1200, () => { + animation.playWithoutTargets(140, 150, 2); }); return true; @@ -150,10 +150,10 @@ export const FieryFalloutEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Pick battle - const encounter = scene.currentBattle.mysteryEncounter!; - setEncounterRewards(scene, { fillRemaining: true }, undefined, () => giveLeadPokemonAttackTypeBoostItem(scene)); + const encounter = globalScene.currentBattle.mysteryEncounter!; + setEncounterRewards({ fillRemaining: true }, undefined, () => giveLeadPokemonAttackTypeBoostItem()); encounter.startOfBattleEffects.push( { @@ -168,7 +168,7 @@ export const FieryFalloutEncounter: MysteryEncounter = move: new PokemonMove(Moves.FIRE_SPIN), ignorePp: true }); - await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]); + await initBattleWithEnemyConfig(globalScene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]); } ) .withSimpleOption( @@ -181,15 +181,15 @@ export const FieryFalloutEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Damage non-fire types and burn 1 random non-fire type member + give it Heatproof - const encounter = scene.currentBattle.mysteryEncounter!; - const nonFireTypes = scene.getPlayerParty().filter((p) => p.isAllowedInBattle() && !p.getTypes().includes(Type.FIRE)); + const encounter = globalScene.currentBattle.mysteryEncounter!; + const nonFireTypes = globalScene.getPlayerParty().filter((p) => p.isAllowedInBattle() && !p.getTypes().includes(Type.FIRE)); for (const pkm of nonFireTypes) { const percentage = DAMAGE_PERCENTAGE / 100; const damage = Math.floor(pkm.getMaxHp() * percentage); - applyDamageToPokemon(scene, pkm, damage); + applyDamageToPokemon(pkm, damage); } // Burn random member @@ -201,7 +201,7 @@ export const FieryFalloutEncounter: MysteryEncounter = // Burn applied encounter.setDialogueToken("burnedPokemon", chosenPokemon.getNameToRender()); encounter.setDialogueToken("abilityName", new Ability(Abilities.HEATPROOF, 3).name); - queueEncounterMessage(scene, `${namespace}:option.2.target_burned`); + queueEncounterMessage(`${namespace}:option.2.target_burned`); // Also permanently change the burned Pokemon's ability to Heatproof applyAbilityOverrideToPokemon(chosenPokemon, Abilities.HEATPROOF); @@ -209,7 +209,7 @@ export const FieryFalloutEncounter: MysteryEncounter = } // No rewards - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); } ) .withOption( @@ -231,44 +231,44 @@ export const FieryFalloutEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Do NOT await this, to prevent player from repeatedly pressing options - transitionMysteryEncounterIntroVisuals(scene, false, false, 2000); + transitionMysteryEncounterIntroVisuals(false, false, 2000); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Fire types help calm the Volcarona - const encounter = scene.currentBattle.mysteryEncounter!; - await transitionMysteryEncounterIntroVisuals(scene); - setEncounterRewards(scene, + const encounter = globalScene.currentBattle.mysteryEncounter!; + await transitionMysteryEncounterIntroVisuals(); + setEncounterRewards( { fillRemaining: true }, undefined, () => { - giveLeadPokemonAttackTypeBoostItem(scene); + giveLeadPokemonAttackTypeBoostItem(); }); const primary = encounter.options[2].primaryPokemon!; - setEncounterExp(scene, [ primary.id ], getPokemonSpecies(Species.VOLCARONA).baseExp * 2); - leaveEncounterWithoutBattle(scene); + setEncounterExp([ primary.id ], getPokemonSpecies(Species.VOLCARONA).baseExp * 2); + leaveEncounterWithoutBattle(); }) .build() ) .build(); -function giveLeadPokemonAttackTypeBoostItem(scene: BattleScene) { +function giveLeadPokemonAttackTypeBoostItem() { // Give first party pokemon attack type boost item for free at end of battle - const leadPokemon = scene.getPlayerParty()?.[0]; + const leadPokemon = globalScene.getPlayerParty()?.[0]; if (leadPokemon) { // Generate type booster held item, default to Charcoal if item fails to generate - let boosterModifierType = generateModifierType(scene, modifierTypes.ATTACK_TYPE_BOOSTER) as AttackTypeBoosterModifierType; + let boosterModifierType = generateModifierType(modifierTypes.ATTACK_TYPE_BOOSTER) as AttackTypeBoosterModifierType; if (!boosterModifierType) { - boosterModifierType = generateModifierType(scene, modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.FIRE ]) as AttackTypeBoosterModifierType; + boosterModifierType = generateModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.FIRE ]) as AttackTypeBoosterModifierType; } - applyModifierTypeToPlayerPokemon(scene, leadPokemon, boosterModifierType); + applyModifierTypeToPlayerPokemon(leadPokemon, boosterModifierType); - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.setDialogueToken("itemName", boosterModifierType.name); encounter.setDialogueToken("leadPokemon", leadPokemon.getNameToRender()); - queueEncounterMessage(scene, `${namespace}:found_item`); + queueEncounterMessage(`${namespace}:found_item`); } } diff --git a/src/data/mystery-encounters/encounters/fight-or-flight-encounter.ts b/src/data/mystery-encounters/encounters/fight-or-flight-encounter.ts index 3533e10df293..6c1a42cafb42 100644 --- a/src/data/mystery-encounters/encounters/fight-or-flight-encounter.ts +++ b/src/data/mystery-encounters/encounters/fight-or-flight-encounter.ts @@ -2,7 +2,8 @@ import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/myst import { EnemyPartyConfig, initBattleWithEnemyConfig, - leaveEncounterWithoutBattle, setEncounterExp, + leaveEncounterWithoutBattle, + setEncounterExp, setEncounterRewards } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { STEALING_MOVES } from "#app/data/mystery-encounters/requirements/requirement-groups"; @@ -16,7 +17,7 @@ import { regenerateModifierPoolThresholds, } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MoveRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -51,13 +52,13 @@ export const FightOrFlightEncounter: MysteryEncounter = text: `${namespace}:intro`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate boss mon - const level = getEncounterPokemonLevelForWave(scene, STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); - const bossSpecies = scene.arena.randomSpecies(scene.currentBattle.waveIndex, level, 0, getPartyLuckValue(scene.getPlayerParty()), true); - const bossPokemon = new EnemyPokemon(scene, bossSpecies, level, TrainerSlot.NONE, true); + const level = getEncounterPokemonLevelForWave(STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); + const bossSpecies = globalScene.arena.randomSpecies(globalScene.currentBattle.waveIndex, level, 0, getPartyLuckValue(globalScene.getPlayerParty()), true); + const bossPokemon = new EnemyPokemon(bossSpecies, level, TrainerSlot.NONE, true); encounter.setDialogueToken("enemyPokemon", bossPokemon.getNameToRender()); const config: EnemyPartyConfig = { pokemonConfigs: [{ @@ -67,10 +68,10 @@ export const FightOrFlightEncounter: MysteryEncounter = isBoss: true, tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - queueEncounterMessage(pokemon.scene, `${namespace}:option.1.stat_boost`); + queueEncounterMessage(`${namespace}:option.1.stat_boost`); // Randomly boost 1 stat 2 stages // Cannot boost Spd, Acc, or Evasion - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ randSeedInt(4, 1) ], 2)); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ randSeedInt(4, 1) ], 2)); } }], }; @@ -79,18 +80,18 @@ export const FightOrFlightEncounter: MysteryEncounter = // Calculate item // Waves 10-40 GREAT, 60-120 ULTRA, 120-160 ROGUE, 160-180 MASTER const tier = - scene.currentBattle.waveIndex > 160 + globalScene.currentBattle.waveIndex > 160 ? ModifierTier.MASTER - : scene.currentBattle.waveIndex > 120 + : globalScene.currentBattle.waveIndex > 120 ? ModifierTier.ROGUE - : scene.currentBattle.waveIndex > 40 + : globalScene.currentBattle.waveIndex > 40 ? ModifierTier.ULTRA : ModifierTier.GREAT; - regenerateModifierPoolThresholds(scene.getPlayerParty(), ModifierPoolType.PLAYER, 0); + regenerateModifierPoolThresholds(globalScene.getPlayerParty(), ModifierPoolType.PLAYER, 0); let item: ModifierTypeOption | null = null; // TMs and Candy Jar excluded from possible rewards as they're too swingy in value for a singular item reward while (!item || item.type.id.includes("TM_") || item.type.id === "CANDY_JAR") { - item = getPlayerModifierTypeOptions(1, scene.getPlayerParty(), [], { guaranteedModifierTiers: [ tier ], allowLuckUpgrades: false })[0]; + item = getPlayerModifierTypeOptions(1, globalScene.getPlayerParty(), [], { guaranteedModifierTiers: [ tier ], allowLuckUpgrades: false })[0]; } encounter.setDialogueToken("itemName", item.type.name); encounter.misc = item; @@ -136,12 +137,12 @@ export const FightOrFlightEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Pick battle // Pokemon will randomly boost 1 stat by 2 stages - const item = scene.currentBattle.mysteryEncounter!.misc as ModifierTypeOption; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: [ item ], fillRemaining: false }); - await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]); + const item = globalScene.currentBattle.mysteryEncounter!.misc as ModifierTypeOption; + setEncounterRewards({ guaranteedModifierTypeOptions: [ item ], fillRemaining: false }); + await initBattleWithEnemyConfig(globalScene.currentBattle.mysteryEncounter!.enemyPartyConfigs[0]); } ) .withOption( @@ -158,16 +159,16 @@ export const FightOrFlightEncounter: MysteryEncounter = } ] }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Pick steal - const encounter = scene.currentBattle.mysteryEncounter!; - const item = scene.currentBattle.mysteryEncounter!.misc as ModifierTypeOption; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: [ item ], fillRemaining: false }); + const encounter = globalScene.currentBattle.mysteryEncounter!; + const item = globalScene.currentBattle.mysteryEncounter!.misc as ModifierTypeOption; + setEncounterRewards({ guaranteedModifierTypeOptions: [ item ], fillRemaining: false }); // Use primaryPokemon to execute the thievery const primaryPokemon = encounter.options[1].primaryPokemon!; - setEncounterExp(scene, primaryPokemon.id, encounter.enemyPartyConfigs[0].pokemonConfigs![0].species.baseExp); - leaveEncounterWithoutBattle(scene); + setEncounterExp(primaryPokemon.id, encounter.enemyPartyConfigs[0].pokemonConfigs![0].species.baseExp); + leaveEncounterWithoutBattle(); }) .build() ) @@ -181,9 +182,9 @@ export const FightOrFlightEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) diff --git a/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts b/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts index 84c3e56a8363..3fd4b16c9e24 100644 --- a/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts +++ b/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts @@ -1,6 +1,6 @@ import { leaveEncounterWithoutBattle, selectPokemonForOption, setEncounterRewards, transitionMysteryEncounterIntroVisuals, updatePlayerMoney, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { TrainerSlot } from "#app/data/trainer-config"; @@ -80,14 +80,14 @@ export const FunAndGamesEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; - scene.loadBgm("mystery_encounter_fun_and_games", "mystery_encounter_fun_and_games.mp3"); + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; + globalScene.loadBgm("mystery_encounter_fun_and_games", "mystery_encounter_fun_and_games.mp3"); encounter.setDialogueToken("wobbuffetName", getPokemonSpecies(Species.WOBBUFFET).getName()); return true; }) - .withOnVisualsStart((scene: BattleScene) => { - scene.fadeAndSwitchBgm("mystery_encounter_fun_and_games"); + .withOnVisualsStart(() => { + globalScene.fadeAndSwitchBgm("mystery_encounter_fun_and_games"); return true; }) .withOption(MysteryEncounterOptionBuilder @@ -102,9 +102,9 @@ export const FunAndGamesEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Select Pokemon for minigame - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { encounter.misc = { playerPokemon: pokemon, @@ -113,28 +113,28 @@ export const FunAndGamesEncounter: MysteryEncounter = // Only Pokemon that are not KOed/legal can be selected const selectableFilter = (pokemon: Pokemon) => { - return isPokemonValidForEncounterOptionSelection(pokemon, scene, `${namespace}:invalid_selection`); + return isPokemonValidForEncounterOptionSelection(pokemon, `${namespace}:invalid_selection`); }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Start minigame - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.misc.turnsRemaining = 3; // Update money const moneyCost = (encounter.options[0].requirements[0] as MoneyRequirement).requiredMoney; - updatePlayerMoney(scene, -moneyCost, true, false); - await showEncounterText(scene, i18next.t("mysteryEncounterMessages:paid_money", { amount: moneyCost })); + updatePlayerMoney(-moneyCost, true, false); + await showEncounterText(i18next.t("mysteryEncounterMessages:paid_money", { amount: moneyCost })); // Handlers for battle events encounter.onTurnStart = handleNextTurn; // triggered during TurnInitPhase encounter.doContinueEncounter = handleLoseMinigame; // triggered during MysteryEncounterRewardsPhase, post VictoryPhase if the player KOs Wobbuffet - hideShowmanIntroSprite(scene); - await summonPlayerPokemon(scene); - await showWobbuffetHealthBar(scene); + hideShowmanIntroSprite(); + await summonPlayerPokemon(); + await showWobbuffetHealthBar(); return true; }) @@ -150,22 +150,22 @@ export const FunAndGamesEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - await transitionMysteryEncounterIntroVisuals(scene, true, true); - leaveEncounterWithoutBattle(scene, true); + await transitionMysteryEncounterIntroVisuals(true, true); + leaveEncounterWithoutBattle(true); return true; } ) .build(); -async function summonPlayerPokemon(scene: BattleScene) { +async function summonPlayerPokemon() { return new Promise(async resolve => { - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const playerPokemon = encounter.misc.playerPokemon; // Swaps the chosen Pokemon and the first player's lead Pokemon in the party - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); const chosenIndex = party.indexOf(playerPokemon); if (chosenIndex !== 0) { const leadPokemon = party[0]; @@ -175,36 +175,36 @@ async function summonPlayerPokemon(scene: BattleScene) { // Do trainer summon animation let playerAnimationPromise: Promise | undefined; - scene.ui.showText(i18next.t("battle:playerGo", { pokemonName: getPokemonNameWithAffix(playerPokemon) })); - scene.pbTray.hide(); - scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); - scene.time.delayedCall(562, () => { - scene.trainer.setFrame("2"); - scene.time.delayedCall(64, () => { - scene.trainer.setFrame("3"); + globalScene.ui.showText(i18next.t("battle:playerGo", { pokemonName: getPokemonNameWithAffix(playerPokemon) })); + globalScene.pbTray.hide(); + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); + globalScene.time.delayedCall(562, () => { + globalScene.trainer.setFrame("2"); + globalScene.time.delayedCall(64, () => { + globalScene.trainer.setFrame("3"); }); }); - scene.tweens.add({ - targets: scene.trainer, + globalScene.tweens.add({ + targets: globalScene.trainer, x: -36, duration: 1000, - onComplete: () => scene.trainer.setVisible(false) + onComplete: () => globalScene.trainer.setVisible(false) }); - scene.time.delayedCall(750, () => { - playerAnimationPromise = summonPlayerPokemonAnimation(scene, playerPokemon); + globalScene.time.delayedCall(750, () => { + playerAnimationPromise = summonPlayerPokemonAnimation(playerPokemon); }); // Also loads Wobbuffet data (cannot be shiny) const enemySpecies = getPokemonSpecies(Species.WOBBUFFET); - scene.currentBattle.enemyParty = []; - const wobbuffet = scene.addEnemyPokemon(enemySpecies, encounter.misc.playerPokemon.level, TrainerSlot.NONE, false, true); + globalScene.currentBattle.enemyParty = []; + const wobbuffet = globalScene.addEnemyPokemon(enemySpecies, encounter.misc.playerPokemon.level, TrainerSlot.NONE, false, true); wobbuffet.ivs = [ 0, 0, 0, 0, 0, 0 ]; wobbuffet.setNature(Nature.MILD); wobbuffet.setAlpha(0); wobbuffet.setVisible(false); wobbuffet.calculateStats(); - scene.currentBattle.enemyParty[0] = wobbuffet; - scene.gameData.setPokemonSeen(wobbuffet, true); + globalScene.currentBattle.enemyParty[0] = wobbuffet; + globalScene.gameData.setPokemonSeen(wobbuffet, true); await wobbuffet.loadAssets(); const id = setInterval(checkPlayerAnimationPromise, 500); async function checkPlayerAnimationPromise() { @@ -217,37 +217,37 @@ async function summonPlayerPokemon(scene: BattleScene) { }); } -function handleLoseMinigame(scene: BattleScene) { +function handleLoseMinigame() { return new Promise(async resolve => { // Check Wobbuffet is still alive - const wobbuffet = scene.getEnemyPokemon(); + const wobbuffet = globalScene.getEnemyPokemon(); if (!wobbuffet || wobbuffet.isFainted(true) || wobbuffet.hp === 0) { // Player loses // End the battle if (wobbuffet) { wobbuffet.hideInfo(); - scene.field.remove(wobbuffet); + globalScene.field.remove(wobbuffet); } - transitionMysteryEncounterIntroVisuals(scene, true, true); - scene.currentBattle.enemyParty = []; - scene.currentBattle.mysteryEncounter!.doContinueEncounter = undefined; - leaveEncounterWithoutBattle(scene, true); - await showEncounterText(scene, `${namespace}:ko`); - const reviveCost = scene.getWaveMoneyAmount(1.5); - updatePlayerMoney(scene, -reviveCost, true, false); + transitionMysteryEncounterIntroVisuals(true, true); + globalScene.currentBattle.enemyParty = []; + globalScene.currentBattle.mysteryEncounter!.doContinueEncounter = undefined; + leaveEncounterWithoutBattle(true); + await showEncounterText(`${namespace}:ko`); + const reviveCost = globalScene.getWaveMoneyAmount(1.5); + updatePlayerMoney(-reviveCost, true, false); } resolve(); }); } -function handleNextTurn(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter!; +function handleNextTurn() { + const encounter = globalScene.currentBattle.mysteryEncounter!; - const wobbuffet = scene.getEnemyPokemon(); + const wobbuffet = globalScene.getEnemyPokemon(); if (!wobbuffet) { // Should never be triggered, just handling the edge case - handleLoseMinigame(scene); + handleLoseMinigame(); return true; } if (encounter.misc.turnsRemaining <= 0) { @@ -257,15 +257,15 @@ function handleNextTurn(scene: BattleScene) { let isHealPhase = false; if (healthRatio < 0.03) { // Grand prize - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.MULTI_LENS ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.MULTI_LENS ], fillRemaining: false }); resultMessageKey = `${namespace}:best_result`; } else if (healthRatio < 0.15) { // 2nd prize - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.SCOPE_LENS ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.SCOPE_LENS ], fillRemaining: false }); resultMessageKey = `${namespace}:great_result`; } else if (healthRatio < 0.33) { // 3rd prize - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.WIDE_LENS ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.WIDE_LENS ], fillRemaining: false }); resultMessageKey = `${namespace}:good_result`; } else { // No prize @@ -275,22 +275,22 @@ function handleNextTurn(scene: BattleScene) { // End the battle wobbuffet.hideInfo(); - scene.field.remove(wobbuffet); - scene.currentBattle.enemyParty = []; - scene.currentBattle.mysteryEncounter!.doContinueEncounter = undefined; - leaveEncounterWithoutBattle(scene, isHealPhase); + globalScene.field.remove(wobbuffet); + globalScene.currentBattle.enemyParty = []; + globalScene.currentBattle.mysteryEncounter!.doContinueEncounter = undefined; + leaveEncounterWithoutBattle(isHealPhase); // Must end the TurnInit phase prematurely so battle phases aren't added to queue - queueEncounterMessage(scene, `${namespace}:end_game`); - queueEncounterMessage(scene, resultMessageKey); + queueEncounterMessage(`${namespace}:end_game`); + queueEncounterMessage(resultMessageKey); // Skip remainder of TurnInitPhase return true; } else { if (encounter.misc.turnsRemaining < 3) { // Display charging messages on turns that aren't the initial turn - queueEncounterMessage(scene, `${namespace}:charging_continue`); + queueEncounterMessage(`${namespace}:charging_continue`); } - queueEncounterMessage(scene, `${namespace}:turn_remaining_${encounter.misc.turnsRemaining}`); + queueEncounterMessage(`${namespace}:turn_remaining_${encounter.misc.turnsRemaining}`); encounter.misc.turnsRemaining--; } @@ -298,33 +298,33 @@ function handleNextTurn(scene: BattleScene) { return false; } -async function showWobbuffetHealthBar(scene: BattleScene) { - const wobbuffet = scene.getEnemyPokemon()!; +async function showWobbuffetHealthBar() { + const wobbuffet = globalScene.getEnemyPokemon()!; - scene.add.existing(wobbuffet); - scene.field.add(wobbuffet); + globalScene.add.existing(wobbuffet); + globalScene.field.add(wobbuffet); - const playerPokemon = scene.getPlayerPokemon() as Pokemon; + const playerPokemon = globalScene.getPlayerPokemon() as Pokemon; if (playerPokemon?.isOnField()) { - scene.field.moveBelow(wobbuffet, playerPokemon); + globalScene.field.moveBelow(wobbuffet, playerPokemon); } // Show health bar and trigger cry wobbuffet.showInfo(); - scene.time.delayedCall(1000, () => { + globalScene.time.delayedCall(1000, () => { wobbuffet.cry(); }); wobbuffet.resetSummonData(); // Track the HP change across turns - scene.currentBattle.mysteryEncounter!.misc.wobbuffetHealth = wobbuffet.hp; + globalScene.currentBattle.mysteryEncounter!.misc.wobbuffetHealth = wobbuffet.hp; } -function summonPlayerPokemonAnimation(scene: BattleScene, pokemon: PlayerPokemon): Promise { +function summonPlayerPokemonAnimation(pokemon: PlayerPokemon): Promise { return new Promise(resolve => { - const pokeball = scene.addFieldSprite(36, 80, "pb", getPokeballAtlasKey(pokemon.pokeball)); + const pokeball = globalScene.addFieldSprite(36, 80, "pb", getPokeballAtlasKey(pokemon.pokeball)); pokeball.setVisible(false); pokeball.setOrigin(0.5, 0.625); - scene.field.add(pokeball); + globalScene.field.add(pokeball); pokemon.setFieldPosition(FieldPosition.CENTER, 0); @@ -332,32 +332,32 @@ function summonPlayerPokemonAnimation(scene: BattleScene, pokemon: PlayerPokemon pokeball.setVisible(true); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, duration: 650, x: 100 + fpOffset[0] }); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, duration: 150, ease: "Cubic.easeOut", y: 70 + fpOffset[1], onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, duration: 500, ease: "Cubic.easeIn", angle: 1440, y: 132 + fpOffset[1], onComplete: () => { - scene.playSound("se/pb_rel"); + globalScene.playSound("se/pb_rel"); pokeball.destroy(); - scene.add.existing(pokemon); - scene.field.add(pokemon); - addPokeballOpenParticles(scene, pokemon.x, pokemon.y - 16, pokemon.pokeball); - scene.updateModifiers(true); - scene.updateFieldScale(); + globalScene.add.existing(pokemon); + globalScene.field.add(pokemon); + addPokeballOpenParticles(pokemon.x, pokemon.y - 16, pokemon.pokeball); + globalScene.updateModifiers(true); + globalScene.updateFieldScale(); pokemon.showInfo(); pokemon.playAnim(); pokemon.setVisible(true); @@ -365,8 +365,8 @@ function summonPlayerPokemonAnimation(scene: BattleScene, pokemon: PlayerPokemon pokemon.setScale(0.5); pokemon.tint(getPokeballTintColor(pokemon.pokeball)); pokemon.untint(250, "Sine.easeIn"); - scene.updateFieldScale(); - scene.tweens.add({ + globalScene.updateFieldScale(); + globalScene.tweens.add({ targets: pokemon, duration: 250, ease: "Sine.easeIn", @@ -375,15 +375,15 @@ function summonPlayerPokemonAnimation(scene: BattleScene, pokemon: PlayerPokemon pokemon.cry(pokemon.getHpRatio() > 0.25 ? undefined : { rate: 0.85 }); pokemon.getSprite().clearTint(); pokemon.resetSummonData(); - scene.time.delayedCall(1000, () => { + globalScene.time.delayedCall(1000, () => { if (pokemon.isShiny()) { - scene.unshiftPhase(new ShinySparklePhase(scene, pokemon.getBattlerIndex())); + globalScene.unshiftPhase(new ShinySparklePhase(pokemon.getBattlerIndex())); } pokemon.resetTurnData(); - scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); - scene.pushPhase(new PostSummonPhase(scene, pokemon.getBattlerIndex())); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); + globalScene.pushPhase(new PostSummonPhase(pokemon.getBattlerIndex())); resolve(); }); } @@ -395,13 +395,13 @@ function summonPlayerPokemonAnimation(scene: BattleScene, pokemon: PlayerPokemon }); } -function hideShowmanIntroSprite(scene: BattleScene) { - const carnivalGame = scene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(0)[0]; - const wobbuffet = scene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(1)[0]; - const showMan = scene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(2)[0]; +function hideShowmanIntroSprite() { + const carnivalGame = globalScene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(0)[0]; + const wobbuffet = globalScene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(1)[0]; + const showMan = globalScene.currentBattle.mysteryEncounter!.introVisuals?.getSpriteAtIndex(2)[0]; // Hide the showman - scene.tweens.add({ + globalScene.tweens.add({ targets: showMan, x: "+=16", y: "-=16", @@ -411,7 +411,7 @@ function hideShowmanIntroSprite(scene: BattleScene) { }); // Slide the Wobbuffet and Game over slightly - scene.tweens.add({ + globalScene.tweens.add({ targets: [ wobbuffet, carnivalGame ], x: "+=16", ease: "Sine.easeInOut", diff --git a/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts b/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts index fa445d75d4fa..612aeced49b4 100644 --- a/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts +++ b/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts @@ -4,7 +4,7 @@ import { ModifierTier } from "#app/modifier/modifier-tier"; import { MusicPreference } from "#app/system/settings/settings"; import { getPlayerModifierTypeOptions, ModifierPoolType, ModifierTypeOption, regenerateModifierPoolThresholds } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { Species } from "#enums/species"; @@ -102,24 +102,24 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Load bgm let bgmKey: string; - if (scene.musicPreference === MusicPreference.CONSISTENT) { + if (globalScene.musicPreference === MusicPreference.CONSISTENT) { bgmKey = "mystery_encounter_gen_5_gts"; - scene.loadBgm(bgmKey, `${bgmKey}.mp3`); + globalScene.loadBgm(bgmKey, `${bgmKey}.mp3`); } else { // Mixed option bgmKey = "mystery_encounter_gen_6_gts"; - scene.loadBgm(bgmKey, `${bgmKey}.mp3`); + globalScene.loadBgm(bgmKey, `${bgmKey}.mp3`); } // Load possible trade options // Maps current party member's id to 3 EnemyPokemon objects // None of the trade options can be the same species - const tradeOptionsMap: Map = getPokemonTradeOptions(scene); + const tradeOptionsMap: Map = getPokemonTradeOptions(); encounter.misc = { tradeOptionsMap, bgmKey @@ -127,8 +127,8 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = return true; }) - .withOnVisualsStart((scene: BattleScene) => { - scene.fadeAndSwitchBgm(scene.currentBattle.mysteryEncounter!.misc.bgmKey); + .withOnVisualsStart(() => { + globalScene.fadeAndSwitchBgm(globalScene.currentBattle.mysteryEncounter!.misc.bgmKey); return true; }) .withOption( @@ -140,8 +140,8 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = buttonTooltip: `${namespace}:option.1.tooltip`, secondOptionPrompt: `${namespace}:option.1.trade_options_prompt`, }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Get the trade species options for the selected pokemon const tradeOptionsMap: Map = encounter.misc.tradeOptionsMap; @@ -165,17 +165,17 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = const formName = tradePokemon.species.forms && tradePokemon.species.forms.length > tradePokemon.formIndex ? tradePokemon.species.forms[tradePokemon.formIndex].formName : null; const line1 = i18next.t("pokemonInfoContainer:ability") + " " + tradePokemon.getAbility().name + (tradePokemon.getGender() !== Gender.GENDERLESS ? " | " + i18next.t("pokemonInfoContainer:gender") + " " + getGenderSymbol(tradePokemon.getGender()) : ""); const line2 = i18next.t("pokemonInfoContainer:nature") + " " + getNatureName(tradePokemon.getNature()) + (formName ? " | " + i18next.t("pokemonInfoContainer:form") + " " + formName : ""); - showEncounterText(scene, `${line1}\n${line2}`, 0, 0, false); + showEncounterText(`${line1}\n${line2}`, 0, 0, false); }, }; return option; }); }; - return selectPokemonForOption(scene, onPokemonSelected); + return selectPokemonForOption(onPokemonSelected); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const tradedPokemon: PlayerPokemon = encounter.misc.tradedPokemon; const receivedPokemonData: EnemyPokemon = encounter.misc.receivedPokemon; const modifiers = tradedPokemon.getHeldItems().filter(m => !(m instanceof PokemonFormChangeItemModifier) && !(m instanceof SpeciesStatBoosterModifier)); @@ -185,32 +185,32 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = encounter.setDialogueToken("tradeTrainerName", traderName.trim()); // Remove the original party member from party - scene.removePokemonFromPlayerParty(tradedPokemon, false); + globalScene.removePokemonFromPlayerParty(tradedPokemon, false); // Set data properly, then generate the new Pokemon's assets receivedPokemonData.passive = tradedPokemon.passive; // Pokeball to Ultra ball, randomly receivedPokemonData.pokeball = randInt(4) as PokeballType; const dataSource = new PokemonData(receivedPokemonData); - const newPlayerPokemon = scene.addPlayerPokemon(receivedPokemonData.species, receivedPokemonData.level, dataSource.abilityIndex, dataSource.formIndex, dataSource.gender, dataSource.shiny, dataSource.variant, dataSource.ivs, dataSource.nature, dataSource); - scene.getPlayerParty().push(newPlayerPokemon); + const newPlayerPokemon = globalScene.addPlayerPokemon(receivedPokemonData.species, receivedPokemonData.level, dataSource.abilityIndex, dataSource.formIndex, dataSource.gender, dataSource.shiny, dataSource.variant, dataSource.ivs, dataSource.nature, dataSource); + globalScene.getPlayerParty().push(newPlayerPokemon); await newPlayerPokemon.loadAssets(); for (const mod of modifiers) { mod.pokemonId = newPlayerPokemon.id; - scene.addModifier(mod, true, false, false, true); + globalScene.addModifier(mod, true, false, false, true); } // Show the trade animation - await showTradeBackground(scene); - await doPokemonTradeSequence(scene, tradedPokemon, newPlayerPokemon); - await showEncounterText(scene, `${namespace}:trade_received`, null, 0, true, 4000); - scene.playBgm(encounter.misc.bgmKey); - await addPokemonDataToDexAndValidateAchievements(scene, newPlayerPokemon); - await hideTradeBackground(scene); + await showTradeBackground(); + await doPokemonTradeSequence(tradedPokemon, newPlayerPokemon); + await showEncounterText(`${namespace}:trade_received`, null, 0, true, 4000); + globalScene.playBgm(encounter.misc.bgmKey); + await addPokemonDataToDexAndValidateAchievements(newPlayerPokemon); + await hideTradeBackground(); tradedPokemon.destroy(); - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -222,19 +222,19 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = buttonLabel: `${namespace}:option.2.label`, buttonTooltip: `${namespace}:option.2.tooltip`, }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Randomly generate a Wonder Trade pokemon - const randomTradeOption = generateTradeOption(scene.getPlayerParty().map(p => p.species)); - const tradePokemon = new EnemyPokemon(scene, randomTradeOption, pokemon.level, TrainerSlot.NONE, false); + const randomTradeOption = generateTradeOption(globalScene.getPlayerParty().map(p => p.species)); + const tradePokemon = new EnemyPokemon(randomTradeOption, pokemon.level, TrainerSlot.NONE, false); // Extra shiny roll at 1/128 odds (boosted by events and charms) if (!tradePokemon.shiny) { const shinyThreshold = new NumberHolder(WONDER_TRADE_SHINY_CHANCE); - if (scene.eventManager.isEventActive()) { - shinyThreshold.value *= scene.eventManager.getShinyMultiplier(); + if (globalScene.eventManager.isEventActive()) { + shinyThreshold.value *= globalScene.eventManager.getShinyMultiplier(); } - scene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); + globalScene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); // Base shiny chance of 512/65536 -> 1/128, affected by events and Shiny Charms // Maximum shiny chance of 4096/65536 -> 1/16, cannot improve further after that @@ -248,7 +248,7 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = if (tradePokemon.species.abilityHidden) { if (tradePokemon.abilityIndex < hiddenIndex) { const hiddenAbilityChance = new NumberHolder(64); - scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); + globalScene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); const hasHiddenAbility = !randSeedInt(hiddenAbilityChance.value); @@ -281,10 +281,10 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = encounter.misc.receivedPokemon = tradePokemon; }; - return selectPokemonForOption(scene, onPokemonSelected); + return selectPokemonForOption(onPokemonSelected); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const tradedPokemon: PlayerPokemon = encounter.misc.tradedPokemon; const receivedPokemonData: EnemyPokemon = encounter.misc.receivedPokemon; const modifiers = tradedPokemon.getHeldItems().filter(m => !(m instanceof PokemonFormChangeItemModifier) && !(m instanceof SpeciesStatBoosterModifier)); @@ -294,31 +294,31 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = encounter.setDialogueToken("tradeTrainerName", traderName.trim()); // Remove the original party member from party - scene.removePokemonFromPlayerParty(tradedPokemon, false); + globalScene.removePokemonFromPlayerParty(tradedPokemon, false); // Set data properly, then generate the new Pokemon's assets receivedPokemonData.passive = tradedPokemon.passive; receivedPokemonData.pokeball = randInt(4) as PokeballType; const dataSource = new PokemonData(receivedPokemonData); - const newPlayerPokemon = scene.addPlayerPokemon(receivedPokemonData.species, receivedPokemonData.level, dataSource.abilityIndex, dataSource.formIndex, dataSource.gender, dataSource.shiny, dataSource.variant, dataSource.ivs, dataSource.nature, dataSource); - scene.getPlayerParty().push(newPlayerPokemon); + const newPlayerPokemon = globalScene.addPlayerPokemon(receivedPokemonData.species, receivedPokemonData.level, dataSource.abilityIndex, dataSource.formIndex, dataSource.gender, dataSource.shiny, dataSource.variant, dataSource.ivs, dataSource.nature, dataSource); + globalScene.getPlayerParty().push(newPlayerPokemon); await newPlayerPokemon.loadAssets(); for (const mod of modifiers) { mod.pokemonId = newPlayerPokemon.id; - scene.addModifier(mod, true, false, false, true); + globalScene.addModifier(mod, true, false, false, true); } // Show the trade animation - await showTradeBackground(scene); - await doPokemonTradeSequence(scene, tradedPokemon, newPlayerPokemon); - await showEncounterText(scene, `${namespace}:trade_received`, null, 0, true, 4000); - scene.playBgm(encounter.misc.bgmKey); - await addPokemonDataToDexAndValidateAchievements(scene, newPlayerPokemon); - await hideTradeBackground(scene); + await showTradeBackground(); + await doPokemonTradeSequence(tradedPokemon, newPlayerPokemon); + await showEncounterText(`${namespace}:trade_received`, null, 0, true, 4000); + globalScene.playBgm(encounter.misc.bgmKey); + await addPokemonDataToDexAndValidateAchievements(newPlayerPokemon); + await hideTradeBackground(); tradedPokemon.destroy(); - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -330,8 +330,8 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = buttonTooltip: `${namespace}:option.3.tooltip`, secondOptionPrompt: `${namespace}:option.3.trade_options_prompt`, }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Get Pokemon held items and filter for valid ones const validItems = pokemon.getHeldItems().filter((it) => { @@ -359,18 +359,18 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = return it.isTransferable; }).length > 0; if (!meetsReqs) { - return getEncounterText(scene, `${namespace}:option.3.invalid_selection`) ?? null; + return getEncounterText(`${namespace}:option.3.invalid_selection`) ?? null; } return null; }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const modifier = encounter.misc.chosenModifier as PokemonHeldItemModifier; - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); const chosenPokemon: PlayerPokemon = encounter.misc.chosenPokemon; // Check tier of the traded item, the received item will be one tier up @@ -397,16 +397,16 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = } encounter.setDialogueToken("itemName", item.type.name); - setEncounterRewards(scene, { guaranteedModifierTypeOptions: [ item ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeOptions: [ item ], fillRemaining: false }); chosenPokemon.loseHeldItem(modifier, false); - await scene.updateModifiers(true, true); + await globalScene.updateModifiers(true, true); // Generate a trainer name const traderName = generateRandomTraderName(); encounter.setDialogueToken("tradeTrainerName", traderName.trim()); - await showEncounterText(scene, `${namespace}:item_trade_selected`); - leaveEncounterWithoutBattle(scene); + await showEncounterText(`${namespace}:item_trade_selected`); + leaveEncounterWithoutBattle(); }) .build() ) @@ -420,26 +420,26 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) .build(); -function getPokemonTradeOptions(scene: BattleScene): Map { +function getPokemonTradeOptions(): Map { const tradeOptionsMap: Map = new Map(); // Starts by filtering out any current party members as valid resulting species - const alreadyUsedSpecies: PokemonSpecies[] = scene.getPlayerParty().map(p => p.species); + const alreadyUsedSpecies: PokemonSpecies[] = globalScene.getPlayerParty().map(p => p.species); - scene.getPlayerParty().forEach(pokemon => { + globalScene.getPlayerParty().forEach(pokemon => { // If the party member is legendary/mythical, the only trade options available are always pulled from generation-specific legendary trade pools if (pokemon.species.legendary || pokemon.species.subLegendary || pokemon.species.mythical) { const generation = pokemon.species.generation; const tradeOptions: EnemyPokemon[] = LEGENDARY_TRADE_POOLS[generation].map(s => { const pokemonSpecies = getPokemonSpecies(s); - return new EnemyPokemon(scene, pokemonSpecies, 5, TrainerSlot.NONE, false); + return new EnemyPokemon(pokemonSpecies, 5, TrainerSlot.NONE, false); }); tradeOptionsMap.set(pokemon.id, tradeOptions); } else { @@ -454,7 +454,7 @@ function getPokemonTradeOptions(scene: BattleScene): Map // Add trade options to map tradeOptionsMap.set(pokemon.id, tradeOptions.map(s => { - return new EnemyPokemon(scene, s, pokemon.level, TrainerSlot.NONE, false); + return new EnemyPokemon(s, pokemon.level, TrainerSlot.NONE, false); })); } }); @@ -497,28 +497,28 @@ function generateTradeOption(alreadyUsedSpecies: PokemonSpecies[], originalBst?: return newSpecies!; } -function showTradeBackground(scene: BattleScene) { +function showTradeBackground() { return new Promise(resolve => { - const tradeContainer = scene.add.container(0, -scene.game.canvas.height / 6); + const tradeContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); tradeContainer.setName("Trade Background"); - const flyByStaticBg = scene.add.rectangle(0, 0, scene.game.canvas.width / 6, scene.game.canvas.height / 6, 0); + const flyByStaticBg = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0); flyByStaticBg.setName("Black Background"); flyByStaticBg.setOrigin(0, 0); flyByStaticBg.setVisible(false); tradeContainer.add(flyByStaticBg); - const tradeBaseBg = scene.add.image(0, 0, "default_bg"); + const tradeBaseBg = globalScene.add.image(0, 0, "default_bg"); tradeBaseBg.setName("Trade Background Image"); tradeBaseBg.setOrigin(0, 0); tradeContainer.add(tradeBaseBg); - scene.fieldUI.add(tradeContainer); - scene.fieldUI.bringToTop(tradeContainer); + globalScene.fieldUI.add(tradeContainer); + globalScene.fieldUI.bringToTop(tradeContainer); tradeContainer.setVisible(true); tradeContainer.alpha = 0; - scene.tweens.add({ + globalScene.tweens.add({ targets: tradeContainer, alpha: 1, duration: 500, @@ -530,17 +530,17 @@ function showTradeBackground(scene: BattleScene) { }); } -function hideTradeBackground(scene: BattleScene) { +function hideTradeBackground() { return new Promise(resolve => { - const transformationContainer = scene.fieldUI.getByName("Trade Background"); + const transformationContainer = globalScene.fieldUI.getByName("Trade Background"); - scene.tweens.add({ + globalScene.tweens.add({ targets: transformationContainer, alpha: 0, duration: 1000, ease: "Sine.easeInOut", onComplete: () => { - scene.fieldUI.remove(transformationContainer, true); + globalScene.fieldUI.remove(transformationContainer, true); resolve(); } }); @@ -549,13 +549,12 @@ function hideTradeBackground(scene: BattleScene) { /** * Initiates an "evolution-like" animation to transform a previousPokemon (presumably from the player's party) into a new one, not necessarily an evolution species. - * @param scene * @param tradedPokemon * @param receivedPokemon */ -function doPokemonTradeSequence(scene: BattleScene, tradedPokemon: PlayerPokemon, receivedPokemon: PlayerPokemon) { +function doPokemonTradeSequence(tradedPokemon: PlayerPokemon, receivedPokemon: PlayerPokemon) { return new Promise(resolve => { - const tradeContainer = scene.fieldUI.getByName("Trade Background") as Phaser.GameObjects.Container; + const tradeContainer = globalScene.fieldUI.getByName("Trade Background") as Phaser.GameObjects.Container; const tradeBaseBg = tradeContainer.getByName("Trade Background Image") as Phaser.GameObjects.Image; let tradedPokemonSprite: Phaser.GameObjects.Sprite; @@ -564,8 +563,8 @@ function doPokemonTradeSequence(scene: BattleScene, tradedPokemon: PlayerPokemon let receivedPokemonTintSprite: Phaser.GameObjects.Sprite; const getPokemonSprite = () => { - const ret = scene.addPokemonSprite(tradedPokemon, tradeBaseBg.displayWidth / 2, tradeBaseBg.displayHeight / 2, "pkmn__sub"); - ret.setPipeline(scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + const ret = globalScene.addPokemonSprite(tradedPokemon, tradeBaseBg.displayWidth / 2, tradeBaseBg.displayHeight / 2, "pkmn__sub"); + ret.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); return ret; }; @@ -589,7 +588,7 @@ function doPokemonTradeSequence(scene: BattleScene, tradedPokemon: PlayerPokemon console.error(`Failed to play animation for ${spriteKey}`, err); } - sprite.setPipeline(scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(tradedPokemon.getTeraType()) }); + sprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(tradedPokemon.getTeraType()) }); sprite.setPipelineData("ignoreTimeTint", true); sprite.setPipelineData("spriteKey", tradedPokemon.getSpriteKey()); sprite.setPipelineData("shiny", tradedPokemon.shiny); @@ -610,7 +609,7 @@ function doPokemonTradeSequence(scene: BattleScene, tradedPokemon: PlayerPokemon console.error(`Failed to play animation for ${spriteKey}`, err); } - sprite.setPipeline(scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(tradedPokemon.getTeraType()) }); + sprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(tradedPokemon.getTeraType()) }); sprite.setPipelineData("ignoreTimeTint", true); sprite.setPipelineData("spriteKey", receivedPokemon.getSpriteKey()); sprite.setPipelineData("shiny", receivedPokemon.shiny); @@ -625,45 +624,45 @@ function doPokemonTradeSequence(scene: BattleScene, tradedPokemon: PlayerPokemon // Traded pokemon pokeball const tradedPbAtlasKey = getPokeballAtlasKey(tradedPokemon.pokeball); - const tradedPokeball: Phaser.GameObjects.Sprite = scene.add.sprite(tradeBaseBg.displayWidth / 2, tradeBaseBg.displayHeight / 2, "pb", tradedPbAtlasKey); + const tradedPokeball: Phaser.GameObjects.Sprite = globalScene.add.sprite(tradeBaseBg.displayWidth / 2, tradeBaseBg.displayHeight / 2, "pb", tradedPbAtlasKey); tradedPokeball.setVisible(false); tradeContainer.add(tradedPokeball); // Received pokemon pokeball const receivedPbAtlasKey = getPokeballAtlasKey(receivedPokemon.pokeball); - const receivedPokeball: Phaser.GameObjects.Sprite = scene.add.sprite(tradeBaseBg.displayWidth / 2, tradeBaseBg.displayHeight / 2, "pb", receivedPbAtlasKey); + const receivedPokeball: Phaser.GameObjects.Sprite = globalScene.add.sprite(tradeBaseBg.displayWidth / 2, tradeBaseBg.displayHeight / 2, "pb", receivedPbAtlasKey); receivedPokeball.setVisible(false); tradeContainer.add(receivedPokeball); - scene.tweens.add({ + globalScene.tweens.add({ targets: tradedPokemonSprite, alpha: 1, ease: "Cubic.easeInOut", duration: 500, onComplete: async () => { - scene.fadeOutBgm(1000, false); - await showEncounterText(scene, `${namespace}:pokemon_trade_selected`); + globalScene.fadeOutBgm(1000, false); + await showEncounterText(`${namespace}:pokemon_trade_selected`); tradedPokemon.cry(); - scene.playBgm("evolution"); - await showEncounterText(scene, `${namespace}:pokemon_trade_goodbye`); + globalScene.playBgm("evolution"); + await showEncounterText(`${namespace}:pokemon_trade_goodbye`); tradedPokeball.setAlpha(0); tradedPokeball.setVisible(true); - scene.tweens.add({ + globalScene.tweens.add({ targets: tradedPokeball, alpha: 1, ease: "Cubic.easeInOut", duration: 250, onComplete: () => { tradedPokeball.setTexture("pb", `${tradedPbAtlasKey}_opening`); - scene.time.delayedCall(17, () => tradedPokeball.setTexture("pb", `${tradedPbAtlasKey}_open`)); - scene.playSound("se/pb_rel"); + globalScene.time.delayedCall(17, () => tradedPokeball.setTexture("pb", `${tradedPbAtlasKey}_open`)); + globalScene.playSound("se/pb_rel"); tradedPokemonTintSprite.setVisible(true); // TODO: need to add particles to fieldUI instead of field - // addPokeballOpenParticles(scene, tradedPokemon.x, tradedPokemon.y, tradedPokemon.pokeball); + // addPokeballOpenParticles(tradedPokemon.x, tradedPokemon.y, tradedPokemon.pokeball); - scene.tweens.add({ + globalScene.tweens.add({ targets: [ tradedPokemonTintSprite, tradedPokemonSprite ], duration: 500, ease: "Sine.easeIn", @@ -672,30 +671,30 @@ function doPokemonTradeSequence(scene: BattleScene, tradedPokemon: PlayerPokemon tradedPokemonSprite.setVisible(false); tradedPokeball.setTexture("pb", `${tradedPbAtlasKey}_opening`); tradedPokemonTintSprite.setVisible(false); - scene.playSound("se/pb_catch"); - scene.time.delayedCall(17, () => tradedPokeball.setTexture("pb", `${tradedPbAtlasKey}`)); + globalScene.playSound("se/pb_catch"); + globalScene.time.delayedCall(17, () => tradedPokeball.setTexture("pb", `${tradedPbAtlasKey}`)); - scene.tweens.add({ + globalScene.tweens.add({ targets: tradedPokeball, y: "+=10", duration: 200, delay: 250, ease: "Cubic.easeIn", onComplete: () => { - scene.playSound("se/pb_bounce_1"); + globalScene.playSound("se/pb_bounce_1"); - scene.tweens.add({ + globalScene.tweens.add({ targets: tradedPokeball, y: "-=100", duration: 200, delay: 1000, ease: "Cubic.easeInOut", onStart: () => { - scene.playSound("se/pb_throw"); + globalScene.playSound("se/pb_throw"); }, onComplete: async () => { - await doPokemonTradeFlyBySequence(scene, tradedPokemonSprite, receivedPokemonSprite); - await doTradeReceivedSequence(scene, receivedPokemon, receivedPokemonSprite, receivedPokemonTintSprite, receivedPokeball, receivedPbAtlasKey); + await doPokemonTradeFlyBySequence(tradedPokemonSprite, receivedPokemonSprite); + await doTradeReceivedSequence(receivedPokemon, receivedPokemonSprite, receivedPokemonTintSprite, receivedPokeball, receivedPbAtlasKey); resolve(); } }); @@ -710,9 +709,9 @@ function doPokemonTradeSequence(scene: BattleScene, tradedPokemon: PlayerPokemon }); } -function doPokemonTradeFlyBySequence(scene: BattleScene, tradedPokemonSprite: Phaser.GameObjects.Sprite, receivedPokemonSprite: Phaser.GameObjects.Sprite) { +function doPokemonTradeFlyBySequence(tradedPokemonSprite: Phaser.GameObjects.Sprite, receivedPokemonSprite: Phaser.GameObjects.Sprite) { return new Promise(resolve => { - const tradeContainer = scene.fieldUI.getByName("Trade Background") as Phaser.GameObjects.Container; + const tradeContainer = globalScene.fieldUI.getByName("Trade Background") as Phaser.GameObjects.Container; const tradeBaseBg = tradeContainer.getByName("Trade Background Image") as Phaser.GameObjects.Image; const flyByStaticBg = tradeContainer.getByName("Black Background") as Phaser.GameObjects.Rectangle; flyByStaticBg.setVisible(true); @@ -733,47 +732,47 @@ function doPokemonTradeFlyBySequence(scene: BattleScene, tradedPokemonSprite: Ph const BASE_ANIM_DURATION = 1000; // Fade out trade background - scene.tweens.add({ + globalScene.tweens.add({ targets: tradeBaseBg, alpha: 0, ease: "Cubic.easeInOut", duration: FADE_DELAY, onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: [ receivedPokemonSprite, tradedPokemonSprite ], y: tradeBaseBg.displayWidth / 2 - 100, ease: "Cubic.easeInOut", duration: BASE_ANIM_DURATION * 3, onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: receivedPokemonSprite, x: tradeBaseBg.displayWidth / 4, ease: "Cubic.easeInOut", duration: BASE_ANIM_DURATION / 2, delay: ANIM_DELAY }); - scene.tweens.add({ + globalScene.tweens.add({ targets: tradedPokemonSprite, x: tradeBaseBg.displayWidth * 3 / 4, ease: "Cubic.easeInOut", duration: BASE_ANIM_DURATION / 2, delay: ANIM_DELAY, onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: receivedPokemonSprite, y: "+=200", ease: "Cubic.easeInOut", duration: BASE_ANIM_DURATION * 2, delay: ANIM_DELAY, }); - scene.tweens.add({ + globalScene.tweens.add({ targets: tradedPokemonSprite, y: "-=200", ease: "Cubic.easeInOut", duration: BASE_ANIM_DURATION * 2, delay: ANIM_DELAY, onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: tradeBaseBg, alpha: 1, ease: "Cubic.easeInOut", @@ -793,9 +792,9 @@ function doPokemonTradeFlyBySequence(scene: BattleScene, tradedPokemonSprite: Ph }); } -function doTradeReceivedSequence(scene: BattleScene, receivedPokemon: PlayerPokemon, receivedPokemonSprite: Phaser.GameObjects.Sprite, receivedPokemonTintSprite: Phaser.GameObjects.Sprite, receivedPokeballSprite: Phaser.GameObjects.Sprite, receivedPbAtlasKey: string) { +function doTradeReceivedSequence(receivedPokemon: PlayerPokemon, receivedPokemonSprite: Phaser.GameObjects.Sprite, receivedPokemonTintSprite: Phaser.GameObjects.Sprite, receivedPokeballSprite: Phaser.GameObjects.Sprite, receivedPbAtlasKey: string) { return new Promise(resolve => { - const tradeContainer = scene.fieldUI.getByName("Trade Background") as Phaser.GameObjects.Container; + const tradeContainer = globalScene.fieldUI.getByName("Trade Background") as Phaser.GameObjects.Container; const tradeBaseBg = tradeContainer.getByName("Trade Background Image") as Phaser.GameObjects.Image; receivedPokemonSprite.setVisible(false); @@ -812,7 +811,7 @@ function doTradeReceivedSequence(scene: BattleScene, receivedPokemon: PlayerPoke // Received pokemon sparkles let pokemonShinySparkle: Phaser.GameObjects.Sprite; if (receivedPokemon.shiny) { - pokemonShinySparkle = scene.add.sprite(receivedPokemonSprite.x, receivedPokemonSprite.y, "shiny"); + pokemonShinySparkle = globalScene.add.sprite(receivedPokemonSprite.x, receivedPokemonSprite.y, "shiny"); pokemonShinySparkle.setVisible(false); tradeContainer.add(pokemonShinySparkle); } @@ -820,19 +819,19 @@ function doTradeReceivedSequence(scene: BattleScene, receivedPokemon: PlayerPoke const BASE_ANIM_DURATION = 1000; // Pokeball falls to the screen - scene.playSound("se/pb_throw"); - scene.tweens.add({ + globalScene.playSound("se/pb_throw"); + globalScene.tweens.add({ targets: receivedPokeballSprite, y: "+=100", ease: "Cubic.easeInOut", duration: BASE_ANIM_DURATION, onComplete: () => { - scene.playSound("se/pb_bounce_1"); - scene.time.delayedCall(100, () => scene.playSound("se/pb_bounce_1")); + globalScene.playSound("se/pb_bounce_1"); + globalScene.time.delayedCall(100, () => globalScene.playSound("se/pb_bounce_1")); - scene.time.delayedCall(2000, () => { - scene.playSound("se/pb_rel"); - scene.fadeOutBgm(500, false); + globalScene.time.delayedCall(2000, () => { + globalScene.playSound("se/pb_rel"); + globalScene.fadeOutBgm(500, false); receivedPokemon.cry(); receivedPokemonTintSprite.scale = 0.25; receivedPokemonTintSprite.alpha = 1; @@ -841,14 +840,14 @@ function doTradeReceivedSequence(scene: BattleScene, receivedPokemon: PlayerPoke receivedPokemonTintSprite.alpha = 1; receivedPokemonTintSprite.setVisible(true); receivedPokeballSprite.setTexture("pb", `${receivedPbAtlasKey}_opening`); - scene.time.delayedCall(17, () => receivedPokeballSprite.setTexture("pb", `${receivedPbAtlasKey}_open`)); - scene.tweens.add({ + globalScene.time.delayedCall(17, () => receivedPokeballSprite.setTexture("pb", `${receivedPbAtlasKey}_open`)); + globalScene.tweens.add({ targets: receivedPokemonSprite, duration: 250, ease: "Sine.easeOut", scale: 1 }); - scene.tweens.add({ + globalScene.tweens.add({ targets: receivedPokemonTintSprite, duration: 250, ease: "Sine.easeOut", @@ -856,12 +855,12 @@ function doTradeReceivedSequence(scene: BattleScene, receivedPokemon: PlayerPoke alpha: 0, onComplete: () => { if (receivedPokemon.shiny) { - scene.time.delayedCall(500, () => { - doShinySparkleAnim(scene, pokemonShinySparkle, receivedPokemon.variant); + globalScene.time.delayedCall(500, () => { + doShinySparkleAnim(pokemonShinySparkle, receivedPokemon.variant); }); } receivedPokeballSprite.destroy(); - scene.time.delayedCall(2000, () => resolve()); + globalScene.time.delayedCall(2000, () => resolve()); } }); }); diff --git a/src/data/mystery-encounters/encounters/lost-at-sea-encounter.ts b/src/data/mystery-encounters/encounters/lost-at-sea-encounter.ts index a8cb076bbe90..ea757377dc53 100644 --- a/src/data/mystery-encounters/encounters/lost-at-sea-encounter.ts +++ b/src/data/mystery-encounters/encounters/lost-at-sea-encounter.ts @@ -2,7 +2,7 @@ import { getPokemonSpecies } from "#app/data/pokemon-species"; import { Moves } from "#app/enums/moves"; import { Species } from "#app/enums/species"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { leaveEncounterWithoutBattle, setEncounterExp } from "../utils/encounter-phase-utils"; @@ -41,8 +41,8 @@ export const LostAtSeaEncounter: MysteryEncounter = MysteryEncounterBuilder.with }, ]) .withIntroDialogue([{ text: `${namespace}:intro` }]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.setDialogueToken("damagePercentage", String(DAMAGE_PERCENTAGE)); encounter.setDialogueToken("option1RequiredMove", new PokemonMove(OPTION_1_REQUIRED_MOVE).getName()); @@ -70,7 +70,7 @@ export const LostAtSeaEncounter: MysteryEncounter = MysteryEncounterBuilder.with }, ], }) - .withOptionPhase(async (scene: BattleScene) => handlePokemonGuidingYouPhase(scene)) + .withOptionPhase(async () => handlePokemonGuidingYouPhase()) .build() ) .withOption( @@ -89,7 +89,7 @@ export const LostAtSeaEncounter: MysteryEncounter = MysteryEncounterBuilder.with }, ], }) - .withOptionPhase(async (scene: BattleScene) => handlePokemonGuidingYouPhase(scene)) + .withOptionPhase(async () => handlePokemonGuidingYouPhase()) .build() ) .withSimpleOption( @@ -103,16 +103,16 @@ export const LostAtSeaEncounter: MysteryEncounter = MysteryEncounterBuilder.with }, ], }, - async (scene: BattleScene) => { - const allowedPokemon = scene.getPlayerParty().filter((p) => p.isAllowedInBattle()); + async () => { + const allowedPokemon = globalScene.getPlayerParty().filter((p) => p.isAllowedInBattle()); for (const pkm of allowedPokemon) { const percentage = DAMAGE_PERCENTAGE / 100; const damage = Math.floor(pkm.getMaxHp() * percentage); - applyDamageToPokemon(scene, pkm, damage); + applyDamageToPokemon(pkm, damage); } - leaveEncounterWithoutBattle(scene); + leaveEncounterWithoutBattle(); return true; } @@ -126,19 +126,17 @@ export const LostAtSeaEncounter: MysteryEncounter = MysteryEncounterBuilder.with /** * Generic handler for using a guiding pokemon to guide you back. - * - * @param scene Battle scene */ -function handlePokemonGuidingYouPhase(scene: BattleScene) { +function handlePokemonGuidingYouPhase() { const laprasSpecies = getPokemonSpecies(Species.LAPRAS); - const { mysteryEncounter } = scene.currentBattle; + const { mysteryEncounter } = globalScene.currentBattle; if (mysteryEncounter?.selectedOption?.primaryPokemon?.id) { - setEncounterExp(scene, mysteryEncounter.selectedOption.primaryPokemon.id, laprasSpecies.baseExp, true); + setEncounterExp(mysteryEncounter.selectedOption.primaryPokemon.id, laprasSpecies.baseExp, true); } else { console.warn("Lost at sea: No guide pokemon found but pokemon guides player. huh!?"); } - leaveEncounterWithoutBattle(scene); + leaveEncounterWithoutBattle(); return true; } diff --git a/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts b/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts index 7fdd29d36a23..3af8475eb173 100644 --- a/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts +++ b/src/data/mystery-encounters/encounters/mysterious-challengers-encounter.ts @@ -13,7 +13,7 @@ import { ModifierTier } from "#app/modifier/modifier-tier"; import { modifierTypes } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { PartyMemberStrength } from "#enums/party-member-strength"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "#app/utils"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -37,12 +37,12 @@ export const MysteriousChallengersEncounter: MysteryEncounter = text: `${namespace}:intro`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculates what trainers are available for battle in the encounter // Normal difficulty trainer is randomly pulled from biome - const normalTrainerType = scene.arena.randomTrainerType(scene.currentBattle.waveIndex); + const normalTrainerType = globalScene.arena.randomTrainerType(globalScene.currentBattle.waveIndex); const normalConfig = trainerConfigs[normalTrainerType].clone(); let female = false; if (normalConfig.hasGenders) { @@ -57,16 +57,16 @@ export const MysteriousChallengersEncounter: MysteryEncounter = // Hard difficulty trainer is another random trainer, but with AVERAGE_BALANCED config // Number of mons is based off wave: 1-20 is 2, 20-40 is 3, etc. capping at 6 after wave 100 let retries = 0; - let hardTrainerType = scene.arena.randomTrainerType(scene.currentBattle.waveIndex); + let hardTrainerType = globalScene.arena.randomTrainerType(globalScene.currentBattle.waveIndex); while (retries < 5 && hardTrainerType === normalTrainerType) { // Will try to use a different trainer from the normal trainer type - hardTrainerType = scene.arena.randomTrainerType(scene.currentBattle.waveIndex); + hardTrainerType = globalScene.arena.randomTrainerType(globalScene.currentBattle.waveIndex); retries++; } const hardTemplate = new TrainerPartyCompoundTemplate( new TrainerPartyTemplate(1, PartyMemberStrength.STRONGER, false, true), new TrainerPartyTemplate( - Math.min(Math.ceil(scene.currentBattle.waveIndex / 20), 5), + Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 20), 5), PartyMemberStrength.AVERAGE, false, true @@ -87,8 +87,8 @@ export const MysteriousChallengersEncounter: MysteryEncounter = // Brutal trainer is pulled from pool of boss trainers (gym leaders) for the biome // They are given an E4 template team, so will be stronger than usual boss encounter and always have 6 mons - const brutalTrainerType = scene.arena.randomTrainerType( - scene.currentBattle.waveIndex, + const brutalTrainerType = globalScene.arena.randomTrainerType( + globalScene.currentBattle.waveIndex, true ); const e4Template = trainerPartyTemplates.ELITE_FOUR; @@ -145,18 +145,18 @@ export const MysteriousChallengersEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Spawn standard trainer battle with memory mushroom reward const config: EnemyPartyConfig = encounter.enemyPartyConfigs[0]; - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.TM_COMMON, modifierTypes.TM_GREAT, modifierTypes.MEMORY_MUSHROOM ], fillRemaining: true }); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.TM_COMMON, modifierTypes.TM_GREAT, modifierTypes.MEMORY_MUSHROOM ], fillRemaining: true }); // Seed offsets to remove possibility of different trainers having exact same teams let initBattlePromise: Promise; - scene.executeWithSeedOffset(() => { - initBattlePromise = initBattleWithEnemyConfig(scene, config); - }, scene.currentBattle.waveIndex * 10); + globalScene.executeWithSeedOffset(() => { + initBattlePromise = initBattleWithEnemyConfig(config); + }, globalScene.currentBattle.waveIndex * 10); await initBattlePromise!; } ) @@ -170,18 +170,18 @@ export const MysteriousChallengersEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Spawn hard fight const config: EnemyPartyConfig = encounter.enemyPartyConfigs[1]; - setEncounterRewards(scene, { guaranteedModifierTiers: [ ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.GREAT, ModifierTier.GREAT ], fillRemaining: true }); + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.GREAT, ModifierTier.GREAT ], fillRemaining: true }); // Seed offsets to remove possibility of different trainers having exact same teams let initBattlePromise: Promise; - scene.executeWithSeedOffset(() => { - initBattlePromise = initBattleWithEnemyConfig(scene, config); - }, scene.currentBattle.waveIndex * 100); + globalScene.executeWithSeedOffset(() => { + initBattlePromise = initBattleWithEnemyConfig(config); + }, globalScene.currentBattle.waveIndex * 100); await initBattlePromise!; } ) @@ -195,21 +195,21 @@ export const MysteriousChallengersEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Spawn brutal fight const config: EnemyPartyConfig = encounter.enemyPartyConfigs[2]; // To avoid player level snowballing from picking this option encounter.expMultiplier = 0.9; - setEncounterRewards(scene, { guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.GREAT ], fillRemaining: true }); + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.GREAT ], fillRemaining: true }); // Seed offsets to remove possibility of different trainers having exact same teams let initBattlePromise: Promise; - scene.executeWithSeedOffset(() => { - initBattlePromise = initBattleWithEnemyConfig(scene, config); - }, scene.currentBattle.waveIndex * 1000); + globalScene.executeWithSeedOffset(() => { + initBattlePromise = initBattleWithEnemyConfig(config); + }, globalScene.currentBattle.waveIndex * 1000); await initBattlePromise!; } ) diff --git a/src/data/mystery-encounters/encounters/mysterious-chest-encounter.ts b/src/data/mystery-encounters/encounters/mysterious-chest-encounter.ts index 877deee66b73..027dd82e3a6b 100644 --- a/src/data/mystery-encounters/encounters/mysterious-chest-encounter.ts +++ b/src/data/mystery-encounters/encounters/mysterious-chest-encounter.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { queueEncounterMessage, showEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils"; @@ -66,8 +66,8 @@ export const MysteriousChestEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate boss mon const config: EnemyPartyConfig = { @@ -106,9 +106,9 @@ export const MysteriousChestEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Play animation - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const introVisuals = encounter.introVisuals!; // Determine roll first @@ -128,13 +128,13 @@ export const MysteriousChestEncounter: MysteryEncounter = introVisuals.spriteConfigs[1].disableAnimation = false; introVisuals.playAnim(); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Open the chest - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const roll = encounter.misc.roll; if (roll >= RAND_LENGTH - COMMON_REWARDS_PERCENT) { // Choose between 2 COMMON / 2 GREAT tier items (20%) - setEncounterRewards(scene, { + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.COMMON, ModifierTier.COMMON, @@ -143,11 +143,11 @@ export const MysteriousChestEncounter: MysteryEncounter = ], }); // Display result message then proceed to rewards - queueEncounterMessage(scene, `${namespace}:option.1.normal`); - leaveEncounterWithoutBattle(scene); + queueEncounterMessage(`${namespace}:option.1.normal`); + leaveEncounterWithoutBattle(); } else if (roll >= RAND_LENGTH - COMMON_REWARDS_PERCENT - ULTRA_REWARDS_PERCENT) { // Choose between 3 ULTRA tier items (30%) - setEncounterRewards(scene, { + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.ULTRA, ModifierTier.ULTRA, @@ -155,39 +155,39 @@ export const MysteriousChestEncounter: MysteryEncounter = ], }); // Display result message then proceed to rewards - queueEncounterMessage(scene, `${namespace}:option.1.good`); - leaveEncounterWithoutBattle(scene); + queueEncounterMessage(`${namespace}:option.1.good`); + leaveEncounterWithoutBattle(); } else if (roll >= RAND_LENGTH - COMMON_REWARDS_PERCENT - ULTRA_REWARDS_PERCENT - ROGUE_REWARDS_PERCENT) { // Choose between 2 ROGUE tier items (10%) - setEncounterRewards(scene, { guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE ]}); + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE ]}); // Display result message then proceed to rewards - queueEncounterMessage(scene, `${namespace}:option.1.great`); - leaveEncounterWithoutBattle(scene); + queueEncounterMessage(`${namespace}:option.1.great`); + leaveEncounterWithoutBattle(); } else if (roll >= RAND_LENGTH - COMMON_REWARDS_PERCENT - ULTRA_REWARDS_PERCENT - ROGUE_REWARDS_PERCENT - MASTER_REWARDS_PERCENT) { // Choose 1 MASTER tier item (5%) - setEncounterRewards(scene, { guaranteedModifierTiers: [ ModifierTier.MASTER ]}); + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.MASTER ]}); // Display result message then proceed to rewards - queueEncounterMessage(scene, `${namespace}:option.1.amazing`); - leaveEncounterWithoutBattle(scene); + queueEncounterMessage(`${namespace}:option.1.amazing`); + leaveEncounterWithoutBattle(); } else { // Your highest level unfainted Pokemon gets OHKO. Start battle against a Gimmighoul (35%) - const highestLevelPokemon = getHighestLevelPlayerPokemon(scene, true, false); - koPlayerPokemon(scene, highestLevelPokemon); + const highestLevelPokemon = getHighestLevelPlayerPokemon(true, false); + koPlayerPokemon(highestLevelPokemon); encounter.setDialogueToken("pokeName", highestLevelPokemon.getNameToRender()); - await showEncounterText(scene, `${namespace}:option.1.bad`); + await showEncounterText(`${namespace}:option.1.bad`); // Handle game over edge case - const allowedPokemon = scene.getPokemonAllowedInBattle(); + const allowedPokemon = globalScene.getPokemonAllowedInBattle(); if (allowedPokemon.length === 0) { // If there are no longer any legal pokemon in the party, game over. - scene.clearPhaseQueue(); - scene.unshiftPhase(new GameOverPhase(scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new GameOverPhase()); } else { // Show which Pokemon was KOed, then start battle against Gimmighoul - await transitionMysteryEncounterIntroVisuals(scene, true, true, 500); - setEncounterRewards(scene, { fillRemaining: true }); - await initBattleWithEnemyConfig(scene, encounter.enemyPartyConfigs[0]); + await transitionMysteryEncounterIntroVisuals(true, true, 500); + setEncounterRewards({ fillRemaining: true }); + await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); } } }) @@ -203,9 +203,9 @@ export const MysteriousChestEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) diff --git a/src/data/mystery-encounters/encounters/part-timer-encounter.ts b/src/data/mystery-encounters/encounters/part-timer-encounter.ts index 092d2ab26739..a43032afc0d4 100644 --- a/src/data/mystery-encounters/encounters/part-timer-encounter.ts +++ b/src/data/mystery-encounters/encounters/part-timer-encounter.ts @@ -1,7 +1,7 @@ import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { leaveEncounterWithoutBattle, selectPokemonForOption, setEncounterExp, setEncounterRewards, transitionMysteryEncounterIntroVisuals, updatePlayerMoney } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MoveRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -52,20 +52,20 @@ export const PartTimerEncounter: MysteryEncounter = text: `${namespace}:intro_dialogue`, }, ]) - .withOnInit((scene: BattleScene) => { + .withOnInit(() => { // Load sfx - scene.loadSe("PRSFX- Horn Drill1", "battle_anims", "PRSFX- Horn Drill1.wav"); - scene.loadSe("PRSFX- Horn Drill3", "battle_anims", "PRSFX- Horn Drill3.wav"); - scene.loadSe("PRSFX- Guillotine2", "battle_anims", "PRSFX- Guillotine2.wav"); - scene.loadSe("PRSFX- Heavy Slam2", "battle_anims", "PRSFX- Heavy Slam2.wav"); + globalScene.loadSe("PRSFX- Horn Drill1", "battle_anims", "PRSFX- Horn Drill1.wav"); + globalScene.loadSe("PRSFX- Horn Drill3", "battle_anims", "PRSFX- Horn Drill3.wav"); + globalScene.loadSe("PRSFX- Guillotine2", "battle_anims", "PRSFX- Guillotine2.wav"); + globalScene.loadSe("PRSFX- Heavy Slam2", "battle_anims", "PRSFX- Heavy Slam2.wav"); - scene.loadSe("PRSFX- Agility", "battle_anims", "PRSFX- Agility.wav"); - scene.loadSe("PRSFX- Extremespeed1", "battle_anims", "PRSFX- Extremespeed1.wav"); - scene.loadSe("PRSFX- Accelerock1", "battle_anims", "PRSFX- Accelerock1.wav"); + globalScene.loadSe("PRSFX- Agility", "battle_anims", "PRSFX- Agility.wav"); + globalScene.loadSe("PRSFX- Extremespeed1", "battle_anims", "PRSFX- Extremespeed1.wav"); + globalScene.loadSe("PRSFX- Accelerock1", "battle_anims", "PRSFX- Accelerock1.wav"); - scene.loadSe("PRSFX- Captivate", "battle_anims", "PRSFX- Captivate.wav"); - scene.loadSe("PRSFX- Attract2", "battle_anims", "PRSFX- Attract2.wav"); - scene.loadSe("PRSFX- Aurora Veil2", "battle_anims", "PRSFX- Aurora Veil2.wav"); + globalScene.loadSe("PRSFX- Captivate", "battle_anims", "PRSFX- Captivate.wav"); + globalScene.loadSe("PRSFX- Attract2", "battle_anims", "PRSFX- Attract2.wav"); + globalScene.loadSe("PRSFX- Aurora Veil2", "battle_anims", "PRSFX- Aurora Veil2.wav"); return true; }) @@ -84,8 +84,8 @@ export const PartTimerEncounter: MysteryEncounter = } ] }) - .withPreOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { encounter.setDialogueToken("selectedPokemon", pokemon.getNameToRender()); @@ -109,41 +109,41 @@ export const PartTimerEncounter: MysteryEncounter = } }); - setEncounterExp(scene, pokemon.id, 100); + setEncounterExp(pokemon.id, 100); // Hide intro visuals - transitionMysteryEncounterIntroVisuals(scene, true, false); + transitionMysteryEncounterIntroVisuals(true, false); // Play sfx for "working" - doDeliverySfx(scene); + doDeliverySfx(); }; // Only Pokemon non-KOd pokemon can be selected const selectableFilter = (pokemon: Pokemon) => { - return isPokemonValidForEncounterOptionSelection(pokemon, scene, `${namespace}:invalid_selection`); + return isPokemonValidForEncounterOptionSelection(pokemon, `${namespace}:invalid_selection`); }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Pick Deliveries // Bring visuals back in - await transitionMysteryEncounterIntroVisuals(scene, false, false); + await transitionMysteryEncounterIntroVisuals(false, false); - const moneyMultiplier = scene.currentBattle.mysteryEncounter!.misc.moneyMultiplier; + const moneyMultiplier = globalScene.currentBattle.mysteryEncounter!.misc.moneyMultiplier; // Give money and do dialogue if (moneyMultiplier > 2.5) { - await showEncounterDialogue(scene, `${namespace}:job_complete_good`, `${namespace}:speaker`); + await showEncounterDialogue(`${namespace}:job_complete_good`, `${namespace}:speaker`); } else { - await showEncounterDialogue(scene, `${namespace}:job_complete_bad`, `${namespace}:speaker`); + await showEncounterDialogue(`${namespace}:job_complete_bad`, `${namespace}:speaker`); } - const moneyChange = scene.getWaveMoneyAmount(moneyMultiplier); - updatePlayerMoney(scene, moneyChange, true, false); - await showEncounterText(scene, i18next.t("mysteryEncounterMessages:receive_money", { amount: moneyChange })); - await showEncounterText(scene, `${namespace}:pokemon_tired`); + const moneyChange = globalScene.getWaveMoneyAmount(moneyMultiplier); + updatePlayerMoney(moneyChange, true, false); + await showEncounterText(i18next.t("mysteryEncounterMessages:receive_money", { amount: moneyChange })); + await showEncounterText(`${namespace}:pokemon_tired`); - setEncounterRewards(scene, { fillRemaining: true }); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ fillRemaining: true }); + leaveEncounterWithoutBattle(); }) .build() ) @@ -158,8 +158,8 @@ export const PartTimerEncounter: MysteryEncounter = } ] }) - .withPreOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { encounter.setDialogueToken("selectedPokemon", pokemon.getNameToRender()); @@ -186,41 +186,41 @@ export const PartTimerEncounter: MysteryEncounter = } }); - setEncounterExp(scene, pokemon.id, 100); + setEncounterExp(pokemon.id, 100); // Hide intro visuals - transitionMysteryEncounterIntroVisuals(scene, true, false); + transitionMysteryEncounterIntroVisuals(true, false); // Play sfx for "working" - doStrongWorkSfx(scene); + doStrongWorkSfx(); }; // Only Pokemon non-KOd pokemon can be selected const selectableFilter = (pokemon: Pokemon) => { - return isPokemonValidForEncounterOptionSelection(pokemon, scene, `${namespace}:invalid_selection`); + return isPokemonValidForEncounterOptionSelection(pokemon, `${namespace}:invalid_selection`); }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Pick Move Warehouse items // Bring visuals back in - await transitionMysteryEncounterIntroVisuals(scene, false, false); + await transitionMysteryEncounterIntroVisuals(false, false); - const moneyMultiplier = scene.currentBattle.mysteryEncounter!.misc.moneyMultiplier; + const moneyMultiplier = globalScene.currentBattle.mysteryEncounter!.misc.moneyMultiplier; // Give money and do dialogue if (moneyMultiplier > 2.5) { - await showEncounterDialogue(scene, `${namespace}:job_complete_good`, `${namespace}:speaker`); + await showEncounterDialogue(`${namespace}:job_complete_good`, `${namespace}:speaker`); } else { - await showEncounterDialogue(scene, `${namespace}:job_complete_bad`, `${namespace}:speaker`); + await showEncounterDialogue(`${namespace}:job_complete_bad`, `${namespace}:speaker`); } - const moneyChange = scene.getWaveMoneyAmount(moneyMultiplier); - updatePlayerMoney(scene, moneyChange, true, false); - await showEncounterText(scene, i18next.t("mysteryEncounterMessages:receive_money", { amount: moneyChange })); - await showEncounterText(scene, `${namespace}:pokemon_tired`); + const moneyChange = globalScene.getWaveMoneyAmount(moneyMultiplier); + updatePlayerMoney(moneyChange, true, false); + await showEncounterText(i18next.t("mysteryEncounterMessages:receive_money", { amount: moneyChange })); + await showEncounterText(`${namespace}:pokemon_tired`); - setEncounterRewards(scene, { fillRemaining: true }); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ fillRemaining: true }); + leaveEncounterWithoutBattle(); }) .build() ) @@ -238,8 +238,8 @@ export const PartTimerEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const selectedPokemon = encounter.selectedOption?.primaryPokemon!; encounter.setDialogueToken("selectedPokemon", selectedPokemon.getNameToRender()); @@ -251,28 +251,28 @@ export const PartTimerEncounter: MysteryEncounter = } }); - setEncounterExp(scene, selectedPokemon.id, 100); + setEncounterExp(selectedPokemon.id, 100); // Hide intro visuals - transitionMysteryEncounterIntroVisuals(scene, true, false); + transitionMysteryEncounterIntroVisuals(true, false); // Play sfx for "working" - doSalesSfx(scene); + doSalesSfx(); return true; }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Assist with Sales // Bring visuals back in - await transitionMysteryEncounterIntroVisuals(scene, false, false); + await transitionMysteryEncounterIntroVisuals(false, false); // Give money and do dialogue - await showEncounterDialogue(scene, `${namespace}:job_complete_good`, `${namespace}:speaker`); - const moneyChange = scene.getWaveMoneyAmount(2.5); - updatePlayerMoney(scene, moneyChange, true, false); - await showEncounterText(scene, i18next.t("mysteryEncounterMessages:receive_money", { amount: moneyChange })); - await showEncounterText(scene, `${namespace}:pokemon_tired`); - - setEncounterRewards(scene, { fillRemaining: true }); - leaveEncounterWithoutBattle(scene); + await showEncounterDialogue(`${namespace}:job_complete_good`, `${namespace}:speaker`); + const moneyChange = globalScene.getWaveMoneyAmount(2.5); + updatePlayerMoney(moneyChange, true, false); + await showEncounterText(i18next.t("mysteryEncounterMessages:receive_money", { amount: moneyChange })); + await showEncounterText(`${namespace}:pokemon_tired`); + + setEncounterRewards({ fillRemaining: true }); + leaveEncounterWithoutBattle(); }) .build() ) @@ -284,51 +284,51 @@ export const PartTimerEncounter: MysteryEncounter = ]) .build(); -function doStrongWorkSfx(scene: BattleScene) { - scene.playSound("battle_anims/PRSFX- Horn Drill1"); - scene.playSound("battle_anims/PRSFX- Horn Drill1"); +function doStrongWorkSfx() { + globalScene.playSound("battle_anims/PRSFX- Horn Drill1"); + globalScene.playSound("battle_anims/PRSFX- Horn Drill1"); - scene.time.delayedCall(1000, () => { - scene.playSound("battle_anims/PRSFX- Guillotine2"); + globalScene.time.delayedCall(1000, () => { + globalScene.playSound("battle_anims/PRSFX- Guillotine2"); }); - scene.time.delayedCall(2000, () => { - scene.playSound("battle_anims/PRSFX- Heavy Slam2"); + globalScene.time.delayedCall(2000, () => { + globalScene.playSound("battle_anims/PRSFX- Heavy Slam2"); }); - scene.time.delayedCall(2500, () => { - scene.playSound("battle_anims/PRSFX- Guillotine2"); + globalScene.time.delayedCall(2500, () => { + globalScene.playSound("battle_anims/PRSFX- Guillotine2"); }); } -function doDeliverySfx(scene: BattleScene) { - scene.playSound("battle_anims/PRSFX- Accelerock1"); +function doDeliverySfx() { + globalScene.playSound("battle_anims/PRSFX- Accelerock1"); - scene.time.delayedCall(1500, () => { - scene.playSound("battle_anims/PRSFX- Extremespeed1"); + globalScene.time.delayedCall(1500, () => { + globalScene.playSound("battle_anims/PRSFX- Extremespeed1"); }); - scene.time.delayedCall(2000, () => { - scene.playSound("battle_anims/PRSFX- Extremespeed1"); + globalScene.time.delayedCall(2000, () => { + globalScene.playSound("battle_anims/PRSFX- Extremespeed1"); }); - scene.time.delayedCall(2250, () => { - scene.playSound("battle_anims/PRSFX- Agility"); + globalScene.time.delayedCall(2250, () => { + globalScene.playSound("battle_anims/PRSFX- Agility"); }); } -function doSalesSfx(scene: BattleScene) { - scene.playSound("battle_anims/PRSFX- Captivate"); +function doSalesSfx() { + globalScene.playSound("battle_anims/PRSFX- Captivate"); - scene.time.delayedCall(1500, () => { - scene.playSound("battle_anims/PRSFX- Attract2"); + globalScene.time.delayedCall(1500, () => { + globalScene.playSound("battle_anims/PRSFX- Attract2"); }); - scene.time.delayedCall(2000, () => { - scene.playSound("battle_anims/PRSFX- Aurora Veil2"); + globalScene.time.delayedCall(2000, () => { + globalScene.playSound("battle_anims/PRSFX- Aurora Veil2"); }); - scene.time.delayedCall(3000, () => { - scene.playSound("battle_anims/PRSFX- Attract2"); + globalScene.time.delayedCall(3000, () => { + globalScene.playSound("battle_anims/PRSFX- Attract2"); }); } diff --git a/src/data/mystery-encounters/encounters/safari-zone-encounter.ts b/src/data/mystery-encounters/encounters/safari-zone-encounter.ts index e16cf2d69737..f32ff8543ffb 100644 --- a/src/data/mystery-encounters/encounters/safari-zone-encounter.ts +++ b/src/data/mystery-encounters/encounters/safari-zone-encounter.ts @@ -1,6 +1,6 @@ import { initSubsequentOptionSelect, leaveEncounterWithoutBattle, transitionMysteryEncounterIntroVisuals, updatePlayerMoney, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import MysteryEncounterOption, { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { TrainerSlot } from "#app/data/trainer-config"; @@ -59,8 +59,8 @@ export const SafariZoneEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - scene.currentBattle.mysteryEncounter?.setDialogueToken("numEncounters", NUM_SAFARI_ENCOUNTERS.toString()); + .withOnInit(() => { + globalScene.currentBattle.mysteryEncounter?.setDialogueToken("numEncounters", NUM_SAFARI_ENCOUNTERS.toString()); return true; }) .withOption(MysteryEncounterOptionBuilder @@ -75,25 +75,25 @@ export const SafariZoneEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Start safari encounter - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.continuousEncounter = true; encounter.misc = { safariPokemonRemaining: NUM_SAFARI_ENCOUNTERS }; - updatePlayerMoney(scene, -(encounter.options[0].requirements[0] as MoneyRequirement).requiredMoney); + updatePlayerMoney(-(encounter.options[0].requirements[0] as MoneyRequirement).requiredMoney); // Load bait/mud assets - scene.loadSe("PRSFX- Bug Bite", "battle_anims", "PRSFX- Bug Bite.wav"); - scene.loadSe("PRSFX- Sludge Bomb2", "battle_anims", "PRSFX- Sludge Bomb2.wav"); - scene.loadSe("PRSFX- Taunt2", "battle_anims", "PRSFX- Taunt2.wav"); - scene.loadAtlas("safari_zone_bait", "mystery-encounters"); - scene.loadAtlas("safari_zone_mud", "mystery-encounters"); + globalScene.loadSe("PRSFX- Bug Bite", "battle_anims", "PRSFX- Bug Bite.wav"); + globalScene.loadSe("PRSFX- Sludge Bomb2", "battle_anims", "PRSFX- Sludge Bomb2.wav"); + globalScene.loadSe("PRSFX- Taunt2", "battle_anims", "PRSFX- Taunt2.wav"); + globalScene.loadAtlas("safari_zone_bait", "mystery-encounters"); + globalScene.loadAtlas("safari_zone_mud", "mystery-encounters"); // Clear enemy party - scene.currentBattle.enemyParty = []; - await transitionMysteryEncounterIntroVisuals(scene); - await summonSafariPokemon(scene); - initSubsequentOptionSelect(scene, { overrideOptions: safariZoneGameOptions, hideDescription: true }); + globalScene.currentBattle.enemyParty = []; + await transitionMysteryEncounterIntroVisuals(); + await summonSafariPokemon(); + initSubsequentOptionSelect({ overrideOptions: safariZoneGameOptions, hideDescription: true }); return true; }) .build() @@ -108,9 +108,9 @@ export const SafariZoneEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) @@ -143,26 +143,26 @@ const safariZoneGameOptions: MysteryEncounterOption[] = [ } ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Throw a ball option - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const pokemon = encounter.misc.pokemon; - const catchResult = await throwPokeball(scene, pokemon); + const catchResult = await throwPokeball(pokemon); if (catchResult) { // You caught pokemon // Check how many safari pokemon left if (encounter.misc.safariPokemonRemaining > 0) { - await summonSafariPokemon(scene); - initSubsequentOptionSelect(scene, { overrideOptions: safariZoneGameOptions, startingCursorIndex: 0, hideDescription: true }); + await summonSafariPokemon(); + initSubsequentOptionSelect({ overrideOptions: safariZoneGameOptions, startingCursorIndex: 0, hideDescription: true }); } else { // End safari mode encounter.continuousEncounter = false; - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); } } else { // Pokemon catch failed, end turn - await doEndTurn(scene, 0); + await doEndTurn(0); } return true; }) @@ -178,22 +178,22 @@ const safariZoneGameOptions: MysteryEncounterOption[] = [ }, ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Throw bait option - const pokemon = scene.currentBattle.mysteryEncounter!.misc.pokemon; - await throwBait(scene, pokemon); + const pokemon = globalScene.currentBattle.mysteryEncounter!.misc.pokemon; + await throwBait(pokemon); // 100% chance to increase catch stage +2 - tryChangeCatchStage(scene, 2); + tryChangeCatchStage(2); // 80% chance to increase flee stage +1 - const fleeChangeResult = tryChangeFleeStage(scene, 1, 8); + const fleeChangeResult = tryChangeFleeStage(1, 8); if (!fleeChangeResult) { - await showEncounterText(scene, getEncounterText(scene, `${namespace}:safari.busy_eating`) ?? "", null, 1000, false ); + await showEncounterText(getEncounterText(`${namespace}:safari.busy_eating`) ?? "", null, 1000, false ); } else { - await showEncounterText(scene, getEncounterText(scene, `${namespace}:safari.eating`) ?? "", null, 1000, false); + await showEncounterText(getEncounterText(`${namespace}:safari.eating`) ?? "", null, 1000, false); } - await doEndTurn(scene, 1); + await doEndTurn(1); return true; }) .build(), @@ -208,21 +208,21 @@ const safariZoneGameOptions: MysteryEncounterOption[] = [ }, ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Throw mud option - const pokemon = scene.currentBattle.mysteryEncounter!.misc.pokemon; - await throwMud(scene, pokemon); + const pokemon = globalScene.currentBattle.mysteryEncounter!.misc.pokemon; + await throwMud(pokemon); // 100% chance to decrease flee stage -2 - tryChangeFleeStage(scene, -2); + tryChangeFleeStage(-2); // 80% chance to decrease catch stage -1 - const catchChangeResult = tryChangeCatchStage(scene, -1, 8); + const catchChangeResult = tryChangeCatchStage(-1, 8); if (!catchChangeResult) { - await showEncounterText(scene, getEncounterText(scene, `${namespace}:safari.beside_itself_angry`) ?? "", null, 1000, false ); + await showEncounterText(getEncounterText(`${namespace}:safari.beside_itself_angry`) ?? "", null, 1000, false ); } else { - await showEncounterText(scene, getEncounterText(scene, `${namespace}:safari.angry`) ?? "", null, 1000, false ); + await showEncounterText(getEncounterText(`${namespace}:safari.angry`) ?? "", null, 1000, false ); } - await doEndTurn(scene, 2); + await doEndTurn(2); return true; }) .build(), @@ -232,40 +232,40 @@ const safariZoneGameOptions: MysteryEncounterOption[] = [ buttonLabel: `${namespace}:safari.4.label`, buttonTooltip: `${namespace}:safari.4.tooltip`, }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Flee option - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const pokemon = encounter.misc.pokemon; - await doPlayerFlee(scene, pokemon); + await doPlayerFlee(pokemon); // Check how many safari pokemon left if (encounter.misc.safariPokemonRemaining > 0) { - await summonSafariPokemon(scene); - initSubsequentOptionSelect(scene, { overrideOptions: safariZoneGameOptions, startingCursorIndex: 3, hideDescription: true }); + await summonSafariPokemon(); + initSubsequentOptionSelect({ overrideOptions: safariZoneGameOptions, startingCursorIndex: 3, hideDescription: true }); } else { // End safari mode encounter.continuousEncounter = false; - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); } return true; }) .build() ]; -async function summonSafariPokemon(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter!; +async function summonSafariPokemon() { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Message pokemon remaining encounter.setDialogueToken("remainingCount", encounter.misc.safariPokemonRemaining); - scene.queueMessage(getEncounterText(scene, `${namespace}:safari.remaining_count`) ?? "", null, true); + globalScene.queueMessage(getEncounterText(`${namespace}:safari.remaining_count`) ?? "", null, true); // Generate pokemon using safariPokemonRemaining so they are always the same pokemon no matter how many turns are taken // Safari pokemon roll twice on shiny and HA chances, but are otherwise normal let enemySpecies; let pokemon; - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { enemySpecies = getSafariSpeciesSpawn(); - const level = scene.currentBattle.getLevelForWave(); - enemySpecies = getPokemonSpecies(enemySpecies.getWildSpeciesForLevel(level, true, false, scene.gameMode)); - pokemon = scene.addEnemyPokemon(enemySpecies, level, TrainerSlot.NONE, false); + const level = globalScene.currentBattle.getLevelForWave(); + enemySpecies = getPokemonSpecies(enemySpecies.getWildSpeciesForLevel(level, true, false, globalScene.gameMode)); + pokemon = globalScene.addEnemyPokemon(enemySpecies, level, TrainerSlot.NONE, false); // Roll shiny twice if (!pokemon.shiny) { @@ -277,7 +277,7 @@ async function summonSafariPokemon(scene: BattleScene) { const hiddenIndex = pokemon.species.ability2 ? 2 : 1; if (pokemon.abilityIndex < hiddenIndex) { const hiddenAbilityChance = new IntegerHolder(256); - scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); + globalScene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); const hasHiddenAbility = !randSeedInt(hiddenAbilityChance.value); @@ -289,10 +289,10 @@ async function summonSafariPokemon(scene: BattleScene) { pokemon.calculateStats(); - scene.currentBattle.enemyParty.unshift(pokemon); - }, scene.currentBattle.waveIndex * 1000 * encounter.misc.safariPokemonRemaining); + globalScene.currentBattle.enemyParty.unshift(pokemon); + }, globalScene.currentBattle.waveIndex * 1000 * encounter.misc.safariPokemonRemaining); - scene.gameData.setPokemonSeen(pokemon, true); + globalScene.gameData.setPokemonSeen(pokemon, true); await pokemon.loadAssets(); // Reset safari catch and flee rates @@ -301,7 +301,7 @@ async function summonSafariPokemon(scene: BattleScene) { encounter.misc.pokemon = pokemon; encounter.misc.safariPokemonRemaining -= 1; - scene.unshiftPhase(new SummonPhase(scene, 0, false)); + globalScene.unshiftPhase(new SummonPhase(0, false)); encounter.setDialogueToken("pokemonName", getPokemonNameWithAffix(pokemon)); @@ -310,49 +310,49 @@ async function summonSafariPokemon(scene: BattleScene) { // shows up and the IV scanner breaks. For now, we place the IV scanner code // separately so that at least the IV scanner works. - const ivScannerModifier = scene.findModifier(m => m instanceof IvScannerModifier); + const ivScannerModifier = globalScene.findModifier(m => m instanceof IvScannerModifier); if (ivScannerModifier) { - scene.pushPhase(new ScanIvsPhase(scene, pokemon.getBattlerIndex(), Math.min(ivScannerModifier.getStackCount() * 2, 6))); + globalScene.pushPhase(new ScanIvsPhase(pokemon.getBattlerIndex(), Math.min(ivScannerModifier.getStackCount() * 2, 6))); } } -function throwPokeball(scene: BattleScene, pokemon: EnemyPokemon): Promise { +function throwPokeball(pokemon: EnemyPokemon): Promise { const baseCatchRate = pokemon.species.catchRate; // Catch stage ranges from -6 to +6 (like stat boost stages) - const safariCatchStage = scene.currentBattle.mysteryEncounter!.misc.catchStage; + const safariCatchStage = globalScene.currentBattle.mysteryEncounter!.misc.catchStage; // Catch modifier ranges from 2/8 (-6 stage) to 8/2 (+6) const safariModifier = (2 + Math.min(Math.max(safariCatchStage, 0), 6)) / (2 - Math.max(Math.min(safariCatchStage, 0), -6)); // Catch rate same as safari ball const pokeballMultiplier = 1.5; const catchRate = Math.round(baseCatchRate * pokeballMultiplier * safariModifier); const ballTwitchRate = Math.round(1048560 / Math.sqrt(Math.sqrt(16711680 / catchRate))); - return trainerThrowPokeball(scene, pokemon, PokeballType.POKEBALL, ballTwitchRate); + return trainerThrowPokeball(pokemon, PokeballType.POKEBALL, ballTwitchRate); } -async function throwBait(scene: BattleScene, pokemon: EnemyPokemon): Promise { +async function throwBait(pokemon: EnemyPokemon): Promise { const originalY: number = pokemon.y; const fpOffset = pokemon.getFieldPositionOffset(); - const bait: Phaser.GameObjects.Sprite = scene.addFieldSprite(16 + 75, 80 + 25, "safari_zone_bait", "0001.png"); + const bait: Phaser.GameObjects.Sprite = globalScene.addFieldSprite(16 + 75, 80 + 25, "safari_zone_bait", "0001.png"); bait.setOrigin(0.5, 0.625); - scene.field.add(bait); + globalScene.field.add(bait); return new Promise(resolve => { - scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); - scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => { - scene.playSound("se/pb_throw"); + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); + globalScene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => { + globalScene.playSound("se/pb_throw"); // Trainer throw frames - scene.trainer.setFrame("2"); - scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => { - scene.trainer.setFrame("3"); - scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => { - scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); + globalScene.trainer.setFrame("2"); + globalScene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => { + globalScene.trainer.setFrame("3"); + globalScene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => { + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); }); }); // Pokeball move and catch logic - scene.tweens.add({ + globalScene.tweens.add({ targets: bait, x: { value: 210 + fpOffset[0], ease: "Linear" }, y: { value: 55 + fpOffset[1], ease: "Cubic.easeOut" }, @@ -360,8 +360,8 @@ async function throwBait(scene: BattleScene, pokemon: EnemyPokemon): Promise { let index = 1; - scene.time.delayedCall(768, () => { - scene.tweens.add({ + globalScene.time.delayedCall(768, () => { + globalScene.tweens.add({ targets: pokemon, duration: 150, ease: "Cubic.easeOut", @@ -369,12 +369,12 @@ async function throwBait(scene: BattleScene, pokemon: EnemyPokemon): Promise { - scene.playSound("battle_anims/PRSFX- Bug Bite"); + globalScene.playSound("battle_anims/PRSFX- Bug Bite"); bait.setFrame("0002.png"); }, onLoop: () => { if (index % 2 === 0) { - scene.playSound("battle_anims/PRSFX- Bug Bite"); + globalScene.playSound("battle_anims/PRSFX- Bug Bite"); } if (index === 4) { bait.setFrame("0003.png"); @@ -382,7 +382,7 @@ async function throwBait(scene: BattleScene, pokemon: EnemyPokemon): Promise { - scene.time.delayedCall(256, () => { + globalScene.time.delayedCall(256, () => { bait.destroy(); resolve(true); }); @@ -395,55 +395,55 @@ async function throwBait(scene: BattleScene, pokemon: EnemyPokemon): Promise { +async function throwMud(pokemon: EnemyPokemon): Promise { const originalY: number = pokemon.y; const fpOffset = pokemon.getFieldPositionOffset(); - const mud: Phaser.GameObjects.Sprite = scene.addFieldSprite(16 + 75, 80 + 35, "safari_zone_mud", "0001.png"); + const mud: Phaser.GameObjects.Sprite = globalScene.addFieldSprite(16 + 75, 80 + 35, "safari_zone_mud", "0001.png"); mud.setOrigin(0.5, 0.625); - scene.field.add(mud); + globalScene.field.add(mud); return new Promise(resolve => { - scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); - scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => { - scene.playSound("se/pb_throw"); + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); + globalScene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => { + globalScene.playSound("se/pb_throw"); // Trainer throw frames - scene.trainer.setFrame("2"); - scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => { - scene.trainer.setFrame("3"); - scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => { - scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); + globalScene.trainer.setFrame("2"); + globalScene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => { + globalScene.trainer.setFrame("3"); + globalScene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => { + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); }); }); // Mud throw and splat - scene.tweens.add({ + globalScene.tweens.add({ targets: mud, x: { value: 230 + fpOffset[0], ease: "Linear" }, y: { value: 55 + fpOffset[1], ease: "Cubic.easeOut" }, duration: 500, onComplete: () => { // Mud frame 2 - scene.playSound("battle_anims/PRSFX- Sludge Bomb2"); + globalScene.playSound("battle_anims/PRSFX- Sludge Bomb2"); mud.setFrame("0002.png"); // Mud splat - scene.time.delayedCall(200, () => { + globalScene.time.delayedCall(200, () => { mud.setFrame("0003.png"); - scene.time.delayedCall(400, () => { + globalScene.time.delayedCall(400, () => { mud.setFrame("0004.png"); }); }); // Fade mud then angry animation - scene.tweens.add({ + globalScene.tweens.add({ targets: mud, alpha: 0, ease: "Cubic.easeIn", duration: 1000, onComplete: () => { mud.destroy(); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, duration: 300, ease: "Cubic.easeOut", @@ -451,10 +451,10 @@ async function throwMud(scene: BattleScene, pokemon: EnemyPokemon): Promise { - scene.playSound("battle_anims/PRSFX- Taunt2"); + globalScene.playSound("battle_anims/PRSFX- Taunt2"); }, onLoop: () => { - scene.playSound("battle_anims/PRSFX- Taunt2"); + globalScene.playSound("battle_anims/PRSFX- Taunt2"); }, onComplete: () => { resolve(true); @@ -478,53 +478,53 @@ function isPokemonFlee(pokemon: EnemyPokemon, fleeStage: number): boolean { return roll < fleeRate; } -function tryChangeFleeStage(scene: BattleScene, change: number, chance?: number): boolean { +function tryChangeFleeStage(change: number, chance?: number): boolean { if (chance && randSeedInt(10) >= chance) { return false; } - const currentFleeStage = scene.currentBattle.mysteryEncounter!.misc.fleeStage ?? 0; - scene.currentBattle.mysteryEncounter!.misc.fleeStage = Math.min(Math.max(currentFleeStage + change, -6), 6); + const currentFleeStage = globalScene.currentBattle.mysteryEncounter!.misc.fleeStage ?? 0; + globalScene.currentBattle.mysteryEncounter!.misc.fleeStage = Math.min(Math.max(currentFleeStage + change, -6), 6); return true; } -function tryChangeCatchStage(scene: BattleScene, change: number, chance?: number): boolean { +function tryChangeCatchStage(change: number, chance?: number): boolean { if (chance && randSeedInt(10) >= chance) { return false; } - const currentCatchStage = scene.currentBattle.mysteryEncounter!.misc.catchStage ?? 0; - scene.currentBattle.mysteryEncounter!.misc.catchStage = Math.min(Math.max(currentCatchStage + change, -6), 6); + const currentCatchStage = globalScene.currentBattle.mysteryEncounter!.misc.catchStage ?? 0; + globalScene.currentBattle.mysteryEncounter!.misc.catchStage = Math.min(Math.max(currentCatchStage + change, -6), 6); return true; } -async function doEndTurn(scene: BattleScene, cursorIndex: number) { +async function doEndTurn(cursorIndex: number) { // First cleanup and destroy old Pokemon objects that were left in the enemyParty // They are left in enemyParty temporarily so that VictoryPhase properly handles EXP - const party = scene.getEnemyParty(); + const party = globalScene.getEnemyParty(); if (party.length > 1) { for (let i = 1; i < party.length; i++) { party[i].destroy(); } - scene.currentBattle.enemyParty = party.slice(0, 1); + globalScene.currentBattle.enemyParty = party.slice(0, 1); } - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const pokemon = encounter.misc.pokemon; const isFlee = isPokemonFlee(pokemon, encounter.misc.fleeStage); if (isFlee) { // Pokemon flees! - await doPokemonFlee(scene, pokemon); + await doPokemonFlee(pokemon); // Check how many safari pokemon left if (encounter.misc.safariPokemonRemaining > 0) { - await summonSafariPokemon(scene); - initSubsequentOptionSelect(scene, { overrideOptions: safariZoneGameOptions, startingCursorIndex: cursorIndex, hideDescription: true }); + await summonSafariPokemon(); + initSubsequentOptionSelect({ overrideOptions: safariZoneGameOptions, startingCursorIndex: cursorIndex, hideDescription: true }); } else { // End safari mode encounter.continuousEncounter = false; - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); } } else { - scene.queueMessage(getEncounterText(scene, `${namespace}:safari.watching`) ?? "", 0, null, 1000); - initSubsequentOptionSelect(scene, { overrideOptions: safariZoneGameOptions, startingCursorIndex: cursorIndex, hideDescription: true }); + globalScene.queueMessage(getEncounterText(`${namespace}:safari.watching`) ?? "", 0, null, 1000); + initSubsequentOptionSelect({ overrideOptions: safariZoneGameOptions, startingCursorIndex: cursorIndex, hideDescription: true }); } } diff --git a/src/data/mystery-encounters/encounters/shady-vitamin-dealer-encounter.ts b/src/data/mystery-encounters/encounters/shady-vitamin-dealer-encounter.ts index 3f1ace47b0f3..e67b9f98fa96 100644 --- a/src/data/mystery-encounters/encounters/shady-vitamin-dealer-encounter.ts +++ b/src/data/mystery-encounters/encounters/shady-vitamin-dealer-encounter.ts @@ -4,7 +4,7 @@ import { modifierTypes } from "#app/modifier/modifier-type"; import { randSeedInt } from "#app/utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { MoneyRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; @@ -79,15 +79,15 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Update money - updatePlayerMoney(scene, -(encounter.options[0].requirements[0] as MoneyRequirement).requiredMoney); + updatePlayerMoney(-(encounter.options[0].requirements[0] as MoneyRequirement).requiredMoney); // Calculate modifiers and dialogue tokens const modifiers = [ - generateModifierType(scene, modifierTypes.BASE_STAT_BOOSTER)!, - generateModifierType(scene, modifierTypes.BASE_STAT_BOOSTER)!, + generateModifierType(modifierTypes.BASE_STAT_BOOSTER)!, + generateModifierType(modifierTypes.BASE_STAT_BOOSTER)!, ]; encounter.setDialogueToken("boost1", modifiers[0].name); encounter.setDialogueToken("boost2", modifiers[1].name); @@ -103,34 +103,34 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = if (!pokemon.isAllowedInChallenge()) { return i18next.t("partyUiHandler:cantBeUsed", { pokemonName: pokemon.getNameToRender() }) ?? null; } - if (!encounter.pokemonMeetsPrimaryRequirements(scene, pokemon)) { - return getEncounterText(scene, `${namespace}:invalid_selection`) ?? null; + if (!encounter.pokemonMeetsPrimaryRequirements(pokemon)) { + return getEncounterText(`${namespace}:invalid_selection`) ?? null; } return null; }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Choose Cheap Option - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const chosenPokemon = encounter.misc.chosenPokemon; const modifiers = encounter.misc.modifiers; for (const modType of modifiers) { - await applyModifierTypeToPlayerPokemon(scene, chosenPokemon, modType); + await applyModifierTypeToPlayerPokemon(chosenPokemon, modType); } - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) - .withPostOptionPhase(async (scene: BattleScene) => { + .withPostOptionPhase(async () => { // Damage and status applied after dealer leaves (to make thematic sense) - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const chosenPokemon = encounter.misc.chosenPokemon as PlayerPokemon; // Pokemon takes half max HP damage and nature is randomized (does not update dex) - applyDamageToPokemon(scene, chosenPokemon, Math.floor(chosenPokemon.getMaxHp() / 2)); + applyDamageToPokemon(chosenPokemon, Math.floor(chosenPokemon.getMaxHp() / 2)); const currentNature = chosenPokemon.nature; let newNature = randSeedInt(25) as Nature; @@ -140,8 +140,8 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = chosenPokemon.setCustomNature(newNature); encounter.setDialogueToken("newNature", getNatureName(newNature)); - queueEncounterMessage(scene, `${namespace}:cheap_side_effects`); - setEncounterExp(scene, [ chosenPokemon.id ], 100); + queueEncounterMessage(`${namespace}:cheap_side_effects`); + setEncounterExp([ chosenPokemon.id ], 100); await chosenPokemon.updateInfo(); }) .build() @@ -159,15 +159,15 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Update money - updatePlayerMoney(scene, -(encounter.options[1].requirements[0] as MoneyRequirement).requiredMoney); + updatePlayerMoney(-(encounter.options[1].requirements[0] as MoneyRequirement).requiredMoney); // Calculate modifiers and dialogue tokens const modifiers = [ - generateModifierType(scene, modifierTypes.BASE_STAT_BOOSTER)!, - generateModifierType(scene, modifierTypes.BASE_STAT_BOOSTER)!, + generateModifierType(modifierTypes.BASE_STAT_BOOSTER)!, + generateModifierType(modifierTypes.BASE_STAT_BOOSTER)!, ]; encounter.setDialogueToken("boost1", modifiers[0].name); encounter.setDialogueToken("boost2", modifiers[1].name); @@ -179,30 +179,30 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = // Only Pokemon that can gain benefits are unfainted const selectableFilter = (pokemon: Pokemon) => { - return isPokemonValidForEncounterOptionSelection(pokemon, scene, `${namespace}:invalid_selection`); + return isPokemonValidForEncounterOptionSelection(pokemon, `${namespace}:invalid_selection`); }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Choose Expensive Option - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const chosenPokemon = encounter.misc.chosenPokemon; const modifiers = encounter.misc.modifiers; for (const modType of modifiers) { - await applyModifierTypeToPlayerPokemon(scene, chosenPokemon, modType); + await applyModifierTypeToPlayerPokemon(chosenPokemon, modType); } - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) - .withPostOptionPhase(async (scene: BattleScene) => { + .withPostOptionPhase(async () => { // Status applied after dealer leaves (to make thematic sense) - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const chosenPokemon = encounter.misc.chosenPokemon; - queueEncounterMessage(scene, `${namespace}:no_bad_effects`); - setEncounterExp(scene, [ chosenPokemon.id ], 100); + queueEncounterMessage(`${namespace}:no_bad_effects`); + setEncounterExp([ chosenPokemon.id ], 100); await chosenPokemon.updateInfo(); }) @@ -219,9 +219,9 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = } ] }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) diff --git a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts index 8dd03e12caa6..484a70df2d9d 100644 --- a/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts +++ b/src/data/mystery-encounters/encounters/slumbering-snorlax-encounter.ts @@ -2,7 +2,7 @@ import { STEALING_MOVES } from "#app/data/mystery-encounters/requirements/requir import { modifierTypes, PokemonHeldItemModifierType } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { StatusEffect } from "#enums/status-effect"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; @@ -51,8 +51,8 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = text: `${namespace}:intro`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; console.log(encounter); // Calculate boss mon @@ -65,11 +65,11 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = moveSet: [ Moves.REST, Moves.SLEEP_TALK, Moves.CRUNCH, Moves.GIGA_IMPACT ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType, stackCount: 2 }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.ENIGMA ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.ENIGMA ]) as PokemonHeldItemModifierType, stackCount: 2 }, ], @@ -83,7 +83,7 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = encounter.enemyPartyConfigs = [ config ]; // Load animations/sfx for Snorlax fight start moves - loadCustomMovesForEncounter(scene, [ Moves.SNORE ]); + loadCustomMovesForEncounter([ Moves.SNORE ]); encounter.setDialogueToken("snorlaxName", getPokemonSpecies(Species.SNORLAX).getName()); @@ -103,10 +103,10 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Pick battle - const encounter = scene.currentBattle.mysteryEncounter!; - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.LEFTOVERS ], fillRemaining: true }); + const encounter = globalScene.currentBattle.mysteryEncounter!; + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.LEFTOVERS ], fillRemaining: true }); encounter.startOfBattleEffects.push( { sourceBattlerIndex: BattlerIndex.ENEMY, @@ -120,7 +120,7 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = move: new PokemonMove(Moves.SNORE), ignorePp: true }); - await initBattleWithEnemyConfig(scene, encounter.enemyPartyConfigs[0]); + await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); } ) .withSimpleOption( @@ -133,12 +133,12 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Fall asleep waiting for Snorlax // Full heal party - scene.unshiftPhase(new PartyHealPhase(scene, true)); - queueEncounterMessage(scene, `${namespace}:option.2.rest_result`); - leaveEncounterWithoutBattle(scene); + globalScene.unshiftPhase(new PartyHealPhase(true)); + queueEncounterMessage(`${namespace}:option.2.rest_result`); + leaveEncounterWithoutBattle(); } ) .withOption( @@ -155,13 +155,13 @@ export const SlumberingSnorlaxEncounter: MysteryEncounter = } ] }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Steal the Snorlax's Leftovers - const instance = scene.currentBattle.mysteryEncounter!; - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.LEFTOVERS ], fillRemaining: false }); + const instance = globalScene.currentBattle.mysteryEncounter!; + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.LEFTOVERS ], fillRemaining: false }); // Snorlax exp to Pokemon that did the stealing - setEncounterExp(scene, instance.primaryPokemon!.id, getPokemonSpecies(Species.SNORLAX).baseExp); - leaveEncounterWithoutBattle(scene); + setEncounterExp(instance.primaryPokemon!.id, getPokemonSpecies(Species.SNORLAX).baseExp); + leaveEncounterWithoutBattle(); }) .build() ) diff --git a/src/data/mystery-encounters/encounters/teleporting-hijinks-encounter.ts b/src/data/mystery-encounters/encounters/teleporting-hijinks-encounter.ts index 042e9278673c..e46d5405ffe6 100644 --- a/src/data/mystery-encounters/encounters/teleporting-hijinks-encounter.ts +++ b/src/data/mystery-encounters/encounters/teleporting-hijinks-encounter.ts @@ -1,7 +1,7 @@ import { EnemyPartyConfig, generateModifierTypeOption, initBattleWithEnemyConfig, setEncounterExp, setEncounterRewards, transitionMysteryEncounterIntroVisuals, updatePlayerMoney, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { randSeedInt } from "#app/utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MoneyRequirement, WaveModulusRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; import Pokemon, { EnemyPokemon } from "#app/field/pokemon"; @@ -62,9 +62,9 @@ export const TeleportingHijinksEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; - const price = scene.getWaveMoneyAmount(MONEY_COST_MULTIPLIER); + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; + const price = globalScene.getWaveMoneyAmount(MONEY_COST_MULTIPLIER); encounter.setDialogueToken("price", price.toString()); encounter.misc = { price @@ -85,14 +85,14 @@ export const TeleportingHijinksEncounter: MysteryEncounter = } ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Update money - updatePlayerMoney(scene, -scene.currentBattle.mysteryEncounter!.misc.price, true, false); + updatePlayerMoney(-globalScene.currentBattle.mysteryEncounter!.misc.price, true, false); }) - .withOptionPhase(async (scene: BattleScene) => { - const config: EnemyPartyConfig = await doBiomeTransitionDialogueAndBattleInit(scene); - setEncounterRewards(scene, { fillRemaining: true }); - await initBattleWithEnemyConfig(scene, config); + .withOptionPhase(async () => { + const config: EnemyPartyConfig = await doBiomeTransitionDialogueAndBattleInit(); + setEncounterRewards({ fillRemaining: true }); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -110,11 +110,11 @@ export const TeleportingHijinksEncounter: MysteryEncounter = } ], }) - .withOptionPhase(async (scene: BattleScene) => { - const config: EnemyPartyConfig = await doBiomeTransitionDialogueAndBattleInit(scene); - setEncounterRewards(scene, { fillRemaining: true }); - setEncounterExp(scene, scene.currentBattle.mysteryEncounter!.selectedOption!.primaryPokemon!.id, 100); - await initBattleWithEnemyConfig(scene, config); + .withOptionPhase(async () => { + const config: EnemyPartyConfig = await doBiomeTransitionDialogueAndBattleInit(); + setEncounterRewards({ fillRemaining: true }); + setEncounterExp(globalScene.currentBattle.mysteryEncounter!.selectedOption!.primaryPokemon!.id, 100); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -128,14 +128,14 @@ export const TeleportingHijinksEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Inspect the Machine - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; // Init enemy - const level = getEncounterPokemonLevelForWave(scene, STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); - const bossSpecies = scene.arena.randomSpecies(scene.currentBattle.waveIndex, level, 0, getPartyLuckValue(scene.getPlayerParty()), true); - const bossPokemon = new EnemyPokemon(scene, bossSpecies, level, TrainerSlot.NONE, true); + const level = getEncounterPokemonLevelForWave(STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); + const bossSpecies = globalScene.arena.randomSpecies(globalScene.currentBattle.waveIndex, level, 0, getPartyLuckValue(globalScene.getPlayerParty()), true); + const bossPokemon = new EnemyPokemon(bossSpecies, level, TrainerSlot.NONE, true); encounter.setDialogueToken("enemyPokemon", getPokemonNameWithAffix(bossPokemon)); const config: EnemyPartyConfig = { pokemonConfigs: [{ @@ -146,36 +146,36 @@ export const TeleportingHijinksEncounter: MysteryEncounter = }], }; - const magnet = generateModifierTypeOption(scene, modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.STEEL ])!; - const metalCoat = generateModifierTypeOption(scene, modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.ELECTRIC ])!; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: [ magnet, metalCoat ], fillRemaining: true }); - await transitionMysteryEncounterIntroVisuals(scene, true, true); - await initBattleWithEnemyConfig(scene, config); + const magnet = generateModifierTypeOption(modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.STEEL ])!; + const metalCoat = generateModifierTypeOption(modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.ELECTRIC ])!; + setEncounterRewards({ guaranteedModifierTypeOptions: [ magnet, metalCoat ], fillRemaining: true }); + await transitionMysteryEncounterIntroVisuals(true, true); + await initBattleWithEnemyConfig(config); } ) .build(); -async function doBiomeTransitionDialogueAndBattleInit(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter!; +async function doBiomeTransitionDialogueAndBattleInit() { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate new biome (cannot be current biome) - const filteredBiomes = BIOME_CANDIDATES.filter(b => scene.arena.biomeType !== b); + const filteredBiomes = BIOME_CANDIDATES.filter(b => globalScene.arena.biomeType !== b); const newBiome = filteredBiomes[randSeedInt(filteredBiomes.length)]; // Show dialogue and transition biome - await showEncounterText(scene, `${namespace}:transport`); - await Promise.all([ animateBiomeChange(scene, newBiome), transitionMysteryEncounterIntroVisuals(scene) ]); - scene.playBgm(); - await showEncounterText(scene, `${namespace}:attacked`); + await showEncounterText(`${namespace}:transport`); + await Promise.all([ animateBiomeChange(newBiome), transitionMysteryEncounterIntroVisuals() ]); + globalScene.playBgm(); + await showEncounterText(`${namespace}:attacked`); // Init enemy - const level = getEncounterPokemonLevelForWave(scene, STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); - const bossSpecies = scene.arena.randomSpecies(scene.currentBattle.waveIndex, level, 0, getPartyLuckValue(scene.getPlayerParty()), true); - const bossPokemon = new EnemyPokemon(scene, bossSpecies, level, TrainerSlot.NONE, true); + const level = getEncounterPokemonLevelForWave(STANDARD_ENCOUNTER_BOOSTED_LEVEL_MODIFIER); + const bossSpecies = globalScene.arena.randomSpecies(globalScene.currentBattle.waveIndex, level, 0, getPartyLuckValue(globalScene.getPlayerParty()), true); + const bossPokemon = new EnemyPokemon(bossSpecies, level, TrainerSlot.NONE, true); encounter.setDialogueToken("enemyPokemon", getPokemonNameWithAffix(bossPokemon)); // Defense/Spd buffs below wave 50, +1 to all stats otherwise - const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = scene.currentBattle.waveIndex < 50 ? + const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = globalScene.currentBattle.waveIndex < 50 ? [ Stat.DEF, Stat.SPDEF, Stat.SPD ] : [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD ]; @@ -187,8 +187,8 @@ async function doBiomeTransitionDialogueAndBattleInit(scene: BattleScene) { isBoss: true, tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - queueEncounterMessage(pokemon.scene, `${namespace}:boss_enraged`); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); + queueEncounterMessage(`${namespace}:boss_enraged`); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); } }], }; @@ -196,46 +196,46 @@ async function doBiomeTransitionDialogueAndBattleInit(scene: BattleScene) { return config; } -async function animateBiomeChange(scene: BattleScene, nextBiome: Biome) { +async function animateBiomeChange(nextBiome: Biome) { return new Promise(resolve => { - scene.tweens.add({ - targets: [ scene.arenaEnemy, scene.lastEnemyTrainer ], + globalScene.tweens.add({ + targets: [ globalScene.arenaEnemy, globalScene.lastEnemyTrainer ], x: "+=300", duration: 2000, onComplete: () => { - scene.newArena(nextBiome); + globalScene.newArena(nextBiome); const biomeKey = getBiomeKey(nextBiome); const bgTexture = `${biomeKey}_bg`; - scene.arenaBgTransition.setTexture(bgTexture); - scene.arenaBgTransition.setAlpha(0); - scene.arenaBgTransition.setVisible(true); - scene.arenaPlayerTransition.setBiome(nextBiome); - scene.arenaPlayerTransition.setAlpha(0); - scene.arenaPlayerTransition.setVisible(true); - - scene.tweens.add({ - targets: [ scene.arenaPlayer, scene.arenaBgTransition, scene.arenaPlayerTransition ], + globalScene.arenaBgTransition.setTexture(bgTexture); + globalScene.arenaBgTransition.setAlpha(0); + globalScene.arenaBgTransition.setVisible(true); + globalScene.arenaPlayerTransition.setBiome(nextBiome); + globalScene.arenaPlayerTransition.setAlpha(0); + globalScene.arenaPlayerTransition.setVisible(true); + + globalScene.tweens.add({ + targets: [ globalScene.arenaPlayer, globalScene.arenaBgTransition, globalScene.arenaPlayerTransition ], duration: 1000, ease: "Sine.easeInOut", - alpha: (target: any) => target === scene.arenaPlayer ? 0 : 1, + alpha: (target: any) => target === globalScene.arenaPlayer ? 0 : 1, onComplete: () => { - scene.arenaBg.setTexture(bgTexture); - scene.arenaPlayer.setBiome(nextBiome); - scene.arenaPlayer.setAlpha(1); - scene.arenaEnemy.setBiome(nextBiome); - scene.arenaEnemy.setAlpha(1); - scene.arenaNextEnemy.setBiome(nextBiome); - scene.arenaBgTransition.setVisible(false); - scene.arenaPlayerTransition.setVisible(false); - if (scene.lastEnemyTrainer) { - scene.lastEnemyTrainer.destroy(); + globalScene.arenaBg.setTexture(bgTexture); + globalScene.arenaPlayer.setBiome(nextBiome); + globalScene.arenaPlayer.setAlpha(1); + globalScene.arenaEnemy.setBiome(nextBiome); + globalScene.arenaEnemy.setAlpha(1); + globalScene.arenaNextEnemy.setBiome(nextBiome); + globalScene.arenaBgTransition.setVisible(false); + globalScene.arenaPlayerTransition.setVisible(false); + if (globalScene.lastEnemyTrainer) { + globalScene.lastEnemyTrainer.destroy(); } resolve(); - scene.tweens.add({ - targets: scene.arenaEnemy, + globalScene.tweens.add({ + targets: globalScene.arenaEnemy, x: "-=300", }); } diff --git a/src/data/mystery-encounters/encounters/the-expert-pokemon-breeder-encounter.ts b/src/data/mystery-encounters/encounters/the-expert-pokemon-breeder-encounter.ts index 5ac9852f27ac..93a55f1aed00 100644 --- a/src/data/mystery-encounters/encounters/the-expert-pokemon-breeder-encounter.ts +++ b/src/data/mystery-encounters/encounters/the-expert-pokemon-breeder-encounter.ts @@ -1,7 +1,7 @@ import { EnemyPartyConfig, generateModifierType, handleMysteryEncounterBattleFailed, initBattleWithEnemyConfig, setEncounterRewards, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { trainerConfigs } from "#app/data/trainer-config"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { randSeedShuffle } from "#app/utils"; import MysteryEncounter, { MysteryEncounterBuilder } from "../mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -93,14 +93,14 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = text: `${namespace}:intro_dialogue`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; - const waveIndex = scene.currentBattle.waveIndex; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; + const waveIndex = globalScene.currentBattle.waveIndex; // Calculates what trainers are available for battle in the encounter // If player is in space biome, uses special "Space" version of the trainer encounter.enemyPartyConfigs = [ - getPartyConfig(scene) + getPartyConfig() ]; const cleffaSpecies = waveIndex < FIRST_STAGE_EVOLUTION_WAVE ? Species.CLEFFA : waveIndex < FINAL_STAGE_EVOLUTION_WAVE ? Species.CLEFAIRY : Species.CLEFABLE; @@ -125,7 +125,7 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = ]; // Determine the 3 pokemon the player can battle with - let partyCopy = scene.getPlayerParty().slice(0); + let partyCopy = globalScene.getPlayerParty().slice(0); partyCopy = partyCopy .filter(p => p.isAllowedInBattle()) .sort((a, b) => a.friendship - b.friendship); @@ -139,7 +139,7 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = // Dialogue and egg calcs for Pokemon 1 const [ pokemon1CommonEggs, pokemon1RareEggs ] = calculateEggRewardsForPokemon(pokemon1); - let pokemon1Tooltip = getEncounterText(scene, `${namespace}:option.1.tooltip_base`)!; + let pokemon1Tooltip = getEncounterText(`${namespace}:option.1.tooltip_base`)!; if (pokemon1RareEggs > 0) { const eggsText = i18next.t(`${namespace}:numEggs`, { count: pokemon1RareEggs, rarity: i18next.t("egg:greatTier") }); pokemon1Tooltip += i18next.t(`${namespace}:eggs_tooltip`, { eggs: eggsText }); @@ -154,7 +154,7 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = // Dialogue and egg calcs for Pokemon 2 const [ pokemon2CommonEggs, pokemon2RareEggs ] = calculateEggRewardsForPokemon(pokemon2); - let pokemon2Tooltip = getEncounterText(scene, `${namespace}:option.2.tooltip_base`)!; + let pokemon2Tooltip = getEncounterText(`${namespace}:option.2.tooltip_base`)!; if (pokemon2RareEggs > 0) { const eggsText = i18next.t(`${namespace}:numEggs`, { count: pokemon2RareEggs, rarity: i18next.t("egg:greatTier") }); pokemon2Tooltip += i18next.t(`${namespace}:eggs_tooltip`, { eggs: eggsText }); @@ -169,7 +169,7 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = // Dialogue and egg calcs for Pokemon 3 const [ pokemon3CommonEggs, pokemon3RareEggs ] = calculateEggRewardsForPokemon(pokemon3); - let pokemon3Tooltip = getEncounterText(scene, `${namespace}:option.3.tooltip_base`)!; + let pokemon3Tooltip = getEncounterText(`${namespace}:option.3.tooltip_base`)!; if (pokemon3RareEggs > 0) { const eggsText = i18next.t(`${namespace}:numEggs`, { count: pokemon3RareEggs, rarity: i18next.t("egg:greatTier") }); pokemon3Tooltip += i18next.t(`${namespace}:eggs_tooltip`, { eggs: eggsText }); @@ -212,22 +212,22 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Spawn battle with first pokemon const config: EnemyPartyConfig = encounter.enemyPartyConfigs[0]; const { pokemon1, pokemon1CommonEggs, pokemon1RareEggs } = encounter.misc; encounter.misc.chosenPokemon = pokemon1; encounter.setDialogueToken("chosenPokemon", pokemon1.getNameToRender()); - const eggOptions = getEggOptions(scene, pokemon1CommonEggs, pokemon1RareEggs); - setEncounterRewards(scene, + const eggOptions = getEggOptions(pokemon1CommonEggs, pokemon1RareEggs); + setEncounterRewards( { guaranteedModifierTypeFuncs: [ modifierTypes.SOOTHE_BELL ], fillRemaining: true }, eggOptions, - () => doPostEncounterCleanup(scene)); + () => doPostEncounterCleanup()); // Remove all Pokemon from the party except the chosen Pokemon - removePokemonFromPartyAndStoreHeldItems(scene, encounter, pokemon1); + removePokemonFromPartyAndStoreHeldItems(encounter, pokemon1); // Configure outro dialogue for egg rewards encounter.dialogue.outro = [ @@ -248,7 +248,7 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = } encounter.onGameOver = onGameOver; - await initBattleWithEnemyConfig(scene, config); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -264,22 +264,22 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Spawn battle with second pokemon const config: EnemyPartyConfig = encounter.enemyPartyConfigs[0]; const { pokemon2, pokemon2CommonEggs, pokemon2RareEggs } = encounter.misc; encounter.misc.chosenPokemon = pokemon2; encounter.setDialogueToken("chosenPokemon", pokemon2.getNameToRender()); - const eggOptions = getEggOptions(scene, pokemon2CommonEggs, pokemon2RareEggs); - setEncounterRewards(scene, + const eggOptions = getEggOptions(pokemon2CommonEggs, pokemon2RareEggs); + setEncounterRewards( { guaranteedModifierTypeFuncs: [ modifierTypes.SOOTHE_BELL ], fillRemaining: true }, eggOptions, - () => doPostEncounterCleanup(scene)); + () => doPostEncounterCleanup()); // Remove all Pokemon from the party except the chosen Pokemon - removePokemonFromPartyAndStoreHeldItems(scene, encounter, pokemon2); + removePokemonFromPartyAndStoreHeldItems(encounter, pokemon2); // Configure outro dialogue for egg rewards encounter.dialogue.outro = [ @@ -300,7 +300,7 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = } encounter.onGameOver = onGameOver; - await initBattleWithEnemyConfig(scene, config); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -316,22 +316,22 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Spawn battle with third pokemon const config: EnemyPartyConfig = encounter.enemyPartyConfigs[0]; const { pokemon3, pokemon3CommonEggs, pokemon3RareEggs } = encounter.misc; encounter.misc.chosenPokemon = pokemon3; encounter.setDialogueToken("chosenPokemon", pokemon3.getNameToRender()); - const eggOptions = getEggOptions(scene, pokemon3CommonEggs, pokemon3RareEggs); - setEncounterRewards(scene, + const eggOptions = getEggOptions(pokemon3CommonEggs, pokemon3RareEggs); + setEncounterRewards( { guaranteedModifierTypeFuncs: [ modifierTypes.SOOTHE_BELL ], fillRemaining: true }, eggOptions, - () => doPostEncounterCleanup(scene)); + () => doPostEncounterCleanup()); // Remove all Pokemon from the party except the chosen Pokemon - removePokemonFromPartyAndStoreHeldItems(scene, encounter, pokemon3); + removePokemonFromPartyAndStoreHeldItems(encounter, pokemon3); // Configure outro dialogue for egg rewards encounter.dialogue.outro = [ @@ -352,7 +352,7 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = } encounter.onGameOver = onGameOver; - await initBattleWithEnemyConfig(scene, config); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -364,9 +364,9 @@ export const TheExpertPokemonBreederEncounter: MysteryEncounter = ]) .build(); -function getPartyConfig(scene: BattleScene): EnemyPartyConfig { +function getPartyConfig(): EnemyPartyConfig { // Bug type superfan trainer config - const waveIndex = scene.currentBattle.waveIndex; + const waveIndex = globalScene.currentBattle.waveIndex; const breederConfig = trainerConfigs[TrainerType.EXPERT_POKEMON_BREEDER].clone(); breederConfig.name = i18next.t(trainerNameKey); @@ -386,14 +386,14 @@ function getPartyConfig(scene: BattleScene): EnemyPartyConfig { ivs: [ 31, 31, 31, 31, 31, 31 ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.TERA_SHARD, [ Type.STEEL ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.TERA_SHARD, [ Type.STEEL ]) as PokemonHeldItemModifierType, } ] } ] }; - if (scene.arena.biomeType === Biome.SPACE) { + if (globalScene.arena.biomeType === Biome.SPACE) { // All 3 members always Cleffa line, but different configs baseConfig.pokemonConfigs!.push({ nickname: i18next.t(`${namespace}:cleffa_2_nickname`, { speciesName: getPokemonSpecies(cleffaSpecies).getName() }), @@ -476,14 +476,13 @@ function calculateEggRewardsForPokemon(pokemon: PlayerPokemon): [number, number] return [ numCommons, numRares ]; } -function getEggOptions(scene: BattleScene, commonEggs: number, rareEggs: number) { +function getEggOptions(commonEggs: number, rareEggs: number) { const eggDescription = i18next.t(`${namespace}:title`) + ":\n" + i18next.t(trainerNameKey); const eggOptions: IEggOptions[] = []; if (commonEggs > 0) { for (let i = 0; i < commonEggs; i++) { eggOptions.push({ - scene, pulled: false, sourceType: EggSourceType.EVENT, eggDescriptor: eggDescription, @@ -494,7 +493,6 @@ function getEggOptions(scene: BattleScene, commonEggs: number, rareEggs: number) if (rareEggs > 0) { for (let i = 0; i < rareEggs; i++) { eggOptions.push({ - scene, pulled: false, sourceType: EggSourceType.EVENT, eggDescriptor: eggDescription, @@ -506,36 +504,36 @@ function getEggOptions(scene: BattleScene, commonEggs: number, rareEggs: number) return eggOptions; } -function removePokemonFromPartyAndStoreHeldItems(scene: BattleScene, encounter: MysteryEncounter, chosenPokemon: PlayerPokemon) { - const party = scene.getPlayerParty(); +function removePokemonFromPartyAndStoreHeldItems(encounter: MysteryEncounter, chosenPokemon: PlayerPokemon) { + const party = globalScene.getPlayerParty(); const chosenIndex = party.indexOf(chosenPokemon); party[chosenIndex] = party[0]; party[0] = chosenPokemon; - encounter.misc.originalParty = scene.getPlayerParty().slice(1); + encounter.misc.originalParty = globalScene.getPlayerParty().slice(1); encounter.misc.originalPartyHeldItems = encounter.misc.originalParty .map(p => p.getHeldItems()); - scene["party"] = [ + globalScene["party"] = [ chosenPokemon ]; } -function restorePartyAndHeldItems(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter!; +function restorePartyAndHeldItems() { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Restore original party - scene.getPlayerParty().push(...encounter.misc.originalParty); + globalScene.getPlayerParty().push(...encounter.misc.originalParty); // Restore held items const originalHeldItems = encounter.misc.originalPartyHeldItems; originalHeldItems.forEach((pokemonHeldItemsList: PokemonHeldItemModifier[]) => { pokemonHeldItemsList.forEach(heldItem => { - scene.addModifier(heldItem, true, false, false, true); + globalScene.addModifier(heldItem, true, false, false, true); }); }); - scene.updateModifiers(true); + globalScene.updateModifiers(true); } -function onGameOver(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter!; +function onGameOver() { + const encounter = globalScene.currentBattle.mysteryEncounter!; encounter.dialogue.outro = [ { @@ -545,7 +543,7 @@ function onGameOver(scene: BattleScene) { ]; // Restore original party, player loses all friendship with chosen mon (it remains fainted) - restorePartyAndHeldItems(scene); + restorePartyAndHeldItems(); const chosenPokemon = encounter.misc.chosenPokemon; chosenPokemon.friendship = 0; @@ -556,33 +554,33 @@ function onGameOver(scene: BattleScene) { encounter.misc.encounterFailed = true; // Revert BGM - scene.playBgm(scene.arena.bgm); + globalScene.playBgm(globalScene.arena.bgm); // Clear any leftover battle phases - scene.clearPhaseQueue(); - scene.clearPhaseQueueSplice(); + globalScene.clearPhaseQueue(); + globalScene.clearPhaseQueueSplice(); // Return enemy Pokemon - const pokemon = scene.getEnemyPokemon(); + const pokemon = globalScene.getEnemyPokemon(); if (pokemon) { - scene.playSound("se/pb_rel"); + globalScene.playSound("se/pb_rel"); pokemon.hideInfo(); pokemon.tint(getPokeballTintColor(pokemon.pokeball), 1, 250, "Sine.easeIn"); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, duration: 250, ease: "Sine.easeIn", scale: 0.5, onComplete: () => { - scene.field.remove(pokemon, true); + globalScene.field.remove(pokemon, true); } }); } // Show the enemy trainer - scene.time.delayedCall(250, () => { - const sprites = scene.currentBattle.trainer?.getSprites(); - const tintSprites = scene.currentBattle.trainer?.getTintSprites(); + globalScene.time.delayedCall(250, () => { + const sprites = globalScene.currentBattle.trainer?.getSprites(); + const tintSprites = globalScene.currentBattle.trainer?.getTintSprites(); if (sprites && tintSprites) { for (let i = 0; i < sprites.length; i++) { sprites[i].setVisible(true); @@ -591,8 +589,8 @@ function onGameOver(scene: BattleScene) { tintSprites[i].clearTint(); } } - scene.tweens.add({ - targets: scene.currentBattle.trainer, + globalScene.tweens.add({ + targets: globalScene.currentBattle.trainer, x: "-=16", y: "+=16", alpha: 1, @@ -602,16 +600,16 @@ function onGameOver(scene: BattleScene) { }); - handleMysteryEncounterBattleFailed(scene, true); + handleMysteryEncounterBattleFailed(true); return false; } -function doPostEncounterCleanup(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter!; +function doPostEncounterCleanup() { + const encounter = globalScene.currentBattle.mysteryEncounter!; if (!encounter.misc.encounterFailed) { // Give 20 friendship to the chosen pokemon encounter.misc.chosenPokemon.addFriendship(FRIENDSHIP_ADDED); - restorePartyAndHeldItems(scene); + restorePartyAndHeldItems(); } } diff --git a/src/data/mystery-encounters/encounters/the-pokemon-salesman-encounter.ts b/src/data/mystery-encounters/encounters/the-pokemon-salesman-encounter.ts index feb6e68d1d17..ed6579165726 100644 --- a/src/data/mystery-encounters/encounters/the-pokemon-salesman-encounter.ts +++ b/src/data/mystery-encounters/encounters/the-pokemon-salesman-encounter.ts @@ -1,7 +1,7 @@ import { leaveEncounterWithoutBattle, transitionMysteryEncounterIntroVisuals, updatePlayerMoney, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { isNullOrUndefined, randSeedInt } from "#app/utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MoneyRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; import { catchPokemon, getRandomSpeciesByStarterCost, getSpriteKeysFromPokemon } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils"; @@ -58,8 +58,8 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; let species = getSalesmanSpeciesOffer(); let tries = 0; @@ -74,9 +74,9 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = if (randSeedInt(SHINY_MAGIKARP_WEIGHT) === 0 || isNullOrUndefined(species.abilityHidden) || species.abilityHidden === Abilities.NONE) { // If no HA mon found or you roll 1%, give shiny Magikarp with random variant species = getPokemonSpecies(Species.MAGIKARP); - pokemon = new PlayerPokemon(scene, species, 5, 2, species.formIndex, undefined, true); + pokemon = new PlayerPokemon(species, 5, 2, species.formIndex, undefined, true); } else { - pokemon = new PlayerPokemon(scene, species, 5, 2, species.formIndex); + pokemon = new PlayerPokemon(species, 5, 2, species.formIndex); } pokemon.generateAndPopulateMoveset(); @@ -101,7 +101,7 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = encounter.dialogue.encounterOptionsDialogue!.description = `${namespace}:description_shiny`; encounter.options[0].dialogue!.buttonTooltip = `${namespace}:option.1.tooltip_shiny`; } - const price = scene.getWaveMoneyAmount(priceMultiplier); + const price = globalScene.getWaveMoneyAmount(priceMultiplier); encounter.setDialogueToken("purchasePokemon", pokemon.getNameToRender()); encounter.setDialogueToken("price", price.toString()); encounter.misc = { @@ -127,24 +127,24 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = } ], }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const price = encounter.misc.price; const purchasedPokemon = encounter.misc.pokemon as PlayerPokemon; // Update money - updatePlayerMoney(scene, -price, true, false); + updatePlayerMoney(-price, true, false); // Show dialogue - await showEncounterDialogue(scene, `${namespace}:option.1.selected_dialogue`, `${namespace}:speaker`); - await transitionMysteryEncounterIntroVisuals(scene); + await showEncounterDialogue(`${namespace}:option.1.selected_dialogue`, `${namespace}:speaker`); + await transitionMysteryEncounterIntroVisuals(); // "Catch" purchased pokemon const data = new PokemonData(purchasedPokemon); data.player = false; - await catchPokemon(scene, data.toPokemon(scene) as EnemyPokemon, null, PokeballType.POKEBALL, true, true); + await catchPokemon(data.toPokemon() as EnemyPokemon, null, PokeballType.POKEBALL, true, true); - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -158,9 +158,9 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) diff --git a/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts b/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts index c5cfd3f954e1..838b4cdd3774 100644 --- a/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts +++ b/src/data/mystery-encounters/encounters/the-strong-stuff-encounter.ts @@ -1,7 +1,7 @@ import { EnemyPartyConfig, initBattleWithEnemyConfig, loadCustomMovesForEncounter, leaveEncounterWithoutBattle, setEncounterRewards, transitionMysteryEncounterIntroVisuals, generateModifierType } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { modifierTypes, PokemonHeldItemModifierType, } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { getPokemonSpecies } from "#app/data/pokemon-species"; import { Species } from "#enums/species"; @@ -67,8 +67,8 @@ export const TheStrongStuffEncounter: MysteryEncounter = text: `${namespace}:intro`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate boss mon const config: EnemyPartyConfig = { @@ -85,26 +85,26 @@ export const TheStrongStuffEncounter: MysteryEncounter = moveSet: [ Moves.INFESTATION, Moves.SALT_CURE, Moves.GASTRO_ACID, Moves.HEAL_ORDER ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.ENIGMA ]) as PokemonHeldItemModifierType + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.ENIGMA ]) as PokemonHeldItemModifierType }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.APICOT ]) as PokemonHeldItemModifierType + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.APICOT ]) as PokemonHeldItemModifierType }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.GANLON ]) as PokemonHeldItemModifierType + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.GANLON ]) as PokemonHeldItemModifierType }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.LUM ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.LUM ]) as PokemonHeldItemModifierType, stackCount: 2 } ], tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - queueEncounterMessage(pokemon.scene, `${namespace}:option.2.stat_boost`); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, [ Stat.DEF, Stat.SPDEF ], 2)); + queueEncounterMessage(`${namespace}:option.2.stat_boost`); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, [ Stat.DEF, Stat.SPDEF ], 2)); } } ], @@ -112,7 +112,7 @@ export const TheStrongStuffEncounter: MysteryEncounter = encounter.enemyPartyConfigs = [ config ]; - loadCustomMovesForEncounter(scene, [ Moves.GASTRO_ACID, Moves.STEALTH_ROCK ]); + loadCustomMovesForEncounter([ Moves.GASTRO_ACID, Moves.STEALTH_ROCK ]); encounter.setDialogueToken("shuckleName", getPokemonSpecies(Species.SHUCKLE).getName()); @@ -132,16 +132,16 @@ export const TheStrongStuffEncounter: MysteryEncounter = } ] }, - async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Do blackout and hide intro visuals during blackout - scene.time.delayedCall(750, () => { - transitionMysteryEncounterIntroVisuals(scene, true, true, 50); + globalScene.time.delayedCall(750, () => { + transitionMysteryEncounterIntroVisuals(true, true, 50); }); // -15 to all base stats of highest BST (halved for HP), +10 to all base stats of rest of party (halved for HP) // Sort party by bst - const sortedParty = scene.getPlayerParty().slice(0) + const sortedParty = globalScene.getPlayerParty().slice(0) .sort((pokemon1, pokemon2) => { const pokemon1Bst = pokemon1.calculateBaseStats().reduce((a, b) => a + b, 0); const pokemon2Bst = pokemon2.calculateBaseStats().reduce((a, b) => a + b, 0); @@ -161,15 +161,15 @@ export const TheStrongStuffEncounter: MysteryEncounter = encounter.setDialogueToken("reductionValue", HIGH_BST_REDUCTION_VALUE.toString()); encounter.setDialogueToken("increaseValue", BST_INCREASE_VALUE.toString()); - await showEncounterText(scene, `${namespace}:option.1.selected_2`, null, undefined, true); + await showEncounterText(`${namespace}:option.1.selected_2`, null, undefined, true); encounter.dialogue.outro = [ { text: `${namespace}:outro`, } ]; - setEncounterRewards(scene, { fillRemaining: true }); - leaveEncounterWithoutBattle(scene, true); + setEncounterRewards({ fillRemaining: true }); + leaveEncounterWithoutBattle(true); return true; } ) @@ -183,10 +183,10 @@ export const TheStrongStuffEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Pick battle - const encounter = scene.currentBattle.mysteryEncounter!; - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.SOUL_DEW ], fillRemaining: true }); + const encounter = globalScene.currentBattle.mysteryEncounter!; + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.SOUL_DEW ], fillRemaining: true }); encounter.startOfBattleEffects.push( { sourceBattlerIndex: BattlerIndex.ENEMY, @@ -202,8 +202,8 @@ export const TheStrongStuffEncounter: MysteryEncounter = }); encounter.dialogue.outro = []; - await transitionMysteryEncounterIntroVisuals(scene, true, true, 500); - await initBattleWithEnemyConfig(scene, encounter.enemyPartyConfigs[0]); + await transitionMysteryEncounterIntroVisuals(true, true, 500); + await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); } ) .build(); diff --git a/src/data/mystery-encounters/encounters/the-winstrate-challenge-encounter.ts b/src/data/mystery-encounters/encounters/the-winstrate-challenge-encounter.ts index f44462418737..1cb2c1264d4e 100644 --- a/src/data/mystery-encounters/encounters/the-winstrate-challenge-encounter.ts +++ b/src/data/mystery-encounters/encounters/the-winstrate-challenge-encounter.ts @@ -1,7 +1,7 @@ import { EnemyPartyConfig, generateModifierType, generateModifierTypeOption, initBattleWithEnemyConfig, leaveEncounterWithoutBattle, setEncounterRewards, transitionMysteryEncounterIntroVisuals, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { modifierTypes, PokemonHeldItemModifierType } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { TrainerType } from "#enums/trainer-type"; @@ -83,15 +83,15 @@ export const TheWinstrateChallengeEncounter: MysteryEncounter = }, ]) .withAutoHideIntroVisuals(false) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Loaded back to front for pop() operations - encounter.enemyPartyConfigs.push(getVitoTrainerConfig(scene)); - encounter.enemyPartyConfigs.push(getVickyTrainerConfig(scene)); - encounter.enemyPartyConfigs.push(getViviTrainerConfig(scene)); - encounter.enemyPartyConfigs.push(getVictoriaTrainerConfig(scene)); - encounter.enemyPartyConfigs.push(getVictorTrainerConfig(scene)); + encounter.enemyPartyConfigs.push(getVitoTrainerConfig()); + encounter.enemyPartyConfigs.push(getVickyTrainerConfig()); + encounter.enemyPartyConfigs.push(getViviTrainerConfig()); + encounter.enemyPartyConfigs.push(getVictoriaTrainerConfig()); + encounter.enemyPartyConfigs.push(getVictorTrainerConfig()); return true; }) @@ -110,13 +110,13 @@ export const TheWinstrateChallengeEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Spawn 5 trainer battles back to back with Macho Brace in rewards - scene.currentBattle.mysteryEncounter!.doContinueEncounter = async (scene: BattleScene) => { - await endTrainerBattleAndShowDialogue(scene); + globalScene.currentBattle.mysteryEncounter!.doContinueEncounter = async () => { + await endTrainerBattleAndShowDialogue(); }; - await transitionMysteryEncounterIntroVisuals(scene, true, false); - await spawnNextTrainerOrEndEncounter(scene); + await transitionMysteryEncounterIntroVisuals(true, false); + await spawnNextTrainerOrEndEncounter(); } ) .withSimpleOption( @@ -130,47 +130,47 @@ export const TheWinstrateChallengeEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Refuse the challenge, they full heal the party and give the player a Rarer Candy - scene.unshiftPhase(new PartyHealPhase(scene, true)); - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.RARER_CANDY ], fillRemaining: false }); - leaveEncounterWithoutBattle(scene); + globalScene.unshiftPhase(new PartyHealPhase(true)); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.RARER_CANDY ], fillRemaining: false }); + leaveEncounterWithoutBattle(); } ) .build(); -async function spawnNextTrainerOrEndEncounter(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter!; +async function spawnNextTrainerOrEndEncounter() { + const encounter = globalScene.currentBattle.mysteryEncounter!; const nextConfig = encounter.enemyPartyConfigs.pop(); if (!nextConfig) { - await transitionMysteryEncounterIntroVisuals(scene, false, false); - await showEncounterDialogue(scene, `${namespace}:victory`, `${namespace}:speaker`); + await transitionMysteryEncounterIntroVisuals(false, false); + await showEncounterDialogue(`${namespace}:victory`, `${namespace}:speaker`); // Give 10x Voucher const newModifier = modifierTypes.VOUCHER_PREMIUM().newModifier(); - await scene.addModifier(newModifier); - scene.playSound("item_fanfare"); - await showEncounterText(scene, i18next.t("battle:rewardGain", { modifierName: newModifier?.type.name })); + await globalScene.addModifier(newModifier); + globalScene.playSound("item_fanfare"); + await showEncounterText(i18next.t("battle:rewardGain", { modifierName: newModifier?.type.name })); - await showEncounterDialogue(scene, `${namespace}:victory_2`, `${namespace}:speaker`); - scene.ui.clearText(); // Clears "Winstrate" title from screen as rewards get animated in - const machoBrace = generateModifierTypeOption(scene, modifierTypes.MYSTERY_ENCOUNTER_MACHO_BRACE)!; + await showEncounterDialogue(`${namespace}:victory_2`, `${namespace}:speaker`); + globalScene.ui.clearText(); // Clears "Winstrate" title from screen as rewards get animated in + const machoBrace = generateModifierTypeOption(modifierTypes.MYSTERY_ENCOUNTER_MACHO_BRACE)!; machoBrace.type.tier = ModifierTier.MASTER; - setEncounterRewards(scene, { guaranteedModifierTypeOptions: [ machoBrace ], fillRemaining: false }); + setEncounterRewards({ guaranteedModifierTypeOptions: [ machoBrace ], fillRemaining: false }); encounter.doContinueEncounter = undefined; - leaveEncounterWithoutBattle(scene, false, MysteryEncounterMode.NO_BATTLE); + leaveEncounterWithoutBattle(false, MysteryEncounterMode.NO_BATTLE); } else { - await initBattleWithEnemyConfig(scene, nextConfig); + await initBattleWithEnemyConfig(nextConfig); } } -function endTrainerBattleAndShowDialogue(scene: BattleScene): Promise { +function endTrainerBattleAndShowDialogue(): Promise { return new Promise(async resolve => { - if (scene.currentBattle.mysteryEncounter!.enemyPartyConfigs.length === 0) { + if (globalScene.currentBattle.mysteryEncounter!.enemyPartyConfigs.length === 0) { // Battle is over - const trainer = scene.currentBattle.trainer; + const trainer = globalScene.currentBattle.trainer; if (trainer) { - scene.tweens.add({ + globalScene.tweens.add({ targets: trainer, x: "+=16", y: "-=16", @@ -178,38 +178,38 @@ function endTrainerBattleAndShowDialogue(scene: BattleScene): Promise { ease: "Sine.easeInOut", duration: 750, onComplete: () => { - scene.field.remove(trainer, true); + globalScene.field.remove(trainer, true); } }); } - await spawnNextTrainerOrEndEncounter(scene); + await spawnNextTrainerOrEndEncounter(); resolve(); // Wait for all dialogue/post battle stuff to complete before resolving } else { - scene.arena.resetArenaEffects(); - const playerField = scene.getPlayerField(); + globalScene.arena.resetArenaEffects(); + const playerField = globalScene.getPlayerField(); playerField.forEach((pokemon) => pokemon.lapseTag(BattlerTagType.COMMANDED)); - playerField.forEach((_, p) => scene.unshiftPhase(new ReturnPhase(scene, p))); + playerField.forEach((_, p) => globalScene.unshiftPhase(new ReturnPhase(p))); - for (const pokemon of scene.getPlayerParty()) { + for (const pokemon of globalScene.getPlayerParty()) { // Only trigger form change when Eiscue is in Noice form // Hardcoded Eiscue for now in case it is fused with another pokemon if (pokemon.species.speciesId === Species.EISCUE && pokemon.hasAbility(Abilities.ICE_FACE) && pokemon.formIndex === 1) { - scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger); } pokemon.resetBattleData(); applyPostBattleInitAbAttrs(PostBattleInitAbAttr, pokemon); } - scene.unshiftPhase(new ShowTrainerPhase(scene)); + globalScene.unshiftPhase(new ShowTrainerPhase()); // Hide the trainer and init next battle - const trainer = scene.currentBattle.trainer; + const trainer = globalScene.currentBattle.trainer; // Unassign previous trainer from battle so it isn't destroyed before animation completes - scene.currentBattle.trainer = null; - await spawnNextTrainerOrEndEncounter(scene); + globalScene.currentBattle.trainer = null; + await spawnNextTrainerOrEndEncounter(); if (trainer) { - scene.tweens.add({ + globalScene.tweens.add({ targets: trainer, x: "+=16", y: "-=16", @@ -217,7 +217,7 @@ function endTrainerBattleAndShowDialogue(scene: BattleScene): Promise { ease: "Sine.easeInOut", duration: 750, onComplete: () => { - scene.field.remove(trainer, true); + globalScene.field.remove(trainer, true); resolve(); } }); @@ -226,7 +226,7 @@ function endTrainerBattleAndShowDialogue(scene: BattleScene): Promise { }); } -function getVictorTrainerConfig(scene: BattleScene): EnemyPartyConfig { +function getVictorTrainerConfig(): EnemyPartyConfig { return { trainerType: TrainerType.VICTOR, pokemonConfigs: [ @@ -238,11 +238,11 @@ function getVictorTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.FACADE, Moves.BRAVE_BIRD, Moves.PROTECT, Moves.QUICK_ATTACK ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.FLAME_ORB) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.FLAME_ORB) as PokemonHeldItemModifierType, isTransferable: false }, { - modifier: generateModifierType(scene, modifierTypes.FOCUS_BAND) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.FOCUS_BAND) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false }, @@ -256,11 +256,11 @@ function getVictorTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.FACADE, Moves.OBSTRUCT, Moves.NIGHT_SLASH, Moves.FIRE_PUNCH ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.FLAME_ORB) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.FLAME_ORB) as PokemonHeldItemModifierType, isTransferable: false }, { - modifier: generateModifierType(scene, modifierTypes.LEFTOVERS) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.LEFTOVERS) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false } @@ -270,7 +270,7 @@ function getVictorTrainerConfig(scene: BattleScene): EnemyPartyConfig { }; } -function getVictoriaTrainerConfig(scene: BattleScene): EnemyPartyConfig { +function getVictoriaTrainerConfig(): EnemyPartyConfig { return { trainerType: TrainerType.VICTORIA, pokemonConfigs: [ @@ -282,11 +282,11 @@ function getVictoriaTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.SYNTHESIS, Moves.SLUDGE_BOMB, Moves.GIGA_DRAIN, Moves.SLEEP_POWDER ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.SOUL_DEW) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.SOUL_DEW) as PokemonHeldItemModifierType, isTransferable: false }, { - modifier: generateModifierType(scene, modifierTypes.QUICK_CLAW) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.QUICK_CLAW) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false } @@ -300,12 +300,12 @@ function getVictoriaTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.PSYSHOCK, Moves.MOONBLAST, Moves.SHADOW_BALL, Moves.WILL_O_WISP ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.PSYCHIC ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.PSYCHIC ]) as PokemonHeldItemModifierType, stackCount: 1, isTransferable: false }, { - modifier: generateModifierType(scene, modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.FAIRY ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.ATTACK_TYPE_BOOSTER, [ Type.FAIRY ]) as PokemonHeldItemModifierType, stackCount: 1, isTransferable: false } @@ -315,7 +315,7 @@ function getVictoriaTrainerConfig(scene: BattleScene): EnemyPartyConfig { }; } -function getViviTrainerConfig(scene: BattleScene): EnemyPartyConfig { +function getViviTrainerConfig(): EnemyPartyConfig { return { trainerType: TrainerType.VIVI, pokemonConfigs: [ @@ -327,12 +327,12 @@ function getViviTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.WATERFALL, Moves.MEGAHORN, Moves.KNOCK_OFF, Moves.REST ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.LUM ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.LUM ]) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false }, { - modifier: generateModifierType(scene, modifierTypes.BASE_STAT_BOOSTER, [ Stat.HP ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BASE_STAT_BOOSTER, [ Stat.HP ]) as PokemonHeldItemModifierType, stackCount: 4, isTransferable: false } @@ -346,12 +346,12 @@ function getViviTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.SPORE, Moves.SWORDS_DANCE, Moves.SEED_BOMB, Moves.DRAIN_PUNCH ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.BASE_STAT_BOOSTER, [ Stat.HP ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BASE_STAT_BOOSTER, [ Stat.HP ]) as PokemonHeldItemModifierType, stackCount: 4, isTransferable: false }, { - modifier: generateModifierType(scene, modifierTypes.TOXIC_ORB) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.TOXIC_ORB) as PokemonHeldItemModifierType, isTransferable: false } ] @@ -364,7 +364,7 @@ function getViviTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.EARTH_POWER, Moves.FIRE_BLAST, Moves.YAWN, Moves.PROTECT ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.QUICK_CLAW) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.QUICK_CLAW) as PokemonHeldItemModifierType, stackCount: 3, isTransferable: false }, @@ -374,7 +374,7 @@ function getViviTrainerConfig(scene: BattleScene): EnemyPartyConfig { }; } -function getVickyTrainerConfig(scene: BattleScene): EnemyPartyConfig { +function getVickyTrainerConfig(): EnemyPartyConfig { return { trainerType: TrainerType.VICKY, pokemonConfigs: [ @@ -386,7 +386,7 @@ function getVickyTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.AXE_KICK, Moves.ICE_PUNCH, Moves.ZEN_HEADBUTT, Moves.BULLET_PUNCH ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType, isTransferable: false } ] @@ -395,7 +395,7 @@ function getVickyTrainerConfig(scene: BattleScene): EnemyPartyConfig { }; } -function getVitoTrainerConfig(scene: BattleScene): EnemyPartyConfig { +function getVitoTrainerConfig(): EnemyPartyConfig { return { trainerType: TrainerType.VITO, pokemonConfigs: [ @@ -407,7 +407,7 @@ function getVitoTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.THUNDERBOLT, Moves.GIGA_DRAIN, Moves.FOUL_PLAY, Moves.THUNDER_WAVE ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.BASE_STAT_BOOSTER, [ Stat.SPD ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BASE_STAT_BOOSTER, [ Stat.SPD ]) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false } @@ -421,47 +421,47 @@ function getVitoTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.SLUDGE_BOMB, Moves.GIGA_DRAIN, Moves.ICE_BEAM, Moves.EARTHQUAKE ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.APICOT ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.APICOT ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.GANLON ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.GANLON ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.STARF ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.STARF ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SALAC ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.SALAC ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.LUM ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.LUM ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.LANSAT ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.LANSAT ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.LIECHI ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.LIECHI ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.PETAYA ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.PETAYA ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.ENIGMA ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.ENIGMA ]) as PokemonHeldItemModifierType, stackCount: 2, }, { - modifier: generateModifierType(scene, modifierTypes.BERRY, [ BerryType.LEPPA ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.BERRY, [ BerryType.LEPPA ]) as PokemonHeldItemModifierType, stackCount: 2, } ] @@ -474,7 +474,7 @@ function getVitoTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.DRILL_PECK, Moves.QUICK_ATTACK, Moves.THRASH, Moves.KNOCK_OFF ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.KINGS_ROCK) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.KINGS_ROCK) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false } @@ -488,7 +488,7 @@ function getVitoTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.PSYCHIC, Moves.SHADOW_BALL, Moves.FOCUS_BLAST, Moves.THUNDERBOLT ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.WIDE_LENS) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.WIDE_LENS) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false }, @@ -502,7 +502,7 @@ function getVitoTrainerConfig(scene: BattleScene): EnemyPartyConfig { moveSet: [ Moves.EARTHQUAKE, Moves.U_TURN, Moves.FLARE_BLITZ, Moves.ROCK_SLIDE ], modifierConfigs: [ { - modifier: generateModifierType(scene, modifierTypes.QUICK_CLAW) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.QUICK_CLAW) as PokemonHeldItemModifierType, stackCount: 2, isTransferable: false }, diff --git a/src/data/mystery-encounters/encounters/training-session-encounter.ts b/src/data/mystery-encounters/encounters/training-session-encounter.ts index 725c4ba79eb7..46368b3f6324 100644 --- a/src/data/mystery-encounters/encounters/training-session-encounter.ts +++ b/src/data/mystery-encounters/encounters/training-session-encounter.ts @@ -10,7 +10,7 @@ import { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; import { isNullOrUndefined, randSeedShuffle } from "#app/utils"; import { BattlerTagType } from "#enums/battler-tag-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { queueEncounterMessage, showEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils"; @@ -71,8 +71,8 @@ export const TrainingSessionEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withPreOptionPhase(async (): Promise => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { encounter.misc = { playerPokemon: pokemon, @@ -81,24 +81,24 @@ export const TrainingSessionEncounter: MysteryEncounter = // Only Pokemon that are not KOed/legal can be trained const selectableFilter = (pokemon: Pokemon) => { - return isPokemonValidForEncounterOptionSelection(pokemon, scene, `${namespace}:invalid_selection`); + return isPokemonValidForEncounterOptionSelection(pokemon, `${namespace}:invalid_selection`); }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const playerPokemon: PlayerPokemon = encounter.misc.playerPokemon; // Spawn light training session with chosen pokemon // Every 50 waves, add +1 boss segment, capping at 5 const segments = Math.min( - 2 + Math.floor(scene.currentBattle.waveIndex / 50), + 2 + Math.floor(globalScene.currentBattle.waveIndex / 50), 5 ); const modifiers = new ModifiersHolder(); - const config = getEnemyConfig(scene, playerPokemon, segments, modifiers); - scene.removePokemonFromPlayerParty(playerPokemon, false); + const config = getEnemyConfig(playerPokemon, segments, modifiers); + globalScene.removePokemonFromPlayerParty(playerPokemon, false); const onBeforeRewardsPhase = () => { encounter.setDialogueToken("stat1", "-"); @@ -148,23 +148,23 @@ export const TrainingSessionEncounter: MysteryEncounter = if (improvedCount > 0) { playerPokemon.calculateStats(); - scene.gameData.updateSpeciesDexIvs(playerPokemon.species.getRootSpeciesId(true), playerPokemon.ivs); - scene.gameData.setPokemonCaught(playerPokemon, false); + globalScene.gameData.updateSpeciesDexIvs(playerPokemon.species.getRootSpeciesId(true), playerPokemon.ivs); + globalScene.gameData.setPokemonCaught(playerPokemon, false); } // Add pokemon and mods back - scene.getPlayerParty().push(playerPokemon); + globalScene.getPlayerParty().push(playerPokemon); for (const mod of modifiers.value) { mod.pokemonId = playerPokemon.id; - scene.addModifier(mod, true, false, false, true); + globalScene.addModifier(mod, true, false, false, true); } - scene.updateModifiers(true); - queueEncounterMessage(scene, `${namespace}:option.1.finished`); + globalScene.updateModifiers(true); + queueEncounterMessage(`${namespace}:option.1.finished`); }; - setEncounterRewards(scene, { fillRemaining: true }, undefined, onBeforeRewardsPhase); + setEncounterRewards({ fillRemaining: true }, undefined, onBeforeRewardsPhase); - await initBattleWithEnemyConfig(scene, config); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -182,15 +182,15 @@ export const TrainingSessionEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { + .withPreOptionPhase(async (): Promise => { // Open menu for selecting pokemon and Nature - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const natures = new Array(25).fill(null).map((val, i) => i as Nature); const onPokemonSelected = (pokemon: PlayerPokemon) => { // Return the options for nature selection return natures.map((nature: Nature) => { const option: OptionSelectItem = { - label: getNatureName(nature, true, true, true, scene.uiTheme), + label: getNatureName(nature, true, true, true, globalScene.uiTheme), handler: () => { // Pokemon and second option selected encounter.setDialogueToken("nature", getNatureName(nature)); @@ -207,40 +207,40 @@ export const TrainingSessionEncounter: MysteryEncounter = // Only Pokemon that are not KOed/legal can be trained const selectableFilter = (pokemon: Pokemon) => { - return isPokemonValidForEncounterOptionSelection(pokemon, scene, `${namespace}:invalid_selection`); + return isPokemonValidForEncounterOptionSelection(pokemon, `${namespace}:invalid_selection`); }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const playerPokemon: PlayerPokemon = encounter.misc.playerPokemon; // Spawn medium training session with chosen pokemon // Every 40 waves, add +1 boss segment, capping at 6 - const segments = Math.min(2 + Math.floor(scene.currentBattle.waveIndex / 40), 6); + const segments = Math.min(2 + Math.floor(globalScene.currentBattle.waveIndex / 40), 6); const modifiers = new ModifiersHolder(); - const config = getEnemyConfig(scene, playerPokemon, segments, modifiers); - scene.removePokemonFromPlayerParty(playerPokemon, false); + const config = getEnemyConfig(playerPokemon, segments, modifiers); + globalScene.removePokemonFromPlayerParty(playerPokemon, false); const onBeforeRewardsPhase = () => { - queueEncounterMessage(scene, `${namespace}:option.2.finished`); + queueEncounterMessage(`${namespace}:option.2.finished`); // Add the pokemon back to party with Nature change playerPokemon.setCustomNature(encounter.misc.chosenNature); - scene.gameData.unlockSpeciesNature(playerPokemon.species, encounter.misc.chosenNature); + globalScene.gameData.unlockSpeciesNature(playerPokemon.species, encounter.misc.chosenNature); // Add pokemon and modifiers back - scene.getPlayerParty().push(playerPokemon); + globalScene.getPlayerParty().push(playerPokemon); for (const mod of modifiers.value) { mod.pokemonId = playerPokemon.id; - scene.addModifier(mod, true, false, false, true); + globalScene.addModifier(mod, true, false, false, true); } - scene.updateModifiers(true); + globalScene.updateModifiers(true); }; - setEncounterRewards(scene, { fillRemaining: true }, undefined, onBeforeRewardsPhase); + setEncounterRewards({ fillRemaining: true }, undefined, onBeforeRewardsPhase); - await initBattleWithEnemyConfig(scene, config); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -258,9 +258,9 @@ export const TrainingSessionEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene): Promise => { + .withPreOptionPhase(async (): Promise => { // Open menu for selecting pokemon and ability to learn - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const onPokemonSelected = (pokemon: PlayerPokemon) => { // Return the options for ability selection const speciesForm = !!pokemon.getFusionSpeciesForm() @@ -286,7 +286,7 @@ export const TrainingSessionEncounter: MysteryEncounter = return true; }, onHover: () => { - showEncounterText(scene, ability.description, 0, 0, false); + showEncounterText(ability.description, 0, 0, false); }, }; optionSelectItems.push(option); @@ -298,28 +298,28 @@ export const TrainingSessionEncounter: MysteryEncounter = // Only Pokemon that are not KOed/legal can be trained const selectableFilter = (pokemon: Pokemon) => { - return isPokemonValidForEncounterOptionSelection(pokemon, scene, `${namespace}:invalid_selection`); + return isPokemonValidForEncounterOptionSelection(pokemon, `${namespace}:invalid_selection`); }; - return selectPokemonForOption(scene, onPokemonSelected, undefined, selectableFilter); + return selectPokemonForOption(onPokemonSelected, undefined, selectableFilter); }) - .withOptionPhase(async (scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOptionPhase(async () => { + const encounter = globalScene.currentBattle.mysteryEncounter!; const playerPokemon: PlayerPokemon = encounter.misc.playerPokemon; // Spawn hard training session with chosen pokemon // Every 30 waves, add +1 boss segment, capping at 6 // Also starts with +1 to all stats - const segments = Math.min(2 + Math.floor(scene.currentBattle.waveIndex / 30), 6); + const segments = Math.min(2 + Math.floor(globalScene.currentBattle.waveIndex / 30), 6); const modifiers = new ModifiersHolder(); - const config = getEnemyConfig(scene, playerPokemon, segments, modifiers); + const config = getEnemyConfig(playerPokemon, segments, modifiers); config.pokemonConfigs![0].tags = [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON, ]; - scene.removePokemonFromPlayerParty(playerPokemon, false); + globalScene.removePokemonFromPlayerParty(playerPokemon, false); const onBeforeRewardsPhase = () => { - queueEncounterMessage(scene, `${namespace}:option.3.finished`); + queueEncounterMessage(`${namespace}:option.3.finished`); // Add the pokemon back to party with ability change const abilityIndex = encounter.misc.abilityIndex; @@ -330,8 +330,8 @@ export const TrainingSessionEncounter: MysteryEncounter = const rootFusionSpecies = playerPokemon.fusionSpecies?.getRootSpeciesId(); if (!isNullOrUndefined(rootFusionSpecies) && speciesStarterCosts.hasOwnProperty(rootFusionSpecies) - && !!scene.gameData.dexData[rootFusionSpecies].caughtAttr) { - scene.gameData.starterData[rootFusionSpecies].abilityAttr |= playerPokemon.fusionAbilityIndex !== 1 || playerPokemon.fusionSpecies?.ability2 + && !!globalScene.gameData.dexData[rootFusionSpecies].caughtAttr) { + globalScene.gameData.starterData[rootFusionSpecies].abilityAttr |= playerPokemon.fusionAbilityIndex !== 1 || playerPokemon.fusionSpecies?.ability2 ? 1 << playerPokemon.fusionAbilityIndex : AbilityAttr.ABILITY_HIDDEN; } @@ -340,20 +340,20 @@ export const TrainingSessionEncounter: MysteryEncounter = } playerPokemon.calculateStats(); - scene.gameData.setPokemonCaught(playerPokemon, false); + globalScene.gameData.setPokemonCaught(playerPokemon, false); // Add pokemon and mods back - scene.getPlayerParty().push(playerPokemon); + globalScene.getPlayerParty().push(playerPokemon); for (const mod of modifiers.value) { mod.pokemonId = playerPokemon.id; - scene.addModifier(mod, true, false, false, true); + globalScene.addModifier(mod, true, false, false, true); } - scene.updateModifiers(true); + globalScene.updateModifiers(true); }; - setEncounterRewards(scene, { fillRemaining: true }, undefined, onBeforeRewardsPhase); + setEncounterRewards({ fillRemaining: true }, undefined, onBeforeRewardsPhase); - await initBattleWithEnemyConfig(scene, config); + await initBattleWithEnemyConfig(config); }) .build() ) @@ -367,15 +367,15 @@ export const TrainingSessionEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave encounter with no rewards or exp - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) .build(); -function getEnemyConfig(scene: BattleScene, playerPokemon: PlayerPokemon, segments: number, modifiers: ModifiersHolder): EnemyPartyConfig { +function getEnemyConfig(playerPokemon: PlayerPokemon, segments: number, modifiers: ModifiersHolder): EnemyPartyConfig { playerPokemon.resetSummonData(); // Passes modifiers by reference diff --git a/src/data/mystery-encounters/encounters/trash-to-treasure-encounter.ts b/src/data/mystery-encounters/encounters/trash-to-treasure-encounter.ts index dfd89cdfb63d..50458a652bc5 100644 --- a/src/data/mystery-encounters/encounters/trash-to-treasure-encounter.ts +++ b/src/data/mystery-encounters/encounters/trash-to-treasure-encounter.ts @@ -1,7 +1,7 @@ import { EnemyPartyConfig, EnemyPokemonConfig, generateModifierType, initBattleWithEnemyConfig, leaveEncounterWithoutBattle, loadCustomMovesForEncounter, setEncounterRewards, transitionMysteryEncounterIntroVisuals, } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { modifierTypes, PokemonHeldItemModifierType } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -58,8 +58,8 @@ export const TrashToTreasureEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate boss mon (shiny locked) const bossSpecies = getPokemonSpecies(Species.GARBODOR); @@ -79,10 +79,10 @@ export const TrashToTreasureEncounter: MysteryEncounter = encounter.enemyPartyConfigs = [ config ]; // Load animations/sfx for Garbodor fight start moves - loadCustomMovesForEncounter(scene, [ Moves.TOXIC, Moves.AMNESIA ]); + loadCustomMovesForEncounter([ Moves.TOXIC, Moves.AMNESIA ]); - scene.loadSe("PRSFX- Dig2", "battle_anims", "PRSFX- Dig2.wav"); - scene.loadSe("PRSFX- Venom Drench", "battle_anims", "PRSFX- Venom Drench.wav"); + globalScene.loadSe("PRSFX- Dig2", "battle_anims", "PRSFX- Dig2.wav"); + globalScene.loadSe("PRSFX- Venom Drench", "battle_anims", "PRSFX- Venom Drench.wav"); encounter.setDialogueToken("costMultiplier", SHOP_ITEM_COST_MULTIPLIER.toString()); @@ -100,24 +100,24 @@ export const TrashToTreasureEncounter: MysteryEncounter = }, ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Play Dig2 and then Venom Drench sfx - doGarbageDig(scene); + doGarbageDig(); }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Gain 2 Leftovers and 2 Shell Bell - await transitionMysteryEncounterIntroVisuals(scene); - await tryApplyDigRewardItems(scene); + await transitionMysteryEncounterIntroVisuals(); + await tryApplyDigRewardItems(); - const blackSludge = generateModifierType(scene, modifierTypes.MYSTERY_ENCOUNTER_BLACK_SLUDGE, [ SHOP_ITEM_COST_MULTIPLIER ]); + const blackSludge = generateModifierType(modifierTypes.MYSTERY_ENCOUNTER_BLACK_SLUDGE, [ SHOP_ITEM_COST_MULTIPLIER ]); const modifier = blackSludge?.newModifier(); if (modifier) { - await scene.addModifier(modifier, false, false, false, true); - scene.playSound("battle_anims/PRSFX- Venom Drench", { volume: 2 }); - await showEncounterText(scene, i18next.t("battle:rewardGain", { modifierName: modifier.type.name }), null, undefined, true); + await globalScene.addModifier(modifier, false, false, false, true); + globalScene.playSound("battle_anims/PRSFX- Venom Drench", { volume: 2 }); + await showEncounterText(i18next.t("battle:rewardGain", { modifierName: modifier.type.name }), null, undefined, true); } - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -133,15 +133,15 @@ export const TrashToTreasureEncounter: MysteryEncounter = }, ], }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Investigate garbage, battle Gmax Garbodor - scene.setFieldScale(0.75); - await showEncounterText(scene, `${namespace}:option.2.selected_2`); - await transitionMysteryEncounterIntroVisuals(scene); + globalScene.setFieldScale(0.75); + await showEncounterText(`${namespace}:option.2.selected_2`); + await transitionMysteryEncounterIntroVisuals(); - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; - setEncounterRewards(scene, { guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.GREAT ], fillRemaining: true }); + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.GREAT ], fillRemaining: true }); encounter.startOfBattleEffects.push( { sourceBattlerIndex: BattlerIndex.ENEMY, @@ -155,81 +155,81 @@ export const TrashToTreasureEncounter: MysteryEncounter = move: new PokemonMove(Moves.AMNESIA), ignorePp: true }); - await initBattleWithEnemyConfig(scene, encounter.enemyPartyConfigs[0]); + await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); }) .build() ) .build(); -async function tryApplyDigRewardItems(scene: BattleScene) { - const shellBell = generateModifierType(scene, modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; - const leftovers = generateModifierType(scene, modifierTypes.LEFTOVERS) as PokemonHeldItemModifierType; +async function tryApplyDigRewardItems() { + const shellBell = generateModifierType(modifierTypes.SHELL_BELL) as PokemonHeldItemModifierType; + const leftovers = generateModifierType(modifierTypes.LEFTOVERS) as PokemonHeldItemModifierType; - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); // Iterate over the party until an item was successfully given // First leftovers for (const pokemon of party) { - const heldItems = scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const heldItems = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id, true) as PokemonHeldItemModifier[]; const existingLeftovers = heldItems.find(m => m instanceof TurnHealModifier) as TurnHealModifier; - if (!existingLeftovers || existingLeftovers.getStackCount() < existingLeftovers.getMaxStackCount(scene)) { - await applyModifierTypeToPlayerPokemon(scene, pokemon, leftovers); + if (!existingLeftovers || existingLeftovers.getStackCount() < existingLeftovers.getMaxStackCount()) { + await applyModifierTypeToPlayerPokemon(pokemon, leftovers); break; } } // Second leftovers for (const pokemon of party) { - const heldItems = scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const heldItems = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id, true) as PokemonHeldItemModifier[]; const existingLeftovers = heldItems.find(m => m instanceof TurnHealModifier) as TurnHealModifier; - if (!existingLeftovers || existingLeftovers.getStackCount() < existingLeftovers.getMaxStackCount(scene)) { - await applyModifierTypeToPlayerPokemon(scene, pokemon, leftovers); + if (!existingLeftovers || existingLeftovers.getStackCount() < existingLeftovers.getMaxStackCount()) { + await applyModifierTypeToPlayerPokemon(pokemon, leftovers); break; } } - scene.playSound("item_fanfare"); - await showEncounterText(scene, i18next.t("battle:rewardGainCount", { modifierName: leftovers.name, count: 2 }), null, undefined, true); + globalScene.playSound("item_fanfare"); + await showEncounterText(i18next.t("battle:rewardGainCount", { modifierName: leftovers.name, count: 2 }), null, undefined, true); // First Shell bell for (const pokemon of party) { - const heldItems = scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const heldItems = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id, true) as PokemonHeldItemModifier[]; const existingShellBell = heldItems.find(m => m instanceof HitHealModifier) as HitHealModifier; - if (!existingShellBell || existingShellBell.getStackCount() < existingShellBell.getMaxStackCount(scene)) { - await applyModifierTypeToPlayerPokemon(scene, pokemon, shellBell); + if (!existingShellBell || existingShellBell.getStackCount() < existingShellBell.getMaxStackCount()) { + await applyModifierTypeToPlayerPokemon(pokemon, shellBell); break; } } // Second Shell bell for (const pokemon of party) { - const heldItems = scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const heldItems = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id, true) as PokemonHeldItemModifier[]; const existingShellBell = heldItems.find(m => m instanceof HitHealModifier) as HitHealModifier; - if (!existingShellBell || existingShellBell.getStackCount() < existingShellBell.getMaxStackCount(scene)) { - await applyModifierTypeToPlayerPokemon(scene, pokemon, shellBell); + if (!existingShellBell || existingShellBell.getStackCount() < existingShellBell.getMaxStackCount()) { + await applyModifierTypeToPlayerPokemon(pokemon, shellBell); break; } } - scene.playSound("item_fanfare"); - await showEncounterText(scene, i18next.t("battle:rewardGainCount", { modifierName: shellBell.name, count: 2 }), null, undefined, true); + globalScene.playSound("item_fanfare"); + await showEncounterText(i18next.t("battle:rewardGainCount", { modifierName: shellBell.name, count: 2 }), null, undefined, true); } -function doGarbageDig(scene: BattleScene) { - scene.playSound("battle_anims/PRSFX- Dig2"); - scene.time.delayedCall(SOUND_EFFECT_WAIT_TIME, () => { - scene.playSound("battle_anims/PRSFX- Dig2"); - scene.playSound("battle_anims/PRSFX- Venom Drench", { volume: 2 }); +function doGarbageDig() { + globalScene.playSound("battle_anims/PRSFX- Dig2"); + globalScene.time.delayedCall(SOUND_EFFECT_WAIT_TIME, () => { + globalScene.playSound("battle_anims/PRSFX- Dig2"); + globalScene.playSound("battle_anims/PRSFX- Venom Drench", { volume: 2 }); }); - scene.time.delayedCall(SOUND_EFFECT_WAIT_TIME * 2, () => { - scene.playSound("battle_anims/PRSFX- Dig2"); + globalScene.time.delayedCall(SOUND_EFFECT_WAIT_TIME * 2, () => { + globalScene.playSound("battle_anims/PRSFX- Dig2"); }); } diff --git a/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts b/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts index d3679825ac87..f9423524b235 100644 --- a/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts +++ b/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts @@ -4,7 +4,7 @@ import { CHARMING_MOVES } from "#app/data/mystery-encounters/requirements/requir import Pokemon, { EnemyPokemon, PokemonMove } from "#app/field/pokemon"; import { getPartyLuckValue } from "#app/modifier/modifier-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MoveRequirement, PersistentModifierRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; @@ -45,14 +45,14 @@ export const UncommonBreedEncounter: MysteryEncounter = text: `${namespace}:intro`, }, ]) - .withOnInit((scene: BattleScene) => { - const encounter = scene.currentBattle.mysteryEncounter!; + .withOnInit(() => { + const encounter = globalScene.currentBattle.mysteryEncounter!; // Calculate boss mon // Level equal to 2 below highest party member - const level = getHighestLevelPlayerPokemon(scene, false, true).level - 2; - const species = scene.arena.randomSpecies(scene.currentBattle.waveIndex, level, 0, getPartyLuckValue(scene.getPlayerParty()), true); - const pokemon = new EnemyPokemon(scene, species, level, TrainerSlot.NONE, true); + const level = getHighestLevelPlayerPokemon(false, true).level - 2; + const species = globalScene.arena.randomSpecies(globalScene.currentBattle.waveIndex, level, 0, getPartyLuckValue(globalScene.getPlayerParty()), true); + const pokemon = new EnemyPokemon(species, level, TrainerSlot.NONE, true); // Pokemon will always have one of its egg moves in its moveset const eggMoves = pokemon.getEggMoves(); @@ -73,7 +73,7 @@ export const UncommonBreedEncounter: MysteryEncounter = } // Defense/Spd buffs below wave 50, +1 to all stats otherwise - const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = scene.currentBattle.waveIndex < 50 ? + const statChangesForBattle: (Stat.ATK | Stat.DEF | Stat.SPATK | Stat.SPDEF | Stat.SPD | Stat.ACC | Stat.EVA)[] = globalScene.currentBattle.waveIndex < 50 ? [ Stat.DEF, Stat.SPDEF, Stat.SPD ] : [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD ]; @@ -85,8 +85,8 @@ export const UncommonBreedEncounter: MysteryEncounter = isBoss: false, tags: [ BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON ], mysteryEncounterBattleEffects: (pokemon: Pokemon) => { - queueEncounterMessage(pokemon.scene, `${namespace}:option.1.stat_boost`); - pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); + queueEncounterMessage(`${namespace}:option.1.stat_boost`); + globalScene.unshiftPhase(new StatStageChangePhase(pokemon.getBattlerIndex(), true, statChangesForBattle, 1)); } }], }; @@ -107,16 +107,16 @@ export const UncommonBreedEncounter: MysteryEncounter = ]; encounter.setDialogueToken("enemyPokemon", pokemon.getNameToRender()); - scene.loadSe("PRSFX- Spotlight2", "battle_anims", "PRSFX- Spotlight2.wav"); + globalScene.loadSe("PRSFX- Spotlight2", "battle_anims", "PRSFX- Spotlight2.wav"); return true; }) - .withOnVisualsStart((scene: BattleScene) => { + .withOnVisualsStart(() => { // Animate the pokemon - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const pokemonSprite = encounter.introVisuals!.getSprites(); // Bounce at the end, then shiny sparkle if the Pokemon is shiny - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonSprite, duration: 300, ease: "Cubic.easeOut", @@ -126,7 +126,7 @@ export const UncommonBreedEncounter: MysteryEncounter = onComplete: () => encounter.introVisuals?.playShinySparkles() }); - scene.time.delayedCall(500, () => scene.playSound("battle_anims/PRSFX- Spotlight2")); + globalScene.time.delayedCall(500, () => globalScene.playSound("battle_anims/PRSFX- Spotlight2")); return true; }) .setLocalizationKey(`${namespace}`) @@ -143,9 +143,9 @@ export const UncommonBreedEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Pick battle - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const eggMove = encounter.misc.eggMove; if (!isNullOrUndefined(eggMove)) { @@ -163,8 +163,8 @@ export const UncommonBreedEncounter: MysteryEncounter = }); } - setEncounterRewards(scene, { fillRemaining: true }); - await initBattleWithEnemyConfig(scene, encounter.enemyPartyConfigs[0]); + setEncounterRewards({ fillRemaining: true }); + await initBattleWithEnemyConfig(encounter.enemyPartyConfigs[0]); } ) .withOption( @@ -181,33 +181,33 @@ export const UncommonBreedEncounter: MysteryEncounter = } ] }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Give it some food // Remove 4 random berries from player's party // Get all player berry items, remove from party, and store reference - const berryItems: BerryModifier[] = scene.findModifiers(m => m instanceof BerryModifier) as BerryModifier[]; + const berryItems: BerryModifier[] = globalScene.findModifiers(m => m instanceof BerryModifier) as BerryModifier[]; for (let i = 0; i < 4; i++) { const index = randSeedInt(berryItems.length); const randBerry = berryItems[index]; randBerry.stackCount--; if (randBerry.stackCount === 0) { - scene.removeModifier(randBerry); + globalScene.removeModifier(randBerry); berryItems.splice(index, 1); } } - await scene.updateModifiers(true, true); + await globalScene.updateModifiers(true, true); // Pokemon joins the team, with 2 egg moves - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const pokemon = encounter.misc.pokemon; // Give 1 additional egg move givePokemonExtraEggMove(pokemon, encounter.misc.eggMove); - await catchPokemon(scene, pokemon, null, PokeballType.POKEBALL, false); - setEncounterRewards(scene, { fillRemaining: true }); - leaveEncounterWithoutBattle(scene); + await catchPokemon(pokemon, null, PokeballType.POKEBALL, false); + setEncounterRewards({ fillRemaining: true }); + leaveEncounterWithoutBattle(); }) .build() ) @@ -225,10 +225,10 @@ export const UncommonBreedEncounter: MysteryEncounter = } ] }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Attract the pokemon with a move // Pokemon joins the team, with 2 egg moves and IVs rolled an additional time - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; const pokemon = encounter.misc.pokemon; // Give 1 additional egg move @@ -240,12 +240,12 @@ export const UncommonBreedEncounter: MysteryEncounter = return newValue > iv ? newValue : iv; }); - await catchPokemon(scene, pokemon, null, PokeballType.POKEBALL, false); + await catchPokemon(pokemon, null, PokeballType.POKEBALL, false); if (encounter.selectedOption?.primaryPokemon?.id) { - setEncounterExp(scene, encounter.selectedOption.primaryPokemon.id, pokemon.getExpValue(), false); + setEncounterExp(encounter.selectedOption.primaryPokemon.id, pokemon.getExpValue(), false); } - setEncounterRewards(scene, { fillRemaining: true }); - leaveEncounterWithoutBattle(scene); + setEncounterRewards({ fillRemaining: true }); + leaveEncounterWithoutBattle(); }) .build() ) diff --git a/src/data/mystery-encounters/encounters/weird-dream-encounter.ts b/src/data/mystery-encounters/encounters/weird-dream-encounter.ts index 3d2e8493d448..2ca8b782f4c7 100644 --- a/src/data/mystery-encounters/encounters/weird-dream-encounter.ts +++ b/src/data/mystery-encounters/encounters/weird-dream-encounter.ts @@ -1,7 +1,7 @@ import { Type } from "#enums/type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { Species } from "#enums/species"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter, { MysteryEncounterBuilder } from "#app/data/mystery-encounters/mystery-encounter"; import { MysteryEncounterOptionBuilder } from "#app/data/mystery-encounters/mystery-encounter-option"; import { EnemyPartyConfig, EnemyPokemonConfig, generateModifierType, initBattleWithEnemyConfig, leaveEncounterWithoutBattle, setEncounterRewards, } from "../utils/encounter-phase-utils"; @@ -138,21 +138,21 @@ export const WeirdDreamEncounter: MysteryEncounter = .withTitle(`${namespace}:title`) .withDescription(`${namespace}:description`) .withQuery(`${namespace}:query`) - .withOnInit((scene: BattleScene) => { - scene.loadBgm("mystery_encounter_weird_dream", "mystery_encounter_weird_dream.mp3"); + .withOnInit(() => { + globalScene.loadBgm("mystery_encounter_weird_dream", "mystery_encounter_weird_dream.mp3"); // Calculate all the newly transformed Pokemon and begin asset load - const teamTransformations = getTeamTransformations(scene); + const teamTransformations = getTeamTransformations(); const loadAssets = teamTransformations.map(t => (t.newPokemon as PlayerPokemon).loadAssets()); - scene.currentBattle.mysteryEncounter!.misc = { + globalScene.currentBattle.mysteryEncounter!.misc = { teamTransformations, loadAssets }; return true; }) - .withOnVisualsStart((scene: BattleScene) => { - scene.fadeAndSwitchBgm("mystery_encounter_weird_dream"); + .withOnVisualsStart(() => { + globalScene.fadeAndSwitchBgm("mystery_encounter_weird_dream"); return true; }) .withOption( @@ -168,25 +168,25 @@ export const WeirdDreamEncounter: MysteryEncounter = } ], }) - .withPreOptionPhase(async (scene: BattleScene) => { + .withPreOptionPhase(async () => { // Play the animation as the player goes through the dialogue - scene.time.delayedCall(1000, () => { - doShowDreamBackground(scene); + globalScene.time.delayedCall(1000, () => { + doShowDreamBackground(); }); - for (const transformation of scene.currentBattle.mysteryEncounter!.misc.teamTransformations) { - scene.removePokemonFromPlayerParty(transformation.previousPokemon, false); - scene.getPlayerParty().push(transformation.newPokemon); + for (const transformation of globalScene.currentBattle.mysteryEncounter!.misc.teamTransformations) { + globalScene.removePokemonFromPlayerParty(transformation.previousPokemon, false); + globalScene.getPlayerParty().push(transformation.newPokemon); } }) - .withOptionPhase(async (scene: BattleScene) => { + .withOptionPhase(async () => { // Starts cutscene dialogue, but does not await so that cutscene plays as player goes through dialogue - const cutsceneDialoguePromise = showEncounterText(scene, `${namespace}:option.1.cutscene`); + const cutsceneDialoguePromise = showEncounterText(`${namespace}:option.1.cutscene`); // Change the entire player's party // Wait for all new Pokemon assets to be loaded before showing transformation animations - await Promise.all(scene.currentBattle.mysteryEncounter!.misc.loadAssets); - const transformations = scene.currentBattle.mysteryEncounter!.misc.teamTransformations; + await Promise.all(globalScene.currentBattle.mysteryEncounter!.misc.loadAssets); + const transformations = globalScene.currentBattle.mysteryEncounter!.misc.teamTransformations; // If there are 1-3 transformations, do them centered back to back // Otherwise, the first 3 transformations are executed side-by-side, then any remaining 1-3 transformations occur in those same respective positions @@ -195,21 +195,21 @@ export const WeirdDreamEncounter: MysteryEncounter = const pokemon1 = transformation.previousPokemon; const pokemon2 = transformation.newPokemon; - await doPokemonTransformationSequence(scene, pokemon1, pokemon2, TransformationScreenPosition.CENTER); + await doPokemonTransformationSequence(pokemon1, pokemon2, TransformationScreenPosition.CENTER); } } else { - await doSideBySideTransformations(scene, transformations); + await doSideBySideTransformations(transformations); } // Make sure player has finished cutscene dialogue await cutsceneDialoguePromise; - doHideDreamBackground(scene); - await showEncounterText(scene, `${namespace}:option.1.dream_complete`); + doHideDreamBackground(); + await showEncounterText(`${namespace}:option.1.dream_complete`); - await doNewTeamPostProcess(scene, transformations); - setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM, modifierTypes.ROGUE_BALL, modifierTypes.MINT, modifierTypes.MINT, modifierTypes.MINT ], fillRemaining: false }); - leaveEncounterWithoutBattle(scene, true); + await doNewTeamPostProcess(transformations); + setEncounterRewards({ guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM, modifierTypes.ROGUE_BALL, modifierTypes.MINT, modifierTypes.MINT, modifierTypes.MINT ], fillRemaining: false }); + leaveEncounterWithoutBattle(true); }) .build() ) @@ -223,9 +223,9 @@ export const WeirdDreamEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Battle your "future" team for some item rewards - const transformations: PokemonTransformation[] = scene.currentBattle.mysteryEncounter!.misc.teamTransformations; + const transformations: PokemonTransformation[] = globalScene.currentBattle.mysteryEncounter!.misc.teamTransformations; // Uses the pokemon that player's party would have transformed into const enemyPokemonConfigs: EnemyPokemonConfig[] = []; @@ -233,7 +233,7 @@ export const WeirdDreamEncounter: MysteryEncounter = const newPokemon = transformation.newPokemon; const previousPokemon = transformation.previousPokemon; - await postProcessTransformedPokemon(scene, previousPokemon, newPokemon, newPokemon.species.getRootSpeciesId(), true); + await postProcessTransformedPokemon(previousPokemon, newPokemon, newPokemon.species.getRootSpeciesId(), true); const dataSource = new PokemonData(newPokemon); dataSource.player = false; @@ -251,7 +251,7 @@ export const WeirdDreamEncounter: MysteryEncounter = if (shouldGetOldGateau(newPokemon)) { const stats = getOldGateauBoostedStats(newPokemon); newPokemonHeldItemConfigs.push({ - modifier: generateModifierType(scene, modifierTypes.MYSTERY_ENCOUNTER_OLD_GATEAU, [ OLD_GATEAU_STATS_UP, stats ]) as PokemonHeldItemModifierType, + modifier: generateModifierType(modifierTypes.MYSTERY_ENCOUNTER_OLD_GATEAU, [ OLD_GATEAU_STATS_UP, stats ]) as PokemonHeldItemModifierType, stackCount: 1, isTransferable: false }); @@ -268,7 +268,7 @@ export const WeirdDreamEncounter: MysteryEncounter = enemyPokemonConfigs.push(enemyConfig); } - const genderIndex = scene.gameData.gender ?? PlayerGender.UNSET; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const trainerConfig = trainerConfigs[genderIndex === PlayerGender.FEMALE ? TrainerType.FUTURE_SELF_F : TrainerType.FUTURE_SELF_M].clone(); trainerConfig.setPartyTemplates(new TrainerPartyTemplate(transformations.length, PartyMemberStrength.STRONG)); const enemyPartyConfig: EnemyPartyConfig = { @@ -280,7 +280,7 @@ export const WeirdDreamEncounter: MysteryEncounter = const onBeforeRewards = () => { // Before battle rewards, unlock the passive on a pokemon in the player's team for the rest of the run (not permanently) // One random pokemon will get its passive unlocked - const passiveDisabledPokemon = scene.getPlayerParty().filter(p => !p.passive); + const passiveDisabledPokemon = globalScene.getPlayerParty().filter(p => !p.passive); if (passiveDisabledPokemon?.length > 0) { const enablePassiveMon = passiveDisabledPokemon[randSeedInt(passiveDisabledPokemon.length)]; enablePassiveMon.passive = true; @@ -288,10 +288,10 @@ export const WeirdDreamEncounter: MysteryEncounter = } }; - setEncounterRewards(scene, { guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.GREAT, ModifierTier.GREAT ], fillRemaining: false }, undefined, onBeforeRewards); + setEncounterRewards({ guaranteedModifierTiers: [ ModifierTier.ROGUE, ModifierTier.ROGUE, ModifierTier.ULTRA, ModifierTier.ULTRA, ModifierTier.GREAT, ModifierTier.GREAT ], fillRemaining: false }, undefined, onBeforeRewards); - await showEncounterText(scene, `${namespace}:option.2.selected_2`, null, undefined, true); - await initBattleWithEnemyConfig(scene, enemyPartyConfig); + await showEncounterText(`${namespace}:option.2.selected_2`, null, undefined, true); + await initBattleWithEnemyConfig(enemyPartyConfig); } ) .withSimpleOption( @@ -304,9 +304,9 @@ export const WeirdDreamEncounter: MysteryEncounter = }, ], }, - async (scene: BattleScene) => { + async () => { // Leave, reduce party levels by 10% - for (const pokemon of scene.getPlayerParty()) { + for (const pokemon of globalScene.getPlayerParty()) { pokemon.level = Math.max(Math.ceil((100 - PERCENT_LEVEL_LOSS_ON_REFUSE) / 100 * pokemon.level), 1); pokemon.exp = getLevelTotalExp(pokemon.level, pokemon.species.growthRate); pokemon.levelExp = 0; @@ -316,7 +316,7 @@ export const WeirdDreamEncounter: MysteryEncounter = await pokemon.updateInfo(); } - leaveEncounterWithoutBattle(scene, true); + leaveEncounterWithoutBattle(true); return true; } ) @@ -329,8 +329,8 @@ interface PokemonTransformation { heldItems: PokemonHeldItemModifier[]; } -function getTeamTransformations(scene: BattleScene): PokemonTransformation[] { - const party = scene.getPlayerParty(); +function getTeamTransformations(): PokemonTransformation[] { + const party = globalScene.getPlayerParty(); // Removes all pokemon from the party const alreadyUsedSpecies: PokemonSpecies[] = party.map(p => p.species); const pokemonTransformations: PokemonTransformation[] = party.map(p => { @@ -379,37 +379,37 @@ function getTeamTransformations(scene: BattleScene): PokemonTransformation[] { for (const transformation of pokemonTransformations) { const newAbilityIndex = randSeedInt(transformation.newSpecies.getAbilityCount()); - transformation.newPokemon = scene.addPlayerPokemon(transformation.newSpecies, transformation.previousPokemon.level, newAbilityIndex, undefined); + transformation.newPokemon = globalScene.addPlayerPokemon(transformation.newSpecies, transformation.previousPokemon.level, newAbilityIndex, undefined); } return pokemonTransformations; } -async function doNewTeamPostProcess(scene: BattleScene, transformations: PokemonTransformation[]) { +async function doNewTeamPostProcess(transformations: PokemonTransformation[]) { let atLeastOneNewStarter = false; for (const transformation of transformations) { const previousPokemon = transformation.previousPokemon; const newPokemon = transformation.newPokemon; const speciesRootForm = newPokemon.species.getRootSpeciesId(); - if (await postProcessTransformedPokemon(scene, previousPokemon, newPokemon, speciesRootForm)) { + if (await postProcessTransformedPokemon(previousPokemon, newPokemon, speciesRootForm)) { atLeastOneNewStarter = true; } // Copy old items to new pokemon for (const item of transformation.heldItems) { item.pokemonId = newPokemon.id; - await scene.addModifier(item, false, false, false, true); + await globalScene.addModifier(item, false, false, false, true); } // Any pokemon that is below 570 BST gets +20 permanent BST to 3 stats if (shouldGetOldGateau(newPokemon)) { const stats = getOldGateauBoostedStats(newPokemon); const modType = modifierTypes.MYSTERY_ENCOUNTER_OLD_GATEAU() - .generateType(scene.getPlayerParty(), [ OLD_GATEAU_STATS_UP, stats ]) + .generateType(globalScene.getPlayerParty(), [ OLD_GATEAU_STATS_UP, stats ]) ?.withIdFromFunc(modifierTypes.MYSTERY_ENCOUNTER_OLD_GATEAU); const modifier = modType?.newModifier(newPokemon); if (modifier) { - await scene.addModifier(modifier, false, false, false, true); + await globalScene.addModifier(modifier, false, false, false, true); } } @@ -418,7 +418,7 @@ async function doNewTeamPostProcess(scene: BattleScene, transformations: Pokemon } // One random pokemon will get its passive unlocked - const passiveDisabledPokemon = scene.getPlayerParty().filter(p => !p.passive); + const passiveDisabledPokemon = globalScene.getPlayerParty().filter(p => !p.passive); if (passiveDisabledPokemon?.length > 0) { const enablePassiveMon = passiveDisabledPokemon[randSeedInt(passiveDisabledPokemon.length)]; enablePassiveMon.passive = true; @@ -427,27 +427,26 @@ async function doNewTeamPostProcess(scene: BattleScene, transformations: Pokemon // If at least one new starter was unlocked, play 1 fanfare if (atLeastOneNewStarter) { - scene.playSound("level_up_fanfare"); + globalScene.playSound("level_up_fanfare"); } } /** * Applies special changes to the newly transformed pokemon, such as passing previous moves, gaining egg moves, etc. * Returns whether the transformed pokemon unlocks a new starter for the player. - * @param scene * @param previousPokemon * @param newPokemon * @param speciesRootForm * @param forBattle Default `false`. If false, will perform achievements and dex unlocks for the player. */ -async function postProcessTransformedPokemon(scene: BattleScene, previousPokemon: PlayerPokemon, newPokemon: PlayerPokemon, speciesRootForm: Species, forBattle: boolean = false): Promise { +async function postProcessTransformedPokemon(previousPokemon: PlayerPokemon, newPokemon: PlayerPokemon, speciesRootForm: Species, forBattle: boolean = false): Promise { let isNewStarter = false; // Roll HA a second time if (newPokemon.species.abilityHidden) { const hiddenIndex = newPokemon.species.ability2 ? 2 : 1; if (newPokemon.abilityIndex < hiddenIndex) { const hiddenAbilityChance = new IntegerHolder(256); - scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); + globalScene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); const hasHiddenAbility = !randSeedInt(hiddenAbilityChance.value); @@ -469,26 +468,26 @@ async function postProcessTransformedPokemon(scene: BattleScene, previousPokemon // For pokemon at/below 570 BST or any shiny pokemon, unlock it permanently as if you had caught it if (!forBattle && (newPokemon.getSpeciesForm().getBaseStatTotal() <= NON_LEGENDARY_BST_THRESHOLD || newPokemon.isShiny())) { if (newPokemon.getSpeciesForm().abilityHidden && newPokemon.abilityIndex === newPokemon.getSpeciesForm().getAbilityCount() - 1) { - scene.validateAchv(achvs.HIDDEN_ABILITY); + globalScene.validateAchv(achvs.HIDDEN_ABILITY); } if (newPokemon.species.subLegendary) { - scene.validateAchv(achvs.CATCH_SUB_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_SUB_LEGENDARY); } if (newPokemon.species.legendary) { - scene.validateAchv(achvs.CATCH_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_LEGENDARY); } if (newPokemon.species.mythical) { - scene.validateAchv(achvs.CATCH_MYTHICAL); + globalScene.validateAchv(achvs.CATCH_MYTHICAL); } - scene.gameData.updateSpeciesDexIvs(newPokemon.species.getRootSpeciesId(true), newPokemon.ivs); - const newStarterUnlocked = await scene.gameData.setPokemonCaught(newPokemon, true, false, false); + globalScene.gameData.updateSpeciesDexIvs(newPokemon.species.getRootSpeciesId(true), newPokemon.ivs); + const newStarterUnlocked = await globalScene.gameData.setPokemonCaught(newPokemon, true, false, false); if (newStarterUnlocked) { isNewStarter = true; - await showEncounterText(scene, i18next.t("battle:addedAsAStarter", { pokemonName: getPokemonSpecies(speciesRootForm).getName() })); + await showEncounterText(i18next.t("battle:addedAsAStarter", { pokemonName: getPokemonSpecies(speciesRootForm).getName() })); } } @@ -504,8 +503,8 @@ async function postProcessTransformedPokemon(scene: BattleScene, previousPokemon }); // For pokemon that the player owns (including ones just caught), gain a candy - if (!forBattle && !!scene.gameData.dexData[speciesRootForm].caughtAttr) { - scene.gameData.addStarterCandy(getPokemonSpecies(speciesRootForm), 1); + if (!forBattle && !!globalScene.gameData.dexData[speciesRootForm].caughtAttr) { + globalScene.gameData.addStarterCandy(getPokemonSpecies(speciesRootForm), 1); } // Set the moveset of the new pokemon to be the same as previous, but with 1 egg move and 1 (attempted) STAB move of the new species @@ -515,7 +514,7 @@ async function postProcessTransformedPokemon(scene: BattleScene, previousPokemon newPokemon.moveset = previousPokemon.moveset.slice(0); - const newEggMoveIndex = await addEggMoveToNewPokemonMoveset(scene, newPokemon, speciesRootForm, forBattle); + const newEggMoveIndex = await addEggMoveToNewPokemonMoveset(newPokemon, speciesRootForm, forBattle); // Try to add a favored STAB move (might fail if Pokemon already knows a bunch of moves from newPokemonGeneratedMoveset) addFavoredMoveToNewPokemonMoveset(newPokemon, newPokemonGeneratedMoveset, newEggMoveIndex); @@ -597,31 +596,31 @@ function getTransformedSpecies(originalBst: number, bstSearchRange: [number, num return newSpecies; } -function doShowDreamBackground(scene: BattleScene) { - const transformationContainer = scene.add.container(0, -scene.game.canvas.height / 6); +function doShowDreamBackground() { + const transformationContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); transformationContainer.name = "Dream Background"; // In case it takes a bit for video to load - const transformationStaticBg = scene.add.rectangle(0, 0, scene.game.canvas.width / 6, scene.game.canvas.height / 6, 0); + const transformationStaticBg = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0); transformationStaticBg.setName("Black Background"); transformationStaticBg.setOrigin(0, 0); transformationContainer.add(transformationStaticBg); transformationStaticBg.setVisible(true); - const transformationVideoBg: Phaser.GameObjects.Video = scene.add.video(0, 0, "evo_bg").stop(); + const transformationVideoBg: Phaser.GameObjects.Video = globalScene.add.video(0, 0, "evo_bg").stop(); transformationVideoBg.setLoop(true); transformationVideoBg.setOrigin(0, 0); transformationVideoBg.setScale(0.4359673025); transformationContainer.add(transformationVideoBg); - scene.fieldUI.add(transformationContainer); - scene.fieldUI.bringToTop(transformationContainer); + globalScene.fieldUI.add(transformationContainer); + globalScene.fieldUI.bringToTop(transformationContainer); transformationVideoBg.play(); transformationContainer.setVisible(true); transformationContainer.alpha = 0; - scene.tweens.add({ + globalScene.tweens.add({ targets: transformationContainer, alpha: 1, duration: 3000, @@ -629,39 +628,39 @@ function doShowDreamBackground(scene: BattleScene) { }); } -function doHideDreamBackground(scene: BattleScene) { - const transformationContainer = scene.fieldUI.getByName("Dream Background"); +function doHideDreamBackground() { + const transformationContainer = globalScene.fieldUI.getByName("Dream Background"); - scene.tweens.add({ + globalScene.tweens.add({ targets: transformationContainer, alpha: 0, duration: 3000, ease: "Sine.easeInOut", onComplete: () => { - scene.fieldUI.remove(transformationContainer, true); + globalScene.fieldUI.remove(transformationContainer, true); } }); } -function doSideBySideTransformations(scene: BattleScene, transformations: PokemonTransformation[]) { +function doSideBySideTransformations(transformations: PokemonTransformation[]) { return new Promise(resolve => { const allTransformationPromises: Promise[] = []; for (let i = 0; i < 3; i++) { const delay = i * 4000; - scene.time.delayedCall(delay, () => { + globalScene.time.delayedCall(delay, () => { const transformation = transformations[i]; const pokemon1 = transformation.previousPokemon; const pokemon2 = transformation.newPokemon; const screenPosition = i as TransformationScreenPosition; - const transformationPromise = doPokemonTransformationSequence(scene, pokemon1, pokemon2, screenPosition) + const transformationPromise = doPokemonTransformationSequence(pokemon1, pokemon2, screenPosition) .then(() => { if (transformations.length > i + 3) { const nextTransformationAtPosition = transformations[i + 3]; const nextPokemon1 = nextTransformationAtPosition.previousPokemon; const nextPokemon2 = nextTransformationAtPosition.newPokemon; - allTransformationPromises.push(doPokemonTransformationSequence(scene, nextPokemon1, nextPokemon2, screenPosition)); + allTransformationPromises.push(doPokemonTransformationSequence(nextPokemon1, nextPokemon2, screenPosition)); } }); allTransformationPromises.push(transformationPromise); @@ -682,11 +681,10 @@ function doSideBySideTransformations(scene: BattleScene, transformations: Pokemo /** * Returns index of the new egg move within the Pokemon's moveset (not the index of the move in `speciesEggMoves`) - * @param scene * @param newPokemon * @param speciesRootForm */ -async function addEggMoveToNewPokemonMoveset(scene: BattleScene, newPokemon: PlayerPokemon, speciesRootForm: Species, forBattle: boolean = false): Promise { +async function addEggMoveToNewPokemonMoveset(newPokemon: PlayerPokemon, speciesRootForm: Species, forBattle: boolean = false): Promise { let eggMoveIndex: null | number = null; const eggMoves = newPokemon.getEggMoves()?.slice(0); if (eggMoves) { @@ -712,8 +710,8 @@ async function addEggMoveToNewPokemonMoveset(scene: BattleScene, newPokemon: Pla } // For pokemon that the player owns (including ones just caught), unlock the egg move - if (!forBattle && !isNullOrUndefined(randomEggMoveIndex) && !!scene.gameData.dexData[speciesRootForm].caughtAttr) { - await scene.gameData.setEggMoveUnlocked(getPokemonSpecies(speciesRootForm), randomEggMoveIndex, true); + if (!forBattle && !isNullOrUndefined(randomEggMoveIndex) && !!globalScene.gameData.dexData[speciesRootForm].caughtAttr) { + await globalScene.gameData.setEggMoveUnlocked(getPokemonSpecies(speciesRootForm), randomEggMoveIndex, true); } } } diff --git a/src/data/mystery-encounters/mystery-encounter-option.ts b/src/data/mystery-encounters/mystery-encounter-option.ts index 4ff8fd95f853..758bd3d3965e 100644 --- a/src/data/mystery-encounters/mystery-encounter-option.ts +++ b/src/data/mystery-encounters/mystery-encounter-option.ts @@ -1,7 +1,7 @@ import { OptionTextDisplay } from "#app/data/mystery-encounters/mystery-encounter-dialogue"; import { Moves } from "#app/enums/moves"; import Pokemon, { PlayerPokemon } from "#app/field/pokemon"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Type } from "#enums/type"; import { EncounterPokemonRequirement, EncounterSceneRequirement, MoneyRequirement, TypeRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; import { CanLearnMoveRequirement, CanLearnMoveRequirementOptions } from "./requirements/can-learn-move-requirement"; @@ -9,7 +9,7 @@ import { isNullOrUndefined, randSeedInt } from "#app/utils"; import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode"; -export type OptionPhaseCallback = (scene: BattleScene) => Promise; +export type OptionPhaseCallback = () => Promise; /** * Used by {@linkcode MysteryEncounterOptionBuilder} class to define required/optional properties on the {@linkcode MysteryEncounterOption} class when building. @@ -74,21 +74,19 @@ export default class MysteryEncounterOption implements IMysteryEncounterOption { /** * Returns true if all {@linkcode EncounterRequirement}s for the option are met - * @param scene */ - meetsRequirements(scene: BattleScene): boolean { - return !this.requirements.some(requirement => !requirement.meetsRequirement(scene)) - && this.meetsSupportingRequirementAndSupportingPokemonSelected(scene) - && this.meetsPrimaryRequirementAndPrimaryPokemonSelected(scene); + meetsRequirements(): boolean { + return !this.requirements.some(requirement => !requirement.meetsRequirement()) + && this.meetsSupportingRequirementAndSupportingPokemonSelected() + && this.meetsPrimaryRequirementAndPrimaryPokemonSelected(); } /** * Returns true if all PRIMARY {@linkcode EncounterRequirement}s for the option are met - * @param scene * @param pokemon */ - pokemonMeetsPrimaryRequirements(scene: BattleScene, pokemon: Pokemon): boolean { - return !this.primaryPokemonRequirements.some(req => !req.queryParty(scene.getPlayerParty()).map(p => p.id).includes(pokemon.id)); + pokemonMeetsPrimaryRequirements(pokemon: Pokemon): boolean { + return !this.primaryPokemonRequirements.some(req => !req.queryParty(globalScene.getPlayerParty()).map(p => p.id).includes(pokemon.id)); } /** @@ -96,16 +94,15 @@ export default class MysteryEncounterOption implements IMysteryEncounterOption { * AND there is a valid Pokemon assigned to {@linkcode primaryPokemon}. * If both {@linkcode primaryPokemonRequirements} and {@linkcode secondaryPokemonRequirements} are defined, * can cause scenarios where there are not enough Pokemon that are sufficient for all requirements. - * @param scene */ - meetsPrimaryRequirementAndPrimaryPokemonSelected(scene: BattleScene): boolean { + meetsPrimaryRequirementAndPrimaryPokemonSelected(): boolean { if (!this.primaryPokemonRequirements || this.primaryPokemonRequirements.length === 0) { return true; } - let qualified: PlayerPokemon[] = scene.getPlayerParty(); + let qualified: PlayerPokemon[] = globalScene.getPlayerParty(); for (const req of this.primaryPokemonRequirements) { - if (req.meetsRequirement(scene)) { - const queryParty = req.queryParty(scene.getPlayerParty()); + if (req.meetsRequirement()) { + const queryParty = req.queryParty(globalScene.getPlayerParty()); qualified = qualified.filter(pkmn => queryParty.includes(pkmn)); } else { this.primaryPokemon = undefined; @@ -154,18 +151,17 @@ export default class MysteryEncounterOption implements IMysteryEncounterOption { * AND there is a valid Pokemon assigned to {@linkcode secondaryPokemon} (if applicable). * If both {@linkcode primaryPokemonRequirements} and {@linkcode secondaryPokemonRequirements} are defined, * can cause scenarios where there are not enough Pokemon that are sufficient for all requirements. - * @param scene */ - meetsSupportingRequirementAndSupportingPokemonSelected(scene: BattleScene): boolean { + meetsSupportingRequirementAndSupportingPokemonSelected(): boolean { if (!this.secondaryPokemonRequirements || this.secondaryPokemonRequirements.length === 0) { this.secondaryPokemon = []; return true; } - let qualified: PlayerPokemon[] = scene.getPlayerParty(); + let qualified: PlayerPokemon[] = globalScene.getPlayerParty(); for (const req of this.secondaryPokemonRequirements) { - if (req.meetsRequirement(scene)) { - const queryParty = req.queryParty(scene.getPlayerParty()); + if (req.meetsRequirement()) { + const queryParty = req.queryParty(globalScene.getPlayerParty()); qualified = qualified.filter(pkmn => queryParty.includes(pkmn)); } else { this.secondaryPokemon = []; diff --git a/src/data/mystery-encounters/mystery-encounter-requirements.ts b/src/data/mystery-encounters/mystery-encounter-requirements.ts index 811b622de763..5a47b2eb69af 100644 --- a/src/data/mystery-encounters/mystery-encounter-requirements.ts +++ b/src/data/mystery-encounters/mystery-encounter-requirements.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { allAbilities } from "#app/data/ability"; import { EvolutionItem, pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import { Nature } from "#enums/nature"; @@ -18,23 +18,21 @@ import { SpeciesFormKey } from "#enums/species-form-key"; import { TimeOfDay } from "#enums/time-of-day"; export interface EncounterRequirement { - meetsRequirement(scene: BattleScene): boolean; // Boolean to see if a requirement is met - getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string]; + meetsRequirement(): boolean; // Boolean to see if a requirement is met + getDialogueToken(pokemon?: PlayerPokemon): [string, string]; } export abstract class EncounterSceneRequirement implements EncounterRequirement { /** * Returns whether the EncounterSceneRequirement's... requirements, are met by the given scene - * @param partyPokemon */ - abstract meetsRequirement(scene: BattleScene): boolean; + abstract meetsRequirement(): boolean; /** * Returns a dialogue token key/value pair for a given Requirement. * Should be overridden by child Requirement classes. - * @param scene * @param pokemon */ - abstract getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string]; + abstract getDialogueToken(pokemon?: PlayerPokemon): [string, string]; } /** @@ -61,33 +59,31 @@ export class CombinationSceneRequirement extends EncounterSceneRequirement { /** * Checks if all/any requirements are met (depends on {@linkcode isAnd}) - * @param scene The {@linkcode BattleScene} to check against * @returns true if all/any requirements are met (depends on {@linkcode isAnd}) */ - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { return this.isAnd - ? this.requirements.every(req => req.meetsRequirement(scene)) - : this.requirements.some(req => req.meetsRequirement(scene)); + ? this.requirements.every(req => req.meetsRequirement()) + : this.requirements.some(req => req.meetsRequirement()); } /** * Retrieves a dialogue token key/value pair for the given {@linkcode EncounterSceneRequirement | requirements}. - * @param scene The {@linkcode BattleScene} to check against * @param pokemon The {@linkcode PlayerPokemon} to check against * @returns A dialogue token key/value pair * @throws An {@linkcode Error} if {@linkcode isAnd} is `true` (not supported) */ - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { if (this.isAnd) { throw new Error("Not implemented (Sorry)"); } else { for (const req of this.requirements) { - if (req.meetsRequirement(scene)) { - return req.getDialogueToken(scene, pokemon); + if (req.meetsRequirement()) { + return req.getDialogueToken(pokemon); } } - return this.requirements[0].getDialogueToken(scene, pokemon); + return this.requirements[0].getDialogueToken(pokemon); } } } @@ -98,9 +94,8 @@ export abstract class EncounterPokemonRequirement implements EncounterRequiremen /** * Returns whether the EncounterPokemonRequirement's... requirements, are met by the given scene - * @param partyPokemon */ - abstract meetsRequirement(scene: BattleScene): boolean; + abstract meetsRequirement(): boolean; /** * Returns all party members that are compatible with this requirement. For non pokemon related requirements, the entire party is returned. @@ -111,10 +106,9 @@ export abstract class EncounterPokemonRequirement implements EncounterRequiremen /** * Returns a dialogue token key/value pair for a given Requirement. * Should be overridden by child Requirement classes. - * @param scene * @param pokemon */ - abstract getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string]; + abstract getDialogueToken(pokemon?: PlayerPokemon): [string, string]; } /** @@ -143,13 +137,12 @@ export class CombinationPokemonRequirement extends EncounterPokemonRequirement { /** * Checks if all/any requirements are met (depends on {@linkcode isAnd}) - * @param scene The {@linkcode BattleScene} to check against * @returns true if all/any requirements are met (depends on {@linkcode isAnd}) */ - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { return this.isAnd - ? this.requirements.every(req => req.meetsRequirement(scene)) - : this.requirements.some(req => req.meetsRequirement(scene)); + ? this.requirements.every(req => req.meetsRequirement()) + : this.requirements.some(req => req.meetsRequirement()); } /** @@ -168,22 +161,21 @@ export class CombinationPokemonRequirement extends EncounterPokemonRequirement { /** * Retrieves a dialogue token key/value pair for the given {@linkcode EncounterPokemonRequirement | requirements}. - * @param scene The {@linkcode BattleScene} to check against * @param pokemon The {@linkcode PlayerPokemon} to check against * @returns A dialogue token key/value pair * @throws An {@linkcode Error} if {@linkcode isAnd} is `true` (not supported) */ - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { if (this.isAnd) { throw new Error("Not implemented (Sorry)"); } else { for (const req of this.requirements) { - if (req.meetsRequirement(scene)) { - return req.getDialogueToken(scene, pokemon); + if (req.meetsRequirement()) { + return req.getDialogueToken(pokemon); } } - return this.requirements[0].getDialogueToken(scene, pokemon); + return this.requirements[0].getDialogueToken(pokemon); } } } @@ -200,12 +192,12 @@ export class PreviousEncounterRequirement extends EncounterSceneRequirement { this.previousEncounterRequirement = previousEncounterRequirement; } - override meetsRequirement(scene: BattleScene): boolean { - return scene.mysteryEncounterSaveData.encounteredEvents.some(e => e.type === this.previousEncounterRequirement); + override meetsRequirement(): boolean { + return globalScene.mysteryEncounterSaveData.encounteredEvents.some(e => e.type === this.previousEncounterRequirement); } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { - return [ "previousEncounter", scene.mysteryEncounterSaveData.encounteredEvents.find(e => e.type === this.previousEncounterRequirement)?.[0].toString() ?? "" ]; + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { + return [ "previousEncounter", globalScene.mysteryEncounterSaveData.encounteredEvents.find(e => e.type === this.previousEncounterRequirement)?.[0].toString() ?? "" ]; } } @@ -222,9 +214,9 @@ export class WaveRangeRequirement extends EncounterSceneRequirement { this.waveRange = waveRange; } - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { if (!isNullOrUndefined(this.waveRange) && this.waveRange[0] <= this.waveRange[1]) { - const waveIndex = scene.currentBattle.waveIndex; + const waveIndex = globalScene.currentBattle.waveIndex; if (waveIndex >= 0 && (this.waveRange[0] >= 0 && this.waveRange[0] > waveIndex) || (this.waveRange[1] >= 0 && this.waveRange[1] < waveIndex)) { return false; } @@ -232,8 +224,8 @@ export class WaveRangeRequirement extends EncounterSceneRequirement { return true; } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { - return [ "waveIndex", scene.currentBattle.waveIndex.toString() ]; + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { + return [ "waveIndex", globalScene.currentBattle.waveIndex.toString() ]; } } @@ -257,12 +249,12 @@ export class WaveModulusRequirement extends EncounterSceneRequirement { this.modulusValue = modulusValue; } - override meetsRequirement(scene: BattleScene): boolean { - return this.waveModuli.includes(scene.currentBattle.waveIndex % this.modulusValue); + override meetsRequirement(): boolean { + return this.waveModuli.includes(globalScene.currentBattle.waveIndex % this.modulusValue); } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { - return [ "waveIndex", scene.currentBattle.waveIndex.toString() ]; + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { + return [ "waveIndex", globalScene.currentBattle.waveIndex.toString() ]; } } @@ -274,8 +266,8 @@ export class TimeOfDayRequirement extends EncounterSceneRequirement { this.requiredTimeOfDay = Array.isArray(timeOfDay) ? timeOfDay : [ timeOfDay ]; } - override meetsRequirement(scene: BattleScene): boolean { - const timeOfDay = scene.arena?.getTimeOfDay(); + override meetsRequirement(): boolean { + const timeOfDay = globalScene.arena?.getTimeOfDay(); if (!isNullOrUndefined(timeOfDay) && this.requiredTimeOfDay?.length > 0 && !this.requiredTimeOfDay.includes(timeOfDay)) { return false; } @@ -283,8 +275,8 @@ export class TimeOfDayRequirement extends EncounterSceneRequirement { return true; } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { - return [ "timeOfDay", TimeOfDay[scene.arena.getTimeOfDay()].toLocaleLowerCase() ]; + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { + return [ "timeOfDay", TimeOfDay[globalScene.arena.getTimeOfDay()].toLocaleLowerCase() ]; } } @@ -296,8 +288,8 @@ export class WeatherRequirement extends EncounterSceneRequirement { this.requiredWeather = Array.isArray(weather) ? weather : [ weather ]; } - override meetsRequirement(scene: BattleScene): boolean { - const currentWeather = scene.arena.weather?.weatherType; + override meetsRequirement(): boolean { + const currentWeather = globalScene.arena.weather?.weatherType; if (!isNullOrUndefined(currentWeather) && this.requiredWeather?.length > 0 && !this.requiredWeather.includes(currentWeather!)) { return false; } @@ -305,8 +297,8 @@ export class WeatherRequirement extends EncounterSceneRequirement { return true; } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { - const currentWeather = scene.arena.weather?.weatherType; + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { + const currentWeather = globalScene.arena.weather?.weatherType; let token = ""; if (!isNullOrUndefined(currentWeather)) { token = WeatherType[currentWeather].replace("_", " ").toLocaleLowerCase(); @@ -331,9 +323,9 @@ export class PartySizeRequirement extends EncounterSceneRequirement { this.excludeDisallowedPokemon = excludeDisallowedPokemon; } - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { if (!isNullOrUndefined(this.partySizeRange) && this.partySizeRange[0] <= this.partySizeRange[1]) { - const partySize = this.excludeDisallowedPokemon ? scene.getPokemonAllowedInBattle().length : scene.getPlayerParty().length; + const partySize = this.excludeDisallowedPokemon ? globalScene.getPokemonAllowedInBattle().length : globalScene.getPlayerParty().length; if (partySize >= 0 && (this.partySizeRange[0] >= 0 && this.partySizeRange[0] > partySize) || (this.partySizeRange[1] >= 0 && this.partySizeRange[1] < partySize)) { return false; } @@ -342,8 +334,8 @@ export class PartySizeRequirement extends EncounterSceneRequirement { return true; } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { - return [ "partySize", scene.getPlayerParty().length.toString() ]; + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { + return [ "partySize", globalScene.getPlayerParty().length.toString() ]; } } @@ -357,14 +349,14 @@ export class PersistentModifierRequirement extends EncounterSceneRequirement { this.requiredHeldItemModifiers = Array.isArray(heldItem) ? heldItem : [ heldItem ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredHeldItemModifiers?.length < 0) { return false; } let modifierCount = 0; this.requiredHeldItemModifiers.forEach(modifier => { - const matchingMods = scene.findModifiers(m => m.constructor.name === modifier); + const matchingMods = globalScene.findModifiers(m => m.constructor.name === modifier); if (matchingMods?.length > 0) { matchingMods.forEach(matchingMod => { modifierCount += matchingMod.stackCount; @@ -375,7 +367,7 @@ export class PersistentModifierRequirement extends EncounterSceneRequirement { return modifierCount >= this.minNumberOfItems; } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { return [ "requiredItem", this.requiredHeldItemModifiers[0] ]; } } @@ -390,20 +382,20 @@ export class MoneyRequirement extends EncounterSceneRequirement { this.scalingMultiplier = scalingMultiplier ?? 0; } - override meetsRequirement(scene: BattleScene): boolean { - const money = scene.money; + override meetsRequirement(): boolean { + const money = globalScene.money; if (isNullOrUndefined(money)) { return false; } if (this.scalingMultiplier > 0) { - this.requiredMoney = scene.getWaveMoneyAmount(this.scalingMultiplier); + this.requiredMoney = globalScene.getWaveMoneyAmount(this.scalingMultiplier); } return !(this.requiredMoney > 0 && this.requiredMoney > money); } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { - const value = this.scalingMultiplier > 0 ? scene.getWaveMoneyAmount(this.scalingMultiplier).toString() : this.requiredMoney.toString(); + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { + const value = this.scalingMultiplier > 0 ? globalScene.getWaveMoneyAmount(this.scalingMultiplier).toString() : this.requiredMoney.toString(); return [ "money", value ]; } } @@ -420,8 +412,8 @@ export class SpeciesRequirement extends EncounterPokemonRequirement { this.requiredSpecies = Array.isArray(species) ? species : [ species ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredSpecies?.length < 0) { return false; } @@ -437,7 +429,7 @@ export class SpeciesRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { if (pokemon?.species.speciesId && this.requiredSpecies.includes(pokemon.species.speciesId)) { return [ "species", Species[pokemon.species.speciesId] ]; } @@ -458,8 +450,8 @@ export class NatureRequirement extends EncounterPokemonRequirement { this.requiredNature = Array.isArray(nature) ? nature : [ nature ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredNature?.length < 0) { return false; } @@ -475,7 +467,7 @@ export class NatureRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { if (!isNullOrUndefined(pokemon?.nature) && this.requiredNature.includes(pokemon.nature)) { return [ "nature", Nature[pokemon.nature] ]; } @@ -497,8 +489,8 @@ export class TypeRequirement extends EncounterPokemonRequirement { this.requiredType = Array.isArray(type) ? type : [ type ]; } - override meetsRequirement(scene: BattleScene): boolean { - let partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + let partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon)) { return false; @@ -520,7 +512,7 @@ export class TypeRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const includedTypes = this.requiredType.filter((ty) => pokemon?.getTypes().includes(ty)); if (includedTypes.length > 0) { return [ "type", Type[includedTypes[0]] ]; @@ -544,8 +536,8 @@ export class MoveRequirement extends EncounterPokemonRequirement { this.requiredMoves = Array.isArray(moves) ? moves : [ moves ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredMoves?.length < 0) { return false; } @@ -566,7 +558,7 @@ export class MoveRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const includedMoves = pokemon?.moveset.filter((move) => move?.moveId && this.requiredMoves.includes(move.moveId)); if (includedMoves && includedMoves.length > 0 && includedMoves[0]) { return [ "move", includedMoves[0].getName() ]; @@ -593,8 +585,8 @@ export class CompatibleMoveRequirement extends EncounterPokemonRequirement { this.requiredMoves = Array.isArray(learnableMove) ? learnableMove : [ learnableMove ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredMoves?.length < 0) { return false; } @@ -610,7 +602,7 @@ export class CompatibleMoveRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const includedCompatMoves = this.requiredMoves.filter((reqMove) => pokemon?.compatibleTms.filter((tm) => !pokemon.moveset.find(m => m?.moveId === tm)).includes(reqMove)); if (includedCompatMoves.length > 0) { return [ "compatibleMove", Moves[includedCompatMoves[0]] ]; @@ -634,8 +626,8 @@ export class AbilityRequirement extends EncounterPokemonRequirement { this.requiredAbilities = Array.isArray(abilities) ? abilities : [ abilities ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredAbilities?.length < 0) { return false; } @@ -655,7 +647,7 @@ export class AbilityRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(_scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const matchingAbility = this.requiredAbilities.find(a => pokemon?.hasAbility(a, false)); if (!isNullOrUndefined(matchingAbility)) { return [ "ability", allAbilities[matchingAbility].name ]; @@ -676,8 +668,8 @@ export class StatusEffectRequirement extends EncounterPokemonRequirement { this.requiredStatusEffect = Array.isArray(statusEffect) ? statusEffect : [ statusEffect ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredStatusEffect?.length < 0) { return false; } @@ -713,7 +705,7 @@ export class StatusEffectRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const reqStatus = this.requiredStatusEffect.filter((a) => { if (a === StatusEffect.NONE) { return isNullOrUndefined(pokemon?.status) || isNullOrUndefined(pokemon.status.effect) || pokemon.status.effect === a; @@ -745,8 +737,8 @@ export class CanFormChangeWithItemRequirement extends EncounterPokemonRequiremen this.requiredFormChangeItem = Array.isArray(formChangeItem) ? formChangeItem : [ formChangeItem ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredFormChangeItem?.length < 0) { return false; } @@ -775,7 +767,7 @@ export class CanFormChangeWithItemRequirement extends EncounterPokemonRequiremen } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const requiredItems = this.requiredFormChangeItem.filter((formChangeItem) => this.filterByForm(pokemon, formChangeItem)); if (requiredItems.length > 0) { return [ "formChangeItem", FormChangeItem[requiredItems[0]] ]; @@ -797,8 +789,8 @@ export class CanEvolveWithItemRequirement extends EncounterPokemonRequirement { this.requiredEvolutionItem = Array.isArray(evolutionItems) ? evolutionItems : [ evolutionItems ]; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon) || this.requiredEvolutionItem?.length < 0) { return false; } @@ -825,7 +817,7 @@ export class CanEvolveWithItemRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const requiredItems = this.requiredEvolutionItem.filter((evoItem) => this.filterByEvo(pokemon, evoItem)); if (requiredItems.length > 0) { return [ "evolutionItem", EvolutionItem[requiredItems[0]] ]; @@ -848,8 +840,8 @@ export class HeldItemRequirement extends EncounterPokemonRequirement { this.requireTransferable = requireTransferable; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon)) { return false; } @@ -873,7 +865,7 @@ export class HeldItemRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const requiredItems = pokemon?.getHeldItems().filter((it) => { return this.requiredHeldItemModifiers.some(heldItem => it.constructor.name === heldItem) && (!this.requireTransferable || it.isTransferable); @@ -899,8 +891,8 @@ export class AttackTypeBoosterHeldItemTypeRequirement extends EncounterPokemonRe this.requireTransferable = requireTransferable; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty(); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty(); if (isNullOrUndefined(partyPokemon)) { return false; } @@ -928,7 +920,7 @@ export class AttackTypeBoosterHeldItemTypeRequirement extends EncounterPokemonRe } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const requiredItems = pokemon?.getHeldItems().filter((it) => { return this.requiredHeldItemTypes.some(heldItemType => it instanceof AttackTypeBoosterModifier @@ -954,10 +946,10 @@ export class LevelRequirement extends EncounterPokemonRequirement { this.requiredLevelRange = requiredLevelRange; } - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { // Party Pokemon inside required level range if (!isNullOrUndefined(this.requiredLevelRange) && this.requiredLevelRange[0] <= this.requiredLevelRange[1]) { - const partyPokemon = scene.getPlayerParty(); + const partyPokemon = globalScene.getPlayerParty(); const pokemonInRange = this.queryParty(partyPokemon); if (pokemonInRange.length < this.minNumberOfPokemon) { return false; @@ -975,7 +967,7 @@ export class LevelRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { return [ "level", pokemon?.level.toString() ?? "" ]; } } @@ -992,10 +984,10 @@ export class FriendshipRequirement extends EncounterPokemonRequirement { this.requiredFriendshipRange = requiredFriendshipRange; } - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { // Party Pokemon inside required friendship range if (!isNullOrUndefined(this.requiredFriendshipRange) && this.requiredFriendshipRange[0] <= this.requiredFriendshipRange[1]) { - const partyPokemon = scene.getPlayerParty(); + const partyPokemon = globalScene.getPlayerParty(); const pokemonInRange = this.queryParty(partyPokemon); if (pokemonInRange.length < this.minNumberOfPokemon) { return false; @@ -1013,7 +1005,7 @@ export class FriendshipRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { return [ "friendship", pokemon?.friendship.toString() ?? "" ]; } } @@ -1035,10 +1027,10 @@ export class HealthRatioRequirement extends EncounterPokemonRequirement { this.requiredHealthRange = requiredHealthRange; } - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { // Party Pokemon's health inside required health range if (!isNullOrUndefined(this.requiredHealthRange) && this.requiredHealthRange[0] <= this.requiredHealthRange[1]) { - const partyPokemon = scene.getPlayerParty(); + const partyPokemon = globalScene.getPlayerParty(); const pokemonInRange = this.queryParty(partyPokemon); if (pokemonInRange.length < this.minNumberOfPokemon) { return false; @@ -1058,7 +1050,7 @@ export class HealthRatioRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { const hpRatio = pokemon?.getHpRatio(); if (!isNullOrUndefined(hpRatio)) { return [ "healthRatio", Math.floor(hpRatio * 100).toString() + "%" ]; @@ -1079,10 +1071,10 @@ export class WeightRequirement extends EncounterPokemonRequirement { this.requiredWeightRange = requiredWeightRange; } - override meetsRequirement(scene: BattleScene): boolean { + override meetsRequirement(): boolean { // Party Pokemon's weight inside required weight range if (!isNullOrUndefined(this.requiredWeightRange) && this.requiredWeightRange[0] <= this.requiredWeightRange[1]) { - const partyPokemon = scene.getPlayerParty(); + const partyPokemon = globalScene.getPlayerParty(); const pokemonInRange = this.queryParty(partyPokemon); if (pokemonInRange.length < this.minNumberOfPokemon) { return false; @@ -1100,7 +1092,7 @@ export class WeightRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(scene: BattleScene, pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(pokemon?: PlayerPokemon): [string, string] { return [ "weight", pokemon?.getWeight().toString() ?? "" ]; } } diff --git a/src/data/mystery-encounters/mystery-encounter.ts b/src/data/mystery-encounters/mystery-encounter.ts index e341da4e4350..bd7ccc44b9ea 100644 --- a/src/data/mystery-encounters/mystery-encounter.ts +++ b/src/data/mystery-encounters/mystery-encounter.ts @@ -2,7 +2,6 @@ import { EnemyPartyConfig } from "#app/data/mystery-encounters/utils/encounter-p import Pokemon, { PlayerPokemon, PokemonMove } from "#app/field/pokemon"; import { capitalizeFirstLetter, isNullOrUndefined } from "#app/utils"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; -import BattleScene from "#app/battle-scene"; import MysteryEncounterIntroVisuals, { MysteryEncounterSpriteConfig } from "#app/field/mystery-encounter-intro"; import * as Utils from "#app/utils"; import { StatusEffect } from "#enums/status-effect"; @@ -16,6 +15,7 @@ import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode import { GameModes } from "#app/game-mode"; import { EncounterAnim } from "#enums/encounter-anims"; import { Challenges } from "#enums/challenges"; +import { globalScene } from "#app/global-scene"; export interface EncounterStartOfBattleEffect { sourcePokemon?: Pokemon; @@ -55,11 +55,11 @@ export interface IMysteryEncounter { skipToFightInput: boolean; preventGameStatsUpdates: boolean; - onInit?: (scene: BattleScene) => boolean; - onVisualsStart?: (scene: BattleScene) => boolean; - doEncounterExp?: (scene: BattleScene) => boolean; - doEncounterRewards?: (scene: BattleScene) => boolean; - doContinueEncounter?: (scene: BattleScene) => Promise; + onInit?: () => boolean; + onVisualsStart?: () => boolean; + doEncounterExp?: () => boolean; + doEncounterRewards?: () => boolean; + doContinueEncounter?: () => Promise; requirements: EncounterSceneRequirement[]; primaryPokemonRequirements: EncounterPokemonRequirement[]; @@ -159,24 +159,24 @@ export default class MysteryEncounter implements IMysteryEncounter { // #region Event callback functions /** Event when Encounter is first loaded, use it for data conditioning */ - onInit?: (scene: BattleScene) => boolean; + onInit?: () => boolean; /** Event when battlefield visuals have finished sliding in and the encounter dialogue begins */ - onVisualsStart?: (scene: BattleScene) => boolean; + onVisualsStart?: () => boolean; /** Event triggered prior to {@linkcode CommandPhase}, during {@linkcode TurnInitPhase} */ - onTurnStart?: (scene: BattleScene) => boolean; + onTurnStart?: () => boolean; /** Event prior to any rewards logic in {@linkcode MysteryEncounterRewardsPhase} */ - onRewards?: (scene: BattleScene) => Promise; + onRewards?: () => Promise; /** Will provide the player party EXP before rewards are displayed for that wave */ - doEncounterExp?: (scene: BattleScene) => boolean; + doEncounterExp?: () => boolean; /** Will provide the player a rewards shop for that wave */ - doEncounterRewards?: (scene: BattleScene) => boolean; + doEncounterRewards?: () => boolean; /** Will execute callback during VictoryPhase of a continuousEncounter */ - doContinueEncounter?: (scene: BattleScene) => Promise; + doContinueEncounter?: () => Promise; /** * Can perform special logic when a ME battle is lost, before GameOver/battle retry prompt. * Should return `true` if it is treated as "real" Game Over, `false` if not. */ - onGameOver?: (scene: BattleScene) => boolean; + onGameOver?: () => boolean; /** * Requirements @@ -296,13 +296,12 @@ export default class MysteryEncounter implements IMysteryEncounter { /** * Checks if the current scene state meets the requirements for the {@linkcode MysteryEncounter} to spawn * This is used to filter the pool of encounters down to only the ones with all requirements met - * @param scene * @returns */ - meetsRequirements(scene: BattleScene): boolean { - const sceneReq = !this.requirements.some(requirement => !requirement.meetsRequirement(scene)); - const secReqs = this.meetsSecondaryRequirementAndSecondaryPokemonSelected(scene); // secondary is checked first to handle cases of primary overlapping with secondary - const priReqs = this.meetsPrimaryRequirementAndPrimaryPokemonSelected(scene); + meetsRequirements(): boolean { + const sceneReq = !this.requirements.some(requirement => !requirement.meetsRequirement()); + const secReqs = this.meetsSecondaryRequirementAndSecondaryPokemonSelected(); // secondary is checked first to handle cases of primary overlapping with secondary + const priReqs = this.meetsPrimaryRequirementAndPrimaryPokemonSelected(); return sceneReq && secReqs && priReqs; } @@ -310,11 +309,10 @@ export default class MysteryEncounter implements IMysteryEncounter { /** * Checks if a specific player pokemon meets all given primary EncounterPokemonRequirements * Used automatically as part of {@linkcode meetsRequirements}, but can also be used to manually check certain Pokemon where needed - * @param scene * @param pokemon */ - pokemonMeetsPrimaryRequirements(scene: BattleScene, pokemon: Pokemon): boolean { - return !this.primaryPokemonRequirements.some(req => !req.queryParty(scene.getPlayerParty()).map(p => p.id).includes(pokemon.id)); + pokemonMeetsPrimaryRequirements(pokemon: Pokemon): boolean { + return !this.primaryPokemonRequirements.some(req => !req.queryParty(globalScene.getPlayerParty()).map(p => p.id).includes(pokemon.id)); } /** @@ -322,22 +320,21 @@ export default class MysteryEncounter implements IMysteryEncounter { * AND there is a valid Pokemon assigned to {@linkcode primaryPokemon}. * If both {@linkcode primaryPokemonRequirements} and {@linkcode secondaryPokemonRequirements} are defined, * can cause scenarios where there are not enough Pokemon that are sufficient for all requirements. - * @param scene */ - private meetsPrimaryRequirementAndPrimaryPokemonSelected(scene: BattleScene): boolean { + private meetsPrimaryRequirementAndPrimaryPokemonSelected(): boolean { if (!this.primaryPokemonRequirements || this.primaryPokemonRequirements.length === 0) { - const activeMon = scene.getPlayerParty().filter(p => p.isActive(true)); + const activeMon = globalScene.getPlayerParty().filter(p => p.isActive(true)); if (activeMon.length > 0) { this.primaryPokemon = activeMon[0]; } else { - this.primaryPokemon = scene.getPlayerParty().filter(p => p.isAllowedInBattle())[0]; + this.primaryPokemon = globalScene.getPlayerParty().filter(p => p.isAllowedInBattle())[0]; } return true; } - let qualified: PlayerPokemon[] = scene.getPlayerParty(); + let qualified: PlayerPokemon[] = globalScene.getPlayerParty(); for (const req of this.primaryPokemonRequirements) { - if (req.meetsRequirement(scene)) { - qualified = qualified.filter(pkmn => req.queryParty(scene.getPlayerParty()).includes(pkmn)); + if (req.meetsRequirement()) { + qualified = qualified.filter(pkmn => req.queryParty(globalScene.getPlayerParty()).includes(pkmn)); } else { this.primaryPokemon = undefined; return false; @@ -386,18 +383,17 @@ export default class MysteryEncounter implements IMysteryEncounter { * AND there is a valid Pokemon assigned to {@linkcode secondaryPokemon} (if applicable). * If both {@linkcode primaryPokemonRequirements} and {@linkcode secondaryPokemonRequirements} are defined, * can cause scenarios where there are not enough Pokemon that are sufficient for all requirements. - * @param scene */ - private meetsSecondaryRequirementAndSecondaryPokemonSelected(scene: BattleScene): boolean { + private meetsSecondaryRequirementAndSecondaryPokemonSelected(): boolean { if (!this.secondaryPokemonRequirements || this.secondaryPokemonRequirements.length === 0) { this.secondaryPokemon = []; return true; } - let qualified: PlayerPokemon[] = scene.getPlayerParty(); + let qualified: PlayerPokemon[] = globalScene.getPlayerParty(); for (const req of this.secondaryPokemonRequirements) { - if (req.meetsRequirement(scene)) { - qualified = qualified.filter(pkmn => req.queryParty(scene.getPlayerParty()).includes(pkmn)); + if (req.meetsRequirement()) { + qualified = qualified.filter(pkmn => req.queryParty(globalScene.getPlayerParty()).includes(pkmn)); } else { this.secondaryPokemon = []; return false; @@ -409,10 +405,9 @@ export default class MysteryEncounter implements IMysteryEncounter { /** * Initializes encounter intro sprites based on the sprite configs defined in spriteConfigs - * @param scene */ - initIntroVisuals(scene: BattleScene): void { - this.introVisuals = new MysteryEncounterIntroVisuals(scene, this); + initIntroVisuals(): void { + this.introVisuals = new MysteryEncounterIntroVisuals(this); } /** @@ -420,11 +415,11 @@ export default class MysteryEncounter implements IMysteryEncounter { * Will use the first support pokemon in list * For multiple support pokemon in the dialogue token, it will have to be overridden. */ - populateDialogueTokensFromRequirements(scene: BattleScene): void { - this.meetsRequirements(scene); + populateDialogueTokensFromRequirements(): void { + this.meetsRequirements(); if (this.requirements?.length > 0) { for (const req of this.requirements) { - const dialogueToken = req.getDialogueToken(scene); + const dialogueToken = req.getDialogueToken(); if (dialogueToken?.length === 2) { this.setDialogueToken(...dialogueToken); } @@ -434,7 +429,7 @@ export default class MysteryEncounter implements IMysteryEncounter { this.setDialogueToken("primaryName", this.primaryPokemon.getNameToRender()); for (const req of this.primaryPokemonRequirements) { if (!req.invertQuery) { - const value = req.getDialogueToken(scene, this.primaryPokemon); + const value = req.getDialogueToken(this.primaryPokemon); if (value?.length === 2) { this.setDialogueToken("primary" + capitalizeFirstLetter(value[0]), value[1]); } @@ -445,7 +440,7 @@ export default class MysteryEncounter implements IMysteryEncounter { this.setDialogueToken("secondaryName", this.secondaryPokemon[0].getNameToRender()); for (const req of this.secondaryPokemonRequirements) { if (!req.invertQuery) { - const value = req.getDialogueToken(scene, this.secondaryPokemon[0]); + const value = req.getDialogueToken(this.secondaryPokemon[0]); if (value?.length === 2) { this.setDialogueToken("primary" + capitalizeFirstLetter(value[0]), value[1]); } @@ -457,11 +452,11 @@ export default class MysteryEncounter implements IMysteryEncounter { // Dialogue tokens for options for (let i = 0; i < this.options.length; i++) { const opt = this.options[i]; - opt.meetsRequirements(scene); + opt.meetsRequirements(); const j = i + 1; if (opt.requirements.length > 0) { for (const req of opt.requirements) { - const dialogueToken = req.getDialogueToken(scene); + const dialogueToken = req.getDialogueToken(); if (dialogueToken?.length === 2) { this.setDialogueToken("option" + j + capitalizeFirstLetter(dialogueToken[0]), dialogueToken[1]); } @@ -471,7 +466,7 @@ export default class MysteryEncounter implements IMysteryEncounter { this.setDialogueToken("option" + j + "PrimaryName", opt.primaryPokemon.getNameToRender()); for (const req of opt.primaryPokemonRequirements) { if (!req.invertQuery) { - const value = req.getDialogueToken(scene, opt.primaryPokemon); + const value = req.getDialogueToken(opt.primaryPokemon); if (value?.length === 2) { this.setDialogueToken("option" + j + "Primary" + capitalizeFirstLetter(value[0]), value[1]); } @@ -482,7 +477,7 @@ export default class MysteryEncounter implements IMysteryEncounter { this.setDialogueToken("option" + j + "SecondaryName", opt.secondaryPokemon[0].getNameToRender()); for (const req of opt.secondaryPokemonRequirements) { if (!req.invertQuery) { - const value = req.getDialogueToken(scene, opt.secondaryPokemon[0]); + const value = req.getDialogueToken(opt.secondaryPokemon[0]); if (value?.length === 2) { this.setDialogueToken("option" + j + "Secondary" + capitalizeFirstLetter(value[0]), value[1]); } @@ -518,10 +513,9 @@ export default class MysteryEncounter implements IMysteryEncounter { /** * Maintains seed offset for RNG consistency * Increments if the same {@linkcode MysteryEncounter} has multiple option select cycles - * @param scene */ - updateSeedOffset(scene: BattleScene) { - const currentOffset = this.seedOffset ?? scene.currentBattle.waveIndex * 1000; + updateSeedOffset() { + const currentOffset = this.seedOffset ?? globalScene.currentBattle.waveIndex * 1000; this.seedOffset = currentOffset + 512; } } @@ -858,7 +852,7 @@ export class MysteryEncounterBuilder implements Partial { * @param doEncounterRewards Synchronous callback function to perform during rewards phase of the encounter * @returns */ - withRewards(doEncounterRewards: (scene: BattleScene) => boolean): this & Required> { + withRewards(doEncounterRewards: () => boolean): this & Required> { return Object.assign(this, { doEncounterRewards: doEncounterRewards }); } @@ -872,7 +866,7 @@ export class MysteryEncounterBuilder implements Partial { * @param doEncounterExp Synchronous callback function to perform during rewards phase of the encounter * @returns */ - withExp(doEncounterExp: (scene: BattleScene) => boolean): this & Required> { + withExp(doEncounterExp: () => boolean): this & Required> { return Object.assign(this, { doEncounterExp: doEncounterExp }); } @@ -883,7 +877,7 @@ export class MysteryEncounterBuilder implements Partial { * @param onInit Synchronous callback function to perform as soon as the encounter is selected for the next phase * @returns */ - withOnInit(onInit: (scene: BattleScene) => boolean): this & Required> { + withOnInit(onInit: () => boolean): this & Required> { return Object.assign(this, { onInit }); } @@ -893,7 +887,7 @@ export class MysteryEncounterBuilder implements Partial { * @param onVisualsStart Synchronous callback function to perform as soon as the enemy field finishes sliding in * @returns */ - withOnVisualsStart(onVisualsStart: (scene: BattleScene) => boolean): this & Required> { + withOnVisualsStart(onVisualsStart: () => boolean): this & Required> { return Object.assign(this, { onVisualsStart: onVisualsStart }); } diff --git a/src/data/mystery-encounters/requirements/can-learn-move-requirement.ts b/src/data/mystery-encounters/requirements/can-learn-move-requirement.ts index a2c08938fbe3..d7012b9ad359 100644 --- a/src/data/mystery-encounters/requirements/can-learn-move-requirement.ts +++ b/src/data/mystery-encounters/requirements/can-learn-move-requirement.ts @@ -1,8 +1,8 @@ -import BattleScene from "#app/battle-scene"; import { Moves } from "#app/enums/moves"; import { PlayerPokemon, PokemonMove } from "#app/field/pokemon"; import { isNullOrUndefined } from "#app/utils"; import { EncounterPokemonRequirement } from "#app/data/mystery-encounters/mystery-encounter-requirements"; +import { globalScene } from "#app/global-scene"; /** * {@linkcode CanLearnMoveRequirement} options @@ -38,8 +38,8 @@ export class CanLearnMoveRequirement extends EncounterPokemonRequirement { this.invertQuery = options.invertQuery ?? false; } - override meetsRequirement(scene: BattleScene): boolean { - const partyPokemon = scene.getPlayerParty().filter((pkm) => (this.includeFainted ? pkm.isAllowedInChallenge() : pkm.isAllowedInBattle())); + override meetsRequirement(): boolean { + const partyPokemon = globalScene.getPlayerParty().filter((pkm) => (this.includeFainted ? pkm.isAllowedInChallenge() : pkm.isAllowedInBattle())); if (isNullOrUndefined(partyPokemon) || this.requiredMoves?.length < 0) { return false; @@ -63,7 +63,7 @@ export class CanLearnMoveRequirement extends EncounterPokemonRequirement { } } - override getDialogueToken(_scene: BattleScene, _pokemon?: PlayerPokemon): [string, string] { + override getDialogueToken(__pokemon?: PlayerPokemon): [string, string] { return [ "requiredMoves", this.requiredMoves.map(m => new PokemonMove(m).getName()).join(", ") ]; } diff --git a/src/data/mystery-encounters/utils/encounter-dialogue-utils.ts b/src/data/mystery-encounters/utils/encounter-dialogue-utils.ts index acaa7c6244fe..e3454739cc3a 100644 --- a/src/data/mystery-encounters/utils/encounter-dialogue-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-dialogue-utils.ts @@ -1,23 +1,23 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { getTextWithColors, TextStyle } from "#app/ui/text"; import { UiTheme } from "#enums/ui-theme"; import { isNullOrUndefined } from "#app/utils"; import i18next from "i18next"; /** - * Will inject all relevant dialogue tokens that exist in the {@linkcode BattleScene.currentBattle.mysteryEncounter.dialogueTokens}, into i18n text. + * Will inject all relevant dialogue tokens that exist in the {@linkcode BattlegScene.currentBattle.mysteryEncounter.dialogueTokens}, into i18n text. * Also adds BBCodeText fragments for colored text, if applicable * @param keyOrString * @param primaryStyle Can define a text style to be applied to the entire string. Must be defined for BBCodeText styles to be applied correctly */ -export function getEncounterText(scene: BattleScene, keyOrString?: string, primaryStyle?: TextStyle): string | null { +export function getEncounterText(keyOrString?: string, primaryStyle?: TextStyle): string | null { if (isNullOrUndefined(keyOrString)) { return null; } - const uiTheme = scene.uiTheme ?? UiTheme.DEFAULT; + const uiTheme = globalScene.uiTheme ?? UiTheme.DEFAULT; - let textString: string | null = getTextWithDialogueTokens(scene, keyOrString); + let textString: string | null = getTextWithDialogueTokens(keyOrString); // Can only color the text if a Primary Style is defined // primaryStyle is applied to all text that does not have its own specified style @@ -29,12 +29,12 @@ export function getEncounterText(scene: BattleScene, keyOrString?: string, prima } /** - * Helper function to inject {@linkcode BattleScene.currentBattle.mysteryEncounter.dialogueTokens} into a given content string + * Helper function to inject {@linkcode globalScene.currentBattle.mysteryEncounter.dialogueTokens} into a given content string * @param scene * @param keyOrString */ -function getTextWithDialogueTokens(scene: BattleScene, keyOrString: string): string | null { - const tokens = scene.currentBattle?.mysteryEncounter?.dialogueTokens; +function getTextWithDialogueTokens(keyOrString: string): string | null { + const tokens = globalScene.currentBattle?.mysteryEncounter?.dialogueTokens; if (i18next.exists(keyOrString, tokens)) { return i18next.t(keyOrString, tokens) as string; @@ -48,9 +48,9 @@ function getTextWithDialogueTokens(scene: BattleScene, keyOrString: string): str * @param scene * @param contentKey */ -export function queueEncounterMessage(scene: BattleScene, contentKey: string): void { - const text: string | null = getEncounterText(scene, contentKey); - scene.queueMessage(text ?? "", null, true); +export function queueEncounterMessage(contentKey: string): void { + const text: string | null = getEncounterText(contentKey); + globalScene.queueMessage(text ?? "", null, true); } /** @@ -62,10 +62,10 @@ export function queueEncounterMessage(scene: BattleScene, contentKey: string): v * @param callbackDelay * @param promptDelay */ -export function showEncounterText(scene: BattleScene, contentKey: string, delay: number | null = null, callbackDelay: number = 0, prompt: boolean = true, promptDelay: number | null = null): Promise { +export function showEncounterText(contentKey: string, delay: number | null = null, callbackDelay: number = 0, prompt: boolean = true, promptDelay: number | null = null): Promise { return new Promise(resolve => { - const text: string | null = getEncounterText(scene, contentKey); - scene.ui.showText(text ?? "", delay, () => resolve(), callbackDelay, prompt, promptDelay); + const text: string | null = getEncounterText(contentKey); + globalScene.ui.showText(text ?? "", delay, () => resolve(), callbackDelay, prompt, promptDelay); }); } @@ -77,10 +77,10 @@ export function showEncounterText(scene: BattleScene, contentKey: string, delay: * @param speakerContentKey * @param callbackDelay */ -export function showEncounterDialogue(scene: BattleScene, textContentKey: string, speakerContentKey: string, delay: number | null = null, callbackDelay: number = 0): Promise { +export function showEncounterDialogue(textContentKey: string, speakerContentKey: string, delay: number | null = null, callbackDelay: number = 0): Promise { return new Promise(resolve => { - const text: string | null = getEncounterText(scene, textContentKey); - const speaker: string | null = getEncounterText(scene, speakerContentKey); - scene.ui.showDialogue(text ?? "", speaker ?? "", delay, () => resolve(), callbackDelay); + const text: string | null = getEncounterText(textContentKey); + const speaker: string | null = getEncounterText(speakerContentKey); + globalScene.ui.showDialogue(text ?? "", speaker ?? "", delay, () => resolve(), callbackDelay); }); } diff --git a/src/data/mystery-encounters/utils/encounter-phase-utils.ts b/src/data/mystery-encounters/utils/encounter-phase-utils.ts index d43bce0ace57..7ada28c9ba2e 100644 --- a/src/data/mystery-encounters/utils/encounter-phase-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-phase-utils.ts @@ -16,7 +16,6 @@ import { BattlerTagType } from "#enums/battler-tag-type"; import { Biome } from "#enums/biome"; import { TrainerType } from "#enums/trainer-type"; import i18next from "i18next"; -import BattleScene from "#app/battle-scene"; import Trainer, { TrainerVariant } from "#app/field/trainer"; import { Gender } from "#app/data/gender"; import { Nature } from "#enums/nature"; @@ -38,32 +37,33 @@ import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { PartyExpPhase } from "#app/phases/party-exp-phase"; import { Variant } from "#app/data/variant"; import { StatusEffect } from "#enums/status-effect"; +import { globalScene } from "#app/global-scene"; /** * Animates exclamation sprite over trainer's head at start of encounter * @param scene */ -export function doTrainerExclamation(scene: BattleScene) { - const exclamationSprite = scene.add.sprite(0, 0, "encounter_exclaim"); +export function doTrainerExclamation() { + const exclamationSprite = globalScene.add.sprite(0, 0, "encounter_exclaim"); exclamationSprite.setName("exclamation"); - scene.field.add(exclamationSprite); - scene.field.moveTo(exclamationSprite, scene.field.getAll().length - 1); + globalScene.field.add(exclamationSprite); + globalScene.field.moveTo(exclamationSprite, globalScene.field.getAll().length - 1); exclamationSprite.setVisible(true); exclamationSprite.setPosition(110, 68); - scene.tweens.add({ + globalScene.tweens.add({ targets: exclamationSprite, y: "-=25", ease: "Cubic.easeOut", duration: 300, yoyo: true, onComplete: () => { - scene.time.delayedCall(800, () => { - scene.field.remove(exclamationSprite, true); + globalScene.time.delayedCall(800, () => { + globalScene.field.remove(exclamationSprite, true); }); } }); - scene.playSound("battle_anims/GEN8- Exclaim", { volume: 0.7 }); + globalScene.playSound("battle_anims/GEN8- Exclaim", { volume: 0.7 }); } export interface EnemyPokemonConfig { @@ -114,14 +114,13 @@ export interface EnemyPartyConfig { * Generates an enemy party for a mystery encounter battle * This will override and replace any standard encounter generation logic * Useful for tailoring specific battles to mystery encounters - * @param scene Battle Scene * @param partyConfig Can pass various customizable attributes for the enemy party, see EnemyPartyConfig */ -export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: EnemyPartyConfig): Promise { +export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig): Promise { const loaded: boolean = false; const loadEnemyAssets: Promise[] = []; - const battle: Battle = scene.currentBattle; + const battle: Battle = globalScene.currentBattle; let doubleBattle: boolean = partyConfig?.doubleBattle ?? false; @@ -130,10 +129,10 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: const partyTrainerConfig = partyConfig?.trainerConfig; let trainerConfig: TrainerConfig; if (!isNullOrUndefined(trainerType) || partyTrainerConfig) { - scene.currentBattle.mysteryEncounter!.encounterMode = MysteryEncounterMode.TRAINER_BATTLE; - if (scene.currentBattle.trainer) { - scene.currentBattle.trainer.setVisible(false); - scene.currentBattle.trainer.destroy(); + globalScene.currentBattle.mysteryEncounter!.encounterMode = MysteryEncounterMode.TRAINER_BATTLE; + if (globalScene.currentBattle.trainer) { + globalScene.currentBattle.trainer.setVisible(false); + globalScene.currentBattle.trainer.destroy(); } trainerConfig = partyTrainerConfig ? partyTrainerConfig : trainerConfigs[trainerType!]; @@ -141,23 +140,23 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: const doubleTrainer = trainerConfig.doubleOnly || (trainerConfig.hasDouble && !!partyConfig.doubleBattle); doubleBattle = doubleTrainer; const trainerFemale = isNullOrUndefined(partyConfig.female) ? !!(Utils.randSeedInt(2)) : partyConfig.female; - const newTrainer = new Trainer(scene, trainerConfig.trainerType, doubleTrainer ? TrainerVariant.DOUBLE : trainerFemale ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT, undefined, undefined, undefined, trainerConfig); + const newTrainer = new Trainer(trainerConfig.trainerType, doubleTrainer ? TrainerVariant.DOUBLE : trainerFemale ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT, undefined, undefined, undefined, trainerConfig); newTrainer.x += 300; newTrainer.setVisible(false); - scene.field.add(newTrainer); - scene.currentBattle.trainer = newTrainer; + globalScene.field.add(newTrainer); + globalScene.currentBattle.trainer = newTrainer; loadEnemyAssets.push(newTrainer.loadAssets().then(() => newTrainer.initSprite())); - battle.enemyLevels = scene.currentBattle.trainer.getPartyLevels(scene.currentBattle.waveIndex); + battle.enemyLevels = globalScene.currentBattle.trainer.getPartyLevels(globalScene.currentBattle.waveIndex); } else { // Wild - scene.currentBattle.mysteryEncounter!.encounterMode = MysteryEncounterMode.WILD_BATTLE; + globalScene.currentBattle.mysteryEncounter!.encounterMode = MysteryEncounterMode.WILD_BATTLE; const numEnemies = partyConfig?.pokemonConfigs && partyConfig.pokemonConfigs.length > 0 ? partyConfig?.pokemonConfigs?.length : doubleBattle ? 2 : 1; - battle.enemyLevels = new Array(numEnemies).fill(null).map(() => scene.currentBattle.getLevelForWave()); + battle.enemyLevels = new Array(numEnemies).fill(null).map(() => globalScene.currentBattle.getLevelForWave()); } - scene.getEnemyParty().forEach(enemyPokemon => { - scene.field.remove(enemyPokemon, true); + globalScene.getEnemyParty().forEach(enemyPokemon => { + globalScene.field.remove(enemyPokemon, true); }); battle.enemyParty = []; battle.double = doubleBattle; @@ -168,7 +167,7 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: // levelAdditiveModifier value of 0.5 will halve the modifier scaling, 2 will double it, etc. // Leaving null/undefined will disable level scaling const mult: number = !isNullOrUndefined(partyConfig.levelAdditiveModifier) ? partyConfig.levelAdditiveModifier : 0; - const additive = Math.max(Math.round((scene.currentBattle.waveIndex / 10) * mult), 0); + const additive = Math.max(Math.round((globalScene.currentBattle.waveIndex / 10) * mult), 0); battle.enemyLevels = battle.enemyLevels.map(level => level + additive); battle.enemyLevels.forEach((level, e) => { @@ -184,7 +183,7 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: dataSource = config.dataSource; enemySpecies = config.species; isBoss = config.isBoss; - battle.enemyParty[e] = scene.addEnemyPokemon(enemySpecies, level, TrainerSlot.TRAINER, isBoss, false, dataSource); + battle.enemyParty[e] = globalScene.addEnemyPokemon(enemySpecies, level, TrainerSlot.TRAINER, isBoss, false, dataSource); } else { battle.enemyParty[e] = battle.trainer.genPartyMember(e); } @@ -196,17 +195,17 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: enemySpecies = config.species; isBoss = config.isBoss; if (isBoss) { - scene.currentBattle.mysteryEncounter!.encounterMode = MysteryEncounterMode.BOSS_BATTLE; + globalScene.currentBattle.mysteryEncounter!.encounterMode = MysteryEncounterMode.BOSS_BATTLE; } } else { - enemySpecies = scene.randomSpecies(battle.waveIndex, level, true); + enemySpecies = globalScene.randomSpecies(battle.waveIndex, level, true); } - battle.enemyParty[e] = scene.addEnemyPokemon(enemySpecies, level, TrainerSlot.NONE, isBoss, false, dataSource); + battle.enemyParty[e] = globalScene.addEnemyPokemon(enemySpecies, level, TrainerSlot.NONE, isBoss, false, dataSource); } } - const enemyPokemon = scene.getEnemyParty()[e]; + const enemyPokemon = globalScene.getEnemyParty()[e]; // Make sure basic data is clean enemyPokemon.hp = enemyPokemon.getMaxHp(); @@ -219,7 +218,7 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: } if (!loaded && isNullOrUndefined(partyConfig.countAsSeen) || partyConfig.countAsSeen) { - scene.gameData.setPokemonSeen(enemyPokemon, true, !!(trainerType || trainerConfig)); + globalScene.gameData.setPokemonSeen(enemyPokemon, true, !!(trainerType || trainerConfig)); } if (partyConfig?.pokemonConfigs && e < partyConfig.pokemonConfigs.length) { @@ -257,7 +256,7 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: // Set Boss if (config.isBoss) { - let segments = !isNullOrUndefined(config.bossSegments) ? config.bossSegments! : scene.getEncounterBossSegments(scene.currentBattle.waveIndex, level, enemySpecies, true); + let segments = !isNullOrUndefined(config.bossSegments) ? config.bossSegments! : globalScene.getEncounterBossSegments(globalScene.currentBattle.waveIndex, level, enemySpecies, true); if (!isNullOrUndefined(config.bossSegmentModifier)) { segments += config.bossSegmentModifier; } @@ -343,7 +342,7 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: console.log(`Pokemon: ${enemyPokemon.name}`, `Species ID: ${enemyPokemon.species.speciesId}`, `Stats: ${enemyPokemon.stats}`, `Ability: ${enemyPokemon.getAbility().name}`, `Passive Ability: ${enemyPokemon.getPassiveAbility().name}`); }); - scene.pushPhase(new MysteryEncounterBattlePhase(scene, partyConfig.disableSwitch)); + globalScene.pushPhase(new MysteryEncounterBattlePhase(partyConfig.disableSwitch)); await Promise.all(loadEnemyAssets); battle.enemyParty.forEach((enemyPokemon_2, e_1) => { @@ -357,11 +356,11 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: } }); if (!loaded) { - regenerateModifierPoolThresholds(scene.getEnemyField(), battle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD); + regenerateModifierPoolThresholds(globalScene.getEnemyField(), battle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD); const customModifierTypes = partyConfig?.pokemonConfigs ?.filter(config => config?.modifierConfigs) .map(config => config.modifierConfigs!); - scene.generateEnemyModifiers(customModifierTypes); + globalScene.generateEnemyModifiers(customModifierTypes); } } @@ -370,45 +369,42 @@ export async function initBattleWithEnemyConfig(scene: BattleScene, partyConfig: * See: [startOfBattleEffects](IMysteryEncounter.startOfBattleEffects) for more details * * This promise does not need to be awaited on if called in an encounter onInit (will just load lazily) - * @param scene * @param moves */ -export function loadCustomMovesForEncounter(scene: BattleScene, moves: Moves | Moves[]) { +export function loadCustomMovesForEncounter(moves: Moves | Moves[]) { moves = Array.isArray(moves) ? moves : [ moves ]; - return Promise.all(moves.map(move => initMoveAnim(scene, move))) - .then(() => loadMoveAnimAssets(scene, moves)); + return Promise.all(moves.map(move => initMoveAnim(move))) + .then(() => loadMoveAnimAssets(moves)); } /** * Will update player money, and animate change (sound optional) - * @param scene * @param changeValue * @param playSound * @param showMessage */ -export function updatePlayerMoney(scene: BattleScene, changeValue: number, playSound: boolean = true, showMessage: boolean = true) { - scene.money = Math.min(Math.max(scene.money + changeValue, 0), Number.MAX_SAFE_INTEGER); - scene.updateMoneyText(); - scene.animateMoneyChanged(false); +export function updatePlayerMoney(changeValue: number, playSound: boolean = true, showMessage: boolean = true) { + globalScene.money = Math.min(Math.max(globalScene.money + changeValue, 0), Number.MAX_SAFE_INTEGER); + globalScene.updateMoneyText(); + globalScene.animateMoneyChanged(false); if (playSound) { - scene.playSound("se/buy"); + globalScene.playSound("se/buy"); } if (showMessage) { if (changeValue < 0) { - scene.queueMessage(i18next.t("mysteryEncounterMessages:paid_money", { amount: -changeValue }), null, true); + globalScene.queueMessage(i18next.t("mysteryEncounterMessages:paid_money", { amount: -changeValue }), null, true); } else { - scene.queueMessage(i18next.t("mysteryEncounterMessages:receive_money", { amount: changeValue }), null, true); + globalScene.queueMessage(i18next.t("mysteryEncounterMessages:receive_money", { amount: changeValue }), null, true); } } } /** * Converts modifier bullshit to an actual item - * @param scene Battle Scene * @param modifier * @param pregenArgs Can specify BerryType for berries, TM for TMs, AttackBoostType for item, etc. */ -export function generateModifierType(scene: BattleScene, modifier: () => ModifierType, pregenArgs?: any[]): ModifierType | null { +export function generateModifierType(modifier: () => ModifierType, pregenArgs?: any[]): ModifierType | null { const modifierId = Object.keys(modifierTypes).find(k => modifierTypes[k] === modifier); if (!modifierId) { return null; @@ -419,19 +415,18 @@ export function generateModifierType(scene: BattleScene, modifier: () => Modifie // Populates item id and tier (order matters) result = result .withIdFromFunc(modifierTypes[modifierId]) - .withTierFromPool(ModifierPoolType.PLAYER, scene.getPlayerParty()); + .withTierFromPool(ModifierPoolType.PLAYER, globalScene.getPlayerParty()); - return result instanceof ModifierTypeGenerator ? result.generateType(scene.getPlayerParty(), pregenArgs) : result; + return result instanceof ModifierTypeGenerator ? result.generateType(globalScene.getPlayerParty(), pregenArgs) : result; } /** * Converts modifier bullshit to an actual item - * @param scene - Battle Scene * @param modifier * @param pregenArgs - can specify BerryType for berries, TM for TMs, AttackBoostType for item, etc. */ -export function generateModifierTypeOption(scene: BattleScene, modifier: () => ModifierType, pregenArgs?: any[]): ModifierTypeOption | null { - const result = generateModifierType(scene, modifier, pregenArgs); +export function generateModifierTypeOption(modifier: () => ModifierType, pregenArgs?: any[]): ModifierTypeOption | null { + const result = generateModifierType(modifier, pregenArgs); if (result) { return new ModifierTypeOption(result, 0); } @@ -440,30 +435,29 @@ export function generateModifierTypeOption(scene: BattleScene, modifier: () => M /** * This function is intended for use inside onPreOptionPhase() of an encounter option - * @param scene * @param onPokemonSelected - Any logic that needs to be performed when Pokemon is chosen * If a second option needs to be selected, onPokemonSelected should return a OptionSelectItem[] object * @param onPokemonNotSelected - Any logic that needs to be performed if no Pokemon is chosen * @param selectablePokemonFilter */ -export function selectPokemonForOption(scene: BattleScene, onPokemonSelected: (pokemon: PlayerPokemon) => void | OptionSelectItem[], onPokemonNotSelected?: () => void, selectablePokemonFilter?: PokemonSelectFilter): Promise { +export function selectPokemonForOption(onPokemonSelected: (pokemon: PlayerPokemon) => void | OptionSelectItem[], onPokemonNotSelected?: () => void, selectablePokemonFilter?: PokemonSelectFilter): Promise { return new Promise(resolve => { - const modeToSetOnExit = scene.ui.getMode(); + const modeToSetOnExit = globalScene.ui.getMode(); // Open party screen to choose pokemon - scene.ui.setMode(Mode.PARTY, PartyUiMode.SELECT, -1, (slotIndex: number, option: PartyOption) => { - if (slotIndex < scene.getPlayerParty().length) { - scene.ui.setMode(modeToSetOnExit).then(() => { - const pokemon = scene.getPlayerParty()[slotIndex]; + globalScene.ui.setMode(Mode.PARTY, PartyUiMode.SELECT, -1, (slotIndex: number, option: PartyOption) => { + if (slotIndex < globalScene.getPlayerParty().length) { + globalScene.ui.setMode(modeToSetOnExit).then(() => { + const pokemon = globalScene.getPlayerParty()[slotIndex]; const secondaryOptions = onPokemonSelected(pokemon); if (!secondaryOptions) { - scene.currentBattle.mysteryEncounter!.setDialogueToken("selectedPokemon", pokemon.getNameToRender()); + globalScene.currentBattle.mysteryEncounter!.setDialogueToken("selectedPokemon", pokemon.getNameToRender()); resolve(true); return; } // There is a second option to choose after selecting the Pokemon - scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { const displayOptions = () => { // Always appends a cancel option to bottom of options const fullOptions = secondaryOptions.map(option => { @@ -471,7 +465,7 @@ export function selectPokemonForOption(scene: BattleScene, onPokemonSelected: (p const onSelect = option.handler; option.handler = () => { onSelect(); - scene.currentBattle.mysteryEncounter!.setDialogueToken("selectedPokemon", pokemon.getNameToRender()); + globalScene.currentBattle.mysteryEncounter!.setDialogueToken("selectedPokemon", pokemon.getNameToRender()); resolve(true); return true; }; @@ -479,13 +473,13 @@ export function selectPokemonForOption(scene: BattleScene, onPokemonSelected: (p }).concat({ label: i18next.t("menu:cancel"), handler: () => { - scene.ui.clearText(); - scene.ui.setMode(modeToSetOnExit); + globalScene.ui.clearText(); + globalScene.ui.setMode(modeToSetOnExit); resolve(false); return true; }, onHover: () => { - showEncounterText(scene, i18next.t("mysteryEncounterMessages:cancel_option"), 0, 0, false); + showEncounterText(i18next.t("mysteryEncounterMessages:cancel_option"), 0, 0, false); } }); @@ -500,19 +494,19 @@ export function selectPokemonForOption(scene: BattleScene, onPokemonSelected: (p if (fullOptions[0].onHover) { fullOptions[0].onHover(); } - scene.ui.setModeWithoutClear(Mode.OPTION_SELECT, config, null, true); + globalScene.ui.setModeWithoutClear(Mode.OPTION_SELECT, config, null, true); }; - const textPromptKey = scene.currentBattle.mysteryEncounter?.selectedOption?.dialogue?.secondOptionPrompt; + const textPromptKey = globalScene.currentBattle.mysteryEncounter?.selectedOption?.dialogue?.secondOptionPrompt; if (!textPromptKey) { displayOptions(); } else { - showEncounterText(scene, textPromptKey).then(() => displayOptions()); + showEncounterText(textPromptKey).then(() => displayOptions()); } }); }); } else { - scene.ui.setMode(modeToSetOnExit).then(() => { + globalScene.ui.setMode(modeToSetOnExit).then(() => { if (onPokemonNotSelected) { onPokemonNotSelected(); } @@ -529,33 +523,33 @@ interface PokemonAndOptionSelected { } /** - * This function is intended for use inside onPreOptionPhase() of an encounter option - * @param scene - * If a second option needs to be selected, onPokemonSelected should return a OptionSelectItem[] object + * This function is intended for use inside `onPreOptionPhase()` of an encounter option + * + * If a second option needs to be selected, `onPokemonSelected` should return a {@linkcode OptionSelectItem}`[]` object * @param options * @param optionSelectPromptKey * @param selectablePokemonFilter * @param onHoverOverCancelOption */ -export function selectOptionThenPokemon(scene: BattleScene, options: OptionSelectItem[], optionSelectPromptKey: string, selectablePokemonFilter?: PokemonSelectFilter, onHoverOverCancelOption?: () => void): Promise { +export function selectOptionThenPokemon(options: OptionSelectItem[], optionSelectPromptKey: string, selectablePokemonFilter?: PokemonSelectFilter, onHoverOverCancelOption?: () => void): Promise { return new Promise(resolve => { - const modeToSetOnExit = scene.ui.getMode(); + const modeToSetOnExit = globalScene.ui.getMode(); const displayOptions = (config: OptionSelectConfig) => { - scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { if (!optionSelectPromptKey) { // Do hover over the starting selection option if (fullOptions[0].onHover) { fullOptions[0].onHover(); } - scene.ui.setMode(Mode.OPTION_SELECT, config); + globalScene.ui.setMode(Mode.OPTION_SELECT, config); } else { - showEncounterText(scene, optionSelectPromptKey).then(() => { + showEncounterText(optionSelectPromptKey).then(() => { // Do hover over the starting selection option if (fullOptions[0].onHover) { fullOptions[0].onHover(); } - scene.ui.setMode(Mode.OPTION_SELECT, config); + globalScene.ui.setMode(Mode.OPTION_SELECT, config); }); } }); @@ -563,10 +557,10 @@ export function selectOptionThenPokemon(scene: BattleScene, options: OptionSelec const selectPokemonAfterOption = (selectedOptionIndex: number) => { // Open party screen to choose a Pokemon - scene.ui.setMode(Mode.PARTY, PartyUiMode.SELECT, -1, (slotIndex: number, option: PartyOption) => { - if (slotIndex < scene.getPlayerParty().length) { + globalScene.ui.setMode(Mode.PARTY, PartyUiMode.SELECT, -1, (slotIndex: number, option: PartyOption) => { + if (slotIndex < globalScene.getPlayerParty().length) { // Pokemon and option selected - scene.ui.setMode(modeToSetOnExit).then(() => { + globalScene.ui.setMode(modeToSetOnExit).then(() => { const result: PokemonAndOptionSelected = { selectedPokemonIndex: slotIndex, selectedOptionIndex: selectedOptionIndex }; resolve(result); }); @@ -590,8 +584,8 @@ export function selectOptionThenPokemon(scene: BattleScene, options: OptionSelec }).concat({ label: i18next.t("menu:cancel"), handler: () => { - scene.ui.clearText(); - scene.ui.setMode(modeToSetOnExit); + globalScene.ui.clearText(); + globalScene.ui.setMode(modeToSetOnExit); resolve(null); return true; }, @@ -599,7 +593,7 @@ export function selectOptionThenPokemon(scene: BattleScene, options: OptionSelec if (onHoverOverCancelOption) { onHoverOverCancelOption(); } - showEncounterText(scene, i18next.t("mysteryEncounterMessages:cancel_option"), 0, 0, false); + showEncounterText(i18next.t("mysteryEncounterMessages:cancel_option"), 0, 0, false); } }); @@ -617,27 +611,26 @@ export function selectOptionThenPokemon(scene: BattleScene, options: OptionSelec /** * Will initialize reward phases to follow the mystery encounter * Can have shop displayed or skipped - * @param scene - Battle Scene * @param customShopRewards - adds a shop phase with the specified rewards / reward tiers * @param eggRewards * @param preRewardsCallback - can execute an arbitrary callback before the new phases if necessary (useful for updating items/party/injecting new phases before {@linkcode MysteryEncounterRewardsPhase}) */ -export function setEncounterRewards(scene: BattleScene, customShopRewards?: CustomModifierSettings, eggRewards?: IEggOptions[], preRewardsCallback?: Function) { - scene.currentBattle.mysteryEncounter!.doEncounterRewards = (scene: BattleScene) => { +export function setEncounterRewards(customShopRewards?: CustomModifierSettings, eggRewards?: IEggOptions[], preRewardsCallback?: Function) { + globalScene.currentBattle.mysteryEncounter!.doEncounterRewards = () => { if (preRewardsCallback) { preRewardsCallback(); } if (customShopRewards) { - scene.unshiftPhase(new SelectModifierPhase(scene, 0, undefined, customShopRewards)); + globalScene.unshiftPhase(new SelectModifierPhase(0, undefined, customShopRewards)); } else { - scene.tryRemovePhase(p => p instanceof SelectModifierPhase); + globalScene.tryRemovePhase(p => p instanceof SelectModifierPhase); } if (eggRewards) { eggRewards.forEach(eggOptions => { const egg = new Egg(eggOptions); - egg.addEggToGameData(scene); + egg.addEggToGameData(); }); } @@ -648,10 +641,11 @@ export function setEncounterRewards(scene: BattleScene, customShopRewards?: Cust /** * Will initialize exp phases into the phase queue (these are in addition to any combat or other exp earned) * Exp Share and Exp Balance will still function as normal - * @param scene - Battle Scene * @param participantId - id/s of party pokemon that get full exp value. Other party members will receive Exp Share amounts * @param baseExpValue - gives exp equivalent to a pokemon of the wave index's level. + * * Guidelines: + * ```md * 36 - Sunkern (lowest in game) * 62-64 - regional starter base evos * 100 - Scyther @@ -660,14 +654,15 @@ export function setEncounterRewards(scene: BattleScene, customShopRewards?: Cust * 290 - trio legendaries * 340 - box legendaries * 608 - Blissey (highest in game) + * ``` * https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_effort_value_yield_(Generation_IX) * @param useWaveIndex - set to false when directly passing the the full exp value instead of baseExpValue */ -export function setEncounterExp(scene: BattleScene, participantId: number | number[], baseExpValue: number, useWaveIndex: boolean = true) { +export function setEncounterExp(participantId: number | number[], baseExpValue: number, useWaveIndex: boolean = true) { const participantIds = Array.isArray(participantId) ? participantId : [ participantId ]; - scene.currentBattle.mysteryEncounter!.doEncounterExp = (scene: BattleScene) => { - scene.unshiftPhase(new PartyExpPhase(scene, baseExpValue, useWaveIndex, new Set(participantIds))); + globalScene.currentBattle.mysteryEncounter!.doEncounterExp = () => { + globalScene.unshiftPhase(new PartyExpPhase(baseExpValue, useWaveIndex, new Set(participantIds))); return true; }; @@ -686,60 +681,57 @@ export class OptionSelectSettings { /** * Can be used to queue a new series of Options to select for an Encounter * MUST be used only in onOptionPhase, will not work in onPreOptionPhase or onPostOptionPhase - * @param scene * @param optionSelectSettings */ -export function initSubsequentOptionSelect(scene: BattleScene, optionSelectSettings: OptionSelectSettings) { - scene.pushPhase(new MysteryEncounterPhase(scene, optionSelectSettings)); +export function initSubsequentOptionSelect(optionSelectSettings: OptionSelectSettings) { + globalScene.pushPhase(new MysteryEncounterPhase(optionSelectSettings)); } /** * Can be used to exit an encounter without any battles or followup * Will skip any shops and rewards, and queue the next encounter phase as normal - * @param scene * @param addHealPhase - when true, will add a shop phase to end of encounter with 0 rewards but healing items are available * @param encounterMode - Can set custom encounter mode if necessary (may be required for forcing Pokemon to return before next phase) */ -export function leaveEncounterWithoutBattle(scene: BattleScene, addHealPhase: boolean = false, encounterMode: MysteryEncounterMode = MysteryEncounterMode.NO_BATTLE) { - scene.currentBattle.mysteryEncounter!.encounterMode = encounterMode; - scene.clearPhaseQueue(); - scene.clearPhaseQueueSplice(); - handleMysteryEncounterVictory(scene, addHealPhase); +export function leaveEncounterWithoutBattle(addHealPhase: boolean = false, encounterMode: MysteryEncounterMode = MysteryEncounterMode.NO_BATTLE) { + globalScene.currentBattle.mysteryEncounter!.encounterMode = encounterMode; + globalScene.clearPhaseQueue(); + globalScene.clearPhaseQueueSplice(); + handleMysteryEncounterVictory(addHealPhase); } /** * - * @param scene * @param addHealPhase - Adds an empty shop phase to allow player to purchase healing items * @param doNotContinue - default `false`. If set to true, will not end the battle and continue to next wave */ -export function handleMysteryEncounterVictory(scene: BattleScene, addHealPhase: boolean = false, doNotContinue: boolean = false) { - const allowedPkm = scene.getPlayerParty().filter((pkm) => pkm.isAllowedInBattle()); +export function handleMysteryEncounterVictory(addHealPhase: boolean = false, doNotContinue: boolean = false) { + const allowedPkm = globalScene.getPlayerParty().filter((pkm) => pkm.isAllowedInBattle()); if (allowedPkm.length === 0) { - scene.clearPhaseQueue(); - scene.unshiftPhase(new GameOverPhase(scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new GameOverPhase()); return; } // If in repeated encounter variant, do nothing // Variant must eventually be swapped in order to handle "true" end of the encounter - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; if (encounter.continuousEncounter || doNotContinue) { return; } else if (encounter.encounterMode === MysteryEncounterMode.NO_BATTLE) { - scene.pushPhase(new MysteryEncounterRewardsPhase(scene, addHealPhase)); - scene.pushPhase(new EggLapsePhase(scene)); - } else if (!scene.getEnemyParty().find(p => encounter.encounterMode !== MysteryEncounterMode.TRAINER_BATTLE ? p.isOnField() : !p?.isFainted(true))) { - scene.pushPhase(new BattleEndPhase(scene, true)); + globalScene.pushPhase(new MysteryEncounterRewardsPhase(addHealPhase)); + globalScene.pushPhase(new EggLapsePhase()); + } else if (!globalScene.getEnemyParty().find(p => encounter.encounterMode !== MysteryEncounterMode.TRAINER_BATTLE ? p.isOnField() : !p?.isFainted(true))) { + globalScene.pushPhase(new BattleEndPhase(true)); if (encounter.encounterMode === MysteryEncounterMode.TRAINER_BATTLE) { - scene.pushPhase(new TrainerVictoryPhase(scene)); + globalScene.pushPhase(new TrainerVictoryPhase()); } - if (scene.gameMode.isEndless || !scene.gameMode.isWaveFinal(scene.currentBattle.waveIndex)) { - scene.pushPhase(new MysteryEncounterRewardsPhase(scene, addHealPhase)); + if (globalScene.gameMode.isEndless || !globalScene.gameMode.isWaveFinal(globalScene.currentBattle.waveIndex)) { + globalScene.pushPhase(new MysteryEncounterRewardsPhase(addHealPhase)); if (!encounter.doContinueEncounter) { // Only lapse eggs once for multi-battle encounters - scene.pushPhase(new EggLapsePhase(scene)); + globalScene.pushPhase(new EggLapsePhase()); } } } @@ -747,48 +739,46 @@ export function handleMysteryEncounterVictory(scene: BattleScene, addHealPhase: /** * Similar to {@linkcode handleMysteryEncounterVictory}, but for cases where the player lost a battle or failed a challenge - * @param scene * @param addHealPhase */ -export function handleMysteryEncounterBattleFailed(scene: BattleScene, addHealPhase: boolean = false, doNotContinue: boolean = false) { - const allowedPkm = scene.getPlayerParty().filter((pkm) => pkm.isAllowedInBattle()); +export function handleMysteryEncounterBattleFailed(addHealPhase: boolean = false, doNotContinue: boolean = false) { + const allowedPkm = globalScene.getPlayerParty().filter((pkm) => pkm.isAllowedInBattle()); if (allowedPkm.length === 0) { - scene.clearPhaseQueue(); - scene.unshiftPhase(new GameOverPhase(scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new GameOverPhase()); return; } // If in repeated encounter variant, do nothing // Variant must eventually be swapped in order to handle "true" end of the encounter - const encounter = scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; if (encounter.continuousEncounter || doNotContinue) { return; } else if (encounter.encounterMode !== MysteryEncounterMode.NO_BATTLE) { - scene.pushPhase(new BattleEndPhase(scene, false)); + globalScene.pushPhase(new BattleEndPhase(false)); } - scene.pushPhase(new MysteryEncounterRewardsPhase(scene, addHealPhase)); + globalScene.pushPhase(new MysteryEncounterRewardsPhase(addHealPhase)); if (!encounter.doContinueEncounter) { // Only lapse eggs once for multi-battle encounters - scene.pushPhase(new EggLapsePhase(scene)); + globalScene.pushPhase(new EggLapsePhase()); } } /** * - * @param scene * @param hide - If true, performs ease out and hide visuals. If false, eases in visuals. Defaults to true * @param destroy - If true, will destroy visuals ONLY ON HIDE TRANSITION. Does nothing on show. Defaults to true * @param duration */ -export function transitionMysteryEncounterIntroVisuals(scene: BattleScene, hide: boolean = true, destroy: boolean = true, duration: number = 750): Promise { +export function transitionMysteryEncounterIntroVisuals(hide: boolean = true, destroy: boolean = true, duration: number = 750): Promise { return new Promise(resolve => { - const introVisuals = scene.currentBattle.mysteryEncounter!.introVisuals; - const enemyPokemon = scene.getEnemyField(); + const introVisuals = globalScene.currentBattle.mysteryEncounter!.introVisuals; + const enemyPokemon = globalScene.getEnemyField(); if (enemyPokemon) { - scene.currentBattle.enemyParty = []; + globalScene.currentBattle.enemyParty = []; } if (introVisuals) { if (!hide) { @@ -800,7 +790,7 @@ export function transitionMysteryEncounterIntroVisuals(scene: BattleScene, hide: } // Transition - scene.tweens.add({ + globalScene.tweens.add({ targets: [ introVisuals, enemyPokemon ], x: `${hide ? "+" : "-"}=16`, y: `${hide ? "-" : "+"}=16`, @@ -809,13 +799,13 @@ export function transitionMysteryEncounterIntroVisuals(scene: BattleScene, hide: duration, onComplete: () => { if (hide && destroy) { - scene.field.remove(introVisuals, true); + globalScene.field.remove(introVisuals, true); enemyPokemon.forEach(pokemon => { - scene.field.remove(pokemon, true); + globalScene.field.remove(pokemon, true); }); - scene.currentBattle.mysteryEncounter!.introVisuals = undefined; + globalScene.currentBattle.mysteryEncounter!.introVisuals = undefined; } resolve(true); } @@ -829,11 +819,10 @@ export function transitionMysteryEncounterIntroVisuals(scene: BattleScene, hide: /** * Will queue moves for any pokemon to use before the first CommandPhase of a battle * Mostly useful for allowing {@linkcode MysteryEncounter} enemies to "cheat" and use moves before the first turn - * @param scene */ -export function handleMysteryEncounterBattleStartEffects(scene: BattleScene) { - const encounter = scene.currentBattle.mysteryEncounter; - if (scene.currentBattle.isBattleMysteryEncounter() && encounter && encounter.encounterMode !== MysteryEncounterMode.NO_BATTLE && !encounter.startOfBattleEffectsComplete) { +export function handleMysteryEncounterBattleStartEffects() { + const encounter = globalScene.currentBattle.mysteryEncounter; + if (globalScene.currentBattle.isBattleMysteryEncounter() && encounter && encounter.encounterMode !== MysteryEncounterMode.NO_BATTLE && !encounter.startOfBattleEffectsComplete) { const effects = encounter.startOfBattleEffects; effects.forEach(effect => { let source; @@ -841,24 +830,24 @@ export function handleMysteryEncounterBattleStartEffects(scene: BattleScene) { source = effect.sourcePokemon; } else if (!isNullOrUndefined(effect.sourceBattlerIndex)) { if (effect.sourceBattlerIndex === BattlerIndex.ATTACKER) { - source = scene.getEnemyField()[0]; + source = globalScene.getEnemyField()[0]; } else if (effect.sourceBattlerIndex === BattlerIndex.ENEMY) { - source = scene.getEnemyField()[0]; + source = globalScene.getEnemyField()[0]; } else if (effect.sourceBattlerIndex === BattlerIndex.ENEMY_2) { - source = scene.getEnemyField()[1]; + source = globalScene.getEnemyField()[1]; } else if (effect.sourceBattlerIndex === BattlerIndex.PLAYER) { - source = scene.getPlayerField()[0]; + source = globalScene.getPlayerField()[0]; } else if (effect.sourceBattlerIndex === BattlerIndex.PLAYER_2) { - source = scene.getPlayerField()[1]; + source = globalScene.getPlayerField()[1]; } } else { - source = scene.getEnemyField()[0]; + source = globalScene.getEnemyField()[0]; } - scene.pushPhase(new MovePhase(scene, source, effect.targets, effect.move, effect.followUp, effect.ignorePp)); + globalScene.pushPhase(new MovePhase(source, effect.targets, effect.move, effect.followUp, effect.ignorePp)); }); // Pseudo turn end phase to reset flinch states, Endure, etc. - scene.pushPhase(new MysteryEncounterBattleStartCleanupPhase(scene)); + globalScene.pushPhase(new MysteryEncounterBattleStartCleanupPhase()); encounter.startOfBattleEffectsComplete = true; } @@ -867,13 +856,12 @@ export function handleMysteryEncounterBattleStartEffects(scene: BattleScene) { /** * Can queue extra phases or logic during {@linkcode TurnInitPhase} * Should mostly just be used for injecting custom phases into the battle system on turn start - * @param scene * @return boolean - if true, will skip the remainder of the {@linkcode TurnInitPhase} */ -export function handleMysteryEncounterTurnStartEffects(scene: BattleScene): boolean { - const encounter = scene.currentBattle.mysteryEncounter; - if (scene.currentBattle.isBattleMysteryEncounter() && encounter && encounter.onTurnStart) { - return encounter.onTurnStart(scene); +export function handleMysteryEncounterTurnStartEffects(): boolean { + const encounter = globalScene.currentBattle.mysteryEncounter; + if (globalScene.currentBattle.isBattleMysteryEncounter() && encounter && encounter.onTurnStart) { + return encounter.onTurnStart(); } return false; @@ -882,10 +870,9 @@ export function handleMysteryEncounterTurnStartEffects(scene: BattleScene): bool /** * TODO: remove once encounter spawn rate is finalized * Just a helper function to calculate aggregate stats for MEs in a Classic run - * @param scene * @param baseSpawnWeight */ -export function calculateMEAggregateStats(scene: BattleScene, baseSpawnWeight: number) { +export function calculateMEAggregateStats(baseSpawnWeight: number) { const numRuns = 1000; let run = 0; const biomes = Object.keys(Biome).filter(key => isNaN(Number(key))); @@ -898,9 +885,9 @@ export function calculateMEAggregateStats(scene: BattleScene, baseSpawnWeight: n const encountersByBiome = new Map(biomes.map(b => [ b, 0 ])); const validMEfloorsByBiome = new Map(biomes.map(b => [ b, 0 ])); let currentBiome = Biome.TOWN; - let currentArena = scene.newArena(currentBiome); - scene.setSeed(Utils.randomString(24)); - scene.resetSeed(); + let currentArena = globalScene.newArena(currentBiome); + globalScene.setSeed(Utils.randomString(24)); + globalScene.resetSeed(); for (let i = 10; i < 180; i++) { // Boss if (i % 10 === 0) { @@ -911,7 +898,7 @@ export function calculateMEAggregateStats(scene: BattleScene, baseSpawnWeight: n if (i % 10 === 1) { if (Array.isArray(biomeLinks[currentBiome])) { let biomes: Biome[]; - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { biomes = (biomeLinks[currentBiome] as (Biome | [Biome, number])[]) .filter(b => { return !Array.isArray(b) || !Utils.randSeedInt(b[1]); @@ -932,20 +919,20 @@ export function calculateMEAggregateStats(scene: BattleScene, baseSpawnWeight: n if (!(i % 50)) { currentBiome = Biome.END; } else { - currentBiome = scene.generateRandomBiome(i); + currentBiome = globalScene.generateRandomBiome(i); } } - currentArena = scene.newArena(currentBiome); + currentArena = globalScene.newArena(currentBiome); } // Fixed battle - if (scene.gameMode.isFixedBattle(i)) { + if (globalScene.gameMode.isFixedBattle(i)) { continue; } // Trainer - if (scene.gameMode.isWaveTrainer(i, currentArena)) { + if (globalScene.gameMode.isWaveTrainer(i, currentArena)) { continue; } @@ -995,7 +982,7 @@ export function calculateMEAggregateStats(scene: BattleScene, baseSpawnWeight: n const encountersByBiomeRuns: Map[] = []; const validFloorsByBiome: Map[] = []; while (run < numRuns) { - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const [ numEncounters, encountersByBiome, validMEfloorsByBiome ] = calculateNumEncounters(); encounterRuns.push(numEncounters); encountersByBiomeRuns.push(encountersByBiome); @@ -1047,17 +1034,16 @@ export function calculateMEAggregateStats(scene: BattleScene, baseSpawnWeight: n /** * TODO: remove once encounter spawn rate is finalized * Just a helper function to calculate aggregate stats for MEs in a Classic run - * @param scene * @param luckValue - 0 to 14 */ -export function calculateRareSpawnAggregateStats(scene: BattleScene, luckValue: number) { +export function calculateRareSpawnAggregateStats(luckValue: number) { const numRuns = 1000; let run = 0; const calculateNumRareEncounters = (): any[] => { const bossEncountersByRarity = [ 0, 0, 0, 0 ]; - scene.setSeed(Utils.randomString(24)); - scene.resetSeed(); + globalScene.setSeed(Utils.randomString(24)); + globalScene.resetSeed(); // There are 12 wild boss floors for (let i = 0; i < 12; i++) { // Roll boss tier @@ -1091,7 +1077,7 @@ export function calculateRareSpawnAggregateStats(scene: BattleScene, luckValue: const encounterRuns: number[][] = []; while (run < numRuns) { - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const bossEncountersByRarity = calculateNumRareEncounters(); encounterRuns.push(bossEncountersByRarity); }, 1000 * run); diff --git a/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts b/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts index 072b5e5b1609..098d7b6bf0af 100644 --- a/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts +++ b/src/data/mystery-encounters/utils/encounter-pokemon-utils.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import i18next from "i18next"; import { isNullOrUndefined, randSeedInt } from "#app/utils"; import { PokemonHeldItemModifier } from "#app/modifier/modifier"; @@ -45,7 +45,6 @@ export function getSpriteKeysFromSpecies(species: Species, female?: boolean, for /** * Gets the sprite key and file root for a given Pokemon (accounts for gender, shiny, variants, forms, and experimental) - * @param pokemon */ export function getSpriteKeysFromPokemon(pokemon: Pokemon): { spriteKey: string, fileRoot: string } { const spriteKey = pokemon.getSpeciesForm().getSpriteKey(pokemon.getGender() === Gender.FEMALE, pokemon.formIndex, pokemon.shiny, pokemon.variant); @@ -57,14 +56,13 @@ export function getSpriteKeysFromPokemon(pokemon: Pokemon): { spriteKey: string, /** * Will never remove the player's last non-fainted Pokemon (if they only have 1). * Otherwise, picks a Pokemon completely at random and removes from the party - * @param scene * @param isAllowed Default `false`. If `true`, only picks from legal mons. If no legal mons are found (or there is 1, with `doNotReturnLastAllowedMon = true`), will return a mon that is not allowed. * @param isFainted Default `false`. If `true`, includes fainted mons. * @param doNotReturnLastAllowedMon Default `false`. If `true`, will never return the last unfainted pokemon in the party. Useful when this function is being used to determine what Pokemon to remove from the party (Don't want to remove last unfainted) * @returns */ -export function getRandomPlayerPokemon(scene: BattleScene, isAllowed: boolean = false, isFainted: boolean = false, doNotReturnLastAllowedMon: boolean = false): PlayerPokemon { - const party = scene.getPlayerParty(); +export function getRandomPlayerPokemon(isAllowed: boolean = false, isFainted: boolean = false, doNotReturnLastAllowedMon: boolean = false): PlayerPokemon { + const party = globalScene.getPlayerParty(); let chosenIndex: number; let chosenPokemon: PlayerPokemon | null = null; const fullyLegalMons = party.filter(p => (!isAllowed || p.isAllowedInChallenge()) && (isFainted || !p.isFainted())); @@ -102,8 +100,8 @@ export function getRandomPlayerPokemon(scene: BattleScene, isAllowed: boolean = * @param isFainted Default false. If true, includes fainted mons. * @returns */ -export function getHighestLevelPlayerPokemon(scene: BattleScene, isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { - const party = scene.getPlayerParty(); +export function getHighestLevelPlayerPokemon(isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { + const party = globalScene.getPlayerParty(); let pokemon: PlayerPokemon | null = null; for (const p of party) { @@ -128,8 +126,8 @@ export function getHighestLevelPlayerPokemon(scene: BattleScene, isAllowed: bool * @param isFainted Default false. If true, includes fainted mons. * @returns */ -export function getHighestStatPlayerPokemon(scene: BattleScene, stat: PermanentStat, isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { - const party = scene.getPlayerParty(); +export function getHighestStatPlayerPokemon(stat: PermanentStat, isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { + const party = globalScene.getPlayerParty(); let pokemon: PlayerPokemon | null = null; for (const p of party) { @@ -153,8 +151,8 @@ export function getHighestStatPlayerPokemon(scene: BattleScene, stat: PermanentS * @param isFainted Default false. If true, includes fainted mons. * @returns */ -export function getLowestLevelPlayerPokemon(scene: BattleScene, isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { - const party = scene.getPlayerParty(); +export function getLowestLevelPlayerPokemon(isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { + const party = globalScene.getPlayerParty(); let pokemon: PlayerPokemon | null = null; for (const p of party) { @@ -178,8 +176,8 @@ export function getLowestLevelPlayerPokemon(scene: BattleScene, isAllowed: boole * @param isFainted Default false. If true, includes fainted mons. * @returns */ -export function getHighestStatTotalPlayerPokemon(scene: BattleScene, isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { - const party = scene.getPlayerParty(); +export function getHighestStatTotalPlayerPokemon(isAllowed: boolean = false, isFainted: boolean = false): PlayerPokemon { + const party = globalScene.getPlayerParty(); let pokemon: PlayerPokemon | null = null; for (const p of party) { @@ -253,11 +251,11 @@ export function getRandomSpeciesByStarterCost(starterTiers: number | [number, nu * @param scene the battle scene * @param pokemon the player pokemon to KO */ -export function koPlayerPokemon(scene: BattleScene, pokemon: PlayerPokemon) { +export function koPlayerPokemon(pokemon: PlayerPokemon) { pokemon.hp = 0; pokemon.trySetStatus(StatusEffect.FAINT); pokemon.updateInfo(); - queueEncounterMessage(scene, i18next.t("battle:fainted", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + queueEncounterMessage(i18next.t("battle:fainted", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } /** @@ -269,11 +267,11 @@ export function koPlayerPokemon(scene: BattleScene, pokemon: PlayerPokemon) { * @param value the hp change amount. Positive for heal. Negative for damage * */ -function applyHpChangeToPokemon(scene: BattleScene, pokemon: PlayerPokemon, value: number) { +function applyHpChangeToPokemon(pokemon: PlayerPokemon, value: number) { const hpChange = Math.round(pokemon.hp + value); const nextHp = Math.max(Math.min(hpChange, pokemon.getMaxHp()), 0); if (nextHp === 0) { - koPlayerPokemon(scene, pokemon); + koPlayerPokemon(pokemon); } else { pokemon.hp = nextHp; } @@ -286,7 +284,7 @@ function applyHpChangeToPokemon(scene: BattleScene, pokemon: PlayerPokemon, valu * @param damage the amount of damage to apply * @see {@linkcode applyHpChangeToPokemon} */ -export function applyDamageToPokemon(scene: BattleScene, pokemon: PlayerPokemon, damage: number) { +export function applyDamageToPokemon(pokemon: PlayerPokemon, damage: number) { if (damage <= 0) { console.warn("Healing pokemon with `applyDamageToPokemon` is not recommended! Please use `applyHealToPokemon` instead."); } @@ -294,7 +292,7 @@ export function applyDamageToPokemon(scene: BattleScene, pokemon: PlayerPokemon, if (pokemon.isAllowedInBattle() && pokemon.hp - damage <= 0) { damage = pokemon.hp - 1; } - applyHpChangeToPokemon(scene, pokemon, -damage); + applyHpChangeToPokemon(pokemon, -damage); } /** @@ -304,12 +302,12 @@ export function applyDamageToPokemon(scene: BattleScene, pokemon: PlayerPokemon, * @param heal the amount of heal to apply * @see {@linkcode applyHpChangeToPokemon} */ -export function applyHealToPokemon(scene: BattleScene, pokemon: PlayerPokemon, heal: number) { +export function applyHealToPokemon(pokemon: PlayerPokemon, heal: number) { if (heal <= 0) { console.warn("Damaging pokemon with `applyHealToPokemon` is not recommended! Please use `applyDamageToPokemon` instead."); } - applyHpChangeToPokemon(scene, pokemon, heal); + applyHpChangeToPokemon(pokemon, heal); } /** @@ -320,11 +318,11 @@ export function applyHealToPokemon(scene: BattleScene, pokemon: PlayerPokemon, h */ export async function modifyPlayerPokemonBST(pokemon: PlayerPokemon, value: number) { const modType = modifierTypes.MYSTERY_ENCOUNTER_SHUCKLE_JUICE() - .generateType(pokemon.scene.getPlayerParty(), [ value ]) + .generateType(globalScene.getPlayerParty(), [ value ]) ?.withIdFromFunc(modifierTypes.MYSTERY_ENCOUNTER_SHUCKLE_JUICE); const modifier = modType?.newModifier(pokemon); if (modifier) { - await pokemon.scene.addModifier(modifier, false, false, false, true); + await globalScene.addModifier(modifier, false, false, false, true); pokemon.calculateStats(); } } @@ -337,10 +335,10 @@ export async function modifyPlayerPokemonBST(pokemon: PlayerPokemon, value: numb * @param modType * @param fallbackModifierType */ -export async function applyModifierTypeToPlayerPokemon(scene: BattleScene, pokemon: PlayerPokemon, modType: PokemonHeldItemModifierType, fallbackModifierType?: PokemonHeldItemModifierType) { +export async function applyModifierTypeToPlayerPokemon(pokemon: PlayerPokemon, modType: PokemonHeldItemModifierType, fallbackModifierType?: PokemonHeldItemModifierType) { // Check if the Pokemon has max stacks of that item already const modifier = modType.newModifier(pokemon); - const existing = scene.findModifier(m => ( + const existing = globalScene.findModifier(m => ( m instanceof PokemonHeldItemModifier && m.type.id === modType.id && m.pokemonId === pokemon.id && @@ -348,16 +346,16 @@ export async function applyModifierTypeToPlayerPokemon(scene: BattleScene, pokem )) as PokemonHeldItemModifier; // At max stacks - if (existing && existing.getStackCount() >= existing.getMaxStackCount(scene)) { + if (existing && existing.getStackCount() >= existing.getMaxStackCount()) { if (!fallbackModifierType) { return; } // Apply fallback - return applyModifierTypeToPlayerPokemon(scene, pokemon, fallbackModifierType); + return applyModifierTypeToPlayerPokemon(pokemon, fallbackModifierType); } - await scene.addModifier(modifier, false, false, false, true); + await globalScene.addModifier(modifier, false, false, false, true); } /** @@ -371,7 +369,7 @@ export async function applyModifierTypeToPlayerPokemon(scene: BattleScene, pokem * @param pokeballType * @param ballTwitchRate - can pass custom ball catch rates (for special events, like safari) */ -export function trainerThrowPokeball(scene: BattleScene, pokemon: EnemyPokemon, pokeballType: PokeballType, ballTwitchRate?: number): Promise { +export function trainerThrowPokeball(pokemon: EnemyPokemon, pokeballType: PokeballType, ballTwitchRate?: number): Promise { const originalY: number = pokemon.y; if (!ballTwitchRate) { @@ -386,43 +384,43 @@ export function trainerThrowPokeball(scene: BattleScene, pokemon: EnemyPokemon, const fpOffset = pokemon.getFieldPositionOffset(); const pokeballAtlasKey = getPokeballAtlasKey(pokeballType); - const pokeball: Phaser.GameObjects.Sprite = scene.addFieldSprite(16 + 75, 80 + 25, "pb", pokeballAtlasKey); + const pokeball: Phaser.GameObjects.Sprite = globalScene.addFieldSprite(16 + 75, 80 + 25, "pb", pokeballAtlasKey); pokeball.setOrigin(0.5, 0.625); - scene.field.add(pokeball); + globalScene.field.add(pokeball); - scene.time.delayedCall(300, () => { - scene.field.moveBelow(pokeball as Phaser.GameObjects.GameObject, pokemon); + globalScene.time.delayedCall(300, () => { + globalScene.field.moveBelow(pokeball as Phaser.GameObjects.GameObject, pokemon); }); return new Promise(resolve => { - scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); - scene.time.delayedCall(512, () => { - scene.playSound("se/pb_throw"); + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); + globalScene.time.delayedCall(512, () => { + globalScene.playSound("se/pb_throw"); // Trainer throw frames - scene.trainer.setFrame("2"); - scene.time.delayedCall(256, () => { - scene.trainer.setFrame("3"); - scene.time.delayedCall(768, () => { - scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); + globalScene.trainer.setFrame("2"); + globalScene.time.delayedCall(256, () => { + globalScene.trainer.setFrame("3"); + globalScene.time.delayedCall(768, () => { + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); }); }); // Pokeball move and catch logic - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, x: { value: 236 + fpOffset[0], ease: "Linear" }, y: { value: 16 + fpOffset[1], ease: "Cubic.easeOut" }, duration: 500, onComplete: () => { pokeball.setTexture("pb", `${pokeballAtlasKey}_opening`); - scene.time.delayedCall(17, () => pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); - scene.playSound("se/pb_rel"); + globalScene.time.delayedCall(17, () => pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); + globalScene.playSound("se/pb_rel"); pokemon.tint(getPokeballTintColor(pokeballType)); - addPokeballOpenParticles(scene, pokeball.x, pokeball.y, pokeballType); + addPokeballOpenParticles(pokeball.x, pokeball.y, pokeballType); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, duration: 500, ease: "Sine.easeIn", @@ -431,13 +429,13 @@ export function trainerThrowPokeball(scene: BattleScene, pokemon: EnemyPokemon, onComplete: () => { pokeball.setTexture("pb", `${pokeballAtlasKey}_opening`); pokemon.setVisible(false); - scene.playSound("se/pb_catch"); - scene.time.delayedCall(17, () => pokeball.setTexture("pb", `${pokeballAtlasKey}`)); + globalScene.playSound("se/pb_catch"); + globalScene.time.delayedCall(17, () => pokeball.setTexture("pb", `${pokeballAtlasKey}`)); const doShake = () => { let shakeCount = 0; const pbX = pokeball.x; - const shakeCounter = scene.tweens.addCounter({ + const shakeCounter = globalScene.tweens.addCounter({ from: 0, to: 1, repeat: 4, @@ -456,30 +454,30 @@ export function trainerThrowPokeball(scene: BattleScene, pokemon: EnemyPokemon, onRepeat: () => { if (!pokemon.species.isObtainable()) { shakeCounter.stop(); - failCatch(scene, pokemon, originalY, pokeball, pokeballType).then(() => resolve(false)); + failCatch(pokemon, originalY, pokeball, pokeballType).then(() => resolve(false)); } else if (shakeCount++ < 3) { if (randSeedInt(65536) < ballTwitchRate) { - scene.playSound("se/pb_move"); + globalScene.playSound("se/pb_move"); } else { shakeCounter.stop(); - failCatch(scene, pokemon, originalY, pokeball, pokeballType).then(() => resolve(false)); + failCatch(pokemon, originalY, pokeball, pokeballType).then(() => resolve(false)); } } else { - scene.playSound("se/pb_lock"); - addPokeballCaptureStars(scene, pokeball); + globalScene.playSound("se/pb_lock"); + addPokeballCaptureStars(pokeball); - const pbTint = scene.add.sprite(pokeball.x, pokeball.y, "pb", "pb"); + const pbTint = globalScene.add.sprite(pokeball.x, pokeball.y, "pb", "pb"); pbTint.setOrigin(pokeball.originX, pokeball.originY); pbTint.setTintFill(0); pbTint.setAlpha(0); - scene.field.add(pbTint); - scene.tweens.add({ + globalScene.field.add(pbTint); + globalScene.tweens.add({ targets: pbTint, alpha: 0.375, duration: 200, easing: "Sine.easeOut", onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: pbTint, alpha: 0, duration: 200, @@ -491,12 +489,12 @@ export function trainerThrowPokeball(scene: BattleScene, pokemon: EnemyPokemon, } }, onComplete: () => { - catchPokemon(scene, pokemon, pokeball, pokeballType).then(() => resolve(true)); + catchPokemon(pokemon, pokeball, pokeballType).then(() => resolve(true)); } }); }; - scene.time.delayedCall(250, () => doPokeballBounceAnim(scene, pokeball, 16, 72, 350, doShake)); + globalScene.time.delayedCall(250, () => doPokeballBounceAnim(pokeball, 16, 72, 350, doShake)); } }); } @@ -513,9 +511,9 @@ export function trainerThrowPokeball(scene: BattleScene, pokemon: EnemyPokemon, * @param pokeball * @param pokeballType */ -function failCatch(scene: BattleScene, pokemon: EnemyPokemon, originalY: number, pokeball: Phaser.GameObjects.Sprite, pokeballType: PokeballType) { +function failCatch(pokemon: EnemyPokemon, originalY: number, pokeball: Phaser.GameObjects.Sprite, pokeballType: PokeballType) { return new Promise(resolve => { - scene.playSound("se/pb_rel"); + globalScene.playSound("se/pb_rel"); pokemon.setY(originalY); if (pokemon.status?.effect !== StatusEffect.SLEEP) { pokemon.cry(pokemon.getHpRatio() > 0.25 ? undefined : { rate: 0.85 }); @@ -526,19 +524,19 @@ function failCatch(scene: BattleScene, pokemon: EnemyPokemon, originalY: number, const pokeballAtlasKey = getPokeballAtlasKey(pokeballType); pokeball.setTexture("pb", `${pokeballAtlasKey}_opening`); - scene.time.delayedCall(17, () => pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); + globalScene.time.delayedCall(17, () => pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, duration: 250, ease: "Sine.easeOut", scale: 1 }); - scene.currentBattle.lastUsedPokeball = pokeballType; - removePb(scene, pokeball); + globalScene.currentBattle.lastUsedPokeball = pokeballType; + removePb(pokeball); - scene.ui.showText(i18next.t("battle:pokemonBrokeFree", { pokemonName: pokemon.getNameToRender() }), null, () => resolve(), null, true); + globalScene.ui.showText(i18next.t("battle:pokemonBrokeFree", { pokemonName: pokemon.getNameToRender() }), null, () => resolve(), null, true); }); } @@ -551,56 +549,56 @@ function failCatch(scene: BattleScene, pokemon: EnemyPokemon, originalY: number, * @param showCatchObtainMessage * @param isObtain */ -export async function catchPokemon(scene: BattleScene, pokemon: EnemyPokemon, pokeball: Phaser.GameObjects.Sprite | null, pokeballType: PokeballType, showCatchObtainMessage: boolean = true, isObtain: boolean = false): Promise { +export async function catchPokemon(pokemon: EnemyPokemon, pokeball: Phaser.GameObjects.Sprite | null, pokeballType: PokeballType, showCatchObtainMessage: boolean = true, isObtain: boolean = false): Promise { const speciesForm = !pokemon.fusionSpecies ? pokemon.getSpeciesForm() : pokemon.getFusionSpeciesForm(); if (speciesForm.abilityHidden && (pokemon.fusionSpecies ? pokemon.fusionAbilityIndex : pokemon.abilityIndex) === speciesForm.getAbilityCount() - 1) { - scene.validateAchv(achvs.HIDDEN_ABILITY); + globalScene.validateAchv(achvs.HIDDEN_ABILITY); } if (pokemon.species.subLegendary) { - scene.validateAchv(achvs.CATCH_SUB_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_SUB_LEGENDARY); } if (pokemon.species.legendary) { - scene.validateAchv(achvs.CATCH_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_LEGENDARY); } if (pokemon.species.mythical) { - scene.validateAchv(achvs.CATCH_MYTHICAL); + globalScene.validateAchv(achvs.CATCH_MYTHICAL); } - scene.pokemonInfoContainer.show(pokemon, true); + globalScene.pokemonInfoContainer.show(pokemon, true); - scene.gameData.updateSpeciesDexIvs(pokemon.species.getRootSpeciesId(true), pokemon.ivs); + globalScene.gameData.updateSpeciesDexIvs(pokemon.species.getRootSpeciesId(true), pokemon.ivs); return new Promise(resolve => { const doPokemonCatchMenu = () => { const end = () => { // Ensure the pokemon is in the enemy party in all situations - if (!scene.getEnemyParty().some(p => p.id === pokemon.id)) { - scene.getEnemyParty().push(pokemon); + if (!globalScene.getEnemyParty().some(p => p.id === pokemon.id)) { + globalScene.getEnemyParty().push(pokemon); } - scene.unshiftPhase(new VictoryPhase(scene, pokemon.id, true)); - scene.pokemonInfoContainer.hide(); + globalScene.unshiftPhase(new VictoryPhase(pokemon.id, true)); + globalScene.pokemonInfoContainer.hide(); if (pokeball) { - removePb(scene, pokeball); + removePb(pokeball); } resolve(); }; const removePokemon = () => { if (pokemon) { - scene.field.remove(pokemon, true); + globalScene.field.remove(pokemon, true); } }; const addToParty = (slotIndex?: number) => { const newPokemon = pokemon.addToParty(pokeballType, slotIndex); - const modifiers = scene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); - if (scene.getPlayerParty().filter(p => p.isShiny()).length === 6) { - scene.validateAchv(achvs.SHINY_PARTY); + const modifiers = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); + if (globalScene.getPlayerParty().filter(p => p.isShiny()).length === 6) { + globalScene.validateAchv(achvs.SHINY_PARTY); } - Promise.all(modifiers.map(m => scene.addModifier(m, true))).then(() => { - scene.updateModifiers(true); + Promise.all(modifiers.map(m => globalScene.addModifier(m, true))).then(() => { + globalScene.updateModifiers(true); removePokemon(); if (newPokemon) { newPokemon.loadAssets().then(end); @@ -609,21 +607,21 @@ export async function catchPokemon(scene: BattleScene, pokemon: EnemyPokemon, po } }); }; - Promise.all([ pokemon.hideInfo(), scene.gameData.setPokemonCaught(pokemon) ]).then(() => { - if (scene.getPlayerParty().length === 6) { + Promise.all([ pokemon.hideInfo(), globalScene.gameData.setPokemonCaught(pokemon) ]).then(() => { + if (globalScene.getPlayerParty().length === 6) { const promptRelease = () => { - scene.ui.showText(i18next.t("battle:partyFull", { pokemonName: pokemon.getNameToRender() }), null, () => { - scene.pokemonInfoContainer.makeRoomForConfirmUi(1, true); - scene.ui.setMode(Mode.CONFIRM, () => { - const newPokemon = scene.addPlayerPokemon(pokemon.species, pokemon.level, pokemon.abilityIndex, pokemon.formIndex, pokemon.gender, pokemon.shiny, pokemon.variant, pokemon.ivs, pokemon.nature, pokemon); - scene.ui.setMode(Mode.SUMMARY, newPokemon, 0, SummaryUiMode.DEFAULT, () => { - scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.showText(i18next.t("battle:partyFull", { pokemonName: pokemon.getNameToRender() }), null, () => { + globalScene.pokemonInfoContainer.makeRoomForConfirmUi(1, true); + globalScene.ui.setMode(Mode.CONFIRM, () => { + const newPokemon = globalScene.addPlayerPokemon(pokemon.species, pokemon.level, pokemon.abilityIndex, pokemon.formIndex, pokemon.gender, pokemon.shiny, pokemon.variant, pokemon.ivs, pokemon.nature, pokemon); + globalScene.ui.setMode(Mode.SUMMARY, newPokemon, 0, SummaryUiMode.DEFAULT, () => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { promptRelease(); }); }, false); }, () => { - scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, 0, (slotIndex: integer, _option: PartyOption) => { - scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, 0, (slotIndex: integer, _option: PartyOption) => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { if (slotIndex < 6) { addToParty(slotIndex); } else { @@ -632,7 +630,7 @@ export async function catchPokemon(scene: BattleScene, pokemon: EnemyPokemon, po }); }); }, () => { - scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { removePokemon(); end(); }); @@ -647,7 +645,7 @@ export async function catchPokemon(scene: BattleScene, pokemon: EnemyPokemon, po }; if (showCatchObtainMessage) { - scene.ui.showText(i18next.t(isObtain ? "battle:pokemonObtained" : "battle:pokemonCaught", { pokemonName: pokemon.getNameToRender() }), null, doPokemonCatchMenu, 0, true); + globalScene.ui.showText(i18next.t(isObtain ? "battle:pokemonObtained" : "battle:pokemonCaught", { pokemonName: pokemon.getNameToRender() }), null, doPokemonCatchMenu, 0, true); } else { doPokemonCatchMenu(); } @@ -659,9 +657,9 @@ export async function catchPokemon(scene: BattleScene, pokemon: EnemyPokemon, po * @param scene * @param pokeball */ -function removePb(scene: BattleScene, pokeball: Phaser.GameObjects.Sprite) { +function removePb(pokeball: Phaser.GameObjects.Sprite) { if (pokeball) { - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, duration: 250, delay: 250, @@ -679,11 +677,11 @@ function removePb(scene: BattleScene, pokeball: Phaser.GameObjects.Sprite) { * @param scene * @param pokemon */ -export async function doPokemonFlee(scene: BattleScene, pokemon: EnemyPokemon): Promise { +export async function doPokemonFlee(pokemon: EnemyPokemon): Promise { await new Promise(resolve => { - scene.playSound("se/flee"); + globalScene.playSound("se/flee"); // Ease pokemon out - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, x: "+=16", y: "-=16", @@ -693,8 +691,8 @@ export async function doPokemonFlee(scene: BattleScene, pokemon: EnemyPokemon): scale: pokemon.getSpriteScale(), onComplete: () => { pokemon.setVisible(false); - scene.field.remove(pokemon, true); - showEncounterText(scene, i18next.t("battle:pokemonFled", { pokemonName: pokemon.getNameToRender() }), null, 600, false) + globalScene.field.remove(pokemon, true); + showEncounterText(i18next.t("battle:pokemonFled", { pokemonName: pokemon.getNameToRender() }), null, 600, false) .then(() => { resolve(); }); @@ -708,10 +706,10 @@ export async function doPokemonFlee(scene: BattleScene, pokemon: EnemyPokemon): * @param scene * @param pokemon */ -export function doPlayerFlee(scene: BattleScene, pokemon: EnemyPokemon): Promise { +export function doPlayerFlee(pokemon: EnemyPokemon): Promise { return new Promise(resolve => { // Ease pokemon out - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, x: "+=16", y: "-=16", @@ -721,8 +719,8 @@ export function doPlayerFlee(scene: BattleScene, pokemon: EnemyPokemon): Promise scale: pokemon.getSpriteScale(), onComplete: () => { pokemon.setVisible(false); - scene.field.remove(pokemon, true); - showEncounterText(scene, i18next.t("battle:playerFled", { pokemonName: pokemon.getNameToRender() }), null, 600, false) + globalScene.field.remove(pokemon, true); + showEncounterText(i18next.t("battle:playerFled", { pokemonName: pokemon.getNameToRender() }), null, 600, false) .then(() => { resolve(); }); @@ -790,35 +788,35 @@ export function getGoldenBugNetSpecies(level: number): PokemonSpecies { * @param scene * @param levelAdditiveModifier Default 0. will add +(1 level / 10 waves * levelAdditiveModifier) to the level calculation */ -export function getEncounterPokemonLevelForWave(scene: BattleScene, levelAdditiveModifier: number = 0) { - const currentBattle = scene.currentBattle; +export function getEncounterPokemonLevelForWave(levelAdditiveModifier: number = 0) { + const currentBattle = globalScene.currentBattle; const baseLevel = currentBattle.getLevelForWave(); // Add a level scaling modifier that is (+1 level per 10 waves) * levelAdditiveModifier return baseLevel + Math.max(Math.round((currentBattle.waveIndex / 10) * levelAdditiveModifier), 0); } -export async function addPokemonDataToDexAndValidateAchievements(scene: BattleScene, pokemon: PlayerPokemon) { +export async function addPokemonDataToDexAndValidateAchievements(pokemon: PlayerPokemon) { const speciesForm = !pokemon.fusionSpecies ? pokemon.getSpeciesForm() : pokemon.getFusionSpeciesForm(); if (speciesForm.abilityHidden && (pokemon.fusionSpecies ? pokemon.fusionAbilityIndex : pokemon.abilityIndex) === speciesForm.getAbilityCount() - 1) { - scene.validateAchv(achvs.HIDDEN_ABILITY); + globalScene.validateAchv(achvs.HIDDEN_ABILITY); } if (pokemon.species.subLegendary) { - scene.validateAchv(achvs.CATCH_SUB_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_SUB_LEGENDARY); } if (pokemon.species.legendary) { - scene.validateAchv(achvs.CATCH_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_LEGENDARY); } if (pokemon.species.mythical) { - scene.validateAchv(achvs.CATCH_MYTHICAL); + globalScene.validateAchv(achvs.CATCH_MYTHICAL); } - scene.gameData.updateSpeciesDexIvs(pokemon.species.getRootSpeciesId(true), pokemon.ivs); - return scene.gameData.setPokemonCaught(pokemon, true, false, false); + globalScene.gameData.updateSpeciesDexIvs(pokemon.species.getRootSpeciesId(true), pokemon.ivs); + return globalScene.gameData.setPokemonCaught(pokemon, true, false, false); } /** @@ -830,12 +828,12 @@ export async function addPokemonDataToDexAndValidateAchievements(scene: BattleSc * @param scene * @param invalidSelectionKey */ -export function isPokemonValidForEncounterOptionSelection(pokemon: Pokemon, scene: BattleScene, invalidSelectionKey: string): string | null { +export function isPokemonValidForEncounterOptionSelection(pokemon: Pokemon, invalidSelectionKey: string): string | null { if (!pokemon.isAllowedInChallenge()) { return i18next.t("partyUiHandler:cantBeUsed", { pokemonName: pokemon.getNameToRender() }) ?? null; } if (!pokemon.isAllowedInBattle()) { - return getEncounterText(scene, invalidSelectionKey) ?? null; + return getEncounterText(invalidSelectionKey) ?? null; } return null; diff --git a/src/data/mystery-encounters/utils/encounter-transformation-sequence.ts b/src/data/mystery-encounters/utils/encounter-transformation-sequence.ts index 424ba15f8119..d348aa376e2f 100644 --- a/src/data/mystery-encounters/utils/encounter-transformation-sequence.ts +++ b/src/data/mystery-encounters/utils/encounter-transformation-sequence.ts @@ -1,8 +1,8 @@ -import BattleScene from "#app/battle-scene"; import { PlayerPokemon } from "#app/field/pokemon"; import { getFrameMs } from "#app/utils"; import { cos, sin } from "#app/field/anims"; import { getTypeRgb } from "#app/data/type"; +import { globalScene } from "#app/global-scene"; export enum TransformationScreenPosition { CENTER, @@ -17,10 +17,10 @@ export enum TransformationScreenPosition { * @param transformPokemon * @param screenPosition */ -export function doPokemonTransformationSequence(scene: BattleScene, previousPokemon: PlayerPokemon, transformPokemon: PlayerPokemon, screenPosition: TransformationScreenPosition) { +export function doPokemonTransformationSequence(previousPokemon: PlayerPokemon, transformPokemon: PlayerPokemon, screenPosition: TransformationScreenPosition) { return new Promise(resolve => { - const transformationContainer = scene.fieldUI.getByName("Dream Background") as Phaser.GameObjects.Container; - const transformationBaseBg = scene.add.image(0, 0, "default_bg"); + const transformationContainer = globalScene.fieldUI.getByName("Dream Background") as Phaser.GameObjects.Container; + const transformationBaseBg = globalScene.add.image(0, 0, "default_bg"); transformationBaseBg.setOrigin(0, 0); transformationBaseBg.setVisible(false); transformationContainer.add(transformationBaseBg); @@ -36,8 +36,8 @@ export function doPokemonTransformationSequence(scene: BattleScene, previousPoke const yOffset = screenPosition !== TransformationScreenPosition.CENTER ? -15 : 0; const getPokemonSprite = () => { - const ret = scene.addPokemonSprite(previousPokemon, transformationBaseBg.displayWidth / 2 + xOffset, transformationBaseBg.displayHeight / 2 + yOffset, "pkmn__sub"); - ret.setPipeline(scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + const ret = globalScene.addPokemonSprite(previousPokemon, transformationBaseBg.displayWidth / 2 + xOffset, transformationBaseBg.displayHeight / 2 + yOffset, "pkmn__sub"); + ret.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); return ret; }; @@ -61,7 +61,7 @@ export function doPokemonTransformationSequence(scene: BattleScene, previousPoke console.error(`Failed to play animation for ${spriteKey}`, err); } - sprite.setPipeline(scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(previousPokemon.getTeraType()) }); + sprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(previousPokemon.getTeraType()) }); sprite.setPipelineData("ignoreTimeTint", true); sprite.setPipelineData("spriteKey", previousPokemon.getSpriteKey()); sprite.setPipelineData("shiny", previousPokemon.shiny); @@ -94,14 +94,14 @@ export function doPokemonTransformationSequence(scene: BattleScene, previousPoke }); }); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonSprite, alpha: 1, ease: "Cubic.easeInOut", duration: 2000, onComplete: () => { - doSpiralUpward(scene, transformationBaseBg, transformationContainer, xOffset, yOffset); - scene.tweens.addCounter({ + doSpiralUpward(transformationBaseBg, transformationContainer, xOffset, yOffset); + globalScene.tweens.addCounter({ from: 0, to: 1, duration: 1000, @@ -110,26 +110,26 @@ export function doPokemonTransformationSequence(scene: BattleScene, previousPoke }, onComplete: () => { pokemonSprite.setVisible(false); - scene.time.delayedCall(700, () => { - doArcDownward(scene, transformationBaseBg, transformationContainer, xOffset, yOffset); - scene.time.delayedCall(1000, () => { + globalScene.time.delayedCall(700, () => { + doArcDownward(transformationBaseBg, transformationContainer, xOffset, yOffset); + globalScene.time.delayedCall(1000, () => { pokemonEvoTintSprite.setScale(0.25); pokemonEvoTintSprite.setVisible(true); - doCycle(scene, 1.5, 6, pokemonTintSprite, pokemonEvoTintSprite).then(() => { + doCycle(1.5, 6, pokemonTintSprite, pokemonEvoTintSprite).then(() => { pokemonEvoSprite.setVisible(true); - doCircleInward(scene, transformationBaseBg, transformationContainer, xOffset, yOffset); + doCircleInward(transformationBaseBg, transformationContainer, xOffset, yOffset); - scene.time.delayedCall(900, () => { - scene.tweens.add({ + globalScene.time.delayedCall(900, () => { + globalScene.tweens.add({ targets: pokemonEvoTintSprite, alpha: 0, duration: 1500, delay: 150, easing: "Sine.easeIn", onComplete: () => { - scene.time.delayedCall(3000, () => { + globalScene.time.delayedCall(3000, () => { resolve(); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonEvoSprite, alpha: 0, duration: 2000, @@ -163,17 +163,17 @@ export function doPokemonTransformationSequence(scene: BattleScene, previousPoke * @param xOffset * @param yOffset */ -function doSpiralUpward(scene: BattleScene, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { +function doSpiralUpward(transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { let f = 0; - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: 64, duration: getFrameMs(1), onRepeat: () => { if (f < 64) { if (!(f & 7)) { for (let i = 0; i < 4; i++) { - doSpiralUpwardParticle(scene, (f & 120) * 2 + i * 64, transformationBaseBg, transformationContainer, xOffset, yOffset); + doSpiralUpwardParticle((f & 120) * 2 + i * 64, transformationBaseBg, transformationContainer, xOffset, yOffset); } } f++; @@ -190,17 +190,17 @@ function doSpiralUpward(scene: BattleScene, transformationBaseBg: Phaser.GameObj * @param xOffset * @param yOffset */ -function doArcDownward(scene: BattleScene, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { +function doArcDownward(transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { let f = 0; - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: 96, duration: getFrameMs(1), onRepeat: () => { if (f < 96) { if (f < 6) { for (let i = 0; i < 9; i++) { - doArcDownParticle(scene, i * 16, transformationBaseBg, transformationContainer, xOffset, yOffset); + doArcDownParticle(i * 16, transformationBaseBg, transformationContainer, xOffset, yOffset); } } f++; @@ -217,17 +217,17 @@ function doArcDownward(scene: BattleScene, transformationBaseBg: Phaser.GameObje * @param pokemonTintSprite * @param pokemonEvoTintSprite */ -function doCycle(scene: BattleScene, l: number, lastCycle: number, pokemonTintSprite: Phaser.GameObjects.Sprite, pokemonEvoTintSprite: Phaser.GameObjects.Sprite): Promise { +function doCycle(l: number, lastCycle: number, pokemonTintSprite: Phaser.GameObjects.Sprite, pokemonEvoTintSprite: Phaser.GameObjects.Sprite): Promise { return new Promise(resolve => { const isLastCycle = l === lastCycle; - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonTintSprite, scale: 0.25, ease: "Cubic.easeInOut", duration: 500 / l, yoyo: !isLastCycle }); - scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonEvoTintSprite, scale: 1, ease: "Cubic.easeInOut", @@ -235,7 +235,7 @@ function doCycle(scene: BattleScene, l: number, lastCycle: number, pokemonTintSp yoyo: !isLastCycle, onComplete: () => { if (l < lastCycle) { - doCycle(scene, l + 0.5, lastCycle, pokemonTintSprite, pokemonEvoTintSprite).then(success => resolve(success)); + doCycle(l + 0.5, lastCycle, pokemonTintSprite, pokemonEvoTintSprite).then(success => resolve(success)); } else { pokemonTintSprite.setVisible(false); resolve(true); @@ -253,20 +253,20 @@ function doCycle(scene: BattleScene, l: number, lastCycle: number, pokemonTintSp * @param xOffset * @param yOffset */ -function doCircleInward(scene: BattleScene, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { +function doCircleInward(transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { let f = 0; - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: 48, duration: getFrameMs(1), onRepeat: () => { if (!f) { for (let i = 0; i < 16; i++) { - doCircleInwardParticle(scene, i * 16, 4, transformationBaseBg, transformationContainer, xOffset, yOffset); + doCircleInwardParticle(i * 16, 4, transformationBaseBg, transformationContainer, xOffset, yOffset); } } else if (f === 32) { for (let i = 0; i < 16; i++) { - doCircleInwardParticle(scene, i * 16, 8, transformationBaseBg, transformationContainer, xOffset, yOffset); + doCircleInwardParticle(i * 16, 8, transformationBaseBg, transformationContainer, xOffset, yOffset); } } f++; @@ -283,15 +283,15 @@ function doCircleInward(scene: BattleScene, transformationBaseBg: Phaser.GameObj * @param xOffset * @param yOffset */ -function doSpiralUpwardParticle(scene: BattleScene, trigIndex: number, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { +function doSpiralUpwardParticle(trigIndex: number, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { const initialX = transformationBaseBg.displayWidth / 2 + xOffset; - const particle = scene.add.image(initialX, 0, "evo_sparkle"); + const particle = globalScene.add.image(initialX, 0, "evo_sparkle"); transformationContainer.add(particle); let f = 0; let amp = 48; - const particleTimer = scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: getFrameMs(1), onRepeat: () => { @@ -328,16 +328,16 @@ function doSpiralUpwardParticle(scene: BattleScene, trigIndex: number, transform * @param xOffset * @param yOffset */ -function doArcDownParticle(scene: BattleScene, trigIndex: number, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { +function doArcDownParticle(trigIndex: number, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { const initialX = transformationBaseBg.displayWidth / 2 + xOffset; - const particle = scene.add.image(initialX, 0, "evo_sparkle"); + const particle = globalScene.add.image(initialX, 0, "evo_sparkle"); particle.setScale(0.5); transformationContainer.add(particle); let f = 0; let amp = 8; - const particleTimer = scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: getFrameMs(1), onRepeat: () => { @@ -371,15 +371,15 @@ function doArcDownParticle(scene: BattleScene, trigIndex: number, transformation * @param xOffset * @param yOffset */ -function doCircleInwardParticle(scene: BattleScene, trigIndex: number, speed: number, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { +function doCircleInwardParticle(trigIndex: number, speed: number, transformationBaseBg: Phaser.GameObjects.Image, transformationContainer: Phaser.GameObjects.Container, xOffset: number, yOffset: number) { const initialX = transformationBaseBg.displayWidth / 2 + xOffset; const initialY = transformationBaseBg.displayHeight / 2 + yOffset; - const particle = scene.add.image(initialX, initialY, "evo_sparkle"); + const particle = globalScene.add.image(initialX, initialY, "evo_sparkle"); transformationContainer.add(particle); let amp = 120; - const particleTimer = scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: getFrameMs(1), onRepeat: () => { diff --git a/src/data/pokeball.ts b/src/data/pokeball.ts index 4c9fc719a4dc..049baf11f3d5 100644 --- a/src/data/pokeball.ts +++ b/src/data/pokeball.ts @@ -1,7 +1,7 @@ +import { globalScene } from "#app/global-scene"; import { CriticalCatchChanceBoosterModifier } from "#app/modifier/modifier"; import { NumberHolder } from "#app/utils"; import { PokeballType } from "#enums/pokeball"; -import BattleScene from "../battle-scene"; import i18next from "i18next"; export const MAX_PER_TYPE_POKEBALLS: integer = 99; @@ -85,18 +85,17 @@ export function getPokeballTintColor(type: PokeballType): number { /** * Gets the critical capture chance based on number of mons registered in Dex and modified {@link https://bulbapedia.bulbagarden.net/wiki/Catch_rate Catch rate} * Formula from {@link https://www.dragonflycave.com/mechanics/gen-vi-vii-capturing Dragonfly Cave Gen 6 Capture Mechanics page} - * @param scene {@linkcode BattleScene} current BattleScene * @param modifiedCatchRate the modified catch rate as calculated in {@linkcode AttemptCapturePhase} * @returns the chance of getting a critical capture, out of 256 */ -export function getCriticalCaptureChance(scene: BattleScene, modifiedCatchRate: number): number { - if (scene.gameMode.isFreshStartChallenge()) { +export function getCriticalCaptureChance(modifiedCatchRate: number): number { + if (globalScene.gameMode.isFreshStartChallenge()) { return 0; } - const dexCount = scene.gameData.getSpeciesCount(d => !!d.caughtAttr); + const dexCount = globalScene.gameData.getSpeciesCount(d => !!d.caughtAttr); const catchingCharmMultiplier = new NumberHolder(1); - scene.findModifier(m => m instanceof CriticalCatchChanceBoosterModifier)?.apply(catchingCharmMultiplier); - const dexMultiplier = scene.gameMode.isDaily || dexCount > 800 ? 2.5 + globalScene.findModifier(m => m instanceof CriticalCatchChanceBoosterModifier)?.apply(catchingCharmMultiplier); + const dexMultiplier = globalScene.gameMode.isDaily || dexCount > 800 ? 2.5 : dexCount > 600 ? 2 : dexCount > 400 ? 1.5 : dexCount > 200 ? 1 @@ -105,7 +104,7 @@ export function getCriticalCaptureChance(scene: BattleScene, modifiedCatchRate: return Math.floor(catchingCharmMultiplier.value * dexMultiplier * Math.min(255, modifiedCatchRate) / 6); } -export function doPokeballBounceAnim(scene: BattleScene, pokeball: Phaser.GameObjects.Sprite, y1: number, y2: number, baseBounceDuration: number, callback: Function, isCritical: boolean = false) { +export function doPokeballBounceAnim(pokeball: Phaser.GameObjects.Sprite, y1: number, y2: number, baseBounceDuration: number, callback: Function, isCritical: boolean = false) { let bouncePower = 1; let bounceYOffset = y1; let bounceY = y2; @@ -116,13 +115,13 @@ export function doPokeballBounceAnim(scene: BattleScene, pokeball: Phaser.GameOb let critShakes = 4; const doBounce = () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, y: y2, duration: bouncePower * baseBounceDuration, ease: "Cubic.easeIn", onComplete: () => { - scene.playSound("se/pb_bounce_1", { volume: bouncePower }); + globalScene.playSound("se/pb_bounce_1", { volume: bouncePower }); bouncePower = bouncePower > 0.01 ? bouncePower * 0.5 : 0; @@ -130,7 +129,7 @@ export function doPokeballBounceAnim(scene: BattleScene, pokeball: Phaser.GameOb bounceYOffset = yd * bouncePower; bounceY = y2 - bounceYOffset; - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, y: bounceY, duration: bouncePower * baseBounceDuration, @@ -145,13 +144,13 @@ export function doPokeballBounceAnim(scene: BattleScene, pokeball: Phaser.GameOb }; const doCritShake = () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, x: x2, duration: 125, ease: "Linear", onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, x: x1, duration: 125, @@ -161,12 +160,12 @@ export function doPokeballBounceAnim(scene: BattleScene, pokeball: Phaser.GameOb if (critShakes > 0) { doCritShake(); } else { - scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, x: x0, duration: 60, ease: "Linear", - onComplete: () => scene.time.delayedCall(500, doBounce) + onComplete: () => globalScene.time.delayedCall(500, doBounce) }); } } @@ -176,7 +175,7 @@ export function doPokeballBounceAnim(scene: BattleScene, pokeball: Phaser.GameOb }; if (isCritical) { - scene.time.delayedCall(500, doCritShake); + globalScene.time.delayedCall(500, doCritShake); } else { doBounce(); } diff --git a/src/data/pokemon-forms.ts b/src/data/pokemon-forms.ts index a1b2d7896d73..ead35cb726f7 100644 --- a/src/data/pokemon-forms.ts +++ b/src/data/pokemon-forms.ts @@ -13,6 +13,7 @@ import i18next from "i18next"; import { WeatherType } from "#enums/weather-type"; import { Challenges } from "#app/enums/challenges"; import { SpeciesFormKey } from "#enums/species-form-key"; +import { globalScene } from "#app/global-scene"; export enum FormChangeItem { NONE, @@ -259,7 +260,7 @@ export class SpeciesFormChangeItemTrigger extends SpeciesFormChangeTrigger { } canChange(pokemon: Pokemon): boolean { - return !!pokemon.scene.findModifier(m => m instanceof PokemonFormChangeItemModifier && m.pokemonId === pokemon.id && m.formChangeItem === this.item && m.active === this.active); + return !!globalScene.findModifier(m => m instanceof PokemonFormChangeItemModifier && m.pokemonId === pokemon.id && m.formChangeItem === this.item && m.active === this.active); } } @@ -272,7 +273,7 @@ export class SpeciesFormChangeTimeOfDayTrigger extends SpeciesFormChangeTrigger } canChange(pokemon: Pokemon): boolean { - return this.timesOfDay.indexOf(pokemon.scene.arena.getTimeOfDay()) > -1; + return this.timesOfDay.indexOf(globalScene.arena.getTimeOfDay()) > -1; } } @@ -335,7 +336,7 @@ export abstract class SpeciesFormChangeMoveTrigger extends SpeciesFormChangeTrig export class SpeciesFormChangePreMoveTrigger extends SpeciesFormChangeMoveTrigger { canChange(pokemon: Pokemon): boolean { - const command = pokemon.scene.currentBattle.turnCommands[pokemon.getBattlerIndex()]; + const command = globalScene.currentBattle.turnCommands[pokemon.getBattlerIndex()]; return !!command?.move && this.movePredicate(command.move.move) === this.used; } } @@ -348,7 +349,7 @@ export class SpeciesFormChangePostMoveTrigger extends SpeciesFormChangeMoveTrigg export class MeloettaFormChangePostMoveTrigger extends SpeciesFormChangePostMoveTrigger { override canChange(pokemon: Pokemon): boolean { - if (pokemon.scene.gameMode.hasChallenge(Challenges.SINGLE_TYPE)) { + if (globalScene.gameMode.hasChallenge(Challenges.SINGLE_TYPE)) { return false; } else { // Meloetta will not transform if it has the ability Sheer Force when using Relic Song @@ -369,7 +370,7 @@ export class SpeciesDefaultFormMatchTrigger extends SpeciesFormChangeTrigger { } canChange(pokemon: Pokemon): boolean { - return this.formKey === pokemon.species.forms[pokemon.scene.getSpeciesFormIndex(pokemon.species, pokemon.gender, pokemon.getNature(), true)].formKey; + return this.formKey === pokemon.species.forms[globalScene.getSpeciesFormIndex(pokemon.species, pokemon.gender, pokemon.getNature(), true)].formKey; } } @@ -393,7 +394,7 @@ export class SpeciesFormChangeTeraTrigger extends SpeciesFormChangeTrigger { * @returns `true` if the Pokémon can change forms, `false` otherwise */ canChange(pokemon: Pokemon): boolean { - return !!pokemon.scene.findModifier(m => m instanceof TerastallizeModifier && m.pokemonId === pokemon.id && m.teraType === this.teraType); + return !!globalScene.findModifier(m => m instanceof TerastallizeModifier && m.pokemonId === pokemon.id && m.teraType === this.teraType); } } @@ -404,7 +405,7 @@ export class SpeciesFormChangeTeraTrigger extends SpeciesFormChangeTrigger { */ export class SpeciesFormChangeLapseTeraTrigger extends SpeciesFormChangeTrigger { canChange(pokemon: Pokemon): boolean { - return !!pokemon.scene.findModifier(m => m instanceof TerastallizeModifier && m.pokemonId === pokemon.id); + return !!globalScene.findModifier(m => m instanceof TerastallizeModifier && m.pokemonId === pokemon.id); } } @@ -432,8 +433,8 @@ export class SpeciesFormChangeWeatherTrigger extends SpeciesFormChangeTrigger { * @returns `true` if the Pokemon can change forms, `false` otherwise */ canChange(pokemon: Pokemon): boolean { - const currentWeather = pokemon.scene.arena.weather?.weatherType ?? WeatherType.NONE; - const isWeatherSuppressed = pokemon.scene.arena.weather?.isEffectSuppressed(pokemon.scene); + const currentWeather = globalScene.arena.weather?.weatherType ?? WeatherType.NONE; + const isWeatherSuppressed = globalScene.arena.weather?.isEffectSuppressed(); const isAbilitySuppressed = pokemon.summonData.abilitySuppressed; return !isAbilitySuppressed && !isWeatherSuppressed && (pokemon.hasAbility(this.ability) && this.weathers.includes(currentWeather)); @@ -466,8 +467,8 @@ export class SpeciesFormChangeRevertWeatherFormTrigger extends SpeciesFormChange */ canChange(pokemon: Pokemon): boolean { if (pokemon.hasAbility(this.ability, false, true)) { - const currentWeather = pokemon.scene.arena.weather?.weatherType ?? WeatherType.NONE; - const isWeatherSuppressed = pokemon.scene.arena.weather?.isEffectSuppressed(pokemon.scene); + const currentWeather = globalScene.arena.weather?.weatherType ?? WeatherType.NONE; + const isWeatherSuppressed = globalScene.arena.weather?.isEffectSuppressed(); const isAbilitySuppressed = pokemon.summonData.abilitySuppressed; const summonDataAbility = pokemon.summonData.ability; const isAbilityChanged = summonDataAbility !== this.ability && summonDataAbility !== Abilities.NONE; @@ -510,7 +511,7 @@ export function getSpeciesFormChangeMessage(pokemon: Pokemon, formChange: Specie * @returns A {@linkcode SpeciesFormChangeCondition} checking if that species is registered as caught */ function getSpeciesDependentFormChangeCondition(species: Species): SpeciesFormChangeCondition { - return new SpeciesFormChangeCondition(p => !!p.scene.gameData.dexData[species].caughtAttr); + return new SpeciesFormChangeCondition(p => !!globalScene.gameData.dexData[species].caughtAttr); } interface PokemonFormChanges { diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index 09788e353cf0..b8889530e3ed 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -4,7 +4,8 @@ import { PartyMemberStrength } from "#enums/party-member-strength"; import { Species } from "#enums/species"; import { QuantizerCelebi, argbFromRgba, rgbaFromArgb } from "@material/material-color-utilities"; import i18next from "i18next"; -import BattleScene, { AnySound } from "#app/battle-scene"; +import { AnySound } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { GameMode } from "#app/game-mode"; import { StarterMoveset } from "#app/system/game-data"; import * as Utils from "#app/utils"; @@ -490,34 +491,34 @@ export abstract class PokemonSpeciesForm { return true; } - loadAssets(scene: BattleScene, female: boolean, formIndex?: number, shiny?: boolean, variant?: Variant, startLoad?: boolean): Promise { + loadAssets(female: boolean, formIndex?: number, shiny?: boolean, variant?: Variant, startLoad?: boolean): Promise { return new Promise(resolve => { const spriteKey = this.getSpriteKey(female, formIndex, shiny, variant); - scene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant)); - scene.load.audio(`${this.getCryKey(formIndex)}`, `audio/${this.getCryKey(formIndex)}.m4a`); - scene.load.once(Phaser.Loader.Events.COMPLETE, () => { + globalScene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant)); + globalScene.load.audio(`${this.getCryKey(formIndex)}`, `audio/${this.getCryKey(formIndex)}.m4a`); + globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => { const originalWarn = console.warn; // Ignore warnings for missing frames, because there will be a lot console.warn = () => {}; - const frameNames = scene.anims.generateFrameNames(spriteKey, { zeroPad: 4, suffix: ".png", start: 1, end: 400 }); + const frameNames = globalScene.anims.generateFrameNames(spriteKey, { zeroPad: 4, suffix: ".png", start: 1, end: 400 }); console.warn = originalWarn; - if (!(scene.anims.exists(spriteKey))) { - scene.anims.create({ + if (!(globalScene.anims.exists(spriteKey))) { + globalScene.anims.create({ key: this.getSpriteKey(female, formIndex, shiny, variant), frames: frameNames, frameRate: 10, repeat: -1 }); } else { - scene.anims.get(spriteKey).frameRate = 10; + globalScene.anims.get(spriteKey).frameRate = 10; } const spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant).replace("variant/", "").replace(/_[1-3]$/, ""); - scene.loadPokemonVariantAssets(spriteKey, spritePath, variant); + globalScene.loadPokemonVariantAssets(spriteKey, spritePath, variant); resolve(); }); if (startLoad) { - if (!scene.load.isLoading()) { - scene.load.start(); + if (!globalScene.load.isLoading()) { + globalScene.load.start(); } } else { resolve(); @@ -525,21 +526,21 @@ export abstract class PokemonSpeciesForm { }); } - cry(scene: BattleScene, soundConfig?: Phaser.Types.Sound.SoundConfig, ignorePlay?: boolean): AnySound { + cry(soundConfig?: Phaser.Types.Sound.SoundConfig, ignorePlay?: boolean): AnySound { const cryKey = this.getCryKey(this.formIndex); - let cry: AnySound | null = scene.sound.get(cryKey) as AnySound; + let cry: AnySound | null = globalScene.sound.get(cryKey) as AnySound; if (cry?.pendingRemove) { cry = null; } - cry = scene.playSound(cry ?? cryKey, soundConfig); + cry = globalScene.playSound(cry ?? cryKey, soundConfig); if (ignorePlay) { cry.stop(); } return cry; } - generateCandyColors(scene: BattleScene): number[][] { - const sourceTexture = scene.textures.get(this.getSpriteKey(false)); + generateCandyColors(): number[][] { + const sourceTexture = globalScene.textures.get(this.getSpriteKey(false)); const sourceFrame = sourceTexture.frames[sourceTexture.firstFrame]; const sourceImage = sourceTexture.getSourceImage() as HTMLImageElement; @@ -582,7 +583,7 @@ export abstract class PokemonSpeciesForm { const originalRandom = Math.random; Math.random = () => Phaser.Math.RND.realInRange(0, 1); - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { paletteColors = QuantizerCelebi.quantize(pixelColors, 2); }, 0, "This result should not vary"); @@ -959,14 +960,13 @@ export const noStarterFormKeys: string[] = [ /** * Method to get the daily list of starters with Pokerus. -* @param scene {@linkcode BattleScene} used as part of RNG * @returns A list of starters with Pokerus */ -export function getPokerusStarters(scene: BattleScene): PokemonSpecies[] { +export function getPokerusStarters(): PokemonSpecies[] { const pokerusStarters: PokemonSpecies[] = []; const date = new Date(); date.setUTCHours(0, 0, 0, 0); - scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { while (pokerusStarters.length < POKERUS_STARTER_COUNT) { const randomSpeciesId = parseInt(Utils.randSeedItem(Object.keys(speciesStarterCosts)), 10); const species = getPokemonSpecies(randomSpeciesId); diff --git a/src/data/trainer-config.ts b/src/data/trainer-config.ts index d99ca601bdf4..c1e0f663498e 100644 --- a/src/data/trainer-config.ts +++ b/src/data/trainer-config.ts @@ -1,4 +1,5 @@ -import BattleScene, { startingWave } from "#app/battle-scene"; +import { startingWave } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ModifierTypeFunc, modifierTypes } from "#app/modifier/modifier-type"; import { EnemyPokemon, PokemonMove } from "#app/field/pokemon"; import * as Utils from "#app/utils"; @@ -169,8 +170,8 @@ export const trainerPartyTemplates = { RIVAL_6: new TrainerPartyCompoundTemplate(new TrainerPartyTemplate(1, PartyMemberStrength.STRONG), new TrainerPartyTemplate(1, PartyMemberStrength.AVERAGE), new TrainerPartyTemplate(3, PartyMemberStrength.AVERAGE, false, true), new TrainerPartyTemplate(1, PartyMemberStrength.STRONGER)) }; -type PartyTemplateFunc = (scene: BattleScene) => TrainerPartyTemplate; -type PartyMemberFunc = (scene: BattleScene, level: integer, strength: PartyMemberStrength) => EnemyPokemon; +type PartyTemplateFunc = () => TrainerPartyTemplate; +type PartyMemberFunc = (level: integer, strength: PartyMemberStrength) => EnemyPokemon; type GenModifiersFunc = (party: EnemyPokemon[]) => PersistentModifier[]; export interface PartyMemberFuncs { @@ -842,7 +843,7 @@ export class TrainerConfig { this.setBattleBgm("battle_unova_gym"); this.setVictoryBgm("victory_gym"); this.setGenModifiersFunc(party => { - const waveIndex = party[0].scene.currentBattle.waveIndex; + const waveIndex = globalScene.currentBattle.waveIndex; return getRandomTeraModifiers(party, waveIndex >= 100 ? 1 : 0, specialtyTypes.length ? specialtyTypes : undefined); }); @@ -1011,28 +1012,28 @@ export class TrainerConfig { return ret; } - loadAssets(scene: BattleScene, variant: TrainerVariant): Promise { + loadAssets(variant: TrainerVariant): Promise { return new Promise(resolve => { const isDouble = variant === TrainerVariant.DOUBLE; const trainerKey = this.getSpriteKey(variant === TrainerVariant.FEMALE, false); const partnerTrainerKey = this.getSpriteKey(true, true); - scene.loadAtlas(trainerKey, "trainer"); + globalScene.loadAtlas(trainerKey, "trainer"); if (isDouble) { - scene.loadAtlas(partnerTrainerKey, "trainer"); + globalScene.loadAtlas(partnerTrainerKey, "trainer"); } - scene.load.once(Phaser.Loader.Events.COMPLETE, () => { + globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => { const originalWarn = console.warn; // Ignore warnings for missing frames, because there will be a lot console.warn = () => { }; - const frameNames = scene.anims.generateFrameNames(trainerKey, { + const frameNames = globalScene.anims.generateFrameNames(trainerKey, { zeroPad: 4, suffix: ".png", start: 1, end: 128 }); const partnerFrameNames = isDouble - ? scene.anims.generateFrameNames(partnerTrainerKey, { + ? globalScene.anims.generateFrameNames(partnerTrainerKey, { zeroPad: 4, suffix: ".png", start: 1, @@ -1040,16 +1041,16 @@ export class TrainerConfig { }) : ""; console.warn = originalWarn; - if (!(scene.anims.exists(trainerKey))) { - scene.anims.create({ + if (!(globalScene.anims.exists(trainerKey))) { + globalScene.anims.create({ key: trainerKey, frames: frameNames, frameRate: 24, repeat: -1 }); } - if (isDouble && !(scene.anims.exists(partnerTrainerKey))) { - scene.anims.create({ + if (isDouble && !(globalScene.anims.exists(partnerTrainerKey))) { + globalScene.anims.create({ key: partnerTrainerKey, frames: partnerFrameNames, frameRate: 24, @@ -1058,8 +1059,8 @@ export class TrainerConfig { } resolve(); }); - if (!scene.load.isLoading()) { - scene.load.start(); + if (!globalScene.load.isLoading()) { + globalScene.load.start(); } }); } @@ -1133,11 +1134,10 @@ interface TrainerConfigs { /** * The function to get variable strength grunts - * @param scene the singleton scene being passed in * @returns the correct TrainerPartyTemplate */ -function getEvilGruntPartyTemplate(scene: BattleScene): TrainerPartyTemplate { - const waveIndex = scene.currentBattle?.waveIndex; +function getEvilGruntPartyTemplate(): TrainerPartyTemplate { + const waveIndex = globalScene.currentBattle?.waveIndex; if (waveIndex < 40) { return trainerPartyTemplates.TWO_AVG; } else if (waveIndex < 63) { @@ -1151,29 +1151,29 @@ function getEvilGruntPartyTemplate(scene: BattleScene): TrainerPartyTemplate { } } -function getWavePartyTemplate(scene: BattleScene, ...templates: TrainerPartyTemplate[]) { - return templates[Math.min(Math.max(Math.ceil((scene.gameMode.getWaveForDifficulty(scene.currentBattle?.waveIndex || startingWave, true) - 20) / 30), 0), templates.length - 1)]; +function getWavePartyTemplate(...templates: TrainerPartyTemplate[]) { + return templates[Math.min(Math.max(Math.ceil((globalScene.gameMode.getWaveForDifficulty(globalScene.currentBattle?.waveIndex || startingWave, true) - 20) / 30), 0), templates.length - 1)]; } -function getGymLeaderPartyTemplate(scene: BattleScene) { - return getWavePartyTemplate(scene, trainerPartyTemplates.GYM_LEADER_1, trainerPartyTemplates.GYM_LEADER_2, trainerPartyTemplates.GYM_LEADER_3, trainerPartyTemplates.GYM_LEADER_4, trainerPartyTemplates.GYM_LEADER_5); +function getGymLeaderPartyTemplate() { + return getWavePartyTemplate(trainerPartyTemplates.GYM_LEADER_1, trainerPartyTemplates.GYM_LEADER_2, trainerPartyTemplates.GYM_LEADER_3, trainerPartyTemplates.GYM_LEADER_4, trainerPartyTemplates.GYM_LEADER_5); } /** * Randomly selects one of the `Species` from `speciesPool`, determines its evolution, level, and strength. - * Then adds Pokemon to scene. + * Then adds Pokemon to globalScene. * @param speciesPool * @param trainerSlot * @param ignoreEvolution * @param postProcess */ export function getRandomPartyMemberFunc(speciesPool: Species[], trainerSlot: TrainerSlot = TrainerSlot.TRAINER, ignoreEvolution: boolean = false, postProcess?: (enemyPokemon: EnemyPokemon) => void) { - return (scene: BattleScene, level: number, strength: PartyMemberStrength) => { + return (level: number, strength: PartyMemberStrength) => { let species = Utils.randSeedItem(speciesPool); if (!ignoreEvolution) { - species = getPokemonSpecies(species).getTrainerSpeciesForLevel(level, true, strength, scene.currentBattle.waveIndex); + species = getPokemonSpecies(species).getTrainerSpeciesForLevel(level, true, strength, globalScene.currentBattle.waveIndex); } - return scene.addEnemyPokemon(getPokemonSpecies(species), level, trainerSlot, undefined, false, undefined, postProcess); + return globalScene.addEnemyPokemon(getPokemonSpecies(species), level, trainerSlot, undefined, false, undefined, postProcess); }; } @@ -1189,12 +1189,12 @@ function getSpeciesFilterRandomPartyMemberFunc( return (allowLegendaries || notLegendary) && !species.isTrainerForbidden() && originalSpeciesFilter(species); }; - return (scene: BattleScene, level: number, strength: PartyMemberStrength) => { - const waveIndex = scene.currentBattle.waveIndex; - const species = getPokemonSpecies(scene.randomSpecies(waveIndex, level, false, speciesFilter) + return (level: number, strength: PartyMemberStrength) => { + const waveIndex = globalScene.currentBattle.waveIndex; + const species = getPokemonSpecies(globalScene.randomSpecies(waveIndex, level, false, speciesFilter) .getTrainerSpeciesForLevel(level, true, strength, waveIndex)); - return scene.addEnemyPokemon(species, level, trainerSlot, undefined, false, undefined, postProcess); + return globalScene.addEnemyPokemon(species, level, trainerSlot, undefined, false, undefined, postProcess); }; } @@ -1353,7 +1353,7 @@ export const signatureSpecies: SignatureSpecies = { export const trainerConfigs: TrainerConfigs = { [TrainerType.UNKNOWN]: new TrainerConfig(0).setHasGenders(), [TrainerType.ACE_TRAINER]: new TrainerConfig(++t).setHasGenders("Ace Trainer Female").setHasDouble("Ace Duo").setMoneyMultiplier(2.25).setEncounterBgm(TrainerType.ACE_TRAINER) - .setPartyTemplateFunc(scene => getWavePartyTemplate(scene, trainerPartyTemplates.THREE_WEAK_BALANCED, trainerPartyTemplates.FOUR_WEAK_BALANCED, trainerPartyTemplates.FIVE_WEAK_BALANCED, trainerPartyTemplates.SIX_WEAK_BALANCED)), + .setPartyTemplateFunc(() => getWavePartyTemplate(trainerPartyTemplates.THREE_WEAK_BALANCED, trainerPartyTemplates.FOUR_WEAK_BALANCED, trainerPartyTemplates.FIVE_WEAK_BALANCED, trainerPartyTemplates.SIX_WEAK_BALANCED)), [TrainerType.ARTIST]: new TrainerConfig(++t).setEncounterBgm(TrainerType.RICH).setPartyTemplates(trainerPartyTemplates.ONE_STRONG, trainerPartyTemplates.TWO_AVG, trainerPartyTemplates.THREE_AVG) .setSpeciesPools([ Species.SMEARGLE ]), [TrainerType.BACKERS]: new TrainerConfig(++t).setHasGenders("Backers").setDoubleOnly().setEncounterBgm(TrainerType.CYCLIST), @@ -1378,7 +1378,7 @@ export const trainerConfigs: TrainerConfigs = { [TrainerPoolTier.ULTRA_RARE]: [ Species.KUBFU ] }), [TrainerType.BREEDER]: new TrainerConfig(++t).setMoneyMultiplier(1.325).setEncounterBgm(TrainerType.POKEFAN).setHasGenders("Breeder Female").setHasDouble("Breeders") - .setPartyTemplateFunc(scene => getWavePartyTemplate(scene, trainerPartyTemplates.FOUR_WEAKER, trainerPartyTemplates.FIVE_WEAKER, trainerPartyTemplates.SIX_WEAKER)) + .setPartyTemplateFunc(() => getWavePartyTemplate(trainerPartyTemplates.FOUR_WEAKER, trainerPartyTemplates.FIVE_WEAKER, trainerPartyTemplates.SIX_WEAKER)) .setSpeciesFilter(s => s.baseTotal < 450), [TrainerType.CLERK]: new TrainerConfig(++t).setHasGenders("Clerk Female").setHasDouble("Colleagues").setEncounterBgm(TrainerType.CLERK) .setPartyTemplates(trainerPartyTemplates.TWO_WEAK, trainerPartyTemplates.THREE_WEAK, trainerPartyTemplates.ONE_AVG, trainerPartyTemplates.TWO_AVG, trainerPartyTemplates.TWO_WEAK_ONE_AVG) @@ -1497,7 +1497,7 @@ export const trainerConfigs: TrainerConfigs = { }), [TrainerType.SWIMMER]: new TrainerConfig(++t).setMoneyMultiplier(1.3).setEncounterBgm(TrainerType.PARASOL_LADY).setHasGenders("Swimmer Female").setHasDouble("Swimmers").setSpecialtyTypes(Type.WATER).setSpeciesFilter(s => s.isOfType(Type.WATER)), [TrainerType.TWINS]: new TrainerConfig(++t).setDoubleOnly().setMoneyMultiplier(0.65).setUseSameSeedForAllMembers() - .setPartyTemplateFunc(scene => getWavePartyTemplate(scene, trainerPartyTemplates.TWO_WEAK, trainerPartyTemplates.TWO_AVG, trainerPartyTemplates.TWO_STRONG)) + .setPartyTemplateFunc(() => getWavePartyTemplate(trainerPartyTemplates.TWO_WEAK, trainerPartyTemplates.TWO_AVG, trainerPartyTemplates.TWO_STRONG)) .setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.PLUSLE, Species.VOLBEAT, Species.PACHIRISU, Species.SILCOON, Species.METAPOD, Species.IGGLYBUFF, Species.PETILIL, Species.EEVEE ])) .setPartyMemberFunc(1, getRandomPartyMemberFunc([ Species.MINUN, Species.ILLUMISE, Species.EMOLGA, Species.CASCOON, Species.KAKUNA, Species.CLEFFA, Species.COTTONEE, Species.EEVEE ], TrainerSlot.TRAINER_PARTNER)) .setEncounterBgm(TrainerType.TWINS), @@ -1513,115 +1513,115 @@ export const trainerConfigs: TrainerConfigs = { .setSpeciesPools( [ Species.CATERPIE, Species.WEEDLE, Species.RATTATA, Species.SENTRET, Species.POOCHYENA, Species.ZIGZAGOON, Species.WURMPLE, Species.BIDOOF, Species.PATRAT, Species.LILLIPUP ] ), - [TrainerType.ROCKET_GRUNT]: new TrainerConfig(++t).setHasGenders("Rocket Grunt Female").setHasDouble("Rocket Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.ROCKET_GRUNT]: new TrainerConfig(++t).setHasGenders("Rocket Grunt Female").setHasDouble("Rocket Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.WEEDLE, Species.RATTATA, Species.EKANS, Species.SANDSHREW, Species.ZUBAT, Species.GEODUDE, Species.KOFFING, Species.GRIMER, Species.ODDISH, Species.SLOWPOKE ], [TrainerPoolTier.UNCOMMON]: [ Species.GYARADOS, Species.LICKITUNG, Species.TAUROS, Species.MANKEY, Species.SCYTHER, Species.ELEKID, Species.MAGBY, Species.CUBONE, Species.GROWLITHE, Species.MURKROW, Species.GASTLY, Species.EXEGGCUTE, Species.VOLTORB, Species.MAGNEMITE ], [TrainerPoolTier.RARE]: [ Species.PORYGON, Species.ALOLA_RATTATA, Species.ALOLA_SANDSHREW, Species.ALOLA_MEOWTH, Species.ALOLA_GRIMER, Species.ALOLA_GEODUDE, Species.PALDEA_TAUROS, Species.OMANYTE, Species.KABUTO ], [TrainerPoolTier.SUPER_RARE]: [ Species.DRATINI, Species.LARVITAR ] }), - [TrainerType.ARCHER]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin", "rocket", [ Species.HOUNDOOM ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.ARIANA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin_female", "rocket", [ Species.ARBOK ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.PROTON]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin", "rocket", [ Species.CROBAT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.PETREL]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin", "rocket", [ Species.WEEZING ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.MAGMA_GRUNT]: new TrainerConfig(++t).setHasGenders("Magma Grunt Female").setHasDouble("Magma Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.ARCHER]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin", "rocket", [ Species.HOUNDOOM ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.ARIANA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin_female", "rocket", [ Species.ARBOK ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.PROTON]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin", "rocket", [ Species.CROBAT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.PETREL]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("rocket_admin", "rocket", [ Species.WEEZING ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_rocket_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.MAGMA_GRUNT]: new TrainerConfig(++t).setHasGenders("Magma Grunt Female").setHasDouble("Magma Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.SLUGMA, Species.POOCHYENA, Species.NUMEL, Species.ZIGZAGOON, Species.DIGLETT, Species.MAGBY, Species.TORKOAL, Species.GROWLITHE, Species.BALTOY ], [TrainerPoolTier.UNCOMMON]: [ Species.SOLROCK, Species.HIPPOPOTAS, Species.SANDACONDA, Species.PHANPY, Species.ROLYCOLY, Species.GLIGAR, Species.RHYHORN, Species.HEATMOR ], [TrainerPoolTier.RARE]: [ Species.TRAPINCH, Species.LILEEP, Species.ANORITH, Species.HISUI_GROWLITHE, Species.TURTONATOR, Species.ARON, Species.TOEDSCOOL ], [TrainerPoolTier.SUPER_RARE]: [ Species.CAPSAKID, Species.CHARCADET ] }), - [TrainerType.TABITHA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("magma_admin", "magma", [ Species.CAMERUPT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.COURTNEY]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("magma_admin_female", "magma", [ Species.CAMERUPT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.AQUA_GRUNT]: new TrainerConfig(++t).setHasGenders("Aqua Grunt Female").setHasDouble("Aqua Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.TABITHA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("magma_admin", "magma", [ Species.CAMERUPT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.COURTNEY]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("magma_admin_female", "magma", [ Species.CAMERUPT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.AQUA_GRUNT]: new TrainerConfig(++t).setHasGenders("Aqua Grunt Female").setHasDouble("Aqua Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.CARVANHA, Species.WAILMER, Species.ZIGZAGOON, Species.LOTAD, Species.CORPHISH, Species.SPHEAL, Species.REMORAID, Species.QWILFISH, Species.BARBOACH ], [TrainerPoolTier.UNCOMMON]: [ Species.CLAMPERL, Species.CHINCHOU, Species.WOOPER, Species.WINGULL, Species.TENTACOOL, Species.AZURILL, Species.CLOBBOPUS, Species.HORSEA ], [TrainerPoolTier.RARE]: [ Species.MANTYKE, Species.DHELMISE, Species.HISUI_QWILFISH, Species.ARROKUDA, Species.PALDEA_WOOPER, Species.SKRELP ], [TrainerPoolTier.SUPER_RARE]: [ Species.DONDOZO, Species.BASCULEGION ] }), - [TrainerType.MATT]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("aqua_admin", "aqua", [ Species.SHARPEDO ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.SHELLY]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("aqua_admin_female", "aqua", [ Species.SHARPEDO ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.GALACTIC_GRUNT]: new TrainerConfig(++t).setHasGenders("Galactic Grunt Female").setHasDouble("Galactic Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.MATT]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("aqua_admin", "aqua", [ Species.SHARPEDO ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.SHELLY]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("aqua_admin_female", "aqua", [ Species.SHARPEDO ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aqua_magma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.GALACTIC_GRUNT]: new TrainerConfig(++t).setHasGenders("Galactic Grunt Female").setHasDouble("Galactic Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.GLAMEOW, Species.STUNKY, Species.CROAGUNK, Species.SHINX, Species.WURMPLE, Species.BRONZOR, Species.DRIFLOON, Species.BURMY, Species.CARNIVINE ], [TrainerPoolTier.UNCOMMON]: [ Species.LICKITUNG, Species.RHYHORN, Species.TANGELA, Species.ZUBAT, Species.YANMA, Species.SKORUPI, Species.GLIGAR, Species.SWINUB ], [TrainerPoolTier.RARE]: [ Species.HISUI_GROWLITHE, Species.HISUI_QWILFISH, Species.SNEASEL, Species.ELEKID, Species.MAGBY, Species.DUSKULL ], [TrainerPoolTier.SUPER_RARE]: [ Species.ROTOM, Species.SPIRITOMB, Species.HISUI_SNEASEL ] }), - [TrainerType.JUPITER]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("galactic_commander_female", "galactic", [ Species.SKUNTANK ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.MARS]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("galactic_commander_female", "galactic", [ Species.PURUGLY ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.SATURN]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("galactic_commander", "galactic", [ Species.TOXICROAK ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.PLASMA_GRUNT]: new TrainerConfig(++t).setHasGenders("Plasma Grunt Female").setHasDouble("Plasma Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_plasma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.JUPITER]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("galactic_commander_female", "galactic", [ Species.SKUNTANK ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.MARS]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("galactic_commander_female", "galactic", [ Species.PURUGLY ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.SATURN]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("galactic_commander", "galactic", [ Species.TOXICROAK ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_galactic_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.PLASMA_GRUNT]: new TrainerConfig(++t).setHasGenders("Plasma Grunt Female").setHasDouble("Plasma Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_plasma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.PATRAT, Species.LILLIPUP, Species.PURRLOIN, Species.SCRAFTY, Species.WOOBAT, Species.VANILLITE, Species.SANDILE, Species.TRUBBISH, Species.TYMPOLE ], [TrainerPoolTier.UNCOMMON]: [ Species.FRILLISH, Species.VENIPEDE, Species.GOLETT, Species.TIMBURR, Species.DARUMAKA, Species.FOONGUS, Species.JOLTIK, Species.CUBCHOO, Species.KLINK ], [TrainerPoolTier.RARE]: [ Species.PAWNIARD, Species.RUFFLET, Species.VULLABY, Species.ZORUA, Species.DRILBUR, Species.MIENFOO, Species.DURANT, Species.BOUFFALANT ], [TrainerPoolTier.SUPER_RARE]: [ Species.DRUDDIGON, Species.HISUI_ZORUA, Species.AXEW, Species.DEINO ] }), - [TrainerType.ZINZOLIN]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("plasma_sage", "plasma", [ Species.CRYOGONAL ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_plasma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.ROOD]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("plasma_sage", "plasma", [ Species.SWOOBAT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_plasma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.FLARE_GRUNT]: new TrainerConfig(++t).setHasGenders("Flare Grunt Female").setHasDouble("Flare Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_flare_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.ZINZOLIN]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("plasma_sage", "plasma", [ Species.CRYOGONAL ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_plasma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.ROOD]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("plasma_sage", "plasma", [ Species.SWOOBAT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_plasma_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.FLARE_GRUNT]: new TrainerConfig(++t).setHasGenders("Flare Grunt Female").setHasDouble("Flare Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_flare_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.FLETCHLING, Species.LITLEO, Species.PONYTA, Species.INKAY, Species.HOUNDOUR, Species.SKORUPI, Species.SCRAFTY, Species.CROAGUNK, Species.SCATTERBUG, Species.ESPURR ], [TrainerPoolTier.UNCOMMON]: [ Species.HELIOPTILE, Species.ELECTRIKE, Species.SKRELP, Species.PANCHAM, Species.PURRLOIN, Species.POOCHYENA, Species.BINACLE, Species.CLAUNCHER, Species.PUMPKABOO, Species.PHANTUMP, Species.FOONGUS ], [TrainerPoolTier.RARE]: [ Species.LITWICK, Species.SNEASEL, Species.PAWNIARD, Species.SLIGGOO ], [TrainerPoolTier.SUPER_RARE]: [ Species.NOIBAT, Species.HISUI_SLIGGOO, Species.HISUI_AVALUGG ] }), - [TrainerType.BRYONY]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("flare_admin_female", "flare", [ Species.LIEPARD ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_flare_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.XEROSIC]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("flare_admin", "flare", [ Species.MALAMAR ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_flare_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.AETHER_GRUNT]: new TrainerConfig(++t).setHasGenders("Aether Grunt Female").setHasDouble("Aether Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aether_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.BRYONY]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("flare_admin_female", "flare", [ Species.LIEPARD ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_flare_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.XEROSIC]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("flare_admin", "flare", [ Species.MALAMAR ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_flare_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.AETHER_GRUNT]: new TrainerConfig(++t).setHasGenders("Aether Grunt Female").setHasDouble("Aether Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aether_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.PIKIPEK, Species.ROCKRUFF, Species.ALOLA_DIGLETT, Species.ALOLA_EXEGGUTOR, Species.YUNGOOS, Species.CORSOLA, Species.ALOLA_GEODUDE, Species.ALOLA_RAICHU, Species.BOUNSWEET, Species.LILLIPUP, Species.KOMALA, Species.MORELULL, Species.COMFEY, Species.TOGEDEMARU ], [TrainerPoolTier.UNCOMMON]: [ Species.POLIWAG, Species.STUFFUL, Species.ORANGURU, Species.PASSIMIAN, Species.BRUXISH, Species.MINIOR, Species.WISHIWASHI, Species.ALOLA_SANDSHREW, Species.ALOLA_VULPIX, Species.CRABRAWLER, Species.CUTIEFLY, Species.ORICORIO, Species.MUDBRAY, Species.PYUKUMUKU, Species.ALOLA_MAROWAK ], [TrainerPoolTier.RARE]: [ Species.GALAR_CORSOLA, Species.TURTONATOR, Species.MIMIKYU, Species.MAGNEMITE, Species.DRAMPA ], [TrainerPoolTier.SUPER_RARE]: [ Species.JANGMO_O, Species.PORYGON ] }), - [TrainerType.FABA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("aether_admin", "aether", [ Species.HYPNO ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aether_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.SKULL_GRUNT]: new TrainerConfig(++t).setHasGenders("Skull Grunt Female").setHasDouble("Skull Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_skull_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.FABA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("aether_admin", "aether", [ Species.HYPNO ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_aether_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.SKULL_GRUNT]: new TrainerConfig(++t).setHasGenders("Skull Grunt Female").setHasDouble("Skull Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_skull_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.SALANDIT, Species.ALOLA_RATTATA, Species.EKANS, Species.ALOLA_MEOWTH, Species.SCRAGGY, Species.KOFFING, Species.ALOLA_GRIMER, Species.MAREANIE, Species.SPINARAK, Species.TRUBBISH, Species.DROWZEE ], [TrainerPoolTier.UNCOMMON]: [ Species.FOMANTIS, Species.SABLEYE, Species.SANDILE, Species.HOUNDOUR, Species.ALOLA_MAROWAK, Species.GASTLY, Species.PANCHAM, Species.ZUBAT, Species.VENIPEDE, Species.VULLABY ], [TrainerPoolTier.RARE]: [ Species.SANDYGAST, Species.PAWNIARD, Species.MIMIKYU, Species.DHELMISE, Species.WISHIWASHI, Species.NYMBLE ], [TrainerPoolTier.SUPER_RARE]: [ Species.GRUBBIN, Species.DEWPIDER ] }), - [TrainerType.PLUMERIA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("skull_admin", "skull", [ Species.SALAZZLE ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_skull_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.MACRO_GRUNT]: new TrainerConfig(++t).setHasGenders("Macro Grunt Female").setHasDouble("Macro Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_macro_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.PLUMERIA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("skull_admin", "skull", [ Species.SALAZZLE ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_skull_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.MACRO_GRUNT]: new TrainerConfig(++t).setHasGenders("Macro Grunt Female").setHasDouble("Macro Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_macro_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.CUFANT, Species.GALAR_MEOWTH, Species.KLINK, Species.ROOKIDEE, Species.CRAMORANT, Species.GALAR_ZIGZAGOON, Species.SKWOVET, Species.STEELIX, Species.MAWILE, Species.FERROSEED ], [TrainerPoolTier.UNCOMMON]: [ Species.DRILBUR, Species.MAGNEMITE, Species.HATENNA, Species.ARROKUDA, Species.APPLIN, Species.GALAR_PONYTA, Species.GALAR_YAMASK, Species.SINISTEA, Species.RIOLU ], [TrainerPoolTier.RARE]: [ Species.FALINKS, Species.BELDUM, Species.GALAR_FARFETCHD, Species.GALAR_MR_MIME, Species.HONEDGE, Species.SCIZOR, Species.GALAR_DARUMAKA ], [TrainerPoolTier.SUPER_RARE]: [ Species.DURALUDON, Species.DREEPY ] }), - [TrainerType.OLEANA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("macro_admin", "macro", [ Species.GARBODOR ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_oleana").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)), - [TrainerType.STAR_GRUNT]: new TrainerConfig(++t).setHasGenders("Star Grunt Female").setHasDouble("Star Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.OLEANA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("macro_admin", "macro", [ Species.GARBODOR ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_oleana").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()), + [TrainerType.STAR_GRUNT]: new TrainerConfig(++t).setHasGenders("Star Grunt Female").setHasDouble("Star Grunts").setMoneyMultiplier(1.0).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_grunt").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setSpeciesPools({ [TrainerPoolTier.COMMON]: [ Species.DUNSPARCE, Species.HOUNDOUR, Species.AZURILL, Species.GULPIN, Species.FOONGUS, Species.FLETCHLING, Species.LITLEO, Species.FLABEBE, Species.CRABRAWLER, Species.NYMBLE, Species.PAWMI, Species.FIDOUGH, Species.SQUAWKABILLY, Species.MASCHIFF, Species.SHROODLE, Species.KLAWF, Species.WIGLETT, Species.PALDEA_WOOPER ], [TrainerPoolTier.UNCOMMON]: [ Species.KOFFING, Species.EEVEE, Species.GIRAFARIG, Species.RALTS, Species.TORKOAL, Species.SEVIPER, Species.SCRAGGY, Species.ZORUA, Species.MIMIKYU, Species.IMPIDIMP, Species.FALINKS, Species.CAPSAKID, Species.TINKATINK, Species.BOMBIRDIER, Species.CYCLIZAR, Species.FLAMIGO, Species.PALDEA_TAUROS ], [TrainerPoolTier.RARE]: [ Species.MANKEY, Species.PAWNIARD, Species.CHARCADET, Species.FLITTLE, Species.VAROOM, Species.ORTHWORM ], [TrainerPoolTier.SUPER_RARE]: [ Species.DONDOZO, Species.GIMMIGHOUL ] }), - [TrainerType.GIACOMO]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_1", [ Species.KINGAMBIT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.GIACOMO]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_1", [ Species.KINGAMBIT ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setPartyMemberFunc(3, getRandomPartyMemberFunc([ Species.REVAVROOM ], TrainerSlot.TRAINER, true, p => { p.formIndex = 1; // Segin Starmobile p.moveset = [ new PokemonMove(Moves.WICKED_TORQUE), new PokemonMove(Moves.SPIN_OUT), new PokemonMove(Moves.SHIFT_GEAR), new PokemonMove(Moves.HIGH_HORSEPOWER) ]; })), - [TrainerType.MELA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_2", [ Species.ARMAROUGE ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.MELA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_2", [ Species.ARMAROUGE ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setPartyMemberFunc(3, getRandomPartyMemberFunc([ Species.REVAVROOM ], TrainerSlot.TRAINER, true, p => { p.formIndex = 2; // Schedar Starmobile p.moveset = [ new PokemonMove(Moves.BLAZING_TORQUE), new PokemonMove(Moves.SPIN_OUT), new PokemonMove(Moves.SHIFT_GEAR), new PokemonMove(Moves.HIGH_HORSEPOWER) ]; })), - [TrainerType.ATTICUS]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_3", [ Species.REVAVROOM ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.ATTICUS]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_3", [ Species.REVAVROOM ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setPartyMemberFunc(3, getRandomPartyMemberFunc([ Species.REVAVROOM ], TrainerSlot.TRAINER, true, p => { p.formIndex = 3; // Navi Starmobile p.moveset = [ new PokemonMove(Moves.NOXIOUS_TORQUE), new PokemonMove(Moves.SPIN_OUT), new PokemonMove(Moves.SHIFT_GEAR), new PokemonMove(Moves.HIGH_HORSEPOWER) ]; })), - [TrainerType.ORTEGA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_4", [ Species.DACHSBUN ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.ORTEGA]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_4", [ Species.DACHSBUN ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setPartyMemberFunc(3, getRandomPartyMemberFunc([ Species.REVAVROOM ], TrainerSlot.TRAINER, true, p => { p.formIndex = 4; // Ruchbah Starmobile p.moveset = [ new PokemonMove(Moves.MAGICAL_TORQUE), new PokemonMove(Moves.SPIN_OUT), new PokemonMove(Moves.SHIFT_GEAR), new PokemonMove(Moves.HIGH_HORSEPOWER) ]; })), - [TrainerType.ERI]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_5", [ Species.ANNIHILAPE ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(scene => getEvilGruntPartyTemplate(scene)) + [TrainerType.ERI]: new TrainerConfig(++t).setMoneyMultiplier(1.5).initForEvilTeamAdmin("star_admin", "star_5", [ Species.ANNIHILAPE ]).setEncounterBgm(TrainerType.PLASMA_GRUNT).setBattleBgm("battle_plasma_grunt").setMixedBattleBgm("battle_star_admin").setVictoryBgm("victory_team_plasma").setPartyTemplateFunc(() => getEvilGruntPartyTemplate()) .setPartyMemberFunc(3, getRandomPartyMemberFunc([ Species.REVAVROOM ], TrainerSlot.TRAINER, true, p => { p.formIndex = 5; // Caph Starmobile p.moveset = [ new PokemonMove(Moves.COMBAT_TORQUE), new PokemonMove(Moves.SPIN_OUT), new PokemonMove(Moves.SHIFT_GEAR), new PokemonMove(Moves.HIGH_HORSEPOWER) ]; diff --git a/src/data/weather.ts b/src/data/weather.ts index 0a76a015402b..cdaceb067b38 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -5,10 +5,10 @@ import Pokemon from "../field/pokemon"; import { Type } from "#enums/type"; import Move, { AttackMove } from "./move"; import * as Utils from "../utils"; -import BattleScene from "../battle-scene"; import { SuppressWeatherEffectAbAttr } from "./ability"; import { TerrainType, getTerrainName } from "./terrain"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; export class Weather { public weatherType: WeatherType; @@ -100,8 +100,8 @@ export class Weather { return false; } - isEffectSuppressed(scene: BattleScene): boolean { - const field = scene.getField(true); + isEffectSuppressed(): boolean { + const field = globalScene.getField(true); for (const pokemon of field) { let suppressWeatherEffectAbAttr: SuppressWeatherEffectAbAttr | null = pokemon.getAbility().getAttrs(SuppressWeatherEffectAbAttr)[0]; diff --git a/src/field/anims.ts b/src/field/anims.ts index 10198c290054..314a4fe32813 100644 --- a/src/field/anims.ts +++ b/src/field/anims.ts @@ -1,32 +1,32 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { PokeballType } from "#enums/pokeball"; import { Variant } from "#app/data/variant"; import { getFrameMs, randGauss } from "#app/utils"; -export function addPokeballOpenParticles(scene: BattleScene, x: number, y: number, pokeballType: PokeballType): void { +export function addPokeballOpenParticles(x: number, y: number, pokeballType: PokeballType): void { switch (pokeballType) { case PokeballType.POKEBALL: - doDefaultPbOpenParticles(scene, x, y, 48); + doDefaultPbOpenParticles(x, y, 48); break; case PokeballType.GREAT_BALL: - doDefaultPbOpenParticles(scene, x, y, 96); + doDefaultPbOpenParticles(x, y, 96); break; case PokeballType.ULTRA_BALL: - doUbOpenParticles(scene, x, y, 8); + doUbOpenParticles(x, y, 8); break; case PokeballType.ROGUE_BALL: - doUbOpenParticles(scene, x, y, 10); + doUbOpenParticles(x, y, 10); break; case PokeballType.MASTER_BALL: - doMbOpenParticles(scene, x, y); + doMbOpenParticles(x, y); break; } } -function doDefaultPbOpenParticles(scene: BattleScene, x: number, y: number, radius: number) { - const pbOpenParticlesFrameNames = scene.anims.generateFrameNames("pb_particles", { start: 0, end: 3, suffix: ".png" }); - if (!(scene.anims.exists("pb_open_particle"))) { - scene.anims.create({ +function doDefaultPbOpenParticles(x: number, y: number, radius: number) { + const pbOpenParticlesFrameNames = globalScene.anims.generateFrameNames("pb_particles", { start: 0, end: 3, suffix: ".png" }); + if (!(globalScene.anims.exists("pb_open_particle"))) { + globalScene.anims.create({ key: "pb_open_particle", frames: pbOpenParticlesFrameNames, frameRate: 16, @@ -35,11 +35,11 @@ function doDefaultPbOpenParticles(scene: BattleScene, x: number, y: number, radi } const addParticle = (index: integer) => { - const particle = scene.add.sprite(x, y, "pb_open_particle"); - scene.field.add(particle); + const particle = globalScene.add.sprite(x, y, "pb_open_particle"); + globalScene.field.add(particle); const angle = index * 45; const [ xCoord, yCoord ] = [ radius * Math.cos(angle * Math.PI / 180), radius * Math.sin(angle * Math.PI / 180) ]; - scene.tweens.add({ + globalScene.tweens.add({ targets: particle, x: x + xCoord, y: y + yCoord, @@ -48,9 +48,9 @@ function doDefaultPbOpenParticles(scene: BattleScene, x: number, y: number, radi particle.play({ key: "pb_open_particle", startFrame: (index + 3) % 4, - frameRate: Math.floor(16 * scene.gameSpeed) + frameRate: Math.floor(16 * globalScene.gameSpeed) }); - scene.tweens.add({ + globalScene.tweens.add({ targets: particle, delay: 500, duration: 75, @@ -61,20 +61,20 @@ function doDefaultPbOpenParticles(scene: BattleScene, x: number, y: number, radi }; let particleCount = 0; - scene.time.addEvent({ + globalScene.time.addEvent({ delay: 20, repeat: 16, callback: () => addParticle(++particleCount) }); } -function doUbOpenParticles(scene: BattleScene, x: number, y: number, frameIndex: integer) { +function doUbOpenParticles(x: number, y: number, frameIndex: integer) { const particles: Phaser.GameObjects.Image[] = []; for (let i = 0; i < 10; i++) { - particles.push(doFanOutParticle(scene, i * 25, x, y, 1, 1, 5, frameIndex)); + particles.push(doFanOutParticle(i * 25, x, y, 1, 1, 5, frameIndex)); } - scene.tweens.add({ + globalScene.tweens.add({ targets: particles, delay: 750, duration: 250, @@ -88,14 +88,14 @@ function doUbOpenParticles(scene: BattleScene, x: number, y: number, frameIndex: }); } -function doMbOpenParticles(scene: BattleScene, x: number, y: number) { +function doMbOpenParticles(x: number, y: number) { const particles: Phaser.GameObjects.Image[] = []; for (let j = 0; j < 2; j++) { for (let i = 0; i < 8; i++) { - particles.push(doFanOutParticle(scene, i * 32, x, y, j ? 1 : 2, j ? 2 : 1, 8, 4)); + particles.push(doFanOutParticle(i * 32, x, y, j ? 1 : 2, j ? 2 : 1, 8, 4)); } - scene.tweens.add({ + globalScene.tweens.add({ targets: particles, delay: 750, duration: 250, @@ -110,11 +110,11 @@ function doMbOpenParticles(scene: BattleScene, x: number, y: number) { } } -function doFanOutParticle(scene: BattleScene, trigIndex: integer, x: integer, y: integer, xSpeed: integer, ySpeed: integer, angle: integer, frameIndex: integer): Phaser.GameObjects.Image { +function doFanOutParticle(trigIndex: integer, x: integer, y: integer, xSpeed: integer, ySpeed: integer, angle: integer, frameIndex: integer): Phaser.GameObjects.Image { let f = 0; - const particle = scene.add.image(x, y, "pb_particles", `${frameIndex}.png`); - scene.field.add(particle); + const particle = globalScene.add.image(x, y, "pb_particles", `${frameIndex}.png`); + globalScene.field.add(particle); const updateParticle = () => { if (!particle.scene) { @@ -126,7 +126,7 @@ function doFanOutParticle(scene: BattleScene, trigIndex: integer, x: integer, y: f++; }; - const particleTimer = scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: getFrameMs(1), onRepeat: () => { @@ -137,20 +137,20 @@ function doFanOutParticle(scene: BattleScene, trigIndex: integer, x: integer, y: return particle; } -export function addPokeballCaptureStars(scene: BattleScene, pokeball: Phaser.GameObjects.Sprite): void { +export function addPokeballCaptureStars(pokeball: Phaser.GameObjects.Sprite): void { const addParticle = () => { - const particle = scene.add.sprite(pokeball.x, pokeball.y, "pb_particles", "4.png"); + const particle = globalScene.add.sprite(pokeball.x, pokeball.y, "pb_particles", "4.png"); particle.setOrigin(pokeball.originX, pokeball.originY); particle.setAlpha(0.5); - scene.field.add(particle); + globalScene.field.add(particle); - scene.tweens.add({ + globalScene.tweens.add({ targets: particle, y: pokeball.y - 10, ease: "Sine.easeOut", duration: 250, onComplete: () => { - scene.tweens.add({ + globalScene.tweens.add({ targets: particle, y: pokeball.y, alpha: 0, @@ -161,13 +161,13 @@ export function addPokeballCaptureStars(scene: BattleScene, pokeball: Phaser.Gam }); const dist = randGauss(25); - scene.tweens.add({ + globalScene.tweens.add({ targets: particle, x: pokeball.x + dist, duration: 500 }); - scene.tweens.add({ + globalScene.tweens.add({ targets: particle, alpha: 0, delay: 425, @@ -193,15 +193,15 @@ export function cos(index: integer, amplitude: integer): number { * @param sparkleSprite the Sprite to play the animation on * @param variant which shiny {@linkcode variant} to play the animation for */ -export function doShinySparkleAnim(scene: BattleScene, sparkleSprite: Phaser.GameObjects.Sprite, variant: Variant) { +export function doShinySparkleAnim(sparkleSprite: Phaser.GameObjects.Sprite, variant: Variant) { const keySuffix = variant ? `_${variant + 1}` : ""; const spriteKey = `shiny${keySuffix}`; const animationKey = `sparkle${keySuffix}`; // Make sure the animation exists, and create it if not - if (!scene.anims.exists(animationKey)) { - const frameNames = scene.anims.generateFrameNames(spriteKey, { suffix: ".png", end: 34 }); - scene.anims.create({ + if (!globalScene.anims.exists(animationKey)) { + const frameNames = globalScene.anims.generateFrameNames(spriteKey, { suffix: ".png", end: 34 }); + globalScene.anims.create({ key: `sparkle${keySuffix}`, frames: frameNames, frameRate: 32, @@ -212,5 +212,5 @@ export function doShinySparkleAnim(scene: BattleScene, sparkleSprite: Phaser.Gam // Play the animation sparkleSprite.play(animationKey); - scene.playSound("se/sparkle"); + globalScene.playSound("se/sparkle"); } diff --git a/src/field/arena.ts b/src/field/arena.ts index 3cbef659d7ab..5ee1d94319c3 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { biomePokemonPools, BiomePoolTier, BiomeTierTrainerPools, biomeTrainerPools, PokemonPools } from "#app/data/balance/biomes"; import { Constructor } from "#app/utils"; import * as Utils from "#app/utils"; @@ -34,7 +34,6 @@ import { ShowAbilityPhase } from "#app/phases/show-ability-phase"; import { WeatherType } from "#enums/weather-type"; export class Arena { - public scene: BattleScene; public biomeType: Biome; public weather: Weather | null; public terrain: Terrain | null; @@ -50,8 +49,7 @@ export class Arena { public readonly eventTarget: EventTarget = new EventTarget(); - constructor(scene: BattleScene, biome: Biome, bgm: string) { - this.scene = scene; + constructor(biome: Biome, bgm: string) { this.biomeType = biome; this.tags = []; this.bgm = bgm; @@ -62,12 +60,12 @@ export class Arena { init() { const biomeKey = getBiomeKey(this.biomeType); - this.scene.arenaPlayer.setBiome(this.biomeType); - this.scene.arenaPlayerTransition.setBiome(this.biomeType); - this.scene.arenaEnemy.setBiome(this.biomeType); - this.scene.arenaNextEnemy.setBiome(this.biomeType); - this.scene.arenaBg.setTexture(`${biomeKey}_bg`); - this.scene.arenaBgTransition.setTexture(`${biomeKey}_bg`); + globalScene.arenaPlayer.setBiome(this.biomeType); + globalScene.arenaPlayerTransition.setBiome(this.biomeType); + globalScene.arenaEnemy.setBiome(this.biomeType); + globalScene.arenaNextEnemy.setBiome(this.biomeType); + globalScene.arenaBg.setTexture(`${biomeKey}_bg`); + globalScene.arenaBgTransition.setTexture(`${biomeKey}_bg`); // Redo this on initialize because during save/load the current wave isn't always // set correctly during construction @@ -86,12 +84,12 @@ export class Arena { } randomSpecies(waveIndex: integer, level: integer, attempt?: integer, luckValue?: integer, isBoss?: boolean): PokemonSpecies { - const overrideSpecies = this.scene.gameMode.getOverrideSpecies(waveIndex); + const overrideSpecies = globalScene.gameMode.getOverrideSpecies(waveIndex); if (overrideSpecies) { return overrideSpecies; } - const isBossSpecies = !!this.scene.getEncounterBossSegments(waveIndex, level) && !!this.pokemonPool[BiomePoolTier.BOSS].length - && (this.biomeType !== Biome.END || this.scene.gameMode.isClassic || this.scene.gameMode.isWaveFinal(waveIndex)); + const isBossSpecies = !!globalScene.getEncounterBossSegments(waveIndex, level) && !!this.pokemonPool[BiomePoolTier.BOSS].length + && (this.biomeType !== Biome.END || globalScene.gameMode.isClassic || globalScene.gameMode.isWaveFinal(waveIndex)); const randVal = isBossSpecies ? 64 : 512; // luck influences encounter rarity let luckModifier = 0; @@ -111,7 +109,7 @@ export class Arena { let ret: PokemonSpecies; let regen = false; if (!tierPool.length) { - ret = this.scene.randomSpecies(waveIndex, level); + ret = globalScene.randomSpecies(waveIndex, level); } else { const entry = tierPool[Utils.randSeedInt(tierPool.length)]; let species: Species; @@ -158,7 +156,7 @@ export class Arena { return this.randomSpecies(waveIndex, level, (attempt || 0) + 1); } - const newSpeciesId = ret.getWildSpeciesForLevel(level, true, isBoss ?? isBossSpecies, this.scene.gameMode); + const newSpeciesId = ret.getWildSpeciesForLevel(level, true, isBoss ?? isBossSpecies, globalScene.gameMode); if (newSpeciesId !== ret.speciesId) { console.log("Replaced", Species[ret.speciesId], "with", Species[newSpeciesId]); ret = getPokemonSpecies(newSpeciesId); @@ -168,7 +166,7 @@ export class Arena { randomTrainerType(waveIndex: integer, isBoss: boolean = false): TrainerType { const isTrainerBoss = !!this.trainerPool[BiomePoolTier.BOSS].length - && (this.scene.gameMode.isTrainerBoss(waveIndex, this.biomeType, this.scene.offsetGym) || isBoss); + && (globalScene.gameMode.isTrainerBoss(waveIndex, this.biomeType, globalScene.offsetGym) || isBoss); console.log(isBoss, this.trainerPool); const tierValue = Utils.randSeedInt(!isTrainerBoss ? 512 : 64); let tier = !isTrainerBoss @@ -243,8 +241,8 @@ export class Arena { */ trySetWeatherOverride(weather: WeatherType): boolean { this.weather = new Weather(weather, 0); - this.scene.unshiftPhase(new CommonAnimPhase(this.scene, undefined, undefined, CommonAnim.SUNNY + (weather - 1))); - this.scene.queueMessage(getWeatherStartMessage(weather)!); // TODO: is this bang correct? + globalScene.unshiftPhase(new CommonAnimPhase(undefined, undefined, CommonAnim.SUNNY + (weather - 1))); + globalScene.queueMessage(getWeatherStartMessage(weather)!); // TODO: is this bang correct? return true; } @@ -269,13 +267,13 @@ export class Arena { this.eventTarget.dispatchEvent(new WeatherChangedEvent(oldWeatherType, this.weather?.weatherType!, this.weather?.turnsLeft!)); // TODO: is this bang correct? if (this.weather) { - this.scene.unshiftPhase(new CommonAnimPhase(this.scene, undefined, undefined, CommonAnim.SUNNY + (weather - 1), true)); - this.scene.queueMessage(getWeatherStartMessage(weather)!); // TODO: is this bang correct? + globalScene.unshiftPhase(new CommonAnimPhase(undefined, undefined, CommonAnim.SUNNY + (weather - 1), true)); + globalScene.queueMessage(getWeatherStartMessage(weather)!); // TODO: is this bang correct? } else { - this.scene.queueMessage(getWeatherClearMessage(oldWeatherType)!); // TODO: is this bang correct? + globalScene.queueMessage(getWeatherClearMessage(oldWeatherType)!); // TODO: is this bang correct? } - this.scene.getField(true).filter(p => p.isOnField()).map(pokemon => { + globalScene.getField(true).filter(p => p.isOnField()).map(pokemon => { pokemon.findAndRemoveTags(t => "weatherTypes" in t && !(t.weatherTypes as WeatherType[]).find(t => t === weather)); applyPostWeatherChangeAbAttrs(PostWeatherChangeAbAttr, pokemon, weather); }); @@ -287,13 +285,13 @@ export class Arena { * Function to trigger all weather based form changes */ triggerWeatherBasedFormChanges(): void { - this.scene.getField(true).forEach( p => { + globalScene.getField(true).forEach( p => { const isCastformWithForecast = (p.hasAbility(Abilities.FORECAST) && p.species.speciesId === Species.CASTFORM); const isCherrimWithFlowerGift = (p.hasAbility(Abilities.FLOWER_GIFT) && p.species.speciesId === Species.CHERRIM); if (isCastformWithForecast || isCherrimWithFlowerGift) { - new ShowAbilityPhase(this.scene, p.getBattlerIndex()); - this.scene.triggerPokemonFormChange(p, SpeciesFormChangeWeatherTrigger); + new ShowAbilityPhase(p.getBattlerIndex()); + globalScene.triggerPokemonFormChange(p, SpeciesFormChangeWeatherTrigger); } }); } @@ -302,13 +300,13 @@ export class Arena { * Function to trigger all weather based form changes back into their normal forms */ triggerWeatherBasedFormChangesToNormal(): void { - this.scene.getField(true).forEach( p => { + globalScene.getField(true).forEach( p => { const isCastformWithForecast = (p.hasAbility(Abilities.FORECAST, false, true) && p.species.speciesId === Species.CASTFORM); const isCherrimWithFlowerGift = (p.hasAbility(Abilities.FLOWER_GIFT, false, true) && p.species.speciesId === Species.CHERRIM); if (isCastformWithForecast || isCherrimWithFlowerGift) { - new ShowAbilityPhase(this.scene, p.getBattlerIndex()); - return this.scene.triggerPokemonFormChange(p, SpeciesFormChangeRevertWeatherFormTrigger); + new ShowAbilityPhase(p.getBattlerIndex()); + return globalScene.triggerPokemonFormChange(p, SpeciesFormChangeRevertWeatherFormTrigger); } }); } @@ -325,14 +323,14 @@ export class Arena { if (this.terrain) { if (!ignoreAnim) { - this.scene.unshiftPhase(new CommonAnimPhase(this.scene, undefined, undefined, CommonAnim.MISTY_TERRAIN + (terrain - 1))); + globalScene.unshiftPhase(new CommonAnimPhase(undefined, undefined, CommonAnim.MISTY_TERRAIN + (terrain - 1))); } - this.scene.queueMessage(getTerrainStartMessage(terrain)!); // TODO: is this bang correct? + globalScene.queueMessage(getTerrainStartMessage(terrain)!); // TODO: is this bang correct? } else { - this.scene.queueMessage(getTerrainClearMessage(oldTerrainType)!); // TODO: is this bang correct? + globalScene.queueMessage(getTerrainClearMessage(oldTerrainType)!); // TODO: is this bang correct? } - this.scene.getField(true).filter(p => p.isOnField()).map(pokemon => { + globalScene.getField(true).filter(p => p.isOnField()).map(pokemon => { pokemon.findAndRemoveTags(t => "terrainTypes" in t && !(t.terrainTypes as TerrainType[]).find(t => t === terrain)); applyPostTerrainChangeAbAttrs(PostTerrainChangeAbAttr, pokemon, terrain); applyAbAttrs(TerrainEventTypeChangeAbAttr, pokemon, null, false); @@ -342,7 +340,7 @@ export class Arena { } public isMoveWeatherCancelled(user: Pokemon, move: Move): boolean { - return !!this.weather && !this.weather.isEffectSuppressed(this.scene) && this.weather.isMoveWeatherCancelled(user, move); + return !!this.weather && !this.weather.isEffectSuppressed() && this.weather.isMoveWeatherCancelled(user, move); } public isMoveTerrainCancelled(user: Pokemon, targets: BattlerIndex[], move: Move): boolean { @@ -355,7 +353,7 @@ export class Arena { getAttackTypeMultiplier(attackType: Type, grounded: boolean): number { let weatherMultiplier = 1; - if (this.weather && !this.weather.isEffectSuppressed(this.scene)) { + if (this.weather && !this.weather.isEffectSuppressed()) { weatherMultiplier = this.weather.getAttackTypeMultiplier(attackType); } @@ -421,7 +419,7 @@ export class Arena { return TimeOfDay.NIGHT; } - const waveCycle = ((this.scene.currentBattle?.waveIndex || 0) + this.scene.waveCycleOffset) % 40; + const waveCycle = ((globalScene.currentBattle?.waveIndex || 0) + globalScene.waveCycleOffset) % 40; if (waveCycle < 15) { return TimeOfDay.DAY; @@ -691,7 +689,7 @@ export class Arena { } preloadBgm(): void { - this.scene.loadBgm(this.bgm); + globalScene.loadBgm(this.bgm); } getBgmLoopPoint(): number { @@ -815,17 +813,17 @@ export class ArenaBase extends Phaser.GameObjects.Container { public base: Phaser.GameObjects.Sprite; public props: Phaser.GameObjects.Sprite[]; - constructor(scene: BattleScene, player: boolean) { - super(scene, 0, 0); + constructor(player: boolean) { + super(globalScene, 0, 0); this.player = player; - this.base = scene.addFieldSprite(0, 0, "plains_a", undefined, 1); + this.base = globalScene.addFieldSprite(0, 0, "plains_a", undefined, 1); this.base.setOrigin(0, 0); this.props = !player ? new Array(3).fill(null).map(() => { - const ret = scene.addFieldSprite(0, 0, "plains_b", undefined, 1); + const ret = globalScene.addFieldSprite(0, 0, "plains_b", undefined, 1); ret.setOrigin(0, 0); ret.setVisible(false); return ret; @@ -841,9 +839,9 @@ export class ArenaBase extends Phaser.GameObjects.Container { this.base.setTexture(baseKey); if (this.base.texture.frameTotal > 1) { - const baseFrameNames = this.scene.anims.generateFrameNames(baseKey, { zeroPad: 4, suffix: ".png", start: 1, end: this.base.texture.frameTotal - 1 }); - if (!(this.scene.anims.exists(baseKey))) { - this.scene.anims.create({ + const baseFrameNames = globalScene.anims.generateFrameNames(baseKey, { zeroPad: 4, suffix: ".png", start: 1, end: this.base.texture.frameTotal - 1 }); + if (!(globalScene.anims.exists(baseKey))) { + globalScene.anims.create({ key: baseKey, frames: baseFrameNames, frameRate: 12, @@ -859,7 +857,7 @@ export class ArenaBase extends Phaser.GameObjects.Container { } if (!this.player) { - (this.scene as BattleScene).executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { this.propValue = propValue === undefined ? hasProps ? Utils.randSeedInt(8) : 0 : propValue; @@ -868,9 +866,9 @@ export class ArenaBase extends Phaser.GameObjects.Container { prop.setTexture(propKey); if (hasProps && prop.texture.frameTotal > 1) { - const propFrameNames = this.scene.anims.generateFrameNames(propKey, { zeroPad: 4, suffix: ".png", start: 1, end: prop.texture.frameTotal - 1 }); - if (!(this.scene.anims.exists(propKey))) { - this.scene.anims.create({ + const propFrameNames = globalScene.anims.generateFrameNames(propKey, { zeroPad: 4, suffix: ".png", start: 1, end: prop.texture.frameTotal - 1 }); + if (!(globalScene.anims.exists(propKey))) { + globalScene.anims.create({ key: propKey, frames: propFrameNames, frameRate: 12, @@ -885,7 +883,7 @@ export class ArenaBase extends Phaser.GameObjects.Container { prop.setVisible(hasProps && !!(this.propValue & (1 << p))); this.add(prop); }); - }, (this.scene as BattleScene).currentBattle?.waveIndex || 0, (this.scene as BattleScene).waveSeed); + }, globalScene.currentBattle?.waveIndex || 0, globalScene.waveSeed); } } } diff --git a/src/field/damage-number-handler.ts b/src/field/damage-number-handler.ts index 4ddcd2d3ee77..e64863b7482f 100644 --- a/src/field/damage-number-handler.ts +++ b/src/field/damage-number-handler.ts @@ -2,6 +2,7 @@ import { TextStyle, addTextObject } from "../ui/text"; import Pokemon, { DamageResult, HitResult } from "./pokemon"; import * as Utils from "../utils"; import { BattlerIndex } from "../battle"; +import { globalScene } from "#app/global-scene"; type TextAndShadowArr = [ string | null, string | null ]; @@ -13,15 +14,13 @@ export default class DamageNumberHandler { } add(target: Pokemon, amount: integer, result: DamageResult | HitResult.HEAL = HitResult.EFFECTIVE, critical: boolean = false): void { - const scene = target.scene; - - if (!scene?.damageNumbersMode) { + if (!globalScene?.damageNumbersMode) { return; } const battlerIndex = target.getBattlerIndex(); const baseScale = target.getSpriteScale() / 6; - const damageNumber = addTextObject(scene, target.x, -(scene.game.canvas.height / 6) + target.y - target.getSprite().height / 2, Utils.formatStat(amount, true), TextStyle.SUMMARY); + const damageNumber = addTextObject(target.x, -(globalScene.game.canvas.height / 6) + target.y - target.getSprite().height / 2, Utils.formatStat(amount, true), TextStyle.SUMMARY); damageNumber.setName("text-damage-number"); damageNumber.setOrigin(0.5, 1); damageNumber.setScale(baseScale); @@ -58,7 +57,7 @@ export default class DamageNumberHandler { } } - scene.fieldUI.add(damageNumber); + globalScene.fieldUI.add(damageNumber); if (!this.damageNumbers.has(battlerIndex)) { this.damageNumbers.set(battlerIndex, []); @@ -71,14 +70,14 @@ export default class DamageNumberHandler { this.damageNumbers.get(battlerIndex)!.push(damageNumber); - if (scene.damageNumbersMode === 1) { - scene.tweens.add({ + if (globalScene.damageNumbersMode === 1) { + globalScene.tweens.add({ targets: damageNumber, duration: Utils.fixedInt(750), alpha: 1, y: "-=32" }); - scene.tweens.add({ + globalScene.tweens.add({ delay: 375, targets: damageNumber, duration: Utils.fixedInt(625), @@ -94,7 +93,7 @@ export default class DamageNumberHandler { damageNumber.setAlpha(0); - scene.tweens.chain({ + globalScene.tweens.chain({ targets: damageNumber, tweens: [ { diff --git a/src/field/mystery-encounter-intro.ts b/src/field/mystery-encounter-intro.ts index b1b85de9b297..3df6af7ea4c8 100644 --- a/src/field/mystery-encounter-intro.ts +++ b/src/field/mystery-encounter-intro.ts @@ -1,12 +1,12 @@ import { GameObjects } from "phaser"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import MysteryEncounter from "#app/data/mystery-encounters/mystery-encounter"; import { Species } from "#enums/species"; import { isNullOrUndefined } from "#app/utils"; import { getSpriteKeysFromSpecies } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils"; -import PlayAnimationConfig = Phaser.Types.Animations.PlayAnimationConfig; import { Variant } from "#app/data/variant"; import { doShinySparkleAnim } from "#app/field/anims"; +import PlayAnimationConfig = Phaser.Types.Animations.PlayAnimationConfig; type KnownFileRoot = | "arenas" @@ -82,8 +82,8 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con public enterFromRight: boolean; private shinySparkleSprites: { sprite: Phaser.GameObjects.Sprite, variant: Variant }[]; - constructor(scene: BattleScene, encounter: MysteryEncounter) { - super(scene, -72, 76); + constructor(encounter: MysteryEncounter) { + super(globalScene, -72, 76); this.encounter = encounter; this.enterFromRight = encounter.enterIntroVisualsFromRight ?? false; // Shallow copy configs to allow visual config updates at runtime without dirtying master copy of Encounter @@ -106,16 +106,16 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con } const getSprite = (spriteKey: string, hasShadow?: boolean, yShadow?: number) => { - const ret = this.scene.addFieldSprite(0, 0, spriteKey); + const ret = globalScene.addFieldSprite(0, 0, spriteKey); ret.setOrigin(0.5, 1); - ret.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow, yShadowOffset: yShadow ?? 0 }); + ret.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow, yShadowOffset: yShadow ?? 0 }); return ret; }; const getItemSprite = (spriteKey: string, hasShadow?: boolean, yShadow?: number) => { - const icon = this.scene.add.sprite(-19, 2, "items", spriteKey); + const icon = globalScene.add.sprite(-19, 2, "items", spriteKey); icon.setOrigin(0.5, 1); - icon.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow, yShadowOffset: yShadow ?? 0 }); + icon.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow, yShadowOffset: yShadow ?? 0 }); return icon; }; @@ -128,7 +128,7 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con const spacingValue = Math.round((maxX - minX) / Math.max(this.spriteConfigs.filter(s => !s.x && !s.y).length, 1)); this.shinySparkleSprites = []; - const shinySparkleSprites = scene.add.container(0, 0); + const shinySparkleSprites = globalScene.add.container(0, 0); this.spriteConfigs?.forEach((config) => { const { spriteKey, isItem, hasShadow, scale, x, y, yShadow, alpha, isPokemon, isShiny, variant } = config; @@ -151,7 +151,7 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con tintSprite.setPipelineData("shiny", true); tintSprite.setPipelineData("variant", variant); // Create Sprite for shiny Sparkle - pokemonShinySparkle = scene.add.sprite(sprite.x, sprite.y, "shiny"); + pokemonShinySparkle = globalScene.add.sprite(sprite.x, sprite.y, "shiny"); pokemonShinySparkle.setOrigin(0.5, 1); pokemonShinySparkle.setVisible(false); this.shinySparkleSprites.push({ sprite: pokemonShinySparkle, variant: variant ?? 0 }); @@ -217,18 +217,18 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con this.spriteConfigs.forEach((config) => { if (config.isPokemon) { - this.scene.loadPokemonAtlas(config.spriteKey, config.fileRoot); + globalScene.loadPokemonAtlas(config.spriteKey, config.fileRoot); if (config.isShiny) { - this.scene.loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant); + globalScene.loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant); } } else if (config.isItem) { - this.scene.loadAtlas("items", ""); + globalScene.loadAtlas("items", ""); } else { - this.scene.loadAtlas(config.spriteKey, config.fileRoot); + globalScene.loadAtlas(config.spriteKey, config.fileRoot); } }); - this.scene.load.once(Phaser.Loader.Events.COMPLETE, () => { + globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => { this.spriteConfigs.every((config) => { if (config.isItem) { return true; @@ -239,11 +239,11 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con // Ignore warnings for missing frames, because there will be a lot console.warn = () => { }; - const frameNames = this.scene.anims.generateFrameNames(config.spriteKey, { zeroPad: 4, suffix: ".png", start: 1, end: 128 }); + const frameNames = globalScene.anims.generateFrameNames(config.spriteKey, { zeroPad: 4, suffix: ".png", start: 1, end: 128 }); console.warn = originalWarn; - if (!(this.scene.anims.exists(config.spriteKey))) { - this.scene.anims.create({ + if (!(globalScene.anims.exists(config.spriteKey))) { + globalScene.anims.create({ key: config.spriteKey, frames: frameNames, frameRate: 10, @@ -257,8 +257,8 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con resolve(); }); - if (!this.scene.load.isLoading()) { - this.scene.load.start(); + if (!globalScene.load.isLoading()) { + globalScene.load.start(); } }); } @@ -337,8 +337,8 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con */ playShinySparkles() { for (const sparkleConfig of this.shinySparkleSprites) { - this.scene.time.delayedCall(500, () => { - doShinySparkleAnim(this.scene, sparkleConfig.sprite, sparkleConfig.variant); + globalScene.time.delayedCall(500, () => { + doShinySparkleAnim(sparkleConfig.sprite, sparkleConfig.variant); }); } } @@ -429,7 +429,7 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con if (duration) { sprite.setAlpha(0); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: sprite, alpha: alpha || 1, duration: duration, @@ -462,7 +462,7 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con */ private untint(sprite, duration: integer, ease?: string): void { if (duration) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: sprite, alpha: 0, duration: duration, @@ -502,10 +502,3 @@ export default class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Con return super.setVisible(value); } } - -/** - * Interface is required so as not to override {@link Phaser.GameObjects.Container.scene} - */ -export default interface MysteryEncounterIntroVisuals { - scene: BattleScene -} diff --git a/src/field/pokemon-sprite-sparkle-handler.ts b/src/field/pokemon-sprite-sparkle-handler.ts index 2c4c295eaa4c..074933f0f00d 100644 --- a/src/field/pokemon-sprite-sparkle-handler.ts +++ b/src/field/pokemon-sprite-sparkle-handler.ts @@ -1,14 +1,14 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import Pokemon from "./pokemon"; import * as Utils from "../utils"; export default class PokemonSpriteSparkleHandler { private sprites: Set; - setup(scene: BattleScene): void { + setup(): void { this.sprites = new Set(); - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: Utils.fixedInt(200), from: 0, to: 1, @@ -37,7 +37,7 @@ export default class PokemonSpriteSparkleHandler { const pixel = texture.manager.getPixel(pixelX, pixelY, texture.key, "__BASE"); if (pixel?.alpha) { const [ xOffset, yOffset ] = [ -s.originX * s.width, -s.originY * s.height ]; - const sparkle = (s.scene as BattleScene).addFieldSprite(((pokemon?.x || 0) + s.x + pixelX * ratioX + xOffset), ((pokemon?.y || 0) + s.y + pixelY * ratioY + yOffset), "tera_sparkle"); + const sparkle = globalScene.addFieldSprite(((pokemon?.x || 0) + s.x + pixelX * ratioX + xOffset), ((pokemon?.y || 0) + s.y + pixelY * ratioY + yOffset), "tera_sparkle"); sparkle.pipelineData["ignoreTimeTint"] = s.pipelineData["ignoreTimeTint"]; sparkle.setName("sprite-tera-sparkle"); sparkle.play("tera_sparkle"); diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index fcfc2ff7536a..56ab87234bd6 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1,5 +1,6 @@ import Phaser from "phaser"; import BattleScene, { AnySound } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Variant, VariantSet, variantColorCache } from "#app/data/variant"; import { variantData } from "#app/data/variant"; import BattleInfo, { PlayerBattleInfo, EnemyBattleInfo } from "#app/ui/battle-info"; @@ -148,8 +149,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { private shinySparkle: Phaser.GameObjects.Sprite; - constructor(scene: BattleScene, x: number, y: number, species: PokemonSpecies, level: integer, abilityIndex?: integer, formIndex?: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData) { - super(scene, x, y); + constructor(x: number, y: number, species: PokemonSpecies, level: integer, abilityIndex?: integer, formIndex?: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData) { + super(globalScene, x, y); if (!species.isObtainable() && this.isPlayer()) { throw `Cannot create a player Pokemon for species '${species.getName(formIndex)}'`; @@ -157,7 +158,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const hiddenAbilityChance = new Utils.IntegerHolder(BASE_HIDDEN_ABILITY_CHANCE); if (!this.hasTrainer()) { - this.scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); + globalScene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); } this.species = species; @@ -235,7 +236,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } if (this.formIndex === undefined) { - this.formIndex = this.scene.getSpeciesFormIndex(species, this.gender, this.nature, this.isPlayer()); + this.formIndex = globalScene.getSpeciesFormIndex(species, this.gender, this.nature, this.isPlayer()); } if (this.shiny === undefined) { @@ -256,15 +257,15 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.friendship = species.baseFriendship; this.metLevel = level; - this.metBiome = scene.currentBattle ? scene.arena.biomeType : -1; + this.metBiome = globalScene.currentBattle ? globalScene.arena.biomeType : -1; this.metSpecies = species.speciesId; - this.metWave = scene.currentBattle ? scene.currentBattle.waveIndex : -1; + this.metWave = globalScene.currentBattle ? globalScene.currentBattle.waveIndex : -1; this.pokerus = false; if (level > 1) { - const fused = new Utils.BooleanHolder(scene.gameMode.isSplicedOnly); + const fused = new Utils.BooleanHolder(globalScene.gameMode.isSplicedOnly); if (!fused.value && !this.isPlayer() && !this.hasTrainer()) { - this.scene.applyModifier(EnemyFusionChanceModifier, false, fused); + globalScene.applyModifier(EnemyFusionChanceModifier, false, fused); } if (fused.value) { @@ -305,12 +306,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.initBattleInfo(); - this.scene.fieldUI.addAt(this.battleInfo, 0); + globalScene.fieldUI.addAt(this.battleInfo, 0); const getSprite = (hasShadow?: boolean) => { - const ret = this.scene.addPokemonSprite(this, 0, 0, `pkmn__${this.isPlayer() ? "back__" : ""}sub`, undefined, true); + const ret = globalScene.addPokemonSprite(this, 0, 0, `pkmn__${this.isPlayer() ? "back__" : ""}sub`, undefined, true); ret.setOrigin(0.5, 1); - ret.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow, teraColor: getTypeRgb(this.getTeraType()) }); + ret.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow, teraColor: getTypeRgb(this.getTeraType()) }); return ret; }; @@ -332,13 +333,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { abstract initBattleInfo(): void; isOnField(): boolean { - if (!this.scene) { + if (!globalScene) { return false; } if (this.switchOutStatus) { return false; } - return this.scene.field.getIndex(this) > -1; + return globalScene.field.getIndex(this) > -1; } /** @@ -366,7 +367,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ public isAllowedInChallenge(): boolean { const challengeAllowed = new Utils.BooleanHolder(true); - applyChallenges(this.scene.gameMode, ChallengeType.POKEMON_IN_BATTLE, this, challengeAllowed); + applyChallenges(globalScene.gameMode, ChallengeType.POKEMON_IN_BATTLE, this, challengeAllowed); return challengeAllowed.value; } @@ -376,7 +377,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns `true` if the pokemon is "active". Returns `false` if there is no active {@linkcode BattleScene} */ public isActive(onField: boolean = false): boolean { - if (!this.scene) { + if (!globalScene) { return false; } return this.isAllowedInBattle() && (!onField || this.isOnField()); @@ -387,7 +388,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ret |= this.gender !== Gender.FEMALE ? DexAttr.MALE : DexAttr.FEMALE; ret |= !this.shiny ? DexAttr.NON_SHINY : DexAttr.SHINY; ret |= this.variant >= 2 ? DexAttr.VARIANT_3 : this.variant === 1 ? DexAttr.VARIANT_2 : DexAttr.DEFAULT_VARIANT; - ret |= this.scene.gameData.getFormAttr(this.formIndex); + ret |= globalScene.gameData.getFormAttr(this.formIndex); return ret; } @@ -418,26 +419,26 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { loadAssets(ignoreOverride: boolean = true): Promise { return new Promise(resolve => { const moveIds = this.getMoveset().map(m => m!.getMove().id); // TODO: is this bang correct? - Promise.allSettled(moveIds.map(m => initMoveAnim(this.scene, m))) + Promise.allSettled(moveIds.map(m => initMoveAnim(m))) .then(() => { - loadMoveAnimAssets(this.scene, moveIds); - this.getSpeciesForm().loadAssets(this.scene, this.getGender() === Gender.FEMALE, this.formIndex, this.shiny, this.variant); + loadMoveAnimAssets(moveIds); + this.getSpeciesForm().loadAssets(this.getGender() === Gender.FEMALE, this.formIndex, this.shiny, this.variant); if (this.isPlayer() || this.getFusionSpeciesForm()) { - this.scene.loadPokemonAtlas(this.getBattleSpriteKey(true, ignoreOverride), this.getBattleSpriteAtlasPath(true, ignoreOverride)); + globalScene.loadPokemonAtlas(this.getBattleSpriteKey(true, ignoreOverride), this.getBattleSpriteAtlasPath(true, ignoreOverride)); } if (this.getFusionSpeciesForm()) { - this.getFusionSpeciesForm().loadAssets(this.scene, this.getFusionGender() === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny, this.fusionVariant); - this.scene.loadPokemonAtlas(this.getFusionBattleSpriteKey(true, ignoreOverride), this.getFusionBattleSpriteAtlasPath(true, ignoreOverride)); + this.getFusionSpeciesForm().loadAssets(this.getFusionGender() === Gender.FEMALE, this.fusionFormIndex, this.fusionShiny, this.fusionVariant); + globalScene.loadPokemonAtlas(this.getFusionBattleSpriteKey(true, ignoreOverride), this.getFusionBattleSpriteAtlasPath(true, ignoreOverride)); } - this.scene.load.once(Phaser.Loader.Events.COMPLETE, () => { + globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => { if (this.isPlayer()) { const originalWarn = console.warn; // Ignore warnings for missing frames, because there will be a lot console.warn = () => {}; - const battleFrameNames = this.scene.anims.generateFrameNames(this.getBattleSpriteKey(), { zeroPad: 4, suffix: ".png", start: 1, end: 400 }); + const battleFrameNames = globalScene.anims.generateFrameNames(this.getBattleSpriteKey(), { zeroPad: 4, suffix: ".png", start: 1, end: 400 }); console.warn = originalWarn; - if (!(this.scene.anims.exists(this.getBattleSpriteKey()))) { - this.scene.anims.create({ + if (!(globalScene.anims.exists(this.getBattleSpriteKey()))) { + globalScene.anims.create({ key: this.getBattleSpriteKey(), frames: battleFrameNames, frameRate: 10, @@ -458,7 +459,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return new Promise(async resolve => { const battleSpritePath = this.getBattleSpriteAtlasPath(isBackSprite, ignoreOverride).replace("variant/", "").replace(/_[1-3]$/, ""); let config = variantData; - const useExpSprite = this.scene.experimentalSprites && this.scene.hasExpSprite(this.getBattleSpriteKey(isBackSprite, ignoreOverride)); + const useExpSprite = globalScene.experimentalSprites && globalScene.hasExpSprite(this.getBattleSpriteKey(isBackSprite, ignoreOverride)); battleSpritePath.split("/").map(p => config ? config = config[p] : null); const variantSet: VariantSet = config as VariantSet; if (variantSet && variantSet[this.variant] === 1) { @@ -479,8 +480,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { updateFusionPaletteAndResolve(); } }); - if (!this.scene.load.isLoading()) { - this.scene.load.start(); + if (!globalScene.load.isLoading()) { + globalScene.load.start(); } }); }); @@ -512,7 +513,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ async populateVariantColorCache(cacheKey: string, useExpSprite: boolean, battleSpritePath: string) { const spritePath = `./images/pokemon/variant/${useExpSprite ? "exp/" : ""}${battleSpritePath}.json`; - return this.scene.cachedFetch(spritePath).then(res => { + return globalScene.cachedFetch(spritePath).then(res => { // Prevent the JSON from processing if it failed to load if (!res.ok) { return this.fallbackVariantColor(cacheKey, res.url, useExpSprite, battleSpritePath, res.status, res.statusText); @@ -667,10 +668,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } getHeldItems(): PokemonHeldItemModifier[] { - if (!this.scene) { + if (!globalScene) { return []; } - return this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === this.id, this.isPlayer()) as PokemonHeldItemModifier[]; + return globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === this.id, this.isPlayer()) as PokemonHeldItemModifier[]; } updateScale(): void { @@ -683,7 +684,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } initShinySparkle(): void { - const shinySparkle = this.scene.addFieldSprite(0, 0, "shiny"); + const shinySparkle = globalScene.addFieldSprite(0, 0, "shiny"); shinySparkle.setVisible(false); shinySparkle.setOrigin(0.5, 1); this.add(shinySparkle); @@ -751,7 +752,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // During the Pokemon's MoveEffect phase, the offset is removed to put the Pokemon "in focus" - const currentPhase = this.scene.getCurrentPhase(); + const currentPhase = globalScene.getCurrentPhase(); if (currentPhase instanceof MoveEffectPhase && currentPhase.getPokemon() === this) { return false; } @@ -796,7 +797,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (subTag?.sprite) { targets.push(subTag.sprite); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: targets, x: (_target, _key, value: number) => value + relX, y: (_target, _key, value: number) => value + relY, @@ -902,8 +903,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { getCritStage(source: Pokemon, move: Move): number { const critStage = new Utils.IntegerHolder(0); applyMoveAttrs(HighCritAttr, source, this, move, critStage); - this.scene.applyModifiers(CritBoosterModifier, source.isPlayer(), source, critStage); - this.scene.applyModifiers(TempCritBoosterModifier, source.isPlayer(), critStage); + globalScene.applyModifiers(CritBoosterModifier, source.isPlayer(), source, critStage); + globalScene.applyModifiers(TempCritBoosterModifier, source.isPlayer(), critStage); const bonusCrit = new Utils.BooleanHolder(false); //@ts-ignore if (applyAbAttrs(BonusCritAbAttr, source, null, false, bonusCrit)) { // TODO: resolve ts-ignore. This is a promise. Checking a promise is bogus. @@ -939,11 +940,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ getEffectiveStat(stat: EffectiveStat, opponent?: Pokemon, move?: Move, ignoreAbility: boolean = false, ignoreOppAbility: boolean = false, isCritical: boolean = false, simulated: boolean = true): integer { const statValue = new Utils.NumberHolder(this.getStat(stat, false)); - this.scene.applyModifiers(StatBoosterModifier, this.isPlayer(), this, stat, statValue); + globalScene.applyModifiers(StatBoosterModifier, this.isPlayer(), this, stat, statValue); // The Ruin abilities here are never ignored, but they reveal themselves on summon anyway const fieldApplied = new Utils.BooleanHolder(false); - for (const pokemon of this.scene.getField(true)) { + for (const pokemon of globalScene.getField(true)) { applyFieldStatMultiplierAbAttrs(FieldMultiplyStatAbAttr, pokemon, stat, statValue, this, fieldApplied, simulated); if (fieldApplied.value) { break; @@ -962,23 +963,23 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } break; case Stat.DEF: - if (this.isOfType(Type.ICE) && this.scene.arena.weather?.weatherType === WeatherType.SNOW) { + if (this.isOfType(Type.ICE) && globalScene.arena.weather?.weatherType === WeatherType.SNOW) { ret *= 1.5; } break; case Stat.SPATK: break; case Stat.SPDEF: - if (this.isOfType(Type.ROCK) && this.scene.arena.weather?.weatherType === WeatherType.SANDSTORM) { + if (this.isOfType(Type.ROCK) && globalScene.arena.weather?.weatherType === WeatherType.SANDSTORM) { ret *= 1.5; } break; case Stat.SPD: const side = this.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - if (this.scene.arena.getTagOnSide(ArenaTagType.TAILWIND, side)) { + if (globalScene.arena.getTagOnSide(ArenaTagType.TAILWIND, side)) { ret *= 2; } - if (this.scene.arena.getTagOnSide(ArenaTagType.GRASS_WATER_PLEDGE, side)) { + if (globalScene.arena.getTagOnSide(ArenaTagType.GRASS_WATER_PLEDGE, side)) { ret >>= 2; } @@ -1014,7 +1015,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const statHolder = new Utils.IntegerHolder(Math.floor(((2 * baseStats[s] + this.ivs[s]) * this.level) * 0.01)); if (s === Stat.HP) { statHolder.value = statHolder.value + this.level + 10; - this.scene.applyModifier(PokemonIncrementingStatModifier, this.isPlayer(), this, s, statHolder); + globalScene.applyModifier(PokemonIncrementingStatModifier, this.isPlayer(), this, s, statHolder); if (this.hasAbility(Abilities.WONDER_GUARD, false, true)) { statHolder.value = 1; } @@ -1029,11 +1030,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } else { statHolder.value += 5; const natureStatMultiplier = new Utils.NumberHolder(getNatureStatMultiplier(this.getNature(), s)); - this.scene.applyModifier(PokemonNatureWeightModifier, this.isPlayer(), this, natureStatMultiplier); + globalScene.applyModifier(PokemonNatureWeightModifier, this.isPlayer(), this, natureStatMultiplier); if (natureStatMultiplier.value !== 1) { statHolder.value = Math.max(Math[natureStatMultiplier.value > 1 ? "ceil" : "floor"](statHolder.value * natureStatMultiplier.value), 1); } - this.scene.applyModifier(PokemonIncrementingStatModifier, this.isPlayer(), this, s, statHolder); + globalScene.applyModifier(PokemonIncrementingStatModifier, this.isPlayer(), this, s, statHolder); } statHolder.value = Phaser.Math.Clamp(statHolder.value, 1, Number.MAX_SAFE_INTEGER); @@ -1045,21 +1046,21 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { calculateBaseStats(): number[] { const baseStats = this.getSpeciesForm(true).baseStats.slice(0); // Shuckle Juice - this.scene.applyModifiers(PokemonBaseStatTotalModifier, this.isPlayer(), this, baseStats); + globalScene.applyModifiers(PokemonBaseStatTotalModifier, this.isPlayer(), this, baseStats); // Old Gateau - this.scene.applyModifiers(PokemonBaseStatFlatModifier, this.isPlayer(), this, baseStats); + globalScene.applyModifiers(PokemonBaseStatFlatModifier, this.isPlayer(), this, baseStats); if (this.isFusion()) { const fusionBaseStats = this.getFusionSpeciesForm(true).baseStats; for (const s of PERMANENT_STATS) { baseStats[s] = Math.ceil((baseStats[s] + fusionBaseStats[s]) / 2); } - } else if (this.scene.gameMode.isSplicedOnly) { + } else if (globalScene.gameMode.isSplicedOnly) { for (const s of PERMANENT_STATS) { baseStats[s] = Math.ceil(baseStats[s] / 2); } } // Vitamins - this.scene.applyModifiers(BaseStatModifier, this.isPlayer(), this, baseStats); + globalScene.applyModifiers(BaseStatModifier, this.isPlayer(), this, baseStats); return baseStats; } @@ -1193,7 +1194,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const species = this.metSpecies in speciesEggMoves ? this.metSpecies : this.getSpeciesForm(true).getRootSpeciesId(true); if (species in speciesEggMoves) { for (let i = 0; i < 4; i++) { - if (this.scene.gameData.starterData[species].eggMoves & (1 << i)) { + if (globalScene.gameData.starterData[species].eggMoves & (1 << i)) { moves.push(speciesEggMoves[species][i]); } } @@ -1212,7 +1213,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ public getLearnableLevelMoves(): Moves[] { let levelMoves = this.getLevelMoves(1, true, false, true).map(lm => lm[1]); - if (this.metBiome === -1 && !this.scene.gameMode.isFreshStartChallenge() && !this.scene.gameMode.isDaily) { + if (this.metBiome === -1 && !globalScene.gameMode.isFreshStartChallenge() && !globalScene.gameMode.isDaily) { levelMoves = this.getUnlockedEggMoves().concat(levelMoves); } if (Array.isArray(this.usedTMs) && this.usedTMs.length > 0) { @@ -1431,7 +1432,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // Classic Final boss and Endless Minor/Major bosses do not have passive - const { currentBattle, gameMode } = this.scene; + const { currentBattle, gameMode } = globalScene; const waveIndex = currentBattle?.waveIndex; if (this instanceof EnemyPokemon && (currentBattle?.battleSpec === BattleSpec.FINAL_BOSS || @@ -1458,7 +1459,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (this.isFusion() && ability.hasAttr(NoFusionAbilityAbAttr)) { return false; } - const arena = this.scene?.arena; + const arena = globalScene?.arena; if (arena.ignoreAbilities && arena.ignoringEffectSource !== this.getBattlerIndex() && ability.isIgnorable) { return false; } @@ -1467,7 +1468,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } if (this.isOnField() && !ability.hasAttr(SuppressFieldAbilitiesAbAttr)) { const suppressed = new Utils.BooleanHolder(false); - this.scene.getField(true).filter(p => p !== this).map(p => { + globalScene.getField(true).filter(p => p !== this).map(p => { if (p.getAbility().hasAttr(SuppressFieldAbilitiesAbAttr) && p.canApplyAbility()) { p.getAbility().getAttrs(SuppressFieldAbilitiesAbAttr).map(a => a.apply(this, false, false, suppressed, [ ability ])); } @@ -1541,20 +1542,19 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } /** - * @returns The tera-formed type of the pokemon, or {@linkcode Type.UNKNOWN} if not present + * @returns the pokemon's current tera {@linkcode Type}, or `Type.UNKNOWN` if the pokemon is not terastallized */ public getTeraType(): Type { - // this.scene can be undefined for a fainted mon in doubles - if (this.scene !== undefined) { - const teraModifier = this.scene.findModifier(m => m instanceof TerastallizeModifier - && m.pokemonId === this.id && !!m.getBattlesLeft(), this.isPlayer()) as TerastallizeModifier; - // return teraType - if (teraModifier) { - return teraModifier.teraType; - } + // I don't think this should be possible anymore, please report if you encounter this. --NightKev + if (globalScene === undefined) { + console.warn("Pokemon.getTeraType(): Global scene is not defined!"); + return Type.UNKNOWN; } - // if scene is undefined, or if teraModifier is considered false, then return unknown type - return Type.UNKNOWN; + const teraModifier = globalScene.findModifier(m => + m instanceof TerastallizeModifier + && m.pokemonId === this.id + && m.getBattlesLeft() > 0, this.isPlayer()) as TerastallizeModifier; + return teraModifier?.teraType ?? Type.UNKNOWN; } public isTerastallized(): boolean { @@ -1575,7 +1575,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ public isTrapped(trappedAbMessages: string[] = [], simulated: boolean = true): boolean { const commandedTag = this.getTag(BattlerTagType.COMMANDED); - if (commandedTag?.getSourcePokemon(this.scene)?.isActive(true)) { + if (commandedTag?.getSourcePokemon()?.isActive(true)) { return true; } @@ -1588,7 +1588,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * Contains opposing Pokemon (Enemy/Player Pokemon) depending on perspective * Afterwards, it filters out Pokemon that have been switched out of the field so trapped abilities/moves do not trigger */ - const opposingFieldUnfiltered = this.isPlayer() ? this.scene.getEnemyField() : this.scene.getPlayerField(); + const opposingFieldUnfiltered = this.isPlayer() ? globalScene.getEnemyField() : globalScene.getPlayerField(); const opposingField = opposingFieldUnfiltered.filter(enemyPkm => enemyPkm.switchOutStatus === false); opposingField.forEach((opponent) => @@ -1596,7 +1596,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { ); const side = this.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - return (trappedByAbility.value || !!this.getTag(TrappedTag) || !!this.scene.arena.getTagOnSide(ArenaTagType.FAIRY_LOCK, side)); + return (trappedByAbility.value || !!this.getTag(TrappedTag) || !!globalScene.arena.getTagOnSide(ArenaTagType.FAIRY_LOCK, side)); } /** @@ -1612,7 +1612,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { applyMoveAttrs(VariableMoveTypeAttr, this, null, move, moveTypeHolder); applyPreAttackAbAttrs(MoveTypeChangeAbAttr, this, null, move, simulated, moveTypeHolder); - this.scene.arena.applyTags(ArenaTagType.ION_DELUGE, simulated, moveTypeHolder); + globalScene.arena.applyTags(ArenaTagType.ION_DELUGE, simulated, moveTypeHolder); if (this.getTag(BattlerTagType.ELECTRIFIED)) { moveTypeHolder.value = Type.ELECTRIC; } @@ -1664,7 +1664,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } if (!cancelledHolder.value) { - const defendingSidePlayField = this.isPlayer() ? this.scene.getPlayerField() : this.scene.getEnemyField(); + const defendingSidePlayField = this.isPlayer() ? globalScene.getPlayerField() : globalScene.getEnemyField(); defendingSidePlayField.forEach((p) => applyPreDefendAbAttrs(FieldPriorityMoveImmunityAbAttr, p, source, move, cancelledHolder)); } } @@ -1703,7 +1703,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.isTerastallized() ? 2 : 1; } const types = this.getTypes(true, true); - const arena = this.scene.arena; + const arena = globalScene.arena; // Handle flying v ground type immunity without removing flying type so effective types are still effective // Related to https://github.com/pagefaultgames/pokerogue/issues/524 @@ -1716,7 +1716,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { let multiplier = types.map(defType => { const multiplier = new Utils.NumberHolder(getTypeDamageMultiplier(moveType, defType)); - applyChallenges(this.scene.gameMode, ChallengeType.TYPE_EFFECTIVENESS, multiplier); + applyChallenges(globalScene.gameMode, ChallengeType.TYPE_EFFECTIVENESS, multiplier); if (move) { applyMoveAttrs(VariableMoveTypeChartAttr, null, this, move, multiplier, defType); } @@ -1742,12 +1742,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }).reduce((acc, cur) => acc * cur, 1) as TypeDamageMultiplier; const typeMultiplierAgainstFlying = new Utils.NumberHolder(getTypeDamageMultiplier(moveType, Type.FLYING)); - applyChallenges(this.scene.gameMode, ChallengeType.TYPE_EFFECTIVENESS, typeMultiplierAgainstFlying); + applyChallenges(globalScene.gameMode, ChallengeType.TYPE_EFFECTIVENESS, typeMultiplierAgainstFlying); // Handle strong winds lowering effectiveness of types super effective against pure flying - if (!ignoreStrongWinds && arena.weather?.weatherType === WeatherType.STRONG_WINDS && !arena.weather.isEffectSuppressed(this.scene) && this.isOfType(Type.FLYING) && typeMultiplierAgainstFlying.value === 2) { + if (!ignoreStrongWinds && arena.weather?.weatherType === WeatherType.STRONG_WINDS && !arena.weather.isEffectSuppressed() && this.isOfType(Type.FLYING) && typeMultiplierAgainstFlying.value === 2) { multiplier /= 2; if (!simulated) { - this.scene.queueMessage(i18next.t("weather:strongWindsEffectMessage")); + globalScene.queueMessage(i18next.t("weather:strongWindsEffectMessage")); } } return multiplier as TypeDamageMultiplier; @@ -1944,23 +1944,23 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ trySetShiny(thresholdOverride?: integer): boolean { // Shiny Pokemon should not spawn in the end biome in endless - if (this.scene.gameMode.isEndless && this.scene.arena.biomeType === Biome.END) { + if (globalScene.gameMode.isEndless && globalScene.arena.biomeType === Biome.END) { return false; } const rand1 = (this.id & 0xFFFF0000) >>> 16; const rand2 = (this.id & 0x0000FFFF); - const E = this.scene.gameData.trainerId ^ this.scene.gameData.secretId; + const E = globalScene.gameData.trainerId ^ globalScene.gameData.secretId; const F = rand1 ^ rand2; const shinyThreshold = new Utils.IntegerHolder(BASE_SHINY_CHANCE); if (thresholdOverride === undefined) { - if (this.scene.eventManager.isEventActive()) { - shinyThreshold.value *= this.scene.eventManager.getShinyMultiplier(); + if (globalScene.eventManager.isEventActive()) { + shinyThreshold.value *= globalScene.eventManager.getShinyMultiplier(); } if (!this.hasTrainer()) { - this.scene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); + globalScene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); } } else { shinyThreshold.value = thresholdOverride; @@ -1991,11 +1991,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (thresholdOverride !== undefined && applyModifiersToOverride) { shinyThreshold.value = thresholdOverride; } - if (this.scene.eventManager.isEventActive()) { - shinyThreshold.value *= this.scene.eventManager.getShinyMultiplier(); + if (globalScene.eventManager.isEventActive()) { + shinyThreshold.value *= globalScene.eventManager.getShinyMultiplier(); } if (!this.hasTrainer()) { - this.scene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); + globalScene.applyModifiers(ShinyRateBoosterModifier, true, shinyThreshold); } } else { shinyThreshold.value = thresholdOverride; @@ -2033,9 +2033,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return 0; } const rand = new Utils.NumberHolder(0); - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { rand.value = Utils.randSeedInt(10); - }, this.id, this.scene.waveSeed); + }, this.id, globalScene.waveSeed); if (rand.value >= SHINY_VARIANT_CHANCE) { return 0; // 6/10 } else if (rand.value >= SHINY_EPIC_CHANCE) { @@ -2048,7 +2048,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { public generateFusionSpecies(forStarter?: boolean): void { const hiddenAbilityChance = new Utils.NumberHolder(BASE_HIDDEN_ABILITY_CHANCE); if (!this.hasTrainer()) { - this.scene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); + globalScene.applyModifiers(HiddenAbilityRateBoosterModifier, true, hiddenAbilityChance); } const hasHiddenAbility = !Utils.randSeedInt(hiddenAbilityChance.value); @@ -2075,7 +2075,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { fusionOverride = getPokemonSpecies(Overrides.OPP_FUSION_SPECIES_OVERRIDE); } - this.fusionSpecies = fusionOverride ?? this.scene.randomSpecies(this.scene.currentBattle?.waveIndex || 0, this.level, false, filter, true); + this.fusionSpecies = fusionOverride ?? globalScene.randomSpecies(globalScene.currentBattle?.waveIndex || 0, this.level, false, filter, true); this.fusionAbilityIndex = (this.fusionSpecies.abilityHidden && hasHiddenAbility ? 2 : this.fusionSpecies.ability2 !== this.fusionSpecies.ability1 ? randAbilityIndex : 0); this.fusionShiny = this.shiny; this.fusionVariant = this.variant; @@ -2091,7 +2091,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - this.fusionFormIndex = this.scene.getSpeciesFormIndex(this.fusionSpecies, this.fusionGender, this.getNature(), true); + this.fusionFormIndex = globalScene.getSpeciesFormIndex(this.fusionSpecies, this.fusionGender, this.getNature(), true); this.fusionLuck = this.luck; this.generateName(); @@ -2292,8 +2292,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // Trigger FormChange, except for enemy Pokemon during Mystery Encounters, to avoid crashes - if (this.isPlayer() || !this.scene.currentBattle?.isBattleMysteryEncounter() || !this.scene.currentBattle?.mysteryEncounter) { - this.scene.triggerPokemonFormChange(this, SpeciesFormChangeMoveLearnedTrigger); + if (this.isPlayer() || !globalScene.currentBattle?.isBattleMysteryEncounter() || !globalScene.currentBattle?.mysteryEncounter) { + globalScene.triggerPokemonFormChange(this, SpeciesFormChangeMoveLearnedTrigger); } } @@ -2306,19 +2306,19 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { showInfo(): void { if (!this.battleInfo.visible) { - const otherBattleInfo = this.scene.fieldUI.getAll().slice(0, 4).filter(ui => ui instanceof BattleInfo && ((ui as BattleInfo) instanceof PlayerBattleInfo) === this.isPlayer()).find(() => true); + const otherBattleInfo = globalScene.fieldUI.getAll().slice(0, 4).filter(ui => ui instanceof BattleInfo && ((ui as BattleInfo) instanceof PlayerBattleInfo) === this.isPlayer()).find(() => true); if (!otherBattleInfo || !this.getFieldIndex()) { - this.scene.fieldUI.sendToBack(this.battleInfo); - this.scene.sendTextToBack(); // Push the top right text objects behind everything else + globalScene.fieldUI.sendToBack(this.battleInfo); + globalScene.sendTextToBack(); // Push the top right text objects behind everything else } else { - this.scene.fieldUI.moveAbove(this.battleInfo, otherBattleInfo); + globalScene.fieldUI.moveAbove(this.battleInfo, otherBattleInfo); } this.battleInfo.setX(this.battleInfo.x + (this.isPlayer() ? 150 : !this.isBoss() ? -150 : -198)); this.battleInfo.setVisible(true); if (this.isPlayer()) { this.battleInfo.expMaskRect.x += 150; } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.battleInfo, this.battleInfo.expMaskRect ], x: this.isPlayer() ? "-=150" : `+=${!this.isBoss() ? 150 : 246}`, duration: 1000, @@ -2330,7 +2330,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { hideInfo(): Promise { return new Promise(resolve => { if (this.battleInfo && this.battleInfo.visible) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.battleInfo, this.battleInfo.expMaskRect ], x: this.isPlayer() ? "+=150" : `-=${!this.isBoss() ? 150 : 246}`, duration: 500, @@ -2379,7 +2379,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } addExp(exp: integer) { - const maxExpLevel = this.scene.getMaxExpLevel(); + const maxExpLevel = globalScene.getMaxExpLevel(); const initialExp = this.exp; this.exp += exp; while (this.level < maxExpLevel && this.exp >= getLevelTotalExp(this.level + 1, this.species.growthRate)) { @@ -2410,7 +2410,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } getOpponents(): Pokemon[] { - return ((this.isPlayer() ? this.scene.getEnemyField() : this.scene.getPlayerField()) as Pokemon[]).filter(p => p.isActive()); + return ((this.isPlayer() ? globalScene.getEnemyField() : globalScene.getPlayerField()) as Pokemon[]).filter(p => p.isActive()); } getOpponentDescriptor(): string { @@ -2422,7 +2422,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } getAlly(): Pokemon { - return (this.isPlayer() ? this.scene.getPlayerField() : this.scene.getEnemyField())[this.getFieldIndex() ? 0 : 1]; + return (this.isPlayer() ? globalScene.getPlayerField() : globalScene.getEnemyField())[this.getFieldIndex() ? 0 : 1]; } /** @@ -2431,7 +2431,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns An array of Pokémon on the allied field. */ getAlliedField(): Pokemon[] { - return this instanceof PlayerPokemon ? this.scene.getPlayerField() : this.scene.getEnemyField(); + return this instanceof PlayerPokemon ? globalScene.getPlayerField() : globalScene.getEnemyField(); } /** @@ -2474,7 +2474,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (!ignoreStatStage.value) { const statStageMultiplier = new Utils.NumberHolder(Math.max(2, 2 + statStage.value) / Math.max(2, 2 - statStage.value)); - this.scene.applyModifiers(TempStatStageBoosterModifier, this.isPlayer(), stat, statStageMultiplier); + globalScene.applyModifiers(TempStatStageBoosterModifier, this.isPlayer(), stat, statStageMultiplier); return Math.min(statStageMultiplier.value, 4); } return 1; @@ -2506,7 +2506,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { applyAbAttrs(IgnoreOpponentStatStagesAbAttr, this, null, false, Stat.EVA, ignoreEvaStatStage); applyMoveAttrs(IgnoreOpponentStatStagesAttr, this, target, sourceMove, ignoreEvaStatStage); - this.scene.applyModifiers(TempStatStageBoosterModifier, this.isPlayer(), Stat.ACC, userAccStage); + globalScene.applyModifiers(TempStatStageBoosterModifier, this.isPlayer(), Stat.ACC, userAccStage); userAccStage.value = ignoreAccStatStage.value ? 0 : Math.min(userAccStage.value, 6); targetEvaStage.value = ignoreEvaStatStage.value ? 0 : targetEvaStage.value; @@ -2618,7 +2618,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const isPhysical = moveCategory === MoveCategory.PHYSICAL; /** Combined damage multiplier from field effects such as weather, terrain, etc. */ - const arenaAttackTypeMultiplier = new Utils.NumberHolder(this.scene.arena.getAttackTypeMultiplier(moveType, source.isGrounded())); + const arenaAttackTypeMultiplier = new Utils.NumberHolder(globalScene.arena.getAttackTypeMultiplier(moveType, source.isGrounded())); applyMoveAttrs(IgnoreWeatherTypeDebuffAttr, source, this, move, arenaAttackTypeMultiplier); const isTypeImmune = (typeMultiplier * arenaAttackTypeMultiplier.value) === 0; @@ -2636,7 +2636,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { applyMoveAttrs(FixedDamageAttr, source, this, move, fixedDamage); if (fixedDamage.value) { const multiLensMultiplier = new Utils.NumberHolder(1); - source.scene.applyModifiers(PokemonMultiHitModifier, source.isPlayer(), source, move.id, null, multiLensMultiplier); + globalScene.applyModifiers(PokemonMultiHitModifier, source.isPlayer(), source, move.id, null, multiLensMultiplier); fixedDamage.value = Utils.toDmgValue(fixedDamage.value * multiLensMultiplier.value); return { @@ -2670,7 +2670,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { /** Multiplier for moves enhanced by Multi-Lens and/or Parental Bond */ const multiStrikeEnhancementMultiplier = new Utils.NumberHolder(1); - source.scene.applyModifiers(PokemonMultiHitModifier, source.isPlayer(), source, move.id, null, multiStrikeEnhancementMultiplier); + globalScene.applyModifiers(PokemonMultiHitModifier, source.isPlayer(), source, move.id, null, multiStrikeEnhancementMultiplier); if (!ignoreSourceAbility) { applyPreAttackAbAttrs(AddSecondStrikeAbAttr, source, this, move, simulated, null, multiStrikeEnhancementMultiplier); } @@ -2726,7 +2726,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { /** Reduces damage if this Pokemon has a relevant screen (e.g. Light Screen for special attacks) */ const screenMultiplier = new Utils.NumberHolder(1); - this.scene.arena.applyTagsForSide(WeakenMoveScreenTag, defendingSide, simulated, source, moveCategory, screenMultiplier); + globalScene.arena.applyTagsForSide(WeakenMoveScreenTag, defendingSide, simulated, source, moveCategory, screenMultiplier); /** * For each {@linkcode HitsTagAttr} the move has, doubles the damage of the move if: @@ -2742,7 +2742,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }); /** Halves damage if this Pokemon is grounded in Misty Terrain against a Dragon-type attack */ - const mistyTerrainMultiplier = (this.scene.arena.terrain?.terrainType === TerrainType.MISTY && this.isGrounded() && moveType === Type.DRAGON) + const mistyTerrainMultiplier = (globalScene.arena.terrain?.terrainType === TerrainType.MISTY && this.isGrounded() && moveType === Type.DRAGON) ? 0.5 : 1; @@ -2769,10 +2769,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { /** Apply the enemy's Damage and Resistance tokens */ if (!source.isPlayer()) { - this.scene.applyModifiers(EnemyDamageBoosterModifier, false, damage); + globalScene.applyModifiers(EnemyDamageBoosterModifier, false, damage); } if (!this.isPlayer()) { - this.scene.applyModifiers(EnemyDamageReducerModifier, false, damage); + globalScene.applyModifiers(EnemyDamageReducerModifier, false, damage); } @@ -2781,7 +2781,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { applyPreDefendAbAttrs(ReceivedMoveDamageMultiplierAbAttr, this, source, move, cancelled, simulated, damage); /** Additionally apply friend guard damage reduction if ally has it. */ - if (this.scene.currentBattle.double && this.getAlly()?.isActive(true)) { + if (globalScene.currentBattle.double && this.getAlly()?.isActive(true)) { applyPreDefendAbAttrs(AlliedFieldDamageReductionAbAttr, this.getAlly(), source, move, cancelled, simulated, damage); } } @@ -2829,7 +2829,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const typeMultiplier = this.getMoveEffectiveness(source, move, false, false, cancelled); if (!cancelled.value && typeMultiplier === 0) { - this.scene.queueMessage(i18next.t("battle:hitResultNoEffect", { pokemonName: getPokemonNameWithAffix(this) })); + globalScene.queueMessage(i18next.t("battle:hitResultNoEffect", { pokemonName: getPokemonNameWithAffix(this) })); } return (typeMultiplier === 0) ? HitResult.NO_EFFECT : HitResult.STATUS; } else { @@ -2843,10 +2843,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { isCritical = true; } else { const critChance = [ 24, 8, 2, 1 ][Math.max(0, Math.min(this.getCritStage(source, move), 3))]; - isCritical = critChance === 1 || !this.scene.randBattleSeedInt(critChance); + isCritical = critChance === 1 || !globalScene.randBattleSeedInt(critChance); } - const noCritTag = this.scene.arena.getTagOnSide(NoCritTag, defendingSide); + const noCritTag = globalScene.arena.getTagOnSide(NoCritTag, defendingSide); const blockCrit = new Utils.BooleanHolder(false); applyAbAttrs(BlockCritAbAttr, this, null, false, blockCrit); if (noCritTag || blockCrit.value || Overrides.NEVER_CRIT_OVERRIDE) { @@ -2865,9 +2865,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (!cancelled) { if (result === HitResult.IMMUNE) { - this.scene.queueMessage(i18next.t("battle:hitResultImmune", { pokemonName: getPokemonNameWithAffix(this) })); + globalScene.queueMessage(i18next.t("battle:hitResultImmune", { pokemonName: getPokemonNameWithAffix(this) })); } else { - this.scene.queueMessage(i18next.t("battle:hitResultNoEffect", { pokemonName: getPokemonNameWithAffix(this) })); + globalScene.queueMessage(i18next.t("battle:hitResultNoEffect", { pokemonName: getPokemonNameWithAffix(this) })); } } return result; @@ -2888,7 +2888,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { substitute.hp -= dmg; } if (!this.isPlayer() && dmg >= this.hp) { - this.scene.applyModifiers(EnemyEndureChanceModifier, false, this); + globalScene.applyModifiers(EnemyEndureChanceModifier, false, this); } /** @@ -2899,9 +2899,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (damage > 0) { if (source.isPlayer()) { - this.scene.validateAchvs(DamageAchv, new Utils.NumberHolder(damage)); - if (damage > this.scene.gameData.gameStats.highestDamage) { - this.scene.gameData.gameStats.highestDamage = damage; + globalScene.validateAchvs(DamageAchv, new Utils.NumberHolder(damage)); + if (damage > globalScene.gameData.gameStats.highestDamage) { + globalScene.gameData.gameStats.highestDamage = damage; } } source.turnData.totalDamageDealt += damage; @@ -2912,34 +2912,34 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const attackResult = { move: move.id, result: result as DamageResult, damage: damage, critical: isCritical, sourceId: source.id, sourceBattlerIndex: source.getBattlerIndex() }; this.turnData.attacksReceived.unshift(attackResult); if (source.isPlayer() && !this.isPlayer()) { - this.scene.applyModifiers(DamageMoneyRewardModifier, true, source, new Utils.NumberHolder(damage)); + globalScene.applyModifiers(DamageMoneyRewardModifier, true, source, new Utils.NumberHolder(damage)); } } } if (isCritical) { - this.scene.queueMessage(i18next.t("battle:hitResultCriticalHit")); + globalScene.queueMessage(i18next.t("battle:hitResultCriticalHit")); } // want to include is.Fainted() in case multi hit move ends early, still want to render message if (source.turnData.hitsLeft === 1 || this.isFainted()) { switch (result) { case HitResult.SUPER_EFFECTIVE: - this.scene.queueMessage(i18next.t("battle:hitResultSuperEffective")); + globalScene.queueMessage(i18next.t("battle:hitResultSuperEffective")); break; case HitResult.NOT_VERY_EFFECTIVE: - this.scene.queueMessage(i18next.t("battle:hitResultNotVeryEffective")); + globalScene.queueMessage(i18next.t("battle:hitResultNotVeryEffective")); break; case HitResult.ONE_HIT_KO: - this.scene.queueMessage(i18next.t("battle:hitResultOneHitKO")); + globalScene.queueMessage(i18next.t("battle:hitResultOneHitKO")); break; } } if (this.isFainted()) { // set splice index here, so future scene queues happen before FaintedPhase - this.scene.setPhaseQueueSplice(); - this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), isOneHitKo, destinyTag, grudgeTag, source)); + globalScene.setPhaseQueueSplice(); + globalScene.unshiftPhase(new FaintPhase(this.getBattlerIndex(), isOneHitKo, destinyTag, grudgeTag, source)); this.destroySubstitute(); this.lapseTag(BattlerTagType.COMMANDED); @@ -2973,7 +2973,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { surviveDamage.value = this.lapseTag(BattlerTagType.ENDURE_TOKEN); } if (!surviveDamage.value) { - this.scene.applyModifiers(SurviveDamageModifier, this.isPlayer(), this, surviveDamage); + globalScene.applyModifiers(SurviveDamageModifier, this.isPlayer(), this, surviveDamage); } if (surviveDamage.value) { damage = this.hp - 1; @@ -2990,8 +2990,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * * Once the MoveEffectPhase is over (and calls it's .end() function, shiftPhase() will reset the PhaseQueueSplice via clearPhaseQueueSplice() ) */ - this.scene.setPhaseQueueSplice(); - this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), preventEndure)); + globalScene.setPhaseQueueSplice(); + globalScene.unshiftPhase(new FaintPhase(this.getBattlerIndex(), preventEndure)); this.destroySubstitute(); this.lapseTag(BattlerTagType.COMMANDED); this.resetSummonData(); @@ -3010,8 +3010,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns integer of damage done */ damageAndUpdate(damage: number, result?: DamageResult, critical: boolean = false, ignoreSegments: boolean = false, preventEndure: boolean = false, ignoreFaintPhase: boolean = false, source?: Pokemon): number { - const damagePhase = new DamageAnimPhase(this.scene, this.getBattlerIndex(), damage, result as DamageResult, critical); - this.scene.unshiftPhase(damagePhase); + const damagePhase = new DamageAnimPhase(this.getBattlerIndex(), damage, result as DamageResult, critical); + globalScene.unshiftPhase(damagePhase); if (this.switchOutStatus && source) { damage = 0; } @@ -3186,7 +3186,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { for (const s of BATTLE_STATS) { const sourceStage = source.getStatStage(s); if ((this instanceof PlayerPokemon) && (sourceStage === 6)) { - this.scene.validateAchv(achvs.TRANSFER_MAX_STAT_STAGE); + globalScene.validateAchv(achvs.TRANSFER_MAX_STAT_STAGE); } this.setStatStage(s, sourceStage); } @@ -3265,7 +3265,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (!this.isOnField()) { return; } - turnMove.turn = this.scene.currentBattle?.turn; + turnMove.turn = globalScene.currentBattle?.turn; this.getMoveHistory().push(turnMove); } @@ -3295,7 +3295,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @param {Pokemon} target If specified, this only cancels subsequent strikes against the given target */ stopMultiHit(target?: Pokemon): void { - const effectPhase = this.scene.getCurrentPhase(); + const effectPhase = globalScene.getCurrentPhase(); if (effectPhase instanceof MoveEffectPhase && effectPhase.getUserPokemon() === this) { effectPhase.stopMultiHit(target); } @@ -3309,28 +3309,28 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (this.abilityIndex >= abilityCount) {// Shouldn't happen this.abilityIndex = abilityCount - 1; } - this.scene.gameData.setPokemonSeen(this, false); + globalScene.gameData.setPokemonSeen(this, false); this.setScale(this.getSpriteScale()); this.loadAssets().then(() => { this.calculateStats(); - this.scene.updateModifiers(this.isPlayer(), true); - Promise.all([ this.updateInfo(), this.scene.updateFieldScale() ]).then(() => resolve()); + globalScene.updateModifiers(this.isPlayer(), true); + Promise.all([ this.updateInfo(), globalScene.updateFieldScale() ]).then(() => resolve()); }); }); } cry(soundConfig?: Phaser.Types.Sound.SoundConfig, sceneOverride?: BattleScene): AnySound { - const scene = sceneOverride || this.scene; - const cry = this.getSpeciesForm().cry(scene, soundConfig); + const scene = sceneOverride ?? globalScene; // TODO: is `sceneOverride` needed? + const cry = this.getSpeciesForm().cry(soundConfig); let duration = cry.totalDuration * 1000; if (this.fusionSpecies && this.getSpeciesForm() !== this.getFusionSpeciesForm()) { - let fusionCry = this.getFusionSpeciesForm().cry(scene, soundConfig, true); + let fusionCry = this.getFusionSpeciesForm().cry(soundConfig, true); duration = Math.min(duration, fusionCry.totalDuration * 1000); fusionCry.destroy(); scene.time.delayedCall(Utils.fixedInt(Math.ceil(duration * 0.4)), () => { try { SoundFade.fadeOut(scene, cry, Utils.fixedInt(Math.ceil(duration * 0.2))); - fusionCry = this.getFusionSpeciesForm().cry(scene, Object.assign({ seek: Math.max(fusionCry.totalDuration * 0.4, 0) }, soundConfig)); + fusionCry = this.getFusionSpeciesForm().cry(Object.assign({ seek: Math.max(fusionCry.totalDuration * 0.4, 0) }, soundConfig)); SoundFade.fadeIn(scene, fusionCry, Utils.fixedInt(Math.ceil(duration * 0.2)), scene.masterVolume * scene.fieldVolume, 0); } catch (err) { console.error(err); @@ -3348,13 +3348,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const key = this.species.getCryKey(this.formIndex); let rate = 0.85; - const cry = this.scene.playSound(key, { rate: rate }) as AnySound; - if (!cry || this.scene.fieldVolume === 0) { + const cry = globalScene.playSound(key, { rate: rate }) as AnySound; + if (!cry || globalScene.fieldVolume === 0) { return callback(); } const sprite = this.getSprite(); const tintSprite = this.getTintSprite(); - const delay = Math.max(this.scene.sound.get(key).totalDuration * 50, 25); + const delay = Math.max(globalScene.sound.get(key).totalDuration * 50, 25); let frameProgress = 0; let frameThreshold: number; @@ -3362,7 +3362,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { sprite.anims.pause(); tintSprite?.anims.pause(); - let faintCryTimer : Phaser.Time.TimerEvent | null = this.scene.time.addEvent({ + let faintCryTimer : Phaser.Time.TimerEvent | null = globalScene.time.addEvent({ delay: Utils.fixedInt(delay), repeat: -1, callback: () => { @@ -3389,8 +3389,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }); // Failsafe - this.scene.time.delayedCall(Utils.fixedInt(3000), () => { - if (!faintCryTimer || !this.scene) { + globalScene.time.delayedCall(Utils.fixedInt(3000), () => { + if (!faintCryTimer || !globalScene) { return; } if (cry?.isPlaying) { @@ -3407,14 +3407,14 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const key = this.species.getCryKey(this.formIndex); let i = 0; let rate = 0.85; - const cry = this.scene.playSound(key, { rate: rate }) as AnySound; + const cry = globalScene.playSound(key, { rate: rate }) as AnySound; const sprite = this.getSprite(); const tintSprite = this.getTintSprite(); let duration = cry.totalDuration * 1000; const fusionCryKey = this.fusionSpecies!.getCryKey(this.fusionFormIndex); - let fusionCry = this.scene.playSound(fusionCryKey, { rate: rate }) as AnySound; - if (!cry || !fusionCry || this.scene.fieldVolume === 0) { + let fusionCry = globalScene.playSound(fusionCryKey, { rate: rate }) as AnySound; + if (!cry || !fusionCry || globalScene.fieldVolume === 0) { return callback(); } fusionCry.stop(); @@ -3443,7 +3443,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { sprite.anims.pause(); tintSprite?.anims.pause(); - let faintCryTimer: Phaser.Time.TimerEvent | null = this.scene.time.addEvent({ + let faintCryTimer: Phaser.Time.TimerEvent | null = globalScene.time.addEvent({ delay: Utils.fixedInt(delay), repeat: -1, callback: () => { @@ -3458,9 +3458,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { frameProgress -= frameThreshold; } if (i === transitionIndex && fusionCryKey) { - SoundFade.fadeOut(this.scene, cry, Utils.fixedInt(Math.ceil((duration / rate) * 0.2))); - fusionCry = this.scene.playSound(fusionCryKey, Object.assign({ seek: Math.max(fusionCry.totalDuration * 0.4, 0), rate: rate })); - SoundFade.fadeIn(this.scene, fusionCry, Utils.fixedInt(Math.ceil((duration / rate) * 0.2)), this.scene.masterVolume * this.scene.fieldVolume, 0); + SoundFade.fadeOut(globalScene, cry, Utils.fixedInt(Math.ceil((duration / rate) * 0.2))); + fusionCry = globalScene.playSound(fusionCryKey, Object.assign({ seek: Math.max(fusionCry.totalDuration * 0.4, 0), rate: rate })); + SoundFade.fadeIn(globalScene, fusionCry, Utils.fixedInt(Math.ceil((duration / rate) * 0.2)), globalScene.masterVolume * globalScene.fieldVolume, 0); } rate *= 0.99; if (cry && !cry.pendingRemove) { @@ -3480,8 +3480,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }); // Failsafe - this.scene.time.delayedCall(Utils.fixedInt(3000), () => { - if (!faintCryTimer || !this.scene) { + globalScene.time.delayedCall(Utils.fixedInt(3000), () => { + if (!faintCryTimer || !globalScene) { return; } if (cry?.isPlaying) { @@ -3515,7 +3515,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (overrideStatus ? this.status?.effect === effect : this.status) { return false; } - if (this.isGrounded() && (!ignoreField && this.scene.arena.terrain?.terrainType === TerrainType.MISTY)) { + if (this.isGrounded() && (!ignoreField && globalScene.arena.terrain?.terrainType === TerrainType.MISTY)) { return false; } } @@ -3560,12 +3560,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } break; case StatusEffect.SLEEP: - if (this.isGrounded() && this.scene.arena.terrain?.terrainType === TerrainType.ELECTRIC) { + if (this.isGrounded() && globalScene.arena.terrain?.terrainType === TerrainType.ELECTRIC) { return false; } break; case StatusEffect.FREEZE: - if (this.isOfType(Type.ICE) || (!ignoreField && (this.scene?.arena?.weather?.weatherType && [ WeatherType.SUNNY, WeatherType.HARSH_SUN ].includes(this.scene.arena.weather.weatherType)))) { + if (this.isOfType(Type.ICE) || (!ignoreField && (globalScene?.arena?.weather?.weatherType && [ WeatherType.SUNNY, WeatherType.HARSH_SUN ].includes(globalScene.arena.weather.weatherType)))) { return false; } break; @@ -3603,7 +3603,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } if (asPhase) { - this.scene.unshiftPhase(new ObtainStatusEffectPhase(this.scene, this.getBattlerIndex(), effect, turnsRemaining, sourceText, sourcePokemon)); + globalScene.unshiftPhase(new ObtainStatusEffectPhase(this.getBattlerIndex(), effect, turnsRemaining, sourceText, sourcePokemon)); return true; } @@ -3635,7 +3635,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.status = new Status(effect, 0, sleepTurnsRemaining?.value); if (effect !== StatusEffect.FAINT) { - this.scene.triggerPokemonFormChange(this, SpeciesFormChangeStatusEffectTrigger, true); + globalScene.triggerPokemonFormChange(this, SpeciesFormChangeStatusEffectTrigger, true); applyPostSetStatusAbAttrs(PostSetStatusAbAttr, this, effect, sourcePokemon); } @@ -3677,7 +3677,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ isSafeguarded(attacker: Pokemon): boolean { const defendingSide = this.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - if (this.scene.arena.getTagOnSide(ArenaTagType.SAFEGUARD, defendingSide)) { + if (globalScene.arena.getTagOnSide(ArenaTagType.SAFEGUARD, defendingSide)) { const bypassed = new Utils.BooleanHolder(false); if (attacker) { applyAbAttrs(InfiltratorAbAttr, attacker, null, false, bypassed); @@ -3710,13 +3710,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } // If this Pokemon has a Substitute when loading in, play an animation to add its sprite if (this.getTag(SubstituteTag)) { - this.scene.triggerPokemonBattleAnim(this, PokemonAnimType.SUBSTITUTE_ADD); + globalScene.triggerPokemonBattleAnim(this, PokemonAnimType.SUBSTITUTE_ADD); this.getTag(SubstituteTag)!.sourceInFocus = false; } // If this Pokemon has Commander and Dondozo as an active ally, hide this Pokemon's sprite. if (this.hasAbilityWithAttr(CommanderAbAttr) - && this.scene.currentBattle.double + && globalScene.currentBattle.double && this.getAlly()?.species.speciesId === Species.DONDOZO) { this.setVisible(false); } @@ -3734,8 +3734,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (this.getTag(BattlerTagType.SEEDED)) { this.lapseTag(BattlerTagType.SEEDED); } - if (this.scene) { - this.scene.triggerPokemonFormChange(this, SpeciesFormChangePostMoveTrigger, true); + if (globalScene) { + globalScene.triggerPokemonFormChange(this, SpeciesFormChangePostMoveTrigger, true); } } @@ -3749,7 +3749,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } setFrameRate(frameRate: integer) { - this.scene.anims.get(this.getBattleSpriteKey()).frameRate = frameRate; + globalScene.anims.get(this.getBattleSpriteKey()).frameRate = frameRate; try { this.getSprite().play(this.getBattleSpriteKey()); } catch (err: unknown) { @@ -3770,7 +3770,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (duration) { tintSprite?.setAlpha(0); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: tintSprite, alpha: alpha || 1, duration: duration, @@ -3785,7 +3785,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const tintSprite = this.getTintSprite(); if (duration) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: tintSprite, alpha: 0, duration: duration, @@ -3824,7 +3824,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { sparkle(): void { if (this.shinySparkle) { - doShinySparkleAnim(this.scene, this.shinySparkle, this.variant); + doShinySparkleAnim(this.shinySparkle, this.variant); } } @@ -3845,10 +3845,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const fusionSpriteKey = fusionSpeciesForm.getSpriteKey(this.getFusionGender(ignoreOveride) === Gender.FEMALE, fusionSpeciesForm.formIndex, this.fusionShiny, this.fusionVariant); const fusionBackSpriteKey = fusionSpeciesForm.getSpriteKey(this.getFusionGender(ignoreOveride) === Gender.FEMALE, fusionSpeciesForm.formIndex, this.fusionShiny, this.fusionVariant).replace("pkmn__", "pkmn__back__"); - const sourceTexture = this.scene.textures.get(spriteKey); - const sourceBackTexture = this.scene.textures.get(backSpriteKey); - const fusionTexture = this.scene.textures.get(fusionSpriteKey); - const fusionBackTexture = this.scene.textures.get(fusionBackSpriteKey); + const sourceTexture = globalScene.textures.get(spriteKey); + const sourceBackTexture = globalScene.textures.get(backSpriteKey); + const fusionTexture = globalScene.textures.get(fusionSpriteKey); + const fusionBackTexture = globalScene.textures.get(fusionBackSpriteKey); const [ sourceFrame, sourceBackFrame, fusionFrame, fusionBackFrame ] = [ sourceTexture, sourceBackTexture, fusionTexture, fusionBackTexture ].map(texture => texture.frames[texture.firstFrame]); const [ sourceImage, sourceBackImage, fusionImage, fusionBackImage ] = [ sourceTexture, sourceBackTexture, fusionTexture, fusionBackTexture ].map(i => i.getSourceImage() as HTMLImageElement); @@ -3950,7 +3950,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const originalRandom = Math.random; Math.random = () => Phaser.Math.RND.realInRange(0, 1); - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { paletteColors = QuantizerCelebi.quantize(pixelColors, 4); fusionPaletteColors = QuantizerCelebi.quantize(fusionPixelColors, 4); }, 0, "This result should not vary"); @@ -4071,10 +4071,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } /** - * Generates a random number using the current battle's seed, or the global seed if `this.scene.currentBattle` is falsy + * Generates a random number using the current battle's seed, or the global seed if `globalScene.currentBattle` is falsy * * This calls either {@linkcode BattleScene.randBattleSeedInt}({@linkcode range}, {@linkcode min}) in `src/battle-scene.ts` - * which calls {@linkcode Battle.randSeedInt}(`scene`, {@linkcode range}, {@linkcode min}) in `src/battle.ts` + * which calls {@linkcode Battle.randSeedInt}({@linkcode range}, {@linkcode min}) in `src/battle.ts` * which calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts`, * or it directly calls {@linkcode Utils.randSeedInt randSeedInt}({@linkcode range}, {@linkcode min}) in `src/utils.ts` if there is no current battle * @@ -4083,13 +4083,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @returns A random integer between {@linkcode min} and ({@linkcode min} + {@linkcode range} - 1) */ randSeedInt(range: integer, min: integer = 0): integer { - return this.scene.currentBattle - ? this.scene.randBattleSeedInt(range, min) + return globalScene.currentBattle + ? globalScene.randBattleSeedInt(range, min) : Utils.randSeedInt(range, min); } /** - * Generates a random number using the current battle's seed, or the global seed if `this.scene.currentBattle` is falsy + * Generates a random number using the current battle's seed, or the global seed if `globalScene.currentBattle` is falsy * @param min The minimum integer to generate * @param max The maximum integer to generate * @returns a random integer between {@linkcode min} and {@linkcode max} inclusive @@ -4115,9 +4115,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (hideInfo) { this.hideInfo(); } - this.scene.field.remove(this); + globalScene.field.remove(this); this.setSwitchOutStatus(true); - this.scene.triggerPokemonFormChange(this, SpeciesFormChangeActiveTrigger, true); + globalScene.triggerPokemonFormChange(this, SpeciesFormChangeActiveTrigger, true); } destroy(): void { @@ -4171,7 +4171,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (heldItem.pokemonId === -1 || heldItem.pokemonId === this.id) { heldItem.stackCount--; if (heldItem.stackCount <= 0) { - this.scene.removeModifier(heldItem, !this.isPlayer()); + globalScene.removeModifier(heldItem, !this.isPlayer()); } if (forBattle) { applyPostItemLostAbAttrs(PostItemLostAbAttr, this, false); @@ -4183,15 +4183,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } -export default interface Pokemon { - scene: BattleScene -} - export class PlayerPokemon extends Pokemon { public compatibleTms: Moves[]; - constructor(scene: BattleScene, species: PokemonSpecies, level: integer, abilityIndex?: integer, formIndex?: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData) { - super(scene, 106, 148, species, level, abilityIndex, formIndex, gender, shiny, variant, ivs, nature, dataSource); + constructor(species: PokemonSpecies, level: integer, abilityIndex?: integer, formIndex?: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData) { + super(106, 148, species, level, abilityIndex, formIndex, gender, shiny, variant, ivs, nature, dataSource); if (Overrides.STATUS_OVERRIDE) { this.status = new Status(Overrides.STATUS_OVERRIDE, 0, 4); @@ -4209,7 +4205,7 @@ export class PlayerPokemon extends Pokemon { } if (!dataSource) { - if (this.scene.gameMode.isDaily) { + if (globalScene.gameMode.isDaily) { this.generateAndPopulateMoveset(); } else { this.moveset = []; @@ -4219,7 +4215,7 @@ export class PlayerPokemon extends Pokemon { } initBattleInfo(): void { - this.battleInfo = new PlayerBattleInfo(this.scene); + this.battleInfo = new PlayerBattleInfo(); this.battleInfo.initInfo(this); } @@ -4236,7 +4232,7 @@ export class PlayerPokemon extends Pokemon { } getFieldIndex(): integer { - return this.scene.getPlayerField().indexOf(this); + return globalScene.getPlayerField().indexOf(this); } getBattlerIndex(): BattlerIndex { @@ -4272,7 +4268,7 @@ export class PlayerPokemon extends Pokemon { } tryPopulateMoveset(moveset: StarterMoveset): boolean { - if (!this.getSpeciesForm().validateStarterMoveset(moveset, this.scene.gameData.starterData[this.species.getRootSpeciesId()].eggMoves)) { + if (!this.getSpeciesForm().validateStarterMoveset(moveset, globalScene.gameData.starterData[this.species.getRootSpeciesId()].eggMoves)) { return false; } @@ -4292,11 +4288,11 @@ export class PlayerPokemon extends Pokemon { return new Promise(resolve => { this.leaveField(switchType === SwitchType.SWITCH); - this.scene.ui.setMode(Mode.PARTY, PartyUiMode.FAINT_SWITCH, this.getFieldIndex(), (slotIndex: integer, option: PartyOption) => { - if (slotIndex >= this.scene.currentBattle.getBattlerCount() && slotIndex < 6) { - this.scene.prependToPhase(new SwitchSummonPhase(this.scene, switchType, this.getFieldIndex(), slotIndex, false), MoveEndPhase); + globalScene.ui.setMode(Mode.PARTY, PartyUiMode.FAINT_SWITCH, this.getFieldIndex(), (slotIndex: integer, option: PartyOption) => { + if (slotIndex >= globalScene.currentBattle.getBattlerCount() && slotIndex < 6) { + globalScene.prependToPhase(new SwitchSummonPhase(switchType, this.getFieldIndex(), slotIndex, false), MoveEndPhase); } - this.scene.ui.setMode(Mode.MESSAGE).then(resolve); + globalScene.ui.setMode(Mode.MESSAGE).then(resolve); }, PartyUiHandler.FilterNonFainted); }); } @@ -4306,28 +4302,28 @@ export class PlayerPokemon extends Pokemon { const starterSpeciesId = this.species.getRootSpeciesId(); const fusionStarterSpeciesId = this.isFusion() && this.fusionSpecies ? this.fusionSpecies.getRootSpeciesId() : 0; const starterData = [ - this.scene.gameData.starterData[starterSpeciesId], - fusionStarterSpeciesId ? this.scene.gameData.starterData[fusionStarterSpeciesId] : null + globalScene.gameData.starterData[starterSpeciesId], + fusionStarterSpeciesId ? globalScene.gameData.starterData[fusionStarterSpeciesId] : null ].filter(d => !!d); const amount = new Utils.NumberHolder(friendship); - this.scene.applyModifier(PokemonFriendshipBoosterModifier, true, this, amount); + globalScene.applyModifier(PokemonFriendshipBoosterModifier, true, this, amount); let candyFriendshipMultiplier = CLASSIC_CANDY_FRIENDSHIP_MULTIPLIER; - if (this.scene.eventManager.isEventActive()) { - candyFriendshipMultiplier *= this.scene.eventManager.getFriendshipMultiplier(); + if (globalScene.eventManager.isEventActive()) { + candyFriendshipMultiplier *= globalScene.eventManager.getFriendshipMultiplier(); } - const starterAmount = new Utils.NumberHolder(Math.floor(amount.value * (this.scene.gameMode.isClassic ? candyFriendshipMultiplier : 1) / (fusionStarterSpeciesId ? 2 : 1))); + const starterAmount = new Utils.NumberHolder(Math.floor(amount.value * (globalScene.gameMode.isClassic ? candyFriendshipMultiplier : 1) / (fusionStarterSpeciesId ? 2 : 1))); // Add friendship to this PlayerPokemon this.friendship = Math.min(this.friendship + amount.value, 255); if (this.friendship === 255) { - this.scene.validateAchv(achvs.MAX_FRIENDSHIP); + globalScene.validateAchv(achvs.MAX_FRIENDSHIP); } // Add to candy progress for this mon's starter species and its fused species (if it has one) starterData.forEach((sd: StarterDataEntry, i: number) => { const speciesId = !i ? starterSpeciesId : fusionStarterSpeciesId as Species; sd.friendship = (sd.friendship || 0) + starterAmount.value; if (sd.friendship >= getStarterValueFriendshipCap(speciesStarterCosts[speciesId])) { - this.scene.gameData.addStarterCandy(getPokemonSpecies(speciesId), 1); + globalScene.gameData.addStarterCandy(getPokemonSpecies(speciesId), 1); sd.friendship = 0; } }); @@ -4343,9 +4339,9 @@ export class PlayerPokemon extends Pokemon { */ revivalBlessing(): Promise { return new Promise(resolve => { - this.scene.ui.setMode(Mode.PARTY, PartyUiMode.REVIVAL_BLESSING, this.getFieldIndex(), (slotIndex:integer, option: PartyOption) => { + globalScene.ui.setMode(Mode.PARTY, PartyUiMode.REVIVAL_BLESSING, this.getFieldIndex(), (slotIndex:integer, option: PartyOption) => { if (slotIndex >= 0 && slotIndex < 6) { - const pokemon = this.scene.getPlayerParty()[slotIndex]; + const pokemon = globalScene.getPlayerParty()[slotIndex]; if (!pokemon || !pokemon.isFainted()) { resolve(); } @@ -4353,23 +4349,23 @@ export class PlayerPokemon extends Pokemon { pokemon.resetTurnData(); pokemon.resetStatus(); pokemon.heal(Math.min(Utils.toDmgValue(0.5 * pokemon.getMaxHp()), pokemon.getMaxHp())); - this.scene.queueMessage(i18next.t("moveTriggers:revivalBlessing", { pokemonName: pokemon.name }), 0, true); + globalScene.queueMessage(i18next.t("moveTriggers:revivalBlessing", { pokemonName: pokemon.name }), 0, true); - if (this.scene.currentBattle.double && this.scene.getPlayerParty().length > 1) { + if (globalScene.currentBattle.double && globalScene.getPlayerParty().length > 1) { const allyPokemon = this.getAlly(); if (slotIndex <= 1) { // Revived ally pokemon - this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, SwitchType.SWITCH, pokemon.getFieldIndex(), slotIndex, false, true)); - this.scene.unshiftPhase(new ToggleDoublePositionPhase(this.scene, true)); + globalScene.unshiftPhase(new SwitchSummonPhase(SwitchType.SWITCH, pokemon.getFieldIndex(), slotIndex, false, true)); + globalScene.unshiftPhase(new ToggleDoublePositionPhase(true)); } else if (allyPokemon.isFainted()) { // Revived party pokemon, and ally pokemon is fainted - this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, SwitchType.SWITCH, allyPokemon.getFieldIndex(), slotIndex, false, true)); - this.scene.unshiftPhase(new ToggleDoublePositionPhase(this.scene, true)); + globalScene.unshiftPhase(new SwitchSummonPhase(SwitchType.SWITCH, allyPokemon.getFieldIndex(), slotIndex, false, true)); + globalScene.unshiftPhase(new ToggleDoublePositionPhase(true)); } } } - this.scene.ui.setMode(Mode.MESSAGE).then(() => resolve()); + globalScene.ui.setMode(Mode.MESSAGE).then(() => resolve()); }, PartyUiHandler.FilterFainted); }); } @@ -4387,12 +4383,12 @@ export class PlayerPokemon extends Pokemon { const originalFusionFormIndex = this.fusionFormIndex; this.fusionSpecies = evolutionSpecies; this.fusionFormIndex = evolution.evoFormKey !== null ? Math.max(evolutionSpecies.forms.findIndex(f => f.formKey === evolution.evoFormKey), 0) : this.fusionFormIndex; - ret = this.scene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); + ret = globalScene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); this.fusionSpecies = originalFusionSpecies; this.fusionFormIndex = originalFusionFormIndex; } else { const formIndex = evolution.evoFormKey !== null && !isFusion ? Math.max(evolutionSpecies.forms.findIndex(f => f.formKey === evolution.evoFormKey), 0) : this.formIndex; - ret = this.scene.addPlayerPokemon(!isFusion ? evolutionSpecies : this.species, this.level, this.abilityIndex, formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); + ret = globalScene.addPlayerPokemon(!isFusion ? evolutionSpecies : this.species, this.level, this.abilityIndex, formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); } ret.loadAssets().then(() => resolve(ret)); }); @@ -4458,13 +4454,13 @@ export class PlayerPokemon extends Pokemon { if (preEvolution.speciesId === Species.GIMMIGHOUL) { const evotracker = this.getHeldItems().filter(m => m instanceof EvoTrackerModifier)[0] ?? null; if (evotracker) { - this.scene.removeModifier(evotracker); + globalScene.removeModifier(evotracker); } } - if (!this.scene.gameMode.isDaily || this.metBiome > -1) { - this.scene.gameData.updateSpeciesDexIvs(this.species.speciesId, this.ivs); - this.scene.gameData.setPokemonSeen(this, false); - this.scene.gameData.setPokemonCaught(this, false).then(() => updateAndResolve()); + if (!globalScene.gameMode.isDaily || this.metBiome > -1) { + globalScene.gameData.updateSpeciesDexIvs(this.species.speciesId, this.ivs); + globalScene.gameData.setPokemonSeen(this, false); + globalScene.gameData.setPokemonCaught(this, false).then(() => updateAndResolve()); } else { updateAndResolve(); } @@ -4479,7 +4475,7 @@ export class PlayerPokemon extends Pokemon { const newEvolution = pokemonEvolutions[evoSpecies.speciesId][1]; if (newEvolution.condition?.predicate(this)) { - const newPokemon = this.scene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, undefined, this.shiny, this.variant, this.ivs, this.nature); + const newPokemon = globalScene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, undefined, this.shiny, this.variant, this.ivs, this.nature); newPokemon.passive = this.passive; newPokemon.moveset = this.moveset.slice(); newPokemon.moveset = this.copyMoveset(); @@ -4497,16 +4493,16 @@ export class PlayerPokemon extends Pokemon { newPokemon.fusionLuck = this.fusionLuck; newPokemon.usedTMs = this.usedTMs; - this.scene.getPlayerParty().push(newPokemon); + globalScene.getPlayerParty().push(newPokemon); newPokemon.evolve((!isFusion ? newEvolution : new FusionSpeciesFormEvolution(this.id, newEvolution)), evoSpecies); - const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const modifiers = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === this.id, true) as PokemonHeldItemModifier[]; modifiers.forEach(m => { const clonedModifier = m.clone() as PokemonHeldItemModifier; clonedModifier.pokemonId = newPokemon.id; - this.scene.addModifier(clonedModifier, true); + globalScene.addModifier(clonedModifier, true); }); - this.scene.updateModifiers(true); + globalScene.updateModifiers(true); } } } @@ -4514,7 +4510,7 @@ export class PlayerPokemon extends Pokemon { getPossibleForm(formChange: SpeciesFormChange): Promise { return new Promise(resolve => { const formIndex = Math.max(this.species.forms.findIndex(f => f.formKey === formChange.formKey), 0); - const ret = this.scene.addPlayerPokemon(this.species, this.level, this.abilityIndex, formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); + const ret = globalScene.addPlayerPokemon(this.species, this.level, this.abilityIndex, formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); ret.loadAssets().then(() => resolve(ret)); }); } @@ -4553,13 +4549,13 @@ export class PlayerPokemon extends Pokemon { const updateAndResolve = () => { this.loadAssets().then(() => { this.calculateStats(); - this.scene.updateModifiers(true, true); + globalScene.updateModifiers(true, true); this.updateInfo(true).then(() => resolve()); }); }; - if (!this.scene.gameMode.isDaily || this.metBiome > -1) { - this.scene.gameData.setPokemonSeen(this, false); - this.scene.gameData.setPokemonCaught(this, false).then(() => updateAndResolve()); + if (!globalScene.gameMode.isDaily || this.metBiome > -1) { + globalScene.gameData.setPokemonSeen(this, false); + globalScene.gameData.setPokemonCaught(this, false).then(() => updateAndResolve()); } else { updateAndResolve(); } @@ -4589,8 +4585,8 @@ export class PlayerPokemon extends Pokemon { this.pauseEvolutions = true; } - this.scene.validateAchv(achvs.SPLICE); - this.scene.gameData.gameStats.pokemonFused++; + globalScene.validateAchv(achvs.SPLICE); + globalScene.gameData.gameStats.pokemonFused++; // Store the average HP% that each Pokemon has const maxHp = this.getMaxHp(); @@ -4613,23 +4609,23 @@ export class PlayerPokemon extends Pokemon { this.generateCompatibleTms(); this.updateInfo(true); - const fusedPartyMemberIndex = this.scene.getPlayerParty().indexOf(pokemon); - let partyMemberIndex = this.scene.getPlayerParty().indexOf(this); + const fusedPartyMemberIndex = globalScene.getPlayerParty().indexOf(pokemon); + let partyMemberIndex = globalScene.getPlayerParty().indexOf(this); if (partyMemberIndex > fusedPartyMemberIndex) { partyMemberIndex--; } - const fusedPartyMemberHeldModifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const fusedPartyMemberHeldModifiers = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id, true) as PokemonHeldItemModifier[]; const transferModifiers: Promise[] = []; for (const modifier of fusedPartyMemberHeldModifiers) { - transferModifiers.push(this.scene.tryTransferHeldItemModifier(modifier, this, false, modifier.getStackCount(), true, true, false)); + transferModifiers.push(globalScene.tryTransferHeldItemModifier(modifier, this, false, modifier.getStackCount(), true, true, false)); } Promise.allSettled(transferModifiers).then(() => { - this.scene.updateModifiers(true, true).then(() => { - this.scene.removePartyMemberModifiers(fusedPartyMemberIndex); - this.scene.getPlayerParty().splice(fusedPartyMemberIndex, 1)[0]; - const newPartyMemberIndex = this.scene.getPlayerParty().indexOf(this); - pokemon.getMoveset(true).map((m: PokemonMove) => this.scene.unshiftPhase(new LearnMovePhase(this.scene, newPartyMemberIndex, m.getMove().id))); + globalScene.updateModifiers(true, true).then(() => { + globalScene.removePartyMemberModifiers(fusedPartyMemberIndex); + globalScene.getPlayerParty().splice(fusedPartyMemberIndex, 1)[0]; + const newPartyMemberIndex = globalScene.getPlayerParty().indexOf(this); + pokemon.getMoveset(true).map((m: PokemonMove) => globalScene.unshiftPhase(new LearnMovePhase(newPartyMemberIndex, m.getMove().id))); pokemon.destroy(); this.updateFusionPalette(); resolve(); @@ -4669,8 +4665,8 @@ export class EnemyPokemon extends Pokemon { /** To indicate if the instance was populated with a dataSource -> e.g. loaded & populated from session data */ public readonly isPopulatedFromDataSource: boolean; - constructor(scene: BattleScene, species: PokemonSpecies, level: integer, trainerSlot: TrainerSlot, boss: boolean, shinyLock: boolean = false, dataSource?: PokemonData) { - super(scene, 236, 84, species, level, dataSource?.abilityIndex, dataSource?.formIndex, dataSource?.gender, + constructor(species: PokemonSpecies, level: integer, trainerSlot: TrainerSlot, boss: boolean, shinyLock: boolean = false, dataSource?: PokemonData) { + super(236, 84, species, level, dataSource?.abilityIndex, dataSource?.formIndex, dataSource?.gender, (!shinyLock && dataSource) ? dataSource.shiny : false, (!shinyLock && dataSource) ? dataSource.variant : undefined, undefined, dataSource ? dataSource.nature : undefined, dataSource); @@ -4737,7 +4733,7 @@ export class EnemyPokemon extends Pokemon { initBattleInfo(): void { if (!this.battleInfo) { - this.battleInfo = new EnemyBattleInfo(this.scene); + this.battleInfo = new EnemyBattleInfo(); this.battleInfo.updateBossSegments(this); this.battleInfo.initInfo(this); } else { @@ -4754,7 +4750,7 @@ export class EnemyPokemon extends Pokemon { */ setBoss(boss: boolean = true, bossSegments: integer = 0): void { if (boss) { - this.bossSegments = bossSegments || this.scene.getEncounterBossSegments(this.scene.currentBattle.waveIndex, this.level, this.species, true); + this.bossSegments = bossSegments || globalScene.getEncounterBossSegments(globalScene.currentBattle.waveIndex, this.level, this.species, true); this.bossSegmentIndex = this.bossSegments - 1; } else { this.bossSegments = 0; @@ -4786,7 +4782,7 @@ export class EnemyPokemon extends Pokemon { new PokemonMove(Moves.FLAMETHROWER), new PokemonMove(Moves.COSMIC_POWER) ]; - if (this.scene.gameMode.hasChallenge(Challenges.INVERSE_BATTLE)) { + if (globalScene.gameMode.hasChallenge(Challenges.INVERSE_BATTLE)) { this.moveset[2] = new PokemonMove(Moves.THUNDERBOLT); } break; @@ -4833,7 +4829,7 @@ export class EnemyPokemon extends Pokemon { } switch (this.aiType) { case AiType.RANDOM: // No enemy should spawn with this AI type in-game - const moveId = movePool[this.scene.randBattleSeedInt(movePool.length)]!.moveId; // TODO: is the bang correct? + const moveId = movePool[globalScene.randBattleSeedInt(movePool.length)]!.moveId; // TODO: is the bang correct? return { move: moveId, targets: this.getNextTargets(moveId) }; case AiType.SMART_RANDOM: case AiType.SMART: @@ -4852,7 +4848,7 @@ export class EnemyPokemon extends Pokemon { return false; } - const fieldPokemon = this.scene.getField(); + const fieldPokemon = globalScene.getField(); const moveTargets = getMoveTargets(this, move.id).targets .map(ind => fieldPokemon[ind]) .filter(p => this.isPlayer() !== p.isPlayer()); @@ -4890,7 +4886,7 @@ export class EnemyPokemon extends Pokemon { break; } - const target = this.scene.getField()[mt]; + const target = globalScene.getField()[mt]; /** * The "target score" of a move is given by the move's user benefit score + the move's target benefit score. * If the target is an ally, the target benefit score is multiplied by -1. @@ -4949,13 +4945,13 @@ export class EnemyPokemon extends Pokemon { let r = 0; if (this.aiType === AiType.SMART_RANDOM) { // Has a 5/8 chance to select the best move, and a 3/8 chance to advance to the next best move (and repeat this roll) - while (r < sortedMovePool.length - 1 && this.scene.randBattleSeedInt(8) >= 5) { + while (r < sortedMovePool.length - 1 && globalScene.randBattleSeedInt(8) >= 5) { r++; } } else if (this.aiType === AiType.SMART) { // The chance to advance to the next best move increases when the compared moves' scores are closer to each other. while (r < sortedMovePool.length - 1 && (moveScores[movePool.indexOf(sortedMovePool[r + 1])] / moveScores[movePool.indexOf(sortedMovePool[r])]) >= 0 - && this.scene.randBattleSeedInt(100) < Math.round((moveScores[movePool.indexOf(sortedMovePool[r + 1])] / moveScores[movePool.indexOf(sortedMovePool[r])]) * 50)) { + && globalScene.randBattleSeedInt(100) < Math.round((moveScores[movePool.indexOf(sortedMovePool[r + 1])] / moveScores[movePool.indexOf(sortedMovePool[r])]) * 50)) { r++; } } @@ -4974,7 +4970,7 @@ export class EnemyPokemon extends Pokemon { */ getNextTargets(moveId: Moves): BattlerIndex[] { const moveTargets = getMoveTargets(this, moveId); - const targets = this.scene.getField(true).filter(p => moveTargets.targets.indexOf(p.getBattlerIndex()) > -1); + const targets = globalScene.getField(true).filter(p => moveTargets.targets.indexOf(p.getBattlerIndex()) > -1); // If the move is multi-target, return all targets' indexes if (moveTargets.multiple) { return targets.map(p => p.getBattlerIndex()); @@ -5036,7 +5032,7 @@ export class EnemyPokemon extends Pokemon { * then select the first target whose cumulative weight (with all previous targets' weights) * is greater than that random number. */ - const randValue = this.scene.randBattleSeedInt(totalWeight); + const randValue = globalScene.randBattleSeedInt(totalWeight); let targetIndex: integer = 0; thresholds.every((t, i) => { @@ -5107,7 +5103,7 @@ export class EnemyPokemon extends Pokemon { } } - switch (this.scene.currentBattle.battleSpec) { + switch (globalScene.currentBattle.battleSpec) { case BattleSpec.FINAL_BOSS: if (!this.formIndex && this.bossSegmentIndex < 1) { damage = Math.min(damage, this.hp - 1); @@ -5131,7 +5127,7 @@ export class EnemyPokemon extends Pokemon { } canBypassBossSegments(segmentCount: integer = 1): boolean { - if (this.scene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { + if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { if (!this.formIndex && (this.bossSegmentIndex - segmentCount) < 1) { return false; } @@ -5182,13 +5178,13 @@ export class EnemyPokemon extends Pokemon { stages++; } - this.scene.unshiftPhase(new StatStageChangePhase(this.scene, this.getBattlerIndex(), true, [ boostedStat! ], stages, true, true)); + globalScene.unshiftPhase(new StatStageChangePhase(this.getBattlerIndex(), true, [ boostedStat! ], stages, true, true)); this.bossSegmentIndex--; } } getFieldIndex(): integer { - return this.scene.getEnemyField().indexOf(this); + return globalScene.getEnemyField().indexOf(this); } getBattlerIndex(): BattlerIndex { @@ -5203,16 +5199,16 @@ export class EnemyPokemon extends Pokemon { * @returns the pokemon that was added or null if the pokemon could not be added */ addToParty(pokeballType: PokeballType, slotIndex: number = -1) { - const party = this.scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); let ret: PlayerPokemon | null = null; if (party.length < PLAYER_PARTY_MAX_SIZE) { this.pokeball = pokeballType; this.metLevel = this.level; - this.metBiome = this.scene.arena.biomeType; - this.metWave = this.scene.currentBattle.waveIndex; + this.metBiome = globalScene.arena.biomeType; + this.metWave = globalScene.currentBattle.waveIndex; this.metSpecies = this.species.speciesId; - const newPokemon = this.scene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); + const newPokemon = globalScene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); if (Utils.isBetween(slotIndex, 0, PLAYER_PARTY_MAX_SIZE - 1)) { party.splice(slotIndex, 0, newPokemon); @@ -5224,7 +5220,7 @@ export class EnemyPokemon extends Pokemon { newPokemon.setVisible(false); ret = newPokemon; - this.scene.triggerPokemonFormChange(newPokemon, SpeciesFormChangeActiveTrigger, true); + globalScene.triggerPokemonFormChange(newPokemon, SpeciesFormChangeActiveTrigger, true); } return ret; diff --git a/src/field/trainer.ts b/src/field/trainer.ts index b77a156f4012..564c53aaa2c9 100644 --- a/src/field/trainer.ts +++ b/src/field/trainer.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions"; import PokemonSpecies, { getPokemonSpecies } from "#app/data/pokemon-species"; import { @@ -35,8 +35,8 @@ export default class Trainer extends Phaser.GameObjects.Container { public name: string; public partnerName: string; - constructor(scene: BattleScene, trainerType: TrainerType, variant: TrainerVariant, partyTemplateIndex?: integer, name?: string, partnerName?: string, trainerConfigOverride?: TrainerConfig) { - super(scene, -72, 80); + constructor(trainerType: TrainerType, variant: TrainerVariant, partyTemplateIndex?: integer, name?: string, partnerName?: string, trainerConfigOverride?: TrainerConfig) { + super(globalScene, -72, 80); this.config = trainerConfigs.hasOwnProperty(trainerType) ? trainerConfigs[trainerType] : trainerConfigs[TrainerType.ACE_TRAINER]; @@ -80,9 +80,9 @@ export default class Trainer extends Phaser.GameObjects.Container { console.log(Object.keys(trainerPartyTemplates)[Object.values(trainerPartyTemplates).indexOf(this.getPartyTemplate())]); const getSprite = (hasShadow?: boolean, forceFemale?: boolean) => { - const ret = this.scene.addFieldSprite(0, 0, this.config.getSpriteKey(variant === TrainerVariant.FEMALE || forceFemale, this.isDouble())); + const ret = globalScene.addFieldSprite(0, 0, this.config.getSpriteKey(variant === TrainerVariant.FEMALE || forceFemale, this.isDouble())); ret.setOrigin(0.5, 1); - ret.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow }); + ret.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: !!hasShadow }); return ret; }; @@ -207,7 +207,7 @@ export default class Trainer extends Phaser.GameObjects.Container { getPartyTemplate(): TrainerPartyTemplate { if (this.config.partyTemplateFunc) { - return this.config.partyTemplateFunc(this.scene); + return this.config.partyTemplateFunc(); } return this.config.partyTemplates[this.partyTemplateIndex]; } @@ -216,7 +216,7 @@ export default class Trainer extends Phaser.GameObjects.Container { const ret: number[] = []; const partyTemplate = this.getPartyTemplate(); - const difficultyWaveIndex = this.scene.gameMode.getWaveForDifficulty(waveIndex); + const difficultyWaveIndex = globalScene.gameMode.getWaveForDifficulty(waveIndex); const baseLevel = 1 + difficultyWaveIndex / 2 + Math.pow(difficultyWaveIndex / 25, 2); if (this.isDouble() && partyTemplate.size < 2) { @@ -261,12 +261,12 @@ export default class Trainer extends Phaser.GameObjects.Container { } genPartyMember(index: integer): EnemyPokemon { - const battle = this.scene.currentBattle; + const battle = globalScene.currentBattle; const level = battle.enemyLevels?.[index]!; // TODO: is this bang correct? let ret: EnemyPokemon; - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const template = this.getPartyTemplate(); const strength: PartyMemberStrength = template.getStrength(index); @@ -275,11 +275,11 @@ export default class Trainer extends Phaser.GameObjects.Container { if (!(this.config.trainerTypeDouble && this.isDouble() && !this.config.doubleOnly)) { if (this.config.partyMemberFuncs.hasOwnProperty(index)) { - ret = this.config.partyMemberFuncs[index](this.scene, level, strength); + ret = this.config.partyMemberFuncs[index](level, strength); return; } if (this.config.partyMemberFuncs.hasOwnProperty(index - template.size)) { - ret = this.config.partyMemberFuncs[index - template.size](this.scene, level, template.getStrength(index)); + ret = this.config.partyMemberFuncs[index - template.size](level, template.getStrength(index)); return; } } @@ -364,23 +364,23 @@ export default class Trainer extends Phaser.GameObjects.Container { let species = useNewSpeciesPool ? getPokemonSpecies(newSpeciesPool[Math.floor(Utils.randSeedInt(newSpeciesPool.length))]) : template.isSameSpecies(index) && index > offset - ? getPokemonSpecies(battle.enemyParty[offset].species.getTrainerSpeciesForLevel(level, false, template.getStrength(offset), this.scene.currentBattle.waveIndex)) + ? getPokemonSpecies(battle.enemyParty[offset].species.getTrainerSpeciesForLevel(level, false, template.getStrength(offset), globalScene.currentBattle.waveIndex)) : this.genNewPartyMemberSpecies(level, strength); // If the species is from newSpeciesPool, we need to adjust it based on the level and strength if (newSpeciesPool) { - species = getPokemonSpecies(species.getSpeciesForLevel(level, true, true, strength, this.scene.currentBattle.waveIndex)); + species = getPokemonSpecies(species.getSpeciesForLevel(level, true, true, strength, globalScene.currentBattle.waveIndex)); } - ret = this.scene.addEnemyPokemon(species, level, !this.isDouble() || !(index % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); - }, this.config.hasStaticParty ? this.config.getDerivedType() + ((index + 1) << 8) : this.scene.currentBattle.waveIndex + (this.config.getDerivedType() << 10) + (((!this.config.useSameSeedForAllMembers ? index : 0) + 1) << 8)); + ret = globalScene.addEnemyPokemon(species, level, !this.isDouble() || !(index % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); + }, this.config.hasStaticParty ? this.config.getDerivedType() + ((index + 1) << 8) : globalScene.currentBattle.waveIndex + (this.config.getDerivedType() << 10) + (((!this.config.useSameSeedForAllMembers ? index : 0) + 1) << 8)); return ret!; // TODO: is this bang correct? } genNewPartyMemberSpecies(level: integer, strength: PartyMemberStrength, attempt?: integer): PokemonSpecies { - const battle = this.scene.currentBattle; + const battle = globalScene.currentBattle; const template = this.getPartyTemplate(); let baseSpecies: PokemonSpecies; @@ -395,10 +395,10 @@ export default class Trainer extends Phaser.GameObjects.Container { const tierPool = this.config.speciesPools[tier]; baseSpecies = getPokemonSpecies(Utils.randSeedItem(tierPool)); } else { - baseSpecies = this.scene.randomSpecies(battle.waveIndex, level, false, this.config.speciesFilter); + baseSpecies = globalScene.randomSpecies(battle.waveIndex, level, false, this.config.speciesFilter); } - let ret = getPokemonSpecies(baseSpecies.getTrainerSpeciesForLevel(level, true, strength, this.scene.currentBattle.waveIndex)); + let ret = getPokemonSpecies(baseSpecies.getTrainerSpeciesForLevel(level, true, strength, globalScene.currentBattle.waveIndex)); let retry = false; console.log(ret.getName()); @@ -417,7 +417,7 @@ export default class Trainer extends Phaser.GameObjects.Container { console.log("Attempting reroll of species evolution to fit specialty type..."); let evoAttempt = 0; while (retry && evoAttempt++ < 10) { - ret = getPokemonSpecies(baseSpecies.getTrainerSpeciesForLevel(level, true, strength, this.scene.currentBattle.waveIndex)); + ret = getPokemonSpecies(baseSpecies.getTrainerSpeciesForLevel(level, true, strength, globalScene.currentBattle.waveIndex)); console.log(ret.name); if (this.config.specialtyTypes.find(t => ret.isOfType(t))) { retry = false; @@ -448,7 +448,7 @@ export default class Trainer extends Phaser.GameObjects.Container { checkDuplicateSpecies(species: PokemonSpecies, baseSpecies: PokemonSpecies): boolean { const staticPartyPokemon = (signatureSpecies[TrainerType[this.config.trainerType]] ?? []).flat(1); - const currentPartySpecies = this.scene.getEnemyParty().map(p => { + const currentPartySpecies = globalScene.getEnemyParty().map(p => { return p.species.speciesId; }); return currentPartySpecies.includes(species.speciesId) || staticPartyPokemon.includes(baseSpecies.speciesId); @@ -459,10 +459,10 @@ export default class Trainer extends Phaser.GameObjects.Container { trainerSlot = TrainerSlot.NONE; } - const party = this.scene.getEnemyParty(); - const nonFaintedLegalPartyMembers = party.slice(this.scene.currentBattle.getBattlerCount()).filter(p => p.isAllowedInBattle()).filter(p => !trainerSlot || p.trainerSlot === trainerSlot); + const party = globalScene.getEnemyParty(); + const nonFaintedLegalPartyMembers = party.slice(globalScene.currentBattle.getBattlerCount()).filter(p => p.isAllowedInBattle()).filter(p => !trainerSlot || p.trainerSlot === trainerSlot); const partyMemberScores = nonFaintedLegalPartyMembers.map(p => { - const playerField = this.scene.getPlayerField().filter(p => p.isAllowedInBattle()); + const playerField = globalScene.getPlayerField().filter(p => p.isAllowedInBattle()); let score = 0; if (playerField.length > 0) { @@ -474,7 +474,7 @@ export default class Trainer extends Phaser.GameObjects.Container { } score /= playerField.length; if (forSwitch && !p.isOnField()) { - this.scene.arena.findTagsOnSide(t => t instanceof ArenaTrapTag, ArenaTagSide.ENEMY).map(t => score *= (t as ArenaTrapTag).getMatchupScoreMultiplier(p)); + globalScene.arena.findTagsOnSide(t => t instanceof ArenaTrapTag, ArenaTagSide.ENEMY).map(t => score *= (t as ArenaTrapTag).getMatchupScoreMultiplier(p)); } } @@ -506,7 +506,7 @@ export default class Trainer extends Phaser.GameObjects.Container { if (maxScorePartyMemberIndexes.length > 1) { let rand: integer; - this.scene.executeWithSeedOffset(() => rand = Utils.randSeedInt(maxScorePartyMemberIndexes.length), this.scene.currentBattle.turn << 2); + globalScene.executeWithSeedOffset(() => rand = Utils.randSeedInt(maxScorePartyMemberIndexes.length), globalScene.currentBattle.turn << 2); return maxScorePartyMemberIndexes[rand!]; } @@ -539,7 +539,7 @@ export default class Trainer extends Phaser.GameObjects.Container { } loadAssets(): Promise { - return this.config.loadAssets(this.scene, this.variant); + return this.config.loadAssets(this.variant); } initSprite(): void { @@ -627,7 +627,7 @@ export default class Trainer extends Phaser.GameObjects.Container { if (duration) { tintSprite.setAlpha(0); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: tintSprite, alpha: alpha || 1, duration: duration, @@ -643,7 +643,7 @@ export default class Trainer extends Phaser.GameObjects.Container { const tintSprites = this.getTintSprites(); tintSprites.map(tintSprite => { if (duration) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: tintSprite, alpha: 0, duration: duration, @@ -660,7 +660,3 @@ export default class Trainer extends Phaser.GameObjects.Container { }); } } - -export default interface Trainer { - scene: BattleScene -} diff --git a/src/game-mode.ts b/src/game-mode.ts index 3f12c5b056ed..6e325e0c320f 100644 --- a/src/game-mode.ts +++ b/src/game-mode.ts @@ -1,6 +1,5 @@ import i18next from "i18next"; import { classicFixedBattles, FixedBattleConfig, FixedBattleConfigs } from "./battle"; -import BattleScene from "./battle-scene"; import { allChallenges, applyChallenges, Challenge, ChallengeType, copyChallenge } from "./data/challenge"; import PokemonSpecies, { allSpecies } from "./data/pokemon-species"; import { Arena } from "./field/arena"; @@ -9,6 +8,7 @@ import * as Utils from "./utils"; import { Biome } from "#enums/biome"; import { Species } from "#enums/species"; import { Challenges } from "./enums/challenges"; +import { globalScene } from "#app/global-scene"; export enum GameModes { CLASSIC, @@ -109,16 +109,15 @@ export class GameMode implements GameModeConfig { } /** - * @param scene current BattleScene * @returns either: * - random biome for Daily mode * - override from overrides.ts * - Town */ - getStartingBiome(scene: BattleScene): Biome { + getStartingBiome(): Biome { switch (this.modeId) { case GameModes.DAILY: - return scene.generateRandomBiome(this.getWaveForDifficulty(1)); + return globalScene.generateRandomBiome(this.getWaveForDifficulty(1)); default: return Overrides.STARTING_BIOME_OVERRIDE || Biome.TOWN; } @@ -136,8 +135,8 @@ export class GameMode implements GameModeConfig { /** * Determines whether or not to generate a trainer * @param waveIndex the current floor the player is on (trainer sprites fail to generate on X1 floors) - * @param arena the arena that contains the scene and functions - * @returns true if a trainer should be generated, false otherwise + * @param arena the current {@linkcode Arena} + * @returns `true` if a trainer should be generated, `false` otherwise */ isWaveTrainer(waveIndex: integer, arena: Arena): boolean { /** @@ -146,14 +145,13 @@ export class GameMode implements GameModeConfig { if (this.isDaily) { return waveIndex % 10 === 5 || (!(waveIndex % 10) && waveIndex > 10 && !this.isWaveFinal(waveIndex)); } - if ((waveIndex % 30) === (arena.scene.offsetGym ? 0 : 20) && !this.isWaveFinal(waveIndex)) { + if ((waveIndex % 30) === (globalScene.offsetGym ? 0 : 20) && !this.isWaveFinal(waveIndex)) { return true; } else if (waveIndex % 10 !== 1 && waveIndex % 10) { /** * Do not check X1 floors since there's a bug that stops trainer sprites from appearing * after a X0 full party heal */ - const trainerChance = arena.getTrainerChance(); let allowTrainerBattle = true; if (trainerChance) { @@ -163,11 +161,11 @@ export class GameMode implements GameModeConfig { if (w === waveIndex) { continue; } - if ((w % 30) === (arena.scene.offsetGym ? 0 : 20) || this.isFixedBattle(w)) { + if ((w % 30) === (globalScene.offsetGym ? 0 : 20) || this.isFixedBattle(w)) { allowTrainerBattle = false; break; } else if (w < waveIndex) { - arena.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const waveTrainerChance = arena.getTrainerChance(); if (!Utils.randSeedInt(waveTrainerChance)) { allowTrainerBattle = false; diff --git a/src/global-scene.ts b/src/global-scene.ts new file mode 100644 index 000000000000..76071bd7fac7 --- /dev/null +++ b/src/global-scene.ts @@ -0,0 +1,7 @@ +import type BattleScene from "#app/battle-scene"; + +export let globalScene: BattleScene; + +export function initGlobalScene(scene: BattleScene): void { + globalScene = scene; +} diff --git a/src/inputs-controller.ts b/src/inputs-controller.ts index 537d28702590..7656de7558ce 100644 --- a/src/inputs-controller.ts +++ b/src/inputs-controller.ts @@ -15,7 +15,7 @@ import { getButtonWithKeycode, getIconForLatestInput, swap, } from "#app/configs/inputs/configHandler"; -import BattleScene from "./battle-scene"; +import { globalScene } from "#app/global-scene"; import { SettingGamepad } from "#app/system/settings/settings-gamepad"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; import TouchControl from "#app/touch-controls"; @@ -75,7 +75,6 @@ const repeatInputDelayMillis = 250; */ export class InputsController { private gamepads: Array = new Array(); - private scene: BattleScene; public events: Phaser.Events.EventEmitter; private buttonLock: Button[] = new Array(); @@ -96,17 +95,13 @@ export class InputsController { /** * Initializes a new instance of the game control system, setting up initial state and configurations. * - * @param scene - The Phaser scene associated with this instance. - * * @remarks * This constructor initializes the game control system with necessary setups for handling inputs. * It prepares an interactions array indexed by button identifiers and configures default states for each button. * Specific buttons like MENU and STATS are set not to repeat their actions. * It concludes by calling the `init` method to complete the setup. */ - - constructor(scene: BattleScene) { - this.scene = scene; + constructor() { this.selectedDevice = { [Device.GAMEPAD]: null, [Device.KEYBOARD]: "default" @@ -134,14 +129,14 @@ export class InputsController { * Additionally, it manages the game's behavior when it loses focus to prevent unwanted game actions during this state. */ init(): void { - this.events = this.scene.game.events; + this.events = globalScene.game.events; - this.scene.game.events.on(Phaser.Core.Events.BLUR, () => { + globalScene.game.events.on(Phaser.Core.Events.BLUR, () => { this.loseFocus(); }); - if (typeof this.scene.input.gamepad !== "undefined") { - this.scene.input.gamepad?.on("connected", function (thisGamepad) { + if (typeof globalScene.input.gamepad !== "undefined") { + globalScene.input.gamepad?.on("connected", function (thisGamepad) { if (!thisGamepad) { return; } @@ -150,25 +145,25 @@ export class InputsController { this.onReconnect(thisGamepad); }, this); - this.scene.input.gamepad?.on("disconnected", function (thisGamepad) { + globalScene.input.gamepad?.on("disconnected", function (thisGamepad) { this.onDisconnect(thisGamepad); // when a gamepad is disconnected }, this); // Check to see if the gamepad has already been setup by the browser - this.scene.input.gamepad?.refreshPads(); - if (this.scene.input.gamepad?.total) { + globalScene.input.gamepad?.refreshPads(); + if (globalScene.input.gamepad?.total) { this.refreshGamepads(); for (const thisGamepad of this.gamepads) { - this.scene.input.gamepad.emit("connected", thisGamepad); + globalScene.input.gamepad.emit("connected", thisGamepad); } } - this.scene.input.gamepad?.on("down", this.gamepadButtonDown, this); - this.scene.input.gamepad?.on("up", this.gamepadButtonUp, this); - this.scene.input.keyboard?.on("keydown", this.keyboardKeyDown, this); - this.scene.input.keyboard?.on("keyup", this.keyboardKeyUp, this); + globalScene.input.gamepad?.on("down", this.gamepadButtonDown, this); + globalScene.input.gamepad?.on("up", this.gamepadButtonUp, this); + globalScene.input.keyboard?.on("keydown", this.keyboardKeyDown, this); + globalScene.input.keyboard?.on("keyup", this.keyboardKeyUp, this); } - this.touchControls = new TouchControl(this.scene); + this.touchControls = new TouchControl(); this.moveTouchControlsHandler = new MoveTouchControlsHandler(this.touchControls); } @@ -238,7 +233,7 @@ export class InputsController { if (gamepadName) { this.selectedDevice[Device.GAMEPAD] = gamepadName.toLowerCase(); } - const handler = this.scene.ui?.handlers[Mode.SETTINGS_GAMEPAD] as SettingsGamepadUiHandler; + const handler = globalScene.ui?.handlers[Mode.SETTINGS_GAMEPAD] as SettingsGamepadUiHandler; handler && handler.updateChosenGamepadDisplay(); } @@ -251,7 +246,7 @@ export class InputsController { if (layoutKeyboard) { this.selectedDevice[Device.KEYBOARD] = layoutKeyboard.toLowerCase(); } - const handler = this.scene.ui?.handlers[Mode.SETTINGS_KEYBOARD] as SettingsKeyboardUiHandler; + const handler = globalScene.ui?.handlers[Mode.SETTINGS_KEYBOARD] as SettingsKeyboardUiHandler; handler && handler.updateChosenKeyboardDisplay(); } @@ -296,10 +291,10 @@ export class InputsController { const config = deepCopy(this.getConfig(gamepadID)) as InterfaceConfig; config.custom = this.configs[gamepadID]?.custom || { ...config.default }; this.configs[gamepadID] = config; - this.scene.gameData?.saveMappingConfigs(gamepadID, this.configs[gamepadID]); + globalScene.gameData?.saveMappingConfigs(gamepadID, this.configs[gamepadID]); } this.lastSource = "gamepad"; - const handler = this.scene.ui?.handlers[Mode.SETTINGS_GAMEPAD] as SettingsGamepadUiHandler; + const handler = globalScene.ui?.handlers[Mode.SETTINGS_GAMEPAD] as SettingsGamepadUiHandler; handler && handler.updateChosenGamepadDisplay(); } @@ -311,7 +306,7 @@ export class InputsController { const config = deepCopy(this.getConfigKeyboard(layout)) as InterfaceConfig; config.custom = this.configs[layout]?.custom || { ...config.default }; this.configs[layout] = config; - this.scene.gameData?.saveMappingConfigs(this.selectedDevice[Device.KEYBOARD], this.configs[layout]); + globalScene.gameData?.saveMappingConfigs(this.selectedDevice[Device.KEYBOARD], this.configs[layout]); } this.initChosenLayoutKeyboard(this.selectedDevice[Device.KEYBOARD]); } @@ -326,7 +321,7 @@ export class InputsController { */ refreshGamepads(): void { // Sometimes, gamepads are undefined. For some reason. - this.gamepads = this.scene.input.gamepad?.gamepads.filter(function (el) { + this.gamepads = globalScene.input.gamepad?.gamepads.filter(function (el) { return el !== null; }) ?? []; @@ -409,7 +404,7 @@ export class InputsController { return; } this.lastSource = "gamepad"; - if (!this.selectedDevice[Device.GAMEPAD] || (this.scene.ui.getMode() !== Mode.GAMEPAD_BINDING && this.selectedDevice[Device.GAMEPAD] !== pad.id.toLowerCase())) { + if (!this.selectedDevice[Device.GAMEPAD] || (globalScene.ui.getMode() !== Mode.GAMEPAD_BINDING && this.selectedDevice[Device.GAMEPAD] !== pad.id.toLowerCase())) { this.setChosenGamepad(pad.id); } if (!this.gamepadSupport || pad.id.toLowerCase() !== this.selectedDevice[Device.GAMEPAD].toLowerCase()) { diff --git a/src/loading-scene.ts b/src/loading-scene.ts index c49b8d5aaa9f..9ecede82d89e 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -20,6 +20,7 @@ import { initStatsKeys } from "#app/ui/game-stats-ui-handler"; import { initVouchers } from "#app/system/voucher"; import { Biome } from "#enums/biome"; import { initMysteryEncounters } from "#app/data/mystery-encounters/mystery-encounters"; +import { globalScene } from "#app/global-scene"; export class LoadingScene extends SceneBase { public static readonly KEY = "loading"; @@ -510,7 +511,7 @@ export class LoadingScene extends SceneBase { async create() { this.events.once(Phaser.Scenes.Events.DESTROY, () => this.handleDestroy()); - this.scene.start("battle"); + globalScene.scene.start("battle"); } handleDestroy() { diff --git a/src/messages.ts b/src/messages.ts index 91f550918e5b..96d2e1717641 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -1,3 +1,4 @@ +import { globalScene } from "#app/global-scene"; import { BattleSpec } from "#enums/battle-spec"; import Pokemon from "./field/pokemon"; import i18next from "i18next"; @@ -12,7 +13,7 @@ export function getPokemonNameWithAffix(pokemon: Pokemon | undefined): string { return "Missigno"; } - switch (pokemon.scene.currentBattle.battleSpec) { + switch (globalScene.currentBattle.battleSpec) { case BattleSpec.DEFAULT: return !pokemon.isPlayer() ? pokemon.hasTrainer() diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 57b3ced18133..ef46a0265b29 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { EvolutionItem, pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import { tmPoolTiers, tmSpecies } from "#app/data/balance/tms"; import { getBerryEffectDescription, getBerryName } from "#app/data/berry"; @@ -64,7 +64,7 @@ export class ModifierType { return i18next.t(`${this.localeKey}.name` as any); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t(`${this.localeKey}.description` as any); } @@ -206,12 +206,12 @@ class AddPokeballModifierType extends ModifierType { }); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.AddPokeballModifierType.description", { "modifierCount": this.count, "pokeballName": getPokeballName(this.pokeballType), "catchRate": getPokeballCatchMultiplier(this.pokeballType) > -1 ? `${getPokeballCatchMultiplier(this.pokeballType)}x` : "100%", - "pokeballAmount": `${scene.pokeballCounts[this.pokeballType]}`, + "pokeballAmount": `${globalScene.pokeballCounts[this.pokeballType]}`, }); } } @@ -233,7 +233,7 @@ class AddVoucherModifierType extends ModifierType { }); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.AddVoucherModifierType.description", { "modifierCount": this.count, "voucherTypeName": getVoucherTypeName(this.voucherType), @@ -255,8 +255,8 @@ export class PokemonHeldItemModifierType extends PokemonModifierType { constructor(localeKey: string, iconImage: string, newModifierFunc: NewModifierFunc, group?: string, soundName?: string) { super(localeKey, iconImage, newModifierFunc, (pokemon: PlayerPokemon) => { const dummyModifier = this.newModifier(pokemon); - const matchingModifier = pokemon.scene.findModifier(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id && m.matchType(dummyModifier)) as PokemonHeldItemModifier; - const maxStackCount = dummyModifier.getMaxStackCount(pokemon.scene); + const matchingModifier = globalScene.findModifier(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id && m.matchType(dummyModifier)) as PokemonHeldItemModifier; + const maxStackCount = dummyModifier.getMaxStackCount(); if (!maxStackCount) { return i18next.t("modifierType:ModifierType.PokemonHeldItemModifierType.extra.inoperable", { "pokemonName": getPokemonNameWithAffix(pokemon) }); } @@ -291,7 +291,7 @@ export class PokemonHpRestoreModifierType extends PokemonModifierType { this.healStatus = healStatus; } - getDescription(scene: BattleScene): string { + getDescription(): string { return this.restorePoints ? i18next.t("modifierType:ModifierType.PokemonHpRestoreModifierType.description", { restorePoints: this.restorePoints, @@ -321,7 +321,7 @@ export class PokemonReviveModifierType extends PokemonHpRestoreModifierType { }; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonReviveModifierType.description", { restorePercent: this.restorePercent }); } } @@ -337,7 +337,7 @@ export class PokemonStatusHealModifierType extends PokemonModifierType { })); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonStatusHealModifierType.description"); } } @@ -369,7 +369,7 @@ export class PokemonPpRestoreModifierType extends PokemonMoveModifierType { this.restorePoints = restorePoints; } - getDescription(scene: BattleScene): string { + getDescription(): string { return this.restorePoints > -1 ? i18next.t("modifierType:ModifierType.PokemonPpRestoreModifierType.description", { restorePoints: this.restorePoints }) : i18next.t("modifierType:ModifierType.PokemonPpRestoreModifierType.extra.fully") @@ -392,7 +392,7 @@ export class PokemonAllMovePpRestoreModifierType extends PokemonModifierType { this.restorePoints = restorePoints; } - getDescription(scene: BattleScene): string { + getDescription(): string { return this.restorePoints > -1 ? i18next.t("modifierType:ModifierType.PokemonAllMovePpRestoreModifierType.description", { restorePoints: this.restorePoints }) : i18next.t("modifierType:ModifierType.PokemonAllMovePpRestoreModifierType.extra.fully") @@ -417,7 +417,7 @@ export class PokemonPpUpModifierType extends PokemonMoveModifierType { this.upPoints = upPoints; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonPpUpModifierType.description", { upPoints: this.upPoints }); } } @@ -441,7 +441,7 @@ export class PokemonNatureChangeModifierType extends PokemonModifierType { return i18next.t("modifierType:ModifierType.PokemonNatureChangeModifierType.name", { natureName: getNatureName(this.nature) }); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonNatureChangeModifierType.description", { natureName: getNatureName(this.nature, true, true, true) }); } } @@ -467,7 +467,7 @@ export class DoubleBattleChanceBoosterModifierType extends ModifierType { this.maxBattles = maxBattles; } - getDescription(_scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.DoubleBattleChanceBoosterModifierType.description", { battleCount: this.maxBattles }); @@ -492,7 +492,7 @@ export class TempStatStageBoosterModifierType extends ModifierType implements Ge return i18next.t(`modifierType:TempStatStageBoosterItem.${this.nameKey}`); } - getDescription(_scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.TempStatStageBoosterModifierType.description", { stat: i18next.t(getStatKey(this.stat)), amount: i18next.t(`modifierType:ModifierType.TempStatStageBoosterModifierType.extra.${this.quantityKey}`) @@ -517,7 +517,7 @@ export class BerryModifierType extends PokemonHeldItemModifierType implements Ge return getBerryName(this.berryType); } - getDescription(scene: BattleScene): string { + getDescription(): string { return getBerryEffectDescription(this.berryType); } @@ -563,7 +563,7 @@ export class AttackTypeBoosterModifierType extends PokemonHeldItemModifierType i return i18next.t(`modifierType:AttackTypeBoosterItem.${AttackTypeBoosterItem[this.moveType]?.toLowerCase()}`); } - getDescription(scene: BattleScene): string { + getDescription(): string { // TODO: Need getTypeName? return i18next.t("modifierType:ModifierType.AttackTypeBoosterModifierType.description", { moveType: i18next.t(`pokemonInfo:Type.${Type[this.moveType]}`) }); } @@ -600,9 +600,9 @@ export class PokemonLevelIncrementModifierType extends PokemonModifierType { super(localeKey, iconImage, (_type, args) => new PokemonLevelIncrementModifier(this, (args[0] as PlayerPokemon).id), (_pokemon: PlayerPokemon) => null); } - getDescription(scene: BattleScene): string { + getDescription(): string { let levels = 1; - const hasCandyJar = scene.modifiers.find(modifier => modifier instanceof LevelIncrementBoosterModifier); + const hasCandyJar = globalScene.modifiers.find(modifier => modifier instanceof LevelIncrementBoosterModifier); if (hasCandyJar) { levels += hasCandyJar.stackCount; } @@ -615,9 +615,9 @@ export class AllPokemonLevelIncrementModifierType extends ModifierType { super(localeKey, iconImage, (_type, _args) => new PokemonLevelIncrementModifier(this, -1)); } - getDescription(scene: BattleScene): string { + getDescription(): string { let levels = 1; - const hasCandyJar = scene.modifiers.find(modifier => modifier instanceof LevelIncrementBoosterModifier); + const hasCandyJar = globalScene.modifiers.find(modifier => modifier instanceof LevelIncrementBoosterModifier); if (hasCandyJar) { levels += hasCandyJar.stackCount; } @@ -641,7 +641,7 @@ export class BaseStatBoosterModifierType extends PokemonHeldItemModifierType imp return i18next.t(`modifierType:BaseStatBoosterItem.${this.key}`); } - getDescription(_scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.BaseStatBoosterModifierType.description", { stat: i18next.t(getStatKey(this.stat)) }); } @@ -661,7 +661,7 @@ export class PokemonBaseStatTotalModifierType extends PokemonHeldItemModifierTyp this.statModifier = statModifier; } - override getDescription(scene: BattleScene): string { + override getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonBaseStatTotalModifierType.description", { increaseDecrease: i18next.t(this.statModifier >= 0 ? "modifierType:ModifierType.PokemonBaseStatTotalModifierType.extra.increase" : "modifierType:ModifierType.PokemonBaseStatTotalModifierType.extra.decrease"), blessCurse: i18next.t(this.statModifier >= 0 ? "modifierType:ModifierType.PokemonBaseStatTotalModifierType.extra.blessed" : "modifierType:ModifierType.PokemonBaseStatTotalModifierType.extra.cursed"), @@ -687,7 +687,7 @@ export class PokemonBaseStatFlatModifierType extends PokemonHeldItemModifierType this.stats = stats; } - override getDescription(scene: BattleScene): string { + override getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonBaseStatFlatModifierType.description", { stats: this.stats.map(stat => i18next.t(getStatKey(stat))).join("/"), statValue: this.statModifier, @@ -708,7 +708,7 @@ class AllPokemonFullHpRestoreModifierType extends ModifierType { this.descriptionKey = descriptionKey!; // TODO: is this bang correct? } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t(`${this.descriptionKey || "modifierType:ModifierType.AllPokemonFullHpRestoreModifierType"}.description` as any); } } @@ -730,10 +730,10 @@ export class MoneyRewardModifierType extends ModifierType { this.moneyMultiplierDescriptorKey = moneyMultiplierDescriptorKey; } - getDescription(scene: BattleScene): string { - const moneyAmount = new NumberHolder(scene.getWaveMoneyAmount(this.moneyMultiplier)); - scene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); - const formattedMoney = formatMoney(scene.moneyFormat, moneyAmount.value); + getDescription(): string { + const moneyAmount = new NumberHolder(globalScene.getWaveMoneyAmount(this.moneyMultiplier)); + globalScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); + const formattedMoney = formatMoney(globalScene.moneyFormat, moneyAmount.value); return i18next.t("modifierType:ModifierType.MoneyRewardModifierType.description", { moneyMultiplier: i18next.t(this.moneyMultiplierDescriptorKey as any), @@ -751,7 +751,7 @@ export class ExpBoosterModifierType extends ModifierType { this.boostPercent = boostPercent; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.ExpBoosterModifierType.description", { boostPercent: this.boostPercent }); } } @@ -765,7 +765,7 @@ export class PokemonExpBoosterModifierType extends PokemonHeldItemModifierType { this.boostPercent = boostPercent; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonExpBoosterModifierType.description", { boostPercent: this.boostPercent }); } } @@ -775,7 +775,7 @@ export class PokemonFriendshipBoosterModifierType extends PokemonHeldItemModifie super(localeKey, iconImage, (_type, args) => new PokemonFriendshipBoosterModifier(this, (args[0] as Pokemon).id)); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonFriendshipBoosterModifierType.description"); } } @@ -789,7 +789,7 @@ export class PokemonMoveAccuracyBoosterModifierType extends PokemonHeldItemModif this.amount = amount; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonMoveAccuracyBoosterModifierType.description", { accuracyAmount: this.amount }); } } @@ -799,7 +799,7 @@ export class PokemonMultiHitModifierType extends PokemonHeldItemModifierType { super(localeKey, iconImage, (type, args) => new PokemonMultiHitModifier(type as PokemonMultiHitModifierType, (args[0] as Pokemon).id)); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.PokemonMultiHitModifierType.description"); } } @@ -826,8 +826,8 @@ export class TmModifierType extends PokemonModifierType { }); } - getDescription(scene: BattleScene): string { - return i18next.t(scene.enableMoveInfo ? "modifierType:ModifierType.TmModifierTypeWithInfo.description" : "modifierType:ModifierType.TmModifierType.description", { moveName: allMoves[this.moveId].name }); + getDescription(): string { + return i18next.t(globalScene.enableMoveInfo ? "modifierType:ModifierType.TmModifierTypeWithInfo.description" : "modifierType:ModifierType.TmModifierType.description", { moveName: allMoves[this.moveId].name }); } } @@ -855,7 +855,7 @@ export class EvolutionItemModifierType extends PokemonModifierType implements Ge return i18next.t(`modifierType:EvolutionItem.${EvolutionItem[this.evolutionItem]}`); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.EvolutionItemModifierType.description"); } @@ -894,7 +894,7 @@ export class FormChangeItemModifierType extends PokemonModifierType implements G return i18next.t(`modifierType:FormChangeItem.${FormChangeItem[this.formChangeItem]}`); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.FormChangeItemModifierType.description"); } @@ -914,7 +914,7 @@ export class FusePokemonModifierType extends PokemonModifierType { }); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.FusePokemonModifierType.description"); } } @@ -1140,12 +1140,12 @@ class FormChangeItemModifierTypeGenerator extends ModifierTypeGenerator { const formChangeItemPool = [ ...new Set(party.filter(p => pokemonFormChanges.hasOwnProperty(p.species.speciesId)).map(p => { const formChanges = pokemonFormChanges[p.species.speciesId]; - let formChangeItemTriggers = formChanges.filter(fc => ((fc.formKey.indexOf(SpeciesFormKey.MEGA) === -1 && fc.formKey.indexOf(SpeciesFormKey.PRIMAL) === -1) || party[0].scene.getModifiers(MegaEvolutionAccessModifier).length) - && ((fc.formKey.indexOf(SpeciesFormKey.GIGANTAMAX) === -1 && fc.formKey.indexOf(SpeciesFormKey.ETERNAMAX) === -1) || party[0].scene.getModifiers(GigantamaxAccessModifier).length) + let formChangeItemTriggers = formChanges.filter(fc => ((fc.formKey.indexOf(SpeciesFormKey.MEGA) === -1 && fc.formKey.indexOf(SpeciesFormKey.PRIMAL) === -1) || globalScene.getModifiers(MegaEvolutionAccessModifier).length) + && ((fc.formKey.indexOf(SpeciesFormKey.GIGANTAMAX) === -1 && fc.formKey.indexOf(SpeciesFormKey.ETERNAMAX) === -1) || globalScene.getModifiers(GigantamaxAccessModifier).length) && (!fc.conditions.length || fc.conditions.filter(cond => cond instanceof SpeciesFormChangeCondition && cond.predicate(p)).length) && (fc.preFormKey === p.getFormKey())) .map(fc => fc.findTrigger(SpeciesFormChangeItemTrigger) as SpeciesFormChangeItemTrigger) - .filter(t => t && t.active && !p.scene.findModifier(m => m instanceof PokemonFormChangeItemModifier && m.pokemonId === p.id && m.formChangeItem === t.item)); + .filter(t => t && t.active && !globalScene.findModifier(m => m instanceof PokemonFormChangeItemModifier && m.pokemonId === p.id && m.formChangeItem === t.item)); if (p.species.speciesId === Species.NECROZMA) { // technically we could use a simplified version and check for formChanges.length > 3, but in case any code changes later, this might break... @@ -1153,7 +1153,7 @@ class FormChangeItemModifierTypeGenerator extends ModifierTypeGenerator { let foundULTRA_Z = false, foundN_LUNA = false, foundN_SOLAR = false; - formChangeItemTriggers.forEach((fc, i) => { + formChangeItemTriggers.forEach((fc, _i) => { switch (fc.item) { case FormChangeItem.ULTRANECROZIUM_Z: foundULTRA_Z = true; @@ -1198,7 +1198,7 @@ export class TerastallizeModifierType extends PokemonHeldItemModifierType implem return i18next.t("modifierType:ModifierType.TerastallizeModifierType.name", { teraType: i18next.t(`pokemonInfo:Type.${Type[this.teraType]}`) }); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.TerastallizeModifierType.description", { teraType: i18next.t(`pokemonInfo:Type.${Type[this.teraType]}`) }); } @@ -1216,7 +1216,7 @@ export class ContactHeldItemTransferChanceModifierType extends PokemonHeldItemMo this.chancePercent = chancePercent; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.ContactHeldItemTransferChanceModifierType.description", { chancePercent: this.chancePercent }); } } @@ -1226,7 +1226,7 @@ export class TurnHeldItemTransferModifierType extends PokemonHeldItemModifierTyp super(localeKey, iconImage, (type, args) => new TurnHeldItemTransferModifier(type, (args[0] as Pokemon).id), group, soundName); } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.TurnHeldItemTransferModifierType.description"); } } @@ -1236,13 +1236,13 @@ export class EnemyAttackStatusEffectChanceModifierType extends ModifierType { private effect: StatusEffect; constructor(localeKey: string, iconImage: string, chancePercent: integer, effect: StatusEffect, stackCount?: integer) { - super(localeKey, iconImage, (type, args) => new EnemyAttackStatusEffectChanceModifier(type, effect, chancePercent, stackCount), "enemy_status_chance"); + super(localeKey, iconImage, (type, _args) => new EnemyAttackStatusEffectChanceModifier(type, effect, chancePercent, stackCount), "enemy_status_chance"); this.chancePercent = chancePercent; this.effect = effect; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.EnemyAttackStatusEffectChanceModifierType.description", { chancePercent: this.chancePercent, statusEffect: getStatusEffectDescriptor(this.effect), @@ -1259,7 +1259,7 @@ export class EnemyEndureChanceModifierType extends ModifierType { this.chancePercent = chancePercent; } - getDescription(scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.EnemyEndureChanceModifierType.description", { chancePercent: this.chancePercent }); } } @@ -1275,9 +1275,9 @@ type WeightedModifierTypeWeightFunc = (party: Pokemon[], rerollCount?: integer) * @returns A WeightedModifierTypeWeightFunc */ function skipInClassicAfterWave(wave: integer, defaultWeight: integer): WeightedModifierTypeWeightFunc { - return (party: Pokemon[]) => { - const gameMode = party[0].scene.gameMode; - const currentWave = party[0].scene.currentBattle.waveIndex; + return () => { + const gameMode = globalScene.gameMode; + const currentWave = globalScene.currentBattle.waveIndex; return gameMode.isClassic && currentWave >= wave ? 0 : defaultWeight; }; } @@ -1300,9 +1300,9 @@ function skipInLastClassicWaveOrDefault(defaultWeight: integer) : WeightedModifi * @returns A WeightedModifierTypeWeightFunc */ function lureWeightFunc(maxBattles: number, weight: number): WeightedModifierTypeWeightFunc { - return (party: Pokemon[]) => { - const lures = party[0].scene.getModifiers(DoubleBattleChanceBoosterModifier); - return !(party[0].scene.gameMode.isClassic && party[0].scene.currentBattle.waveIndex === 199) && (lures.length === 0 || lures.filter(m => m.getMaxBattles() === maxBattles && m.getBattleCount() >= maxBattles * 0.6).length === 0) ? weight : 0; + return () => { + const lures = globalScene.getModifiers(DoubleBattleChanceBoosterModifier); + return !(globalScene.gameMode.isClassic && globalScene.currentBattle.waveIndex === 199) && (lures.length === 0 || lures.filter(m => m.getMaxBattles() === maxBattles && m.getBattleCount() >= maxBattles * 0.6).length === 0) ? weight : 0; }; } class WeightedModifierType { @@ -1436,7 +1436,7 @@ export const modifierTypes = { TEMP_STAT_STAGE_BOOSTER: () => new TempStatStageBoosterModifierTypeGenerator(), DIRE_HIT: () => new class extends ModifierType { - getDescription(_scene: BattleScene): string { + getDescription(): string { return i18next.t("modifierType:ModifierType.TempStatStageBoosterModifierType.description", { stat: i18next.t("modifierType:ModifierType.DIRE_HIT.extra.raises"), amount: i18next.t("modifierType:ModifierType.TempStatStageBoosterModifierType.extra.stage") @@ -1448,7 +1448,7 @@ export const modifierTypes = { ATTACK_TYPE_BOOSTER: () => new AttackTypeBoosterModifierTypeGenerator(), - MINT: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => { + MINT: () => new ModifierTypeGenerator((_party: Pokemon[], pregenArgs?: any[]) => { if (pregenArgs && (pregenArgs.length === 1) && (pregenArgs[0] in Nature)) { return new PokemonNatureChangeModifierType(pregenArgs[0] as Nature); } @@ -1459,7 +1459,7 @@ export const modifierTypes = { if (pregenArgs && (pregenArgs.length === 1) && (pregenArgs[0] in Type)) { return new TerastallizeModifierType(pregenArgs[0] as Type); } - if (!party[0].scene.getModifiers(TerastallizeAccessModifier).length) { + if (!globalScene.getModifiers(TerastallizeAccessModifier).length) { return null; } let type: Type; @@ -1472,7 +1472,7 @@ export const modifierTypes = { return new TerastallizeModifierType(type); }), - BERRY: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => { + BERRY: () => new ModifierTypeGenerator((_party: Pokemon[], pregenArgs?: any[]) => { if (pregenArgs && (pregenArgs.length === 1) && (pregenArgs[0] in BerryType)) { return new BerryModifierType(pregenArgs[0] as BerryType); } @@ -1580,19 +1580,19 @@ export const modifierTypes = { ENEMY_ENDURE_CHANCE: () => new EnemyEndureChanceModifierType("modifierType:ModifierType.ENEMY_ENDURE_CHANCE", "wl_reset_urge", 2), ENEMY_FUSED_CHANCE: () => new ModifierType("modifierType:ModifierType.ENEMY_FUSED_CHANCE", "wl_custom_spliced", (type, _args) => new EnemyFusionChanceModifier(type, 1)), - MYSTERY_ENCOUNTER_SHUCKLE_JUICE: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => { + MYSTERY_ENCOUNTER_SHUCKLE_JUICE: () => new ModifierTypeGenerator((_party: Pokemon[], pregenArgs?: any[]) => { if (pregenArgs) { return new PokemonBaseStatTotalModifierType(pregenArgs[0] as number); } return new PokemonBaseStatTotalModifierType(randSeedInt(20, 1)); }), - MYSTERY_ENCOUNTER_OLD_GATEAU: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => { + MYSTERY_ENCOUNTER_OLD_GATEAU: () => new ModifierTypeGenerator((_party: Pokemon[], pregenArgs?: any[]) => { if (pregenArgs) { return new PokemonBaseStatFlatModifierType(pregenArgs[0] as number, pregenArgs[1] as Stat[]); } return new PokemonBaseStatFlatModifierType(randSeedInt(20, 1), [ Stat.HP, Stat.ATK, Stat.DEF ]); }), - MYSTERY_ENCOUNTER_BLACK_SLUDGE: () => new ModifierTypeGenerator((party: Pokemon[], pregenArgs?: any[]) => { + MYSTERY_ENCOUNTER_BLACK_SLUDGE: () => new ModifierTypeGenerator((_party: Pokemon[], pregenArgs?: any[]) => { if (pregenArgs) { return new ModifierType("modifierType:ModifierType.MYSTERY_ENCOUNTER_BLACK_SLUDGE", "black_sludge", (type, _args) => new HealShopCostModifier(type, pregenArgs[0] as number)); } @@ -1608,17 +1608,16 @@ interface ModifierPool { /** * Used to check if the player has max of a given ball type in Classic - * @param party The player's party, just used to access the scene * @param ballType The {@linkcode PokeballType} being checked * @returns boolean: true if the player has the maximum of a given ball type */ -function hasMaximumBalls(party: Pokemon[], ballType: PokeballType): boolean { - return (party[0].scene.gameMode.isClassic && party[0].scene.pokeballCounts[ballType] >= MAX_PER_TYPE_POKEBALLS); +function hasMaximumBalls(ballType: PokeballType): boolean { + return (globalScene.gameMode.isClassic && globalScene.pokeballCounts[ballType] >= MAX_PER_TYPE_POKEBALLS); } const modifierPool: ModifierPool = { [ModifierTier.COMMON]: [ - new WeightedModifierType(modifierTypes.POKEBALL, (party: Pokemon[]) => (hasMaximumBalls(party, PokeballType.POKEBALL)) ? 0 : 6, 6), + new WeightedModifierType(modifierTypes.POKEBALL, () => (hasMaximumBalls(PokeballType.POKEBALL)) ? 0 : 6, 6), new WeightedModifierType(modifierTypes.RARE_CANDY, 2), new WeightedModifierType(modifierTypes.POTION, (party: Pokemon[]) => { const thresholdPartyMemberCount = Math.min(party.filter(p => (p.getInverseHp() >= 10 && p.getHpRatio() <= 0.875) && !p.isFainted()).length, 3); @@ -1646,7 +1645,7 @@ const modifierPool: ModifierPool = { m.setTier(ModifierTier.COMMON); return m; }), [ModifierTier.GREAT]: [ - new WeightedModifierType(modifierTypes.GREAT_BALL, (party: Pokemon[]) => (hasMaximumBalls(party, PokeballType.GREAT_BALL)) ? 0 : 6, 6), + new WeightedModifierType(modifierTypes.GREAT_BALL, () => (hasMaximumBalls(PokeballType.GREAT_BALL)) ? 0 : 6, 6), new WeightedModifierType(modifierTypes.PP_UP, 2), new WeightedModifierType(modifierTypes.FULL_HEAL, (party: Pokemon[]) => { const statusEffectPartyMemberCount = Math.min(party.filter(p => p.hp && !!p.status && !p.getHeldItems().some(i => { @@ -1699,10 +1698,10 @@ const modifierPool: ModifierPool = { new WeightedModifierType(modifierTypes.DIRE_HIT, 4), new WeightedModifierType(modifierTypes.SUPER_LURE, lureWeightFunc(15, 4)), new WeightedModifierType(modifierTypes.NUGGET, skipInLastClassicWaveOrDefault(5)), - new WeightedModifierType(modifierTypes.EVOLUTION_ITEM, (party: Pokemon[]) => { - return Math.min(Math.ceil(party[0].scene.currentBattle.waveIndex / 15), 8); + new WeightedModifierType(modifierTypes.EVOLUTION_ITEM, () => { + return Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 15), 8); }, 8), - new WeightedModifierType(modifierTypes.MAP, (party: Pokemon[]) => party[0].scene.gameMode.isClassic && party[0].scene.currentBattle.waveIndex < 180 ? 2 : 0, 2), + new WeightedModifierType(modifierTypes.MAP, () => globalScene.gameMode.isClassic && globalScene.currentBattle.waveIndex < 180 ? 2 : 0, 2), new WeightedModifierType(modifierTypes.SOOTHE_BELL, 2), new WeightedModifierType(modifierTypes.TM_GREAT, 3), new WeightedModifierType(modifierTypes.MEMORY_MUSHROOM, (party: Pokemon[]) => { @@ -1714,22 +1713,22 @@ const modifierPool: ModifierPool = { }, 4), new WeightedModifierType(modifierTypes.BASE_STAT_BOOSTER, 3), new WeightedModifierType(modifierTypes.TERA_SHARD, 1), - new WeightedModifierType(modifierTypes.DNA_SPLICERS, (party: Pokemon[]) => party[0].scene.gameMode.isSplicedOnly && party.filter(p => !p.fusionSpecies).length > 1 ? 4 : 0), - new WeightedModifierType(modifierTypes.VOUCHER, (party: Pokemon[], rerollCount: integer) => !party[0].scene.gameMode.isDaily ? Math.max(1 - rerollCount, 0) : 0, 1), + new WeightedModifierType(modifierTypes.DNA_SPLICERS, (party: Pokemon[]) => globalScene.gameMode.isSplicedOnly && party.filter(p => !p.fusionSpecies).length > 1 ? 4 : 0), + new WeightedModifierType(modifierTypes.VOUCHER, (_party: Pokemon[], rerollCount: integer) => !globalScene.gameMode.isDaily ? Math.max(1 - rerollCount, 0) : 0, 1), ].map(m => { m.setTier(ModifierTier.GREAT); return m; }), [ModifierTier.ULTRA]: [ - new WeightedModifierType(modifierTypes.ULTRA_BALL, (party: Pokemon[]) => (hasMaximumBalls(party, PokeballType.ULTRA_BALL)) ? 0 : 15, 15), + new WeightedModifierType(modifierTypes.ULTRA_BALL, () => (hasMaximumBalls(PokeballType.ULTRA_BALL)) ? 0 : 15, 15), new WeightedModifierType(modifierTypes.MAX_LURE, lureWeightFunc(30, 4)), new WeightedModifierType(modifierTypes.BIG_NUGGET, skipInLastClassicWaveOrDefault(12)), new WeightedModifierType(modifierTypes.PP_MAX, 3), new WeightedModifierType(modifierTypes.MINT, 4), - new WeightedModifierType(modifierTypes.RARE_EVOLUTION_ITEM, (party: Pokemon[]) => Math.min(Math.ceil(party[0].scene.currentBattle.waveIndex / 15) * 4, 32), 32), - new WeightedModifierType(modifierTypes.FORM_CHANGE_ITEM, (party: Pokemon[]) => Math.min(Math.ceil(party[0].scene.currentBattle.waveIndex / 50), 4) * 6, 24), + new WeightedModifierType(modifierTypes.RARE_EVOLUTION_ITEM, () => Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 15) * 4, 32), 32), + new WeightedModifierType(modifierTypes.FORM_CHANGE_ITEM, () => Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 50), 4) * 6, 24), new WeightedModifierType(modifierTypes.AMULET_COIN, skipInLastClassicWaveOrDefault(3)), new WeightedModifierType(modifierTypes.EVIOLITE, (party: Pokemon[]) => { - const { gameMode, gameData } = party[0].scene; + const { gameMode, gameData } = globalScene; if (gameMode.isDaily || (!gameMode.isFreshStartChallenge() && gameData.isUnlocked(Unlockables.EVIOLITE))) { return party.some(p => { // Check if Pokemon's species (or fusion species, if applicable) can evolve or if they're G-Max'd @@ -1823,14 +1822,14 @@ const modifierPool: ModifierPool = { new WeightedModifierType(modifierTypes.EXP_CHARM, skipInLastClassicWaveOrDefault(8)), new WeightedModifierType(modifierTypes.EXP_SHARE, skipInLastClassicWaveOrDefault(10)), new WeightedModifierType(modifierTypes.EXP_BALANCE, skipInLastClassicWaveOrDefault(3)), - new WeightedModifierType(modifierTypes.TERA_ORB, (party: Pokemon[]) => Math.min(Math.max(Math.floor(party[0].scene.currentBattle.waveIndex / 50) * 2, 1), 4), 4), + new WeightedModifierType(modifierTypes.TERA_ORB, () => Math.min(Math.max(Math.floor(globalScene.currentBattle.waveIndex / 50) * 2, 1), 4), 4), new WeightedModifierType(modifierTypes.QUICK_CLAW, 3), new WeightedModifierType(modifierTypes.WIDE_LENS, 4), ].map(m => { m.setTier(ModifierTier.ULTRA); return m; }), [ModifierTier.ROGUE]: [ - new WeightedModifierType(modifierTypes.ROGUE_BALL, (party: Pokemon[]) => (hasMaximumBalls(party, PokeballType.ROGUE_BALL)) ? 0 : 16, 16), + new WeightedModifierType(modifierTypes.ROGUE_BALL, () => (hasMaximumBalls(PokeballType.ROGUE_BALL)) ? 0 : 16, 16), new WeightedModifierType(modifierTypes.RELIC_GOLD, skipInLastClassicWaveOrDefault(2)), new WeightedModifierType(modifierTypes.LEFTOVERS, 3), new WeightedModifierType(modifierTypes.SHELL_BELL, 3), @@ -1840,28 +1839,28 @@ const modifierPool: ModifierPool = { new WeightedModifierType(modifierTypes.BATON, 2), new WeightedModifierType(modifierTypes.SOUL_DEW, 7), //new WeightedModifierType(modifierTypes.OVAL_CHARM, 6), - new WeightedModifierType(modifierTypes.CATCHING_CHARM, (party: Pokemon[]) => !party[0].scene.gameMode.isFreshStartChallenge() && party[0].scene.gameData.getSpeciesCount(d => !!d.caughtAttr) > 100 ? 4 : 0, 4), + new WeightedModifierType(modifierTypes.CATCHING_CHARM, () => !globalScene.gameMode.isFreshStartChallenge() && globalScene.gameData.getSpeciesCount(d => !!d.caughtAttr) > 100 ? 4 : 0, 4), new WeightedModifierType(modifierTypes.ABILITY_CHARM, skipInClassicAfterWave(189, 6)), new WeightedModifierType(modifierTypes.FOCUS_BAND, 5), new WeightedModifierType(modifierTypes.KINGS_ROCK, 3), - new WeightedModifierType(modifierTypes.LOCK_CAPSULE, (party: Pokemon[]) => party[0].scene.gameMode.isClassic ? 0 : 3), + new WeightedModifierType(modifierTypes.LOCK_CAPSULE, () => globalScene.gameMode.isClassic ? 0 : 3), new WeightedModifierType(modifierTypes.SUPER_EXP_CHARM, skipInLastClassicWaveOrDefault(8)), - new WeightedModifierType(modifierTypes.RARE_FORM_CHANGE_ITEM, (party: Pokemon[]) => Math.min(Math.ceil(party[0].scene.currentBattle.waveIndex / 50), 4) * 6, 24), - new WeightedModifierType(modifierTypes.MEGA_BRACELET, (party: Pokemon[]) => Math.min(Math.ceil(party[0].scene.currentBattle.waveIndex / 50), 4) * 9, 36), - new WeightedModifierType(modifierTypes.DYNAMAX_BAND, (party: Pokemon[]) => Math.min(Math.ceil(party[0].scene.currentBattle.waveIndex / 50), 4) * 9, 36), - new WeightedModifierType(modifierTypes.VOUCHER_PLUS, (party: Pokemon[], rerollCount: integer) => !party[0].scene.gameMode.isDaily ? Math.max(3 - rerollCount * 1, 0) : 0, 3), + new WeightedModifierType(modifierTypes.RARE_FORM_CHANGE_ITEM, () => Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 50), 4) * 6, 24), + new WeightedModifierType(modifierTypes.MEGA_BRACELET, () => Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 50), 4) * 9, 36), + new WeightedModifierType(modifierTypes.DYNAMAX_BAND, () => Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 50), 4) * 9, 36), + new WeightedModifierType(modifierTypes.VOUCHER_PLUS, (_party: Pokemon[], rerollCount: integer) => !globalScene.gameMode.isDaily ? Math.max(3 - rerollCount * 1, 0) : 0, 3), ].map(m => { m.setTier(ModifierTier.ROGUE); return m; }), [ModifierTier.MASTER]: [ - new WeightedModifierType(modifierTypes.MASTER_BALL, (party: Pokemon[]) => (hasMaximumBalls(party, PokeballType.MASTER_BALL)) ? 0 : 24, 24), + new WeightedModifierType(modifierTypes.MASTER_BALL, () => (hasMaximumBalls(PokeballType.MASTER_BALL)) ? 0 : 24, 24), new WeightedModifierType(modifierTypes.SHINY_CHARM, 14), new WeightedModifierType(modifierTypes.HEALING_CHARM, 18), 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() && party[0].scene.gameData.isUnlocked(Unlockables.MINI_BLACK_HOLE))) ? 1 : 0, 1), + new WeightedModifierType(modifierTypes.VOUCHER_PREMIUM, (_party: Pokemon[], rerollCount: integer) => + !globalScene.gameMode.isDaily && !globalScene.gameMode.isEndless && !globalScene.gameMode.isSplicedOnly ? Math.max(5 - rerollCount * 2, 0) : 0, 5), + new WeightedModifierType(modifierTypes.DNA_SPLICERS, (party: Pokemon[]) => !globalScene.gameMode.isSplicedOnly && party.filter(p => !p.fusionSpecies).length > 1 ? 24 : 0, 24), + new WeightedModifierType(modifierTypes.MINI_BLACK_HOLE, () => (globalScene.gameMode.isDaily || (!globalScene.gameMode.isFreshStartChallenge() && globalScene.gameData.isUnlocked(Unlockables.MINI_BLACK_HOLE))) ? 1 : 0, 1), ].map(m => { m.setTier(ModifierTier.MASTER); return m; }) @@ -2060,7 +2059,7 @@ export const itemPoolChecks: Map = new Ma export function regenerateModifierPoolThresholds(party: Pokemon[], poolType: ModifierPoolType, rerollCount: integer = 0) { const pool = getModifierPoolForType(poolType); - itemPoolChecks.forEach((v, k) => { + itemPoolChecks.forEach((_v, k) => { itemPoolChecks.set(k, false); }); @@ -2074,14 +2073,14 @@ export function regenerateModifierPoolThresholds(party: Pokemon[], poolType: Mod let i = 0; pool[t].reduce((total: integer, modifierType: WeightedModifierType) => { const weightedModifierType = modifierType as WeightedModifierType; - const existingModifiers = party[0].scene.findModifiers(m => m.type.id === weightedModifierType.modifierType.id, poolType === ModifierPoolType.PLAYER); + const existingModifiers = globalScene.findModifiers(m => m.type.id === weightedModifierType.modifierType.id, poolType === ModifierPoolType.PLAYER); const itemModifierType = weightedModifierType.modifierType instanceof ModifierTypeGenerator ? weightedModifierType.modifierType.generateType(party) : weightedModifierType.modifierType; const weight = !existingModifiers.length || itemModifierType instanceof PokemonHeldItemModifierType || itemModifierType instanceof FormChangeItemModifierType - || existingModifiers.find(m => m.stackCount < m.getMaxStackCount(party[0].scene, true)) + || existingModifiers.find(m => m.stackCount < m.getMaxStackCount(true)) ? weightedModifierType.weight instanceof Function ? (weightedModifierType.weight as Function)(party, rerollCount) : weightedModifierType.weight as integer @@ -2183,7 +2182,7 @@ export function getPlayerModifierTypeOptions(count: integer, party: PlayerPokemo // Guaranteed mod functions second if (customModifierSettings.guaranteedModifierTypeFuncs && customModifierSettings.guaranteedModifierTypeFuncs.length > 0) { - customModifierSettings.guaranteedModifierTypeFuncs!.forEach((mod, i) => { + customModifierSettings.guaranteedModifierTypeFuncs!.forEach((mod, _i) => { const modifierId = Object.keys(modifierTypes).find(k => modifierTypes[k] === mod) as string; let guaranteedMod: ModifierType = modifierTypes[modifierId]?.(); @@ -2302,7 +2301,7 @@ export function getPlayerShopModifierTypeOptionsForWave(waveIndex: integer, base return options.slice(0, Math.ceil(Math.max(waveIndex + 10, 0) / 30)).flat(); } -export function getEnemyBuffModifierForWave(tier: ModifierTier, enemyModifiers: PersistentModifier[], scene: BattleScene): EnemyPersistentModifier { +export function getEnemyBuffModifierForWave(tier: ModifierTier, enemyModifiers: PersistentModifier[]): EnemyPersistentModifier { let tierStackCount: number; switch (tier) { case ModifierTier.ULTRA: @@ -2320,7 +2319,7 @@ export function getEnemyBuffModifierForWave(tier: ModifierTier, enemyModifiers: let candidate = getNewModifierTypeOption([], ModifierPoolType.ENEMY_BUFF, tier); let r = 0; let matchingModifier: PersistentModifier | undefined; - while (++r < retryCount && (matchingModifier = enemyModifiers.find(m => m.type.id === candidate?.type?.id)) && matchingModifier.getMaxStackCount(scene) < matchingModifier.stackCount + (r < 10 ? tierStackCount : 1)) { + while (++r < retryCount && (matchingModifier = enemyModifiers.find(m => m.type.id === candidate?.type?.id)) && matchingModifier.getMaxStackCount() < matchingModifier.stackCount + (r < 10 ? tierStackCount : 1)) { candidate = getNewModifierTypeOption([], ModifierPoolType.ENEMY_BUFF, tier); } @@ -2511,11 +2510,11 @@ export class ModifierTypeOption { * @returns A number between 0 and 14 based on the party's total luck value, or a random number between 0 and 14 if the player is in Daily Run mode. */ export function getPartyLuckValue(party: Pokemon[]): integer { - if (party[0].scene.gameMode.isDaily) { + if (globalScene.gameMode.isDaily) { const DailyLuck = new NumberHolder(0); - party[0].scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { DailyLuck.value = randSeedInt(15); // Random number between 0 and 14 - }, 0, party[0].scene.seed); + }, 0, globalScene.seed); return DailyLuck.value; } const luck = Phaser.Math.Clamp(party.map(p => p.isAllowedInBattle() ? p.getLuck() : 0) diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 05d9e8b9897a..c5e1dfd39463 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -1,4 +1,3 @@ -import type BattleScene from "#app/battle-scene"; import { FusionSpeciesFormEvolution, pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import { getBerryEffectFunc, getBerryPredicate } from "#app/data/berry"; import { getLevelTotalExp } from "#app/data/exp"; @@ -32,6 +31,7 @@ import { type DoubleBattleChanceBoosterModifierType, type EvolutionItemModifierT import { Color, ShadowColor } from "#enums/color"; import { FRIENDSHIP_GAIN_FROM_RARE_CANDY } from "#app/data/balance/starters"; import { applyAbAttrs, CommanderAbAttr } from "#app/data/ability"; +import { globalScene } from "#app/global-scene"; export type ModifierPredicate = (modifier: Modifier) => boolean; @@ -65,8 +65,8 @@ export class ModifierBar extends Phaser.GameObjects.Container { private player: boolean; private modifierCache: PersistentModifier[]; - constructor(scene: BattleScene, enemy?: boolean) { - super(scene, 1 + (enemy ? 302 : 0), 2); + constructor(enemy?: boolean) { + super(globalScene, 1 + (enemy ? 302 : 0), 2); this.player = !enemy; this.setScale(0.5); @@ -80,7 +80,7 @@ export class ModifierBar extends Phaser.GameObjects.Container { updateModifiers(modifiers: PersistentModifier[], hideHeldItems: boolean = false) { this.removeAll(true); - const visibleIconModifiers = modifiers.filter(m => m.isIconVisible(this.scene as BattleScene)); + const visibleIconModifiers = modifiers.filter(m => m.isIconVisible()); const nonPokemonSpecificModifiers = visibleIconModifiers.filter(m => !(m as PokemonHeldItemModifier).pokemonId).sort(modifierSortFunc); const pokemonSpecificModifiers = visibleIconModifiers.filter(m => (m as PokemonHeldItemModifier).pokemonId).sort(modifierSortFunc); @@ -89,7 +89,7 @@ export class ModifierBar extends Phaser.GameObjects.Container { const thisArg = this; sortedVisibleIconModifiers.forEach((modifier: PersistentModifier, i: number) => { - const icon = modifier.getIcon(this.scene as BattleScene); + const icon = modifier.getIcon(); if (i >= iconOverflowIndex) { icon.setVisible(false); } @@ -97,13 +97,13 @@ export class ModifierBar extends Phaser.GameObjects.Container { this.setModifierIconPosition(icon, sortedVisibleIconModifiers.length); icon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 32, 24), Phaser.Geom.Rectangle.Contains); icon.on("pointerover", () => { - (this.scene as BattleScene).ui.showTooltip(modifier.type.name, modifier.type.getDescription(this.scene as BattleScene)); + globalScene.ui.showTooltip(modifier.type.name, modifier.type.getDescription()); if (this.modifierCache && this.modifierCache.length > iconOverflowIndex) { thisArg.updateModifierOverflowVisibility(true); } }); icon.on("pointerout", () => { - (this.scene as BattleScene).ui.hideTooltip(); + globalScene.ui.hideTooltip(); if (this.modifierCache && this.modifierCache.length > iconOverflowIndex) { thisArg.updateModifierOverflowVisibility(false); } @@ -171,10 +171,10 @@ export abstract class PersistentModifier extends Modifier { this.virtualStackCount = 0; } - add(modifiers: PersistentModifier[], virtual: boolean, scene: BattleScene): boolean { + add(modifiers: PersistentModifier[], virtual: boolean): boolean { for (const modifier of modifiers) { if (this.match(modifier)) { - return modifier.incrementStack(scene, this.stackCount, virtual); + return modifier.incrementStack(this.stackCount, virtual); } } @@ -192,8 +192,8 @@ export abstract class PersistentModifier extends Modifier { return []; } - incrementStack(scene: BattleScene, amount: number, virtual: boolean): boolean { - if (this.getStackCount() + amount <= this.getMaxStackCount(scene)) { + incrementStack(amount: number, virtual: boolean): boolean { + if (this.getStackCount() + amount <= this.getMaxStackCount()) { if (!virtual) { this.stackCount += amount; } else { @@ -209,26 +209,26 @@ export abstract class PersistentModifier extends Modifier { return this.stackCount + this.virtualStackCount; } - abstract getMaxStackCount(scene: BattleScene, forThreshold?: boolean): number; + abstract getMaxStackCount(forThreshold?: boolean): number; - isIconVisible(scene: BattleScene): boolean { + isIconVisible(): boolean { return true; } - getIcon(scene: BattleScene, forSummary?: boolean): Phaser.GameObjects.Container { - const container = scene.add.container(0, 0); + getIcon(forSummary?: boolean): Phaser.GameObjects.Container { + const container = globalScene.add.container(0, 0); - const item = scene.add.sprite(0, 12, "items"); + const item = globalScene.add.sprite(0, 12, "items"); item.setFrame(this.type.iconImage); item.setOrigin(0, 0.5); container.add(item); - const stackText = this.getIconStackText(scene); + const stackText = this.getIconStackText(); if (stackText) { container.add(stackText); } - const virtualStackText = this.getIconStackText(scene, true); + const virtualStackText = this.getIconStackText(true); if (virtualStackText) { container.add(virtualStackText); } @@ -236,14 +236,14 @@ export abstract class PersistentModifier extends Modifier { return container; } - getIconStackText(scene: BattleScene, virtual?: boolean): Phaser.GameObjects.BitmapText | null { - if (this.getMaxStackCount(scene) === 1 || (virtual && !this.virtualStackCount)) { + getIconStackText(virtual?: boolean): Phaser.GameObjects.BitmapText | null { + if (this.getMaxStackCount() === 1 || (virtual && !this.virtualStackCount)) { return null; } - const text = scene.add.bitmapText(10, 15, "item-count", this.stackCount.toString(), 11); + const text = globalScene.add.bitmapText(10, 15, "item-count", this.stackCount.toString(), 11); text.letterSpacing = -0.5; - if (this.getStackCount() >= this.getMaxStackCount(scene)) { + if (this.getStackCount() >= this.getMaxStackCount()) { text.setTint(0xf89890); } text.setOrigin(0, 0); @@ -278,8 +278,8 @@ export class AddPokeballModifier extends ConsumableModifier { * @param battleScene {@linkcode BattleScene} * @returns always `true` */ - override apply(battleScene: BattleScene): boolean { - const pokeballCounts = battleScene.pokeballCounts; + override apply(): boolean { + const pokeballCounts = globalScene.pokeballCounts; pokeballCounts[this.pokeballType] = Math.min(pokeballCounts[this.pokeballType] + this.count, MAX_PER_TYPE_POKEBALLS); return true; @@ -302,8 +302,8 @@ export class AddVoucherModifier extends ConsumableModifier { * @param battleScene {@linkcode BattleScene} * @returns always `true` */ - override apply(battleScene: BattleScene): boolean { - const voucherCounts = battleScene.gameData.voucherCounts; + override apply(): boolean { + const voucherCounts = globalScene.gameData.voucherCounts; voucherCounts[this.voucherType] += this.count; return true; @@ -343,13 +343,13 @@ export abstract class LapsingPersistentModifier extends PersistentModifier { * @param _scene N/A * @returns `true` if the modifier was successfully added or applied, false otherwise */ - add(modifiers: PersistentModifier[], _virtual: boolean, scene: BattleScene): boolean { + add(modifiers: PersistentModifier[], _virtual: boolean): boolean { for (const modifier of modifiers) { if (this.match(modifier)) { const modifierInstance = modifier as LapsingPersistentModifier; if (modifierInstance.getBattleCount() < modifierInstance.getMaxBattles()) { modifierInstance.resetBattleCount(); - scene.playSound("se/restore"); + globalScene.playSound("se/restore"); return true; } // should never get here @@ -371,8 +371,8 @@ export abstract class LapsingPersistentModifier extends PersistentModifier { return this.battleCount > 0; } - getIcon(scene: BattleScene): Phaser.GameObjects.Container { - const container = super.getIcon(scene); + getIcon(): Phaser.GameObjects.Container { + const container = super.getIcon(); // Linear interpolation on hue const hue = Math.floor(120 * (this.battleCount / this.maxBattles) + 5); @@ -381,7 +381,7 @@ export abstract class LapsingPersistentModifier extends PersistentModifier { const typeHex = hslToHex(hue, 0.5, 0.9); const strokeHex = hslToHex(hue, 0.7, 0.3); - const battleCountText = addTextObject(scene, 27, 0, this.battleCount.toString(), TextStyle.PARTY, { + const battleCountText = addTextObject(27, 0, this.battleCount.toString(), TextStyle.PARTY, { fontSize: "66px", color: typeHex, }); @@ -393,7 +393,7 @@ export abstract class LapsingPersistentModifier extends PersistentModifier { return container; } - getIconStackText(_scene: BattleScene, _virtual?: boolean): Phaser.GameObjects.BitmapText | null { + getIconStackText(_virtual?: boolean): Phaser.GameObjects.BitmapText | null { return null; } @@ -421,7 +421,7 @@ export abstract class LapsingPersistentModifier extends PersistentModifier { return [ this.maxBattles, this.battleCount ]; } - getMaxStackCount(_scene: BattleScene, _forThreshold?: boolean): number { + getMaxStackCount(_forThreshold?: boolean): number { // Must be an abitrary number greater than 1 return 2; } @@ -574,7 +574,7 @@ export class MapModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 1; } } @@ -592,7 +592,7 @@ export class MegaEvolutionAccessModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 1; } } @@ -615,7 +615,7 @@ export class GigantamaxAccessModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 1; } } @@ -638,7 +638,7 @@ export class TerastallizeAccessModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 1; } } @@ -680,33 +680,33 @@ export abstract class PokemonHeldItemModifier extends PersistentModifier { return !!pokemon && (this.pokemonId === -1 || pokemon.id === this.pokemonId); } - isIconVisible(scene: BattleScene): boolean { - return !!(this.getPokemon(scene)?.isOnField()); + isIconVisible(): boolean { + return !!(this.getPokemon()?.isOnField()); } - getIcon(scene: BattleScene, forSummary?: boolean): Phaser.GameObjects.Container { - const container = !forSummary ? scene.add.container(0, 0) : super.getIcon(scene); + getIcon(forSummary?: boolean): Phaser.GameObjects.Container { + const container = !forSummary ? globalScene.add.container(0, 0) : super.getIcon(); if (!forSummary) { - const pokemon = this.getPokemon(scene); + const pokemon = this.getPokemon(); if (pokemon) { - const pokemonIcon = scene.addPokemonIcon(pokemon, -2, 10, 0, 0.5); + const pokemonIcon = globalScene.addPokemonIcon(pokemon, -2, 10, 0, 0.5); container.add(pokemonIcon); container.setName(pokemon.id.toString()); } - const item = scene.add.sprite(16, this.virtualStackCount ? 8 : 16, "items"); + const item = globalScene.add.sprite(16, this.virtualStackCount ? 8 : 16, "items"); item.setScale(0.5); item.setOrigin(0, 0.5); item.setTexture("items", this.type.iconImage); container.add(item); - const stackText = this.getIconStackText(scene); + const stackText = this.getIconStackText(); if (stackText) { container.add(stackText); } - const virtualStackText = this.getIconStackText(scene, true); + const virtualStackText = this.getIconStackText(true); if (virtualStackText) { container.add(virtualStackText); } @@ -717,21 +717,21 @@ export abstract class PokemonHeldItemModifier extends PersistentModifier { return container; } - getPokemon(scene: BattleScene): Pokemon | undefined { - return this.pokemonId ? scene.getPokemonById(this.pokemonId) ?? undefined : undefined; + getPokemon(): Pokemon | undefined { + return this.pokemonId ? globalScene.getPokemonById(this.pokemonId) ?? undefined : undefined; } getScoreMultiplier(): number { return 1; } - getMaxStackCount(scene: BattleScene, forThreshold?: boolean): number { - const pokemon = this.getPokemon(scene); + getMaxStackCount(forThreshold?: boolean): number { + const pokemon = this.getPokemon(); if (!pokemon) { return 0; } if (pokemon.isPlayer() && forThreshold) { - return scene.getPlayerParty().map(p => this.getMaxHeldItemCount(p)).reduce((stackCount: number, maxStackCount: number) => Math.max(stackCount, maxStackCount), 0); + return globalScene.getPlayerParty().map(p => this.getMaxHeldItemCount(p)).reduce((stackCount: number, maxStackCount: number) => Math.max(stackCount, maxStackCount), 0); } return this.getMaxHeldItemCount(pokemon); } @@ -760,15 +760,14 @@ export abstract class LapsingPokemonHeldItemModifier extends PokemonHeldItemModi /** * Retrieve the {@linkcode Modifier | Modifiers} icon as a {@linkcode Phaser.GameObjects.Container | Container} - * @param scene The {@linkcode BattleScene} * @param forSummary `true` if the icon is for the summary screen * @returns the icon as a {@linkcode Phaser.GameObjects.Container | Container} */ - public getIcon(scene: BattleScene, forSummary?: boolean): Phaser.GameObjects.Container { - const container = super.getIcon(scene, forSummary); + public getIcon(forSummary?: boolean): Phaser.GameObjects.Container { + const container = super.getIcon(forSummary); - if (this.getPokemon(scene)?.isPlayer()) { - const battleCountText = addTextObject(scene, 27, 0, this.battlesLeft.toString(), TextStyle.PARTY, { fontSize: "66px", color: Color.PINK }); + if (this.getPokemon()?.isPlayer()) { + const battleCountText = addTextObject(27, 0, this.battlesLeft.toString(), TextStyle.PARTY, { fontSize: "66px", color: Color.PINK }); battleCountText.setShadow(0, 0); battleCountText.setStroke(ShadowColor.RED, 16); battleCountText.setOrigin(1, 0); @@ -782,7 +781,7 @@ export abstract class LapsingPokemonHeldItemModifier extends PokemonHeldItemModi return this.battlesLeft; } - getMaxStackCount(scene: BattleScene, forThreshold?: boolean): number { + getMaxStackCount(forThreshold?: boolean): number { return 1; } } @@ -820,10 +819,10 @@ export class TerastallizeModifier extends LapsingPokemonHeldItemModifier { */ override apply(pokemon: Pokemon): boolean { if (pokemon.isPlayer()) { - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeTeraTrigger); - pokemon.scene.validateAchv(achvs.TERASTALLIZE); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeTeraTrigger); + globalScene.validateAchv(achvs.TERASTALLIZE); if (this.teraType === Type.STELLAR) { - pokemon.scene.validateAchv(achvs.STELLAR_TERASTALLIZE); + globalScene.validateAchv(achvs.STELLAR_TERASTALLIZE); } } pokemon.updateSpritePipelineData(); @@ -838,7 +837,7 @@ export class TerastallizeModifier extends LapsingPokemonHeldItemModifier { public override lapse(pokemon: Pokemon): boolean { const ret = super.lapse(pokemon); if (!ret) { - pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeLapseTeraTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeLapseTeraTrigger); pokemon.updateSpritePipelineData(); } return ret; @@ -944,19 +943,19 @@ export class EvoTrackerModifier extends PokemonHeldItemModifier { return true; } - getIconStackText(scene: BattleScene, virtual?: boolean): Phaser.GameObjects.BitmapText | null { - if (this.getMaxStackCount(scene) === 1 || (virtual && !this.virtualStackCount)) { + getIconStackText(virtual?: boolean): Phaser.GameObjects.BitmapText | null { + if (this.getMaxStackCount() === 1 || (virtual && !this.virtualStackCount)) { return null; } - const pokemon = scene.getPokemonById(this.pokemonId); + const pokemon = globalScene.getPokemonById(this.pokemonId); this.stackCount = pokemon ? pokemon.evoCounter + pokemon.getHeldItems().filter(m => m instanceof DamageMoneyRewardModifier).length - + pokemon.scene.findModifiers(m => m instanceof MoneyMultiplierModifier || m instanceof ExtraModifierModifier || m instanceof TempExtraModifierModifier).length + + globalScene.findModifiers(m => m instanceof MoneyMultiplierModifier || m instanceof ExtraModifierModifier || m instanceof TempExtraModifierModifier).length : this.stackCount; - const text = scene.add.bitmapText(10, 15, "item-count", this.stackCount.toString(), 11); + const text = globalScene.add.bitmapText(10, 15, "item-count", this.stackCount.toString(), 11); text.letterSpacing = -0.5; if (this.getStackCount() >= this.required) { text.setTint(0xf89890); @@ -968,7 +967,7 @@ export class EvoTrackerModifier extends PokemonHeldItemModifier { getMaxHeldItemCount(pokemon: Pokemon): number { this.stackCount = pokemon.evoCounter + pokemon.getHeldItems().filter(m => m instanceof DamageMoneyRewardModifier).length - + pokemon.scene.findModifiers(m => m instanceof MoneyMultiplierModifier || m instanceof ExtraModifierModifier || m instanceof TempExtraModifierModifier).length; + + globalScene.findModifiers(m => m instanceof MoneyMultiplierModifier || m instanceof ExtraModifierModifier || m instanceof TempExtraModifierModifier).length; return 999; } } @@ -1536,7 +1535,7 @@ export class SurviveDamageModifier extends PokemonHeldItemModifier { if (!surviveDamage.value && pokemon.randSeedInt(10) < this.getStackCount()) { surviveDamage.value = true; - pokemon.scene.queueMessage(i18next.t("modifier:surviveDamageApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name })); + globalScene.queueMessage(i18next.t("modifier:surviveDamageApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name })); return true; } @@ -1580,11 +1579,11 @@ export class BypassSpeedChanceModifier extends PokemonHeldItemModifier { override apply(pokemon: Pokemon, doBypassSpeed: BooleanHolder): boolean { if (!doBypassSpeed.value && pokemon.randSeedInt(10) < this.getStackCount()) { doBypassSpeed.value = true; - const isCommandFight = pokemon.scene.currentBattle.turnCommands[pokemon.getBattlerIndex()]?.command === Command.FIGHT; + const isCommandFight = globalScene.currentBattle.turnCommands[pokemon.getBattlerIndex()]?.command === Command.FIGHT; const hasQuickClaw = this.type instanceof PokemonHeldItemModifierType && this.type.id === "QUICK_CLAW"; if (isCommandFight && hasQuickClaw) { - pokemon.scene.queueMessage(i18next.t("modifier:bypassSpeedChanceApply", { pokemonName: getPokemonNameWithAffix(pokemon), itemName: i18next.t("modifierType:ModifierType.QUICK_CLAW.name") })); + globalScene.queueMessage(i18next.t("modifier:bypassSpeedChanceApply", { pokemonName: getPokemonNameWithAffix(pokemon), itemName: i18next.t("modifierType:ModifierType.QUICK_CLAW.name") })); } return true; } @@ -1668,8 +1667,7 @@ export class TurnHealModifier extends PokemonHeldItemModifier { */ override apply(pokemon: Pokemon): boolean { if (!pokemon.isFullHp()) { - const scene = pokemon.scene; - scene.unshiftPhase(new PokemonHealPhase(scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), toDmgValue(pokemon.getMaxHp() / 16) * this.stackCount, i18next.t("modifier:turnHealApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name }), true)); return true; } @@ -1761,8 +1759,7 @@ export class HitHealModifier extends PokemonHeldItemModifier { */ override apply(pokemon: Pokemon): boolean { if (pokemon.turnData.totalDamageDealt && !pokemon.isFullHp()) { - const scene = pokemon.scene; - scene.unshiftPhase(new PokemonHealPhase(scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), toDmgValue(pokemon.turnData.totalDamageDealt / 8) * this.stackCount, i18next.t("modifier:hitHealApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name }), true)); } @@ -1807,7 +1804,7 @@ export class LevelIncrementBoosterModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene, forThreshold?: boolean): number { + getMaxStackCount(forThreshold?: boolean): number { return 99; } } @@ -1851,7 +1848,7 @@ export class BerryModifier extends PokemonHeldItemModifier { */ override apply(pokemon: Pokemon): boolean { const preserve = new BooleanHolder(false); - pokemon.scene.applyModifiers(PreserveBerryModifier, pokemon.isPlayer(), pokemon, preserve); + globalScene.applyModifiers(PreserveBerryModifier, pokemon.isPlayer(), pokemon, preserve); getBerryEffectFunc(this.berryType)(pokemon); if (!preserve.value) { @@ -1906,7 +1903,7 @@ export class PreserveBerryModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 3; } } @@ -1931,14 +1928,14 @@ export class PokemonInstantReviveModifier extends PokemonHeldItemModifier { */ override apply(pokemon: Pokemon): boolean { // Restore the Pokemon to half HP - pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), toDmgValue(pokemon.getMaxHp() / 2), i18next.t("modifier:pokemonInstantReviveApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name }), false, false, true)); // Remove the Pokemon's FAINT status pokemon.resetStatus(true, false, true); // Reapply Commander on the Pokemon's side of the field, if applicable - const field = pokemon.isPlayer() ? pokemon.scene.getPlayerField() : pokemon.scene.getEnemyField(); + const field = pokemon.isPlayer() ? globalScene.getPlayerField() : globalScene.getEnemyField(); field.forEach((p) => applyAbAttrs(CommanderAbAttr, p, null, false)); return true; } @@ -1984,7 +1981,7 @@ export class ResetNegativeStatStageModifier extends PokemonHeldItemModifier { } if (statRestored) { - pokemon.scene.queueMessage(i18next.t("modifier:resetNegativeStatStageApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name })); + globalScene.queueMessage(i18next.t("modifier:resetNegativeStatStageApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name })); } return statRestored; } @@ -2020,8 +2017,8 @@ export abstract class ConsumablePokemonModifier extends ConsumableModifier { */ abstract override apply(playerPokemon: PlayerPokemon, ...args: unknown[]): boolean | Promise; - getPokemon(scene: BattleScene) { - return scene.getPlayerParty().find(p => p.id === this.pokemonId); + getPokemon() { + return globalScene.getPlayerParty().find(p => p.id === this.pokemonId); } } @@ -2189,7 +2186,7 @@ export class PokemonNatureChangeModifier extends ConsumablePokemonModifier { */ override apply(playerPokemon: PlayerPokemon): boolean { playerPokemon.setCustomNature(this.nature); - playerPokemon.scene.gameData.unlockSpeciesNature(playerPokemon.species, this.nature); + globalScene.gameData.unlockSpeciesNature(playerPokemon.species, this.nature); return true; } @@ -2207,17 +2204,17 @@ export class PokemonLevelIncrementModifier extends ConsumablePokemonModifier { * @returns always `true` */ override apply(playerPokemon: PlayerPokemon, levelCount: NumberHolder = new NumberHolder(1)): boolean { - playerPokemon.scene.applyModifiers(LevelIncrementBoosterModifier, true, levelCount); + globalScene.applyModifiers(LevelIncrementBoosterModifier, true, levelCount); playerPokemon.level += levelCount.value; - if (playerPokemon.level <= playerPokemon.scene.getMaxExpLevel(true)) { + if (playerPokemon.level <= globalScene.getMaxExpLevel(true)) { playerPokemon.exp = getLevelTotalExp(playerPokemon.level, playerPokemon.species.growthRate); playerPokemon.levelExp = 0; } playerPokemon.addFriendship(FRIENDSHIP_GAIN_FROM_RARE_CANDY); - playerPokemon.scene.unshiftPhase(new LevelUpPhase(playerPokemon.scene, playerPokemon.scene.getPlayerParty().indexOf(playerPokemon), playerPokemon.level - levelCount.value, playerPokemon.level)); + globalScene.unshiftPhase(new LevelUpPhase(globalScene.getPlayerParty().indexOf(playerPokemon), playerPokemon.level - levelCount.value, playerPokemon.level)); return true; } @@ -2237,7 +2234,7 @@ export class TmModifier extends ConsumablePokemonModifier { */ override apply(playerPokemon: PlayerPokemon): boolean { - playerPokemon.scene.unshiftPhase(new LearnMovePhase(playerPokemon.scene, playerPokemon.scene.getPlayerParty().indexOf(playerPokemon), this.type.moveId, LearnMoveType.TM)); + globalScene.unshiftPhase(new LearnMovePhase(globalScene.getPlayerParty().indexOf(playerPokemon), this.type.moveId, LearnMoveType.TM)); return true; } @@ -2259,7 +2256,7 @@ export class RememberMoveModifier extends ConsumablePokemonModifier { */ override apply(playerPokemon: PlayerPokemon, cost?: number): boolean { - playerPokemon.scene.unshiftPhase(new LearnMovePhase(playerPokemon.scene, playerPokemon.scene.getPlayerParty().indexOf(playerPokemon), playerPokemon.getLearnableLevelMoves()[this.levelMoveIndex], LearnMoveType.MEMORY, cost)); + globalScene.unshiftPhase(new LearnMovePhase(globalScene.getPlayerParty().indexOf(playerPokemon), playerPokemon.getLearnableLevelMoves()[this.levelMoveIndex], LearnMoveType.MEMORY, cost)); return true; } @@ -2294,7 +2291,7 @@ export class EvolutionItemModifier extends ConsumablePokemonModifier { } if (matchingEvolution) { - playerPokemon.scene.unshiftPhase(new EvolutionPhase(playerPokemon.scene, playerPokemon, matchingEvolution, playerPokemon.level - 1)); + globalScene.unshiftPhase(new EvolutionPhase(playerPokemon, matchingEvolution, playerPokemon.level - 1)); return true; } @@ -2354,7 +2351,7 @@ export class MultipleParticipantExpBonusModifier extends PersistentModifier { return new MultipleParticipantExpBonusModifier(this.type, this.stackCount); } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 5; } } @@ -2391,7 +2388,7 @@ export class HealingBoosterModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 5; } } @@ -2432,7 +2429,7 @@ export class ExpBoosterModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene, forThreshold?: boolean): number { + getMaxStackCount(forThreshold?: boolean): number { return this.boostMultiplier < 1 ? this.boostMultiplier < 0.6 ? 99 : 30 : 10; } } @@ -2511,7 +2508,7 @@ export class ExpShareModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 5; } } @@ -2537,7 +2534,7 @@ export class ExpBalanceModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 4; } } @@ -2774,7 +2771,7 @@ export class PokemonFormChangeItemModifier extends PokemonHeldItemModifier { this.active = false; } - const ret = pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeItemTrigger); + const ret = globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeItemTrigger); if (switchActive) { this.active = true; @@ -2799,21 +2796,20 @@ export class MoneyRewardModifier extends ConsumableModifier { /** * Applies {@linkcode MoneyRewardModifier} - * @param battleScene The current {@linkcode BattleScene} * @returns always `true` */ - override apply(battleScene: BattleScene): boolean { - const moneyAmount = new NumberHolder(battleScene.getWaveMoneyAmount(this.moneyMultiplier)); + override apply(): boolean { + const moneyAmount = new NumberHolder(globalScene.getWaveMoneyAmount(this.moneyMultiplier)); - battleScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); + globalScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); - battleScene.addMoney(moneyAmount.value); + globalScene.addMoney(moneyAmount.value); - battleScene.getPlayerParty().map(p => { + globalScene.getPlayerParty().map(p => { if (p.species?.speciesId === Species.GIMMIGHOUL || p.fusionSpecies?.speciesId === Species.GIMMIGHOUL) { p.evoCounter ? p.evoCounter += Math.min(Math.floor(this.moneyMultiplier), 3) : p.evoCounter = Math.min(Math.floor(this.moneyMultiplier), 3); const modifier = getModifierType(modifierTypes.EVOLUTION_TRACKER_GIMMIGHOUL).newModifier(p) as EvoTrackerModifier; - battleScene.addModifier(modifier); + globalScene.addModifier(modifier); } }); @@ -2845,7 +2841,7 @@ export class MoneyMultiplierModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 5; } } @@ -2870,10 +2866,9 @@ export class DamageMoneyRewardModifier extends PokemonHeldItemModifier { * @returns always `true` */ override apply(pokemon: Pokemon, multiplier: NumberHolder): boolean { - const battleScene = pokemon.scene; const moneyAmount = new NumberHolder(Math.floor(multiplier.value * (0.5 * this.getStackCount()))); - battleScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); - battleScene.addMoney(moneyAmount.value); + globalScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); + globalScene.addMoney(moneyAmount.value); return true; } @@ -2894,17 +2889,16 @@ export class MoneyInterestModifier extends PersistentModifier { /** * Applies {@linkcode MoneyInterestModifier} - * @param battleScene The current {@linkcode BattleScene} * @returns always `true` */ - override apply(battleScene: BattleScene): boolean { - const interestAmount = Math.floor(battleScene.money * 0.1 * this.getStackCount()); - battleScene.addMoney(interestAmount); + override apply(): boolean { + const interestAmount = Math.floor(globalScene.money * 0.1 * this.getStackCount()); + globalScene.addMoney(interestAmount); const userLocale = navigator.language || "en-US"; const formattedMoneyAmount = interestAmount.toLocaleString(userLocale); const message = i18next.t("modifier:moneyInterestApply", { moneyAmount: formattedMoneyAmount, typeName: this.type.name }); - battleScene.queueMessage(message, undefined, true); + globalScene.queueMessage(message, undefined, true); return true; } @@ -2913,7 +2907,7 @@ export class MoneyInterestModifier extends PersistentModifier { return new MoneyInterestModifier(this.type, this.stackCount); } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 5; } } @@ -2942,7 +2936,7 @@ export class HiddenAbilityRateBoosterModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 4; } } @@ -2971,7 +2965,7 @@ export class ShinyRateBoosterModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 4; } } @@ -3003,7 +2997,7 @@ export class CriticalCatchChanceBoosterModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 3; } } @@ -3029,7 +3023,7 @@ export class LockModifierTiersModifier extends PersistentModifier { return new LockModifierTiersModifier(this.type, this.stackCount); } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 1; } } @@ -3069,7 +3063,7 @@ export class HealShopCostModifier extends PersistentModifier { return super.getArgs().concat(this.shopMultiplier); } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 1; } } @@ -3095,7 +3089,7 @@ export class BoostBugSpawnModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 1; } } @@ -3173,7 +3167,7 @@ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier { const poolType = pokemon.isPlayer() ? ModifierPoolType.PLAYER : pokemon.hasTrainer() ? ModifierPoolType.TRAINER : ModifierPoolType.WILD; const transferredModifierTypes: ModifierType[] = []; - const itemModifiers = pokemon.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const itemModifiers = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === targetPokemon.id && m.isTransferable, targetPokemon.isPlayer()) as PokemonHeldItemModifier[]; let highestItemTier = itemModifiers.map(m => m.type.getOrInferTier(poolType)).reduce((highestTier, tier) => Math.max(tier!, highestTier), 0); // TODO: is this bang correct? let tierItemModifiers = itemModifiers.filter(m => m.type.getOrInferTier(poolType) === highestItemTier); @@ -3191,7 +3185,7 @@ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier { } const randItemIndex = pokemon.randSeedInt(itemModifiers.length); const randItem = itemModifiers[randItemIndex]; - heldItemTransferPromises.push(pokemon.scene.tryTransferHeldItemModifier(randItem, pokemon, false).then(success => { + heldItemTransferPromises.push(globalScene.tryTransferHeldItemModifier(randItem, pokemon, false).then(success => { if (success) { transferredModifierTypes.push(randItem.type); itemModifiers.splice(randItemIndex, 1); @@ -3201,7 +3195,7 @@ export abstract class HeldItemTransferModifier extends PokemonHeldItemModifier { Promise.all(heldItemTransferPromises).then(() => { for (const mt of transferredModifierTypes) { - pokemon.scene.queueMessage(this.getTransferMessage(pokemon, targetPokemon, mt)); + globalScene.queueMessage(this.getTransferMessage(pokemon, targetPokemon, mt)); } }); @@ -3320,7 +3314,7 @@ export class IvScannerModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 3; } } @@ -3349,7 +3343,7 @@ export class ExtraModifierModifier extends PersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 3; } } @@ -3370,17 +3364,16 @@ export class TempExtraModifierModifier extends LapsingPersistentModifier { * If no existing Silver Pokeballs are found, will add a new one. * @param modifiers {@linkcode PersistentModifier} array of the player's modifiers * @param _virtual N/A - * @param scene * @returns true if the modifier was successfully added or applied, false otherwise */ - add(modifiers: PersistentModifier[], _virtual: boolean, scene: BattleScene): boolean { + add(modifiers: PersistentModifier[], _virtual: boolean): boolean { for (const modifier of modifiers) { if (this.match(modifier)) { const modifierInstance = modifier as TempExtraModifierModifier; const newBattleCount = this.getMaxBattles() + modifierInstance.getBattleCount(); modifierInstance.setNewBattleCount(newBattleCount); - scene.playSound("se/restore"); + globalScene.playSound("se/restore"); return true; } } @@ -3413,7 +3406,7 @@ export abstract class EnemyPersistentModifier extends PersistentModifier { super(type, stackCount); } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 5; } } @@ -3438,7 +3431,7 @@ abstract class EnemyDamageMultiplierModifier extends EnemyPersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 99; } } @@ -3461,7 +3454,7 @@ export class EnemyDamageBoosterModifier extends EnemyDamageMultiplierModifier { return [ (this.damageMultiplier - 1) * 100 ]; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 999; } } @@ -3484,8 +3477,8 @@ export class EnemyDamageReducerModifier extends EnemyDamageMultiplierModifier { return [ (1 - this.damageMultiplier) * 100 ]; } - getMaxStackCount(scene: BattleScene): number { - return scene.currentBattle.waveIndex < 2000 ? super.getMaxStackCount(scene) : 999; + getMaxStackCount(): number { + return globalScene.currentBattle.waveIndex < 2000 ? super.getMaxStackCount() : 999; } } @@ -3518,8 +3511,7 @@ export class EnemyTurnHealModifier extends EnemyPersistentModifier { */ override apply(enemyPokemon: Pokemon): boolean { if (!enemyPokemon.isFullHp()) { - const scene = enemyPokemon.scene; - scene.unshiftPhase(new PokemonHealPhase(scene, enemyPokemon.getBattlerIndex(), + globalScene.unshiftPhase(new PokemonHealPhase(enemyPokemon.getBattlerIndex(), Math.max(Math.floor(enemyPokemon.getMaxHp() / (100 / this.healPercent)) * this.stackCount, 1), i18next.t("modifier:enemyTurnHealApply", { pokemonNameWithAffix: getPokemonNameWithAffix(enemyPokemon) }), true, false, false, false, true)); return true; } @@ -3527,7 +3519,7 @@ export class EnemyTurnHealModifier extends EnemyPersistentModifier { return false; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 10; } } @@ -3569,7 +3561,7 @@ export class EnemyAttackStatusEffectChanceModifier extends EnemyPersistentModifi return false; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 10; } } @@ -3603,7 +3595,7 @@ export class EnemyStatusEffectHealChanceModifier extends EnemyPersistentModifier */ override apply(enemyPokemon: Pokemon): boolean { if (enemyPokemon.status && Phaser.Math.RND.realInRange(0, 1) < (this.chance * this.getStackCount())) { - enemyPokemon.scene.queueMessage(getStatusEffectHealText(enemyPokemon.status.effect, getPokemonNameWithAffix(enemyPokemon))); + globalScene.queueMessage(getStatusEffectHealText(enemyPokemon.status.effect, getPokemonNameWithAffix(enemyPokemon))); enemyPokemon.resetStatus(); enemyPokemon.updateInfo(); return true; @@ -3612,7 +3604,7 @@ export class EnemyStatusEffectHealChanceModifier extends EnemyPersistentModifier return false; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 10; } } @@ -3656,7 +3648,7 @@ export class EnemyEndureChanceModifier extends EnemyPersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 10; } } @@ -3697,7 +3689,7 @@ export class EnemyFusionChanceModifier extends EnemyPersistentModifier { return true; } - getMaxStackCount(scene: BattleScene): number { + getMaxStackCount(): number { return 10; } } @@ -3706,18 +3698,17 @@ export class EnemyFusionChanceModifier extends EnemyPersistentModifier { * Uses either `MODIFIER_OVERRIDE` in overrides.ts to set {@linkcode PersistentModifier}s for either: * - The player * - The enemy - * @param scene current {@linkcode BattleScene} * @param isPlayer {@linkcode boolean} for whether the player (`true`) or enemy (`false`) is being overridden */ -export function overrideModifiers(scene: BattleScene, isPlayer: boolean = true): void { +export function overrideModifiers(isPlayer: boolean = true): void { const modifiersOverride: ModifierOverride[] = isPlayer ? Overrides.STARTING_MODIFIER_OVERRIDE : Overrides.OPP_MODIFIER_OVERRIDE; - if (!modifiersOverride || modifiersOverride.length === 0 || !scene) { + if (!modifiersOverride || modifiersOverride.length === 0 || !globalScene) { return; } // If it's the opponent, clear all of their current modifiers to avoid stacking if (!isPlayer) { - scene.clearEnemyModifiers(); + globalScene.clearEnemyModifiers(); } modifiersOverride.forEach(item => { @@ -3734,9 +3725,9 @@ export function overrideModifiers(scene: BattleScene, isPlayer: boolean = true): modifier.stackCount = item.count || 1; if (isPlayer) { - scene.addModifier(modifier, true, false, false, true); + globalScene.addModifier(modifier, true, false, false, true); } else { - scene.addEnemyModifier(modifier, true, true); + globalScene.addEnemyModifier(modifier, true, true); } } }); @@ -3746,18 +3737,17 @@ export function overrideModifiers(scene: BattleScene, isPlayer: boolean = true): * Uses either `HELD_ITEMS_OVERRIDE` in overrides.ts to set {@linkcode PokemonHeldItemModifier}s for either: * - The first member of the player's team when starting a new game * - An enemy {@linkcode Pokemon} being spawned in - * @param scene current {@linkcode BattleScene} * @param pokemon {@linkcode Pokemon} whose held items are being overridden * @param isPlayer {@linkcode boolean} for whether the {@linkcode pokemon} is the player's (`true`) or an enemy (`false`) */ -export function overrideHeldItems(scene: BattleScene, pokemon: Pokemon, isPlayer: boolean = true): void { +export function overrideHeldItems(pokemon: Pokemon, isPlayer: boolean = true): void { const heldItemsOverride: ModifierOverride[] = isPlayer ? Overrides.STARTING_HELD_ITEMS_OVERRIDE : Overrides.OPP_HELD_ITEMS_OVERRIDE; - if (!heldItemsOverride || heldItemsOverride.length === 0 || !scene) { + if (!heldItemsOverride || heldItemsOverride.length === 0 || !globalScene) { return; } if (!isPlayer) { - scene.clearEnemyHeldItemModifiers(pokemon); + globalScene.clearEnemyHeldItemModifiers(pokemon); } heldItemsOverride.forEach(item => { @@ -3775,9 +3765,9 @@ export function overrideHeldItems(scene: BattleScene, pokemon: Pokemon, isPlayer heldItemModifier.pokemonId = pokemon.id; heldItemModifier.stackCount = qty; if (isPlayer) { - scene.addModifier(heldItemModifier, true, false, false, true); + globalScene.addModifier(heldItemModifier, true, false, false, true); } else { - scene.addEnemyModifier(heldItemModifier, true, true); + globalScene.addEnemyModifier(heldItemModifier, true, true); } } }); diff --git a/src/phase.ts b/src/phase.ts index 5cf91f2c478a..8da00d78b61b 100644 --- a/src/phase.ts +++ b/src/phase.ts @@ -1,19 +1,13 @@ -import BattleScene from "./battle-scene"; +import { globalScene } from "#app/global-scene"; export class Phase { - protected scene: BattleScene; - - constructor(scene: BattleScene) { - this.scene = scene; - } - start() { - if (this.scene.abilityBar.shown) { - this.scene.abilityBar.resetAutoHideTimer(); + if (globalScene.abilityBar.shown) { + globalScene.abilityBar.resetAutoHideTimer(); } } end() { - this.scene.shiftPhase(); + globalScene.shiftPhase(); } } diff --git a/src/phases/add-enemy-buff-modifier-phase.ts b/src/phases/add-enemy-buff-modifier-phase.ts index 451e6e2662c9..d79b4f6eca5e 100644 --- a/src/phases/add-enemy-buff-modifier-phase.ts +++ b/src/phases/add-enemy-buff-modifier-phase.ts @@ -1,26 +1,26 @@ -import BattleScene from "#app/battle-scene"; import { ModifierTier } from "#app/modifier/modifier-tier"; import { regenerateModifierPoolThresholds, ModifierPoolType, getEnemyBuffModifierForWave } from "#app/modifier/modifier-type"; import { EnemyPersistentModifier } from "#app/modifier/modifier"; import { Phase } from "#app/phase"; +import { globalScene } from "#app/global-scene"; export class AddEnemyBuffModifierPhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - const waveIndex = this.scene.currentBattle.waveIndex; + const waveIndex = globalScene.currentBattle.waveIndex; const tier = !(waveIndex % 1000) ? ModifierTier.ULTRA : !(waveIndex % 250) ? ModifierTier.GREAT : ModifierTier.COMMON; - regenerateModifierPoolThresholds(this.scene.getEnemyParty(), ModifierPoolType.ENEMY_BUFF); + regenerateModifierPoolThresholds(globalScene.getEnemyParty(), ModifierPoolType.ENEMY_BUFF); const count = Math.ceil(waveIndex / 250); for (let i = 0; i < count; i++) { - this.scene.addEnemyModifier(getEnemyBuffModifierForWave(tier, this.scene.findModifiers(m => m instanceof EnemyPersistentModifier, false), this.scene), true, true); + globalScene.addEnemyModifier(getEnemyBuffModifierForWave(tier, globalScene.findModifiers(m => m instanceof EnemyPersistentModifier, false)), true, true); } - this.scene.updateModifiers(false, true).then(() => this.end()); + globalScene.updateModifiers(false, true).then(() => this.end()); } } diff --git a/src/phases/attempt-capture-phase.ts b/src/phases/attempt-capture-phase.ts index de10d1eca45f..540a6a6d5c49 100644 --- a/src/phases/attempt-capture-phase.ts +++ b/src/phases/attempt-capture-phase.ts @@ -1,5 +1,4 @@ import { BattlerIndex } from "#app/battle"; -import BattleScene from "#app/battle-scene"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; import { SubstituteTag } from "#app/data/battler-tags"; import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor, getCriticalCaptureChance } from "#app/data/pokeball"; @@ -17,14 +16,15 @@ import { Mode } from "#app/ui/ui"; import { PokeballType } from "#enums/pokeball"; import { StatusEffect } from "#enums/status-effect"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; export class AttemptCapturePhase extends PokemonPhase { private pokeballType: PokeballType; private pokeball: Phaser.GameObjects.Sprite; private originalY: number; - constructor(scene: BattleScene, targetIndex: integer, pokeballType: PokeballType) { - super(scene, BattlerIndex.ENEMY + targetIndex); + constructor(targetIndex: integer, pokeballType: PokeballType) { + super(BattlerIndex.ENEMY + targetIndex); this.pokeballType = pokeballType; } @@ -43,7 +43,7 @@ export class AttemptCapturePhase extends PokemonPhase { substitute.sprite.setVisible(false); } - this.scene.pokeballCounts[this.pokeballType]--; + globalScene.pokeballCounts[this.pokeballType]--; this.originalY = pokemon.y; @@ -54,21 +54,21 @@ export class AttemptCapturePhase extends PokemonPhase { const statusMultiplier = pokemon.status ? getStatusEffectCatchRateMultiplier(pokemon.status.effect) : 1; const modifiedCatchRate = Math.round((((_3m - _2h) * catchRate * pokeballMultiplier) / _3m) * statusMultiplier); const shakeProbability = Math.round(65536 / Math.pow((255 / modifiedCatchRate), 0.1875)); // Formula taken from gen 6 - const criticalCaptureChance = getCriticalCaptureChance(this.scene, modifiedCatchRate); + const criticalCaptureChance = getCriticalCaptureChance(modifiedCatchRate); const isCritical = pokemon.randSeedInt(256) < criticalCaptureChance; const fpOffset = pokemon.getFieldPositionOffset(); const pokeballAtlasKey = getPokeballAtlasKey(this.pokeballType); - this.pokeball = this.scene.addFieldSprite(16, 80, "pb", pokeballAtlasKey); + this.pokeball = globalScene.addFieldSprite(16, 80, "pb", pokeballAtlasKey); this.pokeball.setOrigin(0.5, 0.625); - this.scene.field.add(this.pokeball); + globalScene.field.add(this.pokeball); - this.scene.playSound("se/pb_throw", isCritical ? { rate: 0.2 } : undefined); // Crit catch throws are higher pitched - this.scene.time.delayedCall(300, () => { - this.scene.field.moveBelow(this.pokeball as Phaser.GameObjects.GameObject, pokemon); + globalScene.playSound("se/pb_throw", isCritical ? { rate: 0.2 } : undefined); // Crit catch throws are higher pitched + globalScene.time.delayedCall(300, () => { + globalScene.field.moveBelow(this.pokeball as Phaser.GameObjects.GameObject, pokemon); }); - this.scene.tweens.add({ + globalScene.tweens.add({ // Throw animation targets: this.pokeball, x: { value: 236 + fpOffset[0], ease: "Linear" }, @@ -77,13 +77,13 @@ export class AttemptCapturePhase extends PokemonPhase { onComplete: () => { // Ball opens this.pokeball.setTexture("pb", `${pokeballAtlasKey}_opening`); - this.scene.time.delayedCall(17, () => this.pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); - this.scene.playSound("se/pb_rel"); + globalScene.time.delayedCall(17, () => this.pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); + globalScene.playSound("se/pb_rel"); pokemon.tint(getPokeballTintColor(this.pokeballType)); - addPokeballOpenParticles(this.scene, this.pokeball.x, this.pokeball.y, this.pokeballType); + addPokeballOpenParticles(this.pokeball.x, this.pokeball.y, this.pokeballType); - this.scene.tweens.add({ + globalScene.tweens.add({ // Mon enters ball targets: pokemon, duration: 500, @@ -94,14 +94,14 @@ export class AttemptCapturePhase extends PokemonPhase { // Ball closes this.pokeball.setTexture("pb", `${pokeballAtlasKey}_opening`); pokemon.setVisible(false); - this.scene.playSound("se/pb_catch"); - this.scene.time.delayedCall(17, () => this.pokeball.setTexture("pb", `${pokeballAtlasKey}`)); + globalScene.playSound("se/pb_catch"); + globalScene.time.delayedCall(17, () => this.pokeball.setTexture("pb", `${pokeballAtlasKey}`)); const doShake = () => { // After the overall catch rate check, the game does 3 shake checks before confirming the catch. let shakeCount = 0; const pbX = this.pokeball.x; - const shakeCounter = this.scene.tweens.addCounter({ + const shakeCounter = globalScene.tweens.addCounter({ from: 0, to: 1, repeat: isCritical ? 2 : 4, // Critical captures only perform 1 shake check @@ -124,7 +124,7 @@ export class AttemptCapturePhase extends PokemonPhase { } else if (shakeCount++ < (isCritical ? 1 : 3)) { // Shake check (skip check for critical or guaranteed captures, but still play the sound) if (pokeballMultiplier === -1 || isCritical || modifiedCatchRate >= 255 || pokemon.randSeedInt(65536) < shakeProbability) { - this.scene.playSound("se/pb_move"); + globalScene.playSound("se/pb_move"); } else { shakeCounter.stop(); this.failCatch(shakeCount); @@ -134,21 +134,21 @@ export class AttemptCapturePhase extends PokemonPhase { shakeCounter.stop(); this.failCatch(shakeCount); } else { - this.scene.playSound("se/pb_lock"); - addPokeballCaptureStars(this.scene, this.pokeball); + globalScene.playSound("se/pb_lock"); + addPokeballCaptureStars(this.pokeball); - const pbTint = this.scene.add.sprite(this.pokeball.x, this.pokeball.y, "pb", "pb"); + const pbTint = globalScene.add.sprite(this.pokeball.x, this.pokeball.y, "pb", "pb"); pbTint.setOrigin(this.pokeball.originX, this.pokeball.originY); pbTint.setTintFill(0); pbTint.setAlpha(0); - this.scene.field.add(pbTint); - this.scene.tweens.add({ + globalScene.field.add(pbTint); + globalScene.tweens.add({ targets: pbTint, alpha: 0.375, duration: 200, easing: "Sine.easeOut", onComplete: () => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pbTint, alpha: 0, duration: 200, @@ -166,7 +166,7 @@ export class AttemptCapturePhase extends PokemonPhase { }; // Ball bounces (handled in pokemon.ts) - this.scene.time.delayedCall(250, () => doPokeballBounceAnim(this.scene, this.pokeball, 16, 72, 350, doShake, isCritical)); + globalScene.time.delayedCall(250, () => doPokeballBounceAnim(this.pokeball, 16, 72, 350, doShake, isCritical)); } }); } @@ -176,7 +176,7 @@ export class AttemptCapturePhase extends PokemonPhase { failCatch(shakeCount: integer) { const pokemon = this.getPokemon(); - this.scene.playSound("se/pb_rel"); + globalScene.playSound("se/pb_rel"); pokemon.setY(this.originalY); if (pokemon.status?.effect !== StatusEffect.SLEEP) { pokemon.cry(pokemon.getHpRatio() > 0.25 ? undefined : { rate: 0.85 }); @@ -192,16 +192,16 @@ export class AttemptCapturePhase extends PokemonPhase { const pokeballAtlasKey = getPokeballAtlasKey(this.pokeballType); this.pokeball.setTexture("pb", `${pokeballAtlasKey}_opening`); - this.scene.time.delayedCall(17, () => this.pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); + globalScene.time.delayedCall(17, () => this.pokeball.setTexture("pb", `${pokeballAtlasKey}_open`)); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, duration: 250, ease: "Sine.easeOut", scale: 1 }); - this.scene.currentBattle.lastUsedPokeball = this.pokeballType; + globalScene.currentBattle.lastUsedPokeball = this.pokeballType; this.removePb(); this.end(); } @@ -212,48 +212,48 @@ export class AttemptCapturePhase extends PokemonPhase { const speciesForm = !pokemon.fusionSpecies ? pokemon.getSpeciesForm() : pokemon.getFusionSpeciesForm(); if (speciesForm.abilityHidden && (pokemon.fusionSpecies ? pokemon.fusionAbilityIndex : pokemon.abilityIndex) === speciesForm.getAbilityCount() - 1) { - this.scene.validateAchv(achvs.HIDDEN_ABILITY); + globalScene.validateAchv(achvs.HIDDEN_ABILITY); } if (pokemon.species.subLegendary) { - this.scene.validateAchv(achvs.CATCH_SUB_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_SUB_LEGENDARY); } if (pokemon.species.legendary) { - this.scene.validateAchv(achvs.CATCH_LEGENDARY); + globalScene.validateAchv(achvs.CATCH_LEGENDARY); } if (pokemon.species.mythical) { - this.scene.validateAchv(achvs.CATCH_MYTHICAL); + globalScene.validateAchv(achvs.CATCH_MYTHICAL); } - this.scene.pokemonInfoContainer.show(pokemon, true); + globalScene.pokemonInfoContainer.show(pokemon, true); - this.scene.gameData.updateSpeciesDexIvs(pokemon.species.getRootSpeciesId(true), pokemon.ivs); + globalScene.gameData.updateSpeciesDexIvs(pokemon.species.getRootSpeciesId(true), pokemon.ivs); - this.scene.ui.showText(i18next.t("battle:pokemonCaught", { pokemonName: getPokemonNameWithAffix(pokemon) }), null, () => { + globalScene.ui.showText(i18next.t("battle:pokemonCaught", { pokemonName: getPokemonNameWithAffix(pokemon) }), null, () => { const end = () => { - this.scene.unshiftPhase(new VictoryPhase(this.scene, this.battlerIndex)); - this.scene.pokemonInfoContainer.hide(); + globalScene.unshiftPhase(new VictoryPhase(this.battlerIndex)); + globalScene.pokemonInfoContainer.hide(); this.removePb(); this.end(); }; const removePokemon = () => { - this.scene.addFaintedEnemyScore(pokemon); - this.scene.getPlayerField().filter(p => p.isActive(true)).forEach(playerPokemon => playerPokemon.removeTagsBySourceId(pokemon.id)); + globalScene.addFaintedEnemyScore(pokemon); + globalScene.getPlayerField().filter(p => p.isActive(true)).forEach(playerPokemon => playerPokemon.removeTagsBySourceId(pokemon.id)); pokemon.hp = 0; pokemon.trySetStatus(StatusEffect.FAINT); - this.scene.clearEnemyHeldItemModifiers(); - this.scene.field.remove(pokemon, true); + globalScene.clearEnemyHeldItemModifiers(); + globalScene.field.remove(pokemon, true); }; const addToParty = (slotIndex?: number) => { const newPokemon = pokemon.addToParty(this.pokeballType, slotIndex); - const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); - if (this.scene.getPlayerParty().filter(p => p.isShiny()).length === PLAYER_PARTY_MAX_SIZE) { - this.scene.validateAchv(achvs.SHINY_PARTY); + const modifiers = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier, false); + if (globalScene.getPlayerParty().filter(p => p.isShiny()).length === PLAYER_PARTY_MAX_SIZE) { + globalScene.validateAchv(achvs.SHINY_PARTY); } - Promise.all(modifiers.map(m => this.scene.addModifier(m, true))).then(() => { - this.scene.updateModifiers(true); + Promise.all(modifiers.map(m => globalScene.addModifier(m, true))).then(() => { + globalScene.updateModifiers(true); removePokemon(); if (newPokemon) { newPokemon.loadAssets().then(end); @@ -262,21 +262,21 @@ export class AttemptCapturePhase extends PokemonPhase { } }); }; - Promise.all([ pokemon.hideInfo(), this.scene.gameData.setPokemonCaught(pokemon) ]).then(() => { - if (this.scene.getPlayerParty().length === PLAYER_PARTY_MAX_SIZE) { + Promise.all([ pokemon.hideInfo(), globalScene.gameData.setPokemonCaught(pokemon) ]).then(() => { + if (globalScene.getPlayerParty().length === PLAYER_PARTY_MAX_SIZE) { const promptRelease = () => { - this.scene.ui.showText(i18next.t("battle:partyFull", { pokemonName: pokemon.getNameToRender() }), null, () => { - this.scene.pokemonInfoContainer.makeRoomForConfirmUi(1, true); - this.scene.ui.setMode(Mode.CONFIRM, () => { - const newPokemon = this.scene.addPlayerPokemon(pokemon.species, pokemon.level, pokemon.abilityIndex, pokemon.formIndex, pokemon.gender, pokemon.shiny, pokemon.variant, pokemon.ivs, pokemon.nature, pokemon); - this.scene.ui.setMode(Mode.SUMMARY, newPokemon, 0, SummaryUiMode.DEFAULT, () => { - this.scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.showText(i18next.t("battle:partyFull", { pokemonName: pokemon.getNameToRender() }), null, () => { + globalScene.pokemonInfoContainer.makeRoomForConfirmUi(1, true); + globalScene.ui.setMode(Mode.CONFIRM, () => { + const newPokemon = globalScene.addPlayerPokemon(pokemon.species, pokemon.level, pokemon.abilityIndex, pokemon.formIndex, pokemon.gender, pokemon.shiny, pokemon.variant, pokemon.ivs, pokemon.nature, pokemon); + globalScene.ui.setMode(Mode.SUMMARY, newPokemon, 0, SummaryUiMode.DEFAULT, () => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { promptRelease(); }); }, false); }, () => { - this.scene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, this.fieldIndex, (slotIndex: integer, _option: PartyOption) => { - this.scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.PARTY, PartyUiMode.RELEASE, this.fieldIndex, (slotIndex: integer, _option: PartyOption) => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { if (slotIndex < 6) { addToParty(slotIndex); } else { @@ -285,7 +285,7 @@ export class AttemptCapturePhase extends PokemonPhase { }); }); }, () => { - this.scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { removePokemon(); end(); }); @@ -301,7 +301,7 @@ export class AttemptCapturePhase extends PokemonPhase { } removePb() { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokeball, duration: 250, delay: 250, diff --git a/src/phases/attempt-run-phase.ts b/src/phases/attempt-run-phase.ts index 109fc5b582d5..efbfd698550b 100644 --- a/src/phases/attempt-run-phase.ts +++ b/src/phases/attempt-run-phase.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { applyAbAttrs, RunSuccessAbAttr } from "#app/data/ability"; import { Stat } from "#app/enums/stat"; import { StatusEffect } from "#app/enums/status-effect"; @@ -8,21 +7,22 @@ import * as Utils from "#app/utils"; import { BattleEndPhase } from "./battle-end-phase"; import { NewBattlePhase } from "./new-battle-phase"; import { PokemonPhase } from "./pokemon-phase"; +import { globalScene } from "#app/global-scene"; export class AttemptRunPhase extends PokemonPhase { /** For testing purposes: this is to force the pokemon to fail and escape */ public forceFailEscape = false; - constructor(scene: BattleScene, fieldIndex: number) { - super(scene, fieldIndex); + constructor(fieldIndex: number) { + super(fieldIndex); } start() { super.start(); - const playerField = this.scene.getPlayerField(); - const enemyField = this.scene.getEnemyField(); + const playerField = globalScene.getPlayerField(); + const enemyField = globalScene.getEnemyField(); const playerPokemon = this.getPokemon(); @@ -33,18 +33,18 @@ export class AttemptRunPhase extends PokemonPhase { applyAbAttrs(RunSuccessAbAttr, playerPokemon, null, false, escapeChance); if (playerPokemon.randSeedInt(100) < escapeChance.value && !this.forceFailEscape) { - this.scene.playSound("se/flee"); - this.scene.queueMessage(i18next.t("battle:runAwaySuccess"), null, true, 500); + globalScene.playSound("se/flee"); + globalScene.queueMessage(i18next.t("battle:runAwaySuccess"), null, true, 500); - this.scene.tweens.add({ - targets: [ this.scene.arenaEnemy, enemyField ].flat(), + globalScene.tweens.add({ + targets: [ globalScene.arenaEnemy, enemyField ].flat(), alpha: 0, duration: 250, ease: "Sine.easeIn", onComplete: () => enemyField.forEach(enemyPokemon => enemyPokemon.destroy()) }); - this.scene.clearEnemyHeldItemModifiers(); + globalScene.clearEnemyHeldItemModifiers(); enemyField.forEach(enemyPokemon => { enemyPokemon.hideInfo().then(() => enemyPokemon.destroy()); @@ -52,11 +52,11 @@ export class AttemptRunPhase extends PokemonPhase { enemyPokemon.trySetStatus(StatusEffect.FAINT); }); - this.scene.pushPhase(new BattleEndPhase(this.scene, false)); - this.scene.pushPhase(new NewBattlePhase(this.scene)); + globalScene.pushPhase(new BattleEndPhase(false)); + globalScene.pushPhase(new NewBattlePhase()); } else { playerPokemon.turnData.failedRunAway = true; - this.scene.queueMessage(i18next.t("battle:runAwayCannotEscape"), null, true, 500); + globalScene.queueMessage(i18next.t("battle:runAwayCannotEscape"), null, true, 500); } this.end(); @@ -103,6 +103,6 @@ export class AttemptRunPhase extends PokemonPhase { const escapeSlope = (maxChance - minChance) / speedCap; // This will calculate the escape chance given all of the above and clamp it to the range of [`minChance`, `maxChance`] - escapeChance.value = Phaser.Math.Clamp(Math.round((escapeSlope * speedRatio) + minChance + (escapeBonus * this.scene.currentBattle.escapeAttempts++)), minChance, maxChance); + escapeChance.value = Phaser.Math.Clamp(Math.round((escapeSlope * speedRatio) + minChance + (escapeBonus * globalScene.currentBattle.escapeAttempts++)), minChance, maxChance); } } diff --git a/src/phases/battle-end-phase.ts b/src/phases/battle-end-phase.ts index 8926a2211e05..edffd8498d6e 100644 --- a/src/phases/battle-end-phase.ts +++ b/src/phases/battle-end-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { applyPostBattleAbAttrs, PostBattleAbAttr } from "#app/data/ability"; import { LapsingPersistentModifier, LapsingPokemonHeldItemModifier } from "#app/modifier/modifier"; import { BattlePhase } from "./battle-phase"; @@ -8,8 +8,8 @@ export class BattleEndPhase extends BattlePhase { /** If true, will increment battles won */ isVictory: boolean; - constructor(scene: BattleScene, isVictory: boolean) { - super(scene); + constructor(isVictory: boolean) { + super(); this.isVictory = isVictory; } @@ -17,52 +17,52 @@ export class BattleEndPhase extends BattlePhase { start() { super.start(); - this.scene.gameData.gameStats.battles++; - if (this.scene.gameMode.isEndless && this.scene.currentBattle.waveIndex + 1 > this.scene.gameData.gameStats.highestEndlessWave) { - this.scene.gameData.gameStats.highestEndlessWave = this.scene.currentBattle.waveIndex + 1; + globalScene.gameData.gameStats.battles++; + if (globalScene.gameMode.isEndless && globalScene.currentBattle.waveIndex + 1 > globalScene.gameData.gameStats.highestEndlessWave) { + globalScene.gameData.gameStats.highestEndlessWave = globalScene.currentBattle.waveIndex + 1; } if (this.isVictory) { - this.scene.currentBattle.addBattleScore(this.scene); + globalScene.currentBattle.addBattleScore(); - if (this.scene.currentBattle.trainer) { - this.scene.gameData.gameStats.trainersDefeated++; + if (globalScene.currentBattle.trainer) { + globalScene.gameData.gameStats.trainersDefeated++; } } // Endless graceful end - if (this.scene.gameMode.isEndless && this.scene.currentBattle.waveIndex >= 5850) { - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new GameOverPhase(this.scene, true)); + if (globalScene.gameMode.isEndless && globalScene.currentBattle.waveIndex >= 5850) { + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new GameOverPhase(true)); } - for (const pokemon of this.scene.getField()) { + for (const pokemon of globalScene.getField()) { if (pokemon && pokemon.battleSummonData) { pokemon.battleSummonData.waveTurnCount = 1; } } - for (const pokemon of this.scene.getPokemonAllowedInBattle()) { + for (const pokemon of globalScene.getPokemonAllowedInBattle()) { applyPostBattleAbAttrs(PostBattleAbAttr, pokemon, false, this.isVictory); } - if (this.scene.currentBattle.moneyScattered) { - this.scene.currentBattle.pickUpScatteredMoney(this.scene); + if (globalScene.currentBattle.moneyScattered) { + globalScene.currentBattle.pickUpScatteredMoney(); } - this.scene.clearEnemyHeldItemModifiers(); + globalScene.clearEnemyHeldItemModifiers(); - const lapsingModifiers = this.scene.findModifiers(m => m instanceof LapsingPersistentModifier || m instanceof LapsingPokemonHeldItemModifier) as (LapsingPersistentModifier | LapsingPokemonHeldItemModifier)[]; + const lapsingModifiers = globalScene.findModifiers(m => m instanceof LapsingPersistentModifier || m instanceof LapsingPokemonHeldItemModifier) as (LapsingPersistentModifier | LapsingPokemonHeldItemModifier)[]; for (const m of lapsingModifiers) { const args: any[] = []; if (m instanceof LapsingPokemonHeldItemModifier) { - args.push(this.scene.getPokemonById(m.pokemonId)); + args.push(globalScene.getPokemonById(m.pokemonId)); } if (!m.lapse(...args)) { - this.scene.removeModifier(m); + globalScene.removeModifier(m); } } - this.scene.updateModifiers().then(() => this.end()); + globalScene.updateModifiers().then(() => this.end()); } } diff --git a/src/phases/battle-phase.ts b/src/phases/battle-phase.ts index 11807fdc714f..4fc826b79574 100644 --- a/src/phases/battle-phase.ts +++ b/src/phases/battle-phase.ts @@ -1,15 +1,15 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { TrainerSlot } from "#app/data/trainer-config"; import { Phase } from "#app/phase"; export class BattlePhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } showEnemyTrainer(trainerSlot: TrainerSlot = TrainerSlot.NONE): void { - const sprites = this.scene.currentBattle.trainer?.getSprites()!; // TODO: is this bang correct? - const tintSprites = this.scene.currentBattle.trainer?.getTintSprites()!; // TODO: is this bang correct? + const sprites = globalScene.currentBattle.trainer?.getSprites()!; // TODO: is this bang correct? + const tintSprites = globalScene.currentBattle.trainer?.getTintSprites()!; // TODO: is this bang correct? for (let i = 0; i < sprites.length; i++) { const visible = !trainerSlot || !i === (trainerSlot === TrainerSlot.TRAINER) || sprites.length < 2; [ sprites[i], tintSprites[i] ].map(sprite => { @@ -24,8 +24,8 @@ export class BattlePhase extends Phase { sprites[i].clearTint(); tintSprites[i].clearTint(); } - this.scene.tweens.add({ - targets: this.scene.currentBattle.trainer, + globalScene.tweens.add({ + targets: globalScene.currentBattle.trainer, x: "-=16", y: "+=16", alpha: 1, @@ -35,8 +35,8 @@ export class BattlePhase extends Phase { } hideEnemyTrainer(): void { - this.scene.tweens.add({ - targets: this.scene.currentBattle.trainer, + globalScene.tweens.add({ + targets: globalScene.currentBattle.trainer, x: "+=16", y: "-=16", alpha: 0, diff --git a/src/phases/berry-phase.ts b/src/phases/berry-phase.ts index 5c33ae4b3430..dd56e8b37d76 100644 --- a/src/phases/berry-phase.ts +++ b/src/phases/berry-phase.ts @@ -7,6 +7,7 @@ import i18next from "i18next"; import * as Utils from "#app/utils"; import { FieldPhase } from "./field-phase"; import { CommonAnimPhase } from "./common-anim-phase"; +import { globalScene } from "#app/global-scene"; /** The phase after attacks where the pokemon eat berries */ export class BerryPhase extends FieldPhase { @@ -14,7 +15,7 @@ export class BerryPhase extends FieldPhase { super.start(); this.executeForAll((pokemon) => { - const hasUsableBerry = !!this.scene.findModifier((m) => { + const hasUsableBerry = !!globalScene.findModifier((m) => { return m instanceof BerryModifier && m.shouldApply(pokemon); }, pokemon.isPlayer()); @@ -23,21 +24,21 @@ export class BerryPhase extends FieldPhase { pokemon.getOpponents().map((opp) => applyAbAttrs(PreventBerryUseAbAttr, opp, cancelled)); if (cancelled.value) { - pokemon.scene.queueMessage(i18next.t("abilityTriggers:preventBerryUse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); + globalScene.queueMessage(i18next.t("abilityTriggers:preventBerryUse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); } else { - this.scene.unshiftPhase( - new CommonAnimPhase(this.scene, pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.USE_ITEM) + globalScene.unshiftPhase( + new CommonAnimPhase(pokemon.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.USE_ITEM) ); - for (const berryModifier of this.scene.applyModifiers(BerryModifier, pokemon.isPlayer(), pokemon)) { + for (const berryModifier of globalScene.applyModifiers(BerryModifier, pokemon.isPlayer(), pokemon)) { if (berryModifier.consumed) { berryModifier.consumed = false; pokemon.loseHeldItem(berryModifier); } - this.scene.eventTarget.dispatchEvent(new BerryUsedEvent(berryModifier)); // Announce a berry was used + globalScene.eventTarget.dispatchEvent(new BerryUsedEvent(berryModifier)); // Announce a berry was used } - this.scene.updateModifiers(pokemon.isPlayer()); + globalScene.updateModifiers(pokemon.isPlayer()); applyAbAttrs(HealFromBerryUseAbAttr, pokemon, new Utils.BooleanHolder(false)); } diff --git a/src/phases/check-status-effect-phase.ts b/src/phases/check-status-effect-phase.ts index 44918b549664..dd27e92cb86f 100644 --- a/src/phases/check-status-effect-phase.ts +++ b/src/phases/check-status-effect-phase.ts @@ -1,21 +1,20 @@ import { PostTurnStatusEffectPhase } from "#app/phases/post-turn-status-effect-phase"; import { Phase } from "#app/phase"; import { BattlerIndex } from "#app/battle"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; export class CheckStatusEffectPhase extends Phase { private order : BattlerIndex[]; - constructor(scene : BattleScene, order : BattlerIndex[]) { - super(scene); - this.scene = scene; + constructor(order : BattlerIndex[]) { + super(); this.order = order; } start() { - const field = this.scene.getField(); + const field = globalScene.getField(); for (const o of this.order) { if (field[o].status && field[o].status.isPostTurn()) { - this.scene.unshiftPhase(new PostTurnStatusEffectPhase(this.scene, o)); + globalScene.unshiftPhase(new PostTurnStatusEffectPhase(o)); } } this.end(); diff --git a/src/phases/check-switch-phase.ts b/src/phases/check-switch-phase.ts index 18b999ed2101..06e08f7f30de 100644 --- a/src/phases/check-switch-phase.ts +++ b/src/phases/check-switch-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattleStyle } from "#app/enums/battle-style"; import { BattlerTagType } from "#app/enums/battler-tag-type"; import { getPokemonNameWithAffix } from "#app/messages"; @@ -13,8 +13,8 @@ export class CheckSwitchPhase extends BattlePhase { protected fieldIndex: integer; protected useName: boolean; - constructor(scene: BattleScene, fieldIndex: integer, useName: boolean) { - super(scene); + constructor(fieldIndex: integer, useName: boolean) { + super(); this.fieldIndex = fieldIndex; this.useName = useName; @@ -23,40 +23,40 @@ export class CheckSwitchPhase extends BattlePhase { start() { super.start(); - const pokemon = this.scene.getPlayerField()[this.fieldIndex]; + const pokemon = globalScene.getPlayerField()[this.fieldIndex]; // End this phase early... // ...if the user is playing in Set Mode - if (this.scene.battleStyle === BattleStyle.SET) { + if (globalScene.battleStyle === BattleStyle.SET) { return super.end(); } // ...if the checked Pokemon is somehow not on the field - if (this.scene.field.getAll().indexOf(pokemon) === -1) { - this.scene.unshiftPhase(new SummonMissingPhase(this.scene, this.fieldIndex)); + if (globalScene.field.getAll().indexOf(pokemon) === -1) { + globalScene.unshiftPhase(new SummonMissingPhase(this.fieldIndex)); return super.end(); } // ...if there are no other allowed Pokemon in the player's party to switch with - if (!this.scene.getPlayerParty().slice(1).filter(p => p.isActive()).length) { + if (!globalScene.getPlayerParty().slice(1).filter(p => p.isActive()).length) { return super.end(); } // ...or if any player Pokemon has an effect that prevents the checked Pokemon from switching if (pokemon.getTag(BattlerTagType.FRENZY) || pokemon.isTrapped() - || this.scene.getPlayerField().some(p => p.getTag(BattlerTagType.COMMANDED))) { + || globalScene.getPlayerField().some(p => p.getTag(BattlerTagType.COMMANDED))) { return super.end(); } - this.scene.ui.showText(i18next.t("battle:switchQuestion", { pokemonName: this.useName ? getPokemonNameWithAffix(pokemon) : i18next.t("battle:pokemon") }), null, () => { - this.scene.ui.setMode(Mode.CONFIRM, () => { - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.unshiftPhase(new SwitchPhase(this.scene, SwitchType.INITIAL_SWITCH, this.fieldIndex, false, true)); + globalScene.ui.showText(i18next.t("battle:switchQuestion", { pokemonName: this.useName ? getPokemonNameWithAffix(pokemon) : i18next.t("battle:pokemon") }), null, () => { + globalScene.ui.setMode(Mode.CONFIRM, () => { + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.unshiftPhase(new SwitchPhase(SwitchType.INITIAL_SWITCH, this.fieldIndex, false, true)); this.end(); }, () => { - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); this.end(); }); }); diff --git a/src/phases/command-phase.ts b/src/phases/command-phase.ts index eab76282908e..203c5fc97aa8 100644 --- a/src/phases/command-phase.ts +++ b/src/phases/command-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { TurnCommand, BattleType } from "#app/battle"; import { TrappedTag, EncoreTag } from "#app/data/battler-tags"; import { MoveTargetSet, getMoveTargets } from "#app/data/move"; @@ -23,8 +23,8 @@ import { ArenaTagType } from "#app/enums/arena-tag-type"; export class CommandPhase extends FieldPhase { protected fieldIndex: integer; - constructor(scene: BattleScene, fieldIndex: integer) { - super(scene); + constructor(fieldIndex: integer) { + super(); this.fieldIndex = fieldIndex; } @@ -32,11 +32,11 @@ export class CommandPhase extends FieldPhase { start() { super.start(); - this.scene.updateGameInfo(); + globalScene.updateGameInfo(); - const commandUiHandler = this.scene.ui.handlers[Mode.COMMAND]; + const commandUiHandler = globalScene.ui.handlers[Mode.COMMAND]; if (commandUiHandler) { - if (this.scene.currentBattle.turn === 1 || commandUiHandler.getCursor() === Command.POKEMON) { + if (globalScene.currentBattle.turn === 1 || commandUiHandler.getCursor() === Command.POKEMON) { commandUiHandler.setCursor(Command.FIGHT); } else { commandUiHandler.setCursor(commandUiHandler.getCursor()); @@ -46,19 +46,19 @@ export class CommandPhase extends FieldPhase { if (this.fieldIndex) { // If we somehow are attempting to check the right pokemon but there's only one pokemon out // Switch back to the center pokemon. This can happen rarely in double battles with mid turn switching - if (this.scene.getPlayerField().filter(p => p.isActive()).length === 1) { + if (globalScene.getPlayerField().filter(p => p.isActive()).length === 1) { this.fieldIndex = FieldPosition.CENTER; } else { - const allyCommand = this.scene.currentBattle.turnCommands[this.fieldIndex - 1]; + const allyCommand = globalScene.currentBattle.turnCommands[this.fieldIndex - 1]; if (allyCommand?.command === Command.BALL || allyCommand?.command === Command.RUN) { - this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: allyCommand?.command, skip: true }; + globalScene.currentBattle.turnCommands[this.fieldIndex] = { command: allyCommand?.command, skip: true }; } } } // If the Pokemon has applied Commander's effects to its ally, skip this command - if (this.scene.currentBattle?.double && this.getPokemon().getAlly()?.getTag(BattlerTagType.COMMANDED)?.getSourcePokemon(this.scene) === this.getPokemon()) { - this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.FIGHT, move: { move: Moves.NONE, targets: []}, skip: true }; + if (globalScene.currentBattle?.double && this.getPokemon().getAlly()?.getTag(BattlerTagType.COMMANDED)?.getSourcePokemon() === this.getPokemon()) { + globalScene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.FIGHT, move: { move: Moves.NONE, targets: []}, skip: true }; } // Checks if the Pokemon is under the effects of Encore. If so, Encore can end early if the encored move has no more PP. @@ -67,11 +67,11 @@ export class CommandPhase extends FieldPhase { this.getPokemon().lapseTag(BattlerTagType.ENCORE); } - if (this.scene.currentBattle.turnCommands[this.fieldIndex]?.skip) { + if (globalScene.currentBattle.turnCommands[this.fieldIndex]?.skip) { return this.end(); } - const playerPokemon = this.scene.getPlayerField()[this.fieldIndex]; + const playerPokemon = globalScene.getPlayerField()[this.fieldIndex]; const moveQueue = playerPokemon.getMoveQueue(); @@ -90,21 +90,21 @@ export class CommandPhase extends FieldPhase { if (moveIndex > -1 && playerPokemon.getMoveset()[moveIndex]!.isUsable(playerPokemon, queuedMove.ignorePP)) { // TODO: is the bang correct? this.handleCommand(Command.FIGHT, moveIndex, queuedMove.ignorePP, { targets: queuedMove.targets, multiple: queuedMove.targets.length > 1 }); } else { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); } } } else { - if (this.scene.currentBattle.isBattleMysteryEncounter() && this.scene.currentBattle.mysteryEncounter?.skipToFightInput) { - this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.FIGHT, this.fieldIndex); + if (globalScene.currentBattle.isBattleMysteryEncounter() && globalScene.currentBattle.mysteryEncounter?.skipToFightInput) { + globalScene.ui.clearText(); + globalScene.ui.setMode(Mode.FIGHT, this.fieldIndex); } else { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); } } } handleCommand(command: Command, cursor: integer, ...args: any[]): boolean { - const playerPokemon = this.scene.getPlayerField()[this.fieldIndex]; + const playerPokemon = globalScene.getPlayerField()[this.fieldIndex]; let success: boolean = false; switch (command) { @@ -121,20 +121,20 @@ export class CommandPhase extends FieldPhase { } console.log(moveTargets, getPokemonNameWithAffix(playerPokemon)); if (moveTargets.targets.length > 1 && moveTargets.multiple) { - this.scene.unshiftPhase(new SelectTargetPhase(this.scene, this.fieldIndex)); + globalScene.unshiftPhase(new SelectTargetPhase(this.fieldIndex)); } if (moveTargets.targets.length <= 1 || moveTargets.multiple) { turnCommand.move!.targets = moveTargets.targets; //TODO: is the bang correct here? } else if (playerPokemon.getTag(BattlerTagType.CHARGING) && playerPokemon.getMoveQueue().length >= 1) { turnCommand.move!.targets = playerPokemon.getMoveQueue()[0].targets; //TODO: is the bang correct here? } else { - this.scene.unshiftPhase(new SelectTargetPhase(this.scene, this.fieldIndex)); + globalScene.unshiftPhase(new SelectTargetPhase(this.fieldIndex)); } - this.scene.currentBattle.turnCommands[this.fieldIndex] = turnCommand; + globalScene.currentBattle.turnCommands[this.fieldIndex] = turnCommand; success = true; } else if (cursor < playerPokemon.getMoveset().length) { const move = playerPokemon.getMoveset()[cursor]!; //TODO: is this bang correct? - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); // Decides between a Disabled, Not Implemented, or No PP translation message const errorMessage = @@ -143,58 +143,58 @@ export class CommandPhase extends FieldPhase { : move.getName().endsWith(" (N)") ? "battle:moveNotImplemented" : "battle:moveNoPP"; const moveName = move.getName().replace(" (N)", ""); // Trims off the indicator - this.scene.ui.showText(i18next.t(errorMessage, { moveName: moveName }), null, () => { - this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.FIGHT, this.fieldIndex); + globalScene.ui.showText(i18next.t(errorMessage, { moveName: moveName }), null, () => { + globalScene.ui.clearText(); + globalScene.ui.setMode(Mode.FIGHT, this.fieldIndex); }, null, true); } break; case Command.BALL: - const notInDex = (this.scene.getEnemyField().filter(p => p.isActive(true)).some(p => !p.scene.gameData.dexData[p.species.speciesId].caughtAttr) && this.scene.gameData.getStarterCount(d => !!d.caughtAttr) < Object.keys(speciesStarterCosts).length - 1); - if (this.scene.arena.biomeType === Biome.END && (!this.scene.gameMode.isClassic || this.scene.gameMode.isFreshStartChallenge() || notInDex )) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:noPokeballForce"), null, () => { - this.scene.ui.showText("", 0); - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + const notInDex = (globalScene.getEnemyField().filter(p => p.isActive(true)).some(p => !globalScene.gameData.dexData[p.species.speciesId].caughtAttr) && globalScene.gameData.getStarterCount(d => !!d.caughtAttr) < Object.keys(speciesStarterCosts).length - 1); + if (globalScene.arena.biomeType === Biome.END && (!globalScene.gameMode.isClassic || globalScene.gameMode.isFreshStartChallenge() || notInDex )) { + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:noPokeballForce"), null, () => { + globalScene.ui.showText("", 0); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); }, null, true); - } else if (this.scene.currentBattle.battleType === BattleType.TRAINER) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:noPokeballTrainer"), null, () => { - this.scene.ui.showText("", 0); - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + } else if (globalScene.currentBattle.battleType === BattleType.TRAINER) { + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:noPokeballTrainer"), null, () => { + globalScene.ui.showText("", 0); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); }, null, true); - } else if (this.scene.currentBattle.isBattleMysteryEncounter() && !this.scene.currentBattle.mysteryEncounter!.catchAllowed) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:noPokeballMysteryEncounter"), null, () => { - this.scene.ui.showText("", 0); - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + } else if (globalScene.currentBattle.isBattleMysteryEncounter() && !globalScene.currentBattle.mysteryEncounter!.catchAllowed) { + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:noPokeballMysteryEncounter"), null, () => { + globalScene.ui.showText("", 0); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); }, null, true); } else { - const targets = this.scene.getEnemyField().filter(p => p.isActive(true)).map(p => p.getBattlerIndex()); + const targets = globalScene.getEnemyField().filter(p => p.isActive(true)).map(p => p.getBattlerIndex()); if (targets.length > 1) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:noPokeballMulti"), null, () => { - this.scene.ui.showText("", 0); - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:noPokeballMulti"), null, () => { + globalScene.ui.showText("", 0); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); }, null, true); } else if (cursor < 5) { - const targetPokemon = this.scene.getEnemyField().find(p => p.isActive(true)); + const targetPokemon = globalScene.getEnemyField().find(p => p.isActive(true)); if (targetPokemon?.isBoss() && targetPokemon?.bossSegmentIndex >= 1 && !targetPokemon?.hasAbility(Abilities.WONDER_GUARD, false, true) && cursor < PokeballType.MASTER_BALL) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:noPokeballStrong"), null, () => { - this.scene.ui.showText("", 0); - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:noPokeballStrong"), null, () => { + globalScene.ui.showText("", 0); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); }, null, true); } else { - this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.BALL, cursor: cursor }; - this.scene.currentBattle.turnCommands[this.fieldIndex]!.targets = targets; + globalScene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.BALL, cursor: cursor }; + globalScene.currentBattle.turnCommands[this.fieldIndex]!.targets = targets; if (this.fieldIndex) { - this.scene.currentBattle.turnCommands[this.fieldIndex - 1]!.skip = true; + globalScene.currentBattle.turnCommands[this.fieldIndex - 1]!.skip = true; } success = true; } @@ -204,21 +204,21 @@ export class CommandPhase extends FieldPhase { case Command.POKEMON: case Command.RUN: const isSwitch = command === Command.POKEMON; - const { currentBattle, arena } = this.scene; + const { currentBattle, arena } = globalScene; const mysteryEncounterFleeAllowed = currentBattle.mysteryEncounter?.fleeAllowed; if (!isSwitch && (arena.biomeType === Biome.END || (!isNullOrUndefined(mysteryEncounterFleeAllowed) && !mysteryEncounterFleeAllowed))) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:noEscapeForce"), null, () => { - this.scene.ui.showText("", 0); - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:noEscapeForce"), null, () => { + globalScene.ui.showText("", 0); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); }, null, true); } else if (!isSwitch && (currentBattle.battleType === BattleType.TRAINER || currentBattle.mysteryEncounter?.encounterMode === MysteryEncounterMode.TRAINER_BATTLE)) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:noEscapeTrainer"), null, () => { - this.scene.ui.showText("", 0); - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:noEscapeTrainer"), null, () => { + globalScene.ui.showText("", 0); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); }, null, true); } else { const batonPass = isSwitch && args[0] as boolean; @@ -233,38 +233,38 @@ export class CommandPhase extends FieldPhase { } } else if (trappedAbMessages.length > 0) { if (!isSwitch) { - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); } - this.scene.ui.showText(trappedAbMessages[0], null, () => { - this.scene.ui.showText("", 0); + globalScene.ui.showText(trappedAbMessages[0], null, () => { + globalScene.ui.showText("", 0); if (!isSwitch) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); } }, null, true); } else { const trapTag = playerPokemon.getTag(TrappedTag); - const fairyLockTag = playerPokemon.scene.arena.getTagOnSide(ArenaTagType.FAIRY_LOCK, ArenaTagSide.PLAYER); + const fairyLockTag = globalScene.arena.getTagOnSide(ArenaTagType.FAIRY_LOCK, ArenaTagSide.PLAYER); if (!trapTag && !fairyLockTag) { i18next.t(`battle:noEscape${isSwitch ? "Switch" : "Flee"}`); break; } if (!isSwitch) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.MESSAGE); } const showNoEscapeText = (tag: any) => { - this.scene.ui.showText( + globalScene.ui.showText( i18next.t("battle:noEscapePokemon", { - pokemonName: tag.sourceId && this.scene.getPokemonById(tag.sourceId) ? getPokemonNameWithAffix(this.scene.getPokemonById(tag.sourceId)!) : "", + pokemonName: tag.sourceId && globalScene.getPokemonById(tag.sourceId) ? getPokemonNameWithAffix(globalScene.getPokemonById(tag.sourceId)!) : "", moveName: tag.getMoveName(), escapeVerb: isSwitch ? i18next.t("battle:escapeVerbSwitch") : i18next.t("battle:escapeVerbFlee") }), null, () => { - this.scene.ui.showText("", 0); + globalScene.ui.showText("", 0); if (!isSwitch) { - this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); + globalScene.ui.setMode(Mode.COMMAND, this.fieldIndex); } }, null, @@ -291,8 +291,8 @@ export class CommandPhase extends FieldPhase { cancel() { if (this.fieldIndex) { - this.scene.unshiftPhase(new CommandPhase(this.scene, 0)); - this.scene.unshiftPhase(new CommandPhase(this.scene, 1)); + globalScene.unshiftPhase(new CommandPhase(0)); + globalScene.unshiftPhase(new CommandPhase(1)); this.end(); } } @@ -302,10 +302,10 @@ export class CommandPhase extends FieldPhase { } getPokemon(): PlayerPokemon { - return this.scene.getPlayerField()[this.fieldIndex]; + return globalScene.getPlayerField()[this.fieldIndex]; } end() { - this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end()); + globalScene.ui.setMode(Mode.MESSAGE).then(() => super.end()); } } diff --git a/src/phases/common-anim-phase.ts b/src/phases/common-anim-phase.ts index c4071488eefb..da53b89ac2b3 100644 --- a/src/phases/common-anim-phase.ts +++ b/src/phases/common-anim-phase.ts @@ -1,5 +1,5 @@ -import BattleScene from "#app/battle-scene"; import { BattlerIndex } from "#app/battle"; +import { globalScene } from "#app/global-scene"; import { CommonAnim, CommonBattleAnim } from "#app/data/battle-anims"; import { PokemonPhase } from "./pokemon-phase"; @@ -8,8 +8,8 @@ export class CommonAnimPhase extends PokemonPhase { private targetIndex: integer | undefined; private playOnEmptyField: boolean; - constructor(scene: BattleScene, battlerIndex?: BattlerIndex, targetIndex?: BattlerIndex | undefined, anim?: CommonAnim, playOnEmptyField: boolean = false) { - super(scene, battlerIndex); + constructor(battlerIndex?: BattlerIndex, targetIndex?: BattlerIndex, anim?: CommonAnim, playOnEmptyField: boolean = false) { + super(battlerIndex); this.anim = anim!; // TODO: is this bang correct? this.targetIndex = targetIndex; @@ -21,8 +21,8 @@ export class CommonAnimPhase extends PokemonPhase { } start() { - const target = this.targetIndex !== undefined ? (this.player ? this.scene.getEnemyField() : this.scene.getPlayerField())[this.targetIndex] : this.getPokemon(); - new CommonBattleAnim(this.anim, this.getPokemon(), target).play(this.scene, false, () => { + const target = this.targetIndex !== undefined ? (this.player ? globalScene.getEnemyField() : globalScene.getPlayerField())[this.targetIndex] : this.getPokemon(); + new CommonBattleAnim(this.anim, this.getPokemon(), target).play(false, () => { this.end(); }); } diff --git a/src/phases/damage-anim-phase.ts b/src/phases/damage-anim-phase.ts index 42f0e1ba845c..2983d6b2de08 100644 --- a/src/phases/damage-anim-phase.ts +++ b/src/phases/damage-anim-phase.ts @@ -1,4 +1,4 @@ -import type BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { type BattlerIndex } from "#app/battle"; import { BattleSpec } from "#enums/battle-spec"; import { type DamageResult, HitResult } from "#app/field/pokemon"; @@ -10,8 +10,8 @@ export class DamageAnimPhase extends PokemonPhase { private damageResult: DamageResult; private critical: boolean; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, amount: integer, damageResult?: DamageResult, critical: boolean = false) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, amount: integer, damageResult?: DamageResult, critical: boolean = false) { + super(battlerIndex); this.amount = amount; this.damageResult = damageResult || HitResult.EFFECTIVE; @@ -22,11 +22,11 @@ export class DamageAnimPhase extends PokemonPhase { super.start(); if (this.damageResult === HitResult.ONE_HIT_KO) { - if (this.scene.moveAnimations) { - this.scene.toggleInvert(true); + if (globalScene.moveAnimations) { + globalScene.toggleInvert(true); } - this.scene.time.delayedCall(fixedInt(1000), () => { - this.scene.toggleInvert(false); + globalScene.time.delayedCall(fixedInt(1000), () => { + globalScene.toggleInvert(false); this.applyDamage(); }); return; @@ -42,23 +42,23 @@ export class DamageAnimPhase extends PokemonPhase { applyDamage() { switch (this.damageResult) { case HitResult.EFFECTIVE: - this.scene.playSound("se/hit"); + globalScene.playSound("se/hit"); break; case HitResult.SUPER_EFFECTIVE: case HitResult.ONE_HIT_KO: - this.scene.playSound("se/hit_strong"); + globalScene.playSound("se/hit_strong"); break; case HitResult.NOT_VERY_EFFECTIVE: - this.scene.playSound("se/hit_weak"); + globalScene.playSound("se/hit_weak"); break; } if (this.amount) { - this.scene.damageNumberHandler.add(this.getPokemon(), this.amount, this.damageResult, this.critical); + globalScene.damageNumberHandler.add(this.getPokemon(), this.amount, this.damageResult, this.critical); } if (this.damageResult !== HitResult.OTHER && this.amount > 0) { - const flashTimer = this.scene.time.addEvent({ + const flashTimer = globalScene.time.addEvent({ delay: 100, repeat: 5, startAt: 200, @@ -75,8 +75,8 @@ export class DamageAnimPhase extends PokemonPhase { } override end() { - if (this.scene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { - this.scene.initFinalBossPhaseTwo(this.getPokemon()); + if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { + globalScene.initFinalBossPhaseTwo(this.getPokemon()); } else { super.end(); } diff --git a/src/phases/egg-hatch-phase.ts b/src/phases/egg-hatch-phase.ts index 803fd478fd40..5c6b7d68d222 100644 --- a/src/phases/egg-hatch-phase.ts +++ b/src/phases/egg-hatch-phase.ts @@ -1,4 +1,5 @@ -import BattleScene, { AnySound } from "#app/battle-scene"; +import { AnySound } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Egg } from "#app/data/egg"; import { EggCountChangedEvent } from "#app/events/egg"; import { PlayerPokemon } from "#app/field/pokemon"; @@ -67,8 +68,8 @@ export class EggHatchPhase extends Phase { private evolutionBgm: AnySound; private eggLapsePhase: EggLapsePhase; - constructor(scene: BattleScene, hatchScene: EggLapsePhase, egg: Egg, eggsToHatchCount: integer) { - super(scene); + constructor(hatchScene: EggLapsePhase, egg: Egg, eggsToHatchCount: integer) { + super(); this.eggLapsePhase = hatchScene; this.egg = egg; this.eggsToHatchCount = eggsToHatchCount; @@ -77,37 +78,37 @@ export class EggHatchPhase extends Phase { start() { super.start(); - this.scene.ui.setModeForceTransition(Mode.EGG_HATCH_SCENE).then(() => { + globalScene.ui.setModeForceTransition(Mode.EGG_HATCH_SCENE).then(() => { if (!this.egg) { return this.end(); } - const eggIndex = this.scene.gameData.eggs.findIndex(e => e.id === this.egg.id); + const eggIndex = globalScene.gameData.eggs.findIndex(e => e.id === this.egg.id); if (eggIndex === -1) { return this.end(); } - this.scene.gameData.eggs.splice(eggIndex, 1); + globalScene.gameData.eggs.splice(eggIndex, 1); - this.scene.fadeOutBgm(undefined, false); + globalScene.fadeOutBgm(undefined, false); - this.eggHatchHandler = this.scene.ui.getHandler() as EggHatchSceneHandler; + this.eggHatchHandler = globalScene.ui.getHandler() as EggHatchSceneHandler; this.eggHatchContainer = this.eggHatchHandler.eggHatchContainer; - this.eggHatchBg = this.scene.add.image(0, 0, "default_bg"); + this.eggHatchBg = globalScene.add.image(0, 0, "default_bg"); this.eggHatchBg.setOrigin(0, 0); this.eggHatchContainer.add(this.eggHatchBg); - this.eggContainer = this.scene.add.container(this.eggHatchBg.displayWidth / 2, this.eggHatchBg.displayHeight / 2); + this.eggContainer = globalScene.add.container(this.eggHatchBg.displayWidth / 2, this.eggHatchBg.displayHeight / 2); - this.eggSprite = this.scene.add.sprite(0, 0, "egg", `egg_${this.egg.getKey()}`); - this.eggCrackSprite = this.scene.add.sprite(0, 0, "egg_crack", "0"); + this.eggSprite = globalScene.add.sprite(0, 0, "egg", `egg_${this.egg.getKey()}`); + this.eggCrackSprite = globalScene.add.sprite(0, 0, "egg_crack", "0"); this.eggCrackSprite.setVisible(false); - this.eggLightraysOverlay = this.scene.add.sprite((-this.eggHatchBg.displayWidth / 2) + 4, -this.eggHatchBg.displayHeight / 2, "egg_lightrays", "3"); + this.eggLightraysOverlay = globalScene.add.sprite((-this.eggHatchBg.displayWidth / 2) + 4, -this.eggHatchBg.displayHeight / 2, "egg_lightrays", "3"); this.eggLightraysOverlay.setOrigin(0, 0); this.eggLightraysOverlay.setVisible(false); @@ -116,28 +117,28 @@ export class EggHatchPhase extends Phase { this.eggContainer.add(this.eggLightraysOverlay); this.eggHatchContainer.add(this.eggContainer); - this.eggCounterContainer = new EggCounterContainer(this.scene, this.eggsToHatchCount); + this.eggCounterContainer = new EggCounterContainer(this.eggsToHatchCount); this.eggHatchContainer.add(this.eggCounterContainer); const getPokemonSprite = () => { - const ret = this.scene.add.sprite(this.eggHatchBg.displayWidth / 2, this.eggHatchBg.displayHeight / 2, "pkmn__sub"); - ret.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + const ret = globalScene.add.sprite(this.eggHatchBg.displayWidth / 2, this.eggHatchBg.displayHeight / 2, "pkmn__sub"); + ret.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); return ret; }; this.eggHatchContainer.add((this.pokemonSprite = getPokemonSprite())); - this.pokemonShinySparkle = this.scene.add.sprite(this.pokemonSprite.x, this.pokemonSprite.y, "shiny"); + this.pokemonShinySparkle = globalScene.add.sprite(this.pokemonSprite.x, this.pokemonSprite.y, "shiny"); this.pokemonShinySparkle.setVisible(false); this.eggHatchContainer.add(this.pokemonShinySparkle); - this.eggHatchOverlay = this.scene.add.rectangle(0, -this.scene.game.canvas.height / 6, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0xFFFFFF); + this.eggHatchOverlay = globalScene.add.rectangle(0, -globalScene.game.canvas.height / 6, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0xFFFFFF); this.eggHatchOverlay.setOrigin(0, 0); this.eggHatchOverlay.setAlpha(0); - this.scene.fieldUI.add(this.eggHatchOverlay); + globalScene.fieldUI.add(this.eggHatchOverlay); - this.infoContainer = new PokemonInfoContainer(this.scene); + this.infoContainer = new PokemonInfoContainer(); this.infoContainer.setup(); this.eggHatchContainer.add(this.infoContainer); @@ -155,13 +156,13 @@ export class EggHatchPhase extends Phase { pokemon.loadAssets().then(() => { this.canSkip = true; - this.scene.time.delayedCall(1000, () => { + globalScene.time.delayedCall(1000, () => { if (!this.hatched) { - this.evolutionBgm = this.scene.playSoundWithoutBgm("evolution"); + this.evolutionBgm = globalScene.playSoundWithoutBgm("evolution"); } }); - this.scene.time.delayedCall(2000, () => { + globalScene.time.delayedCall(2000, () => { if (this.hatched) { return; } @@ -171,25 +172,25 @@ export class EggHatchPhase extends Phase { if (this.hatched) { return; } - this.scene.time.delayedCall(1000, () => { + globalScene.time.delayedCall(1000, () => { if (this.hatched) { return; } this.doSpray(2, this.eggSprite.displayHeight / -4); this.eggCrackSprite.setFrame("1"); - this.scene.time.delayedCall(125, () => this.eggCrackSprite.setFrame("2")); + globalScene.time.delayedCall(125, () => this.eggCrackSprite.setFrame("2")); this.doEggShake(4).then(() => { if (this.hatched) { return; } - this.scene.time.delayedCall(1000, () => { + globalScene.time.delayedCall(1000, () => { if (this.hatched) { return; } - this.scene.playSound("se/egg_crack"); + globalScene.playSound("se/egg_crack"); this.doSpray(4); this.eggCrackSprite.setFrame("3"); - this.scene.time.delayedCall(125, () => this.eggCrackSprite.setFrame("4")); + globalScene.time.delayedCall(125, () => this.eggCrackSprite.setFrame("4")); this.doEggShake(8, 2).then(() => { if (!this.hatched) { this.doHatch(); @@ -205,10 +206,10 @@ export class EggHatchPhase extends Phase { } end() { - if (this.scene.findPhase((p) => p instanceof EggHatchPhase)) { + if (globalScene.findPhase((p) => p instanceof EggHatchPhase)) { this.eggHatchHandler.clear(); } else { - this.scene.time.delayedCall(250, () => this.scene.setModifiersVisible(true)); + globalScene.time.delayedCall(250, () => globalScene.setModifiersVisible(true)); } super.end(); } @@ -228,14 +229,14 @@ export class EggHatchPhase extends Phase { if (count === undefined) { count = 0; } - this.scene.playSound("se/pb_move"); - this.scene.tweens.add({ + globalScene.playSound("se/pb_move"); + globalScene.tweens.add({ targets: this.eggContainer, x: `-=${intensity / (count ? 1 : 2)}`, ease: "Sine.easeInOut", duration: 125, onComplete: () => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.eggContainer, x: `+=${intensity}`, ease: "Sine.easeInOut", @@ -245,7 +246,7 @@ export class EggHatchPhase extends Phase { if (count! < repeatCount!) { // we know they are defined return this.doEggShake(intensity, repeatCount, count).then(() => resolve()); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.eggContainer, x: `-=${intensity / 2}`, ease: "Sine.easeInOut", @@ -286,14 +287,14 @@ export class EggHatchPhase extends Phase { this.canSkip = false; this.hatched = true; if (this.evolutionBgm) { - SoundFade.fadeOut(this.scene, this.evolutionBgm, Utils.fixedInt(100)); + SoundFade.fadeOut(globalScene, this.evolutionBgm, Utils.fixedInt(100)); } for (let e = 0; e < 5; e++) { - this.scene.time.delayedCall(Utils.fixedInt(375 * e), () => this.scene.playSound("se/egg_hatch", { volume: 1 - (e * 0.2) })); + globalScene.time.delayedCall(Utils.fixedInt(375 * e), () => globalScene.playSound("se/egg_hatch", { volume: 1 - (e * 0.2) })); } this.eggLightraysOverlay.setVisible(true); this.eggLightraysOverlay.play("egg_lightrays"); - this.scene.tweens.add({ + globalScene.tweens.add({ duration: Utils.fixedInt(125), targets: this.eggHatchOverlay, alpha: 1, @@ -303,7 +304,7 @@ export class EggHatchPhase extends Phase { this.canSkip = true; } }); - this.scene.time.delayedCall(Utils.fixedInt(1500), () => { + globalScene.time.delayedCall(Utils.fixedInt(1500), () => { this.canSkip = false; if (!this.skipped) { this.doReveal(); @@ -318,16 +319,16 @@ export class EggHatchPhase extends Phase { // set the previous dex data so info container can show new unlocks in egg summary const isShiny = this.pokemon.isShiny(); if (this.pokemon.species.subLegendary) { - this.scene.validateAchv(achvs.HATCH_SUB_LEGENDARY); + globalScene.validateAchv(achvs.HATCH_SUB_LEGENDARY); } if (this.pokemon.species.legendary) { - this.scene.validateAchv(achvs.HATCH_LEGENDARY); + globalScene.validateAchv(achvs.HATCH_LEGENDARY); } if (this.pokemon.species.mythical) { - this.scene.validateAchv(achvs.HATCH_MYTHICAL); + globalScene.validateAchv(achvs.HATCH_MYTHICAL); } if (isShiny) { - this.scene.validateAchv(achvs.HATCH_SHINY); + globalScene.validateAchv(achvs.HATCH_SHINY); } this.eggContainer.setVisible(false); const spriteKey = this.pokemon.getSpriteKey(true); @@ -341,33 +342,33 @@ export class EggHatchPhase extends Phase { this.pokemonSprite.setPipelineData("shiny", this.pokemon.shiny); this.pokemonSprite.setPipelineData("variant", this.pokemon.variant); this.pokemonSprite.setVisible(true); - this.scene.time.delayedCall(Utils.fixedInt(250), () => { + globalScene.time.delayedCall(Utils.fixedInt(250), () => { this.eggsToHatchCount--; this.eggHatchHandler.eventTarget.dispatchEvent(new EggCountChangedEvent(this.eggsToHatchCount)); this.pokemon.cry(); if (isShiny) { - this.scene.time.delayedCall(Utils.fixedInt(500), () => { - doShinySparkleAnim(this.scene, this.pokemonShinySparkle, this.pokemon.variant); + globalScene.time.delayedCall(Utils.fixedInt(500), () => { + doShinySparkleAnim(this.pokemonShinySparkle, this.pokemon.variant); }); } - this.scene.time.delayedCall(Utils.fixedInt(!this.skipped ? !isShiny ? 1250 : 1750 : !isShiny ? 250 : 750), () => { + globalScene.time.delayedCall(Utils.fixedInt(!this.skipped ? !isShiny ? 1250 : 1750 : !isShiny ? 250 : 750), () => { this.infoContainer.show(this.pokemon, false, this.skipped ? 2 : 1); - this.scene.playSoundWithoutBgm("evolution_fanfare"); + globalScene.playSoundWithoutBgm("evolution_fanfare"); - this.scene.ui.showText(i18next.t("egg:hatchFromTheEgg", { pokemonName: getPokemonNameWithAffix(this.pokemon) }), null, () => { - this.scene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs); - this.scene.gameData.setPokemonCaught(this.pokemon, true, true).then(() => { - this.scene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex).then((value) => { + globalScene.ui.showText(i18next.t("egg:hatchFromTheEgg", { pokemonName: getPokemonNameWithAffix(this.pokemon) }), null, () => { + globalScene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs); + globalScene.gameData.setPokemonCaught(this.pokemon, true, true).then(() => { + globalScene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex).then((value) => { this.eggHatchData.setEggMoveUnlocked(value); - this.scene.ui.showText("", 0); + globalScene.ui.showText("", 0); this.end(); }); }); }, null, true, 3000); }); }); - this.scene.tweens.add({ + globalScene.tweens.add({ duration: Utils.fixedInt(this.skipped ? 500 : 3000), targets: this.eggHatchOverlay, alpha: 0, @@ -391,7 +392,7 @@ export class EggHatchPhase extends Phase { * @param offsetY how much to offset the Y coordinates */ doSpray(intensity: integer, offsetY?: number) { - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: intensity, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -409,7 +410,7 @@ export class EggHatchPhase extends Phase { const initialX = this.eggHatchBg.displayWidth / 2; const initialY = this.eggHatchBg.displayHeight / 2 + offsetY; const shardKey = !this.egg.isManaphyEgg() ? this.egg.tier.toString() : "1"; - const particle = this.scene.add.image(initialX, initialY, "egg_shard", `${shardKey}_${Math.floor(trigIndex / 2)}`); + const particle = globalScene.add.image(initialX, initialY, "egg_shard", `${shardKey}_${Math.floor(trigIndex / 2)}`); this.eggHatchContainer.add(particle); let f = 0; @@ -417,7 +418,7 @@ export class EggHatchPhase extends Phase { const speed = 3 - Utils.randInt(8); const amp = 24 + Utils.randInt(32); - const particleTimer = this.scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: Utils.getFrameMs(1), onRepeat: () => { diff --git a/src/phases/egg-lapse-phase.ts b/src/phases/egg-lapse-phase.ts index 8de26ee3ef06..f9ba8b97d5dc 100644 --- a/src/phases/egg-lapse-phase.ts +++ b/src/phases/egg-lapse-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Egg, EGG_SEED } from "#app/data/egg"; import { Phase } from "#app/phase"; import i18next from "i18next"; @@ -18,24 +18,24 @@ export class EggLapsePhase extends Phase { private eggHatchData: EggHatchData[] = []; private readonly minEggsToSkip: number = 2; - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - const eggsToHatch: Egg[] = this.scene.gameData.eggs.filter((egg: Egg) => { + const eggsToHatch: Egg[] = globalScene.gameData.eggs.filter((egg: Egg) => { return Overrides.EGG_IMMEDIATE_HATCH_OVERRIDE ? true : --egg.hatchWaves < 1; }); const eggsToHatchCount: number = eggsToHatch.length; this.eggHatchData = []; if (eggsToHatchCount > 0) { - if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 1) { - this.scene.ui.showText(i18next.t("battle:eggHatching"), 0, () => { + if (eggsToHatchCount >= this.minEggsToSkip && globalScene.eggSkipPreference === 1) { + globalScene.ui.showText(i18next.t("battle:eggHatching"), 0, () => { // show prompt for skip, blocking inputs for 1 second - this.scene.ui.showText(i18next.t("battle:eggSkipPrompt", { eggsToHatch: eggsToHatchCount }), 0); - this.scene.ui.setModeWithoutClear(Mode.CONFIRM, () => { + globalScene.ui.showText(i18next.t("battle:eggSkipPrompt", { eggsToHatch: eggsToHatchCount }), 0); + globalScene.ui.setModeWithoutClear(Mode.CONFIRM, () => { this.hatchEggsSkipped(eggsToHatch); this.showSummary(); }, () => { @@ -45,13 +45,13 @@ export class EggLapsePhase extends Phase { null, null, null, 1000, true ); }, 100, true); - } else if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 2) { - this.scene.queueMessage(i18next.t("battle:eggHatching")); + } else if (eggsToHatchCount >= this.minEggsToSkip && globalScene.eggSkipPreference === 2) { + globalScene.queueMessage(i18next.t("battle:eggHatching")); this.hatchEggsSkipped(eggsToHatch); this.showSummary(); } else { // regular hatches, no summary - this.scene.queueMessage(i18next.t("battle:eggHatching")); + globalScene.queueMessage(i18next.t("battle:eggHatching")); this.hatchEggsRegular(eggsToHatch); this.end(); } @@ -67,7 +67,7 @@ export class EggLapsePhase extends Phase { hatchEggsRegular(eggsToHatch: Egg[]) { let eggsToHatchCount: number = eggsToHatch.length; for (const egg of eggsToHatch) { - this.scene.unshiftPhase(new EggHatchPhase(this.scene, this, egg, eggsToHatchCount)); + globalScene.unshiftPhase(new EggHatchPhase(this, egg, eggsToHatchCount)); eggsToHatchCount--; } } @@ -83,7 +83,7 @@ export class EggLapsePhase extends Phase { } showSummary() { - this.scene.unshiftPhase(new EggSummaryPhase(this.scene, this.eggHatchData)); + globalScene.unshiftPhase(new EggSummaryPhase(this.eggHatchData)); this.end(); } @@ -93,11 +93,11 @@ export class EggLapsePhase extends Phase { * @param egg egg to hatch */ hatchEggSilently(egg: Egg) { - const eggIndex = this.scene.gameData.eggs.findIndex(e => e.id === egg.id); + const eggIndex = globalScene.gameData.eggs.findIndex(e => e.id === egg.id); if (eggIndex === -1) { return this.end(); } - this.scene.gameData.eggs.splice(eggIndex, 1); + globalScene.gameData.eggs.splice(eggIndex, 1); const data = this.generatePokemon(egg); const pokemon = data.pokemon; @@ -106,16 +106,16 @@ export class EggLapsePhase extends Phase { } if (pokemon.species.subLegendary) { - this.scene.validateAchv(achvs.HATCH_SUB_LEGENDARY); + globalScene.validateAchv(achvs.HATCH_SUB_LEGENDARY); } if (pokemon.species.legendary) { - this.scene.validateAchv(achvs.HATCH_LEGENDARY); + globalScene.validateAchv(achvs.HATCH_LEGENDARY); } if (pokemon.species.mythical) { - this.scene.validateAchv(achvs.HATCH_MYTHICAL); + globalScene.validateAchv(achvs.HATCH_MYTHICAL); } if (pokemon.isShiny()) { - this.scene.validateAchv(achvs.HATCH_SHINY); + globalScene.validateAchv(achvs.HATCH_SHINY); } } @@ -128,9 +128,9 @@ export class EggLapsePhase extends Phase { generatePokemon(egg: Egg): EggHatchData { let ret: PlayerPokemon; let newHatchData: EggHatchData; - this.scene.executeWithSeedOffset(() => { - ret = egg.generatePlayerPokemon(this.scene); - newHatchData = new EggHatchData(this.scene, ret, egg.eggMoveIndex); + globalScene.executeWithSeedOffset(() => { + ret = egg.generatePlayerPokemon(); + newHatchData = new EggHatchData(ret, egg.eggMoveIndex); newHatchData.setDex(); this.eggHatchData.push(newHatchData); diff --git a/src/phases/egg-summary-phase.ts b/src/phases/egg-summary-phase.ts index b673eb4887ba..1dc4b01b8bfc 100644 --- a/src/phases/egg-summary-phase.ts +++ b/src/phases/egg-summary-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { Mode } from "#app/ui/ui"; import { EggHatchData } from "#app/data/egg-hatch-data"; @@ -11,8 +11,8 @@ import { EggHatchData } from "#app/data/egg-hatch-data"; export class EggSummaryPhase extends Phase { private eggHatchData: EggHatchData[]; - constructor(scene: BattleScene, eggHatchData: EggHatchData[]) { - super(scene); + constructor(eggHatchData: EggHatchData[]) { + super(); this.eggHatchData = eggHatchData; } @@ -22,8 +22,8 @@ export class EggSummaryPhase extends Phase { // updates next pokemon once the current update has been completed const updateNextPokemon = (i: number) => { if (i >= this.eggHatchData.length) { - this.scene.ui.setModeForceTransition(Mode.EGG_HATCH_SUMMARY, this.eggHatchData).then(() => { - this.scene.fadeOutBgm(undefined, false); + globalScene.ui.setModeForceTransition(Mode.EGG_HATCH_SUMMARY, this.eggHatchData).then(() => { + globalScene.fadeOutBgm(undefined, false); }); } else { @@ -40,8 +40,8 @@ export class EggSummaryPhase extends Phase { } end() { - this.scene.time.delayedCall(250, () => this.scene.setModifiersVisible(true)); - this.scene.ui.setModeForceTransition(Mode.MESSAGE).then(() => { + globalScene.time.delayedCall(250, () => globalScene.setModifiersVisible(true)); + globalScene.ui.setModeForceTransition(Mode.MESSAGE).then(() => { super.end(); }); } diff --git a/src/phases/encounter-phase.ts b/src/phases/encounter-phase.ts index a4c9aa44b360..a7c22e1a3a10 100644 --- a/src/phases/encounter-phase.ts +++ b/src/phases/encounter-phase.ts @@ -1,5 +1,5 @@ import { BattlerIndex, BattleType } from "#app/battle"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; import { applyAbAttrs, SyncEncounterNatureAbAttr } from "#app/data/ability"; import { initEncounterAnims, loadEncounterAnimAssets } from "#app/data/battle-anims"; @@ -41,8 +41,8 @@ import { WEIGHT_INCREMENT_ON_SPAWN_MISS } from "#app/data/mystery-encounters/mys export class EncounterPhase extends BattlePhase { private loaded: boolean; - constructor(scene: BattleScene, loaded?: boolean) { - super(scene); + constructor(loaded?: boolean) { + super(); this.loaded = !!loaded; } @@ -50,26 +50,26 @@ export class EncounterPhase extends BattlePhase { start() { super.start(); - this.scene.updateGameInfo(); + globalScene.updateGameInfo(); - this.scene.initSession(); + globalScene.initSession(); - this.scene.eventTarget.dispatchEvent(new EncounterPhaseEvent()); + globalScene.eventTarget.dispatchEvent(new EncounterPhaseEvent()); // Failsafe if players somehow skip floor 200 in classic mode - if (this.scene.gameMode.isClassic && this.scene.currentBattle.waveIndex > 200) { - this.scene.unshiftPhase(new GameOverPhase(this.scene)); + if (globalScene.gameMode.isClassic && globalScene.currentBattle.waveIndex > 200) { + globalScene.unshiftPhase(new GameOverPhase()); } const loadEnemyAssets: Promise[] = []; - const battle = this.scene.currentBattle; + const battle = globalScene.currentBattle; // Generate and Init Mystery Encounter if (battle.isBattleMysteryEncounter() && !battle.mysteryEncounter) { - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const currentSessionEncounterType = battle.mysteryEncounterType; - battle.mysteryEncounter = this.scene.getMysteryEncounter(currentSessionEncounterType); + battle.mysteryEncounter = globalScene.getMysteryEncounter(currentSessionEncounterType); }, battle.waveIndex * 16); } const mysteryEncounter = battle.mysteryEncounter; @@ -77,21 +77,21 @@ export class EncounterPhase extends BattlePhase { // If ME has an onInit() function, call it // Usually used for calculating rand data before initializing anything visual // Also prepopulates any dialogue tokens from encounter/option requirements - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { if (mysteryEncounter.onInit) { - mysteryEncounter.onInit(this.scene); + mysteryEncounter.onInit(); } - mysteryEncounter.populateDialogueTokensFromRequirements(this.scene); + mysteryEncounter.populateDialogueTokensFromRequirements(); }, battle.waveIndex); // Add any special encounter animations to load if (mysteryEncounter.encounterAnimations && mysteryEncounter.encounterAnimations.length > 0) { - loadEnemyAssets.push(initEncounterAnims(this.scene, mysteryEncounter.encounterAnimations).then(() => loadEncounterAnimAssets(this.scene, true))); + loadEnemyAssets.push(initEncounterAnims(mysteryEncounter.encounterAnimations).then(() => loadEncounterAnimAssets(true))); } // Add intro visuals for mystery encounter - mysteryEncounter.initIntroVisuals(this.scene); - this.scene.field.add(mysteryEncounter.introVisuals!); + mysteryEncounter.initIntroVisuals(); + globalScene.field.add(mysteryEncounter.introVisuals!); } let totalBst = 0; @@ -105,35 +105,35 @@ export class EncounterPhase extends BattlePhase { if (battle.battleType === BattleType.TRAINER) { battle.enemyParty[e] = battle.trainer?.genPartyMember(e)!; // TODO:: is the bang correct here? } else { - let enemySpecies = this.scene.randomSpecies(battle.waveIndex, level, true); + let enemySpecies = globalScene.randomSpecies(battle.waveIndex, level, true); // If player has golden bug net, rolls 10% chance to replace non-boss wave wild species from the golden bug net bug pool - if (this.scene.findModifier(m => m instanceof BoostBugSpawnModifier) - && !this.scene.gameMode.isBoss(battle.waveIndex) - && this.scene.arena.biomeType !== Biome.END + if (globalScene.findModifier(m => m instanceof BoostBugSpawnModifier) + && !globalScene.gameMode.isBoss(battle.waveIndex) + && globalScene.arena.biomeType !== Biome.END && randSeedInt(10) === 0) { enemySpecies = getGoldenBugNetSpecies(level); } - battle.enemyParty[e] = this.scene.addEnemyPokemon(enemySpecies, level, TrainerSlot.NONE, !!this.scene.getEncounterBossSegments(battle.waveIndex, level, enemySpecies)); - if (this.scene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { + battle.enemyParty[e] = globalScene.addEnemyPokemon(enemySpecies, level, TrainerSlot.NONE, !!globalScene.getEncounterBossSegments(battle.waveIndex, level, enemySpecies)); + if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { battle.enemyParty[e].ivs = new Array(6).fill(31); } - this.scene.getPlayerParty().slice(0, !battle.double ? 1 : 2).reverse().forEach(playerPokemon => { + globalScene.getPlayerParty().slice(0, !battle.double ? 1 : 2).reverse().forEach(playerPokemon => { applyAbAttrs(SyncEncounterNatureAbAttr, playerPokemon, null, false, battle.enemyParty[e]); }); } } - const enemyPokemon = this.scene.getEnemyParty()[e]; + const enemyPokemon = globalScene.getEnemyParty()[e]; if (e < (battle.double ? 2 : 1)) { enemyPokemon.setX(-66 + enemyPokemon.getFieldPositionOffset()[0]); enemyPokemon.resetSummonData(); } if (!this.loaded) { - this.scene.gameData.setPokemonSeen(enemyPokemon, true, battle.battleType === BattleType.TRAINER || battle?.mysteryEncounter?.encounterMode === MysteryEncounterMode.TRAINER_BATTLE); + globalScene.gameData.setPokemonSeen(enemyPokemon, true, battle.battleType === BattleType.TRAINER || battle?.mysteryEncounter?.encounterMode === MysteryEncounterMode.TRAINER_BATTLE); } if (enemyPokemon.species.speciesId === Species.ETERNATUS) { - if (this.scene.gameMode.isClassic && (battle.battleSpec === BattleSpec.FINAL_BOSS || this.scene.gameMode.isWaveFinal(battle.waveIndex))) { + if (globalScene.gameMode.isClassic && (battle.battleSpec === BattleSpec.FINAL_BOSS || globalScene.gameMode.isWaveFinal(battle.waveIndex))) { if (battle.battleSpec !== BattleSpec.FINAL_BOSS) { enemyPokemon.formIndex = 1; enemyPokemon.updateScale(); @@ -153,8 +153,8 @@ export class EncounterPhase extends BattlePhase { return true; }); - if (this.scene.getPlayerParty().filter(p => p.isShiny()).length === PLAYER_PARTY_MAX_SIZE) { - this.scene.validateAchv(achvs.SHINY_PARTY); + if (globalScene.getPlayerParty().filter(p => p.isShiny()).length === PLAYER_PARTY_MAX_SIZE) { + globalScene.validateAchv(achvs.SHINY_PARTY); } if (battle.battleType === BattleType.TRAINER) { @@ -168,11 +168,11 @@ export class EncounterPhase extends BattlePhase { } // Load Mystery Encounter Exclamation bubble and sfx loadEnemyAssets.push(new Promise(resolve => { - this.scene.loadSe("GEN8- Exclaim", "battle_anims", "GEN8- Exclaim.wav"); - this.scene.loadImage("encounter_exclaim", "mystery-encounters"); - this.scene.load.once(Phaser.Loader.Events.COMPLETE, () => resolve()); - if (!this.scene.load.isLoading()) { - this.scene.load.start(); + globalScene.loadSe("GEN8- Exclaim", "battle_anims", "GEN8- Exclaim.wav"); + globalScene.loadImage("encounter_exclaim", "mystery-encounters"); + globalScene.load.once(Phaser.Loader.Events.COMPLETE, () => resolve()); + if (!globalScene.load.isLoading()) { + globalScene.load.start(); } })); } else { @@ -196,16 +196,16 @@ export class EncounterPhase extends BattlePhase { } if (e < (battle.double ? 2 : 1)) { if (battle.battleType === BattleType.WILD) { - this.scene.field.add(enemyPokemon); + globalScene.field.add(enemyPokemon); battle.seenEnemyPartyMemberIds.add(enemyPokemon.id); - const playerPokemon = this.scene.getPlayerPokemon(); + const playerPokemon = globalScene.getPlayerPokemon(); if (playerPokemon?.isOnField()) { - this.scene.field.moveBelow(enemyPokemon as Pokemon, playerPokemon); + globalScene.field.moveBelow(enemyPokemon as Pokemon, playerPokemon); } enemyPokemon.tint(0, 0.5); } else if (battle.battleType === BattleType.TRAINER) { enemyPokemon.setVisible(false); - this.scene.currentBattle.trainer?.tint(0, 0.5); + globalScene.currentBattle.trainer?.tint(0, 0.5); } if (battle.double) { enemyPokemon.setFieldPosition(e ? FieldPosition.RIGHT : FieldPosition.LEFT); @@ -215,62 +215,56 @@ export class EncounterPhase extends BattlePhase { }); if (!this.loaded && battle.battleType !== BattleType.MYSTERY_ENCOUNTER) { - regenerateModifierPoolThresholds(this.scene.getEnemyField(), battle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD); - this.scene.generateEnemyModifiers(); - overrideModifiers(this.scene, false); - this.scene.getEnemyField().forEach(enemy => { - overrideHeldItems(this.scene, enemy, false); + regenerateModifierPoolThresholds(globalScene.getEnemyField(), battle.battleType === BattleType.TRAINER ? ModifierPoolType.TRAINER : ModifierPoolType.WILD); + globalScene.generateEnemyModifiers(); + overrideModifiers(false); + globalScene.getEnemyField().forEach(enemy => { + overrideHeldItems(enemy, false); }); } - this.scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { if (!this.loaded) { this.trySetWeatherIfNewBiome(); // Set weather before session gets saved // Game syncs to server on waves X1 and X6 (As of 1.2.0) - this.scene.gameData.saveAll(this.scene, true, battle.waveIndex % 5 === 1 || (this.scene.lastSavePlayTime ?? 0) >= 300).then(success => { - this.scene.disableMenu = false; + globalScene.gameData.saveAll(true, battle.waveIndex % 5 === 1 || (globalScene.lastSavePlayTime ?? 0) >= 300).then(success => { + globalScene.disableMenu = false; if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } this.doEncounter(); - this.scene.resetSeed(); + globalScene.resetSeed(); }); } else { this.doEncounter(); - this.scene.resetSeed(); + globalScene.resetSeed(); } }); }); } doEncounter() { - this.scene.playBgm(undefined, true); - this.scene.updateModifiers(false); - this.scene.setFieldScale(1); - - /*if (startingWave > 10) { - for (let m = 0; m < Math.min(Math.floor(startingWave / 10), 99); m++) - this.scene.addModifier(getPlayerModifierTypeOptionsForWave((m + 1) * 10, 1, this.scene.getPlayerParty())[0].type.newModifier(), true); - this.scene.updateModifiers(true); - }*/ - - const { battleType, waveIndex } = this.scene.currentBattle; - if (this.scene.isMysteryEncounterValidForWave(battleType, waveIndex) && !this.scene.currentBattle.isBattleMysteryEncounter()) { + globalScene.playBgm(undefined, true); + globalScene.updateModifiers(false); + globalScene.setFieldScale(1); + + const { battleType, waveIndex } = globalScene.currentBattle; + if (globalScene.isMysteryEncounterValidForWave(battleType, waveIndex) && !globalScene.currentBattle.isBattleMysteryEncounter()) { // Increment ME spawn chance if an ME could have spawned but did not // Only do this AFTER session has been saved to avoid duplicating increments - this.scene.mysteryEncounterSaveData.encounterSpawnChance += WEIGHT_INCREMENT_ON_SPAWN_MISS; + globalScene.mysteryEncounterSaveData.encounterSpawnChance += WEIGHT_INCREMENT_ON_SPAWN_MISS; } - for (const pokemon of this.scene.getPlayerParty()) { + for (const pokemon of globalScene.getPlayerParty()) { if (pokemon) { pokemon.resetBattleData(); } } - const enemyField = this.scene.getEnemyField(); - this.scene.tweens.add({ - targets: [ this.scene.arenaEnemy, this.scene.currentBattle.trainer, enemyField, this.scene.arenaPlayer, this.scene.trainer ].flat(), + const enemyField = globalScene.getEnemyField(); + globalScene.tweens.add({ + targets: [ globalScene.arenaEnemy, globalScene.currentBattle.trainer, enemyField, globalScene.arenaPlayer, globalScene.trainer ].flat(), x: (_target, _key, value, fieldIndex: integer) => fieldIndex < 2 + (enemyField.length) ? value + 300 : value - 300, duration: 2000, onComplete: () => { @@ -280,13 +274,13 @@ export class EncounterPhase extends BattlePhase { } }); - const encounterIntroVisuals = this.scene.currentBattle?.mysteryEncounter?.introVisuals; + const encounterIntroVisuals = globalScene.currentBattle?.mysteryEncounter?.introVisuals; if (encounterIntroVisuals) { const enterFromRight = encounterIntroVisuals.enterFromRight; if (enterFromRight) { encounterIntroVisuals.x += 500; } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: encounterIntroVisuals, x: enterFromRight ? "-=200" : "+=300", duration: 2000 @@ -295,18 +289,18 @@ export class EncounterPhase extends BattlePhase { } getEncounterMessage(): string { - const enemyField = this.scene.getEnemyField(); + const enemyField = globalScene.getEnemyField(); - if (this.scene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { + if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { return i18next.t("battle:bossAppeared", { bossName: getPokemonNameWithAffix(enemyField[0]) }); } - if (this.scene.currentBattle.battleType === BattleType.TRAINER) { - if (this.scene.currentBattle.double) { - return i18next.t("battle:trainerAppearedDouble", { trainerName: this.scene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); + if (globalScene.currentBattle.battleType === BattleType.TRAINER) { + if (globalScene.currentBattle.double) { + return i18next.t("battle:trainerAppearedDouble", { trainerName: globalScene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); } else { - return i18next.t("battle:trainerAppeared", { trainerName: this.scene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); + return i18next.t("battle:trainerAppeared", { trainerName: globalScene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); } } @@ -316,75 +310,75 @@ export class EncounterPhase extends BattlePhase { } doEncounterCommon(showEncounterMessage: boolean = true) { - const enemyField = this.scene.getEnemyField(); + const enemyField = globalScene.getEnemyField(); - if (this.scene.currentBattle.battleType === BattleType.WILD) { + if (globalScene.currentBattle.battleType === BattleType.WILD) { enemyField.forEach(enemyPokemon => { enemyPokemon.untint(100, "Sine.easeOut"); enemyPokemon.cry(); enemyPokemon.showInfo(); if (enemyPokemon.isShiny()) { - this.scene.validateAchv(achvs.SEE_SHINY); + globalScene.validateAchv(achvs.SEE_SHINY); } }); - this.scene.updateFieldScale(); + globalScene.updateFieldScale(); if (showEncounterMessage) { - this.scene.ui.showText(this.getEncounterMessage(), null, () => this.end(), 1500); + globalScene.ui.showText(this.getEncounterMessage(), null, () => this.end(), 1500); } else { this.end(); } - } else if (this.scene.currentBattle.battleType === BattleType.TRAINER) { - const trainer = this.scene.currentBattle.trainer; + } else if (globalScene.currentBattle.battleType === BattleType.TRAINER) { + const trainer = globalScene.currentBattle.trainer; trainer?.untint(100, "Sine.easeOut"); trainer?.playAnim(); const doSummon = () => { - this.scene.currentBattle.started = true; - this.scene.playBgm(undefined); - this.scene.pbTray.showPbTray(this.scene.getPlayerParty()); - this.scene.pbTrayEnemy.showPbTray(this.scene.getEnemyParty()); + globalScene.currentBattle.started = true; + globalScene.playBgm(undefined); + globalScene.pbTray.showPbTray(globalScene.getPlayerParty()); + globalScene.pbTrayEnemy.showPbTray(globalScene.getEnemyParty()); const doTrainerSummon = () => { this.hideEnemyTrainer(); - const availablePartyMembers = this.scene.getEnemyParty().filter(p => !p.isFainted()).length; - this.scene.unshiftPhase(new SummonPhase(this.scene, 0, false)); - if (this.scene.currentBattle.double && availablePartyMembers > 1) { - this.scene.unshiftPhase(new SummonPhase(this.scene, 1, false)); + const availablePartyMembers = globalScene.getEnemyParty().filter(p => !p.isFainted()).length; + globalScene.unshiftPhase(new SummonPhase(0, false)); + if (globalScene.currentBattle.double && availablePartyMembers > 1) { + globalScene.unshiftPhase(new SummonPhase(1, false)); } this.end(); }; if (showEncounterMessage) { - this.scene.ui.showText(this.getEncounterMessage(), null, doTrainerSummon, 1500, true); + globalScene.ui.showText(this.getEncounterMessage(), null, doTrainerSummon, 1500, true); } else { doTrainerSummon(); } }; - const encounterMessages = this.scene.currentBattle.trainer?.getEncounterMessages(); + const encounterMessages = globalScene.currentBattle.trainer?.getEncounterMessages(); if (!encounterMessages?.length) { doSummon(); } else { let message: string; - this.scene.executeWithSeedOffset(() => message = randSeedItem(encounterMessages), this.scene.currentBattle.waveIndex); + globalScene.executeWithSeedOffset(() => message = randSeedItem(encounterMessages), globalScene.currentBattle.waveIndex); message = message!; // tell TS compiler it's defined now const showDialogueAndSummon = () => { - this.scene.ui.showDialogue(message, trainer?.getName(TrainerSlot.NONE, true), null, () => { - this.scene.charSprite.hide().then(() => this.scene.hideFieldOverlay(250).then(() => doSummon())); + globalScene.ui.showDialogue(message, trainer?.getName(TrainerSlot.NONE, true), null, () => { + globalScene.charSprite.hide().then(() => globalScene.hideFieldOverlay(250).then(() => doSummon())); }); }; - if (this.scene.currentBattle.trainer?.config.hasCharSprite && !this.scene.ui.shouldSkipDialogue(message)) { - this.scene.showFieldOverlay(500).then(() => this.scene.charSprite.showCharacter(trainer?.getKey()!, getCharVariantFromDialogue(encounterMessages[0])).then(() => showDialogueAndSummon())); // TODO: is this bang correct? + if (globalScene.currentBattle.trainer?.config.hasCharSprite && !globalScene.ui.shouldSkipDialogue(message)) { + globalScene.showFieldOverlay(500).then(() => globalScene.charSprite.showCharacter(trainer?.getKey()!, getCharVariantFromDialogue(encounterMessages[0])).then(() => showDialogueAndSummon())); // TODO: is this bang correct? } else { showDialogueAndSummon(); } } - } else if (this.scene.currentBattle.isBattleMysteryEncounter() && this.scene.currentBattle.mysteryEncounter) { - const encounter = this.scene.currentBattle.mysteryEncounter; + } else if (globalScene.currentBattle.isBattleMysteryEncounter() && globalScene.currentBattle.mysteryEncounter) { + const encounter = globalScene.currentBattle.mysteryEncounter; const introVisuals = encounter.introVisuals; introVisuals?.playAnim(); if (encounter.onVisualsStart) { - encounter.onVisualsStart(this.scene); + encounter.onVisualsStart(); } else if (encounter.spriteConfigs && introVisuals) { // If the encounter doesn't have any special visual intro, show sparkle for shiny Pokemon introVisuals.playShinySparkles(); @@ -392,10 +386,10 @@ export class EncounterPhase extends BattlePhase { const doEncounter = () => { const doShowEncounterOptions = () => { - this.scene.ui.clearText(); - this.scene.ui.getMessageHandler().hideNameText(); + globalScene.ui.clearText(); + globalScene.ui.getMessageHandler().hideNameText(); - this.scene.unshiftPhase(new MysteryEncounterPhase(this.scene)); + globalScene.unshiftPhase(new MysteryEncounterPhase()); this.end(); }; @@ -409,13 +403,13 @@ export class EncounterPhase extends BattlePhase { const showNextDialogue = () => { const nextAction = i === introDialogue.length - 1 ? doShowEncounterOptions : showNextDialogue; const dialogue = introDialogue[i]; - const title = getEncounterText(this.scene, dialogue?.speaker); - const text = getEncounterText(this.scene, dialogue.text)!; + const title = getEncounterText(dialogue?.speaker); + const text = getEncounterText(dialogue.text)!; i++; if (title) { - this.scene.ui.showDialogue(text, title, null, nextAction, 0, i === 1 ? FIRST_DIALOGUE_PROMPT_DELAY : 0); + globalScene.ui.showDialogue(text, title, null, nextAction, 0, i === 1 ? FIRST_DIALOGUE_PROMPT_DELAY : 0); } else { - this.scene.ui.showText(text, null, nextAction, i === 1 ? FIRST_DIALOGUE_PROMPT_DELAY : 0, true); + globalScene.ui.showText(text, null, nextAction, i === 1 ? FIRST_DIALOGUE_PROMPT_DELAY : 0, true); } }; @@ -433,110 +427,110 @@ export class EncounterPhase extends BattlePhase { if (!encounterMessage) { doEncounter(); } else { - doTrainerExclamation(this.scene); - this.scene.ui.showDialogue(encounterMessage, "???", null, () => { - this.scene.charSprite.hide().then(() => this.scene.hideFieldOverlay(250).then(() => doEncounter())); + doTrainerExclamation(); + globalScene.ui.showDialogue(encounterMessage, "???", null, () => { + globalScene.charSprite.hide().then(() => globalScene.hideFieldOverlay(250).then(() => doEncounter())); }); } } } end() { - const enemyField = this.scene.getEnemyField(); + const enemyField = globalScene.getEnemyField(); enemyField.forEach((enemyPokemon, e) => { if (enemyPokemon.isShiny()) { - this.scene.unshiftPhase(new ShinySparklePhase(this.scene, BattlerIndex.ENEMY + e)); + globalScene.unshiftPhase(new ShinySparklePhase(BattlerIndex.ENEMY + e)); } /** This sets Eternatus' held item to be untransferrable, preventing it from being stolen */ - if (enemyPokemon.species.speciesId === Species.ETERNATUS && (this.scene.gameMode.isBattleClassicFinalBoss(this.scene.currentBattle.waveIndex) || this.scene.gameMode.isEndlessMajorBoss(this.scene.currentBattle.waveIndex))) { - const enemyMBH = this.scene.findModifier(m => m instanceof TurnHeldItemTransferModifier, false) as TurnHeldItemTransferModifier; + if (enemyPokemon.species.speciesId === Species.ETERNATUS && (globalScene.gameMode.isBattleClassicFinalBoss(globalScene.currentBattle.waveIndex) || globalScene.gameMode.isEndlessMajorBoss(globalScene.currentBattle.waveIndex))) { + const enemyMBH = globalScene.findModifier(m => m instanceof TurnHeldItemTransferModifier, false) as TurnHeldItemTransferModifier; if (enemyMBH) { - this.scene.removeModifier(enemyMBH, true); + globalScene.removeModifier(enemyMBH, true); enemyMBH.setTransferrableFalse(); - this.scene.addEnemyModifier(enemyMBH); + globalScene.addEnemyModifier(enemyMBH); } } }); - if (![ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(this.scene.currentBattle.battleType)) { - enemyField.map(p => this.scene.pushConditionalPhase(new PostSummonPhase(this.scene, p.getBattlerIndex()), () => { + if (![ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(globalScene.currentBattle.battleType)) { + enemyField.map(p => globalScene.pushConditionalPhase(new PostSummonPhase(p.getBattlerIndex()), () => { // if there is not a player party, we can't continue - if (!this.scene.getPlayerParty().length) { + if (!globalScene.getPlayerParty().length) { return false; } // how many player pokemon are on the field ? - const pokemonsOnFieldCount = this.scene.getPlayerParty().filter(p => p.isOnField()).length; + const pokemonsOnFieldCount = globalScene.getPlayerParty().filter(p => p.isOnField()).length; // if it's a 2vs1, there will never be a 2nd pokemon on our field even - const requiredPokemonsOnField = Math.min(this.scene.getPlayerParty().filter((p) => !p.isFainted()).length, 2); + const requiredPokemonsOnField = Math.min(globalScene.getPlayerParty().filter((p) => !p.isFainted()).length, 2); // if it's a double, there should be 2, otherwise 1 - if (this.scene.currentBattle.double) { + if (globalScene.currentBattle.double) { return pokemonsOnFieldCount === requiredPokemonsOnField; } return pokemonsOnFieldCount === 1; })); - const ivScannerModifier = this.scene.findModifier(m => m instanceof IvScannerModifier); + const ivScannerModifier = globalScene.findModifier(m => m instanceof IvScannerModifier); if (ivScannerModifier) { - enemyField.map(p => this.scene.pushPhase(new ScanIvsPhase(this.scene, p.getBattlerIndex(), Math.min(ivScannerModifier.getStackCount() * 2, 6)))); + enemyField.map(p => globalScene.pushPhase(new ScanIvsPhase(p.getBattlerIndex(), Math.min(ivScannerModifier.getStackCount() * 2, 6)))); } } if (!this.loaded) { - const availablePartyMembers = this.scene.getPokemonAllowedInBattle(); + const availablePartyMembers = globalScene.getPokemonAllowedInBattle(); if (!availablePartyMembers[0].isOnField()) { - this.scene.pushPhase(new SummonPhase(this.scene, 0)); + globalScene.pushPhase(new SummonPhase(0)); } - if (this.scene.currentBattle.double) { + if (globalScene.currentBattle.double) { if (availablePartyMembers.length > 1) { - this.scene.pushPhase(new ToggleDoublePositionPhase(this.scene, true)); + globalScene.pushPhase(new ToggleDoublePositionPhase(true)); if (!availablePartyMembers[1].isOnField()) { - this.scene.pushPhase(new SummonPhase(this.scene, 1)); + globalScene.pushPhase(new SummonPhase(1)); } } } else { if (availablePartyMembers.length > 1 && availablePartyMembers[1].isOnField()) { - this.scene.pushPhase(new ReturnPhase(this.scene, 1)); + globalScene.pushPhase(new ReturnPhase(1)); } - this.scene.pushPhase(new ToggleDoublePositionPhase(this.scene, false)); + globalScene.pushPhase(new ToggleDoublePositionPhase(false)); } - if (this.scene.currentBattle.battleType !== BattleType.TRAINER && (this.scene.currentBattle.waveIndex > 1 || !this.scene.gameMode.isDaily)) { - const minPartySize = this.scene.currentBattle.double ? 2 : 1; + if (globalScene.currentBattle.battleType !== BattleType.TRAINER && (globalScene.currentBattle.waveIndex > 1 || !globalScene.gameMode.isDaily)) { + const minPartySize = globalScene.currentBattle.double ? 2 : 1; if (availablePartyMembers.length > minPartySize) { - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 0, this.scene.currentBattle.double)); - if (this.scene.currentBattle.double) { - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); + globalScene.pushPhase(new CheckSwitchPhase(0, globalScene.currentBattle.double)); + if (globalScene.currentBattle.double) { + globalScene.pushPhase(new CheckSwitchPhase(1, globalScene.currentBattle.double)); } } } } - handleTutorial(this.scene, Tutorial.Access_Menu).then(() => super.end()); + handleTutorial(Tutorial.Access_Menu).then(() => super.end()); } tryOverrideForBattleSpec(): boolean { - switch (this.scene.currentBattle.battleSpec) { + switch (globalScene.currentBattle.battleSpec) { case BattleSpec.FINAL_BOSS: - const enemy = this.scene.getEnemyPokemon(); - this.scene.ui.showText(this.getEncounterMessage(), null, () => { + const enemy = globalScene.getEnemyPokemon(); + globalScene.ui.showText(this.getEncounterMessage(), null, () => { const localizationKey = "battleSpecDialogue:encounter"; - if (this.scene.ui.shouldSkipDialogue(localizationKey)) { + if (globalScene.ui.shouldSkipDialogue(localizationKey)) { // Logging mirrors logging found in dialogue-ui-handler console.log(`Dialogue ${localizationKey} skipped`); this.doEncounterCommon(false); } else { - const count = 5643853 + this.scene.gameData.gameStats.classicSessionsPlayed; + const count = 5643853 + globalScene.gameData.gameStats.classicSessionsPlayed; // The line below checks if an English ordinal is necessary or not based on whether an entry for encounterLocalizationKey exists in the language or not. const ordinalUsed = !i18next.exists(localizationKey, { fallbackLng: []}) || i18next.resolvedLanguage === "en" ? i18next.t("battleSpecDialogue:key", { count: count, ordinal: true }) : ""; const cycleCount = count.toLocaleString() + ordinalUsed; - const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const genderStr = PlayerGender[genderIndex].toLowerCase(); const encounterDialogue = i18next.t(localizationKey, { context: genderStr, cycleCount: cycleCount }); - if (!this.scene.gameData.getSeenDialogues()[localizationKey]) { - this.scene.gameData.saveSeenDialogue(localizationKey); + if (!globalScene.gameData.getSeenDialogues()[localizationKey]) { + globalScene.gameData.saveSeenDialogue(localizationKey); } - this.scene.ui.showDialogue(encounterDialogue, enemy?.species.name, null, () => { + globalScene.ui.showDialogue(encounterDialogue, enemy?.species.name, null, () => { this.doEncounterCommon(false); }); } @@ -556,7 +550,7 @@ export class EncounterPhase extends BattlePhase { */ trySetWeatherIfNewBiome(): void { if (!this.loaded) { - this.scene.arena.trySetWeather(getRandomWeatherType(this.scene.arena), false); + globalScene.arena.trySetWeather(getRandomWeatherType(globalScene.arena), false); } } } diff --git a/src/phases/end-card-phase.ts b/src/phases/end-card-phase.ts index 274a745017a2..4615a60e661b 100644 --- a/src/phases/end-card-phase.ts +++ b/src/phases/end-card-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { PlayerGender } from "#app/enums/player-gender"; import { Phase } from "#app/phase"; import { addTextObject, TextStyle } from "#app/ui/text"; @@ -8,31 +8,31 @@ export class EndCardPhase extends Phase { public endCard: Phaser.GameObjects.Image; public text: Phaser.GameObjects.Text; - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start(): void { super.start(); - this.scene.ui.getMessageHandler().bg.setVisible(false); - this.scene.ui.getMessageHandler().nameBoxContainer.setVisible(false); + globalScene.ui.getMessageHandler().bg.setVisible(false); + globalScene.ui.getMessageHandler().nameBoxContainer.setVisible(false); - this.endCard = this.scene.add.image(0, 0, `end_${this.scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}`); + this.endCard = globalScene.add.image(0, 0, `end_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}`); this.endCard.setOrigin(0); this.endCard.setScale(0.5); - this.scene.field.add(this.endCard); + globalScene.field.add(this.endCard); - this.text = addTextObject(this.scene, this.scene.game.canvas.width / 12, (this.scene.game.canvas.height / 6) - 16, i18next.t("battle:congratulations"), TextStyle.SUMMARY, { fontSize: "128px" }); + this.text = addTextObject(globalScene.game.canvas.width / 12, (globalScene.game.canvas.height / 6) - 16, i18next.t("battle:congratulations"), TextStyle.SUMMARY, { fontSize: "128px" }); this.text.setOrigin(0.5); - this.scene.field.add(this.text); + globalScene.field.add(this.text); - this.scene.ui.clearText(); + globalScene.ui.clearText(); - this.scene.ui.fadeIn(1000).then(() => { + globalScene.ui.fadeIn(1000).then(() => { - this.scene.ui.showText("", null, () => { - this.scene.ui.getMessageHandler().bg.setVisible(true); + globalScene.ui.showText("", null, () => { + globalScene.ui.getMessageHandler().bg.setVisible(true); this.end(); }, null, true); }); diff --git a/src/phases/end-evolution-phase.ts b/src/phases/end-evolution-phase.ts index 8a6ce52553d4..58e2e2034821 100644 --- a/src/phases/end-evolution-phase.ts +++ b/src/phases/end-evolution-phase.ts @@ -1,16 +1,16 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { Mode } from "#app/ui/ui"; export class EndEvolutionPhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - this.scene.ui.setModeForceTransition(Mode.MESSAGE).then(() => this.end()); + globalScene.ui.setModeForceTransition(Mode.MESSAGE).then(() => this.end()); } } diff --git a/src/phases/enemy-command-phase.ts b/src/phases/enemy-command-phase.ts index 83a85009ae03..715303863be5 100644 --- a/src/phases/enemy-command-phase.ts +++ b/src/phases/enemy-command-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { Command } from "#app/ui/command-ui-handler"; import { FieldPhase } from "./field-phase"; @@ -18,11 +18,11 @@ export class EnemyCommandPhase extends FieldPhase { protected fieldIndex: integer; protected skipTurn: boolean = false; - constructor(scene: BattleScene, fieldIndex: integer) { - super(scene); + constructor(fieldIndex: integer) { + super(); this.fieldIndex = fieldIndex; - if (this.scene.currentBattle.mysteryEncounter?.skipEnemyBattleTurns) { + if (globalScene.currentBattle.mysteryEncounter?.skipEnemyBattleTurns) { this.skipTurn = true; } } @@ -30,9 +30,9 @@ export class EnemyCommandPhase extends FieldPhase { start() { super.start(); - const enemyPokemon = this.scene.getEnemyField()[this.fieldIndex]; + const enemyPokemon = globalScene.getEnemyField()[this.fieldIndex]; - const battle = this.scene.currentBattle; + const battle = globalScene.currentBattle; const trainer = battle.trainer; @@ -81,10 +81,10 @@ export class EnemyCommandPhase extends FieldPhase { /** Select a move to use (and a target to use it against, if applicable) */ const nextMove = enemyPokemon.getNextMove(); - this.scene.currentBattle.turnCommands[this.fieldIndex + BattlerIndex.ENEMY] = + globalScene.currentBattle.turnCommands[this.fieldIndex + BattlerIndex.ENEMY] = { command: Command.FIGHT, move: nextMove, skip: this.skipTurn }; - this.scene.currentBattle.enemySwitchCounter = Math.max(this.scene.currentBattle.enemySwitchCounter - 1, 0); + globalScene.currentBattle.enemySwitchCounter = Math.max(globalScene.currentBattle.enemySwitchCounter - 1, 0); this.end(); } diff --git a/src/phases/enemy-party-member-pokemon-phase.ts b/src/phases/enemy-party-member-pokemon-phase.ts index bb34f53b4755..1f9fcd6402e8 100644 --- a/src/phases/enemy-party-member-pokemon-phase.ts +++ b/src/phases/enemy-party-member-pokemon-phase.ts @@ -1,10 +1,9 @@ -import BattleScene from "#app/battle-scene"; import { EnemyPokemon } from "#app/field/pokemon"; import { PartyMemberPokemonPhase } from "./party-member-pokemon-phase"; export abstract class EnemyPartyMemberPokemonPhase extends PartyMemberPokemonPhase { - constructor(scene: BattleScene, partyMemberIndex: integer) { - super(scene, partyMemberIndex, false); + constructor(partyMemberIndex: integer) { + super(partyMemberIndex, false); } getEnemyPokemon(): EnemyPokemon { diff --git a/src/phases/evolution-phase.ts b/src/phases/evolution-phase.ts index 76e521c9b3d5..29b84d146f0c 100644 --- a/src/phases/evolution-phase.ts +++ b/src/phases/evolution-phase.ts @@ -1,6 +1,7 @@ import SoundFade from "phaser3-rex-plugins/plugins/soundfade"; import { Phase } from "#app/phase"; -import BattleScene, { AnySound } from "#app/battle-scene"; +import { AnySound } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { FusionSpeciesFormEvolution, SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions"; import EvolutionSceneHandler from "#app/ui/evolution-scene-handler"; import * as Utils from "#app/utils"; @@ -35,8 +36,8 @@ export class EvolutionPhase extends Phase { protected pokemonEvoSprite: Phaser.GameObjects.Sprite; protected pokemonEvoTintSprite: Phaser.GameObjects.Sprite; - constructor(scene: BattleScene, pokemon: PlayerPokemon, evolution: SpeciesFormEvolution | null, lastLevel: integer) { - super(scene); + constructor(pokemon: PlayerPokemon, evolution: SpeciesFormEvolution | null, lastLevel: integer) { + super(); this.pokemon = pokemon; this.evolution = evolution; @@ -49,7 +50,7 @@ export class EvolutionPhase extends Phase { } setMode(): Promise { - return this.scene.ui.setModeForceTransition(Mode.EVOLUTION_SCENE); + return globalScene.ui.setModeForceTransition(Mode.EVOLUTION_SCENE); } start() { @@ -61,30 +62,30 @@ export class EvolutionPhase extends Phase { return this.end(); } - this.scene.fadeOutBgm(undefined, false); + globalScene.fadeOutBgm(undefined, false); - this.evolutionHandler = this.scene.ui.getHandler() as EvolutionSceneHandler; + this.evolutionHandler = globalScene.ui.getHandler() as EvolutionSceneHandler; this.evolutionContainer = this.evolutionHandler.evolutionContainer; - this.evolutionBaseBg = this.scene.add.image(0, 0, "default_bg"); + this.evolutionBaseBg = globalScene.add.image(0, 0, "default_bg"); this.evolutionBaseBg.setOrigin(0, 0); this.evolutionContainer.add(this.evolutionBaseBg); - this.evolutionBg = this.scene.add.video(0, 0, "evo_bg").stop(); + this.evolutionBg = globalScene.add.video(0, 0, "evo_bg").stop(); this.evolutionBg.setOrigin(0, 0); this.evolutionBg.setScale(0.4359673025); this.evolutionBg.setVisible(false); this.evolutionContainer.add(this.evolutionBg); - this.evolutionBgOverlay = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x262626); + this.evolutionBgOverlay = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0x262626); this.evolutionBgOverlay.setOrigin(0, 0); this.evolutionBgOverlay.setAlpha(0); this.evolutionContainer.add(this.evolutionBgOverlay); const getPokemonSprite = () => { - const ret = this.scene.addPokemonSprite(this.pokemon, this.evolutionBaseBg.displayWidth / 2, this.evolutionBaseBg.displayHeight / 2, "pkmn__sub"); - ret.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + const ret = globalScene.addPokemonSprite(this.pokemon, this.evolutionBaseBg.displayWidth / 2, this.evolutionBaseBg.displayHeight / 2, "pkmn__sub"); + ret.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); return ret; }; @@ -99,10 +100,10 @@ export class EvolutionPhase extends Phase { this.pokemonEvoTintSprite.setVisible(false); this.pokemonEvoTintSprite.setTintFill(0xFFFFFF); - this.evolutionOverlay = this.scene.add.rectangle(0, -this.scene.game.canvas.height / 6, this.scene.game.canvas.width / 6, (this.scene.game.canvas.height / 6) - 48, 0xFFFFFF); + this.evolutionOverlay = globalScene.add.rectangle(0, -globalScene.game.canvas.height / 6, globalScene.game.canvas.width / 6, (globalScene.game.canvas.height / 6) - 48, 0xFFFFFF); this.evolutionOverlay.setOrigin(0, 0); this.evolutionOverlay.setAlpha(0); - this.scene.ui.add(this.evolutionOverlay); + globalScene.ui.add(this.evolutionOverlay); [ this.pokemonSprite, this.pokemonTintSprite, this.pokemonEvoSprite, this.pokemonEvoTintSprite ].map(sprite => { const spriteKey = this.pokemon.getSpriteKey(true); @@ -112,7 +113,7 @@ export class EvolutionPhase extends Phase { console.error(`Failed to play animation for ${spriteKey}`, err); } - sprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(this.pokemon.getTeraType()) }); + sprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(this.pokemon.getTeraType()) }); sprite.setPipelineData("ignoreTimeTint", true); sprite.setPipelineData("spriteKey", this.pokemon.getSpriteKey()); sprite.setPipelineData("shiny", this.pokemon.shiny); @@ -130,7 +131,7 @@ export class EvolutionPhase extends Phase { } doEvolution(): void { - this.scene.ui.showText(i18next.t("menu:evolving", { pokemonName: this.preEvolvedPokemonName }), null, () => { + globalScene.ui.showText(i18next.t("menu:evolving", { pokemonName: this.preEvolvedPokemonName }), null, () => { this.pokemon.cry(); this.pokemon.getPossibleEvolution(this.evolution).then(evolvedPokemon => { @@ -155,17 +156,17 @@ export class EvolutionPhase extends Phase { }); }); - this.scene.time.delayedCall(1000, () => { - this.evolutionBgm = this.scene.playSoundWithoutBgm("evolution"); - this.scene.tweens.add({ + globalScene.time.delayedCall(1000, () => { + this.evolutionBgm = globalScene.playSoundWithoutBgm("evolution"); + globalScene.tweens.add({ targets: this.evolutionBgOverlay, alpha: 1, delay: 500, duration: 1500, ease: "Sine.easeOut", onComplete: () => { - this.scene.time.delayedCall(1000, () => { - this.scene.tweens.add({ + globalScene.time.delayedCall(1000, () => { + globalScene.tweens.add({ targets: this.evolutionBgOverlay, alpha: 0, duration: 250 @@ -173,9 +174,9 @@ export class EvolutionPhase extends Phase { this.evolutionBg.setVisible(true); this.evolutionBg.play(); }); - this.scene.playSound("se/charge"); + globalScene.playSound("se/charge"); this.doSpiralUpward(); - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ from: 0, to: 1, duration: 2000, @@ -184,10 +185,10 @@ export class EvolutionPhase extends Phase { }, onComplete: () => { this.pokemonSprite.setVisible(false); - this.scene.time.delayedCall(1100, () => { - this.scene.playSound("se/beam"); + globalScene.time.delayedCall(1100, () => { + globalScene.playSound("se/beam"); this.doArcDownward(); - this.scene.time.delayedCall(1500, () => { + globalScene.time.delayedCall(1500, () => { this.pokemonEvoTintSprite.setScale(0.25); this.pokemonEvoTintSprite.setVisible(true); this.evolutionHandler.canCancel = true; @@ -216,7 +217,7 @@ export class EvolutionPhase extends Phase { private handleFailedEvolution(evolvedPokemon: Pokemon): void { this.pokemonSprite.setVisible(true); this.pokemonTintSprite.setScale(1); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.evolutionBg, this.pokemonTintSprite, this.pokemonEvoSprite, this.pokemonEvoTintSprite ], alpha: 0, duration: 250, @@ -225,25 +226,25 @@ export class EvolutionPhase extends Phase { } }); - SoundFade.fadeOut(this.scene, this.evolutionBgm, 100); + SoundFade.fadeOut(globalScene, this.evolutionBgm, 100); - this.scene.unshiftPhase(new EndEvolutionPhase(this.scene)); + globalScene.unshiftPhase(new EndEvolutionPhase()); - this.scene.ui.showText(i18next.t("menu:stoppedEvolving", { pokemonName: this.preEvolvedPokemonName }), null, () => { - this.scene.ui.showText(i18next.t("menu:pauseEvolutionsQuestion", { pokemonName: this.preEvolvedPokemonName }), null, () => { + globalScene.ui.showText(i18next.t("menu:stoppedEvolving", { pokemonName: this.preEvolvedPokemonName }), null, () => { + globalScene.ui.showText(i18next.t("menu:pauseEvolutionsQuestion", { pokemonName: this.preEvolvedPokemonName }), null, () => { const end = () => { - this.scene.ui.showText("", 0); - this.scene.playBgm(); + globalScene.ui.showText("", 0); + globalScene.playBgm(); evolvedPokemon.destroy(); this.end(); }; - this.scene.ui.setOverlayMode(Mode.CONFIRM, () => { - this.scene.ui.revertMode(); + globalScene.ui.setOverlayMode(Mode.CONFIRM, () => { + globalScene.ui.revertMode(); this.pokemon.pauseEvolutions = true; - this.scene.ui.showText(i18next.t("menu:evolutionsPaused", { pokemonName: this.preEvolvedPokemonName }), null, end, 3000); + globalScene.ui.showText(i18next.t("menu:evolutionsPaused", { pokemonName: this.preEvolvedPokemonName }), null, end, 3000); }, () => { - this.scene.ui.revertMode(); - this.scene.time.delayedCall(3000, end); + globalScene.ui.revertMode(); + globalScene.time.delayedCall(3000, end); }); }); }, null, true); @@ -254,38 +255,38 @@ export class EvolutionPhase extends Phase { * @param evolvedPokemon - The evolved Pokemon */ private handleSuccessEvolution(evolvedPokemon: Pokemon): void { - this.scene.playSound("se/sparkle"); + globalScene.playSound("se/sparkle"); this.pokemonEvoSprite.setVisible(true); this.doCircleInward(); const onEvolutionComplete = () => { - SoundFade.fadeOut(this.scene, this.evolutionBgm, 100); - this.scene.time.delayedCall(250, () => { + SoundFade.fadeOut(globalScene, this.evolutionBgm, 100); + globalScene.time.delayedCall(250, () => { this.pokemon.cry(); - this.scene.time.delayedCall(1250, () => { - this.scene.playSoundWithoutBgm("evolution_fanfare"); + globalScene.time.delayedCall(1250, () => { + globalScene.playSoundWithoutBgm("evolution_fanfare"); evolvedPokemon.destroy(); - this.scene.ui.showText(i18next.t("menu:evolutionDone", { pokemonName: this.preEvolvedPokemonName, evolvedPokemonName: this.pokemon.name }), null, () => this.end(), null, true, Utils.fixedInt(4000)); - this.scene.time.delayedCall(Utils.fixedInt(4250), () => this.scene.playBgm()); + globalScene.ui.showText(i18next.t("menu:evolutionDone", { pokemonName: this.preEvolvedPokemonName, evolvedPokemonName: this.pokemon.name }), null, () => this.end(), null, true, Utils.fixedInt(4000)); + globalScene.time.delayedCall(Utils.fixedInt(4250), () => globalScene.playBgm()); }); }); }; - this.scene.time.delayedCall(900, () => { + globalScene.time.delayedCall(900, () => { this.evolutionHandler.canCancel = false; this.pokemon.evolve(this.evolution, this.pokemon.species).then(() => { const learnSituation: LearnMoveSituation = this.fusionSpeciesEvolved ? LearnMoveSituation.EVOLUTION_FUSED : this.pokemon.fusionSpecies ? LearnMoveSituation.EVOLUTION_FUSED_BASE : LearnMoveSituation.EVOLUTION; const levelMoves = this.pokemon.getLevelMoves(this.lastLevel + 1, true, false, false, learnSituation).filter(lm => lm[0] === EVOLVE_MOVE); for (const lm of levelMoves) { - this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.scene.getPlayerParty().indexOf(this.pokemon), lm[1])); + globalScene.unshiftPhase(new LearnMovePhase(globalScene.getPlayerParty().indexOf(this.pokemon), lm[1])); } - this.scene.unshiftPhase(new EndEvolutionPhase(this.scene)); + globalScene.unshiftPhase(new EndEvolutionPhase()); - this.scene.playSound("se/shine"); + globalScene.playSound("se/shine"); this.doSpray(); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.evolutionOverlay, alpha: 1, duration: 250, @@ -293,14 +294,14 @@ export class EvolutionPhase extends Phase { onComplete: () => { this.evolutionBgOverlay.setAlpha(1); this.evolutionBg.setVisible(false); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.evolutionOverlay, this.pokemonEvoTintSprite ], alpha: 0, duration: 2000, delay: 150, easing: "Sine.easeIn", onComplete: () => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.evolutionBgOverlay, alpha: 0, duration: 250, @@ -317,7 +318,7 @@ export class EvolutionPhase extends Phase { doSpiralUpward() { let f = 0; - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: 64, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -336,7 +337,7 @@ export class EvolutionPhase extends Phase { doArcDownward() { let f = 0; - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: 96, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -355,14 +356,14 @@ export class EvolutionPhase extends Phase { doCycle(l: number, lastCycle: integer = 15): Promise { return new Promise(resolve => { const isLastCycle = l === lastCycle; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemonTintSprite, scale: 0.25, ease: "Cubic.easeInOut", duration: 500 / l, yoyo: !isLastCycle }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemonEvoTintSprite, scale: 1, ease: "Cubic.easeInOut", @@ -386,7 +387,7 @@ export class EvolutionPhase extends Phase { doCircleInward() { let f = 0; - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: 48, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -407,7 +408,7 @@ export class EvolutionPhase extends Phase { doSpray() { let f = 0; - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ repeat: 48, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -425,13 +426,13 @@ export class EvolutionPhase extends Phase { doSpiralUpwardParticle(trigIndex: integer) { const initialX = this.evolutionBaseBg.displayWidth / 2; - const particle = this.scene.add.image(initialX, 0, "evo_sparkle"); + const particle = globalScene.add.image(initialX, 0, "evo_sparkle"); this.evolutionContainer.add(particle); let f = 0; let amp = 48; - const particleTimer = this.scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -461,14 +462,14 @@ export class EvolutionPhase extends Phase { doArcDownParticle(trigIndex: integer) { const initialX = this.evolutionBaseBg.displayWidth / 2; - const particle = this.scene.add.image(initialX, 0, "evo_sparkle"); + const particle = globalScene.add.image(initialX, 0, "evo_sparkle"); particle.setScale(0.5); this.evolutionContainer.add(particle); let f = 0; let amp = 8; - const particleTimer = this.scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -495,12 +496,12 @@ export class EvolutionPhase extends Phase { doCircleInwardParticle(trigIndex: integer, speed: integer) { const initialX = this.evolutionBaseBg.displayWidth / 2; const initialY = this.evolutionBaseBg.displayHeight / 2; - const particle = this.scene.add.image(initialX, initialY, "evo_sparkle"); + const particle = globalScene.add.image(initialX, initialY, "evo_sparkle"); this.evolutionContainer.add(particle); let amp = 120; - const particleTimer = this.scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: Utils.getFrameMs(1), onRepeat: () => { @@ -527,7 +528,7 @@ export class EvolutionPhase extends Phase { doSprayParticle(trigIndex: integer) { const initialX = this.evolutionBaseBg.displayWidth / 2; const initialY = this.evolutionBaseBg.displayHeight / 2; - const particle = this.scene.add.image(initialX, initialY, "evo_sparkle"); + const particle = globalScene.add.image(initialX, initialY, "evo_sparkle"); this.evolutionContainer.add(particle); let f = 0; @@ -535,7 +536,7 @@ export class EvolutionPhase extends Phase { const speed = 3 - Utils.randInt(8); const amp = 48 + Utils.randInt(64); - const particleTimer = this.scene.tweens.addCounter({ + const particleTimer = globalScene.tweens.addCounter({ repeat: -1, duration: Utils.getFrameMs(1), onRepeat: () => { diff --git a/src/phases/exp-phase.ts b/src/phases/exp-phase.ts index 81982980d2ae..f0fe9fde7190 100644 --- a/src/phases/exp-phase.ts +++ b/src/phases/exp-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { getPokemonNameWithAffix } from "#app/messages"; import { ExpBoosterModifier } from "#app/modifier/modifier"; import i18next from "i18next"; @@ -9,8 +9,8 @@ import { LevelUpPhase } from "./level-up-phase"; export class ExpPhase extends PlayerPartyMemberPokemonPhase { private expValue: number; - constructor(scene: BattleScene, partyMemberIndex: integer, expValue: number) { - super(scene, partyMemberIndex); + constructor(partyMemberIndex: integer, expValue: number) { + super(partyMemberIndex); this.expValue = expValue; } @@ -20,14 +20,14 @@ export class ExpPhase extends PlayerPartyMemberPokemonPhase { const pokemon = this.getPokemon(); const exp = new Utils.NumberHolder(this.expValue); - this.scene.applyModifiers(ExpBoosterModifier, true, exp); + globalScene.applyModifiers(ExpBoosterModifier, true, exp); exp.value = Math.floor(exp.value); - this.scene.ui.showText(i18next.t("battle:expGain", { pokemonName: getPokemonNameWithAffix(pokemon), exp: exp.value }), null, () => { + globalScene.ui.showText(i18next.t("battle:expGain", { pokemonName: getPokemonNameWithAffix(pokemon), exp: exp.value }), null, () => { const lastLevel = pokemon.level; pokemon.addExp(exp.value); const newLevel = pokemon.level; if (newLevel > lastLevel) { - this.scene.unshiftPhase(new LevelUpPhase(this.scene, this.partyMemberIndex, lastLevel, newLevel)); + globalScene.unshiftPhase(new LevelUpPhase(this.partyMemberIndex, lastLevel, newLevel)); } pokemon.updateInfo().then(() => this.end()); }, null, true); diff --git a/src/phases/faint-phase.ts b/src/phases/faint-phase.ts index a0c10015fbf5..70e8ebac526c 100644 --- a/src/phases/faint-phase.ts +++ b/src/phases/faint-phase.ts @@ -1,5 +1,5 @@ import { BattlerIndex, BattleType } from "#app/battle"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { applyPostFaintAbAttrs, applyPostKnockOutAbAttrs, applyPostVictoryAbAttrs, PostFaintAbAttr, PostKnockOutAbAttr, PostVictoryAbAttr } from "#app/data/ability"; import { BattlerTagLapseType, DestinyBondTag, GrudgeTag } from "#app/data/battler-tags"; import { battleSpecDialogue } from "#app/data/dialogue"; @@ -43,8 +43,8 @@ export class FaintPhase extends PokemonPhase { */ private source?: Pokemon; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, preventEndure: boolean = false, destinyTag?: DestinyBondTag | null, grudgeTag?: GrudgeTag | null, source?: Pokemon) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, preventEndure: boolean = false, destinyTag?: DestinyBondTag | null, grudgeTag?: GrudgeTag | null, source?: Pokemon) { + super(battlerIndex); this.preventEndure = preventEndure; this.destinyTag = destinyTag; @@ -66,20 +66,20 @@ export class FaintPhase extends PokemonPhase { } if (!this.preventEndure) { - const instantReviveModifier = this.scene.applyModifier(PokemonInstantReviveModifier, this.player, faintPokemon) as PokemonInstantReviveModifier; + const instantReviveModifier = globalScene.applyModifier(PokemonInstantReviveModifier, this.player, faintPokemon) as PokemonInstantReviveModifier; if (instantReviveModifier) { faintPokemon.loseHeldItem(instantReviveModifier); - this.scene.updateModifiers(this.player); + globalScene.updateModifiers(this.player); return this.end(); } } /** In case the current pokemon was just switched in, make sure it is counted as participating in the combat */ - this.scene.getPlayerField().forEach((pokemon, i) => { + globalScene.getPlayerField().forEach((pokemon, i) => { if (pokemon?.isActive(true)) { if (pokemon.isPlayer()) { - this.scene.currentBattle.addParticipant(pokemon as PlayerPokemon); + globalScene.currentBattle.addParticipant(pokemon as PlayerPokemon); } } }); @@ -95,27 +95,27 @@ export class FaintPhase extends PokemonPhase { // Track total times pokemon have been KO'd for supreme overlord/last respects if (pokemon.isPlayer()) { - this.scene.currentBattle.playerFaints += 1; - this.scene.currentBattle.playerFaintsHistory.push({ pokemon: pokemon, turn: this.scene.currentBattle.turn }); + globalScene.currentBattle.playerFaints += 1; + globalScene.currentBattle.playerFaintsHistory.push({ pokemon: pokemon, turn: globalScene.currentBattle.turn }); } else { - this.scene.currentBattle.enemyFaints += 1; - this.scene.currentBattle.enemyFaintsHistory.push({ pokemon: pokemon, turn: this.scene.currentBattle.turn }); + globalScene.currentBattle.enemyFaints += 1; + globalScene.currentBattle.enemyFaintsHistory.push({ pokemon: pokemon, turn: globalScene.currentBattle.turn }); } - this.scene.queueMessage(i18next.t("battle:fainted", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, true); - this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); + globalScene.queueMessage(i18next.t("battle:fainted", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) }), null, true); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); if (pokemon.turnData?.attacksReceived?.length) { const lastAttack = pokemon.turnData.attacksReceived[0]; - applyPostFaintAbAttrs(PostFaintAbAttr, pokemon, this.scene.getPokemonById(lastAttack.sourceId)!, new PokemonMove(lastAttack.move).getMove(), lastAttack.result); // TODO: is this bang correct? + applyPostFaintAbAttrs(PostFaintAbAttr, pokemon, globalScene.getPokemonById(lastAttack.sourceId)!, new PokemonMove(lastAttack.move).getMove(), lastAttack.result); // TODO: is this bang correct? } else { //If killed by indirect damage, apply post-faint abilities without providing a last move applyPostFaintAbAttrs(PostFaintAbAttr, pokemon); } - const alivePlayField = this.scene.getField(true); + const alivePlayField = globalScene.getField(true); alivePlayField.forEach(p => applyPostKnockOutAbAttrs(PostKnockOutAbAttr, p, pokemon)); if (pokemon.turnData?.attacksReceived?.length) { - const defeatSource = this.scene.getPokemonById(pokemon.turnData.attacksReceived[0].sourceId); + const defeatSource = globalScene.getPokemonById(pokemon.turnData.attacksReceived[0].sourceId); if (defeatSource?.isOnField()) { applyPostVictoryAbAttrs(PostVictoryAbAttr, defeatSource); const pvmove = allMoves[pokemon.turnData.attacksReceived[0].move]; @@ -130,39 +130,39 @@ export class FaintPhase extends PokemonPhase { if (this.player) { /** The total number of Pokemon in the player's party that can legally fight */ - const legalPlayerPokemon = this.scene.getPokemonAllowedInBattle(); + const legalPlayerPokemon = globalScene.getPokemonAllowedInBattle(); /** The total number of legal player Pokemon that aren't currently on the field */ const legalPlayerPartyPokemon = legalPlayerPokemon.filter(p => !p.isActive(true)); if (!legalPlayerPokemon.length) { /** If the player doesn't have any legal Pokemon, end the game */ - this.scene.unshiftPhase(new GameOverPhase(this.scene)); - } else if (this.scene.currentBattle.double && legalPlayerPokemon.length === 1 && legalPlayerPartyPokemon.length === 0) { + globalScene.unshiftPhase(new GameOverPhase()); + } else if (globalScene.currentBattle.double && legalPlayerPokemon.length === 1 && legalPlayerPartyPokemon.length === 0) { /** * If the player has exactly one Pokemon in total at this point in a double battle, and that Pokemon * is already on the field, unshift a phase that moves that Pokemon to center position. */ - this.scene.unshiftPhase(new ToggleDoublePositionPhase(this.scene, true)); + globalScene.unshiftPhase(new ToggleDoublePositionPhase(true)); } else if (legalPlayerPartyPokemon.length > 0) { /** * If previous conditions weren't met, and the player has at least 1 legal Pokemon off the field, * push a phase that prompts the player to summon a Pokemon from their party. */ - this.scene.pushPhase(new SwitchPhase(this.scene, SwitchType.SWITCH, this.fieldIndex, true, false)); + globalScene.pushPhase(new SwitchPhase(SwitchType.SWITCH, this.fieldIndex, true, false)); } } else { - this.scene.unshiftPhase(new VictoryPhase(this.scene, this.battlerIndex)); - if ([ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(this.scene.currentBattle.battleType)) { - const hasReservePartyMember = !!this.scene.getEnemyParty().filter(p => p.isActive() && !p.isOnField() && p.trainerSlot === (pokemon as EnemyPokemon).trainerSlot).length; + globalScene.unshiftPhase(new VictoryPhase(this.battlerIndex)); + if ([ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(globalScene.currentBattle.battleType)) { + const hasReservePartyMember = !!globalScene.getEnemyParty().filter(p => p.isActive() && !p.isOnField() && p.trainerSlot === (pokemon as EnemyPokemon).trainerSlot).length; if (hasReservePartyMember) { - this.scene.pushPhase(new SwitchSummonPhase(this.scene, SwitchType.SWITCH, this.fieldIndex, -1, false, false)); + globalScene.pushPhase(new SwitchSummonPhase(SwitchType.SWITCH, this.fieldIndex, -1, false, false)); } } } // in double battles redirect potential moves off fainted pokemon - if (this.scene.currentBattle.double) { + if (globalScene.currentBattle.double) { const allyPokemon = pokemon.getAlly(); - this.scene.redirectPokemonMoves(pokemon, allyPokemon); + globalScene.redirectPokemonMoves(pokemon, allyPokemon); } pokemon.faintCry(() => { @@ -170,8 +170,8 @@ export class FaintPhase extends PokemonPhase { pokemon.addFriendship(-FRIENDSHIP_LOSS_FROM_FAINT); } pokemon.hideInfo(); - this.scene.playSound("se/faint"); - this.scene.tweens.add({ + globalScene.playSound("se/faint"); + globalScene.tweens.add({ targets: pokemon, duration: 500, y: pokemon.y + 150, @@ -179,17 +179,17 @@ export class FaintPhase extends PokemonPhase { onComplete: () => { pokemon.resetSprite(); pokemon.lapseTags(BattlerTagLapseType.FAINT); - this.scene.getField(true).filter(p => p !== pokemon).forEach(p => p.removeTagsBySourceId(pokemon.id)); + globalScene.getField(true).filter(p => p !== pokemon).forEach(p => p.removeTagsBySourceId(pokemon.id)); pokemon.y -= 150; pokemon.trySetStatus(StatusEffect.FAINT); if (pokemon.isPlayer()) { - this.scene.currentBattle.removeFaintedParticipant(pokemon as PlayerPokemon); + globalScene.currentBattle.removeFaintedParticipant(pokemon as PlayerPokemon); } else { - this.scene.addFaintedEnemyScore(pokemon as EnemyPokemon); - this.scene.currentBattle.addPostBattleLoot(pokemon as EnemyPokemon); + globalScene.addFaintedEnemyScore(pokemon as EnemyPokemon); + globalScene.currentBattle.addPostBattleLoot(pokemon as EnemyPokemon); } - this.scene.field.remove(pokemon); + globalScene.field.remove(pokemon); this.end(); } }); @@ -197,16 +197,16 @@ export class FaintPhase extends PokemonPhase { } tryOverrideForBattleSpec(): boolean { - switch (this.scene.currentBattle.battleSpec) { + switch (globalScene.currentBattle.battleSpec) { case BattleSpec.FINAL_BOSS: if (!this.player) { const enemy = this.getPokemon(); if (enemy.formIndex) { - this.scene.ui.showDialogue(battleSpecDialogue[BattleSpec.FINAL_BOSS].secondStageWin, enemy.species.name, null, () => this.doFaint()); + globalScene.ui.showDialogue(battleSpecDialogue[BattleSpec.FINAL_BOSS].secondStageWin, enemy.species.name, null, () => this.doFaint()); } else { // Final boss' HP threshold has been bypassed; cancel faint and force check for 2nd phase enemy.hp++; - this.scene.unshiftPhase(new DamageAnimPhase(this.scene, enemy.getBattlerIndex(), 0, HitResult.OTHER)); + globalScene.unshiftPhase(new DamageAnimPhase(enemy.getBattlerIndex(), 0, HitResult.OTHER)); this.end(); } return true; diff --git a/src/phases/field-phase.ts b/src/phases/field-phase.ts index 46c3c4983b4b..d50b3e49bf34 100644 --- a/src/phases/field-phase.ts +++ b/src/phases/field-phase.ts @@ -1,3 +1,4 @@ +import { globalScene } from "#app/global-scene"; import Pokemon from "#app/field/pokemon"; import { BattlePhase } from "./battle-phase"; @@ -5,7 +6,7 @@ type PokemonFunc = (pokemon: Pokemon) => void; export abstract class FieldPhase extends BattlePhase { executeForAll(func: PokemonFunc): void { - const field = this.scene.getField(true).filter(p => p.summonData); + const field = globalScene.getField(true).filter(p => p.summonData); field.forEach(pokemon => func(pokemon)); } } diff --git a/src/phases/form-change-phase.ts b/src/phases/form-change-phase.ts index b042cd98294c..67b550648bca 100644 --- a/src/phases/form-change-phase.ts +++ b/src/phases/form-change-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "../utils"; import { achvs } from "../system/achv"; import { SpeciesFormChange, getSpeciesFormChangeMessage } from "../data/pokemon-forms"; @@ -15,8 +15,8 @@ export class FormChangePhase extends EvolutionPhase { private formChange: SpeciesFormChange; private modal: boolean; - constructor(scene: BattleScene, pokemon: PlayerPokemon, formChange: SpeciesFormChange, modal: boolean) { - super(scene, pokemon, null, 0); + constructor(pokemon: PlayerPokemon, formChange: SpeciesFormChange, modal: boolean) { + super(pokemon, null, 0); this.formChange = formChange; this.modal = modal; @@ -30,7 +30,7 @@ export class FormChangePhase extends EvolutionPhase { if (!this.modal) { return super.setMode(); } - return this.scene.ui.setOverlayMode(Mode.EVOLUTION_SCENE); + return globalScene.ui.setOverlayMode(Mode.EVOLUTION_SCENE); } doEvolution(): void { @@ -58,16 +58,16 @@ export class FormChangePhase extends EvolutionPhase { }); }); - this.scene.time.delayedCall(250, () => { - this.scene.tweens.add({ + globalScene.time.delayedCall(250, () => { + globalScene.tweens.add({ targets: this.evolutionBgOverlay, alpha: 1, delay: 500, duration: 1500, ease: "Sine.easeOut", onComplete: () => { - this.scene.time.delayedCall(1000, () => { - this.scene.tweens.add({ + globalScene.time.delayedCall(1000, () => { + globalScene.tweens.add({ targets: this.evolutionBgOverlay, alpha: 0, duration: 250 @@ -75,9 +75,9 @@ export class FormChangePhase extends EvolutionPhase { this.evolutionBg.setVisible(true); this.evolutionBg.play(); }); - this.scene.playSound("se/charge"); + globalScene.playSound("se/charge"); this.doSpiralUpward(); - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ from: 0, to: 1, duration: 2000, @@ -86,25 +86,25 @@ export class FormChangePhase extends EvolutionPhase { }, onComplete: () => { this.pokemonSprite.setVisible(false); - this.scene.time.delayedCall(1100, () => { - this.scene.playSound("se/beam"); + globalScene.time.delayedCall(1100, () => { + globalScene.playSound("se/beam"); this.doArcDownward(); - this.scene.time.delayedCall(1000, () => { + globalScene.time.delayedCall(1000, () => { this.pokemonEvoTintSprite.setScale(0.25); this.pokemonEvoTintSprite.setVisible(true); this.doCycle(1, 1).then(_success => { - this.scene.playSound("se/sparkle"); + globalScene.playSound("se/sparkle"); this.pokemonEvoSprite.setVisible(true); this.doCircleInward(); - this.scene.time.delayedCall(900, () => { + globalScene.time.delayedCall(900, () => { this.pokemon.changeForm(this.formChange).then(() => { if (!this.modal) { - this.scene.unshiftPhase(new EndEvolutionPhase(this.scene)); + globalScene.unshiftPhase(new EndEvolutionPhase()); } - this.scene.playSound("se/shine"); + globalScene.playSound("se/shine"); this.doSpray(); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.evolutionOverlay, alpha: 1, duration: 250, @@ -112,36 +112,36 @@ export class FormChangePhase extends EvolutionPhase { onComplete: () => { this.evolutionBgOverlay.setAlpha(1); this.evolutionBg.setVisible(false); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.evolutionOverlay, this.pokemonEvoTintSprite ], alpha: 0, duration: 2000, delay: 150, easing: "Sine.easeIn", onComplete: () => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.evolutionBgOverlay, alpha: 0, duration: 250, onComplete: () => { - this.scene.time.delayedCall(250, () => { + globalScene.time.delayedCall(250, () => { this.pokemon.cry(); - this.scene.time.delayedCall(1250, () => { + globalScene.time.delayedCall(1250, () => { let playEvolutionFanfare = false; if (this.formChange.formKey.indexOf(SpeciesFormKey.MEGA) > -1) { - this.scene.validateAchv(achvs.MEGA_EVOLVE); + globalScene.validateAchv(achvs.MEGA_EVOLVE); playEvolutionFanfare = true; } else if (this.formChange.formKey.indexOf(SpeciesFormKey.GIGANTAMAX) > -1 || this.formChange.formKey.indexOf(SpeciesFormKey.ETERNAMAX) > -1) { - this.scene.validateAchv(achvs.GIGANTAMAX); + globalScene.validateAchv(achvs.GIGANTAMAX); playEvolutionFanfare = true; } const delay = playEvolutionFanfare ? 4000 : 1750; - this.scene.playSoundWithoutBgm(playEvolutionFanfare ? "evolution_fanfare" : "minor_fanfare"); + globalScene.playSoundWithoutBgm(playEvolutionFanfare ? "evolution_fanfare" : "minor_fanfare"); transformedPokemon.destroy(); - this.scene.ui.showText(getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName), null, () => this.end(), null, true, Utils.fixedInt(delay)); - this.scene.time.delayedCall(Utils.fixedInt(delay + 250), () => this.scene.playBgm()); + globalScene.ui.showText(getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName), null, () => this.end(), null, true, Utils.fixedInt(delay)); + globalScene.time.delayedCall(Utils.fixedInt(delay + 250), () => globalScene.playBgm()); }); }); } @@ -166,9 +166,9 @@ export class FormChangePhase extends EvolutionPhase { end(): void { this.pokemon.findAndRemoveTags(t => t.tagType === BattlerTagType.AUTOTOMIZED); if (this.modal) { - this.scene.ui.revertMode().then(() => { - if (this.scene.ui.getMode() === Mode.PARTY) { - const partyUiHandler = this.scene.ui.getHandler() as PartyUiHandler; + globalScene.ui.revertMode().then(() => { + if (globalScene.ui.getMode() === Mode.PARTY) { + const partyUiHandler = globalScene.ui.getHandler() as PartyUiHandler; partyUiHandler.clearPartySlots(); partyUiHandler.populatePartySlots(); } diff --git a/src/phases/game-over-modifier-reward-phase.ts b/src/phases/game-over-modifier-reward-phase.ts index a698e62e2e11..6a713d878710 100644 --- a/src/phases/game-over-modifier-reward-phase.ts +++ b/src/phases/game-over-modifier-reward-phase.ts @@ -1,24 +1,24 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ModifierTypeFunc } from "#app/modifier/modifier-type"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; import { ModifierRewardPhase } from "./modifier-reward-phase"; export class GameOverModifierRewardPhase extends ModifierRewardPhase { - constructor(scene: BattleScene, modifierTypeFunc: ModifierTypeFunc) { - super(scene, modifierTypeFunc); + constructor(modifierTypeFunc: ModifierTypeFunc) { + super(modifierTypeFunc); } doReward(): Promise { return new Promise(resolve => { const newModifier = this.modifierType.newModifier(); - this.scene.addModifier(newModifier).then(() => { + globalScene.addModifier(newModifier).then(() => { // Sound loaded into game as is - this.scene.playSound("level_up_fanfare"); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.fadeIn(250).then(() => { - this.scene.ui.showText(i18next.t("battle:rewardGain", { modifierName: newModifier?.type.name }), null, () => { - this.scene.time.delayedCall(1500, () => this.scene.arenaBg.setVisible(true)); + globalScene.playSound("level_up_fanfare"); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.fadeIn(250).then(() => { + globalScene.ui.showText(i18next.t("battle:rewardGain", { modifierName: newModifier?.type.name }), null, () => { + globalScene.time.delayedCall(1500, () => globalScene.arenaBg.setVisible(true)); resolve(); }, null, true, 1500); }); diff --git a/src/phases/game-over-phase.ts b/src/phases/game-over-phase.ts index 52d0996b9462..e43524ae18ce 100644 --- a/src/phases/game-over-phase.ts +++ b/src/phases/game-over-phase.ts @@ -1,6 +1,6 @@ import { clientSessionId } from "#app/account"; import { BattleType } from "#app/battle"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import { getCharVariantFromDialogue } from "#app/data/dialogue"; import PokemonSpecies, { getPokemonSpecies } from "#app/data/pokemon-species"; @@ -35,8 +35,8 @@ export class GameOverPhase extends BattlePhase { private isVictory: boolean; private firstRibbons: PokemonSpecies[] = []; - constructor(scene: BattleScene, isVictory: boolean = false) { - super(scene); + constructor(isVictory: boolean = false) { + super(); this.isVictory = isVictory; } @@ -45,47 +45,47 @@ export class GameOverPhase extends BattlePhase { super.start(); // Failsafe if players somehow skip floor 200 in classic mode - if (this.scene.gameMode.isClassic && this.scene.currentBattle.waveIndex > 200) { + if (globalScene.gameMode.isClassic && globalScene.currentBattle.waveIndex > 200) { this.isVictory = true; } // Handle Mystery Encounter special Game Over cases // Situations such as when player lost a battle, but it isn't treated as full Game Over - if (!this.isVictory && this.scene.currentBattle.mysteryEncounter?.onGameOver && !this.scene.currentBattle.mysteryEncounter.onGameOver(this.scene)) { + if (!this.isVictory && globalScene.currentBattle.mysteryEncounter?.onGameOver && !globalScene.currentBattle.mysteryEncounter.onGameOver()) { // Do not end the game return this.end(); } // Otherwise, continue standard Game Over logic - if (this.isVictory && this.scene.gameMode.isEndless) { - const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET; + if (this.isVictory && globalScene.gameMode.isEndless) { + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const genderStr = PlayerGender[genderIndex].toLowerCase(); - this.scene.ui.showDialogue(i18next.t("miscDialogue:ending_endless", { context: genderStr }), i18next.t("miscDialogue:ending_name"), 0, () => this.handleGameOver()); - } else if (this.isVictory || !this.scene.enableRetries) { + globalScene.ui.showDialogue(i18next.t("miscDialogue:ending_endless", { context: genderStr }), i18next.t("miscDialogue:ending_name"), 0, () => this.handleGameOver()); + } else if (this.isVictory || !globalScene.enableRetries) { this.handleGameOver(); } else { - this.scene.ui.showText(i18next.t("battle:retryBattle"), null, () => { - this.scene.ui.setMode(Mode.CONFIRM, () => { - this.scene.ui.fadeOut(1250).then(() => { - this.scene.reset(); - this.scene.clearPhaseQueue(); - this.scene.gameData.loadSession(this.scene, this.scene.sessionSlotId).then(() => { - this.scene.pushPhase(new EncounterPhase(this.scene, true)); - - const availablePartyMembers = this.scene.getPokemonAllowedInBattle().length; - - this.scene.pushPhase(new SummonPhase(this.scene, 0)); - if (this.scene.currentBattle.double && availablePartyMembers > 1) { - this.scene.pushPhase(new SummonPhase(this.scene, 1)); + globalScene.ui.showText(i18next.t("battle:retryBattle"), null, () => { + globalScene.ui.setMode(Mode.CONFIRM, () => { + globalScene.ui.fadeOut(1250).then(() => { + globalScene.reset(); + globalScene.clearPhaseQueue(); + globalScene.gameData.loadSession(globalScene.sessionSlotId).then(() => { + globalScene.pushPhase(new EncounterPhase(true)); + + const availablePartyMembers = globalScene.getPokemonAllowedInBattle().length; + + globalScene.pushPhase(new SummonPhase(0)); + if (globalScene.currentBattle.double && availablePartyMembers > 1) { + globalScene.pushPhase(new SummonPhase(1)); } - if (this.scene.currentBattle.waveIndex > 1 && this.scene.currentBattle.battleType !== BattleType.TRAINER) { - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 0, this.scene.currentBattle.double)); - if (this.scene.currentBattle.double && availablePartyMembers > 1) { - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); + if (globalScene.currentBattle.waveIndex > 1 && globalScene.currentBattle.battleType !== BattleType.TRAINER) { + globalScene.pushPhase(new CheckSwitchPhase(0, globalScene.currentBattle.double)); + if (globalScene.currentBattle.double && availablePartyMembers > 1) { + globalScene.pushPhase(new CheckSwitchPhase(1, globalScene.currentBattle.double)); } } - this.scene.ui.fadeIn(1250); + globalScene.ui.fadeIn(1250); this.end(); }); }); @@ -96,38 +96,38 @@ export class GameOverPhase extends BattlePhase { handleGameOver(): void { const doGameOver = (newClear: boolean) => { - this.scene.disableMenu = true; - this.scene.time.delayedCall(1000, () => { + globalScene.disableMenu = true; + globalScene.time.delayedCall(1000, () => { let firstClear = false; if (this.isVictory && newClear) { - if (this.scene.gameMode.isClassic) { - firstClear = this.scene.validateAchv(achvs.CLASSIC_VICTORY); - this.scene.validateAchv(achvs.UNEVOLVED_CLASSIC_VICTORY); - this.scene.gameData.gameStats.sessionsWon++; - for (const pokemon of this.scene.getPlayerParty()) { + if (globalScene.gameMode.isClassic) { + firstClear = globalScene.validateAchv(achvs.CLASSIC_VICTORY); + globalScene.validateAchv(achvs.UNEVOLVED_CLASSIC_VICTORY); + globalScene.gameData.gameStats.sessionsWon++; + for (const pokemon of globalScene.getPlayerParty()) { this.awardRibbon(pokemon); if (pokemon.species.getRootSpeciesId() !== pokemon.species.getRootSpeciesId(true)) { this.awardRibbon(pokemon, true); } } - } else if (this.scene.gameMode.isDaily && newClear) { - this.scene.gameData.gameStats.dailyRunSessionsWon++; + } else if (globalScene.gameMode.isDaily && newClear) { + globalScene.gameData.gameStats.dailyRunSessionsWon++; } } const fadeDuration = this.isVictory ? 10000 : 5000; - this.scene.fadeOutBgm(fadeDuration, true); - const activeBattlers = this.scene.getField().filter(p => p?.isActive(true)); + globalScene.fadeOutBgm(fadeDuration, true); + const activeBattlers = globalScene.getField().filter(p => p?.isActive(true)); activeBattlers.map(p => p.hideInfo()); - this.scene.ui.fadeOut(fadeDuration).then(() => { + globalScene.ui.fadeOut(fadeDuration).then(() => { activeBattlers.map(a => a.setVisible(false)); - this.scene.setFieldScale(1, true); - this.scene.clearPhaseQueue(); - this.scene.ui.clearText(); + globalScene.setFieldScale(1, true); + globalScene.clearPhaseQueue(); + globalScene.ui.clearText(); - if (this.isVictory && this.scene.gameMode.isChallenge) { - this.scene.gameMode.challenges.forEach(c => this.scene.validateAchvs(ChallengeAchv, c)); + if (this.isVictory && globalScene.gameMode.isChallenge) { + globalScene.gameMode.challenges.forEach(c => globalScene.validateAchvs(ChallengeAchv, c)); } const clear = (endCardPhase?: EndCardPhase) => { @@ -135,34 +135,34 @@ export class GameOverPhase extends BattlePhase { this.handleUnlocks(); for (const species of this.firstRibbons) { - this.scene.unshiftPhase(new RibbonModifierRewardPhase(this.scene, modifierTypes.VOUCHER_PLUS, species)); + globalScene.unshiftPhase(new RibbonModifierRewardPhase(modifierTypes.VOUCHER_PLUS, species)); } if (!firstClear) { - this.scene.unshiftPhase(new GameOverModifierRewardPhase(this.scene, modifierTypes.VOUCHER_PREMIUM)); + globalScene.unshiftPhase(new GameOverModifierRewardPhase(modifierTypes.VOUCHER_PREMIUM)); } } this.getRunHistoryEntry().then(runHistoryEntry => { - this.scene.gameData.saveRunHistory(this.scene, runHistoryEntry, this.isVictory); - this.scene.pushPhase(new PostGameOverPhase(this.scene, endCardPhase)); + globalScene.gameData.saveRunHistory(runHistoryEntry, this.isVictory); + globalScene.pushPhase(new PostGameOverPhase(endCardPhase)); this.end(); }); }; - if (this.isVictory && this.scene.gameMode.isClassic) { + if (this.isVictory && globalScene.gameMode.isClassic) { const dialogueKey = "miscDialogue:ending"; - if (!this.scene.ui.shouldSkipDialogue(dialogueKey)) { - this.scene.ui.fadeIn(500).then(() => { - const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET; + if (!globalScene.ui.shouldSkipDialogue(dialogueKey)) { + globalScene.ui.fadeIn(500).then(() => { + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const genderStr = PlayerGender[genderIndex].toLowerCase(); // Dialogue has to be retrieved so that the rival's expressions can be loaded and shown via getCharVariantFromDialogue const dialogue = i18next.t(dialogueKey, { context: genderStr }); - this.scene.charSprite.showCharacter(`rival_${this.scene.gameData.gender === PlayerGender.FEMALE ? "m" : "f"}`, getCharVariantFromDialogue(dialogue)).then(() => { - this.scene.ui.showDialogue(dialogueKey, this.scene.gameData.gender === PlayerGender.FEMALE ? trainerConfigs[TrainerType.RIVAL].name : trainerConfigs[TrainerType.RIVAL].nameFemale, null, () => { - this.scene.ui.fadeOut(500).then(() => { - this.scene.charSprite.hide().then(() => { - const endCardPhase = new EndCardPhase(this.scene); - this.scene.unshiftPhase(endCardPhase); + globalScene.charSprite.showCharacter(`rival_${globalScene.gameData.gender === PlayerGender.FEMALE ? "m" : "f"}`, getCharVariantFromDialogue(dialogue)).then(() => { + globalScene.ui.showDialogue(dialogueKey, globalScene.gameData.gender === PlayerGender.FEMALE ? trainerConfigs[TrainerType.RIVAL].name : trainerConfigs[TrainerType.RIVAL].nameFemale, null, () => { + globalScene.ui.fadeOut(500).then(() => { + globalScene.charSprite.hide().then(() => { + const endCardPhase = new EndCardPhase(); + globalScene.unshiftPhase(endCardPhase); clear(endCardPhase); }); }); @@ -170,8 +170,8 @@ export class GameOverPhase extends BattlePhase { }); }); } else { - const endCardPhase = new EndCardPhase(this.scene); - this.scene.unshiftPhase(endCardPhase); + const endCardPhase = new EndCardPhase(); + globalScene.unshiftPhase(endCardPhase); clear(endCardPhase); } } else { @@ -185,10 +185,10 @@ export class GameOverPhase extends BattlePhase { If Online, execute apiFetch as intended If Offline, execute offlineNewClear() only for victory, a localStorage implementation of newClear daily run checks */ if (!Utils.isLocal || Utils.isLocalServerConnected) { - pokerogueApi.savedata.session.newclear({ slot: this.scene.sessionSlotId, isVictory: this.isVictory, clientSessionId: clientSessionId }) + pokerogueApi.savedata.session.newclear({ slot: globalScene.sessionSlotId, isVictory: this.isVictory, clientSessionId: clientSessionId }) .then((success) => doGameOver(!!success)); } else if (this.isVictory) { - this.scene.gameData.offlineNewClear(this.scene).then(result => { + globalScene.gameData.offlineNewClear().then(result => { doGameOver(result); }); } else { @@ -197,57 +197,58 @@ export class GameOverPhase extends BattlePhase { } handleUnlocks(): void { - if (this.isVictory && this.scene.gameMode.isClassic) { - if (!this.scene.gameData.unlocks[Unlockables.ENDLESS_MODE]) { - this.scene.unshiftPhase(new UnlockPhase(this.scene, Unlockables.ENDLESS_MODE)); + if (this.isVictory && globalScene.gameMode.isClassic) { + if (!globalScene.gameData.unlocks[Unlockables.ENDLESS_MODE]) { + globalScene.unshiftPhase(new UnlockPhase(Unlockables.ENDLESS_MODE)); } - if (this.scene.getPlayerParty().filter(p => p.fusionSpecies).length && !this.scene.gameData.unlocks[Unlockables.SPLICED_ENDLESS_MODE]) { - this.scene.unshiftPhase(new UnlockPhase(this.scene, Unlockables.SPLICED_ENDLESS_MODE)); + if (globalScene.getPlayerParty().filter(p => p.fusionSpecies).length && !globalScene.gameData.unlocks[Unlockables.SPLICED_ENDLESS_MODE]) { + globalScene.unshiftPhase(new UnlockPhase(Unlockables.SPLICED_ENDLESS_MODE)); } - if (!this.scene.gameData.unlocks[Unlockables.MINI_BLACK_HOLE]) { - this.scene.unshiftPhase(new UnlockPhase(this.scene, Unlockables.MINI_BLACK_HOLE)); + if (!globalScene.gameData.unlocks[Unlockables.MINI_BLACK_HOLE]) { + globalScene.unshiftPhase(new UnlockPhase(Unlockables.MINI_BLACK_HOLE)); } - if (!this.scene.gameData.unlocks[Unlockables.EVIOLITE] && this.scene.getPlayerParty().some(p => p.getSpeciesForm(true).speciesId in pokemonEvolutions)) { - this.scene.unshiftPhase(new UnlockPhase(this.scene, Unlockables.EVIOLITE)); + if (!globalScene.gameData.unlocks[Unlockables.EVIOLITE] && globalScene.getPlayerParty().some(p => p.getSpeciesForm(true).speciesId in pokemonEvolutions)) { + globalScene.unshiftPhase(new UnlockPhase(Unlockables.EVIOLITE)); } } } awardRibbon(pokemon: Pokemon, forStarter: boolean = false): void { const speciesId = getPokemonSpecies(pokemon.species.speciesId); - const speciesRibbonCount = this.scene.gameData.incrementRibbonCount(speciesId, forStarter); + const speciesRibbonCount = globalScene.gameData.incrementRibbonCount(speciesId, forStarter); // first time classic win, award voucher if (speciesRibbonCount === 1) { this.firstRibbons.push(getPokemonSpecies(pokemon.species.getRootSpeciesId(forStarter))); } } + // TODO: Make function use existing getSessionSaveData() function and then modify the values from there. /** * Slightly modified version of {@linkcode GameData.getSessionSaveData}. * @returns A promise containing the {@linkcode SessionSaveData} */ private async getRunHistoryEntry(): Promise { - const preWaveSessionData = await this.scene.gameData.getSession(this.scene.sessionSlotId); + const preWaveSessionData = await globalScene.gameData.getSession(globalScene.sessionSlotId); return { - seed: this.scene.seed, - playTime: this.scene.sessionPlayTime, - gameMode: this.scene.gameMode.modeId, - party: this.scene.getPlayerParty().map(p => new PokemonData(p)), - enemyParty: this.scene.getEnemyParty().map(p => new PokemonData(p)), - modifiers: preWaveSessionData ? preWaveSessionData.modifiers : this.scene.findModifiers(() => true).map(m => new PersistentModifierData(m, true)), - enemyModifiers: preWaveSessionData ? preWaveSessionData.enemyModifiers : this.scene.findModifiers(() => true, false).map(m => new PersistentModifierData(m, false)), - arena: new ArenaData(this.scene.arena), - pokeballCounts: this.scene.pokeballCounts, - money: Math.floor(this.scene.money), - score: this.scene.score, - waveIndex: this.scene.currentBattle.waveIndex, - battleType: this.scene.currentBattle.battleType, - trainer: this.scene.currentBattle.trainer ? new TrainerData(this.scene.currentBattle.trainer) : null, - gameVersion: this.scene.game.config.gameVersion, + seed: globalScene.seed, + playTime: globalScene.sessionPlayTime, + gameMode: globalScene.gameMode.modeId, + party: globalScene.getPlayerParty().map(p => new PokemonData(p)), + enemyParty: globalScene.getEnemyParty().map(p => new PokemonData(p)), + modifiers: preWaveSessionData ? preWaveSessionData.modifiers : globalScene.findModifiers(() => true).map(m => new PersistentModifierData(m, true)), + enemyModifiers: preWaveSessionData ? preWaveSessionData.enemyModifiers : globalScene.findModifiers(() => true, false).map(m => new PersistentModifierData(m, false)), + arena: new ArenaData(globalScene.arena), + pokeballCounts: globalScene.pokeballCounts, + money: Math.floor(globalScene.money), + score: globalScene.score, + waveIndex: globalScene.currentBattle.waveIndex, + battleType: globalScene.currentBattle.battleType, + trainer: globalScene.currentBattle.trainer ? new TrainerData(globalScene.currentBattle.trainer) : null, + gameVersion: globalScene.game.config.gameVersion, timestamp: new Date().getTime(), - challenges: this.scene.gameMode.challenges.map(c => new ChallengeData(c)), - mysteryEncounterType: this.scene.currentBattle.mysteryEncounter?.encounterType ?? -1, - mysteryEncounterSaveData: this.scene.mysteryEncounterSaveData + challenges: globalScene.gameMode.challenges.map(c => new ChallengeData(c)), + mysteryEncounterType: globalScene.currentBattle.mysteryEncounter?.encounterType ?? -1, + mysteryEncounterSaveData: globalScene.mysteryEncounterSaveData } as SessionSaveData; } } diff --git a/src/phases/hide-party-exp-bar-phase.ts b/src/phases/hide-party-exp-bar-phase.ts index 303650ea1adb..0dce41044c0d 100644 --- a/src/phases/hide-party-exp-bar-phase.ts +++ b/src/phases/hide-party-exp-bar-phase.ts @@ -1,14 +1,14 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlePhase } from "./battle-phase"; export class HidePartyExpBarPhase extends BattlePhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - this.scene.partyExpBar.hide().then(() => this.end()); + globalScene.partyExpBar.hide().then(() => this.end()); } } diff --git a/src/phases/learn-move-phase.ts b/src/phases/learn-move-phase.ts index fefda3840924..8498e938bb54 100644 --- a/src/phases/learn-move-phase.ts +++ b/src/phases/learn-move-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { initMoveAnim, loadMoveAnimAssets } from "#app/data/battle-anims"; import Move, { allMoves } from "#app/data/move"; import { SpeciesFormChangeMoveLearnedTrigger } from "#app/data/pokemon-forms"; @@ -28,8 +28,8 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { private learnMoveType; private cost: number; - constructor(scene: BattleScene, partyMemberIndex: integer, moveId: Moves, learnMoveType: LearnMoveType = LearnMoveType.LEARN_MOVE, cost: number = -1) { - super(scene, partyMemberIndex); + constructor(partyMemberIndex: integer, moveId: Moves, learnMoveType: LearnMoveType = LearnMoveType.LEARN_MOVE, cost: number = -1) { + super(partyMemberIndex); this.moveId = moveId; this.learnMoveType = learnMoveType; this.cost = cost; @@ -48,8 +48,8 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { return this.end(); } - this.messageMode = this.scene.ui.getHandler() instanceof EvolutionSceneHandler ? Mode.EVOLUTION_SCENE : Mode.MESSAGE; - this.scene.ui.setMode(this.messageMode); + this.messageMode = globalScene.ui.getHandler() instanceof EvolutionSceneHandler ? Mode.EVOLUTION_SCENE : Mode.MESSAGE; + globalScene.ui.setMode(this.messageMode); // If the Pokemon has less than 4 moves, the new move is added to the largest empty moveset index // If it has 4 moves, the phase then checks if the player wants to replace the move itself. if (currentMoveset.length < 4) { @@ -73,12 +73,12 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { const moveLimitReached = i18next.t("battle:learnMoveLimitReached", { pokemonName: getPokemonNameWithAffix(pokemon) }); const shouldReplaceQ = i18next.t("battle:learnMoveReplaceQuestion", { moveName: move.name }); const preQText = [ learnMovePrompt, moveLimitReached ].join("$"); - await this.scene.ui.showTextPromise(preQText); - await this.scene.ui.showTextPromise(shouldReplaceQ, undefined, false); - await this.scene.ui.setModeWithoutClear(Mode.CONFIRM, + await globalScene.ui.showTextPromise(preQText); + await globalScene.ui.showTextPromise(shouldReplaceQ, undefined, false); + await globalScene.ui.setModeWithoutClear(Mode.CONFIRM, () => this.forgetMoveProcess(move, pokemon), // Yes () => { // No - this.scene.ui.setMode(this.messageMode); + globalScene.ui.setMode(this.messageMode); this.rejectMoveAndEnd(move, pokemon); } ); @@ -96,16 +96,16 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { * @param Pokemon The Pokemon learning the move */ async forgetMoveProcess(move: Move, pokemon: Pokemon) { - this.scene.ui.setMode(this.messageMode); - await this.scene.ui.showTextPromise(i18next.t("battle:learnMoveForgetQuestion"), undefined, true); - await this.scene.ui.setModeWithoutClear(Mode.SUMMARY, pokemon, SummaryUiMode.LEARN_MOVE, move, (moveIndex: integer) => { + globalScene.ui.setMode(this.messageMode); + await globalScene.ui.showTextPromise(i18next.t("battle:learnMoveForgetQuestion"), undefined, true); + await globalScene.ui.setModeWithoutClear(Mode.SUMMARY, pokemon, SummaryUiMode.LEARN_MOVE, move, (moveIndex: integer) => { if (moveIndex === 4) { - this.scene.ui.setMode(this.messageMode).then(() => this.rejectMoveAndEnd(move, pokemon)); + globalScene.ui.setMode(this.messageMode).then(() => this.rejectMoveAndEnd(move, pokemon)); return; } const forgetSuccessText = i18next.t("battle:learnMoveForgetSuccess", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: pokemon.moveset[moveIndex]!.getName() }); const fullText = [ i18next.t("battle:countdownPoof"), forgetSuccessText, i18next.t("battle:learnMoveAnd") ].join("$"); - this.scene.ui.setMode(this.messageMode).then(() => this.learnMove(moveIndex, move, pokemon, fullText)); + globalScene.ui.setMode(this.messageMode).then(() => this.learnMove(moveIndex, move, pokemon, fullText)); }); } @@ -120,14 +120,14 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { * @param Pokemon The Pokemon learning the move */ async rejectMoveAndEnd(move: Move, pokemon: Pokemon) { - await this.scene.ui.showTextPromise(i18next.t("battle:learnMoveStopTeaching", { moveName: move.name }), undefined, false); - this.scene.ui.setModeWithoutClear(Mode.CONFIRM, + await globalScene.ui.showTextPromise(i18next.t("battle:learnMoveStopTeaching", { moveName: move.name }), undefined, false); + globalScene.ui.setModeWithoutClear(Mode.CONFIRM, () => { - this.scene.ui.setMode(this.messageMode); - this.scene.ui.showTextPromise(i18next.t("battle:learnMoveNotLearned", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: move.name }), undefined, true).then(() => this.end()); + globalScene.ui.setMode(this.messageMode); + globalScene.ui.showTextPromise(i18next.t("battle:learnMoveNotLearned", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: move.name }), undefined, true).then(() => this.end()); }, () => { - this.scene.ui.setMode(this.messageMode); + globalScene.ui.setMode(this.messageMode); this.replaceMoveCheck(move, pokemon); } ); @@ -154,31 +154,31 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { pokemon.usedTMs = []; } pokemon.usedTMs.push(this.moveId); - this.scene.tryRemovePhase((phase) => phase instanceof SelectModifierPhase); + globalScene.tryRemovePhase((phase) => phase instanceof SelectModifierPhase); } else if (this.learnMoveType === LearnMoveType.MEMORY) { if (this.cost !== -1) { if (!Overrides.WAIVE_ROLL_FEE_OVERRIDE) { - this.scene.money -= this.cost; - this.scene.updateMoneyText(); - this.scene.animateMoneyChanged(false); + globalScene.money -= this.cost; + globalScene.updateMoneyText(); + globalScene.animateMoneyChanged(false); } - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); } else { - this.scene.tryRemovePhase((phase) => phase instanceof SelectModifierPhase); + globalScene.tryRemovePhase((phase) => phase instanceof SelectModifierPhase); } } pokemon.setMove(index, this.moveId); - initMoveAnim(this.scene, this.moveId).then(() => { - loadMoveAnimAssets(this.scene, [ this.moveId ], true); + initMoveAnim(this.moveId).then(() => { + loadMoveAnimAssets([ this.moveId ], true); }); - this.scene.ui.setMode(this.messageMode); + globalScene.ui.setMode(this.messageMode); const learnMoveText = i18next.t("battle:learnMove", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: move.name }); if (textMessage) { - await this.scene.ui.showTextPromise(textMessage); + await globalScene.ui.showTextPromise(textMessage); } - this.scene.playSound("level_up_fanfare"); // Sound loaded into game as is - this.scene.ui.showText(learnMoveText, null, () => { - this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeMoveLearnedTrigger, true); + globalScene.playSound("level_up_fanfare"); // Sound loaded into game as is + globalScene.ui.showText(learnMoveText, null, () => { + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeMoveLearnedTrigger, true); this.end(); }, this.messageMode === Mode.EVOLUTION_SCENE ? 1000 : undefined, true); } diff --git a/src/phases/level-cap-phase.ts b/src/phases/level-cap-phase.ts index d1404e450104..d75bc3be6d49 100644 --- a/src/phases/level-cap-phase.ts +++ b/src/phases/level-cap-phase.ts @@ -1,20 +1,20 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; import { FieldPhase } from "./field-phase"; export class LevelCapPhase extends FieldPhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start(): void { super.start(); - this.scene.ui.setMode(Mode.MESSAGE).then(() => { + globalScene.ui.setMode(Mode.MESSAGE).then(() => { // Sound loaded into game as is - this.scene.playSound("level_up_fanfare"); - this.scene.ui.showText(i18next.t("battle:levelCapUp", { levelCap: this.scene.getMaxExpLevel() }), null, () => this.end(), null, true); + globalScene.playSound("level_up_fanfare"); + globalScene.ui.showText(i18next.t("battle:levelCapUp", { levelCap: globalScene.getMaxExpLevel() }), null, () => this.end(), null, true); this.executeForAll(pokemon => pokemon.updateInfo(true)); }); } diff --git a/src/phases/level-up-phase.ts b/src/phases/level-up-phase.ts index 4f26abc5af30..450ecca0c705 100644 --- a/src/phases/level-up-phase.ts +++ b/src/phases/level-up-phase.ts @@ -1,4 +1,4 @@ -import type BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ExpNotification } from "#app/enums/exp-notification"; import type { PlayerPokemon } from "#app/field/pokemon"; import { getPokemonNameWithAffix } from "#app/messages"; @@ -14,8 +14,8 @@ export class LevelUpPhase extends PlayerPartyMemberPokemonPhase { protected level: number; protected pokemon: PlayerPokemon = this.getPlayerPokemon(); - constructor(scene: BattleScene, partyMemberIndex: number, lastLevel: number, level: number) { - super(scene, partyMemberIndex); + constructor(partyMemberIndex: number, lastLevel: number, level: number) { + super(partyMemberIndex); this.lastLevel = lastLevel; this.level = level; @@ -24,27 +24,27 @@ export class LevelUpPhase extends PlayerPartyMemberPokemonPhase { public override start() { super.start(); - if (this.level > this.scene.gameData.gameStats.highestLevel) { - this.scene.gameData.gameStats.highestLevel = this.level; + if (this.level > globalScene.gameData.gameStats.highestLevel) { + globalScene.gameData.gameStats.highestLevel = this.level; } - this.scene.validateAchvs(LevelAchv, new NumberHolder(this.level)); + globalScene.validateAchvs(LevelAchv, new NumberHolder(this.level)); const prevStats = this.pokemon.stats.slice(0); this.pokemon.calculateStats(); this.pokemon.updateInfo(); - if (this.scene.expParty === ExpNotification.DEFAULT) { - this.scene.playSound("level_up_fanfare"); - this.scene.ui.showText( + if (globalScene.expParty === ExpNotification.DEFAULT) { + globalScene.playSound("level_up_fanfare"); + globalScene.ui.showText( i18next.t("battle:levelUp", { pokemonName: getPokemonNameWithAffix(this.pokemon), level: this.level }), null, - () => this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false) + () => globalScene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false) .then(() => this.end()), null, true); - } else if (this.scene.expParty === ExpNotification.SKIP) { + } else if (globalScene.expParty === ExpNotification.SKIP) { this.end(); } else { // we still want to display the stats if activated - this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false).then(() => this.end()); + globalScene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false).then(() => this.end()); } } @@ -52,13 +52,13 @@ export class LevelUpPhase extends PlayerPartyMemberPokemonPhase { if (this.lastLevel < 100) { // this feels like an unnecessary optimization const levelMoves = this.getPokemon().getLevelMoves(this.lastLevel + 1); for (const lm of levelMoves) { - this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, lm[1])); + globalScene.unshiftPhase(new LearnMovePhase(this.partyMemberIndex, lm[1])); } } if (!this.pokemon.pauseEvolutions) { const evolution = this.pokemon.getEvolution(); if (evolution) { - this.scene.unshiftPhase(new EvolutionPhase(this.scene, this.pokemon, evolution, this.lastLevel)); + globalScene.unshiftPhase(new EvolutionPhase(this.pokemon, evolution, this.lastLevel)); } } return super.end(); diff --git a/src/phases/login-phase.ts b/src/phases/login-phase.ts index ac1e68d1b0ee..0ed8b6feb880 100644 --- a/src/phases/login-phase.ts +++ b/src/phases/login-phase.ts @@ -1,5 +1,6 @@ import { updateUserInfo } from "#app/account"; -import BattleScene, { bypassLogin } from "#app/battle-scene"; +import { bypassLogin } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { handleTutorial, Tutorial } from "#app/tutorial"; import { Mode } from "#app/ui/ui"; @@ -11,8 +12,8 @@ import { UnavailablePhase } from "./unavailable-phase"; export class LoginPhase extends Phase { private showText: boolean; - constructor(scene: BattleScene, showText?: boolean) { - super(scene); + constructor(showText?: boolean) { + super(); this.showText = showText === undefined || !!showText; } @@ -22,50 +23,50 @@ export class LoginPhase extends Phase { const hasSession = !!Utils.getCookie(Utils.sessionIdKey); - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); Utils.executeIf(bypassLogin || hasSession, updateUserInfo).then(response => { const success = response ? response[0] : false; const statusCode = response ? response[1] : null; if (!success) { if (!statusCode || statusCode === 400) { if (this.showText) { - this.scene.ui.showText(i18next.t("menu:logInOrCreateAccount")); + globalScene.ui.showText(i18next.t("menu:logInOrCreateAccount")); } - this.scene.playSound("menu_open"); + globalScene.playSound("menu_open"); const loadData = () => { updateUserInfo().then(success => { if (!success[0]) { Utils.removeCookie(Utils.sessionIdKey); - this.scene.reset(true, true); + globalScene.reset(true, true); return; } - this.scene.gameData.loadSystem().then(() => this.end()); + globalScene.gameData.loadSystem().then(() => this.end()); }); }; - this.scene.ui.setMode(Mode.LOGIN_FORM, { + globalScene.ui.setMode(Mode.LOGIN_FORM, { buttonActions: [ () => { - this.scene.ui.playSelect(); + globalScene.ui.playSelect(); loadData(); }, () => { - this.scene.playSound("menu_open"); - this.scene.ui.setMode(Mode.REGISTRATION_FORM, { + globalScene.playSound("menu_open"); + globalScene.ui.setMode(Mode.REGISTRATION_FORM, { buttonActions: [ () => { - this.scene.ui.playSelect(); + globalScene.ui.playSelect(); updateUserInfo().then(success => { if (!success[0]) { Utils.removeCookie(Utils.sessionIdKey); - this.scene.reset(true, true); + globalScene.reset(true, true); return; } this.end(); } ); }, () => { - this.scene.unshiftPhase(new LoginPhase(this.scene, false)); + globalScene.unshiftPhase(new LoginPhase(false)); this.end(); } ] @@ -85,19 +86,19 @@ export class LoginPhase extends Phase { }); } else if (statusCode === 401) { Utils.removeCookie(Utils.sessionIdKey); - this.scene.reset(true, true); + globalScene.reset(true, true); } else { - this.scene.unshiftPhase(new UnavailablePhase(this.scene)); + globalScene.unshiftPhase(new UnavailablePhase()); super.end(); } return null; } else { - this.scene.gameData.loadSystem().then(success => { + globalScene.gameData.loadSystem().then(success => { if (success || bypassLogin) { this.end(); } else { - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(t("menu:failedToLoadSaveData")); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(t("menu:failedToLoadSaveData")); } }); } @@ -105,12 +106,12 @@ export class LoginPhase extends Phase { } end(): void { - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); - if (!this.scene.gameData.gender) { - this.scene.unshiftPhase(new SelectGenderPhase(this.scene)); + if (!globalScene.gameData.gender) { + globalScene.unshiftPhase(new SelectGenderPhase()); } - handleTutorial(this.scene, Tutorial.Intro).then(() => super.end()); + handleTutorial(Tutorial.Intro).then(() => super.end()); } } diff --git a/src/phases/message-phase.ts b/src/phases/message-phase.ts index 1d9538011782..9439d8286c31 100644 --- a/src/phases/message-phase.ts +++ b/src/phases/message-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; export class MessagePhase extends Phase { @@ -8,8 +8,8 @@ export class MessagePhase extends Phase { private promptDelay: integer | null; private speaker?: string; - constructor(scene: BattleScene, text: string, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null, speaker?: string) { - super(scene); + constructor(text: string, callbackDelay?: integer | null, prompt?: boolean | null, promptDelay?: integer | null, speaker?: string) { + super(); this.text = text; this.callbackDelay = callbackDelay!; // TODO: is this bang correct? @@ -23,20 +23,20 @@ export class MessagePhase extends Phase { if (this.text.indexOf("$") > -1) { const pageIndex = this.text.indexOf("$"); - this.scene.unshiftPhase(new MessagePhase(this.scene, this.text.slice(pageIndex + 1), this.callbackDelay, this.prompt, this.promptDelay, this.speaker)); + globalScene.unshiftPhase(new MessagePhase(this.text.slice(pageIndex + 1), this.callbackDelay, this.prompt, this.promptDelay, this.speaker)); this.text = this.text.slice(0, pageIndex).trim(); } if (this.speaker) { - this.scene.ui.showDialogue(this.text, this.speaker, null, () => this.end(), this.callbackDelay || (this.prompt ? 0 : 1500), this.promptDelay ?? 0); + globalScene.ui.showDialogue(this.text, this.speaker, null, () => this.end(), this.callbackDelay || (this.prompt ? 0 : 1500), this.promptDelay ?? 0); } else { - this.scene.ui.showText(this.text, null, () => this.end(), this.callbackDelay || (this.prompt ? 0 : 1500), this.prompt, this.promptDelay); + globalScene.ui.showText(this.text, null, () => this.end(), this.callbackDelay || (this.prompt ? 0 : 1500), this.prompt, this.promptDelay); } } end() { - if (this.scene.abilityBar.shown) { - this.scene.abilityBar.hide(); + if (globalScene.abilityBar.shown) { + globalScene.abilityBar.hide(); } super.end(); diff --git a/src/phases/modifier-reward-phase.ts b/src/phases/modifier-reward-phase.ts index 20a8366d9c67..ac8665bee77e 100644 --- a/src/phases/modifier-reward-phase.ts +++ b/src/phases/modifier-reward-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ModifierType, ModifierTypeFunc, getModifierType } from "#app/modifier/modifier-type"; import i18next from "i18next"; import { BattlePhase } from "./battle-phase"; @@ -6,8 +6,8 @@ import { BattlePhase } from "./battle-phase"; export class ModifierRewardPhase extends BattlePhase { protected modifierType: ModifierType; - constructor(scene: BattleScene, modifierTypeFunc: ModifierTypeFunc) { - super(scene); + constructor(modifierTypeFunc: ModifierTypeFunc) { + super(); this.modifierType = getModifierType(modifierTypeFunc); } @@ -21,9 +21,9 @@ export class ModifierRewardPhase extends BattlePhase { doReward(): Promise { return new Promise(resolve => { const newModifier = this.modifierType.newModifier(); - this.scene.addModifier(newModifier).then(() => { - this.scene.playSound("item_fanfare"); - this.scene.ui.showText(i18next.t("battle:rewardGain", { modifierName: newModifier?.type.name }), null, () => resolve(), null, true); + globalScene.addModifier(newModifier).then(() => { + globalScene.playSound("item_fanfare"); + globalScene.ui.showText(i18next.t("battle:rewardGain", { modifierName: newModifier?.type.name }), null, () => resolve(), null, true); }); }); } diff --git a/src/phases/money-reward-phase.ts b/src/phases/money-reward-phase.ts index 2f0a4f7b9903..70f0019227c3 100644 --- a/src/phases/money-reward-phase.ts +++ b/src/phases/money-reward-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ArenaTagType } from "#app/enums/arena-tag-type"; import { MoneyMultiplierModifier } from "#app/modifier/modifier"; import i18next from "i18next"; @@ -8,27 +8,27 @@ import { BattlePhase } from "./battle-phase"; export class MoneyRewardPhase extends BattlePhase { private moneyMultiplier: number; - constructor(scene: BattleScene, moneyMultiplier: number) { - super(scene); + constructor(moneyMultiplier: number) { + super(); this.moneyMultiplier = moneyMultiplier; } start() { - const moneyAmount = new Utils.IntegerHolder(this.scene.getWaveMoneyAmount(this.moneyMultiplier)); + const moneyAmount = new Utils.IntegerHolder(globalScene.getWaveMoneyAmount(this.moneyMultiplier)); - this.scene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); + globalScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); - if (this.scene.arena.getTag(ArenaTagType.HAPPY_HOUR)) { + if (globalScene.arena.getTag(ArenaTagType.HAPPY_HOUR)) { moneyAmount.value *= 2; } - this.scene.addMoney(moneyAmount.value); + globalScene.addMoney(moneyAmount.value); const userLocale = navigator.language || "en-US"; const formattedMoneyAmount = moneyAmount.value.toLocaleString(userLocale); const message = i18next.t("battle:moneyWon", { moneyAmount: formattedMoneyAmount }); - this.scene.ui.showText(message, null, () => this.end(), null, true); + globalScene.ui.showText(message, null, () => this.end(), null, true); } } diff --git a/src/phases/move-anim-test-phase.ts b/src/phases/move-anim-test-phase.ts index e4b04ce5de6f..588fc402357d 100644 --- a/src/phases/move-anim-test-phase.ts +++ b/src/phases/move-anim-test-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { initMoveAnim, loadMoveAnimAssets, MoveAnim } from "#app/data/battle-anims"; import { allMoves, SelfStatusMove } from "#app/data/move"; import { Moves } from "#app/enums/moves"; @@ -8,8 +8,8 @@ import { BattlePhase } from "./battle-phase"; export class MoveAnimTestPhase extends BattlePhase { private moveQueue: Moves[]; - constructor(scene: BattleScene, moveQueue?: Moves[]) { - super(scene); + constructor(moveQueue?: Moves[]) { + super(); this.moveQueue = moveQueue || Utils.getEnumValues(Moves).slice(1); } @@ -28,12 +28,12 @@ export class MoveAnimTestPhase extends BattlePhase { console.log(Moves[moveId]); } - initMoveAnim(this.scene, moveId).then(() => { - loadMoveAnimAssets(this.scene, [ moveId ], true) + initMoveAnim(moveId).then(() => { + loadMoveAnimAssets([ moveId ], true) .then(() => { - const user = player ? this.scene.getPlayerPokemon()! : this.scene.getEnemyPokemon()!; - const target = (player !== (allMoves[moveId] instanceof SelfStatusMove)) ? this.scene.getEnemyPokemon()! : this.scene.getPlayerPokemon()!; - new MoveAnim(moveId, user, target.getBattlerIndex()).play(this.scene, allMoves[moveId].hitsSubstitute(user, target), () => { // TODO: are the bangs correct here? + const user = player ? globalScene.getPlayerPokemon()! : globalScene.getEnemyPokemon()!; + const target = (player !== (allMoves[moveId] instanceof SelfStatusMove)) ? globalScene.getEnemyPokemon()! : globalScene.getPlayerPokemon()!; + new MoveAnim(moveId, user, target.getBattlerIndex()).play(allMoves[moveId].hitsSubstitute(user, target), () => { // TODO: are the bangs correct here? if (player) { this.playMoveAnim(moveQueue, false); } else { diff --git a/src/phases/move-charge-phase.ts b/src/phases/move-charge-phase.ts index d1dc340b81bc..7995b6ebb769 100644 --- a/src/phases/move-charge-phase.ts +++ b/src/phases/move-charge-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { MoveChargeAnim } from "#app/data/battle-anims"; import { applyMoveChargeAttrs, MoveEffectAttr, InstantChargeAttr } from "#app/data/move"; @@ -19,8 +19,8 @@ export class MoveChargePhase extends PokemonPhase { /** The field index targeted by the move (Charging moves assume single target) */ public targetIndex: BattlerIndex; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, targetIndex: BattlerIndex, move: PokemonMove) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, targetIndex: BattlerIndex, move: PokemonMove) { + super(battlerIndex); this.move = move; this.targetIndex = targetIndex; } @@ -39,7 +39,7 @@ export class MoveChargePhase extends PokemonPhase { return super.end(); } - new MoveChargeAnim(move.chargeAnim, move.id, user).play(this.scene, false, () => { + new MoveChargeAnim(move.chargeAnim, move.id, user).play(false, () => { move.showChargeText(user, target); applyMoveChargeAttrs(MoveEffectAttr, user, target, move).then(() => { @@ -61,9 +61,9 @@ export class MoveChargePhase extends PokemonPhase { if (instantCharge.value) { // this MoveEndPhase will be duplicated by the queued MovePhase if not removed - this.scene.tryRemovePhase((phase) => phase instanceof MoveEndPhase && phase.getPokemon() === user); + globalScene.tryRemovePhase((phase) => phase instanceof MoveEndPhase && phase.getPokemon() === user); // queue a new MovePhase for this move's attack phase - this.scene.unshiftPhase(new MovePhase(this.scene, user, [ this.targetIndex ], this.move, false)); + globalScene.unshiftPhase(new MovePhase(user, [ this.targetIndex ], this.move, false)); } else { user.getMoveQueue().push({ move: move.id, targets: [ this.targetIndex ]}); } @@ -75,10 +75,10 @@ export class MoveChargePhase extends PokemonPhase { } public getUserPokemon(): Pokemon { - return (this.player ? this.scene.getPlayerField() : this.scene.getEnemyField())[this.fieldIndex]; + return (this.player ? globalScene.getPlayerField() : globalScene.getEnemyField())[this.fieldIndex]; } public getTargetPokemon(): Pokemon | undefined { - return this.scene.getField(true).find((p) => this.targetIndex === p.getBattlerIndex()); + return globalScene.getField(true).find((p) => this.targetIndex === p.getBattlerIndex()); } } diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index d08fc46e563c..6de29191814f 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -1,5 +1,5 @@ import { BattlerIndex } from "#app/battle"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { AddSecondStrikeAbAttr, AlwaysHitAbAttr, @@ -65,8 +65,8 @@ export class MoveEffectPhase extends PokemonPhase { public move: PokemonMove; protected targets: BattlerIndex[]; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, targets: BattlerIndex[], move: PokemonMove) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, targets: BattlerIndex[], move: PokemonMove) { + super(battlerIndex); this.move = move; /** * In double battles, if the right Pokemon selects a spread move and the left Pokemon dies @@ -149,7 +149,7 @@ export class MoveEffectPhase extends PokemonPhase { // If Parental Bond is applicable, add another hit applyPreAttackAbAttrs(AddSecondStrikeAbAttr, user, null, move, false, hitCount, null); // If Multi-Lens is applicable, add hits equal to the number of held Multi-Lenses - this.scene.applyModifiers(PokemonMultiHitModifier, user.isPlayer(), user, move.id, hitCount); + globalScene.applyModifiers(PokemonMultiHitModifier, user.isPlayer(), user, move.id, hitCount); // Set the user's relevant turnData fields to reflect the final hit count user.turnData.hitCount = hitCount.value; user.turnData.hitsLeft = hitCount.value; @@ -182,11 +182,11 @@ export class MoveEffectPhase extends PokemonPhase { if (!hasActiveTargets || (!move.hasAttr(VariableTargetAttr) && !move.isMultiTarget() && !targetHitChecks[this.targets[0]] && !targets[0].getTag(ProtectedTag) && !isImmune)) { this.stopMultiHit(); if (hasActiveTargets) { - this.scene.queueMessage(i18next.t("battle:attackMissed", { pokemonNameWithAffix: this.getFirstTarget() ? getPokemonNameWithAffix(this.getFirstTarget()!) : "" })); + globalScene.queueMessage(i18next.t("battle:attackMissed", { pokemonNameWithAffix: this.getFirstTarget() ? getPokemonNameWithAffix(this.getFirstTarget()!) : "" })); moveHistoryEntry.result = MoveResult.MISS; applyMoveAttrs(MissEffectAttr, user, null, this.move.getMove()); } else { - this.scene.queueMessage(i18next.t("battle:attackFailed")); + globalScene.queueMessage(i18next.t("battle:attackFailed")); moveHistoryEntry.result = MoveResult.FAIL; } user.pushMoveHistory(moveHistoryEntry); @@ -196,9 +196,9 @@ export class MoveEffectPhase extends PokemonPhase { /** All move effect attributes are chained together in this array to be applied asynchronously. */ const applyAttrs: Promise[] = []; - const playOnEmptyField = this.scene.currentBattle?.mysteryEncounter?.hasBattleAnimationsWithoutTargets ?? false; + const playOnEmptyField = globalScene.currentBattle?.mysteryEncounter?.hasBattleAnimationsWithoutTargets ?? false; // Move animation only needs one target - new MoveAnim(move.id as Moves, user, this.getFirstTarget()!.getBattlerIndex(), playOnEmptyField).play(this.scene, move.hitsSubstitute(user, this.getFirstTarget()!), () => { + new MoveAnim(move.id as Moves, user, this.getFirstTarget()!.getBattlerIndex(), playOnEmptyField).play(move.hitsSubstitute(user, this.getFirstTarget()!), () => { /** Has the move successfully hit a target (for damage) yet? */ let hasHit: boolean = false; for (const target of targets) { @@ -215,7 +215,7 @@ export class MoveEffectPhase extends PokemonPhase { const bypassIgnoreProtect = new BooleanHolder(false); /** If the move is not targeting a Pokemon on the user's side, try to apply conditional protection effects */ if (!this.move.getMove().isAllyTarget()) { - this.scene.arena.applyTagsForSide(ConditionalProtectTag, targetSide, false, hasConditionalProtectApplied, user, target, move.id, bypassIgnoreProtect); + globalScene.arena.applyTagsForSide(ConditionalProtectTag, targetSide, false, hasConditionalProtectApplied, user, target, move.id, bypassIgnoreProtect); } /** Is the target protected by Protect, etc. or a relevant conditional protection effect? */ @@ -234,7 +234,7 @@ export class MoveEffectPhase extends PokemonPhase { && !target.getTag(SemiInvulnerableTag); /** Is the target hidden by the effects of its Commander ability? */ - const isCommanding = this.scene.currentBattle.double && target.getAlly()?.getTag(BattlerTagType.COMMANDED)?.getSourcePokemon(this.scene) === target; + const isCommanding = globalScene.currentBattle.double && target.getAlly()?.getTag(BattlerTagType.COMMANDED)?.getSourcePokemon() === target; /** * If the move missed a target, stop all future hits against that target @@ -243,7 +243,7 @@ export class MoveEffectPhase extends PokemonPhase { if (target.switchOutStatus || isCommanding || (!isImmune && !isProtected && !targetHitChecks[target.getBattlerIndex()])) { this.stopMultiHit(target); if (!target.switchOutStatus) { - this.scene.queueMessage(i18next.t("battle:attackMissed", { pokemonNameWithAffix: getPokemonNameWithAffix(target) })); + globalScene.queueMessage(i18next.t("battle:attackMissed", { pokemonNameWithAffix: getPokemonNameWithAffix(target) })); } if (moveHistoryEntry.result === MoveResult.PENDING) { moveHistoryEntry.result = MoveResult.MISS; @@ -312,7 +312,7 @@ export class MoveEffectPhase extends PokemonPhase { * (see Relic Song's interaction with Parental Bond when used by Meloetta). */ if (lastHit) { - this.scene.triggerPokemonFormChange(user, SpeciesFormChangePostMoveTrigger); + globalScene.triggerPokemonFormChange(user, SpeciesFormChangePostMoveTrigger); /** * Multi-Lens, Multi Hit move and Parental Bond check for PostDamageAbAttr * other damage source are calculated in damageAndUpdate in pokemon.ts @@ -404,16 +404,16 @@ export class MoveEffectPhase extends PokemonPhase { */ if (user) { if (user.turnData.hitsLeft && --user.turnData.hitsLeft >= 1 && this.getFirstTarget()?.isActive()) { - this.scene.unshiftPhase(this.getNewHitPhase()); + globalScene.unshiftPhase(this.getNewHitPhase()); } else { // Queue message for number of hits made by multi-move // If multi-hit attack only hits once, still want to render a message const hitsTotal = user.turnData.hitCount - Math.max(user.turnData.hitsLeft, 0); if (hitsTotal > 1 || (user.turnData.hitsLeft && user.turnData.hitsLeft > 0)) { // If there are multiple hits, or if there are hits of the multi-hit move left - this.scene.queueMessage(i18next.t("battle:attackHitsCount", { count: hitsTotal })); + globalScene.queueMessage(i18next.t("battle:attackHitsCount", { count: hitsTotal })); } - this.scene.applyModifiers(HitHealModifier, this.player, user); + globalScene.applyModifiers(HitHealModifier, this.player, user); // Clear all cached move effectiveness values among targets this.getTargets().forEach((target) => target.turnData.moveEffectiveness = null); } @@ -492,7 +492,7 @@ export class MoveEffectPhase extends PokemonPhase { if (!this.move.getMove().hitsSubstitute(user, target)) { if (!user.isPlayer() && this.move.getMove() instanceof AttackMove) { - user.scene.applyShuffledModifiers(this.scene, EnemyAttackStatusEffectChanceModifier, false, target); + globalScene.applyShuffledModifiers(EnemyAttackStatusEffectChanceModifier, false, target); } target.lapseTags(BattlerTagLapseType.AFTER_HIT); @@ -521,7 +521,7 @@ export class MoveEffectPhase extends PokemonPhase { applyPostAttackAbAttrs(PostAttackAbAttr, user, target, this.move.getMove(), hitResult)).then(() => { // Item Stealing Effects if (this.move.getMove() instanceof AttackMove) { - this.scene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target); + globalScene.applyModifiers(ContactHeldItemTransferChanceModifier, this.player, user, target); } }) ); @@ -542,7 +542,7 @@ export class MoveEffectPhase extends PokemonPhase { if (dealsDamage && !target.hasAbilityWithAttr(IgnoreMoveEffectsAbAttr) && !this.move.getMove().hitsSubstitute(user, target)) { const flinched = new BooleanHolder(false); - user.scene.applyModifiers(FlinchChanceModifier, user.isPlayer(), user, flinched); + globalScene.applyModifiers(FlinchChanceModifier, user.isPlayer(), user, flinched); if (flinched.value) { target.addTag(BattlerTagType.FLINCHED, undefined, this.move.moveId, user.id); } @@ -616,14 +616,14 @@ export class MoveEffectPhase extends PokemonPhase { /** @returns The {@linkcode Pokemon} using this phase's invoked move */ public getUserPokemon(): Pokemon | null { if (this.battlerIndex > BattlerIndex.ENEMY_2) { - return this.scene.getPokemonById(this.battlerIndex); + return globalScene.getPokemonById(this.battlerIndex); } - return (this.player ? this.scene.getPlayerField() : this.scene.getEnemyField())[this.fieldIndex]; + return (this.player ? globalScene.getPlayerField() : globalScene.getEnemyField())[this.fieldIndex]; } /** @returns An array of all {@linkcode Pokemon} targeted by this phase's invoked move */ public getTargets(): Pokemon[] { - return this.scene.getField(true).filter(p => this.targets.indexOf(p.getBattlerIndex()) > -1); + return globalScene.getField(true).filter(p => this.targets.indexOf(p.getBattlerIndex()) > -1); } /** @returns The first target of this phase's invoked move */ @@ -665,6 +665,6 @@ export class MoveEffectPhase extends PokemonPhase { /** @returns A new `MoveEffectPhase` with the same properties as this phase */ protected getNewHitPhase(): MoveEffectPhase { - return new MoveEffectPhase(this.scene, this.battlerIndex, this.targets, this.move); + return new MoveEffectPhase(this.battlerIndex, this.targets, this.move); } } diff --git a/src/phases/move-end-phase.ts b/src/phases/move-end-phase.ts index e03f2ec14b09..534d8118cacd 100644 --- a/src/phases/move-end-phase.ts +++ b/src/phases/move-end-phase.ts @@ -1,11 +1,11 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { BattlerTagLapseType } from "#app/data/battler-tags"; import { PokemonPhase } from "./pokemon-phase"; export class MoveEndPhase extends PokemonPhase { - constructor(scene: BattleScene, battlerIndex: BattlerIndex) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex) { + super(battlerIndex); } start() { @@ -16,7 +16,7 @@ export class MoveEndPhase extends PokemonPhase { pokemon.lapseTags(BattlerTagLapseType.AFTER_MOVE); } - this.scene.arena.setIgnoreAbilities(false); + globalScene.arena.setIgnoreAbilities(false); this.end(); } diff --git a/src/phases/move-header-phase.ts b/src/phases/move-header-phase.ts index c307ff0be6e9..5fb943cf4ab6 100644 --- a/src/phases/move-header-phase.ts +++ b/src/phases/move-header-phase.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { applyMoveAttrs, MoveHeaderAttr } from "#app/data/move"; import Pokemon, { PokemonMove } from "#app/field/pokemon"; import { BattlePhase } from "./battle-phase"; @@ -7,8 +6,8 @@ export class MoveHeaderPhase extends BattlePhase { public pokemon: Pokemon; public move: PokemonMove; - constructor(scene: BattleScene, pokemon: Pokemon, move: PokemonMove) { - super(scene); + constructor(pokemon: Pokemon, move: PokemonMove) { + super(); this.pokemon = pokemon; this.move = move; diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 089386bee002..632a3c3a5907 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -1,5 +1,5 @@ import { BattlerIndex } from "#app/battle"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { applyAbAttrs, applyPostMoveUsedAbAttrs, @@ -85,8 +85,8 @@ export class MovePhase extends BattlePhase { * @param followUp Indicates that the move being uses is a "follow-up" - for example, a move being used by Metronome or Dancer. * Follow-ups bypass a few failure conditions, including flinches, sleep/paralysis/freeze and volatile status checks, etc. */ - constructor(scene: BattleScene, pokemon: Pokemon, targets: BattlerIndex[], move: PokemonMove, followUp: boolean = false, ignorePp: boolean = false) { - super(scene); + constructor(pokemon: Pokemon, targets: BattlerIndex[], move: PokemonMove, followUp: boolean = false, ignorePp: boolean = false) { + super(); this.pokemon = pokemon; this.targets = targets; @@ -140,7 +140,7 @@ export class MovePhase extends BattlePhase { // Check move to see if arena.ignoreAbilities should be true. if (!this.followUp) { if (this.move.getMove().checkFlag(MoveFlags.IGNORE_ABILITIES, this.pokemon, null)) { - this.scene.arena.setIgnoreAbilities(true, this.pokemon.getBattlerIndex()); + globalScene.arena.setIgnoreAbilities(true, this.pokemon.getBattlerIndex()); } } @@ -180,7 +180,7 @@ export class MovePhase extends BattlePhase { } public getActiveTargetPokemon(): Pokemon[] { - return this.scene.getField(true).filter(p => this.targets.includes(p.getBattlerIndex())); + return globalScene.getField(true).filter(p => this.targets.includes(p.getBattlerIndex())); } /** @@ -219,10 +219,10 @@ export class MovePhase extends BattlePhase { if (activated) { this.cancel(); - this.scene.queueMessage(getStatusEffectActivationText(this.pokemon.status.effect, getPokemonNameWithAffix(this.pokemon))); - this.scene.unshiftPhase(new CommonAnimPhase(this.scene, this.pokemon.getBattlerIndex(), undefined, CommonAnim.POISON + (this.pokemon.status.effect - 1))); + globalScene.queueMessage(getStatusEffectActivationText(this.pokemon.status.effect, getPokemonNameWithAffix(this.pokemon))); + globalScene.unshiftPhase(new CommonAnimPhase(this.pokemon.getBattlerIndex(), undefined, CommonAnim.POISON + (this.pokemon.status.effect - 1))); } else if (healed) { - this.scene.queueMessage(getStatusEffectHealText(this.pokemon.status.effect, getPokemonNameWithAffix(this.pokemon))); + globalScene.queueMessage(getStatusEffectHealText(this.pokemon.status.effect, getPokemonNameWithAffix(this.pokemon))); this.pokemon.resetStatus(); this.pokemon.updateInfo(); } @@ -247,13 +247,13 @@ export class MovePhase extends BattlePhase { const moveQueue = this.pokemon.getMoveQueue(); // form changes happen even before we know that the move wll execute. - this.scene.triggerPokemonFormChange(this.pokemon, SpeciesFormChangePreMoveTrigger); + globalScene.triggerPokemonFormChange(this.pokemon, SpeciesFormChangePreMoveTrigger); const isDelayedAttack = this.move.getMove().hasAttr(DelayedAttackAttr); if (isDelayedAttack) { // Check the player side arena if future sight is active - const futureSightTags = this.scene.arena.findTags(t => t.tagType === ArenaTagType.FUTURE_SIGHT); - const doomDesireTags = this.scene.arena.findTags(t => t.tagType === ArenaTagType.DOOM_DESIRE); + const futureSightTags = globalScene.arena.findTags(t => t.tagType === ArenaTagType.FUTURE_SIGHT); + const doomDesireTags = globalScene.arena.findTags(t => t.tagType === ArenaTagType.DOOM_DESIRE); let fail = false; const currentTargetIndex = targets[0].getBattlerIndex(); for (const tag of futureSightTags) { @@ -291,12 +291,12 @@ export class MovePhase extends BattlePhase { const ppUsed = 1 + this.getPpIncreaseFromPressure(targets); this.move.usePp(ppUsed); - this.scene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), this.move.ppUsed)); + globalScene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), this.move.ppUsed)); } // Update the battle's "last move" pointer, unless we're currently mimicking a move. if (!allMoves[this.move.moveId].hasAttr(CopyMoveAttr)) { - this.scene.currentBattle.lastMove = this.move.moveId; + globalScene.currentBattle.lastMove = this.move.moveId; } /** @@ -317,8 +317,8 @@ export class MovePhase extends BattlePhase { * TODO: is this sustainable? */ const passesConditions = move.applyConditions(this.pokemon, targets[0], move); - const failedDueToWeather: boolean = this.scene.arena.isMoveWeatherCancelled(this.pokemon, move); - const failedDueToTerrain: boolean = this.scene.arena.isMoveTerrainCancelled(this.pokemon, this.targets, move); + const failedDueToWeather: boolean = globalScene.arena.isMoveWeatherCancelled(this.pokemon, move); + const failedDueToTerrain: boolean = globalScene.arena.isMoveTerrainCancelled(this.pokemon, this.targets, move); const success = passesConditions && !failedDueToWeather && !failedDueToTerrain; @@ -330,7 +330,7 @@ export class MovePhase extends BattlePhase { */ if (success) { applyPreAttackAbAttrs(PokemonTypeChangeAbAttr, this.pokemon, null, this.move.getMove()); - this.scene.unshiftPhase(new MoveEffectPhase(this.scene, this.pokemon.getBattlerIndex(), this.targets, this.move)); + globalScene.unshiftPhase(new MoveEffectPhase(this.pokemon.getBattlerIndex(), this.targets, this.move)); } else { if ([ Moves.ROAR, Moves.WHIRLWIND, Moves.TRICK_OR_TREAT, Moves.FORESTS_CURSE ].includes(this.move.moveId)) { @@ -345,7 +345,7 @@ export class MovePhase extends BattlePhase { if (failureMessage) { failedText = failureMessage; } else if (failedDueToTerrain) { - failedText = getTerrainBlockMessage(this.pokemon, this.scene.arena.getTerrainType()); + failedText = getTerrainBlockMessage(this.pokemon, globalScene.arena.getTerrainType()); } this.showFailedText(failedText); @@ -357,7 +357,7 @@ export class MovePhase extends BattlePhase { // Handle Dancer, which triggers immediately after a move is used (rather than waiting on `this.end()`). // Note that the `!this.followUp` check here prevents an infinite Dancer loop. if (this.move.getMove().hasFlag(MoveFlags.DANCE_MOVE) && !this.followUp) { - this.scene.getField(true).forEach(pokemon => { + globalScene.getField(true).forEach(pokemon => { applyPostMoveUsedAbAttrs(PostMoveUsedAbAttr, pokemon, this.move, this.pokemon, this.targets); }); } @@ -373,7 +373,7 @@ export class MovePhase extends BattlePhase { applyPreAttackAbAttrs(PokemonTypeChangeAbAttr, this.pokemon, null, this.move.getMove()); this.showMoveText(); - this.scene.unshiftPhase(new MoveChargePhase(this.scene, this.pokemon.getBattlerIndex(), this.targets[0], this.move)); + globalScene.unshiftPhase(new MoveChargePhase(this.pokemon.getBattlerIndex(), this.targets[0], this.move)); } else { this.pokemon.pushMoveHistory({ move: this.move.moveId, targets: this.targets, result: MoveResult.FAIL, virtual: this.move.virtual }); @@ -392,7 +392,7 @@ export class MovePhase extends BattlePhase { */ public end(): void { if (!this.followUp && this.canMove()) { - this.scene.unshiftPhase(new MoveEndPhase(this.scene, this.pokemon.getBattlerIndex())); + globalScene.unshiftPhase(new MoveEndPhase(this.pokemon.getBattlerIndex())); } super.end(); @@ -420,7 +420,7 @@ export class MovePhase extends BattlePhase { const redirectTarget = new NumberHolder(currentTarget); // check move redirection abilities of every pokemon *except* the user. - this.scene.getField(true).filter(p => p !== this.pokemon).forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, false, this.move.moveId, redirectTarget)); + globalScene.getField(true).filter(p => p !== this.pokemon).forEach(p => applyAbAttrs(RedirectMoveAbAttr, p, null, false, this.move.moveId, redirectTarget)); /** `true` if an Ability is responsible for redirecting the move to another target; `false` otherwise */ let redirectedByAbility = (currentTarget !== redirectTarget.value); @@ -447,7 +447,7 @@ export class MovePhase extends BattlePhase { if (this.pokemon.hasAbilityWithAttr(BlockRedirectAbAttr)) { redirectTarget.value = currentTarget; - this.scene.unshiftPhase(new ShowAbilityPhase(this.scene, this.pokemon.getBattlerIndex(), this.pokemon.getPassiveAbility().hasAttr(BlockRedirectAbAttr))); + globalScene.unshiftPhase(new ShowAbilityPhase(this.pokemon.getBattlerIndex(), this.pokemon.getPassiveAbility().hasAttr(BlockRedirectAbAttr))); } this.targets[0] = redirectTarget.value; @@ -470,9 +470,9 @@ export class MovePhase extends BattlePhase { // account for metal burst and comeuppance hitting remaining targets in double battles // counterattack will redirect to remaining ally if original attacker faints - if (this.scene.currentBattle.double && this.move.getMove().hasFlag(MoveFlags.REDIRECT_COUNTER)) { - if (this.scene.getField()[this.targets[0]].hp === 0) { - const opposingField = this.pokemon.isPlayer() ? this.scene.getEnemyField() : this.scene.getPlayerField(); + if (globalScene.currentBattle.double && this.move.getMove().hasFlag(MoveFlags.REDIRECT_COUNTER)) { + if (globalScene.getField()[this.targets[0]].hp === 0) { + const opposingField = this.pokemon.isPlayer() ? globalScene.getEnemyField() : globalScene.getPlayerField(); this.targets[0] = opposingField.find(p => p.hp > 0)?.getBattlerIndex() ?? BattlerIndex.ATTACKER; } } @@ -509,7 +509,7 @@ export class MovePhase extends BattlePhase { this.move.usePp(); } - this.scene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), ppUsed)); + globalScene.eventTarget.dispatchEvent(new MoveUsedEvent(this.pokemon?.id, this.move.getMove(), ppUsed)); } if (this.cancelled && this.pokemon.summonData?.tags?.find(t => t.tagType === BattlerTagType.FRENZY)) { @@ -538,7 +538,7 @@ export class MovePhase extends BattlePhase { return; } - this.scene.queueMessage(i18next.t("battle:useMove", { + globalScene.queueMessage(i18next.t("battle:useMove", { pokemonNameWithAffix: getPokemonNameWithAffix(this.pokemon), moveName: this.move.getName() }), 500); @@ -546,6 +546,6 @@ export class MovePhase extends BattlePhase { } public showFailedText(failedText?: string): void { - this.scene.queueMessage(failedText ?? i18next.t("battle:attackFailed")); + globalScene.queueMessage(failedText ?? i18next.t("battle:attackFailed")); } } diff --git a/src/phases/mystery-encounter-phases.ts b/src/phases/mystery-encounter-phases.ts index 2d1c3c4ae317..7c8e1eb65d73 100644 --- a/src/phases/mystery-encounter-phases.ts +++ b/src/phases/mystery-encounter-phases.ts @@ -17,7 +17,7 @@ import { BattlerTagType } from "#enums/battler-tag-type"; import { MysteryEncounterMode } from "#enums/mystery-encounter-mode"; import { SwitchType } from "#enums/switch-type"; import i18next from "i18next"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { getCharVariantFromDialogue } from "../data/dialogue"; import { OptionSelectSettings, transitionMysteryEncounterIntroVisuals } from "../data/mystery-encounters/utils/encounter-phase-utils"; import { TrainerSlot } from "../data/trainer-config"; @@ -42,11 +42,10 @@ export class MysteryEncounterPhase extends Phase { /** * Mostly useful for having repeated queries during a single encounter, where the queries and options may differ each time - * @param scene * @param optionSelectSettings allows overriding the typical options of an encounter with new ones */ - constructor(scene: BattleScene, optionSelectSettings?: OptionSelectSettings) { - super(scene); + constructor(optionSelectSettings?: OptionSelectSettings) { + super(); this.optionSelectSettings = optionSelectSettings; } @@ -57,20 +56,20 @@ export class MysteryEncounterPhase extends Phase { super.start(); // Clears out queued phases that are part of standard battle - this.scene.clearPhaseQueue(); - this.scene.clearPhaseQueueSplice(); + globalScene.clearPhaseQueue(); + globalScene.clearPhaseQueueSplice(); - const encounter = this.scene.currentBattle.mysteryEncounter!; - encounter.updateSeedOffset(this.scene); + const encounter = globalScene.currentBattle.mysteryEncounter!; + encounter.updateSeedOffset(); if (!this.optionSelectSettings) { // Sets flag that ME was encountered, only if this is not a followup option select phase // Can be used in later MEs to check for requirements to spawn, run history, etc. - this.scene.mysteryEncounterSaveData.encounteredEvents.push(new SeenEncounterData(encounter.encounterType, encounter.encounterTier, this.scene.currentBattle.waveIndex)); + globalScene.mysteryEncounterSaveData.encounteredEvents.push(new SeenEncounterData(encounter.encounterType, encounter.encounterTier, globalScene.currentBattle.waveIndex)); } // Initiates encounter dialogue window and option select - this.scene.ui.setMode(Mode.MYSTERY_ENCOUNTER, this.optionSelectSettings); + globalScene.ui.setMode(Mode.MYSTERY_ENCOUNTER, this.optionSelectSettings); } /** @@ -80,13 +79,13 @@ export class MysteryEncounterPhase extends Phase { */ handleOptionSelect(option: MysteryEncounterOption, index: number): boolean { // Set option selected flag - this.scene.currentBattle.mysteryEncounter!.selectedOption = option; + globalScene.currentBattle.mysteryEncounter!.selectedOption = option; if (!this.optionSelectSettings) { // Saves the selected option in the ME save data, only if this is not a followup option select phase // Can be used for analytics purposes to track what options are popular on certain encounters - const encounterSaveData = this.scene.mysteryEncounterSaveData.encounteredEvents[this.scene.mysteryEncounterSaveData.encounteredEvents.length - 1]; - if (encounterSaveData.type === this.scene.currentBattle.mysteryEncounter?.encounterType) { + const encounterSaveData = globalScene.mysteryEncounterSaveData.encounteredEvents[globalScene.mysteryEncounterSaveData.encounteredEvents.length - 1]; + if (encounterSaveData.type === globalScene.currentBattle.mysteryEncounter?.encounterType) { encounterSaveData.selectedOption = index; } } @@ -96,17 +95,17 @@ export class MysteryEncounterPhase extends Phase { } // Populate dialogue tokens for option requirements - this.scene.currentBattle.mysteryEncounter!.populateDialogueTokensFromRequirements(this.scene); + globalScene.currentBattle.mysteryEncounter!.populateDialogueTokensFromRequirements(); if (option.onPreOptionPhase) { - this.scene.executeWithSeedOffset(async () => { - return await option.onPreOptionPhase!(this.scene) + globalScene.executeWithSeedOffset(async () => { + return await option.onPreOptionPhase!() .then((result) => { if (isNullOrUndefined(result) || result) { this.continueEncounter(); } }); - }, this.scene.currentBattle.mysteryEncounter?.getSeedOffset()); + }, globalScene.currentBattle.mysteryEncounter?.getSeedOffset()); } else { this.continueEncounter(); } @@ -119,30 +118,30 @@ export class MysteryEncounterPhase extends Phase { */ continueEncounter() { const endDialogueAndContinueEncounter = () => { - this.scene.pushPhase(new MysteryEncounterOptionSelectedPhase(this.scene)); + globalScene.pushPhase(new MysteryEncounterOptionSelectedPhase()); this.end(); }; - const optionSelectDialogue = this.scene.currentBattle?.mysteryEncounter?.selectedOption?.dialogue; + const optionSelectDialogue = globalScene.currentBattle?.mysteryEncounter?.selectedOption?.dialogue; if (optionSelectDialogue?.selected && optionSelectDialogue.selected.length > 0) { // Handle intermediate dialogue (between player selection event and the onOptionSelect logic) - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); const selectedDialogue = optionSelectDialogue.selected; let i = 0; const showNextDialogue = () => { const nextAction = i === selectedDialogue.length - 1 ? endDialogueAndContinueEncounter : showNextDialogue; const dialogue = selectedDialogue[i]; let title: string | null = null; - const text: string | null = getEncounterText(this.scene, dialogue.text); + const text: string | null = getEncounterText(dialogue.text); if (dialogue.speaker) { - title = getEncounterText(this.scene, dialogue.speaker); + title = getEncounterText(dialogue.speaker); } i++; if (title) { - this.scene.ui.showDialogue(text ?? "", title, null, nextAction, 0, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0); + globalScene.ui.showDialogue(text ?? "", title, null, nextAction, 0, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0); } else { - this.scene.ui.showText(text ?? "", null, nextAction, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0, true); + globalScene.ui.showText(text ?? "", null, nextAction, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0, true); } }; @@ -156,7 +155,7 @@ export class MysteryEncounterPhase extends Phase { * Ends phase */ end() { - this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end()); + globalScene.ui.setMode(Mode.MESSAGE).then(() => super.end()); } } @@ -170,9 +169,9 @@ export class MysteryEncounterPhase extends Phase { export class MysteryEncounterOptionSelectedPhase extends Phase { onOptionSelect: OptionPhaseCallback; - constructor(scene: BattleScene) { - super(scene); - this.onOptionSelect = this.scene.currentBattle.mysteryEncounter!.selectedOption!.onOptionPhase; + constructor() { + super(); + this.onOptionSelect = globalScene.currentBattle.mysteryEncounter!.selectedOption!.onOptionPhase; } /** @@ -184,20 +183,20 @@ export class MysteryEncounterOptionSelectedPhase extends Phase { */ start() { super.start(); - if (this.scene.currentBattle.mysteryEncounter?.autoHideIntroVisuals) { - transitionMysteryEncounterIntroVisuals(this.scene).then(() => { - this.scene.executeWithSeedOffset(() => { - this.onOptionSelect(this.scene).finally(() => { + if (globalScene.currentBattle.mysteryEncounter?.autoHideIntroVisuals) { + transitionMysteryEncounterIntroVisuals().then(() => { + globalScene.executeWithSeedOffset(() => { + this.onOptionSelect().finally(() => { this.end(); }); - }, this.scene.currentBattle.mysteryEncounter?.getSeedOffset() * 500); + }, globalScene.currentBattle.mysteryEncounter?.getSeedOffset() * 500); }); } else { - this.scene.executeWithSeedOffset(() => { - this.onOptionSelect(this.scene).finally(() => { + globalScene.executeWithSeedOffset(() => { + this.onOptionSelect().finally(() => { this.end(); }); - }, this.scene.currentBattle.mysteryEncounter?.getSeedOffset() * 500); + }, globalScene.currentBattle.mysteryEncounter?.getSeedOffset() * 500); } } } @@ -209,8 +208,8 @@ export class MysteryEncounterOptionSelectedPhase extends Phase { * See {@linkcode TurnEndPhase} for more details */ export class MysteryEncounterBattleStartCleanupPhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } /** @@ -221,7 +220,7 @@ export class MysteryEncounterBattleStartCleanupPhase extends Phase { // Lapse any residual flinches/endures but ignore all other turn-end battle tags const includedLapseTags = [ BattlerTagType.FLINCHED, BattlerTagType.ENDURING ]; - const field = this.scene.getField(true).filter(p => p.summonData); + const field = globalScene.getField(true).filter(p => p.summonData); field.forEach(pokemon => { const tags = pokemon.summonData.tags; tags.filter(t => includedLapseTags.includes(t.tagType) @@ -233,31 +232,31 @@ export class MysteryEncounterBattleStartCleanupPhase extends Phase { }); // Remove any status tick phases - while (!!this.scene.findPhase(p => p instanceof PostTurnStatusEffectPhase)) { - this.scene.tryRemovePhase(p => p instanceof PostTurnStatusEffectPhase); + while (!!globalScene.findPhase(p => p instanceof PostTurnStatusEffectPhase)) { + globalScene.tryRemovePhase(p => p instanceof PostTurnStatusEffectPhase); } // The total number of Pokemon in the player's party that can legally fight - const legalPlayerPokemon = this.scene.getPokemonAllowedInBattle(); + const legalPlayerPokemon = globalScene.getPokemonAllowedInBattle(); // The total number of legal player Pokemon that aren't currently on the field const legalPlayerPartyPokemon = legalPlayerPokemon.filter(p => !p.isActive(true)); if (!legalPlayerPokemon.length) { - this.scene.unshiftPhase(new GameOverPhase(this.scene)); + globalScene.unshiftPhase(new GameOverPhase()); return this.end(); } // Check for any KOd player mons and switch // For each fainted mon on the field, if there is a legal replacement, summon it - const playerField = this.scene.getPlayerField(); + const playerField = globalScene.getPlayerField(); playerField.forEach((pokemon, i) => { if (!pokemon.isAllowedInBattle() && legalPlayerPartyPokemon.length > i) { - this.scene.unshiftPhase(new SwitchPhase(this.scene, SwitchType.SWITCH, i, true, false)); + globalScene.unshiftPhase(new SwitchPhase(SwitchType.SWITCH, i, true, false)); } }); // THEN, if is a double battle, and player only has 1 summoned pokemon, center pokemon on field - if (this.scene.currentBattle.double && legalPlayerPokemon.length === 1 && legalPlayerPartyPokemon.length === 0) { - this.scene.unshiftPhase(new ToggleDoublePositionPhase(this.scene, true)); + if (globalScene.currentBattle.double && legalPlayerPokemon.length === 1 && legalPlayerPartyPokemon.length === 0) { + globalScene.unshiftPhase(new ToggleDoublePositionPhase(true)); } this.end(); @@ -274,8 +273,8 @@ export class MysteryEncounterBattleStartCleanupPhase extends Phase { export class MysteryEncounterBattlePhase extends Phase { disableSwitch: boolean; - constructor(scene: BattleScene, disableSwitch = false) { - super(scene); + constructor(disableSwitch = false) { + super(); this.disableSwitch = disableSwitch; } @@ -285,28 +284,27 @@ export class MysteryEncounterBattlePhase extends Phase { start() { super.start(); - this.doMysteryEncounterBattle(this.scene); + this.doMysteryEncounterBattle(); } /** * Gets intro battle message for new battle - * @param scene * @private */ - private getBattleMessage(scene: BattleScene): string { - const enemyField = scene.getEnemyField(); - const encounterMode = scene.currentBattle.mysteryEncounter!.encounterMode; + private getBattleMessage(): string { + const enemyField = globalScene.getEnemyField(); + const encounterMode = globalScene.currentBattle.mysteryEncounter!.encounterMode; - if (scene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { + if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { return i18next.t("battle:bossAppeared", { bossName: enemyField[0].name }); } if (encounterMode === MysteryEncounterMode.TRAINER_BATTLE) { - if (scene.currentBattle.double) { - return i18next.t("battle:trainerAppearedDouble", { trainerName: scene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); + if (globalScene.currentBattle.double) { + return i18next.t("battle:trainerAppearedDouble", { trainerName: globalScene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); } else { - return i18next.t("battle:trainerAppeared", { trainerName: scene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); + return i18next.t("battle:trainerAppeared", { trainerName: globalScene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }); } } @@ -317,66 +315,65 @@ export class MysteryEncounterBattlePhase extends Phase { /** * Queues {@linkcode SummonPhase}s for the new battle, and handles trainer animations/dialogue if it's a Trainer battle - * @param scene * @private */ - private doMysteryEncounterBattle(scene: BattleScene) { - const encounterMode = scene.currentBattle.mysteryEncounter!.encounterMode; + private doMysteryEncounterBattle() { + const encounterMode = globalScene.currentBattle.mysteryEncounter!.encounterMode; if (encounterMode === MysteryEncounterMode.WILD_BATTLE || encounterMode === MysteryEncounterMode.BOSS_BATTLE) { // Summons the wild/boss Pokemon if (encounterMode === MysteryEncounterMode.BOSS_BATTLE) { - scene.playBgm(undefined); + globalScene.playBgm(); } - const availablePartyMembers = scene.getEnemyParty().filter(p => !p.isFainted()).length; - scene.unshiftPhase(new SummonPhase(scene, 0, false)); - if (scene.currentBattle.double && availablePartyMembers > 1) { - scene.unshiftPhase(new SummonPhase(scene, 1, false)); + const availablePartyMembers = globalScene.getEnemyParty().filter(p => !p.isFainted()).length; + globalScene.unshiftPhase(new SummonPhase(0, false)); + if (globalScene.currentBattle.double && availablePartyMembers > 1) { + globalScene.unshiftPhase(new SummonPhase(1, false)); } - if (!scene.currentBattle.mysteryEncounter?.hideBattleIntroMessage) { - scene.ui.showText(this.getBattleMessage(scene), null, () => this.endBattleSetup(scene), 0); + if (!globalScene.currentBattle.mysteryEncounter?.hideBattleIntroMessage) { + globalScene.ui.showText(this.getBattleMessage(), null, () => this.endBattleSetup(), 0); } else { - this.endBattleSetup(scene); + this.endBattleSetup(); } } else if (encounterMode === MysteryEncounterMode.TRAINER_BATTLE) { this.showEnemyTrainer(); const doSummon = () => { - scene.currentBattle.started = true; - scene.playBgm(undefined); - scene.pbTray.showPbTray(scene.getPlayerParty()); - scene.pbTrayEnemy.showPbTray(scene.getEnemyParty()); + globalScene.currentBattle.started = true; + globalScene.playBgm(); + globalScene.pbTray.showPbTray(globalScene.getPlayerParty()); + globalScene.pbTrayEnemy.showPbTray(globalScene.getEnemyParty()); const doTrainerSummon = () => { this.hideEnemyTrainer(); - const availablePartyMembers = scene.getEnemyParty().filter(p => !p.isFainted()).length; - scene.unshiftPhase(new SummonPhase(scene, 0, false)); - if (scene.currentBattle.double && availablePartyMembers > 1) { - scene.unshiftPhase(new SummonPhase(scene, 1, false)); + const availablePartyMembers = globalScene.getEnemyParty().filter(p => !p.isFainted()).length; + globalScene.unshiftPhase(new SummonPhase(0, false)); + if (globalScene.currentBattle.double && availablePartyMembers > 1) { + globalScene.unshiftPhase(new SummonPhase(1, false)); } - this.endBattleSetup(scene); + this.endBattleSetup(); }; - if (!scene.currentBattle.mysteryEncounter?.hideBattleIntroMessage) { - scene.ui.showText(this.getBattleMessage(scene), null, doTrainerSummon, 1000, true); + if (!globalScene.currentBattle.mysteryEncounter?.hideBattleIntroMessage) { + globalScene.ui.showText(this.getBattleMessage(), null, doTrainerSummon, 1000, true); } else { doTrainerSummon(); } }; - const encounterMessages = scene.currentBattle.trainer?.getEncounterMessages(); + const encounterMessages = globalScene.currentBattle.trainer?.getEncounterMessages(); if (!encounterMessages || !encounterMessages.length) { doSummon(); } else { - const trainer = this.scene.currentBattle.trainer; + const trainer = globalScene.currentBattle.trainer; let message: string; - scene.executeWithSeedOffset(() => message = Utils.randSeedItem(encounterMessages), this.scene.currentBattle.mysteryEncounter?.getSeedOffset()); + globalScene.executeWithSeedOffset(() => message = Utils.randSeedItem(encounterMessages), globalScene.currentBattle.mysteryEncounter?.getSeedOffset()); message = message!; // tell TS compiler it's defined now const showDialogueAndSummon = () => { - scene.ui.showDialogue(message, trainer?.getName(TrainerSlot.NONE, true), null, () => { - scene.charSprite.hide().then(() => scene.hideFieldOverlay(250).then(() => doSummon())); + globalScene.ui.showDialogue(message, trainer?.getName(TrainerSlot.NONE, true), null, () => { + globalScene.charSprite.hide().then(() => globalScene.hideFieldOverlay(250).then(() => doSummon())); }); }; - if (this.scene.currentBattle.trainer?.config.hasCharSprite && !this.scene.ui.shouldSkipDialogue(message)) { - this.scene.showFieldOverlay(500).then(() => this.scene.charSprite.showCharacter(trainer?.getKey()!, getCharVariantFromDialogue(encounterMessages[0])).then(() => showDialogueAndSummon())); // TODO: is this bang correct? + if (globalScene.currentBattle.trainer?.config.hasCharSprite && !globalScene.ui.shouldSkipDialogue(message)) { + globalScene.showFieldOverlay(500).then(() => globalScene.charSprite.showCharacter(trainer?.getKey()!, getCharVariantFromDialogue(encounterMessages[0])).then(() => showDialogueAndSummon())); // TODO: is this bang correct? } else { showDialogueAndSummon(); } @@ -386,49 +383,48 @@ export class MysteryEncounterBattlePhase extends Phase { /** * Initiate {@linkcode SummonPhase}s, {@linkcode ScanIvsPhase}, {@linkcode PostSummonPhase}s, etc. - * @param scene * @private */ - private endBattleSetup(scene: BattleScene) { - const enemyField = scene.getEnemyField(); - const encounterMode = scene.currentBattle.mysteryEncounter!.encounterMode; + private endBattleSetup() { + const enemyField = globalScene.getEnemyField(); + const encounterMode = globalScene.currentBattle.mysteryEncounter!.encounterMode; // PostSummon and ShinySparkle phases are handled by SummonPhase if (encounterMode !== MysteryEncounterMode.TRAINER_BATTLE) { - const ivScannerModifier = this.scene.findModifier(m => m instanceof IvScannerModifier); + const ivScannerModifier = globalScene.findModifier(m => m instanceof IvScannerModifier); if (ivScannerModifier) { - enemyField.map(p => this.scene.pushPhase(new ScanIvsPhase(this.scene, p.getBattlerIndex(), Math.min(ivScannerModifier.getStackCount() * 2, 6)))); + enemyField.map(p => globalScene.pushPhase(new ScanIvsPhase(p.getBattlerIndex(), Math.min(ivScannerModifier.getStackCount() * 2, 6)))); } } - const availablePartyMembers = scene.getPlayerParty().filter(p => p.isAllowedInBattle()); + const availablePartyMembers = globalScene.getPlayerParty().filter(p => p.isAllowedInBattle()); if (!availablePartyMembers[0].isOnField()) { - scene.pushPhase(new SummonPhase(scene, 0)); + globalScene.pushPhase(new SummonPhase(0)); } - if (scene.currentBattle.double) { + if (globalScene.currentBattle.double) { if (availablePartyMembers.length > 1) { - scene.pushPhase(new ToggleDoublePositionPhase(scene, true)); + globalScene.pushPhase(new ToggleDoublePositionPhase(true)); if (!availablePartyMembers[1].isOnField()) { - scene.pushPhase(new SummonPhase(scene, 1)); + globalScene.pushPhase(new SummonPhase(1)); } } } else { if (availablePartyMembers.length > 1 && availablePartyMembers[1].isOnField()) { - scene.getPlayerField().forEach((pokemon) => pokemon.lapseTag(BattlerTagType.COMMANDED)); - scene.pushPhase(new ReturnPhase(scene, 1)); + globalScene.getPlayerField().forEach((pokemon) => pokemon.lapseTag(BattlerTagType.COMMANDED)); + globalScene.pushPhase(new ReturnPhase(1)); } - scene.pushPhase(new ToggleDoublePositionPhase(scene, false)); + globalScene.pushPhase(new ToggleDoublePositionPhase(false)); } if (encounterMode !== MysteryEncounterMode.TRAINER_BATTLE && !this.disableSwitch) { - const minPartySize = scene.currentBattle.double ? 2 : 1; + const minPartySize = globalScene.currentBattle.double ? 2 : 1; if (availablePartyMembers.length > minPartySize) { - scene.pushPhase(new CheckSwitchPhase(scene, 0, scene.currentBattle.double)); - if (scene.currentBattle.double) { - scene.pushPhase(new CheckSwitchPhase(scene, 1, scene.currentBattle.double)); + globalScene.pushPhase(new CheckSwitchPhase(0, globalScene.currentBattle.double)); + if (globalScene.currentBattle.double) { + globalScene.pushPhase(new CheckSwitchPhase(1, globalScene.currentBattle.double)); } } } @@ -442,7 +438,7 @@ export class MysteryEncounterBattlePhase extends Phase { */ private showEnemyTrainer(): void { // Show enemy trainer - const trainer = this.scene.currentBattle.trainer; + const trainer = globalScene.currentBattle.trainer; if (!trainer) { return; } @@ -450,7 +446,7 @@ export class MysteryEncounterBattlePhase extends Phase { trainer.x += 16; trainer.y -= 16; trainer.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: trainer, x: "-=16", y: "+=16", @@ -465,8 +461,8 @@ export class MysteryEncounterBattlePhase extends Phase { } private hideEnemyTrainer(): void { - this.scene.tweens.add({ - targets: this.scene.currentBattle.trainer, + globalScene.tweens.add({ + targets: globalScene.currentBattle.trainer, x: "+=16", y: "-=16", alpha: 0, @@ -490,8 +486,8 @@ export class MysteryEncounterBattlePhase extends Phase { export class MysteryEncounterRewardsPhase extends Phase { addHealPhase: boolean; - constructor(scene: BattleScene, addHealPhase: boolean = false) { - super(scene); + constructor(addHealPhase: boolean = false) { + super(); this.addHealPhase = addHealPhase; } @@ -500,23 +496,23 @@ export class MysteryEncounterRewardsPhase extends Phase { */ start() { super.start(); - const encounter = this.scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; if (encounter.doContinueEncounter) { - encounter.doContinueEncounter(this.scene).then(() => { + encounter.doContinueEncounter().then(() => { this.end(); }); } else { - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { if (encounter.onRewards) { - encounter.onRewards(this.scene).then(() => { + encounter.onRewards().then(() => { this.doEncounterRewardsAndContinue(); }); } else { this.doEncounterRewardsAndContinue(); } // Do not use ME's seedOffset for rewards, these should always be consistent with waveIndex (once per wave) - }, this.scene.currentBattle.waveIndex * 1000); + }, globalScene.currentBattle.waveIndex * 1000); } } @@ -524,20 +520,20 @@ export class MysteryEncounterRewardsPhase extends Phase { * Queues encounter EXP and rewards phases, {@linkcode PostMysteryEncounterPhase}, and ends phase */ doEncounterRewardsAndContinue() { - const encounter = this.scene.currentBattle.mysteryEncounter!; + const encounter = globalScene.currentBattle.mysteryEncounter!; if (encounter.doEncounterExp) { - encounter.doEncounterExp(this.scene); + encounter.doEncounterExp(); } if (encounter.doEncounterRewards) { - encounter.doEncounterRewards(this.scene); + encounter.doEncounterRewards(); } else if (this.addHealPhase) { - this.scene.tryRemovePhase(p => p instanceof SelectModifierPhase); - this.scene.unshiftPhase(new SelectModifierPhase(this.scene, 0, undefined, { fillRemaining: false, rerollMultiplier: -1 })); + globalScene.tryRemovePhase(p => p instanceof SelectModifierPhase); + globalScene.unshiftPhase(new SelectModifierPhase(0, undefined, { fillRemaining: false, rerollMultiplier: -1 })); } - this.scene.pushPhase(new PostMysteryEncounterPhase(this.scene)); + globalScene.pushPhase(new PostMysteryEncounterPhase()); this.end(); } } @@ -553,9 +549,9 @@ export class PostMysteryEncounterPhase extends Phase { private readonly FIRST_DIALOGUE_PROMPT_DELAY = 750; onPostOptionSelect?: OptionPhaseCallback; - constructor(scene: BattleScene) { - super(scene); - this.onPostOptionSelect = this.scene.currentBattle.mysteryEncounter?.selectedOption?.onPostOptionPhase; + constructor() { + super(); + this.onPostOptionSelect = globalScene.currentBattle.mysteryEncounter?.selectedOption?.onPostOptionPhase; } /** @@ -565,14 +561,14 @@ export class PostMysteryEncounterPhase extends Phase { super.start(); if (this.onPostOptionSelect) { - this.scene.executeWithSeedOffset(async () => { - return await this.onPostOptionSelect!(this.scene) + globalScene.executeWithSeedOffset(async () => { + return await this.onPostOptionSelect!() .then((result) => { if (isNullOrUndefined(result) || result) { this.continueEncounter(); } }); - }, this.scene.currentBattle.mysteryEncounter?.getSeedOffset() * 2000); + }, globalScene.currentBattle.mysteryEncounter?.getSeedOffset() * 2000); } else { this.continueEncounter(); } @@ -583,28 +579,28 @@ export class PostMysteryEncounterPhase extends Phase { */ continueEncounter() { const endPhase = () => { - this.scene.pushPhase(new NewBattlePhase(this.scene)); + globalScene.pushPhase(new NewBattlePhase()); this.end(); }; - const outroDialogue = this.scene.currentBattle?.mysteryEncounter?.dialogue?.outro; + const outroDialogue = globalScene.currentBattle?.mysteryEncounter?.dialogue?.outro; if (outroDialogue && outroDialogue.length > 0) { let i = 0; const showNextDialogue = () => { const nextAction = i === outroDialogue.length - 1 ? endPhase : showNextDialogue; const dialogue = outroDialogue[i]; let title: string | null = null; - const text: string | null = getEncounterText(this.scene, dialogue.text); + const text: string | null = getEncounterText(dialogue.text); if (dialogue.speaker) { - title = getEncounterText(this.scene, dialogue.speaker); + title = getEncounterText(dialogue.speaker); } i++; - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); if (title) { - this.scene.ui.showDialogue(text ?? "", title, null, nextAction, 0, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0); + globalScene.ui.showDialogue(text ?? "", title, null, nextAction, 0, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0); } else { - this.scene.ui.showText(text ?? "", null, nextAction, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0, true); + globalScene.ui.showText(text ?? "", null, nextAction, i === 1 ? this.FIRST_DIALOGUE_PROMPT_DELAY : 0, true); } }; diff --git a/src/phases/new-battle-phase.ts b/src/phases/new-battle-phase.ts index 5a422c9e6c74..8cdbdc5891aa 100644 --- a/src/phases/new-battle-phase.ts +++ b/src/phases/new-battle-phase.ts @@ -1,10 +1,11 @@ +import { globalScene } from "#app/global-scene"; import { BattlePhase } from "./battle-phase"; export class NewBattlePhase extends BattlePhase { start() { super.start(); - this.scene.newBattle(); + globalScene.newBattle(); this.end(); } diff --git a/src/phases/new-biome-encounter-phase.ts b/src/phases/new-biome-encounter-phase.ts index 910306b76ad5..be6815333e55 100644 --- a/src/phases/new-biome-encounter-phase.ts +++ b/src/phases/new-biome-encounter-phase.ts @@ -1,34 +1,34 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { applyAbAttrs, PostBiomeChangeAbAttr } from "#app/data/ability"; import { getRandomWeatherType } from "#app/data/weather"; import { NextEncounterPhase } from "./next-encounter-phase"; export class NewBiomeEncounterPhase extends NextEncounterPhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } doEncounter(): void { - this.scene.playBgm(undefined, true); + globalScene.playBgm(undefined, true); - for (const pokemon of this.scene.getPlayerParty()) { + for (const pokemon of globalScene.getPlayerParty()) { if (pokemon) { pokemon.resetBattleData(); } } - for (const pokemon of this.scene.getPlayerParty().filter(p => p.isOnField())) { + for (const pokemon of globalScene.getPlayerParty().filter(p => p.isOnField())) { applyAbAttrs(PostBiomeChangeAbAttr, pokemon, null); } - const enemyField = this.scene.getEnemyField(); - const moveTargets: any[] = [ this.scene.arenaEnemy, enemyField ]; - const mysteryEncounter = this.scene.currentBattle?.mysteryEncounter?.introVisuals; + const enemyField = globalScene.getEnemyField(); + const moveTargets: any[] = [ globalScene.arenaEnemy, enemyField ]; + const mysteryEncounter = globalScene.currentBattle?.mysteryEncounter?.introVisuals; if (mysteryEncounter) { moveTargets.push(mysteryEncounter); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: moveTargets.flat(), x: "+=300", duration: 2000, @@ -44,6 +44,6 @@ export class NewBiomeEncounterPhase extends NextEncounterPhase { * Set biome weather. */ trySetWeatherIfNewBiome(): void { - this.scene.arena.trySetWeather(getRandomWeatherType(this.scene.arena), false); + globalScene.arena.trySetWeather(getRandomWeatherType(globalScene.arena), false); } } diff --git a/src/phases/next-encounter-phase.ts b/src/phases/next-encounter-phase.ts index e086ed4fe3e9..229d37f9a697 100644 --- a/src/phases/next-encounter-phase.ts +++ b/src/phases/next-encounter-phase.ts @@ -1,9 +1,9 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { EncounterPhase } from "./encounter-phase"; export class NextEncounterPhase extends EncounterPhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { @@ -11,29 +11,29 @@ export class NextEncounterPhase extends EncounterPhase { } doEncounter(): void { - this.scene.playBgm(undefined, true); + globalScene.playBgm(undefined, true); - for (const pokemon of this.scene.getPlayerParty()) { + for (const pokemon of globalScene.getPlayerParty()) { if (pokemon) { pokemon.resetBattleData(); } } - this.scene.arenaNextEnemy.setBiome(this.scene.arena.biomeType); - this.scene.arenaNextEnemy.setVisible(true); + globalScene.arenaNextEnemy.setBiome(globalScene.arena.biomeType); + globalScene.arenaNextEnemy.setVisible(true); - const enemyField = this.scene.getEnemyField(); - const moveTargets: any[] = [ this.scene.arenaEnemy, this.scene.arenaNextEnemy, this.scene.currentBattle.trainer, enemyField, this.scene.lastEnemyTrainer ]; - const lastEncounterVisuals = this.scene.lastMysteryEncounter?.introVisuals; + const enemyField = globalScene.getEnemyField(); + const moveTargets: any[] = [ globalScene.arenaEnemy, globalScene.arenaNextEnemy, globalScene.currentBattle.trainer, enemyField, globalScene.lastEnemyTrainer ]; + const lastEncounterVisuals = globalScene.lastMysteryEncounter?.introVisuals; if (lastEncounterVisuals) { moveTargets.push(lastEncounterVisuals); } - const nextEncounterVisuals = this.scene.currentBattle.mysteryEncounter?.introVisuals; + const nextEncounterVisuals = globalScene.currentBattle.mysteryEncounter?.introVisuals; if (nextEncounterVisuals) { const enterFromRight = nextEncounterVisuals.enterFromRight; if (enterFromRight) { nextEncounterVisuals.x += 500; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: nextEncounterVisuals, x: "-=200", duration: 2000 @@ -43,22 +43,22 @@ export class NextEncounterPhase extends EncounterPhase { } } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: moveTargets.flat(), x: "+=300", duration: 2000, onComplete: () => { - this.scene.arenaEnemy.setBiome(this.scene.arena.biomeType); - this.scene.arenaEnemy.setX(this.scene.arenaNextEnemy.x); - this.scene.arenaEnemy.setAlpha(1); - this.scene.arenaNextEnemy.setX(this.scene.arenaNextEnemy.x - 300); - this.scene.arenaNextEnemy.setVisible(false); - if (this.scene.lastEnemyTrainer) { - this.scene.lastEnemyTrainer.destroy(); + globalScene.arenaEnemy.setBiome(globalScene.arena.biomeType); + globalScene.arenaEnemy.setX(globalScene.arenaNextEnemy.x); + globalScene.arenaEnemy.setAlpha(1); + globalScene.arenaNextEnemy.setX(globalScene.arenaNextEnemy.x - 300); + globalScene.arenaNextEnemy.setVisible(false); + if (globalScene.lastEnemyTrainer) { + globalScene.lastEnemyTrainer.destroy(); } if (lastEncounterVisuals) { - this.scene.field.remove(lastEncounterVisuals, true); - this.scene.lastMysteryEncounter!.introVisuals = undefined; + globalScene.field.remove(lastEncounterVisuals, true); + globalScene.lastMysteryEncounter!.introVisuals = undefined; } if (!this.tryOverrideForBattleSpec()) { diff --git a/src/phases/obtain-status-effect-phase.ts b/src/phases/obtain-status-effect-phase.ts index 01384b932cbc..d6d00f851f7c 100644 --- a/src/phases/obtain-status-effect-phase.ts +++ b/src/phases/obtain-status-effect-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { CommonBattleAnim, CommonAnim } from "#app/data/battle-anims"; import { getStatusEffectObtainText, getStatusEffectOverlapText } from "#app/data/status-effect"; @@ -13,8 +13,8 @@ export class ObtainStatusEffectPhase extends PokemonPhase { private sourceText?: string | null; private sourcePokemon?: Pokemon | null; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, statusEffect?: StatusEffect, turnsRemaining?: number, sourceText?: string | null, sourcePokemon?: Pokemon | null) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, statusEffect?: StatusEffect, turnsRemaining?: number, sourceText?: string | null, sourcePokemon?: Pokemon | null) { + super(battlerIndex); this.statusEffect = statusEffect; this.turnsRemaining = turnsRemaining; @@ -30,14 +30,14 @@ export class ObtainStatusEffectPhase extends PokemonPhase { pokemon.status!.sleepTurnsRemaining = this.turnsRemaining; } pokemon.updateInfo(true); - new CommonBattleAnim(CommonAnim.POISON + (this.statusEffect! - 1), pokemon).play(this.scene, false, () => { - this.scene.queueMessage(getStatusEffectObtainText(this.statusEffect, getPokemonNameWithAffix(pokemon), this.sourceText ?? undefined)); + new CommonBattleAnim(CommonAnim.POISON + (this.statusEffect! - 1), pokemon).play(false, () => { + globalScene.queueMessage(getStatusEffectObtainText(this.statusEffect, getPokemonNameWithAffix(pokemon), this.sourceText ?? undefined)); this.end(); }); return; } } else if (pokemon.status?.effect === this.statusEffect) { - this.scene.queueMessage(getStatusEffectOverlapText(this.statusEffect ?? StatusEffect.NONE, getPokemonNameWithAffix(pokemon))); + globalScene.queueMessage(getStatusEffectOverlapText(this.statusEffect ?? StatusEffect.NONE, getPokemonNameWithAffix(pokemon))); } this.end(); } diff --git a/src/phases/party-exp-phase.ts b/src/phases/party-exp-phase.ts index c5a254871cae..8fd9e1cf0f68 100644 --- a/src/phases/party-exp-phase.ts +++ b/src/phases/party-exp-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; /** @@ -10,8 +10,8 @@ export class PartyExpPhase extends Phase { useWaveIndexMultiplier?: boolean; pokemonParticipantIds?: Set; - constructor(scene: BattleScene, expValue: number, useWaveIndexMultiplier?: boolean, pokemonParticipantIds?: Set) { - super(scene); + constructor(expValue: number, useWaveIndexMultiplier?: boolean, pokemonParticipantIds?: Set) { + super(); this.expValue = expValue; this.useWaveIndexMultiplier = useWaveIndexMultiplier; @@ -24,7 +24,7 @@ export class PartyExpPhase extends Phase { start() { super.start(); - this.scene.applyPartyExp(this.expValue, false, this.useWaveIndexMultiplier, this.pokemonParticipantIds); + globalScene.applyPartyExp(this.expValue, false, this.useWaveIndexMultiplier, this.pokemonParticipantIds); this.end(); } diff --git a/src/phases/party-heal-phase.ts b/src/phases/party-heal-phase.ts index 4841bf9a5b44..2c1a6c33163a 100644 --- a/src/phases/party-heal-phase.ts +++ b/src/phases/party-heal-phase.ts @@ -1,12 +1,12 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "#app/utils"; import { BattlePhase } from "./battle-phase"; export class PartyHealPhase extends BattlePhase { private resumeBgm: boolean; - constructor(scene: BattleScene, resumeBgm: boolean) { - super(scene); + constructor(resumeBgm: boolean) { + super(); this.resumeBgm = resumeBgm; } @@ -14,12 +14,12 @@ export class PartyHealPhase extends BattlePhase { start() { super.start(); - const bgmPlaying = this.scene.isBgmPlaying(); + const bgmPlaying = globalScene.isBgmPlaying(); if (bgmPlaying) { - this.scene.fadeOutBgm(1000, false); + globalScene.fadeOutBgm(1000, false); } - this.scene.ui.fadeOut(1000).then(() => { - for (const pokemon of this.scene.getPlayerParty()) { + globalScene.ui.fadeOut(1000).then(() => { + for (const pokemon of globalScene.getPlayerParty()) { pokemon.hp = pokemon.getMaxHp(); pokemon.resetStatus(); for (const move of pokemon.moveset) { @@ -27,13 +27,13 @@ export class PartyHealPhase extends BattlePhase { } pokemon.updateInfo(true); } - const healSong = this.scene.playSoundWithoutBgm("heal"); - this.scene.time.delayedCall(Utils.fixedInt(healSong.totalDuration * 1000), () => { + const healSong = globalScene.playSoundWithoutBgm("heal"); + globalScene.time.delayedCall(Utils.fixedInt(healSong.totalDuration * 1000), () => { healSong.destroy(); if (this.resumeBgm && bgmPlaying) { - this.scene.playBgm(); + globalScene.playBgm(); } - this.scene.ui.fadeIn(500).then(() => this.end()); + globalScene.ui.fadeIn(500).then(() => this.end()); }); }); } diff --git a/src/phases/party-member-pokemon-phase.ts b/src/phases/party-member-pokemon-phase.ts index f2e2b23bfb26..71ddb1612547 100644 --- a/src/phases/party-member-pokemon-phase.ts +++ b/src/phases/party-member-pokemon-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import Pokemon from "#app/field/pokemon"; import { FieldPhase } from "./field-phase"; @@ -7,18 +7,18 @@ export abstract class PartyMemberPokemonPhase extends FieldPhase { protected fieldIndex: integer; protected player: boolean; - constructor(scene: BattleScene, partyMemberIndex: integer, player: boolean) { - super(scene); + constructor(partyMemberIndex: integer, player: boolean) { + super(); this.partyMemberIndex = partyMemberIndex; - this.fieldIndex = partyMemberIndex < this.scene.currentBattle.getBattlerCount() + this.fieldIndex = partyMemberIndex < globalScene.currentBattle.getBattlerCount() ? partyMemberIndex : -1; this.player = player; } getParty(): Pokemon[] { - return this.player ? this.scene.getPlayerParty() : this.scene.getEnemyParty(); + return this.player ? globalScene.getPlayerParty() : globalScene.getEnemyParty(); } getPokemon(): Pokemon { diff --git a/src/phases/player-party-member-pokemon-phase.ts b/src/phases/player-party-member-pokemon-phase.ts index 87855b9334c1..d9f059910aa8 100644 --- a/src/phases/player-party-member-pokemon-phase.ts +++ b/src/phases/player-party-member-pokemon-phase.ts @@ -1,10 +1,9 @@ -import BattleScene from "#app/battle-scene"; import { PlayerPokemon } from "#app/field/pokemon"; import { PartyMemberPokemonPhase } from "./party-member-pokemon-phase"; export abstract class PlayerPartyMemberPokemonPhase extends PartyMemberPokemonPhase { - constructor(scene: BattleScene, partyMemberIndex: integer) { - super(scene, partyMemberIndex, true); + constructor(partyMemberIndex: integer) { + super(partyMemberIndex, true); } getPlayerPokemon(): PlayerPokemon { diff --git a/src/phases/pokemon-anim-phase.ts b/src/phases/pokemon-anim-phase.ts index eb5431cbc56b..1589d3bc8cf7 100644 --- a/src/phases/pokemon-anim-phase.ts +++ b/src/phases/pokemon-anim-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { SubstituteTag } from "#app/data/battler-tags"; import Pokemon from "#app/field/pokemon"; import { BattlePhase } from "#app/phases/battle-phase"; @@ -15,8 +15,8 @@ export class PokemonAnimPhase extends BattlePhase { /** Any other field sprites affected by this animation */ private fieldAssets: Phaser.GameObjects.Sprite[]; - constructor(scene: BattleScene, key: PokemonAnimType, pokemon: Pokemon, fieldAssets?: Phaser.GameObjects.Sprite[]) { - super(scene); + constructor(key: PokemonAnimType, pokemon: Pokemon, fieldAssets?: Phaser.GameObjects.Sprite[]) { + super(); this.key = key; this.pokemon = pokemon; @@ -57,13 +57,13 @@ export class PokemonAnimPhase extends BattlePhase { } const getSprite = () => { - const sprite = this.scene.addFieldSprite( + const sprite = globalScene.addFieldSprite( this.pokemon.x + this.pokemon.getSprite().x, this.pokemon.y + this.pokemon.getSprite().y, `pkmn${this.pokemon.isPlayer() ? "__back" : ""}__sub` ); sprite.setOrigin(0.5, 1); - this.scene.field.add(sprite); + globalScene.field.add(sprite); return sprite; }; @@ -76,12 +76,12 @@ export class PokemonAnimPhase extends BattlePhase { subTintSprite.setScale(0.01); if (this.pokemon.isPlayer()) { - this.scene.field.bringToTop(this.pokemon); + globalScene.field.bringToTop(this.pokemon); } - this.scene.playSound("PRSFX- Transform"); + globalScene.playSound("PRSFX- Transform"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemon, duration: 500, x: this.pokemon.x + this.pokemon.getSubstituteOffset()[0], @@ -90,7 +90,7 @@ export class PokemonAnimPhase extends BattlePhase { ease: "Sine.easeIn" }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: subTintSprite, delay: 250, scale: subScale, @@ -98,7 +98,7 @@ export class PokemonAnimPhase extends BattlePhase { duration: 500, onComplete: () => { subSprite.setVisible(true); - this.pokemon.scene.tweens.add({ + globalScene.tweens.add({ targets: subTintSprite, delay: 250, alpha: 0, @@ -124,14 +124,14 @@ export class PokemonAnimPhase extends BattlePhase { return this.end(); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: subSprite, alpha: 0, ease: "Sine.easeInOut", duration: 500 }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemon, x: subSprite.x, y: subSprite.y, @@ -153,7 +153,7 @@ export class PokemonAnimPhase extends BattlePhase { return this.end(); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemon, x: subSprite.x + this.pokemon.getSubstituteOffset()[0], y: subSprite.y + this.pokemon.getSubstituteOffset()[1], @@ -162,7 +162,7 @@ export class PokemonAnimPhase extends BattlePhase { duration: 500 }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: subSprite, alpha: 1, ease: "Sine.easeInOut", @@ -183,13 +183,13 @@ export class PokemonAnimPhase extends BattlePhase { } const getSprite = () => { - const sprite = this.scene.addFieldSprite( + const sprite = globalScene.addFieldSprite( subSprite.x, subSprite.y, `pkmn${this.pokemon.isPlayer() ? "__back" : ""}__sub` ); sprite.setOrigin(0.5, 1); - this.scene.field.add(sprite); + globalScene.field.add(sprite); return sprite; }; @@ -199,30 +199,30 @@ export class PokemonAnimPhase extends BattlePhase { subTintSprite.setTintFill(0xFFFFFF); subTintSprite.setScale(subScale); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: subTintSprite, alpha: 1, ease: "Sine.easeInOut", duration: 500, onComplete: () => { subSprite.destroy(); - const flashTimer = this.scene.time.addEvent({ + const flashTimer = globalScene.time.addEvent({ delay: 100, repeat: 7, startAt: 200, callback: () => { - this.scene.playSound("PRSFX- Substitute2.wav"); + globalScene.playSound("PRSFX- Substitute2.wav"); subTintSprite.setVisible(flashTimer.repeatCount % 2 === 0); if (!flashTimer.repeatCount) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: subTintSprite, scale: 0.01, ease: "Sine.cubicEaseIn", duration: 500 }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemon, x: this.pokemon.x - this.pokemon.getSubstituteOffset()[0], y: this.pokemon.y - this.pokemon.getSubstituteOffset()[1], @@ -243,7 +243,7 @@ export class PokemonAnimPhase extends BattlePhase { } private doCommanderApplyAnim(): void { - if (!this.scene.currentBattle?.double) { + if (!globalScene.currentBattle?.double) { return this.end(); } const dondozo = this.pokemon.getAlly(); @@ -256,7 +256,7 @@ export class PokemonAnimPhase extends BattlePhase { const tatsugiriY = this.pokemon.y + this.pokemon.getSprite().y; const getSourceSprite = () => { - const sprite = this.scene.addPokemonSprite(this.pokemon, tatsugiriX, tatsugiriY, this.pokemon.getSprite().texture, this.pokemon.getSprite()!.frame.name, true); + const sprite = globalScene.addPokemonSprite(this.pokemon, tatsugiriX, tatsugiriY, this.pokemon.getSprite().texture, this.pokemon.getSprite()!.frame.name, true); [ "spriteColors", "fusionSpriteColors" ].map(k => sprite.pipelineData[k] = this.pokemon.getSprite().pipelineData[k]); sprite.setPipelineData("spriteKey", this.pokemon.getBattleSpriteKey()); sprite.setPipelineData("shiny", this.pokemon.shiny); @@ -264,7 +264,7 @@ export class PokemonAnimPhase extends BattlePhase { sprite.setPipelineData("ignoreFieldPos", true); sprite.setOrigin(0.5, 1); this.pokemon.getSprite().on("animationupdate", (_anim, frame) => sprite.setFrame(frame.textureFrame)); - this.scene.field.add(sprite); + globalScene.field.add(sprite); return sprite; }; @@ -275,17 +275,17 @@ export class PokemonAnimPhase extends BattlePhase { const sourceFpOffset = this.pokemon.getFieldPositionOffset(); const dondozoFpOffset = dondozo.getFieldPositionOffset(); - this.scene.playSound("se/pb_throw"); + globalScene.playSound("se/pb_throw"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: sourceSprite, duration: 375, scale: 0.5, x: { value: tatsugiriX + (dondozoFpOffset[0] - sourceFpOffset[0]) / 2, ease: "Linear" }, y: { value: (this.pokemon.isPlayer() ? 100 : 65) + sourceFpOffset[1], ease: "Sine.easeOut" }, onComplete: () => { - this.scene.field.bringToTop(dondozo); - this.scene.tweens.add({ + globalScene.field.bringToTop(dondozo); + globalScene.tweens.add({ targets: sourceSprite, duration: 375, scale: 0.01, @@ -293,8 +293,8 @@ export class PokemonAnimPhase extends BattlePhase { y: { value: dondozo.y + dondozo.height / 2, ease: "Sine.easeIn" }, onComplete: () => { sourceSprite.destroy(); - this.scene.playSound("battle_anims/PRSFX- Liquidation1.wav"); - this.scene.tweens.add({ + globalScene.playSound("battle_anims/PRSFX- Liquidation1.wav"); + globalScene.tweens.add({ targets: dondozo, duration: 250, ease: "Sine.easeInOut", @@ -317,7 +317,7 @@ export class PokemonAnimPhase extends BattlePhase { return this.end(); } - const tatsuSprite = this.scene.addPokemonSprite( + const tatsuSprite = globalScene.addPokemonSprite( tatsugiri, this.pokemon.x + this.pokemon.getSprite().x, this.pokemon.y + this.pokemon.getSprite().y + this.pokemon.height / 2, @@ -335,19 +335,19 @@ export class PokemonAnimPhase extends BattlePhase { tatsuSprite.setOrigin(0.5, 1); tatsuSprite.setScale(0.01); - this.scene.field.add(tatsuSprite); - this.scene.field.bringToTop(this.pokemon); + globalScene.field.add(tatsuSprite); + globalScene.field.bringToTop(this.pokemon); tatsuSprite.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemon, duration: 250, ease: "Sine.easeInOut", scale: 1.15, yoyo: true, onComplete: () => { - this.scene.playSound("battle_anims/PRSFX- Liquidation4.wav"); - this.scene.tweens.add({ + globalScene.playSound("battle_anims/PRSFX- Liquidation4.wav"); + globalScene.tweens.add({ targets: tatsuSprite, duration: 500, scale: 1, diff --git a/src/phases/pokemon-heal-phase.ts b/src/phases/pokemon-heal-phase.ts index c95b92e3b64a..a410959e7bfc 100644 --- a/src/phases/pokemon-heal-phase.ts +++ b/src/phases/pokemon-heal-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { CommonAnim } from "#app/data/battle-anims"; import { getStatusEffectHealText } from "#app/data/status-effect"; @@ -23,8 +23,8 @@ export class PokemonHealPhase extends CommonAnimPhase { private preventFullHeal: boolean; private fullRestorePP: boolean; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, hpHealed: integer, message: string | null, showFullHpMessage: boolean, skipAnim: boolean = false, revive: boolean = false, healStatus: boolean = false, preventFullHeal: boolean = false, fullRestorePP: boolean = false) { - super(scene, battlerIndex, undefined, CommonAnim.HEALTH_UP); + constructor(battlerIndex: BattlerIndex, hpHealed: integer, message: string | null, showFullHpMessage: boolean, skipAnim: boolean = false, revive: boolean = false, healStatus: boolean = false, preventFullHeal: boolean = false, fullRestorePP: boolean = false) { + super(battlerIndex, undefined, CommonAnim.HEALTH_UP); this.hpHealed = hpHealed; this.message = message; @@ -57,13 +57,13 @@ export class PokemonHealPhase extends CommonAnimPhase { let lastStatusEffect = StatusEffect.NONE; if (healBlock && this.hpHealed > 0) { - this.scene.queueMessage(healBlock.onActivation(pokemon)); + globalScene.queueMessage(healBlock.onActivation(pokemon)); this.message = null; return super.end(); } else if (healOrDamage) { const hpRestoreMultiplier = new Utils.IntegerHolder(1); if (!this.revive) { - this.scene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier); + globalScene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier); } const healAmount = new Utils.NumberHolder(Math.floor(this.hpHealed * hpRestoreMultiplier.value)); if (healAmount.value < 0) { @@ -76,12 +76,12 @@ export class PokemonHealPhase extends CommonAnimPhase { } healAmount.value = pokemon.heal(healAmount.value); if (healAmount.value) { - this.scene.damageNumberHandler.add(pokemon, healAmount.value, HitResult.HEAL); + globalScene.damageNumberHandler.add(pokemon, healAmount.value, HitResult.HEAL); } if (pokemon.isPlayer()) { - this.scene.validateAchvs(HealAchv, healAmount); - if (healAmount.value > this.scene.gameData.gameStats.highestHeal) { - this.scene.gameData.gameStats.highestHeal = healAmount.value; + globalScene.validateAchvs(HealAchv, healAmount); + if (healAmount.value > globalScene.gameData.gameStats.highestHeal) { + globalScene.gameData.gameStats.highestHeal = healAmount.value; } } if (this.healStatus && !this.revive && pokemon.status) { @@ -105,11 +105,11 @@ export class PokemonHealPhase extends CommonAnimPhase { } if (this.message) { - this.scene.queueMessage(this.message); + globalScene.queueMessage(this.message); } if (this.healStatus && lastStatusEffect && !hasMessage) { - this.scene.queueMessage(getStatusEffectHealText(lastStatusEffect, getPokemonNameWithAffix(pokemon))); + globalScene.queueMessage(getStatusEffectHealText(lastStatusEffect, getPokemonNameWithAffix(pokemon))); } if (!healOrDamage && !lastStatusEffect) { diff --git a/src/phases/pokemon-phase.ts b/src/phases/pokemon-phase.ts index b980c1d17190..204282426673 100644 --- a/src/phases/pokemon-phase.ts +++ b/src/phases/pokemon-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import Pokemon from "#app/field/pokemon"; import { FieldPhase } from "./field-phase"; @@ -8,11 +8,11 @@ export abstract class PokemonPhase extends FieldPhase { public player: boolean; public fieldIndex: integer; - constructor(scene: BattleScene, battlerIndex?: BattlerIndex | integer) { - super(scene); + constructor(battlerIndex?: BattlerIndex | integer) { + super(); if (battlerIndex === undefined) { - battlerIndex = scene.getField().find(p => p?.isActive())!.getBattlerIndex(); // TODO: is the bang correct here? + battlerIndex = globalScene.getField().find(p => p?.isActive())!.getBattlerIndex(); // TODO: is the bang correct here? } this.battlerIndex = battlerIndex; @@ -22,8 +22,8 @@ export abstract class PokemonPhase extends FieldPhase { getPokemon(): Pokemon { if (this.battlerIndex > BattlerIndex.ENEMY_2) { - return this.scene.getPokemonById(this.battlerIndex)!; //TODO: is this bang correct? + return globalScene.getPokemonById(this.battlerIndex)!; //TODO: is this bang correct? } - return this.scene.getField()[this.battlerIndex]!; //TODO: is this bang correct? + return globalScene.getField()[this.battlerIndex]!; //TODO: is this bang correct? } } diff --git a/src/phases/post-game-over-phase.ts b/src/phases/post-game-over-phase.ts index beeb30c72602..36d3eb4ecebe 100644 --- a/src/phases/post-game-over-phase.ts +++ b/src/phases/post-game-over-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { EndCardPhase } from "./end-card-phase"; import { TitlePhase } from "./title-phase"; @@ -6,8 +6,8 @@ import { TitlePhase } from "./title-phase"; export class PostGameOverPhase extends Phase { private endCardPhase: EndCardPhase | null; - constructor(scene: BattleScene, endCardPhase?: EndCardPhase) { - super(scene); + constructor(endCardPhase?: EndCardPhase) { + super(); this.endCardPhase = endCardPhase!; // TODO: is this bang correct? } @@ -16,24 +16,24 @@ export class PostGameOverPhase extends Phase { super.start(); const saveAndReset = () => { - this.scene.gameData.saveAll(this.scene, true, true, true).then(success => { + globalScene.gameData.saveAll(true, true, true).then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } - this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => { + globalScene.gameData.tryClearSession(globalScene.sessionSlotId).then((success: boolean | [boolean, boolean]) => { if (!success[0]) { - return this.scene.reset(true); + return globalScene.reset(true); } - this.scene.reset(); - this.scene.unshiftPhase(new TitlePhase(this.scene)); + globalScene.reset(); + globalScene.unshiftPhase(new TitlePhase()); this.end(); }); }); }; if (this.endCardPhase) { - this.scene.ui.fadeOut(500).then(() => { - this.scene.ui.getMessageHandler().bg.setVisible(true); + globalScene.ui.fadeOut(500).then(() => { + globalScene.ui.getMessageHandler().bg.setVisible(true); this.endCardPhase?.endCard.destroy(); this.endCardPhase?.text.destroy(); diff --git a/src/phases/post-summon-phase.ts b/src/phases/post-summon-phase.ts index 42e5b930eb13..bec211cccb19 100644 --- a/src/phases/post-summon-phase.ts +++ b/src/phases/post-summon-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { applyAbAttrs, applyPostSummonAbAttrs, CommanderAbAttr, PostSummonAbAttr } from "#app/data/ability"; import { ArenaTrapTag } from "#app/data/arena-tag"; @@ -8,8 +8,8 @@ import { MysteryEncounterPostSummonTag } from "#app/data/battler-tags"; import { BattlerTagType } from "#enums/battler-tag-type"; export class PostSummonPhase extends PokemonPhase { - constructor(scene: BattleScene, battlerIndex: BattlerIndex) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex) { + super(battlerIndex); } start() { @@ -20,16 +20,16 @@ export class PostSummonPhase extends PokemonPhase { if (pokemon.status?.effect === StatusEffect.TOXIC) { pokemon.status.toxicTurnCount = 0; } - this.scene.arena.applyTags(ArenaTrapTag, false, pokemon); + globalScene.arena.applyTags(ArenaTrapTag, false, pokemon); // If this is mystery encounter and has post summon phase tag, apply post summon effects - if (this.scene.currentBattle.isBattleMysteryEncounter() && pokemon.findTags(t => t instanceof MysteryEncounterPostSummonTag).length > 0) { + if (globalScene.currentBattle.isBattleMysteryEncounter() && pokemon.findTags(t => t instanceof MysteryEncounterPostSummonTag).length > 0) { pokemon.lapseTag(BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON); } applyPostSummonAbAttrs(PostSummonAbAttr, pokemon) .then(() => { - const field = pokemon.isPlayer() ? this.scene.getPlayerField() : this.scene.getEnemyField(); + const field = pokemon.isPlayer() ? globalScene.getPlayerField() : globalScene.getEnemyField(); field.forEach((p) => applyAbAttrs(CommanderAbAttr, p, null, false)); this.end(); diff --git a/src/phases/post-turn-status-effect-phase.ts b/src/phases/post-turn-status-effect-phase.ts index 378a932cdc55..e891bf4ae09a 100644 --- a/src/phases/post-turn-status-effect-phase.ts +++ b/src/phases/post-turn-status-effect-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { applyAbAttrs, applyPostDamageAbAttrs, BlockNonDirectDamageAbAttr, BlockStatusDamageAbAttr, PostDamageAbAttr, ReduceBurnDamageAbAttr } from "#app/data/ability"; import { CommonBattleAnim, CommonAnim } from "#app/data/battle-anims"; @@ -10,8 +10,8 @@ import * as Utils from "#app/utils"; import { PokemonPhase } from "./pokemon-phase"; export class PostTurnStatusEffectPhase extends PokemonPhase { - constructor(scene: BattleScene, battlerIndex: BattlerIndex) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex) { + super(battlerIndex); } start() { @@ -23,7 +23,7 @@ export class PostTurnStatusEffectPhase extends PokemonPhase { applyAbAttrs(BlockStatusDamageAbAttr, pokemon, cancelled); if (!cancelled.value) { - this.scene.queueMessage(getStatusEffectActivationText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); + globalScene.queueMessage(getStatusEffectActivationText(pokemon.status.effect, getPokemonNameWithAffix(pokemon))); const damage = new Utils.NumberHolder(0); switch (pokemon.status.effect) { case StatusEffect.POISON: @@ -39,11 +39,11 @@ export class PostTurnStatusEffectPhase extends PokemonPhase { } if (damage.value) { // Set preventEndure flag to avoid pokemon surviving thanks to focus band, sturdy, endure ... - this.scene.damageNumberHandler.add(this.getPokemon(), pokemon.damage(damage.value, false, true)); + globalScene.damageNumberHandler.add(this.getPokemon(), pokemon.damage(damage.value, false, true)); pokemon.updateInfo(); applyPostDamageAbAttrs(PostDamageAbAttr, pokemon, damage.value, pokemon.hasPassive(), false, []); } - new CommonBattleAnim(CommonAnim.POISON + (pokemon.status.effect - 1), pokemon).play(this.scene, false, () => this.end()); + new CommonBattleAnim(CommonAnim.POISON + (pokemon.status.effect - 1), pokemon).play(false, () => this.end()); } else { this.end(); } @@ -53,8 +53,8 @@ export class PostTurnStatusEffectPhase extends PokemonPhase { } override end() { - if (this.scene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { - this.scene.initFinalBossPhaseTwo(this.getPokemon()); + if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) { + globalScene.initFinalBossPhaseTwo(this.getPokemon()); } else { super.end(); } diff --git a/src/phases/quiet-form-change-phase.ts b/src/phases/quiet-form-change-phase.ts index c9e5bec845df..e371dc5b4e8b 100644 --- a/src/phases/quiet-form-change-phase.ts +++ b/src/phases/quiet-form-change-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { SemiInvulnerableTag } from "#app/data/battler-tags"; import { SpeciesFormChange, getSpeciesFormChangeMessage } from "#app/data/pokemon-forms"; import { getTypeRgb } from "#app/data/type"; @@ -14,8 +14,8 @@ export class QuietFormChangePhase extends BattlePhase { protected pokemon: Pokemon; protected formChange: SpeciesFormChange; - constructor(scene: BattleScene, pokemon: Pokemon, formChange: SpeciesFormChange) { - super(scene); + constructor(pokemon: Pokemon, formChange: SpeciesFormChange) { + super(); this.pokemon = pokemon; this.formChange = formChange; } @@ -32,7 +32,7 @@ export class QuietFormChangePhase extends BattlePhase { if (!this.pokemon.isOnField() || this.pokemon.getTag(SemiInvulnerableTag) || this.pokemon.isFainted()) { if (this.pokemon.isPlayer() || this.pokemon.isActive()) { this.pokemon.changeForm(this.formChange).then(() => { - this.scene.ui.showText(getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName), null, () => this.end(), 1500); + globalScene.ui.showText(getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName), null, () => this.end(), 1500); }); } else { this.end(); @@ -41,7 +41,7 @@ export class QuietFormChangePhase extends BattlePhase { } const getPokemonSprite = () => { - const sprite = this.scene.addPokemonSprite(this.pokemon, this.pokemon.x + this.pokemon.getSprite().x, this.pokemon.y + this.pokemon.getSprite().y, "pkmn__sub"); + const sprite = globalScene.addPokemonSprite(this.pokemon, this.pokemon.x + this.pokemon.getSprite().x, this.pokemon.y + this.pokemon.getSprite().y, "pkmn__sub"); sprite.setOrigin(0.5, 1); const spriteKey = this.pokemon.getBattleSpriteKey(); try { @@ -49,14 +49,14 @@ export class QuietFormChangePhase extends BattlePhase { } catch (err: unknown) { console.error(`Failed to play animation for ${spriteKey}`, err); } - sprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(this.pokemon.getTeraType()) }); + sprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(this.pokemon.getTeraType()) }); [ "spriteColors", "fusionSpriteColors" ].map(k => { if (this.pokemon.summonData?.speciesForm) { k += "Base"; } sprite.pipelineData[k] = this.pokemon.getSprite().pipelineData[k]; }); - this.scene.field.add(sprite); + globalScene.field.add(sprite); return sprite; }; @@ -75,9 +75,9 @@ export class QuietFormChangePhase extends BattlePhase { pokemonFormTintSprite.setVisible(false); pokemonFormTintSprite.setTintFill(0xFFFFFF); - this.scene.playSound("battle_anims/PRSFX- Transform"); + globalScene.playSound("battle_anims/PRSFX- Transform"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonTintSprite, alpha: 1, duration: 1000, @@ -93,7 +93,7 @@ export class QuietFormChangePhase extends BattlePhase { console.error(`Failed to play animation for ${spriteKey}`, err); } pokemonFormTintSprite.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonTintSprite, delay: 250, scale: 0.01, @@ -101,7 +101,7 @@ export class QuietFormChangePhase extends BattlePhase { duration: 500, onComplete: () => pokemonTintSprite.destroy() }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonFormTintSprite, delay: 250, scale: this.pokemon.getSpriteScale(), @@ -109,7 +109,7 @@ export class QuietFormChangePhase extends BattlePhase { duration: 500, onComplete: () => { this.pokemon.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokemonFormTintSprite, delay: 250, alpha: 0, @@ -117,7 +117,7 @@ export class QuietFormChangePhase extends BattlePhase { duration: 1000, onComplete: () => { pokemonTintSprite.setVisible(false); - this.scene.ui.showText(getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName), null, () => this.end(), 1500); + globalScene.ui.showText(getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName), null, () => this.end(), 1500); } }); } @@ -129,16 +129,16 @@ export class QuietFormChangePhase extends BattlePhase { end(): void { this.pokemon.findAndRemoveTags(t => t.tagType === BattlerTagType.AUTOTOMIZED); - if (this.pokemon.scene?.currentBattle.battleSpec === BattleSpec.FINAL_BOSS && this.pokemon instanceof EnemyPokemon) { - this.scene.playBgm(); - this.scene.unshiftPhase(new PokemonHealPhase(this.scene, this.pokemon.getBattlerIndex(), this.pokemon.getMaxHp(), null, false, false, false, true)); + if (globalScene?.currentBattle.battleSpec === BattleSpec.FINAL_BOSS && this.pokemon instanceof EnemyPokemon) { + globalScene.playBgm(); + globalScene.unshiftPhase(new PokemonHealPhase(this.pokemon.getBattlerIndex(), this.pokemon.getMaxHp(), null, false, false, false, true)); this.pokemon.findAndRemoveTags(() => true); this.pokemon.bossSegments = 5; this.pokemon.bossSegmentIndex = 4; this.pokemon.initBattleInfo(); this.pokemon.cry(); - const movePhase = this.scene.findPhase(p => p instanceof MovePhase && p.pokemon === this.pokemon) as MovePhase; + const movePhase = globalScene.findPhase(p => p instanceof MovePhase && p.pokemon === this.pokemon) as MovePhase; if (movePhase) { movePhase.cancel(); } diff --git a/src/phases/reload-session-phase.ts b/src/phases/reload-session-phase.ts index f8a38105869c..a88cb1b1de34 100644 --- a/src/phases/reload-session-phase.ts +++ b/src/phases/reload-session-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { Mode } from "#app/ui/ui"; import * as Utils from "#app/utils"; @@ -6,19 +6,19 @@ import * as Utils from "#app/utils"; export class ReloadSessionPhase extends Phase { private systemDataStr: string | null; - constructor(scene: BattleScene, systemDataStr?: string) { - super(scene); + constructor(systemDataStr?: string) { + super(); this.systemDataStr = systemDataStr ?? null; } start(): void { - this.scene.ui.setMode(Mode.SESSION_RELOAD); + globalScene.ui.setMode(Mode.SESSION_RELOAD); let delayElapsed = false; let loaded = false; - this.scene.time.delayedCall(Utils.fixedInt(1500), () => { + globalScene.time.delayedCall(Utils.fixedInt(1500), () => { if (loaded) { this.end(); } else { @@ -26,9 +26,9 @@ export class ReloadSessionPhase extends Phase { } }); - this.scene.gameData.clearLocalData(); + globalScene.gameData.clearLocalData(); - (this.systemDataStr ? this.scene.gameData.initSystem(this.systemDataStr) : this.scene.gameData.loadSystem()).then(() => { + (this.systemDataStr ? globalScene.gameData.initSystem(this.systemDataStr) : globalScene.gameData.loadSystem()).then(() => { if (delayElapsed) { this.end(); } else { diff --git a/src/phases/return-phase.ts b/src/phases/return-phase.ts index eb5872015858..9dd13f6d5be1 100644 --- a/src/phases/return-phase.ts +++ b/src/phases/return-phase.ts @@ -1,11 +1,11 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { SpeciesFormChangeActiveTrigger } from "#app/data/pokemon-forms"; import { SwitchType } from "#enums/switch-type"; import { SwitchSummonPhase } from "./switch-summon-phase"; export class ReturnPhase extends SwitchSummonPhase { - constructor(scene: BattleScene, fieldIndex: integer) { - super(scene, SwitchType.SWITCH, fieldIndex, -1, true); + constructor(fieldIndex: integer) { + super(SwitchType.SWITCH, fieldIndex, -1, true); } switchAndSummon(): void { @@ -21,8 +21,8 @@ export class ReturnPhase extends SwitchSummonPhase { pokemon.resetTurnData(); pokemon.resetSummonData(); - this.scene.updateFieldScale(); + globalScene.updateFieldScale(); - this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger); } } diff --git a/src/phases/ribbon-modifier-reward-phase.ts b/src/phases/ribbon-modifier-reward-phase.ts index fabb3bfa1b13..beda85c24634 100644 --- a/src/phases/ribbon-modifier-reward-phase.ts +++ b/src/phases/ribbon-modifier-reward-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import PokemonSpecies from "#app/data/pokemon-species"; import { ModifierTypeFunc } from "#app/modifier/modifier-type"; import { Mode } from "#app/ui/ui"; @@ -8,8 +8,8 @@ import { ModifierRewardPhase } from "./modifier-reward-phase"; export class RibbonModifierRewardPhase extends ModifierRewardPhase { private species: PokemonSpecies; - constructor(scene: BattleScene, modifierTypeFunc: ModifierTypeFunc, species: PokemonSpecies) { - super(scene, modifierTypeFunc); + constructor(modifierTypeFunc: ModifierTypeFunc, species: PokemonSpecies) { + super(modifierTypeFunc); this.species = species; } @@ -17,12 +17,12 @@ export class RibbonModifierRewardPhase extends ModifierRewardPhase { doReward(): Promise { return new Promise(resolve => { const newModifier = this.modifierType.newModifier(); - this.scene.addModifier(newModifier).then(() => { - this.scene.playSound("level_up_fanfare"); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:beatModeFirstTime", { + globalScene.addModifier(newModifier).then(() => { + globalScene.playSound("level_up_fanfare"); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:beatModeFirstTime", { speciesName: this.species.name, - gameMode: this.scene.gameMode.getName(), + gameMode: globalScene.gameMode.getName(), newModifier: newModifier?.type.name }), null, () => { resolve(); diff --git a/src/phases/scan-ivs-phase.ts b/src/phases/scan-ivs-phase.ts index 5ec61d5eec6f..6f9413bc4fde 100644 --- a/src/phases/scan-ivs-phase.ts +++ b/src/phases/scan-ivs-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { CommonBattleAnim, CommonAnim } from "#app/data/battle-anims"; import { Stat } from "#app/enums/stat"; @@ -11,8 +11,8 @@ import { PokemonPhase } from "./pokemon-phase"; export class ScanIvsPhase extends PokemonPhase { private shownIvs: integer; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, shownIvs: integer) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, shownIvs: integer) { + super(battlerIndex); this.shownIvs = shownIvs; } @@ -29,12 +29,12 @@ export class ScanIvsPhase extends PokemonPhase { let enemyIvs: number[] = []; let statsContainer: Phaser.GameObjects.Sprite[] = []; let statsContainerLabels: Phaser.GameObjects.Sprite[] = []; - const enemyField = this.scene.getEnemyField(); - const uiTheme = (this.scene as BattleScene).uiTheme; // Assuming uiTheme is accessible + const enemyField = globalScene.getEnemyField(); + const uiTheme = globalScene.uiTheme; // Assuming uiTheme is accessible for (let e = 0; e < enemyField.length; e++) { enemyIvs = enemyField[e].ivs; - const currentIvs = this.scene.gameData.dexData[enemyField[e].species.getRootSpeciesId()].ivs; // we are using getRootSpeciesId() here because we want to check against the baby form, not the mid form if it exists - const ivsToShow = this.scene.ui.getMessageHandler().getTopIvs(enemyIvs, this.shownIvs); + const currentIvs = globalScene.gameData.dexData[enemyField[e].species.getRootSpeciesId()].ivs; // we are using getRootSpeciesId() here because we want to check against the baby form, not the mid form if it exists + const ivsToShow = globalScene.ui.getMessageHandler().getTopIvs(enemyIvs, this.shownIvs); statsContainer = enemyField[e].getBattleInfo().getStatsValueContainer().list as Phaser.GameObjects.Sprite[]; statsContainerLabels = statsContainer.filter(m => m.name.indexOf("icon_stat_label") >= 0); for (let s = 0; s < statsContainerLabels.length; s++) { @@ -48,17 +48,17 @@ export class ScanIvsPhase extends PokemonPhase { } } - if (!this.scene.hideIvs) { - this.scene.ui.showText(i18next.t("battle:ivScannerUseQuestion", { pokemonName: getPokemonNameWithAffix(pokemon) }), null, () => { - this.scene.ui.setMode(Mode.CONFIRM, () => { - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.clearText(); - new CommonBattleAnim(CommonAnim.LOCK_ON, pokemon, pokemon).play(this.scene, false, () => { - this.scene.ui.getMessageHandler().promptIvs(pokemon.id, pokemon.ivs, this.shownIvs).then(() => this.end()); + if (!globalScene.hideIvs) { + globalScene.ui.showText(i18next.t("battle:ivScannerUseQuestion", { pokemonName: getPokemonNameWithAffix(pokemon) }), null, () => { + globalScene.ui.setMode(Mode.CONFIRM, () => { + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.clearText(); + new CommonBattleAnim(CommonAnim.LOCK_ON, pokemon, pokemon).play(false, () => { + globalScene.ui.getMessageHandler().promptIvs(pokemon.id, pokemon.ivs, this.shownIvs).then(() => this.end()); }); }, () => { - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.clearText(); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.clearText(); this.end(); }); }); diff --git a/src/phases/select-biome-phase.ts b/src/phases/select-biome-phase.ts index 817cd7bcd3d1..55dbbdf69b1d 100644 --- a/src/phases/select-biome-phase.ts +++ b/src/phases/select-biome-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { biomeLinks, getBiomeName } from "#app/data/balance/biomes"; import { Biome } from "#app/enums/biome"; import { MoneyInterestModifier, MapModifier } from "#app/modifier/modifier"; @@ -10,58 +10,58 @@ import { PartyHealPhase } from "./party-heal-phase"; import { SwitchBiomePhase } from "./switch-biome-phase"; export class SelectBiomePhase extends BattlePhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - const currentBiome = this.scene.arena.biomeType; + const currentBiome = globalScene.arena.biomeType; const setNextBiome = (nextBiome: Biome) => { - if (this.scene.currentBattle.waveIndex % 10 === 1) { - this.scene.applyModifiers(MoneyInterestModifier, true, this.scene); - this.scene.unshiftPhase(new PartyHealPhase(this.scene, false)); + if (globalScene.currentBattle.waveIndex % 10 === 1) { + globalScene.applyModifiers(MoneyInterestModifier, true); + globalScene.unshiftPhase(new PartyHealPhase(false)); } - this.scene.unshiftPhase(new SwitchBiomePhase(this.scene, nextBiome)); + globalScene.unshiftPhase(new SwitchBiomePhase(nextBiome)); this.end(); }; - if ((this.scene.gameMode.isClassic && this.scene.gameMode.isWaveFinal(this.scene.currentBattle.waveIndex + 9)) - || (this.scene.gameMode.isDaily && this.scene.gameMode.isWaveFinal(this.scene.currentBattle.waveIndex)) - || (this.scene.gameMode.hasShortBiomes && !(this.scene.currentBattle.waveIndex % 50))) { + if ((globalScene.gameMode.isClassic && globalScene.gameMode.isWaveFinal(globalScene.currentBattle.waveIndex + 9)) + || (globalScene.gameMode.isDaily && globalScene.gameMode.isWaveFinal(globalScene.currentBattle.waveIndex)) + || (globalScene.gameMode.hasShortBiomes && !(globalScene.currentBattle.waveIndex % 50))) { setNextBiome(Biome.END); - } else if (this.scene.gameMode.hasRandomBiomes) { + } else if (globalScene.gameMode.hasRandomBiomes) { setNextBiome(this.generateNextBiome()); } else if (Array.isArray(biomeLinks[currentBiome])) { let biomes: Biome[] = []; - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { biomes = (biomeLinks[currentBiome] as (Biome | [Biome, integer])[]) .filter(b => !Array.isArray(b) || !Utils.randSeedInt(b[1])) .map(b => !Array.isArray(b) ? b : b[0]); - }, this.scene.currentBattle.waveIndex); - if (biomes.length > 1 && this.scene.findModifier(m => m instanceof MapModifier)) { + }, globalScene.currentBattle.waveIndex); + if (biomes.length > 1 && globalScene.findModifier(m => m instanceof MapModifier)) { let biomeChoices: Biome[] = []; - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { biomeChoices = (!Array.isArray(biomeLinks[currentBiome]) ? [ biomeLinks[currentBiome] as Biome ] : biomeLinks[currentBiome] as (Biome | [Biome, integer])[]) .filter((b, i) => !Array.isArray(b) || !Utils.randSeedInt(b[1])) .map(b => Array.isArray(b) ? b[0] : b); - }, this.scene.currentBattle.waveIndex); + }, globalScene.currentBattle.waveIndex); const biomeSelectItems = biomeChoices.map(b => { const ret: OptionSelectItem = { label: getBiomeName(b), handler: () => { - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); setNextBiome(b); return true; } }; return ret; }); - this.scene.ui.setMode(Mode.OPTION_SELECT, { + globalScene.ui.setMode(Mode.OPTION_SELECT, { options: biomeSelectItems, delay: 1000 }); @@ -76,9 +76,9 @@ export class SelectBiomePhase extends BattlePhase { } generateNextBiome(): Biome { - if (!(this.scene.currentBattle.waveIndex % 50)) { + if (!(globalScene.currentBattle.waveIndex % 50)) { return Biome.END; } - return this.scene.generateRandomBiome(this.scene.currentBattle.waveIndex); + return globalScene.generateRandomBiome(globalScene.currentBattle.waveIndex); } } diff --git a/src/phases/select-challenge-phase.ts b/src/phases/select-challenge-phase.ts index 9450c60fec57..2a6797d3556b 100644 --- a/src/phases/select-challenge-phase.ts +++ b/src/phases/select-challenge-phase.ts @@ -1,17 +1,17 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { Mode } from "#app/ui/ui"; export class SelectChallengePhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - this.scene.playBgm("menu"); + globalScene.playBgm("menu"); - this.scene.ui.setMode(Mode.CHALLENGE_SELECT); + globalScene.ui.setMode(Mode.CHALLENGE_SELECT); } } diff --git a/src/phases/select-gender-phase.ts b/src/phases/select-gender-phase.ts index 7f2c965f1d1f..45cbb70dcacd 100644 --- a/src/phases/select-gender-phase.ts +++ b/src/phases/select-gender-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { PlayerGender } from "#app/enums/player-gender"; import { Phase } from "#app/phase"; import { SettingKeys } from "#app/system/settings/settings"; @@ -6,31 +6,31 @@ import { Mode } from "#app/ui/ui"; import i18next from "i18next"; export class SelectGenderPhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start(): void { super.start(); - this.scene.ui.showText(i18next.t("menu:boyOrGirl"), null, () => { - this.scene.ui.setMode(Mode.OPTION_SELECT, { + globalScene.ui.showText(i18next.t("menu:boyOrGirl"), null, () => { + globalScene.ui.setMode(Mode.OPTION_SELECT, { options: [ { label: i18next.t("settings:boy"), handler: () => { - this.scene.gameData.gender = PlayerGender.MALE; - this.scene.gameData.saveSetting(SettingKeys.Player_Gender, 0); - this.scene.gameData.saveSystem().then(() => this.end()); + globalScene.gameData.gender = PlayerGender.MALE; + globalScene.gameData.saveSetting(SettingKeys.Player_Gender, 0); + globalScene.gameData.saveSystem().then(() => this.end()); return true; } }, { label: i18next.t("settings:girl"), handler: () => { - this.scene.gameData.gender = PlayerGender.FEMALE; - this.scene.gameData.saveSetting(SettingKeys.Player_Gender, 1); - this.scene.gameData.saveSystem().then(() => this.end()); + globalScene.gameData.gender = PlayerGender.FEMALE; + globalScene.gameData.saveSetting(SettingKeys.Player_Gender, 1); + globalScene.gameData.saveSystem().then(() => this.end()); return true; } } @@ -40,7 +40,7 @@ export class SelectGenderPhase extends Phase { } end(): void { - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.MESSAGE); super.end(); } } diff --git a/src/phases/select-modifier-phase.ts b/src/phases/select-modifier-phase.ts index 19e1ccc12aea..0ab6c6d4bc5a 100644 --- a/src/phases/select-modifier-phase.ts +++ b/src/phases/select-modifier-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ModifierTier } from "#app/modifier/modifier-tier"; import { regenerateModifierPoolThresholds, ModifierTypeOption, ModifierType, getPlayerShopModifierTypeOptionsForWave, PokemonModifierType, FusePokemonModifierType, PokemonMoveModifierType, TmModifierType, RememberMoveModifierType, PokemonPpRestoreModifierType, PokemonPpUpModifierType, ModifierPoolType, getPlayerModifierTypeOptions } from "#app/modifier/modifier-type"; import { ExtraModifierModifier, HealShopCostModifier, Modifier, PokemonHeldItemModifier, TempExtraModifierModifier } from "#app/modifier/modifier"; @@ -20,8 +20,8 @@ export class SelectModifierPhase extends BattlePhase { private typeOptions: ModifierTypeOption[]; - constructor(scene: BattleScene, rerollCount: integer = 0, modifierTiers?: ModifierTier[], customModifierSettings?: CustomModifierSettings, isCopy: boolean = false) { - super(scene); + constructor(rerollCount: integer = 0, modifierTiers?: ModifierTier[], customModifierSettings?: CustomModifierSettings, isCopy: boolean = false) { + super(); this.rerollCount = rerollCount; this.modifierTiers = modifierTiers; @@ -35,17 +35,17 @@ export class SelectModifierPhase extends BattlePhase { if (!this.rerollCount && !this.isCopy) { this.updateSeed(); } else if (this.rerollCount) { - this.scene.reroll = false; + globalScene.reroll = false; } - const party = this.scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); if (!this.isCopy) { regenerateModifierPoolThresholds(party, this.getPoolType(), this.rerollCount); } const modifierCount = new Utils.IntegerHolder(3); if (this.isPlayer()) { - this.scene.applyModifiers(ExtraModifierModifier, true, modifierCount); - this.scene.applyModifiers(TempExtraModifierModifier, true, modifierCount); + globalScene.applyModifiers(ExtraModifierModifier, true, modifierCount); + globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCount); } // If custom modifiers are specified, overrides default item count @@ -65,64 +65,64 @@ export class SelectModifierPhase extends BattlePhase { const modifierSelectCallback = (rowCursor: integer, cursor: integer) => { if (rowCursor < 0 || cursor < 0) { - this.scene.ui.showText(i18next.t("battle:skipItemQuestion"), null, () => { - this.scene.ui.setOverlayMode(Mode.CONFIRM, () => { - this.scene.ui.revertMode(); - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:skipItemQuestion"), null, () => { + globalScene.ui.setOverlayMode(Mode.CONFIRM, () => { + globalScene.ui.revertMode(); + globalScene.ui.setMode(Mode.MESSAGE); super.end(); - }, () => this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(this.scene.lockModifierTiers))); + }, () => globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(globalScene.lockModifierTiers))); }); return false; } let modifierType: ModifierType; let cost: integer; - const rerollCost = this.getRerollCost(this.scene.lockModifierTiers); + const rerollCost = this.getRerollCost(globalScene.lockModifierTiers); switch (rowCursor) { case 0: switch (cursor) { case 0: - if (rerollCost < 0 || this.scene.money < rerollCost) { - this.scene.ui.playError(); + if (rerollCost < 0 || globalScene.money < rerollCost) { + globalScene.ui.playError(); return false; } else { - this.scene.reroll = true; - this.scene.unshiftPhase(new SelectModifierPhase(this.scene, this.rerollCount + 1, this.typeOptions.map(o => o.type?.tier).filter(t => t !== undefined) as ModifierTier[])); - this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end()); + globalScene.reroll = true; + globalScene.unshiftPhase(new SelectModifierPhase(this.rerollCount + 1, this.typeOptions.map(o => o.type?.tier).filter(t => t !== undefined) as ModifierTier[])); + globalScene.ui.clearText(); + globalScene.ui.setMode(Mode.MESSAGE).then(() => super.end()); if (!Overrides.WAIVE_ROLL_FEE_OVERRIDE) { - this.scene.money -= rerollCost; - this.scene.updateMoneyText(); - this.scene.animateMoneyChanged(false); + globalScene.money -= rerollCost; + globalScene.updateMoneyText(); + globalScene.animateMoneyChanged(false); } - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); } break; case 1: - this.scene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.MODIFIER_TRANSFER, -1, (fromSlotIndex: integer, itemIndex: integer, itemQuantity: integer, toSlotIndex: integer) => { + globalScene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.MODIFIER_TRANSFER, -1, (fromSlotIndex: integer, itemIndex: integer, itemQuantity: integer, toSlotIndex: integer) => { if (toSlotIndex !== undefined && fromSlotIndex < 6 && toSlotIndex < 6 && fromSlotIndex !== toSlotIndex && itemIndex > -1) { - const itemModifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const itemModifiers = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === party[fromSlotIndex].id) as PokemonHeldItemModifier[]; const itemModifier = itemModifiers[itemIndex]; - this.scene.tryTransferHeldItemModifier(itemModifier, party[toSlotIndex], true, itemQuantity, undefined, undefined, false); + globalScene.tryTransferHeldItemModifier(itemModifier, party[toSlotIndex], true, itemQuantity, undefined, undefined, false); } else { - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(this.scene.lockModifierTiers)); + globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(globalScene.lockModifierTiers)); } }, PartyUiHandler.FilterItemMaxStacks); break; case 2: - this.scene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.CHECK, -1, () => { - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(this.scene.lockModifierTiers)); + globalScene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.CHECK, -1, () => { + globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(globalScene.lockModifierTiers)); }); break; case 3: if (rerollCost < 0) { // Reroll lock button is also disabled when reroll is disabled - this.scene.ui.playError(); + globalScene.ui.playError(); return false; } - this.scene.lockModifierTiers = !this.scene.lockModifierTiers; - const uiHandler = this.scene.ui.getHandler() as ModifierSelectUiHandler; - uiHandler.setRerollCost(this.getRerollCost(this.scene.lockModifierTiers)); + globalScene.lockModifierTiers = !globalScene.lockModifierTiers; + const uiHandler = globalScene.ui.getHandler() as ModifierSelectUiHandler; + uiHandler.setRerollCost(this.getRerollCost(globalScene.lockModifierTiers)); uiHandler.updateLockRaritiesText(); uiHandler.updateRerollCostText(); return false; @@ -130,8 +130,8 @@ export class SelectModifierPhase extends BattlePhase { return true; case 1: if (this.typeOptions.length === 0) { - this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.clearText(); + globalScene.ui.setMode(Mode.MESSAGE); super.end(); return true; } @@ -140,51 +140,51 @@ export class SelectModifierPhase extends BattlePhase { } break; default: - const shopOptions = getPlayerShopModifierTypeOptionsForWave(this.scene.currentBattle.waveIndex, this.scene.getWaveMoneyAmount(1)); + const shopOptions = getPlayerShopModifierTypeOptionsForWave(globalScene.currentBattle.waveIndex, globalScene.getWaveMoneyAmount(1)); const shopOption = shopOptions[rowCursor > 2 || shopOptions.length <= SHOP_OPTIONS_ROW_LIMIT ? cursor : cursor + SHOP_OPTIONS_ROW_LIMIT]; if (shopOption.type) { modifierType = shopOption.type; } // Apply Black Sludge to healing item cost const healingItemCost = new NumberHolder(shopOption.cost); - this.scene.applyModifier(HealShopCostModifier, true, healingItemCost); + globalScene.applyModifier(HealShopCostModifier, true, healingItemCost); cost = healingItemCost.value; break; } - if (cost! && (this.scene.money < cost) && !Overrides.WAIVE_ROLL_FEE_OVERRIDE) { // TODO: is the bang on cost correct? - this.scene.ui.playError(); + if (cost! && (globalScene.money < cost) && !Overrides.WAIVE_ROLL_FEE_OVERRIDE) { // TODO: is the bang on cost correct? + globalScene.ui.playError(); return false; } const applyModifier = (modifier: Modifier, playSound: boolean = false) => { - const result = this.scene.addModifier(modifier, false, playSound, undefined, undefined, cost); + const result = globalScene.addModifier(modifier, false, playSound, undefined, undefined, cost); // Queue a copy of this phase when applying a TM or Memory Mushroom. // If the player selects either of these, then escapes out of consuming them, // they are returned to a shop in the same state. if (modifier.type instanceof RememberMoveModifierType || modifier.type instanceof TmModifierType) { - this.scene.unshiftPhase(this.copy()); + globalScene.unshiftPhase(this.copy()); } if (cost && !(modifier.type instanceof RememberMoveModifierType)) { result.then(success => { if (success) { if (!Overrides.WAIVE_ROLL_FEE_OVERRIDE) { - this.scene.money -= cost; - this.scene.updateMoneyText(); - this.scene.animateMoneyChanged(false); + globalScene.money -= cost; + globalScene.updateMoneyText(); + globalScene.animateMoneyChanged(false); } - this.scene.playSound("se/buy"); - (this.scene.ui.getHandler() as ModifierSelectUiHandler).updateCostText(); + globalScene.playSound("se/buy"); + (globalScene.ui.getHandler() as ModifierSelectUiHandler).updateCostText(); } else { - this.scene.ui.playError(); + globalScene.ui.playError(); } }); } else { const doEnd = () => { - this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.clearText(); + globalScene.ui.setMode(Mode.MESSAGE); super.end(); }; if (result instanceof Promise) { @@ -197,14 +197,14 @@ export class SelectModifierPhase extends BattlePhase { if (modifierType! instanceof PokemonModifierType) { //TODO: is the bang correct? if (modifierType instanceof FusePokemonModifierType) { - this.scene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.SPLICE, -1, (fromSlotIndex: integer, spliceSlotIndex: integer) => { + globalScene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.SPLICE, -1, (fromSlotIndex: integer, spliceSlotIndex: integer) => { if (spliceSlotIndex !== undefined && fromSlotIndex < 6 && spliceSlotIndex < 6 && fromSlotIndex !== spliceSlotIndex) { - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer()).then(() => { + globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer()).then(() => { const modifier = modifierType.newModifier(party[fromSlotIndex], party[spliceSlotIndex])!; //TODO: is the bang correct? applyModifier(modifier, true); }); } else { - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(this.scene.lockModifierTiers)); + globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(globalScene.lockModifierTiers)); } }, modifierType.selectFilter); } else { @@ -220,9 +220,9 @@ export class SelectModifierPhase extends BattlePhase { const tmMoveId = isTmModifier ? (modifierType as TmModifierType).moveId : undefined; - this.scene.ui.setModeWithoutClear(Mode.PARTY, partyUiMode, -1, (slotIndex: integer, option: PartyOption) => { + globalScene.ui.setModeWithoutClear(Mode.PARTY, partyUiMode, -1, (slotIndex: integer, option: PartyOption) => { if (slotIndex < 6) { - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer()).then(() => { + globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer()).then(() => { const modifier = !isMoveModifier ? !isRememberMoveModifier ? modifierType.newModifier(party[slotIndex]) @@ -231,7 +231,7 @@ export class SelectModifierPhase extends BattlePhase { applyModifier(modifier!, true); // TODO: is the bang correct? }); } else { - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(this.scene.lockModifierTiers)); + globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(globalScene.lockModifierTiers)); } }, pokemonModifierType.selectFilter, modifierType instanceof PokemonMoveModifierType ? (modifierType as PokemonMoveModifierType).moveSelectFilter : undefined, tmMoveId, isPpRestoreModifier); } @@ -241,11 +241,11 @@ export class SelectModifierPhase extends BattlePhase { return !cost!;// TODO: is the bang correct? }; - this.scene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(this.scene.lockModifierTiers)); + globalScene.ui.setMode(Mode.MODIFIER_SELECT, this.isPlayer(), this.typeOptions, modifierSelectCallback, this.getRerollCost(globalScene.lockModifierTiers)); } updateSeed(): void { - this.scene.resetSeed(); + globalScene.resetSeed(); } isPlayer(): boolean { @@ -276,11 +276,11 @@ export class SelectModifierPhase extends BattlePhase { multiplier = this.customModifierSettings.rerollMultiplier; } - const baseMultiplier = Math.min(Math.ceil(this.scene.currentBattle.waveIndex / 10) * baseValue * (2 ** this.rerollCount) * multiplier, Number.MAX_SAFE_INTEGER); + const baseMultiplier = Math.min(Math.ceil(globalScene.currentBattle.waveIndex / 10) * baseValue * (2 ** this.rerollCount) * multiplier, Number.MAX_SAFE_INTEGER); // Apply Black Sludge to reroll cost const modifiedRerollCost = new NumberHolder(baseMultiplier); - this.scene.applyModifier(HealShopCostModifier, true, modifiedRerollCost); + globalScene.applyModifier(HealShopCostModifier, true, modifiedRerollCost); return modifiedRerollCost.value; } @@ -289,12 +289,11 @@ export class SelectModifierPhase extends BattlePhase { } getModifierTypeOptions(modifierCount: integer): ModifierTypeOption[] { - return getPlayerModifierTypeOptions(modifierCount, this.scene.getPlayerParty(), this.scene.lockModifierTiers ? this.modifierTiers : undefined, this.customModifierSettings); + return getPlayerModifierTypeOptions(modifierCount, globalScene.getPlayerParty(), globalScene.lockModifierTiers ? this.modifierTiers : undefined, this.customModifierSettings); } copy(): SelectModifierPhase { return new SelectModifierPhase( - this.scene, this.rerollCount, this.modifierTiers, { guaranteedModifierTypeOptions: this.typeOptions, rerollMultiplier: this.customModifierSettings?.rerollMultiplier, allowLuckUpgrades: false }, @@ -303,6 +302,6 @@ export class SelectModifierPhase extends BattlePhase { } addModifier(modifier: Modifier): Promise { - return this.scene.addModifier(modifier, false, true); + return globalScene.addModifier(modifier, false, true); } } diff --git a/src/phases/select-starter-phase.ts b/src/phases/select-starter-phase.ts index 2273ab1cd3c9..1a015504698c 100644 --- a/src/phases/select-starter-phase.ts +++ b/src/phases/select-starter-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { applyChallenges, ChallengeType } from "#app/data/challenge"; import { Gender } from "#app/data/gender"; import { SpeciesFormChangeMoveLearnedTrigger } from "#app/data/pokemon-forms"; @@ -15,24 +15,24 @@ import SoundFade from "phaser3-rex-plugins/plugins/soundfade"; export class SelectStarterPhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - this.scene.playBgm("menu"); + globalScene.playBgm("menu"); - this.scene.ui.setMode(Mode.STARTER_SELECT, (starters: Starter[]) => { - this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.SAVE_SLOT, SaveSlotUiMode.SAVE, (slotId: integer) => { + globalScene.ui.setMode(Mode.STARTER_SELECT, (starters: Starter[]) => { + globalScene.ui.clearText(); + globalScene.ui.setMode(Mode.SAVE_SLOT, SaveSlotUiMode.SAVE, (slotId: integer) => { if (slotId === -1) { - this.scene.clearPhaseQueue(); - this.scene.pushPhase(new TitlePhase(this.scene)); + globalScene.clearPhaseQueue(); + globalScene.pushPhase(new TitlePhase()); return this.end(); } - this.scene.sessionSlotId = slotId; + globalScene.sessionSlotId = slotId; this.initBattle(starters); }); }); @@ -43,13 +43,13 @@ export class SelectStarterPhase extends Phase { * @param starters {@linkcode Pokemon} with which to start the first battle */ initBattle(starters: Starter[]) { - const party = this.scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); const loadPokemonAssets: Promise[] = []; starters.forEach((starter: Starter, i: integer) => { if (!i && Overrides.STARTER_SPECIES_OVERRIDE) { starter.species = getPokemonSpecies(Overrides.STARTER_SPECIES_OVERRIDE as Species); } - const starterProps = this.scene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr); + const starterProps = globalScene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr); let starterFormIndex = Math.min(starterProps.formIndex, Math.max(starter.species.forms.length - 1, 0)); if ( starter.species.speciesId in Overrides.STARTER_FORM_OVERRIDES && @@ -64,13 +64,13 @@ export class SelectStarterPhase extends Phase { if (Overrides.GENDER_OVERRIDE !== null) { starterGender = Overrides.GENDER_OVERRIDE; } - const starterIvs = this.scene.gameData.dexData[starter.species.speciesId].ivs.slice(0); - const starterPokemon = this.scene.addPlayerPokemon(starter.species, this.scene.gameMode.getStartingLevel(), starter.abilityIndex, starterFormIndex, starterGender, starterProps.shiny, starterProps.variant, starterIvs, starter.nature); + const starterIvs = globalScene.gameData.dexData[starter.species.speciesId].ivs.slice(0); + const starterPokemon = globalScene.addPlayerPokemon(starter.species, globalScene.gameMode.getStartingLevel(), starter.abilityIndex, starterFormIndex, starterGender, starterProps.shiny, starterProps.variant, starterIvs, starter.nature); starter.moveset && starterPokemon.tryPopulateMoveset(starter.moveset); if (starter.passive) { starterPokemon.passive = true; } - starterPokemon.luck = this.scene.gameData.getDexAttrLuck(this.scene.gameData.dexData[starter.species.speciesId].caughtAttr); + starterPokemon.luck = globalScene.gameData.getDexAttrLuck(globalScene.gameData.dexData[starter.species.speciesId].caughtAttr); if (starter.pokerus) { starterPokemon.pokerus = true; } @@ -79,31 +79,31 @@ export class SelectStarterPhase extends Phase { starterPokemon.nickname = starter.nickname; } - if (this.scene.gameMode.isSplicedOnly || Overrides.STARTER_FUSION_OVERRIDE) { + if (globalScene.gameMode.isSplicedOnly || Overrides.STARTER_FUSION_OVERRIDE) { starterPokemon.generateFusionSpecies(true); } starterPokemon.setVisible(false); - applyChallenges(this.scene.gameMode, ChallengeType.STARTER_MODIFY, starterPokemon); + applyChallenges(globalScene.gameMode, ChallengeType.STARTER_MODIFY, starterPokemon); party.push(starterPokemon); loadPokemonAssets.push(starterPokemon.loadAssets()); }); - overrideModifiers(this.scene); - overrideHeldItems(this.scene, party[0]); + overrideModifiers(); + overrideHeldItems(party[0]); Promise.all(loadPokemonAssets).then(() => { - SoundFade.fadeOut(this.scene, this.scene.sound.get("menu"), 500, true); - this.scene.time.delayedCall(500, () => this.scene.playBgm()); - if (this.scene.gameMode.isClassic) { - this.scene.gameData.gameStats.classicSessionsPlayed++; + SoundFade.fadeOut(globalScene, globalScene.sound.get("menu"), 500, true); + globalScene.time.delayedCall(500, () => globalScene.playBgm()); + if (globalScene.gameMode.isClassic) { + globalScene.gameData.gameStats.classicSessionsPlayed++; } else { - this.scene.gameData.gameStats.endlessSessionsPlayed++; + globalScene.gameData.gameStats.endlessSessionsPlayed++; } - this.scene.newBattle(); - this.scene.arena.init(); - this.scene.sessionPlayTime = 0; - this.scene.lastSavePlayTime = 0; + globalScene.newBattle(); + globalScene.arena.init(); + globalScene.sessionPlayTime = 0; + globalScene.lastSavePlayTime = 0; // Ensures Keldeo (or any future Pokemon that have this type of form change) starts in the correct form - this.scene.getPlayerParty().forEach((p) => { - this.scene.triggerPokemonFormChange(p, SpeciesFormChangeMoveLearnedTrigger); + globalScene.getPlayerParty().forEach((p) => { + globalScene.triggerPokemonFormChange(p, SpeciesFormChangeMoveLearnedTrigger); }); this.end(); }); diff --git a/src/phases/select-target-phase.ts b/src/phases/select-target-phase.ts index 6f11f984c4b8..6bce3bf67a4c 100644 --- a/src/phases/select-target-phase.ts +++ b/src/phases/select-target-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { Command } from "#app/ui/command-ui-handler"; import { Mode } from "#app/ui/ui"; @@ -8,33 +8,33 @@ import i18next from "#app/plugins/i18n"; import { allMoves } from "#app/data/move"; export class SelectTargetPhase extends PokemonPhase { - constructor(scene: BattleScene, fieldIndex: integer) { - super(scene, fieldIndex); + constructor(fieldIndex: integer) { + super(fieldIndex); } start() { super.start(); - const turnCommand = this.scene.currentBattle.turnCommands[this.fieldIndex]; + const turnCommand = globalScene.currentBattle.turnCommands[this.fieldIndex]; const move = turnCommand?.move?.move; - this.scene.ui.setMode(Mode.TARGET_SELECT, this.fieldIndex, move, (targets: BattlerIndex[]) => { - this.scene.ui.setMode(Mode.MESSAGE); - const fieldSide = this.scene.getField(); + globalScene.ui.setMode(Mode.TARGET_SELECT, this.fieldIndex, move, (targets: BattlerIndex[]) => { + globalScene.ui.setMode(Mode.MESSAGE); + const fieldSide = globalScene.getField(); const user = fieldSide[this.fieldIndex]; const moveObject = allMoves[move!]; if (moveObject && user.isMoveTargetRestricted(moveObject.id, user, fieldSide[targets[0]])) { const errorMessage = user.getRestrictingTag(move!, user, fieldSide[targets[0]])!.selectionDeniedText(user, moveObject.id); - user.scene.queueMessage(i18next.t(errorMessage, { moveName: moveObject.name }), 0, true); + globalScene.queueMessage(i18next.t(errorMessage, { moveName: moveObject.name }), 0, true); targets = []; } if (targets.length < 1) { - this.scene.currentBattle.turnCommands[this.fieldIndex] = null; - this.scene.unshiftPhase(new CommandPhase(this.scene, this.fieldIndex)); + globalScene.currentBattle.turnCommands[this.fieldIndex] = null; + globalScene.unshiftPhase(new CommandPhase(this.fieldIndex)); } else { turnCommand!.targets = targets; //TODO: is the bang correct here? } if (turnCommand?.command === Command.BALL && this.fieldIndex) { - this.scene.currentBattle.turnCommands[this.fieldIndex - 1]!.skip = true; //TODO: is the bang correct here? + globalScene.currentBattle.turnCommands[this.fieldIndex - 1]!.skip = true; //TODO: is the bang correct here? } this.end(); }); diff --git a/src/phases/shiny-sparkle-phase.ts b/src/phases/shiny-sparkle-phase.ts index 49c60a82dd56..61d6674601d5 100644 --- a/src/phases/shiny-sparkle-phase.ts +++ b/src/phases/shiny-sparkle-phase.ts @@ -1,16 +1,16 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { PokemonPhase } from "./pokemon-phase"; export class ShinySparklePhase extends PokemonPhase { - constructor(scene: BattleScene, battlerIndex: BattlerIndex) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex) { + super(battlerIndex); } start() { super.start(); this.getPokemon().sparkle(); - this.scene.time.delayedCall(1000, () => this.end()); + globalScene.time.delayedCall(1000, () => this.end()); } } diff --git a/src/phases/show-ability-phase.ts b/src/phases/show-ability-phase.ts index cf34e327b4fb..66885c06af8b 100644 --- a/src/phases/show-ability-phase.ts +++ b/src/phases/show-ability-phase.ts @@ -1,12 +1,12 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { PokemonPhase } from "./pokemon-phase"; export class ShowAbilityPhase extends PokemonPhase { private passive: boolean; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, passive: boolean = false) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, passive: boolean = false) { + super(battlerIndex); this.passive = passive; } @@ -17,7 +17,7 @@ export class ShowAbilityPhase extends PokemonPhase { const pokemon = this.getPokemon(); if (pokemon) { - this.scene.abilityBar.showAbility(pokemon, this.passive); + globalScene.abilityBar.showAbility(pokemon, this.passive); if (pokemon?.battleData) { pokemon.battleData.abilityRevealed = true; diff --git a/src/phases/show-party-exp-bar-phase.ts b/src/phases/show-party-exp-bar-phase.ts index f1783e7715f6..71bd39e38980 100644 --- a/src/phases/show-party-exp-bar-phase.ts +++ b/src/phases/show-party-exp-bar-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ExpGainsSpeed } from "#app/enums/exp-gains-speed"; import { ExpNotification } from "#app/enums/exp-notification"; import { ExpBoosterModifier } from "#app/modifier/modifier"; @@ -10,8 +10,8 @@ import { PlayerPartyMemberPokemonPhase } from "./player-party-member-pokemon-pha export class ShowPartyExpBarPhase extends PlayerPartyMemberPokemonPhase { private expValue: number; - constructor(scene: BattleScene, partyMemberIndex: integer, expValue: number) { - super(scene, partyMemberIndex); + constructor(partyMemberIndex: integer, expValue: number) { + super(partyMemberIndex); this.expValue = expValue; } @@ -21,33 +21,33 @@ export class ShowPartyExpBarPhase extends PlayerPartyMemberPokemonPhase { const pokemon = this.getPokemon(); const exp = new Utils.NumberHolder(this.expValue); - this.scene.applyModifiers(ExpBoosterModifier, true, exp); + globalScene.applyModifiers(ExpBoosterModifier, true, exp); exp.value = Math.floor(exp.value); const lastLevel = pokemon.level; pokemon.addExp(exp.value); const newLevel = pokemon.level; if (newLevel > lastLevel) { - this.scene.unshiftPhase(new LevelUpPhase(this.scene, this.partyMemberIndex, lastLevel, newLevel)); + globalScene.unshiftPhase(new LevelUpPhase(this.partyMemberIndex, lastLevel, newLevel)); } - this.scene.unshiftPhase(new HidePartyExpBarPhase(this.scene)); + globalScene.unshiftPhase(new HidePartyExpBarPhase()); pokemon.updateInfo(); - if (this.scene.expParty === ExpNotification.SKIP) { + if (globalScene.expParty === ExpNotification.SKIP) { this.end(); - } else if (this.scene.expParty === ExpNotification.ONLY_LEVEL_UP) { + } else if (globalScene.expParty === ExpNotification.ONLY_LEVEL_UP) { if (newLevel > lastLevel) { // this means if we level up // instead of displaying the exp gain in the small frame, we display the new level // we use the same method for mode 0 & 1, by giving a parameter saying to display the exp or the level - this.scene.partyExpBar.showPokemonExp(pokemon, exp.value, this.scene.expParty === ExpNotification.ONLY_LEVEL_UP, newLevel).then(() => { - setTimeout(() => this.end(), 800 / Math.pow(2, this.scene.expGainsSpeed)); + globalScene.partyExpBar.showPokemonExp(pokemon, exp.value, globalScene.expParty === ExpNotification.ONLY_LEVEL_UP, newLevel).then(() => { + setTimeout(() => this.end(), 800 / Math.pow(2, globalScene.expGainsSpeed)); }); } else { this.end(); } - } else if (this.scene.expGainsSpeed < ExpGainsSpeed.SKIP) { - this.scene.partyExpBar.showPokemonExp(pokemon, exp.value, false, newLevel).then(() => { - setTimeout(() => this.end(), 500 / Math.pow(2, this.scene.expGainsSpeed)); + } else if (globalScene.expGainsSpeed < ExpGainsSpeed.SKIP) { + globalScene.partyExpBar.showPokemonExp(pokemon, exp.value, false, newLevel).then(() => { + setTimeout(() => this.end(), 500 / Math.pow(2, globalScene.expGainsSpeed)); }); } else { this.end(); diff --git a/src/phases/show-trainer-phase.ts b/src/phases/show-trainer-phase.ts index 26ccddd53fc0..17106b54048a 100644 --- a/src/phases/show-trainer-phase.ts +++ b/src/phases/show-trainer-phase.ts @@ -1,21 +1,21 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { PlayerGender } from "#app/enums/player-gender"; import { BattlePhase } from "./battle-phase"; export class ShowTrainerPhase extends BattlePhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - this.scene.trainer.setVisible(true); + globalScene.trainer.setVisible(true); - this.scene.trainer.setTexture(`trainer_${this.scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); - this.scene.tweens.add({ - targets: this.scene.trainer, + globalScene.tweens.add({ + targets: globalScene.trainer, x: 106, duration: 1000, onComplete: () => this.end() diff --git a/src/phases/stat-stage-change-phase.ts b/src/phases/stat-stage-change-phase.ts index 44144f9d0478..f1e268b3c6c9 100644 --- a/src/phases/stat-stage-change-phase.ts +++ b/src/phases/stat-stage-change-phase.ts @@ -1,5 +1,5 @@ +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; -import BattleScene from "#app/battle-scene"; import { applyAbAttrs, applyPostStatStageChangeAbAttrs, applyPreStatStageChangeAbAttrs, PostStatStageChangeAbAttr, ProtectStatAbAttr, StatStageChangeCopyAbAttr, StatStageChangeMultiplierAbAttr } from "#app/data/ability"; import { ArenaTagSide, MistTag } from "#app/data/arena-tag"; import Pokemon from "#app/field/pokemon"; @@ -23,8 +23,8 @@ export class StatStageChangePhase extends PokemonPhase { private onChange: StatStageChangeCallback | null; - constructor(scene: BattleScene, battlerIndex: BattlerIndex, selfTarget: boolean, stats: BattleStat[], stages: integer, showMessage: boolean = true, ignoreAbilities: boolean = false, canBeCopied: boolean = true, onChange: StatStageChangeCallback | null = null) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex, selfTarget: boolean, stats: BattleStat[], stages: integer, showMessage: boolean = true, ignoreAbilities: boolean = false, canBeCopied: boolean = true, onChange: StatStageChangeCallback | null = null) { + super(battlerIndex); this.selfTarget = selfTarget; this.stats = stats; @@ -41,7 +41,7 @@ export class StatStageChangePhase extends PokemonPhase { if (this.stats.length > 1) { for (let i = 0; i < this.stats.length; i++) { const stat = [ this.stats[i] ]; - this.scene.unshiftPhase(new StatStageChangePhase(this.scene, this.battlerIndex, this.selfTarget, stat, this.stages, this.showMessage, this.ignoreAbilities, this.canBeCopied, this.onChange)); + globalScene.unshiftPhase(new StatStageChangePhase(this.battlerIndex, this.selfTarget, stat, this.stages, this.showMessage, this.ignoreAbilities, this.canBeCopied, this.onChange)); } return this.end(); } @@ -65,7 +65,7 @@ export class StatStageChangePhase extends PokemonPhase { if (!this.selfTarget && stages.value < 0) { // TODO: add a reference to the source of the stat change to fix Infiltrator interaction - this.scene.arena.applyTagsForSide(MistTag, pokemon.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY, false, null, cancelled); + globalScene.arena.applyTagsForSide(MistTag, pokemon.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY, false, null, cancelled); } if (!cancelled.value && !this.selfTarget && stages.value < 0) { @@ -88,7 +88,7 @@ export class StatStageChangePhase extends PokemonPhase { if (this.showMessage) { const messages = this.getStatStageChangeMessages(filteredStats, stages.value, relLevels); for (const message of messages) { - this.scene.queueMessage(message); + globalScene.queueMessage(message); } } @@ -119,50 +119,50 @@ export class StatStageChangePhase extends PokemonPhase { applyPostStatStageChangeAbAttrs(PostStatStageChangeAbAttr, pokemon, filteredStats, this.stages, this.selfTarget); // Look for any other stat change phases; if this is the last one, do White Herb check - const existingPhase = this.scene.findPhase(p => p instanceof StatStageChangePhase && p.battlerIndex === this.battlerIndex); + const existingPhase = globalScene.findPhase(p => p instanceof StatStageChangePhase && p.battlerIndex === this.battlerIndex); if (!(existingPhase instanceof StatStageChangePhase)) { // Apply White Herb if needed - const whiteHerb = this.scene.applyModifier(ResetNegativeStatStageModifier, this.player, pokemon) as ResetNegativeStatStageModifier; + const whiteHerb = globalScene.applyModifier(ResetNegativeStatStageModifier, this.player, pokemon) as ResetNegativeStatStageModifier; // If the White Herb was applied, consume it if (whiteHerb) { pokemon.loseHeldItem(whiteHerb); - this.scene.updateModifiers(this.player); + globalScene.updateModifiers(this.player); } } pokemon.updateInfo(); - handleTutorial(this.scene, Tutorial.Stat_Change).then(() => super.end()); + handleTutorial(Tutorial.Stat_Change).then(() => super.end()); }; - if (relLevels.filter(l => l).length && this.scene.moveAnimations) { + if (relLevels.filter(l => l).length && globalScene.moveAnimations) { pokemon.enableMask(); const pokemonMaskSprite = pokemon.maskSprite; - const tileX = (this.player ? 106 : 236) * pokemon.getSpriteScale() * this.scene.field.scale; - const tileY = ((this.player ? 148 : 84) + (stages.value >= 1 ? 160 : 0)) * pokemon.getSpriteScale() * this.scene.field.scale; - const tileWidth = 156 * this.scene.field.scale * pokemon.getSpriteScale(); - const tileHeight = 316 * this.scene.field.scale * pokemon.getSpriteScale(); + const tileX = (this.player ? 106 : 236) * pokemon.getSpriteScale() * globalScene.field.scale; + const tileY = ((this.player ? 148 : 84) + (stages.value >= 1 ? 160 : 0)) * pokemon.getSpriteScale() * globalScene.field.scale; + const tileWidth = 156 * globalScene.field.scale * pokemon.getSpriteScale(); + const tileHeight = 316 * globalScene.field.scale * pokemon.getSpriteScale(); // On increase, show the red sprite located at ATK // On decrease, show the blue sprite located at SPD const spriteColor = stages.value >= 1 ? Stat[Stat.ATK].toLowerCase() : Stat[Stat.SPD].toLowerCase(); - const statSprite = this.scene.add.tileSprite(tileX, tileY, tileWidth, tileHeight, "battle_stats", spriteColor); - statSprite.setPipeline(this.scene.fieldSpritePipeline); + const statSprite = globalScene.add.tileSprite(tileX, tileY, tileWidth, tileHeight, "battle_stats", spriteColor); + statSprite.setPipeline(globalScene.fieldSpritePipeline); statSprite.setAlpha(0); statSprite.setScale(6); statSprite.setOrigin(0.5, 1); - this.scene.playSound(`se/stat_${stages.value >= 1 ? "up" : "down"}`); + globalScene.playSound(`se/stat_${stages.value >= 1 ? "up" : "down"}`); - statSprite.setMask(new Phaser.Display.Masks.BitmapMask(this.scene, pokemonMaskSprite ?? undefined)); + statSprite.setMask(new Phaser.Display.Masks.BitmapMask(globalScene, pokemonMaskSprite ?? undefined)); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: statSprite, duration: 250, alpha: 0.8375, onComplete: () => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: statSprite, delay: 1000, duration: 250, @@ -171,13 +171,13 @@ export class StatStageChangePhase extends PokemonPhase { } }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: statSprite, duration: 1500, y: `${stages.value >= 1 ? "-" : "+"}=${160 * 6}` }); - this.scene.time.delayedCall(1750, () => { + globalScene.time.delayedCall(1750, () => { pokemon.disableMask(); end(); }); @@ -191,21 +191,21 @@ export class StatStageChangePhase extends PokemonPhase { const isAccEva = accEva.some(s => this.stats.includes(s)); let existingPhase: StatStageChangePhase; if (this.stats.length === 1) { - while ((existingPhase = (this.scene.findPhase(p => p instanceof StatStageChangePhase && p.battlerIndex === this.battlerIndex && p.stats.length === 1 + while ((existingPhase = (globalScene.findPhase(p => p instanceof StatStageChangePhase && p.battlerIndex === this.battlerIndex && p.stats.length === 1 && (p.stats[0] === this.stats[0]) && p.selfTarget === this.selfTarget && p.showMessage === this.showMessage && p.ignoreAbilities === this.ignoreAbilities) as StatStageChangePhase))) { this.stages += existingPhase.stages; - if (!this.scene.tryRemovePhase(p => p === existingPhase)) { + if (!globalScene.tryRemovePhase(p => p === existingPhase)) { break; } } } - while ((existingPhase = (this.scene.findPhase(p => p instanceof StatStageChangePhase && p.battlerIndex === this.battlerIndex && p.selfTarget === this.selfTarget + while ((existingPhase = (globalScene.findPhase(p => p instanceof StatStageChangePhase && p.battlerIndex === this.battlerIndex && p.selfTarget === this.selfTarget && (accEva.some(s => p.stats.includes(s)) === isAccEva) && p.stages === this.stages && p.showMessage === this.showMessage && p.ignoreAbilities === this.ignoreAbilities) as StatStageChangePhase))) { this.stats.push(...existingPhase.stats); - if (!this.scene.tryRemovePhase(p => p === existingPhase)) { + if (!globalScene.tryRemovePhase(p => p === existingPhase)) { break; } } diff --git a/src/phases/summon-missing-phase.ts b/src/phases/summon-missing-phase.ts index 83ac8779dd8d..f32f6a377f5a 100644 --- a/src/phases/summon-missing-phase.ts +++ b/src/phases/summon-missing-phase.ts @@ -1,15 +1,15 @@ -import BattleScene from "#app/battle-scene"; import { getPokemonNameWithAffix } from "#app/messages"; import i18next from "i18next"; import { SummonPhase } from "./summon-phase"; +import { globalScene } from "#app/global-scene"; export class SummonMissingPhase extends SummonPhase { - constructor(scene: BattleScene, fieldIndex: integer) { - super(scene, fieldIndex); + constructor(fieldIndex: integer) { + super(fieldIndex); } preSummon(): void { - this.scene.ui.showText(i18next.t("battle:sendOutPokemon", { pokemonName: getPokemonNameWithAffix(this.getPokemon()) })); - this.scene.time.delayedCall(250, () => this.summon()); + globalScene.ui.showText(i18next.t("battle:sendOutPokemon", { pokemonName: getPokemonNameWithAffix(this.getPokemon()) })); + globalScene.time.delayedCall(250, () => this.summon()); } } diff --git a/src/phases/summon-phase.ts b/src/phases/summon-phase.ts index 177e09c45275..bc4440c30984 100644 --- a/src/phases/summon-phase.ts +++ b/src/phases/summon-phase.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { BattleType } from "#app/battle"; import { getPokeballAtlasKey, getPokeballTintColor } from "#app/data/pokeball"; import { SpeciesFormChangeActiveTrigger } from "#app/data/pokemon-forms"; @@ -13,12 +12,13 @@ import { PostSummonPhase } from "./post-summon-phase"; import { GameOverPhase } from "./game-over-phase"; import { ShinySparklePhase } from "./shiny-sparkle-phase"; import { MysteryEncounterMode } from "#enums/mystery-encounter-mode"; +import { globalScene } from "#app/global-scene"; export class SummonPhase extends PartyMemberPokemonPhase { private loaded: boolean; - constructor(scene: BattleScene, fieldIndex: integer, player: boolean = true, loaded: boolean = false) { - super(scene, fieldIndex, player); + constructor(fieldIndex: integer, player: boolean = true, loaded: boolean = false) { + super(fieldIndex, player); this.loaded = loaded; } @@ -50,8 +50,8 @@ export class SummonPhase extends PartyMemberPokemonPhase { if (legalIndex === -1) { console.error("Party Details:\n", party); console.error("All available Pokemon were fainted or illegal!"); - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new GameOverPhase(this.scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new GameOverPhase()); this.end(); return; } @@ -62,33 +62,33 @@ export class SummonPhase extends PartyMemberPokemonPhase { } if (this.player) { - this.scene.ui.showText(i18next.t("battle:playerGo", { pokemonName: getPokemonNameWithAffix(this.getPokemon()) })); + globalScene.ui.showText(i18next.t("battle:playerGo", { pokemonName: getPokemonNameWithAffix(this.getPokemon()) })); if (this.player) { - this.scene.pbTray.hide(); + globalScene.pbTray.hide(); } - this.scene.trainer.setTexture(`trainer_${this.scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); - this.scene.time.delayedCall(562, () => { - this.scene.trainer.setFrame("2"); - this.scene.time.delayedCall(64, () => { - this.scene.trainer.setFrame("3"); + globalScene.trainer.setTexture(`trainer_${globalScene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); + globalScene.time.delayedCall(562, () => { + globalScene.trainer.setFrame("2"); + globalScene.time.delayedCall(64, () => { + globalScene.trainer.setFrame("3"); }); }); - this.scene.tweens.add({ - targets: this.scene.trainer, + globalScene.tweens.add({ + targets: globalScene.trainer, x: -36, duration: 1000, - onComplete: () => this.scene.trainer.setVisible(false) + onComplete: () => globalScene.trainer.setVisible(false) }); - this.scene.time.delayedCall(750, () => this.summon()); - } else if (this.scene.currentBattle.battleType === BattleType.TRAINER || this.scene.currentBattle.mysteryEncounter?.encounterMode === MysteryEncounterMode.TRAINER_BATTLE) { - const trainerName = this.scene.currentBattle.trainer?.getName(!(this.fieldIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); + globalScene.time.delayedCall(750, () => this.summon()); + } else if (globalScene.currentBattle.battleType === BattleType.TRAINER || globalScene.currentBattle.mysteryEncounter?.encounterMode === MysteryEncounterMode.TRAINER_BATTLE) { + const trainerName = globalScene.currentBattle.trainer?.getName(!(this.fieldIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); const pokemonName = this.getPokemon().getNameToRender(); const message = i18next.t("battle:trainerSendOut", { trainerName, pokemonName }); - this.scene.pbTrayEnemy.hide(); - this.scene.ui.showText(message, null, () => this.summon()); - } else if (this.scene.currentBattle.isBattleMysteryEncounter()) { - this.scene.pbTrayEnemy.hide(); + globalScene.pbTrayEnemy.hide(); + globalScene.ui.showText(message, null, () => this.summon()); + } else if (globalScene.currentBattle.isBattleMysteryEncounter()) { + globalScene.pbTrayEnemy.hide(); this.summonWild(); } } @@ -99,55 +99,55 @@ export class SummonPhase extends PartyMemberPokemonPhase { summon(): void { const pokemon = this.getPokemon(); - const pokeball = this.scene.addFieldSprite(this.player ? 36 : 248, this.player ? 80 : 44, "pb", getPokeballAtlasKey(pokemon.pokeball)); + const pokeball = globalScene.addFieldSprite(this.player ? 36 : 248, this.player ? 80 : 44, "pb", getPokeballAtlasKey(pokemon.pokeball)); pokeball.setVisible(false); pokeball.setOrigin(0.5, 0.625); - this.scene.field.add(pokeball); + globalScene.field.add(pokeball); if (this.fieldIndex === 1) { pokemon.setFieldPosition(FieldPosition.RIGHT, 0); } else { const availablePartyMembers = this.getParty().filter(p => p.isAllowedInBattle()).length; - pokemon.setFieldPosition(!this.scene.currentBattle.double || availablePartyMembers === 1 ? FieldPosition.CENTER : FieldPosition.LEFT); + pokemon.setFieldPosition(!globalScene.currentBattle.double || availablePartyMembers === 1 ? FieldPosition.CENTER : FieldPosition.LEFT); } const fpOffset = pokemon.getFieldPositionOffset(); pokeball.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, duration: 650, x: (this.player ? 100 : 236) + fpOffset[0] }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, duration: 150, ease: "Cubic.easeOut", y: (this.player ? 70 : 34) + fpOffset[1], onComplete: () => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokeball, duration: 500, ease: "Cubic.easeIn", angle: 1440, y: (this.player ? 132 : 86) + fpOffset[1], onComplete: () => { - this.scene.playSound("se/pb_rel"); + globalScene.playSound("se/pb_rel"); pokeball.destroy(); - this.scene.add.existing(pokemon); - this.scene.field.add(pokemon); + globalScene.add.existing(pokemon); + globalScene.field.add(pokemon); if (!this.player) { - const playerPokemon = this.scene.getPlayerPokemon() as Pokemon; + const playerPokemon = globalScene.getPlayerPokemon() as Pokemon; if (playerPokemon?.isOnField()) { - this.scene.field.moveBelow(pokemon, playerPokemon); + globalScene.field.moveBelow(pokemon, playerPokemon); } - this.scene.currentBattle.seenEnemyPartyMemberIds.add(pokemon.id); + globalScene.currentBattle.seenEnemyPartyMemberIds.add(pokemon.id); } - addPokeballOpenParticles(this.scene, pokemon.x, pokemon.y - 16, pokemon.pokeball); - this.scene.updateModifiers(this.player); - this.scene.updateFieldScale(); + addPokeballOpenParticles(pokemon.x, pokemon.y - 16, pokemon.pokeball); + globalScene.updateModifiers(this.player); + globalScene.updateFieldScale(); pokemon.showInfo(); pokemon.playAnim(); pokemon.setVisible(true); @@ -155,8 +155,8 @@ export class SummonPhase extends PartyMemberPokemonPhase { pokemon.setScale(0.5); pokemon.tint(getPokeballTintColor(pokemon.pokeball)); pokemon.untint(250, "Sine.easeIn"); - this.scene.updateFieldScale(); - this.scene.tweens.add({ + globalScene.updateFieldScale(); + globalScene.tweens.add({ targets: pokemon, duration: 250, ease: "Sine.easeIn", @@ -165,7 +165,7 @@ export class SummonPhase extends PartyMemberPokemonPhase { pokemon.cry(pokemon.getHpRatio() > 0.25 ? undefined : { rate: 0.85 }); pokemon.getSprite().clearTint(); pokemon.resetSummonData(); - this.scene.time.delayedCall(1000, () => this.end()); + globalScene.time.delayedCall(1000, () => this.end()); } }); } @@ -186,20 +186,20 @@ export class SummonPhase extends PartyMemberPokemonPhase { pokemon.setFieldPosition(FieldPosition.RIGHT, 0); } else { const availablePartyMembers = this.getParty().filter(p => !p.isFainted()).length; - pokemon.setFieldPosition(!this.scene.currentBattle.double || availablePartyMembers === 1 ? FieldPosition.CENTER : FieldPosition.LEFT); + pokemon.setFieldPosition(!globalScene.currentBattle.double || availablePartyMembers === 1 ? FieldPosition.CENTER : FieldPosition.LEFT); } - this.scene.add.existing(pokemon); - this.scene.field.add(pokemon); + globalScene.add.existing(pokemon); + globalScene.field.add(pokemon); if (!this.player) { - const playerPokemon = this.scene.getPlayerPokemon() as Pokemon; + const playerPokemon = globalScene.getPlayerPokemon() as Pokemon; if (playerPokemon?.isOnField()) { - this.scene.field.moveBelow(pokemon, playerPokemon); + globalScene.field.moveBelow(pokemon, playerPokemon); } - this.scene.currentBattle.seenEnemyPartyMemberIds.add(pokemon.id); + globalScene.currentBattle.seenEnemyPartyMemberIds.add(pokemon.id); } - this.scene.updateModifiers(this.player); - this.scene.updateFieldScale(); + globalScene.updateModifiers(this.player); + globalScene.updateFieldScale(); pokemon.showInfo(); pokemon.playAnim(); pokemon.setVisible(true); @@ -207,13 +207,13 @@ export class SummonPhase extends PartyMemberPokemonPhase { pokemon.setScale(0.75); pokemon.tint(getPokeballTintColor(pokemon.pokeball)); pokemon.untint(250, "Sine.easeIn"); - this.scene.updateFieldScale(); + globalScene.updateFieldScale(); pokemon.x += 16; pokemon.y -= 20; pokemon.alpha = 0; // Ease pokemon in - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, x: "-=16", y: "+=16", @@ -225,8 +225,8 @@ export class SummonPhase extends PartyMemberPokemonPhase { pokemon.cry(pokemon.getHpRatio() > 0.25 ? undefined : { rate: 0.85 }); pokemon.getSprite().clearTint(); pokemon.resetSummonData(); - this.scene.updateFieldScale(); - this.scene.time.delayedCall(1000, () => this.end()); + globalScene.updateFieldScale(); + globalScene.time.delayedCall(1000, () => this.end()); } }); } @@ -235,19 +235,19 @@ export class SummonPhase extends PartyMemberPokemonPhase { const pokemon = this.getPokemon(); if (pokemon.isShiny()) { - this.scene.unshiftPhase(new ShinySparklePhase(this.scene, pokemon.getBattlerIndex())); + globalScene.unshiftPhase(new ShinySparklePhase(pokemon.getBattlerIndex())); } pokemon.resetTurnData(); - if (!this.loaded || [ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(this.scene.currentBattle.battleType) || (this.scene.currentBattle.waveIndex % 10) === 1) { - this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); + if (!this.loaded || [ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(globalScene.currentBattle.battleType) || (globalScene.currentBattle.waveIndex % 10) === 1) { + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); this.queuePostSummon(); } } queuePostSummon(): void { - this.scene.pushPhase(new PostSummonPhase(this.scene, this.getPokemon().getBattlerIndex())); + globalScene.pushPhase(new PostSummonPhase(this.getPokemon().getBattlerIndex())); } end() { diff --git a/src/phases/switch-biome-phase.ts b/src/phases/switch-biome-phase.ts index 80a31794209e..e242268d572c 100644 --- a/src/phases/switch-biome-phase.ts +++ b/src/phases/switch-biome-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Biome } from "#app/enums/biome"; import { getBiomeKey } from "#app/field/arena"; import { BattlePhase } from "./battle-phase"; @@ -6,8 +6,8 @@ import { BattlePhase } from "./battle-phase"; export class SwitchBiomePhase extends BattlePhase { private nextBiome: Biome; - constructor(scene: BattleScene, nextBiome: Biome) { - super(scene); + constructor(nextBiome: Biome) { + super(); this.nextBiome = nextBiome; } @@ -19,41 +19,41 @@ export class SwitchBiomePhase extends BattlePhase { return this.end(); } - this.scene.tweens.add({ - targets: [ this.scene.arenaEnemy, this.scene.lastEnemyTrainer ], + globalScene.tweens.add({ + targets: [ globalScene.arenaEnemy, globalScene.lastEnemyTrainer ], x: "+=300", duration: 2000, onComplete: () => { - this.scene.arenaEnemy.setX(this.scene.arenaEnemy.x - 600); + globalScene.arenaEnemy.setX(globalScene.arenaEnemy.x - 600); - this.scene.newArena(this.nextBiome); + globalScene.newArena(this.nextBiome); const biomeKey = getBiomeKey(this.nextBiome); const bgTexture = `${biomeKey}_bg`; - this.scene.arenaBgTransition.setTexture(bgTexture); - this.scene.arenaBgTransition.setAlpha(0); - this.scene.arenaBgTransition.setVisible(true); - this.scene.arenaPlayerTransition.setBiome(this.nextBiome); - this.scene.arenaPlayerTransition.setAlpha(0); - this.scene.arenaPlayerTransition.setVisible(true); + globalScene.arenaBgTransition.setTexture(bgTexture); + globalScene.arenaBgTransition.setAlpha(0); + globalScene.arenaBgTransition.setVisible(true); + globalScene.arenaPlayerTransition.setBiome(this.nextBiome); + globalScene.arenaPlayerTransition.setAlpha(0); + globalScene.arenaPlayerTransition.setVisible(true); - this.scene.tweens.add({ - targets: [ this.scene.arenaPlayer, this.scene.arenaBgTransition, this.scene.arenaPlayerTransition ], + globalScene.tweens.add({ + targets: [ globalScene.arenaPlayer, globalScene.arenaBgTransition, globalScene.arenaPlayerTransition ], duration: 1000, delay: 1000, ease: "Sine.easeInOut", - alpha: (target: any) => target === this.scene.arenaPlayer ? 0 : 1, + alpha: (target: any) => target === globalScene.arenaPlayer ? 0 : 1, onComplete: () => { - this.scene.arenaBg.setTexture(bgTexture); - this.scene.arenaPlayer.setBiome(this.nextBiome); - this.scene.arenaPlayer.setAlpha(1); - this.scene.arenaEnemy.setBiome(this.nextBiome); - this.scene.arenaEnemy.setAlpha(1); - this.scene.arenaNextEnemy.setBiome(this.nextBiome); - this.scene.arenaBgTransition.setVisible(false); - this.scene.arenaPlayerTransition.setVisible(false); - if (this.scene.lastEnemyTrainer) { - this.scene.lastEnemyTrainer.destroy(); + globalScene.arenaBg.setTexture(bgTexture); + globalScene.arenaPlayer.setBiome(this.nextBiome); + globalScene.arenaPlayer.setAlpha(1); + globalScene.arenaEnemy.setBiome(this.nextBiome); + globalScene.arenaEnemy.setAlpha(1); + globalScene.arenaNextEnemy.setBiome(this.nextBiome); + globalScene.arenaBgTransition.setVisible(false); + globalScene.arenaPlayerTransition.setVisible(false); + if (globalScene.lastEnemyTrainer) { + globalScene.lastEnemyTrainer.destroy(); } this.end(); diff --git a/src/phases/switch-phase.ts b/src/phases/switch-phase.ts index 481d64c451ee..e763aee15212 100644 --- a/src/phases/switch-phase.ts +++ b/src/phases/switch-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import PartyUiHandler, { PartyOption, PartyUiMode } from "#app/ui/party-ui-handler"; import { Mode } from "#app/ui/ui"; import { SwitchType } from "#enums/switch-type"; @@ -18,7 +18,6 @@ export class SwitchPhase extends BattlePhase { /** * Creates a new SwitchPhase - * @param scene {@linkcode BattleScene} Current battle scene * @param switchType {@linkcode SwitchType} The type of switch logic this phase implements * @param fieldIndex Field index to switch out * @param isModal Indicates if the switch should be forced (true) or is @@ -26,8 +25,8 @@ export class SwitchPhase extends BattlePhase { * @param doReturn Indicates if the party member on the field should be * recalled to ball or has already left the field. Passed to {@linkcode SwitchSummonPhase}. */ - constructor(scene: BattleScene, switchType: SwitchType, fieldIndex: integer, isModal: boolean, doReturn: boolean) { - super(scene); + constructor(switchType: SwitchType, fieldIndex: integer, isModal: boolean, doReturn: boolean) { + super(); this.switchType = switchType; this.fieldIndex = fieldIndex; @@ -39,7 +38,7 @@ export class SwitchPhase extends BattlePhase { super.start(); // Skip modal switch if impossible (no remaining party members that aren't in battle) - if (this.isModal && !this.scene.getPlayerParty().filter(p => p.isAllowedInBattle() && !p.isActive(true)).length) { + if (this.isModal && !globalScene.getPlayerParty().filter(p => p.isAllowedInBattle() && !p.isActive(true)).length) { return super.end(); } @@ -50,27 +49,27 @@ export class SwitchPhase extends BattlePhase { * if the mon should have already been returned but is still alive and well * on the field. see also; battle.test.ts */ - if (this.isModal && !this.doReturn && !this.scene.getPlayerParty()[this.fieldIndex].isFainted()) { + if (this.isModal && !this.doReturn && !globalScene.getPlayerParty()[this.fieldIndex].isFainted()) { return super.end(); } // Check if there is any space still in field - if (this.isModal && this.scene.getPlayerField().filter(p => p.isAllowedInBattle() && p.isActive(true)).length >= this.scene.currentBattle.getBattlerCount()) { + if (this.isModal && globalScene.getPlayerField().filter(p => p.isAllowedInBattle() && p.isActive(true)).length >= globalScene.currentBattle.getBattlerCount()) { return super.end(); } // Override field index to 0 in case of double battle where 2/3 remaining legal party members fainted at once - const fieldIndex = this.scene.currentBattle.getBattlerCount() === 1 || this.scene.getPokemonAllowedInBattle().length > 1 ? this.fieldIndex : 0; + const fieldIndex = globalScene.currentBattle.getBattlerCount() === 1 || globalScene.getPokemonAllowedInBattle().length > 1 ? this.fieldIndex : 0; - this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.POST_BATTLE_SWITCH, fieldIndex, (slotIndex: integer, option: PartyOption) => { - if (slotIndex >= this.scene.currentBattle.getBattlerCount() && slotIndex < 6) { + globalScene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.POST_BATTLE_SWITCH, fieldIndex, (slotIndex: integer, option: PartyOption) => { + if (slotIndex >= globalScene.currentBattle.getBattlerCount() && slotIndex < 6) { // Remove any pre-existing PostSummonPhase under the same field index. // Pre-existing PostSummonPhases may occur when this phase is invoked during a prompt to switch at the start of a wave. - this.scene.tryRemovePhase(p => p instanceof PostSummonPhase && p.player && p.fieldIndex === this.fieldIndex); + globalScene.tryRemovePhase(p => p instanceof PostSummonPhase && p.player && p.fieldIndex === this.fieldIndex); const switchType = (option === PartyOption.PASS_BATON) ? SwitchType.BATON_PASS : this.switchType; - this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, switchType, fieldIndex, slotIndex, this.doReturn)); + globalScene.unshiftPhase(new SwitchSummonPhase(switchType, fieldIndex, slotIndex, this.doReturn)); } - this.scene.ui.setMode(Mode.MESSAGE).then(() => super.end()); + globalScene.ui.setMode(Mode.MESSAGE).then(() => super.end()); }, PartyUiHandler.FilterNonFainted); } } diff --git a/src/phases/switch-summon-phase.ts b/src/phases/switch-summon-phase.ts index a1925768d836..056e76e582d3 100644 --- a/src/phases/switch-summon-phase.ts +++ b/src/phases/switch-summon-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { applyPreSwitchOutAbAttrs, PostDamageForceSwitchAbAttr, PreSwitchOutAbAttr } from "#app/data/ability"; import { allMoves, ForceSwitchOutAttr } from "#app/data/move"; import { getPokeballTintColor } from "#app/data/pokeball"; @@ -23,15 +23,14 @@ export class SwitchSummonPhase extends SummonPhase { /** * Constructor for creating a new SwitchSummonPhase - * @param scene {@linkcode BattleScene} the scene the phase is associated with * @param switchType the type of switch behavior * @param fieldIndex integer representing position on the battle field * @param slotIndex integer for the index of pokemon (in party of 6) to switch into * @param doReturn boolean whether to render "comeback" dialogue * @param player boolean if the switch is from the player */ - constructor(scene: BattleScene, switchType: SwitchType, fieldIndex: integer, slotIndex: integer, doReturn: boolean, player?: boolean) { - super(scene, fieldIndex, player !== undefined ? player : true); + constructor(switchType: SwitchType, fieldIndex: integer, slotIndex: integer, doReturn: boolean, player?: boolean) { + super(fieldIndex, player !== undefined ? player : true); this.switchType = switchType; this.slotIndex = slotIndex; @@ -46,29 +45,29 @@ export class SwitchSummonPhase extends SummonPhase { if (!this.player) { if (this.slotIndex === -1) { //@ts-ignore - this.slotIndex = this.scene.currentBattle.trainer?.getNextSummonIndex(!this.fieldIndex ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); // TODO: what would be the default trainer-slot fallback? + this.slotIndex = globalScene.currentBattle.trainer?.getNextSummonIndex(!this.fieldIndex ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); // TODO: what would be the default trainer-slot fallback? } if (this.slotIndex > -1) { this.showEnemyTrainer(!(this.fieldIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); - this.scene.pbTrayEnemy.showPbTray(this.scene.getEnemyParty()); + globalScene.pbTrayEnemy.showPbTray(globalScene.getEnemyParty()); } } - if (!this.doReturn || (this.slotIndex !== -1 && !(this.player ? this.scene.getPlayerParty() : this.scene.getEnemyParty())[this.slotIndex])) { + if (!this.doReturn || (this.slotIndex !== -1 && !(this.player ? globalScene.getPlayerParty() : globalScene.getEnemyParty())[this.slotIndex])) { if (this.player) { return this.switchAndSummon(); } else { - this.scene.time.delayedCall(750, () => this.switchAndSummon()); + globalScene.time.delayedCall(750, () => this.switchAndSummon()); return; } } const pokemon = this.getPokemon(); - (this.player ? this.scene.getEnemyField() : this.scene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.removeTagsBySourceId(pokemon.id)); + (this.player ? globalScene.getEnemyField() : globalScene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.removeTagsBySourceId(pokemon.id)); if (this.switchType === SwitchType.SWITCH || this.switchType === SwitchType.INITIAL_SWITCH) { const substitute = pokemon.getTag(SubstituteTag); if (substitute) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: substitute.sprite, duration: 250, scale: substitute.sprite.scale * 0.5, @@ -78,40 +77,40 @@ export class SwitchSummonPhase extends SummonPhase { } } - this.scene.ui.showText(this.player ? + globalScene.ui.showText(this.player ? i18next.t("battle:playerComeBack", { pokemonName: getPokemonNameWithAffix(pokemon) }) : i18next.t("battle:trainerComeBack", { - trainerName: this.scene.currentBattle.trainer?.getName(!(this.fieldIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER), + trainerName: globalScene.currentBattle.trainer?.getName(!(this.fieldIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER), pokemonName: pokemon.getNameToRender() }) ); - this.scene.playSound("se/pb_rel"); + globalScene.playSound("se/pb_rel"); pokemon.hideInfo(); pokemon.tint(getPokeballTintColor(pokemon.pokeball), 1, 250, "Sine.easeIn"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: pokemon, duration: 250, ease: "Sine.easeIn", scale: 0.5, onComplete: () => { pokemon.leaveField(this.switchType === SwitchType.SWITCH, false); - this.scene.time.delayedCall(750, () => this.switchAndSummon()); + globalScene.time.delayedCall(750, () => this.switchAndSummon()); } }); } switchAndSummon() { - const party = this.player ? this.getParty() : this.scene.getEnemyParty(); + const party = this.player ? this.getParty() : globalScene.getEnemyParty(); const switchedInPokemon = party[this.slotIndex]; this.lastPokemon = this.getPokemon(); applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, this.lastPokemon); if (this.switchType === SwitchType.BATON_PASS && switchedInPokemon) { - (this.player ? this.scene.getEnemyField() : this.scene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.transferTagsBySourceId(this.lastPokemon.id, switchedInPokemon.id)); - if (!this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === switchedInPokemon.id)) { - const batonPassModifier = this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier + (this.player ? globalScene.getEnemyField() : globalScene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.transferTagsBySourceId(this.lastPokemon.id, switchedInPokemon.id)); + if (!globalScene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === switchedInPokemon.id)) { + const batonPassModifier = globalScene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === this.lastPokemon.id) as SwitchEffectTransferModifier; - if (batonPassModifier && !this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === switchedInPokemon.id)) { - this.scene.tryTransferHeldItemModifier(batonPassModifier, switchedInPokemon, false, undefined, undefined, undefined, false); + if (batonPassModifier && !globalScene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === switchedInPokemon.id)) { + globalScene.tryTransferHeldItemModifier(batonPassModifier, switchedInPokemon, false, undefined, undefined, undefined, false); } } } @@ -119,10 +118,10 @@ export class SwitchSummonPhase extends SummonPhase { party[this.slotIndex] = this.lastPokemon; party[this.fieldIndex] = switchedInPokemon; const showTextAndSummon = () => { - this.scene.ui.showText(this.player ? + globalScene.ui.showText(this.player ? i18next.t("battle:playerGo", { pokemonName: getPokemonNameWithAffix(switchedInPokemon) }) : i18next.t("battle:trainerGo", { - trainerName: this.scene.currentBattle.trainer?.getName(!(this.fieldIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER), + trainerName: globalScene.currentBattle.trainer?.getName(!(this.fieldIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER), pokemonName: this.getPokemon().getNameToRender() }) ); @@ -145,9 +144,9 @@ export class SwitchSummonPhase extends SummonPhase { if (this.player) { showTextAndSummon(); } else { - this.scene.time.delayedCall(1500, () => { + globalScene.time.delayedCall(1500, () => { this.hideEnemyTrainer(); - this.scene.pbTrayEnemy.hide(); + globalScene.pbTrayEnemy.hide(); showTextAndSummon(); }); } @@ -161,10 +160,10 @@ export class SwitchSummonPhase extends SummonPhase { const pokemon = this.getPokemon(); - const moveId = this.lastPokemon?.scene.currentBattle.lastMove; + const moveId = globalScene.currentBattle.lastMove; const lastUsedMove = moveId ? allMoves[moveId] : undefined; - const currentCommand = pokemon.scene.currentBattle.turnCommands[this.fieldIndex]?.command; + const currentCommand = globalScene.currentBattle.turnCommands[this.fieldIndex]?.command; const lastPokemonIsForceSwitchedAndNotFainted = lastUsedMove?.hasAttr(ForceSwitchOutAttr) && !this.lastPokemon.isFainted(); const lastPokemonHasForceSwitchAbAttr = this.lastPokemon.hasAbilityWithAttr(PostDamageForceSwitchAbAttr) && !this.lastPokemon.isFainted(); @@ -191,12 +190,12 @@ export class SwitchSummonPhase extends SummonPhase { this.lastPokemon?.resetSummonData(); - this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); // Reverts to weather-based forms when weather suppressors (Cloud Nine/Air Lock) are switched out - this.scene.arena.triggerWeatherBasedFormChanges(); + globalScene.arena.triggerWeatherBasedFormChanges(); } queuePostSummon(): void { - this.scene.unshiftPhase(new PostSummonPhase(this.scene, this.getPokemon().getBattlerIndex())); + globalScene.unshiftPhase(new PostSummonPhase(this.getPokemon().getBattlerIndex())); } } diff --git a/src/phases/test-message-phase.ts b/src/phases/test-message-phase.ts index 464a5ed1f946..d5e74efd4904 100644 --- a/src/phases/test-message-phase.ts +++ b/src/phases/test-message-phase.ts @@ -1,8 +1,7 @@ -import BattleScene from "#app/battle-scene"; import { MessagePhase } from "./message-phase"; export class TestMessagePhase extends MessagePhase { - constructor(scene: BattleScene, message: string) { - super(scene, message, null, true); + constructor(message: string) { + super(message, null, true); } } diff --git a/src/phases/title-phase.ts b/src/phases/title-phase.ts index 887936177765..8d8615e315b9 100644 --- a/src/phases/title-phase.ts +++ b/src/phases/title-phase.ts @@ -1,6 +1,5 @@ import { loggedInUser } from "#app/account"; import { BattleType } from "#app/battle"; -import BattleScene from "#app/battle-scene"; import { fetchDailyRunSeed, getDailyRunStarters } from "#app/data/daily-run"; import { Gender } from "#app/data/gender"; import { getBiomeKey } from "#app/field/arena"; @@ -21,6 +20,7 @@ import { EncounterPhase } from "./encounter-phase"; import { SelectChallengePhase } from "./select-challenge-phase"; import { SelectStarterPhase } from "./select-starter-phase"; import { SummonPhase } from "./summon-phase"; +import { globalScene } from "#app/global-scene"; export class TitlePhase extends Phase { @@ -28,8 +28,8 @@ export class TitlePhase extends Phase { private lastSessionData: SessionSaveData; public gameMode: GameModes; - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); this.loaded = false; } @@ -37,17 +37,17 @@ export class TitlePhase extends Phase { start(): void { super.start(); - this.scene.ui.clearText(); - this.scene.ui.fadeIn(250); + globalScene.ui.clearText(); + globalScene.ui.fadeIn(250); - this.scene.playBgm("title", true); + globalScene.playBgm("title", true); - this.scene.gameData.getSession(loggedInUser?.lastSessionSlot ?? -1).then(sessionData => { + globalScene.gameData.getSession(loggedInUser?.lastSessionSlot ?? -1).then(sessionData => { if (sessionData) { this.lastSessionData = sessionData; const biomeKey = getBiomeKey(sessionData.arena.biome); const bgTexture = `${biomeKey}_bg`; - this.scene.arenaBg.setTexture(bgTexture); + globalScene.arenaBg.setTexture(bgTexture); } this.showOptions(); }).catch(err => { @@ -72,11 +72,11 @@ export class TitlePhase extends Phase { handler: () => { const setModeAndEnd = (gameMode: GameModes) => { this.gameMode = gameMode; - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.clearText(); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.clearText(); this.end(); }; - const { gameData } = this.scene; + const { gameData } = globalScene; if (gameData.isUnlocked(Unlockables.ENDLESS_MODE)) { const options: OptionSelectItem[] = [ { @@ -113,17 +113,17 @@ export class TitlePhase extends Phase { options.push({ label: i18next.t("menu:cancel"), handler: () => { - this.scene.clearPhaseQueue(); - this.scene.pushPhase(new TitlePhase(this.scene)); + globalScene.clearPhaseQueue(); + globalScene.pushPhase(new TitlePhase()); super.end(); return true; } }); - this.scene.ui.showText(i18next.t("menu:selectGameMode"), null, () => this.scene.ui.setOverlayMode(Mode.OPTION_SELECT, { options: options })); + globalScene.ui.showText(i18next.t("menu:selectGameMode"), null, () => globalScene.ui.setOverlayMode(Mode.OPTION_SELECT, { options: options })); } else { this.gameMode = GameModes.CLASSIC; - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.clearText(); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.clearText(); this.end(); } return true; @@ -132,7 +132,7 @@ export class TitlePhase extends Phase { { label: i18next.t("menu:loadGame"), handler: () => { - this.scene.ui.setOverlayMode(Mode.SAVE_SLOT, SaveSlotUiMode.LOAD, + globalScene.ui.setOverlayMode(Mode.SAVE_SLOT, SaveSlotUiMode.LOAD, (slotId: integer) => { if (slotId === -1) { return this.showOptions(); @@ -153,7 +153,7 @@ export class TitlePhase extends Phase { { label: i18next.t("menu:settings"), handler: () => { - this.scene.ui.setOverlayMode(Mode.SETTINGS); + globalScene.ui.setOverlayMode(Mode.SETTINGS); return true; }, keepOpen: true @@ -163,55 +163,55 @@ export class TitlePhase extends Phase { noCancel: true, yOffset: 47 }; - this.scene.ui.setMode(Mode.TITLE, config); + globalScene.ui.setMode(Mode.TITLE, config); } loadSaveSlot(slotId: integer): void { - this.scene.sessionSlotId = slotId > -1 || !loggedInUser ? slotId : loggedInUser.lastSessionSlot; - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.resetModeChain(); - this.scene.gameData.loadSession(this.scene, slotId, slotId === -1 ? this.lastSessionData : undefined).then((success: boolean) => { + globalScene.sessionSlotId = slotId > -1 || !loggedInUser ? slotId : loggedInUser.lastSessionSlot; + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.resetModeChain(); + globalScene.gameData.loadSession(slotId, slotId === -1 ? this.lastSessionData : undefined).then((success: boolean) => { if (success) { this.loaded = true; - this.scene.ui.showText(i18next.t("menu:sessionSuccess"), null, () => this.end()); + globalScene.ui.showText(i18next.t("menu:sessionSuccess"), null, () => this.end()); } else { this.end(); } }).catch(err => { console.error(err); - this.scene.ui.showText(i18next.t("menu:failedToLoadSession"), null); + globalScene.ui.showText(i18next.t("menu:failedToLoadSession"), null); }); } initDailyRun(): void { - this.scene.ui.setMode(Mode.SAVE_SLOT, SaveSlotUiMode.SAVE, (slotId: integer) => { - this.scene.clearPhaseQueue(); + globalScene.ui.setMode(Mode.SAVE_SLOT, SaveSlotUiMode.SAVE, (slotId: integer) => { + globalScene.clearPhaseQueue(); if (slotId === -1) { - this.scene.pushPhase(new TitlePhase(this.scene)); + globalScene.pushPhase(new TitlePhase()); return super.end(); } - this.scene.sessionSlotId = slotId; + globalScene.sessionSlotId = slotId; const generateDaily = (seed: string) => { - this.scene.gameMode = getGameMode(GameModes.DAILY); + globalScene.gameMode = getGameMode(GameModes.DAILY); - this.scene.setSeed(seed); - this.scene.resetSeed(0); + globalScene.setSeed(seed); + globalScene.resetSeed(0); - this.scene.money = this.scene.gameMode.getStartingMoney(); + globalScene.money = globalScene.gameMode.getStartingMoney(); - const starters = getDailyRunStarters(this.scene, seed); - const startingLevel = this.scene.gameMode.getStartingLevel(); + const starters = getDailyRunStarters(seed); + const startingLevel = globalScene.gameMode.getStartingLevel(); - const party = this.scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); const loadPokemonAssets: Promise[] = []; for (const starter of starters) { - const starterProps = this.scene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr); + const starterProps = globalScene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr); const starterFormIndex = Math.min(starterProps.formIndex, Math.max(starter.species.forms.length - 1, 0)); const starterGender = starter.species.malePercent !== null ? !starterProps.female ? Gender.MALE : Gender.FEMALE : Gender.GENDERLESS; - const starterPokemon = this.scene.addPlayerPokemon(starter.species, startingLevel, starter.abilityIndex, starterFormIndex, starterGender, starterProps.shiny, starterProps.variant, undefined, starter.nature); + const starterPokemon = globalScene.addPlayerPokemon(starter.species, startingLevel, starter.abilityIndex, starterFormIndex, starterGender, starterProps.shiny, starterProps.variant, undefined, starter.nature); starterPokemon.setVisible(false); party.push(starterPokemon); loadPokemonAssets.push(starterPokemon.loadAssets()); @@ -226,18 +226,18 @@ export class TitlePhase extends Phase { .filter((m) => m !== null); for (const m of modifiers) { - this.scene.addModifier(m, true, false, false, true); + globalScene.addModifier(m, true, false, false, true); } - this.scene.updateModifiers(true, true); + globalScene.updateModifiers(true, true); Promise.all(loadPokemonAssets).then(() => { - this.scene.time.delayedCall(500, () => this.scene.playBgm()); - this.scene.gameData.gameStats.dailyRunSessionsPlayed++; - this.scene.newArena(this.scene.gameMode.getStartingBiome(this.scene)); - this.scene.newBattle(); - this.scene.arena.init(); - this.scene.sessionPlayTime = 0; - this.scene.lastSavePlayTime = 0; + globalScene.time.delayedCall(500, () => globalScene.playBgm()); + globalScene.gameData.gameStats.dailyRunSessionsPlayed++; + globalScene.newArena(globalScene.gameMode.getStartingBiome()); + globalScene.newBattle(); + globalScene.arena.init(); + globalScene.sessionPlayTime = 0; + globalScene.lastSavePlayTime = 0; this.end(); }); }; @@ -260,43 +260,43 @@ export class TitlePhase extends Phase { } end(): void { - if (!this.loaded && !this.scene.gameMode.isDaily) { - this.scene.arena.preloadBgm(); - this.scene.gameMode = getGameMode(this.gameMode); + if (!this.loaded && !globalScene.gameMode.isDaily) { + globalScene.arena.preloadBgm(); + globalScene.gameMode = getGameMode(this.gameMode); if (this.gameMode === GameModes.CHALLENGE) { - this.scene.pushPhase(new SelectChallengePhase(this.scene)); + globalScene.pushPhase(new SelectChallengePhase()); } else { - this.scene.pushPhase(new SelectStarterPhase(this.scene)); + globalScene.pushPhase(new SelectStarterPhase()); } - this.scene.newArena(this.scene.gameMode.getStartingBiome(this.scene)); + globalScene.newArena(globalScene.gameMode.getStartingBiome()); } else { - this.scene.playBgm(); + globalScene.playBgm(); } - this.scene.pushPhase(new EncounterPhase(this.scene, this.loaded)); + globalScene.pushPhase(new EncounterPhase(this.loaded)); if (this.loaded) { - const availablePartyMembers = this.scene.getPokemonAllowedInBattle().length; + const availablePartyMembers = globalScene.getPokemonAllowedInBattle().length; - this.scene.pushPhase(new SummonPhase(this.scene, 0, true, true)); - if (this.scene.currentBattle.double && availablePartyMembers > 1) { - this.scene.pushPhase(new SummonPhase(this.scene, 1, true, true)); + globalScene.pushPhase(new SummonPhase(0, true, true)); + if (globalScene.currentBattle.double && availablePartyMembers > 1) { + globalScene.pushPhase(new SummonPhase(1, true, true)); } - if (this.scene.currentBattle.battleType !== BattleType.TRAINER && (this.scene.currentBattle.waveIndex > 1 || !this.scene.gameMode.isDaily)) { - const minPartySize = this.scene.currentBattle.double ? 2 : 1; + if (globalScene.currentBattle.battleType !== BattleType.TRAINER && (globalScene.currentBattle.waveIndex > 1 || !globalScene.gameMode.isDaily)) { + const minPartySize = globalScene.currentBattle.double ? 2 : 1; if (availablePartyMembers > minPartySize) { - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 0, this.scene.currentBattle.double)); - if (this.scene.currentBattle.double) { - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); + globalScene.pushPhase(new CheckSwitchPhase(0, globalScene.currentBattle.double)); + if (globalScene.currentBattle.double) { + globalScene.pushPhase(new CheckSwitchPhase(1, globalScene.currentBattle.double)); } } } } - for (const achv of Object.keys(this.scene.gameData.achvUnlocks)) { + for (const achv of Object.keys(globalScene.gameData.achvUnlocks)) { if (vouchers.hasOwnProperty(achv) && achv !== "CLASSIC_VICTORY") { - this.scene.validateVoucher(vouchers[achv]); + globalScene.validateVoucher(vouchers[achv]); } } diff --git a/src/phases/toggle-double-position-phase.ts b/src/phases/toggle-double-position-phase.ts index eff92bc6acd8..f61577444d21 100644 --- a/src/phases/toggle-double-position-phase.ts +++ b/src/phases/toggle-double-position-phase.ts @@ -1,12 +1,12 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { FieldPosition } from "#app/field/pokemon"; import { BattlePhase } from "./battle-phase"; export class ToggleDoublePositionPhase extends BattlePhase { private double: boolean; - constructor(scene: BattleScene, double: boolean) { - super(scene); + constructor(double: boolean) { + super(); this.double = double; } @@ -14,11 +14,11 @@ export class ToggleDoublePositionPhase extends BattlePhase { start() { super.start(); - const playerPokemon = this.scene.getPlayerField().find(p => p.isActive(true)); + const playerPokemon = globalScene.getPlayerField().find(p => p.isActive(true)); if (playerPokemon) { - playerPokemon.setFieldPosition(this.double && this.scene.getPokemonAllowedInBattle().length > 1 ? FieldPosition.LEFT : FieldPosition.CENTER, 500).then(() => { + playerPokemon.setFieldPosition(this.double && globalScene.getPokemonAllowedInBattle().length > 1 ? FieldPosition.LEFT : FieldPosition.CENTER, 500).then(() => { if (playerPokemon.getFieldIndex() === 1) { - const party = this.scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); party[1] = party[0]; party[0] = playerPokemon; } diff --git a/src/phases/trainer-message-test-phase.ts b/src/phases/trainer-message-test-phase.ts index d9e58473bd51..64883157fd16 100644 --- a/src/phases/trainer-message-test-phase.ts +++ b/src/phases/trainer-message-test-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { trainerConfigs } from "#app/data/trainer-config"; import { TrainerType } from "#app/enums/trainer-type"; import { BattlePhase } from "./battle-phase"; @@ -7,8 +7,8 @@ import { TestMessagePhase } from "./test-message-phase"; export class TrainerMessageTestPhase extends BattlePhase { private trainerTypes: TrainerType[]; - constructor(scene: BattleScene, ...trainerTypes: TrainerType[]) { - super(scene); + constructor(...trainerTypes: TrainerType[]) { + super(); this.trainerTypes = trainerTypes; } @@ -33,7 +33,7 @@ export class TrainerMessageTestPhase extends BattlePhase { } for (const message of testMessages) { - this.scene.pushPhase(new TestMessagePhase(this.scene, message)); + globalScene.pushPhase(new TestMessagePhase(message)); } this.end(); diff --git a/src/phases/trainer-victory-phase.ts b/src/phases/trainer-victory-phase.ts index d797e4360acb..3fa7209751a5 100644 --- a/src/phases/trainer-victory-phase.ts +++ b/src/phases/trainer-victory-phase.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { getCharVariantFromDialogue } from "#app/data/dialogue"; import { TrainerType } from "#app/enums/trainer-type"; import { modifierTypes } from "#app/modifier/modifier-type"; @@ -9,63 +8,66 @@ import { BattlePhase } from "./battle-phase"; import { ModifierRewardPhase } from "./modifier-reward-phase"; import { MoneyRewardPhase } from "./money-reward-phase"; import { TrainerSlot } from "#app/data/trainer-config"; +import { globalScene } from "#app/global-scene"; import { Biome } from "#app/enums/biome"; import { achvs } from "#app/system/achv"; export class TrainerVictoryPhase extends BattlePhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { - this.scene.disableMenu = true; + globalScene.disableMenu = true; - this.scene.playBgm(this.scene.currentBattle.trainer?.config.victoryBgm); + globalScene.playBgm(globalScene.currentBattle.trainer?.config.victoryBgm); - this.scene.unshiftPhase(new MoneyRewardPhase(this.scene, this.scene.currentBattle.trainer?.config.moneyMultiplier!)); // TODO: is this bang correct? + globalScene.unshiftPhase(new MoneyRewardPhase(globalScene.currentBattle.trainer?.config.moneyMultiplier!)); // TODO: is this bang correct? - const modifierRewardFuncs = this.scene.currentBattle.trainer?.config.modifierRewardFuncs!; // TODO: is this bang correct? + const modifierRewardFuncs = globalScene.currentBattle.trainer?.config.modifierRewardFuncs!; // TODO: is this bang correct? for (const modifierRewardFunc of modifierRewardFuncs) { - this.scene.unshiftPhase(new ModifierRewardPhase(this.scene, modifierRewardFunc)); + globalScene.unshiftPhase(new ModifierRewardPhase(modifierRewardFunc)); } - if (this.scene.eventManager.isEventActive()) { - for (const rewardFunc of this.scene.currentBattle.trainer?.config.eventRewardFuncs!) { - this.scene.unshiftPhase(new ModifierRewardPhase(this.scene, rewardFunc)); + if (globalScene.eventManager.isEventActive()) { + for (const rewardFunc of globalScene.currentBattle.trainer?.config.eventRewardFuncs!) { + globalScene.unshiftPhase(new ModifierRewardPhase(rewardFunc)); } } - const trainerType = this.scene.currentBattle.trainer?.config.trainerType!; // TODO: is this bang correct? + const trainerType = globalScene.currentBattle.trainer?.config.trainerType!; // TODO: is this bang correct? // Validate Voucher for boss trainers if (vouchers.hasOwnProperty(TrainerType[trainerType])) { - if (!this.scene.validateVoucher(vouchers[TrainerType[trainerType]]) && this.scene.currentBattle.trainer?.config.isBoss) { - this.scene.unshiftPhase(new ModifierRewardPhase(this.scene, [ modifierTypes.VOUCHER, modifierTypes.VOUCHER, modifierTypes.VOUCHER_PLUS, modifierTypes.VOUCHER_PREMIUM ][vouchers[TrainerType[trainerType]].voucherType])); + if (!globalScene.validateVoucher(vouchers[TrainerType[trainerType]]) && globalScene.currentBattle.trainer?.config.isBoss) { + globalScene.unshiftPhase(new ModifierRewardPhase([ modifierTypes.VOUCHER, modifierTypes.VOUCHER, modifierTypes.VOUCHER_PLUS, modifierTypes.VOUCHER_PREMIUM ][vouchers[TrainerType[trainerType]].voucherType])); } } // Breeders in Space achievement - if (this.scene.arena.biomeType === Biome.SPACE - && (trainerType === TrainerType.BREEDER || trainerType === TrainerType.EXPERT_POKEMON_BREEDER)) { - this.scene.validateAchv(achvs.BREEDERS_IN_SPACE); + if ( + globalScene.arena.biomeType === Biome.SPACE + && (trainerType === TrainerType.BREEDER || trainerType === TrainerType.EXPERT_POKEMON_BREEDER) + ) { + globalScene.validateAchv(achvs.BREEDERS_IN_SPACE); } - this.scene.ui.showText(i18next.t("battle:trainerDefeated", { trainerName: this.scene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }), null, () => { - const victoryMessages = this.scene.currentBattle.trainer?.getVictoryMessages()!; // TODO: is this bang correct? + globalScene.ui.showText(i18next.t("battle:trainerDefeated", { trainerName: globalScene.currentBattle.trainer?.getName(TrainerSlot.NONE, true) }), null, () => { + const victoryMessages = globalScene.currentBattle.trainer?.getVictoryMessages()!; // TODO: is this bang correct? let message: string; - this.scene.executeWithSeedOffset(() => message = Utils.randSeedItem(victoryMessages), this.scene.currentBattle.waveIndex); + globalScene.executeWithSeedOffset(() => message = Utils.randSeedItem(victoryMessages), globalScene.currentBattle.waveIndex); message = message!; // tell TS compiler it's defined now const showMessage = () => { const originalFunc = showMessageOrEnd; - showMessageOrEnd = () => this.scene.ui.showDialogue(message, this.scene.currentBattle.trainer?.getName(TrainerSlot.TRAINER, true), null, originalFunc); + showMessageOrEnd = () => globalScene.ui.showDialogue(message, globalScene.currentBattle.trainer?.getName(TrainerSlot.TRAINER, true), null, originalFunc); showMessageOrEnd(); }; let showMessageOrEnd = () => this.end(); if (victoryMessages?.length) { - if (this.scene.currentBattle.trainer?.config.hasCharSprite && !this.scene.ui.shouldSkipDialogue(message)) { + if (globalScene.currentBattle.trainer?.config.hasCharSprite && !globalScene.ui.shouldSkipDialogue(message)) { const originalFunc = showMessageOrEnd; - showMessageOrEnd = () => this.scene.charSprite.hide().then(() => this.scene.hideFieldOverlay(250).then(() => originalFunc())); - this.scene.showFieldOverlay(500).then(() => this.scene.charSprite.showCharacter(this.scene.currentBattle.trainer?.getKey()!, getCharVariantFromDialogue(victoryMessages[0])).then(() => showMessage())); // TODO: is this bang correct? + showMessageOrEnd = () => globalScene.charSprite.hide().then(() => globalScene.hideFieldOverlay(250).then(() => originalFunc())); + globalScene.showFieldOverlay(500).then(() => globalScene.charSprite.showCharacter(globalScene.currentBattle.trainer?.getKey()!, getCharVariantFromDialogue(victoryMessages[0])).then(() => showMessage())); // TODO: is this bang correct? } else { showMessage(); } diff --git a/src/phases/turn-end-phase.ts b/src/phases/turn-end-phase.ts index e5f1850758da..3316f1a7247b 100644 --- a/src/phases/turn-end-phase.ts +++ b/src/phases/turn-end-phase.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { applyPostTurnAbAttrs, PostTurnAbAttr } from "#app/data/ability"; import { BattlerTagLapseType } from "#app/data/battler-tags"; import { TerrainType } from "#app/data/terrain"; @@ -10,40 +9,41 @@ import { TurnHealModifier, EnemyTurnHealModifier, EnemyStatusEffectHealChanceMod import i18next from "i18next"; import { FieldPhase } from "./field-phase"; import { PokemonHealPhase } from "./pokemon-heal-phase"; +import { globalScene } from "#app/global-scene"; export class TurnEndPhase extends FieldPhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - this.scene.currentBattle.incrementTurn(this.scene); - this.scene.eventTarget.dispatchEvent(new TurnEndEvent(this.scene.currentBattle.turn)); + globalScene.currentBattle.incrementTurn(); + globalScene.eventTarget.dispatchEvent(new TurnEndEvent(globalScene.currentBattle.turn)); const handlePokemon = (pokemon: Pokemon) => { if (!pokemon.switchOutStatus) { pokemon.lapseTags(BattlerTagLapseType.TURN_END); - this.scene.applyModifiers(TurnHealModifier, pokemon.isPlayer(), pokemon); + globalScene.applyModifiers(TurnHealModifier, pokemon.isPlayer(), pokemon); - if (this.scene.arena.terrain?.terrainType === TerrainType.GRASSY && pokemon.isGrounded()) { - this.scene.unshiftPhase(new PokemonHealPhase(this.scene, pokemon.getBattlerIndex(), + if (globalScene.arena.terrain?.terrainType === TerrainType.GRASSY && pokemon.isGrounded()) { + globalScene.unshiftPhase(new PokemonHealPhase(pokemon.getBattlerIndex(), Math.max(pokemon.getMaxHp() >> 4, 1), i18next.t("battle:turnEndHpRestore", { pokemonName: getPokemonNameWithAffix(pokemon) }), true)); } if (!pokemon.isPlayer()) { - this.scene.applyModifiers(EnemyTurnHealModifier, false, pokemon); - this.scene.applyModifier(EnemyStatusEffectHealChanceModifier, false, pokemon); + globalScene.applyModifiers(EnemyTurnHealModifier, false, pokemon); + globalScene.applyModifier(EnemyStatusEffectHealChanceModifier, false, pokemon); } applyPostTurnAbAttrs(PostTurnAbAttr, pokemon); } - this.scene.applyModifiers(TurnStatusEffectModifier, pokemon.isPlayer(), pokemon); + globalScene.applyModifiers(TurnStatusEffectModifier, pokemon.isPlayer(), pokemon); - this.scene.applyModifiers(TurnHeldItemTransferModifier, pokemon.isPlayer(), pokemon); + globalScene.applyModifiers(TurnHeldItemTransferModifier, pokemon.isPlayer(), pokemon); pokemon.battleSummonData.turnCount++; pokemon.battleSummonData.waveTurnCount++; @@ -51,15 +51,15 @@ export class TurnEndPhase extends FieldPhase { this.executeForAll(handlePokemon); - this.scene.arena.lapseTags(); + globalScene.arena.lapseTags(); - if (this.scene.arena.weather && !this.scene.arena.weather.lapse()) { - this.scene.arena.trySetWeather(WeatherType.NONE, false); - this.scene.arena.triggerWeatherBasedFormChangesToNormal(); + if (globalScene.arena.weather && !globalScene.arena.weather.lapse()) { + globalScene.arena.trySetWeather(WeatherType.NONE, false); + globalScene.arena.triggerWeatherBasedFormChangesToNormal(); } - if (this.scene.arena.terrain && !this.scene.arena.terrain.lapse()) { - this.scene.arena.trySetTerrain(TerrainType.NONE, false); + if (globalScene.arena.terrain && !globalScene.arena.terrain.lapse()) { + globalScene.arena.trySetTerrain(TerrainType.NONE, false); } this.end(); diff --git a/src/phases/turn-init-phase.ts b/src/phases/turn-init-phase.ts index baff6c7d73f0..4f20361d5fa6 100644 --- a/src/phases/turn-init-phase.ts +++ b/src/phases/turn-init-phase.ts @@ -1,5 +1,4 @@ import { BattlerIndex } from "#app/battle"; -import BattleScene from "#app/battle-scene"; import { handleMysteryEncounterBattleStartEffects, handleMysteryEncounterTurnStartEffects } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; import { TurnInitEvent } from "#app/events/battle-scene"; import { PlayerPokemon } from "#app/field/pokemon"; @@ -10,27 +9,28 @@ import { FieldPhase } from "./field-phase"; import { GameOverPhase } from "./game-over-phase"; import { ToggleDoublePositionPhase } from "./toggle-double-position-phase"; import { TurnStartPhase } from "./turn-start-phase"; +import { globalScene } from "#app/global-scene"; export class TurnInitPhase extends FieldPhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start() { super.start(); - this.scene.getPlayerField().forEach(p => { + globalScene.getPlayerField().forEach(p => { // If this pokemon is in play and evolved into something illegal under the current challenge, force a switch if (p.isOnField() && !p.isAllowedInBattle()) { - this.scene.queueMessage(i18next.t("challenges:illegalEvolution", { "pokemon": p.name }), null, true); + globalScene.queueMessage(i18next.t("challenges:illegalEvolution", { "pokemon": p.name }), null, true); - const allowedPokemon = this.scene.getPokemonAllowedInBattle(); + const allowedPokemon = globalScene.getPokemonAllowedInBattle(); if (!allowedPokemon.length) { // If there are no longer any legal pokemon in the party, game over. - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new GameOverPhase(this.scene)); - } else if (allowedPokemon.length >= this.scene.currentBattle.getBattlerCount() || (this.scene.currentBattle.double && !allowedPokemon[0].isActive(true))) { + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new GameOverPhase()); + } else if (allowedPokemon.length >= globalScene.currentBattle.getBattlerCount() || (globalScene.currentBattle.double && !allowedPokemon[0].isActive(true))) { // If there is at least one pokemon in the back that is legal to switch in, force a switch. p.switchOut(); } else { @@ -38,36 +38,35 @@ export class TurnInitPhase extends FieldPhase { // This should only happen in double battles. p.leaveField(); } - if (allowedPokemon.length === 1 && this.scene.currentBattle.double) { - this.scene.unshiftPhase(new ToggleDoublePositionPhase(this.scene, true)); + if (allowedPokemon.length === 1 && globalScene.currentBattle.double) { + globalScene.unshiftPhase(new ToggleDoublePositionPhase(true)); } } }); - //this.scene.pushPhase(new MoveAnimTestPhase(this.scene)); - this.scene.eventTarget.dispatchEvent(new TurnInitEvent()); + globalScene.eventTarget.dispatchEvent(new TurnInitEvent()); - handleMysteryEncounterBattleStartEffects(this.scene); + handleMysteryEncounterBattleStartEffects(); // If true, will skip remainder of current phase (and not queue CommandPhases etc.) - if (handleMysteryEncounterTurnStartEffects(this.scene)) { + if (handleMysteryEncounterTurnStartEffects()) { this.end(); return; } - this.scene.getField().forEach((pokemon, i) => { + globalScene.getField().forEach((pokemon, i) => { if (pokemon?.isActive()) { if (pokemon.isPlayer()) { - this.scene.currentBattle.addParticipant(pokemon as PlayerPokemon); + globalScene.currentBattle.addParticipant(pokemon as PlayerPokemon); } pokemon.resetTurnData(); - this.scene.pushPhase(pokemon.isPlayer() ? new CommandPhase(this.scene, i) : new EnemyCommandPhase(this.scene, i - BattlerIndex.ENEMY)); + globalScene.pushPhase(pokemon.isPlayer() ? new CommandPhase(i) : new EnemyCommandPhase(i - BattlerIndex.ENEMY)); } }); - this.scene.pushPhase(new TurnStartPhase(this.scene)); + globalScene.pushPhase(new TurnStartPhase()); this.end(); } diff --git a/src/phases/turn-start-phase.ts b/src/phases/turn-start-phase.ts index b48b018a046c..30f153ad290c 100644 --- a/src/phases/turn-start-phase.ts +++ b/src/phases/turn-start-phase.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { applyAbAttrs, BypassSpeedChanceAbAttr, PreventBypassSpeedChanceAbAttr } from "#app/data/ability"; import { allMoves, MoveHeaderAttr } from "#app/data/move"; import { Abilities } from "#app/enums/abilities"; @@ -20,10 +19,11 @@ import { CheckStatusEffectPhase } from "#app/phases/check-status-effect-phase"; import { BattlerIndex } from "#app/battle"; import { TrickRoomTag } from "#app/data/arena-tag"; import { SwitchType } from "#enums/switch-type"; +import { globalScene } from "#app/global-scene"; export class TurnStartPhase extends FieldPhase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } /** @@ -32,20 +32,20 @@ export class TurnStartPhase extends FieldPhase { * @returns {@linkcode BattlerIndex[]} the battle indices of all pokemon on the field ordered by speed */ getSpeedOrder(): BattlerIndex[] { - const playerField = this.scene.getPlayerField().filter(p => p.isActive()) as Pokemon[]; - const enemyField = this.scene.getEnemyField().filter(p => p.isActive()) as Pokemon[]; + const playerField = globalScene.getPlayerField().filter(p => p.isActive()) as Pokemon[]; + const enemyField = globalScene.getEnemyField().filter(p => p.isActive()) as Pokemon[]; // We shuffle the list before sorting so speed ties produce random results let orderedTargets: Pokemon[] = playerField.concat(enemyField); // We seed it with the current turn to prevent an inconsistency where it // was varying based on how long since you last reloaded - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { orderedTargets = Utils.randSeedShuffle(orderedTargets); - }, this.scene.currentBattle.turn, this.scene.waveSeed); + }, globalScene.currentBattle.turn, globalScene.waveSeed); // Next, a check for Trick Room is applied to determine sort order. const speedReversed = new Utils.BooleanHolder(false); - this.scene.arena.applyTags(TrickRoomTag, false, speedReversed); + globalScene.arena.applyTags(TrickRoomTag, false, speedReversed); // Adjust the sort function based on whether Trick Room is active. orderedTargets.sort((a: Pokemon, b: Pokemon) => { @@ -70,13 +70,13 @@ export class TurnStartPhase extends FieldPhase { // This occurs before the main loop because of battles with more than two Pokemon const battlerBypassSpeed = {}; - this.scene.getField(true).filter(p => p.summonData).map(p => { + globalScene.getField(true).filter(p => p.summonData).map(p => { const bypassSpeed = new Utils.BooleanHolder(false); const canCheckHeldItems = new Utils.BooleanHolder(true); applyAbAttrs(BypassSpeedChanceAbAttr, p, null, false, bypassSpeed); applyAbAttrs(PreventBypassSpeedChanceAbAttr, p, null, false, bypassSpeed, canCheckHeldItems); if (canCheckHeldItems.value) { - this.scene.applyModifiers(BypassSpeedChanceModifier, p.isPlayer(), p, bypassSpeed); + globalScene.applyModifiers(BypassSpeedChanceModifier, p.isPlayer(), p, bypassSpeed); } battlerBypassSpeed[p.getBattlerIndex()] = bypassSpeed; }); @@ -85,8 +85,8 @@ export class TurnStartPhase extends FieldPhase { // Non-FIGHT commands (SWITCH, BALL, RUN) have a higher command priority and will always occur before any FIGHT commands. moveOrder = moveOrder.slice(0); moveOrder.sort((a, b) => { - const aCommand = this.scene.currentBattle.turnCommands[a]; - const bCommand = this.scene.currentBattle.turnCommands[b]; + const aCommand = globalScene.currentBattle.turnCommands[a]; + const bCommand = globalScene.currentBattle.turnCommands[b]; if (aCommand?.command !== bCommand?.command) { if (aCommand?.command === Command.FIGHT) { @@ -98,8 +98,8 @@ export class TurnStartPhase extends FieldPhase { const aMove = allMoves[aCommand.move!.move]; const bMove = allMoves[bCommand!.move!.move]; - const aUser = this.scene.getField(true).find(p => p.getBattlerIndex() === a)!; - const bUser = this.scene.getField(true).find(p => p.getBattlerIndex() === b)!; + const aUser = globalScene.getField(true).find(p => p.getBattlerIndex() === a)!; + const bUser = globalScene.getField(true).find(p => p.getBattlerIndex() === b)!; const aPriority = aMove.getPriority(aUser, false); const bPriority = bMove.getPriority(bUser, false); @@ -133,7 +133,7 @@ export class TurnStartPhase extends FieldPhase { start() { super.start(); - const field = this.scene.getField(); + const field = globalScene.getField(); const moveOrder = this.getCommandOrder(); let orderIndex = 0; @@ -141,7 +141,7 @@ export class TurnStartPhase extends FieldPhase { for (const o of moveOrder) { const pokemon = field[o]; - const turnCommand = this.scene.currentBattle.turnCommands[o]; + const turnCommand = globalScene.currentBattle.turnCommands[o]; if (turnCommand?.skip) { continue; @@ -156,29 +156,29 @@ export class TurnStartPhase extends FieldPhase { } const move = pokemon.getMoveset().find(m => m?.moveId === queuedMove.move && m?.ppUsed < m?.getMovePp()) || new PokemonMove(queuedMove.move); if (move.getMove().hasAttr(MoveHeaderAttr)) { - this.scene.unshiftPhase(new MoveHeaderPhase(this.scene, pokemon, move)); + globalScene.unshiftPhase(new MoveHeaderPhase(pokemon, move)); } if (pokemon.isPlayer()) { if (turnCommand.cursor === -1) { - this.scene.pushPhase(new MovePhase(this.scene, pokemon, turnCommand.targets || turnCommand.move!.targets, move));//TODO: is the bang correct here? + globalScene.pushPhase(new MovePhase(pokemon, turnCommand.targets || turnCommand.move!.targets, move));//TODO: is the bang correct here? } else { - const playerPhase = new MovePhase(this.scene, pokemon, turnCommand.targets || turnCommand.move!.targets, move, false, queuedMove.ignorePP);//TODO: is the bang correct here? - this.scene.pushPhase(playerPhase); + const playerPhase = new MovePhase(pokemon, turnCommand.targets || turnCommand.move!.targets, move, false, queuedMove.ignorePP);//TODO: is the bang correct here? + globalScene.pushPhase(playerPhase); } } else { - this.scene.pushPhase(new MovePhase(this.scene, pokemon, turnCommand.targets || turnCommand.move!.targets, move, false, queuedMove.ignorePP));//TODO: is the bang correct here? + globalScene.pushPhase(new MovePhase(pokemon, turnCommand.targets || turnCommand.move!.targets, move, false, queuedMove.ignorePP));//TODO: is the bang correct here? } break; case Command.BALL: - this.scene.unshiftPhase(new AttemptCapturePhase(this.scene, turnCommand.targets![0] % 2, turnCommand.cursor!));//TODO: is the bang correct here? + globalScene.unshiftPhase(new AttemptCapturePhase(turnCommand.targets![0] % 2, turnCommand.cursor!));//TODO: is the bang correct here? break; case Command.POKEMON: const switchType = turnCommand.args?.[0] ? SwitchType.BATON_PASS : SwitchType.SWITCH; - this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, switchType, pokemon.getFieldIndex(), turnCommand.cursor!, true, pokemon.isPlayer())); + globalScene.unshiftPhase(new SwitchSummonPhase(switchType, pokemon.getFieldIndex(), turnCommand.cursor!, true, pokemon.isPlayer())); break; case Command.RUN: let runningPokemon = pokemon; - if (this.scene.currentBattle.double) { + if (globalScene.currentBattle.double) { const playerActivePokemon = field.filter(pokemon => { if (!!pokemon) { return pokemon.isPlayer() && pokemon.isActive(); @@ -195,18 +195,18 @@ export class TurnStartPhase extends FieldPhase { runningPokemon = hasRunAway !== undefined ? hasRunAway : fasterPokemon; } } - this.scene.unshiftPhase(new AttemptRunPhase(this.scene, runningPokemon.getFieldIndex())); + globalScene.unshiftPhase(new AttemptRunPhase(runningPokemon.getFieldIndex())); break; } } - this.scene.pushPhase(new WeatherEffectPhase(this.scene)); - this.scene.pushPhase(new BerryPhase(this.scene)); + globalScene.pushPhase(new WeatherEffectPhase()); + globalScene.pushPhase(new BerryPhase()); /** Add a new phase to check who should be taking status damage */ - this.scene.pushPhase(new CheckStatusEffectPhase(this.scene, moveOrder)); + globalScene.pushPhase(new CheckStatusEffectPhase(moveOrder)); - this.scene.pushPhase(new TurnEndPhase(this.scene)); + globalScene.pushPhase(new TurnEndPhase()); /** * this.end() will call shiftPhase(), which dumps everything from PrependQueue (aka everything that is unshifted()) to the front diff --git a/src/phases/unavailable-phase.ts b/src/phases/unavailable-phase.ts index 59bfca7875e0..c0b5d4224c5b 100644 --- a/src/phases/unavailable-phase.ts +++ b/src/phases/unavailable-phase.ts @@ -1,16 +1,16 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { Mode } from "#app/ui/ui"; import { LoginPhase } from "./login-phase"; export class UnavailablePhase extends Phase { - constructor(scene: BattleScene) { - super(scene); + constructor() { + super(); } start(): void { - this.scene.ui.setMode(Mode.UNAVAILABLE, () => { - this.scene.unshiftPhase(new LoginPhase(this.scene, true)); + globalScene.ui.setMode(Mode.UNAVAILABLE, () => { + globalScene.unshiftPhase(new LoginPhase(true)); this.end(); }); } diff --git a/src/phases/unlock-phase.ts b/src/phases/unlock-phase.ts index 65060309a6c1..344187051d02 100644 --- a/src/phases/unlock-phase.ts +++ b/src/phases/unlock-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { Unlockables, getUnlockableName } from "#app/system/unlockables"; import { Mode } from "#app/ui/ui"; @@ -7,20 +7,20 @@ import i18next from "i18next"; export class UnlockPhase extends Phase { private unlockable: Unlockables; - constructor(scene: BattleScene, unlockable: Unlockables) { - super(scene); + constructor(unlockable: Unlockables) { + super(); this.unlockable = unlockable; } start(): void { - this.scene.time.delayedCall(2000, () => { - this.scene.gameData.unlocks[this.unlockable] = true; + globalScene.time.delayedCall(2000, () => { + globalScene.gameData.unlocks[this.unlockable] = true; // Sound loaded into game as is - this.scene.playSound("level_up_fanfare"); - this.scene.ui.setMode(Mode.MESSAGE); - this.scene.ui.showText(i18next.t("battle:unlockedSomething", { unlockedThing: getUnlockableName(this.unlockable) }), null, () => { - this.scene.time.delayedCall(1500, () => this.scene.arenaBg.setVisible(true)); + globalScene.playSound("level_up_fanfare"); + globalScene.ui.setMode(Mode.MESSAGE); + globalScene.ui.showText(i18next.t("battle:unlockedSomething", { unlockedThing: getUnlockableName(this.unlockable) }), null, () => { + globalScene.time.delayedCall(1500, () => globalScene.arenaBg.setVisible(true)); this.end(); }, null, true, 1500); }); diff --git a/src/phases/victory-phase.ts b/src/phases/victory-phase.ts index 62479241a6ce..df7b6aff2128 100644 --- a/src/phases/victory-phase.ts +++ b/src/phases/victory-phase.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { BattlerIndex, BattleType, ClassicFixedBossWaves } from "#app/battle"; import { CustomModifierSettings, modifierTypes } from "#app/modifier/modifier-type"; import { BattleEndPhase } from "./battle-end-phase"; @@ -11,13 +10,14 @@ import { ModifierRewardPhase } from "./modifier-reward-phase"; import { SelectModifierPhase } from "./select-modifier-phase"; import { TrainerVictoryPhase } from "./trainer-victory-phase"; import { handleMysteryEncounterVictory } from "#app/data/mystery-encounters/utils/encounter-phase-utils"; +import { globalScene } from "#app/global-scene"; export class VictoryPhase extends PokemonPhase { /** If true, indicates that the phase is intended for EXP purposes only, and not to continue a battle to next phase */ isExpOnly: boolean; - constructor(scene: BattleScene, battlerIndex: BattlerIndex | integer, isExpOnly: boolean = false) { - super(scene, battlerIndex); + constructor(battlerIndex: BattlerIndex | integer, isExpOnly: boolean = false) { + super(battlerIndex); this.isExpOnly = isExpOnly; } @@ -25,61 +25,61 @@ export class VictoryPhase extends PokemonPhase { start() { super.start(); - const isMysteryEncounter = this.scene.currentBattle.isBattleMysteryEncounter(); + const isMysteryEncounter = globalScene.currentBattle.isBattleMysteryEncounter(); // update Pokemon defeated count except for MEs that disable it - if (!isMysteryEncounter || !this.scene.currentBattle.mysteryEncounter?.preventGameStatsUpdates) { - this.scene.gameData.gameStats.pokemonDefeated++; + if (!isMysteryEncounter || !globalScene.currentBattle.mysteryEncounter?.preventGameStatsUpdates) { + globalScene.gameData.gameStats.pokemonDefeated++; } const expValue = this.getPokemon().getExpValue(); - this.scene.applyPartyExp(expValue, true); + globalScene.applyPartyExp(expValue, true); if (isMysteryEncounter) { - handleMysteryEncounterVictory(this.scene, false, this.isExpOnly); + handleMysteryEncounterVictory(false, this.isExpOnly); return this.end(); } - if (!this.scene.getEnemyParty().find(p => this.scene.currentBattle.battleType === BattleType.WILD ? p.isOnField() : !p?.isFainted(true))) { - this.scene.pushPhase(new BattleEndPhase(this.scene, true)); - if (this.scene.currentBattle.battleType === BattleType.TRAINER) { - this.scene.pushPhase(new TrainerVictoryPhase(this.scene)); + if (!globalScene.getEnemyParty().find(p => globalScene.currentBattle.battleType === BattleType.WILD ? p.isOnField() : !p?.isFainted(true))) { + globalScene.pushPhase(new BattleEndPhase(true)); + if (globalScene.currentBattle.battleType === BattleType.TRAINER) { + globalScene.pushPhase(new TrainerVictoryPhase()); } - if (this.scene.gameMode.isEndless || !this.scene.gameMode.isWaveFinal(this.scene.currentBattle.waveIndex)) { - this.scene.pushPhase(new EggLapsePhase(this.scene)); - if (this.scene.gameMode.isClassic && this.scene.currentBattle.waveIndex === ClassicFixedBossWaves.EVIL_BOSS_2) { + if (globalScene.gameMode.isEndless || !globalScene.gameMode.isWaveFinal(globalScene.currentBattle.waveIndex)) { + globalScene.pushPhase(new EggLapsePhase()); + if (globalScene.gameMode.isClassic && globalScene.currentBattle.waveIndex === ClassicFixedBossWaves.EVIL_BOSS_2) { // Should get Lock Capsule on 165 before shop phase so it can be used in the rewards shop - this.scene.pushPhase(new ModifierRewardPhase(this.scene, modifierTypes.LOCK_CAPSULE)); + globalScene.pushPhase(new ModifierRewardPhase(modifierTypes.LOCK_CAPSULE)); } - if (this.scene.currentBattle.waveIndex % 10) { - this.scene.pushPhase(new SelectModifierPhase(this.scene, undefined, undefined, this.getFixedBattleCustomModifiers())); - } else if (this.scene.gameMode.isDaily) { - this.scene.pushPhase(new ModifierRewardPhase(this.scene, modifierTypes.EXP_CHARM)); - if (this.scene.currentBattle.waveIndex > 10 && !this.scene.gameMode.isWaveFinal(this.scene.currentBattle.waveIndex)) { - this.scene.pushPhase(new ModifierRewardPhase(this.scene, modifierTypes.GOLDEN_POKEBALL)); + if (globalScene.currentBattle.waveIndex % 10) { + globalScene.pushPhase(new SelectModifierPhase(undefined, undefined, this.getFixedBattleCustomModifiers())); + } else if (globalScene.gameMode.isDaily) { + globalScene.pushPhase(new ModifierRewardPhase(modifierTypes.EXP_CHARM)); + if (globalScene.currentBattle.waveIndex > 10 && !globalScene.gameMode.isWaveFinal(globalScene.currentBattle.waveIndex)) { + globalScene.pushPhase(new ModifierRewardPhase(modifierTypes.GOLDEN_POKEBALL)); } } else { - const superExpWave = !this.scene.gameMode.isEndless ? (this.scene.offsetGym ? 0 : 20) : 10; - if (this.scene.gameMode.isEndless && this.scene.currentBattle.waveIndex === 10) { - this.scene.pushPhase(new ModifierRewardPhase(this.scene, modifierTypes.EXP_SHARE)); + const superExpWave = !globalScene.gameMode.isEndless ? (globalScene.offsetGym ? 0 : 20) : 10; + if (globalScene.gameMode.isEndless && globalScene.currentBattle.waveIndex === 10) { + globalScene.pushPhase(new ModifierRewardPhase(modifierTypes.EXP_SHARE)); } - if (this.scene.currentBattle.waveIndex <= 750 && (this.scene.currentBattle.waveIndex <= 500 || (this.scene.currentBattle.waveIndex % 30) === superExpWave)) { - this.scene.pushPhase(new ModifierRewardPhase(this.scene, (this.scene.currentBattle.waveIndex % 30) !== superExpWave || this.scene.currentBattle.waveIndex > 250 ? modifierTypes.EXP_CHARM : modifierTypes.SUPER_EXP_CHARM)); + if (globalScene.currentBattle.waveIndex <= 750 && (globalScene.currentBattle.waveIndex <= 500 || (globalScene.currentBattle.waveIndex % 30) === superExpWave)) { + globalScene.pushPhase(new ModifierRewardPhase((globalScene.currentBattle.waveIndex % 30) !== superExpWave || globalScene.currentBattle.waveIndex > 250 ? modifierTypes.EXP_CHARM : modifierTypes.SUPER_EXP_CHARM)); } - if (this.scene.currentBattle.waveIndex <= 150 && !(this.scene.currentBattle.waveIndex % 50)) { - this.scene.pushPhase(new ModifierRewardPhase(this.scene, modifierTypes.GOLDEN_POKEBALL)); + if (globalScene.currentBattle.waveIndex <= 150 && !(globalScene.currentBattle.waveIndex % 50)) { + globalScene.pushPhase(new ModifierRewardPhase(modifierTypes.GOLDEN_POKEBALL)); } - if (this.scene.gameMode.isEndless && !(this.scene.currentBattle.waveIndex % 50)) { - this.scene.pushPhase(new ModifierRewardPhase(this.scene, !(this.scene.currentBattle.waveIndex % 250) ? modifierTypes.VOUCHER_PREMIUM : modifierTypes.VOUCHER_PLUS)); - this.scene.pushPhase(new AddEnemyBuffModifierPhase(this.scene)); + if (globalScene.gameMode.isEndless && !(globalScene.currentBattle.waveIndex % 50)) { + globalScene.pushPhase(new ModifierRewardPhase(!(globalScene.currentBattle.waveIndex % 250) ? modifierTypes.VOUCHER_PREMIUM : modifierTypes.VOUCHER_PLUS)); + globalScene.pushPhase(new AddEnemyBuffModifierPhase()); } } - this.scene.pushPhase(new NewBattlePhase(this.scene)); + globalScene.pushPhase(new NewBattlePhase()); } else { - this.scene.currentBattle.battleType = BattleType.CLEAR; - this.scene.score += this.scene.gameMode.getClearScoreBonus(); - this.scene.updateScoreText(); - this.scene.pushPhase(new GameOverPhase(this.scene, true)); + globalScene.currentBattle.battleType = BattleType.CLEAR; + globalScene.score += globalScene.gameMode.getClearScoreBonus(); + globalScene.updateScoreText(); + globalScene.pushPhase(new GameOverPhase(true)); } } @@ -91,8 +91,8 @@ export class VictoryPhase extends PokemonPhase { * will pass those settings to the upcoming {@linkcode SelectModifierPhase}`. */ getFixedBattleCustomModifiers(): CustomModifierSettings | undefined { - const gameMode = this.scene.gameMode; - const waveIndex = this.scene.currentBattle.waveIndex; + const gameMode = globalScene.gameMode; + const waveIndex = globalScene.currentBattle.waveIndex; if (gameMode.isFixedBattle(waveIndex)) { return gameMode.getFixedBattle(waveIndex).customModifierRewardSettings; } diff --git a/src/phases/weather-effect-phase.ts b/src/phases/weather-effect-phase.ts index 442bafa0ca7c..735a1f770cc5 100644 --- a/src/phases/weather-effect-phase.ts +++ b/src/phases/weather-effect-phase.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { applyPreWeatherEffectAbAttrs, SuppressWeatherEffectAbAttr, PreWeatherDamageAbAttr, applyAbAttrs, BlockNonDirectDamageAbAttr, applyPostWeatherLapseAbAttrs, PostWeatherLapseAbAttr } from "#app/data/ability"; import { CommonAnim } from "#app/data/battle-anims"; import { Weather, getWeatherDamageMessage, getWeatherLapseMessage } from "#app/data/weather"; @@ -11,14 +11,14 @@ import { CommonAnimPhase } from "./common-anim-phase"; export class WeatherEffectPhase extends CommonAnimPhase { public weather: Weather | null; - constructor(scene: BattleScene) { - super(scene, undefined, undefined, CommonAnim.SUNNY + ((scene?.arena?.weather?.weatherType || WeatherType.NONE) - 1)); - this.weather = scene?.arena?.weather; + constructor() { + super(undefined, undefined, CommonAnim.SUNNY + ((globalScene?.arena?.weather?.weatherType || WeatherType.NONE) - 1)); + this.weather = globalScene?.arena?.weather; } start() { // Update weather state with any changes that occurred during the turn - this.weather = this.scene?.arena?.weather; + this.weather = globalScene?.arena?.weather; if (!this.weather) { this.end(); @@ -46,7 +46,7 @@ export class WeatherEffectPhase extends CommonAnimPhase { const damage = Utils.toDmgValue(pokemon.getMaxHp() / 16); - this.scene.queueMessage(getWeatherDamageMessage(this.weather?.weatherType!, pokemon)!); // TODO: are those bangs correct? + globalScene.queueMessage(getWeatherDamageMessage(this.weather?.weatherType!, pokemon)!); // TODO: are those bangs correct? pokemon.damageAndUpdate(damage, HitResult.EFFECTIVE, false, false, true); }; @@ -59,7 +59,7 @@ export class WeatherEffectPhase extends CommonAnimPhase { } } - this.scene.ui.showText(getWeatherLapseMessage(this.weather.weatherType) ?? "", null, () => { + globalScene.ui.showText(getWeatherLapseMessage(this.weather.weatherType) ?? "", null, () => { this.executeForAll((pokemon: Pokemon) => { if (!pokemon.switchOutStatus) { applyPostWeatherLapseAbAttrs(PostWeatherLapseAbAttr, pokemon, this.weather); diff --git a/src/pipelines/field-sprite.ts b/src/pipelines/field-sprite.ts index c370f5586e56..f81845073c1d 100644 --- a/src/pipelines/field-sprite.ts +++ b/src/pipelines/field-sprite.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { TerrainType, getTerrainColor } from "../data/terrain"; import * as Utils from "../utils"; @@ -227,22 +227,21 @@ export default class FieldSpritePipeline extends Phaser.Renderer.WebGL.Pipelines super.onBind(); const sprite = gameObject as Phaser.GameObjects.Sprite | Phaser.GameObjects.NineSlice; - const scene = sprite.scene as BattleScene; const data = sprite.pipelineData; const ignoreTimeTint = data["ignoreTimeTint"] as boolean; const terrainColorRatio = data["terrainColorRatio"] as number || 0; - const time = scene.currentBattle?.waveIndex - ? ((scene.currentBattle.waveIndex + scene.waveCycleOffset) % 40) / 40 // ((new Date().getSeconds() * 1000 + new Date().getMilliseconds()) % 10000) / 10000 + const time = globalScene.currentBattle?.waveIndex + ? ((globalScene.currentBattle.waveIndex + globalScene.waveCycleOffset) % 40) / 40 // ((new Date().getSeconds() * 1000 + new Date().getMilliseconds()) % 10000) / 10000 : Utils.getCurrentTime(); this.set1f("time", time); this.set1i("ignoreTimeTint", ignoreTimeTint ? 1 : 0); - this.set1i("isOutside", scene.arena.isOutside() ? 1 : 0); - this.set3fv("dayTint", scene.arena.getDayTint().map(c => c / 255)); - this.set3fv("duskTint", scene.arena.getDuskTint().map(c => c / 255)); - this.set3fv("nightTint", scene.arena.getNightTint().map(c => c / 255)); - this.set3fv("terrainColor", getTerrainColor(scene.arena.terrain?.terrainType || TerrainType.NONE).map(c => c / 255)); + this.set1i("isOutside", globalScene.arena.isOutside() ? 1 : 0); + this.set3fv("dayTint", globalScene.arena.getDayTint().map(c => c / 255)); + this.set3fv("duskTint", globalScene.arena.getDuskTint().map(c => c / 255)); + this.set3fv("nightTint", globalScene.arena.getNightTint().map(c => c / 255)); + this.set3fv("terrainColor", getTerrainColor(globalScene.arena.terrain?.terrainType || TerrainType.NONE).map(c => c / 255)); this.set1f("terrainColorRatio", terrainColorRatio); } diff --git a/src/pipelines/sprite.ts b/src/pipelines/sprite.ts index 88d6ce2d3871..1fc3b7718974 100644 --- a/src/pipelines/sprite.ts +++ b/src/pipelines/sprite.ts @@ -1,10 +1,10 @@ -import BattleScene from "../battle-scene"; import { variantColorCache } from "#app/data/variant"; -import Pokemon from "../field/pokemon"; -import Trainer from "../field/trainer"; +import MysteryEncounterIntroVisuals from "#app/field/mystery-encounter-intro"; +import Pokemon from "#app/field/pokemon"; +import Trainer from "#app/field/trainer"; +import { globalScene } from "#app/global-scene"; +import * as Utils from "#app/utils"; import FieldSpritePipeline from "./field-sprite"; -import * as Utils from "../utils"; -import MysteryEncounterIntroVisuals from "../field/mystery-encounter-intro"; const spriteFragShader = ` #ifdef GL_FRAGMENT_PRECISION_HIGH @@ -384,7 +384,7 @@ export default class SpritePipeline extends FieldSpritePipeline { this.set4fv("tone", tone); this.bindTexture(this.game.textures.get("tera").source[0].glTexture!, 1); // TODO: is this bang correct? - if ((gameObject.scene as BattleScene).fusionPaletteSwaps) { + if (globalScene.fusionPaletteSwaps) { const spriteColors = ((ignoreOverride && data["spriteColorsBase"]) || data["spriteColors"] || []) as number[][]; const fusionSpriteColors = ((ignoreOverride && data["fusionSpriteColorsBase"]) || data["fusionSpriteColors"] || []) as number[][]; diff --git a/src/system/achv.ts b/src/system/achv.ts index a98e396264d0..14d826074233 100644 --- a/src/system/achv.ts +++ b/src/system/achv.ts @@ -1,5 +1,4 @@ import { Modifier } from "typescript"; -import BattleScene from "../battle-scene"; import { TurnHeldItemTransferModifier } from "../modifier/modifier"; import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; import i18next from "i18next"; @@ -9,6 +8,7 @@ import { Challenge, FreshStartChallenge, SingleGenerationChallenge, SingleTypeCh import { ConditionFn } from "#app/@types/common"; import { Stat, getShortenedStatKey } from "#app/enums/stat"; import { Challenges } from "#app/enums/challenges"; +import { globalScene } from "#app/global-scene"; export enum AchvTier { COMMON, @@ -66,8 +66,8 @@ export class Achv { return this; } - validate(scene: BattleScene, args?: any[]): boolean { - return !this.conditionFunc || this.conditionFunc(scene, args); + validate(args?: any[]): boolean { + return !this.conditionFunc || this.conditionFunc(args); } getTier(): AchvTier { @@ -91,7 +91,7 @@ export class MoneyAchv extends Achv { moneyAmount: integer; constructor(localizationKey: string, name: string, moneyAmount: integer, iconImage: string, score: integer) { - super(localizationKey, name, "", iconImage, score, (scene: BattleScene, _args: any[]) => scene.money >= this.moneyAmount); + super(localizationKey, name, "", iconImage, score, (_args: any[]) => globalScene.money >= this.moneyAmount); this.moneyAmount = moneyAmount; } } @@ -100,7 +100,7 @@ export class RibbonAchv extends Achv { ribbonAmount: integer; constructor(localizationKey: string, name: string, ribbonAmount: integer, iconImage: string, score: integer) { - super(localizationKey, name, "", iconImage, score, (scene: BattleScene, _args: any[]) => scene.gameData.gameStats.ribbonsOwned >= this.ribbonAmount); + super(localizationKey, name, "", iconImage, score, (_args: any[]) => globalScene.gameData.gameStats.ribbonsOwned >= this.ribbonAmount); this.ribbonAmount = ribbonAmount; } } @@ -109,7 +109,7 @@ export class DamageAchv extends Achv { damageAmount: integer; constructor(localizationKey: string, name: string, damageAmount: integer, iconImage: string, score: integer) { - super(localizationKey, name, "", iconImage, score, (_scene: BattleScene, args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.damageAmount); + super(localizationKey, name, "", iconImage, score, (args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.damageAmount); this.damageAmount = damageAmount; } } @@ -118,7 +118,7 @@ export class HealAchv extends Achv { healAmount: integer; constructor(localizationKey: string, name: string, healAmount: integer, iconImage: string, score: integer) { - super(localizationKey, name, "", iconImage, score, (_scene: BattleScene, args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.healAmount); + super(localizationKey, name, "", iconImage, score, (args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.healAmount); this.healAmount = healAmount; } } @@ -127,20 +127,20 @@ export class LevelAchv extends Achv { level: integer; constructor(localizationKey: string, name: string, level: integer, iconImage: string, score: integer) { - super(localizationKey, name, "", iconImage, score, (scene: BattleScene, args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.level); + super(localizationKey, name, "", iconImage, score, (args: any[]) => (args[0] instanceof Utils.NumberHolder ? args[0].value : args[0]) >= this.level); this.level = level; } } export class ModifierAchv extends Achv { constructor(localizationKey: string, name: string, description: string, iconImage: string, score: integer, modifierFunc: (modifier: Modifier) => boolean) { - super(localizationKey, name, description, iconImage, score, (_scene: BattleScene, args: any[]) => modifierFunc((args[0] as Modifier))); + super(localizationKey, name, description, iconImage, score, (args: any[]) => modifierFunc((args[0] as Modifier))); } } export class ChallengeAchv extends Achv { - constructor(localizationKey: string, name: string, description: string, iconImage: string, score: integer, challengeFunc: (challenge: Challenge, scene: BattleScene) => boolean) { - super(localizationKey, name, description, iconImage, score, (_scene: BattleScene, args: any[]) => challengeFunc(args[0] as Challenge, _scene)); + constructor(localizationKey: string, name: string, description: string, iconImage: string, score: integer, challengeFunc: (challenge: Challenge) => boolean) { + super(localizationKey, name, description, iconImage, score, (args: any[]) => challengeFunc(args[0] as Challenge)); } } @@ -152,7 +152,7 @@ export class ChallengeAchv extends Achv { */ export function getAchievementDescription(localizationKey: string): string { // We need to get the player gender from the game data to add the correct prefix to the achievement name - const genderIndex = this?.scene?.gameData?.gender ?? PlayerGender.MALE; //TODO: why is `this` being used here!? We are not inside a scope (copied from original) + const genderIndex = globalScene?.gameData?.gender ?? PlayerGender.MALE; const genderStr = PlayerGender[genderIndex].toLowerCase(); switch (localizationKey) { @@ -327,36 +327,36 @@ export const achvs = { HATCH_SHINY: new Achv("HATCH_SHINY", "", "HATCH_SHINY.description", "golden_egg", 100).setSecret(), HIDDEN_ABILITY: new Achv("HIDDEN_ABILITY", "", "HIDDEN_ABILITY.description", "ability_charm", 75), PERFECT_IVS: new Achv("PERFECT_IVS", "", "PERFECT_IVS.description", "blunder_policy", 100), - CLASSIC_VICTORY: new Achv("CLASSIC_VICTORY", "", "CLASSIC_VICTORY.description", "relic_crown", 150, c => c.gameData.gameStats.sessionsWon === 0), - UNEVOLVED_CLASSIC_VICTORY: new Achv("UNEVOLVED_CLASSIC_VICTORY", "", "UNEVOLVED_CLASSIC_VICTORY.description", "eviolite", 175, c => c.getPlayerParty().some(p => p.getSpeciesForm(true).speciesId in pokemonEvolutions)), - MONO_GEN_ONE_VICTORY: new ChallengeAchv("MONO_GEN_ONE", "", "MONO_GEN_ONE.description", "ribbon_gen1", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 1 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_TWO_VICTORY: new ChallengeAchv("MONO_GEN_TWO", "", "MONO_GEN_TWO.description", "ribbon_gen2", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 2 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_THREE_VICTORY: new ChallengeAchv("MONO_GEN_THREE", "", "MONO_GEN_THREE.description", "ribbon_gen3", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 3 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_FOUR_VICTORY: new ChallengeAchv("MONO_GEN_FOUR", "", "MONO_GEN_FOUR.description", "ribbon_gen4", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 4 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_FIVE_VICTORY: new ChallengeAchv("MONO_GEN_FIVE", "", "MONO_GEN_FIVE.description", "ribbon_gen5", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 5 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_SIX_VICTORY: new ChallengeAchv("MONO_GEN_SIX", "", "MONO_GEN_SIX.description", "ribbon_gen6", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 6 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_SEVEN_VICTORY: new ChallengeAchv("MONO_GEN_SEVEN", "", "MONO_GEN_SEVEN.description", "ribbon_gen7", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 7 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_EIGHT_VICTORY: new ChallengeAchv("MONO_GEN_EIGHT", "", "MONO_GEN_EIGHT.description", "ribbon_gen8", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 8 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GEN_NINE_VICTORY: new ChallengeAchv("MONO_GEN_NINE", "", "MONO_GEN_NINE.description", "ribbon_gen9", 100, (c, scene) => c instanceof SingleGenerationChallenge && c.value === 9 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_NORMAL: new ChallengeAchv("MONO_NORMAL", "", "MONO_NORMAL.description", "silk_scarf", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 1 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_FIGHTING: new ChallengeAchv("MONO_FIGHTING", "", "MONO_FIGHTING.description", "black_belt", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 2 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_FLYING: new ChallengeAchv("MONO_FLYING", "", "MONO_FLYING.description", "sharp_beak", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 3 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_POISON: new ChallengeAchv("MONO_POISON", "", "MONO_POISON.description", "poison_barb", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 4 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GROUND: new ChallengeAchv("MONO_GROUND", "", "MONO_GROUND.description", "soft_sand", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 5 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_ROCK: new ChallengeAchv("MONO_ROCK", "", "MONO_ROCK.description", "hard_stone", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 6 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_BUG: new ChallengeAchv("MONO_BUG", "", "MONO_BUG.description", "silver_powder", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 7 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GHOST: new ChallengeAchv("MONO_GHOST", "", "MONO_GHOST.description", "spell_tag", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 8 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_STEEL: new ChallengeAchv("MONO_STEEL", "", "MONO_STEEL.description", "metal_coat", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 9 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_FIRE: new ChallengeAchv("MONO_FIRE", "", "MONO_FIRE.description", "charcoal", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 10 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_WATER: new ChallengeAchv("MONO_WATER", "", "MONO_WATER.description", "mystic_water", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 11 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_GRASS: new ChallengeAchv("MONO_GRASS", "", "MONO_GRASS.description", "miracle_seed", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 12 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_ELECTRIC: new ChallengeAchv("MONO_ELECTRIC", "", "MONO_ELECTRIC.description", "magnet", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 13 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_PSYCHIC: new ChallengeAchv("MONO_PSYCHIC", "", "MONO_PSYCHIC.description", "twisted_spoon", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 14 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_ICE: new ChallengeAchv("MONO_ICE", "", "MONO_ICE.description", "never_melt_ice", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 15 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_DRAGON: new ChallengeAchv("MONO_DRAGON", "", "MONO_DRAGON.description", "dragon_fang", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 16 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_DARK: new ChallengeAchv("MONO_DARK", "", "MONO_DARK.description", "black_glasses", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 17 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - MONO_FAIRY: new ChallengeAchv("MONO_FAIRY", "", "MONO_FAIRY.description", "fairy_feather", 100, (c, scene) => c instanceof SingleTypeChallenge && c.value === 18 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), - FRESH_START: new ChallengeAchv("FRESH_START", "", "FRESH_START.description", "reviver_seed", 100, (c, scene) => c instanceof FreshStartChallenge && c.value > 0 && !scene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + CLASSIC_VICTORY: new Achv("CLASSIC_VICTORY", "", "CLASSIC_VICTORY.description", "relic_crown", 150, (_) => globalScene.gameData.gameStats.sessionsWon === 0), + UNEVOLVED_CLASSIC_VICTORY: new Achv("UNEVOLVED_CLASSIC_VICTORY", "", "UNEVOLVED_CLASSIC_VICTORY.description", "eviolite", 175, (_) => globalScene.getPlayerParty().some(p => p.getSpeciesForm(true).speciesId in pokemonEvolutions)), + MONO_GEN_ONE_VICTORY: new ChallengeAchv("MONO_GEN_ONE", "", "MONO_GEN_ONE.description", "ribbon_gen1", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 1 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_TWO_VICTORY: new ChallengeAchv("MONO_GEN_TWO", "", "MONO_GEN_TWO.description", "ribbon_gen2", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 2 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_THREE_VICTORY: new ChallengeAchv("MONO_GEN_THREE", "", "MONO_GEN_THREE.description", "ribbon_gen3", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 3 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_FOUR_VICTORY: new ChallengeAchv("MONO_GEN_FOUR", "", "MONO_GEN_FOUR.description", "ribbon_gen4", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 4 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_FIVE_VICTORY: new ChallengeAchv("MONO_GEN_FIVE", "", "MONO_GEN_FIVE.description", "ribbon_gen5", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 5 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_SIX_VICTORY: new ChallengeAchv("MONO_GEN_SIX", "", "MONO_GEN_SIX.description", "ribbon_gen6", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 6 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_SEVEN_VICTORY: new ChallengeAchv("MONO_GEN_SEVEN", "", "MONO_GEN_SEVEN.description", "ribbon_gen7", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 7 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_EIGHT_VICTORY: new ChallengeAchv("MONO_GEN_EIGHT", "", "MONO_GEN_EIGHT.description", "ribbon_gen8", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 8 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GEN_NINE_VICTORY: new ChallengeAchv("MONO_GEN_NINE", "", "MONO_GEN_NINE.description", "ribbon_gen9", 100, (c) => c instanceof SingleGenerationChallenge && c.value === 9 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_NORMAL: new ChallengeAchv("MONO_NORMAL", "", "MONO_NORMAL.description", "silk_scarf", 100, (c) => c instanceof SingleTypeChallenge && c.value === 1 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_FIGHTING: new ChallengeAchv("MONO_FIGHTING", "", "MONO_FIGHTING.description", "black_belt", 100, (c) => c instanceof SingleTypeChallenge && c.value === 2 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_FLYING: new ChallengeAchv("MONO_FLYING", "", "MONO_FLYING.description", "sharp_beak", 100, (c) => c instanceof SingleTypeChallenge && c.value === 3 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_POISON: new ChallengeAchv("MONO_POISON", "", "MONO_POISON.description", "poison_barb", 100, (c) => c instanceof SingleTypeChallenge && c.value === 4 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GROUND: new ChallengeAchv("MONO_GROUND", "", "MONO_GROUND.description", "soft_sand", 100, (c) => c instanceof SingleTypeChallenge && c.value === 5 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_ROCK: new ChallengeAchv("MONO_ROCK", "", "MONO_ROCK.description", "hard_stone", 100, (c) => c instanceof SingleTypeChallenge && c.value === 6 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_BUG: new ChallengeAchv("MONO_BUG", "", "MONO_BUG.description", "silver_powder", 100, (c) => c instanceof SingleTypeChallenge && c.value === 7 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GHOST: new ChallengeAchv("MONO_GHOST", "", "MONO_GHOST.description", "spell_tag", 100, (c) => c instanceof SingleTypeChallenge && c.value === 8 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_STEEL: new ChallengeAchv("MONO_STEEL", "", "MONO_STEEL.description", "metal_coat", 100, (c) => c instanceof SingleTypeChallenge && c.value === 9 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_FIRE: new ChallengeAchv("MONO_FIRE", "", "MONO_FIRE.description", "charcoal", 100, (c) => c instanceof SingleTypeChallenge && c.value === 10 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_WATER: new ChallengeAchv("MONO_WATER", "", "MONO_WATER.description", "mystic_water", 100, (c) => c instanceof SingleTypeChallenge && c.value === 11 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_GRASS: new ChallengeAchv("MONO_GRASS", "", "MONO_GRASS.description", "miracle_seed", 100, (c) => c instanceof SingleTypeChallenge && c.value === 12 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_ELECTRIC: new ChallengeAchv("MONO_ELECTRIC", "", "MONO_ELECTRIC.description", "magnet", 100, (c) => c instanceof SingleTypeChallenge && c.value === 13 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_PSYCHIC: new ChallengeAchv("MONO_PSYCHIC", "", "MONO_PSYCHIC.description", "twisted_spoon", 100, (c) => c instanceof SingleTypeChallenge && c.value === 14 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_ICE: new ChallengeAchv("MONO_ICE", "", "MONO_ICE.description", "never_melt_ice", 100, (c) => c instanceof SingleTypeChallenge && c.value === 15 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_DRAGON: new ChallengeAchv("MONO_DRAGON", "", "MONO_DRAGON.description", "dragon_fang", 100, (c) => c instanceof SingleTypeChallenge && c.value === 16 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_DARK: new ChallengeAchv("MONO_DARK", "", "MONO_DARK.description", "black_glasses", 100, (c) => c instanceof SingleTypeChallenge && c.value === 17 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + MONO_FAIRY: new ChallengeAchv("MONO_FAIRY", "", "MONO_FAIRY.description", "fairy_feather", 100, (c) => c instanceof SingleTypeChallenge && c.value === 18 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), + FRESH_START: new ChallengeAchv("FRESH_START", "", "FRESH_START.description", "reviver_seed", 100, (c) => c instanceof FreshStartChallenge && c.value > 0 && !globalScene.gameMode.challenges.some(c => c.id === Challenges.INVERSE_BATTLE && c.value > 0)), INVERSE_BATTLE: new ChallengeAchv("INVERSE_BATTLE", "", "INVERSE_BATTLE.description", "inverse", 100, c => c instanceof InverseBattleChallenge && c.value > 0), BREEDERS_IN_SPACE: new Achv("BREEDERS_IN_SPACE", "", "BREEDERS_IN_SPACE.description", "moon_stone", 50).setSecret(), }; diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 3e3a6ce8f8b9..7abb626e854e 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -1,5 +1,6 @@ import i18next from "i18next"; -import BattleScene, { bypassLogin, PokeballCounts } from "#app/battle-scene"; +import { bypassLogin, PokeballCounts } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import Pokemon, { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; import { pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions"; import PokemonSpecies, { allSpecies, getPokemonSpecies, noStarterFormKeys } from "#app/data/pokemon-species"; @@ -298,8 +299,6 @@ const systemShortKeys = { }; export class GameData { - private scene: BattleScene; - public trainerId: integer; public secretId: integer; @@ -323,8 +322,7 @@ export class GameData { public eggPity: integer[]; public unlockPity: integer[]; - constructor(scene: BattleScene) { - this.scene = scene; + constructor() { this.loadSettings(); this.loadGamepadSettings(); this.loadMappingConfigs(); @@ -367,7 +365,7 @@ export class GameData { voucherUnlocks: this.voucherUnlocks, voucherCounts: this.voucherCounts, eggs: this.eggs.map(e => new EggData(e)), - gameVersion: this.scene.game.config.gameVersion, + gameVersion: globalScene.game.config.gameVersion, timestamp: new Date().getTime(), eggPity: this.eggPity.slice(0), unlockPity: this.unlockPity.slice(0) @@ -388,7 +386,7 @@ export class GameData { public saveSystem(): Promise { return new Promise(resolve => { - this.scene.ui.savingIcon.show(); + globalScene.ui.savingIcon.show(); const data = this.getSystemSaveData(); const maxIntAttrValue = 0x80000000; @@ -399,11 +397,11 @@ export class GameData { if (!bypassLogin) { pokerogueApi.savedata.system.update({ clientSessionId }, systemData) .then(error => { - this.scene.ui.savingIcon.hide(); + globalScene.ui.savingIcon.hide(); if (error) { if (error.startsWith("session out of date")) { - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new ReloadSessionPhase(this.scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new ReloadSessionPhase()); } console.error(error); return resolve(false); @@ -411,7 +409,7 @@ export class GameData { resolve(true); }); } else { - this.scene.ui.savingIcon.hide(); + globalScene.ui.savingIcon.hide(); resolve(true); } @@ -431,10 +429,10 @@ export class GameData { .then(saveDataOrErr => { if (!saveDataOrErr || saveDataOrErr.length === 0 || saveDataOrErr[0] !== "{") { if (saveDataOrErr?.startsWith("sql: no rows in result set")) { - this.scene.queueMessage("Save data could not be found. If this is a new account, you can safely ignore this message.", null, true); + globalScene.queueMessage("Save data could not be found. If this is a new account, you can safely ignore this message.", null, true); return resolve(true); } else if (saveDataOrErr?.includes("Too many connections")) { - this.scene.queueMessage("Too many people are trying to connect and the server is overloaded. Please try again later.", null, true); + globalScene.queueMessage("Too many people are trying to connect and the server is overloaded. Please try again later.", null, true); return resolve(false); } console.error(saveDataOrErr); @@ -574,7 +572,7 @@ export class GameData { * Retrieves current run history data, organized by time stamp. * At the moment, only retrievable from locale cache */ - async getRunHistoryData(scene: BattleScene): Promise { + async getRunHistoryData(): Promise { if (!Utils.isLocal) { /** * Networking Code DO NOT DELETE! @@ -623,13 +621,12 @@ export class GameData { /** * Saves a new entry to Run History - * @param scene: BattleScene object * @param runEntry: most recent SessionSaveData of the run * @param isVictory: result of the run * Arbitrary limit of 25 runs per player - Will delete runs, starting with the oldest one, if needed */ - async saveRunHistory(scene: BattleScene, runEntry : SessionSaveData, isVictory: boolean): Promise { - const runHistoryData = await this.getRunHistoryData(scene); + async saveRunHistory(runEntry : SessionSaveData, isVictory: boolean): Promise { + const runHistoryData = await this.getRunHistoryData(); // runHistoryData should always return run history or {} empty object let timestamps = Object.keys(runHistoryData).map(Number); @@ -707,8 +704,8 @@ export class GameData { const systemData = await pokerogueApi.savedata.system.verify({ clientSessionId }); if (systemData) { - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new ReloadSessionPhase(this.scene, JSON.stringify(systemData))); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new ReloadSessionPhase(JSON.stringify(systemData))); this.clearLocalData(); return false; } @@ -738,10 +735,10 @@ export class GameData { settings = JSON.parse(localStorage.getItem("settings")!); // TODO: is this bang correct? } - setSetting(this.scene, setting, valueIndex); + setSetting(setting, valueIndex); settings[setting] = valueIndex; - settings["gameVersion"] = this.scene.game.config.gameVersion; + settings["gameVersion"] = globalScene.game.config.gameVersion; localStorage.setItem("settings", JSON.stringify(settings)); @@ -787,7 +784,7 @@ export class GameData { const mappingConfigs = JSON.parse(localStorage.getItem("mappingConfigs")!); // Parse the existing 'mappingConfigs' from localStorage // TODO: is this bang correct? for (const key of Object.keys(mappingConfigs)) {// Iterate over the keys of the mapping configurations - this.scene.inputController.injectConfig(key, mappingConfigs[key]); + globalScene.inputController.injectConfig(key, mappingConfigs[key]); } // Inject each configuration into the input controller for the corresponding key return true; // Return true to indicate the operation was successful @@ -798,7 +795,7 @@ export class GameData { return false; } // If 'mappingConfigs' does not exist, return false localStorage.removeItem("mappingConfigs"); - this.scene.inputController.resetConfigs(); + globalScene.inputController.resetConfigs(); return true; // TODO: is `true` the correct return value? } @@ -823,9 +820,9 @@ export class GameData { } if (device === Device.GAMEPAD) { - setSettingGamepad(this.scene, setting as SettingGamepad, valueIndex); // Set the gamepad setting in the current scene + setSettingGamepad(setting as SettingGamepad, valueIndex); } else if (device === Device.KEYBOARD) { - setSettingKeyboard(this.scene, setting as SettingKeyboard, valueIndex); // Set the keyboard setting in the current scene + setSettingKeyboard(setting as SettingKeyboard, valueIndex); } Object.keys(settingDefaults).forEach(s => { // Iterate over the default gamepad settings @@ -844,7 +841,7 @@ export class GameData { * @returns true if succesful, false if not */ private loadSettings(): boolean { - resetSettings(this.scene); + resetSettings(); if (!localStorage.hasOwnProperty("settings")) { return false; @@ -855,14 +852,14 @@ export class GameData { applySettingsVersionMigration(settings); for (const setting of Object.keys(settings)) { - setSetting(this.scene, setting, settings[setting]); + setSetting(setting, settings[setting]); } return true; // TODO: is `true` the correct return value? } private loadGamepadSettings(): boolean { - Object.values(SettingGamepad).map(setting => setting as SettingGamepad).forEach(setting => setSettingGamepad(this.scene, setting, settingGamepadDefaults[setting])); + Object.values(SettingGamepad).map(setting => setting as SettingGamepad).forEach(setting => setSettingGamepad(setting, settingGamepadDefaults[setting])); if (!localStorage.hasOwnProperty("settingsGamepad")) { return false; @@ -870,7 +867,7 @@ export class GameData { const settingsGamepad = JSON.parse(localStorage.getItem("settingsGamepad")!); // TODO: is this bang correct? for (const setting of Object.keys(settingsGamepad)) { - setSettingGamepad(this.scene, setting as SettingGamepad, settingsGamepad[setting]); + setSettingGamepad(setting as SettingGamepad, settingsGamepad[setting]); } return true; // TODO: is `true` the correct return value? @@ -943,27 +940,27 @@ export class GameData { return ret; } - public getSessionSaveData(scene: BattleScene): SessionSaveData { + public getSessionSaveData(): SessionSaveData { return { - seed: scene.seed, - playTime: scene.sessionPlayTime, - gameMode: scene.gameMode.modeId, - party: scene.getPlayerParty().map(p => new PokemonData(p)), - enemyParty: scene.getEnemyParty().map(p => new PokemonData(p)), - modifiers: scene.findModifiers(() => true).map(m => new PersistentModifierData(m, true)), - enemyModifiers: scene.findModifiers(() => true, false).map(m => new PersistentModifierData(m, false)), - arena: new ArenaData(scene.arena), - pokeballCounts: scene.pokeballCounts, - money: Math.floor(scene.money), - score: scene.score, - waveIndex: scene.currentBattle.waveIndex, - battleType: scene.currentBattle.battleType, - trainer: scene.currentBattle.battleType === BattleType.TRAINER ? new TrainerData(scene.currentBattle.trainer) : null, - gameVersion: scene.game.config.gameVersion, + seed: globalScene.seed, + playTime: globalScene.sessionPlayTime, + gameMode: globalScene.gameMode.modeId, + party: globalScene.getPlayerParty().map(p => new PokemonData(p)), + enemyParty: globalScene.getEnemyParty().map(p => new PokemonData(p)), + modifiers: globalScene.findModifiers(() => true).map(m => new PersistentModifierData(m, true)), + enemyModifiers: globalScene.findModifiers(() => true, false).map(m => new PersistentModifierData(m, false)), + arena: new ArenaData(globalScene.arena), + pokeballCounts: globalScene.pokeballCounts, + money: Math.floor(globalScene.money), + score: globalScene.score, + waveIndex: globalScene.currentBattle.waveIndex, + battleType: globalScene.currentBattle.battleType, + trainer: globalScene.currentBattle.battleType === BattleType.TRAINER ? new TrainerData(globalScene.currentBattle.trainer) : null, + gameVersion: globalScene.game.config.gameVersion, timestamp: new Date().getTime(), - challenges: scene.gameMode.challenges.map(c => new ChallengeData(c)), - mysteryEncounterType: scene.currentBattle.mysteryEncounter?.encounterType ?? -1, - mysteryEncounterSaveData: scene.mysteryEncounterSaveData + challenges: globalScene.gameMode.challenges.map(c => new ChallengeData(c)), + mysteryEncounterType: globalScene.currentBattle.mysteryEncounter?.encounterType ?? -1, + mysteryEncounterSaveData: globalScene.mysteryEncounterSaveData } as SessionSaveData; } @@ -1005,68 +1002,68 @@ export class GameData { }); } - loadSession(scene: BattleScene, slotId: integer, sessionData?: SessionSaveData): Promise { + loadSession(slotId: integer, sessionData?: SessionSaveData): Promise { return new Promise(async (resolve, reject) => { try { const initSessionFromData = async (sessionData: SessionSaveData) => { console.debug(sessionData); - scene.gameMode = getGameMode(sessionData.gameMode || GameModes.CLASSIC); + globalScene.gameMode = getGameMode(sessionData.gameMode || GameModes.CLASSIC); if (sessionData.challenges) { - scene.gameMode.challenges = sessionData.challenges.map(c => c.toChallenge()); + globalScene.gameMode.challenges = sessionData.challenges.map(c => c.toChallenge()); } - scene.setSeed(sessionData.seed || scene.game.config.seed[0]); - scene.resetSeed(); + globalScene.setSeed(sessionData.seed || globalScene.game.config.seed[0]); + globalScene.resetSeed(); - console.log("Seed:", scene.seed); + console.log("Seed:", globalScene.seed); - scene.sessionPlayTime = sessionData.playTime || 0; - scene.lastSavePlayTime = 0; + globalScene.sessionPlayTime = sessionData.playTime || 0; + globalScene.lastSavePlayTime = 0; const loadPokemonAssets: Promise[] = []; - const party = scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); party.splice(0, party.length); for (const p of sessionData.party) { - const pokemon = p.toPokemon(scene) as PlayerPokemon; + const pokemon = p.toPokemon() as PlayerPokemon; pokemon.setVisible(false); loadPokemonAssets.push(pokemon.loadAssets()); party.push(pokemon); } - Object.keys(scene.pokeballCounts).forEach((key: string) => { - scene.pokeballCounts[key] = sessionData.pokeballCounts[key] || 0; + Object.keys(globalScene.pokeballCounts).forEach((key: string) => { + globalScene.pokeballCounts[key] = sessionData.pokeballCounts[key] || 0; }); if (Overrides.POKEBALL_OVERRIDE.active) { - scene.pokeballCounts = Overrides.POKEBALL_OVERRIDE.pokeballs; + globalScene.pokeballCounts = Overrides.POKEBALL_OVERRIDE.pokeballs; } - scene.money = Math.floor(sessionData.money || 0); - scene.updateMoneyText(); + globalScene.money = Math.floor(sessionData.money || 0); + globalScene.updateMoneyText(); - if (scene.money > this.gameStats.highestMoney) { - this.gameStats.highestMoney = scene.money; + if (globalScene.money > this.gameStats.highestMoney) { + this.gameStats.highestMoney = globalScene.money; } - scene.score = sessionData.score; - scene.updateScoreText(); + globalScene.score = sessionData.score; + globalScene.updateScoreText(); - scene.mysteryEncounterSaveData = new MysteryEncounterSaveData(sessionData.mysteryEncounterSaveData); + globalScene.mysteryEncounterSaveData = new MysteryEncounterSaveData(sessionData.mysteryEncounterSaveData); - scene.newArena(sessionData.arena.biome); + globalScene.newArena(sessionData.arena.biome); const battleType = sessionData.battleType || 0; const trainerConfig = sessionData.trainer ? trainerConfigs[sessionData.trainer.trainerType] : null; const mysteryEncounterType = sessionData.mysteryEncounterType !== -1 ? sessionData.mysteryEncounterType : undefined; - const battle = scene.newBattle(sessionData.waveIndex, battleType, sessionData.trainer, battleType === BattleType.TRAINER ? trainerConfig?.doubleOnly || sessionData.trainer?.variant === TrainerVariant.DOUBLE : sessionData.enemyParty.length > 1, mysteryEncounterType)!; // TODO: is this bang correct? + const battle = globalScene.newBattle(sessionData.waveIndex, battleType, sessionData.trainer, battleType === BattleType.TRAINER ? trainerConfig?.doubleOnly || sessionData.trainer?.variant === TrainerVariant.DOUBLE : sessionData.enemyParty.length > 1, mysteryEncounterType)!; // TODO: is this bang correct? battle.enemyLevels = sessionData.enemyParty.map(p => p.level); - scene.arena.init(); + globalScene.arena.init(); sessionData.enemyParty.forEach((enemyData, e) => { - const enemyPokemon = enemyData.toPokemon(scene, battleType, e, sessionData.trainer?.variant === TrainerVariant.DOUBLE) as EnemyPokemon; + const enemyPokemon = enemyData.toPokemon(battleType, e, sessionData.trainer?.variant === TrainerVariant.DOUBLE) as EnemyPokemon; battle.enemyParty[e] = enemyPokemon; if (battleType === BattleType.WILD) { battle.seenEnemyPartyMemberIds.add(enemyPokemon.id); @@ -1075,41 +1072,41 @@ export class GameData { loadPokemonAssets.push(enemyPokemon.loadAssets()); }); - scene.arena.weather = sessionData.arena.weather; - scene.arena.eventTarget.dispatchEvent(new WeatherChangedEvent(WeatherType.NONE, scene.arena.weather?.weatherType!, scene.arena.weather?.turnsLeft!)); // TODO: is this bang correct? + globalScene.arena.weather = sessionData.arena.weather; + globalScene.arena.eventTarget.dispatchEvent(new WeatherChangedEvent(WeatherType.NONE, globalScene.arena.weather?.weatherType!, globalScene.arena.weather?.turnsLeft!)); // TODO: is this bang correct? - scene.arena.terrain = sessionData.arena.terrain; - scene.arena.eventTarget.dispatchEvent(new TerrainChangedEvent(TerrainType.NONE, scene.arena.terrain?.terrainType!, scene.arena.terrain?.turnsLeft!)); // TODO: is this bang correct? + globalScene.arena.terrain = sessionData.arena.terrain; + globalScene.arena.eventTarget.dispatchEvent(new TerrainChangedEvent(TerrainType.NONE, globalScene.arena.terrain?.terrainType!, globalScene.arena.terrain?.turnsLeft!)); // TODO: is this bang correct? - scene.arena.tags = sessionData.arena.tags; - if (scene.arena.tags) { - for (const tag of scene.arena.tags) { + globalScene.arena.tags = sessionData.arena.tags; + if (globalScene.arena.tags) { + for (const tag of globalScene.arena.tags) { if (tag instanceof ArenaTrapTag) { const { tagType, side, turnCount, layers, maxLayers } = tag as ArenaTrapTag; - scene.arena.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, layers, maxLayers)); + globalScene.arena.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, layers, maxLayers)); } else { - scene.arena.eventTarget.dispatchEvent(new TagAddedEvent(tag.tagType, tag.side, tag.turnCount)); + globalScene.arena.eventTarget.dispatchEvent(new TagAddedEvent(tag.tagType, tag.side, tag.turnCount)); } } } for (const modifierData of sessionData.modifiers) { - const modifier = modifierData.toModifier(scene, Modifier[modifierData.className]); + const modifier = modifierData.toModifier(Modifier[modifierData.className]); if (modifier) { - scene.addModifier(modifier, true); + globalScene.addModifier(modifier, true); } } - scene.updateModifiers(true); + globalScene.updateModifiers(true); for (const enemyModifierData of sessionData.enemyModifiers) { - const modifier = enemyModifierData.toModifier(scene, Modifier[enemyModifierData.className]); + const modifier = enemyModifierData.toModifier(Modifier[enemyModifierData.className]); if (modifier) { - scene.addEnemyModifier(modifier, true); + globalScene.addEnemyModifier(modifier, true); } } - scene.updateModifiers(false); + globalScene.updateModifiers(false); Promise.all(loadPokemonAssets).then(() => resolve(true)); }; @@ -1150,8 +1147,8 @@ export class GameData { pokerogueApi.savedata.session.delete({ slot: slotId, clientSessionId }).then(error => { if (error) { if (error.startsWith("session out of date")) { - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new ReloadSessionPhase(this.scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new ReloadSessionPhase()); } console.error(error); resolve(false); @@ -1172,9 +1169,9 @@ export class GameData { /* Defines a localStorage item 'daily' to check on clears, offline implementation of savedata/newclear API If a GameModes clear other than Daily is checked, newClear = true as usual If a Daily mode is cleared, checks if it was already cleared before, based on seed, and returns true only to new daily clear runs */ - offlineNewClear(scene: BattleScene): Promise { + offlineNewClear(): Promise { return new Promise(resolve => { - const sessionData = this.getSessionSaveData(scene); + const sessionData = this.getSessionSaveData(); const seed = sessionData.seed; let daily: string[] = []; @@ -1205,14 +1202,14 @@ export class GameData { * After session data is removed, attempt to update user info so the menu updates * To delete an unfinished run instead, use {@linkcode deleteSession} */ - async tryClearSession(scene: BattleScene, slotId: integer): Promise<[success: boolean, newClear: boolean]> { + async tryClearSession(slotId: integer): Promise<[success: boolean, newClear: boolean]> { let result: [boolean, boolean] = [ false, false ]; if (bypassLogin) { localStorage.removeItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`); result = [ true, true ]; } else { - const sessionData = this.getSessionSaveData(scene); + const sessionData = this.getSessionSaveData(); const { trainerId } = this; const jsonResponse = await pokerogueApi.savedata.session.clear({ slot: slotId, trainerId, clientSessionId }, sessionData); @@ -1224,8 +1221,8 @@ export class GameData { localStorage.removeItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`); } else { if (jsonResponse && jsonResponse.error?.startsWith("session out of date")) { - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new ReloadSessionPhase(this.scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new ReloadSessionPhase()); } console.error(jsonResponse); @@ -1240,12 +1237,6 @@ export class GameData { parseSessionData(dataStr: string): SessionSaveData { const sessionData = JSON.parse(dataStr, (k: string, v: any) => { - /*const versions = [ scene.game.config.gameVersion, sessionData.gameVersion || '0.0.0' ]; - - if (versions[0] !== versions[1]) { - const [ versionNumbers, oldVersionNumbers ] = versions.map(ver => ver.split('.').map(v => parseInt(v))); - }*/ - if (k === "party" || k === "enemyParty") { const ret: PokemonData[] = []; if (v === null) { @@ -1310,16 +1301,18 @@ export class GameData { return sessionData; } - saveAll(scene: BattleScene, skipVerification: boolean = false, sync: boolean = false, useCachedSession: boolean = false, useCachedSystem: boolean = false): Promise { + saveAll(skipVerification: boolean = false, sync: boolean = false, useCachedSession: boolean = false, useCachedSystem: boolean = false): Promise { return new Promise(resolve => { Utils.executeIf(!skipVerification, updateUserInfo).then(success => { if (success !== null && !success) { return resolve(false); } if (sync) { - this.scene.ui.savingIcon.show(); + globalScene.ui.savingIcon.show(); } - const sessionData = useCachedSession ? this.parseSessionData(decrypt(localStorage.getItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ""}_${loggedInUser?.username}`)!, bypassLogin)) : this.getSessionSaveData(scene); // TODO: is this bang correct? + const sessionData = useCachedSession ? + this.parseSessionData(decrypt(localStorage.getItem(`sessionData${globalScene.sessionSlotId ? globalScene.sessionSlotId : ""}_${loggedInUser?.username}`)!, bypassLogin)) // TODO: is this bang correct? + : this.getSessionSaveData(); const maxIntAttrValue = 0x80000000; const systemData = useCachedSystem ? this.parseSystemData(decrypt(localStorage.getItem(`data_${loggedInUser?.username}`)!, bypassLogin)) : this.getSystemSaveData(); // TODO: is this bang correct? @@ -1327,13 +1320,13 @@ export class GameData { const request = { system: systemData, session: sessionData, - sessionSlotId: scene.sessionSlotId, + sessionSlotId: globalScene.sessionSlotId, clientSessionId: clientSessionId }; localStorage.setItem(`data_${loggedInUser?.username}`, encrypt(JSON.stringify(systemData, (k: any, v: any) => typeof v === "bigint" ? v <= maxIntAttrValue ? Number(v) : v.toString() : v), bypassLogin)); - localStorage.setItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ""}_${loggedInUser?.username}`, encrypt(JSON.stringify(sessionData), bypassLogin)); + localStorage.setItem(`sessionData${globalScene.sessionSlotId ? globalScene.sessionSlotId : ""}_${loggedInUser?.username}`, encrypt(JSON.stringify(sessionData), bypassLogin)); console.debug("Session data saved"); @@ -1341,13 +1334,13 @@ export class GameData { pokerogueApi.savedata.updateAll(request) .then(error => { if (sync) { - this.scene.lastSavePlayTime = 0; - this.scene.ui.savingIcon.hide(); + globalScene.lastSavePlayTime = 0; + globalScene.ui.savingIcon.hide(); } if (error) { if (error.startsWith("session out of date")) { - this.scene.clearPhaseQueue(); - this.scene.unshiftPhase(new ReloadSessionPhase(this.scene)); + globalScene.clearPhaseQueue(); + globalScene.unshiftPhase(new ReloadSessionPhase()); } console.error(error); return resolve(false); @@ -1356,7 +1349,7 @@ export class GameData { }); } else { this.verify().then(success => { - this.scene.ui.savingIcon.hide(); + globalScene.ui.savingIcon.hide(); resolve(success); }); } @@ -1462,15 +1455,15 @@ export class GameData { console.error(ex); } - const displayError = (error: string) => this.scene.ui.showText(error, null, () => this.scene.ui.showText("", 0), Utils.fixedInt(1500)); + const displayError = (error: string) => globalScene.ui.showText(error, null, () => globalScene.ui.showText("", 0), Utils.fixedInt(1500)); dataName = dataName!; // tell TS compiler that dataName is defined! if (!valid) { - return this.scene.ui.showText(`Your ${dataName} data could not be loaded. It may be corrupted.`, null, () => this.scene.ui.showText("", 0), Utils.fixedInt(1500)); + return globalScene.ui.showText(`Your ${dataName} data could not be loaded. It may be corrupted.`, null, () => globalScene.ui.showText("", 0), Utils.fixedInt(1500)); } - this.scene.ui.showText(`Your ${dataName} data will be overridden and the page will reload. Proceed?`, null, () => { - this.scene.ui.setOverlayMode(Mode.CONFIRM, () => { + globalScene.ui.showText(`Your ${dataName} data will be overridden and the page will reload. Proceed?`, null, () => { + globalScene.ui.setOverlayMode(Mode.CONFIRM, () => { localStorage.setItem(dataKey, encrypt(dataStr, bypassLogin)); if (!bypassLogin && dataType < GameDataType.SETTINGS) { @@ -1498,8 +1491,8 @@ export class GameData { window.location = window.location; } }, () => { - this.scene.ui.revertMode(); - this.scene.ui.showText("", 0); + globalScene.ui.revertMode(); + globalScene.ui.showText("", 0); }, false, -98); }); }; @@ -1509,9 +1502,6 @@ export class GameData { } ); saveFile.click(); - /*(this.scene.plugins.get('rexfilechooserplugin') as FileChooserPlugin).open({ accept: '.prsv' }) - .then(result => { - });*/ } private initDexData(): void { @@ -1527,7 +1517,7 @@ export class GameData { const defaultStarterNatures: Nature[] = []; - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { const neutralNatures = [ Nature.HARDY, Nature.DOCILE, Nature.SERIOUS, Nature.BASHFUL, Nature.QUIRKY ]; for (let s = 0; s < defaultStarterSpecies.length; s++) { defaultStarterNatures.push(Utils.randSeedItem(neutralNatures)); @@ -1571,7 +1561,7 @@ export class GameData { setPokemonSeen(pokemon: Pokemon, incrementCount: boolean = true, trainer: boolean = false): void { // Some Mystery Encounters block updates to these stats - if (this.scene.currentBattle?.isBattleMysteryEncounter() && this.scene.currentBattle.mysteryEncounter?.preventGameStatsUpdates) { + if (globalScene.currentBattle?.isBattleMysteryEncounter() && globalScene.currentBattle.mysteryEncounter?.preventGameStatsUpdates) { return; } const dexEntry = this.dexData[pokemon.species.speciesId]; @@ -1604,7 +1594,7 @@ export class GameData { // If incrementCount === false (not a catch scenario), only update the pokemon's dex data if the Pokemon has already been marked as caught in dex // Prevents form changes, nature changes, etc. from unintentionally updating the dex data of a "rental" pokemon const speciesRootForm = pokemon.species.getRootSpeciesId(); - if (!incrementCount && !this.scene.gameData.dexData[speciesRootForm].caughtAttr) { + if (!incrementCount && !globalScene.gameData.dexData[speciesRootForm].caughtAttr) { return Promise.resolve(false); } else { return this.setPokemonSpeciesCaught(pokemon, pokemon.species, incrementCount, fromEgg, showMessage); @@ -1677,7 +1667,7 @@ export class GameData { } } - if (!hasPrevolution && (!pokemon.scene.gameMode.isDaily || hasNewAttr || fromEgg)) { + if (!hasPrevolution && (!globalScene.gameMode.isDaily || hasNewAttr || fromEgg)) { this.addStarterCandy(species, (1 * (pokemon.isShiny() ? 5 * (1 << (pokemon.variant ?? 0)) : 1)) * (fromEgg || pokemon.isBoss() ? 2 : 1)); } } @@ -1696,8 +1686,8 @@ export class GameData { resolve(true); return; } - this.scene.playSound("level_up_fanfare"); - this.scene.ui.showText(i18next.t("battle:addedAsAStarter", { pokemonName: species.name }), null, () => checkPrevolution(true), null, true); + globalScene.playSound("level_up_fanfare"); + globalScene.ui.showText(i18next.t("battle:addedAsAStarter", { pokemonName: species.name }), null, () => checkPrevolution(true), null, true); } else { checkPrevolution(false); } @@ -1712,25 +1702,25 @@ export class GameData { } if (!this.starterData[speciesIdToIncrement].classicWinCount) { - this.scene.gameData.gameStats.ribbonsOwned++; + globalScene.gameData.gameStats.ribbonsOwned++; } - const ribbonsInStats: integer = this.scene.gameData.gameStats.ribbonsOwned; + const ribbonsInStats: integer = globalScene.gameData.gameStats.ribbonsOwned; if (ribbonsInStats >= 100) { - this.scene.validateAchv(achvs._100_RIBBONS); + globalScene.validateAchv(achvs._100_RIBBONS); } if (ribbonsInStats >= 75) { - this.scene.validateAchv(achvs._75_RIBBONS); + globalScene.validateAchv(achvs._75_RIBBONS); } if (ribbonsInStats >= 50) { - this.scene.validateAchv(achvs._50_RIBBONS); + globalScene.validateAchv(achvs._50_RIBBONS); } if (ribbonsInStats >= 25) { - this.scene.validateAchv(achvs._25_RIBBONS); + globalScene.validateAchv(achvs._25_RIBBONS); } if (ribbonsInStats >= 10) { - this.scene.validateAchv(achvs._10_RIBBONS); + globalScene.validateAchv(achvs._10_RIBBONS); } return ++this.starterData[speciesIdToIncrement].classicWinCount; @@ -1745,8 +1735,8 @@ export class GameData { addStarterCandy(species: PokemonSpecies, count: integer): void { // Only gain candies if the Pokemon has already been marked as caught in dex (ignore "rental" pokemon) const speciesRootForm = species.getRootSpeciesId(); - if (this.scene.gameData.dexData[speciesRootForm].caughtAttr) { - this.scene.candyBar.showStarterSpeciesCandy(species.speciesId, count); + if (globalScene.gameData.dexData[speciesRootForm].caughtAttr) { + globalScene.candyBar.showStarterSpeciesCandy(species.speciesId, count); this.starterData[species.speciesId].candyCount += count; } } @@ -1782,12 +1772,12 @@ export class GameData { resolve(true); return; } - this.scene.playSound("level_up_fanfare"); + globalScene.playSound("level_up_fanfare"); const moveName = allMoves[speciesEggMoves[speciesId][eggMoveIndex]].name; let message = prependSpeciesToMessage ? species.getName() + " " : ""; message += eggMoveIndex === 3 ? i18next.t("egg:rareEggMoveUnlock", { moveName: moveName }) : i18next.t("egg:eggMoveUnlock", { moveName: moveName }); - this.scene.ui.showText(message, null, () => resolve(true), null, true); + globalScene.ui.showText(message, null, () => resolve(true), null, true); }); } @@ -1820,7 +1810,7 @@ export class GameData { updateSpeciesDexIvs(speciesId: Species, ivs: integer[]): void { let dexEntry: DexEntry; do { - dexEntry = this.scene.gameData.dexData[speciesId]; + dexEntry = globalScene.gameData.dexData[speciesId]; const dexIvs = dexEntry.ivs; for (let i = 0; i < dexIvs.length; i++) { if (dexIvs[i] < ivs[i]) { @@ -1828,7 +1818,7 @@ export class GameData { } } if (dexIvs.filter(iv => iv === 31).length === 6) { - this.scene.validateAchv(achvs.PERFECT_IVS); + globalScene.validateAchv(achvs.PERFECT_IVS); } } while (pokemonPrevolutions.hasOwnProperty(speciesId) && (speciesId = pokemonPrevolutions[speciesId])); } @@ -1966,7 +1956,7 @@ export class GameData { } const cost = new Utils.NumberHolder(value); - applyChallenges(this.scene.gameMode, ChallengeType.STARTER_COST, speciesId, cost); + applyChallenges(globalScene.gameMode, ChallengeType.STARTER_COST, speciesId, cost); return cost.value; } diff --git a/src/system/game-speed.ts b/src/system/game-speed.ts index 861c3d4705d0..66687aa8a4c7 100644 --- a/src/system/game-speed.ts +++ b/src/system/game-speed.ts @@ -1,7 +1,8 @@ import SoundFade from "phaser3-rex-plugins/plugins/soundfade"; import FadeIn from "phaser3-rex-plugins/plugins/audio/fade/FadeIn"; import FadeOut from "phaser3-rex-plugins/plugins/audio/fade/FadeOut"; -import BattleScene from "../battle-scene"; +import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "../utils"; type FadeIn = typeof FadeIn; @@ -98,7 +99,7 @@ export function initGameSpeed() { sound: Phaser.Sound.BaseSound, duration: number, destroy?: boolean - ) => originalFadeOut(scene, sound, transformValue(duration), destroy)) as FadeOut; + ) => originalFadeOut(globalScene, sound, transformValue(duration), destroy)) as FadeOut; const originalFadeIn = SoundFade.fadeIn; SoundFade.fadeIn = (( @@ -107,5 +108,5 @@ export function initGameSpeed() { duration: number, endVolume?: number, startVolume?: number - ) => originalFadeIn(scene, sound, transformValue(duration), endVolume, startVolume)) as FadeIn; + ) => originalFadeIn(globalScene, sound, transformValue(duration), endVolume, startVolume)) as FadeIn; } diff --git a/src/system/modifier-data.ts b/src/system/modifier-data.ts index c68f9ccb47da..b02a0fb1d475 100644 --- a/src/system/modifier-data.ts +++ b/src/system/modifier-data.ts @@ -1,6 +1,6 @@ -import BattleScene from "../battle-scene"; -import { PersistentModifier } from "../modifier/modifier"; -import { GeneratedPersistentModifierType, ModifierType, ModifierTypeGenerator, getModifierTypeFuncById } from "../modifier/modifier-type"; +import { globalScene } from "#app/global-scene"; +import { PersistentModifier } from "#app/modifier/modifier"; +import { GeneratedPersistentModifierType, ModifierType, ModifierTypeGenerator, getModifierTypeFuncById } from "#app/modifier/modifier-type"; export default class ModifierData { public player: boolean; @@ -27,7 +27,7 @@ export default class ModifierData { this.className = sourceModifier ? sourceModifier.constructor.name : source.className; } - toModifier(scene: BattleScene, constructor: any): PersistentModifier | null { + toModifier(constructor: any): PersistentModifier | null { const typeFunc = getModifierTypeFuncById(this.typeId); if (!typeFunc) { return null; @@ -38,13 +38,13 @@ export default class ModifierData { type.id = this.typeId; if (type instanceof ModifierTypeGenerator) { - type = (type as ModifierTypeGenerator).generateType(this.player ? scene.getPlayerParty() : scene.getEnemyField(), this.typePregenArgs); + type = (type as ModifierTypeGenerator).generateType(this.player ? globalScene.getPlayerParty() : globalScene.getEnemyField(), this.typePregenArgs); } const ret = Reflect.construct(constructor, ([ type ] as any[]).concat(this.args).concat(this.stackCount)) as PersistentModifier; - if (ret.stackCount > ret.getMaxStackCount(scene)) { - ret.stackCount = ret.getMaxStackCount(scene); + if (ret.stackCount > ret.getMaxStackCount()) { + ret.stackCount = ret.getMaxStackCount(); } return ret; diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 64801cc0ff1f..ee745dad0030 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -1,5 +1,5 @@ import { BattleType } from "../battle"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { Gender } from "../data/gender"; import { Nature } from "#enums/nature"; import { PokeballType } from "#enums/pokeball"; @@ -163,15 +163,15 @@ export default class PokemonData { } } - toPokemon(scene: BattleScene, battleType?: BattleType, partyMemberIndex: integer = 0, double: boolean = false): Pokemon { + toPokemon(battleType?: BattleType, partyMemberIndex: integer = 0, double: boolean = false): Pokemon { const species = getPokemonSpecies(this.species); const ret: Pokemon = this.player - ? scene.addPlayerPokemon(species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this, (playerPokemon) => { + ? globalScene.addPlayerPokemon(species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this, (playerPokemon) => { if (this.nickname) { playerPokemon.nickname = this.nickname; } }) - : scene.addEnemyPokemon(species, this.level, battleType === BattleType.TRAINER ? !double || !(partyMemberIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER : TrainerSlot.NONE, this.boss, false, this); + : globalScene.addEnemyPokemon(species, this.level, battleType === BattleType.TRAINER ? !double || !(partyMemberIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER : TrainerSlot.NONE, this.boss, false, this); if (this.summonData) { ret.primeSummonData(this.summonData); } diff --git a/src/system/settings/settings-gamepad.ts b/src/system/settings/settings-gamepad.ts index 322b2baac9ea..2e7df0b53afb 100644 --- a/src/system/settings/settings-gamepad.ts +++ b/src/system/settings/settings-gamepad.ts @@ -1,9 +1,9 @@ -import BattleScene from "../../battle-scene"; import SettingsGamepadUiHandler from "../../ui/settings/settings-gamepad-ui-handler"; import { Mode } from "../../ui/ui"; import { truncateString } from "../../utils"; import { Button } from "#enums/buttons"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; +import { globalScene } from "#app/global-scene"; export enum SettingGamepad { Controller = "CONTROLLER", @@ -80,12 +80,12 @@ export const settingGamepadBlackList = [ SettingKeyboard.Button_Right, ]; -export function setSettingGamepad(scene: BattleScene, setting: SettingGamepad, value: integer): boolean { +export function setSettingGamepad(setting: SettingGamepad, value: integer): boolean { switch (setting) { case SettingGamepad.Gamepad_Support: // if we change the value of the gamepad support, we call a method in the inputController to // activate or deactivate the controller listener - scene.inputController.setGamepadSupport(settingGamepadOptions[setting][value] !== "Disabled"); + globalScene.inputController.setGamepadSupport(settingGamepadOptions[setting][value] !== "Disabled"); break; case SettingGamepad.Button_Action: case SettingGamepad.Button_Cancel: @@ -101,13 +101,13 @@ export function setSettingGamepad(scene: BattleScene, setting: SettingGamepad, v case SettingGamepad.Button_Slow_Down: case SettingGamepad.Button_Submit: if (value) { - if (scene.ui) { + if (globalScene.ui) { const cancelHandler = (success: boolean = false) : boolean => { - scene.ui.revertMode(); - (scene.ui.getHandler() as SettingsGamepadUiHandler).updateBindings(); + globalScene.ui.revertMode(); + (globalScene.ui.getHandler() as SettingsGamepadUiHandler).updateBindings(); return success; }; - scene.ui.setOverlayMode(Mode.GAMEPAD_BINDING, { + globalScene.ui.setOverlayMode(Mode.GAMEPAD_BINDING, { target: setting, cancelHandler: cancelHandler, }); @@ -116,20 +116,20 @@ export function setSettingGamepad(scene: BattleScene, setting: SettingGamepad, v break; case SettingGamepad.Controller: if (value) { - const gp = scene.inputController.getGamepadsName(); - if (scene.ui && gp) { + const gp = globalScene.inputController.getGamepadsName(); + if (globalScene.ui && gp) { const cancelHandler = () => { - scene.ui.revertMode(); - (scene.ui.getHandler() as SettingsGamepadUiHandler).setOptionCursor(Object.values(SettingGamepad).indexOf(SettingGamepad.Controller), 0, true); - (scene.ui.getHandler() as SettingsGamepadUiHandler).updateBindings(); + globalScene.ui.revertMode(); + (globalScene.ui.getHandler() as SettingsGamepadUiHandler).setOptionCursor(Object.values(SettingGamepad).indexOf(SettingGamepad.Controller), 0, true); + (globalScene.ui.getHandler() as SettingsGamepadUiHandler).updateBindings(); return false; }; const changeGamepadHandler = (gamepad: string) => { - scene.inputController.setChosenGamepad(gamepad); + globalScene.inputController.setChosenGamepad(gamepad); cancelHandler(); return true; }; - scene.ui.setOverlayMode(Mode.OPTION_SELECT, { + globalScene.ui.setOverlayMode(Mode.OPTION_SELECT, { options: [ ...gp.map((g: string) => ({ label: truncateString(g, 30), // Truncate the gamepad name for display handler: () => changeGamepadHandler(g) diff --git a/src/system/settings/settings-keyboard.ts b/src/system/settings/settings-keyboard.ts index 97990f61c86f..d259710cc5d9 100644 --- a/src/system/settings/settings-keyboard.ts +++ b/src/system/settings/settings-keyboard.ts @@ -1,8 +1,8 @@ import { Button } from "#enums/buttons"; -import BattleScene from "#app/battle-scene"; import { Mode } from "#app/ui/ui"; import SettingsKeyboardUiHandler from "#app/ui/settings/settings-keyboard-ui-handler"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; export enum SettingKeyboard { // Default_Layout = "DEFAULT_LAYOUT", @@ -133,7 +133,7 @@ export const settingKeyboardBlackList = [ ]; -export function setSettingKeyboard(scene: BattleScene, setting: SettingKeyboard, value: integer): boolean { +export function setSettingKeyboard(setting: SettingKeyboard, value: integer): boolean { switch (setting) { case SettingKeyboard.Button_Up: case SettingKeyboard.Button_Down: @@ -169,40 +169,19 @@ export function setSettingKeyboard(scene: BattleScene, setting: SettingKeyboard, case SettingKeyboard.Alt_Button_Slow_Down: case SettingKeyboard.Alt_Button_Submit: if (value) { - if (scene.ui) { + if (globalScene.ui) { const cancelHandler = (success: boolean = false) : boolean => { - scene.ui.revertMode(); - (scene.ui.getHandler() as SettingsKeyboardUiHandler).updateBindings(); + globalScene.ui.revertMode(); + (globalScene.ui.getHandler() as SettingsKeyboardUiHandler).updateBindings(); return success; }; - scene.ui.setOverlayMode(Mode.KEYBOARD_BINDING, { + globalScene.ui.setOverlayMode(Mode.KEYBOARD_BINDING, { target: setting, cancelHandler: cancelHandler, }); } } break; - // case SettingKeyboard.Default_Layout: - // if (value && scene.ui) { - // const cancelHandler = () => { - // scene.ui.revertMode(); - // (scene.ui.getHandler() as SettingsKeyboardUiHandler).setOptionCursor(Object.values(SettingKeyboard).indexOf(SettingKeyboard.Default_Layout), 0, true); - // (scene.ui.getHandler() as SettingsKeyboardUiHandler).updateBindings(); - // return false; - // }; - // const changeKeyboardHandler = (keyboardLayout: string) => { - // scene.inputController.setChosenKeyboardLayout(keyboardLayout); - // cancelHandler(); - // return true; - // }; - // scene.ui.setOverlayMode(Mode.OPTION_SELECT, { - // options: [{ - // label: 'Default', - // handler: changeKeyboardHandler, - // }] - // }); - // return false; - // } } return true; diff --git a/src/system/settings/settings.ts b/src/system/settings/settings.ts index 64ddfdae5cfe..6772923335e8 100644 --- a/src/system/settings/settings.ts +++ b/src/system/settings/settings.ts @@ -1,6 +1,6 @@ import { Mode } from "#app/ui/ui"; import i18next from "i18next"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { hasTouchscreen } from "#app/touch-controls"; import { updateWindowType } from "#app/ui/ui-theme"; import { CandyUpgradeNotificationChangedEvent } from "#app/events/battle-scene"; @@ -8,22 +8,14 @@ import SettingsUiHandler from "#app/ui/settings/settings-ui-handler"; import { EaseType } from "#enums/ease-type"; import { MoneyFormat } from "#enums/money-format"; import { PlayerGender } from "#enums/player-gender"; -import { getIsInitialized, initI18n } from "#app/plugins/i18n"; -import { ShopCursorTarget } from "#app/enums/shop-cursor-target"; - -function getTranslation(key: string): string { - if (!getIsInitialized()) { - initI18n(); - } - return i18next.t(key); -} +import { ShopCursorTarget } from "#enums/shop-cursor-target"; const VOLUME_OPTIONS: SettingOption[] = new Array(11).fill(null).map((_, i) => i ? { value: (i * 10).toString(), label: (i * 10).toString(), } : { value: "Mute", - label: getTranslation("settings:mute") + label: i18next.t("settings:mute") }); const SHOP_OVERLAY_OPACITY_OPTIONS: SettingOption[] = new Array(9).fill(null).map((_, i) => { @@ -702,171 +694,169 @@ export function settingIndex(key: string) { /** * Resets all settings to their defaults - * @param scene current BattleScene */ -export function resetSettings(scene: BattleScene) { - Setting.forEach(s => setSetting(scene, s.key, s.default)); +export function resetSettings() { + Setting.forEach(s => setSetting(s.key, s.default)); } /** - * Updates a setting for current BattleScene - * @param scene current BattleScene + * Updates a setting * @param setting string ideally from SettingKeys * @param value value to update setting with * @returns true if successful, false if not */ -export function setSetting(scene: BattleScene, setting: string, value: integer): boolean { +export function setSetting(setting: string, value: integer): boolean { const index: number = settingIndex(setting); if (index === -1) { return false; } switch (Setting[index].key) { case SettingKeys.Game_Speed: - scene.gameSpeed = parseFloat(Setting[index].options[value].value.replace("x", "")); + globalScene.gameSpeed = parseFloat(Setting[index].options[value].value.replace("x", "")); break; case SettingKeys.Master_Volume: - scene.masterVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; - scene.updateSoundVolume(); + globalScene.masterVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; + globalScene.updateSoundVolume(); break; case SettingKeys.BGM_Volume: - scene.bgmVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; - scene.updateSoundVolume(); + globalScene.bgmVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; + globalScene.updateSoundVolume(); break; case SettingKeys.Field_Volume: - scene.fieldVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; - scene.updateSoundVolume(); + globalScene.fieldVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; + globalScene.updateSoundVolume(); break; case SettingKeys.SE_Volume: - scene.seVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; - scene.updateSoundVolume(); + globalScene.seVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; + globalScene.updateSoundVolume(); break; case SettingKeys.UI_Volume: - scene.uiVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; + globalScene.uiVolume = value ? parseInt(Setting[index].options[value].value) * 0.01 : 0; break; case SettingKeys.Music_Preference: - scene.musicPreference = value; + globalScene.musicPreference = value; break; case SettingKeys.Damage_Numbers: - scene.damageNumbersMode = value; + globalScene.damageNumbersMode = value; break; case SettingKeys.UI_Theme: - scene.uiTheme = value; + globalScene.uiTheme = value; break; case SettingKeys.Window_Type: - updateWindowType(scene, parseInt(Setting[index].options[value].value)); + updateWindowType(parseInt(Setting[index].options[value].value)); break; case SettingKeys.Tutorials: - scene.enableTutorials = Setting[index].options[value].value === "On"; + globalScene.enableTutorials = Setting[index].options[value].value === "On"; break; case SettingKeys.Move_Info: - scene.enableMoveInfo = Setting[index].options[value].value === "On"; + globalScene.enableMoveInfo = Setting[index].options[value].value === "On"; break; case SettingKeys.Enable_Retries: - scene.enableRetries = Setting[index].options[value].value === "On"; + globalScene.enableRetries = Setting[index].options[value].value === "On"; break; case SettingKeys.Hide_IVs: - scene.hideIvs = Setting[index].options[value].value === "On"; + globalScene.hideIvs = Setting[index].options[value].value === "On"; break; case SettingKeys.Skip_Seen_Dialogues: - scene.skipSeenDialogues = Setting[index].options[value].value === "On"; + globalScene.skipSeenDialogues = Setting[index].options[value].value === "On"; break; case SettingKeys.Egg_Skip: - scene.eggSkipPreference = value; + globalScene.eggSkipPreference = value; break; case SettingKeys.Battle_Style: - scene.battleStyle = value; + globalScene.battleStyle = value; break; case SettingKeys.Show_BGM_Bar: - scene.showBgmBar = Setting[index].options[value].value === "On"; + globalScene.showBgmBar = Setting[index].options[value].value === "On"; break; case SettingKeys.Candy_Upgrade_Notification: - if (scene.candyUpgradeNotification === value) { + if (globalScene.candyUpgradeNotification === value) { break; } - scene.candyUpgradeNotification = value; - scene.eventTarget.dispatchEvent(new CandyUpgradeNotificationChangedEvent(value)); + globalScene.candyUpgradeNotification = value; + globalScene.eventTarget.dispatchEvent(new CandyUpgradeNotificationChangedEvent(value)); break; case SettingKeys.Candy_Upgrade_Display: - scene.candyUpgradeDisplay = value; + globalScene.candyUpgradeDisplay = value; case SettingKeys.Money_Format: switch (Setting[index].options[value].value) { case "Normal": - scene.moneyFormat = MoneyFormat.NORMAL; + globalScene.moneyFormat = MoneyFormat.NORMAL; break; case "Abbreviated": - scene.moneyFormat = MoneyFormat.ABBREVIATED; + globalScene.moneyFormat = MoneyFormat.ABBREVIATED; break; } - scene.updateMoneyText(false); + globalScene.updateMoneyText(false); break; case SettingKeys.Sprite_Set: - scene.experimentalSprites = !!value; + globalScene.experimentalSprites = !!value; if (value) { - scene.initExpSprites(); + globalScene.initExpSprites(); } break; case SettingKeys.Move_Animations: - scene.moveAnimations = Setting[index].options[value].value === "On"; + globalScene.moveAnimations = Setting[index].options[value].value === "On"; break; case SettingKeys.Show_Moveset_Flyout: - scene.showMovesetFlyout = Setting[index].options[value].value === "On"; + globalScene.showMovesetFlyout = Setting[index].options[value].value === "On"; break; case SettingKeys.Show_Arena_Flyout: - scene.showArenaFlyout = Setting[index].options[value].value === "On"; + globalScene.showArenaFlyout = Setting[index].options[value].value === "On"; break; case SettingKeys.Show_Time_Of_Day_Widget: - scene.showTimeOfDayWidget = Setting[index].options[value].value === "On"; + globalScene.showTimeOfDayWidget = Setting[index].options[value].value === "On"; break; case SettingKeys.Time_Of_Day_Animation: - scene.timeOfDayAnimation = Setting[index].options[value].value === "Bounce" ? EaseType.BOUNCE : EaseType.BACK; + globalScene.timeOfDayAnimation = Setting[index].options[value].value === "Bounce" ? EaseType.BOUNCE : EaseType.BACK; break; case SettingKeys.Show_Stats_on_Level_Up: - scene.showLevelUpStats = Setting[index].options[value].value === "On"; + globalScene.showLevelUpStats = Setting[index].options[value].value === "On"; break; case SettingKeys.Shop_Cursor_Target: const selectedValue = shopCursorTargetIndexMap[value]; - scene.shopCursorTarget = selectedValue; + globalScene.shopCursorTarget = selectedValue; break; case SettingKeys.EXP_Gains_Speed: - scene.expGainsSpeed = value; + globalScene.expGainsSpeed = value; break; case SettingKeys.EXP_Party_Display: - scene.expParty = value; + globalScene.expParty = value; break; case SettingKeys.HP_Bar_Speed: - scene.hpBarSpeed = value; + globalScene.hpBarSpeed = value; break; case SettingKeys.Fusion_Palette_Swaps: - scene.fusionPaletteSwaps = !!value; + globalScene.fusionPaletteSwaps = !!value; break; case SettingKeys.Player_Gender: - if (scene.gameData) { + if (globalScene.gameData) { const female = Setting[index].options[value].value === "Girl"; - scene.gameData.gender = female ? PlayerGender.FEMALE : PlayerGender.MALE; - scene.trainer.setTexture(scene.trainer.texture.key.replace(female ? "m" : "f", female ? "f" : "m")); + globalScene.gameData.gender = female ? PlayerGender.FEMALE : PlayerGender.MALE; + globalScene.trainer.setTexture(globalScene.trainer.texture.key.replace(female ? "m" : "f", female ? "f" : "m")); } else { return false; } break; case SettingKeys.Touch_Controls: - scene.enableTouchControls = Setting[index].options[value].value !== "Disabled" && hasTouchscreen(); + globalScene.enableTouchControls = Setting[index].options[value].value !== "Disabled" && hasTouchscreen(); const touchControls = document.getElementById("touchControls"); if (touchControls) { - touchControls.classList.toggle("visible", scene.enableTouchControls); + touchControls.classList.toggle("visible", globalScene.enableTouchControls); } break; case SettingKeys.Vibration: - scene.enableVibration = Setting[index].options[value].value !== "Disabled" && hasTouchscreen(); + globalScene.enableVibration = Setting[index].options[value].value !== "Disabled" && hasTouchscreen(); break; case SettingKeys.Type_Hints: - scene.typeHints = Setting[index].options[value].value === "On"; + globalScene.typeHints = Setting[index].options[value].value === "On"; break; case SettingKeys.Language: if (value) { - if (scene.ui) { + if (globalScene.ui) { const cancelHandler = () => { - scene.ui.revertMode(); - (scene.ui.getHandler() as SettingsUiHandler).setOptionCursor(-1, 0, true); + globalScene.ui.revertMode(); + (globalScene.ui.getHandler() as SettingsUiHandler).setOptionCursor(-1, 0, true); }; const changeLocaleHandler = (locale: string): boolean => { try { @@ -881,7 +871,7 @@ export function setSetting(scene: BattleScene, setting: string, value: integer): return false; } }; - scene.ui.setOverlayMode(Mode.OPTION_SELECT, { + globalScene.ui.setOverlayMode(Mode.OPTION_SELECT, { options: [ { label: "English", @@ -939,7 +929,7 @@ export function setSetting(scene: BattleScene, setting: string, value: integer): } break; case SettingKeys.Shop_Overlay_Opacity: - scene.updateShopOverlayOpacity(parseInt(Setting[index].options[value].value) * .01); + globalScene.updateShopOverlayOpacity(parseInt(Setting[index].options[value].value) * .01); break; } diff --git a/src/system/trainer-data.ts b/src/system/trainer-data.ts index fc8a14488cc5..468cc95e000c 100644 --- a/src/system/trainer-data.ts +++ b/src/system/trainer-data.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { TrainerType } from "#enums/trainer-type"; import Trainer, { TrainerVariant } from "../field/trainer"; @@ -18,7 +17,7 @@ export default class TrainerData { this.partnerName = source.partnerName; } - toTrainer(scene: BattleScene): Trainer { - return new Trainer(scene, this.trainerType, this.variant, this.partyTemplateIndex, this.name, this.partnerName); + toTrainer(): Trainer { + return new Trainer(this.trainerType, this.variant, this.partyTemplateIndex, this.name, this.partnerName); } } diff --git a/src/system/voucher.ts b/src/system/voucher.ts index b38fd528c9fe..8f7fffa6f5de 100644 --- a/src/system/voucher.ts +++ b/src/system/voucher.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import i18next from "i18next"; import { AchvTier, achvs, getAchievementDescription } from "./achv"; import { PlayerGender } from "#enums/player-gender"; @@ -26,8 +25,8 @@ export class Voucher { this.conditionFunc = conditionFunc; } - validate(scene: BattleScene, args?: any[]): boolean { - return !this.conditionFunc || this.conditionFunc(scene, args); + validate(args?: any[]): boolean { + return !this.conditionFunc || this.conditionFunc(args); } /** diff --git a/src/test/abilities/infiltrator.test.ts b/src/test/abilities/infiltrator.test.ts index 01c5cef77963..8ea72b55b0c5 100644 --- a/src/test/abilities/infiltrator.test.ts +++ b/src/test/abilities/infiltrator.test.ts @@ -75,7 +75,7 @@ describe("Abilities - Infiltrator", () => { }); // TODO: fix this interaction to pass this test - it.skip("should bypass the target's Mist", async () => { + it.todo("should bypass the target's Mist", async () => { await game.classicMode.startBattle([ Species.MAGIKARP ]); const player = game.scene.getPlayerPokemon()!; diff --git a/src/test/abilities/libero.test.ts b/src/test/abilities/libero.test.ts index e7bc9eeeb630..25d2309463eb 100644 --- a/src/test/abilities/libero.test.ts +++ b/src/test/abilities/libero.test.ts @@ -54,6 +54,7 @@ describe("Abilities - Libero", () => { }, ); + // Test for Gen9+ functionality, we are using previous funcionality test.skip( "ability applies only once per switch in", async () => { diff --git a/src/test/abilities/protean.test.ts b/src/test/abilities/protean.test.ts index 0d7202e3f6d7..368701610e4f 100644 --- a/src/test/abilities/protean.test.ts +++ b/src/test/abilities/protean.test.ts @@ -54,6 +54,7 @@ describe("Abilities - Protean", () => { }, ); + // Test for Gen9+ functionality, we are using previous funcionality test.skip( "ability applies only once per switch in", async () => { diff --git a/src/test/achievements/achievement.test.ts b/src/test/achievements/achievement.test.ts index a3669c604633..b515c6bafa83 100644 --- a/src/test/achievements/achievement.test.ts +++ b/src/test/achievements/achievement.test.ts @@ -58,11 +58,11 @@ describe("Achv", () => { }); it("should validate the achievement based on the condition function", () => { - const conditionFunc = vi.fn((scene: BattleScene, args: any[]) => args[0] === 10); + const conditionFunc = vi.fn((args: any[]) => args[0] === 10); const achv = new Achv("", "Test Achievement", "Test Description", "test_icon", 10, conditionFunc); - expect(achv.validate(new BattleScene(), [ 5 ])).toBe(false); - expect(achv.validate(new BattleScene(), [ 10 ])).toBe(true); + expect(achv.validate([ 5 ])).toBe(false); + expect(achv.validate([ 10 ])).toBe(true); expect(conditionFunc).toHaveBeenCalledTimes(2); }); }); @@ -79,10 +79,10 @@ describe("MoneyAchv", () => { const scene = new BattleScene(); scene.money = 5000; - expect(moneyAchv.validate(scene, [])).toBe(false); + expect(moneyAchv.validate([])).toBe(false); scene.money = 15000; - expect(moneyAchv.validate(scene, [])).toBe(true); + expect(moneyAchv.validate([])).toBe(true); }); }); @@ -122,10 +122,10 @@ describe("RibbonAchv", () => { const ribbonAchv = new RibbonAchv("", "Test Ribbon Achievement", 10, "ribbon_icon", 10); scene.gameData.gameStats.ribbonsOwned = 5; - expect(ribbonAchv.validate(scene, [])).toBe(false); + expect(ribbonAchv.validate([])).toBe(false); scene.gameData.gameStats.ribbonsOwned = 15; - expect(ribbonAchv.validate(scene, [])).toBe(true); + expect(ribbonAchv.validate([])).toBe(true); }); }); @@ -138,13 +138,12 @@ describe("DamageAchv", () => { it("should validate the achievement based on the damage amount", () => { const damageAchv = new DamageAchv("", "Test Damage Achievement", 250, "damage_icon", 10); - const scene = new BattleScene(); const numberHolder = new NumberHolder(200); - expect(damageAchv.validate(scene, [ numberHolder ])).toBe(false); + expect(damageAchv.validate([ numberHolder ])).toBe(false); numberHolder.value = 300; - expect(damageAchv.validate(scene, [ numberHolder ])).toBe(true); + expect(damageAchv.validate([ numberHolder ])).toBe(true); }); }); @@ -157,13 +156,12 @@ describe("HealAchv", () => { it("should validate the achievement based on the heal amount", () => { const healAchv = new HealAchv("", "Test Heal Achievement", 250, "heal_icon", 10); - const scene = new BattleScene(); const numberHolder = new NumberHolder(200); - expect(healAchv.validate(scene, [ numberHolder ])).toBe(false); + expect(healAchv.validate([ numberHolder ])).toBe(false); numberHolder.value = 300; - expect(healAchv.validate(scene, [ numberHolder ])).toBe(true); + expect(healAchv.validate([ numberHolder ])).toBe(true); }); }); @@ -176,13 +174,12 @@ describe("LevelAchv", () => { it("should validate the achievement based on the level", () => { const levelAchv = new LevelAchv("", "Test Level Achievement", 100, "level_icon", 10); - const scene = new BattleScene(); const integerHolder = new IntegerHolder(50); - expect(levelAchv.validate(scene, [ integerHolder ])).toBe(false); + expect(levelAchv.validate([ integerHolder ])).toBe(false); integerHolder.value = 150; - expect(levelAchv.validate(scene, [ integerHolder ])).toBe(true); + expect(levelAchv.validate([ integerHolder ])).toBe(true); }); }); @@ -195,10 +192,9 @@ describe("ModifierAchv", () => { it("should validate the achievement based on the modifier function", () => { const modifierAchv = new ModifierAchv("", "Test Modifier Achievement", "Test Description", "modifier_icon", 10, () => true); - const scene = new BattleScene(); const modifier = new TurnHeldItemTransferModifier(null!, 3, 1); - expect(modifierAchv.validate(scene, [ modifier ])).toBe(true); + expect(modifierAchv.validate([ modifier ])).toBe(true); }); }); diff --git a/src/test/battle/battle.test.ts b/src/test/battle/battle.test.ts index d2b074acce04..bd84cb2fd3b8 100644 --- a/src/test/battle/battle.test.ts +++ b/src/test/battle/battle.test.ts @@ -188,8 +188,8 @@ describe("Test Battle Phase", () => { game.onNextPrompt("TitlePhase", Mode.TITLE, () => { game.scene.gameMode = getGameMode(GameModes.CLASSIC); const starters = generateStarter(game.scene); - const selectStarterPhase = new SelectStarterPhase(game.scene); - game.scene.pushPhase(new EncounterPhase(game.scene, false)); + const selectStarterPhase = new SelectStarterPhase(); + game.scene.pushPhase(new EncounterPhase(false)); selectStarterPhase.initBattle(starters); }); await game.phaseInterceptor.runFrom(SelectGenderPhase).to(SummonPhase); diff --git a/src/test/battle/error-handling.test.ts b/src/test/battle/error-handling.test.ts deleted file mode 100644 index 208463e7064d..000000000000 --- a/src/test/battle/error-handling.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Abilities } from "#enums/abilities"; -import { Moves } from "#enums/moves"; -import { Species } from "#enums/species"; -import GameManager from "#test/utils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Error Handling", () => { - let phaserGame: Phaser.Game; - let game: GameManager; - const moveToUse = Moves.SPLASH; - - beforeAll(() => { - phaserGame = new Phaser.Game({ - type: Phaser.HEADLESS, - }); - }); - - afterEach(() => { - game.phaseInterceptor.restoreOg(); - }); - - beforeEach(() => { - game = new GameManager(phaserGame); - game.override - .battleType("single") - .startingWave(3); - game.override.starterSpecies(Species.MEWTWO); - game.override.enemySpecies(Species.RATTATA); - game.override.enemyAbility(Abilities.HYDRATION); - game.override.ability(Abilities.ZEN_MODE); - game.override.startingLevel(2000); - game.override.moveset([ moveToUse ]); - game.override.enemyMoveset([ Moves.TACKLE, Moves.TACKLE, Moves.TACKLE, Moves.TACKLE ]); - }); - - it.skip("to next turn", async () => { - await game.startBattle(); - const turn = game.scene.currentBattle.turn; - game.move.select(moveToUse); - await game.toNextTurn(); - expect(game.scene.currentBattle.turn).toBeGreaterThan(turn); - }, 20000); -}); - diff --git a/src/test/battlerTags/octolock.test.ts b/src/test/battlerTags/octolock.test.ts index 9efce220fe84..2a403055d816 100644 --- a/src/test/battlerTags/octolock.test.ts +++ b/src/test/battlerTags/octolock.test.ts @@ -1,23 +1,34 @@ -import BattleScene from "#app/battle-scene"; -import { describe, expect, it, vi } from "vitest"; +import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; import Pokemon from "#app/field/pokemon"; import { BattlerTagLapseType, OctolockTag, TrappedTag } from "#app/data/battler-tags"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { Stat } from "#enums/stat"; - -vi.mock("#app/battle-scene.js"); +import GameManager from "#test/utils/gameManager"; describe("BattlerTag - OctolockTag", () => { describe("lapse behavior", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + game = new GameManager(phaserGame); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + it("unshifts a StatStageChangePhase with expected stat stage changes", async () => { const mockPokemon = { - scene: new BattleScene(), getBattlerIndex: () => 0, } as Pokemon; const subject = new OctolockTag(1); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementation(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementation(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(-1); expect((phase as StatStageChangePhase)["stats"]).toEqual([ Stat.DEF, Stat.SPDEF ]); @@ -25,7 +36,7 @@ describe("BattlerTag - OctolockTag", () => { subject.lapse(mockPokemon, BattlerTagLapseType.TURN_END); - expect(mockPokemon.scene.unshiftPhase).toBeCalledTimes(1); + expect(game.scene.unshiftPhase).toBeCalledTimes(1); }); }); diff --git a/src/test/battlerTags/stockpiling.test.ts b/src/test/battlerTags/stockpiling.test.ts index dab189853c57..b0e4c7a56bcd 100644 --- a/src/test/battlerTags/stockpiling.test.ts +++ b/src/test/battlerTags/stockpiling.test.ts @@ -1,28 +1,41 @@ -import BattleScene from "#app/battle-scene"; -import { beforeEach, describe, expect, it, vi } from "vitest"; -import Pokemon, { PokemonSummonData } from "#app/field/pokemon"; import { StockpilingTag } from "#app/data/battler-tags"; -import { Stat } from "#enums/stat"; +import Pokemon, { PokemonSummonData } from "#app/field/pokemon"; import * as messages from "#app/messages"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; +import { Stat } from "#enums/stat"; +import GameManager from "#test/utils/gameManager"; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; beforeEach(() => { vi.spyOn(messages, "getPokemonNameWithAffix").mockImplementation(() => ""); }); describe("BattlerTag - StockpilingTag", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + game = new GameManager(phaserGame); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + describe("onAdd", () => { it("unshifts a StatStageChangePhase with expected stat stage changes on add", async () => { const mockPokemon = { - scene: vi.mocked(new BattleScene()) as BattleScene, getBattlerIndex: () => 0, } as Pokemon; - vi.spyOn(mockPokemon.scene, "queueMessage").mockImplementation(() => {}); + vi.spyOn(game.scene, "queueMessage").mockImplementation(() => {}); const subject = new StockpilingTag(1); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementation(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementation(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(1); expect((phase as StatStageChangePhase)["stats"]).toEqual(expect.arrayContaining([ Stat.DEF, Stat.SPDEF ])); @@ -32,24 +45,23 @@ describe("BattlerTag - StockpilingTag", () => { subject.onAdd(mockPokemon); - expect(mockPokemon.scene.unshiftPhase).toBeCalledTimes(1); + expect(game.scene.unshiftPhase).toBeCalledTimes(1); }); it("unshifts a StatStageChangePhase with expected stat changes on add (one stat maxed)", async () => { const mockPokemon = { - scene: new BattleScene(), summonData: new PokemonSummonData(), getBattlerIndex: () => 0, - } as Pokemon; + } as unknown as Pokemon; - vi.spyOn(mockPokemon.scene, "queueMessage").mockImplementation(() => {}); + vi.spyOn(game.scene, "queueMessage").mockImplementation(() => {}); mockPokemon.summonData.statStages[Stat.DEF - 1] = 6; mockPokemon.summonData.statStages[Stat.SPD - 1] = 5; const subject = new StockpilingTag(1); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementation(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementation(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(1); expect((phase as StatStageChangePhase)["stats"]).toEqual(expect.arrayContaining([ Stat.DEF, Stat.SPDEF ])); @@ -59,22 +71,21 @@ describe("BattlerTag - StockpilingTag", () => { subject.onAdd(mockPokemon); - expect(mockPokemon.scene.unshiftPhase).toBeCalledTimes(1); + expect(game.scene.unshiftPhase).toBeCalledTimes(1); }); }); describe("onOverlap", () => { it("unshifts a StatStageChangePhase with expected stat changes on overlap", async () => { const mockPokemon = { - scene: new BattleScene(), getBattlerIndex: () => 0, } as Pokemon; - vi.spyOn(mockPokemon.scene, "queueMessage").mockImplementation(() => {}); + vi.spyOn(game.scene, "queueMessage").mockImplementation(() => {}); const subject = new StockpilingTag(1); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementation(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementation(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(1); expect((phase as StatStageChangePhase)["stats"]).toEqual(expect.arrayContaining([ Stat.DEF, Stat.SPDEF ])); @@ -84,26 +95,25 @@ describe("BattlerTag - StockpilingTag", () => { subject.onOverlap(mockPokemon); - expect(mockPokemon.scene.unshiftPhase).toBeCalledTimes(1); + expect(game.scene.unshiftPhase).toBeCalledTimes(1); }); }); describe("stack limit, stat tracking, and removal", () => { it("can be added up to three times, even when one stat does not change", async () => { const mockPokemon = { - scene: new BattleScene(), summonData: new PokemonSummonData(), getBattlerIndex: () => 0, } as Pokemon; - vi.spyOn(mockPokemon.scene, "queueMessage").mockImplementation(() => {}); + vi.spyOn(game.scene, "queueMessage").mockImplementation(() => {}); mockPokemon.summonData.statStages[Stat.DEF - 1] = 5; mockPokemon.summonData.statStages[Stat.SPD - 1] = 4; const subject = new StockpilingTag(1); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementationOnce(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementationOnce(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(1); expect((phase as StatStageChangePhase)["stats"]).toEqual(expect.arrayContaining([ Stat.DEF, Stat.SPDEF ])); @@ -115,7 +125,7 @@ describe("BattlerTag - StockpilingTag", () => { subject.onAdd(mockPokemon); expect(subject.stockpiledCount).toBe(1); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementationOnce(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementationOnce(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(1); expect((phase as StatStageChangePhase)["stats"]).toEqual(expect.arrayContaining([ Stat.DEF, Stat.SPDEF ])); @@ -127,7 +137,7 @@ describe("BattlerTag - StockpilingTag", () => { subject.onOverlap(mockPokemon); expect(subject.stockpiledCount).toBe(2); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementationOnce(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementationOnce(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(1); expect((phase as StatStageChangePhase)["stats"]).toEqual(expect.arrayContaining([ Stat.DEF, Stat.SPDEF ])); @@ -138,7 +148,7 @@ describe("BattlerTag - StockpilingTag", () => { subject.onOverlap(mockPokemon); expect(subject.stockpiledCount).toBe(3); - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementationOnce(_phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementationOnce(_phase => { throw new Error("Should not be called a fourth time"); }); @@ -148,14 +158,14 @@ describe("BattlerTag - StockpilingTag", () => { expect(subject.statChangeCounts).toMatchObject({ [Stat.DEF]: 0, [Stat.SPDEF]: 2 }); // removing tag should reverse stat changes - vi.spyOn(mockPokemon.scene, "unshiftPhase").mockImplementationOnce(phase => { + vi.spyOn(game.scene, "unshiftPhase").mockImplementationOnce(phase => { expect(phase).toBeInstanceOf(StatStageChangePhase); expect((phase as StatStageChangePhase)["stages"]).toEqual(-2); expect((phase as StatStageChangePhase)["stats"]).toEqual(expect.arrayContaining([ Stat.SPDEF ])); }); subject.onRemove(mockPokemon); - expect(mockPokemon.scene.unshiftPhase).toHaveBeenCalledOnce(); // note that re-spying each add/overlap has been refreshing call count + expect(game.scene.unshiftPhase).toHaveBeenCalledOnce(); // note that re-spying each add/overlap has been refreshing call count }); }); }); diff --git a/src/test/battlerTags/substitute.test.ts b/src/test/battlerTags/substitute.test.ts index af0aa63af89b..6d1c6e0cda65 100644 --- a/src/test/battlerTags/substitute.test.ts +++ b/src/test/battlerTags/substitute.test.ts @@ -8,8 +8,6 @@ import * as messages from "#app/messages"; import { allMoves } from "#app/data/move"; import { MoveEffectPhase } from "#app/phases/move-effect-phase"; -vi.mock("#app/battle-scene.js"); - describe("BattlerTag - SubstituteTag", () => { let mockPokemon: Pokemon; @@ -26,10 +24,10 @@ describe("BattlerTag - SubstituteTag", () => { expect(tagFilter(trapTag)).toBeTruthy(); return true; }) as Pokemon["findAndRemoveTags"] - } as Pokemon; + } as unknown as Pokemon; vi.spyOn(messages, "getPokemonNameWithAffix").mockReturnValue(""); - vi.spyOn(mockPokemon.scene, "getPokemonById").mockImplementation(pokemonId => mockPokemon.id === pokemonId ? mockPokemon : null); + vi.spyOn(mockPokemon.scene as BattleScene, "getPokemonById").mockImplementation(pokemonId => mockPokemon.id === pokemonId ? mockPokemon : null); }); it( @@ -37,8 +35,8 @@ describe("BattlerTag - SubstituteTag", () => { async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockReturnValue(true); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockReturnValue(true); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); subject.onAdd(mockPokemon); @@ -51,20 +49,20 @@ describe("BattlerTag - SubstituteTag", () => { async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockImplementation( + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockImplementation( (pokemon, battleAnimType, fieldAssets?, delayed?) => { expect(battleAnimType).toBe(PokemonAnimType.SUBSTITUTE_ADD); return true; } ); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); subject.onAdd(mockPokemon); expect(subject.sourceInFocus).toBeFalsy(); - expect(mockPokemon.scene.triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); - expect(mockPokemon.scene.queueMessage).toHaveBeenCalledTimes(1); + expect((mockPokemon.scene as BattleScene).triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); + expect((mockPokemon.scene as BattleScene).queueMessage).toHaveBeenCalledTimes(1); } ); @@ -73,7 +71,7 @@ describe("BattlerTag - SubstituteTag", () => { async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); subject.onAdd(mockPokemon); expect(mockPokemon.findAndRemoveTags).toHaveBeenCalledTimes(1); @@ -88,7 +86,7 @@ describe("BattlerTag - SubstituteTag", () => { hp: 101, id: 0, isFainted: vi.fn().mockReturnValue(false) as Pokemon["isFainted"] - } as Pokemon; + } as unknown as Pokemon; vi.spyOn(messages, "getPokemonNameWithAffix").mockReturnValue(""); }); @@ -99,19 +97,19 @@ describe("BattlerTag - SubstituteTag", () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); subject.sourceInFocus = false; - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockImplementation( + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockImplementation( (pokemon, battleAnimType, fieldAssets?, delayed?) => { expect(battleAnimType).toBe(PokemonAnimType.SUBSTITUTE_REMOVE); return true; } ); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); subject.onRemove(mockPokemon); - expect(mockPokemon.scene.triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); - expect(mockPokemon.scene.queueMessage).toHaveBeenCalledTimes(1); + expect((mockPokemon.scene as BattleScene).triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); + expect((mockPokemon.scene as BattleScene).queueMessage).toHaveBeenCalledTimes(1); } ); }); @@ -124,7 +122,7 @@ describe("BattlerTag - SubstituteTag", () => { id: 0, turnData: { acted: true } as PokemonTurnData, getLastXMoves: vi.fn().mockReturnValue([ { move: Moves.TACKLE, result: MoveResult.SUCCESS } as TurnMove ]) as Pokemon["getLastXMoves"], - } as Pokemon; + } as unknown as Pokemon; vi.spyOn(messages, "getPokemonNameWithAffix").mockReturnValue(""); }); @@ -134,20 +132,20 @@ describe("BattlerTag - SubstituteTag", () => { async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockImplementation( + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockImplementation( (pokemon, battleAnimType, fieldAssets?, delayed?) => { expect(battleAnimType).toBe(PokemonAnimType.SUBSTITUTE_PRE_MOVE); return true; } ); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); expect(subject.lapse(mockPokemon, BattlerTagLapseType.PRE_MOVE)).toBeTruthy(); expect(subject.sourceInFocus).toBeTruthy(); - expect(mockPokemon.scene.triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); - expect(mockPokemon.scene.queueMessage).not.toHaveBeenCalled(); + expect((mockPokemon.scene as BattleScene).triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); + expect((mockPokemon.scene as BattleScene).queueMessage).not.toHaveBeenCalled(); } ); @@ -156,31 +154,31 @@ describe("BattlerTag - SubstituteTag", () => { async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockImplementation( + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockImplementation( (pokemon, battleAnimType, fieldAssets?, delayed?) => { expect(battleAnimType).toBe(PokemonAnimType.SUBSTITUTE_POST_MOVE); return true; } ); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); expect(subject.lapse(mockPokemon, BattlerTagLapseType.AFTER_MOVE)).toBeTruthy(); expect(subject.sourceInFocus).toBeFalsy(); - expect(mockPokemon.scene.triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); - expect(mockPokemon.scene.queueMessage).not.toHaveBeenCalled(); + expect((mockPokemon.scene as BattleScene).triggerPokemonBattleAnim).toHaveBeenCalledTimes(1); + expect((mockPokemon.scene as BattleScene).queueMessage).not.toHaveBeenCalled(); } ); - /** TODO: Figure out how to mock a MoveEffectPhase correctly for this test */ - it.skip( + // TODO: Figure out how to mock a MoveEffectPhase correctly for this test + it.todo( "HIT lapse triggers on-hit message", async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockReturnValue(true); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockReturnValue(true); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); const pokemonMove = { getMove: vi.fn().mockReturnValue(allMoves[Moves.TACKLE]) as PokemonMove["getMove"] @@ -191,13 +189,13 @@ describe("BattlerTag - SubstituteTag", () => { getUserPokemon: vi.fn().mockReturnValue(undefined) as MoveEffectPhase["getUserPokemon"] } as MoveEffectPhase; - vi.spyOn(mockPokemon.scene, "getCurrentPhase").mockReturnValue(moveEffectPhase); + vi.spyOn(mockPokemon.scene as BattleScene, "getCurrentPhase").mockReturnValue(moveEffectPhase); vi.spyOn(allMoves[Moves.TACKLE], "hitsSubstitute").mockReturnValue(true); expect(subject.lapse(mockPokemon, BattlerTagLapseType.HIT)).toBeTruthy(); - expect(mockPokemon.scene.triggerPokemonBattleAnim).not.toHaveBeenCalled(); - expect(mockPokemon.scene.queueMessage).toHaveBeenCalledTimes(1); + expect((mockPokemon.scene as BattleScene).triggerPokemonBattleAnim).not.toHaveBeenCalled(); + expect((mockPokemon.scene as BattleScene).queueMessage).toHaveBeenCalledTimes(1); } ); @@ -206,8 +204,8 @@ describe("BattlerTag - SubstituteTag", () => { async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockReturnValue(true); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockReturnValue(true); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); expect(subject.lapse(mockPokemon, BattlerTagLapseType.CUSTOM)).toBeFalsy(); } @@ -218,13 +216,13 @@ describe("BattlerTag - SubstituteTag", () => { async () => { const subject = new SubstituteTag(Moves.SUBSTITUTE, mockPokemon.id); - vi.spyOn(mockPokemon.scene, "triggerPokemonBattleAnim").mockReturnValue(true); - vi.spyOn(mockPokemon.scene, "queueMessage").mockReturnValue(); + vi.spyOn(mockPokemon.scene as BattleScene, "triggerPokemonBattleAnim").mockReturnValue(true); + vi.spyOn(mockPokemon.scene as BattleScene, "queueMessage").mockReturnValue(); expect(subject.lapse(mockPokemon, BattlerTagLapseType.TURN_END)).toBeTruthy(); - expect(mockPokemon.scene.triggerPokemonBattleAnim).not.toHaveBeenCalled(); - expect(mockPokemon.scene.queueMessage).not.toHaveBeenCalled(); + expect((mockPokemon.scene as BattleScene).triggerPokemonBattleAnim).not.toHaveBeenCalled(); + expect((mockPokemon.scene as BattleScene).queueMessage).not.toHaveBeenCalled(); } ); }); diff --git a/src/test/eggs/egg.test.ts b/src/test/eggs/egg.test.ts index 1a33b4eff7c2..3394771d84af 100644 --- a/src/test/eggs/egg.test.ts +++ b/src/test/eggs/egg.test.ts @@ -33,20 +33,18 @@ describe("Egg Generation Tests", () => { }); it("should return Kyogre for the 10th of June", () => { - const scene = game.scene; const timestamp = new Date(2024, 5, 10, 15, 0, 0, 0).getTime(); const expectedSpecies = Species.KYOGRE; - const result = getLegendaryGachaSpeciesForTimestamp(scene, timestamp); + const result = getLegendaryGachaSpeciesForTimestamp(timestamp); expect(result).toBe(expectedSpecies); }); it("should return Kyogre for the 10th of July", () => { - const scene = game.scene; const timestamp = new Date(2024, 6, 10, 15, 0, 0, 0).getTime(); const expectedSpecies = Species.KYOGRE; - const result = getLegendaryGachaSpeciesForTimestamp(scene, timestamp); + const result = getLegendaryGachaSpeciesForTimestamp(timestamp); expect(result).toBe(expectedSpecies); }); @@ -57,7 +55,7 @@ describe("Egg Generation Tests", () => { let gachaSpeciesCount = 0; for (let i = 0; i < EGG_HATCH_COUNT; i++) { - const result = new Egg({ scene, timestamp, sourceType: EggSourceType.GACHA_LEGENDARY, tier: EggTier.LEGENDARY }).generatePlayerPokemon(scene).species.speciesId; + const result = new Egg({ scene, timestamp, sourceType: EggSourceType.GACHA_LEGENDARY, tier: EggTier.LEGENDARY }).generatePlayerPokemon().species.speciesId; if (result === expectedSpecies) { gachaSpeciesCount++; } @@ -76,7 +74,7 @@ describe("Egg Generation Tests", () => { const scene = game.scene; const expectedSpecies = Species.ARCEUS; - const result = new Egg({ scene, species: expectedSpecies }).generatePlayerPokemon(scene).species.speciesId; + const result = new Egg({ scene, species: expectedSpecies }).generatePlayerPokemon().species.speciesId; expect(result).toBe(expectedSpecies); }); @@ -140,7 +138,7 @@ describe("Egg Generation Tests", () => { const scene = game.scene; const expectedResult = true; - const result = new Egg({ scene, isShiny: expectedResult, species: Species.BULBASAUR }).generatePlayerPokemon(scene).isShiny(); + const result = new Egg({ scene, isShiny: expectedResult, species: Species.BULBASAUR }).generatePlayerPokemon().isShiny(); expect(result).toBe(expectedResult); }); @@ -148,7 +146,7 @@ describe("Egg Generation Tests", () => { const scene = game.scene; const expectedVariantTier = VariantTier.STANDARD; - const result = new Egg({ scene, isShiny: true, variantTier: expectedVariantTier, species: Species.BULBASAUR }).generatePlayerPokemon(scene).variant; + const result = new Egg({ scene, isShiny: true, variantTier: expectedVariantTier, species: Species.BULBASAUR }).generatePlayerPokemon().variant; expect(result).toBe(expectedVariantTier); }); @@ -156,7 +154,7 @@ describe("Egg Generation Tests", () => { const scene = game.scene; const expectedVariantTier = VariantTier.RARE; - const result = new Egg({ scene, isShiny: true, variantTier: expectedVariantTier, species: Species.BULBASAUR }).generatePlayerPokemon(scene).variant; + const result = new Egg({ scene, isShiny: true, variantTier: expectedVariantTier, species: Species.BULBASAUR }).generatePlayerPokemon().variant; expect(result).toBe(expectedVariantTier); }); @@ -164,7 +162,7 @@ describe("Egg Generation Tests", () => { const scene = game.scene; const expectedVariantTier = VariantTier.EPIC; - const result = new Egg({ scene, isShiny: true, variantTier: expectedVariantTier, species: Species.BULBASAUR }).generatePlayerPokemon(scene).variant; + const result = new Egg({ scene, isShiny: true, variantTier: expectedVariantTier, species: Species.BULBASAUR }).generatePlayerPokemon().variant; expect(result).toBe(expectedVariantTier); }); @@ -187,7 +185,7 @@ describe("Egg Generation Tests", () => { it("should return a hatched pokemon with a hidden ability", () => { const scene = game.scene; - const playerPokemon = new Egg({ scene, overrideHiddenAbility: true, species: Species.BULBASAUR }).generatePlayerPokemon(scene); + const playerPokemon = new Egg({ scene, overrideHiddenAbility: true, species: Species.BULBASAUR }).generatePlayerPokemon(); const expectedAbilityIndex = playerPokemon.species.ability2 ? 2 : 1; const result = playerPokemon.abilityIndex; @@ -332,7 +330,7 @@ describe("Egg Generation Tests", () => { scene.resetSeed(); const firstEgg = new Egg({ scene, sourceType: EggSourceType.GACHA_SHINY, tier: EggTier.COMMON }); - const firstHatch = firstEgg.generatePlayerPokemon(scene); + const firstHatch = firstEgg.generatePlayerPokemon(); let diffEggMove = false; let diffSpecies = false; let diffShiny = false; @@ -343,7 +341,7 @@ describe("Egg Generation Tests", () => { scene.resetSeed(); // Make sure that eggs are unpredictable even if using same seed const newEgg = new Egg({ scene, sourceType: EggSourceType.GACHA_SHINY, tier: EggTier.COMMON }); - const newHatch = newEgg.generatePlayerPokemon(scene); + const newHatch = newEgg.generatePlayerPokemon(); diffEggMove = diffEggMove || (newEgg.eggMoveIndex !== firstEgg.eggMoveIndex); diffSpecies = diffSpecies || (newHatch.species.speciesId !== firstHatch.species.speciesId); diffShiny = diffShiny || (newHatch.shiny !== firstHatch.shiny); @@ -362,7 +360,7 @@ describe("Egg Generation Tests", () => { scene.resetSeed(); const firstEgg = new Egg({ scene, species: Species.BULBASAUR }); - const firstHatch = firstEgg.generatePlayerPokemon(scene); + const firstHatch = firstEgg.generatePlayerPokemon(); let diffEggMove = false; let diffSpecies = false; let diffShiny = false; @@ -372,7 +370,7 @@ describe("Egg Generation Tests", () => { scene.resetSeed(); // Make sure that eggs are unpredictable even if using same seed const newEgg = new Egg({ scene, species: Species.BULBASAUR }); - const newHatch = newEgg.generatePlayerPokemon(scene); + const newHatch = newEgg.generatePlayerPokemon(); diffEggMove = diffEggMove || (newEgg.eggMoveIndex !== firstEgg.eggMoveIndex); diffSpecies = diffSpecies || (newHatch.species.speciesId !== firstHatch.species.speciesId); diffShiny = diffShiny || (newHatch.shiny !== firstHatch.shiny); diff --git a/src/test/eggs/manaphy-egg.test.ts b/src/test/eggs/manaphy-egg.test.ts index 3b2c40ae84a9..4285476a9133 100644 --- a/src/test/eggs/manaphy-egg.test.ts +++ b/src/test/eggs/manaphy-egg.test.ts @@ -48,7 +48,7 @@ describe("Manaphy Eggs", () => { rngSweepProgress = (2 * i + 1) / (2 * EGG_HATCH_COUNT); const newEgg = new Egg({ scene, tier: EggTier.COMMON, sourceType: EggSourceType.GACHA_SHINY, id: 204 }); - const newHatch = newEgg.generatePlayerPokemon(scene); + const newHatch = newEgg.generatePlayerPokemon(); if (newHatch.species.speciesId === Species.MANAPHY) { manaphyCount++; } else if (newHatch.species.speciesId === Species.PHIONE) { @@ -74,7 +74,7 @@ describe("Manaphy Eggs", () => { rngSweepProgress = (2 * i + 1) / (2 * EGG_HATCH_COUNT); const newEgg = new Egg({ scene, species: Species.PHIONE, sourceType: EggSourceType.SAME_SPECIES_EGG }); - const newHatch = newEgg.generatePlayerPokemon(scene); + const newHatch = newEgg.generatePlayerPokemon(); if (newHatch.species.speciesId === Species.MANAPHY) { manaphyCount++; } else if (newHatch.species.speciesId === Species.PHIONE) { @@ -100,7 +100,7 @@ describe("Manaphy Eggs", () => { rngSweepProgress = (2 * i + 1) / (2 * EGG_HATCH_COUNT); const newEgg = new Egg({ scene, species: Species.MANAPHY, sourceType: EggSourceType.SAME_SPECIES_EGG }); - const newHatch = newEgg.generatePlayerPokemon(scene); + const newHatch = newEgg.generatePlayerPokemon(); if (newHatch.species.speciesId === Species.MANAPHY) { manaphyCount++; } else if (newHatch.species.speciesId === Species.PHIONE) { diff --git a/src/test/enemy_command.test.ts b/src/test/enemy_command.test.ts index 49419f5b34d6..c87ec5709c7d 100644 --- a/src/test/enemy_command.test.ts +++ b/src/test/enemy_command.test.ts @@ -1,3 +1,4 @@ +import type BattleScene from "#app/battle-scene"; import { allMoves, MoveCategory } from "#app/data/move"; import { Abilities } from "#app/enums/abilities"; import { Moves } from "#app/enums/moves"; @@ -8,14 +9,14 @@ import GameManager from "#test/utils/gameManager"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; - +let globalScene: BattleScene; const NUM_TRIALS = 300; type MoveChoiceSet = { [key: number]: number }; function getEnemyMoveChoices(pokemon: EnemyPokemon, moveChoices: MoveChoiceSet): void { // Use an unseeded random number generator in place of the mocked-out randBattleSeedInt - vi.spyOn(pokemon.scene, "randBattleSeedInt").mockImplementation((range, min?) => { + vi.spyOn(globalScene, "randBattleSeedInt").mockImplementation((range, min?) => { return randSeedInt(range, min); }); for (let i = 0; i < NUM_TRIALS; i++) { @@ -44,6 +45,7 @@ describe("Enemy Commands - Move Selection", () => { beforeEach(() => { game = new GameManager(phaserGame); + globalScene = game.scene; game.override .ability(Abilities.BALL_FETCH) diff --git a/src/test/items/exp_booster.test.ts b/src/test/items/exp_booster.test.ts index 36107329706f..7441dcaeb739 100644 --- a/src/test/items/exp_booster.test.ts +++ b/src/test/items/exp_booster.test.ts @@ -34,7 +34,7 @@ describe("EXP Modifier Items", () => { const partyMember = game.scene.getPlayerPokemon()!; partyMember.exp = 100; const expHolder = new Utils.NumberHolder(partyMember.exp); - partyMember.scene.applyModifiers(PokemonExpBoosterModifier, true, partyMember, expHolder); + game.scene.applyModifiers(PokemonExpBoosterModifier, true, partyMember, expHolder); expect(expHolder.value).toBe(440); }, 20000); }); diff --git a/src/test/items/light_ball.test.ts b/src/test/items/light_ball.test.ts index fe79b6a20453..987a5ab8b0cc 100644 --- a/src/test/items/light_ball.test.ts +++ b/src/test/items/light_ball.test.ts @@ -75,17 +75,17 @@ describe("Items - Light Ball", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); const spAtkValue = new Utils.NumberHolder(spAtkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); expect(spAtkValue.value / spAtkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); expect(atkValue.value / atkStat).toBe(2); expect(spAtkValue.value / spAtkStat).toBe(2); @@ -114,17 +114,17 @@ describe("Items - Light Ball", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); const spAtkValue = new Utils.NumberHolder(spAtkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); expect(spAtkValue.value / spAtkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); expect(atkValue.value / atkStat).toBe(2); expect(spAtkValue.value / spAtkStat).toBe(2); @@ -153,17 +153,17 @@ describe("Items - Light Ball", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); const spAtkValue = new Utils.NumberHolder(spAtkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); expect(spAtkValue.value / spAtkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); expect(atkValue.value / atkStat).toBe(2); expect(spAtkValue.value / spAtkStat).toBe(2); @@ -181,17 +181,17 @@ describe("Items - Light Ball", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, atkValue); const spAtkValue = new Utils.NumberHolder(spAtkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPDEF, spAtkValue); expect(atkValue.value / atkStat).toBe(1); expect(spAtkValue.value / spAtkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "LIGHT_BALL" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPATK, spAtkValue); expect(atkValue.value / atkStat).toBe(1); expect(spAtkValue.value / spAtkStat).toBe(1); diff --git a/src/test/items/lock_capsule.test.ts b/src/test/items/lock_capsule.test.ts index 0b6534b5eafa..2d95cea58471 100644 --- a/src/test/items/lock_capsule.test.ts +++ b/src/test/items/lock_capsule.test.ts @@ -34,7 +34,7 @@ describe("Items - Lock Capsule", () => { it("doesn't set the cost of common tier items to 0", async () => { await game.classicMode.startBattle(); - game.scene.overridePhase(new SelectModifierPhase(game.scene, 0, undefined, { guaranteedModifierTiers: [ ModifierTier.COMMON, ModifierTier.COMMON, ModifierTier.COMMON ], fillRemaining: false })); + game.scene.overridePhase(new SelectModifierPhase(0, undefined, { guaranteedModifierTiers: [ ModifierTier.COMMON, ModifierTier.COMMON, ModifierTier.COMMON ], fillRemaining: false })); game.onNextPrompt("SelectModifierPhase", Mode.MODIFIER_SELECT, () => { const selectModifierPhase = game.scene.getCurrentPhase() as SelectModifierPhase; diff --git a/src/test/items/metal_powder.test.ts b/src/test/items/metal_powder.test.ts index 86e7d329ecb9..42ef9c1bb163 100644 --- a/src/test/items/metal_powder.test.ts +++ b/src/test/items/metal_powder.test.ts @@ -74,13 +74,13 @@ describe("Items - Metal Powder", () => { // Making sure modifier is not applied without holding item const defValue = new Utils.NumberHolder(defStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(2); }, 20000); @@ -107,13 +107,13 @@ describe("Items - Metal Powder", () => { // Making sure modifier is not applied without holding item const defValue = new Utils.NumberHolder(defStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(2); }, 20000); @@ -140,13 +140,13 @@ describe("Items - Metal Powder", () => { // Making sure modifier is not applied without holding item const defValue = new Utils.NumberHolder(defStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(2); }, 20000); @@ -162,13 +162,13 @@ describe("Items - Metal Powder", () => { // Making sure modifier is not applied without holding item const defValue = new Utils.NumberHolder(defStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "METAL_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.DEF, defValue); expect(defValue.value / defStat).toBe(1); }, 20000); diff --git a/src/test/items/quick_powder.test.ts b/src/test/items/quick_powder.test.ts index 905d023ad8b0..d30111cbd6af 100644 --- a/src/test/items/quick_powder.test.ts +++ b/src/test/items/quick_powder.test.ts @@ -74,13 +74,13 @@ describe("Items - Quick Powder", () => { // Making sure modifier is not applied without holding item const spdValue = new Utils.NumberHolder(spdStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(2); }, 20000); @@ -107,13 +107,13 @@ describe("Items - Quick Powder", () => { // Making sure modifier is not applied without holding item const spdValue = new Utils.NumberHolder(spdStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(2); }, 20000); @@ -140,13 +140,13 @@ describe("Items - Quick Powder", () => { // Making sure modifier is not applied without holding item const spdValue = new Utils.NumberHolder(spdStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(2); }, 20000); @@ -162,13 +162,13 @@ describe("Items - Quick Powder", () => { // Making sure modifier is not applied without holding item const spdValue = new Utils.NumberHolder(spdStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "QUICK_POWDER" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.SPD, spdValue); expect(spdValue.value / spdStat).toBe(1); }, 20000); diff --git a/src/test/items/thick_club.test.ts b/src/test/items/thick_club.test.ts index d349a1ad7b99..08b19250ea78 100644 --- a/src/test/items/thick_club.test.ts +++ b/src/test/items/thick_club.test.ts @@ -74,13 +74,13 @@ describe("Items - Thick Club", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(2); }, 20000); @@ -96,13 +96,13 @@ describe("Items - Thick Club", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(2); }, 20000); @@ -118,13 +118,13 @@ describe("Items - Thick Club", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(2); }, 20000); @@ -155,13 +155,13 @@ describe("Items - Thick Club", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(2); }, 20000); @@ -192,13 +192,13 @@ describe("Items - Thick Club", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(2); }, 20000); @@ -214,13 +214,13 @@ describe("Items - Thick Club", () => { // Making sure modifier is not applied without holding item const atkValue = new Utils.NumberHolder(atkStat); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); // Giving Eviolite to party member and testing if it applies - partyMember.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); - partyMember.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); + game.scene.addModifier(modifierTypes.SPECIES_STAT_BOOSTER().generateType([], [ "THICK_CLUB" ])!.newModifier(partyMember), true); + game.scene.applyModifiers(SpeciesStatBoosterModifier, true, partyMember, Stat.ATK, atkValue); expect(atkValue.value / atkStat).toBe(1); }, 20000); diff --git a/src/test/moves/aurora_veil.test.ts b/src/test/moves/aurora_veil.test.ts index 2d7484b4eb54..52dfdf6f6dab 100644 --- a/src/test/moves/aurora_veil.test.ts +++ b/src/test/moves/aurora_veil.test.ts @@ -1,3 +1,4 @@ +import type BattleScene from "#app/battle-scene"; import { ArenaTagSide } from "#app/data/arena-tag"; import Move, { allMoves } from "#app/data/move"; import { ArenaTagType } from "#app/enums/arena-tag-type"; @@ -12,6 +13,7 @@ import GameManager from "#test/utils/gameManager"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +let globalScene: BattleScene; describe("Moves - Aurora Veil", () => { let phaserGame: Phaser.Game; @@ -31,6 +33,7 @@ describe("Moves - Aurora Veil", () => { beforeEach(() => { game = new GameManager(phaserGame); + globalScene = game.scene; game.override.battleType("single"); game.override.ability(Abilities.NONE); game.override.moveset([ Moves.ABSORB, Moves.ROCK_SLIDE, Moves.TACKLE ]); @@ -110,8 +113,8 @@ const getMockedMoveDamage = (defender: Pokemon, attacker: Pokemon, move: Move) = const multiplierHolder = new NumberHolder(1); const side = defender.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - if (defender.scene.arena.getTagOnSide(ArenaTagType.AURORA_VEIL, side)) { - defender.scene.arena.applyTagsForSide(ArenaTagType.AURORA_VEIL, side, false, attacker, move.category, multiplierHolder); + if (globalScene.arena.getTagOnSide(ArenaTagType.AURORA_VEIL, side)) { + globalScene.arena.applyTagsForSide(ArenaTagType.AURORA_VEIL, side, false, attacker, move.category, multiplierHolder); } return move.power * multiplierHolder.value; diff --git a/src/test/moves/burning_jealousy.test.ts b/src/test/moves/burning_jealousy.test.ts index fe2735cfa964..abe2c09bb72c 100644 --- a/src/test/moves/burning_jealousy.test.ts +++ b/src/test/moves/burning_jealousy.test.ts @@ -82,7 +82,8 @@ describe("Moves - Burning Jealousy", () => { expect(enemy.status?.effect).toBeUndefined(); }); - it.skip("should ignore weakness policy", async () => { // TODO: Make this test if WP is implemented + // TODO: Make this test if WP is implemented + it.todo("should ignore weakness policy", async () => { await game.classicMode.startBattle(); }); diff --git a/src/test/moves/dynamax_cannon.test.ts b/src/test/moves/dynamax_cannon.test.ts index 269374f7514b..033d8960bad7 100644 --- a/src/test/moves/dynamax_cannon.test.ts +++ b/src/test/moves/dynamax_cannon.test.ts @@ -81,7 +81,7 @@ describe("Moves - Dynamax Cannon", () => { const phase = game.scene.getCurrentPhase() as MoveEffectPhase; expect(phase.move.moveId).toBe(dynamaxCannon.id); // Force level cap to be 100 - vi.spyOn(phase.getFirstTarget()!.scene, "getMaxExpLevel").mockReturnValue(100); + vi.spyOn(game.scene, "getMaxExpLevel").mockReturnValue(100); await game.phaseInterceptor.to(DamageAnimPhase, false); expect(dynamaxCannon.calculateBattlePower).toHaveLastReturnedWith(120); }, 20000); @@ -98,7 +98,7 @@ describe("Moves - Dynamax Cannon", () => { const phase = game.scene.getCurrentPhase() as MoveEffectPhase; expect(phase.move.moveId).toBe(dynamaxCannon.id); // Force level cap to be 100 - vi.spyOn(phase.getFirstTarget()!.scene, "getMaxExpLevel").mockReturnValue(100); + vi.spyOn(game.scene, "getMaxExpLevel").mockReturnValue(100); await game.phaseInterceptor.to(DamageAnimPhase, false); expect(dynamaxCannon.calculateBattlePower).toHaveLastReturnedWith(140); }, 20000); @@ -115,7 +115,7 @@ describe("Moves - Dynamax Cannon", () => { const phase = game.scene.getCurrentPhase() as MoveEffectPhase; expect(phase.move.moveId).toBe(dynamaxCannon.id); // Force level cap to be 100 - vi.spyOn(phase.getFirstTarget()!.scene, "getMaxExpLevel").mockReturnValue(100); + vi.spyOn(game.scene, "getMaxExpLevel").mockReturnValue(100); await game.phaseInterceptor.to(DamageAnimPhase, false); expect(dynamaxCannon.calculateBattlePower).toHaveLastReturnedWith(160); }, 20000); @@ -132,7 +132,7 @@ describe("Moves - Dynamax Cannon", () => { const phase = game.scene.getCurrentPhase() as MoveEffectPhase; expect(phase.move.moveId).toBe(dynamaxCannon.id); // Force level cap to be 100 - vi.spyOn(phase.getFirstTarget()!.scene, "getMaxExpLevel").mockReturnValue(100); + vi.spyOn(game.scene, "getMaxExpLevel").mockReturnValue(100); await game.phaseInterceptor.to(DamageAnimPhase, false); expect(dynamaxCannon.calculateBattlePower).toHaveLastReturnedWith(180); }, 20000); @@ -149,7 +149,7 @@ describe("Moves - Dynamax Cannon", () => { const phase = game.scene.getCurrentPhase() as MoveEffectPhase; expect(phase.move.moveId).toBe(dynamaxCannon.id); // Force level cap to be 100 - vi.spyOn(phase.getFirstTarget()!.scene, "getMaxExpLevel").mockReturnValue(100); + vi.spyOn(game.scene, "getMaxExpLevel").mockReturnValue(100); await game.phaseInterceptor.to(DamageAnimPhase, false); expect(dynamaxCannon.calculateBattlePower).toHaveLastReturnedWith(200); }, 20000); diff --git a/src/test/moves/effectiveness.test.ts b/src/test/moves/effectiveness.test.ts index 5ad258d79904..7742178f595a 100644 --- a/src/test/moves/effectiveness.test.ts +++ b/src/test/moves/effectiveness.test.ts @@ -23,7 +23,7 @@ function testMoveEffectiveness(game: GameManager, move: Moves, targetSpecies: Sp const target = game.scene.addEnemyPokemon(getPokemonSpecies(targetSpecies), 5, TrainerSlot.NONE); if (teraType !== undefined) { - overrideHeldItems(game.scene, target, false); + overrideHeldItems(target, false); } expect(target.getMoveEffectiveness(user, allMoves[move])).toBe(expected); diff --git a/src/test/moves/light_screen.test.ts b/src/test/moves/light_screen.test.ts index af14d9273e67..be334b244404 100644 --- a/src/test/moves/light_screen.test.ts +++ b/src/test/moves/light_screen.test.ts @@ -1,3 +1,4 @@ +import type BattleScene from "#app/battle-scene"; import { ArenaTagSide } from "#app/data/arena-tag"; import Move, { allMoves } from "#app/data/move"; import { Abilities } from "#app/enums/abilities"; @@ -11,6 +12,7 @@ import GameManager from "#test/utils/gameManager"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +let globalScene: BattleScene; describe("Moves - Light Screen", () => { let phaserGame: Phaser.Game; @@ -30,6 +32,7 @@ describe("Moves - Light Screen", () => { beforeEach(() => { game = new GameManager(phaserGame); + globalScene = game.scene; game.override.battleType("single"); game.override.ability(Abilities.NONE); game.override.moveset([ Moves.ABSORB, Moves.DAZZLING_GLEAM, Moves.TACKLE ]); @@ -93,8 +96,8 @@ const getMockedMoveDamage = (defender: Pokemon, attacker: Pokemon, move: Move) = const multiplierHolder = new NumberHolder(1); const side = defender.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - if (defender.scene.arena.getTagOnSide(ArenaTagType.LIGHT_SCREEN, side)) { - defender.scene.arena.applyTagsForSide(ArenaTagType.LIGHT_SCREEN, side, false, attacker, move.category, multiplierHolder); + if (globalScene.arena.getTagOnSide(ArenaTagType.LIGHT_SCREEN, side)) { + globalScene.arena.applyTagsForSide(ArenaTagType.LIGHT_SCREEN, side, false, attacker, move.category, multiplierHolder); } return move.power * multiplierHolder.value; diff --git a/src/test/moves/parting_shot.test.ts b/src/test/moves/parting_shot.test.ts index cfdf6c159668..30ad3660a325 100644 --- a/src/test/moves/parting_shot.test.ts +++ b/src/test/moves/parting_shot.test.ts @@ -75,7 +75,7 @@ describe("Moves - Parting Shot", () => { } ); - it.skip( // TODO: fix this bug to pass the test! + it.todo( // TODO: fix this bug to pass the test! "Parting shot should fail if target is -6/-6 de-buffed", async () => { game.override.moveset([ Moves.PARTING_SHOT, Moves.MEMENTO, Moves.SPLASH ]); @@ -117,7 +117,7 @@ describe("Moves - Parting Shot", () => { } ); - it.skip( // TODO: fix this bug to pass the test! + it.todo( // TODO: fix this bug to pass the test! "Parting shot shouldn't allow switch out when mist is active", async () => { game.override @@ -138,7 +138,7 @@ describe("Moves - Parting Shot", () => { } ); - it.skip( // TODO: fix this bug to pass the test! + it.todo( // TODO: fix this bug to pass the test! "Parting shot shouldn't allow switch out against clear body ability", async () => { game.override @@ -158,7 +158,7 @@ describe("Moves - Parting Shot", () => { } ); - it.skip( // TODO: fix this bug to pass the test! + it.todo( // TODO: fix this bug to pass the test! "Parting shot should de-buff and not fail if no party available to switch - party size 1", async () => { await game.startBattle([ Species.MURKROW ]); @@ -175,7 +175,7 @@ describe("Moves - Parting Shot", () => { } ); - it.skip( // TODO: fix this bug to pass the test! + it.todo( // TODO: fix this bug to pass the test! "Parting shot regularly not fail if no party available to switch - party fainted", async () => { await game.startBattle([ Species.MURKROW, Species.MEOWTH ]); diff --git a/src/test/moves/reflect.test.ts b/src/test/moves/reflect.test.ts index 3bf415ea75c3..03fe050448c4 100644 --- a/src/test/moves/reflect.test.ts +++ b/src/test/moves/reflect.test.ts @@ -1,3 +1,4 @@ +import type BattleScene from "#app/battle-scene"; import { ArenaTagSide } from "#app/data/arena-tag"; import Move, { allMoves } from "#app/data/move"; import { Abilities } from "#app/enums/abilities"; @@ -11,6 +12,7 @@ import GameManager from "#test/utils/gameManager"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +let globalScene: BattleScene; describe("Moves - Reflect", () => { let phaserGame: Phaser.Game; @@ -30,6 +32,7 @@ describe("Moves - Reflect", () => { beforeEach(() => { game = new GameManager(phaserGame); + globalScene = game.scene; game.override.battleType("single"); game.override.ability(Abilities.NONE); game.override.moveset([ Moves.ABSORB, Moves.ROCK_SLIDE, Moves.TACKLE ]); @@ -93,8 +96,8 @@ const getMockedMoveDamage = (defender: Pokemon, attacker: Pokemon, move: Move) = const multiplierHolder = new NumberHolder(1); const side = defender.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY; - if (defender.scene.arena.getTagOnSide(ArenaTagType.REFLECT, side)) { - defender.scene.arena.applyTagsForSide(ArenaTagType.REFLECT, side, false, attacker, move.category, multiplierHolder); + if (globalScene.arena.getTagOnSide(ArenaTagType.REFLECT, side)) { + globalScene.arena.applyTagsForSide(ArenaTagType.REFLECT, side, false, attacker, move.category, multiplierHolder); } return move.power * multiplierHolder.value; diff --git a/src/test/moves/tera_blast.test.ts b/src/test/moves/tera_blast.test.ts index 311ac0f0d0e3..44dc29f68b55 100644 --- a/src/test/moves/tera_blast.test.ts +++ b/src/test/moves/tera_blast.test.ts @@ -87,7 +87,7 @@ describe("Moves - Tera Blast", () => { }); // Currently abilities are bugged and can't see when a move's category is changed - it.skip("uses the higher stat of the user's Atk and SpAtk for damage calculation", async () => { + it.todo("uses the higher stat of the user's Atk and SpAtk for damage calculation", async () => { game.override.enemyAbility(Abilities.TOXIC_DEBRIS); await game.startBattle(); diff --git a/src/test/moves/toxic_spikes.test.ts b/src/test/moves/toxic_spikes.test.ts index bdd59ed0ac85..90129908db0f 100644 --- a/src/test/moves/toxic_spikes.test.ts +++ b/src/test/moves/toxic_spikes.test.ts @@ -116,8 +116,7 @@ describe("Moves - Toxic Spikes", () => { it("should persist through reload", async () => { game.override.startingWave(1); - const scene = game.scene; - const gameData = new GameData(scene); + const gameData = new GameData(); await game.classicMode.runToSummon([ Species.MIGHTYENA ]); @@ -128,10 +127,10 @@ describe("Moves - Toxic Spikes", () => { await game.phaseInterceptor.to("BattleEndPhase"); await game.toNextWave(); - const sessionData : SessionSaveData = gameData["getSessionSaveData"](game.scene); + const sessionData : SessionSaveData = gameData["getSessionSaveData"](); localStorage.setItem("sessionTestData", encrypt(JSON.stringify(sessionData), true)); const recoveredData : SessionSaveData = gameData.parseSessionData(decrypt(localStorage.getItem("sessionTestData")!, true)); - gameData.loadSession(game.scene, 0, recoveredData); + gameData.loadSession(0, recoveredData); expect(sessionData.arena.tags).toEqual(recoveredData.arena.tags); localStorage.removeItem("sessionTestData"); diff --git a/src/test/mystery-encounter/encounter-test-utils.ts b/src/test/mystery-encounter/encounter-test-utils.ts index ee67f1b5d39d..a0e06536b51d 100644 --- a/src/test/mystery-encounter/encounter-test-utils.ts +++ b/src/test/mystery-encounter/encounter-test-utils.ts @@ -52,7 +52,7 @@ export async function runMysteryEncounterToEnd(game: GameManager, optionNo: numb game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.scene.clearPhaseQueue(); game.scene.clearPhaseQueueSplice(); - game.scene.unshiftPhase(new VictoryPhase(game.scene, 0)); + game.scene.unshiftPhase(new VictoryPhase(0)); game.endPhase(); }); @@ -170,7 +170,7 @@ export async function skipBattleRunMysteryEncounterRewardsPhase(game: GameManage p.status = new Status(StatusEffect.FAINT); game.scene.field.remove(p); }); - game.scene.pushPhase(new VictoryPhase(game.scene, 0)); + game.scene.pushPhase(new VictoryPhase(0)); game.phaseInterceptor.superEndPhase(); game.setMode(Mode.MESSAGE); await game.phaseInterceptor.to(MysteryEncounterRewardsPhase, runRewardsPhase); diff --git a/src/test/mystery-encounter/encounters/a-trainers-test-encounter.test.ts b/src/test/mystery-encounter/encounters/a-trainers-test-encounter.test.ts index 7d7839584227..b1a520c88c8a 100644 --- a/src/test/mystery-encounter/encounters/a-trainers-test-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/a-trainers-test-encounter.test.ts @@ -78,8 +78,8 @@ describe("A Trainer's Test - Mystery Encounter", () => { expect(ATrainersTestEncounter.onInit).toBeDefined(); - ATrainersTestEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + ATrainersTestEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(ATrainersTestEncounter.dialogueTokens?.statTrainerName).toBeDefined(); expect(ATrainersTestEncounter.misc.trainerType).toBeDefined(); diff --git a/src/test/mystery-encounter/encounters/an-offer-you-cant-refuse-encounter.test.ts b/src/test/mystery-encounter/encounters/an-offer-you-cant-refuse-encounter.test.ts index 727a3993d9b4..2db7843bd9aa 100644 --- a/src/test/mystery-encounter/encounters/an-offer-you-cant-refuse-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/an-offer-you-cant-refuse-encounter.test.ts @@ -91,8 +91,8 @@ describe("An Offer You Can't Refuse - Mystery Encounter", () => { expect(AnOfferYouCantRefuseEncounter.onInit).toBeDefined(); - AnOfferYouCantRefuseEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + AnOfferYouCantRefuseEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.strongestPokemon).toBeDefined(); expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.price).toBeDefined(); @@ -130,7 +130,7 @@ describe("An Offer You Can't Refuse - Mystery Encounter", () => { const price = scene.currentBattle.mysteryEncounter!.misc.price; - expect(updateMoneySpy).toHaveBeenCalledWith(scene, price); + expect(updateMoneySpy).toHaveBeenCalledWith(price); expect(scene.money).toBe(initialMoney + price); }); @@ -220,7 +220,7 @@ describe("An Offer You Can't Refuse - Mystery Encounter", () => { const price = scene.currentBattle.mysteryEncounter!.misc.price; - expect(updateMoneySpy).toHaveBeenCalledWith(scene, price); + expect(updateMoneySpy).toHaveBeenCalledWith(price); expect(scene.money).toBe(initialMoney + price); }); diff --git a/src/test/mystery-encounter/encounters/berries-abound-encounter.test.ts b/src/test/mystery-encounter/encounters/berries-abound-encounter.test.ts index 2507b94e5ae5..4eb15b420dcf 100644 --- a/src/test/mystery-encounter/encounters/berries-abound-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/berries-abound-encounter.test.ts @@ -80,8 +80,8 @@ describe("Berries Abound - Mystery Encounter", () => { expect(BerriesAboundEncounter.onInit).toBeDefined(); - BerriesAboundEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + BerriesAboundEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); const config = BerriesAboundEncounter.enemyPartyConfigs[0]; expect(config).toBeDefined(); @@ -192,7 +192,7 @@ describe("Berries Abound - Mystery Encounter", () => { // Should be enraged expect(enemyField[0].summonData.statStages).toEqual([ 0, 1, 0, 1, 1, 0, 0 ]); - expect(encounterTextSpy).toHaveBeenCalledWith(expect.any(BattleScene), `${namespace}:option.2.selected_bad`); + expect(encounterTextSpy).toHaveBeenCalledWith(`${namespace}:option.2.selected_bad`); }); it("should start battle if fastest pokemon is slower than boss above wave 50", async () => { @@ -216,7 +216,7 @@ describe("Berries Abound - Mystery Encounter", () => { // Should be enraged expect(enemyField[0].summonData.statStages).toEqual([ 1, 1, 1, 1, 1, 0, 0 ]); - expect(encounterTextSpy).toHaveBeenCalledWith(expect.any(BattleScene), `${namespace}:option.2.selected_bad`); + expect(encounterTextSpy).toHaveBeenCalledWith(`${namespace}:option.2.selected_bad`); }); it("Should skip battle when fastest pokemon is faster than boss", async () => { @@ -241,7 +241,7 @@ describe("Berries Abound - Mystery Encounter", () => { expect(option.modifierTypeOption.type.id).toContain("BERRY"); } - expect(EncounterDialogueUtils.showEncounterText).toHaveBeenCalledWith(expect.any(BattleScene), `${namespace}:option.2.selected`); + expect(EncounterDialogueUtils.showEncounterText).toHaveBeenCalledWith(`${namespace}:option.2.selected`); expect(EncounterPhaseUtils.leaveEncounterWithoutBattle).toBeCalled(); }); }); diff --git a/src/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts b/src/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts index e0f37c7e0458..f3ebb6db57a5 100644 --- a/src/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts @@ -209,8 +209,8 @@ describe("Bug-Type Superfan - Mystery Encounter", () => { expect(BugTypeSuperfanEncounter.onInit).toBeDefined(); - BugTypeSuperfanEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + BugTypeSuperfanEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); const config = BugTypeSuperfanEncounter.enemyPartyConfigs[0]; expect(config).toBeDefined(); @@ -384,7 +384,7 @@ describe("Bug-Type Superfan - Mystery Encounter", () => { await game.phaseInterceptor.run(MysteryEncounterRewardsPhase); expect(selectOptionSpy).toHaveBeenCalledTimes(1); - const optionData = selectOptionSpy.mock.calls[0][1]; + const optionData = selectOptionSpy.mock.calls[0][0]; expect(PHYSICAL_TUTOR_MOVES.some(move => new PokemonMove(move).getName() === optionData[0].label)).toBe(true); expect(SPECIAL_TUTOR_MOVES.some(move => new PokemonMove(move).getName() === optionData[1].label)).toBe(true); expect(STATUS_TUTOR_MOVES.some(move => new PokemonMove(move).getName() === optionData[2].label)).toBe(true); diff --git a/src/test/mystery-encounter/encounters/clowning-around-encounter.test.ts b/src/test/mystery-encounter/encounters/clowning-around-encounter.test.ts index e7ea6eea0eaa..5bfab7dfc997 100644 --- a/src/test/mystery-encounter/encounters/clowning-around-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/clowning-around-encounter.test.ts @@ -105,8 +105,8 @@ describe("Clowning Around - Mystery Encounter", () => { expect(ClowningAroundEncounter.onInit).toBeDefined(); - ClowningAroundEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + ClowningAroundEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); const config = ClowningAroundEncounter.enemyPartyConfigs[0]; expect(config.doubleBattle).toBe(true); @@ -255,29 +255,29 @@ describe("Clowning Around - Mystery Encounter", () => { // 2 Sitrus Berries on lead scene.modifiers = []; - let itemType = generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType; + let itemType = generateModifierType(modifierTypes.BERRY, [ BerryType.SITRUS ]) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[0], 2, itemType); // 2 Ganlon Berries on lead - itemType = generateModifierType(scene, modifierTypes.BERRY, [ BerryType.GANLON ]) as PokemonHeldItemModifierType; + itemType = generateModifierType(modifierTypes.BERRY, [ BerryType.GANLON ]) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[0], 2, itemType); // 5 Golden Punch on lead (ultra) - itemType = generateModifierType(scene, modifierTypes.GOLDEN_PUNCH) as PokemonHeldItemModifierType; + itemType = generateModifierType(modifierTypes.GOLDEN_PUNCH) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[0], 5, itemType); // 5 Lucky Egg on lead (ultra) - itemType = generateModifierType(scene, modifierTypes.LUCKY_EGG) as PokemonHeldItemModifierType; + itemType = generateModifierType(modifierTypes.LUCKY_EGG) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[0], 5, itemType); // 3 Soothe Bell on lead (great tier, but counted as ultra by this ME) - itemType = generateModifierType(scene, modifierTypes.SOOTHE_BELL) as PokemonHeldItemModifierType; + itemType = generateModifierType(modifierTypes.SOOTHE_BELL) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[0], 3, itemType); // 5 Soul Dew on lead (rogue) - itemType = generateModifierType(scene, modifierTypes.SOUL_DEW) as PokemonHeldItemModifierType; + itemType = generateModifierType(modifierTypes.SOUL_DEW) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[0], 5, itemType); // 2 Golden Egg on lead (rogue) - itemType = generateModifierType(scene, modifierTypes.GOLDEN_EGG) as PokemonHeldItemModifierType; + itemType = generateModifierType(modifierTypes.GOLDEN_EGG) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[0], 2, itemType); // 5 Soul Dew on second party pokemon (these should not change) - itemType = generateModifierType(scene, modifierTypes.SOUL_DEW) as PokemonHeldItemModifierType; + itemType = generateModifierType(modifierTypes.SOUL_DEW) as PokemonHeldItemModifierType; await addItemToPokemon(scene, scene.getPlayerParty()[1], 5, itemType); await runMysteryEncounterToEnd(game, 2); diff --git a/src/test/mystery-encounter/encounters/delibirdy-encounter.test.ts b/src/test/mystery-encounter/encounters/delibirdy-encounter.test.ts index c226d60a9b46..d4cb0a7ef945 100644 --- a/src/test/mystery-encounter/encounters/delibirdy-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/delibirdy-encounter.test.ts @@ -100,7 +100,7 @@ describe("Delibird-y - Mystery Encounter", () => { const price = (scene.currentBattle.mysteryEncounter?.options[0].requirements[0] as MoneyRequirement).requiredMoney; - expect(updateMoneySpy).toHaveBeenCalledWith(scene, -price, true, false); + expect(updateMoneySpy).toHaveBeenCalledWith(-price, true, false); expect(scene.money).toBe(initialMoney - price); }); @@ -121,7 +121,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Max Amulet Coins scene.modifiers = []; - const amuletCoin = generateModifierType(scene, modifierTypes.AMULET_COIN)!.newModifier() as MoneyMultiplierModifier; + const amuletCoin = generateModifierType(modifierTypes.AMULET_COIN)!.newModifier() as MoneyMultiplierModifier; amuletCoin.stackCount = 5; await scene.addModifier(amuletCoin, true, false, false, true); await scene.updateModifiers(true); @@ -190,7 +190,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Set 2 Sitrus berries on party lead scene.modifiers = []; - const sitrus = generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SITRUS ])!; + const sitrus = generateModifierType(modifierTypes.BERRY, [ BerryType.SITRUS ])!; const sitrusMod = sitrus.newModifier(scene.getPlayerParty()[0]) as BerryModifier; sitrusMod.stackCount = 2; await scene.addModifier(sitrusMod, true, false, false, true); @@ -211,7 +211,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Set 1 Reviver Seed on party lead scene.modifiers = []; - const revSeed = generateModifierType(scene, modifierTypes.REVIVER_SEED)!; + const revSeed = generateModifierType(modifierTypes.REVIVER_SEED)!; const modifier = revSeed.newModifier(scene.getPlayerParty()[0]) as PokemonInstantReviveModifier; modifier.stackCount = 1; await scene.addModifier(modifier, true, false, false, true); @@ -232,10 +232,10 @@ describe("Delibird-y - Mystery Encounter", () => { // 99 Candy Jars scene.modifiers = []; - const candyJar = generateModifierType(scene, modifierTypes.CANDY_JAR)!.newModifier() as LevelIncrementBoosterModifier; + const candyJar = generateModifierType(modifierTypes.CANDY_JAR)!.newModifier() as LevelIncrementBoosterModifier; candyJar.stackCount = 99; await scene.addModifier(candyJar, true, false, false, true); - const sitrus = generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SITRUS ])!; + const sitrus = generateModifierType(modifierTypes.BERRY, [ BerryType.SITRUS ])!; // Sitrus berries on party const sitrusMod = sitrus.newModifier(scene.getPlayerParty()[0]) as BerryModifier; @@ -261,12 +261,12 @@ describe("Delibird-y - Mystery Encounter", () => { // 3 Berry Pouches scene.modifiers = []; - const healingCharm = generateModifierType(scene, modifierTypes.BERRY_POUCH)!.newModifier() as PreserveBerryModifier; + const healingCharm = generateModifierType(modifierTypes.BERRY_POUCH)!.newModifier() as PreserveBerryModifier; healingCharm.stackCount = 3; await scene.addModifier(healingCharm, true, false, false, true); // Set 1 Reviver Seed on party lead - const revSeed = generateModifierType(scene, modifierTypes.REVIVER_SEED)!; + const revSeed = generateModifierType(modifierTypes.REVIVER_SEED)!; const modifier = revSeed.newModifier(scene.getPlayerParty()[0]) as PokemonInstantReviveModifier; modifier.stackCount = 1; await scene.addModifier(modifier, true, false, false, true); @@ -290,7 +290,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Set 1 Soul Dew on party lead scene.modifiers = []; - const soulDew = generateModifierType(scene, modifierTypes.SOUL_DEW)!; + const soulDew = generateModifierType(modifierTypes.SOUL_DEW)!; const modifier = soulDew.newModifier(scene.getPlayerParty()[0]); await scene.addModifier(modifier, true, false, false, true); await scene.updateModifiers(true); @@ -318,7 +318,7 @@ describe("Delibird-y - Mystery Encounter", () => { await game.runToMysteryEncounter(MysteryEncounterType.DELIBIRDY, defaultParty); // Set 1 Reviver Seed on party lead - const revSeed = generateModifierType(scene, modifierTypes.REVIVER_SEED)!; + const revSeed = generateModifierType(modifierTypes.REVIVER_SEED)!; const modifier = revSeed.newModifier(scene.getPlayerParty()[0]) as PokemonInstantReviveModifier; modifier.stackCount = 1; await scene.addModifier(modifier, true, false, false, true); @@ -352,7 +352,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Set 2 Soul Dew on party lead scene.modifiers = []; - const soulDew = generateModifierType(scene, modifierTypes.SOUL_DEW)!; + const soulDew = generateModifierType(modifierTypes.SOUL_DEW)!; const modifier = soulDew.newModifier(scene.getPlayerParty()[0]) as PokemonNatureWeightModifier; modifier.stackCount = 2; await scene.addModifier(modifier, true, false, false, true); @@ -373,7 +373,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Set 1 Soul Dew on party lead scene.modifiers = []; - const soulDew = generateModifierType(scene, modifierTypes.SOUL_DEW)!; + const soulDew = generateModifierType(modifierTypes.SOUL_DEW)!; const modifier = soulDew.newModifier(scene.getPlayerParty()[0]) as PokemonNatureWeightModifier; modifier.stackCount = 1; await scene.addModifier(modifier, true, false, false, true); @@ -394,12 +394,12 @@ describe("Delibird-y - Mystery Encounter", () => { // 5 Healing Charms scene.modifiers = []; - const healingCharm = generateModifierType(scene, modifierTypes.HEALING_CHARM)!.newModifier() as HealingBoosterModifier; + const healingCharm = generateModifierType(modifierTypes.HEALING_CHARM)!.newModifier() as HealingBoosterModifier; healingCharm.stackCount = 5; await scene.addModifier(healingCharm, true, false, false, true); // Set 1 Soul Dew on party lead - const soulDew = generateModifierType(scene, modifierTypes.SOUL_DEW)!; + const soulDew = generateModifierType(modifierTypes.SOUL_DEW)!; const modifier = soulDew.newModifier(scene.getPlayerParty()[0]) as PokemonNatureWeightModifier; modifier.stackCount = 1; await scene.addModifier(modifier, true, false, false, true); @@ -423,7 +423,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Set 1 Reviver Seed on party lead scene.modifiers = []; - const revSeed = generateModifierType(scene, modifierTypes.REVIVER_SEED)!; + const revSeed = generateModifierType(modifierTypes.REVIVER_SEED)!; const modifier = revSeed.newModifier(scene.getPlayerParty()[0]); await scene.addModifier(modifier, true, false, false, true); await scene.updateModifiers(true); @@ -452,7 +452,7 @@ describe("Delibird-y - Mystery Encounter", () => { // Set 1 Soul Dew on party lead scene.modifiers = []; - const soulDew = generateModifierType(scene, modifierTypes.SOUL_DEW)!; + const soulDew = generateModifierType(modifierTypes.SOUL_DEW)!; const modifier = soulDew.newModifier(scene.getPlayerParty()[0]) as PokemonNatureWeightModifier; modifier.stackCount = 1; await scene.addModifier(modifier, true, false, false, true); diff --git a/src/test/mystery-encounter/encounters/fiery-fallout-encounter.test.ts b/src/test/mystery-encounter/encounters/fiery-fallout-encounter.test.ts index 215cab5c65ad..87725c79a98e 100644 --- a/src/test/mystery-encounter/encounters/fiery-fallout-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/fiery-fallout-encounter.test.ts @@ -104,8 +104,8 @@ describe("Fiery Fallout - Mystery Encounter", () => { expect(FieryFalloutEncounter.onInit).toBeDefined(); - FieryFalloutEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + FieryFalloutEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(FieryFalloutEncounter.enemyPartyConfigs).toEqual([ { diff --git a/src/test/mystery-encounter/encounters/fight-or-flight-encounter.test.ts b/src/test/mystery-encounter/encounters/fight-or-flight-encounter.test.ts index a5098f682eb8..60346c75a554 100644 --- a/src/test/mystery-encounter/encounters/fight-or-flight-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/fight-or-flight-encounter.test.ts @@ -75,8 +75,8 @@ describe("Fight or Flight - Mystery Encounter", () => { expect(FightOrFlightEncounter.onInit).toBeDefined(); - FightOrFlightEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + FightOrFlightEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); const config = FightOrFlightEncounter.enemyPartyConfigs[0]; expect(config).toBeDefined(); diff --git a/src/test/mystery-encounter/encounters/fun-and-games-encounter.test.ts b/src/test/mystery-encounter/encounters/fun-and-games-encounter.test.ts index 2f4f6bed2881..2b23efeaea8c 100644 --- a/src/test/mystery-encounter/encounters/fun-and-games-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/fun-and-games-encounter.test.ts @@ -95,7 +95,7 @@ describe("Fun And Games! - Mystery Encounter", () => { expect(encounter.onInit).toBeDefined(); - const onInitResult = onInit!(scene); + const onInitResult = onInit!(); expect(onInitResult).toBe(true); }); diff --git a/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts b/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts index 2c226df3c8c0..4be1aebf639d 100644 --- a/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/global-trade-system-encounter.test.ts @@ -221,7 +221,7 @@ describe("Global Trade System - Mystery Encounter", () => { // Set 2 Soul Dew on party lead scene.modifiers = []; - const soulDew = generateModifierType(scene, modifierTypes.SOUL_DEW)!; + const soulDew = generateModifierType(modifierTypes.SOUL_DEW)!; const modifier = soulDew.newModifier(scene.getPlayerParty()[0]) as PokemonNatureWeightModifier; modifier.stackCount = 2; await scene.addModifier(modifier, true, false, false, true); @@ -246,7 +246,7 @@ describe("Global Trade System - Mystery Encounter", () => { // Set 1 Soul Dew on party lead scene.modifiers = []; - const soulDew = generateModifierType(scene, modifierTypes.SOUL_DEW)!; + const soulDew = generateModifierType(modifierTypes.SOUL_DEW)!; const modifier = soulDew.newModifier(scene.getPlayerParty()[0]) as PokemonNatureWeightModifier; modifier.stackCount = 1; await scene.addModifier(modifier, true, false, false, true); diff --git a/src/test/mystery-encounter/encounters/lost-at-sea-encounter.test.ts b/src/test/mystery-encounter/encounters/lost-at-sea-encounter.test.ts index 51f759c92689..126fc349f8d7 100644 --- a/src/test/mystery-encounter/encounters/lost-at-sea-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/lost-at-sea-encounter.test.ts @@ -83,8 +83,8 @@ describe("Lost at Sea - Mystery Encounter", () => { expect(LostAtSeaEncounter.onInit).toBeDefined(); - LostAtSeaEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + LostAtSeaEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(LostAtSeaEncounter.dialogueTokens?.damagePercentage).toBe("25"); expect(LostAtSeaEncounter.dialogueTokens?.option1RequiredMove).toBe(i18next.t("move:surf.name")); diff --git a/src/test/mystery-encounter/encounters/mysterious-challengers-encounter.test.ts b/src/test/mystery-encounter/encounters/mysterious-challengers-encounter.test.ts index 7bbc505dd8eb..3fb994f06ced 100644 --- a/src/test/mystery-encounter/encounters/mysterious-challengers-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/mysterious-challengers-encounter.test.ts @@ -89,8 +89,8 @@ describe("Mysterious Challengers - Mystery Encounter", () => { expect(encounter.onInit).toBeDefined(); - encounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + encounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(encounter.enemyPartyConfigs).toBeDefined(); expect(encounter.enemyPartyConfigs.length).toBe(3); diff --git a/src/test/mystery-encounter/encounters/part-timer-encounter.test.ts b/src/test/mystery-encounter/encounters/part-timer-encounter.test.ts index e063a4f3349a..a9035153de7b 100644 --- a/src/test/mystery-encounter/encounters/part-timer-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/part-timer-encounter.test.ts @@ -107,7 +107,7 @@ describe("Part-Timer - Mystery Encounter", () => { }); await runMysteryEncounterToEnd(game, 1, { pokemonNo: 1 }); - expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene, scene.getWaveMoneyAmount(1), true, false); + expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene.getWaveMoneyAmount(1), true, false); // Expect PP of mon's moves to have been reduced to 2 const moves = scene.getPlayerParty()[0].moveset; for (const move of moves) { @@ -127,7 +127,7 @@ describe("Part-Timer - Mystery Encounter", () => { }); await runMysteryEncounterToEnd(game, 1, { pokemonNo: 2 }); - expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene, scene.getWaveMoneyAmount(4), true, false); + expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene.getWaveMoneyAmount(4), true, false); // Expect PP of mon's moves to have been reduced to 2 const moves = scene.getPlayerParty()[1].moveset; for (const move of moves) { @@ -172,7 +172,7 @@ describe("Part-Timer - Mystery Encounter", () => { }); await runMysteryEncounterToEnd(game, 2, { pokemonNo: 3 }); - expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene, scene.getWaveMoneyAmount(1), true, false); + expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene.getWaveMoneyAmount(1), true, false); // Expect PP of mon's moves to have been reduced to 2 const moves = scene.getPlayerParty()[2].moveset; for (const move of moves) { @@ -192,7 +192,7 @@ describe("Part-Timer - Mystery Encounter", () => { }); await runMysteryEncounterToEnd(game, 2, { pokemonNo: 4 }); - expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene, scene.getWaveMoneyAmount(4), true, false); + expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene.getWaveMoneyAmount(4), true, false); // Expect PP of mon's moves to have been reduced to 2 const moves = scene.getPlayerParty()[3].moveset; for (const move of moves) { @@ -259,7 +259,7 @@ describe("Part-Timer - Mystery Encounter", () => { scene.getPlayerParty()[0].moveset = [ new PokemonMove(Moves.ATTRACT) ]; await runMysteryEncounterToEnd(game, 3); - expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene, scene.getWaveMoneyAmount(2.5), true, false); + expect(EncounterPhaseUtils.updatePlayerMoney).toHaveBeenCalledWith(scene.getWaveMoneyAmount(2.5), true, false); // Expect PP of mon's moves to have been reduced to 2 const moves = scene.getPlayerParty()[0].moveset; for (const move of moves) { diff --git a/src/test/mystery-encounter/encounters/safari-zone.test.ts b/src/test/mystery-encounter/encounters/safari-zone.test.ts index 5699afe254f5..77fbb411ac6f 100644 --- a/src/test/mystery-encounter/encounters/safari-zone.test.ts +++ b/src/test/mystery-encounter/encounters/safari-zone.test.ts @@ -85,8 +85,8 @@ describe("Safari Zone - Mystery Encounter", () => { expect(encounter.onInit).toBeDefined(); - encounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + encounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(onInitResult).toBe(true); }); diff --git a/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts b/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts index 02375d83b98c..45263a6c0650 100644 --- a/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts @@ -115,8 +115,8 @@ describe("Teleporting Hijinks - Mystery Encounter", () => { expect(TeleportingHijinksEncounter.onInit).toBeDefined(); - TeleportingHijinksEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + TeleportingHijinksEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(TeleportingHijinksEncounter.misc.price).toBeDefined(); expect(TeleportingHijinksEncounter.dialogueTokens.price).toBeDefined(); diff --git a/src/test/mystery-encounter/encounters/the-expert-breeder-encounter.test.ts b/src/test/mystery-encounter/encounters/the-expert-breeder-encounter.test.ts index 87ccff71e224..19662a34cb84 100644 --- a/src/test/mystery-encounter/encounters/the-expert-breeder-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/the-expert-breeder-encounter.test.ts @@ -96,8 +96,8 @@ describe("The Expert Pokémon Breeder - Mystery Encounter", () => { expect(encounter.onInit).toBeDefined(); - encounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + encounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(encounter.enemyPartyConfigs).toBeDefined(); expect(encounter.enemyPartyConfigs.length).toBe(1); diff --git a/src/test/mystery-encounter/encounters/the-pokemon-salesman-encounter.test.ts b/src/test/mystery-encounter/encounters/the-pokemon-salesman-encounter.test.ts index e90bc4efe56d..cd1e5566af91 100644 --- a/src/test/mystery-encounter/encounters/the-pokemon-salesman-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/the-pokemon-salesman-encounter.test.ts @@ -88,8 +88,8 @@ describe("The Pokemon Salesman - Mystery Encounter", () => { expect(ThePokemonSalesmanEncounter.onInit).toBeDefined(); - ThePokemonSalesmanEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + ThePokemonSalesmanEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(ThePokemonSalesmanEncounter.dialogueTokens?.purchasePokemon).toBeDefined(); expect(ThePokemonSalesmanEncounter.dialogueTokens?.price).toBeDefined(); @@ -133,7 +133,7 @@ describe("The Pokemon Salesman - Mystery Encounter", () => { const price = scene.currentBattle.mysteryEncounter!.misc.price; - expect(updateMoneySpy).toHaveBeenCalledWith(scene, -price, true, false); + expect(updateMoneySpy).toHaveBeenCalledWith(-price, true, false); expect(scene.money).toBe(initialMoney - price); }); diff --git a/src/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts b/src/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts index 5c965b13bd40..fa2686260d90 100644 --- a/src/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/the-strong-stuff-encounter.test.ts @@ -97,8 +97,8 @@ describe("The Strong Stuff - Mystery Encounter", () => { expect(TheStrongStuffEncounter.onInit).toBeDefined(); - TheStrongStuffEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + TheStrongStuffEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(TheStrongStuffEncounter.enemyPartyConfigs).toEqual([ { diff --git a/src/test/mystery-encounter/encounters/the-winstrate-challenge-encounter.test.ts b/src/test/mystery-encounter/encounters/the-winstrate-challenge-encounter.test.ts index 701a3c94add3..13ee04f1af2f 100644 --- a/src/test/mystery-encounter/encounters/the-winstrate-challenge-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/the-winstrate-challenge-encounter.test.ts @@ -101,8 +101,8 @@ describe("The Winstrate Challenge - Mystery Encounter", () => { expect(encounter.onInit).toBeDefined(); - encounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + encounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(encounter.enemyPartyConfigs).toBeDefined(); expect(encounter.enemyPartyConfigs.length).toBe(5); @@ -363,7 +363,7 @@ async function skipBattleToNextBattle(game: GameManager, isFinalBattle: boolean game.scene.field.remove(p); }); game.phaseInterceptor["onHold"] = []; - game.scene.pushPhase(new VictoryPhase(game.scene, 0)); + game.scene.pushPhase(new VictoryPhase(0)); game.phaseInterceptor.superEndPhase(); if (isFinalBattle) { await game.phaseInterceptor.to(MysteryEncounterRewardsPhase); diff --git a/src/test/mystery-encounter/encounters/trash-to-treasure-encounter.test.ts b/src/test/mystery-encounter/encounters/trash-to-treasure-encounter.test.ts index f8d96487092e..ab57500894f7 100644 --- a/src/test/mystery-encounter/encounters/trash-to-treasure-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/trash-to-treasure-encounter.test.ts @@ -81,8 +81,8 @@ describe("Trash to Treasure - Mystery Encounter", () => { expect(TrashToTreasureEncounter.onInit).toBeDefined(); - TrashToTreasureEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + TrashToTreasureEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(TrashToTreasureEncounter.enemyPartyConfigs).toEqual([ { diff --git a/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts b/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts index c811bda673da..b919f87dd7b7 100644 --- a/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/uncommon-breed-encounter.test.ts @@ -85,8 +85,8 @@ describe("Uncommon Breed - Mystery Encounter", () => { expect(UncommonBreedEncounter.onInit).toBeDefined(); - UncommonBreedEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + UncommonBreedEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); const config = UncommonBreedEncounter.enemyPartyConfigs[0]; expect(config).toBeDefined(); @@ -213,11 +213,11 @@ describe("Uncommon Breed - Mystery Encounter", () => { await game.runToMysteryEncounter(MysteryEncounterType.UNCOMMON_BREED, defaultParty); // Berries on party lead - const sitrus = generateModifierType(scene, modifierTypes.BERRY, [ BerryType.SITRUS ])!; + const sitrus = generateModifierType(modifierTypes.BERRY, [ BerryType.SITRUS ])!; const sitrusMod = sitrus.newModifier(scene.getPlayerParty()[0]) as BerryModifier; sitrusMod.stackCount = 2; await scene.addModifier(sitrusMod, true, false, false, true); - const ganlon = generateModifierType(scene, modifierTypes.BERRY, [ BerryType.GANLON ])!; + const ganlon = generateModifierType(modifierTypes.BERRY, [ BerryType.GANLON ])!; const ganlonMod = ganlon.newModifier(scene.getPlayerParty()[0]) as BerryModifier; ganlonMod.stackCount = 3; await scene.addModifier(ganlonMod, true, false, false, true); diff --git a/src/test/mystery-encounter/encounters/weird-dream-encounter.test.ts b/src/test/mystery-encounter/encounters/weird-dream-encounter.test.ts index ec9cf1509b1a..d3183b267345 100644 --- a/src/test/mystery-encounter/encounters/weird-dream-encounter.test.ts +++ b/src/test/mystery-encounter/encounters/weird-dream-encounter.test.ts @@ -84,8 +84,8 @@ describe("Weird Dream - Mystery Encounter", () => { expect(WeirdDreamEncounter.onInit).toBeDefined(); - WeirdDreamEncounter.populateDialogueTokensFromRequirements(scene); - const onInitResult = onInit!(scene); + WeirdDreamEncounter.populateDialogueTokensFromRequirements(); + const onInitResult = onInit!(); expect(loadBgmSpy).toHaveBeenCalled(); expect(onInitResult).toBe(true); diff --git a/src/test/mystery-encounter/mystery-encounter-utils.test.ts b/src/test/mystery-encounter/mystery-encounter-utils.test.ts index d17b5c8a587f..73b133bc0514 100644 --- a/src/test/mystery-encounter/mystery-encounter-utils.test.ts +++ b/src/test/mystery-encounter/mystery-encounter-utils.test.ts @@ -39,12 +39,12 @@ describe("Mystery Encounter Utils", () => { // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) game.override.seed("random"); - let result = getRandomPlayerPokemon(scene); + let result = getRandomPlayerPokemon(); expect(result.species.speciesId).toBe(Species.MANAPHY); game.override.seed("random2"); - result = getRandomPlayerPokemon(scene); + result = getRandomPlayerPokemon(); expect(result.species.speciesId).toBe(Species.ARCEUS); }); @@ -59,12 +59,12 @@ describe("Mystery Encounter Utils", () => { // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) game.override.seed("random"); - let result = getRandomPlayerPokemon(scene); + let result = getRandomPlayerPokemon(); expect(result.species.speciesId).toBe(Species.MANAPHY); game.override.seed("random2"); - result = getRandomPlayerPokemon(scene); + result = getRandomPlayerPokemon(); expect(result.species.speciesId).toBe(Species.ARCEUS); }); @@ -78,12 +78,12 @@ describe("Mystery Encounter Utils", () => { // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) game.override.seed("random"); - let result = getRandomPlayerPokemon(scene, true); + let result = getRandomPlayerPokemon(true); expect(result.species.speciesId).toBe(Species.MANAPHY); game.override.seed("random2"); - result = getRandomPlayerPokemon(scene, true); + result = getRandomPlayerPokemon(true); expect(result.species.speciesId).toBe(Species.MANAPHY); }); @@ -97,12 +97,12 @@ describe("Mystery Encounter Utils", () => { // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) game.override.seed("random"); - let result = getRandomPlayerPokemon(scene, true, false); + let result = getRandomPlayerPokemon(true, false); expect(result.species.speciesId).toBe(Species.MANAPHY); game.override.seed("random2"); - result = getRandomPlayerPokemon(scene, true, false); + result = getRandomPlayerPokemon(true, false); expect(result.species.speciesId).toBe(Species.MANAPHY); }); @@ -116,12 +116,12 @@ describe("Mystery Encounter Utils", () => { // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) game.override.seed("random"); - let result = getRandomPlayerPokemon(scene, true, false, true); + let result = getRandomPlayerPokemon(true, false, true); expect(result.species.speciesId).toBe(Species.ARCEUS); game.override.seed("random2"); - result = getRandomPlayerPokemon(scene, true, false, true); + result = getRandomPlayerPokemon(true, false, true); expect(result.species.speciesId).toBe(Species.ARCEUS); }); }); @@ -131,7 +131,7 @@ describe("Mystery Encounter Utils", () => { const party = scene.getPlayerParty(); party[0].level = 100; - const result = getHighestLevelPlayerPokemon(scene); + const result = getHighestLevelPlayerPokemon(); expect(result.species.speciesId).toBe(Species.ARCEUS); }); @@ -139,7 +139,7 @@ describe("Mystery Encounter Utils", () => { const party = scene.getPlayerParty(); party[1].level = 100; - const result = getHighestLevelPlayerPokemon(scene); + const result = getHighestLevelPlayerPokemon(); expect(result.species.speciesId).toBe(Species.MANAPHY); }); @@ -148,7 +148,7 @@ describe("Mystery Encounter Utils", () => { party[0].level = 100; party[1].level = 100; - const result = getHighestLevelPlayerPokemon(scene); + const result = getHighestLevelPlayerPokemon(); expect(result.species.speciesId).toBe(Species.ARCEUS); }); @@ -160,7 +160,7 @@ describe("Mystery Encounter Utils", () => { party[0].updateInfo(); party[1].level = 10; - const result = getHighestLevelPlayerPokemon(scene, true); + const result = getHighestLevelPlayerPokemon(true); expect(result.species.speciesId).toBe(Species.MANAPHY); }); }); @@ -170,7 +170,7 @@ describe("Mystery Encounter Utils", () => { const party = scene.getPlayerParty(); party[0].level = 100; - const result = getLowestLevelPlayerPokemon(scene); + const result = getLowestLevelPlayerPokemon(); expect(result.species.speciesId).toBe(Species.MANAPHY); }); @@ -178,7 +178,7 @@ describe("Mystery Encounter Utils", () => { const party = scene.getPlayerParty(); party[1].level = 100; - const result = getLowestLevelPlayerPokemon(scene); + const result = getLowestLevelPlayerPokemon(); expect(result.species.speciesId).toBe(Species.ARCEUS); }); @@ -187,7 +187,7 @@ describe("Mystery Encounter Utils", () => { party[0].level = 100; party[1].level = 100; - const result = getLowestLevelPlayerPokemon(scene); + const result = getLowestLevelPlayerPokemon(); expect(result.species.speciesId).toBe(Species.ARCEUS); }); @@ -199,7 +199,7 @@ describe("Mystery Encounter Utils", () => { party[0].updateInfo(); party[1].level = 100; - const result = getLowestLevelPlayerPokemon(scene, true); + const result = getLowestLevelPlayerPokemon(true); expect(result.species.speciesId).toBe(Species.MANAPHY); }); }); @@ -244,7 +244,7 @@ describe("Mystery Encounter Utils", () => { arceus.hp = 100; expect(arceus.isAllowedInBattle()).toBe(true); - koPlayerPokemon(scene, arceus); + koPlayerPokemon(arceus); expect(arceus.isAllowedInBattle()).toBe(false); }); }); @@ -254,7 +254,7 @@ describe("Mystery Encounter Utils", () => { scene.currentBattle.mysteryEncounter = new MysteryEncounter(null); scene.currentBattle.mysteryEncounter.setDialogueToken("test", "value"); - const result = getEncounterText(scene, "mysteryEncounter:unit_test_dialogue"); + const result = getEncounterText("mysteryEncounter:unit_test_dialogue"); expect(result).toEqual("mysteryEncounter:unit_test_dialogue"); }); @@ -263,7 +263,7 @@ describe("Mystery Encounter Utils", () => { scene.currentBattle.mysteryEncounter.setDialogueToken("test", "value"); scene.currentBattle.mysteryEncounter.setDialogueToken("testvalue", "new"); - const result = getEncounterText(scene, "mysteryEncounter:unit_test_dialogue"); + const result = getEncounterText("mysteryEncounter:unit_test_dialogue"); expect(result).toEqual("mysteryEncounter:unit_test_dialogue"); }); }); @@ -275,7 +275,7 @@ describe("Mystery Encounter Utils", () => { const spy = vi.spyOn(game.scene, "queueMessage"); const phaseSpy = vi.spyOn(game.scene, "unshiftPhase"); - queueEncounterMessage(scene, "mysteryEncounter:unit_test_dialogue"); + queueEncounterMessage("mysteryEncounter:unit_test_dialogue"); expect(spy).toHaveBeenCalledWith("mysteryEncounter:unit_test_dialogue", null, true); expect(phaseSpy).toHaveBeenCalledWith(expect.any(MessagePhase)); }); @@ -287,7 +287,7 @@ describe("Mystery Encounter Utils", () => { scene.currentBattle.mysteryEncounter.setDialogueToken("test", "value"); const spy = vi.spyOn(game.scene.ui, "showText"); - await showEncounterText(scene, "mysteryEncounter:unit_test_dialogue"); + await showEncounterText("mysteryEncounter:unit_test_dialogue"); expect(spy).toHaveBeenCalledWith("mysteryEncounter:unit_test_dialogue", null, expect.any(Function), 0, true, null); }); }); @@ -298,7 +298,7 @@ describe("Mystery Encounter Utils", () => { scene.currentBattle.mysteryEncounter.setDialogueToken("test", "value"); const spy = vi.spyOn(game.scene.ui, "showDialogue"); - await showEncounterDialogue(scene, "mysteryEncounter:unit_test_dialogue", "mysteryEncounter:unit_test_dialogue"); + await showEncounterDialogue("mysteryEncounter:unit_test_dialogue", "mysteryEncounter:unit_test_dialogue"); expect(spy).toHaveBeenCalledWith("mysteryEncounter:unit_test_dialogue", "mysteryEncounter:unit_test_dialogue", null, expect.any(Function), 0); }); }); diff --git a/src/test/phases/form-change-phase.test.ts b/src/test/phases/form-change-phase.test.ts index 3c0016260a39..07e59cafe1ca 100644 --- a/src/test/phases/form-change-phase.test.ts +++ b/src/test/phases/form-change-phase.test.ts @@ -44,7 +44,7 @@ describe("Form Change Phase", () => { expect(zacian.calculateBaseStats()).toStrictEqual([ 92, 120, 115, 80, 115, 138 ]); // Give Zacian a Rusted Sword - const rustedSwordType = generateModifierType(game.scene, modifierTypes.RARE_FORM_CHANGE_ITEM)!; + const rustedSwordType = generateModifierType( modifierTypes.RARE_FORM_CHANGE_ITEM)!; const rustedSword = rustedSwordType.newModifier(zacian); await game.scene.addModifier(rustedSword); diff --git a/src/test/phases/phases.test.ts b/src/test/phases/phases.test.ts index 5ef25361a3f1..59cca7e19876 100644 --- a/src/test/phases/phases.test.ts +++ b/src/test/phases/phases.test.ts @@ -29,7 +29,7 @@ describe("Phases", () => { describe("LoginPhase", () => { it("should start the login phase", async () => { - const loginPhase = new LoginPhase(scene); + const loginPhase = new LoginPhase(); scene.unshiftPhase(loginPhase); await game.phaseInterceptor.run(LoginPhase); expect(scene.ui.getMode()).to.equal(Mode.MESSAGE); @@ -38,7 +38,7 @@ describe("Phases", () => { describe("TitlePhase", () => { it("should start the title phase", async () => { - const titlePhase = new TitlePhase(scene); + const titlePhase = new TitlePhase(); scene.unshiftPhase(titlePhase); await game.phaseInterceptor.run(TitlePhase); expect(scene.ui.getMode()).to.equal(Mode.TITLE); @@ -47,7 +47,7 @@ describe("Phases", () => { describe("UnavailablePhase", () => { it("should start the unavailable phase", async () => { - const unavailablePhase = new UnavailablePhase(scene); + const unavailablePhase = new UnavailablePhase(); scene.unshiftPhase(unavailablePhase); await game.phaseInterceptor.run(UnavailablePhase); expect(scene.ui.getMode()).to.equal(Mode.UNAVAILABLE); diff --git a/src/test/phases/select-modifier-phase.test.ts b/src/test/phases/select-modifier-phase.test.ts index 60f81f3ad543..d4341a89b8c2 100644 --- a/src/test/phases/select-modifier-phase.test.ts +++ b/src/test/phases/select-modifier-phase.test.ts @@ -1,17 +1,20 @@ -import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import Phaser from "phaser"; -import GameManager from "#app/test/utils/gameManager"; -import { initSceneWithoutEncounterPhase } from "#app/test/utils/gameManagerUtils"; -import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler"; +import type BattleScene from "#app/battle-scene"; +import { getPokemonSpecies } from "#app/data/pokemon-species"; +import { PlayerPokemon } from "#app/field/pokemon"; import { ModifierTier } from "#app/modifier/modifier-tier"; -import * as Utils from "#app/utils"; import { CustomModifierSettings, ModifierTypeOption, modifierTypes } from "#app/modifier/modifier-type"; -import BattleScene from "#app/battle-scene"; -import { Species } from "#enums/species"; -import { Mode } from "#app/ui/ui"; -import { PlayerPokemon } from "#app/field/pokemon"; -import { getPokemonSpecies } from "#app/data/pokemon-species"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; +import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler"; +import { Mode } from "#app/ui/ui"; +import { shiftCharCodes } from "#app/utils"; +import { Abilities } from "#enums/abilities"; +import { Button } from "#enums/buttons"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; describe("SelectModifierPhase", () => { let phaserGame: Phaser.Game; @@ -28,7 +31,11 @@ describe("SelectModifierPhase", () => { game = new GameManager(phaserGame); scene = game.scene; - initSceneWithoutEncounterPhase(scene, [ Species.ABRA, Species.VOLCARONA ]); + game.override + .moveset([ Moves.FISSURE, Moves.SPLASH ]) + .ability(Abilities.NO_GUARD) + .startingLevel(200) + .enemySpecies(Species.MAGIKARP); }); afterEach(() => { @@ -38,7 +45,8 @@ describe("SelectModifierPhase", () => { }); it("should start a select modifier phase", async () => { - const selectModifierPhase = new SelectModifierPhase(scene); + initSceneWithoutEncounterPhase(scene, [ Species.ABRA, Species.VOLCARONA ]); + const selectModifierPhase = new SelectModifierPhase(); scene.pushPhase(selectModifierPhase); await game.phaseInterceptor.run(SelectModifierPhase); @@ -46,10 +54,9 @@ describe("SelectModifierPhase", () => { }); it("should generate random modifiers", async () => { - const selectModifierPhase = new SelectModifierPhase(scene); - scene.pushPhase(selectModifierPhase); - await game.phaseInterceptor.run(SelectModifierPhase); - + await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); + game.move.select(Moves.FISSURE); + await game.phaseInterceptor.to("SelectModifierPhase"); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; @@ -57,64 +64,63 @@ describe("SelectModifierPhase", () => { }); it("should modify reroll cost", async () => { + initSceneWithoutEncounterPhase(scene, [ Species.ABRA, Species.VOLCARONA ]); const options = [ new ModifierTypeOption(modifierTypes.POTION(), 0, 100), new ModifierTypeOption(modifierTypes.ETHER(), 0, 400), new ModifierTypeOption(modifierTypes.REVIVE(), 0, 1000) ]; - const selectModifierPhase1 = new SelectModifierPhase(scene, 0, undefined, { guaranteedModifierTypeOptions: options }); - const selectModifierPhase2 = new SelectModifierPhase(scene, 0, undefined, { guaranteedModifierTypeOptions: options, rerollMultiplier: 2 }); + const selectModifierPhase1 = new SelectModifierPhase(0, undefined, { guaranteedModifierTypeOptions: options }); + const selectModifierPhase2 = new SelectModifierPhase(0, undefined, { guaranteedModifierTypeOptions: options, rerollMultiplier: 2 }); const cost1 = selectModifierPhase1.getRerollCost(false); const cost2 = selectModifierPhase2.getRerollCost(false); expect(cost2).toEqual(cost1 * 2); }); - it("should generate random modifiers from reroll", async () => { - let selectModifierPhase = new SelectModifierPhase(scene); - scene.pushPhase(selectModifierPhase); - await game.phaseInterceptor.run(SelectModifierPhase); + it.todo("should generate random modifiers from reroll", async () => { + await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); + scene.money = 1000000; + scene.shopCursorTarget = 0; + + game.move.select(Moves.FISSURE); + await game.phaseInterceptor.to("SelectModifierPhase"); + // TODO: nagivate the ui to reroll somehow + //const smphase = scene.getCurrentPhase() as SelectModifierPhase; expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; expect(modifierSelectHandler.options.length).toEqual(3); - // Simulate selecting reroll - selectModifierPhase = new SelectModifierPhase(scene, 1, [ ModifierTier.COMMON, ModifierTier.COMMON, ModifierTier.COMMON ]); - scene.unshiftPhase(selectModifierPhase); - scene.ui.setMode(Mode.MESSAGE).then(() => game.endPhase()); - await game.phaseInterceptor.run(SelectModifierPhase); + modifierSelectHandler.processInput(Button.ACTION); + expect(scene.money).toBe(1000000 - 250); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); expect(modifierSelectHandler.options.length).toEqual(3); }); - it("should generate random modifiers of same tier for reroll with reroll lock", async () => { + it.todo("should generate random modifiers of same tier for reroll with reroll lock", async () => { + game.override.startingModifier([{ name: "LOCK_CAPSULE" }]); + await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); + scene.money = 1000000; // Just use fully random seed for this test vi.spyOn(scene, "resetSeed").mockImplementation(() => { - scene.waveSeed = Utils.shiftCharCodes(scene.seed, 5); + scene.waveSeed = shiftCharCodes(scene.seed, 5); Phaser.Math.RND.sow([ scene.waveSeed ]); console.log("Wave Seed:", scene.waveSeed, 5); scene.rngCounter = 0; }); - let selectModifierPhase = new SelectModifierPhase(scene); - scene.pushPhase(selectModifierPhase); - await game.phaseInterceptor.run(SelectModifierPhase); + game.move.select(Moves.FISSURE); + await game.phaseInterceptor.to("SelectModifierPhase"); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; expect(modifierSelectHandler.options.length).toEqual(3); const firstRollTiers: ModifierTier[] = modifierSelectHandler.options.map(o => o.modifierTypeOption.type.tier); - // Simulate selecting reroll with lock - scene.lockModifierTiers = true; - scene.reroll = true; - selectModifierPhase = new SelectModifierPhase(scene, 1, firstRollTiers); - scene.unshiftPhase(selectModifierPhase); - scene.ui.setMode(Mode.MESSAGE).then(() => game.endPhase()); - await game.phaseInterceptor.run(SelectModifierPhase); + // TODO: nagivate ui to reroll with lock capsule enabled expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); expect(modifierSelectHandler.options.length).toEqual(3); @@ -125,13 +131,15 @@ describe("SelectModifierPhase", () => { }); it("should generate custom modifiers", async () => { + await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); + scene.money = 1000000; const customModifiers: CustomModifierSettings = { guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM, modifierTypes.TM_ULTRA, modifierTypes.LEFTOVERS, modifierTypes.AMULET_COIN, modifierTypes.GOLDEN_PUNCH ] }; - const selectModifierPhase = new SelectModifierPhase(scene, 0, undefined, customModifiers); - scene.pushPhase(selectModifierPhase); - await game.phaseInterceptor.run(SelectModifierPhase); - + const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers); + scene.unshiftPhase(selectModifierPhase); + game.move.select(Moves.SPLASH); + await game.phaseInterceptor.to("SelectModifierPhase"); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; @@ -144,10 +152,12 @@ describe("SelectModifierPhase", () => { }); it("should generate custom modifier tiers that can upgrade from luck", async () => { + await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); + scene.money = 1000000; const customModifiers: CustomModifierSettings = { guaranteedModifierTiers: [ ModifierTier.COMMON, ModifierTier.GREAT, ModifierTier.ULTRA, ModifierTier.ROGUE, ModifierTier.MASTER ] }; - const pokemon = new PlayerPokemon(scene, getPokemonSpecies(Species.BULBASAUR), 10, undefined, 0, undefined, true, 2, undefined, undefined, undefined); + const pokemon = new PlayerPokemon(getPokemonSpecies(Species.BULBASAUR), 10, undefined, 0, undefined, true, 2); // Fill party with max shinies while (scene.getPlayerParty().length > 0) { @@ -155,10 +165,10 @@ describe("SelectModifierPhase", () => { } scene.getPlayerParty().push(pokemon, pokemon, pokemon, pokemon, pokemon, pokemon); - const selectModifierPhase = new SelectModifierPhase(scene, 0, undefined, customModifiers); - scene.pushPhase(selectModifierPhase); - await game.phaseInterceptor.run(SelectModifierPhase); - + const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers); + scene.unshiftPhase(selectModifierPhase); + game.move.select(Moves.SPLASH); + await game.phaseInterceptor.to("SelectModifierPhase"); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; @@ -171,12 +181,15 @@ describe("SelectModifierPhase", () => { }); it("should generate custom modifiers and modifier tiers together", async () => { + await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); + scene.money = 1000000; const customModifiers: CustomModifierSettings = { guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM, modifierTypes.TM_COMMON ], guaranteedModifierTiers: [ ModifierTier.MASTER, ModifierTier.MASTER ] }; - const selectModifierPhase = new SelectModifierPhase(scene, 0, undefined, customModifiers); - scene.pushPhase(selectModifierPhase); + const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers); + scene.unshiftPhase(selectModifierPhase); + game.move.select(Moves.SPLASH); await game.phaseInterceptor.run(SelectModifierPhase); @@ -190,13 +203,16 @@ describe("SelectModifierPhase", () => { }); it("should fill remaining modifiers if fillRemaining is true with custom modifiers", async () => { + await game.classicMode.startBattle([ Species.ABRA, Species.VOLCARONA ]); + scene.money = 1000000; const customModifiers: CustomModifierSettings = { guaranteedModifierTypeFuncs: [ modifierTypes.MEMORY_MUSHROOM ], guaranteedModifierTiers: [ ModifierTier.MASTER ], fillRemaining: true }; - const selectModifierPhase = new SelectModifierPhase(scene, 0, undefined, customModifiers); - scene.pushPhase(selectModifierPhase); + const selectModifierPhase = new SelectModifierPhase(0, undefined, customModifiers); + scene.unshiftPhase(selectModifierPhase); + game.move.select(Moves.SPLASH); await game.phaseInterceptor.run(SelectModifierPhase); diff --git a/src/test/system/game_data.test.ts b/src/test/system/game_data.test.ts index 1e3494703025..6dcd4091b667 100644 --- a/src/test/system/game_data.test.ts +++ b/src/test/system/game_data.test.ts @@ -41,7 +41,7 @@ describe("System - Game Data", () => { it("should return [true, true] if bypassLogin is true", async () => { vi.spyOn(BattleScene, "bypassLogin", "get").mockReturnValue(true); - const result = await game.scene.gameData.tryClearSession(game.scene, 0); + const result = await game.scene.gameData.tryClearSession(0); expect(result).toEqual([ true, true ]); }); @@ -49,7 +49,7 @@ describe("System - Game Data", () => { it("should return [true, true] if successful", async () => { vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ success: true }); - const result = await game.scene.gameData.tryClearSession(game.scene, 0); + const result = await game.scene.gameData.tryClearSession(0); expect(result).toEqual([ true, true ]); expect(account.updateUserInfo).toHaveBeenCalled(); @@ -58,7 +58,7 @@ describe("System - Game Data", () => { it("should return [true, false] if not successful", async () => { vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ success: false }); - const result = await game.scene.gameData.tryClearSession(game.scene, 0); + const result = await game.scene.gameData.tryClearSession(0); expect(result).toEqual([ true, false ]); expect(account.updateUserInfo).toHaveBeenCalled(); @@ -67,7 +67,7 @@ describe("System - Game Data", () => { it("should return [false, false] session is out of date", async () => { vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ error: "session out of date" }); - const result = await game.scene.gameData.tryClearSession(game.scene, 0); + const result = await game.scene.gameData.tryClearSession(0); expect(result).toEqual([ false, false ]); expect(account.updateUserInfo).toHaveBeenCalled(); diff --git a/src/test/utils/gameManager.ts b/src/test/utils/gameManager.ts index fe8d06c2c3b8..4ba44a0b46dc 100644 --- a/src/test/utils/gameManager.ts +++ b/src/test/utils/gameManager.ts @@ -173,8 +173,8 @@ export default class GameManager { this.onNextPrompt("TitlePhase", Mode.TITLE, () => { this.scene.gameMode = getGameMode(mode); const starters = generateStarter(this.scene, species); - const selectStarterPhase = new SelectStarterPhase(this.scene); - this.scene.pushPhase(new EncounterPhase(this.scene, false)); + const selectStarterPhase = new SelectStarterPhase(); + this.scene.pushPhase(new EncounterPhase(false)); selectStarterPhase.initBattle(starters); }); @@ -206,8 +206,8 @@ export default class GameManager { this.onNextPrompt("TitlePhase", Mode.TITLE, () => { this.scene.gameMode = getGameMode(GameModes.CLASSIC); const starters = generateStarter(this.scene, species); - const selectStarterPhase = new SelectStarterPhase(this.scene); - this.scene.pushPhase(new EncounterPhase(this.scene, false)); + const selectStarterPhase = new SelectStarterPhase(); + this.scene.pushPhase(new EncounterPhase(false)); selectStarterPhase.initBattle(starters); }, () => this.isCurrentPhase(EncounterPhase)); @@ -375,7 +375,7 @@ export default class GameManager { exportSaveToTest(): Promise { const saveKey = "x0i2O7WRiANTqPmZ"; return new Promise(async (resolve) => { - const sessionSaveData = this.scene.gameData.getSessionSaveData(this.scene); + const sessionSaveData = this.scene.gameData.getSessionSaveData(); const encryptedSaveData = AES.encrypt(JSON.stringify(sessionSaveData), saveKey).toString(); resolve(encryptedSaveData); }); @@ -403,7 +403,7 @@ export default class GameManager { async killPokemon(pokemon: PlayerPokemon | EnemyPokemon) { return new Promise(async (resolve, reject) => { pokemon.hp = 0; - this.scene.pushPhase(new FaintPhase(this.scene, pokemon.getBattlerIndex(), true)); + this.scene.pushPhase(new FaintPhase(pokemon.getBattlerIndex(), true)); await this.phaseInterceptor.to(FaintPhase).catch((e) => reject(e)); resolve(); }); diff --git a/src/test/utils/gameManagerUtils.ts b/src/test/utils/gameManagerUtils.ts index 0c70bcf7f182..af9f4bedc9ac 100644 --- a/src/test/utils/gameManagerUtils.ts +++ b/src/test/utils/gameManagerUtils.ts @@ -1,13 +1,14 @@ -import BattleScene from "#app/battle-scene"; +import Battle, { BattleType } from "#app/battle"; +import type BattleScene from "#app/battle-scene"; import { getDailyRunStarters } from "#app/data/daily-run"; import { Gender } from "#app/data/gender"; import { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species"; -import { Moves } from "#app/enums/moves"; import { PlayerPokemon } from "#app/field/pokemon"; import { GameModes, getGameMode } from "#app/game-mode"; +import type { StarterMoveset } from "#app/system/game-data"; import { Starter } from "#app/ui/starter-select-ui-handler"; +import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; -import Battle, { BattleType } from "#app/battle"; /** Function to convert Blob to string */ export function blobToString(blob) { @@ -31,9 +32,9 @@ export function holdOn(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); } -export function generateStarter(scene, species?: Species[]) { +export function generateStarter(scene: BattleScene, species?: Species[]): Starter[] { const seed = "test"; - const starters = getTestRunStarters(scene, seed, species); + const starters = getTestRunStarters(seed, species); const startingLevel = scene.gameMode.getStartingLevel(); for (const starter of starters) { const starterProps = scene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr); @@ -42,14 +43,18 @@ export function generateStarter(scene, species?: Species[]) { ? !starterProps.female ? Gender.MALE : Gender.FEMALE : Gender.GENDERLESS; const starterPokemon = scene.addPlayerPokemon(starter.species, startingLevel, starter.abilityIndex, starterFormIndex, starterGender, starterProps.shiny, starterProps.variant, undefined, starter.nature); - starter.moveset = starterPokemon.moveset; + const moveset: Moves[] = []; + starterPokemon.moveset.forEach((move) => { + moveset.push(move!.getMove().id); + }); + starter.moveset = moveset as StarterMoveset; } return starters; } -function getTestRunStarters(scene, seed, species) { +function getTestRunStarters(seed: string, species?: Species[]): Starter[] { if (!species) { - return getDailyRunStarters(scene, seed); + return getDailyRunStarters(seed); } const starters: Starter[] = []; const startingLevel = getGameMode(GameModes.CLASSIC).getStartingLevel(); @@ -57,7 +62,7 @@ function getTestRunStarters(scene, seed, species) { for (const specie of species) { const starterSpeciesForm = getPokemonSpeciesForm(specie, 0); const starterSpecies = getPokemonSpecies(starterSpeciesForm.speciesId); - const pokemon = new PlayerPokemon(scene, starterSpecies, startingLevel, undefined, 0, undefined, undefined, undefined, undefined, undefined, undefined); + const pokemon = new PlayerPokemon(starterSpecies, startingLevel, undefined, 0); const starter: Starter = { species: starterSpecies, dexAttr: pokemon.getDexAttr(), @@ -71,7 +76,7 @@ function getTestRunStarters(scene, seed, species) { return starters; } -export function waitUntil(truth) { +export function waitUntil(truth): Promise { return new Promise(resolve => { const interval = setInterval(() => { if (truth()) { @@ -83,7 +88,7 @@ export function waitUntil(truth) { } /** Get the index of `move` from the moveset of the pokemon on the player's field at location `pokemonIndex` */ -export function getMovePosition(scene: BattleScene, pokemonIndex: 0 | 1, move: Moves) { +export function getMovePosition(scene: BattleScene, pokemonIndex: 0 | 1, move: Moves): number { const playerPokemon = scene.getPlayerField()[pokemonIndex]; const moveSet = playerPokemon.getMoveset(); const index = moveSet.findIndex((m) => m?.moveId === move && m?.ppUsed < m?.getMovePp()); @@ -93,10 +98,8 @@ export function getMovePosition(scene: BattleScene, pokemonIndex: 0 | 1, move: M /** * Useful for populating party, wave index, etc. without having to spin up and run through an entire EncounterPhase - * @param scene - * @param species */ -export function initSceneWithoutEncounterPhase(scene: BattleScene, species?: Species[]) { +export function initSceneWithoutEncounterPhase(scene: BattleScene, species?: Species[]): void { const starters = generateStarter(scene, species); starters.forEach((starter) => { const starterProps = scene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr); diff --git a/src/test/utils/helpers/challengeModeHelper.ts b/src/test/utils/helpers/challengeModeHelper.ts index 5210d942d5a7..a1731eafee96 100644 --- a/src/test/utils/helpers/challengeModeHelper.ts +++ b/src/test/utils/helpers/challengeModeHelper.ts @@ -45,8 +45,8 @@ export class ChallengeModeHelper extends GameManagerHelper { this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => { this.game.scene.gameMode.challenges = this.challenges; const starters = generateStarter(this.game.scene, species); - const selectStarterPhase = new SelectStarterPhase(this.game.scene); - this.game.scene.pushPhase(new EncounterPhase(this.game.scene, false)); + const selectStarterPhase = new SelectStarterPhase(); + this.game.scene.pushPhase(new EncounterPhase(false)); selectStarterPhase.initBattle(starters); }); diff --git a/src/test/utils/helpers/classicModeHelper.ts b/src/test/utils/helpers/classicModeHelper.ts index 41a21a52b72a..040bd2b57b4b 100644 --- a/src/test/utils/helpers/classicModeHelper.ts +++ b/src/test/utils/helpers/classicModeHelper.ts @@ -30,8 +30,8 @@ export class ClassicModeHelper extends GameManagerHelper { this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => { this.game.scene.gameMode = getGameMode(GameModes.CLASSIC); const starters = generateStarter(this.game.scene, species); - const selectStarterPhase = new SelectStarterPhase(this.game.scene); - this.game.scene.pushPhase(new EncounterPhase(this.game.scene, false)); + const selectStarterPhase = new SelectStarterPhase(); + this.game.scene.pushPhase(new EncounterPhase(false)); selectStarterPhase.initBattle(starters); }); diff --git a/src/test/utils/helpers/dailyModeHelper.ts b/src/test/utils/helpers/dailyModeHelper.ts index 813544f85dfb..bdd44935ba77 100644 --- a/src/test/utils/helpers/dailyModeHelper.ts +++ b/src/test/utils/helpers/dailyModeHelper.ts @@ -26,7 +26,7 @@ export class DailyModeHelper extends GameManagerHelper { } this.game.onNextPrompt("TitlePhase", Mode.TITLE, () => { - const titlePhase = new TitlePhase(this.game.scene); + const titlePhase = new TitlePhase(); titlePhase.initDailyRun(); }); diff --git a/src/test/utils/helpers/reloadHelper.ts b/src/test/utils/helpers/reloadHelper.ts index e0e538120cce..04d58cafa229 100644 --- a/src/test/utils/helpers/reloadHelper.ts +++ b/src/test/utils/helpers/reloadHelper.ts @@ -18,9 +18,9 @@ export class ReloadHelper extends GameManagerHelper { super(game); // Whenever the game saves the session, save it to the reloadHelper instead - vi.spyOn(game.scene.gameData, "saveAll").mockImplementation((scene) => { + vi.spyOn(game.scene.gameData, "saveAll").mockImplementation(() => { return new Promise((resolve, reject) => { - this.sessionData = scene.gameData.getSessionSaveData(scene); + this.sessionData = game.scene.gameData.getSessionSaveData(); resolve(true); }); }); @@ -33,7 +33,7 @@ export class ReloadHelper extends GameManagerHelper { */ async reloadSession() : Promise { const scene = this.game.scene; - const titlePhase = new TitlePhase(scene); + const titlePhase = new TitlePhase(); scene.clearPhaseQueue(); diff --git a/src/test/utils/inputsHandler.ts b/src/test/utils/inputsHandler.ts index bf690d5d74c9..7017799a037e 100644 --- a/src/test/utils/inputsHandler.ts +++ b/src/test/utils/inputsHandler.ts @@ -58,7 +58,7 @@ export default class InputsHandler { } init(): void { - const touchControl = new TouchControl(this.scene); + const touchControl = new TouchControl(); touchControl.deactivatePressedKey(); //test purpose this.events = this.inputController.events; this.scene.input.gamepad?.emit("connected", this.fakePad); diff --git a/src/test/utils/phaseInterceptor.ts b/src/test/utils/phaseInterceptor.ts index 137506090041..d60e0e783736 100644 --- a/src/test/utils/phaseInterceptor.ts +++ b/src/test/utils/phaseInterceptor.ts @@ -510,7 +510,13 @@ export default class PhaseInterceptor { const currentHandler = this.scene.ui.getHandler(); if (expireFn) { this.prompts.shift(); - } else if (currentMode === actionForNextPrompt.mode && currentPhase === actionForNextPrompt.phaseTarget && currentHandler.active && (!actionForNextPrompt.awaitingActionInput || (actionForNextPrompt.awaitingActionInput && currentHandler.awaitingActionInput))) { + } else if ( + currentMode === actionForNextPrompt.mode + && currentPhase === actionForNextPrompt.phaseTarget + && currentHandler.active + && (!actionForNextPrompt.awaitingActionInput + || (actionForNextPrompt.awaitingActionInput && currentHandler.awaitingActionInput)) + ) { const prompt = this.prompts.shift(); if (prompt?.callback) { prompt.callback(); diff --git a/src/timed-event-manager.ts b/src/timed-event-manager.ts index 9515be7b49ee..b97ccd5bccd5 100644 --- a/src/timed-event-manager.ts +++ b/src/timed-event-manager.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject } from "#app/ui/text"; import { nil } from "#app/utils"; import i18next from "i18next"; @@ -94,9 +94,9 @@ export class TimedEventDisplay extends Phaser.GameObjects.Container { private availableWidth: number; private eventTimer: NodeJS.Timeout | null; - constructor(scene: BattleScene, x: number, y: number, event?: TimedEvent) { - super(scene, x, y); - this.availableWidth = scene.scaledCanvas.width; + constructor(x: number, y: number, event?: TimedEvent) { + super(globalScene, x, y); + this.availableWidth = globalScene.scaledCanvas.width; this.event = event; this.setVisible(false); } @@ -132,14 +132,13 @@ export class TimedEventDisplay extends Phaser.GameObjects.Container { console.log(this.event.bannerKey); const padding = 5; const showTimer = this.event.eventType !== EventType.NO_TIMER_DISPLAY; - const yPosition = this.scene.game.canvas.height / 6 - padding - (showTimer ? 10 : 0) - (this.event.yOffset ?? 0); - this.banner = new Phaser.GameObjects.Image(this.scene, this.availableWidth / 2, yPosition - padding, key); + const yPosition = globalScene.game.canvas.height / 6 - padding - (showTimer ? 10 : 0) - (this.event.yOffset ?? 0); + this.banner = new Phaser.GameObjects.Image(globalScene, this.availableWidth / 2, yPosition - padding, key); this.banner.setName("img-event-banner"); this.banner.setOrigin(0.5, 1); this.banner.setScale(this.event.scale ?? 0.18); if (showTimer) { this.eventTimerText = addTextObject( - this.scene, this.banner.x, this.banner.y + 2, this.timeToGo(this.event.endDate), diff --git a/src/touch-controls.ts b/src/touch-controls.ts index 93032ce59fe0..db2ae223d3f1 100644 --- a/src/touch-controls.ts +++ b/src/touch-controls.ts @@ -1,6 +1,6 @@ +import { globalScene } from "#app/global-scene"; import { Button } from "#enums/buttons"; import EventEmitter = Phaser.Events.EventEmitter; -import BattleScene from "./battle-scene"; const repeatInputDelayMillis = 250; @@ -13,8 +13,8 @@ export default class TouchControl { /** Whether the last touch event has finished before disabling */ private finishedLastTouch: boolean = false; - constructor(scene: BattleScene) { - this.events = scene.game.events; + constructor() { + this.events = globalScene.game.events; this.init(); } diff --git a/src/tutorial.ts b/src/tutorial.ts index 3934ffee57f9..5d02b8a01933 100644 --- a/src/tutorial.ts +++ b/src/tutorial.ts @@ -1,4 +1,4 @@ -import BattleScene from "./battle-scene"; +import { globalScene } from "#app/global-scene"; import AwaitableUiHandler from "./ui/awaitable-ui-handler"; import UiHandler from "./ui/ui-handler"; import { Mode } from "./ui/ui"; @@ -17,50 +17,50 @@ export enum Tutorial { } const tutorialHandlers = { - [Tutorial.Intro]: (scene: BattleScene) => { + [Tutorial.Intro]: () => { return new Promise(resolve => { - scene.ui.showText(i18next.t("tutorial:intro"), null, () => resolve(), null, true); + globalScene.ui.showText(i18next.t("tutorial:intro"), null, () => resolve(), null, true); }); }, - [Tutorial.Access_Menu]: (scene: BattleScene) => { + [Tutorial.Access_Menu]: () => { return new Promise(resolve => { - if (scene.enableTouchControls) { + if (globalScene.enableTouchControls) { return resolve(); } - scene.showFieldOverlay(1000).then(() => scene.ui.showText(i18next.t("tutorial:accessMenu"), null, () => scene.hideFieldOverlay(1000).then(() => resolve()), null, true)); + globalScene.showFieldOverlay(1000).then(() => globalScene.ui.showText(i18next.t("tutorial:accessMenu"), null, () => globalScene.hideFieldOverlay(1000).then(() => resolve()), null, true)); }); }, - [Tutorial.Menu]: (scene: BattleScene) => { + [Tutorial.Menu]: () => { return new Promise(resolve => { - scene.gameData.saveTutorialFlag(Tutorial.Access_Menu, true); - scene.ui.showText(i18next.t("tutorial:menu"), null, () => scene.ui.showText("", null, () => resolve()), null, true); + globalScene.gameData.saveTutorialFlag(Tutorial.Access_Menu, true); + globalScene.ui.showText(i18next.t("tutorial:menu"), null, () => globalScene.ui.showText("", null, () => resolve()), null, true); }); }, - [Tutorial.Starter_Select]: (scene: BattleScene) => { + [Tutorial.Starter_Select]: () => { return new Promise(resolve => { - scene.ui.showText(i18next.t("tutorial:starterSelect"), null, () => scene.ui.showText("", null, () => resolve()), null, true); + globalScene.ui.showText(i18next.t("tutorial:starterSelect"), null, () => globalScene.ui.showText("", null, () => resolve()), null, true); }); }, - [Tutorial.Pokerus]: (scene: BattleScene) => { + [Tutorial.Pokerus]: () => { return new Promise(resolve => { - scene.ui.showText(i18next.t("tutorial:pokerus"), null, () => scene.ui.showText("", null, () => resolve()), null, true); + globalScene.ui.showText(i18next.t("tutorial:pokerus"), null, () => globalScene.ui.showText("", null, () => resolve()), null, true); }); }, - [Tutorial.Stat_Change]: (scene: BattleScene) => { + [Tutorial.Stat_Change]: () => { return new Promise(resolve => { - scene.showFieldOverlay(1000).then(() => scene.ui.showText(i18next.t("tutorial:statChange"), null, () => scene.ui.showText("", null, () => scene.hideFieldOverlay(1000).then(() => resolve())), null, true)); + globalScene.showFieldOverlay(1000).then(() => globalScene.ui.showText(i18next.t("tutorial:statChange"), null, () => globalScene.ui.showText("", null, () => globalScene.hideFieldOverlay(1000).then(() => resolve())), null, true)); }); }, - [Tutorial.Select_Item]: (scene: BattleScene) => { + [Tutorial.Select_Item]: () => { return new Promise(resolve => { - scene.ui.setModeWithoutClear(Mode.MESSAGE).then(() => { - scene.ui.showText(i18next.t("tutorial:selectItem"), null, () => scene.ui.showText("", null, () => scene.ui.setModeWithoutClear(Mode.MODIFIER_SELECT).then(() => resolve())), null, true); + globalScene.ui.setModeWithoutClear(Mode.MESSAGE).then(() => { + globalScene.ui.showText(i18next.t("tutorial:selectItem"), null, () => globalScene.ui.showText("", null, () => globalScene.ui.setModeWithoutClear(Mode.MODIFIER_SELECT).then(() => resolve())), null, true); }); }); }, - [Tutorial.Egg_Gacha]: (scene: BattleScene) => { + [Tutorial.Egg_Gacha]: () => { return new Promise(resolve => { - scene.ui.showText(i18next.t("tutorial:eggGacha"), null, () => scene.ui.showText("", null, () => resolve()), null, true); + globalScene.ui.showText(i18next.t("tutorial:eggGacha"), null, () => globalScene.ui.showText("", null, () => resolve()), null, true); }); }, }; @@ -69,35 +69,34 @@ const tutorialHandlers = { * Run through the specified tutorial if it hasn't been seen before and mark it as seen once done * This will show a tutorial overlay if defined in the current {@linkcode AwaitableUiHandler} * The main menu will also get disabled while the tutorial is running - * @param scene the current {@linkcode BattleScene} * @param tutorial the {@linkcode Tutorial} to play * @returns a promise with result `true` if the tutorial was run and finished, `false` otherwise */ -export async function handleTutorial(scene: BattleScene, tutorial: Tutorial): Promise { - if (!scene.enableTutorials && !Overrides.BYPASS_TUTORIAL_SKIP_OVERRIDE) { +export async function handleTutorial(tutorial: Tutorial): Promise { + if (!globalScene.enableTutorials && !Overrides.BYPASS_TUTORIAL_SKIP_OVERRIDE) { return false; } - if (scene.gameData.getTutorialFlags()[tutorial] && !Overrides.BYPASS_TUTORIAL_SKIP_OVERRIDE) { + if (globalScene.gameData.getTutorialFlags()[tutorial] && !Overrides.BYPASS_TUTORIAL_SKIP_OVERRIDE) { return false; } - const handler = scene.ui.getHandler(); - const isMenuDisabled = scene.disableMenu; + const handler = globalScene.ui.getHandler(); + const isMenuDisabled = globalScene.disableMenu; // starting tutorial, disable menu - scene.disableMenu = true; + globalScene.disableMenu = true; if (handler instanceof AwaitableUiHandler) { handler.tutorialActive = true; } - await showTutorialOverlay(scene, handler); - await tutorialHandlers[tutorial](scene); - await hideTutorialOverlay(scene, handler); + await showTutorialOverlay(handler); + await tutorialHandlers[tutorial](); + await hideTutorialOverlay(handler); // tutorial finished and overlay gone, re-enable menu, save tutorial as seen - scene.disableMenu = isMenuDisabled; - scene.gameData.saveTutorialFlag(tutorial, true); + globalScene.disableMenu = isMenuDisabled; + globalScene.gameData.saveTutorialFlag(tutorial, true); if (handler instanceof AwaitableUiHandler) { handler.tutorialActive = false; } @@ -107,13 +106,12 @@ export async function handleTutorial(scene: BattleScene, tutorial: Tutorial): Pr /** * Show the tutorial overlay if there is one - * @param scene the current BattleScene * @param handler the current UiHandler * @returns `true` once the overlay has finished appearing, or if there is no overlay */ -async function showTutorialOverlay(scene: BattleScene, handler: UiHandler) { +async function showTutorialOverlay(handler: UiHandler) { if (handler instanceof AwaitableUiHandler && handler.tutorialOverlay) { - scene.tweens.add({ + globalScene.tweens.add({ targets: handler.tutorialOverlay, alpha: 0.5, duration: 750, @@ -129,13 +127,12 @@ async function showTutorialOverlay(scene: BattleScene, handler: UiHandler) { /** * Hide the tutorial overlay if there is one - * @param scene the current BattleScene * @param handler the current UiHandler * @returns `true` once the overlay has finished disappearing, or if there is no overlay */ -async function hideTutorialOverlay(scene: BattleScene, handler: UiHandler) { +async function hideTutorialOverlay(handler: UiHandler) { if (handler instanceof AwaitableUiHandler && handler.tutorialOverlay) { - scene.tweens.add({ + globalScene.tweens.add({ targets: handler.tutorialOverlay, alpha: 0, duration: 500, diff --git a/src/ui-inputs.ts b/src/ui-inputs.ts index 92b1653df3de..84c029b90d3e 100644 --- a/src/ui-inputs.ts +++ b/src/ui-inputs.ts @@ -8,7 +8,7 @@ import SettingsUiHandler from "./ui/settings/settings-ui-handler"; import { Button } from "#enums/buttons"; import SettingsGamepadUiHandler from "./ui/settings/settings-gamepad-ui-handler"; import SettingsKeyboardUiHandler from "#app/ui/settings/settings-keyboard-ui-handler"; -import BattleScene from "./battle-scene"; +import { globalScene } from "#app/global-scene"; import SettingsDisplayUiHandler from "./ui/settings/settings-display-ui-handler"; import SettingsAudioUiHandler from "./ui/settings/settings-audio-ui-handler"; import RunInfoUiHandler from "./ui/run-info-ui-handler"; @@ -16,12 +16,10 @@ import RunInfoUiHandler from "./ui/run-info-ui-handler"; type ActionKeys = Record void>; export class UiInputs { - private scene: BattleScene; private events: Phaser.Events.EventEmitter; private inputsController: InputsController; - constructor(scene: BattleScene, inputsController: InputsController) { - this.scene = scene; + constructor(inputsController: InputsController) { this.inputsController = inputsController; this.init(); } @@ -35,12 +33,12 @@ export class UiInputs { if (evt.controller_type === "keyboard") { //if the touch property is present and defined, then this is a simulated keyboard event from the touch screen if (evt.hasOwnProperty("isTouch") && evt.isTouch) { - this.scene.inputMethod = "touch"; + globalScene.inputMethod = "touch"; } else { - this.scene.inputMethod = "keyboard"; + globalScene.inputMethod = "keyboard"; } } else if (evt.controller_type === "gamepad") { - this.scene.inputMethod = "gamepad"; + globalScene.inputMethod = "gamepad"; } } @@ -65,7 +63,7 @@ export class UiInputs { } doVibration(inputSuccess: boolean, vibrationLength: number): void { - if (inputSuccess && this.scene.enableVibration && typeof navigator.vibrate !== "undefined") { + if (inputSuccess && globalScene.enableVibration && typeof navigator.vibrate !== "undefined") { navigator.vibrate(vibrationLength); } } @@ -117,59 +115,59 @@ export class UiInputs { } buttonDirection(direction: Button): void { - const inputSuccess = this.scene.ui.processInput(direction); + const inputSuccess = globalScene.ui.processInput(direction); const vibrationLength = 5; this.doVibration(inputSuccess, vibrationLength); } buttonAb(button: Button): void { - this.scene.ui.processInput(button); + globalScene.ui.processInput(button); } buttonTouch(): void { - this.scene.ui.processInput(Button.SUBMIT) || this.scene.ui.processInput(Button.ACTION); + globalScene.ui.processInput(Button.SUBMIT) || globalScene.ui.processInput(Button.ACTION); } buttonStats(pressed: boolean = true): void { // allow access to Button.STATS as a toggle for other elements - for (const t of this.scene.getInfoToggles(true)) { + for (const t of globalScene.getInfoToggles(true)) { t.toggleInfo(pressed); } // handle normal pokemon battle ui - for (const p of this.scene.getField().filter(p => p?.isActive(true))) { + for (const p of globalScene.getField().filter(p => p?.isActive(true))) { p.toggleStats(pressed); } } buttonGoToFilter(button: Button): void { const whitelist = [ StarterSelectUiHandler ]; - const uiHandler = this.scene.ui?.getHandler(); + const uiHandler = globalScene.ui?.getHandler(); if (whitelist.some(handler => uiHandler instanceof handler)) { - this.scene.ui.processInput(button); + globalScene.ui.processInput(button); } else { this.buttonStats(true); } } buttonInfo(pressed: boolean = true): void { - if (this.scene.showMovesetFlyout ) { - for (const p of this.scene.getField().filter(p => p?.isActive(true))) { + if (globalScene.showMovesetFlyout ) { + for (const p of globalScene.getField().filter(p => p?.isActive(true))) { p.toggleFlyout(pressed); } } - if (this.scene.showArenaFlyout) { - this.scene.ui.processInfoButton(pressed); + if (globalScene.showArenaFlyout) { + globalScene.ui.processInfoButton(pressed); } } buttonMenu(): void { - if (this.scene.disableMenu) { + if (globalScene.disableMenu) { return; } - switch (this.scene.ui?.getMode()) { + switch (globalScene.ui?.getMode()) { case Mode.MESSAGE: - const messageHandler = this.scene.ui.getHandler(); + const messageHandler = globalScene.ui.getHandler(); if (!messageHandler.pendingPrompt || messageHandler.isTextAnimationInProgress()) { return; } @@ -177,14 +175,14 @@ export class UiInputs { case Mode.COMMAND: case Mode.MODIFIER_SELECT: case Mode.MYSTERY_ENCOUNTER: - this.scene.ui.setOverlayMode(Mode.MENU); + globalScene.ui.setOverlayMode(Mode.MENU); break; case Mode.STARTER_SELECT: this.buttonTouch(); break; case Mode.MENU: - this.scene.ui.revertMode(); - this.scene.playSound("ui/select"); + globalScene.ui.revertMode(); + globalScene.playSound("ui/select"); break; default: return; @@ -193,9 +191,9 @@ export class UiInputs { buttonCycleOption(button: Button): void { const whitelist = [ StarterSelectUiHandler, SettingsUiHandler, RunInfoUiHandler, SettingsDisplayUiHandler, SettingsAudioUiHandler, SettingsGamepadUiHandler, SettingsKeyboardUiHandler ]; - const uiHandler = this.scene.ui?.getHandler(); + const uiHandler = globalScene.ui?.getHandler(); if (whitelist.some(handler => uiHandler instanceof handler)) { - this.scene.ui.processInput(button); + globalScene.ui.processInput(button); } else if (button === Button.V) { this.buttonInfo(true); } @@ -203,15 +201,15 @@ export class UiInputs { buttonSpeedChange(up = true): void { const settingGameSpeed = settingIndex(SettingKeys.Game_Speed); - if (up && this.scene.gameSpeed < 5) { - this.scene.gameData.saveSetting(SettingKeys.Game_Speed, Setting[settingGameSpeed].options.findIndex((item) => item.label === `${this.scene.gameSpeed}x`) + 1); - if (this.scene.ui?.getMode() === Mode.SETTINGS) { - (this.scene.ui.getHandler() as SettingsUiHandler).show([]); + if (up && globalScene.gameSpeed < 5) { + globalScene.gameData.saveSetting(SettingKeys.Game_Speed, Setting[settingGameSpeed].options.findIndex((item) => item.label === `${globalScene.gameSpeed}x`) + 1); + if (globalScene.ui?.getMode() === Mode.SETTINGS) { + (globalScene.ui.getHandler() as SettingsUiHandler).show([]); } - } else if (!up && this.scene.gameSpeed > 1) { - this.scene.gameData.saveSetting(SettingKeys.Game_Speed, Math.max(Setting[settingGameSpeed].options.findIndex((item) => item.label === `${this.scene.gameSpeed}x`) - 1, 0)); - if (this.scene.ui?.getMode() === Mode.SETTINGS) { - (this.scene.ui.getHandler() as SettingsUiHandler).show([]); + } else if (!up && globalScene.gameSpeed > 1) { + globalScene.gameData.saveSetting(SettingKeys.Game_Speed, Math.max(Setting[settingGameSpeed].options.findIndex((item) => item.label === `${globalScene.gameSpeed}x`) - 1, 0)); + if (globalScene.ui?.getMode() === Mode.SETTINGS) { + (globalScene.ui.getHandler() as SettingsUiHandler).show([]); } } } diff --git a/src/ui/ability-bar.ts b/src/ui/ability-bar.ts index a924d5458527..5b1e31a61614 100644 --- a/src/ui/ability-bar.ts +++ b/src/ui/ability-bar.ts @@ -1,5 +1,5 @@ import { getPokemonNameWithAffix } from "#app/messages"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import Pokemon from "../field/pokemon"; import { TextStyle, addTextObject } from "./text"; import i18next from "i18next"; @@ -17,17 +17,17 @@ export default class AbilityBar extends Phaser.GameObjects.Container { public shown: boolean; - constructor(scene: BattleScene) { - super(scene, hiddenX, baseY); + constructor() { + super(globalScene, hiddenX, baseY); } setup(): void { - this.bg = this.scene.add.image(0, 0, "ability_bar_left"); + this.bg = globalScene.add.image(0, 0, "ability_bar_left"); this.bg.setOrigin(0, 0); this.add(this.bg); - this.abilityBarText = addTextObject(this.scene, 15, 3, "", TextStyle.MESSAGE, { fontSize: "72px" }); + this.abilityBarText = addTextObject(15, 3, "", TextStyle.MESSAGE, { fontSize: "72px" }); this.abilityBarText.setOrigin(0, 0); this.abilityBarText.setWordWrapWidth(600, true); this.add(this.abilityBarText); @@ -43,11 +43,11 @@ export default class AbilityBar extends Phaser.GameObjects.Container { return; } - (this.scene as BattleScene).fieldUI.bringToTop(this); + globalScene.fieldUI.bringToTop(this); - this.y = baseY + ((this.scene as BattleScene).currentBattle.double ? 14 : 0); - this.tween = this.scene.tweens.add({ + this.y = baseY + (globalScene.currentBattle.double ? 14 : 0); + this.tween = globalScene.tweens.add({ targets: this, x: shownX, duration: 500, @@ -75,7 +75,7 @@ export default class AbilityBar extends Phaser.GameObjects.Container { this.tween.stop(); } - this.tween = this.scene.tweens.add({ + this.tween = globalScene.tweens.add({ targets: this, x: -91, duration: 500, diff --git a/src/ui/abstact-option-select-ui-handler.ts b/src/ui/abstact-option-select-ui-handler.ts index 01fc5b000143..df592fc45b10 100644 --- a/src/ui/abstact-option-select-ui-handler.ts +++ b/src/ui/abstact-option-select-ui-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject, getTextStyleOptions } from "./text"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; @@ -46,8 +46,8 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { private cursorObj: Phaser.GameObjects.Image | null; - constructor(scene: BattleScene, mode: Mode | null) { - super(scene, mode); + constructor(mode: Mode | null) { + super(mode); } abstract getWindowWidth(): integer; @@ -59,19 +59,19 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { setup() { const ui = this.getUi(); - this.optionSelectContainer = this.scene.add.container((this.scene.game.canvas.width / 6) - 1, -48); + this.optionSelectContainer = globalScene.add.container((globalScene.game.canvas.width / 6) - 1, -48); this.optionSelectContainer.setName(`option-select-${this.mode ? Mode[this.mode] : "UNKNOWN"}`); this.optionSelectContainer.setVisible(false); ui.add(this.optionSelectContainer); - this.optionSelectBg = addWindow(this.scene, 0, 0, this.getWindowWidth(), this.getWindowHeight()); + this.optionSelectBg = addWindow(0, 0, this.getWindowWidth(), this.getWindowHeight()); this.optionSelectBg.setName("option-select-bg"); this.optionSelectBg.setOrigin(1, 1); this.optionSelectContainer.add(this.optionSelectBg); this.optionSelectIcons = []; - this.scale = getTextStyleOptions(TextStyle.WINDOW, (this.scene as BattleScene).uiTheme).scale; + this.scale = getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale; this.setCursor(0); } @@ -84,7 +84,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { // for performance reasons, this limits how many options we can see at once. Without this, it would try to make text options for every single options // which makes the performance take a hit. If there's not enough options to do this (set to 10 at the moment) and the ui mode !== Mode.AUTO_COMPLETE, // this is ignored and the original code is untouched, with the options array being all the options from the config - if (configOptions.length >= 10 && this.scene.ui.getMode() === Mode.AUTO_COMPLETE) { + if (configOptions.length >= 10 && globalScene.ui.getMode() === Mode.AUTO_COMPLETE) { const optionsScrollTotal = configOptions.length; const optionStartIndex = this.scrollCursor; const optionEndIndex = Math.min(optionsScrollTotal, optionStartIndex + (!optionStartIndex || this.scrollCursor + (this.config?.maxOptions! - 1) >= optionsScrollTotal ? this.config?.maxOptions! - 1 : this.config?.maxOptions! - 2)); @@ -101,12 +101,12 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { this.optionSelectIcons.splice(0, this.optionSelectIcons.length); } - this.optionSelectText = addTextObject(this.scene, 0, 0, options.map(o => o.item ? ` ${o.label}` : o.label).join("\n"), TextStyle.WINDOW, { maxLines: options.length }); + this.optionSelectText = addTextObject(0, 0, options.map(o => o.item ? ` ${o.label}` : o.label).join("\n"), TextStyle.WINDOW, { maxLines: options.length }); this.optionSelectText.setLineSpacing(this.scale * 72); this.optionSelectText.setName("text-option-select"); this.optionSelectText.setLineSpacing(12); this.optionSelectContainer.add(this.optionSelectText); - this.optionSelectContainer.setPosition((this.scene.game.canvas.width / 6) - 1 - (this.config?.xOffset || 0), -48 + (this.config?.yOffset || 0)); + this.optionSelectContainer.setPosition((globalScene.game.canvas.width / 6) - 1 - (this.config?.xOffset || 0), -48 + (this.config?.yOffset || 0)); this.optionSelectBg.width = Math.max(this.optionSelectText.displayWidth + 24, this.getWindowWidth()); @@ -120,7 +120,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { options.forEach((option: OptionSelectItem, i: integer) => { if (option.item) { - const itemIcon = this.scene.add.sprite(0, 0, "items", option.item); + const itemIcon = globalScene.add.sprite(0, 0, "items", option.item); itemIcon.setScale(3 * this.scale); this.optionSelectIcons.push(itemIcon); @@ -129,7 +129,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { itemIcon.setPositionRelative(this.optionSelectText, 36 * this.scale, 7 + i * (114 * this.scale - 3)); if (option.item === "candy") { - const itemOverlayIcon = this.scene.add.sprite(0, 0, "items", "candy_overlay"); + const itemOverlayIcon = globalScene.add.sprite(0, 0, "items", "candy_overlay"); itemOverlayIcon.setScale(3 * this.scale); this.optionSelectIcons.push(itemOverlayIcon); @@ -156,7 +156,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { this.config = args[0] as OptionSelectConfig; this.setupOptions(); - this.scene.ui.bringToTop(this.optionSelectContainer); + globalScene.ui.bringToTop(this.optionSelectContainer); this.optionSelectContainer.setVisible(true); this.scrollCursor = 0; @@ -166,7 +166,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { this.blockInput = true; this.optionSelectText.setAlpha(0.5); this.cursorObj?.setAlpha(0.8); - this.scene.time.delayedCall(Utils.fixedInt(this.config.delay), () => this.unblockInput()); + globalScene.time.delayedCall(Utils.fixedInt(this.config.delay), () => this.unblockInput()); } return true; @@ -332,7 +332,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler { } if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.optionSelectContainer.add(this.cursorObj); } diff --git a/src/ui/achv-bar.ts b/src/ui/achv-bar.ts index 6e7b3185024d..94b36429d98d 100644 --- a/src/ui/achv-bar.ts +++ b/src/ui/achv-bar.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { Achv, getAchievementDescription } from "../system/achv"; import { Voucher } from "../system/voucher"; import { TextStyle, addTextObject } from "./text"; @@ -19,33 +19,33 @@ export default class AchvBar extends Phaser.GameObjects.Container { public shown: boolean; - constructor(scene: BattleScene) { - super(scene, scene.game.canvas.width / 6, 0); - this.playerGender = scene.gameData.gender; + constructor() { + super(globalScene, globalScene.game.canvas.width / 6, 0); + this.playerGender = globalScene.gameData.gender; } setup(): void { this.defaultWidth = 200; this.defaultHeight = 40; - this.bg = this.scene.add.nineslice(0, 0, "achv_bar", undefined, this.defaultWidth, this.defaultHeight, 41, 6, 16, 4); + this.bg = globalScene.add.nineslice(0, 0, "achv_bar", undefined, this.defaultWidth, this.defaultHeight, 41, 6, 16, 4); this.bg.setOrigin(0, 0); this.add(this.bg); - this.icon = this.scene.add.sprite(4, 4, "items"); + this.icon = globalScene.add.sprite(4, 4, "items"); this.icon.setOrigin(0, 0); this.add(this.icon); - this.titleText = addTextObject(this.scene, 40, 3, "", TextStyle.MESSAGE, { fontSize: "72px" }); + this.titleText = addTextObject(40, 3, "", TextStyle.MESSAGE, { fontSize: "72px" }); this.titleText.setOrigin(0, 0); this.add(this.titleText); - this.scoreText = addTextObject(this.scene, 150, 3, "", TextStyle.MESSAGE, { fontSize: "72px" }); + this.scoreText = addTextObject(150, 3, "", TextStyle.MESSAGE, { fontSize: "72px" }); this.scoreText.setOrigin(1, 0); this.add(this.scoreText); - this.descriptionText = addTextObject(this.scene, 43, 16, "", TextStyle.WINDOW_ALT, { fontSize: "72px" }); + this.descriptionText = addTextObject(43, 16, "", TextStyle.WINDOW_ALT, { fontSize: "72px" }); this.descriptionText.setOrigin(0, 0); this.add(this.descriptionText); @@ -90,16 +90,16 @@ export default class AchvBar extends Phaser.GameObjects.Container { this.bg.height = Math.max(this.defaultHeight, this.titleText.displayHeight + this.descriptionText.displayHeight + 8); this.icon.y = (this.bg.height / 2) - (this.icon.height / 2); - (this.scene as BattleScene).playSound("se/achv"); + globalScene.playSound("se/achv"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6) - (this.bg.width / 2), + x: (globalScene.game.canvas.width / 6) - (this.bg.width / 2), duration: 500, ease: "Sine.easeOut" }); - this.scene.time.delayedCall(10000, () => this.hide(this.playerGender)); + globalScene.time.delayedCall(10000, () => this.hide(this.playerGender)); this.setVisible(true); this.shown = true; @@ -110,9 +110,9 @@ export default class AchvBar extends Phaser.GameObjects.Container { return; } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6), + x: (globalScene.game.canvas.width / 6), duration: 500, ease: "Sine.easeIn", onComplete: () => { diff --git a/src/ui/achvs-ui-handler.ts b/src/ui/achvs-ui-handler.ts index a1ced6145ebc..549c5bca2d13 100644 --- a/src/ui/achvs-ui-handler.ts +++ b/src/ui/achvs-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { Button } from "#enums/buttons"; import i18next from "i18next"; import { Achv, achvs, getAchievementDescription } from "#app/system/achv"; @@ -9,6 +8,7 @@ import { Mode } from "#app/ui/ui"; import { addWindow } from "#app/ui/ui-theme"; import { ScrollBar } from "#app/ui/scroll-bar"; import { PlayerGender } from "#enums/player-gender"; +import { globalScene } from "#app/global-scene"; enum Page { ACHIEVEMENTS, @@ -57,8 +57,8 @@ export default class AchvsUiHandler extends MessageUiHandler { private cursorObj: Phaser.GameObjects.NineSlice | null; private currentPage: Page; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.achvsTotal = Object.keys(achvs).length; this.vouchersTotal = Object.keys(vouchers).length; @@ -68,37 +68,37 @@ export default class AchvsUiHandler extends MessageUiHandler { setup() { const ui = this.getUi(); - this.mainContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1); + this.mainContainer = globalScene.add.container(1, -(globalScene.game.canvas.height / 6) + 1); - this.mainContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.mainContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); - this.headerBg = addWindow(this.scene, 0, 0, (this.scene.game.canvas.width / 6) - 2, 24); + this.headerBg = addWindow(0, 0, (globalScene.game.canvas.width / 6) - 2, 24); this.headerBg.setOrigin(0, 0); - this.headerText = addTextObject(this.scene, 0, 0, "", TextStyle.SETTINGS_LABEL); + this.headerText = addTextObject(0, 0, "", TextStyle.SETTINGS_LABEL); this.headerText.setOrigin(0, 0); this.headerText.setPositionRelative(this.headerBg, 8, 4); - this.headerActionButton = new Phaser.GameObjects.Sprite(this.scene, 0, 0, "keyboard", "ACTION.png"); + this.headerActionButton = new Phaser.GameObjects.Sprite(globalScene, 0, 0, "keyboard", "ACTION.png"); this.headerActionButton.setOrigin(0, 0); this.headerActionButton.setPositionRelative(this.headerBg, 236, 6); - this.headerActionText = addTextObject(this.scene, 0, 0, "", TextStyle.WINDOW, { fontSize:"60px" }); + this.headerActionText = addTextObject(0, 0, "", TextStyle.WINDOW, { fontSize:"60px" }); this.headerActionText.setOrigin(0, 0); this.headerActionText.setPositionRelative(this.headerBg, 264, 8); // We need to get the player gender from the game data to add the correct prefix to the achievement name - const genderIndex = this.scene.gameData.gender ?? PlayerGender.MALE; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.MALE; const genderStr = PlayerGender[genderIndex].toLowerCase(); this.achvsName = i18next.t("achv:Achievements.name", { context: genderStr }); this.vouchersName = i18next.t("voucher:vouchers"); - this.iconsBg = addWindow(this.scene, 0, this.headerBg.height, (this.scene.game.canvas.width / 6) - 2, (this.scene.game.canvas.height / 6) - this.headerBg.height - 68); + this.iconsBg = addWindow(0, this.headerBg.height, (globalScene.game.canvas.width / 6) - 2, (globalScene.game.canvas.height / 6) - this.headerBg.height - 68); this.iconsBg.setOrigin(0, 0); const yOffset = 6; - this.scrollBar = new ScrollBar(this.scene, this.iconsBg.width - 9, this.iconsBg.y + yOffset, 4, this.iconsBg.height - yOffset * 2, this.ROWS); + this.scrollBar = new ScrollBar(this.iconsBg.width - 9, this.iconsBg.y + yOffset, 4, this.iconsBg.height - yOffset * 2, this.ROWS); - this.iconsContainer = this.scene.add.container(5, this.headerBg.height + 8); + this.iconsContainer = globalScene.add.container(5, this.headerBg.height + 8); this.icons = []; @@ -106,7 +106,7 @@ export default class AchvsUiHandler extends MessageUiHandler { const x = (a % this.COLS) * 18; const y = Math.floor(a / this.COLS) * 18; - const icon = this.scene.add.sprite(x, y, "items", "unknown"); + const icon = globalScene.add.sprite(x, y, "items", "unknown"); icon.setOrigin(0, 0); icon.setScale(0.5); @@ -114,11 +114,11 @@ export default class AchvsUiHandler extends MessageUiHandler { this.iconsContainer.add(icon); } - const titleBg = addWindow(this.scene, 0, this.headerBg.height + this.iconsBg.height, 174, 24); + const titleBg = addWindow(0, this.headerBg.height + this.iconsBg.height, 174, 24); titleBg.setOrigin(0, 0); this.titleBg = titleBg; - this.titleText = addTextObject(this.scene, 0, 0, "", TextStyle.WINDOW); + this.titleText = addTextObject(0, 0, "", TextStyle.WINDOW); const textSize = languageSettings[i18next.language]?.TextSize ?? this.titleText.style.fontSize; this.titleText.setFontSize(textSize); const titleBgCenterX = titleBg.x + titleBg.width / 2; @@ -126,26 +126,26 @@ export default class AchvsUiHandler extends MessageUiHandler { this.titleText.setOrigin(0.5, 0.5); this.titleText.setPosition(titleBgCenterX, titleBgCenterY); - this.scoreContainer = this.scene.add.container(titleBg.x + titleBg.width, titleBg.y); - const scoreBg = addWindow(this.scene, 0, 0, 46, 24); + this.scoreContainer = globalScene.add.container(titleBg.x + titleBg.width, titleBg.y); + const scoreBg = addWindow(0, 0, 46, 24); scoreBg.setOrigin(0, 0); this.scoreContainer.add(scoreBg); - this.scoreText = addTextObject(this.scene, scoreBg.width / 2, scoreBg.height / 2, "", TextStyle.WINDOW); + this.scoreText = addTextObject(scoreBg.width / 2, scoreBg.height / 2, "", TextStyle.WINDOW); this.scoreText.setOrigin(0.5, 0.5); this.scoreContainer.add(this.scoreText); - const unlockBg = addWindow(this.scene, this.scoreContainer.x + scoreBg.width, titleBg.y, 98, 24); + const unlockBg = addWindow(this.scoreContainer.x + scoreBg.width, titleBg.y, 98, 24); unlockBg.setOrigin(0, 0); - this.unlockText = addTextObject(this.scene, 0, 0, "", TextStyle.WINDOW); + this.unlockText = addTextObject(0, 0, "", TextStyle.WINDOW); this.unlockText.setOrigin(0.5, 0.5); this.unlockText.setPositionRelative(unlockBg, unlockBg.width / 2, unlockBg.height / 2); - const descriptionBg = addWindow(this.scene, 0, titleBg.y + titleBg.height, (this.scene.game.canvas.width / 6) - 2, 42); + const descriptionBg = addWindow(0, titleBg.y + titleBg.height, (globalScene.game.canvas.width / 6) - 2, 42); descriptionBg.setOrigin(0, 0); - const descriptionText = addTextObject(this.scene, 0, 0, "", TextStyle.WINDOW, { maxLines: 2 }); + const descriptionText = addTextObject(0, 0, "", TextStyle.WINDOW, { maxLines: 2 }); descriptionText.setWordWrapWidth(1870); descriptionText.setOrigin(0, 0); descriptionText.setPositionRelative(descriptionBg, 8, 4); @@ -195,12 +195,12 @@ export default class AchvsUiHandler extends MessageUiHandler { protected showAchv(achv: Achv) { // We need to get the player gender from the game data to add the correct prefix to the achievement name - const genderIndex = this.scene.gameData.gender ?? PlayerGender.MALE; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.MALE; const genderStr = PlayerGender[genderIndex].toLowerCase(); achv.name = i18next.t(`achv:${achv.localizationKey}.name`, { context: genderStr }); achv.description = getAchievementDescription(achv.localizationKey); - const achvUnlocks = this.scene.gameData.achvUnlocks; + const achvUnlocks = globalScene.gameData.achvUnlocks; const unlocked = achvUnlocks.hasOwnProperty(achv.id); const hidden = !unlocked && achv.secret && (!achv.parentId || !achvUnlocks.hasOwnProperty(achv.parentId)); this.titleText.setText(unlocked ? achv.name : "???"); @@ -210,7 +210,7 @@ export default class AchvsUiHandler extends MessageUiHandler { } protected showVoucher(voucher: Voucher) { - const voucherUnlocks = this.scene.gameData.voucherUnlocks; + const voucherUnlocks = globalScene.gameData.voucherUnlocks; const unlocked = voucherUnlocks.hasOwnProperty(voucher.id); this.titleText.setText(getVoucherTypeName(voucher.voucherType)); @@ -240,7 +240,7 @@ export default class AchvsUiHandler extends MessageUiHandler { } if (button === Button.CANCEL) { success = true; - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); } else { const rowIndex = Math.floor(this.cursor / this.COLS); const itemOffset = (this.scrollCursor * this.COLS); @@ -306,7 +306,7 @@ export default class AchvsUiHandler extends MessageUiHandler { let update = ret; if (!this.cursorObj) { - this.cursorObj = this.scene.add.nineslice(0, 0, "select_cursor_highlight", undefined, 16, 16, 1, 1, 1, 1); + this.cursorObj = globalScene.add.nineslice(0, 0, "select_cursor_highlight", undefined, 16, 16, 1, 1, 1, 1); this.cursorObj.setOrigin(0, 0); this.iconsContainer.add(this.cursorObj); update = true; @@ -382,7 +382,7 @@ export default class AchvsUiHandler extends MessageUiHandler { this.headerActionText.setX(textPosition); this.headerActionButton.setX(textPosition - this.headerActionButton.displayWidth - 4); - const achvUnlocks = this.scene.gameData.achvUnlocks; + const achvUnlocks = globalScene.gameData.achvUnlocks; const itemOffset = this.scrollCursor * this.COLS; const itemLimit = this.ROWS * this.COLS; @@ -422,7 +422,7 @@ export default class AchvsUiHandler extends MessageUiHandler { this.headerActionText.setX(textPosition); this.headerActionButton.setX(textPosition - this.headerActionButton.displayWidth - 4); - const voucherUnlocks = this.scene.gameData.voucherUnlocks; + const voucherUnlocks = globalScene.gameData.voucherUnlocks; const itemOffset = this.scrollCursor * this.COLS; const itemLimit = this.ROWS * this.COLS; diff --git a/src/ui/admin-ui-handler.ts b/src/ui/admin-ui-handler.ts index 269b5ac5096e..e6da6f4d0d9a 100644 --- a/src/ui/admin-ui-handler.ts +++ b/src/ui/admin-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { Button } from "#app/enums/buttons"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; import { formatText } from "#app/utils"; @@ -6,6 +5,7 @@ import { FormModalUiHandler, InputFieldConfig } from "./form-modal-ui-handler"; import { ModalConfig } from "./modal-ui-handler"; import { TextStyle } from "./text"; import { Mode } from "./ui"; +import { globalScene } from "#app/global-scene"; type AdminUiHandlerService = "discord" | "google"; type AdminUiHandlerServiceMode = "Link" | "Unlink"; @@ -31,8 +31,8 @@ export default class AdminUiHandler extends FormModalUiHandler { return `Username and ${service} successfully ${mode.toLowerCase()}ed`; }; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); } override getModalTitle(): string { @@ -126,10 +126,10 @@ export default class AdminUiHandler extends FormModalUiHandler { const adminSearchResult: AdminSearchInfo = this.convertInputsToAdmin(); // this converts the input texts into a single object for use later const validFields = this.areFieldsValid(this.adminMode); if (validFields.error) { - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error return this.showMessage(validFields.errorMessage ?? "", adminSearchResult, true); } - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); if (this.adminMode === AdminMode.LINK) { this.adminLinkUnlink(adminSearchResult, "discord", "Link") // calls server to link discord .then(response => { @@ -157,11 +157,11 @@ export default class AdminUiHandler extends FormModalUiHandler { } showMessage(message: string, adminResult: AdminSearchInfo, isError: boolean) { - this.scene.ui.setMode(Mode.ADMIN, Object.assign(this.config, { errorMessage: message?.trim() }), this.adminMode, adminResult, isError); + globalScene.ui.setMode(Mode.ADMIN, Object.assign(this.config, { errorMessage: message?.trim() }), this.adminMode, adminResult, isError); if (isError) { - this.scene.ui.playError(); + globalScene.ui.playError(); } else { - this.scene.ui.playSelect(); + globalScene.ui.playSelect(); } } @@ -185,7 +185,7 @@ export default class AdminUiHandler extends FormModalUiHandler { this.inputs[i].setText(adminResult[aR]); if (aR === "discordId" || aR === "googleId") { // this is here to add the icons for linking/unlinking of google/discord IDs const nineSlice = this.inputContainers[i].list.find(iC => iC.type === "NineSlice"); - const img = this.scene.add.image(this.inputContainers[i].x + nineSlice!.width + this.buttonGap, this.inputContainers[i].y + (Math.floor(nineSlice!.height / 2)), adminResult[aR] === "" ? "link_icon" : "unlink_icon"); + const img = globalScene.add.image(this.inputContainers[i].x + nineSlice!.width + this.buttonGap, this.inputContainers[i].y + (Math.floor(nineSlice!.height / 2)), adminResult[aR] === "" ? "link_icon" : "unlink_icon"); img.setName(`adminBtn_${aR}`); img.setOrigin(0.5, 0.5); img.setInteractive(); @@ -194,15 +194,15 @@ export default class AdminUiHandler extends FormModalUiHandler { const mode = adminResult[aR] === "" ? "Link" : "Unlink"; // this figures out if we're linking or unlinking a service const validFields = this.areFieldsValid(this.adminMode, service); if (validFields.error) { - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); // this is here to force a loading screen to allow the admin tool to reopen again if there's an error return this.showMessage(validFields.errorMessage ?? "", adminResult, true); } this.adminLinkUnlink(this.convertInputsToAdmin(), service as AdminUiHandlerService, mode).then(response => { // attempts to link/unlink depending on the service if (response.error) { - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); return this.showMessage(response.errorType, adminResult, true); // fail } else { // success, reload panel with new results - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); this.adminSearch(adminResult) .then(response => { if (response.error) { @@ -340,16 +340,16 @@ export default class AdminUiHandler extends FormModalUiHandler { private updateAdminPanelInfo(adminSearchResult: AdminSearchInfo, mode?: AdminMode) { mode = mode ?? AdminMode.ADMIN; - this.scene.ui.setMode(Mode.ADMIN, { + globalScene.ui.setMode(Mode.ADMIN, { buttonActions: [ // we double revert here and below to go back 2 layers of menus () => { - this.scene.ui.revertMode(); - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); + globalScene.ui.revertMode(); }, () => { - this.scene.ui.revertMode(); - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); + globalScene.ui.revertMode(); } ] }, mode, adminSearchResult); diff --git a/src/ui/arena-flyout.ts b/src/ui/arena-flyout.ts index 573cb85db70c..2ecb8457c16e 100644 --- a/src/ui/arena-flyout.ts +++ b/src/ui/arena-flyout.ts @@ -1,5 +1,5 @@ import { addTextObject, TextStyle } from "./text"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { ArenaTagSide, ArenaTrapTag } from "#app/data/arena-tag"; import { WeatherType } from "#enums/weather-type"; import { TerrainType } from "#app/data/terrain"; @@ -45,9 +45,6 @@ export function getFieldEffectText(arenaTagType: string): string { } export class ArenaFlyout extends Phaser.GameObjects.Container { - /** An alias for the scene typecast to a {@linkcode BattleScene} */ - private battleScene: BattleScene; - /** The restricted width of the flyout which should be drawn to */ private flyoutWidth = 170; /** The restricted height of the flyout which should be drawn to */ @@ -98,62 +95,61 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { private readonly onFieldEffectChangedEvent = (event: Event) => this.onFieldEffectChanged(event); - constructor(scene: Phaser.Scene) { - super(scene, 0, 0); + constructor() { + super(globalScene, 0, 0); this.setName("arena-flyout"); - this.battleScene = this.scene as BattleScene; this.translationX = this.flyoutWidth; this.anchorX = 0; this.anchorY = -98; - this.flyoutParent = this.scene.add.container(this.anchorX - this.translationX, this.anchorY); + this.flyoutParent = globalScene.add.container(this.anchorX - this.translationX, this.anchorY); this.flyoutParent.setAlpha(0); this.add(this.flyoutParent); - this.flyoutContainer = this.scene.add.container(0, 0); + this.flyoutContainer = globalScene.add.container(0, 0); this.flyoutParent.add(this.flyoutContainer); - this.flyoutWindow = addWindow(this.scene as BattleScene, 0, 0, this.flyoutWidth, this.flyoutHeight, false, false, 0, 0, WindowVariant.THIN); + this.flyoutWindow = addWindow(0, 0, this.flyoutWidth, this.flyoutHeight, false, false, 0, 0, WindowVariant.THIN); this.flyoutContainer.add(this.flyoutWindow); - this.flyoutWindowHeader = addWindow(this.scene as BattleScene, this.flyoutWidth / 2, 0, this.flyoutWidth / 2, 14, false, false, 0, 0, WindowVariant.XTHIN); + this.flyoutWindowHeader = addWindow(this.flyoutWidth / 2, 0, this.flyoutWidth / 2, 14, false, false, 0, 0, WindowVariant.XTHIN); this.flyoutWindowHeader.setOrigin(); this.flyoutContainer.add(this.flyoutWindowHeader); - this.flyoutTextHeader = addTextObject(this.scene, this.flyoutWidth / 2, 0, i18next.t("arenaFlyout:activeBattleEffects"), TextStyle.BATTLE_INFO); + this.flyoutTextHeader = addTextObject(this.flyoutWidth / 2, 0, i18next.t("arenaFlyout:activeBattleEffects"), TextStyle.BATTLE_INFO); this.flyoutTextHeader.setFontSize(54); this.flyoutTextHeader.setAlign("center"); this.flyoutTextHeader.setOrigin(); this.flyoutContainer.add(this.flyoutTextHeader); - this.timeOfDayWidget = new TimeOfDayWidget(this.scene, (this.flyoutWidth / 2) + (this.flyoutWindowHeader.displayWidth / 2)); + this.timeOfDayWidget = new TimeOfDayWidget((this.flyoutWidth / 2) + (this.flyoutWindowHeader.displayWidth / 2)); this.flyoutContainer.add(this.timeOfDayWidget); - this.flyoutTextHeaderPlayer = addTextObject(this.scene, 6, 5, i18next.t("arenaFlyout:player"), TextStyle.SUMMARY_BLUE); + this.flyoutTextHeaderPlayer = addTextObject(6, 5, i18next.t("arenaFlyout:player"), TextStyle.SUMMARY_BLUE); this.flyoutTextHeaderPlayer.setFontSize(54); this.flyoutTextHeaderPlayer.setAlign("left"); this.flyoutTextHeaderPlayer.setOrigin(0, 0); this.flyoutContainer.add(this.flyoutTextHeaderPlayer); - this.flyoutTextHeaderField = addTextObject(this.scene, this.flyoutWidth / 2, 5, i18next.t("arenaFlyout:neutral"), TextStyle.SUMMARY_GREEN); + this.flyoutTextHeaderField = addTextObject(this.flyoutWidth / 2, 5, i18next.t("arenaFlyout:neutral"), TextStyle.SUMMARY_GREEN); this.flyoutTextHeaderField.setFontSize(54); this.flyoutTextHeaderField.setAlign("center"); this.flyoutTextHeaderField.setOrigin(0.5, 0); this.flyoutContainer.add(this.flyoutTextHeaderField); - this.flyoutTextHeaderEnemy = addTextObject(this.scene, this.flyoutWidth - 6, 5, i18next.t("arenaFlyout:enemy"), TextStyle.SUMMARY_RED); + this.flyoutTextHeaderEnemy = addTextObject(this.flyoutWidth - 6, 5, i18next.t("arenaFlyout:enemy"), TextStyle.SUMMARY_RED); this.flyoutTextHeaderEnemy.setFontSize(54); this.flyoutTextHeaderEnemy.setAlign("right"); this.flyoutTextHeaderEnemy.setOrigin(1, 0); this.flyoutContainer.add(this.flyoutTextHeaderEnemy); - this.flyoutTextPlayer = addTextObject(this.scene, 6, 13, "", TextStyle.BATTLE_INFO); + this.flyoutTextPlayer = addTextObject(6, 13, "", TextStyle.BATTLE_INFO); this.flyoutTextPlayer.setLineSpacing(-1); this.flyoutTextPlayer.setFontSize(48); this.flyoutTextPlayer.setAlign("left"); @@ -161,7 +157,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { this.flyoutContainer.add(this.flyoutTextPlayer); - this.flyoutTextField = addTextObject(this.scene, this.flyoutWidth / 2, 13, "", TextStyle.BATTLE_INFO); + this.flyoutTextField = addTextObject(this.flyoutWidth / 2, 13, "", TextStyle.BATTLE_INFO); this.flyoutTextField.setLineSpacing(-1); this.flyoutTextField.setFontSize(48); this.flyoutTextField.setAlign("center"); @@ -169,7 +165,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { this.flyoutContainer.add(this.flyoutTextField); - this.flyoutTextEnemy = addTextObject(this.scene, this.flyoutWidth - 6, 13, "", TextStyle.BATTLE_INFO); + this.flyoutTextEnemy = addTextObject(this.flyoutWidth - 6, 13, "", TextStyle.BATTLE_INFO); this.flyoutTextEnemy.setLineSpacing(-1); this.flyoutTextEnemy.setFontSize(48); this.flyoutTextEnemy.setAlign("right"); @@ -181,18 +177,18 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { this.flyoutParent.name = "Fight Flyout Parent"; // Subscribes to required events available on game start - this.battleScene.eventTarget.addEventListener(BattleSceneEventType.NEW_ARENA, this.onNewArenaEvent); - this.battleScene.eventTarget.addEventListener(BattleSceneEventType.TURN_END, this.onTurnEndEvent); + globalScene.eventTarget.addEventListener(BattleSceneEventType.NEW_ARENA, this.onNewArenaEvent); + globalScene.eventTarget.addEventListener(BattleSceneEventType.TURN_END, this.onTurnEndEvent); } private onNewArena(event: Event) { this.fieldEffectInfo.length = 0; // Subscribes to required events available on battle start - this.battleScene.arena.eventTarget.addEventListener(ArenaEventType.WEATHER_CHANGED, this.onFieldEffectChangedEvent); - this.battleScene.arena.eventTarget.addEventListener(ArenaEventType.TERRAIN_CHANGED, this.onFieldEffectChangedEvent); - this.battleScene.arena.eventTarget.addEventListener(ArenaEventType.TAG_ADDED, this.onFieldEffectChangedEvent); - this.battleScene.arena.eventTarget.addEventListener(ArenaEventType.TAG_REMOVED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.addEventListener(ArenaEventType.WEATHER_CHANGED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.addEventListener(ArenaEventType.TERRAIN_CHANGED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.addEventListener(ArenaEventType.TAG_ADDED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.addEventListener(ArenaEventType.TAG_REMOVED, this.onFieldEffectChangedEvent); } @@ -255,7 +251,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { switch (arenaEffectChangedEvent.constructor) { case TagAddedEvent: const tagAddedEvent = arenaEffectChangedEvent as TagAddedEvent; - const isArenaTrapTag = this.battleScene.arena.getTag(tagAddedEvent.arenaTagType) instanceof ArenaTrapTag; + const isArenaTrapTag = globalScene.arena.getTag(tagAddedEvent.arenaTagType) instanceof ArenaTrapTag; let arenaEffectType: ArenaEffectType; if (tagAddedEvent.arenaTagSide === ArenaTagSide.BOTH) { @@ -367,7 +363,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { * @param visible Should the flyout be shown? */ public toggleFlyout(visible: boolean): void { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.flyoutParent, x: visible ? this.anchorX : this.anchorX - this.translationX, duration: Utils.fixedInt(125), @@ -378,13 +374,13 @@ export class ArenaFlyout extends Phaser.GameObjects.Container { } public destroy(fromScene?: boolean): void { - this.battleScene.eventTarget.removeEventListener(BattleSceneEventType.NEW_ARENA, this.onNewArenaEvent); - this.battleScene.eventTarget.removeEventListener(BattleSceneEventType.TURN_END, this.onTurnEndEvent); + globalScene.eventTarget.removeEventListener(BattleSceneEventType.NEW_ARENA, this.onNewArenaEvent); + globalScene.eventTarget.removeEventListener(BattleSceneEventType.TURN_END, this.onTurnEndEvent); - this.battleScene.arena.eventTarget.removeEventListener(ArenaEventType.WEATHER_CHANGED, this.onFieldEffectChangedEvent); - this.battleScene.arena.eventTarget.removeEventListener(ArenaEventType.TERRAIN_CHANGED, this.onFieldEffectChangedEvent); - this.battleScene.arena.eventTarget.removeEventListener(ArenaEventType.TAG_ADDED, this.onFieldEffectChangedEvent); - this.battleScene.arena.eventTarget.removeEventListener(ArenaEventType.TAG_REMOVED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.removeEventListener(ArenaEventType.WEATHER_CHANGED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.removeEventListener(ArenaEventType.TERRAIN_CHANGED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.removeEventListener(ArenaEventType.TAG_ADDED, this.onFieldEffectChangedEvent); + globalScene.arena.eventTarget.removeEventListener(ArenaEventType.TAG_REMOVED, this.onFieldEffectChangedEvent); super.destroy(fromScene); } diff --git a/src/ui/autocomplete-ui-handler.ts b/src/ui/autocomplete-ui-handler.ts index 480a3cf72d0f..8754e65db77b 100644 --- a/src/ui/autocomplete-ui-handler.ts +++ b/src/ui/autocomplete-ui-handler.ts @@ -1,12 +1,11 @@ import { Button } from "#enums/buttons"; -import BattleScene from "../battle-scene"; import AbstractOptionSelectUiHandler from "./abstact-option-select-ui-handler"; import { Mode } from "./ui"; export default class AutoCompleteUiHandler extends AbstractOptionSelectUiHandler { modalContainer: Phaser.GameObjects.Container; - constructor(scene: BattleScene, mode: Mode = Mode.OPTION_SELECT) { - super(scene, mode); + constructor(mode: Mode = Mode.OPTION_SELECT) { + super(mode); } getWindowWidth(): integer { diff --git a/src/ui/awaitable-ui-handler.ts b/src/ui/awaitable-ui-handler.ts index 8256f938106e..63b0dac9d1b4 100644 --- a/src/ui/awaitable-ui-handler.ts +++ b/src/ui/awaitable-ui-handler.ts @@ -1,7 +1,7 @@ -import BattleScene from "../battle-scene"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; import { Button } from "#enums/buttons"; +import { globalScene } from "#app/global-scene"; export default abstract class AwaitableUiHandler extends UiHandler { protected awaitingActionInput: boolean; @@ -9,8 +9,8 @@ export default abstract class AwaitableUiHandler extends UiHandler { public tutorialActive: boolean = false; public tutorialOverlay: Phaser.GameObjects.Rectangle; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); } processTutorialInput(button: Button): boolean { @@ -32,7 +32,7 @@ export default abstract class AwaitableUiHandler extends UiHandler { */ initTutorialOverlay(container: Phaser.GameObjects.Container) { if (!this.tutorialOverlay) { - this.tutorialOverlay = new Phaser.GameObjects.Rectangle(this.scene, -1, -1, this.scene.scaledCanvas.width, this.scene.scaledCanvas.height, 0x070707); + this.tutorialOverlay = new Phaser.GameObjects.Rectangle(globalScene, -1, -1, globalScene.scaledCanvas.width, globalScene.scaledCanvas.height, 0x070707); this.tutorialOverlay.setName("tutorial-overlay"); this.tutorialOverlay.setOrigin(0, 0); this.tutorialOverlay.setAlpha(0); diff --git a/src/ui/ball-ui-handler.ts b/src/ui/ball-ui-handler.ts index 9df6da36055a..420fd7609ae4 100644 --- a/src/ui/ball-ui-handler.ts +++ b/src/ui/ball-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { getPokeballName } from "../data/pokeball"; import { addTextObject, getTextStyleOptions, TextStyle } from "./text"; import { Command } from "./command-ui-handler"; @@ -7,6 +6,7 @@ import UiHandler from "./ui-handler"; import { addWindow } from "./ui-theme"; import { Button } from "#enums/buttons"; import { CommandPhase } from "#app/phases/command-phase"; +import { globalScene } from "#app/global-scene"; export default class BallUiHandler extends UiHandler { private pokeballSelectContainer: Phaser.GameObjects.Container; @@ -17,28 +17,28 @@ export default class BallUiHandler extends UiHandler { private scale: number = 0.1666666667; - constructor(scene: BattleScene) { - super(scene, Mode.BALL); + constructor() { + super(Mode.BALL); } setup() { const ui = this.getUi(); - this.scale = getTextStyleOptions(TextStyle.WINDOW, this.scene.uiTheme).scale; + this.scale = getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale; let optionsTextContent = ""; - for (let pb = 0; pb < Object.keys(this.scene.pokeballCounts).length; pb++) { + for (let pb = 0; pb < Object.keys(globalScene.pokeballCounts).length; pb++) { optionsTextContent += `${getPokeballName(pb)}\n`; } optionsTextContent += "Cancel"; - const optionsText = addTextObject(this.scene, 0, 0, optionsTextContent, TextStyle.WINDOW, { align: "right", maxLines: 6 }); + const optionsText = addTextObject(0, 0, optionsTextContent, TextStyle.WINDOW, { align: "right", maxLines: 6 }); const optionsTextWidth = optionsText.displayWidth; - this.pokeballSelectContainer = this.scene.add.container((this.scene.game.canvas.width / 6) - 51 - Math.max(64, optionsTextWidth), -49); + this.pokeballSelectContainer = globalScene.add.container((globalScene.game.canvas.width / 6) - 51 - Math.max(64, optionsTextWidth), -49); this.pokeballSelectContainer.setVisible(false); ui.add(this.pokeballSelectContainer); - this.pokeballSelectBg = addWindow(this.scene, 0, 0, 50 + Math.max(64, optionsTextWidth), 32 + 480 * this.scale); + this.pokeballSelectBg = addWindow(0, 0, 50 + Math.max(64, optionsTextWidth), 32 + 480 * this.scale); this.pokeballSelectBg.setOrigin(0, 1); this.pokeballSelectContainer.add(this.pokeballSelectBg); this.pokeballSelectContainer.add(optionsText); @@ -46,7 +46,7 @@ export default class BallUiHandler extends UiHandler { optionsText.setPositionRelative(this.pokeballSelectBg, 42, 9); optionsText.setLineSpacing(this.scale * 72); - this.countsText = addTextObject(this.scene, 0, 0, "", TextStyle.WINDOW, { maxLines: 5 }); + this.countsText = addTextObject(0, 0, "", TextStyle.WINDOW, { maxLines: 5 }); this.countsText.setPositionRelative(this.pokeballSelectBg, 18, 9); this.countsText.setLineSpacing(this.scale * 72); this.pokeballSelectContainer.add(this.countsText); @@ -69,16 +69,16 @@ export default class BallUiHandler extends UiHandler { let success = false; - const pokeballTypeCount = Object.keys(this.scene.pokeballCounts).length; + const pokeballTypeCount = Object.keys(globalScene.pokeballCounts).length; if (button === Button.ACTION || button === Button.CANCEL) { - const commandPhase = this.scene.getCurrentPhase() as CommandPhase; + const commandPhase = globalScene.getCurrentPhase() as CommandPhase; success = true; if (button === Button.ACTION && this.cursor < pokeballTypeCount) { - if (this.scene.pokeballCounts[this.cursor]) { + if (globalScene.pokeballCounts[this.cursor]) { if (commandPhase.handleCommand(Command.BALL, this.cursor)) { - this.scene.ui.setMode(Mode.COMMAND, commandPhase.getFieldIndex()); - this.scene.ui.setMode(Mode.MESSAGE); + globalScene.ui.setMode(Mode.COMMAND, commandPhase.getFieldIndex()); + globalScene.ui.setMode(Mode.MESSAGE); success = true; } } else { @@ -107,14 +107,14 @@ export default class BallUiHandler extends UiHandler { } updateCounts() { - this.countsText.setText(Object.values(this.scene.pokeballCounts).map(c => `x${c}`).join("\n")); + this.countsText.setText(Object.values(globalScene.pokeballCounts).map(c => `x${c}`).join("\n")); } setCursor(cursor: integer): boolean { const ret = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.pokeballSelectContainer.add(this.cursorObj); } diff --git a/src/ui/battle-flyout.ts b/src/ui/battle-flyout.ts index 4541a2bfefae..7dc807524e78 100644 --- a/src/ui/battle-flyout.ts +++ b/src/ui/battle-flyout.ts @@ -1,7 +1,7 @@ import { default as Pokemon } from "../field/pokemon"; import { addTextObject, TextStyle } from "./text"; import * as Utils from "../utils"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import Move from "#app/data/move"; import { BattleSceneEventType, BerryUsedEvent, MoveUsedEvent } from "../events/battle-scene"; import { BerryType } from "#enums/berry-type"; @@ -22,9 +22,6 @@ interface MoveInfo { /** A Flyout Menu attached to each {@linkcode BattleInfo} object on the field UI */ export default class BattleFlyout extends Phaser.GameObjects.Container { - /** An alias for the scene typecast to a {@linkcode BattleScene} */ - private battleScene: BattleScene; - /** Is this object linked to a player's Pokemon? */ private player: boolean; @@ -63,9 +60,8 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { private readonly onMoveUsedEvent = (event: Event) => this.onMoveUsed(event); private readonly onBerryUsedEvent = (event: Event) => this.onBerryUsed(event); - constructor(scene: Phaser.Scene, player: boolean) { - super(scene, 0, 0); - this.battleScene = scene as BattleScene; + constructor(player: boolean) { + super(globalScene, 0, 0); // Note that all player based flyouts are disabled. This is included in case of future development this.player = player; @@ -74,23 +70,22 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { this.anchorX = (this.player ? -130 : -40); this.anchorY = -2.5 + (this.player ? -18.5 : -13); - this.flyoutParent = this.scene.add.container(this.anchorX - this.translationX, this.anchorY); + this.flyoutParent = globalScene.add.container(this.anchorX - this.translationX, this.anchorY); this.flyoutParent.setAlpha(0); this.add(this.flyoutParent); // Load the background image - this.flyoutBackground = this.scene.add.sprite(0, 0, "pbinfo_enemy_boss_stats"); + this.flyoutBackground = globalScene.add.sprite(0, 0, "pbinfo_enemy_boss_stats"); this.flyoutBackground.setOrigin(0, 0); this.flyoutParent.add(this.flyoutBackground); - this.flyoutContainer = this.scene.add.container(44 + (this.player ? -this.flyoutWidth : 0), 2); + this.flyoutContainer = globalScene.add.container(44 + (this.player ? -this.flyoutWidth : 0), 2); this.flyoutParent.add(this.flyoutContainer); // Loops through and sets the position of each text object according to the width and height of the flyout for (let i = 0; i < 4; i++) { this.flyoutText[i] = addTextObject( - this.scene, (this.flyoutWidth / 4) + (this.flyoutWidth / 2) * (i % 2), (this.flyoutHeight / 4) + (this.flyoutHeight / 2) * (i < 2 ? 0 : 1), "???", TextStyle.BATTLE_INFO); this.flyoutText[i].setFontSize(45); @@ -102,9 +97,9 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { this.flyoutContainer.add(this.flyoutText); this.flyoutContainer.add( - new Phaser.GameObjects.Rectangle(this.scene, this.flyoutWidth / 2, 0, 1, this.flyoutHeight + (this.battleScene.uiTheme === UiTheme.LEGACY ? 1 : 0), 0x212121).setOrigin(0.5, 0)); + new Phaser.GameObjects.Rectangle(globalScene, this.flyoutWidth / 2, 0, 1, this.flyoutHeight + (globalScene.uiTheme === UiTheme.LEGACY ? 1 : 0), 0x212121).setOrigin(0.5, 0)); this.flyoutContainer.add( - new Phaser.GameObjects.Rectangle(this.scene, 0, this.flyoutHeight / 2, this.flyoutWidth + 6, 1, 0x212121).setOrigin(0, 0.5)); + new Phaser.GameObjects.Rectangle(globalScene, 0, this.flyoutHeight / 2, this.flyoutWidth + 6, 1, 0x212121).setOrigin(0, 0.5)); } /** @@ -117,8 +112,8 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { this.name = `Flyout ${getPokemonNameWithAffix(this.pokemon)}`; this.flyoutParent.name = `Flyout Parent ${getPokemonNameWithAffix(this.pokemon)}`; - this.battleScene.eventTarget.addEventListener(BattleSceneEventType.MOVE_USED, this.onMoveUsedEvent); - this.battleScene.eventTarget.addEventListener(BattleSceneEventType.BERRY_USED, this.onBerryUsedEvent); + globalScene.eventTarget.addEventListener(BattleSceneEventType.MOVE_USED, this.onMoveUsedEvent); + globalScene.eventTarget.addEventListener(BattleSceneEventType.BERRY_USED, this.onBerryUsedEvent); } /** Sets and formats the text property for all {@linkcode Phaser.GameObjects.Text} in the flyoutText array */ @@ -176,7 +171,7 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { toggleFlyout(visible: boolean): void { this.flyoutVisible = visible; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.flyoutParent, x: visible ? this.anchorX : this.anchorX - this.translationX, duration: Utils.fixedInt(125), @@ -186,8 +181,8 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { } destroy(fromScene?: boolean): void { - this.battleScene.eventTarget.removeEventListener(BattleSceneEventType.MOVE_USED, this.onMoveUsedEvent); - this.battleScene.eventTarget.removeEventListener(BattleSceneEventType.BERRY_USED, this.onBerryUsedEvent); + globalScene.eventTarget.removeEventListener(BattleSceneEventType.MOVE_USED, this.onMoveUsedEvent); + globalScene.eventTarget.removeEventListener(BattleSceneEventType.BERRY_USED, this.onBerryUsedEvent); super.destroy(fromScene); } diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index 72447988bddb..55e8e4e646a7 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -4,7 +4,7 @@ import * as Utils from "../utils"; import { addTextObject, TextStyle } from "./text"; import { getGenderSymbol, getGenderColor, Gender } from "../data/gender"; import { StatusEffect } from "#enums/status-effect"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { getTypeRgb } from "#app/data/type"; import { Type } from "#enums/type"; import { getVariantTint } from "#app/data/variant"; @@ -76,8 +76,8 @@ export default class BattleInfo extends Phaser.GameObjects.Container { private readonly statOrderPlayer = [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.ACC, Stat.EVA, Stat.SPD ]; private readonly statOrderEnemy = [ Stat.HP, Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.ACC, Stat.EVA, Stat.SPD ]; - constructor(scene: Phaser.Scene, x: number, y: number, player: boolean) { - super(scene, x, y); + constructor(x: number, y: number, player: boolean) { + super(globalScene, x, y); this.baseY = y; this.player = player; this.mini = !player; @@ -96,31 +96,31 @@ export default class BattleInfo extends Phaser.GameObjects.Container { // Initially invisible and shown via Pokemon.showInfo this.setVisible(false); - this.box = this.scene.add.sprite(0, 0, this.getTextureName()); + this.box = globalScene.add.sprite(0, 0, this.getTextureName()); this.box.setName("box"); this.box.setOrigin(1, 0.5); this.add(this.box); - this.nameText = addTextObject(this.scene, player ? -115 : -124, player ? -15.2 : -11.2, "", TextStyle.BATTLE_INFO); + this.nameText = addTextObject(player ? -115 : -124, player ? -15.2 : -11.2, "", TextStyle.BATTLE_INFO); this.nameText.setName("text_name"); this.nameText.setOrigin(0, 0); this.add(this.nameText); - this.genderText = addTextObject(this.scene, 0, 0, "", TextStyle.BATTLE_INFO); + this.genderText = addTextObject(0, 0, "", TextStyle.BATTLE_INFO); this.genderText.setName("text_gender"); this.genderText.setOrigin(0, 0); this.genderText.setPositionRelative(this.nameText, 0, 2); this.add(this.genderText); if (!this.player) { - this.ownedIcon = this.scene.add.sprite(0, 0, "icon_owned"); + this.ownedIcon = globalScene.add.sprite(0, 0, "icon_owned"); this.ownedIcon.setName("icon_owned"); this.ownedIcon.setVisible(false); this.ownedIcon.setOrigin(0, 0); this.ownedIcon.setPositionRelative(this.nameText, 0, 11.75); this.add(this.ownedIcon); - this.championRibbon = this.scene.add.sprite(0, 0, "champion_ribbon"); + this.championRibbon = globalScene.add.sprite(0, 0, "champion_ribbon"); this.championRibbon.setName("icon_champion_ribbon"); this.championRibbon.setVisible(false); this.championRibbon.setOrigin(0, 0); @@ -128,7 +128,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.add(this.championRibbon); } - this.teraIcon = this.scene.add.sprite(0, 0, "icon_tera"); + this.teraIcon = globalScene.add.sprite(0, 0, "icon_tera"); this.teraIcon.setName("icon_tera"); this.teraIcon.setVisible(false); this.teraIcon.setOrigin(0, 0); @@ -137,7 +137,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.teraIcon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 12, 15), Phaser.Geom.Rectangle.Contains); this.add(this.teraIcon); - this.shinyIcon = this.scene.add.sprite(0, 0, "shiny_star"); + this.shinyIcon = globalScene.add.sprite(0, 0, "shiny_star"); this.shinyIcon.setName("icon_shiny"); this.shinyIcon.setVisible(false); this.shinyIcon.setOrigin(0, 0); @@ -146,7 +146,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.shinyIcon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 12, 15), Phaser.Geom.Rectangle.Contains); this.add(this.shinyIcon); - this.fusionShinyIcon = this.scene.add.sprite(0, 0, "shiny_star_2"); + this.fusionShinyIcon = globalScene.add.sprite(0, 0, "shiny_star_2"); this.fusionShinyIcon.setName("icon_fusion_shiny"); this.fusionShinyIcon.setVisible(false); this.fusionShinyIcon.setOrigin(0, 0); @@ -154,7 +154,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.fusionShinyIcon.setPosition(this.shinyIcon.x, this.shinyIcon.y); this.add(this.fusionShinyIcon); - this.splicedIcon = this.scene.add.sprite(0, 0, "icon_spliced"); + this.splicedIcon = globalScene.add.sprite(0, 0, "icon_spliced"); this.splicedIcon.setName("icon_spliced"); this.splicedIcon.setVisible(false); this.splicedIcon.setOrigin(0, 0); @@ -163,42 +163,42 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.splicedIcon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 12, 15), Phaser.Geom.Rectangle.Contains); this.add(this.splicedIcon); - this.statusIndicator = this.scene.add.sprite(0, 0, Utils.getLocalizedSpriteKey("statuses")); + this.statusIndicator = globalScene.add.sprite(0, 0, Utils.getLocalizedSpriteKey("statuses")); this.statusIndicator.setName("icon_status"); this.statusIndicator.setVisible(false); this.statusIndicator.setOrigin(0, 0); this.statusIndicator.setPositionRelative(this.nameText, 0, 11.5); this.add(this.statusIndicator); - this.levelContainer = this.scene.add.container(player ? -41 : -50, player ? -10 : -5); + this.levelContainer = globalScene.add.container(player ? -41 : -50, player ? -10 : -5); this.levelContainer.setName("container_level"); this.add(this.levelContainer); - const levelOverlay = this.scene.add.image(0, 0, "overlay_lv"); + const levelOverlay = globalScene.add.image(0, 0, "overlay_lv"); this.levelContainer.add(levelOverlay); - this.hpBar = this.scene.add.image(player ? -61 : -71, player ? -1 : 4.5, "overlay_hp"); + this.hpBar = globalScene.add.image(player ? -61 : -71, player ? -1 : 4.5, "overlay_hp"); this.hpBar.setName("hp_bar"); this.hpBar.setOrigin(0); this.add(this.hpBar); this.hpBarSegmentDividers = []; - this.levelNumbersContainer = this.scene.add.container(9.5, (this.scene as BattleScene).uiTheme ? 0 : -0.5); + this.levelNumbersContainer = globalScene.add.container(9.5, globalScene.uiTheme ? 0 : -0.5); this.levelNumbersContainer.setName("container_level"); this.levelContainer.add(this.levelNumbersContainer); if (this.player) { - this.hpNumbersContainer = this.scene.add.container(-15, 10); + this.hpNumbersContainer = globalScene.add.container(-15, 10); this.hpNumbersContainer.setName("container_hp"); this.add(this.hpNumbersContainer); - const expBar = this.scene.add.image(-98, 18, "overlay_exp"); + const expBar = globalScene.add.image(-98, 18, "overlay_exp"); expBar.setName("overlay_exp"); expBar.setOrigin(0); this.add(expBar); - const expMaskRect = this.scene.make.graphics({}); + const expMaskRect = globalScene.make.graphics({}); expMaskRect.setScale(6); expMaskRect.fillStyle(0xFFFFFF); expMaskRect.beginPath(); @@ -212,12 +212,12 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.expMaskRect = expMaskRect; } - this.statsContainer = this.scene.add.container(0, 0); + this.statsContainer = globalScene.add.container(0, 0); this.statsContainer.setName("container_stats"); this.statsContainer.setAlpha(0); this.add(this.statsContainer); - this.statsBox = this.scene.add.sprite(0, 0, `${this.getTextureName()}_stats`); + this.statsBox = globalScene.add.sprite(0, 0, `${this.getTextureName()}_stats`); this.statsBox.setName("box_stats"); this.statsBox.setOrigin(1, 0.5); this.statsContainer.add(this.statsBox); @@ -225,7 +225,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { const statLabels: Phaser.GameObjects.Sprite[] = []; this.statNumbers = []; - this.statValuesContainer = this.scene.add.container(0, 0); + this.statValuesContainer = globalScene.add.container(0, 0); this.statsContainer.add(this.statValuesContainer); // this gives us a different starting location from the left of the label and padding between stats for a player vs enemy @@ -249,13 +249,13 @@ export default class BattleInfo extends Phaser.GameObjects.Container { statY = baseY + (!!(i % 2) === this.player ? 10 : 0); // we compare i % 2 against this.player to tell us where to place the label; because this.battleStatOrder for enemies has HP, this.battleStatOrder[1]=ATK, but for players this.battleStatOrder[0]=ATK, so this comparing i % 2 to this.player fixes this issue for us } - const statLabel = this.scene.add.sprite(statX, statY, "pbinfo_stat", Stat[s]); + const statLabel = globalScene.add.sprite(statX, statY, "pbinfo_stat", Stat[s]); statLabel.setName("icon_stat_label_" + i.toString()); statLabel.setOrigin(0, 0); statLabels.push(statLabel); this.statValuesContainer.add(statLabel); - const statNumber = this.scene.add.sprite(statX + statLabel.width, statY, "pbinfo_stat_numbers", this.statOrder[i] !== Stat.HP ? "3" : "empty"); + const statNumber = globalScene.add.sprite(statX + statLabel.width, statY, "pbinfo_stat_numbers", this.statOrder[i] !== Stat.HP ? "3" : "empty"); statNumber.setName("icon_stat_number_" + i.toString()); statNumber.setOrigin(0, 0); this.statNumbers.push(statNumber); @@ -269,35 +269,35 @@ export default class BattleInfo extends Phaser.GameObjects.Container { }); if (!this.player) { - this.flyoutMenu = new BattleFlyout(this.scene, this.player); + this.flyoutMenu = new BattleFlyout(this.player); this.add(this.flyoutMenu); this.moveBelow(this.flyoutMenu, this.box); } - this.type1Icon = this.scene.add.sprite(player ? -139 : -15, player ? -17 : -15.5, `pbinfo_${player ? "player" : "enemy"}_type1`); + this.type1Icon = globalScene.add.sprite(player ? -139 : -15, player ? -17 : -15.5, `pbinfo_${player ? "player" : "enemy"}_type1`); this.type1Icon.setName("icon_type_1"); this.type1Icon.setOrigin(0, 0); this.add(this.type1Icon); - this.type2Icon = this.scene.add.sprite(player ? -139 : -15, player ? -1 : -2.5, `pbinfo_${player ? "player" : "enemy"}_type2`); + this.type2Icon = globalScene.add.sprite(player ? -139 : -15, player ? -1 : -2.5, `pbinfo_${player ? "player" : "enemy"}_type2`); this.type2Icon.setName("icon_type_2"); this.type2Icon.setOrigin(0, 0); this.add(this.type2Icon); - this.type3Icon = this.scene.add.sprite(player ? -154 : 0, player ? -17 : -15.5, `pbinfo_${player ? "player" : "enemy"}_type`); + this.type3Icon = globalScene.add.sprite(player ? -154 : 0, player ? -17 : -15.5, `pbinfo_${player ? "player" : "enemy"}_type`); this.type3Icon.setName("icon_type_3"); this.type3Icon.setOrigin(0, 0); this.add(this.type3Icon); if (!this.player) { - this.effectivenessContainer = this.scene.add.container(0, 0); + this.effectivenessContainer = globalScene.add.container(0, 0); this.effectivenessContainer.setPositionRelative(this.type1Icon, 22, 4); this.effectivenessContainer.setVisible(false); this.add(this.effectivenessContainer); - this.effectivenessText = addTextObject(this.scene, 5, 4.5, "", TextStyle.BATTLE_INFO); - this.effectivenessWindow = addWindow((this.scene as BattleScene), 0, 0, 0, 20, undefined, false, undefined, undefined, WindowVariant.XTHIN); + this.effectivenessText = addTextObject(5, 4.5, "", TextStyle.BATTLE_INFO); + this.effectivenessWindow = addWindow(0, 0, 0, 20, undefined, false, undefined, undefined, WindowVariant.XTHIN); this.effectivenessContainer.add(this.effectivenessWindow); this.effectivenessContainer.add(this.effectivenessText); @@ -327,18 +327,18 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.teraIcon.setVisible(this.lastTeraType !== Type.UNKNOWN); this.teraIcon.on("pointerover", () => { if (this.lastTeraType !== Type.UNKNOWN) { - (this.scene as BattleScene).ui.showTooltip("", i18next.t("fightUiHandler:teraHover", { type: i18next.t(`pokemonInfo:Type.${Type[this.lastTeraType]}`) })); + globalScene.ui.showTooltip("", i18next.t("fightUiHandler:teraHover", { type: i18next.t(`pokemonInfo:Type.${Type[this.lastTeraType]}`) })); } }); - this.teraIcon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.teraIcon.on("pointerout", () => globalScene.ui.hideTooltip()); const isFusion = pokemon.isFusion(); this.splicedIcon.setPositionRelative(this.nameText, nameTextWidth + this.genderText.displayWidth + 1 + (this.teraIcon.visible ? this.teraIcon.displayWidth + 1 : 0), 2.5); this.splicedIcon.setVisible(isFusion); if (this.splicedIcon.visible) { - this.splicedIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", `${pokemon.species.getName(pokemon.formIndex)}/${pokemon.fusionSpecies?.getName(pokemon.fusionFormIndex)}`)); - this.splicedIcon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.splicedIcon.on("pointerover", () => globalScene.ui.showTooltip("", `${pokemon.species.getName(pokemon.formIndex)}/${pokemon.fusionSpecies?.getName(pokemon.fusionFormIndex)}`)); + this.splicedIcon.on("pointerout", () => globalScene.ui.hideTooltip()); } const doubleShiny = isFusion && pokemon.shiny && pokemon.fusionShiny; @@ -352,8 +352,8 @@ export default class BattleInfo extends Phaser.GameObjects.Container { const shinyDescriptor = doubleShiny || baseVariant ? `${baseVariant === 2 ? i18next.t("common:epicShiny") : baseVariant === 1 ? i18next.t("common:rareShiny") : i18next.t("common:commonShiny")}${doubleShiny ? `/${pokemon.fusionVariant === 2 ? i18next.t("common:epicShiny") : pokemon.fusionVariant === 1 ? i18next.t("common:rareShiny") : i18next.t("common:commonShiny")}` : ""}` : ""; - this.shinyIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", `${i18next.t("common:shinyOnHover")}${shinyDescriptor ? ` (${shinyDescriptor})` : ""}`)); - this.shinyIcon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.shinyIcon.on("pointerover", () => globalScene.ui.showTooltip("", `${i18next.t("common:shinyOnHover")}${shinyDescriptor ? ` (${shinyDescriptor})` : ""}`)); + this.shinyIcon.on("pointerout", () => globalScene.ui.hideTooltip()); } this.fusionShinyIcon.setPosition(this.shinyIcon.x, this.shinyIcon.y); @@ -364,15 +364,15 @@ export default class BattleInfo extends Phaser.GameObjects.Container { if (!this.player) { if (this.nameText.visible) { - this.nameText.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", i18next.t("battleInfo:generation", { generation: i18next.t(`starterSelectUiHandler:gen${pokemon.species.generation}`) }))); - this.nameText.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.nameText.on("pointerover", () => globalScene.ui.showTooltip("", i18next.t("battleInfo:generation", { generation: i18next.t(`starterSelectUiHandler:gen${pokemon.species.generation}`) }))); + this.nameText.on("pointerout", () => globalScene.ui.hideTooltip()); } - const dexEntry = pokemon.scene.gameData.dexData[pokemon.species.speciesId]; + const dexEntry = globalScene.gameData.dexData[pokemon.species.speciesId]; this.ownedIcon.setVisible(!!dexEntry.caughtAttr); const opponentPokemonDexAttr = pokemon.getDexAttr(); - if (pokemon.scene.gameMode.isClassic) { - if (pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId()].classicWinCount > 0 && pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId(true)].classicWinCount > 0) { + if (globalScene.gameMode.isClassic) { + if (globalScene.gameData.starterData[pokemon.species.getRootSpeciesId()].classicWinCount > 0 && globalScene.gameData.starterData[pokemon.species.getRootSpeciesId(true)].classicWinCount > 0) { this.championRibbon.setVisible(true); } } @@ -380,7 +380,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { // Check if Player owns all genders and forms of the Pokemon const missingDexAttrs = ((dexEntry.caughtAttr & opponentPokemonDexAttr) < opponentPokemonDexAttr); - const ownedAbilityAttrs = pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId()].abilityAttr; + const ownedAbilityAttrs = globalScene.gameData.starterData[pokemon.species.getRootSpeciesId()].abilityAttr; // Check if the player owns ability for the root form const playerOwnsThisAbility = pokemon.checkIfPlayerHasAbilityOfStarter(ownedAbilityAttrs); @@ -469,7 +469,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } toggleStats(visible: boolean): void { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.statsContainer, duration: Utils.fixedInt(125), ease: "Sine.easeInOut", @@ -501,11 +501,11 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } if (this.boss && this.bossSegments > 1) { - const uiTheme = (this.scene as BattleScene).uiTheme; + const uiTheme = globalScene.uiTheme; const maxHp = pokemon.getMaxHp(); for (let s = 1; s < this.bossSegments; s++) { const dividerX = (Math.round((maxHp / this.bossSegments) * s) / maxHp) * this.hpBar.width; - const divider = this.scene.add.rectangle(0, 0, 1, this.hpBar.height - (uiTheme ? 0 : 1), pokemon.bossSegmentIndex >= s ? 0xFFFFFF : 0x404040); + const divider = globalScene.add.rectangle(0, 0, 1, this.hpBar.height - (uiTheme ? 0 : 1), pokemon.bossSegmentIndex >= s ? 0xFFFFFF : 0x404040); divider.setOrigin(0.5, 0); divider.setName("hpBar_divider_" + s.toString()); this.add(divider); @@ -531,7 +531,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { updateInfo(pokemon: Pokemon, instant?: boolean): Promise { return new Promise(resolve => { - if (!this.scene) { + if (!globalScene) { return resolve(); } @@ -595,11 +595,11 @@ export default class BattleInfo extends Phaser.GameObjects.Container { const updatePokemonHp = () => { let duration = !instant ? Phaser.Math.Clamp(Math.abs((this.lastHp) - pokemon.hp) * 5, 250, 5000) : 0; - const speed = (this.scene as BattleScene).hpBarSpeed; + const speed = globalScene.hpBarSpeed; if (speed) { duration = speed >= 3 ? 0 : duration / Math.pow(2, speed); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.hpBar, ease: "Sine.easeOut", scaleX: pokemon.getHpRatio(true), @@ -625,7 +625,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { }; if (this.player) { - const isLevelCapped = pokemon.level >= (this.scene as BattleScene).getMaxExpLevel(); + const isLevelCapped = pokemon.level >= globalScene.getMaxExpLevel(); if ((this.lastExp !== pokemon.exp || this.lastLevel !== pokemon.level)) { const originalResolve = resolve; @@ -663,7 +663,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { let displayName = pokemon.getNameToRender().replace(/[♂♀]/g, ""); let nameTextWidth: number; - const nameSizeTest = addTextObject(this.scene, 0, 0, displayName, TextStyle.BATTLE_INFO); + const nameSizeTest = addTextObject(0, 0, displayName, TextStyle.BATTLE_INFO); nameTextWidth = nameSizeTest.displayWidth; while (nameTextWidth > (this.player || !this.boss ? 60 : 98) - ((pokemon.gender !== Gender.GENDERLESS ? 6 : 0) + (pokemon.fusionSpecies ? 8 : 0) + (pokemon.isShiny() ? 8 : 0) + (Math.min(pokemon.level.toString().length, 3) - 3) * 8)) { @@ -688,7 +688,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { const relLevelExp = getLevelRelExp(this.lastLevel + 1, pokemon.species.growthRate); const levelExp = levelUp ? relLevelExp : pokemon.levelExp; let ratio = relLevelExp ? levelExp / relLevelExp : 0; - if (this.lastLevel >= (this.scene as BattleScene).getMaxExpLevel(true)) { + if (this.lastLevel >= globalScene.getMaxExpLevel(true)) { if (levelUp) { ratio = 1; } else { @@ -698,7 +698,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } const durationMultiplier = Phaser.Tweens.Builders.GetEaseFunction("Sine.easeIn")(1 - (Math.max(this.lastLevel - 100, 0) / 150)); let duration = this.visible && !instant ? (((levelExp - this.lastLevelExp) / relLevelExp) * BattleInfo.EXP_GAINS_DURATION_BASE) * durationMultiplier * levelDurationMultiplier : 0; - const speed = (this.scene as BattleScene).expGainsSpeed; + const speed = globalScene.expGainsSpeed; if (speed && speed >= ExpGainsSpeed.DEFAULT) { duration = speed >= ExpGainsSpeed.SKIP ? ExpGainsSpeed.DEFAULT : duration / Math.pow(2, speed); } @@ -710,24 +710,24 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.lastLevelExp = pokemon.levelExp; } if (duration) { - (this.scene as BattleScene).playSound("se/exp"); + globalScene.playSound("se/exp"); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.expMaskRect, ease: "Sine.easeIn", x: ratio * 510, duration: duration, onComplete: () => { - if (!this.scene) { + if (!globalScene) { return resolve(); } if (duration) { - this.scene.sound.stopByKey("se/exp"); + globalScene.sound.stopByKey("se/exp"); } if (ratio === 1) { - (this.scene as BattleScene).playSound("se/level_up"); + globalScene.playSound("se/level_up"); this.setLevel(this.lastLevel); - this.scene.time.delayedCall(500 * levelDurationMultiplier, () => { + globalScene.time.delayedCall(500 * levelDurationMultiplier, () => { this.expMaskRect.x = 0; this.updateInfo(pokemon, instant).then(() => resolve()); }); @@ -740,17 +740,17 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } setLevel(level: integer): void { - const isCapped = level >= (this.scene as BattleScene).getMaxExpLevel(); + const isCapped = level >= globalScene.getMaxExpLevel(); this.levelNumbersContainer.removeAll(true); const levelStr = level.toString(); for (let i = 0; i < levelStr.length; i++) { - this.levelNumbersContainer.add(this.scene.add.image(i * 8, 0, `numbers${isCapped && this.player ? "_red" : ""}`, levelStr[i])); + this.levelNumbersContainer.add(globalScene.add.image(i * 8, 0, `numbers${isCapped && this.player ? "_red" : ""}`, levelStr[i])); } this.levelContainer.setX((this.player ? -41 : -50) - 8 * Math.max(levelStr.length - 3, 0)); } setHpNumbers(hp: integer, maxHp: integer): void { - if (!this.player || !this.scene) { + if (!this.player || !globalScene) { return; } this.hpNumbersContainer.removeAll(true); @@ -758,11 +758,11 @@ export default class BattleInfo extends Phaser.GameObjects.Container { const maxHpStr = maxHp.toString(); let offset = 0; for (let i = maxHpStr.length - 1; i >= 0; i--) { - this.hpNumbersContainer.add(this.scene.add.image(offset++ * -8, 0, "numbers", maxHpStr[i])); + this.hpNumbersContainer.add(globalScene.add.image(offset++ * -8, 0, "numbers", maxHpStr[i])); } - this.hpNumbersContainer.add(this.scene.add.image(offset++ * -8, 0, "numbers", "/")); + this.hpNumbersContainer.add(globalScene.add.image(offset++ * -8, 0, "numbers", "/")); for (let i = hpStr.length - 1; i >= 0; i--) { - this.hpNumbersContainer.add(this.scene.add.image(offset++ * -8, 0, "numbers", hpStr[i])); + this.hpNumbersContainer.add(globalScene.add.image(offset++ * -8, 0, "numbers", hpStr[i])); } } @@ -797,7 +797,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } this.currentEffectiveness = effectiveness; - if (!(this.scene as BattleScene).typeHints || effectiveness === undefined || this.flyoutMenu?.flyoutVisible) { + if (!globalScene.typeHints || effectiveness === undefined || this.flyoutMenu?.flyoutVisible) { this.effectivenessContainer.setVisible(false); return; } @@ -817,14 +817,14 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } export class PlayerBattleInfo extends BattleInfo { - constructor(scene: Phaser.Scene) { - super(scene, Math.floor(scene.game.canvas.width / 6) - 10, -72, true); + constructor() { + super(Math.floor(globalScene.game.canvas.width / 6) - 10, -72, true); } } export class EnemyBattleInfo extends BattleInfo { - constructor(scene: Phaser.Scene) { - super(scene, 140, -141, false); + constructor() { + super(140, -141, false); } setMini(mini: boolean): void { } // Always mini diff --git a/src/ui/battle-message-ui-handler.ts b/src/ui/battle-message-ui-handler.ts index 180fc66ed9b4..8dbfaaa78e0e 100644 --- a/src/ui/battle-message-ui-handler.ts +++ b/src/ui/battle-message-ui-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { addBBCodeTextObject, addTextObject, getTextColor, TextStyle } from "./text"; import { Mode } from "./ui"; import MessageUiHandler from "./message-ui-handler"; @@ -22,8 +22,8 @@ export default class BattleMessageUiHandler extends MessageUiHandler { public readonly wordWrapWidth: number = 1780; - constructor(scene: BattleScene) { - super(scene, Mode.MESSAGE); + constructor() { + super(Mode.MESSAGE); } setup(): void { @@ -32,36 +32,36 @@ export default class BattleMessageUiHandler extends MessageUiHandler { this.textTimer = null; this.textCallbackTimer = null; - this.bg = this.scene.add.sprite(0, 0, "bg", this.scene.windowType); + this.bg = globalScene.add.sprite(0, 0, "bg", globalScene.windowType); this.bg.setName("sprite-battle-msg-bg"); this.bg.setOrigin(0, 1); ui.add(this.bg); - this.commandWindow = addWindow(this.scene, 202, 0, 118, 48); + this.commandWindow = addWindow(202, 0, 118, 48); this.commandWindow.setName("window-command"); this.commandWindow.setOrigin(0, 1); this.commandWindow.setVisible(false); ui.add(this.commandWindow); - this.movesWindowContainer = this.scene.add.container(0, 0); + this.movesWindowContainer = globalScene.add.container(0, 0); this.movesWindowContainer.setName("moves-bg"); this.movesWindowContainer.setVisible(false); - const movesWindow = addWindow(this.scene, 0, 0, 243, 48); + const movesWindow = addWindow(0, 0, 243, 48); movesWindow.setName("moves-window"); movesWindow.setOrigin(0, 1); - const moveDetailsWindow = addWindow(this.scene, 240, 0, 80, 48, false, false, -1, 132); + const moveDetailsWindow = addWindow(240, 0, 80, 48, false, false, -1, 132); moveDetailsWindow.setName("move-details-window"); moveDetailsWindow.setOrigin(0, 1); this.movesWindowContainer.add([ movesWindow, moveDetailsWindow ]); ui.add(this.movesWindowContainer); - const messageContainer = this.scene.add.container(12, -39); + const messageContainer = globalScene.add.container(12, -39); ui.add(messageContainer); - const message = addTextObject(this.scene, 0, 0, "", TextStyle.MESSAGE, { + const message = addTextObject(0, 0, "", TextStyle.MESSAGE, { maxLines: 2, wordWrap: { width: this.wordWrapWidth @@ -71,13 +71,13 @@ export default class BattleMessageUiHandler extends MessageUiHandler { this.message = message; - this.nameBoxContainer = this.scene.add.container(0, -16); + this.nameBoxContainer = globalScene.add.container(0, -16); this.nameBoxContainer.setVisible(false); - this.nameBox = this.scene.add.nineslice(0, 0, "namebox", this.scene.windowType, 72, 16, 8, 8, 5, 5); + this.nameBox = globalScene.add.nineslice(0, 0, "namebox", globalScene.windowType, 72, 16, 8, 8, 5, 5); this.nameBox.setOrigin(0, 0); - this.nameText = addTextObject(this.scene, 8, 0, "Rival", TextStyle.MESSAGE, { maxLines: 1 }); + this.nameText = addTextObject(8, 0, "Rival", TextStyle.MESSAGE, { maxLines: 1 }); this.nameBoxContainer.add(this.nameBox); this.nameBoxContainer.add(this.nameText); @@ -85,13 +85,13 @@ export default class BattleMessageUiHandler extends MessageUiHandler { this.initPromptSprite(messageContainer); - const levelUpStatsContainer = this.scene.add.container(0, 0); + const levelUpStatsContainer = globalScene.add.container(0, 0); levelUpStatsContainer.setVisible(false); ui.add(levelUpStatsContainer); this.levelUpStatsContainer = levelUpStatsContainer; - const levelUpStatsLabelsContent = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 73, -94, "", TextStyle.WINDOW, { maxLines: 6 }); + const levelUpStatsLabelsContent = addTextObject((globalScene.game.canvas.width / 6) - 73, -94, "", TextStyle.WINDOW, { maxLines: 6 }); levelUpStatsLabelsContent.setLineSpacing(i18next.resolvedLanguage === "ja" ? 25 : 5); let levelUpStatsLabelText = ""; @@ -101,19 +101,19 @@ export default class BattleMessageUiHandler extends MessageUiHandler { levelUpStatsLabelsContent.text = levelUpStatsLabelText; levelUpStatsLabelsContent.x -= levelUpStatsLabelsContent.displayWidth; - const levelUpStatsBg = addWindow(this.scene, (this.scene.game.canvas.width / 6), -100, 80 + levelUpStatsLabelsContent.displayWidth, 100); + const levelUpStatsBg = addWindow((globalScene.game.canvas.width / 6), -100, 80 + levelUpStatsLabelsContent.displayWidth, 100); levelUpStatsBg.setOrigin(1, 0); levelUpStatsContainer.add(levelUpStatsBg); levelUpStatsContainer.add(levelUpStatsLabelsContent); - const levelUpStatsIncrContent = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 50, -94, "+\n+\n+\n+\n+\n+", TextStyle.WINDOW, { maxLines: 6 }); + const levelUpStatsIncrContent = addTextObject((globalScene.game.canvas.width / 6) - 50, -94, "+\n+\n+\n+\n+\n+", TextStyle.WINDOW, { maxLines: 6 }); levelUpStatsIncrContent.setLineSpacing(i18next.resolvedLanguage === "ja" ? 25 : 5); levelUpStatsContainer.add(levelUpStatsIncrContent); this.levelUpStatsIncrContent = levelUpStatsIncrContent; - const levelUpStatsValuesContent = addBBCodeTextObject(this.scene, (this.scene.game.canvas.width / 6) - 7, -94, "", TextStyle.WINDOW, { maxLines: 6, lineSpacing: 5 }); + const levelUpStatsValuesContent = addBBCodeTextObject((globalScene.game.canvas.width / 6) - 7, -94, "", TextStyle.WINDOW, { maxLines: 6, lineSpacing: 5 }); levelUpStatsValuesContent.setLineSpacing(i18next.resolvedLanguage === "ja" ? 25 : 5); levelUpStatsValuesContent.setOrigin(1, 0); levelUpStatsValuesContent.setAlign("right"); @@ -167,10 +167,10 @@ export default class BattleMessageUiHandler extends MessageUiHandler { promptLevelUpStats(partyMemberIndex: integer, prevStats: integer[], showTotals: boolean): Promise { return new Promise(resolve => { - if (!this.scene.showLevelUpStats) { + if (!globalScene.showLevelUpStats) { return resolve(); } - const newStats = (this.scene as BattleScene).getPlayerParty()[partyMemberIndex].stats; + const newStats = globalScene.getPlayerParty()[partyMemberIndex].stats; let levelUpStatsValuesText = ""; for (const s of PERMANENT_STATS) { levelUpStatsValuesText += `${showTotals ? newStats[s] : newStats[s] - prevStats[s]}\n`; @@ -192,7 +192,7 @@ export default class BattleMessageUiHandler extends MessageUiHandler { promptIvs(pokemonId: integer, ivs: integer[], shownIvsCount: integer): Promise { return new Promise(resolve => { - this.scene.executeWithSeedOffset(() => { + globalScene.executeWithSeedOffset(() => { let levelUpStatsValuesText = ""; const shownStats = this.getTopIvs(ivs, shownIvsCount); for (const s of PERMANENT_STATS) { @@ -226,9 +226,9 @@ export default class BattleMessageUiHandler extends MessageUiHandler { } getIvDescriptor(value: integer, typeIv: integer, pokemonId: integer): string { - const starterSpecies = this.scene.getPokemonById(pokemonId)!.species.getRootSpeciesId(); // we are using getRootSpeciesId() here because we want to check against the baby form, not the mid form if it exists - const starterIvs: number[] = this.scene.gameData.dexData[starterSpecies].ivs; - const uiTheme = (this.scene as BattleScene).uiTheme; // Assuming uiTheme is accessible + const starterSpecies = globalScene.getPokemonById(pokemonId)!.species.getRootSpeciesId(); // we are using getRootSpeciesId() here because we want to check against the baby form, not the mid form if it exists + const starterIvs: number[] = globalScene.gameData.dexData[starterSpecies].ivs; + const uiTheme = globalScene.uiTheme; // Assuming uiTheme is accessible // Function to wrap text in color based on comparison const coloredText = (text: string, isBetter: boolean, ivValue) => { diff --git a/src/ui/bgm-bar.ts b/src/ui/bgm-bar.ts index 616b3ff87cf8..0cd3da71248e 100644 --- a/src/ui/bgm-bar.ts +++ b/src/ui/bgm-bar.ts @@ -1,7 +1,7 @@ -import BattleScene from "../battle-scene"; import { addTextObject, TextStyle } from "./text"; import i18next from "i18next"; import * as Utils from "#app/utils"; +import { globalScene } from "#app/global-scene"; const hiddenX = -150; const shownX = 0; @@ -16,20 +16,20 @@ export default class BgmBar extends Phaser.GameObjects.Container { public shown: boolean; - constructor(scene: BattleScene) { - super(scene, hiddenX, baseY); + constructor() { + super(globalScene, hiddenX, baseY); } setup(): void { this.defaultWidth = 230; this.defaultHeight = 100; - this.bg = this.scene.add.nineslice(-5, -5, "bgm_bar", undefined, this.defaultWidth, this.defaultHeight, 0, 0, 10, 10); + this.bg = globalScene.add.nineslice(-5, -5, "bgm_bar", undefined, this.defaultWidth, this.defaultHeight, 0, 0, 10, 10); this.bg.setOrigin(0, 0); this.add(this.bg); - this.musicText = addTextObject(this.scene, 5, 5, "", TextStyle.BGM_BAR); + this.musicText = addTextObject(5, 5, "", TextStyle.BGM_BAR); this.musicText.setOrigin(0, 0); this.musicText.setWordWrapWidth(650, true); @@ -52,7 +52,7 @@ export default class BgmBar extends Phaser.GameObjects.Container { this.bg.width = Math.min(this.defaultWidth, this.musicText.displayWidth + 23); this.bg.height = Math.min(this.defaultHeight, this.musicText.displayHeight + 20); - (this.scene as BattleScene).fieldUI.bringToTop(this); + globalScene.fieldUI.bringToTop(this); this.y = baseY; } @@ -72,11 +72,11 @@ export default class BgmBar extends Phaser.GameObjects.Container { return; } - if (!(this.scene as BattleScene).showBgmBar) { + if (!globalScene.showBgmBar) { this.setVisible(false); return; } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, x: visible ? shownX : hiddenX, duration: 500, diff --git a/src/ui/candy-bar.ts b/src/ui/candy-bar.ts index 14015f022596..20c0918de2f9 100644 --- a/src/ui/candy-bar.ts +++ b/src/ui/candy-bar.ts @@ -1,4 +1,5 @@ -import BattleScene, { starterColors } from "../battle-scene"; +import { starterColors } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject } from "./text"; import { argbFromRgba } from "@material/material-color-utilities"; import * as Utils from "../utils"; @@ -16,29 +17,29 @@ export default class CandyBar extends Phaser.GameObjects.Container { public shown: boolean; - constructor(scene: BattleScene) { - super(scene, (scene.game.canvas.width / 6), -((scene.game.canvas.height) / 6) + 15); + constructor() { + super(globalScene, (globalScene.game.canvas.width / 6), -((globalScene.game.canvas.height) / 6) + 15); } setup(): void { - this.bg = this.scene.add.nineslice(0, 0, "party_exp_bar", undefined, 8, 18, 21, 5, 6, 4); + this.bg = globalScene.add.nineslice(0, 0, "party_exp_bar", undefined, 8, 18, 21, 5, 6, 4); this.bg.setOrigin(0, 0); this.add(this.bg); - this.candyIcon = this.scene.add.sprite(14, 0, "items", "candy"); + this.candyIcon = globalScene.add.sprite(14, 0, "items", "candy"); this.candyIcon.setOrigin(0.5, 0); this.candyIcon.setScale(0.5); this.add(this.candyIcon); - this.candyOverlayIcon = this.scene.add.sprite(14, 0, "items", "candy_overlay"); + this.candyOverlayIcon = globalScene.add.sprite(14, 0, "items", "candy_overlay"); this.candyOverlayIcon.setOrigin(0.5, 0); this.candyOverlayIcon.setScale(0.5); this.add(this.candyOverlayIcon); - this.countText = addTextObject(this.scene, 22, 4, "", TextStyle.BATTLE_INFO); + this.countText = addTextObject(22, 4, "", TextStyle.BATTLE_INFO); this.countText.setOrigin(0, 0); this.add(this.countText); @@ -61,21 +62,21 @@ export default class CandyBar extends Phaser.GameObjects.Container { this.candyIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[0]))); this.candyOverlayIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[1]))); - this.countText.setText(`${(this.scene as BattleScene).gameData.starterData[starterSpeciesId].candyCount + count} (+${count.toString()})`); + this.countText.setText(`${globalScene.gameData.starterData[starterSpeciesId].candyCount + count} (+${count.toString()})`); this.bg.width = this.countText.displayWidth + 28; - (this.scene as BattleScene).fieldUI.bringToTop(this); + globalScene.fieldUI.bringToTop(this); if (this.tween) { this.tween.stop(); } - (this.scene as BattleScene).playSound("se/shing"); + globalScene.playSound("se/shing"); - this.tween = this.scene.tweens.add({ + this.tween = globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6) - (this.bg.width - 5), + x: (globalScene.game.canvas.width / 6) - (this.bg.width - 5), duration: 500, ease: "Sine.easeOut", onComplete: () => { @@ -104,9 +105,9 @@ export default class CandyBar extends Phaser.GameObjects.Container { this.tween.stop(); } - this.tween = this.scene.tweens.add({ + this.tween = globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6), + x: (globalScene.game.canvas.width / 6), duration: 500, ease: "Sine.easeIn", onComplete: () => { diff --git a/src/ui/challenges-select-ui-handler.ts b/src/ui/challenges-select-ui-handler.ts index e2547a626def..a89a45c6066b 100644 --- a/src/ui/challenges-select-ui-handler.ts +++ b/src/ui/challenges-select-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; @@ -12,6 +11,7 @@ import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; import { Color, ShadowColor } from "#app/enums/color"; import { SelectStarterPhase } from "#app/phases/select-starter-phase"; import { TitlePhase } from "#app/phases/title-phase"; +import { globalScene } from "#app/global-scene"; /** * Handles all the UI for choosing optional challenges. @@ -45,8 +45,8 @@ export default class GameChallengesUiHandler extends UiHandler { private readonly leftArrowGap: number = 90; // distance from the label to the left arrow private readonly arrowSpacing: number = 3; // distance between the arrows and the value area - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); } setup() { @@ -54,49 +54,37 @@ export default class GameChallengesUiHandler extends UiHandler { this.widestTextBox = 0; - this.challengesContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1); + this.challengesContainer = globalScene.add.container(1, -(globalScene.game.canvas.height / 6) + 1); this.challengesContainer.setName("challenges"); - this.challengesContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.challengesContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); - const bgOverlay = this.scene.add.rectangle(-1, -1, this.scene.scaledCanvas.width, this.scene.scaledCanvas.height, 0x424242, 0.8); + const bgOverlay = globalScene.add.rectangle(-1, -1, globalScene.scaledCanvas.width, globalScene.scaledCanvas.height, 0x424242, 0.8); bgOverlay.setName("rect-challenge-overlay"); bgOverlay.setOrigin(0, 0); this.challengesContainer.add(bgOverlay); // TODO: Change this back to /9 when adding in difficulty - const headerBg = addWindow(this.scene, 0, 0, (this.scene.game.canvas.width / 6), 24); + const headerBg = addWindow(0, 0, (globalScene.game.canvas.width / 6), 24); headerBg.setName("window-header-bg"); headerBg.setOrigin(0, 0); - const headerText = addTextObject(this.scene, 0, 0, i18next.t("challenges:title"), TextStyle.SETTINGS_LABEL); + const headerText = addTextObject(0, 0, i18next.t("challenges:title"), TextStyle.SETTINGS_LABEL); headerText.setName("text-header"); headerText.setOrigin(0, 0); headerText.setPositionRelative(headerBg, 8, 4); - // const difficultyBg = addWindow(this.scene, 0, 0, (this.scene.game.canvas.width / 18) - 2, 24); - // difficultyBg.setOrigin(0, 0); - // difficultyBg.setPositionRelative(headerBg, headerBg.width, 0); - - // this.difficultyText = addTextObject(this.scene, 0, 0, "0", TextStyle.SETTINGS_LABEL); - // this.difficultyText.setOrigin(0, 0); - // this.difficultyText.setPositionRelative(difficultyBg, 8, 4); - - // const difficultyName = addTextObject(this.scene, 0, 0, i18next.t("challenges:points"), TextStyle.SETTINGS_LABEL); - // difficultyName.setOrigin(0, 0); - // difficultyName.setPositionRelative(difficultyBg, difficultyBg.width - difficultyName.displayWidth - 8, 4); - - this.optionsWidth = this.scene.scaledCanvas.width * 0.6; - this.optionsBg = addWindow(this.scene, 0, headerBg.height, this.optionsWidth, this.scene.scaledCanvas.height - headerBg.height - 2); + this.optionsWidth = globalScene.scaledCanvas.width * 0.6; + this.optionsBg = addWindow(0, headerBg.height, this.optionsWidth, globalScene.scaledCanvas.height - headerBg.height - 2); this.optionsBg.setName("window-options-bg"); this.optionsBg.setOrigin(0, 0); - const descriptionBg = addWindow(this.scene, 0, headerBg.height, this.scene.scaledCanvas.width - this.optionsWidth, this.scene.scaledCanvas.height - headerBg.height - 26); + const descriptionBg = addWindow(0, headerBg.height, globalScene.scaledCanvas.width - this.optionsWidth, globalScene.scaledCanvas.height - headerBg.height - 26); descriptionBg.setName("window-desc-bg"); descriptionBg.setOrigin(0, 0); descriptionBg.setPositionRelative(this.optionsBg, this.optionsBg.width, 0); - this.descriptionText = new BBCodeText(this.scene, descriptionBg.x + 6, descriptionBg.y + 4, "", { + this.descriptionText = new BBCodeText(globalScene, descriptionBg.x + 6, descriptionBg.y + 4, "", { fontFamily: "emerald", fontSize: 84, color: Color.ORANGE, @@ -109,54 +97,54 @@ export default class GameChallengesUiHandler extends UiHandler { } }); this.descriptionText.setName("text-desc"); - this.scene.add.existing(this.descriptionText); + globalScene.add.existing(this.descriptionText); this.descriptionText.setScale(1 / 6); this.descriptionText.setShadow(4, 5, ShadowColor.ORANGE); this.descriptionText.setOrigin(0, 0); - this.startBg = addWindow(this.scene, 0, 0, descriptionBg.width, 24); + this.startBg = addWindow(0, 0, descriptionBg.width, 24); this.startBg.setName("window-start-bg"); this.startBg.setOrigin(0, 0); this.startBg.setPositionRelative(descriptionBg, 0, descriptionBg.height); - this.startText = addTextObject(this.scene, 0, 0, i18next.t("challenges:noneSelected"), TextStyle.SETTINGS_LABEL); + this.startText = addTextObject(0, 0, i18next.t("challenges:noneSelected"), TextStyle.SETTINGS_LABEL); this.startText.setName("text-start"); this.startText.setOrigin(0, 0); this.startText.setPositionRelative(this.startBg, (this.startBg.width - this.startText.displayWidth) / 2, 4); - this.startCursor = this.scene.add.nineslice(0, 0, "summary_moves_cursor", undefined, descriptionBg.width - 8, 16, 1, 1, 1, 1); + this.startCursor = globalScene.add.nineslice(0, 0, "summary_moves_cursor", undefined, descriptionBg.width - 8, 16, 1, 1, 1, 1); this.startCursor.setName("9s-start-cursor"); this.startCursor.setOrigin(0, 0); this.startCursor.setPositionRelative(this.startBg, 4, 3); this.startCursor.setVisible(false); - this.valuesContainer = this.scene.add.container(0, 0); + this.valuesContainer = globalScene.add.container(0, 0); this.valuesContainer.setName("values"); this.challengeLabels = []; for (let i = 0; i < 9; i++) { - const label = addTextObject(this.scene, 8, 28 + i * 16, "", TextStyle.SETTINGS_LABEL); + const label = addTextObject(8, 28 + i * 16, "", TextStyle.SETTINGS_LABEL); label.setName(`text-challenge-label-${i}`); label.setOrigin(0, 0); this.valuesContainer.add(label); - const leftArrow = this.scene.add.image(0, 0, "cursor_reverse"); + const leftArrow = globalScene.add.image(0, 0, "cursor_reverse"); leftArrow.setName(`challenge-left-arrow-${i}`); leftArrow.setOrigin(0, 0); leftArrow.setVisible(false); leftArrow.setScale(0.75); this.valuesContainer.add(leftArrow); - const rightArrow = this.scene.add.image(0, 0, "cursor"); + const rightArrow = globalScene.add.image(0, 0, "cursor"); rightArrow.setName(`challenge-right-arrow-${i}`); rightArrow.setOrigin(0, 0); rightArrow.setScale(0.75); rightArrow.setVisible(false); this.valuesContainer.add(rightArrow); - const value = addTextObject(this.scene, 0, 28 + i * 16, "", TextStyle.SETTINGS_LABEL); + const value = addTextObject(0, 28 + i * 16, "", TextStyle.SETTINGS_LABEL); value.setName(`challenge-value-text-${i}`); value.setPositionRelative(label, 100, 0); this.valuesContainer.add(value); @@ -169,7 +157,7 @@ export default class GameChallengesUiHandler extends UiHandler { }; } - this.monoTypeValue = this.scene.add.sprite(8, 98, Utils.getLocalizedSpriteKey("types")); + this.monoTypeValue = globalScene.add.sprite(8, 98, Utils.getLocalizedSpriteKey("types")); this.monoTypeValue.setName("challenge-value-monotype-sprite"); this.monoTypeValue.setScale(0.86); this.monoTypeValue.setVisible(false); @@ -209,20 +197,20 @@ export default class GameChallengesUiHandler extends UiHandler { * init all challenge labels */ initLabels(): void { - this.setDescription(this.scene.gameMode.challenges[0].getDescription()); + this.setDescription(globalScene.gameMode.challenges[0].getDescription()); this.widestTextBox = 0; for (let i = 0; i < 9; i++) { - if (i < this.scene.gameMode.challenges.length) { + if (i < globalScene.gameMode.challenges.length) { this.challengeLabels[i].label.setVisible(true); this.challengeLabels[i].value.setVisible(true); this.challengeLabels[i].leftArrow.setVisible(true); this.challengeLabels[i].rightArrow.setVisible(true); - const tempText = addTextObject(this.scene, 0, 0, "", TextStyle.SETTINGS_LABEL); // this is added here to get the widest text object for this language, which will be used for the arrow placement + const tempText = addTextObject(0, 0, "", TextStyle.SETTINGS_LABEL); // this is added here to get the widest text object for this language, which will be used for the arrow placement - for (let j = 0; j <= this.scene.gameMode.challenges[i].maxValue; j++) { // this goes through each challenge's value to find out what the max width will be - if (this.scene.gameMode.challenges[i].id !== Challenges.SINGLE_TYPE) { - tempText.setText(this.scene.gameMode.challenges[i].getValue(j)); + for (let j = 0; j <= globalScene.gameMode.challenges[i].maxValue; j++) { // this goes through each challenge's value to find out what the max width will be + if (globalScene.gameMode.challenges[i].id !== Challenges.SINGLE_TYPE) { + tempText.setText(globalScene.gameMode.challenges[i].getValue(j)); if (tempText.displayWidth > this.widestTextBox) { this.widestTextBox = tempText.displayWidth; } @@ -240,8 +228,8 @@ export default class GameChallengesUiHandler extends UiHandler { updateText(): void { this.setDescription(this.getActiveChallenge().getDescription()); let monoTypeVisible = false; - for (let i = 0; i < Math.min(9, this.scene.gameMode.challenges.length); i++) { - const challenge = this.scene.gameMode.challenges[this.scrollCursor + i]; + for (let i = 0; i < Math.min(9, globalScene.gameMode.challenges.length); i++) { + const challenge = globalScene.gameMode.challenges[this.scrollCursor + i]; const challengeLabel = this.challengeLabels[i]; challengeLabel.label.setText(challenge.getName()); challengeLabel.leftArrow.setPositionRelative(challengeLabel.label, this.leftArrowGap, 4.5); @@ -276,7 +264,7 @@ export default class GameChallengesUiHandler extends UiHandler { } // This checks if a challenge has been selected by the user and updates the text/its opacity accordingly. - this.hasSelectedChallenge = this.scene.gameMode.challenges.some(c => c.value !== 0); + this.hasSelectedChallenge = globalScene.gameMode.challenges.some(c => c.value !== 0); if (this.hasSelectedChallenge) { this.startText.setText(i18next.t("common:start")); @@ -289,11 +277,6 @@ export default class GameChallengesUiHandler extends UiHandler { this.startText.setPositionRelative(this.startBg, (this.startBg.width - this.startText.displayWidth) / 2, 4); } this.challengesContainer.update(); - - // const totalDifficulty = this.scene.gameMode.challenges.reduce((v, c) => v + c.getDifficulty(), 0); - // const totalMinDifficulty = this.scene.gameMode.challenges.reduce((v, c) => v + c.getMinDifficulty(), 0); - // this.difficultyText.text = `${totalDifficulty}` + (totalMinDifficulty ? `/${totalMinDifficulty}` : ""); - // this.difficultyText.updateText(); } show(args: any[]): boolean { @@ -303,7 +286,7 @@ export default class GameChallengesUiHandler extends UiHandler { this.updateChallengeArrows(false); this.challengesContainer.setVisible(true); // Should always be false at the start - this.hasSelectedChallenge = this.scene.gameMode.challenges.some(c => c.value !== 0); + this.hasSelectedChallenge = globalScene.gameMode.challenges.some(c => c.value !== 0); this.setCursor(0); this.initLabels(); @@ -319,7 +302,7 @@ export default class GameChallengesUiHandler extends UiHandler { /* This code updates the challenge starter arrows to be tinted/not tinted when the start button is selected to show they can't be changed */ updateChallengeArrows(tinted: boolean) { - for (let i = 0; i < Math.min(9, this.scene.gameMode.challenges.length); i++) { + for (let i = 0; i < Math.min(9, globalScene.gameMode.challenges.length); i++) { const challengeLabel = this.challengeLabels[i]; if (tinted) { challengeLabel.leftArrow.setTint(0x808080); @@ -354,16 +337,16 @@ export default class GameChallengesUiHandler extends UiHandler { this.cursorObj?.setVisible(true); this.updateChallengeArrows(this.startCursor.visible); } else { - this.scene.clearPhaseQueue(); - this.scene.pushPhase(new TitlePhase(this.scene)); - this.scene.getCurrentPhase()?.end(); + globalScene.clearPhaseQueue(); + globalScene.pushPhase(new TitlePhase()); + globalScene.getCurrentPhase()?.end(); } success = true; } else if (button === Button.SUBMIT || button === Button.ACTION) { if (this.hasSelectedChallenge) { if (this.startCursor.visible) { - this.scene.unshiftPhase(new SelectStarterPhase(this.scene)); - this.scene.getCurrentPhase()?.end(); + globalScene.unshiftPhase(new SelectStarterPhase()); + globalScene.getCurrentPhase()?.end(); } else { this.startCursor.setVisible(true); this.cursorObj?.setVisible(false); @@ -380,14 +363,14 @@ export default class GameChallengesUiHandler extends UiHandler { if (this.cursor === 0) { if (this.scrollCursor === 0) { // When at the top of the menu and pressing UP, move to the bottommost item. - if (this.scene.gameMode.challenges.length > rowsToDisplay) { // If there are more than 9 challenges, scroll to the bottom + if (globalScene.gameMode.challenges.length > rowsToDisplay) { // If there are more than 9 challenges, scroll to the bottom // First, set the cursor to the last visible element, preparing for the scroll to the end. const successA = this.setCursor(rowsToDisplay - 1); // Then, adjust the scroll to display the bottommost elements of the menu. - const successB = this.setScrollCursor(this.scene.gameMode.challenges.length - rowsToDisplay); + const successB = this.setScrollCursor(globalScene.gameMode.challenges.length - rowsToDisplay); success = successA && successB; // success is just there to play the little validation sound effect } else { // If there are 9 or less challenges, just move to the bottom one - success = this.setCursor(this.scene.gameMode.challenges.length - 1); + success = this.setCursor(globalScene.gameMode.challenges.length - 1); } } else { success = this.setScrollCursor(this.scrollCursor - 1); @@ -401,7 +384,7 @@ export default class GameChallengesUiHandler extends UiHandler { break; case Button.DOWN: if (this.cursor === rowsToDisplay - 1) { - if (this.scrollCursor < this.scene.gameMode.challenges.length - rowsToDisplay) { + if (this.scrollCursor < globalScene.gameMode.challenges.length - rowsToDisplay) { // When at the bottom and pressing DOWN, scroll if possible. success = this.setScrollCursor(this.scrollCursor + 1); } else { @@ -412,7 +395,7 @@ export default class GameChallengesUiHandler extends UiHandler { const successB = this.setScrollCursor(0); success = successA && successB; // success is just there to play the little validation sound effect } - } else if (this.scene.gameMode.challenges.length < rowsToDisplay && this.cursor === this.scene.gameMode.challenges.length - 1) { + } else if (globalScene.gameMode.challenges.length < rowsToDisplay && this.cursor === globalScene.gameMode.challenges.length - 1) { // When at the bottom of a non-scrolling menu and pressing DOWN, move to the topmost item. success = this.setCursor(0); } else { @@ -451,7 +434,7 @@ export default class GameChallengesUiHandler extends UiHandler { let ret = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.nineslice(0, 0, "summary_moves_cursor", undefined, this.optionsWidth - 8, 16, 1, 1, 1, 1); + this.cursorObj = globalScene.add.nineslice(0, 0, "summary_moves_cursor", undefined, this.optionsWidth - 8, 16, 1, 1, 1, 1); this.cursorObj.setOrigin(0, 0); this.valuesContainer.add(this.cursorObj); } @@ -477,7 +460,7 @@ export default class GameChallengesUiHandler extends UiHandler { } getActiveChallenge(): Challenge { - return this.scene.gameMode.challenges[this.cursor + this.scrollCursor]; + return globalScene.gameMode.challenges[this.cursor + this.scrollCursor]; } clear() { diff --git a/src/ui/char-sprite.ts b/src/ui/char-sprite.ts index d76c7ec59d04..ccd97e2c8e47 100644 --- a/src/ui/char-sprite.ts +++ b/src/ui/char-sprite.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "../utils"; export default class CharSprite extends Phaser.GameObjects.Container { @@ -9,13 +9,13 @@ export default class CharSprite extends Phaser.GameObjects.Container { public variant: string; public shown: boolean; - constructor(scene: BattleScene) { - super(scene, (scene.game.canvas.width / 6) + 32, -42); + constructor() { + super(globalScene, (globalScene.game.canvas.width / 6) + 32, -42); } setup(): void { [ this.sprite, this.transitionSprite ] = new Array(2).fill(null).map(() => { - const ret = this.scene.add.sprite(0, 0, "", ""); + const ret = globalScene.add.sprite(0, 0, "", ""); ret.setOrigin(0.5, 1); this.add(ret); return ret; @@ -45,11 +45,11 @@ export default class CharSprite extends Phaser.GameObjects.Container { this.sprite.setTexture(key, variant); - (this.scene as BattleScene).fieldUI.bringToTop(this); + globalScene.fieldUI.bringToTop(this); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6) - 102, + x: (globalScene.game.canvas.width / 6) - 102, duration: 750, ease: "Cubic.easeOut", onComplete: () => { @@ -57,7 +57,7 @@ export default class CharSprite extends Phaser.GameObjects.Container { } }); - this.setVisible(this.scene.textures.get(key).key !== Utils.MissingTextureKey); + this.setVisible(globalScene.textures.get(key).key !== Utils.MissingTextureKey); this.shown = true; this.key = key; @@ -67,12 +67,12 @@ export default class CharSprite extends Phaser.GameObjects.Container { setVariant(variant: string): Promise { return new Promise(resolve => { - (this.scene as BattleScene).fieldUI.bringToTop(this); + globalScene.fieldUI.bringToTop(this); this.transitionSprite.setTexture(this.key, variant); this.transitionSprite.setAlpha(0); this.transitionSprite.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.transitionSprite, alpha: 1, duration: 250, @@ -93,9 +93,9 @@ export default class CharSprite extends Phaser.GameObjects.Container { return resolve(); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6) + 32, + x: (globalScene.game.canvas.width / 6) + 32, duration: 750, ease: "Cubic.easeIn", onComplete: () => { diff --git a/src/ui/command-ui-handler.ts b/src/ui/command-ui-handler.ts index 0dacacc7b70c..32a3bb764a9a 100644 --- a/src/ui/command-ui-handler.ts +++ b/src/ui/command-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { addTextObject, TextStyle } from "./text"; import PartyUiHandler, { PartyUiMode } from "./party-ui-handler"; import { Mode } from "./ui"; @@ -7,6 +6,7 @@ import i18next from "i18next"; import { Button } from "#enums/buttons"; import { getPokemonNameWithAffix } from "#app/messages"; import { CommandPhase } from "#app/phases/command-phase"; +import { globalScene } from "#app/global-scene"; export enum Command { FIGHT = 0, @@ -22,8 +22,8 @@ export default class CommandUiHandler extends UiHandler { protected fieldIndex: integer = 0; protected cursor2: integer = 0; - constructor(scene: BattleScene) { - super(scene, Mode.COMMAND); + constructor() { + super(Mode.COMMAND); } setup() { @@ -35,13 +35,13 @@ export default class CommandUiHandler extends UiHandler { i18next.t("commandUiHandler:run") ]; - this.commandsContainer = this.scene.add.container(217, -38.7); + this.commandsContainer = globalScene.add.container(217, -38.7); this.commandsContainer.setName("commands"); this.commandsContainer.setVisible(false); ui.add(this.commandsContainer); for (let c = 0; c < commands.length; c++) { - const commandText = addTextObject(this.scene, c % 2 === 0 ? 0 : 55.8, c < 2 ? 0 : 16, commands[c], TextStyle.WINDOW); + const commandText = addTextObject(c % 2 === 0 ? 0 : 55.8, c < 2 ? 0 : 16, commands[c], TextStyle.WINDOW); commandText.setName(commands[c]); this.commandsContainer.add(commandText); } @@ -55,11 +55,11 @@ export default class CommandUiHandler extends UiHandler { this.commandsContainer.setVisible(true); let commandPhase: CommandPhase; - const currentPhase = this.scene.getCurrentPhase(); + const currentPhase = globalScene.getCurrentPhase(); if (currentPhase instanceof CommandPhase) { commandPhase = currentPhase; } else { - commandPhase = this.scene.getStandbyPhase() as CommandPhase; + commandPhase = globalScene.getStandbyPhase() as CommandPhase; } const messageHandler = this.getUi().getMessageHandler(); @@ -90,7 +90,7 @@ export default class CommandUiHandler extends UiHandler { switch (cursor) { // Fight case Command.FIGHT: - ui.setMode(Mode.FIGHT, (this.scene.getCurrentPhase() as CommandPhase).getFieldIndex()); + ui.setMode(Mode.FIGHT, (globalScene.getCurrentPhase() as CommandPhase).getFieldIndex()); success = true; break; // Ball @@ -100,17 +100,17 @@ export default class CommandUiHandler extends UiHandler { break; // Pokemon case Command.POKEMON: - ui.setMode(Mode.PARTY, PartyUiMode.SWITCH, (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getFieldIndex(), null, PartyUiHandler.FilterNonFainted); + ui.setMode(Mode.PARTY, PartyUiMode.SWITCH, (globalScene.getCurrentPhase() as CommandPhase).getPokemon().getFieldIndex(), null, PartyUiHandler.FilterNonFainted); success = true; break; // Run case Command.RUN: - (this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.RUN, 0); + (globalScene.getCurrentPhase() as CommandPhase).handleCommand(Command.RUN, 0); success = true; break; } } else { - (this.scene.getCurrentPhase() as CommandPhase).cancel(); + (globalScene.getCurrentPhase() as CommandPhase).cancel(); } } else { switch (button) { @@ -159,7 +159,7 @@ export default class CommandUiHandler extends UiHandler { } if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.commandsContainer.add(this.cursorObj); } diff --git a/src/ui/confirm-ui-handler.ts b/src/ui/confirm-ui-handler.ts index 2022508fc0d9..68fad7ff59d6 100644 --- a/src/ui/confirm-ui-handler.ts +++ b/src/ui/confirm-ui-handler.ts @@ -1,8 +1,8 @@ -import BattleScene from "../battle-scene"; import AbstractOptionSelectUiHandler, { OptionSelectConfig } from "./abstact-option-select-ui-handler"; import { Mode } from "./ui"; import i18next from "i18next"; import { Button } from "#enums/buttons"; +import { globalScene } from "#app/global-scene"; export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler { @@ -12,8 +12,8 @@ export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler { private switchCheck: boolean; private switchCheckCursor: integer; - constructor(scene: BattleScene) { - super(scene, Mode.CONFIRM); + constructor() { + super(Mode.CONFIRM); } getWindowWidth(): integer { @@ -54,7 +54,7 @@ export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler { const xOffset = (args.length >= 6 && args[5] !== null ? args[5] as number : 0); const yOffset = (args.length >= 7 && args[6] !== null ? args[6] as number : 0); - this.optionSelectContainer.setPosition((this.scene.game.canvas.width / 6) - 1 + xOffset, -48 + yOffset); + this.optionSelectContainer.setPosition((globalScene.game.canvas.width / 6) - 1 + xOffset, -48 + yOffset); this.setCursor(this.switchCheck ? this.switchCheckCursor : 0); return true; @@ -87,7 +87,7 @@ export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler { const xOffset = (args.length >= 4 && args[3] !== null ? args[3] as number : 0); const yOffset = (args.length >= 5 && args[4] !== null ? args[4] as number : 0); - this.optionSelectContainer.setPosition((this.scene.game.canvas.width / 6) - 1 + xOffset, -48 + yOffset); + this.optionSelectContainer.setPosition((globalScene.game.canvas.width / 6) - 1 + xOffset, -48 + yOffset); this.setCursor(this.switchCheck ? this.switchCheckCursor : 0); diff --git a/src/ui/daily-run-scoreboard.ts b/src/ui/daily-run-scoreboard.ts index bb93b1fb1f5b..0c7ac0d60b3f 100644 --- a/src/ui/daily-run-scoreboard.ts +++ b/src/ui/daily-run-scoreboard.ts @@ -1,5 +1,5 @@ import i18next from "i18next"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "../utils"; import { TextStyle, addTextObject } from "./text"; import { WindowVariant, addWindow } from "./ui-theme"; @@ -34,8 +34,8 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { private _isUpdating: boolean; - constructor(scene: BattleScene, x: number, y: number) { - super(scene, x, y); + constructor(x: number, y: number) { + super(globalScene, x, y); this._isUpdating = false; this.setup(); @@ -60,24 +60,24 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { } setup() { - const titleWindow = addWindow(this.scene, 0, 0, 114, 18, false, false, undefined, undefined, WindowVariant.THIN); + const titleWindow = addWindow(0, 0, 114, 18, false, false, undefined, undefined, WindowVariant.THIN); this.add(titleWindow); - this.titleLabel = addTextObject(this.scene, titleWindow.displayWidth / 2, titleWindow.displayHeight / 2, i18next.t("menu:loading"), TextStyle.WINDOW, { fontSize: "64px" }); + this.titleLabel = addTextObject(titleWindow.displayWidth / 2, titleWindow.displayHeight / 2, i18next.t("menu:loading"), TextStyle.WINDOW, { fontSize: "64px" }); this.titleLabel.setOrigin(0.5, 0.5); this.add(this.titleLabel); - const window = addWindow(this.scene, 0, 17, 114, 118, false, false, undefined, undefined, WindowVariant.THIN); + const window = addWindow(0, 17, 114, 118, false, false, undefined, undefined, WindowVariant.THIN); this.add(window); - this.rankingsContainer = this.scene.add.container(6, 21); + this.rankingsContainer = globalScene.add.container(6, 21); this.add(this.rankingsContainer); - this.loadingLabel = addTextObject(this.scene, window.displayWidth / 2, window.displayHeight / 2 + 16, "", TextStyle.WINDOW); + this.loadingLabel = addTextObject(window.displayWidth / 2, window.displayHeight / 2 + 16, "", TextStyle.WINDOW); this.loadingLabel.setOrigin(0.5, 0.5); this.loadingLabel.setVisible(false); - this.prevCategoryButton = this.scene.add.sprite(4, 4, "cursor_reverse"); + this.prevCategoryButton = globalScene.add.sprite(4, 4, "cursor_reverse"); this.prevCategoryButton.setOrigin(0, 0); this.add(this.prevCategoryButton); @@ -86,7 +86,7 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { this.update(this.category ? this.category - 1 : Utils.getEnumKeys(ScoreboardCategory).length - 1); }); - this.nextCategoryButton = this.scene.add.sprite(window.displayWidth - 4, 4, "cursor"); + this.nextCategoryButton = globalScene.add.sprite(window.displayWidth - 4, 4, "cursor"); this.nextCategoryButton.setOrigin(1, 0); this.add(this.nextCategoryButton); @@ -95,7 +95,7 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { this.update(this.category < Utils.getEnumKeys(ScoreboardCategory).length - 1 ? this.category + 1 : 0); }); - this.prevPageButton = this.scene.add.sprite(window.displayWidth / 2 - 16, titleWindow.displayHeight + window.displayHeight - 15, "cursor_reverse"); + this.prevPageButton = globalScene.add.sprite(window.displayWidth / 2 - 16, titleWindow.displayHeight + window.displayHeight - 15, "cursor_reverse"); this.prevPageButton.setOrigin(0, 0); this.prevPageButton.setAlpha(0.5); this.add(this.prevPageButton); @@ -107,11 +107,11 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { } }); - this.pageNumberLabel = addTextObject(this.scene, window.displayWidth / 2, titleWindow.displayHeight + window.displayHeight - 16, "1", TextStyle.WINDOW, { fontSize: "64px" }); + this.pageNumberLabel = addTextObject(window.displayWidth / 2, titleWindow.displayHeight + window.displayHeight - 16, "1", TextStyle.WINDOW, { fontSize: "64px" }); this.pageNumberLabel.setOrigin(0.5, 0); this.add(this.pageNumberLabel); - this.nextPageButton = this.scene.add.sprite(window.displayWidth / 2 + 16, titleWindow.displayHeight + window.displayHeight - 15, "cursor"); + this.nextPageButton = globalScene.add.sprite(window.displayWidth / 2 + 16, titleWindow.displayHeight + window.displayHeight - 15, "cursor"); this.nextPageButton.setOrigin(1, 0); this.nextPageButton.setAlpha(0.5); this.add(this.nextPageButton); @@ -131,20 +131,20 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { updateRankings(rankings: RankingEntry[]) { const getEntry = (rank: string, username: string, score: string, wave: string) => { - const entryContainer = this.scene.add.container(0, 0); + const entryContainer = globalScene.add.container(0, 0); - const rankLabel = addTextObject(this.scene, 0, 0, rank, TextStyle.WINDOW, { fontSize: "54px" }); + const rankLabel = addTextObject(0, 0, rank, TextStyle.WINDOW, { fontSize: "54px" }); entryContainer.add(rankLabel); - const usernameLabel = addTextObject(this.scene, 12, 0, username, TextStyle.WINDOW, { fontSize: "54px" }); + const usernameLabel = addTextObject(12, 0, username, TextStyle.WINDOW, { fontSize: "54px" }); entryContainer.add(usernameLabel); - const scoreLabel = addTextObject(this.scene, 84, 0, score, TextStyle.WINDOW, { fontSize: "54px" }); + const scoreLabel = addTextObject(84, 0, score, TextStyle.WINDOW, { fontSize: "54px" }); entryContainer.add(scoreLabel); switch (this.category) { case ScoreboardCategory.DAILY: - const waveLabel = addTextObject(this.scene, 68, 0, wave, TextStyle.WINDOW, { fontSize: "54px" }); + const waveLabel = addTextObject(68, 0, wave, TextStyle.WINDOW, { fontSize: "54px" }); entryContainer.add(waveLabel); break; case ScoreboardCategory.WEEKLY: @@ -236,7 +236,3 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { }); } } - -export interface DailyRunScoreboard { - scene: BattleScene -} diff --git a/src/ui/dropdown.ts b/src/ui/dropdown.ts index e16efe170361..ec124312e14b 100644 --- a/src/ui/dropdown.ts +++ b/src/ui/dropdown.ts @@ -1,5 +1,4 @@ -import BattleScene from "#app/battle-scene"; -import { SceneBase } from "#app/scene-base"; +import { globalScene } from "#app/global-scene"; import { addTextObject, TextStyle } from "./text"; import { addWindow, WindowVariant } from "./ui-theme"; import i18next from "i18next"; @@ -57,8 +56,8 @@ export class DropDownOption extends Phaser.GameObjects.Container { private excludeColor = 0xff5555; private unlockableColor = 0xffff00; - constructor(scene: SceneBase, val: any, labels: DropDownLabel | DropDownLabel[]) { - super(scene); + constructor(val: any, labels: DropDownLabel | DropDownLabel[]) { + super(globalScene); this.val = val; if (Array.isArray(labels)) { @@ -70,7 +69,7 @@ export class DropDownOption extends Phaser.GameObjects.Container { const currentLabel = this.labels[this.currentLabelIndex]; this.state = currentLabel.state; - this.text = addTextObject(scene, 0, 0, currentLabel.text || "", TextStyle.TOOLTIP_CONTENT); + this.text = addTextObject(0, 0, currentLabel.text || "", TextStyle.TOOLTIP_CONTENT); this.text.setOrigin(0, 0.5); this.add(this.text); @@ -96,12 +95,12 @@ export class DropDownOption extends Phaser.GameObjects.Container { */ setupToggleIcon(type: DropDownType, visible: boolean): void { if (type === DropDownType.SINGLE) { - this.toggle = this.scene.add.sprite(0, 0, "cursor"); + this.toggle = globalScene.add.sprite(0, 0, "cursor"); this.toggle.setScale(0.5); this.toggle.setOrigin(0, 0.5); this.toggle.setRotation(Math.PI / 180 * -90); } else { - this.toggle = this.scene.add.sprite(0, 0, "candy"); + this.toggle = globalScene.add.sprite(0, 0, "candy"); this.toggle.setScale(0.3); this.toggle.setOrigin(0, 0.5); } @@ -283,7 +282,7 @@ export class DropDown extends Phaser.GameObjects.Container { private lastDir: SortDirection = SortDirection.ASC; private defaultSettings: any[]; - constructor(scene: BattleScene, x: number, y: number, options: DropDownOption[], onChange: () => void, type: DropDownType = DropDownType.MULTI, optionSpacing: number = 2) { + constructor(x: number, y: number, options: DropDownOption[], onChange: () => void, type: DropDownType = DropDownType.MULTI, optionSpacing: number = 2) { const windowPadding = 5; const optionHeight = 7; const optionPaddingX = 4; @@ -291,19 +290,19 @@ export class DropDown extends Phaser.GameObjects.Container { const cursorOffset = 7; const optionWidth = 100; - super(scene, x - cursorOffset - windowPadding, y); + super(globalScene, x - cursorOffset - windowPadding, y); this.options = options; this.dropDownType = type; this.onChange = onChange; - this.cursorObj = scene.add.image(optionPaddingX + 3, 0, "cursor"); + this.cursorObj = globalScene.add.image(optionPaddingX + 3, 0, "cursor"); this.cursorObj.setScale(0.5); this.cursorObj.setOrigin(0, 0.5); this.cursorObj.setVisible(false); // For MULTI and HYBRID filter, add an ALL option at the top if (this.dropDownType === DropDownType.MULTI || this.dropDownType === DropDownType.HYBRID) { - this.options.unshift(new DropDownOption(scene, "ALL", new DropDownLabel(i18next.t("filterBar:all"), undefined, this.checkForAllOn() ? DropDownState.ON : DropDownState.OFF))); + this.options.unshift(new DropDownOption("ALL", new DropDownLabel(i18next.t("filterBar:all"), undefined, this.checkForAllOn() ? DropDownState.ON : DropDownState.OFF))); } this.defaultSettings = this.getSettings(); @@ -326,7 +325,7 @@ export class DropDown extends Phaser.GameObjects.Container { } }); - this.window = addWindow(scene, 0, 0, optionWidth, options[options.length - 1].y + optionHeight + optionPaddingY, false, false, undefined, undefined, WindowVariant.XTHIN); + this.window = addWindow(0, 0, optionWidth, options[options.length - 1].y + optionHeight + optionPaddingY, false, false, undefined, undefined, WindowVariant.XTHIN); this.add(this.window); this.add(options); this.add(this.cursorObj); diff --git a/src/ui/egg-counter-container.ts b/src/ui/egg-counter-container.ts index 21cebf5d97e0..b6fa96a6c703 100644 --- a/src/ui/egg-counter-container.ts +++ b/src/ui/egg-counter-container.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { addWindow } from "./ui-theme"; import { addTextObject, TextStyle } from "./text"; import { EggCountChangedEvent, EggEventType } from "#app/events/egg"; @@ -6,7 +6,7 @@ import EggHatchSceneHandler from "./egg-hatch-scene-handler"; /** * A container that displays the count of hatching eggs. - * Extends Phaser.GameObjects.Container. + * @extends Phaser.GameObjects.Container */ export default class EggCounterContainer extends Phaser.GameObjects.Container { private readonly WINDOW_DEFAULT_WIDTH = 37; @@ -14,21 +14,18 @@ export default class EggCounterContainer extends Phaser.GameObjects.Container { private readonly WINDOW_HEIGHT = 26; private readonly onEggCountChangedEvent = (event: Event) => this.onEggCountChanged(event); - private battleScene: BattleScene; - private eggCount: integer; + private eggCount: number; private eggCountWindow: Phaser.GameObjects.NineSlice; public eggCountText: Phaser.GameObjects.Text; /** - * @param {BattleScene} scene - The scene to which this container belongs. - * @param {number} eggCount - The number of eggs to hatch. + * @param eggCount - The number of eggs to hatch. */ - constructor(scene: BattleScene, eggCount: integer) { - super(scene, 0, 0); + constructor(eggCount: number) { + super(globalScene, 0, 0); this.eggCount = eggCount; - this.battleScene = scene; - const uiHandler = this.battleScene.ui.getHandler() as EggHatchSceneHandler; + const uiHandler = globalScene.ui.getHandler() as EggHatchSceneHandler; uiHandler.eventTarget.addEventListener(EggEventType.EGG_COUNT_CHANGED, this.onEggCountChangedEvent); this.setup(); @@ -40,15 +37,15 @@ export default class EggCounterContainer extends Phaser.GameObjects.Container { private setup(): void { const windowWidth = this.eggCount > 9 ? this.WINDOW_MEDIUM_WIDTH : this.WINDOW_DEFAULT_WIDTH; - this.eggCountWindow = addWindow(this.battleScene, 5, 5, windowWidth, this.WINDOW_HEIGHT); + this.eggCountWindow = addWindow(5, 5, windowWidth, this.WINDOW_HEIGHT); this.setVisible(this.eggCount > 1); this.add(this.eggCountWindow); - const eggSprite = this.battleScene.add.sprite(19, 18, "egg", "egg_0"); + const eggSprite = globalScene.add.sprite(19, 18, "egg", "egg_0"); eggSprite.setScale(0.32); - this.eggCountText = addTextObject(this.battleScene, 28, 13, `${this.eggCount}`, TextStyle.MESSAGE, { fontSize: "66px" }); + this.eggCountText = addTextObject(28, 13, `${this.eggCount}`, TextStyle.MESSAGE, { fontSize: "66px" }); this.eggCountText.setName("text-egg-count"); this.add(eggSprite); @@ -66,7 +63,6 @@ export default class EggCounterContainer extends Phaser.GameObjects.Container { * Handles window size, the egg count to show, and whether it should be displayed. * * @param event {@linkcode Event} being sent - * @returns void */ private onEggCountChanged(event: Event): void { const eggCountChangedEvent = event as EggCountChangedEvent; diff --git a/src/ui/egg-gacha-ui-handler.ts b/src/ui/egg-gacha-ui-handler.ts index b14f5381a846..5dd0584b19a6 100644 --- a/src/ui/egg-gacha-ui-handler.ts +++ b/src/ui/egg-gacha-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { Mode } from "./ui"; import { TextStyle, addTextObject, getEggTierTextTint, getTextStyleOptions } from "./text"; import MessageUiHandler from "./message-ui-handler"; @@ -13,6 +12,7 @@ import Overrides from "#app/overrides"; import { GachaType } from "#app/enums/gacha-types"; import i18next from "i18next"; import { EggTier } from "#enums/egg-type"; +import { globalScene } from "#app/global-scene"; export default class EggGachaUiHandler extends MessageUiHandler { private eggGachaContainer: Phaser.GameObjects.Container; @@ -39,8 +39,8 @@ export default class EggGachaUiHandler extends MessageUiHandler { private scale: number = 0.1666666667; - constructor(scene: BattleScene) { - super(scene, Mode.EGG_GACHA); + constructor() { + super(Mode.EGG_GACHA); this.gachaContainers = []; this.gachaKnobs = []; @@ -53,29 +53,29 @@ export default class EggGachaUiHandler extends MessageUiHandler { setup() { this.gachaCursor = 0; - this.scale = getTextStyleOptions(TextStyle.WINDOW, this.scene.uiTheme).scale; + this.scale = getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale; const ui = this.getUi(); - this.eggGachaContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.eggGachaContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); this.eggGachaContainer.setVisible(false); ui.add(this.eggGachaContainer); - const bg = this.scene.add.nineslice(0, 0, "default_bg", undefined, 320, 180, 0, 0, 16, 0); + const bg = globalScene.add.nineslice(0, 0, "default_bg", undefined, 320, 180, 0, 0, 16, 0); bg.setOrigin(0, 0); this.eggGachaContainer.add(bg); - const hatchFrameNames = this.scene.anims.generateFrameNames("gacha_hatch", { suffix: ".png", start: 1, end: 4 }); - if (!(this.scene.anims.exists("open"))) { - this.scene.anims.create({ + const hatchFrameNames = globalScene.anims.generateFrameNames("gacha_hatch", { suffix: ".png", start: 1, end: 4 }); + if (!(globalScene.anims.exists("open"))) { + globalScene.anims.create({ key: "open", frames: hatchFrameNames, frameRate: 12 }); } - if (!(this.scene.anims.exists("close"))) { - this.scene.anims.create({ + if (!(globalScene.anims.exists("close"))) { + globalScene.anims.create({ key: "close", frames: hatchFrameNames.reverse(), frameRate: 12 @@ -84,21 +84,21 @@ export default class EggGachaUiHandler extends MessageUiHandler { Utils.getEnumValues(GachaType).forEach((gachaType, g) => { const gachaTypeKey = GachaType[gachaType].toString().toLowerCase(); - const gachaContainer = this.scene.add.container(180 * g, 18); + const gachaContainer = globalScene.add.container(180 * g, 18); - const gacha = this.scene.add.sprite(0, 0, `gacha_${gachaTypeKey}`); + const gacha = globalScene.add.sprite(0, 0, `gacha_${gachaTypeKey}`); gacha.setOrigin(0, 0); - const gachaUnderlay = this.scene.add.sprite(115, 80, `gacha_underlay_${gachaTypeKey}`); + const gachaUnderlay = globalScene.add.sprite(115, 80, `gacha_underlay_${gachaTypeKey}`); gachaUnderlay.setOrigin(0, 0); - const gachaEggs = this.scene.add.sprite(0, 0, "gacha_eggs"); + const gachaEggs = globalScene.add.sprite(0, 0, "gacha_eggs"); gachaEggs.setOrigin(0, 0); - const gachaGlass = this.scene.add.sprite(0, 0, "gacha_glass"); + const gachaGlass = globalScene.add.sprite(0, 0, "gacha_glass"); gachaGlass.setOrigin(0, 0); - const gachaInfoContainer = this.scene.add.container(160, 46); + const gachaInfoContainer = globalScene.add.container(160, 46); const currentLanguage = i18next.resolvedLanguage ?? "en"; let gachaTextStyle = TextStyle.WINDOW_ALT; @@ -122,7 +122,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { legendaryLabelY = 0; } - const gachaUpLabel = addTextObject(this.scene, gachaX, gachaY, i18next.t("egg:legendaryUPGacha"), gachaTextStyle); + const gachaUpLabel = addTextObject(gachaX, gachaY, i18next.t("egg:legendaryUPGacha"), gachaTextStyle); gachaUpLabel.setOrigin(0, 0); gachaInfoContainer.add(gachaUpLabel); @@ -139,7 +139,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { } gachaUpLabel.setY(legendaryLabelY); - const pokemonIcon = this.scene.add.sprite(pokemonIconX, pokemonIconY, "pokemon_icons_0"); + const pokemonIcon = globalScene.add.sprite(pokemonIconX, pokemonIconY, "pokemon_icons_0"); if ([ "pt-BR" ].includes(currentLanguage)) { pokemonIcon.setX(pokemonIconX - 2); } @@ -170,9 +170,9 @@ export default class EggGachaUiHandler extends MessageUiHandler { break; } - const gachaKnob = this.scene.add.sprite(191, 89, "gacha_knob"); + const gachaKnob = globalScene.add.sprite(191, 89, "gacha_knob"); - const gachaHatch = this.scene.add.sprite(115, 73, "gacha_hatch"); + const gachaHatch = globalScene.add.sprite(115, 73, "gacha_hatch"); gachaHatch.setOrigin(0, 0); gachaContainer.add(gachaEggs); @@ -198,13 +198,13 @@ export default class EggGachaUiHandler extends MessageUiHandler { this.updateGachaInfo(g); }); - this.eggGachaOptionsContainer = this.scene.add.container(); + this.eggGachaOptionsContainer = globalScene.add.container(); - this.eggGachaOptionsContainer = this.scene.add.container((this.scene.game.canvas.width / 6), 148); + this.eggGachaOptionsContainer = globalScene.add.container((globalScene.game.canvas.width / 6), 148); this.eggGachaContainer.add(this.eggGachaOptionsContainer); - this.eggGachaOptionSelectBg = addWindow(this.scene, 0, 0, 96, 16 + 576 * this.scale); + this.eggGachaOptionSelectBg = addWindow(0, 0, 96, 16 + 576 * this.scale); this.eggGachaOptionSelectBg.setOrigin(1, 1); this.eggGachaOptionsContainer.add(this.eggGachaOptionSelectBg); @@ -231,7 +231,6 @@ export default class EggGachaUiHandler extends MessageUiHandler { }).join("\n"); const optionText = addTextObject( - this.scene, 0, 0, `${pullOptionsText}\n${i18next.t("menu:cancel")}`, @@ -246,7 +245,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { optionText.setPositionRelative(this.eggGachaOptionSelectBg, 16, 9); pullOptions.forEach((option, i) => { - const icon = this.scene.add.sprite(0, 0, "items", option.icon); + const icon = globalScene.add.sprite(0, 0, "items", option.icon); icon.setScale(3 * this.scale); icon.setPositionRelative(this.eggGachaOptionSelectBg, 20, 9 + (48 + i * 96) * this.scale); this.eggGachaOptionsContainer.add(icon); @@ -255,13 +254,13 @@ export default class EggGachaUiHandler extends MessageUiHandler { this.eggGachaContainer.add(this.eggGachaOptionsContainer); new Array(Utils.getEnumKeys(VoucherType).length).fill(null).map((_, i) => { - const container = this.scene.add.container((this.scene.game.canvas.width / 6) - 56 * i, 0); + const container = globalScene.add.container((globalScene.game.canvas.width / 6) - 56 * i, 0); - const bg = addWindow(this.scene, 0, 0, 56, 22); + const bg = addWindow(0, 0, 56, 22); bg.setOrigin(1, 0); container.add(bg); - const countLabel = addTextObject(this.scene, -48, 3, "0", TextStyle.WINDOW); + const countLabel = addTextObject(-48, 3, "0", TextStyle.WINDOW); countLabel.setOrigin(0, 0); container.add(countLabel); @@ -269,7 +268,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { const iconImage = getVoucherTypeIcon(i as VoucherType); - const icon = this.scene.add.sprite(-19, 2, "items", iconImage); + const icon = globalScene.add.sprite(-19, 2, "items", iconImage); icon.setOrigin(0, 0); icon.setScale(0.5); container.add(icon); @@ -277,25 +276,25 @@ export default class EggGachaUiHandler extends MessageUiHandler { this.eggGachaContainer.add(container); }); - this.eggGachaOverlay = this.scene.add.rectangle(0, 0, bg.displayWidth, bg.displayHeight, 0x000000); + this.eggGachaOverlay = globalScene.add.rectangle(0, 0, bg.displayWidth, bg.displayHeight, 0x000000); this.eggGachaOverlay.setOrigin(0, 0); this.eggGachaOverlay.setAlpha(0); this.eggGachaContainer.add(this.eggGachaOverlay); - this.eggGachaSummaryContainer = this.scene.add.container(0, 0); + this.eggGachaSummaryContainer = globalScene.add.container(0, 0); this.eggGachaSummaryContainer.setVisible(false); this.eggGachaContainer.add(this.eggGachaSummaryContainer); - const gachaMessageBoxContainer = this.scene.add.container(0, 148); + const gachaMessageBoxContainer = globalScene.add.container(0, 148); - const gachaMessageBox = addWindow(this.scene, 0, 0, 320, 32); + const gachaMessageBox = addWindow(0, 0, 320, 32); gachaMessageBox.setOrigin(0, 0); gachaMessageBoxContainer.add(gachaMessageBox); this.eggGachaMessageBox = gachaMessageBox; - const gachaMessageText = addTextObject(this.scene, 8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); + const gachaMessageText = addTextObject(8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); gachaMessageText.setOrigin(0, 0); gachaMessageBoxContainer.add(gachaMessageText); @@ -326,7 +325,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { this.eggGachaContainer.setVisible(true); - handleTutorial(this.scene, Tutorial.Egg_Gacha); + handleTutorial(Tutorial.Egg_Gacha); return true; } @@ -351,41 +350,41 @@ export default class EggGachaUiHandler extends MessageUiHandler { return this.showSummary(eggs!); } - const egg = this.scene.add.sprite(127, 75, "egg", `egg_${eggs![count].getKey()}`); + const egg = globalScene.add.sprite(127, 75, "egg", `egg_${eggs![count].getKey()}`); egg.setScale(0.5); this.gachaContainers[this.gachaCursor].add(egg); this.gachaContainers[this.gachaCursor].moveTo(egg, 2); const doPullAnim = () => { - this.scene.playSound("se/gacha_running", { loop: true }); - this.scene.time.delayedCall(this.getDelayValue(count ? 500 : 1250), () => { - this.scene.playSound("se/gacha_dispense"); - this.scene.time.delayedCall(this.getDelayValue(750), () => { - this.scene.sound.stopByKey("se/gacha_running"); - this.scene.tweens.add({ + globalScene.playSound("se/gacha_running", { loop: true }); + globalScene.time.delayedCall(this.getDelayValue(count ? 500 : 1250), () => { + globalScene.playSound("se/gacha_dispense"); + globalScene.time.delayedCall(this.getDelayValue(750), () => { + globalScene.sound.stopByKey("se/gacha_running"); + globalScene.tweens.add({ targets: egg, duration: this.getDelayValue(350), y: 95, ease: "Bounce.easeOut", onComplete: () => { - this.scene.time.delayedCall(this.getDelayValue(125), () => { - this.scene.playSound("se/pb_catch"); + globalScene.time.delayedCall(this.getDelayValue(125), () => { + globalScene.playSound("se/pb_catch"); this.gachaHatches[this.gachaCursor].play("open"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: egg, duration: this.getDelayValue(350), scale: 0.75, ease: "Sine.easeIn" }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: egg, y: 110, duration: this.getDelayValue(350), ease: "Back.easeOut", onComplete: () => { this.gachaHatches[this.gachaCursor].play("close"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: egg, y: 200, duration: this.getDelayValue(350), @@ -408,20 +407,20 @@ export default class EggGachaUiHandler extends MessageUiHandler { }; if (!count) { - this.scene.playSound("se/gacha_dial"); - this.scene.tweens.add({ + globalScene.playSound("se/gacha_dial"); + globalScene.tweens.add({ targets: this.gachaKnobs[this.gachaCursor], duration: this.getDelayValue(350), angle: 90, ease: "Cubic.easeInOut", onComplete: () => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.gachaKnobs[this.gachaCursor], duration: this.getDelayValue(350), angle: 0, ease: "Sine.easeInOut" }); - this.scene.time.delayedCall(this.getDelayValue(350), doPullAnim); + globalScene.time.delayedCall(this.getDelayValue(350), doPullAnim); } }); } else { @@ -438,7 +437,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { if (!eggs) { eggs = []; for (let i = 1; i <= pullCount; i++) { - const eggOptions: IEggOptions = { scene: this.scene, pulled: true, sourceType: this.gachaCursor }; + const eggOptions: IEggOptions = { pulled: true, sourceType: this.gachaCursor }; // Before creating the last egg, check if the guaranteed egg tier was already generated // if not, override the egg tier @@ -456,9 +455,9 @@ export default class EggGachaUiHandler extends MessageUiHandler { eggs = Utils.randSeedShuffle(eggs); - (this.scene.currentBattle ? this.scene.gameData.saveAll(this.scene, true, true, true) : this.scene.gameData.saveSystem()).then(success => { + (globalScene.currentBattle ? globalScene.gameData.saveAll(true, true, true) : globalScene.gameData.saveSystem()).then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } doPull(); }); @@ -490,7 +489,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { const eggScale = eggs.length < 20 ? 1 : 0.5; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.eggGachaOverlay, alpha: 0.5, ease: "Sine.easeOut", @@ -508,13 +507,13 @@ export default class EggGachaUiHandler extends MessageUiHandler { const sliceWidth = this.eggGachaOverlay.displayWidth / (cols + 2); const sliceHeight = height / (rows + 2); const yOffset = (sliceHeight / 2 * (row / Math.max(rows - 1, 1))) + sliceHeight / 4; - const ret = this.scene.add.container(sliceWidth * (col + 1) + (sliceWidth * 0.5), sliceHeight * (row + 1) + yOffset); + const ret = globalScene.add.container(sliceWidth * (col + 1) + (sliceWidth * 0.5), sliceHeight * (row + 1) + yOffset); ret.setScale(0.0001); - const eggSprite = this.scene.add.sprite(0, 0, "egg", `egg_${egg.getKey()}`); + const eggSprite = globalScene.add.sprite(0, 0, "egg", `egg_${egg.getKey()}`); ret.add(eggSprite); - const eggText = addTextObject(this.scene, 0, 14, egg.getEggDescriptor(), TextStyle.PARTY, { align: "center" }); + const eggText = addTextObject(0, 14, egg.getEggDescriptor(), TextStyle.PARTY, { align: "center" }); eggText.setOrigin(0.5, 0); eggText.setTint(getEggTierTextTint(!egg.isManaphyEgg() ? egg.tier : EggTier.EPIC)); ret.add(eggText); @@ -527,8 +526,8 @@ export default class EggGachaUiHandler extends MessageUiHandler { // Otherwise show the eggs one by one with a small delay between each eggContainers.forEach((eggContainer, index) => { const delay = !this.transitionCancelled ? this.getDelayValue(index * 100) : 0; - this.scene.time.delayedCall(delay, () => - this.scene.tweens.add({ + globalScene.time.delayedCall(delay, () => + globalScene.tweens.add({ targets: eggContainer, duration: this.getDelayValue(350), scale: eggScale, @@ -548,7 +547,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { hideSummary() { this.setTransitioning(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.eggGachaOverlay, this.eggGachaSummaryContainer ], alpha: 0, duration: this.getDelayValue(250), @@ -568,7 +567,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { const infoContainer = this.gachaInfoContainers[gachaType]; switch (gachaType as GachaType) { case GachaType.LEGENDARY: - const species = getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(this.scene, new Date().getTime())); + const species = getPokemonSpecies(getLegendaryGachaSpeciesForTimestamp(new Date().getTime())); const pokemonIcon = infoContainer.getAt(1) as Phaser.GameObjects.Sprite; pokemonIcon.setTexture(species.getIconAtlasKey(), species.getIconId(false)); break; @@ -576,13 +575,13 @@ export default class EggGachaUiHandler extends MessageUiHandler { } consumeVouchers(voucherType: VoucherType, count: integer): void { - this.scene.gameData.voucherCounts[voucherType] = Math.max(this.scene.gameData.voucherCounts[voucherType] - count, 0); + globalScene.gameData.voucherCounts[voucherType] = Math.max(globalScene.gameData.voucherCounts[voucherType] - count, 0); this.updateVoucherCounts(); } updateVoucherCounts(): void { this.voucherCountLabels.forEach((label, type) => { - label.setText(this.scene.gameData.voucherCounts[type].toString()); + label.setText(globalScene.gameData.voucherCounts[type].toString()); }); } @@ -641,10 +640,10 @@ export default class EggGachaUiHandler extends MessageUiHandler { case Button.ACTION: switch (this.cursor) { case 0: - if (!this.scene.gameData.voucherCounts[VoucherType.REGULAR] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { + if (!globalScene.gameData.voucherCounts[VoucherType.REGULAR] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { error = true; this.showError(i18next.t("egg:notEnoughVouchers")); - } else if (this.scene.gameData.eggs.length < 99 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { + } else if (globalScene.gameData.eggs.length < 99 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { if (!Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { this.consumeVouchers(VoucherType.REGULAR, 1); } @@ -656,10 +655,10 @@ export default class EggGachaUiHandler extends MessageUiHandler { } break; case 2: - if (!this.scene.gameData.voucherCounts[VoucherType.PLUS] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { + if (!globalScene.gameData.voucherCounts[VoucherType.PLUS] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { error = true; this.showError(i18next.t("egg:notEnoughVouchers")); - } else if (this.scene.gameData.eggs.length < 95 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { + } else if (globalScene.gameData.eggs.length < 95 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { if (!Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { this.consumeVouchers(VoucherType.PLUS, 1); } @@ -672,11 +671,11 @@ export default class EggGachaUiHandler extends MessageUiHandler { break; case 1: case 3: - if ((this.cursor === 1 && this.scene.gameData.voucherCounts[VoucherType.REGULAR] < 10 && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) - || (this.cursor === 3 && !this.scene.gameData.voucherCounts[VoucherType.PREMIUM] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE)) { + if ((this.cursor === 1 && globalScene.gameData.voucherCounts[VoucherType.REGULAR] < 10 && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) + || (this.cursor === 3 && !globalScene.gameData.voucherCounts[VoucherType.PREMIUM] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE)) { error = true; this.showError(i18next.t("egg:notEnoughVouchers")); - } else if (this.scene.gameData.eggs.length < 90 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { + } else if (globalScene.gameData.eggs.length < 90 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { if (this.cursor === 3) { if (!Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { this.consumeVouchers(VoucherType.PREMIUM, 1); @@ -694,10 +693,10 @@ export default class EggGachaUiHandler extends MessageUiHandler { } break; case 4: - if (!this.scene.gameData.voucherCounts[VoucherType.GOLDEN] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { + if (!globalScene.gameData.voucherCounts[VoucherType.GOLDEN] && !Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { error = true; this.showError(i18next.t("egg:notEnoughVouchers")); - } else if (this.scene.gameData.eggs.length < 75 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { + } else if (globalScene.gameData.eggs.length < 75 || Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { if (!Overrides.EGG_FREE_GACHA_PULLS_OVERRIDE) { this.consumeVouchers(VoucherType.GOLDEN, 1); } @@ -755,7 +754,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { const ret = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.eggGachaOptionsContainer.add(this.cursorObj); } @@ -775,7 +774,7 @@ export default class EggGachaUiHandler extends MessageUiHandler { this.setTransitioning(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.gachaContainers, duration: this.eggGachaContainer.visible ? 500 : 0, x: (_target, _key, _value, index) => 180 * (index - cursor), diff --git a/src/ui/egg-hatch-scene-handler.ts b/src/ui/egg-hatch-scene-handler.ts index 1bf58a786e12..189d2f295d19 100644 --- a/src/ui/egg-hatch-scene-handler.ts +++ b/src/ui/egg-hatch-scene-handler.ts @@ -1,8 +1,8 @@ -import BattleScene from "../battle-scene"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; import { Button } from "#enums/buttons"; import { EggHatchPhase } from "#app/phases/egg-hatch-phase"; +import { globalScene } from "#app/global-scene"; export default class EggHatchSceneHandler extends UiHandler { public eggHatchContainer: Phaser.GameObjects.Container; @@ -15,17 +15,17 @@ export default class EggHatchSceneHandler extends UiHandler { */ public readonly eventTarget: EventTarget = new EventTarget(); - constructor(scene: BattleScene) { - super(scene, Mode.EGG_HATCH_SCENE); + constructor() { + super(Mode.EGG_HATCH_SCENE); } setup() { - this.eggHatchContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); - this.scene.fieldUI.add(this.eggHatchContainer); + this.eggHatchContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); + globalScene.fieldUI.add(this.eggHatchContainer); - const eggLightraysAnimFrames = this.scene.anims.generateFrameNames("egg_lightrays", { start: 0, end: 3 }); - if (!(this.scene.anims.exists("egg_lightrays"))) { - this.scene.anims.create({ + const eggLightraysAnimFrames = globalScene.anims.generateFrameNames("egg_lightrays", { start: 0, end: 3 }); + if (!(globalScene.anims.exists("egg_lightrays"))) { + globalScene.anims.create({ key: "egg_lightrays", frames: eggLightraysAnimFrames, frameRate: 32 @@ -38,20 +38,20 @@ export default class EggHatchSceneHandler extends UiHandler { this.getUi().showText("", 0); - this.scene.setModifiersVisible(false); + globalScene.setModifiersVisible(false); return true; } processInput(button: Button): boolean { if (button === Button.ACTION || button === Button.CANCEL) { - const phase = this.scene.getCurrentPhase(); + const phase = globalScene.getCurrentPhase(); if (phase instanceof EggHatchPhase && phase.trySkip()) { return true; } } - return this.scene.ui.getMessageHandler().processInput(button); + return globalScene.ui.getMessageHandler().processInput(button); } setCursor(_cursor: integer): boolean { diff --git a/src/ui/egg-list-ui-handler.ts b/src/ui/egg-list-ui-handler.ts index 939f95fabe6e..1b25d55d96df 100644 --- a/src/ui/egg-list-ui-handler.ts +++ b/src/ui/egg-list-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { Mode } from "#app/ui/ui"; import PokemonIconAnimHandler, { PokemonIconAnimMode } from "#app/ui/pokemon-icon-anim-handler"; import { TextStyle, addTextObject } from "#app/ui/text"; @@ -8,6 +7,7 @@ import { Button } from "#enums/buttons"; import i18next from "i18next"; import ScrollableGridUiHandler from "#app/ui/scrollable-grid-handler"; import { ScrollBar } from "#app/ui/scroll-bar"; +import { globalScene } from "#app/global-scene"; export default class EggListUiHandler extends MessageUiHandler { private readonly ROWS = 9; @@ -28,59 +28,59 @@ export default class EggListUiHandler extends MessageUiHandler { private iconAnimHandler: PokemonIconAnimHandler; - constructor(scene: BattleScene) { - super(scene, Mode.EGG_LIST); + constructor() { + super(Mode.EGG_LIST); } setup() { const ui = this.getUi(); - this.eggListContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.eggListContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); this.eggListContainer.setVisible(false); ui.add(this.eggListContainer); - const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860); + const bgColor = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0x006860); bgColor.setOrigin(0, 0); this.eggListContainer.add(bgColor); - const eggListBg = this.scene.add.image(0, 0, "egg_list_bg"); + const eggListBg = globalScene.add.image(0, 0, "egg_list_bg"); eggListBg.setOrigin(0, 0); this.eggListContainer.add(eggListBg); - this.eggListContainer.add(addWindow(this.scene, 1, 85, 106, 22)); - this.eggListContainer.add(addWindow(this.scene, 1, 102, 106, 50, true)); - this.eggListContainer.add(addWindow(this.scene, 1, 147, 106, 32, true)); - this.eggListContainer.add(addWindow(this.scene, 107, 1, 212, 178)); + this.eggListContainer.add(addWindow(1, 85, 106, 22)); + this.eggListContainer.add(addWindow(1, 102, 106, 50, true)); + this.eggListContainer.add(addWindow(1, 147, 106, 32, true)); + this.eggListContainer.add(addWindow(107, 1, 212, 178)); this.iconAnimHandler = new PokemonIconAnimHandler(); - this.iconAnimHandler.setup(this.scene); + this.iconAnimHandler.setup(); - this.eggNameText = addTextObject(this.scene, 8, 68, "", TextStyle.SUMMARY); + this.eggNameText = addTextObject(8, 68, "", TextStyle.SUMMARY); this.eggNameText.setOrigin(0, 0); this.eggListContainer.add(this.eggNameText); - this.eggDateText = addTextObject(this.scene, 8, 91, "", TextStyle.TOOLTIP_CONTENT); + this.eggDateText = addTextObject(8, 91, "", TextStyle.TOOLTIP_CONTENT); this.eggListContainer.add(this.eggDateText); - this.eggHatchWavesText = addTextObject(this.scene, 8, 108, "", TextStyle.TOOLTIP_CONTENT); + this.eggHatchWavesText = addTextObject(8, 108, "", TextStyle.TOOLTIP_CONTENT); this.eggHatchWavesText.setWordWrapWidth(540); this.eggListContainer.add(this.eggHatchWavesText); - this.eggGachaInfoText = addTextObject(this.scene, 8, 152, "", TextStyle.TOOLTIP_CONTENT); + this.eggGachaInfoText = addTextObject(8, 152, "", TextStyle.TOOLTIP_CONTENT); this.eggGachaInfoText.setWordWrapWidth(540); this.eggListContainer.add(this.eggGachaInfoText); - this.eggListIconContainer = this.scene.add.container(113, 5); + this.eggListIconContainer = globalScene.add.container(113, 5); this.eggListContainer.add(this.eggListIconContainer); - this.cursorObj = this.scene.add.image(0, 0, "select_cursor"); + this.cursorObj = globalScene.add.image(0, 0, "select_cursor"); this.cursorObj.setOrigin(0, 0); this.eggListContainer.add(this.cursorObj); - this.eggSprite = this.scene.add.sprite(54, 37, "egg"); + this.eggSprite = globalScene.add.sprite(54, 37, "egg"); this.eggListContainer.add(this.eggSprite); - const scrollBar = new ScrollBar(this.scene, 310, 5, 4, 170, this.ROWS); + const scrollBar = new ScrollBar(310, 5, 4, 170, this.ROWS); this.eggListContainer.add(scrollBar); this.scrollGridHandler = new ScrollableGridUiHandler(this, this.ROWS, this.COLUMNS) @@ -88,15 +88,15 @@ export default class EggListUiHandler extends MessageUiHandler { .withUpdateGridCallBack(() => this.updateEggIcons()) .withUpdateSingleElementCallback((i:number) => this.setEggDetails(i)); - this.eggListMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6); + this.eggListMessageBoxContainer = globalScene.add.container(0, globalScene.game.canvas.height / 6); this.eggListMessageBoxContainer.setVisible(false); this.eggListContainer.add(this.eggListMessageBoxContainer); - const eggListMessageBox = addWindow(this.scene, 1, -1, 318, 28); + const eggListMessageBox = addWindow(1, -1, 318, 28); eggListMessageBox.setOrigin(0, 1); this.eggListMessageBoxContainer.add(eggListMessageBox); - this.message = addTextObject(this.scene, 8, -8, "", TextStyle.WINDOW, { maxLines: 1 }); + this.message = addTextObject(8, -8, "", TextStyle.WINDOW, { maxLines: 1 }); this.message.setOrigin(0, 1); this.eggListMessageBoxContainer.add(this.message); @@ -112,7 +112,7 @@ export default class EggListUiHandler extends MessageUiHandler { this.eggListContainer.setVisible(true); - this.scrollGridHandler.setTotalElements(this.scene.gameData.eggs.length); + this.scrollGridHandler.setTotalElements(globalScene.gameData.eggs.length); this.updateEggIcons(); this.setCursor(0); @@ -125,10 +125,10 @@ export default class EggListUiHandler extends MessageUiHandler { */ private initEggIcons() { this.eggIcons = []; - for (let i = 0; i < Math.min(this.ROWS * this.COLUMNS, this.scene.gameData.eggs.length); i++) { + for (let i = 0; i < Math.min(this.ROWS * this.COLUMNS, globalScene.gameData.eggs.length); i++) { const x = (i % this.COLUMNS) * 18; const y = Math.floor(i / this.COLUMNS) * 18; - const icon = this.scene.add.sprite(x - 2, y + 2, "egg_icons"); + const icon = globalScene.add.sprite(x - 2, y + 2, "egg_icons"); icon.setScale(0.5); icon.setOrigin(0, 0); this.eggListIconContainer.add(icon); @@ -141,14 +141,14 @@ export default class EggListUiHandler extends MessageUiHandler { */ private updateEggIcons() { const indexOffset = this.scrollGridHandler.getItemOffset(); - const eggsToShow = Math.min(this.eggIcons.length, this.scene.gameData.eggs.length - indexOffset); + const eggsToShow = Math.min(this.eggIcons.length, globalScene.gameData.eggs.length - indexOffset); this.eggIcons.forEach((icon, i) => { if (i !== this.cursor) { this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.NONE); } if (i < eggsToShow) { - const egg = this.scene.gameData.eggs[i + indexOffset]; + const egg = globalScene.gameData.eggs[i + indexOffset]; icon.setFrame(egg.getKey()); icon.setVisible(true); } else { @@ -162,7 +162,7 @@ export default class EggListUiHandler extends MessageUiHandler { * @param index which egg in the list to display the info for */ private setEggDetails(index: number): void { - const egg = this.scene.gameData.eggs[index]; + const egg = globalScene.gameData.eggs[index]; this.eggSprite.setFrame(`egg_${egg.getKey()}`); this.eggNameText.setText(`${i18next.t("egg:egg")} (${egg.getEggDescriptor()})`); this.eggDateText.setText( @@ -174,7 +174,7 @@ export default class EggListUiHandler extends MessageUiHandler { }) ); this.eggHatchWavesText.setText(egg.getEggHatchWavesMessage()); - this.eggGachaInfoText.setText(egg.getEggTypeDescriptor(this.scene)); + this.eggGachaInfoText.setText(egg.getEggTypeDescriptor()); } processInput(button: Button): boolean { diff --git a/src/ui/egg-summary-ui-handler.ts b/src/ui/egg-summary-ui-handler.ts index da93168926ed..372cfec280a9 100644 --- a/src/ui/egg-summary-ui-handler.ts +++ b/src/ui/egg-summary-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { Mode } from "./ui"; import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim-handler"; import MessageUiHandler from "./message-ui-handler"; @@ -10,6 +9,7 @@ import { EggHatchData } from "#app/data/egg-hatch-data"; import ScrollableGridUiHandler from "./scrollable-grid-handler"; import { HatchedPokemonContainer } from "./hatched-pokemon-container"; import { ScrollBar } from "#app/ui/scroll-bar"; +import { globalScene } from "#app/global-scene"; const iconContainerX = 112; const iconContainerY = 9; @@ -53,43 +53,43 @@ export default class EggSummaryUiHandler extends MessageUiHandler { */ public readonly eventTarget: EventTarget = new EventTarget(); - constructor(scene: BattleScene) { - super(scene, Mode.EGG_HATCH_SUMMARY); + constructor() { + super(Mode.EGG_HATCH_SUMMARY); } setup() { const ui = this.getUi(); - this.summaryContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.summaryContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); this.summaryContainer.setVisible(false); ui.add(this.summaryContainer); - this.eggHatchContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.eggHatchContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); this.eggHatchContainer.setVisible(false); ui.add(this.eggHatchContainer); this.iconAnimHandler = new PokemonIconAnimHandler(); - this.iconAnimHandler.setup(this.scene); + this.iconAnimHandler.setup(); - this.eggHatchBg = this.scene.add.image(0, 0, "egg_summary_bg"); + this.eggHatchBg = globalScene.add.image(0, 0, "egg_summary_bg"); this.eggHatchBg.setOrigin(0, 0); this.eggHatchContainer.add(this.eggHatchBg); - this.cursorObj = this.scene.add.image(0, 0, "select_cursor"); + this.cursorObj = globalScene.add.image(0, 0, "select_cursor"); this.cursorObj.setOrigin(0, 0); this.summaryContainer.add(this.cursorObj); this.pokemonContainers = []; - this.pokemonIconsContainer = this.scene.add.container(iconContainerX, iconContainerY); + this.pokemonIconsContainer = globalScene.add.container(iconContainerX, iconContainerY); this.summaryContainer.add(this.pokemonIconsContainer); - this.infoContainer = new PokemonHatchInfoContainer(this.scene, this.summaryContainer); + this.infoContainer = new PokemonHatchInfoContainer(this.summaryContainer); this.infoContainer.setup(); this.infoContainer.changeToEggSummaryLayout(); this.infoContainer.setVisible(true); this.summaryContainer.add(this.infoContainer); - const scrollBar = new ScrollBar(this.scene, iconContainerX + numCols * iconSize, iconContainerY + 3, 4, this.scene.game.canvas.height / 6 - 20, numRows); + const scrollBar = new ScrollBar(iconContainerX + numCols * iconSize, iconContainerY + 3, 4, globalScene.game.canvas.height / 6 - 20, numRows); this.summaryContainer.add(scrollBar); this.scrollGridHandler = new ScrollableGridUiHandler(this, numRows, numCols) @@ -112,19 +112,19 @@ export default class EggSummaryUiHandler extends MessageUiHandler { this.getUi().hideTooltip(); // Note: Questions on garbage collection go to @frutescens - const activeKeys = this.scene.getActiveKeys(); + const activeKeys = globalScene.getActiveKeys(); // Removing unnecessary sprites from animation manager - const animKeys = Object.keys(this.scene.anims["anims"]["entries"]); + const animKeys = Object.keys(globalScene.anims["anims"]["entries"]); animKeys.forEach(key => { if (key.startsWith("pkmn__") && !activeKeys.includes(key)) { - this.scene.anims.remove(key); + globalScene.anims.remove(key); } }); // Removing unnecessary cries from audio cache - const audioKeys = Object.keys(this.scene.cache.audio.entries.entries); + const audioKeys = Object.keys(globalScene.cache.audio.entries.entries); audioKeys.forEach(key => { if (key.startsWith("cry/") && !activeKeys.includes(key)) { - delete this.scene.cache.audio.entries.entries[key]; + delete globalScene.cache.audio.entries.entries[key]; } }); // Clears eggHatchData in EggSummaryUiHandler @@ -170,13 +170,13 @@ export default class EggSummaryUiHandler extends MessageUiHandler { this.updatePokemonIcons(); this.setCursor(0); - this.scene.playSoundWithoutBgm("evolution_fanfare"); + globalScene.playSoundWithoutBgm("evolution_fanfare"); // Prevent exiting the egg summary for 2 seconds if the egg hatching // was skipped automatically and for 1 second otherwise - const exitBlockingDuration = (this.scene.eggSkipPreference === 2) ? 2000 : 1000; + const exitBlockingDuration = (globalScene.eggSkipPreference === 2) ? 2000 : 1000; this.blockExit = true; - this.scene.time.delayedCall(exitBlockingDuration, () => this.blockExit = false); + globalScene.time.delayedCall(exitBlockingDuration, () => this.blockExit = false); return true; } @@ -196,7 +196,7 @@ export default class EggSummaryUiHandler extends MessageUiHandler { if (!hatchContainer) { const x = (i % numCols) * iconSize; const y = Math.floor(i / numCols) * iconSize; - hatchContainer = new HatchedPokemonContainer(this.scene, x, y, hatchData).setVisible(false); + hatchContainer = new HatchedPokemonContainer(x, y, hatchData).setVisible(false); this.pokemonContainers.push(hatchContainer); this.pokemonIconsContainer.add(hatchContainer); } @@ -216,7 +216,7 @@ export default class EggSummaryUiHandler extends MessageUiHandler { let error = false; if (button === Button.CANCEL) { if (!this.blockExit) { - const phase = this.scene.getCurrentPhase(); + const phase = globalScene.getCurrentPhase(); if (phase instanceof EggSummaryPhase) { phase.end(); } diff --git a/src/ui/evolution-scene-handler.ts b/src/ui/evolution-scene-handler.ts index a116a33f3733..e7866dfea532 100644 --- a/src/ui/evolution-scene-handler.ts +++ b/src/ui/evolution-scene-handler.ts @@ -1,8 +1,8 @@ -import BattleScene from "../battle-scene"; import MessageUiHandler from "./message-ui-handler"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; import { Button } from "#enums/buttons"; +import { globalScene } from "#app/global-scene"; export default class EvolutionSceneHandler extends MessageUiHandler { public evolutionContainer: Phaser.GameObjects.Container; @@ -11,8 +11,8 @@ export default class EvolutionSceneHandler extends MessageUiHandler { public canCancel: boolean; public cancelled: boolean; - constructor(scene: BattleScene) { - super(scene, Mode.EVOLUTION_SCENE); + constructor() { + super(Mode.EVOLUTION_SCENE); } setup() { @@ -21,21 +21,21 @@ export default class EvolutionSceneHandler extends MessageUiHandler { const ui = this.getUi(); - this.evolutionContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.evolutionContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); ui.add(this.evolutionContainer); - const messageBg = this.scene.add.sprite(0, 0, "bg", this.scene.windowType); + const messageBg = globalScene.add.sprite(0, 0, "bg", globalScene.windowType); messageBg.setOrigin(0, 1); messageBg.setVisible(false); ui.add(messageBg); this.messageBg = messageBg; - this.messageContainer = this.scene.add.container(12, -39); + this.messageContainer = globalScene.add.container(12, -39); this.messageContainer.setVisible(false); ui.add(this.messageContainer); - const message = addTextObject(this.scene, 0, 0, "", TextStyle.MESSAGE, { + const message = addTextObject(0, 0, "", TextStyle.MESSAGE, { maxLines: 2, wordWrap: { width: 1780 @@ -51,9 +51,9 @@ export default class EvolutionSceneHandler extends MessageUiHandler { show(_args: any[]): boolean { super.show(_args); - this.scene.ui.bringToTop(this.evolutionContainer); - this.scene.ui.bringToTop(this.messageBg); - this.scene.ui.bringToTop(this.messageContainer); + globalScene.ui.bringToTop(this.evolutionContainer); + globalScene.ui.bringToTop(this.messageBg); + globalScene.ui.bringToTop(this.messageContainer); this.messageBg.setVisible(true); this.messageContainer.setVisible(true); diff --git a/src/ui/fight-ui-handler.ts b/src/ui/fight-ui-handler.ts index eaf504495d54..97a8648b3c31 100644 --- a/src/ui/fight-ui-handler.ts +++ b/src/ui/fight-ui-handler.ts @@ -1,4 +1,5 @@ -import BattleScene, { InfoToggle } from "../battle-scene"; +import { InfoToggle } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { addTextObject, TextStyle } from "./text"; import { getTypeDamageMultiplierColor } from "#app/data/type"; import { Type } from "#enums/type"; @@ -33,79 +34,79 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { protected fieldIndex: integer = 0; protected cursor2: integer = 0; - constructor(scene: BattleScene) { - super(scene, Mode.FIGHT); + constructor() { + super(Mode.FIGHT); } setup() { const ui = this.getUi(); - this.movesContainer = this.scene.add.container(18, -38.7); + this.movesContainer = globalScene.add.container(18, -38.7); this.movesContainer.setName(FightUiHandler.MOVES_CONTAINER_NAME); ui.add(this.movesContainer); - this.moveInfoContainer = this.scene.add.container(1, 0); + this.moveInfoContainer = globalScene.add.container(1, 0); this.moveInfoContainer.setName("move-info"); ui.add(this.moveInfoContainer); - this.typeIcon = this.scene.add.sprite(this.scene.scaledCanvas.width - 57, -36, Utils.getLocalizedSpriteKey("types"), "unknown"); + this.typeIcon = globalScene.add.sprite(globalScene.scaledCanvas.width - 57, -36, Utils.getLocalizedSpriteKey("types"), "unknown"); this.typeIcon.setVisible(false); this.moveInfoContainer.add(this.typeIcon); - this.moveCategoryIcon = this.scene.add.sprite(this.scene.scaledCanvas.width - 25, -36, "categories", "physical"); + this.moveCategoryIcon = globalScene.add.sprite(globalScene.scaledCanvas.width - 25, -36, "categories", "physical"); this.moveCategoryIcon.setVisible(false); this.moveInfoContainer.add(this.moveCategoryIcon); - this.ppLabel = addTextObject(this.scene, this.scene.scaledCanvas.width - 70, -26, "PP", TextStyle.MOVE_INFO_CONTENT); + this.ppLabel = addTextObject(globalScene.scaledCanvas.width - 70, -26, "PP", TextStyle.MOVE_INFO_CONTENT); this.ppLabel.setOrigin(0.0, 0.5); this.ppLabel.setVisible(false); this.ppLabel.setText(i18next.t("fightUiHandler:pp")); this.moveInfoContainer.add(this.ppLabel); - this.ppText = addTextObject(this.scene, this.scene.scaledCanvas.width - 12, -26, "--/--", TextStyle.MOVE_INFO_CONTENT); + this.ppText = addTextObject(globalScene.scaledCanvas.width - 12, -26, "--/--", TextStyle.MOVE_INFO_CONTENT); this.ppText.setOrigin(1, 0.5); this.ppText.setVisible(false); this.moveInfoContainer.add(this.ppText); - this.powerLabel = addTextObject(this.scene, this.scene.scaledCanvas.width - 70, -18, "POWER", TextStyle.MOVE_INFO_CONTENT); + this.powerLabel = addTextObject(globalScene.scaledCanvas.width - 70, -18, "POWER", TextStyle.MOVE_INFO_CONTENT); this.powerLabel.setOrigin(0.0, 0.5); this.powerLabel.setVisible(false); this.powerLabel.setText(i18next.t("fightUiHandler:power")); this.moveInfoContainer.add(this.powerLabel); - this.powerText = addTextObject(this.scene, this.scene.scaledCanvas.width - 12, -18, "---", TextStyle.MOVE_INFO_CONTENT); + this.powerText = addTextObject(globalScene.scaledCanvas.width - 12, -18, "---", TextStyle.MOVE_INFO_CONTENT); this.powerText.setOrigin(1, 0.5); this.powerText.setVisible(false); this.moveInfoContainer.add(this.powerText); - this.accuracyLabel = addTextObject(this.scene, this.scene.scaledCanvas.width - 70, -10, "ACC", TextStyle.MOVE_INFO_CONTENT); + this.accuracyLabel = addTextObject(globalScene.scaledCanvas.width - 70, -10, "ACC", TextStyle.MOVE_INFO_CONTENT); this.accuracyLabel.setOrigin(0.0, 0.5); this.accuracyLabel.setVisible(false); this.accuracyLabel.setText(i18next.t("fightUiHandler:accuracy")); this.moveInfoContainer.add(this.accuracyLabel); - this.accuracyText = addTextObject(this.scene, this.scene.scaledCanvas.width - 12, -10, "---", TextStyle.MOVE_INFO_CONTENT); + this.accuracyText = addTextObject(globalScene.scaledCanvas.width - 12, -10, "---", TextStyle.MOVE_INFO_CONTENT); this.accuracyText.setOrigin(1, 0.5); this.accuracyText.setVisible(false); this.moveInfoContainer.add(this.accuracyText); // prepare move overlay const overlayScale = 1; - this.moveInfoOverlay = new MoveInfoOverlay(this.scene, { + this.moveInfoOverlay = new MoveInfoOverlay({ delayVisibility: true, scale: overlayScale, onSide: true, right: true, x: 0, y: -MoveInfoOverlay.getHeight(overlayScale, true), - width: (this.scene.game.canvas.width / 6) + 4, + width: (globalScene.game.canvas.width / 6) + 4, hideEffectBox: true, hideBg: true }); ui.add(this.moveInfoOverlay); // register the overlay to receive toggle events - this.scene.addInfoToggle(this.moveInfoOverlay); - this.scene.addInfoToggle(this); + globalScene.addInfoToggle(this.moveInfoOverlay); + globalScene.addInfoToggle(this); } show(args: any[]): boolean { @@ -117,7 +118,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { messageHandler.bg.setVisible(false); messageHandler.commandWindow.setVisible(false); messageHandler.movesWindowContainer.setVisible(true); - const pokemon = (this.scene.getCurrentPhase() as CommandPhase).getPokemon(); + const pokemon = (globalScene.getCurrentPhase() as CommandPhase).getPokemon(); if (pokemon.battleSummonData.turnCount <= 1) { this.setCursor(0); } else { @@ -138,14 +139,14 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { if (button === Button.CANCEL || button === Button.ACTION) { if (button === Button.ACTION) { - if ((this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, cursor, false)) { + if ((globalScene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, cursor, false)) { success = true; } else { ui.playError(); } } else { // Cannot back out of fight menu if skipToFightInput is enabled - const { battleType, mysteryEncounter } = this.scene.currentBattle; + const { battleType, mysteryEncounter } = globalScene.currentBattle; if (battleType !== BattleType.MYSTERY_ENCOUNTER || !mysteryEncounter?.skipToFightInput) { ui.setMode(Mode.COMMAND, this.fieldIndex); success = true; @@ -188,7 +189,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { this.movesContainer.setVisible(false); this.cursorObj?.setVisible(false); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.movesContainer, this.cursorObj ], duration: Utils.fixedInt(125), ease: "Sine.easeInOut", @@ -222,11 +223,11 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { } if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); ui.add(this.cursorObj); } - const pokemon = (this.scene.getCurrentPhase() as CommandPhase).getPokemon(); + const pokemon = (globalScene.getCurrentPhase() as CommandPhase).getPokemon(); const moveset = pokemon.getMoveset(); const hasMove = cursor < moveset.length; @@ -300,11 +301,11 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { } displayMoves() { - const pokemon = (this.scene.getCurrentPhase() as CommandPhase).getPokemon(); + const pokemon = (globalScene.getCurrentPhase() as CommandPhase).getPokemon(); const moveset = pokemon.getMoveset(); for (let moveIndex = 0; moveIndex < 4; moveIndex++) { - const moveText = addTextObject(this.scene, moveIndex % 2 === 0 ? 0 : 100, moveIndex < 2 ? 0 : 16, "-", TextStyle.WINDOW); + const moveText = addTextObject(moveIndex % 2 === 0 ? 0 : 100, moveIndex < 2 ? 0 : 16, "-", TextStyle.WINDOW); moveText.setName("text-empty-move"); if (moveIndex < moveset.length) { @@ -324,7 +325,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { * @returns A color or undefined if the default color should be used */ private getMoveColor(pokemon: Pokemon, pokemonMove: PokemonMove): string | undefined { - if (!this.scene.typeHints) { + if (!globalScene.typeHints) { return undefined; } @@ -362,7 +363,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { clearMoves() { this.movesContainer.removeAll(true); - const opponents = (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getOpponents(); + const opponents = (globalScene.getCurrentPhase() as CommandPhase).getPokemon().getOpponents(); opponents.forEach((opponent) => { opponent.updateEffectiveness(undefined); }); diff --git a/src/ui/filter-bar.ts b/src/ui/filter-bar.ts index bcf7409fce0f..a13fbd30cda9 100644 --- a/src/ui/filter-bar.ts +++ b/src/ui/filter-bar.ts @@ -1,9 +1,9 @@ -import BattleScene from "#app/battle-scene"; import { DropDown, DropDownType } from "./dropdown"; import { StarterContainer } from "./starter-container"; import { addTextObject, getTextColor, TextStyle } from "./text"; import { UiTheme } from "#enums/ui-theme"; import { addWindow, WindowVariant } from "./ui-theme"; +import { globalScene } from "#app/global-scene"; export enum DropDownColumn { GEN, @@ -25,22 +25,22 @@ export class FilterBar extends Phaser.GameObjects.Container { private lastCursor: number = -1; private uiTheme: UiTheme; - constructor(scene: BattleScene, x: number, y: number, width: number, height: number) { - super(scene, x, y); + constructor(x: number, y: number, width: number, height: number) { + super(globalScene, x, y); this.width = width; this.height = height; - this.window = addWindow(scene, 0, 0, width, height, false, false, undefined, undefined, WindowVariant.THIN); + this.window = addWindow(0, 0, width, height, false, false, undefined, undefined, WindowVariant.THIN); this.add(this.window); - this.cursorObj = this.scene.add.image(1, 1, "cursor"); + this.cursorObj = globalScene.add.image(1, 1, "cursor"); this.cursorObj.setScale(0.5); this.cursorObj.setVisible(false); this.cursorObj.setOrigin(0, 0); this.add(this.cursorObj); - this.uiTheme = scene.uiTheme; + this.uiTheme = globalScene.uiTheme; } /** @@ -58,7 +58,7 @@ export class FilterBar extends Phaser.GameObjects.Container { this.columns.push(column); - const filterTypesLabel = addTextObject(this.scene, 0, 3, title, TextStyle.TOOLTIP_CONTENT); + const filterTypesLabel = addTextObject(0, 3, title, TextStyle.TOOLTIP_CONTENT); this.labels.push(filterTypesLabel); this.add(filterTypesLabel); this.dropDowns.push(dropDown); diff --git a/src/ui/form-modal-ui-handler.ts b/src/ui/form-modal-ui-handler.ts index 65ee9f2db10c..9655ded4b40b 100644 --- a/src/ui/form-modal-ui-handler.ts +++ b/src/ui/form-modal-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { ModalConfig, ModalUiHandler } from "./modal-ui-handler"; import { Mode } from "./ui"; import { TextStyle, addTextInputObject, addTextObject } from "./text"; @@ -6,6 +5,7 @@ import { WindowVariant, addWindow } from "./ui-theme"; import InputText from "phaser3-rex-plugins/plugins/inputtext"; import * as Utils from "../utils"; import { Button } from "#enums/buttons"; +import { globalScene } from "#app/global-scene"; export interface FormModalConfig extends ModalConfig { errorMessage?: string; @@ -20,8 +20,8 @@ export abstract class FormModalUiHandler extends ModalUiHandler { protected tween: Phaser.Tweens.Tween; protected formLabels: Phaser.GameObjects.Text[]; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.editing = false; this.inputContainers = []; @@ -59,7 +59,7 @@ export abstract class FormModalUiHandler extends ModalUiHandler { this.updateFields(config, hasTitle); } - this.errorMessage = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * (config.length - 1) + 16 + this.getButtonTopMargin(), "", TextStyle.TOOLTIP_CONTENT); + this.errorMessage = addTextObject(10, (hasTitle ? 31 : 5) + 20 * (config.length - 1) + 16 + this.getButtonTopMargin(), "", TextStyle.TOOLTIP_CONTENT); this.errorMessage.setColor(this.getTextColor(TextStyle.SUMMARY_PINK)); this.errorMessage.setShadowColor(this.getTextColor(TextStyle.SUMMARY_PINK, true)); this.errorMessage.setVisible(false); @@ -71,20 +71,20 @@ export abstract class FormModalUiHandler extends ModalUiHandler { this.inputs = []; this.formLabels = []; fieldsConfig.forEach((config, f) => { - const label = addTextObject(this.scene, 10, (hasTitle ? 31 : 5) + 20 * f, config.label, TextStyle.TOOLTIP_CONTENT); + const label = addTextObject(10, (hasTitle ? 31 : 5) + 20 * f, config.label, TextStyle.TOOLTIP_CONTENT); label.name = "formLabel" + f; this.formLabels.push(label); this.modalContainer.add(this.formLabels[this.formLabels.length - 1]); - const inputContainer = this.scene.add.container(70, (hasTitle ? 28 : 2) + 20 * f); + const inputContainer = globalScene.add.container(70, (hasTitle ? 28 : 2) + 20 * f); inputContainer.setVisible(false); - const inputBg = addWindow(this.scene, 0, 0, 80, 16, false, false, 0, 0, WindowVariant.XTHIN); + const inputBg = addWindow(0, 0, 80, 16, false, false, 0, 0, WindowVariant.XTHIN); const isPassword = config?.isPassword; const isReadOnly = config?.isReadOnly; - const input = addTextInputObject(this.scene, 4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { type: isPassword ? "password" : "text", maxLength: isPassword ? 64 : 20, readOnly: isReadOnly }); + const input = addTextInputObject(4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { type: isPassword ? "password" : "text", maxLength: isPassword ? 64 : 20, readOnly: isReadOnly }); input.setOrigin(0, 0); inputContainer.add(inputBg); @@ -119,7 +119,7 @@ export abstract class FormModalUiHandler extends ModalUiHandler { this.modalContainer.y += 24; this.modalContainer.setAlpha(0); - this.tween = this.scene.tweens.add({ + this.tween = globalScene.tweens.add({ targets: this.modalContainer, duration: Utils.fixedInt(1000), ease: "Sine.easeInOut", diff --git a/src/ui/game-stats-ui-handler.ts b/src/ui/game-stats-ui-handler.ts index 671bed290368..b3ec0d43f6ec 100644 --- a/src/ui/game-stats-ui-handler.ts +++ b/src/ui/game-stats-ui-handler.ts @@ -1,5 +1,4 @@ import Phaser from "phaser"; -import BattleScene from "#app/battle-scene"; import { TextStyle, addTextObject } from "#app/ui/text"; import { Mode } from "#app/ui/ui"; import UiHandler from "#app/ui/ui-handler"; @@ -10,6 +9,7 @@ import { speciesStarterCosts } from "#app/data/balance/starters"; import { Button } from "#enums/buttons"; import i18next from "i18next"; import { UiTheme } from "#enums/ui-theme"; +import { globalScene } from "#app/global-scene"; interface DisplayStat { label_key?: string; @@ -222,8 +222,8 @@ export default class GameStatsUiHandler extends UiHandler { private arrowUp: Phaser.GameObjects.Sprite; private arrowDown: Phaser.GameObjects.Sprite; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.statLabels = []; this.statValues = []; @@ -232,37 +232,37 @@ export default class GameStatsUiHandler extends UiHandler { setup() { const ui = this.getUi(); - this.gameStatsContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1); + this.gameStatsContainer = globalScene.add.container(1, -(globalScene.game.canvas.height / 6) + 1); - this.gameStatsContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.gameStatsContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); - const headerBg = addWindow(this.scene, 0, 0, (this.scene.game.canvas.width / 6) - 2, 24); + const headerBg = addWindow(0, 0, (globalScene.game.canvas.width / 6) - 2, 24); headerBg.setOrigin(0, 0); - const headerText = addTextObject(this.scene, 0, 0, i18next.t("gameStatsUiHandler:stats"), TextStyle.SETTINGS_LABEL); + const headerText = addTextObject(0, 0, i18next.t("gameStatsUiHandler:stats"), TextStyle.SETTINGS_LABEL); headerText.setOrigin(0, 0); headerText.setPositionRelative(headerBg, 8, 4); - const statsBgWidth = ((this.scene.game.canvas.width / 6) - 2) / 2; + const statsBgWidth = ((globalScene.game.canvas.width / 6) - 2) / 2; const [ statsBgLeft, statsBgRight ] = new Array(2).fill(null).map((_, i) => { const width = statsBgWidth + 2; - const height = Math.floor((this.scene.game.canvas.height / 6) - headerBg.height - 2); - const statsBg = addWindow(this.scene, (statsBgWidth - 2) * i, headerBg.height, width, height, false, false, i > 0 ? -3 : 0, 1); + const height = Math.floor((globalScene.game.canvas.height / 6) - headerBg.height - 2); + const statsBg = addWindow((statsBgWidth - 2) * i, headerBg.height, width, height, false, false, i > 0 ? -3 : 0, 1); statsBg.setOrigin(0, 0); return statsBg; }); - this.statsContainer = this.scene.add.container(0, 0); + this.statsContainer = globalScene.add.container(0, 0); new Array(18).fill(null).map((_, s) => { - const statLabel = addTextObject(this.scene, 8 + (s % 2 === 1 ? statsBgWidth : 0), 28 + Math.floor(s / 2) * 16, "", TextStyle.STATS_LABEL); + const statLabel = addTextObject(8 + (s % 2 === 1 ? statsBgWidth : 0), 28 + Math.floor(s / 2) * 16, "", TextStyle.STATS_LABEL); statLabel.setOrigin(0, 0); this.statsContainer.add(statLabel); this.statLabels.push(statLabel); - const statValue = addTextObject(this.scene, (statsBgWidth * ((s % 2) + 1)) - 8, statLabel.y, "", TextStyle.STATS_VALUE); + const statValue = addTextObject((statsBgWidth * ((s % 2) + 1)) - 8, statLabel.y, "", TextStyle.STATS_VALUE); statValue.setOrigin(1, 0); this.statsContainer.add(statValue); this.statValues.push(statValue); @@ -275,10 +275,10 @@ export default class GameStatsUiHandler extends UiHandler { this.gameStatsContainer.add(this.statsContainer); // arrows to show that we can scroll through the stats - const isLegacyTheme = this.scene.uiTheme === UiTheme.LEGACY; - this.arrowDown = this.scene.add.sprite(statsBgWidth, this.scene.game.canvas.height / 6 - (isLegacyTheme ? 9 : 5), "prompt"); + const isLegacyTheme = globalScene.uiTheme === UiTheme.LEGACY; + this.arrowDown = globalScene.add.sprite(statsBgWidth, globalScene.game.canvas.height / 6 - (isLegacyTheme ? 9 : 5), "prompt"); this.gameStatsContainer.add(this.arrowDown); - this.arrowUp = this.scene.add.sprite(statsBgWidth, headerBg.height + (isLegacyTheme ? 7 : 3), "prompt"); + this.arrowUp = globalScene.add.sprite(statsBgWidth, headerBg.height + (isLegacyTheme ? 7 : 3), "prompt"); this.arrowUp.flipY = true; this.gameStatsContainer.add(this.arrowUp); @@ -298,7 +298,7 @@ export default class GameStatsUiHandler extends UiHandler { this.arrowUp.play("prompt"); this.arrowDown.play("prompt"); - if (this.scene.uiTheme === UiTheme.LEGACY) { + if (globalScene.uiTheme === UiTheme.LEGACY) { this.arrowUp.setTint(0x484848); this.arrowDown.setTint(0x484848); } @@ -318,7 +318,7 @@ export default class GameStatsUiHandler extends UiHandler { const statKeys = Object.keys(displayStats).slice(this.cursor * 2, this.cursor * 2 + 18); statKeys.forEach((key, s) => { const stat = displayStats[key] as DisplayStat; - const value = stat.sourceFunc!(this.scene.gameData); // TODO: is this bang correct? + const value = stat.sourceFunc!(globalScene.gameData); // TODO: is this bang correct? this.statLabels[s].setText(!stat.hidden || isNaN(parseInt(value)) || parseInt(value) ? i18next.t(`gameStatsUiHandler:${stat.label_key}`) : "???"); this.statValues[s].setText(value); }); @@ -348,7 +348,7 @@ export default class GameStatsUiHandler extends UiHandler { if (button === Button.CANCEL) { success = true; - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); } else { switch (button) { case Button.UP: diff --git a/src/ui/hatched-pokemon-container.ts b/src/ui/hatched-pokemon-container.ts index 9fb1fd26b30b..15057bab560b 100644 --- a/src/ui/hatched-pokemon-container.ts +++ b/src/ui/hatched-pokemon-container.ts @@ -2,7 +2,7 @@ import { EggHatchData } from "#app/data/egg-hatch-data"; import { Gender } from "#app/data/gender"; import { getVariantTint } from "#app/data/variant"; import { DexAttr } from "#app/system/game-data"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import PokemonSpecies from "#app/data/pokemon-species"; import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim-handler"; @@ -12,7 +12,6 @@ import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim * shiny variant, hidden ability, new egg move, new catch */ export class HatchedPokemonContainer extends Phaser.GameObjects.Container { - public scene: BattleScene; public species: PokemonSpecies; public icon: Phaser.GameObjects.Sprite; public shinyIcon: Phaser.GameObjects.Image; @@ -21,13 +20,12 @@ export class HatchedPokemonContainer extends Phaser.GameObjects.Container { public eggMoveIcon: Phaser.GameObjects.Image; /** - * @param scene the current {@linkcode BattleScene} * @param x x position * @param y y position * @param hatchData the {@linkcode EggHatchData} to load the icons and sprites for */ - constructor(scene: BattleScene, x: number, y: number, hatchData: EggHatchData) { - super(scene, x, y); + constructor(x: number, y: number, hatchData: EggHatchData) { + super(globalScene, x, y); const displayPokemon = hatchData.pokemon; this.species = displayPokemon.species; @@ -41,7 +39,7 @@ export class HatchedPokemonContainer extends Phaser.GameObjects.Container { const isShiny = displayPokemon.shiny; // Pokemon sprite - const pokemonIcon = this.scene.add.sprite(-offset, offset, species.getIconAtlasKey(formIndex, isShiny, variant)); + const pokemonIcon = globalScene.add.sprite(-offset, offset, species.getIconAtlasKey(formIndex, isShiny, variant)); pokemonIcon.setScale(0.5); pokemonIcon.setOrigin(0, 0); pokemonIcon.setFrame(species.getIconId(female, formIndex, isShiny, variant)); @@ -50,27 +48,27 @@ export class HatchedPokemonContainer extends Phaser.GameObjects.Container { this.add(this.icon); // Shiny icon - this.shinyIcon = this.scene.add.image(rightSideX, offset, "shiny_star_small"); + this.shinyIcon = globalScene.add.image(rightSideX, offset, "shiny_star_small"); this.shinyIcon.setOrigin(0, 0); this.shinyIcon.setScale(0.5); this.add(this.shinyIcon); // Hidden ability icon - const haIcon = this.scene.add.image(rightSideX, offset * 4, "ha_capsule"); + const haIcon = globalScene.add.image(rightSideX, offset * 4, "ha_capsule"); haIcon.setOrigin(0, 0); haIcon.setScale(0.5); this.hiddenAbilityIcon = haIcon; this.add(this.hiddenAbilityIcon); // Pokeball icon - const pokeballIcon = this.scene.add.image(rightSideX, offset * 7, "icon_owned"); + const pokeballIcon = globalScene.add.image(rightSideX, offset * 7, "icon_owned"); pokeballIcon.setOrigin(0, 0); pokeballIcon.setScale(0.5); this.pokeballIcon = pokeballIcon; this.add(this.pokeballIcon); // Egg move icon - const eggMoveIcon = this.scene.add.image(0, offset, "icon_egg_move"); + const eggMoveIcon = globalScene.add.image(0, offset, "icon_egg_move"); eggMoveIcon.setOrigin(0, 0); eggMoveIcon.setScale(0.5); this.eggMoveIcon = eggMoveIcon; diff --git a/src/ui/loading-modal-ui-handler.ts b/src/ui/loading-modal-ui-handler.ts index d86f7afd3b6b..1036869e4f9a 100644 --- a/src/ui/loading-modal-ui-handler.ts +++ b/src/ui/loading-modal-ui-handler.ts @@ -1,12 +1,11 @@ import i18next from "i18next"; -import BattleScene from "../battle-scene"; import { ModalUiHandler } from "./modal-ui-handler"; import { addTextObject, TextStyle } from "./text"; import { Mode } from "./ui"; export default class LoadingModalUiHandler extends ModalUiHandler { - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); } getModalTitle(): string { @@ -32,7 +31,7 @@ export default class LoadingModalUiHandler extends ModalUiHandler { setup(): void { super.setup(); - const label = addTextObject(this.scene, this.getWidth() / 2, this.getHeight() / 2, i18next.t("menu:loading"), TextStyle.WINDOW); + const label = addTextObject(this.getWidth() / 2, this.getHeight() / 2, i18next.t("menu:loading"), TextStyle.WINDOW); label.setOrigin(0.5, 0.5); this.modalContainer.add(label); diff --git a/src/ui/login-form-ui-handler.ts b/src/ui/login-form-ui-handler.ts index 787554236040..b81c574d6d7c 100644 --- a/src/ui/login-form-ui-handler.ts +++ b/src/ui/login-form-ui-handler.ts @@ -3,11 +3,11 @@ import { ModalConfig } from "./modal-ui-handler"; import * as Utils from "../utils"; import { Mode } from "./ui"; import i18next from "i18next"; -import BattleScene from "#app/battle-scene"; import { addTextObject, TextStyle } from "./text"; import { addWindow } from "./ui-theme"; import { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; +import { globalScene } from "#app/global-scene"; import JSZip from "jszip"; interface BuildInteractableImageOpts { @@ -33,15 +33,15 @@ export default class LoginFormUiHandler extends FormModalUiHandler { private infoContainer: Phaser.GameObjects.Container; private externalPartyBg: Phaser.GameObjects.NineSlice; private externalPartyTitle: Phaser.GameObjects.Text; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); } setup(): void { super.setup(); this.buildExternalPartyContainer(); - this.infoContainer = this.scene.add.container(0, 0); + this.infoContainer = globalScene.add.container(0, 0); this.usernameInfoImage = this.buildInteractableImage("settings_icon", "username-info-icon", { x: 20, @@ -61,11 +61,11 @@ export default class LoginFormUiHandler extends FormModalUiHandler { } private buildExternalPartyContainer() { - this.externalPartyContainer = this.scene.add.container(0, 0); - this.externalPartyContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 12, this.scene.game.canvas.height / 12), Phaser.Geom.Rectangle.Contains); - this.externalPartyTitle = addTextObject(this.scene, 0, 4, "", TextStyle.SETTINGS_LABEL); + this.externalPartyContainer = globalScene.add.container(0, 0); + this.externalPartyContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 12, globalScene.game.canvas.height / 12), Phaser.Geom.Rectangle.Contains); + this.externalPartyTitle = addTextObject(0, 4, "", TextStyle.SETTINGS_LABEL); this.externalPartyTitle.setOrigin(0.5, 0); - this.externalPartyBg = addWindow(this.scene, 0, 0, 0, 0); + this.externalPartyBg = addWindow(0, 0, 0, 0); this.externalPartyContainer.add(this.externalPartyBg); this.externalPartyContainer.add(this.externalPartyTitle); @@ -140,10 +140,10 @@ export default class LoginFormUiHandler extends FormModalUiHandler { // Prevent overlapping overrides on action modification this.submitAction = originalLoginAction; this.sanitizeInputs(); - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); const onFail = error => { - this.scene.ui.setMode(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() })); - this.scene.ui.playError(); + globalScene.ui.setMode(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() })); + globalScene.ui.playError(); }; if (!this.inputs[0].text) { return onFail(i18next.t("menu:emptyUsername")); @@ -207,9 +207,9 @@ export default class LoginFormUiHandler extends FormModalUiHandler { }); const onFail = error => { - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); - this.scene.ui.setModeForceTransition(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() })); - this.scene.ui.playError(); + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); + globalScene.ui.setModeForceTransition(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() })); + globalScene.ui.playError(); }; this.usernameInfoImage.on("pointerdown", () => { @@ -222,17 +222,17 @@ export default class LoginFormUiHandler extends FormModalUiHandler { options.push({ label: dataKeys[i].replace(keyToFind, ""), handler: () => { - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); this.infoContainer.disableInteractive(); return true; } }); } - this.scene.ui.setOverlayMode(Mode.OPTION_SELECT, { + globalScene.ui.setOverlayMode(Mode.OPTION_SELECT, { options: options, delay: 1000 }); - this.infoContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width, this.scene.game.canvas.height), Phaser.Geom.Rectangle.Contains); + this.infoContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width, globalScene.game.canvas.height), Phaser.Geom.Rectangle.Contains); } else { if (dataKeys.length > 2) { return onFail(this.ERR_TOO_MANY_SAVES); @@ -271,7 +271,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler { }); this.externalPartyContainer.setAlpha(0); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.externalPartyContainer, duration: Utils.fixedInt(1000), ease: "Sine.easeInOut", @@ -280,7 +280,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler { }); this.infoContainer.setAlpha(0); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.infoContainer, duration: Utils.fixedInt(1000), ease: "Sine.easeInOut", @@ -296,7 +296,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler { y = 0, origin = { x: 0, y: 0 } } = opts; - const img = this.scene.add.image(x, y, texture); + const img = globalScene.add.image(x, y, texture); img.setName(name); img.setOrigin(origin.x, origin.y); img.setScale(scale); diff --git a/src/ui/menu-ui-handler.ts b/src/ui/menu-ui-handler.ts index 3ce3f3b7cf07..e29fc248132f 100644 --- a/src/ui/menu-ui-handler.ts +++ b/src/ui/menu-ui-handler.ts @@ -1,4 +1,5 @@ -import BattleScene, { bypassLogin } from "../battle-scene"; +import { bypassLogin } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject, getTextStyleOptions } from "./text"; import { Mode } from "./ui"; import * as Utils from "../utils"; @@ -63,8 +64,8 @@ export default class MenuUiHandler extends MessageUiHandler { public bgmBar: BgmBar; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.excludedMenus = () => [ { condition: [ Mode.COMMAND, Mode.TITLE ].includes(mode ?? Mode.TITLE), options: [ MenuOptions.EGG_GACHA, MenuOptions.EGG_LIST ]}, @@ -86,16 +87,16 @@ export default class MenuUiHandler extends MessageUiHandler { wikiUrl = `https://wiki.pokerogue.net/${lang}:start`; } - this.bgmBar = new BgmBar(this.scene); + this.bgmBar = new BgmBar(); this.bgmBar.setup(); ui.bgmBar = this.bgmBar; - this.menuContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1); + this.menuContainer = globalScene.add.container(1, -(globalScene.game.canvas.height / 6) + 1); this.menuContainer.setName("menu"); - this.menuContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.menuContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); - this.menuOverlay = new Phaser.GameObjects.Rectangle(this.scene, -1, -1, this.scene.scaledCanvas.width, this.scene.scaledCanvas.height, 0xffffff, 0.3); + this.menuOverlay = new Phaser.GameObjects.Rectangle(globalScene, -1, -1, globalScene.scaledCanvas.width, globalScene.scaledCanvas.height, 0xffffff, 0.3); this.menuOverlay.setName("menu-overlay"); this.menuOverlay.setOrigin(0, 0); this.menuContainer.add(this.menuOverlay); @@ -110,7 +111,7 @@ export default class MenuUiHandler extends MessageUiHandler { render() { const ui = this.getUi(); this.excludedMenus = () => [ - { condition: this.scene.getCurrentPhase() instanceof SelectModifierPhase, options: [ MenuOptions.EGG_GACHA, MenuOptions.EGG_LIST ]}, + { condition: globalScene.getCurrentPhase() instanceof SelectModifierPhase, options: [ MenuOptions.EGG_GACHA, MenuOptions.EGG_LIST ]}, { condition: bypassLogin, options: [ MenuOptions.LOG_OUT ]} ]; @@ -120,15 +121,15 @@ export default class MenuUiHandler extends MessageUiHandler { return !this.excludedMenus().some(exclusion => exclusion.condition && exclusion.options.includes(m)); }); - this.optionSelectText = addTextObject(this.scene, 0, 0, this.menuOptions.map(o => `${i18next.t(`menuUiHandler:${MenuOptions[o]}`)}`).join("\n"), TextStyle.WINDOW, { maxLines: this.menuOptions.length }); + this.optionSelectText = addTextObject(0, 0, this.menuOptions.map(o => `${i18next.t(`menuUiHandler:${MenuOptions[o]}`)}`).join("\n"), TextStyle.WINDOW, { maxLines: this.menuOptions.length }); this.optionSelectText.setLineSpacing(12); - this.scale = getTextStyleOptions(TextStyle.WINDOW, (this.scene as BattleScene).uiTheme).scale; - this.menuBg = addWindow(this.scene, - (this.scene.game.canvas.width / 6) - (this.optionSelectText.displayWidth + 25), + this.scale = getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale; + this.menuBg = addWindow( + (globalScene.game.canvas.width / 6) - (this.optionSelectText.displayWidth + 25), 0, this.optionSelectText.displayWidth + 19 + 24 * this.scale, - (this.scene.game.canvas.height / 6) - 2 + (globalScene.game.canvas.height / 6) - 2 ); this.menuBg.setOrigin(0, 0); @@ -140,21 +141,21 @@ export default class MenuUiHandler extends MessageUiHandler { ui.add(this.menuContainer); - this.menuMessageBoxContainer = this.scene.add.container(0, 130); + this.menuMessageBoxContainer = globalScene.add.container(0, 130); this.menuMessageBoxContainer.setName("menu-message-box"); this.menuMessageBoxContainer.setVisible(false); // Window for general messages - this.menuMessageBox = addWindow(this.scene, 0, 0, this.defaultMessageBoxWidth, 48); + this.menuMessageBox = addWindow(0, 0, this.defaultMessageBoxWidth, 48); this.menuMessageBox.setOrigin(0, 0); this.menuMessageBoxContainer.add(this.menuMessageBox); // Full-width window used for testing dialog messages in debug mode - this.dialogueMessageBox = addWindow(this.scene, -this.textPadding, 0, this.scene.game.canvas.width / 6 + this.textPadding * 2, 49, false, false, 0, 0, WindowVariant.THIN); + this.dialogueMessageBox = addWindow(-this.textPadding, 0, globalScene.game.canvas.width / 6 + this.textPadding * 2, 49, false, false, 0, 0, WindowVariant.THIN); this.dialogueMessageBox.setOrigin(0, 0); this.menuMessageBoxContainer.add(this.dialogueMessageBox); - const menuMessageText = addTextObject(this.scene, this.textPadding, this.textPadding, "", TextStyle.WINDOW, { maxLines: 2 }); + const menuMessageText = addTextObject(this.textPadding, this.textPadding, "", TextStyle.WINDOW, { maxLines: 2 }); menuMessageText.setName("menu-message"); menuMessageText.setOrigin(0, 0); this.menuMessageBoxContainer.add(menuMessageText); @@ -203,7 +204,7 @@ export default class MenuUiHandler extends MessageUiHandler { manageDataOptions.push({ label: i18next.t("menuUiHandler:importSession"), handler: () => { - confirmSlot(i18next.t("menuUiHandler:importSlotSelect"), () => true, slotId => this.scene.gameData.importData(GameDataType.SESSION, slotId)); + confirmSlot(i18next.t("menuUiHandler:importSlotSelect"), () => true, slotId => globalScene.gameData.importData(GameDataType.SESSION, slotId)); return true; }, keepOpen: true @@ -216,7 +217,7 @@ export default class MenuUiHandler extends MessageUiHandler { Promise.all( new Array(5).fill(null).map((_, i) => { const slotId = i; - return this.scene.gameData.getSession(slotId).then(data => { + return globalScene.gameData.getSession(slotId).then(data => { if (data) { dataSlots.push(slotId); } @@ -224,7 +225,7 @@ export default class MenuUiHandler extends MessageUiHandler { })).then(() => { confirmSlot(i18next.t("menuUiHandler:exportSlotSelect"), i => dataSlots.indexOf(i) > -1, - slotId => this.scene.gameData.tryExportData(GameDataType.SESSION, slotId)); + slotId => globalScene.gameData.tryExportData(GameDataType.SESSION, slotId)); }); return true; }, @@ -233,7 +234,7 @@ export default class MenuUiHandler extends MessageUiHandler { manageDataOptions.push({ label: i18next.t("menuUiHandler:importRunHistory"), handler: () => { - this.scene.gameData.importData(GameDataType.RUN_HISTORY); + globalScene.gameData.importData(GameDataType.RUN_HISTORY); return true; }, keepOpen: true @@ -241,7 +242,7 @@ export default class MenuUiHandler extends MessageUiHandler { manageDataOptions.push({ label: i18next.t("menuUiHandler:exportRunHistory"), handler: () => { - this.scene.gameData.tryExportData(GameDataType.RUN_HISTORY); + globalScene.gameData.tryExportData(GameDataType.RUN_HISTORY); return true; }, keepOpen: true @@ -251,7 +252,7 @@ export default class MenuUiHandler extends MessageUiHandler { label: i18next.t("menuUiHandler:importData"), handler: () => { ui.revertMode(); - this.scene.gameData.importData(GameDataType.SYSTEM); + globalScene.gameData.importData(GameDataType.SYSTEM); return true; }, keepOpen: true @@ -260,7 +261,7 @@ export default class MenuUiHandler extends MessageUiHandler { manageDataOptions.push({ label: i18next.t("menuUiHandler:exportData"), handler: () => { - this.scene.gameData.tryExportData(GameDataType.SYSTEM); + globalScene.gameData.tryExportData(GameDataType.SYSTEM); return true; }, keepOpen: true @@ -311,7 +312,7 @@ export default class MenuUiHandler extends MessageUiHandler { } // Switch to the dialog test window this.setDialogTestMode(true); - ui.showText(String(i18next.t(translatedString, interpolatorOptions)), null, () => this.scene.ui.showText("", 0, () => { + ui.showText(String(i18next.t(translatedString, interpolatorOptions)), null, () => globalScene.ui.showText("", 0, () => { handler.tutorialActive = false; // Go back to the default message window this.setDialogTestMode(false); @@ -330,7 +331,7 @@ export default class MenuUiHandler extends MessageUiHandler { manageDataOptions.push({ label: i18next.t("menuUiHandler:cancel"), handler: () => { - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); return true; }, keepOpen: true @@ -421,7 +422,7 @@ export default class MenuUiHandler extends MessageUiHandler { return true; } }); - this.scene.ui.setOverlayMode(Mode.OPTION_SELECT, { + globalScene.ui.setOverlayMode(Mode.OPTION_SELECT, { options: options, delay: 0 }); @@ -433,7 +434,7 @@ export default class MenuUiHandler extends MessageUiHandler { communityOptions.push({ label: i18next.t("menuUiHandler:cancel"), handler: () => { - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); return true; } }); @@ -461,12 +462,12 @@ export default class MenuUiHandler extends MessageUiHandler { this.getUi().hideTooltip(); - this.scene.playSound("ui/menu_open"); + globalScene.playSound("ui/menu_open"); // Make sure the tutorial overlay sits above everything, but below the message box this.menuContainer.bringToTop(this.tutorialOverlay); this.menuContainer.bringToTop(this.menuMessageBoxContainer); - handleTutorial(this.scene, Tutorial.Menu); + handleTutorial(Tutorial.Menu); this.bgmBar.toggleBgmBar(true); @@ -512,7 +513,7 @@ export default class MenuUiHandler extends MessageUiHandler { success = true; break; case MenuOptions.EGG_LIST: - if (this.scene.gameData.eggs.length) { + if (globalScene.gameData.eggs.length) { ui.revertMode(); ui.setOverlayMode(Mode.EGG_LIST); success = true; @@ -541,7 +542,7 @@ export default class MenuUiHandler extends MessageUiHandler { return true; } else { pokerogueApi.unlinkDiscord().then(_isSuccess => { - updateUserInfo().then(() => this.scene.reset(true, true)); + updateUserInfo().then(() => globalScene.reset(true, true)); }); return true; } @@ -559,7 +560,7 @@ export default class MenuUiHandler extends MessageUiHandler { return true; } else { pokerogueApi.unlinkGoogle().then(_isSuccess => { - updateUserInfo().then(() => this.scene.reset(true, true)); + updateUserInfo().then(() => globalScene.reset(true, true)); }); return true; } @@ -574,18 +575,18 @@ export default class MenuUiHandler extends MessageUiHandler { success = true; break; case MenuOptions.SAVE_AND_QUIT: - if (this.scene.currentBattle) { + if (globalScene.currentBattle) { success = true; const doSaveQuit = () => { ui.setMode(Mode.LOADING, { buttonActions: [], fadeOut: () => - this.scene.gameData.saveAll(this.scene, true, true, true, true).then(() => { + globalScene.gameData.saveAll(true, true, true, true).then(() => { - this.scene.reset(true); + globalScene.reset(true); }) }); }; - if (this.scene.currentBattle.turn > 1) { + if (globalScene.currentBattle.turn > 1) { ui.showText(i18next.t("menuUiHandler:losingProgressionWarning"), null, () => { if (!this.active) { this.showText("", 0); @@ -608,11 +609,11 @@ export default class MenuUiHandler extends MessageUiHandler { const doLogout = () => { ui.setMode(Mode.LOADING, { buttonActions: [], fadeOut: () => pokerogueApi.account.logout().then(() => { - updateUserInfo().then(() => this.scene.reset(true, true)); + updateUserInfo().then(() => globalScene.reset(true, true)); }) }); }; - if (this.scene.currentBattle) { + if (globalScene.currentBattle) { ui.showText(i18next.t("menuUiHandler:losingProgressionWarning"), null, () => { if (!this.active) { this.showText("", 0); @@ -673,7 +674,7 @@ export default class MenuUiHandler extends MessageUiHandler { this.menuMessageBox.setVisible(!isDialogMode); this.dialogueMessageBox.setVisible(isDialogMode); // If we're testing dialog, we use the same word wrapping as the battle message handler - this.message.setWordWrapWidth(isDialogMode ? this.scene.ui.getMessageHandler().wordWrapWidth : this.defaultWordWrapWidth); + this.message.setWordWrapWidth(isDialogMode ? globalScene.ui.getMessageHandler().wordWrapWidth : this.defaultWordWrapWidth); this.message.setX(isDialogMode ? this.textPadding + 1 : this.textPadding); this.message.setY(isDialogMode ? this.textPadding + 0.4 : this.textPadding); } @@ -688,7 +689,7 @@ export default class MenuUiHandler extends MessageUiHandler { const ret = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.cursorObj.setOrigin(0, 0); this.menuContainer.add(this.cursorObj); } diff --git a/src/ui/message-ui-handler.ts b/src/ui/message-ui-handler.ts index 5ae4707e329b..094d41c340a9 100644 --- a/src/ui/message-ui-handler.ts +++ b/src/ui/message-ui-handler.ts @@ -1,7 +1,7 @@ -import BattleScene from "../battle-scene"; import AwaitableUiHandler from "./awaitable-ui-handler"; import { Mode } from "./ui"; import * as Utils from "../utils"; +import { globalScene } from "#app/global-scene"; export default abstract class MessageUiHandler extends AwaitableUiHandler { protected textTimer: Phaser.Time.TimerEvent | null; @@ -11,8 +11,8 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { public message: Phaser.GameObjects.Text; public prompt: Phaser.GameObjects.Sprite; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.pendingPrompt = false; } @@ -23,7 +23,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { */ initPromptSprite(container: Phaser.GameObjects.Container) { if (!this.prompt) { - const promptSprite = this.scene.add.sprite(0, 0, "prompt"); + const promptSprite = globalScene.add.sprite(0, 0, "prompt"); promptSprite.setVisible(false); promptSprite.setOrigin(0, 0); this.prompt = promptSprite; @@ -108,7 +108,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { callback = () => { const showPrompt = () => this.showPrompt(originalCallback, callbackDelay); if (promptDelay) { - this.scene.time.delayedCall(promptDelay, showPrompt); + globalScene.time.delayedCall(promptDelay, showPrompt); } else { showPrompt(); } @@ -119,7 +119,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { if (prompt) { this.pendingPrompt = true; } - this.textTimer = this.scene.time.addEvent({ + this.textTimer = globalScene.time.addEvent({ delay: delay, callback: () => { const charIndex = text.length - (this.textTimer?.repeatCount!); // TODO: is this bang correct? @@ -130,14 +130,14 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { this.message.setText(text.slice(0, charIndex)); const advance = () => { if (charVar) { - this.scene.charSprite.setVariant(charVar); + globalScene.charSprite.setVariant(charVar); } if (charSound) { - this.scene.playSound(charSound); + globalScene.playSound(charSound); } if (callback && !this.textTimer?.repeatCount) { if (callbackDelay && !prompt) { - this.textCallbackTimer = this.scene.time.delayedCall(callbackDelay, () => { + this.textCallbackTimer = globalScene.time.delayedCall(callbackDelay, () => { if (this.textCallbackTimer) { this.textCallbackTimer.destroy(); this.textCallbackTimer = null; @@ -151,7 +151,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { }; if (charDelay) { this.textTimer!.paused = true; // TODO: is the bang correct? - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: Utils.getFrameMs(charDelay), onComplete: () => { this.textTimer!.paused = false; // TODO: is the bang correct? @@ -160,11 +160,11 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { }); } else if (charFade) { this.textTimer!.paused = true; - this.scene.time.delayedCall(150, () => { - this.scene.ui.fadeOut(750).then(() => { + globalScene.time.delayedCall(150, () => { + globalScene.ui.fadeOut(750).then(() => { const delay = Utils.getFrameMs(charFade); - this.scene.time.delayedCall(delay, () => { - this.scene.ui.fadeIn(500).then(() => { + globalScene.time.delayedCall(delay, () => { + globalScene.ui.fadeIn(500).then(() => { this.textTimer!.paused = false; advance(); }); @@ -192,7 +192,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { const wrappedTextLines = this.message.runWordWrap(this.message.text).split(/\n/g); const textLinesCount = wrappedTextLines.length; const lastTextLine = wrappedTextLines[wrappedTextLines.length - 1]; - const lastLineTest = this.scene.add.text(0, 0, lastTextLine, { font: "96px emerald" }); + const lastLineTest = globalScene.add.text(0, 0, lastTextLine, { font: "96px emerald" }); lastLineTest.setScale(this.message.scale); const lastLineWidth = lastLineTest.displayWidth; lastLineTest.destroy(); @@ -209,7 +209,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler { } if (callback) { if (callbackDelay) { - this.textCallbackTimer = this.scene.time.delayedCall(callbackDelay, () => { + this.textCallbackTimer = globalScene.time.delayedCall(callbackDelay, () => { if (this.textCallbackTimer) { this.textCallbackTimer.destroy(); this.textCallbackTimer = null; diff --git a/src/ui/modal-ui-handler.ts b/src/ui/modal-ui-handler.ts index 79f1e8afeed1..4bec753ff5a6 100644 --- a/src/ui/modal-ui-handler.ts +++ b/src/ui/modal-ui-handler.ts @@ -1,9 +1,9 @@ -import BattleScene from "../battle-scene"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; import { WindowVariant, addWindow } from "./ui-theme"; import { Button } from "#enums/buttons"; +import { globalScene } from "#app/global-scene"; export interface ModalConfig { buttonActions: Function[]; @@ -17,8 +17,8 @@ export abstract class ModalUiHandler extends UiHandler { protected buttonBgs: Phaser.GameObjects.NineSlice[]; protected buttonLabels: Phaser.GameObjects.Text[]; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.buttonContainers = []; this.buttonBgs = []; @@ -42,15 +42,15 @@ export abstract class ModalUiHandler extends UiHandler { setup() { const ui = this.getUi(); - this.modalContainer = this.scene.add.container(0, 0); + this.modalContainer = globalScene.add.container(0, 0); - this.modalContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.modalContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); - this.modalBg = addWindow(this.scene, 0, 0, 0, 0); + this.modalBg = addWindow(0, 0, 0, 0); this.modalContainer.add(this.modalBg); - this.titleText = addTextObject(this.scene, 0, 4, "", TextStyle.SETTINGS_LABEL); + this.titleText = addTextObject(0, 4, "", TextStyle.SETTINGS_LABEL); this.titleText.setOrigin(0.5, 0); this.modalContainer.add(this.titleText); @@ -68,14 +68,14 @@ export abstract class ModalUiHandler extends UiHandler { private addButton(label: string) { const buttonTopMargin = this.getButtonTopMargin(); - const buttonLabel = addTextObject(this.scene, 0, 8, label, TextStyle.TOOLTIP_CONTENT); + const buttonLabel = addTextObject(0, 8, label, TextStyle.TOOLTIP_CONTENT); buttonLabel.setOrigin(0.5, 0.5); - const buttonBg = addWindow(this.scene, 0, 0, buttonLabel.getBounds().width + 8, 16, false, false, 0, 0, WindowVariant.THIN); + const buttonBg = addWindow(0, 0, buttonLabel.getBounds().width + 8, 16, false, false, 0, 0, WindowVariant.THIN); buttonBg.setOrigin(0.5, 0); buttonBg.setInteractive(new Phaser.Geom.Rectangle(0, 0, buttonBg.width, buttonBg.height), Phaser.Geom.Rectangle.Contains); - const buttonContainer = this.scene.add.container(0, buttonTopMargin); + const buttonContainer = globalScene.add.container(0, buttonTopMargin); this.buttonLabels.push(buttonLabel); this.buttonBgs.push(buttonBg); @@ -95,7 +95,7 @@ export abstract class ModalUiHandler extends UiHandler { if (args[0].hasOwnProperty("fadeOut") && typeof args[0].fadeOut === "function") { const [ marginTop, marginRight, marginBottom, marginLeft ] = this.getMargin(); - const overlay = this.scene.add.rectangle(( this.getWidth() + marginLeft + marginRight) / 2, (this.getHeight() + marginTop + marginBottom) / 2, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0); + const overlay = globalScene.add.rectangle(( this.getWidth() + marginLeft + marginRight) / 2, (this.getHeight() + marginTop + marginBottom) / 2, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0); overlay.setOrigin(0.5, 0.5); overlay.setName("rect-ui-overlay-modal"); overlay.setAlpha(0); @@ -103,7 +103,7 @@ export abstract class ModalUiHandler extends UiHandler { this.modalContainer.add(overlay); this.modalContainer.moveTo(overlay, 0); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: overlay, alpha: 1, duration: 250, @@ -136,7 +136,7 @@ export abstract class ModalUiHandler extends UiHandler { const [ marginTop, marginRight, marginBottom, marginLeft ] = this.getMargin(config); const [ width, height ] = [ this.getWidth(config), this.getHeight(config) ]; - this.modalContainer.setPosition((((this.scene.game.canvas.width / 6) - (width + (marginRight - marginLeft))) / 2), (((-this.scene.game.canvas.height / 6) - (height + (marginBottom - marginTop))) / 2)); + this.modalContainer.setPosition((((globalScene.game.canvas.width / 6) - (width + (marginRight - marginLeft))) / 2), (((-globalScene.game.canvas.height / 6) - (height + (marginBottom - marginTop))) / 2)); this.modalBg.setSize(width, height); diff --git a/src/ui/modifier-select-ui-handler.ts b/src/ui/modifier-select-ui-handler.ts index a0358b5ca8c0..79396757767b 100644 --- a/src/ui/modifier-select-ui-handler.ts +++ b/src/ui/modifier-select-ui-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { getPlayerShopModifierTypeOptionsForWave, ModifierTypeOption, TmModifierType } from "../modifier/modifier-type"; import { getPokeballAtlasKey } from "#app/data/pokeball"; import { addTextObject, getTextStyleOptions, getModifierTierTextTint, getTextColor, TextStyle } from "./text"; @@ -49,8 +49,8 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { private cursorObj: Phaser.GameObjects.Image | null; - constructor(scene: BattleScene) { - super(scene, Mode.CONFIRM); + constructor() { + super(Mode.CONFIRM); this.options = []; this.shopOptionsRows = []; @@ -59,12 +59,12 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { setup() { const ui = this.getUi(); - this.modifierContainer = this.scene.add.container(0, 0); + this.modifierContainer = globalScene.add.container(0, 0); ui.add(this.modifierContainer); const canvas = document.createElement("canvas"); const context = canvas.getContext("2d"); - const styleOptions = getTextStyleOptions(TextStyle.PARTY, (this.scene as BattleScene).uiTheme).styleOptions; + const styleOptions = getTextStyleOptions(TextStyle.PARTY, globalScene.uiTheme).styleOptions; if (context) { context.font = styleOptions.fontSize + "px " + styleOptions.fontFamily; @@ -72,78 +72,78 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.checkButtonWidth = context.measureText(i18next.t("modifierSelectUiHandler:checkTeam")).width; } - this.transferButtonContainer = this.scene.add.container((this.scene.game.canvas.width - this.checkButtonWidth) / 6 - 21, OPTION_BUTTON_YPOSITION); + this.transferButtonContainer = globalScene.add.container((globalScene.game.canvas.width - this.checkButtonWidth) / 6 - 21, OPTION_BUTTON_YPOSITION); this.transferButtonContainer.setName("transfer-btn"); this.transferButtonContainer.setVisible(false); ui.add(this.transferButtonContainer); - const transferButtonText = addTextObject(this.scene, -4, -2, i18next.t("modifierSelectUiHandler:transfer"), TextStyle.PARTY); + const transferButtonText = addTextObject(-4, -2, i18next.t("modifierSelectUiHandler:transfer"), TextStyle.PARTY); transferButtonText.setName("text-transfer-btn"); transferButtonText.setOrigin(1, 0); this.transferButtonContainer.add(transferButtonText); - this.checkButtonContainer = this.scene.add.container((this.scene.game.canvas.width) / 6 - 1, OPTION_BUTTON_YPOSITION); + this.checkButtonContainer = globalScene.add.container((globalScene.game.canvas.width) / 6 - 1, OPTION_BUTTON_YPOSITION); this.checkButtonContainer.setName("use-btn"); this.checkButtonContainer.setVisible(false); ui.add(this.checkButtonContainer); - const checkButtonText = addTextObject(this.scene, -4, -2, i18next.t("modifierSelectUiHandler:checkTeam"), TextStyle.PARTY); + const checkButtonText = addTextObject(-4, -2, i18next.t("modifierSelectUiHandler:checkTeam"), TextStyle.PARTY); checkButtonText.setName("text-use-btn"); checkButtonText.setOrigin(1, 0); this.checkButtonContainer.add(checkButtonText); - this.rerollButtonContainer = this.scene.add.container(16, OPTION_BUTTON_YPOSITION); + this.rerollButtonContainer = globalScene.add.container(16, OPTION_BUTTON_YPOSITION); this.rerollButtonContainer.setName("reroll-brn"); this.rerollButtonContainer.setVisible(false); ui.add(this.rerollButtonContainer); - const rerollButtonText = addTextObject(this.scene, -4, -2, i18next.t("modifierSelectUiHandler:reroll"), TextStyle.PARTY); + const rerollButtonText = addTextObject(-4, -2, i18next.t("modifierSelectUiHandler:reroll"), TextStyle.PARTY); rerollButtonText.setName("text-reroll-btn"); rerollButtonText.setOrigin(0, 0); this.rerollButtonContainer.add(rerollButtonText); - this.rerollCostText = addTextObject(this.scene, 0, 0, "", TextStyle.MONEY); + this.rerollCostText = addTextObject(0, 0, "", TextStyle.MONEY); this.rerollCostText.setName("text-reroll-cost"); this.rerollCostText.setOrigin(0, 0); this.rerollCostText.setPositionRelative(rerollButtonText, rerollButtonText.displayWidth + 5, 1); this.rerollButtonContainer.add(this.rerollCostText); - this.lockRarityButtonContainer = this.scene.add.container(16, OPTION_BUTTON_YPOSITION); + this.lockRarityButtonContainer = globalScene.add.container(16, OPTION_BUTTON_YPOSITION); this.lockRarityButtonContainer.setVisible(false); ui.add(this.lockRarityButtonContainer); - this.lockRarityButtonText = addTextObject(this.scene, -4, -2, i18next.t("modifierSelectUiHandler:lockRarities"), TextStyle.PARTY); + this.lockRarityButtonText = addTextObject(-4, -2, i18next.t("modifierSelectUiHandler:lockRarities"), TextStyle.PARTY); this.lockRarityButtonText.setOrigin(0, 0); this.lockRarityButtonContainer.add(this.lockRarityButtonText); - this.continueButtonContainer = this.scene.add.container((this.scene.game.canvas.width / 12), -(this.scene.game.canvas.height / 12)); + this.continueButtonContainer = globalScene.add.container((globalScene.game.canvas.width / 12), -(globalScene.game.canvas.height / 12)); this.continueButtonContainer.setVisible(false); ui.add(this.continueButtonContainer); // Create continue button - const continueButtonText = addTextObject(this.scene, -24, 5, i18next.t("modifierSelectUiHandler:continueNextWaveButton"), TextStyle.MESSAGE); + const continueButtonText = addTextObject(-24, 5, i18next.t("modifierSelectUiHandler:continueNextWaveButton"), TextStyle.MESSAGE); continueButtonText.setName("text-continue-btn"); this.continueButtonContainer.add(continueButtonText); // prepare move overlay const overlayScale = 1; - this.moveInfoOverlay = new MoveInfoOverlay(this.scene, { + this.moveInfoOverlay = new MoveInfoOverlay({ delayVisibility: true, scale: overlayScale, onSide: true, right: true, x: 1, y: -MoveInfoOverlay.getHeight(overlayScale, true) - 1, - width: (this.scene.game.canvas.width / 6) - 2, + width: (globalScene.game.canvas.width / 6) - 2, }); ui.add(this.moveInfoOverlay); // register the overlay to receive toggle events - this.scene.addInfoToggle(this.moveInfoOverlay); + globalScene.addInfoToggle(this.moveInfoOverlay); } show(args: any[]): boolean { - this.scene.disableMenu = false; + globalScene.disableMenu = false; if (this.active) { if (args.length >= 3) { @@ -164,8 +164,8 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.player = args[0]; - const partyHasHeldItem = this.player && !!this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.isTransferable).length; - const canLockRarities = !!this.scene.findModifier(m => m instanceof LockModifierTiersModifier); + const partyHasHeldItem = this.player && !!globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.isTransferable).length; + const canLockRarities = !!globalScene.findModifier(m => m instanceof LockModifierTiersModifier); this.transferButtonContainer.setVisible(false); this.transferButtonContainer.setAlpha(0); @@ -189,19 +189,19 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.updateRerollCostText(); const typeOptions = args[1] as ModifierTypeOption[]; - const removeHealShop = this.scene.gameMode.hasNoShop; - const baseShopCost = new IntegerHolder(this.scene.getWaveMoneyAmount(1)); - this.scene.applyModifier(HealShopCostModifier, true, baseShopCost); + const removeHealShop = globalScene.gameMode.hasNoShop; + const baseShopCost = new IntegerHolder(globalScene.getWaveMoneyAmount(1)); + globalScene.applyModifier(HealShopCostModifier, true, baseShopCost); const shopTypeOptions = !removeHealShop - ? getPlayerShopModifierTypeOptionsForWave(this.scene.currentBattle.waveIndex, baseShopCost.value) + ? getPlayerShopModifierTypeOptionsForWave(globalScene.currentBattle.waveIndex, baseShopCost.value) : []; const optionsYOffset = shopTypeOptions.length > SHOP_OPTIONS_ROW_LIMIT ? -SINGLE_SHOP_ROW_YOFFSET : -DOUBLE_SHOP_ROW_YOFFSET; for (let m = 0; m < typeOptions.length; m++) { - const sliceWidth = (this.scene.game.canvas.width / 6) / (typeOptions.length + 2); - const option = new ModifierOption(this.scene, sliceWidth * (m + 1) + (sliceWidth * 0.5), -this.scene.game.canvas.height / 12 + optionsYOffset, typeOptions[m]); + const sliceWidth = (globalScene.game.canvas.width / 6) / (typeOptions.length + 2); + const option = new ModifierOption(sliceWidth * (m + 1) + (sliceWidth * 0.5), -globalScene.game.canvas.height / 12 + optionsYOffset, typeOptions[m]); option.setScale(0.5); - this.scene.add.existing(option); + globalScene.add.existing(option); this.modifierContainer.add(option); this.options.push(option); } @@ -215,10 +215,10 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { const row = m < SHOP_OPTIONS_ROW_LIMIT ? 0 : 1; const col = m < SHOP_OPTIONS_ROW_LIMIT ? m : m - SHOP_OPTIONS_ROW_LIMIT; const rowOptions = shopTypeOptions.slice(row ? SHOP_OPTIONS_ROW_LIMIT : 0, row ? undefined : SHOP_OPTIONS_ROW_LIMIT); - const sliceWidth = (this.scene.game.canvas.width / 6) / (rowOptions.length + 2); - const option = new ModifierOption(this.scene, sliceWidth * (col + 1) + (sliceWidth * 0.5), ((-this.scene.game.canvas.height / 12) - (this.scene.game.canvas.height / 32) - (42 - (28 * row - 1))), shopTypeOptions[m]); + const sliceWidth = (globalScene.game.canvas.width / 6) / (rowOptions.length + 2); + const option = new ModifierOption(sliceWidth * (col + 1) + (sliceWidth * 0.5), ((-globalScene.game.canvas.height / 12) - (globalScene.game.canvas.height / 32) - (42 - (28 * row - 1))), shopTypeOptions[m]); option.setScale(0.375); - this.scene.add.existing(option); + globalScene.add.existing(option); this.modifierContainer.add(option); if (row >= this.shopOptionsRows.length) { @@ -230,17 +230,17 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { const maxUpgradeCount = typeOptions.map(to => to.upgradeCount).reduce((max, current) => Math.max(current, max), 0); /* Force updateModifiers without pokemonSpecificModifiers */ - this.scene.getModifierBar().updateModifiers(this.scene.modifiers, true); + globalScene.getModifierBar().updateModifiers(globalScene.modifiers, true); /* Multiplies the appearance duration by the speed parameter so that it is always constant, and avoids "flashbangs" at game speed x5 */ - this.scene.showShopOverlay(750 * this.scene.gameSpeed); - this.scene.updateAndShowText(750); - this.scene.updateBiomeWaveText(); - this.scene.updateMoneyText(); + globalScene.showShopOverlay(750 * globalScene.gameSpeed); + globalScene.updateAndShowText(750); + globalScene.updateBiomeWaveText(); + globalScene.updateMoneyText(); let i = 0; - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ ease: "Sine.easeIn", duration: 1250, onUpdate: t => { @@ -254,17 +254,17 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { } }); - this.scene.time.delayedCall(1000 + maxUpgradeCount * 2000, () => { + globalScene.time.delayedCall(1000 + maxUpgradeCount * 2000, () => { for (const shopOption of this.shopOptionsRows.flat()) { shopOption.show(0, 0); } }); - this.scene.time.delayedCall(4000 + maxUpgradeCount * 2000, () => { + globalScene.time.delayedCall(4000 + maxUpgradeCount * 2000, () => { if (partyHasHeldItem) { this.transferButtonContainer.setAlpha(0); this.transferButtonContainer.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.transferButtonContainer, alpha: 1, duration: 250 @@ -280,34 +280,34 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.continueButtonContainer.setVisible(this.rerollCost < 0); this.lockRarityButtonContainer.setVisible(canLockRarities); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.checkButtonContainer, this.continueButtonContainer ], alpha: 1, duration: 250 }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.rerollButtonContainer, this.lockRarityButtonContainer ], alpha: this.rerollCost < 0 ? 0.5 : 1, duration: 250 }); const updateCursorTarget = () => { - if (this.scene.shopCursorTarget === ShopCursorTarget.CHECK_TEAM) { + if (globalScene.shopCursorTarget === ShopCursorTarget.CHECK_TEAM) { this.setRowCursor(0); this.setCursor(2); - } else if ((this.scene.shopCursorTarget === ShopCursorTarget.SHOP) && this.scene.gameMode.hasNoShop) { + } else if ((globalScene.shopCursorTarget === ShopCursorTarget.SHOP) && globalScene.gameMode.hasNoShop) { this.setRowCursor(ShopCursorTarget.REWARDS); this.setCursor(0); } else { - this.setRowCursor(this.scene.shopCursorTarget); + this.setRowCursor(globalScene.shopCursorTarget); this.setCursor(0); } }; updateCursorTarget(); - handleTutorial(this.scene, Tutorial.Select_Item).then((res) => { + handleTutorial(Tutorial.Select_Item).then((res) => { if (res) { updateCursorTarget(); } @@ -446,7 +446,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { const ret = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.modifierContainer.add(this.cursorObj); } @@ -460,22 +460,22 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { if (this.rowCursor === 1 && options.length === 0) { // Continue button when no shop items this.cursorObj.setScale(1.25); - this.cursorObj.setPosition((this.scene.game.canvas.width / 18) + 23, (-this.scene.game.canvas.height / 12) - (this.shopOptionsRows.length > 1 ? SINGLE_SHOP_ROW_YOFFSET - 2 : DOUBLE_SHOP_ROW_YOFFSET - 2)); + this.cursorObj.setPosition((globalScene.game.canvas.width / 18) + 23, (-globalScene.game.canvas.height / 12) - (this.shopOptionsRows.length > 1 ? SINGLE_SHOP_ROW_YOFFSET - 2 : DOUBLE_SHOP_ROW_YOFFSET - 2)); ui.showText(i18next.t("modifierSelectUiHandler:continueNextWaveDescription")); return ret; } - const sliceWidth = (this.scene.game.canvas.width / 6) / (options.length + 2); + const sliceWidth = (globalScene.game.canvas.width / 6) / (options.length + 2); if (this.rowCursor < 2) { // Cursor on free items - this.cursorObj.setPosition(sliceWidth * (cursor + 1) + (sliceWidth * 0.5) - 20, (-this.scene.game.canvas.height / 12) - (this.shopOptionsRows.length > 1 ? SINGLE_SHOP_ROW_YOFFSET - 2 : DOUBLE_SHOP_ROW_YOFFSET - 2)); + this.cursorObj.setPosition(sliceWidth * (cursor + 1) + (sliceWidth * 0.5) - 20, (-globalScene.game.canvas.height / 12) - (this.shopOptionsRows.length > 1 ? SINGLE_SHOP_ROW_YOFFSET - 2 : DOUBLE_SHOP_ROW_YOFFSET - 2)); } else { // Cursor on paying items - this.cursorObj.setPosition(sliceWidth * (cursor + 1) + (sliceWidth * 0.5) - 16, (-this.scene.game.canvas.height / 12 - this.scene.game.canvas.height / 32) - (-14 + 28 * (this.rowCursor - (this.shopOptionsRows.length - 1)))); + this.cursorObj.setPosition(sliceWidth * (cursor + 1) + (sliceWidth * 0.5) - 16, (-globalScene.game.canvas.height / 12 - globalScene.game.canvas.height / 32) - (-14 + 28 * (this.rowCursor - (this.shopOptionsRows.length - 1)))); } const type = options[this.cursor].modifierTypeOption.type; - type && ui.showText(type.getDescription(this.scene)); + type && ui.showText(type.getDescription()); if (type instanceof TmModifierType) { // prepare the move overlay to be shown with the toggle this.moveInfoOverlay.show(allMoves[type.moveId]); @@ -484,10 +484,10 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.cursorObj.setPosition(6, this.lockRarityButtonContainer.visible ? OPTION_BUTTON_YPOSITION - 8 : OPTION_BUTTON_YPOSITION + 4); ui.showText(i18next.t("modifierSelectUiHandler:rerollDesc")); } else if (cursor === 1) { - this.cursorObj.setPosition((this.scene.game.canvas.width - this.transferButtonWidth - this.checkButtonWidth) / 6 - 30, OPTION_BUTTON_YPOSITION + 4); + this.cursorObj.setPosition((globalScene.game.canvas.width - this.transferButtonWidth - this.checkButtonWidth) / 6 - 30, OPTION_BUTTON_YPOSITION + 4); ui.showText(i18next.t("modifierSelectUiHandler:transferDesc")); } else if (cursor === 2) { - this.cursorObj.setPosition((this.scene.game.canvas.width - this.checkButtonWidth) / 6 - 10, OPTION_BUTTON_YPOSITION + 4); + this.cursorObj.setPosition((globalScene.game.canvas.width - this.checkButtonWidth) / 6 - 10, OPTION_BUTTON_YPOSITION + 4); ui.showText(i18next.t("modifierSelectUiHandler:checkTeamDesc")); } else { this.cursorObj.setPosition(6, OPTION_BUTTON_YPOSITION + 4); @@ -558,9 +558,9 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { } else { this.rerollCostText.setVisible(true); } - const canReroll = this.scene.money >= this.rerollCost; + const canReroll = globalScene.money >= this.rerollCost; - const formattedMoney = Utils.formatMoney(this.scene.moneyFormat, this.rerollCost); + const formattedMoney = Utils.formatMoney(globalScene.moneyFormat, this.rerollCost); this.rerollCostText.setText(i18next.t("modifierSelectUiHandler:rerollCost", { formattedMoney })); this.rerollCostText.setColor(this.getTextColor(canReroll ? TextStyle.MONEY : TextStyle.PARTY_RED)); @@ -568,7 +568,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { } updateLockRaritiesText(): void { - const textStyle = this.scene.lockModifierTiers ? TextStyle.SUMMARY_BLUE : TextStyle.PARTY; + const textStyle = globalScene.lockModifierTiers ? TextStyle.SUMMARY_BLUE : TextStyle.PARTY; this.lockRarityButtonText.setColor(this.getTextColor(textStyle)); this.lockRarityButtonText.setShadowColor(this.getTextColor(textStyle, true)); } @@ -588,17 +588,17 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.rowCursor = 0; /* Multiplies the fade time duration by the speed parameter so that it is always constant, and avoids "flashbangs" at game speed x5 */ - this.scene.hideShopOverlay(750 * this.scene.gameSpeed); - this.scene.hideLuckText(250); + globalScene.hideShopOverlay(750 * globalScene.gameSpeed); + globalScene.hideLuckText(250); /* Normally already called just after the shop, but not sure if it happens in 100% of cases */ - this.scene.getModifierBar().updateModifiers(this.scene.modifiers); + globalScene.getModifierBar().updateModifiers(globalScene.modifiers); const options = this.options.concat(this.shopOptionsRows.flat()); this.options.splice(0, this.options.length); this.shopOptionsRows.splice(0, this.shopOptionsRows.length); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: options, scale: 0.01, duration: 250, @@ -608,7 +608,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { [ this.rerollButtonContainer, this.checkButtonContainer, this.transferButtonContainer, this.lockRarityButtonContainer, this.continueButtonContainer ].forEach(container => { if (container.visible) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: container, alpha: 0, duration: 250, @@ -643,8 +643,8 @@ class ModifierOption extends Phaser.GameObjects.Container { private itemText: Phaser.GameObjects.Text; private itemCostText: Phaser.GameObjects.Text; - constructor(scene: BattleScene, x: number, y: number, modifierTypeOption: ModifierTypeOption) { - super(scene, x, y); + constructor(x: number, y: number, modifierTypeOption: ModifierTypeOption) { + super(globalScene, x, y); this.modifierTypeOption = modifierTypeOption; @@ -654,7 +654,7 @@ class ModifierOption extends Phaser.GameObjects.Container { setup() { if (!this.modifierTypeOption.cost) { const getPb = (): Phaser.GameObjects.Sprite => { - const pb = this.scene.add.sprite(0, -182, "pb", this.getPbAtlasKey(-this.modifierTypeOption.upgradeCount)); + const pb = globalScene.add.sprite(0, -182, "pb", this.getPbAtlasKey(-this.modifierTypeOption.upgradeCount)); pb.setScale(2); return pb; }; @@ -667,13 +667,13 @@ class ModifierOption extends Phaser.GameObjects.Container { this.add(this.pbTint); } - this.itemContainer = this.scene.add.container(0, 0); + this.itemContainer = globalScene.add.container(0, 0); this.itemContainer.setScale(0.5); this.itemContainer.setAlpha(0); this.add(this.itemContainer); const getItem = () => { - const item = this.scene.add.sprite(0, 0, "items", this.modifierTypeOption.type?.iconImage); + const item = globalScene.add.sprite(0, 0, "items", this.modifierTypeOption.type?.iconImage); return item; }; @@ -686,14 +686,14 @@ class ModifierOption extends Phaser.GameObjects.Container { this.itemContainer.add(this.itemTint); } - this.itemText = addTextObject(this.scene, 0, 35, this.modifierTypeOption.type?.name!, TextStyle.PARTY, { align: "center" }); // TODO: is this bang correct? + this.itemText = addTextObject(0, 35, this.modifierTypeOption.type?.name!, TextStyle.PARTY, { align: "center" }); // TODO: is this bang correct? this.itemText.setOrigin(0.5, 0); this.itemText.setAlpha(0); this.itemText.setTint(this.modifierTypeOption.type?.tier ? getModifierTierTextTint(this.modifierTypeOption.type?.tier) : undefined); this.add(this.itemText); if (this.modifierTypeOption.cost) { - this.itemCostText = addTextObject(this.scene, 0, 45, "", TextStyle.MONEY, { align: "center" }); + this.itemCostText = addTextObject(0, 45, "", TextStyle.MONEY, { align: "center" }); this.itemCostText.setOrigin(0.5, 0); this.itemCostText.setAlpha(0); @@ -705,7 +705,7 @@ class ModifierOption extends Phaser.GameObjects.Container { show(remainingDuration: integer, upgradeCountOffset: integer) { if (!this.modifierTypeOption.cost) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pb, y: 0, duration: 1250, @@ -716,18 +716,18 @@ class ModifierOption extends Phaser.GameObjects.Container { let bounceCount = 0; let bounce = false; - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ from: 1, to: 0, duration: 1250, ease: "Bounce.Out", onUpdate: t => { - if (!this.scene) { + if (!globalScene) { return; } const value = t.getValue(); if (!bounce && value > lastValue) { - (this.scene as BattleScene).playSound("se/pb_bounce_1", { volume: 1 / ++bounceCount }); + globalScene.playSound("se/pb_bounce_1", { volume: 1 / ++bounceCount }); bounce = true; } else if (bounce && value < lastValue) { bounce = false; @@ -738,20 +738,20 @@ class ModifierOption extends Phaser.GameObjects.Container { for (let u = 0; u < this.modifierTypeOption.upgradeCount; u++) { const upgradeIndex = u; - this.scene.time.delayedCall(remainingDuration - 2000 * (this.modifierTypeOption.upgradeCount - (upgradeIndex + 1 + upgradeCountOffset)), () => { - (this.scene as BattleScene).playSound("se/upgrade", { rate: 1 + 0.25 * upgradeIndex }); + globalScene.time.delayedCall(remainingDuration - 2000 * (this.modifierTypeOption.upgradeCount - (upgradeIndex + 1 + upgradeCountOffset)), () => { + globalScene.playSound("se/upgrade", { rate: 1 + 0.25 * upgradeIndex }); this.pbTint.setPosition(this.pb.x, this.pb.y); this.pbTint.setTintFill(0xFFFFFF); this.pbTint.setAlpha(0); this.pbTint.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pbTint, alpha: 1, duration: 1000, ease: "Sine.easeIn", onComplete: () => { this.pb.setTexture("pb", this.getPbAtlasKey(-this.modifierTypeOption.upgradeCount + (upgradeIndex + 1))); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pbTint, alpha: 0, duration: 750, @@ -766,16 +766,16 @@ class ModifierOption extends Phaser.GameObjects.Container { } } - this.scene.time.delayedCall(remainingDuration + 2000, () => { - if (!this.scene) { + globalScene.time.delayedCall(remainingDuration + 2000, () => { + if (!globalScene) { return; } if (!this.modifierTypeOption.cost) { this.pb.setTexture("pb", `${this.getPbAtlasKey(0)}_open`); - (this.scene as BattleScene).playSound("se/pb_rel"); + globalScene.playSound("se/pb_rel"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pb, duration: 500, delay: 250, @@ -785,7 +785,7 @@ class ModifierOption extends Phaser.GameObjects.Container { }); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.itemContainer, duration: 500, ease: "Elastic.Out", @@ -793,7 +793,7 @@ class ModifierOption extends Phaser.GameObjects.Container { alpha: 1 }); if (!this.modifierTypeOption.cost) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.itemTint, alpha: 0, duration: 500, @@ -801,7 +801,7 @@ class ModifierOption extends Phaser.GameObjects.Container { onComplete: () => this.itemTint.destroy() }); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.itemText, duration: 500, alpha: 1, @@ -809,7 +809,7 @@ class ModifierOption extends Phaser.GameObjects.Container { ease: "Cubic.easeInOut" }); if (this.itemCostText) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.itemCostText, duration: 500, alpha: 1, @@ -825,14 +825,13 @@ class ModifierOption extends Phaser.GameObjects.Container { } updateCostText(): void { - const scene = this.scene as BattleScene; const cost = Overrides.WAIVE_ROLL_FEE_OVERRIDE ? 0 : this.modifierTypeOption.cost; - const textStyle = cost <= scene.money ? TextStyle.MONEY : TextStyle.PARTY_RED; + const textStyle = cost <= globalScene.money ? TextStyle.MONEY : TextStyle.PARTY_RED; - const formattedMoney = Utils.formatMoney(scene.moneyFormat, cost); + const formattedMoney = Utils.formatMoney(globalScene.moneyFormat, cost); this.itemCostText.setText(i18next.t("modifierSelectUiHandler:itemCost", { formattedMoney })); - this.itemCostText.setColor(getTextColor(textStyle, false, scene.uiTheme)); - this.itemCostText.setShadowColor(getTextColor(textStyle, true, scene.uiTheme)); + this.itemCostText.setColor(getTextColor(textStyle, false, globalScene.uiTheme)); + this.itemCostText.setShadowColor(getTextColor(textStyle, true, globalScene.uiTheme)); } } diff --git a/src/ui/move-info-overlay.ts b/src/ui/move-info-overlay.ts index d9c4200ea9b3..744a447659f8 100644 --- a/src/ui/move-info-overlay.ts +++ b/src/ui/move-info-overlay.ts @@ -1,4 +1,5 @@ -import BattleScene, { InfoToggle } from "../battle-scene"; +import { InfoToggle } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { TextStyle, addTextObject } from "./text"; import { addWindow } from "./ui-theme"; import * as Utils from "../utils"; @@ -46,23 +47,23 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem private options : MoveInfoOverlaySettings; - constructor(scene: BattleScene, options?: MoveInfoOverlaySettings) { + constructor(options?: MoveInfoOverlaySettings) { if (options?.onSide) { options.top = false; } - super(scene, options?.x, options?.y); + super(globalScene, options?.x, options?.y); const scale = options?.scale || 1; // set up the scale this.setScale(scale); this.options = options || {}; // prepare the description box - const width = (options?.width || MoveInfoOverlay.getWidth(scale, scene)) / scale; // divide by scale as we always want this to be half a window wide - this.descBg = addWindow(scene, (options?.onSide && !options?.right ? EFF_WIDTH : 0), options?.top ? EFF_HEIGHT : 0, width - (options?.onSide ? EFF_WIDTH : 0), DESC_HEIGHT); + const width = (options?.width || MoveInfoOverlay.getWidth(scale)) / scale; // divide by scale as we always want this to be half a window wide + this.descBg = addWindow( (options?.onSide && !options?.right ? EFF_WIDTH : 0), options?.top ? EFF_HEIGHT : 0, width - (options?.onSide ? EFF_WIDTH : 0), DESC_HEIGHT); this.descBg.setOrigin(0, 0); this.add(this.descBg); // set up the description; wordWrap uses true pixels, unaffected by any scaling, while other values are affected - this.desc = addTextObject(scene, (options?.onSide && !options?.right ? EFF_WIDTH : 0) + BORDER, (options?.top ? EFF_HEIGHT : 0) + BORDER - 2, "", TextStyle.BATTLE_INFO, { wordWrap: { width: (width - (BORDER - 2) * 2 - (options?.onSide ? EFF_WIDTH : 0)) * GLOBAL_SCALE }}); + this.desc = addTextObject((options?.onSide && !options?.right ? EFF_WIDTH : 0) + BORDER, (options?.top ? EFF_HEIGHT : 0) + BORDER - 2, "", TextStyle.BATTLE_INFO, { wordWrap: { width: (width - (BORDER - 2) * 2 - (options?.onSide ? EFF_WIDTH : 0)) * GLOBAL_SCALE }}); this.desc.setLineSpacing(i18next.resolvedLanguage === "ja" ? 25 : 5); // limit the text rendering, required for scrolling later on @@ -71,13 +72,13 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem y: (options?.y || 0), }; if (maskPointOrigin.x < 0) { - maskPointOrigin.x += this.scene.game.canvas.width / GLOBAL_SCALE; + maskPointOrigin.x += globalScene.game.canvas.width / GLOBAL_SCALE; } if (maskPointOrigin.y < 0) { - maskPointOrigin.y += this.scene.game.canvas.height / GLOBAL_SCALE; + maskPointOrigin.y += globalScene.game.canvas.height / GLOBAL_SCALE; } - const moveDescriptionTextMaskRect = this.scene.make.graphics(); + const moveDescriptionTextMaskRect = globalScene.make.graphics(); moveDescriptionTextMaskRect.fillStyle(0xFF0000); moveDescriptionTextMaskRect.fillRect( maskPointOrigin.x + ((options?.onSide && !options?.right ? EFF_WIDTH : 0) + BORDER) * scale, maskPointOrigin.y + ((options?.top ? EFF_HEIGHT : 0) + BORDER - 2) * scale, @@ -89,44 +90,44 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem this.desc.setMask(moveDescriptionTextMask); // prepare the effect box - this.val = new Phaser.GameObjects.Container(scene, options?.right ? width - EFF_WIDTH : 0, options?.top || options?.onSide ? 0 : DESC_HEIGHT); + this.val = new Phaser.GameObjects.Container(globalScene, options?.right ? width - EFF_WIDTH : 0, options?.top || options?.onSide ? 0 : DESC_HEIGHT); this.add(this.val); - const valuesBg = addWindow(scene, 0, 0, EFF_WIDTH, EFF_HEIGHT); + const valuesBg = addWindow(0, 0, EFF_WIDTH, EFF_HEIGHT); valuesBg.setOrigin(0, 0); this.val.add(valuesBg); - this.typ = this.scene.add.sprite(25, EFF_HEIGHT - 35, Utils.getLocalizedSpriteKey("types"), "unknown"); + this.typ = globalScene.add.sprite(25, EFF_HEIGHT - 35, Utils.getLocalizedSpriteKey("types"), "unknown"); this.typ.setScale(0.8); this.val.add(this.typ); - this.cat = this.scene.add.sprite(57, EFF_HEIGHT - 35, "categories", "physical"); + this.cat = globalScene.add.sprite(57, EFF_HEIGHT - 35, "categories", "physical"); this.val.add(this.cat); - const ppTxt = addTextObject(scene, 12, EFF_HEIGHT - 25, "PP", TextStyle.MOVE_INFO_CONTENT); + const ppTxt = addTextObject(12, EFF_HEIGHT - 25, "PP", TextStyle.MOVE_INFO_CONTENT); ppTxt.setOrigin(0.0, 0.5); ppTxt.setText(i18next.t("fightUiHandler:pp")); this.val.add(ppTxt); - this.pp = addTextObject(scene, 70, EFF_HEIGHT - 25, "--", TextStyle.MOVE_INFO_CONTENT); + this.pp = addTextObject(70, EFF_HEIGHT - 25, "--", TextStyle.MOVE_INFO_CONTENT); this.pp.setOrigin(1, 0.5); this.val.add(this.pp); - const powTxt = addTextObject(scene, 12, EFF_HEIGHT - 17, "POWER", TextStyle.MOVE_INFO_CONTENT); + const powTxt = addTextObject(12, EFF_HEIGHT - 17, "POWER", TextStyle.MOVE_INFO_CONTENT); powTxt.setOrigin(0.0, 0.5); powTxt.setText(i18next.t("fightUiHandler:power")); this.val.add(powTxt); - this.pow = addTextObject(scene, 70, EFF_HEIGHT - 17, "---", TextStyle.MOVE_INFO_CONTENT); + this.pow = addTextObject(70, EFF_HEIGHT - 17, "---", TextStyle.MOVE_INFO_CONTENT); this.pow.setOrigin(1, 0.5); this.val.add(this.pow); - const accTxt = addTextObject(scene, 12, EFF_HEIGHT - 9, "ACC", TextStyle.MOVE_INFO_CONTENT); + const accTxt = addTextObject(12, EFF_HEIGHT - 9, "ACC", TextStyle.MOVE_INFO_CONTENT); accTxt.setOrigin(0.0, 0.5); accTxt.setText(i18next.t("fightUiHandler:accuracy")); this.val.add(accTxt); - this.acc = addTextObject(scene, 70, EFF_HEIGHT - 9, "---", TextStyle.MOVE_INFO_CONTENT); + this.acc = addTextObject(70, EFF_HEIGHT - 9, "---", TextStyle.MOVE_INFO_CONTENT); this.acc.setOrigin(1, 0.5); this.val.add(this.acc); @@ -144,7 +145,7 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem // show this component with infos for the specific move show(move : Move):boolean { - if (!(this.scene as BattleScene).enableMoveInfo) { + if (!globalScene.enableMoveInfo) { return false; // move infos have been disabled // TODO:: is `false` correct? i used to be `undeefined` } this.move = move; @@ -167,7 +168,7 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem const moveDescriptionLineCount = Math.floor(this.desc.displayHeight * (96 / 72) / 14.83); if (moveDescriptionLineCount > 3) { // generate scrolling effects - this.descScroll = this.scene.tweens.add({ + this.descScroll = globalScene.tweens.add({ targets: this.desc, delay: Utils.fixedInt(2000), loop: -1, @@ -193,7 +194,7 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem if (visible) { this.setVisible(true); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.desc, duration: Utils.fixedInt(125), ease: "Sine.easeInOut", @@ -209,8 +210,8 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem } // width of this element - static getWidth(scale:number, scene: BattleScene):number { - return scene.game.canvas.width / GLOBAL_SCALE / 2; + static getWidth(scale:number):number { + return globalScene.game.canvas.width / GLOBAL_SCALE / 2; } // height of this element diff --git a/src/ui/mystery-encounter-ui-handler.ts b/src/ui/mystery-encounter-ui-handler.ts index cdb1c9024c50..5c82d01fa90e 100644 --- a/src/ui/mystery-encounter-ui-handler.ts +++ b/src/ui/mystery-encounter-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { addBBCodeTextObject, getBBCodeFrag, TextStyle } from "./text"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; @@ -16,6 +15,7 @@ import i18next from "i18next"; import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; +import { globalScene } from "#app/global-scene"; export default class MysteryEncounterUiHandler extends UiHandler { private cursorContainer: Phaser.GameObjects.Container; @@ -47,45 +47,45 @@ export default class MysteryEncounterUiHandler extends UiHandler { protected blockInput: boolean = true; - constructor(scene: BattleScene) { - super(scene, Mode.MYSTERY_ENCOUNTER); + constructor() { + super(Mode.MYSTERY_ENCOUNTER); } override setup() { const ui = this.getUi(); - this.cursorContainer = this.scene.add.container(18, -38.7); + this.cursorContainer = globalScene.add.container(18, -38.7); this.cursorContainer.setVisible(false); ui.add(this.cursorContainer); - this.optionsContainer = this.scene.add.container(12, -38.7); + this.optionsContainer = globalScene.add.container(12, -38.7); this.optionsContainer.setVisible(false); ui.add(this.optionsContainer); - this.dexProgressContainer = this.scene.add.container(214, -43); + this.dexProgressContainer = globalScene.add.container(214, -43); this.dexProgressContainer.setVisible(false); ui.add(this.dexProgressContainer); - this.descriptionContainer = this.scene.add.container(0, -152); + this.descriptionContainer = globalScene.add.container(0, -152); this.descriptionContainer.setVisible(false); ui.add(this.descriptionContainer); - this.tooltipContainer = this.scene.add.container(210, -48); + this.tooltipContainer = globalScene.add.container(210, -48); this.tooltipContainer.setVisible(false); ui.add(this.tooltipContainer); this.setCursor(this.getCursor()); - this.descriptionWindow = addWindow(this.scene, 0, 0, 150, 105, false, false, 0, 0, WindowVariant.THIN); + this.descriptionWindow = addWindow(0, 0, 150, 105, false, false, 0, 0, WindowVariant.THIN); this.descriptionContainer.add(this.descriptionWindow); - this.tooltipWindow = addWindow(this.scene, 0, 0, 110, 48, false, false, 0, 0, WindowVariant.THIN); + this.tooltipWindow = addWindow(0, 0, 110, 48, false, false, 0, 0, WindowVariant.THIN); this.tooltipContainer.add(this.tooltipWindow); - this.dexProgressWindow = addWindow(this.scene, 0, 0, 24, 28, false, false, 0, 0, WindowVariant.THIN); + this.dexProgressWindow = addWindow(0, 0, 24, 28, false, false, 0, 0, WindowVariant.THIN); this.dexProgressContainer.add(this.dexProgressWindow); - this.rarityBall = this.scene.add.sprite(141, 9, "pb"); + this.rarityBall = globalScene.add.sprite(141, 9, "pb"); this.rarityBall.setScale(0.75); this.descriptionContainer.add(this.rarityBall); - const dexProgressIndicator = this.scene.add.sprite(12, 10, "encounter_radar"); + const dexProgressIndicator = globalScene.add.sprite(12, 10, "encounter_radar"); dexProgressIndicator.setScale(0.80); this.dexProgressContainer.add(dexProgressIndicator); this.dexProgressContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, 24, 28), Phaser.Geom.Rectangle.Contains); @@ -138,8 +138,8 @@ export default class MysteryEncounterUiHandler extends UiHandler { ...this.overrideSettings, slideInDescription: false }; - this.scene.ui.setMode(Mode.PARTY, PartyUiMode.CHECK, -1, () => { - this.scene.ui.setMode(Mode.MYSTERY_ENCOUNTER, overrideSettings); + globalScene.ui.setMode(Mode.PARTY, PartyUiMode.CHECK, -1, () => { + globalScene.ui.setMode(Mode.MYSTERY_ENCOUNTER, overrideSettings); setTimeout(() => { this.setCursor(this.viewPartyIndex); this.unblockInput(); @@ -148,7 +148,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { } else if (this.blockInput || (!this.optionsMeetsReqs[cursor] && (selected.optionMode === MysteryEncounterOptionMode.DISABLED_OR_DEFAULT || selected.optionMode === MysteryEncounterOptionMode.DISABLED_OR_SPECIAL))) { success = false; } else { - if ((this.scene.getCurrentPhase() as MysteryEncounterPhase).handleOptionSelect(selected, cursor)) { + if ((globalScene.getCurrentPhase() as MysteryEncounterPhase).handleOptionSelect(selected, cursor)) { success = true; } else { ui.playError(); @@ -315,7 +315,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { this.viewPartyIndex = this.optionsContainer.getAll()?.length - 1; if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.cursorContainer.add(this.cursorObj); } @@ -334,13 +334,13 @@ export default class MysteryEncounterUiHandler extends UiHandler { displayEncounterOptions(slideInDescription: boolean = true): void { this.getUi().clearText(); - const mysteryEncounter = this.scene.currentBattle.mysteryEncounter!; + const mysteryEncounter = globalScene.currentBattle.mysteryEncounter!; this.encounterOptions = this.overrideSettings?.overrideOptions ?? mysteryEncounter.options; this.optionsMeetsReqs = []; - const titleText: string | null = getEncounterText(this.scene, mysteryEncounter.dialogue.encounterOptionsDialogue?.title, TextStyle.TOOLTIP_TITLE); - const descriptionText: string | null = getEncounterText(this.scene, mysteryEncounter.dialogue.encounterOptionsDialogue?.description, TextStyle.TOOLTIP_CONTENT); - const queryText: string | null = getEncounterText(this.scene, mysteryEncounter.dialogue.encounterOptionsDialogue?.query, TextStyle.TOOLTIP_CONTENT); + const titleText: string | null = getEncounterText(mysteryEncounter.dialogue.encounterOptionsDialogue?.title, TextStyle.TOOLTIP_TITLE); + const descriptionText: string | null = getEncounterText(mysteryEncounter.dialogue.encounterOptionsDialogue?.description, TextStyle.TOOLTIP_CONTENT); + const queryText: string | null = getEncounterText(mysteryEncounter.dialogue.encounterOptionsDialogue?.query, TextStyle.TOOLTIP_CONTENT); // Clear options container (except cursor) this.optionsContainer.removeAll(true); @@ -353,25 +353,25 @@ export default class MysteryEncounterUiHandler extends UiHandler { switch (this.encounterOptions.length) { default: case 2: - optionText = addBBCodeTextObject(this.scene, i % 2 === 0 ? 0 : 100, 8, "-", TextStyle.WINDOW, { fontSize: "80px", lineSpacing: -8 }); + optionText = addBBCodeTextObject(i % 2 === 0 ? 0 : 100, 8, "-", TextStyle.WINDOW, { fontSize: "80px", lineSpacing: -8 }); break; case 3: - optionText = addBBCodeTextObject(this.scene, i % 2 === 0 ? 0 : 100, i < 2 ? 0 : 16, "-", TextStyle.WINDOW, { fontSize: "80px", lineSpacing: -8 }); + optionText = addBBCodeTextObject(i % 2 === 0 ? 0 : 100, i < 2 ? 0 : 16, "-", TextStyle.WINDOW, { fontSize: "80px", lineSpacing: -8 }); break; case 4: - optionText = addBBCodeTextObject(this.scene, i % 2 === 0 ? 0 : 100, i < 2 ? 0 : 16, "-", TextStyle.WINDOW, { fontSize: "80px", lineSpacing: -8 }); + optionText = addBBCodeTextObject(i % 2 === 0 ? 0 : 100, i < 2 ? 0 : 16, "-", TextStyle.WINDOW, { fontSize: "80px", lineSpacing: -8 }); break; } - this.optionsMeetsReqs.push(option.meetsRequirements(this.scene)); + this.optionsMeetsReqs.push(option.meetsRequirements()); const optionDialogue = option.dialogue!; const label = !this.optionsMeetsReqs[i] && optionDialogue.disabledButtonLabel ? optionDialogue.disabledButtonLabel : optionDialogue.buttonLabel; let text: string | null; if (option.hasRequirements() && this.optionsMeetsReqs[i] && (option.optionMode === MysteryEncounterOptionMode.DEFAULT_OR_SPECIAL || option.optionMode === MysteryEncounterOptionMode.DISABLED_OR_SPECIAL)) { // Options with special requirements that are met are automatically colored green - text = getEncounterText(this.scene, label, TextStyle.ME_OPTION_SPECIAL); + text = getEncounterText(label, TextStyle.ME_OPTION_SPECIAL); } else { - text = getEncounterText(this.scene, label, optionDialogue.style ? optionDialogue.style : TextStyle.ME_OPTION_DEFAULT); + text = getEncounterText(label, optionDialogue.style ? optionDialogue.style : TextStyle.ME_OPTION_DEFAULT); } if (text) { @@ -387,7 +387,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { // Sets up the mask that hides the option text to give an illusion of scrolling const nonScrollWidth = 90; - const optionTextMaskRect = this.scene.make.graphics({}); + const optionTextMaskRect = globalScene.make.graphics({}); optionTextMaskRect.setScale(6); optionTextMaskRect.fillStyle(0xFFFFFF); optionTextMaskRect.beginPath(); @@ -406,7 +406,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { // Animates the option text scrolling sideways if (optionTextWidth > nonScrollWidth) { - this.optionScrollTweens[i] = this.scene.tweens.add({ + this.optionScrollTweens[i] = globalScene.tweens.add({ targets: optionText, delay: Utils.fixedInt(2000), loop: -1, @@ -420,13 +420,13 @@ export default class MysteryEncounterUiHandler extends UiHandler { } // View Party Button - const viewPartyText = addBBCodeTextObject(this.scene, (this.scene.game.canvas.width) / 6, -24, getBBCodeFrag(i18next.t("mysteryEncounterMessages:view_party_button"), TextStyle.PARTY), TextStyle.PARTY); + const viewPartyText = addBBCodeTextObject((globalScene.game.canvas.width) / 6, -24, getBBCodeFrag(i18next.t("mysteryEncounterMessages:view_party_button"), TextStyle.PARTY), TextStyle.PARTY); this.optionsContainer.add(viewPartyText); viewPartyText.x -= (viewPartyText.displayWidth + 16); this.viewPartyXPosition = viewPartyText.x - 10; // Description Window - const titleTextObject = addBBCodeTextObject(this.scene, 0, 0, titleText ?? "", TextStyle.TOOLTIP_TITLE, { wordWrap: { width: 750 }, align: "center", lineSpacing: -8 }); + const titleTextObject = addBBCodeTextObject(0, 0, titleText ?? "", TextStyle.TOOLTIP_TITLE, { wordWrap: { width: 750 }, align: "center", lineSpacing: -8 }); this.descriptionContainer.add(titleTextObject); titleTextObject.setPosition(72 - titleTextObject.displayWidth / 2, 5.5); @@ -438,10 +438,10 @@ export default class MysteryEncounterUiHandler extends UiHandler { const ballType = getPokeballAtlasKey(index); this.rarityBall.setTexture("pb", ballType); - const descriptionTextObject = addBBCodeTextObject(this.scene, 6, 25, descriptionText ?? "", TextStyle.TOOLTIP_CONTENT, { wordWrap: { width: 830 }}); + const descriptionTextObject = addBBCodeTextObject(6, 25, descriptionText ?? "", TextStyle.TOOLTIP_CONTENT, { wordWrap: { width: 830 }}); // Sets up the mask that hides the description text to give an illusion of scrolling - const descriptionTextMaskRect = this.scene.make.graphics({}); + const descriptionTextMaskRect = globalScene.make.graphics({}); descriptionTextMaskRect.setScale(6); descriptionTextMaskRect.fillStyle(0xFFFFFF); descriptionTextMaskRect.beginPath(); @@ -460,7 +460,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { // Animates the description text moving upwards if (descriptionLineCount > 6) { - this.descriptionScrollTween = this.scene.tweens.add({ + this.descriptionScrollTween = globalScene.tweens.add({ targets: descriptionTextObject, delay: Utils.fixedInt(2000), loop: -1, @@ -472,14 +472,14 @@ export default class MysteryEncounterUiHandler extends UiHandler { this.descriptionContainer.add(descriptionTextObject); - const queryTextObject = addBBCodeTextObject(this.scene, 0, 0, queryText ?? "", TextStyle.TOOLTIP_CONTENT, { wordWrap: { width: 830 }}); + const queryTextObject = addBBCodeTextObject(0, 0, queryText ?? "", TextStyle.TOOLTIP_CONTENT, { wordWrap: { width: 830 }}); this.descriptionContainer.add(queryTextObject); queryTextObject.setPosition(75 - queryTextObject.displayWidth / 2, 90); // Slide in description container if (slideInDescription) { this.descriptionContainer.x -= 150; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.descriptionContainer, x: "+=150", ease: "Sine.easeInOut", @@ -511,9 +511,9 @@ export default class MysteryEncounterUiHandler extends UiHandler { const cursorOption = this.encounterOptions[cursor]; const optionDialogue = cursorOption.dialogue!; if (!this.optionsMeetsReqs[cursor] && (cursorOption.optionMode === MysteryEncounterOptionMode.DISABLED_OR_DEFAULT || cursorOption.optionMode === MysteryEncounterOptionMode.DISABLED_OR_SPECIAL) && optionDialogue.disabledButtonTooltip) { - text = getEncounterText(this.scene, optionDialogue.disabledButtonTooltip, TextStyle.TOOLTIP_CONTENT); + text = getEncounterText(optionDialogue.disabledButtonTooltip, TextStyle.TOOLTIP_CONTENT); } else { - text = getEncounterText(this.scene, optionDialogue.buttonTooltip, TextStyle.TOOLTIP_CONTENT); + text = getEncounterText(optionDialogue.buttonTooltip, TextStyle.TOOLTIP_CONTENT); } // Auto-color options green/blue for good/bad by looking for (+)/(-) @@ -524,11 +524,11 @@ export default class MysteryEncounterUiHandler extends UiHandler { } if (text) { - const tooltipTextObject = addBBCodeTextObject(this.scene, 6, 7, text, TextStyle.TOOLTIP_CONTENT, { wordWrap: { width: 600 }, fontSize: "72px" }); + const tooltipTextObject = addBBCodeTextObject(6, 7, text, TextStyle.TOOLTIP_CONTENT, { wordWrap: { width: 600 }, fontSize: "72px" }); this.tooltipContainer.add(tooltipTextObject); // Sets up the mask that hides the description text to give an illusion of scrolling - const tooltipTextMaskRect = this.scene.make.graphics({}); + const tooltipTextMaskRect = globalScene.make.graphics({}); tooltipTextMaskRect.setScale(6); tooltipTextMaskRect.fillStyle(0xFFFFFF); tooltipTextMaskRect.beginPath(); @@ -546,7 +546,7 @@ export default class MysteryEncounterUiHandler extends UiHandler { // Animates the tooltip text moving upwards if (tooltipLineCount > 3) { - this.tooltipScrollTween = this.scene.tweens.add({ + this.tooltipScrollTween = globalScene.tweens.add({ targets: tooltipTextObject, delay: Utils.fixedInt(1200), loop: -1, @@ -593,25 +593,25 @@ export default class MysteryEncounterUiHandler extends UiHandler { private showHideDexProgress(show: boolean) { if (show && !this.showDexProgress) { this.showDexProgress = true; - this.scene.tweens.killTweensOf(this.dexProgressContainer); - this.scene.tweens.add({ + globalScene.tweens.killTweensOf(this.dexProgressContainer); + globalScene.tweens.add({ targets: this.dexProgressContainer, y: -63, ease: "Sine.easeInOut", duration: 750, onComplete: () => { this.dexProgressContainer.on("pointerover", () => { - (this.scene as BattleScene).ui.showTooltip("", i18next.t("mysteryEncounterMessages:affects_pokedex"), true); + globalScene.ui.showTooltip("", i18next.t("mysteryEncounterMessages:affects_pokedex"), true); }); this.dexProgressContainer.on("pointerout", () => { - (this.scene as BattleScene).ui.hideTooltip(); + globalScene.ui.hideTooltip(); }); } }); } else if (!show && this.showDexProgress) { this.showDexProgress = false; - this.scene.tweens.killTweensOf(this.dexProgressContainer); - this.scene.tweens.add({ + globalScene.tweens.killTweensOf(this.dexProgressContainer); + globalScene.tweens.add({ targets: this.dexProgressContainer, y: -43, ease: "Sine.easeInOut", diff --git a/src/ui/party-exp-bar.ts b/src/ui/party-exp-bar.ts index d2521225375d..8c0673c55418 100644 --- a/src/ui/party-exp-bar.ts +++ b/src/ui/party-exp-bar.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import Pokemon from "../field/pokemon"; import { TextStyle, addTextObject } from "./text"; @@ -11,17 +11,17 @@ export default class PartyExpBar extends Phaser.GameObjects.Container { public shown: boolean; - constructor(scene: BattleScene) { - super(scene, (scene.game.canvas.width / 6), -((scene.game.canvas.height) / 6) + 15); + constructor() { + super(globalScene, (globalScene.game.canvas.width / 6), -((globalScene.game.canvas.height) / 6) + 15); } setup(): void { - this.bg = this.scene.add.nineslice(0, 0, "party_exp_bar", undefined, 8, 18, 21, 5, 6, 4); + this.bg = globalScene.add.nineslice(0, 0, "party_exp_bar", undefined, 8, 18, 21, 5, 6, 4); this.bg.setOrigin(0, 0); this.add(this.bg); - this.expText = addTextObject(this.scene, 22, 4, "", TextStyle.BATTLE_INFO); + this.expText = addTextObject(22, 4, "", TextStyle.BATTLE_INFO); this.expText.setOrigin(0, 0); this.add(this.expText); @@ -35,7 +35,7 @@ export default class PartyExpBar extends Phaser.GameObjects.Container { return resolve(); } - this.pokemonIcon = (this.scene as BattleScene).addPokemonIcon(pokemon, -8, 15, 0, 0.5); + this.pokemonIcon = globalScene.addPokemonIcon(pokemon, -8, 15, 0, 0.5); this.pokemonIcon.setScale(0.5); this.add(this.pokemonIcon); @@ -54,16 +54,16 @@ export default class PartyExpBar extends Phaser.GameObjects.Container { this.bg.width = this.expText.displayWidth + 28; - (this.scene as BattleScene).fieldUI.bringToTop(this); + globalScene.fieldUI.bringToTop(this); if (this.tween) { this.tween.stop(); } - this.tween = this.scene.tweens.add({ + this.tween = globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6) - (this.bg.width - 5), - duration: 500 / Math.pow(2, pokemon.scene.expGainsSpeed), + x: (globalScene.game.canvas.width / 6) - (this.bg.width - 5), + duration: 500 / Math.pow(2, globalScene.expGainsSpeed), ease: "Sine.easeOut", onComplete: () => { this.tween = null; @@ -86,9 +86,9 @@ export default class PartyExpBar extends Phaser.GameObjects.Container { this.tween.stop(); } - this.tween = this.scene.tweens.add({ + this.tween = globalScene.tweens.add({ targets: this, - x: (this.scene.game.canvas.width / 6), + x: (globalScene.game.canvas.width / 6), duration: 500, ease: "Sine.easeIn", onComplete: () => { diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 0d20753f0695..b335e4fba594 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import Pokemon, { MoveResult, PlayerPokemon, PokemonMove } from "#app/field/pokemon"; import { addBBCodeTextObject, addTextObject, getTextColor, TextStyle } from "#app/ui/text"; import { Command } from "#app/ui/command-ui-handler"; @@ -24,6 +23,7 @@ import { Species } from "#enums/species"; import { getPokemonNameWithAffix } from "#app/messages"; import { CommandPhase } from "#app/phases/command-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; +import { globalScene } from "#app/global-scene"; const defaultMessage = i18next.t("partyUiHandler:choosePokemon"); @@ -197,7 +197,7 @@ export default class PartyUiHandler extends MessageUiHandler { */ private FilterChallengeLegal = (pokemon: PlayerPokemon) => { const challengeAllowed = new Utils.BooleanHolder(true); - applyChallenges(this.scene.gameMode, ChallengeType.POKEMON_IN_BATTLE, pokemon, challengeAllowed); + applyChallenges(globalScene.gameMode, ChallengeType.POKEMON_IN_BATTLE, pokemon, challengeAllowed); if (!challengeAllowed.value) { return i18next.t("partyUiHandler:cantBeUsed", { pokemonName: getPokemonNameWithAffix(pokemon) }); } @@ -207,8 +207,8 @@ export default class PartyUiHandler extends MessageUiHandler { private static FilterAllMoves = (_pokemonMove: PokemonMove) => null; public static FilterItemMaxStacks = (pokemon: PlayerPokemon, modifier: PokemonHeldItemModifier) => { - const matchingModifier = pokemon.scene.findModifier(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id && m.matchType(modifier)) as PokemonHeldItemModifier; - if (matchingModifier && matchingModifier.stackCount === matchingModifier.getMaxStackCount(pokemon.scene)) { + const matchingModifier = globalScene.findModifier(m => m instanceof PokemonHeldItemModifier && m.pokemonId === pokemon.id && m.matchType(modifier)) as PokemonHeldItemModifier; + if (matchingModifier && matchingModifier.stackCount === matchingModifier.getMaxStackCount()) { return i18next.t("partyUiHandler:tooManyItems", { pokemonName: getPokemonNameWithAffix(pokemon) }); } return null; @@ -218,44 +218,44 @@ export default class PartyUiHandler extends MessageUiHandler { private localizedOptions = [ PartyOption.SEND_OUT, PartyOption.SUMMARY, PartyOption.CANCEL, PartyOption.APPLY, PartyOption.RELEASE, PartyOption.TEACH, PartyOption.SPLICE, PartyOption.UNSPLICE, PartyOption.REVIVE, PartyOption.TRANSFER, PartyOption.UNPAUSE_EVOLUTION, PartyOption.PASS_BATON, PartyOption.RENAME, PartyOption.SELECT ]; - constructor(scene: BattleScene) { - super(scene, Mode.PARTY); + constructor() { + super(Mode.PARTY); } setup() { const ui = this.getUi(); - const partyContainer = this.scene.add.container(0, 0); + const partyContainer = globalScene.add.container(0, 0); partyContainer.setName("party"); partyContainer.setVisible(false); ui.add(partyContainer); this.partyContainer = partyContainer; - this.partyBg = this.scene.add.image(0, 0, "party_bg"); + this.partyBg = globalScene.add.image(0, 0, "party_bg"); this.partyBg.setName("img-party-bg"); partyContainer.add(this.partyBg); this.partyBg.setOrigin(0, 1); - const partySlotsContainer = this.scene.add.container(0, 0); + const partySlotsContainer = globalScene.add.container(0, 0); partySlotsContainer.setName("party-slots"); partyContainer.add(partySlotsContainer); this.partySlotsContainer = partySlotsContainer; - const partyMessageBoxContainer = this.scene.add.container(0, -32); + const partyMessageBoxContainer = globalScene.add.container(0, -32); partyMessageBoxContainer.setName("party-msg-box"); partyContainer.add(partyMessageBoxContainer); - const partyMessageBox = addWindow(this.scene, 1, 31, 262, 30); + const partyMessageBox = addWindow(1, 31, 262, 30); partyMessageBox.setName("window-party-msg-box"); partyMessageBox.setOrigin(0, 1); partyMessageBoxContainer.add(partyMessageBox); this.partyMessageBox = partyMessageBox; - const partyMessageText = addTextObject(this.scene, 10, 8, defaultMessage, TextStyle.WINDOW, { maxLines: 2 }); + const partyMessageText = addTextObject(10, 8, defaultMessage, TextStyle.WINDOW, { maxLines: 2 }); partyMessageText.setName("text-party-msg"); partyMessageText.setOrigin(0, 0); @@ -263,25 +263,25 @@ export default class PartyUiHandler extends MessageUiHandler { this.message = partyMessageText; - const partyCancelButton = new PartyCancelButton(this.scene, 291, -16); + const partyCancelButton = new PartyCancelButton(291, -16); partyContainer.add(partyCancelButton); this.partyCancelButton = partyCancelButton; - this.optionsContainer = this.scene.add.container((this.scene.game.canvas.width / 6) - 1, -1); + this.optionsContainer = globalScene.add.container((globalScene.game.canvas.width / 6) - 1, -1); partyContainer.add(this.optionsContainer); this.iconAnimHandler = new PokemonIconAnimHandler(); - this.iconAnimHandler.setup(this.scene); + this.iconAnimHandler.setup(); // prepare move overlay. in case it appears to be too big, set the overlayScale to .5 const overlayScale = 1; - this.moveInfoOverlay = new MoveInfoOverlay(this.scene, { + this.moveInfoOverlay = new MoveInfoOverlay({ scale: overlayScale, top: true, x: 1, - y: -MoveInfoOverlay.getHeight(overlayScale) - 1, //this.scene.game.canvas.height / 6 - MoveInfoOverlay.getHeight(overlayScale) - 29, - width: this.scene.game.canvas.width / 12 - 30, + y: -MoveInfoOverlay.getHeight(overlayScale) - 1, + width: globalScene.game.canvas.width / 12 - 30, }); ui.add(this.moveInfoOverlay); @@ -315,7 +315,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.showMovePp = args.length > 6 && args[6]; this.partyContainer.setVisible(true); - this.partyBg.setTexture(`party_bg${this.scene.currentBattle.double ? "_double" : ""}`); + this.partyBg.setTexture(`party_bg${globalScene.currentBattle.double ? "_double" : ""}`); this.populatePartySlots(); this.setCursor(0); @@ -346,22 +346,22 @@ export default class PartyUiHandler extends MessageUiHandler { if (this.optionsMode) { const option = this.options[this.optionsCursor]; if (button === Button.ACTION) { - const pokemon = this.scene.getPlayerParty()[this.cursor]; + const pokemon = globalScene.getPlayerParty()[this.cursor]; if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && !this.transferMode && option !== PartyOption.CANCEL) { this.startTransfer(); let ableToTransfer: string; - for (let p = 0; p < this.scene.getPlayerParty().length; p++) { // this fore look goes through each of the party pokemon - const newPokemon = this.scene.getPlayerParty()[p]; + for (let p = 0; p < globalScene.getPlayerParty().length; p++) { // this for look goes through each of the party pokemon + const newPokemon = globalScene.getPlayerParty()[p]; // this next line gets all of the transferable items from pokemon [p]; it does this by getting all the held modifiers that are transferable and checking to see if they belong to pokemon [p] const getTransferrableItemsFromPokemon = (newPokemon: PlayerPokemon) => - this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).isTransferable && (m as PokemonHeldItemModifier).pokemonId === newPokemon.id) as PokemonHeldItemModifier[]; + globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).isTransferable && (m as PokemonHeldItemModifier).pokemonId === newPokemon.id) as PokemonHeldItemModifier[]; // this next bit checks to see if the the selected item from the original transfer pokemon exists on the new pokemon [p]; this returns undefined if the new pokemon doesn't have the item at all, otherwise it returns the pokemonHeldItemModifier for that item - const matchingModifier = newPokemon.scene.findModifier(m => m instanceof PokemonHeldItemModifier && m.pokemonId === newPokemon.id && m.matchType(getTransferrableItemsFromPokemon(pokemon)[this.transferOptionCursor])) as PokemonHeldItemModifier; + const matchingModifier = globalScene.findModifier(m => m instanceof PokemonHeldItemModifier && m.pokemonId === newPokemon.id && m.matchType(getTransferrableItemsFromPokemon(pokemon)[this.transferOptionCursor])) as PokemonHeldItemModifier; const partySlot = this.partySlots.filter(m => m.getPokemon() === newPokemon)[0]; // this gets pokemon [p] for us if (p !== this.transferCursor) { // this skips adding the able/not able labels on the pokemon doing the transfer if (matchingModifier) { // if matchingModifier exists then the item exists on the new pokemon - if (matchingModifier.getMaxStackCount(this.scene) === matchingModifier.stackCount) { // checks to see if the stack of items is at max stack; if so, set the description label to "Not able" + if (matchingModifier.getMaxStackCount() === matchingModifier.stackCount) { // checks to see if the stack of items is at max stack; if so, set the description label to "Not able" ableToTransfer = i18next.t("partyUiHandler:notAble"); } else { // if the pokemon isn't at max stack, make the label "Able" ableToTransfer = i18next.t("partyUiHandler:able"); @@ -399,7 +399,7 @@ export default class PartyUiHandler extends MessageUiHandler { || (option === PartyOption.RELEASE && this.partyUiMode === PartyUiMode.RELEASE)) { let filterResult: string | null; const getTransferrableItemsFromPokemon = (pokemon: PlayerPokemon) => - this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === pokemon.id) as PokemonHeldItemModifier[]; + globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === pokemon.id) as PokemonHeldItemModifier[]; if (option !== PartyOption.TRANSFER && option !== PartyOption.SPLICE) { filterResult = (this.selectFilter as PokemonSelectFilter)(pokemon); if (filterResult === null && (option === PartyOption.SEND_OUT || option === PartyOption.PASS_BATON)) { @@ -409,7 +409,7 @@ export default class PartyUiHandler extends MessageUiHandler { filterResult = this.moveSelectFilter(pokemon.moveset[this.optionsCursor]!); // TODO: is this bang correct? } } else { - filterResult = (this.selectFilter as PokemonModifierTransferSelectFilter)(pokemon, getTransferrableItemsFromPokemon(this.scene.getPlayerParty()[this.transferCursor])[this.transferOptionCursor]); + filterResult = (this.selectFilter as PokemonModifierTransferSelectFilter)(pokemon, getTransferrableItemsFromPokemon(globalScene.getPlayerParty()[this.transferCursor])[this.transferOptionCursor]); } if (filterResult === null) { if (this.partyUiMode !== PartyUiMode.SPLICE) { @@ -419,7 +419,7 @@ export default class PartyUiHandler extends MessageUiHandler { if (option === PartyOption.TRANSFER) { if (this.transferCursor !== this.cursor) { if (this.transferAll) { - getTransferrableItemsFromPokemon(this.scene.getPlayerParty()[this.transferCursor]).forEach((_, i) => (this.selectCallback as PartyModifierTransferSelectCallback)(this.transferCursor, i, this.transferQuantitiesMax[i], this.cursor)); + getTransferrableItemsFromPokemon(globalScene.getPlayerParty()[this.transferCursor]).forEach((_, i) => (this.selectCallback as PartyModifierTransferSelectCallback)(this.transferCursor, i, this.transferQuantitiesMax[i], this.cursor)); } else { (this.selectCallback as PartyModifierTransferSelectCallback)(this.transferCursor, this.transferOptionCursor, this.transferQuantities[this.transferOptionCursor], this.cursor); } @@ -441,15 +441,15 @@ export default class PartyUiHandler extends MessageUiHandler { selectCallback(this.cursor, option); } } else { - if (option >= PartyOption.FORM_CHANGE_ITEM && this.scene.getCurrentPhase() instanceof SelectModifierPhase) { + if (option >= PartyOption.FORM_CHANGE_ITEM && globalScene.getCurrentPhase() instanceof SelectModifierPhase) { if (this.partyUiMode === PartyUiMode.CHECK) { const formChangeItemModifiers = this.getFormChangeItemsModifiers(pokemon); const modifier = formChangeItemModifiers[option - PartyOption.FORM_CHANGE_ITEM]; modifier.active = !modifier.active; - this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeItemTrigger, false, true); + globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeItemTrigger, false, true); } } else if (this.cursor) { - (this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.POKEMON, this.cursor, option === PartyOption.PASS_BATON); + (globalScene.getCurrentPhase() as CommandPhase).handleCommand(Command.POKEMON, this.cursor, option === PartyOption.PASS_BATON); } } if (this.partyUiMode !== PartyUiMode.MODIFIER && this.partyUiMode !== PartyUiMode.TM_MODIFIER && this.partyUiMode !== PartyUiMode.MOVE_MODIFIER) { @@ -492,7 +492,7 @@ export default class PartyUiHandler extends MessageUiHandler { } else if (option === PartyOption.RELEASE) { this.clearOptions(); ui.playSelect(); - if (this.cursor >= this.scene.currentBattle.getBattlerCount() || !pokemon.isAllowedInBattle()) { + if (this.cursor >= globalScene.currentBattle.getBattlerCount() || !pokemon.isAllowedInBattle()) { this.blockInput = true; this.showText(i18next.t("partyUiHandler:releaseConfirmation", { pokemonName: getPokemonNameWithAffix(pokemon) }), null, () => { this.blockInput = false; @@ -580,7 +580,7 @@ export default class PartyUiHandler extends MessageUiHandler { // show move description if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) { const option = this.options[this.optionsCursor]; - const pokemon = this.scene.getPlayerParty()[this.cursor]; + const pokemon = globalScene.getPlayerParty()[this.cursor]; const move = allMoves[pokemon.getLearnableLevelMoves()[option]]; if (move) { this.moveInfoOverlay.show(move); @@ -595,8 +595,8 @@ export default class PartyUiHandler extends MessageUiHandler { if (this.cursor < 6) { if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && !this.transferMode) { /** Initialize item quantities for the selected Pokemon */ - const itemModifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier - && m.isTransferable && m.pokemonId === this.scene.getPlayerParty()[this.cursor].id) as PokemonHeldItemModifier[]; + const itemModifiers = globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier + && m.isTransferable && m.pokemonId === globalScene.getPlayerParty()[this.cursor].id) as PokemonHeldItemModifier[]; this.transferQuantities = itemModifiers.map(item => item.getStackCount()); this.transferQuantitiesMax = itemModifiers.map(item => item.getStackCount()); } @@ -628,7 +628,7 @@ export default class PartyUiHandler extends MessageUiHandler { } const slotCount = this.partySlots.length; - const battlerCount = this.scene.currentBattle.getBattlerCount(); + const battlerCount = globalScene.currentBattle.getBattlerCount(); switch (button) { case Button.UP: @@ -664,7 +664,7 @@ export default class PartyUiHandler extends MessageUiHandler { } populatePartySlots() { - const party = this.scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); if (this.cursor < 6 && this.cursor >= party.length) { this.cursor = party.length - 1; @@ -677,8 +677,8 @@ export default class PartyUiHandler extends MessageUiHandler { for (const p in party) { const slotIndex = parseInt(p); - const partySlot = new PartySlot(this.scene, slotIndex, party[p], this.iconAnimHandler, this.partyUiMode, this.tmMoveId); - this.scene.add.existing(partySlot); + const partySlot = new PartySlot(slotIndex, party[p], this.iconAnimHandler, this.partyUiMode, this.tmMoveId); + globalScene.add.existing(partySlot); this.partySlotsContainer.add(partySlot); this.partySlots.push(partySlot); if (this.cursor === slotIndex) { @@ -721,7 +721,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.optionsCursor = cursor; } if (!this.optionsCursorObj) { - this.optionsCursorObj = this.scene.add.image(0, 0, "cursor"); + this.optionsCursorObj = globalScene.add.image(0, 0, "cursor"); this.optionsCursorObj.setOrigin(0, 0); this.optionsContainer.add(this.optionsCursorObj); } @@ -803,7 +803,7 @@ export default class PartyUiHandler extends MessageUiHandler { } updateOptions(): void { - const pokemon = this.scene.getPlayerParty()[this.cursor]; + const pokemon = globalScene.getPlayerParty()[this.cursor]; const learnableLevelMoves = this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER ? pokemon.getLearnableLevelMoves() @@ -815,7 +815,7 @@ export default class PartyUiHandler extends MessageUiHandler { } const itemModifiers = this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER - ? this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + ? globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === pokemon.id) as PokemonHeldItemModifier[] : []; @@ -832,13 +832,13 @@ export default class PartyUiHandler extends MessageUiHandler { case PartyUiMode.SWITCH: case PartyUiMode.FAINT_SWITCH: case PartyUiMode.POST_BATTLE_SWITCH: - if (this.cursor >= this.scene.currentBattle.getBattlerCount()) { + if (this.cursor >= globalScene.currentBattle.getBattlerCount()) { const allowBatonModifierSwitch = this.partyUiMode !== PartyUiMode.FAINT_SWITCH - && this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier - && (m as SwitchEffectTransferModifier).pokemonId === this.scene.getPlayerField()[this.fieldIndex].id); + && globalScene.findModifier(m => m instanceof SwitchEffectTransferModifier + && (m as SwitchEffectTransferModifier).pokemonId === globalScene.getPlayerField()[this.fieldIndex].id); - const moveHistory = this.scene.getPlayerField()[this.fieldIndex].getMoveHistory(); + const moveHistory = globalScene.getPlayerField()[this.fieldIndex].getMoveHistory(); const isBatonPassMove = this.partyUiMode === PartyUiMode.FAINT_SWITCH && moveHistory.length && allMoves[moveHistory[moveHistory.length - 1].move].getAttrs(ForceSwitchOutAttr)[0]?.isBatonPass() && moveHistory[moveHistory.length - 1].result === MoveResult.SUCCESS; // isBatonPassMove and allowBatonModifierSwitch shouldn't ever be true @@ -877,7 +877,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.options.push(PartyOption.RELEASE); break; case PartyUiMode.CHECK: - if (this.scene.getCurrentPhase() instanceof SelectModifierPhase) { + if (globalScene.getCurrentPhase() instanceof SelectModifierPhase) { formChangeItemModifiers = this.getFormChangeItemsModifiers(pokemon); for (let i = 0; i < formChangeItemModifiers.length; i++) { this.options.push(PartyOption.FORM_CHANGE_ITEM + i); @@ -941,7 +941,7 @@ export default class PartyUiHandler extends MessageUiHandler { this.options.push(PartyOption.CANCEL); - this.optionsBg = addWindow(this.scene, 0, 0, 0, 16 * this.options.length + 13); + this.optionsBg = addWindow(0, 0, 0, 16 * this.options.length + 13); this.optionsBg.setOrigin(1, 1); this.optionsContainer.add(this.optionsBg); @@ -1002,7 +1002,7 @@ export default class PartyUiHandler extends MessageUiHandler { } const yCoord = -6 - 16 * o; - const optionText = addBBCodeTextObject(this.scene, 0, yCoord - 16, optionName, TextStyle.WINDOW, { maxLines: 1 }); + const optionText = addBBCodeTextObject(0, yCoord - 16, optionName, TextStyle.WINDOW, { maxLines: 1 }); if (altText) { optionText.setColor("#40c8f8"); optionText.setShadowColor("#006090"); @@ -1059,13 +1059,13 @@ export default class PartyUiHandler extends MessageUiHandler { } doRelease(slotIndex: integer): void { - this.showText(this.getReleaseMessage(getPokemonNameWithAffix(this.scene.getPlayerParty()[slotIndex])), null, () => { + this.showText(this.getReleaseMessage(getPokemonNameWithAffix(globalScene.getPlayerParty()[slotIndex])), null, () => { this.clearPartySlots(); - this.scene.removePartyMemberModifiers(slotIndex); - const releasedPokemon = this.scene.getPlayerParty().splice(slotIndex, 1)[0]; + globalScene.removePartyMemberModifiers(slotIndex); + const releasedPokemon = globalScene.getPlayerParty().splice(slotIndex, 1)[0]; releasedPokemon.destroy(); this.populatePartySlots(); - if (this.cursor >= this.scene.getPlayerParty().length) { + if (this.cursor >= globalScene.getPlayerParty().length) { this.setCursor(this.cursor - 1); } if (this.partyUiMode === PartyUiMode.RELEASE) { @@ -1103,7 +1103,7 @@ export default class PartyUiHandler extends MessageUiHandler { } getFormChangeItemsModifiers(pokemon: Pokemon) { - let formChangeItemModifiers = this.scene.findModifiers(m => m instanceof PokemonFormChangeItemModifier && m.pokemonId === pokemon.id) as PokemonFormChangeItemModifier[]; + let formChangeItemModifiers = globalScene.findModifiers(m => m instanceof PokemonFormChangeItemModifier && m.pokemonId === pokemon.id) as PokemonFormChangeItemModifier[]; const ultraNecrozmaModifiers = formChangeItemModifiers.filter(m => m.active && m.formChangeItem === FormChangeItem.ULTRANECROZIUM_Z); if (ultraNecrozmaModifiers.length > 0) { // ULTRANECROZIUM_Z is active and deactivating it should be the only option @@ -1177,10 +1177,10 @@ class PartySlot extends Phaser.GameObjects.Container { private pokemonIcon: Phaser.GameObjects.Container; private iconAnimHandler: PokemonIconAnimHandler; - constructor(scene: BattleScene, slotIndex: integer, pokemon: PlayerPokemon, iconAnimHandler: PokemonIconAnimHandler, partyUiMode: PartyUiMode, tmMoveId: Moves) { - super(scene, slotIndex >= scene.currentBattle.getBattlerCount() ? 230.5 : 64, - slotIndex >= scene.currentBattle.getBattlerCount() ? -184 + (scene.currentBattle.double ? -40 : 0) - + (28 + (scene.currentBattle.double ? 8 : 0)) * slotIndex : -124 + (scene.currentBattle.double ? -8 : 0) + slotIndex * 64); + constructor(slotIndex: integer, pokemon: PlayerPokemon, iconAnimHandler: PokemonIconAnimHandler, partyUiMode: PartyUiMode, tmMoveId: Moves) { + super(globalScene, slotIndex >= globalScene.currentBattle.getBattlerCount() ? 230.5 : 64, + slotIndex >= globalScene.currentBattle.getBattlerCount() ? -184 + (globalScene.currentBattle.double ? -40 : 0) + + (28 + (globalScene.currentBattle.double ? 8 : 0)) * slotIndex : -124 + (globalScene.currentBattle.double ? -8 : 0) + slotIndex * 64); this.slotIndex = slotIndex; this.pokemon = pokemon; @@ -1194,33 +1194,33 @@ class PartySlot extends Phaser.GameObjects.Container { } setup(partyUiMode: PartyUiMode, tmMoveId: Moves) { - const battlerCount = (this.scene as BattleScene).currentBattle.getBattlerCount(); + const battlerCount = globalScene.currentBattle.getBattlerCount(); const slotKey = `party_slot${this.slotIndex >= battlerCount ? "" : "_main"}`; - const slotBg = this.scene.add.sprite(0, 0, slotKey, `${slotKey}${this.pokemon.hp ? "" : "_fnt"}`); + const slotBg = globalScene.add.sprite(0, 0, slotKey, `${slotKey}${this.pokemon.hp ? "" : "_fnt"}`); this.slotBg = slotBg; this.add(slotBg); - const slotPb = this.scene.add.sprite(this.slotIndex >= battlerCount ? -85.5 : -51, this.slotIndex >= battlerCount ? 0 : -20.5, "party_pb"); + const slotPb = globalScene.add.sprite(this.slotIndex >= battlerCount ? -85.5 : -51, this.slotIndex >= battlerCount ? 0 : -20.5, "party_pb"); this.slotPb = slotPb; this.add(slotPb); - this.pokemonIcon = (this.scene as BattleScene).addPokemonIcon(this.pokemon, slotPb.x, slotPb.y, 0.5, 0.5, true); + this.pokemonIcon = globalScene.addPokemonIcon(this.pokemon, slotPb.x, slotPb.y, 0.5, 0.5, true); this.add(this.pokemonIcon); this.iconAnimHandler.addOrUpdate(this.pokemonIcon, PokemonIconAnimMode.PASSIVE); - const slotInfoContainer = this.scene.add.container(0, 0); + const slotInfoContainer = globalScene.add.container(0, 0); this.add(slotInfoContainer); let displayName = this.pokemon.getNameToRender(); let nameTextWidth: number; - const nameSizeTest = addTextObject(this.scene, 0, 0, displayName, TextStyle.PARTY); + const nameSizeTest = addTextObject(0, 0, displayName, TextStyle.PARTY); nameTextWidth = nameSizeTest.displayWidth; while (nameTextWidth > (this.slotIndex >= battlerCount ? 52 : (76 - (this.pokemon.fusionSpecies ? 8 : 0)))) { @@ -1231,15 +1231,15 @@ class PartySlot extends Phaser.GameObjects.Container { nameSizeTest.destroy(); - this.slotName = addTextObject(this.scene, 0, 0, displayName, TextStyle.PARTY); + this.slotName = addTextObject(0, 0, displayName, TextStyle.PARTY); this.slotName.setPositionRelative(slotBg, this.slotIndex >= battlerCount ? 21 : 24, this.slotIndex >= battlerCount ? 2 : 10); this.slotName.setOrigin(0, 0); - const slotLevelLabel = this.scene.add.image(0, 0, "party_slot_overlay_lv"); + const slotLevelLabel = globalScene.add.image(0, 0, "party_slot_overlay_lv"); slotLevelLabel.setPositionRelative(this.slotName, 8, 12); slotLevelLabel.setOrigin(0, 0); - const slotLevelText = addTextObject(this.scene, 0, 0, this.pokemon.level.toString(), this.pokemon.level < (this.scene as BattleScene).getMaxExpLevel() ? TextStyle.PARTY : TextStyle.PARTY_RED); + const slotLevelText = addTextObject(0, 0, this.pokemon.level.toString(), this.pokemon.level < globalScene.getMaxExpLevel() ? TextStyle.PARTY : TextStyle.PARTY_RED); slotLevelText.setPositionRelative(slotLevelLabel, 9, 0); slotLevelText.setOrigin(0, 0.25); @@ -1248,7 +1248,7 @@ class PartySlot extends Phaser.GameObjects.Container { const genderSymbol = getGenderSymbol(this.pokemon.getGender(true)); if (genderSymbol) { - const slotGenderText = addTextObject(this.scene, 0, 0, genderSymbol, TextStyle.PARTY); + const slotGenderText = addTextObject(0, 0, genderSymbol, TextStyle.PARTY); slotGenderText.setColor(getGenderColor(this.pokemon.getGender(true))); slotGenderText.setShadowColor(getGenderColor(this.pokemon.getGender(true), true)); if (this.slotIndex >= battlerCount) { @@ -1262,7 +1262,7 @@ class PartySlot extends Phaser.GameObjects.Container { } if (this.pokemon.fusionSpecies) { - const splicedIcon = this.scene.add.image(0, 0, "icon_spliced"); + const splicedIcon = globalScene.add.image(0, 0, "icon_spliced"); splicedIcon.setScale(0.5); splicedIcon.setOrigin(0, 0); if (this.slotIndex >= battlerCount) { @@ -1275,7 +1275,7 @@ class PartySlot extends Phaser.GameObjects.Container { } if (this.pokemon.status) { - const statusIndicator = this.scene.add.sprite(0, 0, Utils.getLocalizedSpriteKey("statuses")); + const statusIndicator = globalScene.add.sprite(0, 0, Utils.getLocalizedSpriteKey("statuses")); statusIndicator.setFrame(StatusEffect[this.pokemon.status?.effect].toLowerCase()); statusIndicator.setOrigin(0, 0); statusIndicator.setPositionRelative(slotLevelLabel, this.slotIndex >= battlerCount ? 43 : 55, 0); @@ -1286,7 +1286,7 @@ class PartySlot extends Phaser.GameObjects.Container { if (this.pokemon.isShiny()) { const doubleShiny = this.pokemon.isFusion() && this.pokemon.shiny && this.pokemon.fusionShiny; - const shinyStar = this.scene.add.image(0, 0, `shiny_star_small${doubleShiny ? "_1" : ""}`); + const shinyStar = globalScene.add.image(0, 0, `shiny_star_small${doubleShiny ? "_1" : ""}`); shinyStar.setOrigin(0, 0); shinyStar.setPositionRelative(this.slotName, -9, 3); shinyStar.setTint(getVariantTint(!doubleShiny ? this.pokemon.getVariant() : this.pokemon.variant)); @@ -1294,7 +1294,7 @@ class PartySlot extends Phaser.GameObjects.Container { slotInfoContainer.add(shinyStar); if (doubleShiny) { - const fusionShinyStar = this.scene.add.image(0, 0, "shiny_star_small_2"); + const fusionShinyStar = globalScene.add.image(0, 0, "shiny_star_small_2"); fusionShinyStar.setOrigin(0, 0); fusionShinyStar.setPosition(shinyStar.x, shinyStar.y); fusionShinyStar.setTint(getVariantTint(this.pokemon.fusionVariant)); @@ -1303,25 +1303,25 @@ class PartySlot extends Phaser.GameObjects.Container { } } - this.slotHpBar = this.scene.add.image(0, 0, "party_slot_hp_bar"); + this.slotHpBar = globalScene.add.image(0, 0, "party_slot_hp_bar"); this.slotHpBar.setPositionRelative(slotBg, this.slotIndex >= battlerCount ? 72 : 8, this.slotIndex >= battlerCount ? 6 : 31); this.slotHpBar.setOrigin(0, 0); this.slotHpBar.setVisible(false); const hpRatio = this.pokemon.getHpRatio(); - this.slotHpOverlay = this.scene.add.sprite(0, 0, "party_slot_hp_overlay", hpRatio > 0.5 ? "high" : hpRatio > 0.25 ? "medium" : "low"); + this.slotHpOverlay = globalScene.add.sprite(0, 0, "party_slot_hp_overlay", hpRatio > 0.5 ? "high" : hpRatio > 0.25 ? "medium" : "low"); this.slotHpOverlay.setPositionRelative(this.slotHpBar, 16, 2); this.slotHpOverlay.setOrigin(0, 0); this.slotHpOverlay.setScale(hpRatio, 1); this.slotHpOverlay.setVisible(false); - this.slotHpText = addTextObject(this.scene, 0, 0, `${this.pokemon.hp}/${this.pokemon.getMaxHp()}`, TextStyle.PARTY); + this.slotHpText = addTextObject(0, 0, `${this.pokemon.hp}/${this.pokemon.getMaxHp()}`, TextStyle.PARTY); this.slotHpText.setPositionRelative(this.slotHpBar, this.slotHpBar.width - 3, this.slotHpBar.height - 2); this.slotHpText.setOrigin(1, 0); this.slotHpText.setVisible(false); - this.slotDescriptionLabel = addTextObject(this.scene, 0, 0, "", TextStyle.MESSAGE); + this.slotDescriptionLabel = addTextObject(0, 0, "", TextStyle.MESSAGE); this.slotDescriptionLabel.setPositionRelative(slotBg, this.slotIndex >= battlerCount ? 94 : 32, this.slotIndex >= battlerCount ? 16 : 46); this.slotDescriptionLabel.setOrigin(0, 1); this.slotDescriptionLabel.setVisible(false); @@ -1387,7 +1387,7 @@ class PartySlot extends Phaser.GameObjects.Container { } private updateSlotTexture(): void { - const battlerCount = (this.scene as BattleScene).currentBattle.getBattlerCount(); + const battlerCount = globalScene.currentBattle.getBattlerCount(); this.slotBg.setTexture(`party_slot${this.slotIndex >= battlerCount ? "" : "_main"}`, `party_slot${this.slotIndex >= battlerCount ? "" : "_main"}${this.transfer ? "_swap" : this.pokemon.hp ? "" : "_fnt"}${this.selected ? "_sel" : ""}`); } @@ -1399,24 +1399,24 @@ class PartyCancelButton extends Phaser.GameObjects.Container { private partyCancelBg: Phaser.GameObjects.Sprite; private partyCancelPb: Phaser.GameObjects.Sprite; - constructor(scene: BattleScene, x: number, y: number) { - super(scene, x, y); + constructor(x: number, y: number) { + super(globalScene, x, y); this.setup(); } setup() { - const partyCancelBg = this.scene.add.sprite(0, 0, "party_cancel"); + const partyCancelBg = globalScene.add.sprite(0, 0, "party_cancel"); this.add(partyCancelBg); this.partyCancelBg = partyCancelBg; - const partyCancelPb = this.scene.add.sprite(-17, 0, "party_pb"); + const partyCancelPb = globalScene.add.sprite(-17, 0, "party_pb"); this.add(partyCancelPb); this.partyCancelPb = partyCancelPb; - const partyCancelText = addTextObject(this.scene, -8, -7, i18next.t("partyUiHandler:cancel"), TextStyle.PARTY); + const partyCancelText = addTextObject(-8, -7, i18next.t("partyUiHandler:cancel"), TextStyle.PARTY); this.add(partyCancelText); } diff --git a/src/ui/pokeball-tray.ts b/src/ui/pokeball-tray.ts index 0313812ef790..bd0208401ffe 100644 --- a/src/ui/pokeball-tray.ts +++ b/src/ui/pokeball-tray.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import Pokemon from "../field/pokemon"; export default class PokeballTray extends Phaser.GameObjects.Container { @@ -9,18 +9,18 @@ export default class PokeballTray extends Phaser.GameObjects.Container { public shown: boolean; - constructor(scene: BattleScene, player: boolean) { - super(scene, player ? (scene.game.canvas.width / 6) : 0, player ? -72 : -144); + constructor(player: boolean) { + super(globalScene, player ? (globalScene.game.canvas.width / 6) : 0, player ? -72 : -144); this.player = player; } setup(): void { - this.bg = this.scene.add.nineslice(0, 0, `pb_tray_overlay_${this.player ? "player" : "enemy"}`, undefined, 104, 4, 48, 8, 0, 0); + this.bg = globalScene.add.nineslice(0, 0, `pb_tray_overlay_${this.player ? "player" : "enemy"}`, undefined, 104, 4, 48, 8, 0, 0); this.bg.setOrigin(this.player ? 1 : 0, 0); this.add(this.bg); - this.balls = new Array(6).fill(null).map((_, i) => this.scene.add.sprite((this.player ? -83 : 76) + (this.scene.game.canvas.width / 6) * (this.player ? -1 : 1) + 10 * i * (this.player ? 1 : -1), -8, "pb_tray_ball", "empty")); + this.balls = new Array(6).fill(null).map((_, i) => globalScene.add.sprite((this.player ? -83 : 76) + (globalScene.game.canvas.width / 6) * (this.player ? -1 : 1) + 10 * i * (this.player ? 1 : -1), -8, "pb_tray_ball", "empty")); for (const ball of this.balls) { ball.setOrigin(0, 0); @@ -37,7 +37,7 @@ export default class PokeballTray extends Phaser.GameObjects.Container { return resolve(); } - (this.scene as BattleScene).fieldUI.bringToTop(this); + globalScene.fieldUI.bringToTop(this); this.x += 104 * (this.player ? 1 : -1); @@ -45,7 +45,7 @@ export default class PokeballTray extends Phaser.GameObjects.Container { this.bg.alpha = 1; this.balls.forEach((ball, b) => { - ball.x += (this.scene.game.canvas.width / 6 + 104) * (this.player ? 1 : -1); + ball.x += (globalScene.game.canvas.width / 6 + 104) * (this.player ? 1 : -1); let ballFrame = "ball"; if (b >= party.length) { ballFrame = "empty"; @@ -57,21 +57,21 @@ export default class PokeballTray extends Phaser.GameObjects.Container { ball.setFrame(ballFrame); }); - (this.scene as BattleScene).playSound("se/pb_tray_enter"); + globalScene.playSound("se/pb_tray_enter"); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, x: `${this.player ? "-" : "+"}=104`, duration: 500, ease: "Sine.easeIn", onComplete: () => { this.balls.forEach((ball, b) => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: ball, x: `${this.player ? "-" : "+"}=104`, duration: b * 100, ease: "Sine.easeIn", - onComplete: () => (this.scene as BattleScene).playSound(`se/${(b < party.length ? "pb_tray_ball" : "pb_tray_empty")}`) + onComplete: () => globalScene.playSound(`se/${(b < party.length ? "pb_tray_ball" : "pb_tray_empty")}`) }); }); } @@ -80,7 +80,7 @@ export default class PokeballTray extends Phaser.GameObjects.Container { this.setVisible(true); this.shown = true; - this.scene.time.delayedCall(1100, () => resolve()); + globalScene.time.delayedCall(1100, () => resolve()); }); } @@ -91,16 +91,16 @@ export default class PokeballTray extends Phaser.GameObjects.Container { } this.balls.forEach((ball, b) => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: ball, - x: `${this.player ? "-" : "+"}=${this.scene.game.canvas.width / 6}`, + x: `${this.player ? "-" : "+"}=${globalScene.game.canvas.width / 6}`, duration: 250, delay: b * 100, ease: "Sine.easeIn" }); }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.bg, width: 144, alpha: 0, @@ -108,7 +108,7 @@ export default class PokeballTray extends Phaser.GameObjects.Container { ease: "Sine.easeIn" }); - this.scene.time.delayedCall(850, () => { + globalScene.time.delayedCall(850, () => { this.setVisible(false); resolve(); }); diff --git a/src/ui/pokemon-hatch-info-container.ts b/src/ui/pokemon-hatch-info-container.ts index 494855d20fa7..34d4f691b497 100644 --- a/src/ui/pokemon-hatch-info-container.ts +++ b/src/ui/pokemon-hatch-info-container.ts @@ -1,5 +1,4 @@ import PokemonInfoContainer from "#app/ui/pokemon-info-container"; -import BattleScene from "#app/battle-scene"; import { Gender } from "#app/data/gender"; import { Type } from "#enums/type"; import * as Utils from "#app/utils"; @@ -9,6 +8,7 @@ import { allMoves } from "#app/data/move"; import { Species } from "#enums/species"; import { getEggTierForSpecies } from "#app/data/egg"; import { starterColors } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { argbFromRgba } from "@material/material-color-utilities"; import { EggHatchData } from "#app/data/egg-hatch-data"; import { PlayerPokemon } from "#app/field/pokemon"; @@ -32,8 +32,8 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { private pokemonCandyOverlayIcon: Phaser.GameObjects.Sprite; private pokemonCandyCountText: Phaser.GameObjects.Text; - constructor(scene: BattleScene, listContainer : Phaser.GameObjects.Container, x: number = 115, y: number = 9,) { - super(scene, x, y); + constructor(listContainer : Phaser.GameObjects.Container, x: number = 115, y: number = 9,) { + super(x, y); this.pokemonListContainer = listContainer; } @@ -41,37 +41,37 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { super.setup(); super.changeToEggSummaryLayout(); - this.currentPokemonSprite = this.scene.add.sprite(54, 80, "pkmn__sub"); + this.currentPokemonSprite = globalScene.add.sprite(54, 80, "pkmn__sub"); this.currentPokemonSprite.setScale(0.8); - this.currentPokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + this.currentPokemonSprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); this.pokemonListContainer.add(this.currentPokemonSprite); // setup name and number - this.pokemonNumberText = addTextObject(this.scene, 80, 107.5, "0000", TextStyle.SUMMARY, { fontSize: 74 }); + this.pokemonNumberText = addTextObject(80, 107.5, "0000", TextStyle.SUMMARY, { fontSize: 74 }); this.pokemonNumberText.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonNumberText); - this.pokemonNameText = addTextObject(this.scene, 7, 107.5, "", TextStyle.SUMMARY, { fontSize: 74 }); + this.pokemonNameText = addTextObject(7, 107.5, "", TextStyle.SUMMARY, { fontSize: 74 }); this.pokemonNameText.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonNameText); // setup egg icon and candy count - this.pokemonHatchedIcon = this.scene.add.sprite(-5, 90, "egg_icons"); + this.pokemonHatchedIcon = globalScene.add.sprite(-5, 90, "egg_icons"); this.pokemonHatchedIcon.setOrigin(0, 0.2); this.pokemonHatchedIcon.setScale(0.8); this.pokemonListContainer.add(this.pokemonHatchedIcon); - this.pokemonCandyIcon = this.scene.add.sprite(4.5, 40, "candy"); + this.pokemonCandyIcon = globalScene.add.sprite(4.5, 40, "candy"); this.pokemonCandyIcon.setScale(0.5); this.pokemonCandyIcon.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonCandyIcon); - this.pokemonCandyOverlayIcon = this.scene.add.sprite(4.5, 40, "candy_overlay"); + this.pokemonCandyOverlayIcon = globalScene.add.sprite(4.5, 40, "candy_overlay"); this.pokemonCandyOverlayIcon.setScale(0.5); this.pokemonCandyOverlayIcon.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonCandyOverlayIcon); - this.pokemonCandyCountText = addTextObject(this.scene, 14, 40, "x0", TextStyle.SUMMARY, { fontSize: "56px" }); + this.pokemonCandyCountText = addTextObject(14, 40, "x0", TextStyle.SUMMARY, { fontSize: "56px" }); this.pokemonCandyCountText.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonCandyCountText); @@ -79,17 +79,17 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.pokemonEggMoveContainers = []; this.pokemonEggMoveBgs = []; this.pokemonEggMoveLabels = []; - this.pokemonEggMovesContainer = this.scene.add.container(0, 200); + this.pokemonEggMovesContainer = globalScene.add.container(0, 200); this.pokemonEggMovesContainer.setVisible(false); this.pokemonEggMovesContainer.setScale(0.5); for (let m = 0; m < 4; m++) { - const eggMoveContainer = this.scene.add.container(0, 0 + 6 * m); + const eggMoveContainer = globalScene.add.container(0, 0 + 6 * m); - const eggMoveBg = this.scene.add.nineslice(70, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); + const eggMoveBg = globalScene.add.nineslice(70, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); eggMoveBg.setOrigin(1, 0); - const eggMoveLabel = addTextObject(this.scene, 70 - eggMoveBg.width / 2, 0, "???", TextStyle.PARTY); + const eggMoveLabel = addTextObject(70 - eggMoveBg.width / 2, 0, "???", TextStyle.PARTY); eggMoveLabel.setOrigin(0.5, 0); this.pokemonEggMoveBgs.push(eggMoveBg); @@ -126,9 +126,9 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { const shiny = pokemon.shiny; const variant = pokemon.variant; this.currentPokemonSprite.setVisible(false); - species.loadAssets(this.scene, female, formIndex, shiny, variant, true).then(() => { + species.loadAssets(female, formIndex, shiny, variant, true).then(() => { - getPokemonSpeciesForm(species.speciesId, pokemon.formIndex).cry(this.scene); + getPokemonSpeciesForm(species.speciesId, pokemon.formIndex).cry(); this.currentPokemonSprite.play(species.getSpriteKey(female, formIndex, shiny, variant)); this.currentPokemonSprite.setPipelineData("shiny", shiny); this.currentPokemonSprite.setPipelineData("variant", variant); @@ -156,7 +156,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.pokemonCandyIcon.setVisible(true); this.pokemonCandyOverlayIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[1]))); this.pokemonCandyOverlayIcon.setVisible(true); - this.pokemonCandyCountText.setText(`x${this.scene.gameData.starterData[species.speciesId].candyCount}`); + this.pokemonCandyCountText.setText(`x${globalScene.gameData.starterData[species.speciesId].candyCount}`); this.pokemonCandyCountText.setVisible(true); this.pokemonNumberText.setText(Utils.padInt(species.speciesId, 4)); @@ -166,7 +166,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { for (let em = 0; em < 4; em++) { const eggMove = hasEggMoves ? allMoves[speciesEggMoves[species.speciesId][em]] : null; - const eggMoveUnlocked = eggMove && this.scene.gameData.starterData[species.speciesId].eggMoves & Math.pow(2, em); + const eggMoveUnlocked = eggMove && globalScene.gameData.starterData[species.speciesId].eggMoves & Math.pow(2, em); this.pokemonEggMoveBgs[em].setFrame(Type[eggMove ? eggMove.type : Type.UNKNOWN].toString().toLowerCase()); this.pokemonEggMoveLabels[em].setText(eggMove && eggMoveUnlocked ? eggMove.name : "???"); diff --git a/src/ui/pokemon-icon-anim-handler.ts b/src/ui/pokemon-icon-anim-handler.ts index c7a24f69200e..010d23315f2b 100644 --- a/src/ui/pokemon-icon-anim-handler.ts +++ b/src/ui/pokemon-icon-anim-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "../utils"; export enum PokemonIconAnimMode { @@ -13,7 +13,7 @@ export default class PokemonIconAnimHandler { private icons: Map; private toggled: boolean; - setup(scene: BattleScene): void { + setup(): void { this.icons = new Map(); this.toggled = false; @@ -26,7 +26,7 @@ export default class PokemonIconAnimHandler { i.y += delta * (this.toggled ? 1 : -1); } }; - scene.tweens.addCounter({ + globalScene.tweens.addCounter({ duration: Utils.fixedInt(200), from: 0, to: 1, diff --git a/src/ui/pokemon-info-container.ts b/src/ui/pokemon-info-container.ts index e0d432265a33..6f06572447ad 100644 --- a/src/ui/pokemon-info-container.ts +++ b/src/ui/pokemon-info-container.ts @@ -1,6 +1,6 @@ import { getVariantTint } from "#app/data/variant"; import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { Gender, getGenderColor, getGenderSymbol } from "../data/gender"; import { getNatureName } from "../data/nature"; import { Type } from "#enums/type"; @@ -57,8 +57,8 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { public shown: boolean; - constructor(scene: BattleScene, x: number = 372, y: number = 66) { - super(scene, x, y); + constructor(x: number = 372, y: number = 66) { + super(globalScene, x, y); this.initialX = x; } @@ -67,11 +67,11 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { const currentLanguage = i18next.resolvedLanguage!; // TODO: is this bang correct? const langSettingKey = Object.keys(languageSettings).find(lang => currentLanguage?.includes(lang))!; // TODO: is this bang correct? const textSettings = languageSettings[langSettingKey]; - this.infoBg = addWindow(this.scene, 0, 0, this.infoWindowWidth, 132); + this.infoBg = addWindow(0, 0, this.infoWindowWidth, 132); this.infoBg.setOrigin(0.5, 0.5); this.infoBg.setName("window-info-bg"); - this.pokemonMovesContainer = this.scene.add.container(6, 14); + this.pokemonMovesContainer = globalScene.add.container(6, 14); this.pokemonMovesContainer.setName("pkmn-moves"); this.movesContainerInitialX = this.pokemonMovesContainer.x; @@ -80,26 +80,26 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { this.pokemonMoveBgs = []; this.pokemonMoveLabels = []; - const movesBg = addWindow(this.scene, 0, 0, 58, 52); + const movesBg = addWindow(0, 0, 58, 52); movesBg.setOrigin(1, 0); movesBg.setName("window-moves-bg"); this.pokemonMovesContainer.add(movesBg); - const movesLabel = addTextObject(this.scene, -movesBg.width / 2, 6, i18next.t("pokemonInfoContainer:moveset"), TextStyle.WINDOW, { fontSize: "64px" }); + const movesLabel = addTextObject(-movesBg.width / 2, 6, i18next.t("pokemonInfoContainer:moveset"), TextStyle.WINDOW, { fontSize: "64px" }); movesLabel.setOrigin(0.5, 0); movesLabel.setName("text-moves"); this.pokemonMovesContainer.add(movesLabel); for (let m = 0; m < 4; m++) { - const moveContainer = this.scene.add.container(-6, 18 + 7 * m); + const moveContainer = globalScene.add.container(-6, 18 + 7 * m); moveContainer.setScale(0.5); moveContainer.setName("move"); - const moveBg = this.scene.add.nineslice(0, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); + const moveBg = globalScene.add.nineslice(0, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); moveBg.setOrigin(1, 0); moveBg.setName("nineslice-move-bg"); - const moveLabel = addTextObject(this.scene, -moveBg.width / 2, 0, "-", TextStyle.PARTY); + const moveLabel = addTextObject(-moveBg.width / 2, 0, "-", TextStyle.PARTY); moveLabel.setOrigin(0.5, 0); moveLabel.setName("text-move-label"); @@ -115,7 +115,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { this.add(this.pokemonMovesContainer); - this.statsContainer = new StatsContainer(this.scene, -48, -64, true); + this.statsContainer = new StatsContainer(-48, -64, true); this.add(this.infoBg); this.add(this.statsContainer); @@ -127,62 +127,62 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { // The font size should be set by language const infoContainerTextSize = textSettings?.infoContainerTextSize || "64px"; - this.pokemonFormLabelText = addTextObject(this.scene, infoContainerLabelXPos, 19, i18next.t("pokemonInfoContainer:form"), TextStyle.WINDOW, { fontSize: infoContainerTextSize }); + this.pokemonFormLabelText = addTextObject(infoContainerLabelXPos, 19, i18next.t("pokemonInfoContainer:form"), TextStyle.WINDOW, { fontSize: infoContainerTextSize }); this.pokemonFormLabelText.setOrigin(1, 0); this.pokemonFormLabelText.setVisible(false); this.add(this.pokemonFormLabelText); - this.pokemonFormText = addTextObject(this.scene, infoContainerTextXPos, 19, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); + this.pokemonFormText = addTextObject(infoContainerTextXPos, 19, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); this.pokemonFormText.setOrigin(0, 0); this.pokemonFormText.setVisible(false); this.add(this.pokemonFormText); - this.pokemonGenderText = addTextObject(this.scene, -42, -61, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); + this.pokemonGenderText = addTextObject(-42, -61, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); this.pokemonGenderText.setOrigin(0, 0); this.pokemonGenderText.setVisible(false); this.pokemonGenderText.setName("text-pkmn-gender"); this.add(this.pokemonGenderText); - this.pokemonGenderNewText = addTextObject(this.scene, -36, -61, "", TextStyle.WINDOW, { fontSize: "64px" }); + this.pokemonGenderNewText = addTextObject(-36, -61, "", TextStyle.WINDOW, { fontSize: "64px" }); this.pokemonGenderNewText.setOrigin(0, 0); this.pokemonGenderNewText.setVisible(false); this.pokemonGenderNewText.setName("text-pkmn-new-gender"); this.add(this.pokemonGenderNewText); - this.pokemonAbilityLabelText = addTextObject(this.scene, infoContainerLabelXPos, 29, i18next.t("pokemonInfoContainer:ability"), TextStyle.WINDOW, { fontSize: infoContainerTextSize }); + this.pokemonAbilityLabelText = addTextObject(infoContainerLabelXPos, 29, i18next.t("pokemonInfoContainer:ability"), TextStyle.WINDOW, { fontSize: infoContainerTextSize }); this.pokemonAbilityLabelText.setOrigin(1, 0); this.pokemonAbilityLabelText.setName("text-pkmn-ability-label"); this.add(this.pokemonAbilityLabelText); - this.pokemonAbilityText = addTextObject(this.scene, infoContainerTextXPos, 29, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); + this.pokemonAbilityText = addTextObject(infoContainerTextXPos, 29, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); this.pokemonAbilityText.setOrigin(0, 0); this.pokemonAbilityText.setName("text-pkmn-ability"); this.add(this.pokemonAbilityText); - this.pokemonNatureLabelText = addTextObject(this.scene, infoContainerLabelXPos, 39, i18next.t("pokemonInfoContainer:nature"), TextStyle.WINDOW, { fontSize: infoContainerTextSize }); + this.pokemonNatureLabelText = addTextObject(infoContainerLabelXPos, 39, i18next.t("pokemonInfoContainer:nature"), TextStyle.WINDOW, { fontSize: infoContainerTextSize }); this.pokemonNatureLabelText.setOrigin(1, 0); this.pokemonNatureLabelText.setName("text-pkmn-nature-label"); this.add(this.pokemonNatureLabelText); - this.pokemonNatureText = addBBCodeTextObject(this.scene, infoContainerTextXPos, 39, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize, lineSpacing: 3, maxLines: 2 }); + this.pokemonNatureText = addBBCodeTextObject(infoContainerTextXPos, 39, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize, lineSpacing: 3, maxLines: 2 }); this.pokemonNatureText.setOrigin(0, 0); this.pokemonNatureText.setName("text-pkmn-nature"); this.add(this.pokemonNatureText); - this.pokemonShinyIcon = this.scene.add.image(-43.5, 48.5, "shiny_star"); + this.pokemonShinyIcon = globalScene.add.image(-43.5, 48.5, "shiny_star"); this.pokemonShinyIcon.setOrigin(0, 0); this.pokemonShinyIcon.setScale(0.75); this.pokemonShinyIcon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 12, 15), Phaser.Geom.Rectangle.Contains); this.pokemonShinyIcon.setName("img-pkmn-shiny-icon"); this.add(this.pokemonShinyIcon); - this.pokemonShinyNewIcon = addTextObject(this.scene, this.pokemonShinyIcon.x + 12, this.pokemonShinyIcon.y, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); + this.pokemonShinyNewIcon = addTextObject(this.pokemonShinyIcon.x + 12, this.pokemonShinyIcon.y, "", TextStyle.WINDOW, { fontSize: infoContainerTextSize }); this.pokemonShinyNewIcon.setOrigin(0, 0); this.pokemonShinyNewIcon.setName("text-pkmn-shiny-new-icon"); this.add(this.pokemonShinyNewIcon); this.pokemonShinyNewIcon.setVisible(false); - this.pokemonFusionShinyIcon = this.scene.add.image(this.pokemonShinyIcon.x, this.pokemonShinyIcon.y, "shiny_star_2"); + this.pokemonFusionShinyIcon = globalScene.add.image(this.pokemonShinyIcon.x, this.pokemonShinyIcon.y, "shiny_star_2"); this.pokemonFusionShinyIcon.setOrigin(0, 0); this.pokemonFusionShinyIcon.setScale(0.75); this.pokemonFusionShinyIcon.setName("img-pkmn-fusion-shiny-icon"); @@ -194,10 +194,10 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { show(pokemon: Pokemon, showMoves: boolean = false, speedMultiplier: number = 1, dexEntry?: DexEntry, starterEntry?: StarterDataEntry, eggInfo = false): Promise { return new Promise(resolve => { if (!dexEntry) { - dexEntry = pokemon.scene.gameData.dexData[pokemon.species.speciesId]; + dexEntry = globalScene.gameData.dexData[pokemon.species.speciesId]; } if (!starterEntry) { - starterEntry = pokemon.scene.gameData.starterData[pokemon.species.getRootSpeciesId()]; + starterEntry = globalScene.gameData.starterData[pokemon.species.getRootSpeciesId()]; } const caughtAttr = BigInt(dexEntry.caughtAttr); @@ -209,8 +209,8 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { const newGender = BigInt(1 << pokemon.gender) * DexAttr.MALE; this.pokemonGenderNewText.setText("(+)"); - this.pokemonGenderNewText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, this.scene.uiTheme)); - this.pokemonGenderNewText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, this.scene.uiTheme)); + this.pokemonGenderNewText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, globalScene.uiTheme)); + this.pokemonGenderNewText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, globalScene.uiTheme)); this.pokemonGenderNewText.setVisible((newGender & caughtAttr) === BigInt(0)); } else { this.pokemonGenderNewText.setVisible(false); @@ -241,18 +241,18 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { const newForm = BigInt(1 << pokemon.formIndex) * DexAttr.DEFAULT_FORM; if ((newForm & caughtAttr) === BigInt(0)) { - this.pokemonFormLabelText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, this.scene.uiTheme)); - this.pokemonFormLabelText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, this.scene.uiTheme)); + this.pokemonFormLabelText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, globalScene.uiTheme)); + this.pokemonFormLabelText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, globalScene.uiTheme)); } else { - this.pokemonFormLabelText.setColor(getTextColor(TextStyle.WINDOW, false, this.scene.uiTheme)); - this.pokemonFormLabelText.setShadowColor(getTextColor(TextStyle.WINDOW, true, this.scene.uiTheme)); + this.pokemonFormLabelText.setColor(getTextColor(TextStyle.WINDOW, false, globalScene.uiTheme)); + this.pokemonFormLabelText.setShadowColor(getTextColor(TextStyle.WINDOW, true, globalScene.uiTheme)); } this.pokemonFormText.setText(formName.length > this.numCharsBeforeCutoff ? formName.substring(0, this.numCharsBeforeCutoff - 3) + "..." : formName); if (formName.length > this.numCharsBeforeCutoff) { this.pokemonFormText.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.pokemonFormText.width, this.pokemonFormText.height), Phaser.Geom.Rectangle.Contains); - this.pokemonFormText.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", formName, true)); - this.pokemonFormText.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.pokemonFormText.on("pointerover", () => globalScene.ui.showTooltip("", formName, true)); + this.pokemonFormText.on("pointerout", () => globalScene.ui.hideTooltip()); } else { this.pokemonFormText.disableInteractive(); } @@ -264,31 +264,31 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { const abilityTextStyle = pokemon.abilityIndex === 2 ? TextStyle.MONEY : TextStyle.WINDOW; this.pokemonAbilityText.setText(pokemon.getAbility(true).name); - this.pokemonAbilityText.setColor(getTextColor(abilityTextStyle, false, this.scene.uiTheme)); - this.pokemonAbilityText.setShadowColor(getTextColor(abilityTextStyle, true, this.scene.uiTheme)); + this.pokemonAbilityText.setColor(getTextColor(abilityTextStyle, false, globalScene.uiTheme)); + this.pokemonAbilityText.setShadowColor(getTextColor(abilityTextStyle, true, globalScene.uiTheme)); // Check if the player owns ability for the root form const playerOwnsThisAbility = pokemon.checkIfPlayerHasAbilityOfStarter(starterEntry.abilityAttr); if (!playerOwnsThisAbility) { - this.pokemonAbilityLabelText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, this.scene.uiTheme)); - this.pokemonAbilityLabelText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, this.scene.uiTheme)); + this.pokemonAbilityLabelText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, globalScene.uiTheme)); + this.pokemonAbilityLabelText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, globalScene.uiTheme)); } else { - this.pokemonAbilityLabelText.setColor(getTextColor(TextStyle.WINDOW, false, this.scene.uiTheme)); - this.pokemonAbilityLabelText.setShadowColor(getTextColor(TextStyle.WINDOW, true, this.scene.uiTheme)); + this.pokemonAbilityLabelText.setColor(getTextColor(TextStyle.WINDOW, false, globalScene.uiTheme)); + this.pokemonAbilityLabelText.setShadowColor(getTextColor(TextStyle.WINDOW, true, globalScene.uiTheme)); } - this.pokemonNatureText.setText(getNatureName(pokemon.getNature(), true, false, false, this.scene.uiTheme)); + this.pokemonNatureText.setText(getNatureName(pokemon.getNature(), true, false, false, globalScene.uiTheme)); const dexNatures = dexEntry.natureAttr; const newNature = 1 << (pokemon.nature + 1); if (!(dexNatures & newNature)) { - this.pokemonNatureLabelText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, this.scene.uiTheme)); - this.pokemonNatureLabelText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, this.scene.uiTheme)); + this.pokemonNatureLabelText.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, globalScene.uiTheme)); + this.pokemonNatureLabelText.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, globalScene.uiTheme)); } else { - this.pokemonNatureLabelText.setColor(getTextColor(TextStyle.WINDOW, false, this.scene.uiTheme)); - this.pokemonNatureLabelText.setShadowColor(getTextColor(TextStyle.WINDOW, true, this.scene.uiTheme)); + this.pokemonNatureLabelText.setColor(getTextColor(TextStyle.WINDOW, false, globalScene.uiTheme)); + this.pokemonNatureLabelText.setShadowColor(getTextColor(TextStyle.WINDOW, true, globalScene.uiTheme)); } const isFusion = pokemon.isFusion(); @@ -302,22 +302,22 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { const shinyDescriptor = doubleShiny || baseVariant ? `${baseVariant === 2 ? i18next.t("common:epicShiny") : baseVariant === 1 ? i18next.t("common:rareShiny") : i18next.t("common:commonShiny")}${doubleShiny ? `/${pokemon.fusionVariant === 2 ? i18next.t("common:epicShiny") : pokemon.fusionVariant === 1 ? i18next.t("common:rareShiny") : i18next.t("common:commonShiny")}` : ""}` : ""; - this.pokemonShinyIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", `${i18next.t("common:shinyOnHover")}${shinyDescriptor ? ` (${shinyDescriptor})` : ""}`, true)); - this.pokemonShinyIcon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.pokemonShinyIcon.on("pointerover", () => globalScene.ui.showTooltip("", `${i18next.t("common:shinyOnHover")}${shinyDescriptor ? ` (${shinyDescriptor})` : ""}`, true)); + this.pokemonShinyIcon.on("pointerout", () => globalScene.ui.hideTooltip()); const newShiny = BigInt(1 << (pokemon.shiny ? 1 : 0)); const newVariant = BigInt(1 << (pokemon.variant + 4)); this.pokemonShinyNewIcon.setText("(+)"); - this.pokemonShinyNewIcon.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, this.scene.uiTheme)); - this.pokemonShinyNewIcon.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, this.scene.uiTheme)); + this.pokemonShinyNewIcon.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, globalScene.uiTheme)); + this.pokemonShinyNewIcon.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, globalScene.uiTheme)); const newShinyOrVariant = ((newShiny & caughtAttr) === BigInt(0)) || ((newVariant & caughtAttr) === BigInt(0)); this.pokemonShinyNewIcon.setVisible(!!newShinyOrVariant); } else if ((caughtAttr & DexAttr.NON_SHINY) === BigInt(0) && ((caughtAttr & DexAttr.SHINY) === DexAttr.SHINY)) { //If the player has *only* caught any shiny variant of this species, not a non-shiny this.pokemonShinyNewIcon.setVisible(true); this.pokemonShinyNewIcon.setText("(+)"); - this.pokemonShinyNewIcon.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, this.scene.uiTheme)); - this.pokemonShinyNewIcon.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, this.scene.uiTheme)); + this.pokemonShinyNewIcon.setColor(getTextColor(TextStyle.SUMMARY_BLUE, false, globalScene.uiTheme)); + this.pokemonShinyNewIcon.setShadowColor(getTextColor(TextStyle.SUMMARY_BLUE, true, globalScene.uiTheme)); } else { this.pokemonShinyNewIcon.setVisible(false); } @@ -329,12 +329,12 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { } const starterSpeciesId = pokemon.species.getRootSpeciesId(); - const originalIvs: integer[] | null = eggInfo ? (dexEntry.caughtAttr ? dexEntry.ivs : null) : (this.scene.gameData.dexData[starterSpeciesId].caughtAttr - ? this.scene.gameData.dexData[starterSpeciesId].ivs : null); + const originalIvs: integer[] | null = eggInfo ? (dexEntry.caughtAttr ? dexEntry.ivs : null) : (globalScene.gameData.dexData[starterSpeciesId].caughtAttr + ? globalScene.gameData.dexData[starterSpeciesId].ivs : null); this.statsContainer.updateIvs(pokemon.ivs, originalIvs!); // TODO: is this bang correct? if (!eggInfo) { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, duration: Utils.fixedInt(Math.floor(750 / speedMultiplier)), ease: "Cubic.easeInOut", @@ -345,7 +345,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { }); if (showMoves) { - this.scene.tweens.add({ + globalScene.tweens.add({ delay: Utils.fixedInt(Math.floor(325 / speedMultiplier)), targets: this.pokemonMovesContainer, duration: Utils.fixedInt(Math.floor(325 / speedMultiplier)), @@ -365,7 +365,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { this.setVisible(true); this.shown = true; - this.scene.hideEnemyModifierBar(); + globalScene.hideEnemyModifierBar(); }); } @@ -402,7 +402,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { makeRoomForConfirmUi(speedMultiplier: number = 1, fromCatch: boolean = false): Promise { const xPosition = fromCatch ? this.initialX - this.infoWindowWidth - 65 : this.initialX - this.infoWindowWidth - ConfirmUiHandler.windowWidth; return new Promise(resolve => { - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, duration: Utils.fixedInt(Math.floor(150 / speedMultiplier)), ease: "Cubic.easeInOut", @@ -417,18 +417,18 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { hide(speedMultiplier: number = 1): Promise { return new Promise(resolve => { if (!this.shown) { - this.scene.showEnemyModifierBar(); + globalScene.showEnemyModifierBar(); return resolve(); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.pokemonMovesContainer, duration: Utils.fixedInt(Math.floor(750 / speedMultiplier)), ease: "Cubic.easeInOut", x: this.movesContainerInitialX }); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, duration: Utils.fixedInt(Math.floor(750 / speedMultiplier)), ease: "Cubic.easeInOut", @@ -437,8 +437,8 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { this.setVisible(false); this.pokemonShinyIcon.off("pointerover"); this.pokemonShinyIcon.off("pointerout"); - (this.scene as BattleScene).ui.hideTooltip(); - this.scene.showEnemyModifierBar(); + globalScene.ui.hideTooltip(); + globalScene.showEnemyModifierBar(); resolve(); } }); @@ -447,7 +447,3 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { }); } } - -export default interface PokemonInfoContainer { - scene: BattleScene -} diff --git a/src/ui/registration-form-ui-handler.ts b/src/ui/registration-form-ui-handler.ts index 892f78bd1ba4..9c1fd3139fda 100644 --- a/src/ui/registration-form-ui-handler.ts +++ b/src/ui/registration-form-ui-handler.ts @@ -4,6 +4,7 @@ import { Mode } from "./ui"; import { TextStyle, addTextObject } from "./text"; import i18next from "i18next"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; +import { globalScene } from "#app/global-scene"; interface LanguageSetting { @@ -78,7 +79,7 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler { }); const warningMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.warningMessageFontSize ?? "42px"; - const label = addTextObject(this.scene, 10, 87, i18next.t("menu:registrationAgeWarning"), TextStyle.TOOLTIP_CONTENT, { fontSize: warningMessageFontSize }); + const label = addTextObject(10, 87, i18next.t("menu:registrationAgeWarning"), TextStyle.TOOLTIP_CONTENT, { fontSize: warningMessageFontSize }); this.modalContainer.add(label); } @@ -92,10 +93,10 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler { // Prevent overlapping overrides on action modification this.submitAction = originalRegistrationAction; this.sanitizeInputs(); - this.scene.ui.setMode(Mode.LOADING, { buttonActions: []}); + globalScene.ui.setMode(Mode.LOADING, { buttonActions: []}); const onFail = error => { - this.scene.ui.setMode(Mode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() })); - this.scene.ui.playError(); + globalScene.ui.setMode(Mode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() })); + globalScene.ui.playError(); const errorMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.errorMessageFontSize; if (errorMessageFontSize) { this.errorMessage.setFontSize(errorMessageFontSize); diff --git a/src/ui/run-history-ui-handler.ts b/src/ui/run-history-ui-handler.ts index 061f15d0956d..846eae917d7b 100644 --- a/src/ui/run-history-ui-handler.ts +++ b/src/ui/run-history-ui-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { GameModes } from "../game-mode"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; @@ -40,34 +40,34 @@ export default class RunHistoryUiHandler extends MessageUiHandler { private runContainerInitialY: number; - constructor(scene: BattleScene) { - super(scene, Mode.RUN_HISTORY); + constructor() { + super(Mode.RUN_HISTORY); } override setup() { const ui = this.getUi(); - this.runSelectContainer = this.scene.add.container(0, 0); + this.runSelectContainer = globalScene.add.container(0, 0); this.runSelectContainer.setVisible(false); ui.add(this.runSelectContainer); - const loadSessionBg = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, -this.scene.game.canvas.height / 6, 0x006860); + const loadSessionBg = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, -globalScene.game.canvas.height / 6, 0x006860); loadSessionBg.setOrigin(0, 0); this.runSelectContainer.add(loadSessionBg); - this.runContainerInitialY = -this.scene.game.canvas.height / 6 + 8; + this.runContainerInitialY = -globalScene.game.canvas.height / 6 + 8; - this.runsContainer = this.scene.add.container(8, this.runContainerInitialY); + this.runsContainer = globalScene.add.container(8, this.runContainerInitialY); this.runSelectContainer.add(this.runsContainer); this.runs = []; - this.scene.loadImage("hall_of_fame_red", "ui"); - this.scene.loadImage("hall_of_fame_blue", "ui"); + globalScene.loadImage("hall_of_fame_red", "ui"); + globalScene.loadImage("hall_of_fame_blue", "ui"); // For some reason, the game deletes/unloads the rival sprites. As a result, Run Info cannot access the rival sprites. // The rivals are loaded here to have some way of accessing those sprites. - this.scene.loadAtlas("rival_f", "trainer"); - this.scene.loadAtlas("rival_m", "trainer"); + globalScene.loadAtlas("rival_f", "trainer"); + globalScene.loadAtlas("rival_m", "trainer"); } override show(args: any[]): boolean { @@ -75,7 +75,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler { this.getUi().bringToTop(this.runSelectContainer); this.runSelectContainer.setVisible(true); - this.populateRuns(this.scene).then(() => { + this.populateRuns().then(() => { this.setScrollCursor(0); this.setCursor(0); @@ -105,7 +105,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler { if (button === Button.ACTION) { const cursor = this.cursor + this.scrollCursor; if (this.runs[cursor]) { - this.scene.ui.setOverlayMode(Mode.RUN_INFO, this.runs[cursor].entryData, RunDisplayMode.RUN_HISTORY, true); + globalScene.ui.setOverlayMode(Mode.RUN_INFO, this.runs[cursor].entryData, RunDisplayMode.RUN_HISTORY, true); } else { return false; } @@ -114,7 +114,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler { } else { this.runSelectCallback = null; success = true; - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); } } else if (this.runs.length > 0) { switch (button) { @@ -153,12 +153,11 @@ export default class RunHistoryUiHandler extends MessageUiHandler { /** * This retrieves the player's run history and facilitates the processes necessary for the output display. - * @param scene: BattleScene * Runs are displayed from newest --> oldest in descending order. * In the for loop, each run is processed to create an RunEntryContainer used to display and store the run's unique information */ - private async populateRuns(scene: BattleScene) { - const response = await this.scene.gameData.getRunHistoryData(this.scene); + private async populateRuns() { + const response = await globalScene.gameData.getRunHistoryData(); const timestamps = Object.keys(response); if (timestamps.length === 0) { this.showEmpty(); @@ -170,8 +169,8 @@ export default class RunHistoryUiHandler extends MessageUiHandler { } const entryCount = timestamps.length; for (let s = 0; s < entryCount; s++) { - const entry = new RunEntryContainer(this.scene, response[timestampsNo[s]], s); - this.scene.add.existing(entry); + const entry = new RunEntryContainer(response[timestampsNo[s]], s); + globalScene.add.existing(entry); this.runsContainer.add(entry); this.runs.push(entry); } @@ -184,10 +183,10 @@ export default class RunHistoryUiHandler extends MessageUiHandler { * If the player has no runs saved so far, this creates a giant window labeled empty instead. */ private async showEmpty() { - const emptyWindow = addWindow(this.scene, 0, 0, 304, 165); + const emptyWindow = addWindow(0, 0, 304, 165); this.runsContainer.add(emptyWindow); const emptyWindowCoordinates = emptyWindow.getCenter(); - const emptyText = addTextObject(this.scene, 0, 0, i18next.t("saveSlotSelectUiHandler:empty"), TextStyle.WINDOW, { fontSize: "128px" }); + const emptyText = addTextObject(0, 0, i18next.t("saveSlotSelectUiHandler:empty"), TextStyle.WINDOW, { fontSize: "128px" }); emptyText.setPosition(emptyWindowCoordinates.x - 18, emptyWindowCoordinates.y - 15); this.runsContainer.add(emptyText); } @@ -196,7 +195,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler { const changed = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.nineslice(0, 0, "select_cursor_highlight_thick", undefined, 296, 46, 6, 6, 6, 6); + this.cursorObj = globalScene.add.nineslice(0, 0, "select_cursor_highlight_thick", undefined, 296, 46, 6, 6, 6, 6); this.cursorObj.setOrigin(0, 0); this.runsContainer.add(this.cursorObj); } @@ -210,7 +209,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler { if (changed) { this.scrollCursor = scrollCursor; this.setCursor(this.cursor); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.runsContainer, y: this.runContainerInitialY - 56 * scrollCursor, duration: Utils.fixedInt(325), @@ -255,8 +254,8 @@ class RunEntryContainer extends Phaser.GameObjects.Container { private slotId: number; public entryData: RunEntry; - constructor(scene: BattleScene, entryData: RunEntry, slotId: number) { - super(scene, 0, slotId * 56); + constructor(entryData: RunEntry, slotId: number) { + super(globalScene, 0, slotId * 56); this.slotId = slotId; this.entryData = entryData; @@ -278,31 +277,31 @@ class RunEntryContainer extends Phaser.GameObjects.Container { private setup(run: RunEntry) { const victory = run.isVictory; - const data = this.scene.gameData.parseSessionData(JSON.stringify(run.entry)); + const data = globalScene.gameData.parseSessionData(JSON.stringify(run.entry)); - const slotWindow = addWindow(this.scene, 0, 0, 304, 52); + const slotWindow = addWindow(0, 0, 304, 52); this.add(slotWindow); // Run Result: Victory if (victory) { - const gameOutcomeLabel = addTextObject(this.scene, 8, 5, `${i18next.t("runHistory:victory")}`, TextStyle.WINDOW); + const gameOutcomeLabel = addTextObject(8, 5, `${i18next.t("runHistory:victory")}`, TextStyle.WINDOW); this.add(gameOutcomeLabel); } else { // Run Result: Defeats - const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const genderStr = PlayerGender[genderIndex].toLowerCase(); // Defeats from wild Pokemon battles will show the Pokemon responsible by the text of the run result. if (data.battleType === BattleType.WILD || (data.battleType === BattleType.MYSTERY_ENCOUNTER && !data.trainer)) { - const enemyContainer = this.scene.add.container(8, 5); - const gameOutcomeLabel = addTextObject(this.scene, 0, 0, `${i18next.t("runHistory:defeatedWild", { context: genderStr })}`, TextStyle.WINDOW); + const enemyContainer = globalScene.add.container(8, 5); + const gameOutcomeLabel = addTextObject(0, 0, `${i18next.t("runHistory:defeatedWild", { context: genderStr })}`, TextStyle.WINDOW); enemyContainer.add(gameOutcomeLabel); data.enemyParty.forEach((enemyData, e) => { - const enemyIconContainer = this.scene.add.container(65 + (e * 25), -8); + const enemyIconContainer = globalScene.add.container(65 + (e * 25), -8); enemyIconContainer.setScale(0.75); enemyData.boss = false; enemyData["player"] = true; - const enemy = enemyData.toPokemon(this.scene); - const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0); - const enemyLevel = addTextObject(this.scene, 32, 20, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }); + const enemy = enemyData.toPokemon(); + const enemyIcon = globalScene.addPokemonIcon(enemy, 0, 0, 0, 0); + const enemyLevel = addTextObject(32, 20, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }); enemyLevel.setShadow(0, 0, undefined); enemyLevel.setStroke("#424242", 14); enemyLevel.setOrigin(1, 0); @@ -313,15 +312,15 @@ class RunEntryContainer extends Phaser.GameObjects.Container { }); this.add(enemyContainer); } else if (data.battleType === BattleType.TRAINER || (data.battleType === BattleType.MYSTERY_ENCOUNTER && data.trainer)) { // Defeats from Trainers show the trainer's title and name - const tObj = data.trainer.toTrainer(this.scene); + const tObj = data.trainer.toTrainer(); // Because of the interesting mechanics behind rival names, the rival name and title have to be retrieved differently const RIVAL_TRAINER_ID_THRESHOLD = 375; if (data.trainer.trainerType >= RIVAL_TRAINER_ID_THRESHOLD) { const rivalName = (tObj.variant === TrainerVariant.FEMALE) ? "trainerNames:rival_female" : "trainerNames:rival"; - const gameOutcomeLabel = addTextObject(this.scene, 8, 5, `${i18next.t("runHistory:defeatedRival", { context: genderStr })} ${i18next.t(rivalName)}`, TextStyle.WINDOW); + const gameOutcomeLabel = addTextObject(8, 5, `${i18next.t("runHistory:defeatedRival", { context: genderStr })} ${i18next.t(rivalName)}`, TextStyle.WINDOW); this.add(gameOutcomeLabel); } else { - const gameOutcomeLabel = addTextObject(this.scene, 8, 5, `${i18next.t("runHistory:defeatedTrainer", { context: genderStr })}${tObj.getName(0, true)}`, TextStyle.WINDOW); + const gameOutcomeLabel = addTextObject(8, 5, `${i18next.t("runHistory:defeatedTrainer", { context: genderStr })}${tObj.getName(0, true)}`, TextStyle.WINDOW); this.add(gameOutcomeLabel); } } @@ -330,7 +329,7 @@ class RunEntryContainer extends Phaser.GameObjects.Container { // Game Mode + Waves // Because Endless (Spliced) tends to have the longest name across languages, the line tends to spill into the party icons. // To fix this, the Spliced icon is used to indicate an Endless Spliced run - const gameModeLabel = addTextObject(this.scene, 8, 19, "", TextStyle.WINDOW); + const gameModeLabel = addTextObject(8, 19, "", TextStyle.WINDOW); let mode = ""; switch (data.gameMode) { case GameModes.DAILY: @@ -349,7 +348,7 @@ class RunEntryContainer extends Phaser.GameObjects.Container { } gameModeLabel.appendText(mode, false); if (data.gameMode === GameModes.SPLICED_ENDLESS) { - const splicedIcon = this.scene.add.image(0, 0, "icon_spliced"); + const splicedIcon = globalScene.add.image(0, 0, "icon_spliced"); splicedIcon.setScale(0.75); const coords = gameModeLabel.getTopRight(); splicedIcon.setPosition(coords.x + 5, 27); @@ -362,21 +361,21 @@ class RunEntryContainer extends Phaser.GameObjects.Container { gameModeLabel.appendText(i18next.t("saveSlotSelectUiHandler:wave") + " " + data.waveIndex, false); this.add(gameModeLabel); - const timestampLabel = addTextObject(this.scene, 8, 33, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW); + const timestampLabel = addTextObject(8, 33, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW); this.add(timestampLabel); // pokemonIconsContainer holds the run's party Pokemon icons and levels // Icons should be level with each other here, but there are significant number of icons that have a center axis / position far from the norm. // The code here does not account for icon weirdness. - const pokemonIconsContainer = this.scene.add.container(140, 17); + const pokemonIconsContainer = globalScene.add.container(140, 17); data.party.forEach((p: PokemonData, i: number) => { - const iconContainer = this.scene.add.container(26 * i, 0); + const iconContainer = globalScene.add.container(26 * i, 0); iconContainer.setScale(0.75); - const pokemon = p.toPokemon(this.scene); - const icon = this.scene.addPokemonIcon(pokemon, 0, 0, 0, 0); + const pokemon = p.toPokemon(); + const icon = globalScene.addPokemonIcon(pokemon, 0, 0, 0, 0); - const text = addTextObject(this.scene, 32, 20, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(pokemon.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }); + const text = addTextObject(32, 20, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(pokemon.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }); text.setShadow(0, 0, undefined); text.setStroke("#424242", 14); text.setOrigin(1, 0); @@ -392,8 +391,3 @@ class RunEntryContainer extends Phaser.GameObjects.Container { this.add(pokemonIconsContainer); } } - -interface RunEntryContainer { - scene: BattleScene; -} - diff --git a/src/ui/run-info-ui-handler.ts b/src/ui/run-info-ui-handler.ts index 071690aee54b..e5f6369e0ea4 100644 --- a/src/ui/run-info-ui-handler.ts +++ b/src/ui/run-info-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import { GameModes } from "../game-mode"; import UiHandler from "./ui-handler"; import { SessionSaveData } from "../system/game-data"; @@ -26,6 +25,7 @@ import { PlayerGender } from "#enums/player-gender"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; import { getBiomeName } from "#app/data/balance/biomes"; import { MysteryEncounterType } from "#enums/mystery-encounter-type"; +import { globalScene } from "#app/global-scene"; /** * RunInfoUiMode indicates possible overlays of RunInfoUiHandler. @@ -67,16 +67,16 @@ export default class RunInfoUiHandler extends UiHandler { private partyVisibility: Boolean; private modifiersModule: any; - constructor(scene: BattleScene) { - super(scene, Mode.RUN_INFO); + constructor() { + super(Mode.RUN_INFO); } override async setup() { - this.runContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1); + this.runContainer = globalScene.add.container(1, -(globalScene.game.canvas.height / 6) + 1); // The import of the modifiersModule is loaded here to sidestep async/await issues. this.modifiersModule = Modifier; this.runContainer.setVisible(false); - this.scene.loadImage("encounter_exclaim", "mystery-encounters"); + globalScene.loadImage("encounter_exclaim", "mystery-encounters"); } /** @@ -93,14 +93,14 @@ export default class RunInfoUiHandler extends UiHandler { override show(args: any[]): boolean { super.show(args); - const gameStatsBg = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width, this.scene.game.canvas.height, 0x006860); + const gameStatsBg = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width, globalScene.game.canvas.height, 0x006860); gameStatsBg.setOrigin(0, 0); this.runContainer.add(gameStatsBg); const run = args[0]; this.runDisplayMode = args[1]; if (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) { - this.runInfo = this.scene.gameData.parseSessionData(JSON.stringify(run.entry)); + this.runInfo = globalScene.gameData.parseSessionData(JSON.stringify(run.entry)); this.isVictory = run.isVictory ?? false; } else if (this.runDisplayMode === RunDisplayMode.SESSION_PREVIEW) { this.runInfo = args[0]; @@ -112,11 +112,11 @@ export default class RunInfoUiHandler extends UiHandler { // Creates Header and adds to this.runContainer this.addHeader(); - this.statsBgWidth = ((this.scene.game.canvas.width / 6) - 2) / 3; + this.statsBgWidth = ((globalScene.game.canvas.width / 6) - 2) / 3; // Creates Run Result Container - this.runResultContainer = this.scene.add.container(0, 24); - const runResultWindow = addWindow(this.scene, 0, 0, this.statsBgWidth - 11, 65); + this.runResultContainer = globalScene.add.container(0, 24); + const runResultWindow = addWindow(0, 0, this.statsBgWidth - 11, 65); runResultWindow.setOrigin(0, 0); runResultWindow.setName("Run_Result_Window"); this.runResultContainer.add(runResultWindow); @@ -127,18 +127,18 @@ export default class RunInfoUiHandler extends UiHandler { } // Creates Run Info Container - this.runInfoContainer = this.scene.add.container(0, 89); - const runInfoWindow = addWindow(this.scene, 0, 0, this.statsBgWidth - 11, 90); + this.runInfoContainer = globalScene.add.container(0, 89); + const runInfoWindow = addWindow(0, 0, this.statsBgWidth - 11, 90); const runInfoWindowCoords = runInfoWindow.getBottomRight(); this.runInfoContainer.add(runInfoWindow); this.parseRunInfo(runInfoWindowCoords.x, runInfoWindowCoords.y); // Creates Player Party Container - this.partyContainer = this.scene.add.container(this.statsBgWidth - 10, 23); + this.partyContainer = globalScene.add.container(this.statsBgWidth - 10, 23); this.parsePartyInfo(); this.showParty(true); - this.runContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.runContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); this.getUi().bringToTop(this.runContainer); this.runContainer.setVisible(true); @@ -163,25 +163,25 @@ export default class RunInfoUiHandler extends UiHandler { * It does not check if the run has any PokemonHeldItemModifiers though. */ private addHeader() { - const headerBg = addWindow(this.scene, 0, 0, (this.scene.game.canvas.width / 6) - 2, 24); + const headerBg = addWindow(0, 0, (globalScene.game.canvas.width / 6) - 2, 24); headerBg.setOrigin(0, 0); this.runContainer.add(headerBg); if (this.runInfo.modifiers.length !== 0) { const headerBgCoords = headerBg.getTopRight(); - const abilityButtonContainer = this.scene.add.container(0, 0); - const abilityButtonText = addTextObject(this.scene, 8, 0, i18next.t("runHistory:viewHeldItems"), TextStyle.WINDOW, { fontSize:"34px" }); + const abilityButtonContainer = globalScene.add.container(0, 0); + const abilityButtonText = addTextObject(8, 0, i18next.t("runHistory:viewHeldItems"), TextStyle.WINDOW, { fontSize:"34px" }); const gamepadType = this.getUi().getGamepadType(); let abilityButtonElement: Phaser.GameObjects.Sprite; if (gamepadType === "touch") { - abilityButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 2, "keyboard", "E.png"); + abilityButtonElement = new Phaser.GameObjects.Sprite(globalScene, 0, 2, "keyboard", "E.png"); } else { - abilityButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 2, gamepadType, this.scene.inputController?.getIconForLatestInputRecorded(SettingKeyboard.Button_Cycle_Ability)); + abilityButtonElement = new Phaser.GameObjects.Sprite(globalScene, 0, 2, gamepadType, globalScene.inputController?.getIconForLatestInputRecorded(SettingKeyboard.Button_Cycle_Ability)); } abilityButtonContainer.add([ abilityButtonText, abilityButtonElement ]); abilityButtonContainer.setPosition(headerBgCoords.x - abilityButtonText.displayWidth - abilityButtonElement.displayWidth - 8, 10); this.runContainer.add(abilityButtonContainer); } - const headerText = addTextObject(this.scene, 0, 0, i18next.t("runHistory:runInfo"), TextStyle.SETTINGS_LABEL); + const headerText = addTextObject(0, 0, i18next.t("runHistory:runInfo"), TextStyle.SETTINGS_LABEL); headerText.setOrigin(0, 0); headerText.setPositionRelative(headerBg, 8, 4); this.runContainer.add(headerText); @@ -196,25 +196,25 @@ export default class RunInfoUiHandler extends UiHandler { * */ private async parseRunResult() { - const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const genderStr = PlayerGender[genderIndex]; const runResultTextStyle = this.isVictory ? TextStyle.PERFECT_IV : TextStyle.SUMMARY_RED; const runResultTitle = this.isVictory ? i18next.t("runHistory:victory") : i18next.t("runHistory:defeated", { context: genderStr }); - const runResultText = addTextObject(this.scene, 6, 5, `${runResultTitle} - ${i18next.t("saveSlotSelectUiHandler:wave")} ${this.runInfo.waveIndex}`, runResultTextStyle, { fontSize : "65px", lineSpacing: 0.1 }); + const runResultText = addTextObject(6, 5, `${runResultTitle} - ${i18next.t("saveSlotSelectUiHandler:wave")} ${this.runInfo.waveIndex}`, runResultTextStyle, { fontSize : "65px", lineSpacing: 0.1 }); if (this.isVictory) { - const hallofFameInstructionContainer = this.scene.add.container(0, 0); - const shinyButtonText = addTextObject(this.scene, 8, 0, i18next.t("runHistory:viewHallOfFame"), TextStyle.WINDOW, { fontSize:"65px" }); - const formButtonText = addTextObject(this.scene, 8, 12, i18next.t("runHistory:viewEndingSplash"), TextStyle.WINDOW, { fontSize:"65px" }); + const hallofFameInstructionContainer = globalScene.add.container(0, 0); + const shinyButtonText = addTextObject(8, 0, i18next.t("runHistory:viewHallOfFame"), TextStyle.WINDOW, { fontSize:"65px" }); + const formButtonText = addTextObject(8, 12, i18next.t("runHistory:viewEndingSplash"), TextStyle.WINDOW, { fontSize:"65px" }); const gamepadType = this.getUi().getGamepadType(); let shinyButtonElement: Phaser.GameObjects.Sprite; let formButtonElement: Phaser.GameObjects.Sprite; if (gamepadType === "touch") { - shinyButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 4, "keyboard", "R.png"); - formButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 16, "keyboard", "F.png"); + shinyButtonElement = new Phaser.GameObjects.Sprite(globalScene, 0, 4, "keyboard", "R.png"); + formButtonElement = new Phaser.GameObjects.Sprite(globalScene, 0, 16, "keyboard", "F.png"); } else { - shinyButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 4, gamepadType, this.scene.inputController?.getIconForLatestInputRecorded(SettingKeyboard.Button_Cycle_Shiny)); - formButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 16, gamepadType, this.scene.inputController?.getIconForLatestInputRecorded(SettingKeyboard.Button_Cycle_Form)); + shinyButtonElement = new Phaser.GameObjects.Sprite(globalScene, 0, 4, gamepadType, globalScene.inputController?.getIconForLatestInputRecorded(SettingKeyboard.Button_Cycle_Shiny)); + formButtonElement = new Phaser.GameObjects.Sprite(globalScene, 0, 16, gamepadType, globalScene.inputController?.getIconForLatestInputRecorded(SettingKeyboard.Button_Cycle_Form)); } hallofFameInstructionContainer.add([ shinyButtonText, shinyButtonElement ]); @@ -227,7 +227,7 @@ export default class RunInfoUiHandler extends UiHandler { this.runResultContainer.add(runResultText); if (!this.isVictory) { - const enemyContainer = this.scene.add.container(0, 0); + const enemyContainer = globalScene.add.container(0, 0); // Wild - Single and Doubles if (this.runInfo.battleType === BattleType.WILD || (this.runInfo.battleType === BattleType.MYSTERY_ENCOUNTER && !this.runInfo.trainer)) { switch (this.runInfo.enemyParty.length) { @@ -255,7 +255,7 @@ export default class RunInfoUiHandler extends UiHandler { * Mystery Encounters contain sprites associated with MEs + the title of the specific ME. */ private parseRunStatus() { - const enemyContainer = this.scene.add.container(0, 0); + const enemyContainer = globalScene.add.container(0, 0); this.runResultContainer.add(enemyContainer); if (this.runInfo.battleType === BattleType.WILD) { if (this.runInfo.enemyParty.length === 1) { @@ -267,13 +267,13 @@ export default class RunInfoUiHandler extends UiHandler { this.showTrainerSprites(enemyContainer); const row_limit = 3; this.runInfo.enemyParty.forEach((p, i) => { - const pokeball = this.scene.add.sprite(0, 0, "pb"); + const pokeball = globalScene.add.sprite(0, 0, "pb"); pokeball.setFrame(getPokeballAtlasKey(p.pokeball)); pokeball.setScale(0.5); pokeball.setPosition(58 + ((i % row_limit) * 8), (i <= 2) ? 18 : 25); enemyContainer.add(pokeball); }); - const trainerObj = this.runInfo.trainer.toTrainer(this.scene); + const trainerObj = this.runInfo.trainer.toTrainer(); const RIVAL_TRAINER_ID_THRESHOLD = 375; let trainerName = ""; if (this.runInfo.trainer.trainerType >= RIVAL_TRAINER_ID_THRESHOLD) { @@ -282,21 +282,21 @@ export default class RunInfoUiHandler extends UiHandler { trainerName = trainerObj.getName(0, true); } const boxString = i18next.t(trainerObj.variant !== TrainerVariant.DOUBLE ? "battle:trainerAppeared" : "battle:trainerAppearedDouble", { trainerName: trainerName }).replace(/\n/g, " "); - const descContainer = this.scene.add.container(0, 0); - const textBox = addTextObject(this.scene, 0, 0, boxString, TextStyle.WINDOW, { fontSize : "35px", wordWrap: { width: 200 }}); + const descContainer = globalScene.add.container(0, 0); + const textBox = addTextObject(0, 0, boxString, TextStyle.WINDOW, { fontSize : "35px", wordWrap: { width: 200 }}); descContainer.add(textBox); descContainer.setPosition(55, 32); this.runResultContainer.add(descContainer); } else if (this.runInfo.battleType === BattleType.MYSTERY_ENCOUNTER) { - const encounterExclaim = this.scene.add.sprite(0, 0, "encounter_exclaim"); + const encounterExclaim = globalScene.add.sprite(0, 0, "encounter_exclaim"); encounterExclaim.setPosition(34, 26); encounterExclaim.setScale(0.65); - const subSprite = this.scene.add.sprite(56, -106, "pkmn__sub"); + const subSprite = globalScene.add.sprite(56, -106, "pkmn__sub"); subSprite.setScale(0.65); subSprite.setPosition(34, 46); - const mysteryEncounterTitle = i18next.t(this.scene.getMysteryEncounter(this.runInfo.mysteryEncounterType as MysteryEncounterType, true).localizationKey + ":title"); - const descContainer = this.scene.add.container(0, 0); - const textBox = addTextObject(this.scene, 0, 0, mysteryEncounterTitle, TextStyle.WINDOW, { fontSize : "45px", wordWrap: { width: 160 }}); + const mysteryEncounterTitle = i18next.t(globalScene.getMysteryEncounter(this.runInfo.mysteryEncounterType as MysteryEncounterType, true).localizationKey + ":title"); + const descContainer = globalScene.add.container(0, 0); + const textBox = addTextObject(0, 0, mysteryEncounterTitle, TextStyle.WINDOW, { fontSize : "45px", wordWrap: { width: 160 }}); descContainer.add(textBox); descContainer.setPosition(47, 37); this.runResultContainer.add([ encounterExclaim, subSprite, descContainer ]); @@ -306,10 +306,10 @@ export default class RunInfoUiHandler extends UiHandler { const windowCenterX = runResultWindow.getTopCenter().x; const windowBottomY = runResultWindow.getBottomCenter().y; - const runStatusText = addTextObject(this.scene, windowCenterX, 5, `${i18next.t("saveSlotSelectUiHandler:wave")} ${this.runInfo.waveIndex}`, TextStyle.WINDOW, { fontSize : "60px", lineSpacing: 0.1 }); + const runStatusText = addTextObject(windowCenterX, 5, `${i18next.t("saveSlotSelectUiHandler:wave")} ${this.runInfo.waveIndex}`, TextStyle.WINDOW, { fontSize : "60px", lineSpacing: 0.1 }); runStatusText.setOrigin(0.5, 0); - const currentBiomeText = addTextObject(this.scene, windowCenterX, windowBottomY - 5, `${getBiomeName(this.runInfo.arena.biome)}`, TextStyle.WINDOW, { fontSize: "60px" }); + const currentBiomeText = addTextObject(windowCenterX, windowBottomY - 5, `${getBiomeName(this.runInfo.arena.biome)}`, TextStyle.WINDOW, { fontSize: "60px" }); currentBiomeText.setOrigin(0.5, 1); this.runResultContainer.add([ runStatusText, currentBiomeText ]); @@ -321,16 +321,16 @@ export default class RunInfoUiHandler extends UiHandler { * @param enemyContainer - container holding enemy visual and level information */ private parseWildSingleDefeat(enemyContainer: Phaser.GameObjects.Container) { - const enemyIconContainer = this.scene.add.container(0, 0); + const enemyIconContainer = globalScene.add.container(0, 0); const enemyData = this.runInfo.enemyParty[0]; const bossStatus = enemyData.boss; enemyData.boss = false; enemyData["player"] = true; //addPokemonIcon() throws an error if the Pokemon used is a boss - const enemy = enemyData.toPokemon(this.scene); - const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0); + const enemy = enemyData.toPokemon(); + const enemyIcon = globalScene.addPokemonIcon(enemy, 0, 0, 0, 0); const enemyLevelStyle = bossStatus ? TextStyle.PARTY_RED : TextStyle.PARTY; - const enemyLevel = addTextObject(this.scene, 36, 26, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, enemyLevelStyle, { fontSize: "44px", color: "#f8f8f8" }); + const enemyLevel = addTextObject(36, 26, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, enemyLevelStyle, { fontSize: "44px", color: "#f8f8f8" }); enemyLevel.setShadow(0, 0, undefined); enemyLevel.setStroke("#424242", 14); enemyLevel.setOrigin(1, 0); @@ -348,13 +348,13 @@ export default class RunInfoUiHandler extends UiHandler { */ private parseWildDoubleDefeat(enemyContainer: Phaser.GameObjects.Container) { this.runInfo.enemyParty.forEach((enemyData, e) => { - const enemyIconContainer = this.scene.add.container(0, 0); + const enemyIconContainer = globalScene.add.container(0, 0); const bossStatus = enemyData.boss; enemyData.boss = false; enemyData["player"] = true; - const enemy = enemyData.toPokemon(this.scene); - const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0); - const enemyLevel = addTextObject(this.scene, 36, 26, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, bossStatus ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "44px", color: "#f8f8f8" }); + const enemy = enemyData.toPokemon(); + const enemyIcon = globalScene.addPokemonIcon(enemy, 0, 0, 0, 0); + const enemyLevel = addTextObject(36, 26, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, bossStatus ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "44px", color: "#f8f8f8" }); enemyLevel.setShadow(0, 0, undefined); enemyLevel.setStroke("#424242", 14); enemyLevel.setOrigin(1, 0); @@ -374,16 +374,16 @@ export default class RunInfoUiHandler extends UiHandler { */ private showTrainerSprites(enemyContainer: Phaser.GameObjects.Container) { // Creating the trainer sprite and adding it to enemyContainer - const tObj = this.runInfo.trainer.toTrainer(this.scene); + const tObj = this.runInfo.trainer.toTrainer(); // Loads trainer assets on demand, as they are not loaded by default in the scene - tObj.config.loadAssets(this.scene, this.runInfo.trainer.variant).then(() => { + tObj.config.loadAssets(this.runInfo.trainer.variant).then(() => { const tObjSpriteKey = tObj.config.getSpriteKey(this.runInfo.trainer.variant === TrainerVariant.FEMALE, false); - const tObjSprite = this.scene.add.sprite(0, 5, tObjSpriteKey); + const tObjSprite = globalScene.add.sprite(0, 5, tObjSpriteKey); if (this.runInfo.trainer.variant === TrainerVariant.DOUBLE && !tObj.config.doubleOnly) { - const doubleContainer = this.scene.add.container(5, 8); + const doubleContainer = globalScene.add.container(5, 8); tObjSprite.setPosition(-3, -3); const tObjPartnerSpriteKey = tObj.config.getSpriteKey(true, true); - const tObjPartnerSprite = this.scene.add.sprite(5, -3, tObjPartnerSpriteKey); + const tObjPartnerSprite = globalScene.add.sprite(5, -3, tObjPartnerSpriteKey); // Double Trainers have smaller sprites than Single Trainers if (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) { tObjPartnerSprite.setScale(0.20); @@ -424,7 +424,7 @@ export default class RunInfoUiHandler extends UiHandler { // Creates a dictionary {PokemonId: TeraShardType} const teraPokemon = {}; this.runInfo.enemyModifiers.forEach((m) => { - const modifier = m.toModifier(this.scene, this.modifiersModule[m.className]); + const modifier = m.toModifier(this.modifiersModule[m.className]); if (modifier instanceof Modifier.TerastallizeModifier) { const teraDetails = modifier?.getArgs(); const pkmnId = teraDetails[0]; @@ -434,16 +434,16 @@ export default class RunInfoUiHandler extends UiHandler { // Creates the Pokemon icons + level information and adds it to enemyContainer // 2 Rows x 3 Columns - const enemyPartyContainer = this.scene.add.container(0, 0); + const enemyPartyContainer = globalScene.add.container(0, 0); this.runInfo.enemyParty.forEach((enemyData, e) => { const pokemonRowHeight = Math.floor(e / 3); - const enemyIconContainer = this.scene.add.container(0, 0); + const enemyIconContainer = globalScene.add.container(0, 0); enemyIconContainer.setScale(0.6); const isBoss = enemyData.boss; enemyData.boss = false; enemyData["player"] = true; - const enemy = enemyData.toPokemon(this.scene); - const enemyIcon = this.scene.addPokemonIcon(enemy, 0, 0, 0, 0); + const enemy = enemyData.toPokemon(); + const enemyIcon = globalScene.addPokemonIcon(enemy, 0, 0, 0, 0); // Applying Terastallizing Type tint to Pokemon icon // If the Pokemon is a fusion, it has two sprites and so, the tint has to be applied to each icon separately const enemySprite1 = enemyIcon.list[0] as Phaser.GameObjects.Sprite; @@ -457,7 +457,7 @@ export default class RunInfoUiHandler extends UiHandler { } } enemyIcon.setPosition(39 * (e % 3) + 5, (35 * pokemonRowHeight)); - const enemyLevel = addTextObject(this.scene, 43 * (e % 3), (27 * (pokemonRowHeight + 1)), `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, isBoss ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "54px" }); + const enemyLevel = addTextObject(43 * (e % 3), (27 * (pokemonRowHeight + 1)), `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(enemy.level, 1000)}`, isBoss ? TextStyle.PARTY_RED : TextStyle.PARTY, { fontSize: "54px" }); enemyLevel.setShadow(0, 0, undefined); enemyLevel.setStroke("#424242", 14); enemyLevel.setOrigin(0, 0); @@ -480,7 +480,7 @@ export default class RunInfoUiHandler extends UiHandler { private async parseRunInfo(windowX: number, windowY: number) { // Parsing and displaying the mode. // In the future, parsing Challenges + Challenge Rules may have to be reworked as PokeRogue adds additional challenges and users can stack these challenges in various ways. - const modeText = addBBCodeTextObject(this.scene, 7, 0, "", TextStyle.WINDOW, { fontSize : "50px", lineSpacing:3 }); + const modeText = addBBCodeTextObject(7, 0, "", TextStyle.WINDOW, { fontSize : "50px", lineSpacing:3 }); modeText.setPosition(7, 5); modeText.appendText(i18next.t("runHistory:mode") + ": ", false); switch (this.runInfo.gameMode) { @@ -514,27 +514,27 @@ export default class RunInfoUiHandler extends UiHandler { } // If the player achieves a personal best in Endless, the mode text will be tinted similarly to SSS luck to celebrate their achievement. - if ((this.runInfo.gameMode === GameModes.ENDLESS || this.runInfo.gameMode === GameModes.SPLICED_ENDLESS) && this.runInfo.waveIndex === this.scene.gameData.gameStats.highestEndlessWave) { + if ((this.runInfo.gameMode === GameModes.ENDLESS || this.runInfo.gameMode === GameModes.SPLICED_ENDLESS) && this.runInfo.waveIndex === globalScene.gameData.gameStats.highestEndlessWave) { modeText.appendText(` [${i18next.t("runHistory:personalBest")}]`); modeText.setTint(0xffef5c, 0x47ff69, 0x6b6bff, 0xff6969); } // Duration + Money - const runInfoTextContainer = this.scene.add.container(0, 0); + const runInfoTextContainer = globalScene.add.container(0, 0); // Japanese is set to a greater line spacing of 35px in addBBCodeTextObject() if lineSpacing < 12. const lineSpacing = (i18next.resolvedLanguage === "ja") ? 12 : 3; - const runInfoText = addBBCodeTextObject(this.scene, 7, 0, "", TextStyle.WINDOW, { fontSize: "50px", lineSpacing: lineSpacing }); + const runInfoText = addBBCodeTextObject(7, 0, "", TextStyle.WINDOW, { fontSize: "50px", lineSpacing: lineSpacing }); const runTime = Utils.getPlayTimeString(this.runInfo.playTime); runInfoText.appendText(`${i18next.t("runHistory:runLength")}: ${runTime}`, false); - const runMoney = Utils.formatMoney(this.scene.moneyFormat, this.runInfo.money); - const moneyTextColor = getTextColor(TextStyle.MONEY_WINDOW, false, this.scene.uiTheme); + const runMoney = Utils.formatMoney(globalScene.moneyFormat, this.runInfo.money); + const moneyTextColor = getTextColor(TextStyle.MONEY_WINDOW, false, globalScene.uiTheme); runInfoText.appendText(`[color=${moneyTextColor}]${i18next.t("battleScene:moneyOwned", { formattedMoney : runMoney })}[/color]`); runInfoText.setPosition(7, 70); runInfoTextContainer.add(runInfoText); // Luck // Uses the parameters windowX and windowY to dynamically position the luck value neatly into the bottom right corner - const luckText = addBBCodeTextObject(this.scene, 0, 0, "", TextStyle.WINDOW, { fontSize: "55px" }); - const luckValue = Phaser.Math.Clamp(this.runInfo.party.map(p => p.toPokemon(this.scene).getLuck()).reduce((total: integer, value: integer) => total += value, 0), 0, 14); + const luckText = addBBCodeTextObject(0, 0, "", TextStyle.WINDOW, { fontSize: "55px" }); + const luckValue = Phaser.Math.Clamp(this.runInfo.party.map(p => p.toPokemon().getLuck()).reduce((total: integer, value: integer) => total += value, 0), 0, 14); let luckInfo = i18next.t("runHistory:luck") + ": " + getLuckString(luckValue); if (luckValue < 14) { luckInfo = "[color=#" + (getLuckTextTint(luckValue)).toString(16) + "]" + luckInfo + "[/color]"; @@ -550,14 +550,14 @@ export default class RunInfoUiHandler extends UiHandler { if (this.runInfo.modifiers.length) { let visibleModifierIndex = 0; - const modifierIconsContainer = this.scene.add.container(8, (this.runInfo.gameMode === GameModes.CHALLENGE) ? 20 : 15); + const modifierIconsContainer = globalScene.add.container(8, (this.runInfo.gameMode === GameModes.CHALLENGE) ? 20 : 15); modifierIconsContainer.setScale(0.45); for (const m of this.runInfo.modifiers) { - const modifier = m.toModifier(this.scene, this.modifiersModule[m.className]); + const modifier = m.toModifier(this.modifiersModule[m.className]); if (modifier instanceof Modifier.PokemonHeldItemModifier) { continue; } - const icon = modifier?.getIcon(this.scene, false); + const icon = modifier?.getIcon(false); if (icon) { const rowHeightModifier = Math.floor(visibleModifierIndex / 7); icon.setPosition(24 * (visibleModifierIndex % 7), 20 + (35 * rowHeightModifier)); @@ -565,7 +565,7 @@ export default class RunInfoUiHandler extends UiHandler { } if (++visibleModifierIndex === 20) { - const maxItems = addTextObject(this.scene, 45, 90, "+", TextStyle.WINDOW); + const maxItems = addTextObject(45, 90, "+", TextStyle.WINDOW); maxItems.setPositionRelative(modifierIconsContainer, 70, 45); this.runInfoContainer.add(maxItems); break; @@ -619,13 +619,13 @@ export default class RunInfoUiHandler extends UiHandler { private parsePartyInfo(): void { const party = this.runInfo.party; const currentLanguage = i18next.resolvedLanguage ?? "en"; - const windowHeight = ((this.scene.game.canvas.height / 6) - 23) / 6; + const windowHeight = ((globalScene.game.canvas.height / 6) - 23) / 6; party.forEach((p: PokemonData, i: integer) => { - const pokemonInfoWindow = new RoundRectangle(this.scene, 0, 14, (this.statsBgWidth * 2) + 10, windowHeight - 2, 3); + const pokemonInfoWindow = new RoundRectangle(globalScene, 0, 14, (this.statsBgWidth * 2) + 10, windowHeight - 2, 3); - const pokemon = p.toPokemon(this.scene); - const pokemonInfoContainer = this.scene.add.container(this.statsBgWidth + 5, (windowHeight - 0.5) * i); + const pokemon = p.toPokemon(); + const pokemonInfoContainer = globalScene.add.container(this.statsBgWidth + 5, (windowHeight - 0.5) * i); const types = pokemon.getTypes(); const type1 = getTypeRgb(types[0]); @@ -634,8 +634,8 @@ export default class RunInfoUiHandler extends UiHandler { const bgColor = type1Color.clone().darken(45); pokemonInfoWindow.setFillStyle(bgColor.color); - const iconContainer = this.scene.add.container(0, 0); - const icon = this.scene.addPokemonIcon(pokemon, 0, 0, 0, 0); + const iconContainer = globalScene.add.container(0, 0); + const icon = globalScene.addPokemonIcon(pokemon, 0, 0, 0, 0); icon.setScale(0.75); icon.setPosition(-99, 1); const type2 = types[1] ? getTypeRgb(types[1]) : undefined; @@ -645,7 +645,7 @@ export default class RunInfoUiHandler extends UiHandler { this.getUi().bringToTop(icon); // Contains Name, Level + Nature, Ability, Passive - const pokeInfoTextContainer = this.scene.add.container(-85, 3.5); + const pokeInfoTextContainer = globalScene.add.container(-85, 3.5); const textContainerFontSize = "34px"; // This checks if the Pokemon's nature has been overwritten during the run and displays the change accurately const pNature = pokemon.getNature(); @@ -664,7 +664,7 @@ export default class RunInfoUiHandler extends UiHandler { const pAbilityInfo = abilityLabel + ": " + pokemon.getAbility().name; // Japanese is set to a greater line spacing of 35px in addBBCodeTextObject() if lineSpacing < 12. const lineSpacing = (i18next.resolvedLanguage === "ja") ? 12 : 3; - const pokeInfoText = addBBCodeTextObject(this.scene, 0, 0, pName, TextStyle.SUMMARY, { fontSize: textContainerFontSize, lineSpacing: lineSpacing }); + const pokeInfoText = addBBCodeTextObject(0, 0, pName, TextStyle.SUMMARY, { fontSize: textContainerFontSize, lineSpacing: lineSpacing }); pokeInfoText.appendText(`${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatFancyLargeNumber(pokemon.level, 1)} - ${pNatureName}`); pokeInfoText.appendText(pAbilityInfo); pokeInfoText.appendText(pPassiveInfo); @@ -672,7 +672,7 @@ export default class RunInfoUiHandler extends UiHandler { // Pokemon Stats // Colored Arrows (Red/Blue) are placed by stats that are boosted from natures - const pokeStatTextContainer = this.scene.add.container(-35, 6); + const pokeStatTextContainer = globalScene.add.container(-35, 6); const pStats : string[] = []; pokemon.stats.forEach((element) => pStats.push(Utils.formatFancyLargeNumber(element, 1))); for (let i = 0; i < pStats.length; i++) { @@ -688,20 +688,20 @@ export default class RunInfoUiHandler extends UiHandler { const speedLabel = (currentLanguage === "es-ES" || currentLanguage === "pt_BR") ? i18next.t("runHistory:SPDshortened") : i18next.t("pokemonInfo:Stat.SPDshortened"); const speed = speedLabel + ": " + pStats[5]; // Column 1: HP Atk Def - const pokeStatText1 = addBBCodeTextObject(this.scene, -5, 0, hp, TextStyle.SUMMARY, { fontSize: textContainerFontSize, lineSpacing: lineSpacing }); + const pokeStatText1 = addBBCodeTextObject(-5, 0, hp, TextStyle.SUMMARY, { fontSize: textContainerFontSize, lineSpacing: lineSpacing }); pokeStatText1.appendText(atk); pokeStatText1.appendText(def); pokeStatTextContainer.add(pokeStatText1); // Column 2: SpAtk SpDef Speed - const pokeStatText2 = addBBCodeTextObject(this.scene, 25, 0, spatk, TextStyle.SUMMARY, { fontSize: textContainerFontSize, lineSpacing: lineSpacing }); + const pokeStatText2 = addBBCodeTextObject(25, 0, spatk, TextStyle.SUMMARY, { fontSize: textContainerFontSize, lineSpacing: lineSpacing }); pokeStatText2.appendText(spdef); pokeStatText2.appendText(speed); pokeStatTextContainer.add(pokeStatText2); // Shiny + Fusion Status - const marksContainer = this.scene.add.container(0, 0); + const marksContainer = globalScene.add.container(0, 0); if (pokemon.fusionSpecies) { - const splicedIcon = this.scene.add.image(0, 0, "icon_spliced"); + const splicedIcon = globalScene.add.image(0, 0, "icon_spliced"); splicedIcon.setScale(0.35); splicedIcon.setOrigin(0, 0); pokemon.isShiny() ? splicedIcon.setPositionRelative(pokeInfoTextContainer, 35, 0) : splicedIcon.setPositionRelative(pokeInfoTextContainer, 28, 0); @@ -710,7 +710,7 @@ export default class RunInfoUiHandler extends UiHandler { } if (pokemon.isShiny()) { const doubleShiny = pokemon.isFusion() && pokemon.shiny && pokemon.fusionShiny; - const shinyStar = this.scene.add.image(0, 0, `shiny_star_small${doubleShiny ? "_1" : ""}`); + const shinyStar = globalScene.add.image(0, 0, `shiny_star_small${doubleShiny ? "_1" : ""}`); shinyStar.setOrigin(0, 0); shinyStar.setScale(0.65); shinyStar.setPositionRelative(pokeInfoTextContainer, 28, 0); @@ -718,7 +718,7 @@ export default class RunInfoUiHandler extends UiHandler { marksContainer.add(shinyStar); this.getUi().bringToTop(shinyStar); if (doubleShiny) { - const fusionShinyStar = this.scene.add.image(0, 0, "shiny_star_small_2"); + const fusionShinyStar = globalScene.add.image(0, 0, "shiny_star_small_2"); fusionShinyStar.setOrigin(0, 0); fusionShinyStar.setScale(0.5); fusionShinyStar.setPosition(shinyStar.x + 1, shinyStar.y + 1); @@ -731,16 +731,16 @@ export default class RunInfoUiHandler extends UiHandler { // Pokemon Moveset // Need to check if dynamically typed moves const pokemonMoveset = pokemon.getMoveset(); - const movesetContainer = this.scene.add.container(70, -29); + const movesetContainer = globalScene.add.container(70, -29); const pokemonMoveBgs : Phaser.GameObjects.NineSlice[] = []; const pokemonMoveLabels : Phaser.GameObjects.Text[] = []; const movePos = [[ -6.5, 35.5 ], [ 37, 35.5 ], [ -6.5, 43.5 ], [ 37, 43.5 ]]; for (let m = 0; m < pokemonMoveset?.length; m++) { - const moveContainer = this.scene.add.container(movePos[m][0], movePos[m][1]); + const moveContainer = globalScene.add.container(movePos[m][0], movePos[m][1]); moveContainer.setScale(0.5); - const moveBg = this.scene.add.nineslice(0, 0, "type_bgs", "unknown", 85, 15, 2, 2, 2, 2); + const moveBg = globalScene.add.nineslice(0, 0, "type_bgs", "unknown", 85, 15, 2, 2, 2, 2); moveBg.setOrigin(1, 0); - const moveLabel = addTextObject(this.scene, -moveBg.width / 2, 2, "-", TextStyle.PARTY); + const moveLabel = addTextObject(-moveBg.width / 2, 2, "-", TextStyle.PARTY); moveLabel.setOrigin(0.5, 0); moveLabel.setName("text-move-label"); pokemonMoveBgs.push(moveBg); @@ -756,11 +756,11 @@ export default class RunInfoUiHandler extends UiHandler { // Pokemon Held Items - not displayed by default // Endless/Endless Spliced have a different scale because Pokemon tend to accumulate more items in these runs. const heldItemsScale = (this.runInfo.gameMode === GameModes.SPLICED_ENDLESS || this.runInfo.gameMode === GameModes.ENDLESS) ? 0.25 : 0.5; - const heldItemsContainer = this.scene.add.container(-82, 2); + const heldItemsContainer = globalScene.add.container(-82, 2); const heldItemsList : Modifier.PokemonHeldItemModifier[] = []; if (this.runInfo.modifiers.length) { for (const m of this.runInfo.modifiers) { - const modifier = m.toModifier(this.scene, this.modifiersModule[m.className]); + const modifier = m.toModifier(this.modifiersModule[m.className]); if (modifier instanceof Modifier.PokemonHeldItemModifier && modifier.pokemonId === pokemon.id) { modifier.stackCount = m["stackCount"]; heldItemsList.push(modifier); @@ -771,11 +771,11 @@ export default class RunInfoUiHandler extends UiHandler { let row = 0; for (const [ index, item ] of heldItemsList.entries()) { if ( index > 36 ) { - const overflowIcon = addTextObject(this.scene, 182, 4, "+", TextStyle.WINDOW); + const overflowIcon = addTextObject(182, 4, "+", TextStyle.WINDOW); heldItemsContainer.add(overflowIcon); break; } - const itemIcon = item?.getIcon(this.scene, true); + const itemIcon = item?.getIcon(true); if (item?.stackCount < item?.getMaxHeldItemCount(pokemon) && itemIcon.list[1] instanceof Phaser.GameObjects.BitmapText) { itemIcon.list[1].clearTint(); } @@ -833,13 +833,13 @@ export default class RunInfoUiHandler extends UiHandler { * Shows the ending art. */ private createVictorySplash(): void { - this.endCardContainer = this.scene.add.container(0, 0); - const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET; + this.endCardContainer = globalScene.add.container(0, 0); + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const isFemale = genderIndex === PlayerGender.FEMALE; - const endCard = this.scene.add.image(0, 0, `end_${isFemale ? "f" : "m"}`); + const endCard = globalScene.add.image(0, 0, `end_${isFemale ? "f" : "m"}`); endCard.setOrigin(0); endCard.setScale(0.5); - const text = addTextObject(this.scene, this.scene.game.canvas.width / 12, (this.scene.game.canvas.height / 6) - 16, i18next.t("battle:congratulations"), TextStyle.SUMMARY, { fontSize: "128px" }); + const text = addTextObject(globalScene.game.canvas.width / 12, (globalScene.game.canvas.height / 6) - 16, i18next.t("battle:congratulations"), TextStyle.SUMMARY, { fontSize: "128px" }); text.setOrigin(0.5); this.endCardContainer.add(endCard); this.endCardContainer.add(text); @@ -850,45 +850,45 @@ export default class RunInfoUiHandler extends UiHandler { * This could be adapted into a public-facing method for victory screens. Perhaps. */ private createHallofFame(): void { - const genderIndex = this.scene.gameData.gender ?? PlayerGender.UNSET; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const isFemale = genderIndex === PlayerGender.FEMALE; const genderStr = PlayerGender[genderIndex].toLowerCase(); // Issue Note (08-05-2024): It seems as if fused pokemon do not appear with the averaged color b/c pokemonData's loadAsset requires there to be some active battle? // As an alternative, the icons of the second/bottom fused Pokemon have been placed next to their fellow fused Pokemon in Hall of Fame - this.hallofFameContainer = this.scene.add.container(0, 0); + this.hallofFameContainer = globalScene.add.container(0, 0); // Thank you Hayuna for the code - const endCard = this.scene.add.image(0, 0, `end_${isFemale ? "f" : "m"}`); + const endCard = globalScene.add.image(0, 0, `end_${isFemale ? "f" : "m"}`); endCard.setOrigin(0); endCard.setPosition(-1, -1); endCard.setScale(0.5); const endCardCoords = endCard.getBottomCenter(); const overlayColor = isFemale ? "red" : "blue"; - const hallofFameBg = this.scene.add.image(0, 0, "hall_of_fame_" + overlayColor); + const hallofFameBg = globalScene.add.image(0, 0, "hall_of_fame_" + overlayColor); hallofFameBg.setPosition(159, 89); - hallofFameBg.setSize(this.scene.game.canvas.width, this.scene.game.canvas.height + 10); + hallofFameBg.setSize(globalScene.game.canvas.width, globalScene.game.canvas.height + 10); hallofFameBg.setAlpha(0.8); this.hallofFameContainer.add(endCard); this.hallofFameContainer.add(hallofFameBg); - const hallofFameText = addTextObject(this.scene, 0, 0, i18next.t("runHistory:hallofFameText", { context: genderStr }), TextStyle.WINDOW); + const hallofFameText = addTextObject(0, 0, i18next.t("runHistory:hallofFameText", { context: genderStr }), TextStyle.WINDOW); hallofFameText.setPosition(endCardCoords.x - (hallofFameText.displayWidth / 2), 164); this.hallofFameContainer.add(hallofFameText); this.runInfo.party.forEach((p, i) => { - const pkmn = p.toPokemon(this.scene); + const pkmn = p.toPokemon(); const row = i % 2; const id = pkmn.id; const shiny = pkmn.shiny; const formIndex = pkmn.formIndex; const variant = pkmn.variant; const species = pkmn.getSpeciesForm(); - const pokemonSprite: Phaser.GameObjects.Sprite = this.scene.add.sprite(60 + 40 * i, 40 + row * 80, "pkmn__sub"); - pokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + const pokemonSprite: Phaser.GameObjects.Sprite = globalScene.add.sprite(60 + 40 * i, 40 + row * 80, "pkmn__sub"); + pokemonSprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); this.hallofFameContainer.add(pokemonSprite); const speciesLoaded: Map = new Map(); speciesLoaded.set(id, false); const female = pkmn.gender === 1; - species.loadAssets(this.scene, female, formIndex, shiny, variant, true).then(() => { + species.loadAssets(female, formIndex, shiny, variant, true).then(() => { speciesLoaded.set(id, true); pokemonSprite.play(species.getSpriteKey(female, formIndex, shiny, variant)); pokemonSprite.setPipelineData("shiny", shiny); @@ -897,7 +897,7 @@ export default class RunInfoUiHandler extends UiHandler { pokemonSprite.setVisible(true); }); if (pkmn.isFusion()) { - const fusionIcon = this.scene.add.sprite(80 + 40 * i, 50 + row * 80, pkmn.getFusionIconAtlasKey()); + const fusionIcon = globalScene.add.sprite(80 + 40 * i, 50 + row * 80, pkmn.getFusionIconAtlasKey()); fusionIcon.setName("sprite-fusion-icon"); fusionIcon.setOrigin(0.5, 0); fusionIcon.setFrame(pkmn.getFusionIconId(true)); diff --git a/src/ui/save-slot-select-ui-handler.ts b/src/ui/save-slot-select-ui-handler.ts index b36c0af6ec84..767be9f99316 100644 --- a/src/ui/save-slot-select-ui-handler.ts +++ b/src/ui/save-slot-select-ui-handler.ts @@ -1,5 +1,5 @@ import i18next from "i18next"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { Button } from "#enums/buttons"; import { GameMode } from "../game-mode"; import * as Modifier from "../modifier/modifier"; @@ -39,35 +39,35 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { private sessionSlotsContainerInitialY: number; - constructor(scene: BattleScene) { - super(scene, Mode.SAVE_SLOT); + constructor() { + super(Mode.SAVE_SLOT); } setup() { const ui = this.getUi(); - this.saveSlotSelectContainer = this.scene.add.container(0, 0); + this.saveSlotSelectContainer = globalScene.add.container(0, 0); this.saveSlotSelectContainer.setVisible(false); ui.add(this.saveSlotSelectContainer); - const loadSessionBg = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, -this.scene.game.canvas.height / 6, 0x006860); + const loadSessionBg = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, -globalScene.game.canvas.height / 6, 0x006860); loadSessionBg.setOrigin(0, 0); this.saveSlotSelectContainer.add(loadSessionBg); - this.sessionSlotsContainerInitialY = -this.scene.game.canvas.height / 6 + 8; + this.sessionSlotsContainerInitialY = -globalScene.game.canvas.height / 6 + 8; - this.sessionSlotsContainer = this.scene.add.container(8, this.sessionSlotsContainerInitialY); + this.sessionSlotsContainer = globalScene.add.container(8, this.sessionSlotsContainerInitialY); this.saveSlotSelectContainer.add(this.sessionSlotsContainer); - this.saveSlotSelectMessageBoxContainer = this.scene.add.container(0, 0); + this.saveSlotSelectMessageBoxContainer = globalScene.add.container(0, 0); this.saveSlotSelectMessageBoxContainer.setVisible(false); this.saveSlotSelectContainer.add(this.saveSlotSelectMessageBoxContainer); - this.saveSlotSelectMessageBox = addWindow(this.scene, 1, -1, 318, 28); + this.saveSlotSelectMessageBox = addWindow(1, -1, 318, 28); this.saveSlotSelectMessageBox.setOrigin(0, 1); this.saveSlotSelectMessageBoxContainer.add(this.saveSlotSelectMessageBox); - this.message = addTextObject(this.scene, 8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); + this.message = addTextObject(8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); this.message.setOrigin(0, 0); this.saveSlotSelectMessageBoxContainer.add(this.message); @@ -122,9 +122,9 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { if (this.sessionSlots[cursor].hasData) { ui.showText(i18next.t("saveSlotSelectUiHandler:overwriteData"), null, () => { ui.setOverlayMode(Mode.CONFIRM, () => { - this.scene.gameData.deleteSession(cursor).then(response => { + globalScene.gameData.deleteSession(cursor).then(response => { if (response === false) { - this.scene.reset(true); + globalScene.reset(true); } else { saveAndCallback(); } @@ -168,7 +168,7 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { break; case Button.RIGHT: if (this.sessionSlots[cursorPosition].hasData && this.sessionSlots[cursorPosition].saveData) { - this.scene.ui.setOverlayMode(Mode.RUN_INFO, this.sessionSlots[cursorPosition].saveData, RunDisplayMode.SESSION_PREVIEW); + globalScene.ui.setOverlayMode(Mode.RUN_INFO, this.sessionSlots[cursorPosition].saveData, RunDisplayMode.SESSION_PREVIEW); success = true; } } @@ -185,8 +185,8 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { populateSessionSlots() { for (let s = 0; s < SESSION_SLOTS_COUNT; s++) { - const sessionSlot = new SessionSlot(this.scene, s); - this.scene.add.existing(sessionSlot); + const sessionSlot = new SessionSlot(s); + globalScene.add.existing(sessionSlot); this.sessionSlotsContainer.add(sessionSlot); this.sessionSlots.push(sessionSlot); sessionSlot.load().then((success) => { @@ -223,9 +223,9 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { const changed = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.container(0, 0); - const cursorBox = this.scene.add.nineslice(0, 0, "select_cursor_highlight_thick", undefined, 296, 44, 6, 6, 6, 6); - const rightArrow = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.container(0, 0); + const cursorBox = globalScene.add.nineslice(0, 0, "select_cursor_highlight_thick", undefined, 296, 44, 6, 6, 6, 6); + const rightArrow = globalScene.add.image(0, 0, "cursor"); rightArrow.setPosition(160, 0); rightArrow.setName("rightArrow"); this.cursorObj.add([ cursorBox, rightArrow ]); @@ -286,7 +286,7 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { if (changed) { this.scrollCursor = scrollCursor; this.setCursor(this.cursor, prevSlotIndex); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.sessionSlotsContainer, y: this.sessionSlotsContainerInitialY - 56 * scrollCursor, duration: Utils.fixedInt(325), @@ -326,8 +326,8 @@ class SessionSlot extends Phaser.GameObjects.Container { public saveData: SessionSaveData; - constructor(scene: BattleScene, slotId: integer) { - super(scene, 0, slotId * 56); + constructor(slotId: integer) { + super(globalScene, 0, slotId * 56); this.slotId = slotId; @@ -335,10 +335,10 @@ class SessionSlot extends Phaser.GameObjects.Container { } setup() { - const slotWindow = addWindow(this.scene, 0, 0, 304, 52); + const slotWindow = addWindow(0, 0, 304, 52); this.add(slotWindow); - this.loadingLabel = addTextObject(this.scene, 152, 26, i18next.t("saveSlotSelectUiHandler:loading"), TextStyle.WINDOW); + this.loadingLabel = addTextObject(152, 26, i18next.t("saveSlotSelectUiHandler:loading"), TextStyle.WINDOW); this.loadingLabel.setOrigin(0.5, 0.5); this.add(this.loadingLabel); } @@ -346,24 +346,24 @@ class SessionSlot extends Phaser.GameObjects.Container { async setupWithData(data: SessionSaveData) { this.remove(this.loadingLabel, true); - const gameModeLabel = addTextObject(this.scene, 8, 5, `${GameMode.getModeName(data.gameMode) || i18next.t("gameMode:unkown")} - ${i18next.t("saveSlotSelectUiHandler:wave")} ${data.waveIndex}`, TextStyle.WINDOW); + const gameModeLabel = addTextObject(8, 5, `${GameMode.getModeName(data.gameMode) || i18next.t("gameMode:unkown")} - ${i18next.t("saveSlotSelectUiHandler:wave")} ${data.waveIndex}`, TextStyle.WINDOW); this.add(gameModeLabel); - const timestampLabel = addTextObject(this.scene, 8, 19, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW); + const timestampLabel = addTextObject(8, 19, new Date(data.timestamp).toLocaleString(), TextStyle.WINDOW); this.add(timestampLabel); - const playTimeLabel = addTextObject(this.scene, 8, 33, Utils.getPlayTimeString(data.playTime), TextStyle.WINDOW); + const playTimeLabel = addTextObject(8, 33, Utils.getPlayTimeString(data.playTime), TextStyle.WINDOW); this.add(playTimeLabel); - const pokemonIconsContainer = this.scene.add.container(144, 4); + const pokemonIconsContainer = globalScene.add.container(144, 4); data.party.forEach((p: PokemonData, i: integer) => { - const iconContainer = this.scene.add.container(26 * i, 0); + const iconContainer = globalScene.add.container(26 * i, 0); iconContainer.setScale(0.75); - const pokemon = p.toPokemon(this.scene); - const icon = this.scene.addPokemonIcon(pokemon, 0, 0, 0, 0); + const pokemon = p.toPokemon(); + const icon = globalScene.addPokemonIcon(pokemon, 0, 0, 0, 0); - const text = addTextObject(this.scene, 32, 20, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(pokemon.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }); + const text = addTextObject(32, 20, `${i18next.t("saveSlotSelectUiHandler:lv")}${Utils.formatLargeNumber(pokemon.level, 1000)}`, TextStyle.PARTY, { fontSize: "54px", color: "#f8f8f8" }); text.setShadow(0, 0, undefined); text.setStroke("#424242", 14); text.setOrigin(1, 0); @@ -378,15 +378,15 @@ class SessionSlot extends Phaser.GameObjects.Container { this.add(pokemonIconsContainer); - const modifierIconsContainer = this.scene.add.container(148, 30); + const modifierIconsContainer = globalScene.add.container(148, 30); modifierIconsContainer.setScale(0.5); let visibleModifierIndex = 0; for (const m of data.modifiers) { - const modifier = m.toModifier(this.scene, Modifier[m.className]); + const modifier = m.toModifier(Modifier[m.className]); if (modifier instanceof Modifier.PokemonHeldItemModifier) { continue; } - const icon = modifier?.getIcon(this.scene, false); + const icon = modifier?.getIcon(false); if (icon) { icon.setPosition(24 * visibleModifierIndex, 0); modifierIconsContainer.add(icon); @@ -401,7 +401,7 @@ class SessionSlot extends Phaser.GameObjects.Container { load(): Promise { return new Promise(resolve => { - this.scene.gameData.getSession(this.slotId).then(async sessionData => { + globalScene.gameData.getSession(this.slotId).then(async sessionData => { // Ignore the results if the view was exited if (!this.active) { return; @@ -420,7 +420,3 @@ class SessionSlot extends Phaser.GameObjects.Container { }); } } - -interface SessionSlot { - scene: BattleScene; -} diff --git a/src/ui/saving-icon-handler.ts b/src/ui/saving-icon-handler.ts index f62b0dc61629..ca7b1fb1aa82 100644 --- a/src/ui/saving-icon-handler.ts +++ b/src/ui/saving-icon-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import * as Utils from "../utils"; export default class SavingIconHandler extends Phaser.GameObjects.Container { @@ -7,12 +7,12 @@ export default class SavingIconHandler extends Phaser.GameObjects.Container { private animActive: boolean; private shown: boolean; - constructor(scene: BattleScene) { - super(scene, scene.game.canvas.width / 6 - 4, scene.game.canvas.height / 6 - 4); + constructor() { + super(globalScene, globalScene.game.canvas.width / 6 - 4, globalScene.game.canvas.height / 6 - 4); } setup(): void { - this.icon = this.scene.add.sprite(0, 0, "saving_icon"); + this.icon = globalScene.add.sprite(0, 0, "saving_icon"); this.icon.setOrigin(1, 1); this.add(this.icon); @@ -33,13 +33,13 @@ export default class SavingIconHandler extends Phaser.GameObjects.Container { this.animActive = true; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, alpha: 1, duration: Utils.fixedInt(250), ease: "Sine.easeInOut", onComplete: () => { - this.scene.time.delayedCall(Utils.fixedInt(500), () => { + globalScene.time.delayedCall(Utils.fixedInt(500), () => { this.animActive = false; if (!this.shown) { this.hide(); @@ -61,7 +61,7 @@ export default class SavingIconHandler extends Phaser.GameObjects.Container { this.animActive = true; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this, alpha: 0, duration: Utils.fixedInt(250), diff --git a/src/ui/scroll-bar.ts b/src/ui/scroll-bar.ts index 9874be0f73ae..eb74bfddfde6 100644 --- a/src/ui/scroll-bar.ts +++ b/src/ui/scroll-bar.ts @@ -1,3 +1,5 @@ +import { globalScene } from "#app/global-scene"; + /** * A vertical scrollbar element that resizes dynamically based on the current scrolling * and number of elements that can be shown on screen @@ -11,15 +13,14 @@ export class ScrollBar extends Phaser.GameObjects.Container { private maxRows: number; /** - * @param scene the current scene * @param x the scrollbar's x position (origin: top left) * @param y the scrollbar's y position (origin: top left) * @param width the scrollbar's width * @param height the scrollbar's height * @param maxRows the maximum number of rows that can be shown at once */ - constructor(scene: Phaser.Scene, x: number, y: number, width: number, height: number, maxRows: number) { - super(scene, x, y); + constructor(x: number, y: number, width: number, height: number, maxRows: number) { + super(globalScene, x, y); this.maxRows = maxRows; this.totalRows = maxRows; @@ -28,15 +29,15 @@ export class ScrollBar extends Phaser.GameObjects.Container { const borderSize = 2; width = Math.max(width, 4); - this.bg = scene.add.nineslice(0, 0, "scroll_bar", undefined, width, height, borderSize, borderSize, borderSize, borderSize); + this.bg = globalScene.add.nineslice(0, 0, "scroll_bar", undefined, width, height, borderSize, borderSize, borderSize, borderSize); this.bg.setOrigin(0, 0); this.add(this.bg); - this.handleBody = scene.add.rectangle(1, 1, width - 2, 4, 0xaaaaaa); + this.handleBody = globalScene.add.rectangle(1, 1, width - 2, 4, 0xaaaaaa); this.handleBody.setOrigin(0, 0); this.add(this.handleBody); - this.handleBottom = scene.add.nineslice(1, 1, "scroll_bar_handle", undefined, width - 2, 2, 2, 0, 0, 0); + this.handleBottom = globalScene.add.nineslice(1, 1, "scroll_bar_handle", undefined, width - 2, 2, 2, 0, 0, 0); this.handleBottom.setOrigin(0, 0); this.add(this.handleBottom); } diff --git a/src/ui/scrollable-grid-handler.ts b/src/ui/scrollable-grid-handler.ts index cced92a2083f..b879d25b758a 100644 --- a/src/ui/scrollable-grid-handler.ts +++ b/src/ui/scrollable-grid-handler.ts @@ -24,15 +24,14 @@ export default class ScrollableGridUiHandler { private cursor: number; private scrollCursor: number; private scrollBar?: ScrollBar; + /** Optional function that will get called if the whole grid needs to get updated */ private updateGridCallback?: UpdateGridCallbackFunction; + /** Optional function that will get called if a single element's information needs to get updated */ private updateDetailsCallback?: UpdateDetailsCallbackFunction; /** - * @param scene the {@linkcode UiHandler} that needs its cursor updated based on the scrolling * @param rows the maximum number of rows shown at once * @param columns the maximum number of columns shown at once - * @param updateGridCallback optional function that will get called if the whole grid needs to get updated - * @param updateDetailsCallback optional function that will get called if a single element's information needs to get updated */ constructor(handler: UiHandler, rows: number, columns: number) { this.handler = handler; diff --git a/src/ui/session-reload-modal-ui-handler.ts b/src/ui/session-reload-modal-ui-handler.ts index 147634b19d2c..6590f0899508 100644 --- a/src/ui/session-reload-modal-ui-handler.ts +++ b/src/ui/session-reload-modal-ui-handler.ts @@ -1,11 +1,10 @@ -import BattleScene from "../battle-scene"; import { ModalConfig, ModalUiHandler } from "./modal-ui-handler"; import { addTextObject, TextStyle } from "./text"; import { Mode } from "./ui"; export default class SessionReloadModalUiHandler extends ModalUiHandler { - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); } getModalTitle(): string { @@ -31,7 +30,7 @@ export default class SessionReloadModalUiHandler extends ModalUiHandler { setup(): void { super.setup(); - const label = addTextObject(this.scene, this.getWidth() / 2, this.getHeight() / 2, "Your session is out of date.\nYour data will be reloaded…", TextStyle.WINDOW, { fontSize: "48px", align: "center" }); + const label = addTextObject(this.getWidth() / 2, this.getHeight() / 2, "Your session is out of date.\nYour data will be reloaded…", TextStyle.WINDOW, { fontSize: "48px", align: "center" }); label.setOrigin(0.5, 0.5); this.modalContainer.add(label); diff --git a/src/ui/settings/abstract-binding-ui-handler.ts b/src/ui/settings/abstract-binding-ui-handler.ts index 9ebc3c493a47..eec3e89eb5de 100644 --- a/src/ui/settings/abstract-binding-ui-handler.ts +++ b/src/ui/settings/abstract-binding-ui-handler.ts @@ -1,11 +1,11 @@ import UiHandler from "../ui-handler"; -import BattleScene from "../../battle-scene"; import { Mode } from "../ui"; import { addWindow } from "../ui-theme"; import { addTextObject, TextStyle } from "../text"; import { Button } from "#enums/buttons"; import { NavigationManager } from "#app/ui/settings/navigationMenu"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; type CancelFn = (succes?: boolean) => boolean; @@ -49,11 +49,10 @@ export default abstract class AbstractBindingUiHandler extends UiHandler { /** * Constructor for the AbstractBindingUiHandler. * - * @param scene - The BattleScene instance. * @param mode - The UI mode. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); } /** @@ -61,8 +60,8 @@ export default abstract class AbstractBindingUiHandler extends UiHandler { */ setup() { const ui = this.getUi(); - this.optionSelectContainer = this.scene.add.container(0, 0); - this.actionsContainer = this.scene.add.container(0, 0); + this.optionSelectContainer = globalScene.add.container(0, 0); + this.actionsContainer = globalScene.add.container(0, 0); // Initially, containers are not visible. this.optionSelectContainer.setVisible(false); this.actionsContainer.setVisible(false); @@ -72,30 +71,30 @@ export default abstract class AbstractBindingUiHandler extends UiHandler { ui.add(this.actionsContainer); // Setup backgrounds and text objects for UI. - this.titleBg = addWindow(this.scene, (this.scene.game.canvas.width / 6) - this.getWindowWidth(), -(this.scene.game.canvas.height / 6) + 28 + 21, this.getWindowWidth(), 24); + this.titleBg = addWindow((globalScene.game.canvas.width / 6) - this.getWindowWidth(), -(globalScene.game.canvas.height / 6) + 28 + 21, this.getWindowWidth(), 24); this.titleBg.setOrigin(0.5); this.optionSelectContainer.add(this.titleBg); - this.actionBg = addWindow(this.scene, (this.scene.game.canvas.width / 6) - this.getWindowWidth(), -(this.scene.game.canvas.height / 6) + this.getWindowHeight() + 28 + 21 + 21, this.getWindowWidth(), 24); + this.actionBg = addWindow((globalScene.game.canvas.width / 6) - this.getWindowWidth(), -(globalScene.game.canvas.height / 6) + this.getWindowHeight() + 28 + 21 + 21, this.getWindowWidth(), 24); this.actionBg.setOrigin(0.5); this.actionsContainer.add(this.actionBg); // Text prompts and instructions for the user. - this.unlockText = addTextObject(this.scene, 0, 0, i18next.t("settings:pressButton"), TextStyle.WINDOW); + this.unlockText = addTextObject(0, 0, i18next.t("settings:pressButton"), TextStyle.WINDOW); this.unlockText.setOrigin(0, 0); this.unlockText.setPositionRelative(this.titleBg, 36, 4); this.optionSelectContainer.add(this.unlockText); - this.timerText = addTextObject(this.scene, 0, 0, "(5)", TextStyle.WINDOW); + this.timerText = addTextObject(0, 0, "(5)", TextStyle.WINDOW); this.timerText.setOrigin(0, 0); this.timerText.setPositionRelative(this.unlockText, (this.unlockText.width / 6) + 5, 0); this.optionSelectContainer.add(this.timerText); - this.optionSelectBg = addWindow(this.scene, (this.scene.game.canvas.width / 6) - this.getWindowWidth(), -(this.scene.game.canvas.height / 6) + this.getWindowHeight() + 28, this.getWindowWidth(), this.getWindowHeight()); + this.optionSelectBg = addWindow((globalScene.game.canvas.width / 6) - this.getWindowWidth(), -(globalScene.game.canvas.height / 6) + this.getWindowHeight() + 28, this.getWindowWidth(), this.getWindowHeight()); this.optionSelectBg.setOrigin(0.5); this.optionSelectContainer.add(this.optionSelectBg); - this.cancelLabel = addTextObject(this.scene, 0, 0, i18next.t("settings:back"), TextStyle.SETTINGS_LABEL); + this.cancelLabel = addTextObject(0, 0, i18next.t("settings:back"), TextStyle.SETTINGS_LABEL); this.cancelLabel.setOrigin(0, 0.5); this.cancelLabel.setPositionRelative(this.actionBg, 10, this.actionBg.height / 2); this.actionsContainer.add(this.cancelLabel); diff --git a/src/ui/settings/abstract-control-settings-ui-handler.ts b/src/ui/settings/abstract-control-settings-ui-handler.ts index 69f8eb241d36..5d79a3f35660 100644 --- a/src/ui/settings/abstract-control-settings-ui-handler.ts +++ b/src/ui/settings/abstract-control-settings-ui-handler.ts @@ -1,5 +1,4 @@ import UiHandler from "#app/ui/ui-handler"; -import BattleScene from "#app/battle-scene"; import { Mode } from "#app/ui/ui"; import { InterfaceConfig } from "#app/inputs-controller"; import { addWindow } from "#app/ui/ui-theme"; @@ -10,6 +9,7 @@ import NavigationMenu, { NavigationManager } from "#app/ui/settings/navigationMe import { Device } from "#enums/devices"; import { Button } from "#enums/buttons"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; export interface InputsIcons { [key: string]: Phaser.GameObjects.Sprite; @@ -67,16 +67,15 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler protected device: Device; abstract saveSettingToLocalStorage(setting, cursor): void; - abstract setSetting(scene: BattleScene, setting, value: number): boolean; + abstract setSetting(setting, value: number): boolean; /** * Constructor for the AbstractSettingsUiHandler. * - * @param scene - The BattleScene instance. * @param mode - The UI mode. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.rowsToDisplay = 8; } @@ -99,44 +98,44 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler const ui = this.getUi(); this.navigationIcons = {}; - this.settingsContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1); + this.settingsContainer = globalScene.add.container(1, -(globalScene.game.canvas.height / 6) + 1); this.settingsContainer.setName(`settings-${this.titleSelected}`); - this.settingsContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.settingsContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); - this.navigationContainer = new NavigationMenu(this.scene, 0, 0); + this.navigationContainer = new NavigationMenu(0, 0); - this.optionsBg = addWindow(this.scene, 0, this.navigationContainer.height, (this.scene.game.canvas.width / 6) - 2, (this.scene.game.canvas.height / 6) - 16 - this.navigationContainer.height - 2); + this.optionsBg = addWindow(0, this.navigationContainer.height, (globalScene.game.canvas.width / 6) - 2, (globalScene.game.canvas.height / 6) - 16 - this.navigationContainer.height - 2); this.optionsBg.setOrigin(0, 0); - this.actionsBg = addWindow(this.scene, 0, (this.scene.game.canvas.height / 6) - this.navigationContainer.height, (this.scene.game.canvas.width / 6) - 2, 22); + this.actionsBg = addWindow(0, (globalScene.game.canvas.height / 6) - this.navigationContainer.height, (globalScene.game.canvas.width / 6) - 2, 22); this.actionsBg.setOrigin(0, 0); - const iconAction = this.scene.add.sprite(0, 0, "keyboard"); + const iconAction = globalScene.add.sprite(0, 0, "keyboard"); iconAction.setOrigin(0, -0.1); iconAction.setPositionRelative(this.actionsBg, this.navigationContainer.width - 32, 4); this.navigationIcons["BUTTON_ACTION"] = iconAction; - const actionText = addTextObject(this.scene, 0, 0, i18next.t("settings:action"), TextStyle.SETTINGS_LABEL); + const actionText = addTextObject(0, 0, i18next.t("settings:action"), TextStyle.SETTINGS_LABEL); actionText.setOrigin(0, 0.15); actionText.setPositionRelative(iconAction, -actionText.width / 6 - 2, 0); - const iconCancel = this.scene.add.sprite(0, 0, "keyboard"); + const iconCancel = globalScene.add.sprite(0, 0, "keyboard"); iconCancel.setOrigin(0, -0.1); iconCancel.setPositionRelative(this.actionsBg, this.navigationContainer.width - 100, 4); this.navigationIcons["BUTTON_CANCEL"] = iconCancel; - const cancelText = addTextObject(this.scene, 0, 0, i18next.t("settings:back"), TextStyle.SETTINGS_LABEL); + const cancelText = addTextObject(0, 0, i18next.t("settings:back"), TextStyle.SETTINGS_LABEL); cancelText.setOrigin(0, 0.15); cancelText.setPositionRelative(iconCancel, -cancelText.width / 6 - 2, 0); - const iconReset = this.scene.add.sprite(0, 0, "keyboard"); + const iconReset = globalScene.add.sprite(0, 0, "keyboard"); iconReset.setOrigin(0, -0.1); iconReset.setPositionRelative(this.actionsBg, this.navigationContainer.width - 180, 4); this.navigationIcons["BUTTON_HOME"] = iconReset; - const resetText = addTextObject(this.scene, 0, 0, i18next.t("settings:reset"), TextStyle.SETTINGS_LABEL); + const resetText = addTextObject(0, 0, i18next.t("settings:reset"), TextStyle.SETTINGS_LABEL); resetText.setOrigin(0, 0.15); resetText.setPositionRelative(iconReset, -resetText.width / 6 - 2, 0); @@ -156,7 +155,7 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler this.layout[config.padType] = new Map(); // Create a container for gamepad options in the scene, initially hidden. - const optionsContainer = this.scene.add.container(0, 0); + const optionsContainer = globalScene.add.container(0, 0); optionsContainer.setVisible(false); // Gather all binding settings from the configuration. @@ -195,7 +194,7 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler } else { labelText = i18next.t(`settings:${i18nKey}`); } - settingLabels[s] = addTextObject(this.scene, 8, 28 + s * 16, labelText, labelStyle); + settingLabels[s] = addTextObject(8, 28 + s * 16, labelText, labelStyle); settingLabels[s].setOrigin(0, 0); optionsContainer.add(settingLabels[s]); @@ -208,14 +207,14 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler if (bindingSettings.includes(this.setting[setting])) { // Create a label for non-null options, typically indicating actionable options like 'change'. if (o) { - const valueLabel = addTextObject(this.scene, 0, 0, isLock ? "" : option, TextStyle.WINDOW); + const valueLabel = addTextObject(0, 0, isLock ? "" : option, TextStyle.WINDOW); valueLabel.setOrigin(0, 0); optionsContainer.add(valueLabel); valueLabels.push(valueLabel); continue; } // For null options, add an icon for the key. - const icon = this.scene.add.sprite(0, 0, this.textureOverride ? this.textureOverride : config.padType); + const icon = globalScene.add.sprite(0, 0, this.textureOverride ? this.textureOverride : config.padType); icon.setOrigin(0, -0.15); inputsIcons[this.setting[setting]] = icon; optionsContainer.add(icon); @@ -223,7 +222,7 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler continue; } // For regular settings like 'Gamepad support', create a label and determine if it is selected. - const valueLabel = addTextObject(this.scene, 0, 0, option, this.settingDeviceDefaults[this.setting[setting]] === o ? TextStyle.SETTINGS_SELECTED : TextStyle.WINDOW); + const valueLabel = addTextObject(0, 0, option, this.settingDeviceDefaults[this.setting[setting]] === o ? TextStyle.SETTINGS_SELECTED : TextStyle.WINDOW); valueLabel.setOrigin(0, 0); optionsContainer.add(valueLabel); @@ -273,7 +272,7 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler } // Add vertical scrollbar - this.scrollBar = new ScrollBar(this.scene, this.optionsBg.width - 9, this.optionsBg.y + 5, 4, this.optionsBg.height - 11, this.rowsToDisplay); + this.scrollBar = new ScrollBar(this.optionsBg.width - 9, this.optionsBg.y + 5, 4, this.optionsBg.height - 11, this.rowsToDisplay); this.settingsContainer.add(this.scrollBar); // Add the settings container to the UI. @@ -289,7 +288,7 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler * @returns The active configuration for current device */ getActiveConfig(): InterfaceConfig { - return this.scene.inputController.getActiveConfig(this.device); + return globalScene.inputController.getActiveConfig(this.device); } /** @@ -349,9 +348,9 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler this.navigationIcons[settingName].alpha = 1; continue; } - const icon = this.scene.inputController?.getIconForLatestInputRecorded(settingName); + const icon = globalScene.inputController?.getIconForLatestInputRecorded(settingName); if (icon) { - const type = this.scene.inputController?.getLastSourceType(); + const type = globalScene.inputController?.getLastSourceType(); this.navigationIcons[settingName].setTexture(type); this.navigationIcons[settingName].setFrame(icon); this.navigationIcons[settingName].alpha = 1; @@ -444,7 +443,7 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler // Handle cancel button press, reverting UI mode to previous state. success = true; NavigationManager.getInstance().reset(); - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); } else { const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position. const setting = this.setting[Object.keys(this.setting)[cursor]]; @@ -456,7 +455,7 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler if (this.settingBlacklisted.includes(setting) || !setting.includes("BUTTON_")) { success = false; } else { - success = this.setSetting(this.scene, setting, 1); + success = this.setSetting(setting, 1); } break; case Button.UP: // Move up in the menu. @@ -556,8 +555,8 @@ export default abstract class AbstractControlSettingsUiHandler extends UiHandler // Check if the cursor object exists, if not, create it. if (!this.cursorObj) { - const cursorWidth = (this.scene.game.canvas.width / 6) - (this.scrollBar.visible ? 16 : 10); - this.cursorObj = this.scene.add.nineslice(0, 0, "summary_moves_cursor", undefined, cursorWidth, 16, 1, 1, 1, 1); + const cursorWidth = (globalScene.game.canvas.width / 6) - (this.scrollBar.visible ? 16 : 10); + this.cursorObj = globalScene.add.nineslice(0, 0, "summary_moves_cursor", undefined, cursorWidth, 16, 1, 1, 1, 1); this.cursorObj.setOrigin(0, 0); // Set the origin to the top-left corner. this.optionsContainer.add(this.cursorObj); // Add the cursor to the options container. } diff --git a/src/ui/settings/abstract-settings-ui-handler.ts b/src/ui/settings/abstract-settings-ui-handler.ts index cbc93887810f..cd5763cb0cf0 100644 --- a/src/ui/settings/abstract-settings-ui-handler.ts +++ b/src/ui/settings/abstract-settings-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "#app/battle-scene"; import { TextStyle, addTextObject } from "#app/ui/text"; import { Mode } from "#app/ui/ui"; import MessageUiHandler from "#app/ui/message-ui-handler"; @@ -9,6 +8,7 @@ import { InputsIcons } from "#app/ui/settings/abstract-control-settings-ui-handl import NavigationMenu, { NavigationManager } from "#app/ui/settings/navigationMenu"; import { Setting, SettingKeys, SettingType } from "#app/system/settings/settings"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; /** @@ -42,8 +42,8 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { protected settings: Array; protected localStorageKey: string; - constructor(scene: BattleScene, type: SettingType, mode: Mode | null = null) { - super(scene, mode); + constructor(type: SettingType, mode: Mode | null = null) { + super(mode); this.settings = Setting.filter(s => s.type === type && !s?.isHidden?.()); this.reloadRequired = false; this.rowsToDisplay = 8; @@ -55,40 +55,40 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { setup() { const ui = this.getUi(); - this.settingsContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1); + this.settingsContainer = globalScene.add.container(1, -(globalScene.game.canvas.height / 6) + 1); this.settingsContainer.setName(`settings-${this.title}`); - this.settingsContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6 - 20), Phaser.Geom.Rectangle.Contains); + this.settingsContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6 - 20), Phaser.Geom.Rectangle.Contains); this.navigationIcons = {}; - this.navigationContainer = new NavigationMenu(this.scene, 0, 0); + this.navigationContainer = new NavigationMenu(0, 0); - this.optionsBg = addWindow(this.scene, 0, this.navigationContainer.height, (this.scene.game.canvas.width / 6) - 2, (this.scene.game.canvas.height / 6) - 16 - this.navigationContainer.height - 2); + this.optionsBg = addWindow(0, this.navigationContainer.height, (globalScene.game.canvas.width / 6) - 2, (globalScene.game.canvas.height / 6) - 16 - this.navigationContainer.height - 2); this.optionsBg.setName("window-options-bg"); this.optionsBg.setOrigin(0, 0); - const actionsBg = addWindow(this.scene, 0, (this.scene.game.canvas.height / 6) - this.navigationContainer.height, (this.scene.game.canvas.width / 6) - 2, 22); + const actionsBg = addWindow(0, (globalScene.game.canvas.height / 6) - this.navigationContainer.height, (globalScene.game.canvas.width / 6) - 2, 22); actionsBg.setOrigin(0, 0); - const iconAction = this.scene.add.sprite(0, 0, "keyboard"); + const iconAction = globalScene.add.sprite(0, 0, "keyboard"); iconAction.setOrigin(0, -0.1); iconAction.setPositionRelative(actionsBg, this.navigationContainer.width - 32, 4); this.navigationIcons["BUTTON_ACTION"] = iconAction; - const actionText = addTextObject(this.scene, 0, 0, i18next.t("settings:action"), TextStyle.SETTINGS_LABEL); + const actionText = addTextObject(0, 0, i18next.t("settings:action"), TextStyle.SETTINGS_LABEL); actionText.setOrigin(0, 0.15); actionText.setPositionRelative(iconAction, -actionText.width / 6 - 2, 0); - const iconCancel = this.scene.add.sprite(0, 0, "keyboard"); + const iconCancel = globalScene.add.sprite(0, 0, "keyboard"); iconCancel.setOrigin(0, -0.1); iconCancel.setPositionRelative(actionsBg, this.navigationContainer.width - 100, 4); this.navigationIcons["BUTTON_CANCEL"] = iconCancel; - const cancelText = addTextObject(this.scene, 0, 0, i18next.t("settings:back"), TextStyle.SETTINGS_LABEL); + const cancelText = addTextObject(0, 0, i18next.t("settings:back"), TextStyle.SETTINGS_LABEL); cancelText.setOrigin(0, 0.15); cancelText.setPositionRelative(iconCancel, -cancelText.width / 6 - 2, 0); - this.optionsContainer = this.scene.add.container(0, 0); + this.optionsContainer = globalScene.add.container(0, 0); this.settingLabels = []; this.optionValueLabels = []; @@ -102,12 +102,12 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { settingName += ` (${i18next.t("settings:requireReload")})`; } - this.settingLabels[s] = addTextObject(this.scene, 8, 28 + s * 16, settingName, TextStyle.SETTINGS_LABEL); + this.settingLabels[s] = addTextObject(8, 28 + s * 16, settingName, TextStyle.SETTINGS_LABEL); this.settingLabels[s].setOrigin(0, 0); this.optionsContainer.add(this.settingLabels[s]); this.optionValueLabels.push(setting.options.map((option, o) => { - const valueLabel = addTextObject(this.scene, 0, 0, option.label, setting.default === o ? TextStyle.SETTINGS_SELECTED : TextStyle.SETTINGS_VALUE); + const valueLabel = addTextObject(0, 0, option.label, setting.default === o ? TextStyle.SETTINGS_SELECTED : TextStyle.SETTINGS_VALUE); valueLabel.setOrigin(0, 0); this.optionsContainer.add(valueLabel); @@ -132,20 +132,20 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { this.optionCursors = this.settings.map(setting => setting.default); - this.scrollBar = new ScrollBar(this.scene, this.optionsBg.width - 9, this.optionsBg.y + 5, 4, this.optionsBg.height - 11, this.rowsToDisplay); + this.scrollBar = new ScrollBar(this.optionsBg.width - 9, this.optionsBg.y + 5, 4, this.optionsBg.height - 11, this.rowsToDisplay); this.scrollBar.setTotalRows(this.settings.length); // Two-lines message box - this.messageBoxContainer = this.scene.add.container(0, this.scene.scaledCanvas.height); + this.messageBoxContainer = globalScene.add.container(0, globalScene.scaledCanvas.height); this.messageBoxContainer.setName("settings-message-box"); this.messageBoxContainer.setVisible(false); - const settingsMessageBox = addWindow(this.scene, 0, -1, this.scene.scaledCanvas.width - 2, 48); + const settingsMessageBox = addWindow(0, -1, globalScene.scaledCanvas.width - 2, 48); settingsMessageBox.setOrigin(0, 1); this.messageBoxContainer.add(settingsMessageBox); - const messageText = addTextObject(this.scene, 8, -40, "", TextStyle.WINDOW, { maxLines: 2 }); - messageText.setWordWrapWidth(this.scene.game.canvas.width - 60); + const messageText = addTextObject(8, -40, "", TextStyle.WINDOW, { maxLines: 2 }); + messageText.setWordWrapWidth(globalScene.game.canvas.width - 60); messageText.setName("settings-message"); messageText.setOrigin(0, 0); @@ -181,9 +181,9 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { this.navigationIcons[settingName].alpha = 1; continue; } - const icon = this.scene.inputController?.getIconForLatestInputRecorded(settingName); + const icon = globalScene.inputController?.getIconForLatestInputRecorded(settingName); if (icon) { - const type = this.scene.inputController?.getLastSourceType(); + const type = globalScene.inputController?.getLastSourceType(); this.navigationIcons[settingName].setTexture(type); this.navigationIcons[settingName].setFrame(icon); this.navigationIcons[settingName].alpha = 1; @@ -238,7 +238,7 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { success = true; NavigationManager.getInstance().reset(); // Reverts UI to its previous state on cancel. - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); } else { const cursor = this.cursor + this.scrollCursor; switch (button) { @@ -314,7 +314,7 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { activateSetting(setting: Setting): boolean { switch (setting.key) { case SettingKeys.Move_Touch_Controls: - this.scene.inputController.moveTouchControlsHandler.enableConfigurationMode(this.getUi(), this.scene); + globalScene.inputController.moveTouchControlsHandler.enableConfigurationMode(this.getUi()); return true; } return false; @@ -330,8 +330,8 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { const ret = super.setCursor(cursor); if (!this.cursorObj) { - const cursorWidth = (this.scene.game.canvas.width / 6) - (this.scrollBar.visible ? 16 : 10); - this.cursorObj = this.scene.add.nineslice(0, 0, "summary_moves_cursor", undefined, cursorWidth, 16, 1, 1, 1, 1); + const cursorWidth = (globalScene.game.canvas.width / 6) - (this.scrollBar.visible ? 16 : 10); + this.cursorObj = globalScene.add.nineslice(0, 0, "summary_moves_cursor", undefined, cursorWidth, 16, 1, 1, 1, 1); this.cursorObj.setOrigin(0, 0); this.optionsContainer.add(this.cursorObj); } @@ -369,7 +369,7 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { if (save) { const saveSetting = () => { - this.scene.gameData.saveSetting(setting.key, cursor); + globalScene.gameData.saveSetting(setting.key, cursor); if (setting.requireReload) { this.reloadRequired = true; } @@ -378,20 +378,20 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { // For settings that ask for confirmation, display confirmation message and a Yes/No prompt before saving the setting if (setting.options[cursor].needConfirmation) { const confirmUpdateSetting = () => { - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); this.showText(""); saveSetting(); }; const cancelUpdateSetting = () => { - this.scene.ui.revertMode(); + globalScene.ui.revertMode(); this.showText(""); // Put the cursor back to its previous position without saving or asking for confirmation again this.setOptionCursor(settingIndex, lastCursor, false); }; const confirmationMessage = setting.options[cursor].confirmationMessage ?? i18next.t("settings:defaultConfirmMessage"); - this.scene.ui.showText(confirmationMessage, null, () => { - this.scene.ui.setOverlayMode(Mode.CONFIRM, confirmUpdateSetting, cancelUpdateSetting, null, null, 1, 750); + globalScene.ui.showText(confirmationMessage, null, () => { + globalScene.ui.setOverlayMode(Mode.CONFIRM, confirmUpdateSetting, cancelUpdateSetting, null, null, 1, 750); }); } else { saveSetting(); @@ -445,10 +445,10 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler { this.settingsContainer.setVisible(false); this.setScrollCursor(0); this.eraseCursor(); - this.getUi().bgmBar.toggleBgmBar(this.scene.showBgmBar); + this.getUi().bgmBar.toggleBgmBar(globalScene.showBgmBar); if (this.reloadRequired) { this.reloadRequired = false; - this.scene.reset(true, false, true); + globalScene.reset(true, false, true); } } diff --git a/src/ui/settings/gamepad-binding-ui-handler.ts b/src/ui/settings/gamepad-binding-ui-handler.ts index e89529f64535..e69578312bbc 100644 --- a/src/ui/settings/gamepad-binding-ui-handler.ts +++ b/src/ui/settings/gamepad-binding-ui-handler.ts @@ -1,37 +1,37 @@ -import BattleScene from "../../battle-scene"; import AbstractBindingUiHandler from "./abstract-binding-ui-handler"; import { Mode } from "../ui"; import { Device } from "#enums/devices"; import { getIconWithSettingName, getKeyWithKeycode } from "#app/configs/inputs/configHandler"; import { addTextObject, TextStyle } from "#app/ui/text"; +import { globalScene } from "#app/global-scene"; export default class GamepadBindingUiHandler extends AbstractBindingUiHandler { - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); - this.scene.input.gamepad?.on("down", this.gamepadButtonDown, this); + constructor(mode: Mode | null = null) { + super(mode); + globalScene.input.gamepad?.on("down", this.gamepadButtonDown, this); } setup() { super.setup(); // New button icon setup. - this.newButtonIcon = this.scene.add.sprite(0, 0, "xbox"); + this.newButtonIcon = globalScene.add.sprite(0, 0, "xbox"); this.newButtonIcon.setPositionRelative(this.optionSelectBg, 78, 16); this.newButtonIcon.setOrigin(0.5); this.newButtonIcon.setVisible(false); - this.swapText = addTextObject(this.scene, 0, 0, "will swap with", TextStyle.WINDOW); + this.swapText = addTextObject(0, 0, "will swap with", TextStyle.WINDOW); this.swapText.setOrigin(0.5); this.swapText.setPositionRelative(this.optionSelectBg, this.optionSelectBg.width / 2 - 2, this.optionSelectBg.height / 2 - 2); this.swapText.setVisible(false); - this.targetButtonIcon = this.scene.add.sprite(0, 0, "xbox"); + this.targetButtonIcon = globalScene.add.sprite(0, 0, "xbox"); this.targetButtonIcon.setPositionRelative(this.optionSelectBg, 78, 48); this.targetButtonIcon.setOrigin(0.5); this.targetButtonIcon.setVisible(false); - this.actionLabel = addTextObject(this.scene, 0, 0, "Confirm swap", TextStyle.SETTINGS_LABEL); + this.actionLabel = addTextObject(0, 0, "Confirm swap", TextStyle.SETTINGS_LABEL); this.actionLabel.setOrigin(0, 0.5); this.actionLabel.setPositionRelative(this.actionBg, this.actionBg.width - 75, this.actionBg.height / 2); this.actionsContainer.add(this.actionLabel); @@ -42,7 +42,7 @@ export default class GamepadBindingUiHandler extends AbstractBindingUiHandler { } getSelectedDevice() { - return this.scene.inputController?.selectedDevice[Device.GAMEPAD]; + return globalScene.inputController?.selectedDevice[Device.GAMEPAD]; } gamepadButtonDown(pad: Phaser.Input.Gamepad.Gamepad, button: Phaser.Input.Gamepad.Button, value: number): void { @@ -51,7 +51,7 @@ export default class GamepadBindingUiHandler extends AbstractBindingUiHandler { if (!this.listening || pad.id.toLowerCase() !== this.getSelectedDevice() || blacklist.includes(button.index) || this.buttonPressed !== null) { return; } - const activeConfig = this.scene.inputController.getActiveConfig(Device.GAMEPAD); + const activeConfig = globalScene.inputController.getActiveConfig(Device.GAMEPAD); const type = activeConfig.padType; const key = getKeyWithKeycode(activeConfig, button.index); const buttonIcon = activeConfig.icons[key]; @@ -64,9 +64,9 @@ export default class GamepadBindingUiHandler extends AbstractBindingUiHandler { } swapAction(): boolean { - const activeConfig = this.scene.inputController.getActiveConfig(Device.GAMEPAD); - if (this.scene.inputController.assignBinding(activeConfig, this.target, this.buttonPressed)) { - this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig); + const activeConfig = globalScene.inputController.getActiveConfig(Device.GAMEPAD); + if (globalScene.inputController.assignBinding(activeConfig, this.target, this.buttonPressed)) { + globalScene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig); return true; } return false; diff --git a/src/ui/settings/keyboard-binding-ui-handler.ts b/src/ui/settings/keyboard-binding-ui-handler.ts index 52b1a0e385f9..18238241c946 100644 --- a/src/ui/settings/keyboard-binding-ui-handler.ts +++ b/src/ui/settings/keyboard-binding-ui-handler.ts @@ -1,29 +1,29 @@ -import BattleScene from "../../battle-scene"; import AbstractBindingUiHandler from "./abstract-binding-ui-handler"; import { Mode } from "../ui"; import { getKeyWithKeycode } from "#app/configs/inputs/configHandler"; import { Device } from "#enums/devices"; import { addTextObject, TextStyle } from "#app/ui/text"; +import { globalScene } from "#app/global-scene"; export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler { - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); // Listen to gamepad button down events to initiate binding. - scene.input.keyboard?.on("keydown", this.onKeyDown, this); + globalScene.input.keyboard?.on("keydown", this.onKeyDown, this); } setup() { super.setup(); // New button icon setup. - this.newButtonIcon = this.scene.add.sprite(0, 0, "keyboard"); + this.newButtonIcon = globalScene.add.sprite(0, 0, "keyboard"); this.newButtonIcon.setPositionRelative(this.optionSelectBg, 78, 32); this.newButtonIcon.setOrigin(0.5); this.newButtonIcon.setVisible(false); - this.actionLabel = addTextObject(this.scene, 0, 0, "Assign button", TextStyle.SETTINGS_LABEL); + this.actionLabel = addTextObject(0, 0, "Assign button", TextStyle.SETTINGS_LABEL); this.actionLabel.setOrigin(0, 0.5); this.actionLabel.setPositionRelative(this.actionBg, this.actionBg.width - 80, this.actionBg.height / 2); this.actionsContainer.add(this.actionLabel); @@ -32,7 +32,7 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler { } getSelectedDevice() { - return this.scene.inputController?.selectedDevice[Device.KEYBOARD]; + return globalScene.inputController?.selectedDevice[Device.KEYBOARD]; } onKeyDown(event): void { @@ -51,7 +51,7 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler { if (!this.listening || this.buttonPressed !== null || blacklist.includes(key)) { return; } - const activeConfig = this.scene.inputController.getActiveConfig(Device.KEYBOARD); + const activeConfig = globalScene.inputController.getActiveConfig(Device.KEYBOARD); const _key = getKeyWithKeycode(activeConfig, key); const buttonIcon = activeConfig.icons[_key]; if (!buttonIcon) { @@ -63,9 +63,9 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler { } swapAction(): boolean { - const activeConfig = this.scene.inputController.getActiveConfig(Device.KEYBOARD); - if (this.scene.inputController.assignBinding(activeConfig, this.target, this.buttonPressed)) { - this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig); + const activeConfig = globalScene.inputController.getActiveConfig(Device.KEYBOARD); + if (globalScene.inputController.assignBinding(activeConfig, this.target, this.buttonPressed)) { + globalScene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig); return true; } return false; diff --git a/src/ui/settings/move-touch-controls-handler.ts b/src/ui/settings/move-touch-controls-handler.ts index eda75a54a63a..614e6288457f 100644 --- a/src/ui/settings/move-touch-controls-handler.ts +++ b/src/ui/settings/move-touch-controls-handler.ts @@ -1,6 +1,6 @@ +import { globalScene } from "#app/global-scene"; import TouchControl from "#app/touch-controls"; import UI from "#app/ui/ui"; -import { Scene } from "phaser"; export const TOUCH_CONTROL_POSITIONS_LANDSCAPE = "touchControlPositionsLandscape"; export const TOUCH_CONTROL_POSITIONS_PORTRAIT = "touchControlPositionsPortrait"; @@ -319,11 +319,10 @@ export default class MoveTouchControlsHandler { * Creates an overlay that covers the screen and allows the user to drag the touch controls around. * Also enables the toolbar for saving, resetting, and canceling the changes. * @param ui The UI of the game. - * @param scene The scene of the game. */ - private createOverlay(ui: UI, scene: Scene) { - const container = new Phaser.GameObjects.Container(scene, 0, 0); - const overlay = new Phaser.GameObjects.Rectangle(scene, 0, 0, scene.game.canvas.width, scene.game.canvas.height, 0x000000, 0.5); + private createOverlay(ui: UI) { + const container = new Phaser.GameObjects.Container(globalScene, 0, 0); + const overlay = new Phaser.GameObjects.Rectangle(globalScene, 0, 0, globalScene.game.canvas.width, globalScene.game.canvas.height, 0x000000, 0.5); overlay.setInteractive(); container.add(overlay); ui.add(container); @@ -336,15 +335,14 @@ export default class MoveTouchControlsHandler { /** * Allows the user to configure the touch controls by dragging buttons around the screen. * @param ui The UI of the game. - * @param scene The scene of the game. */ - public enableConfigurationMode(ui: UI, scene: Scene) { + public enableConfigurationMode(ui: UI) { if (this.inConfigurationMode) { return; } this.inConfigurationMode = true; this.touchControls.disable(); - this.createOverlay(ui, scene); + this.createOverlay(ui); this.createToolbar(); // Create event listeners with a delay to prevent the touchstart event from being triggered immediately. setTimeout(() => { diff --git a/src/ui/settings/navigationMenu.ts b/src/ui/settings/navigationMenu.ts index ab86fa1569a0..af6c3b0b45c8 100644 --- a/src/ui/settings/navigationMenu.ts +++ b/src/ui/settings/navigationMenu.ts @@ -1,4 +1,4 @@ -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Mode } from "#app/ui/ui"; import { InputsIcons } from "#app/ui/settings/abstract-control-settings-ui-handler"; import { addTextObject, setTextStyle, TextStyle } from "#app/ui/text"; @@ -23,7 +23,7 @@ export class NavigationManager { * Creates an instance of NavigationManager. * To create a new tab in the menu, add the mode to the modes array and the label to the labels array. * and instantiate a new NavigationMenu instance in your handler - * like: this.navigationContainer = new NavigationMenu(this.scene, 0, 0); + * like: this.navigationContainer = new NavigationMenu(0, 0); */ constructor() { this.modes = [ @@ -54,10 +54,9 @@ export class NavigationManager { /** * Navigates modes based on given direction - * @param scene The current BattleScene instance * @param direction LEFT or RIGHT */ - public navigate(scene, direction) { + public navigate(direction) { const pos = this.modes.indexOf(this.selectedMode); const maxPos = this.modes.length - 1; const increment = direction === LEFT ? -1 : 1; @@ -68,7 +67,7 @@ export class NavigationManager { } else { this.selectedMode = this.modes[pos + increment]; } - scene.ui.setMode(this.selectedMode); + globalScene.ui.setMode(this.selectedMode); this.updateNavigationMenus(); } @@ -94,18 +93,15 @@ export class NavigationManager { export default class NavigationMenu extends Phaser.GameObjects.Container { private navigationIcons: InputsIcons; - public scene: BattleScene; protected headerTitles: Phaser.GameObjects.Text[] = new Array(); /** * Creates an instance of NavigationMenu. - * @param scene The current BattleScene instance. * @param x The x position of the NavigationMenu. * @param y The y position of the NavigationMenu. */ - constructor(scene: BattleScene, x: number, y: number) { - super(scene, x, y); - this.scene = scene; + constructor(x: number, y: number) { + super(globalScene, x, y); this.setup(); } @@ -115,7 +111,7 @@ export default class NavigationMenu extends Phaser.GameObjects.Container { */ setup() { const navigationManager = NavigationManager.getInstance(); - const headerBg = addWindow(this.scene, 0, 0, (this.scene.game.canvas.width / 6) - 2, 24); + const headerBg = addWindow(0, 0, (globalScene.game.canvas.width / 6) - 2, 24); headerBg.setOrigin(0, 0); this.add(headerBg); this.width = headerBg.width; @@ -123,12 +119,12 @@ export default class NavigationMenu extends Phaser.GameObjects.Container { this.navigationIcons = {}; - const iconPreviousTab = this.scene.add.sprite(8, 4, "keyboard"); + const iconPreviousTab = globalScene.add.sprite(8, 4, "keyboard"); iconPreviousTab.setOrigin(0, -0.1); iconPreviousTab.setPositionRelative(headerBg, 8, 4); this.navigationIcons["BUTTON_CYCLE_FORM"] = iconPreviousTab; - const iconNextTab = this.scene.add.sprite(0, 0, "keyboard"); + const iconNextTab = globalScene.add.sprite(0, 0, "keyboard"); iconNextTab.setOrigin(0, -0.1); iconNextTab.setPositionRelative(headerBg, headerBg.width - 20, 4); this.navigationIcons["BUTTON_CYCLE_SHINY"] = iconNextTab; @@ -136,7 +132,7 @@ export default class NavigationMenu extends Phaser.GameObjects.Container { let relative: Phaser.GameObjects.Sprite | Phaser.GameObjects.Text = iconPreviousTab; let relativeWidth: number = iconPreviousTab.width * 6; for (const label of navigationManager.labels) { - const labelText = addTextObject(this.scene, 0, 0, label, TextStyle.SETTINGS_LABEL); + const labelText = addTextObject(0, 0, label, TextStyle.SETTINGS_LABEL); labelText.setOrigin(0, 0); labelText.setPositionRelative(relative, 6 + relativeWidth / 6, 0); this.add(labelText); @@ -159,7 +155,7 @@ export default class NavigationMenu extends Phaser.GameObjects.Container { const posSelected = navigationManager.modes.indexOf(navigationManager.selectedMode); for (const [ index, title ] of this.headerTitles.entries()) { - setTextStyle(title, this.scene, index === posSelected ? TextStyle.SETTINGS_SELECTED : TextStyle.SETTINGS_LABEL); + setTextStyle(title, index === posSelected ? TextStyle.SETTINGS_SELECTED : TextStyle.SETTINGS_LABEL); } } @@ -178,9 +174,9 @@ export default class NavigationMenu extends Phaser.GameObjects.Container { this.navigationIcons[settingName].alpha = 1; continue; } - const icon = this.scene.inputController?.getIconForLatestInputRecorded(settingName); + const icon = globalScene.inputController?.getIconForLatestInputRecorded(settingName); if (icon) { - const type = this.scene.inputController?.getLastSourceType(); + const type = globalScene.inputController?.getLastSourceType(); this.navigationIcons[settingName].setTexture(type); this.navigationIcons[settingName].setFrame(icon); this.navigationIcons[settingName].alpha = 1; @@ -199,10 +195,10 @@ export default class NavigationMenu extends Phaser.GameObjects.Container { const navigationManager = NavigationManager.getInstance(); switch (button) { case Button.CYCLE_FORM: - navigationManager.navigate(this.scene, LEFT); + navigationManager.navigate(LEFT); return true; case Button.CYCLE_SHINY: - navigationManager.navigate(this.scene, RIGHT); + navigationManager.navigate(RIGHT); return true; } return false; diff --git a/src/ui/settings/option-select-ui-handler.ts b/src/ui/settings/option-select-ui-handler.ts index 8d2c534476aa..5deaba5cfc57 100644 --- a/src/ui/settings/option-select-ui-handler.ts +++ b/src/ui/settings/option-select-ui-handler.ts @@ -1,10 +1,9 @@ -import BattleScene from "../../battle-scene"; import AbstractOptionSelectUiHandler from "../abstact-option-select-ui-handler"; import { Mode } from "../ui"; export default class OptionSelectUiHandler extends AbstractOptionSelectUiHandler { - constructor(scene: BattleScene, mode: Mode = Mode.OPTION_SELECT) { - super(scene, mode); + constructor(mode: Mode = Mode.OPTION_SELECT) { + super(mode); } getWindowWidth(): integer { diff --git a/src/ui/settings/settings-audio-ui-handler.ts b/src/ui/settings/settings-audio-ui-handler.ts index 86c6a9bce40f..ad9f4dda6c30 100644 --- a/src/ui/settings/settings-audio-ui-handler.ts +++ b/src/ui/settings/settings-audio-ui-handler.ts @@ -1,18 +1,16 @@ -import BattleScene from "../../battle-scene"; import { Mode } from "../ui"; -"#app/inputs-controller"; import AbstractSettingsUiHandler from "./abstract-settings-ui-handler"; import { SettingType } from "#app/system/settings/settings"; +"#app/inputs-controller"; export default class SettingsAudioUiHandler extends AbstractSettingsUiHandler { /** * Creates an instance of SettingsAudioUiHandler. * - * @param scene - The BattleScene instance. * @param mode - The UI mode, optional. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, SettingType.AUDIO, mode); + constructor(mode: Mode | null = null) { + super(SettingType.AUDIO, mode); this.title = "Audio"; this.localStorageKey = "settings"; this.rowsToDisplay = 6; diff --git a/src/ui/settings/settings-display-ui-handler.ts b/src/ui/settings/settings-display-ui-handler.ts index c4cbb0dfe586..69fb53eddb4d 100644 --- a/src/ui/settings/settings-display-ui-handler.ts +++ b/src/ui/settings/settings-display-ui-handler.ts @@ -1,18 +1,16 @@ -import BattleScene from "../../battle-scene"; import { Mode } from "../ui"; -"#app/inputs-controller"; import AbstractSettingsUiHandler from "./abstract-settings-ui-handler"; import { SettingKeys, SettingType } from "#app/system/settings/settings"; +"#app/inputs-controller"; export default class SettingsDisplayUiHandler extends AbstractSettingsUiHandler { /** * Creates an instance of SettingsGamepadUiHandler. * - * @param scene - The BattleScene instance. * @param mode - The UI mode, optional. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, SettingType.DISPLAY, mode); + constructor(mode: Mode | null = null) { + super(SettingType.DISPLAY, mode); this.title = "Display"; /** diff --git a/src/ui/settings/settings-gamepad-ui-handler.ts b/src/ui/settings/settings-gamepad-ui-handler.ts index 864142e055be..6d07671ff542 100644 --- a/src/ui/settings/settings-gamepad-ui-handler.ts +++ b/src/ui/settings/settings-gamepad-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../../battle-scene"; import { addTextObject, TextStyle } from "../text"; import { Mode } from "../ui"; import { @@ -16,6 +15,7 @@ import AbstractControlSettingsUiHandler from "#app/ui/settings/abstract-control- import { Device } from "#enums/devices"; import { truncateString } from "#app/utils"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; /** * Class representing the settings UI handler for gamepads. @@ -28,11 +28,10 @@ export default class SettingsGamepadUiHandler extends AbstractControlSettingsUiH /** * Creates an instance of SettingsGamepadUiHandler. * - * @param scene - The BattleScene instance. * @param mode - The UI mode, optional. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.titleSelected = "Gamepad"; this.setting = SettingGamepad; this.settingDeviceDefaults = settingGamepadDefaults; @@ -53,9 +52,9 @@ export default class SettingsGamepadUiHandler extends AbstractControlSettingsUiH super.setup(); // If no gamepads are detected, set up a default UI prompt in the settings container. this.layout["noGamepads"] = new Map(); - const optionsContainer = this.scene.add.container(0, 0); + const optionsContainer = globalScene.add.container(0, 0); optionsContainer.setVisible(false); // Initially hide the container as no gamepads are connected. - const label = addTextObject(this.scene, 8, 28, i18next.t("settings:gamepadPleasePlug"), TextStyle.SETTINGS_LABEL); + const label = addTextObject(8, 28, i18next.t("settings:gamepadPleasePlug"), TextStyle.SETTINGS_LABEL); label.setOrigin(0, 0); optionsContainer.add(label); this.settingsContainer.add(optionsContainer); @@ -107,7 +106,7 @@ export default class SettingsGamepadUiHandler extends AbstractControlSettingsUiH // Update the text of the first option label under the current setting to the name of the chosen gamepad, // truncating the name to 30 characters if necessary. - this.layout[_key].optionValueLabels[index][0].setText(truncateString(this.scene.inputController.selectedDevice[Device.GAMEPAD], 20)); + this.layout[_key].optionValueLabels[index][0].setText(truncateString(globalScene.inputController.selectedDevice[Device.GAMEPAD], 20)); } } } @@ -121,7 +120,7 @@ export default class SettingsGamepadUiHandler extends AbstractControlSettingsUiH */ saveSettingToLocalStorage(settingName, cursor): void { if (this.setting[settingName] !== this.setting.Controller) { - this.scene.gameData.saveControlSetting(this.device, this.localStoragePropertyName, settingName, this.settingDeviceDefaults, cursor); + globalScene.gameData.saveControlSetting(this.device, this.localStoragePropertyName, settingName, this.settingDeviceDefaults, cursor); } } } diff --git a/src/ui/settings/settings-keyboard-ui-handler.ts b/src/ui/settings/settings-keyboard-ui-handler.ts index 17d91b27c575..0f9d09696ebb 100644 --- a/src/ui/settings/settings-keyboard-ui-handler.ts +++ b/src/ui/settings/settings-keyboard-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../../battle-scene"; import { Mode } from "../ui"; import cfg_keyboard_qwerty from "#app/configs/inputs/cfg_keyboard_qwerty"; import { @@ -16,6 +15,7 @@ import { deleteBind } from "#app/configs/inputs/configHandler"; import { Device } from "#enums/devices"; import { NavigationManager } from "#app/ui/settings/navigationMenu"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; /** * Class representing the settings UI handler for keyboards. @@ -26,11 +26,10 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi /** * Creates an instance of SettingsKeyboardUiHandler. * - * @param scene - The BattleScene instance. * @param mode - The UI mode, optional. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.titleSelected = "Keyboard"; this.setting = SettingKeyboard; this.settingDeviceDefaults = settingKeyboardDefaults; @@ -42,8 +41,8 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi this.settingBlacklisted = settingKeyboardBlackList; this.device = Device.KEYBOARD; - const deleteEvent = scene.input.keyboard?.addKey(Phaser.Input.Keyboard.KeyCodes.DELETE); - const restoreDefaultEvent = scene.input.keyboard?.addKey(Phaser.Input.Keyboard.KeyCodes.HOME); + const deleteEvent = globalScene.input.keyboard?.addKey(Phaser.Input.Keyboard.KeyCodes.DELETE); + const restoreDefaultEvent = globalScene.input.keyboard?.addKey(Phaser.Input.Keyboard.KeyCodes.HOME); deleteEvent && deleteEvent.on("up", this.onDeleteDown, this); restoreDefaultEvent && restoreDefaultEvent.on("up", this.onHomeDown, this); } @@ -57,19 +56,19 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi super.setup(); // If no gamepads are detected, set up a default UI prompt in the settings container. this.layout["noKeyboard"] = new Map(); - const optionsContainer = this.scene.add.container(0, 0); + const optionsContainer = globalScene.add.container(0, 0); optionsContainer.setVisible(false); // Initially hide the container as no gamepads are connected. - const label = addTextObject(this.scene, 8, 28, i18next.t("settings:keyboardPleasePress"), TextStyle.SETTINGS_LABEL); + const label = addTextObject(8, 28, i18next.t("settings:keyboardPleasePress"), TextStyle.SETTINGS_LABEL); label.setOrigin(0, 0); optionsContainer.add(label); this.settingsContainer.add(optionsContainer); - const iconDelete = this.scene.add.sprite(0, 0, "keyboard"); + const iconDelete = globalScene.add.sprite(0, 0, "keyboard"); iconDelete.setOrigin(0, -0.1); iconDelete.setPositionRelative(this.actionsBg, this.navigationContainer.width - 260, 4); this.navigationIcons["BUTTON_DELETE"] = iconDelete; - const deleteText = addTextObject(this.scene, 0, 0, i18next.t("settings:delete"), TextStyle.SETTINGS_LABEL); + const deleteText = addTextObject(0, 0, i18next.t("settings:delete"), TextStyle.SETTINGS_LABEL); deleteText.setOrigin(0, 0.15); deleteText.setPositionRelative(iconDelete, -deleteText.width / 6 - 2, 0); @@ -86,10 +85,10 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi * Handle the home key press event. */ onHomeDown(): void { - if (![ Mode.SETTINGS_KEYBOARD, Mode.SETTINGS_GAMEPAD ].includes(this.scene.ui.getMode())) { + if (![ Mode.SETTINGS_KEYBOARD, Mode.SETTINGS_GAMEPAD ].includes(globalScene.ui.getMode())) { return; } - this.scene.gameData.resetMappingToFactory(); + globalScene.gameData.resetMappingToFactory(); NavigationManager.getInstance().updateIcons(); } @@ -97,7 +96,7 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi * Handle the delete key press event. */ onDeleteDown(): void { - if (this.scene.ui.getMode() !== Mode.SETTINGS_KEYBOARD) { + if (globalScene.ui.getMode() !== Mode.SETTINGS_KEYBOARD) { return; } const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position. @@ -153,7 +152,7 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi } // Skip updating the no gamepad layout. // Update the text of the first option label under the current setting to the name of the chosen gamepad, // truncating the name to 30 characters if necessary. - this.layout[_key].optionValueLabels[index][0].setText(truncateString(this.scene.inputController.selectedDevice[Device.KEYBOARD], 22)); + this.layout[_key].optionValueLabels[index][0].setText(truncateString(globalScene.inputController.selectedDevice[Device.KEYBOARD], 22)); } } } @@ -166,7 +165,7 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi * @param config - The configuration to save. */ saveCustomKeyboardMappingToLocalStorage(config): void { - this.scene.gameData.saveMappingConfigs(this.scene.inputController?.selectedDevice[Device.KEYBOARD], config); + globalScene.gameData.saveMappingConfigs(globalScene.inputController?.selectedDevice[Device.KEYBOARD], config); } /** @@ -177,7 +176,7 @@ export default class SettingsKeyboardUiHandler extends AbstractControlSettingsUi */ saveSettingToLocalStorage(settingName, cursor): void { if (this.setting[settingName] !== this.setting.Default_Layout) { - this.scene.gameData.saveControlSetting(this.device, this.localStoragePropertyName, settingName, this.settingDeviceDefaults, cursor); + globalScene.gameData.saveControlSetting(this.device, this.localStoragePropertyName, settingName, this.settingDeviceDefaults, cursor); } } } diff --git a/src/ui/settings/settings-ui-handler.ts b/src/ui/settings/settings-ui-handler.ts index 3c5a7dd2c904..f290878bb15f 100644 --- a/src/ui/settings/settings-ui-handler.ts +++ b/src/ui/settings/settings-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../../battle-scene"; import { SettingType } from "../../system/settings/settings"; import { Mode } from "../ui"; import AbstractSettingsUiHandler from "./abstract-settings-ui-handler"; @@ -7,11 +6,10 @@ export default class SettingsUiHandler extends AbstractSettingsUiHandler { /** * Creates an instance of SettingsGamepadUiHandler. * - * @param scene - The BattleScene instance. * @param mode - The UI mode, optional. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, SettingType.GENERAL, mode); + constructor(mode: Mode | null = null) { + super(SettingType.GENERAL, mode); this.title = "General"; this.localStorageKey = "settings"; } diff --git a/src/ui/starter-container.ts b/src/ui/starter-container.ts index ce21d13add89..abf484677cec 100644 --- a/src/ui/starter-container.ts +++ b/src/ui/starter-container.ts @@ -1,9 +1,8 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import PokemonSpecies from "../data/pokemon-species"; import { addTextObject, TextStyle } from "./text"; export class StarterContainer extends Phaser.GameObjects.Container { - public scene: BattleScene; public species: PokemonSpecies; public icon: Phaser.GameObjects.Sprite; public shinyIcons: Phaser.GameObjects.Image[] = []; @@ -16,16 +15,16 @@ export class StarterContainer extends Phaser.GameObjects.Container { public candyUpgradeOverlayIcon: Phaser.GameObjects.Image; public cost: number = 0; - constructor(scene: BattleScene, species: PokemonSpecies) { - super(scene, 0, 0); + constructor(species: PokemonSpecies) { + super(globalScene, 0, 0); this.species = species; - const defaultDexAttr = scene.gameData.getSpeciesDefaultDexAttr(species, false, true); - const defaultProps = scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, false, true); + const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); // starter passive bg - const starterPassiveBg = this.scene.add.image(2, 5, "passive_bg"); + const starterPassiveBg = globalScene.add.image(2, 5, "passive_bg"); starterPassiveBg.setOrigin(0, 0); starterPassiveBg.setScale(0.75); starterPassiveBg.setVisible(false); @@ -33,7 +32,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { this.starterPassiveBgs = starterPassiveBg; // icon - this.icon = this.scene.add.sprite(-2, 2, species.getIconAtlasKey(defaultProps.formIndex, defaultProps.shiny, defaultProps.variant)); + this.icon = globalScene.add.sprite(-2, 2, species.getIconAtlasKey(defaultProps.formIndex, defaultProps.shiny, defaultProps.variant)); this.icon.setScale(0.5); this.icon.setOrigin(0, 0); this.icon.setFrame(species.getIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant)); @@ -43,7 +42,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { // shiny icons for (let i = 0; i < 3; i++) { - const shinyIcon = this.scene.add.image(i * -3 + 12, 2, "shiny_star_small"); + const shinyIcon = globalScene.add.image(i * -3 + 12, 2, "shiny_star_small"); shinyIcon.setScale(0.5); shinyIcon.setOrigin(0, 0); shinyIcon.setVisible(false); @@ -52,7 +51,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { this.add(this.shinyIcons); // value label - const label = addTextObject(this.scene, 1, 2, "0", TextStyle.WINDOW, { fontSize: "32px" }); + const label = addTextObject(1, 2, "0", TextStyle.WINDOW, { fontSize: "32px" }); label.setShadowOffset(2, 2); label.setOrigin(0, 0); label.setVisible(false); @@ -60,7 +59,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { this.label = label; // hidden ability icon - const abilityIcon = this.scene.add.image(12, 7, "ha_capsule"); + const abilityIcon = globalScene.add.image(12, 7, "ha_capsule"); abilityIcon.setOrigin(0, 0); abilityIcon.setScale(0.5); abilityIcon.setVisible(false); @@ -68,7 +67,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { this.hiddenAbilityIcon = abilityIcon; // favorite icon - const favoriteIcon = this.scene.add.image(0, 7, "favorite"); + const favoriteIcon = globalScene.add.image(0, 7, "favorite"); favoriteIcon.setOrigin(0, 0); favoriteIcon.setScale(0.5); favoriteIcon.setVisible(false); @@ -76,7 +75,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { this.favoriteIcon = favoriteIcon; // classic win icon - const classicWinIcon = this.scene.add.image(0, 12, "champion_ribbon"); + const classicWinIcon = globalScene.add.image(0, 12, "champion_ribbon"); classicWinIcon.setOrigin(0, 0); classicWinIcon.setScale(0.5); classicWinIcon.setVisible(false); @@ -84,7 +83,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { this.classicWinIcon = classicWinIcon; // candy upgrade icon - const candyUpgradeIcon = this.scene.add.image(12, 12, "candy"); + const candyUpgradeIcon = globalScene.add.image(12, 12, "candy"); candyUpgradeIcon.setOrigin(0, 0); candyUpgradeIcon.setScale(0.25); candyUpgradeIcon.setVisible(false); @@ -92,7 +91,7 @@ export class StarterContainer extends Phaser.GameObjects.Container { this.candyUpgradeIcon = candyUpgradeIcon; // candy upgrade overlay icon - const candyUpgradeOverlayIcon = this.scene.add.image(12, 12, "candy_overlay"); + const candyUpgradeOverlayIcon = globalScene.add.image(12, 12, "candy_overlay"); candyUpgradeOverlayIcon.setOrigin(0, 0); candyUpgradeOverlayIcon.setScale(0.25); candyUpgradeOverlayIcon.setVisible(false); diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 691e339eafc1..df77791e6869 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -4,7 +4,8 @@ import { Variant, getVariantTint, getVariantIcon } from "#app/data/variant"; import { argbFromRgba } from "@material/material-color-utilities"; import i18next from "i18next"; import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; -import BattleScene, { starterColors } from "#app/battle-scene"; +import { starterColors } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { allAbilities } from "#app/data/ability"; import { speciesEggMoves } from "#app/data/balance/egg-moves"; import { GrowthRate, getGrowthRateColor } from "#app/data/exp"; @@ -334,8 +335,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler { protected blockInput: boolean = false; - constructor(scene: BattleScene) { - super(scene, Mode.STARTER_SELECT); + constructor() { + super(Mode.STARTER_SELECT); } setup() { @@ -344,49 +345,49 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const langSettingKey = Object.keys(languageSettings).find(lang => currentLanguage.includes(lang)) ?? "en"; const textSettings = languageSettings[langSettingKey]; - this.starterSelectContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.starterSelectContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); this.starterSelectContainer.setVisible(false); ui.add(this.starterSelectContainer); - const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860); + const bgColor = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0x006860); bgColor.setOrigin(0, 0); this.starterSelectContainer.add(bgColor); - const starterSelectBg = this.scene.add.image(0, 0, "starter_select_bg"); + const starterSelectBg = globalScene.add.image(0, 0, "starter_select_bg"); starterSelectBg.setOrigin(0, 0); this.starterSelectContainer.add(starterSelectBg); - this.shinyOverlay = this.scene.add.image(6, 6, "summary_overlay_shiny"); + this.shinyOverlay = globalScene.add.image(6, 6, "summary_overlay_shiny"); this.shinyOverlay.setOrigin(0, 0); this.shinyOverlay.setVisible(false); this.starterSelectContainer.add(this.shinyOverlay); - const starterContainerWindow = addWindow(this.scene, speciesContainerX, filterBarHeight + 1, 175, 161); - const starterContainerBg = this.scene.add.image(speciesContainerX + 1, filterBarHeight + 2, "starter_container_bg"); + const starterContainerWindow = addWindow(speciesContainerX, filterBarHeight + 1, 175, 161); + const starterContainerBg = globalScene.add.image(speciesContainerX + 1, filterBarHeight + 2, "starter_container_bg"); starterContainerBg.setOrigin(0, 0); this.starterSelectContainer.add(starterContainerBg); - this.starterSelectContainer.add(addWindow(this.scene, teamWindowX, teamWindowY, teamWindowWidth, teamWindowHeight)); - this.starterSelectContainer.add(addWindow(this.scene, teamWindowX, teamWindowY + teamWindowHeight - 5, teamWindowWidth, teamWindowWidth, true)); + this.starterSelectContainer.add(addWindow(teamWindowX, teamWindowY, teamWindowWidth, teamWindowHeight)); + this.starterSelectContainer.add(addWindow(teamWindowX, teamWindowY + teamWindowHeight - 5, teamWindowWidth, teamWindowWidth, true)); this.starterSelectContainer.add(starterContainerWindow); // Create and initialise filter bar - this.filterBarContainer = this.scene.add.container(0, 0); - this.filterBar = new FilterBar(this.scene, Math.min(speciesContainerX, teamWindowX), 1, 210, filterBarHeight); + this.filterBarContainer = globalScene.add.container(0, 0); + this.filterBar = new FilterBar(Math.min(speciesContainerX, teamWindowX), 1, 210, filterBarHeight); // gen filter const genOptions: DropDownOption[] = [ - new DropDownOption(this.scene, 1, new DropDownLabel(i18next.t("starterSelectUiHandler:gen1"))), - new DropDownOption(this.scene, 2, new DropDownLabel(i18next.t("starterSelectUiHandler:gen2"))), - new DropDownOption(this.scene, 3, new DropDownLabel(i18next.t("starterSelectUiHandler:gen3"))), - new DropDownOption(this.scene, 4, new DropDownLabel(i18next.t("starterSelectUiHandler:gen4"))), - new DropDownOption(this.scene, 5, new DropDownLabel(i18next.t("starterSelectUiHandler:gen5"))), - new DropDownOption(this.scene, 6, new DropDownLabel(i18next.t("starterSelectUiHandler:gen6"))), - new DropDownOption(this.scene, 7, new DropDownLabel(i18next.t("starterSelectUiHandler:gen7"))), - new DropDownOption(this.scene, 8, new DropDownLabel(i18next.t("starterSelectUiHandler:gen8"))), - new DropDownOption(this.scene, 9, new DropDownLabel(i18next.t("starterSelectUiHandler:gen9"))), + new DropDownOption(1, new DropDownLabel(i18next.t("starterSelectUiHandler:gen1"))), + new DropDownOption(2, new DropDownLabel(i18next.t("starterSelectUiHandler:gen2"))), + new DropDownOption(3, new DropDownLabel(i18next.t("starterSelectUiHandler:gen3"))), + new DropDownOption(4, new DropDownLabel(i18next.t("starterSelectUiHandler:gen4"))), + new DropDownOption(5, new DropDownLabel(i18next.t("starterSelectUiHandler:gen5"))), + new DropDownOption(6, new DropDownLabel(i18next.t("starterSelectUiHandler:gen6"))), + new DropDownOption(7, new DropDownLabel(i18next.t("starterSelectUiHandler:gen7"))), + new DropDownOption(8, new DropDownLabel(i18next.t("starterSelectUiHandler:gen8"))), + new DropDownOption(9, new DropDownLabel(i18next.t("starterSelectUiHandler:gen9"))), ]; - const genDropDown: DropDown = new DropDown(this.scene, 0, 0, genOptions, this.updateStarters, DropDownType.HYBRID); + const genDropDown: DropDown = new DropDown(0, 0, genOptions, this.updateStarters, DropDownType.HYBRID); this.filterBar.addFilter(DropDownColumn.GEN, i18next.t("filterBar:genFilter"), genDropDown); // type filter @@ -396,39 +397,39 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (index === 0 || index === 19) { return; } - const typeSprite = this.scene.add.sprite(0, 0, getLocalizedSpriteKey("types")); + const typeSprite = globalScene.add.sprite(0, 0, getLocalizedSpriteKey("types")); typeSprite.setScale(0.5); typeSprite.setFrame(type.toLowerCase()); - typeOptions.push(new DropDownOption(this.scene, index, new DropDownLabel("", typeSprite))); + typeOptions.push(new DropDownOption(index, new DropDownLabel("", typeSprite))); }); - this.filterBar.addFilter(DropDownColumn.TYPES, i18next.t("filterBar:typeFilter"), new DropDown(this.scene, 0, 0, typeOptions, this.updateStarters, DropDownType.HYBRID, 0.5)); + this.filterBar.addFilter(DropDownColumn.TYPES, i18next.t("filterBar:typeFilter"), new DropDown(0, 0, typeOptions, this.updateStarters, DropDownType.HYBRID, 0.5)); // caught filter - const shiny1Sprite = this.scene.add.sprite(0, 0, "shiny_icons"); + const shiny1Sprite = globalScene.add.sprite(0, 0, "shiny_icons"); shiny1Sprite.setOrigin(0.15, 0.2); shiny1Sprite.setScale(0.6); shiny1Sprite.setFrame(getVariantIcon(0)); shiny1Sprite.setTint(getVariantTint(0)); - const shiny2Sprite = this.scene.add.sprite(0, 0, "shiny_icons"); + const shiny2Sprite = globalScene.add.sprite(0, 0, "shiny_icons"); shiny2Sprite.setOrigin(0.15, 0.2); shiny2Sprite.setScale(0.6); shiny2Sprite.setFrame(getVariantIcon(1)); shiny2Sprite.setTint(getVariantTint(1)); - const shiny3Sprite = this.scene.add.sprite(0, 0, "shiny_icons"); + const shiny3Sprite = globalScene.add.sprite(0, 0, "shiny_icons"); shiny3Sprite.setOrigin(0.15, 0.2); shiny3Sprite.setScale(0.6); shiny3Sprite.setFrame(getVariantIcon(2)); shiny3Sprite.setTint(getVariantTint(2)); const caughtOptions = [ - new DropDownOption(this.scene, "SHINY3", new DropDownLabel("", shiny3Sprite)), - new DropDownOption(this.scene, "SHINY2", new DropDownLabel("", shiny2Sprite)), - new DropDownOption(this.scene, "SHINY", new DropDownLabel("", shiny1Sprite)), - new DropDownOption(this.scene, "NORMAL", new DropDownLabel(i18next.t("filterBar:normal"))), - new DropDownOption(this.scene, "UNCAUGHT", new DropDownLabel(i18next.t("filterBar:uncaught"))) + new DropDownOption("SHINY3", new DropDownLabel("", shiny3Sprite)), + new DropDownOption("SHINY2", new DropDownLabel("", shiny2Sprite)), + new DropDownOption("SHINY", new DropDownLabel("", shiny1Sprite)), + new DropDownOption("NORMAL", new DropDownLabel(i18next.t("filterBar:normal"))), + new DropDownOption("UNCAUGHT", new DropDownLabel(i18next.t("filterBar:uncaught"))) ]; - this.filterBar.addFilter(DropDownColumn.CAUGHT, i18next.t("filterBar:caughtFilter"), new DropDown(this.scene, 0, 0, caughtOptions, this.updateStarters, DropDownType.HYBRID)); + this.filterBar.addFilter(DropDownColumn.CAUGHT, i18next.t("filterBar:caughtFilter"), new DropDown(0, 0, caughtOptions, this.updateStarters, DropDownType.HYBRID)); // unlocks filter const passiveLabels = [ @@ -446,11 +447,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { ]; const unlocksOptions = [ - new DropDownOption(this.scene, "PASSIVE", passiveLabels), - new DropDownOption(this.scene, "COST_REDUCTION", costReductionLabels), + new DropDownOption("PASSIVE", passiveLabels), + new DropDownOption("COST_REDUCTION", costReductionLabels), ]; - this.filterBar.addFilter(DropDownColumn.UNLOCKS, i18next.t("filterBar:unlocksFilter"), new DropDown(this.scene, 0, 0, unlocksOptions, this.updateStarters, DropDownType.RADIAL)); + this.filterBar.addFilter(DropDownColumn.UNLOCKS, i18next.t("filterBar:unlocksFilter"), new DropDown(0, 0, unlocksOptions, this.updateStarters, DropDownType.RADIAL)); // misc filter const favoriteLabels = [ @@ -477,23 +478,23 @@ export default class StarterSelectUiHandler extends MessageUiHandler { new DropDownLabel(i18next.t("filterBar:hasPokerus"), undefined, DropDownState.ON), ]; const miscOptions = [ - new DropDownOption(this.scene, "FAVORITE", favoriteLabels), - new DropDownOption(this.scene, "WIN", winLabels), - new DropDownOption(this.scene, "HIDDEN_ABILITY", hiddenAbilityLabels), - new DropDownOption(this.scene, "EGG", eggLabels), - new DropDownOption(this.scene, "POKERUS", pokerusLabels), + new DropDownOption("FAVORITE", favoriteLabels), + new DropDownOption("WIN", winLabels), + new DropDownOption("HIDDEN_ABILITY", hiddenAbilityLabels), + new DropDownOption("EGG", eggLabels), + new DropDownOption("POKERUS", pokerusLabels), ]; - this.filterBar.addFilter(DropDownColumn.MISC, i18next.t("filterBar:miscFilter"), new DropDown(this.scene, 0, 0, miscOptions, this.updateStarters, DropDownType.RADIAL)); + this.filterBar.addFilter(DropDownColumn.MISC, i18next.t("filterBar:miscFilter"), new DropDown(0, 0, miscOptions, this.updateStarters, DropDownType.RADIAL)); // sort filter const sortOptions = [ - new DropDownOption(this.scene, SortCriteria.NUMBER, new DropDownLabel(i18next.t("filterBar:sortByNumber"), undefined, DropDownState.ON)), - new DropDownOption(this.scene, SortCriteria.COST, new DropDownLabel(i18next.t("filterBar:sortByCost"))), - new DropDownOption(this.scene, SortCriteria.CANDY, new DropDownLabel(i18next.t("filterBar:sortByCandies"))), - new DropDownOption(this.scene, SortCriteria.IV, new DropDownLabel(i18next.t("filterBar:sortByIVs"))), - new DropDownOption(this.scene, SortCriteria.NAME, new DropDownLabel(i18next.t("filterBar:sortByName"))) + new DropDownOption(SortCriteria.NUMBER, new DropDownLabel(i18next.t("filterBar:sortByNumber"), undefined, DropDownState.ON)), + new DropDownOption(SortCriteria.COST, new DropDownLabel(i18next.t("filterBar:sortByCost"))), + new DropDownOption(SortCriteria.CANDY, new DropDownLabel(i18next.t("filterBar:sortByCandies"))), + new DropDownOption(SortCriteria.IV, new DropDownLabel(i18next.t("filterBar:sortByIVs"))), + new DropDownOption(SortCriteria.NAME, new DropDownLabel(i18next.t("filterBar:sortByName"))) ]; - this.filterBar.addFilter(DropDownColumn.SORT, i18next.t("filterBar:sortFilter"), new DropDown(this.scene, 0, 0, sortOptions, this.updateStarters, DropDownType.SINGLE)); + this.filterBar.addFilter(DropDownColumn.SORT, i18next.t("filterBar:sortFilter"), new DropDown(0, 0, sortOptions, this.updateStarters, DropDownType.SINGLE)); this.filterBarContainer.add(this.filterBar); this.starterSelectContainer.add(this.filterBarContainer); @@ -501,35 +502,35 @@ export default class StarterSelectUiHandler extends MessageUiHandler { // Offset the generation filter dropdown to avoid covering the filtered pokemon this.filterBar.offsetHybridFilters(); - if (!this.scene.uiTheme) { + if (!globalScene.uiTheme) { starterContainerWindow.setVisible(false); } this.iconAnimHandler = new PokemonIconAnimHandler(); - this.iconAnimHandler.setup(this.scene); + this.iconAnimHandler.setup(); - this.pokemonNumberText = addTextObject(this.scene, 17, 1, "0000", TextStyle.SUMMARY); + this.pokemonNumberText = addTextObject(17, 1, "0000", TextStyle.SUMMARY); this.pokemonNumberText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNumberText); - this.pokemonNameText = addTextObject(this.scene, 6, 112, "", TextStyle.SUMMARY); + this.pokemonNameText = addTextObject(6, 112, "", TextStyle.SUMMARY); this.pokemonNameText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNameText); - this.pokemonGrowthRateLabelText = addTextObject(this.scene, 8, 106, i18next.t("starterSelectUiHandler:growthRate"), TextStyle.SUMMARY_ALT, { fontSize: "36px" }); + this.pokemonGrowthRateLabelText = addTextObject(8, 106, i18next.t("starterSelectUiHandler:growthRate"), TextStyle.SUMMARY_ALT, { fontSize: "36px" }); this.pokemonGrowthRateLabelText.setOrigin(0, 0); this.pokemonGrowthRateLabelText.setVisible(false); this.starterSelectContainer.add(this.pokemonGrowthRateLabelText); - this.pokemonGrowthRateText = addTextObject(this.scene, 34, 106, "", TextStyle.SUMMARY_PINK, { fontSize: "36px" }); + this.pokemonGrowthRateText = addTextObject(34, 106, "", TextStyle.SUMMARY_PINK, { fontSize: "36px" }); this.pokemonGrowthRateText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonGrowthRateText); - this.pokemonGenderText = addTextObject(this.scene, 96, 112, "", TextStyle.SUMMARY_ALT); + this.pokemonGenderText = addTextObject(96, 112, "", TextStyle.SUMMARY_ALT); this.pokemonGenderText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonGenderText); - this.pokemonUncaughtText = addTextObject(this.scene, 6, 127, i18next.t("starterSelectUiHandler:uncaught"), TextStyle.SUMMARY_ALT, { fontSize: "56px" }); + this.pokemonUncaughtText = addTextObject(6, 127, i18next.t("starterSelectUiHandler:uncaught"), TextStyle.SUMMARY_ALT, { fontSize: "56px" }); this.pokemonUncaughtText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonUncaughtText); @@ -541,46 +542,46 @@ export default class StarterSelectUiHandler extends MessageUiHandler { // The font size should be set per language const starterInfoTextSize = textSettings?.starterInfoTextSize || 56; - this.pokemonAbilityLabelText = addTextObject(this.scene, 6, 127 + starterInfoYOffset, i18next.t("starterSelectUiHandler:ability"), TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); + this.pokemonAbilityLabelText = addTextObject(6, 127 + starterInfoYOffset, i18next.t("starterSelectUiHandler:ability"), TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); this.pokemonAbilityLabelText.setOrigin(0, 0); this.pokemonAbilityLabelText.setVisible(false); this.starterSelectContainer.add(this.pokemonAbilityLabelText); - this.pokemonAbilityText = addTextObject(this.scene, starterInfoXPos, 127 + starterInfoYOffset, "", TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); + this.pokemonAbilityText = addTextObject(starterInfoXPos, 127 + starterInfoYOffset, "", TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); this.pokemonAbilityText.setOrigin(0, 0); this.pokemonAbilityText.setInteractive(new Phaser.Geom.Rectangle(0, 0, 250, 55), Phaser.Geom.Rectangle.Contains); this.starterSelectContainer.add(this.pokemonAbilityText); - this.pokemonPassiveLabelText = addTextObject(this.scene, 6, 136 + starterInfoYOffset, i18next.t("starterSelectUiHandler:passive"), TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); + this.pokemonPassiveLabelText = addTextObject(6, 136 + starterInfoYOffset, i18next.t("starterSelectUiHandler:passive"), TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); this.pokemonPassiveLabelText.setOrigin(0, 0); this.pokemonPassiveLabelText.setVisible(false); this.starterSelectContainer.add(this.pokemonPassiveLabelText); - this.pokemonPassiveText = addTextObject(this.scene, starterInfoXPos, 136 + starterInfoYOffset, "", TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); + this.pokemonPassiveText = addTextObject(starterInfoXPos, 136 + starterInfoYOffset, "", TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); this.pokemonPassiveText.setOrigin(0, 0); this.pokemonPassiveText.setInteractive(new Phaser.Geom.Rectangle(0, 0, 250, 55), Phaser.Geom.Rectangle.Contains); this.starterSelectContainer.add(this.pokemonPassiveText); - this.pokemonPassiveDisabledIcon = this.scene.add.sprite(starterInfoXPos, 137 + starterInfoYOffset, "icon_stop"); + this.pokemonPassiveDisabledIcon = globalScene.add.sprite(starterInfoXPos, 137 + starterInfoYOffset, "icon_stop"); this.pokemonPassiveDisabledIcon.setOrigin(0, 0.5); this.pokemonPassiveDisabledIcon.setScale(0.35); this.pokemonPassiveDisabledIcon.setVisible(false); this.starterSelectContainer.add(this.pokemonPassiveDisabledIcon); - this.pokemonPassiveLockedIcon = this.scene.add.sprite(starterInfoXPos, 137 + starterInfoYOffset, "icon_lock"); + this.pokemonPassiveLockedIcon = globalScene.add.sprite(starterInfoXPos, 137 + starterInfoYOffset, "icon_lock"); this.pokemonPassiveLockedIcon.setOrigin(0, 0.5); this.pokemonPassiveLockedIcon.setScale(0.42, 0.38); this.pokemonPassiveLockedIcon.setVisible(false); this.starterSelectContainer.add(this.pokemonPassiveLockedIcon); - this.pokemonNatureLabelText = addTextObject(this.scene, 6, 145 + starterInfoYOffset, i18next.t("starterSelectUiHandler:nature"), TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); + this.pokemonNatureLabelText = addTextObject(6, 145 + starterInfoYOffset, i18next.t("starterSelectUiHandler:nature"), TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); this.pokemonNatureLabelText.setOrigin(0, 0); this.pokemonNatureLabelText.setVisible(false); this.starterSelectContainer.add(this.pokemonNatureLabelText); - this.pokemonNatureText = addBBCodeTextObject(this.scene, starterInfoXPos, 145 + starterInfoYOffset, "", TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); + this.pokemonNatureText = addBBCodeTextObject(starterInfoXPos, 145 + starterInfoYOffset, "", TextStyle.SUMMARY_ALT, { fontSize: starterInfoTextSize }); this.pokemonNatureText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNatureText); @@ -592,29 +593,29 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonEggMoveBgs = []; this.pokemonEggMoveLabels = []; - this.valueLimitLabel = addTextObject(this.scene, teamWindowX + 17, 150, "0/10", TextStyle.TOOLTIP_CONTENT); + this.valueLimitLabel = addTextObject(teamWindowX + 17, 150, "0/10", TextStyle.TOOLTIP_CONTENT); this.valueLimitLabel.setOrigin(0.5, 0); this.starterSelectContainer.add(this.valueLimitLabel); - const startLabel = addTextObject(this.scene, teamWindowX + 17, 162, i18next.t("common:start"), TextStyle.TOOLTIP_CONTENT); + const startLabel = addTextObject(teamWindowX + 17, 162, i18next.t("common:start"), TextStyle.TOOLTIP_CONTENT); startLabel.setOrigin(0.5, 0); this.starterSelectContainer.add(startLabel); - this.startCursorObj = this.scene.add.nineslice(teamWindowX + 4, 160, "select_cursor", undefined, 26, 15, 6, 6, 6, 6); + this.startCursorObj = globalScene.add.nineslice(teamWindowX + 4, 160, "select_cursor", undefined, 26, 15, 6, 6, 6, 6); this.startCursorObj.setVisible(false); this.startCursorObj.setOrigin(0, 0); this.starterSelectContainer.add(this.startCursorObj); const starterSpecies: Species[] = []; - const starterBoxContainer = this.scene.add.container(speciesContainerX + 6, 9); //115 + const starterBoxContainer = globalScene.add.container(speciesContainerX + 6, 9); //115 - this.starterSelectScrollBar = new ScrollBar(this.scene, 161, 12, 5, starterContainerWindow.height - 6, 9); + this.starterSelectScrollBar = new ScrollBar(161, 12, 5, starterContainerWindow.height - 6, 9); starterBoxContainer.add(this.starterSelectScrollBar); this.pokerusCursorObjs = new Array(POKERUS_STARTER_COUNT).fill(null).map(() => { - const cursorObj = this.scene.add.image(0, 0, "select_cursor_pokerus"); + const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus"); cursorObj.setVisible(false); cursorObj.setOrigin(0, 0); starterBoxContainer.add(cursorObj); @@ -622,16 +623,16 @@ export default class StarterSelectUiHandler extends MessageUiHandler { }); this.starterCursorObjs = new Array(6).fill(null).map(() => { - const cursorObj = this.scene.add.image(0, 0, "select_cursor_highlight"); + const cursorObj = globalScene.add.image(0, 0, "select_cursor_highlight"); cursorObj.setVisible(false); cursorObj.setOrigin(0, 0); starterBoxContainer.add(cursorObj); return cursorObj; }); - this.cursorObj = this.scene.add.image(0, 0, "select_cursor"); + this.cursorObj = globalScene.add.image(0, 0, "select_cursor"); this.cursorObj.setOrigin(0, 0); - this.starterIconsCursorObj = this.scene.add.image(289, 64, "select_gen_cursor"); + this.starterIconsCursorObj = globalScene.add.image(289, 64, "select_gen_cursor"); this.starterIconsCursorObj.setName("starter-icons-cursor"); this.starterIconsCursorObj.setVisible(false); this.starterIconsCursorObj.setOrigin(0, 0); @@ -648,7 +649,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.speciesLoaded.set(species.speciesId, false); this.allSpecies.push(species); - const starterContainer = new StarterContainer(this.scene, species).setVisible(false); + const starterContainer = new StarterContainer(species).setVisible(false); this.iconAnimHandler.addOrUpdate(starterContainer.icon, PokemonIconAnimMode.NONE); this.starterContainers.push(starterContainer); starterBoxContainer.add(starterContainer); @@ -657,7 +658,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.starterSelectContainer.add(starterBoxContainer); this.starterIcons = new Array(6).fill(null).map((_, i) => { - const icon = this.scene.add.sprite(teamWindowX + 7, calcStarterIconY(i), "pokemon_icons_0"); + const icon = globalScene.add.sprite(teamWindowX + 7, calcStarterIconY(i), "pokemon_icons_0"); icon.setScale(0.5); icon.setOrigin(0, 0); icon.setFrame("unknown"); @@ -666,96 +667,96 @@ export default class StarterSelectUiHandler extends MessageUiHandler { return icon; }); - this.pokemonSprite = this.scene.add.sprite(53, 63, "pkmn__sub"); - this.pokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + this.pokemonSprite = globalScene.add.sprite(53, 63, "pkmn__sub"); + this.pokemonSprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); this.starterSelectContainer.add(this.pokemonSprite); - this.type1Icon = this.scene.add.sprite(8, 98, getLocalizedSpriteKey("types")); + this.type1Icon = globalScene.add.sprite(8, 98, getLocalizedSpriteKey("types")); this.type1Icon.setScale(0.5); this.type1Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type1Icon); - this.type2Icon = this.scene.add.sprite(26, 98, getLocalizedSpriteKey("types")); + this.type2Icon = globalScene.add.sprite(26, 98, getLocalizedSpriteKey("types")); this.type2Icon.setScale(0.5); this.type2Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type2Icon); - this.pokemonLuckLabelText = addTextObject(this.scene, 8, 89, i18next.t("common:luckIndicator"), TextStyle.WINDOW_ALT, { fontSize: "56px" }); + this.pokemonLuckLabelText = addTextObject(8, 89, i18next.t("common:luckIndicator"), TextStyle.WINDOW_ALT, { fontSize: "56px" }); this.pokemonLuckLabelText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonLuckLabelText); - this.pokemonLuckText = addTextObject(this.scene, 8 + this.pokemonLuckLabelText.displayWidth + 2, 89, "0", TextStyle.WINDOW, { fontSize: "56px" }); + this.pokemonLuckText = addTextObject(8 + this.pokemonLuckLabelText.displayWidth + 2, 89, "0", TextStyle.WINDOW, { fontSize: "56px" }); this.pokemonLuckText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonLuckText); // Candy icon and count - this.pokemonCandyContainer = this.scene.add.container(4.5, 18); + this.pokemonCandyContainer = globalScene.add.container(4.5, 18); - this.pokemonCandyIcon = this.scene.add.sprite(0, 0, "candy"); + this.pokemonCandyIcon = globalScene.add.sprite(0, 0, "candy"); this.pokemonCandyIcon.setScale(0.5); this.pokemonCandyIcon.setOrigin(0, 0); this.pokemonCandyContainer.add(this.pokemonCandyIcon); - this.pokemonCandyOverlayIcon = this.scene.add.sprite(0, 0, "candy_overlay"); + this.pokemonCandyOverlayIcon = globalScene.add.sprite(0, 0, "candy_overlay"); this.pokemonCandyOverlayIcon.setScale(0.5); this.pokemonCandyOverlayIcon.setOrigin(0, 0); this.pokemonCandyContainer.add(this.pokemonCandyOverlayIcon); - this.pokemonCandyDarknessOverlay = this.scene.add.sprite(0, 0, "candy"); + this.pokemonCandyDarknessOverlay = globalScene.add.sprite(0, 0, "candy"); this.pokemonCandyDarknessOverlay.setScale(0.5); this.pokemonCandyDarknessOverlay.setOrigin(0, 0); this.pokemonCandyDarknessOverlay.setTint(0x000000); this.pokemonCandyDarknessOverlay.setAlpha(0.50); this.pokemonCandyContainer.add(this.pokemonCandyDarknessOverlay); - this.pokemonCandyCountText = addTextObject(this.scene, 9.5, 0, "x0", TextStyle.WINDOW_ALT, { fontSize: "56px" }); + this.pokemonCandyCountText = addTextObject(9.5, 0, "x0", TextStyle.WINDOW_ALT, { fontSize: "56px" }); this.pokemonCandyCountText.setOrigin(0, 0); this.pokemonCandyContainer.add(this.pokemonCandyCountText); this.pokemonCandyContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, 30, 20), Phaser.Geom.Rectangle.Contains); this.starterSelectContainer.add(this.pokemonCandyContainer); - this.pokemonFormText = addTextObject(this.scene, 6, 42, "Form", TextStyle.WINDOW_ALT, { fontSize: "42px" }); + this.pokemonFormText = addTextObject(6, 42, "Form", TextStyle.WINDOW_ALT, { fontSize: "42px" }); this.pokemonFormText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonFormText); - this.pokemonCaughtHatchedContainer = this.scene.add.container(2, 25); + this.pokemonCaughtHatchedContainer = globalScene.add.container(2, 25); this.pokemonCaughtHatchedContainer.setScale(0.5); this.starterSelectContainer.add(this.pokemonCaughtHatchedContainer); - const pokemonCaughtIcon = this.scene.add.sprite(1, 0, "items", "pb"); + const pokemonCaughtIcon = globalScene.add.sprite(1, 0, "items", "pb"); pokemonCaughtIcon.setOrigin(0, 0); pokemonCaughtIcon.setScale(0.75); this.pokemonCaughtHatchedContainer.add(pokemonCaughtIcon); - this.pokemonCaughtCountText = addTextObject(this.scene, 24, 4, "0", TextStyle.SUMMARY_ALT); + this.pokemonCaughtCountText = addTextObject(24, 4, "0", TextStyle.SUMMARY_ALT); this.pokemonCaughtCountText.setOrigin(0, 0); this.pokemonCaughtHatchedContainer.add(this.pokemonCaughtCountText); - this.pokemonHatchedIcon = this.scene.add.sprite(1, 14, "egg_icons"); + this.pokemonHatchedIcon = globalScene.add.sprite(1, 14, "egg_icons"); this.pokemonHatchedIcon.setOrigin(0.15, 0.2); this.pokemonHatchedIcon.setScale(0.8); this.pokemonCaughtHatchedContainer.add(this.pokemonHatchedIcon); - this.pokemonShinyIcon = this.scene.add.sprite(14, 76, "shiny_icons"); + this.pokemonShinyIcon = globalScene.add.sprite(14, 76, "shiny_icons"); this.pokemonShinyIcon.setOrigin(0.15, 0.2); this.pokemonShinyIcon.setScale(1); this.pokemonCaughtHatchedContainer.add(this.pokemonShinyIcon); - this.pokemonHatchedCountText = addTextObject(this.scene, 24, 19, "0", TextStyle.SUMMARY_ALT); + this.pokemonHatchedCountText = addTextObject(24, 19, "0", TextStyle.SUMMARY_ALT); this.pokemonHatchedCountText.setOrigin(0, 0); this.pokemonCaughtHatchedContainer.add(this.pokemonHatchedCountText); - this.pokemonMovesContainer = this.scene.add.container(102, 16); + this.pokemonMovesContainer = globalScene.add.container(102, 16); this.pokemonMovesContainer.setScale(0.375); for (let m = 0; m < 4; m++) { - const moveContainer = this.scene.add.container(0, 14 * m); + const moveContainer = globalScene.add.container(0, 14 * m); - const moveBg = this.scene.add.nineslice(0, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); + const moveBg = globalScene.add.nineslice(0, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); moveBg.setOrigin(1, 0); - const moveLabel = addTextObject(this.scene, -moveBg.width / 2, 0, "-", TextStyle.PARTY); + const moveLabel = addTextObject(-moveBg.width / 2, 0, "-", TextStyle.PARTY); moveLabel.setOrigin(0.5, 0); this.pokemonMoveBgs.push(moveBg); @@ -768,28 +769,28 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonMovesContainer.add(moveContainer); } - this.pokemonAdditionalMoveCountLabel = addTextObject(this.scene, -this.pokemonMoveBgs[0].width / 2, 56, "(+0)", TextStyle.PARTY); + this.pokemonAdditionalMoveCountLabel = addTextObject(-this.pokemonMoveBgs[0].width / 2, 56, "(+0)", TextStyle.PARTY); this.pokemonAdditionalMoveCountLabel.setOrigin(0.5, 0); this.pokemonMovesContainer.add(this.pokemonAdditionalMoveCountLabel); this.starterSelectContainer.add(this.pokemonMovesContainer); - this.pokemonEggMovesContainer = this.scene.add.container(102, 85); + this.pokemonEggMovesContainer = globalScene.add.container(102, 85); this.pokemonEggMovesContainer.setScale(0.375); - const eggMovesLabel = addTextObject(this.scene, -46, 0, i18next.t("starterSelectUiHandler:eggMoves"), TextStyle.WINDOW_ALT); + const eggMovesLabel = addTextObject(-46, 0, i18next.t("starterSelectUiHandler:eggMoves"), TextStyle.WINDOW_ALT); eggMovesLabel.setOrigin(0.5, 0); this.pokemonEggMovesContainer.add(eggMovesLabel); for (let m = 0; m < 4; m++) { - const eggMoveContainer = this.scene.add.container(0, 16 + 14 * m); + const eggMoveContainer = globalScene.add.container(0, 16 + 14 * m); - const eggMoveBg = this.scene.add.nineslice(0, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); + const eggMoveBg = globalScene.add.nineslice(0, 0, "type_bgs", "unknown", 92, 14, 2, 2, 2, 2); eggMoveBg.setOrigin(1, 0); - const eggMoveLabel = addTextObject(this.scene, -eggMoveBg.width / 2, 0, "???", TextStyle.PARTY); + const eggMoveLabel = addTextObject(-eggMoveBg.width / 2, 0, "???", TextStyle.PARTY); eggMoveLabel.setOrigin(0.5, 0); this.pokemonEggMoveBgs.push(eggMoveBg); @@ -808,85 +809,85 @@ export default class StarterSelectUiHandler extends MessageUiHandler { // The font size should be set per language const instructionTextSize = textSettings.instructionTextSize; - this.instructionsContainer = this.scene.add.container(4, 156); + this.instructionsContainer = globalScene.add.container(4, 156); this.instructionsContainer.setVisible(true); this.starterSelectContainer.add(this.instructionsContainer); // instruction rows that will be pushed into the container dynamically based on need // creating new sprites since they will be added to the scene later - this.shinyIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "R.png"); + this.shinyIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "R.png"); this.shinyIconElement.setName("sprite-shiny-icon-element"); this.shinyIconElement.setScale(0.675); this.shinyIconElement.setOrigin(0.0, 0.0); - this.shinyLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleShiny"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.shinyLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleShiny"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.shinyLabel.setName("text-shiny-label"); - this.formIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "F.png"); + this.formIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "F.png"); this.formIconElement.setName("sprite-form-icon-element"); this.formIconElement.setScale(0.675); this.formIconElement.setOrigin(0.0, 0.0); - this.formLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleForm"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.formLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleForm"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.formLabel.setName("text-form-label"); - this.genderIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "G.png"); + this.genderIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "G.png"); this.genderIconElement.setName("sprite-gender-icon-element"); this.genderIconElement.setScale(0.675); this.genderIconElement.setOrigin(0.0, 0.0); - this.genderLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleGender"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.genderLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleGender"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.genderLabel.setName("text-gender-label"); - this.abilityIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "E.png"); + this.abilityIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "E.png"); this.abilityIconElement.setName("sprite-ability-icon-element"); this.abilityIconElement.setScale(0.675); this.abilityIconElement.setOrigin(0.0, 0.0); - this.abilityLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleAbility"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.abilityLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleAbility"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.abilityLabel.setName("text-ability-label"); - this.natureIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "N.png"); + this.natureIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "N.png"); this.natureIconElement.setName("sprite-nature-icon-element"); this.natureIconElement.setScale(0.675); this.natureIconElement.setOrigin(0.0, 0.0); - this.natureLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleNature"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.natureLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleNature"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.natureLabel.setName("text-nature-label"); - this.variantIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "V.png"); + this.variantIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "V.png"); this.variantIconElement.setName("sprite-variant-icon-element"); this.variantIconElement.setScale(0.675); this.variantIconElement.setOrigin(0.0, 0.0); - this.variantLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleVariant"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.variantLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleVariant"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.variantLabel.setName("text-variant-label"); - this.goFilterIconElement = new Phaser.GameObjects.Sprite(this.scene, this.filterInstructionRowX, this.filterInstructionRowY, "keyboard", "C.png"); + this.goFilterIconElement = new Phaser.GameObjects.Sprite(globalScene, this.filterInstructionRowX, this.filterInstructionRowY, "keyboard", "C.png"); this.goFilterIconElement.setName("sprite-goFilter-icon-element"); this.goFilterIconElement.setScale(0.675); this.goFilterIconElement.setOrigin(0.0, 0.0); - this.goFilterLabel = addTextObject(this.scene, this.filterInstructionRowX + this.instructionRowTextOffset, this.filterInstructionRowY, i18next.t("starterSelectUiHandler:goFilter"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.goFilterLabel = addTextObject(this.filterInstructionRowX + this.instructionRowTextOffset, this.filterInstructionRowY, i18next.t("starterSelectUiHandler:goFilter"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.goFilterLabel.setName("text-goFilter-label"); this.hideInstructions(); - this.filterInstructionsContainer = this.scene.add.container(50, 5); + this.filterInstructionsContainer = globalScene.add.container(50, 5); this.filterInstructionsContainer.setVisible(true); this.starterSelectContainer.add(this.filterInstructionsContainer); - this.starterSelectMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6); + this.starterSelectMessageBoxContainer = globalScene.add.container(0, globalScene.game.canvas.height / 6); this.starterSelectMessageBoxContainer.setVisible(false); this.starterSelectContainer.add(this.starterSelectMessageBoxContainer); - this.starterSelectMessageBox = addWindow(this.scene, 1, -1, 318, 28); + this.starterSelectMessageBox = addWindow(1, -1, 318, 28); this.starterSelectMessageBox.setOrigin(0, 1); this.starterSelectMessageBoxContainer.add(this.starterSelectMessageBox); - this.message = addTextObject(this.scene, 8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); + this.message = addTextObject(8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); this.message.setOrigin(0, 0); this.starterSelectMessageBoxContainer.add(this.message); // arrow icon for the message box this.initPromptSprite(this.starterSelectMessageBoxContainer); - this.statsContainer = new StatsContainer(this.scene, 6, 16); + this.statsContainer = new StatsContainer(6, 16); - this.scene.add.existing(this.statsContainer); + globalScene.add.existing(this.statsContainer); this.statsContainer.setVisible(false); @@ -894,11 +895,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { // add the info overlay last to be the top most ui element and prevent the IVs from overlaying this const overlayScale = 1; - this.moveInfoOverlay = new MoveInfoOverlay(this.scene, { + this.moveInfoOverlay = new MoveInfoOverlay({ scale: overlayScale, top: true, x: 1, - y: this.scene.game.canvas.height / 6 - MoveInfoOverlay.getHeight(overlayScale) - 29, + y: globalScene.game.canvas.height / 6 - MoveInfoOverlay.getHeight(overlayScale) - 29, }); this.starterSelectContainer.add(this.moveInfoOverlay); @@ -907,7 +908,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.initTutorialOverlay(this.starterSelectContainer); this.starterSelectContainer.bringToTop(this.starterSelectMessageBoxContainer); - this.scene.eventTarget.addEventListener(BattleSceneEventType.CANDY_UPGRADE_NOTIFICATION_CHANGED, (e) => this.onCandyUpgradeDisplayChanged(e)); + globalScene.eventTarget.addEventListener(BattleSceneEventType.CANDY_UPGRADE_NOTIFICATION_CHANGED, (e) => this.onCandyUpgradeDisplayChanged(e)); this.updateInstructions(); } @@ -918,7 +919,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.starterPreferences = StarterPrefs.load(); } this.moveInfoOverlay.clear(); // clear this when removing a menu; the cancel button doesn't seem to trigger this automatically on controllers - this.pokerusSpecies = getPokerusStarters(this.scene); + this.pokerusSpecies = getPokerusStarters(); if (args.length >= 1 && args[0] instanceof Function) { super.show(args); @@ -928,7 +929,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.allSpecies.forEach((species, s) => { const icon = this.starterContainers[s].icon; - const dexEntry = this.scene.gameData.dexData[species.speciesId]; + const dexEntry = globalScene.gameData.dexData[species.speciesId]; // Initialize the StarterAttributes for this species this.starterPreferences[species.speciesId] = this.initStarterPrefs(species); @@ -950,7 +951,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.setCursor(0); this.tryUpdateValue(0); - handleTutorial(this.scene, Tutorial.Starter_Select); + handleTutorial(Tutorial.Starter_Select); return true; } @@ -968,8 +969,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler { */ initStarterPrefs(species: PokemonSpecies): StarterAttributes { const starterAttributes = this.starterPreferences[species.speciesId]; - const dexEntry = this.scene.gameData.dexData[species.speciesId]; - const starterData = this.scene.gameData.starterData[species.speciesId]; + const dexEntry = globalScene.gameData.dexData[species.speciesId]; + const starterData = globalScene.gameData.starterData[species.speciesId]; // no preferences or Pokemon wasn't caught, return empty attribute if (!starterAttributes || !dexEntry.caughtAttr) { @@ -1028,13 +1029,13 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } const selectedForm = starterAttributes.form; - if (selectedForm !== undefined && (!species.forms[selectedForm]?.isStarterSelectable || !(caughtAttr & this.scene.gameData.getFormAttr(selectedForm)))) { + if (selectedForm !== undefined && (!species.forms[selectedForm]?.isStarterSelectable || !(caughtAttr & globalScene.gameData.getFormAttr(selectedForm)))) { // requested form wasn't unlocked/isn't a starter form, purging setting delete starterAttributes.form; } if (starterAttributes.nature !== undefined) { - const unlockedNatures = this.scene.gameData.getNaturesForAttr(dexEntry.natureAttr); + const unlockedNatures = globalScene.gameData.getNaturesForAttr(dexEntry.natureAttr); if (unlockedNatures.indexOf(starterAttributes.nature as unknown as Nature) < 0) { // requested nature wasn't unlocked, purging setting delete starterAttributes.nature; @@ -1073,7 +1074,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.starterSelectMessageBoxContainer.setY(0); this.message.setY(4); } else { - this.starterSelectMessageBoxContainer.setY(this.scene.game.canvas.height / 6); + this.starterSelectMessageBoxContainer.setY(globalScene.game.canvas.height / 6); this.starterSelectMessageBox.setOrigin(0, 1); this.message.setY(singleLine ? -22 : -37); } @@ -1086,14 +1087,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler { * @returns true if upgrade notifications are enabled and set to display an 'Icon' */ isUpgradeIconEnabled(): boolean { - return this.scene.candyUpgradeNotification !== 0 && this.scene.candyUpgradeDisplay === 0; + return globalScene.candyUpgradeNotification !== 0 && globalScene.candyUpgradeDisplay === 0; } /** * Determines if 'Animation' based upgrade notifications should be shown * @returns true if upgrade notifications are enabled and set to display an 'Animation' */ isUpgradeAnimationEnabled(): boolean { - return this.scene.candyUpgradeNotification !== 0 && this.scene.candyUpgradeDisplay === 1; + return globalScene.candyUpgradeNotification !== 0 && globalScene.candyUpgradeDisplay === 1; } /** @@ -1103,7 +1104,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { */ isPassiveAvailable(speciesId: number): boolean { // Get this species ID's starter data - const starterData = this.scene.gameData.starterData[speciesId]; + const starterData = globalScene.gameData.starterData[speciesId]; return starterData.candyCount >= getPassiveCandyCount(speciesStarterCosts[speciesId]) && !(starterData.passiveAttr & PassiveAttr.UNLOCKED); @@ -1116,7 +1117,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { */ isValueReductionAvailable(speciesId: number): boolean { // Get this species ID's starter data - const starterData = this.scene.gameData.starterData[speciesId]; + const starterData = globalScene.gameData.starterData[speciesId]; return starterData.candyCount >= getValueReductionCandyCounts(speciesStarterCosts[speciesId])[starterData.valueReduction] && starterData.valueReduction < valueReductionMax; @@ -1129,7 +1130,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { */ isSameSpeciesEggAvailable(speciesId: number): boolean { // Get this species ID's starter data - const starterData = this.scene.gameData.starterData[speciesId]; + const starterData = globalScene.gameData.starterData[speciesId]; return starterData.candyCount >= getSameSpeciesEggCandyCounts(speciesStarterCosts[speciesId]); } @@ -1141,9 +1142,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler { * @param startPaused Should this animation be paused after it is added? */ setUpgradeAnimation(icon: Phaser.GameObjects.Sprite, species: PokemonSpecies, startPaused: boolean = false): void { - this.scene.tweens.killTweensOf(icon); + globalScene.tweens.killTweensOf(icon); // Skip animations if they are disabled - if (this.scene.candyUpgradeDisplay === 0 || species.speciesId !== species.getRootSpeciesId(false)) { + if (globalScene.candyUpgradeDisplay === 0 || species.speciesId !== species.getRootSpeciesId(false)) { return; } @@ -1177,14 +1178,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const isSameSpeciesEggAvailable = this.isSameSpeciesEggAvailable(species.speciesId); // 'Passives Only' mode - if (this.scene.candyUpgradeNotification === 1) { + if (globalScene.candyUpgradeNotification === 1) { if (isPassiveAvailable) { - this.scene.tweens.chain(tweenChain).paused = startPaused; + globalScene.tweens.chain(tweenChain).paused = startPaused; } // 'On' mode - } else if (this.scene.candyUpgradeNotification === 2) { + } else if (globalScene.candyUpgradeNotification === 2) { if (isPassiveAvailable || isValueReductionAvailable || isSameSpeciesEggAvailable) { - this.scene.tweens.chain(tweenChain).paused = startPaused; + globalScene.tweens.chain(tweenChain).paused = startPaused; } } } @@ -1196,7 +1197,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const species = starter.species; const slotVisible = !!species?.speciesId; - if (!species || this.scene.candyUpgradeNotification === 0 || species.speciesId !== species.getRootSpeciesId(false)) { + if (!species || globalScene.candyUpgradeNotification === 0 || species.speciesId !== species.getRootSpeciesId(false)) { starter.candyUpgradeIcon.setVisible(false); starter.candyUpgradeOverlayIcon.setVisible(false); return; @@ -1207,12 +1208,12 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const isSameSpeciesEggAvailable = this.isSameSpeciesEggAvailable(species.speciesId); // 'Passive Only' mode - if (this.scene.candyUpgradeNotification === 1) { + if (globalScene.candyUpgradeNotification === 1) { starter.candyUpgradeIcon.setVisible(slotVisible && isPassiveAvailable); starter.candyUpgradeOverlayIcon.setVisible(slotVisible && starter.candyUpgradeIcon.visible); // 'On' mode - } else if (this.scene.candyUpgradeNotification === 2) { + } else if (globalScene.candyUpgradeNotification === 2) { starter.candyUpgradeIcon.setVisible( slotVisible && ( isPassiveAvailable || isValueReductionAvailable || isSameSpeciesEggAvailable )); starter.candyUpgradeOverlayIcon.setVisible(slotVisible && starter.candyUpgradeIcon.visible); @@ -1243,7 +1244,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } // Loop through all visible candy icons when set to 'Icon' mode - if (this.scene.candyUpgradeDisplay === 0) { + if (globalScene.candyUpgradeDisplay === 0) { this.filteredStarterContainers.forEach((starter) => { this.setUpgradeIcon(starter); }); @@ -1440,7 +1441,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } else { let starterContainer; - const starterData = this.scene.gameData.starterData[this.lastSpecies.speciesId]; + const starterData = globalScene.gameData.starterData[this.lastSpecies.speciesId]; // prepare persistent starter data to store changes let starterAttributes = this.starterPreferences[this.lastSpecies.speciesId]; @@ -1464,17 +1465,17 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const isPartyValid = this.isPartyValid(); const isValidForChallenge = new BooleanHolder(true); - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, this.lastSpecies, isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)), isPartyValid); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, this.lastSpecies, isValidForChallenge, globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)), isPartyValid); - const currentPartyValue = this.starterSpecies.map(s => s.generation).reduce((total: number, gen: number, i: number) => total += this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0); - const newCost = this.scene.gameData.getSpeciesStarterValue(this.lastSpecies.speciesId); + const currentPartyValue = this.starterSpecies.map(s => s.generation).reduce((total: number, gen: number, i: number) => total += globalScene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0); + const newCost = globalScene.gameData.getSpeciesStarterValue(this.lastSpecies.speciesId); if (!isDupe && isValidForChallenge.value && currentPartyValue + newCost <= this.getValueLimit() && this.starterSpecies.length < PLAYER_PARTY_MAX_SIZE) { // this checks to make sure the pokemon doesn't exist in your party, it's valid for the challenge and that it won't go over the cost limit; if it meets all these criteria it will add it to your party options = [ { label: i18next.t("starterSelectUiHandler:addToParty"), handler: () => { ui.setMode(Mode.STARTER_SELECT); - const isOverValueLimit = this.tryUpdateValue(this.scene.gameData.getSpeciesStarterValue(this.lastSpecies.speciesId), true); + const isOverValueLimit = this.tryUpdateValue(globalScene.gameData.getSpeciesStarterValue(this.lastSpecies.speciesId), true); if (!isDupe && isValidForChallenge.value && isOverValueLimit) { const cursorObj = this.starterCursorObjs[this.starterSpecies.length]; cursorObj.setVisible(true); @@ -1603,11 +1604,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { ui.setMode(Mode.STARTER_SELECT).then(() => { ui.showText(i18next.t("starterSelectUiHandler:selectNature"), null, () => { - const natures = this.scene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr); + const natures = globalScene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr); ui.setModeWithoutClear(Mode.OPTION_SELECT, { options: natures.map((n: Nature, i: number) => { const option: OptionSelectItem = { - label: getNatureName(n, true, true, true, this.scene.uiTheme), + label: getNatureName(n, true, true, true, globalScene.uiTheme), handler: () => { // update default nature in starter save data if (!starterAttributes) { @@ -1745,19 +1746,19 @@ export default class StarterSelectUiHandler extends MessageUiHandler { starterData.candyCount -= passiveCost; } this.pokemonCandyCountText.setText(`x${starterData.candyCount}`); - this.scene.gameData.saveSystem().then(success => { + globalScene.gameData.saveSystem().then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } }); ui.setMode(Mode.STARTER_SELECT); this.setSpeciesDetails(this.lastSpecies); - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); // update the passive background and icon/animation for available upgrade if (starterContainer) { this.updateCandyUpgradeDisplay(starterContainer); - starterContainer.starterPassiveBgs.setVisible(!!this.scene.gameData.starterData[this.lastSpecies.speciesId].passiveAttr); + starterContainer.starterPassiveBgs.setVisible(!!globalScene.gameData.starterData[this.lastSpecies.speciesId].passiveAttr); } return true; } @@ -1781,14 +1782,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler { starterData.candyCount -= reductionCost; } this.pokemonCandyCountText.setText(`x${starterData.candyCount}`); - this.scene.gameData.saveSystem().then(success => { + globalScene.gameData.saveSystem().then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } }); this.tryUpdateValue(0); ui.setMode(Mode.STARTER_SELECT); - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); // update the value label and icon/animation for available upgrade if (starterContainer) { @@ -1810,7 +1811,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { label: `x${sameSpeciesEggCost} ${i18next.t("starterSelectUiHandler:sameSpeciesEgg")}`, handler: () => { if (Overrides.FREE_CANDY_UPGRADE_OVERRIDE || candyCount >= sameSpeciesEggCost) { - if (this.scene.gameData.eggs.length >= 99 && !Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { + if (globalScene.gameData.eggs.length >= 99 && !Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { // Egg list full, show error message at the top of the screen and abort this.showText(i18next.t("egg:tooManyEggs"), undefined, () => this.showText("", 0, () => this.tutorialActive = false), 2000, false, undefined, true); return false; @@ -1820,16 +1821,16 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } this.pokemonCandyCountText.setText(`x${starterData.candyCount}`); - const egg = new Egg({ scene: this.scene, species: this.lastSpecies.speciesId, sourceType: EggSourceType.SAME_SPECIES_EGG }); - egg.addEggToGameData(this.scene); + const egg = new Egg({ species: this.lastSpecies.speciesId, sourceType: EggSourceType.SAME_SPECIES_EGG }); + egg.addEggToGameData(); - this.scene.gameData.saveSystem().then(success => { + globalScene.gameData.saveSystem().then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } }); ui.setMode(Mode.STARTER_SELECT); - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); // update the icon/animation for available upgrade if (starterContainer) { @@ -1878,7 +1879,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { success = true; } } else { - const props = this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)); + const props = globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)); switch (button) { case Button.CYCLE_SHINY: if (this.canCycleShiny) { @@ -1886,11 +1887,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (starterAttributes.shiny) { // Change to shiny, we need to get the proper default variant - const newProps = this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)); + const newProps = globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)); const newVariant = starterAttributes.variant ? starterAttributes.variant as Variant : newProps.variant; this.setSpeciesDetails(this.lastSpecies, { shiny: true, variant: newVariant }); - this.scene.playSound("se/sparkle"); + globalScene.playSound("se/sparkle"); // Set the variant label to the shiny tint const tint = getVariantTint(newVariant); this.pokemonShinyIcon.setFrame(getVariantIcon(newVariant)); @@ -1937,7 +1938,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { let newFormIndex = props.formIndex; do { newFormIndex = (newFormIndex + 1) % formCount; - if (this.lastSpecies.forms[newFormIndex].isStarterSelectable && this.speciesStarterDexEntry!.caughtAttr! & this.scene.gameData.getFormAttr(newFormIndex)) { // TODO: are those bangs correct? + if (this.lastSpecies.forms[newFormIndex].isStarterSelectable && this.speciesStarterDexEntry!.caughtAttr! & globalScene.gameData.getFormAttr(newFormIndex)) { // TODO: are those bangs correct? break; } } while (newFormIndex !== props.formIndex); @@ -1956,7 +1957,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { case Button.CYCLE_ABILITY: if (this.canCycleAbility) { const abilityCount = this.lastSpecies.getAbilityCount(); - const abilityAttr = this.scene.gameData.starterData[this.lastSpecies.speciesId].abilityAttr; + const abilityAttr = globalScene.gameData.starterData[this.lastSpecies.speciesId].abilityAttr; const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1; let newAbilityIndex = this.abilityCursor; do { @@ -1979,11 +1980,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } while (newAbilityIndex !== this.abilityCursor); starterAttributes.ability = newAbilityIndex; // store the selected ability - const { visible: tooltipVisible } = this.scene.ui.getTooltip(); + const { visible: tooltipVisible } = globalScene.ui.getTooltip(); if (tooltipVisible && this.activeTooltip === "ABILITY") { const newAbility = allAbilities[this.lastSpecies.getAbility(newAbilityIndex)]; - this.scene.ui.editTooltip(`${newAbility.name}`, `${newAbility.description}`); + globalScene.ui.editTooltip(`${newAbility.name}`, `${newAbility.description}`); } this.setSpeciesDetails(this.lastSpecies, { abilityIndex: newAbilityIndex }); @@ -1992,7 +1993,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { break; case Button.CYCLE_NATURE: if (this.canCycleNature) { - const natures = this.scene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr); + const natures = globalScene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr); const natureIndex = natures.indexOf(this.natureCursor); const newNature = natures[natureIndex < natures.length - 1 ? natureIndex + 1 : 0]; // store cycled nature as default @@ -2160,7 +2161,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } addToParty(species: PokemonSpecies, dexAttr: bigint, abilityIndex: integer, nature: Nature, moveset: StarterMoveset) { - const props = this.scene.gameData.getSpeciesDexAttrProps(species, dexAttr); + const props = globalScene.gameData.getSpeciesDexAttrProps(species, dexAttr); this.starterIcons[this.starterSpecies.length].setTexture(species.getIconAtlasKey(props.formIndex, props.shiny, props.variant)); this.starterIcons[this.starterSpecies.length].setFrame(species.getIconId(props.female, props.formIndex, props.shiny, props.variant)); this.checkIconId(this.starterIcons[this.starterSpecies.length], species, props.female, props.formIndex, props.shiny, props.variant); @@ -2171,13 +2172,13 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.starterNatures.push(nature); this.starterMovesets.push(moveset); if (this.speciesLoaded.get(species.speciesId)) { - getPokemonSpeciesForm(species.speciesId, props.formIndex).cry(this.scene); + getPokemonSpeciesForm(species.speciesId, props.formIndex).cry(); } this.updateInstructions(); } updatePartyIcon(species: PokemonSpecies, index: number) { - const props = this.scene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)); + const props = globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)); this.starterIcons[index].setTexture(species.getIconAtlasKey(props.formIndex, props.shiny, props.variant)); this.starterIcons[index].setFrame(species.getIconId(props.female, props.formIndex, props.shiny, props.variant)); this.checkIconId(this.starterIcons[index], species, props.female, props.formIndex, props.shiny, props.variant); @@ -2190,29 +2191,29 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (existingMoveIndex > -1) { this.starterMoveset![existingMoveIndex] = move; // TODO: is this bang correct? } - const props: DexAttrProps = this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.dexAttrCursor); + const props: DexAttrProps = globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.dexAttrCursor); // species has different forms if (pokemonFormLevelMoves.hasOwnProperty(speciesId)) { // starterMoveData doesn't have base form moves or is using the single form format - if (!this.scene.gameData.starterData[speciesId].moveset || Array.isArray(this.scene.gameData.starterData[speciesId].moveset)) { - this.scene.gameData.starterData[speciesId].moveset = { [props.formIndex]: this.starterMoveset?.slice(0) as StarterMoveset }; + if (!globalScene.gameData.starterData[speciesId].moveset || Array.isArray(globalScene.gameData.starterData[speciesId].moveset)) { + globalScene.gameData.starterData[speciesId].moveset = { [props.formIndex]: this.starterMoveset?.slice(0) as StarterMoveset }; } - const starterMoveData = this.scene.gameData.starterData[speciesId].moveset; + const starterMoveData = globalScene.gameData.starterData[speciesId].moveset; // starterMoveData doesn't have active form moves if (!starterMoveData.hasOwnProperty(props.formIndex)) { - this.scene.gameData.starterData[speciesId].moveset[props.formIndex] = this.starterMoveset?.slice(0) as StarterMoveset; + globalScene.gameData.starterData[speciesId].moveset[props.formIndex] = this.starterMoveset?.slice(0) as StarterMoveset; } // does the species' starter move data have its form's starter moves and has it been updated if (starterMoveData.hasOwnProperty(props.formIndex)) { // active form move hasn't been updated if (starterMoveData[props.formIndex][existingMoveIndex] !== newMove) { - this.scene.gameData.starterData[speciesId].moveset[props.formIndex] = this.starterMoveset?.slice(0) as StarterMoveset; + globalScene.gameData.starterData[speciesId].moveset[props.formIndex] = this.starterMoveset?.slice(0) as StarterMoveset; } } } else { - this.scene.gameData.starterData[speciesId].moveset = this.starterMoveset?.slice(0) as StarterMoveset; + globalScene.gameData.starterData[speciesId].moveset = this.starterMoveset?.slice(0) as StarterMoveset; } this.setSpeciesDetails(this.lastSpecies, { forSeen: false }); @@ -2259,7 +2260,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { break; } } else { - iconPath = this.scene.inputController?.getIconForLatestInputRecorded(iconSetting); + iconPath = globalScene.inputController?.getIconForLatestInputRecorded(iconSetting); } iconElement.setTexture(gamepadType, iconPath); iconElement.setPosition(this.instructionRowX, this.instructionRowY); @@ -2282,7 +2283,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { gamepadType = "keyboard"; iconPath = "C.png"; } else { - iconPath = this.scene.inputController?.getIconForLatestInputRecorded(iconSetting); + iconPath = globalScene.inputController?.getIconForLatestInputRecorded(iconSetting); } iconElement.setTexture(gamepadType, iconPath); iconElement.setPosition(this.filterInstructionRowX, this.filterInstructionRowY); @@ -2306,10 +2307,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.instructionsContainer.removeAll(); this.filterInstructionsContainer.removeAll(); let gamepadType; - if (this.scene.inputMethod === "gamepad") { - gamepadType = this.scene.inputController.getConfig(this.scene.inputController.selectedDevice[Device.GAMEPAD]).padType; + if (globalScene.inputMethod === "gamepad") { + gamepadType = globalScene.inputController.getConfig(globalScene.inputController.selectedDevice[Device.GAMEPAD]).padType; } else { - gamepadType = this.scene.inputMethod; + gamepadType = globalScene.inputMethod; } if (!gamepadType) { @@ -2346,7 +2347,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { getValueLimit(): number { const valueLimit = new NumberHolder(0); - switch (this.scene.gameMode.modeId) { + switch (globalScene.gameMode.modeId) { case GameModes.ENDLESS: case GameModes.SPLICED_ENDLESS: valueLimit.value = 15; @@ -2355,7 +2356,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { valueLimit.value = 10; } - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_POINTS, valueLimit); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_POINTS, valueLimit); return valueLimit.value; } @@ -2371,7 +2372,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.filterBar.updateFilterLabels(); // pre filter for challenges - if (this.scene.gameMode.modeId === GameModes.CHALLENGE) { + if (globalScene.gameMode.modeId === GameModes.CHALLENGE) { this.starterContainers.forEach(container => { const species = container.species; let allFormsValid = false; @@ -2382,12 +2383,12 @@ export default class StarterSelectUiHandler extends MessageUiHandler { */ const tempFormProps = BigInt(Math.pow(2, i)) * DexAttr.DEFAULT_FORM; const isValidForChallenge = new BooleanHolder(true); - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, container.species, isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(species, tempFormProps), true); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, container.species, isValidForChallenge, globalScene.gameData.getSpeciesDexAttrProps(species, tempFormProps), true); allFormsValid = allFormsValid || isValidForChallenge.value; } } else { const isValidForChallenge = new BooleanHolder(true); - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, container.species, isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(species, this.scene.gameData.getSpeciesDefaultDexAttr(container.species, false, true)), true); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, container.species, isValidForChallenge, globalScene.gameData.getSpeciesDexAttrProps(species, globalScene.gameData.getSpeciesDefaultDexAttr(container.species, false, true)), true); allFormsValid = isValidForChallenge.value; } if (allFormsValid) { @@ -2406,7 +2407,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const starterSprite = currentFilteredContainer.icon as Phaser.GameObjects.Sprite; const currentDexAttr = this.getCurrentDexProps(currentFilteredContainer.species.speciesId); - const props = this.scene.gameData.getSpeciesDexAttrProps(currentFilteredContainer.species, currentDexAttr); + const props = globalScene.gameData.getSpeciesDexAttrProps(currentFilteredContainer.species, currentDexAttr); starterSprite.setTexture(currentFilteredContainer.species.getIconAtlasKey(props.formIndex, props.shiny, props.variant), currentFilteredContainer.species.getIconId(props.female!, props.formIndex, props.shiny, props.variant)); currentFilteredContainer.checkIconId(props.female, props.formIndex, props.shiny, props.variant); @@ -2416,11 +2417,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.validStarterContainers.forEach(container => { container.setVisible(false); - container.cost = this.scene.gameData.getSpeciesStarterValue(container.species.speciesId); + container.cost = globalScene.gameData.getSpeciesStarterValue(container.species.speciesId); // First, ensure you have the caught attributes for the species else default to bigint 0 - const caughtAttr = this.scene.gameData.dexData[container.species.speciesId]?.caughtAttr || BigInt(0); - const starterData = this.scene.gameData.starterData[container.species.speciesId]; + const caughtAttr = globalScene.gameData.dexData[container.species.speciesId]?.caughtAttr || BigInt(0); + const starterData = globalScene.gameData.starterData[container.species.speciesId]; const isStarterProgressable = speciesEggMoves.hasOwnProperty(container.species.speciesId); // Gen filter @@ -2563,12 +2564,12 @@ export default class StarterSelectUiHandler extends MessageUiHandler { case SortCriteria.COST: return (a.cost - b.cost) * -sort.dir; case SortCriteria.CANDY: - const candyCountA = this.scene.gameData.starterData[a.species.speciesId].candyCount; - const candyCountB = this.scene.gameData.starterData[b.species.speciesId].candyCount; + const candyCountA = globalScene.gameData.starterData[a.species.speciesId].candyCount; + const candyCountB = globalScene.gameData.starterData[b.species.speciesId].candyCount; return (candyCountA - candyCountB) * -sort.dir; case SortCriteria.IV: - const avgIVsA = this.scene.gameData.dexData[a.species.speciesId].ivs.reduce((a, b) => a + b, 0) / this.scene.gameData.dexData[a.species.speciesId].ivs.length; - const avgIVsB = this.scene.gameData.dexData[b.species.speciesId].ivs.reduce((a, b) => a + b, 0) / this.scene.gameData.dexData[b.species.speciesId].ivs.length; + const avgIVsA = globalScene.gameData.dexData[a.species.speciesId].ivs.reduce((a, b) => a + b, 0) / globalScene.gameData.dexData[a.species.speciesId].ivs.length; + const avgIVsB = globalScene.gameData.dexData[b.species.speciesId].ivs.reduce((a, b) => a + b, 0) / globalScene.gameData.dexData[b.species.speciesId].ivs.length; return (avgIVsA - avgIVsB) * -sort.dir; case SortCriteria.NAME: return a.species.name.localeCompare(b.species.name) * -sort.dir; @@ -2623,8 +2624,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.updateStarterValueLabel(container); container.label.setVisible(true); - const speciesVariants = speciesId && this.scene.gameData.dexData[speciesId].caughtAttr & DexAttr.SHINY - ? [ DexAttr.DEFAULT_VARIANT, DexAttr.VARIANT_2, DexAttr.VARIANT_3 ].filter(v => !!(this.scene.gameData.dexData[speciesId].caughtAttr & v)) + const speciesVariants = speciesId && globalScene.gameData.dexData[speciesId].caughtAttr & DexAttr.SHINY + ? [ DexAttr.DEFAULT_VARIANT, DexAttr.VARIANT_2, DexAttr.VARIANT_3 ].filter(v => !!(globalScene.gameData.dexData[speciesId].caughtAttr & v)) : []; for (let v = 0; v < 3; v++) { const hasVariant = speciesVariants.length > v; @@ -2634,13 +2635,13 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } } - container.starterPassiveBgs.setVisible(!!this.scene.gameData.starterData[speciesId].passiveAttr); - container.hiddenAbilityIcon.setVisible(!!this.scene.gameData.dexData[speciesId].caughtAttr && !!(this.scene.gameData.starterData[speciesId].abilityAttr & 4)); - container.classicWinIcon.setVisible(this.scene.gameData.starterData[speciesId].classicWinCount > 0); + container.starterPassiveBgs.setVisible(!!globalScene.gameData.starterData[speciesId].passiveAttr); + container.hiddenAbilityIcon.setVisible(!!globalScene.gameData.dexData[speciesId].caughtAttr && !!(globalScene.gameData.starterData[speciesId].abilityAttr & 4)); + container.classicWinIcon.setVisible(globalScene.gameData.starterData[speciesId].classicWinCount > 0); container.favoriteIcon.setVisible(this.starterPreferences[speciesId]?.favorite ?? false); // 'Candy Icon' mode - if (this.scene.candyUpgradeDisplay === 0) { + if (globalScene.candyUpgradeDisplay === 0) { if (!starterColors[speciesId]) { // Default to white if no colors are found @@ -2652,7 +2653,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { container.candyUpgradeOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(starterColors[speciesId][1]))); this.setUpgradeIcon(container); - } else if (this.scene.candyUpgradeDisplay === 1) { + } else if (globalScene.candyUpgradeDisplay === 1) { container.candyUpgradeIcon.setVisible(false); container.candyUpgradeOverlayIcon.setVisible(false); } @@ -2679,7 +2680,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (species) { const defaultDexAttr = this.getCurrentDexProps(species.speciesId); - const defaultProps = this.scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); const variant = this.starterPreferences[species.speciesId]?.variant ? this.starterPreferences[species.speciesId].variant as Variant : defaultProps.variant; const tint = getVariantTint(variant); this.pokemonShinyIcon.setFrame(getVariantIcon(variant)); @@ -2723,7 +2724,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } getFriendship(speciesId: number) { - let currentFriendship = this.scene.gameData.starterData[speciesId].friendship; + let currentFriendship = globalScene.gameData.starterData[speciesId].friendship; if (!currentFriendship || currentFriendship === undefined) { currentFriendship = 0; } @@ -2734,13 +2735,13 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } setSpecies(species: PokemonSpecies | null) { - this.speciesStarterDexEntry = species ? this.scene.gameData.dexData[species.speciesId] : null; + this.speciesStarterDexEntry = species ? globalScene.gameData.dexData[species.speciesId] : null; this.dexAttrCursor = species ? this.getCurrentDexProps(species.speciesId) : 0n; - this.abilityCursor = species ? this.scene.gameData.getStarterSpeciesDefaultAbilityIndex(species) : 0; - this.natureCursor = species ? this.scene.gameData.getSpeciesDefaultNature(species) : 0; + this.abilityCursor = species ? globalScene.gameData.getStarterSpeciesDefaultAbilityIndex(species) : 0; + this.natureCursor = species ? globalScene.gameData.getSpeciesDefaultNature(species) : 0; - if (!species && this.scene.ui.getTooltip().visible) { - this.scene.ui.hideTooltip(); + if (!species && globalScene.ui.getTooltip().visible) { + globalScene.ui.hideTooltip(); } this.pokemonAbilityText.off("pointerover"); @@ -2770,7 +2771,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (this.lastSpecies) { const dexAttr = this.getCurrentDexProps(this.lastSpecies.speciesId); - const props = this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr); + const props = globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr); const speciesIndex = this.allSpecies.indexOf(this.lastSpecies); const lastSpeciesIcon = this.starterContainers[speciesIndex].icon; this.checkIconId(lastSpeciesIcon, this.lastSpecies, props.female, props.formIndex, props.shiny, props.variant); @@ -2778,7 +2779,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { // Resume the animation for the previously selected species const icon = this.starterContainers[speciesIndex].icon; - this.scene.tweens.getTweensOf(icon).forEach(tween => tween.resume()); + globalScene.tweens.getTweensOf(icon).forEach(tween => tween.resume()); } this.lastSpecies = species!; // TODO: is this bang correct? @@ -2795,7 +2796,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (this.speciesStarterDexEntry?.caughtAttr) { const colorScheme = starterColors[species.speciesId]; - const luck = this.scene.gameData.getDexAttrLuck(this.speciesStarterDexEntry.caughtAttr); + const luck = globalScene.gameData.getDexAttrLuck(this.speciesStarterDexEntry.caughtAttr); this.pokemonLuckText.setVisible(!!luck); this.pokemonLuckText.setText(luck.toString()); this.pokemonLuckText.setTint(getVariantTint(Math.min(luck - 1, 2) as Variant)); @@ -2825,7 +2826,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonHatchedCountText.setText(`${this.speciesStarterDexEntry.hatchedCount}`); const defaultDexAttr = this.getCurrentDexProps(species.speciesId); - const defaultProps = this.scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); const variant = defaultProps.variant; const tint = getVariantTint(variant); this.pokemonShinyIcon.setFrame(getVariantIcon(variant)); @@ -2849,7 +2850,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonShinyIcon.setY(117); this.pokemonCandyIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[0]))); this.pokemonCandyOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[1]))); - this.pokemonCandyCountText.setText(`x${this.scene.gameData.starterData[species.speciesId].candyCount}`); + this.pokemonCandyCountText.setText(`x${globalScene.gameData.starterData[species.speciesId].candyCount}`); this.pokemonCandyContainer.setVisible(true); this.pokemonFormText.setY(42); this.pokemonHatchedIcon.setVisible(true); @@ -2860,11 +2861,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonCandyDarknessOverlay.setCrop(0, 0, 16, candyCropY); this.pokemonCandyContainer.on("pointerover", () => { - this.scene.ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true); + globalScene.ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true); this.activeTooltip = "CANDY"; }); this.pokemonCandyContainer.on("pointerout", () => { - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); this.activeTooltip = undefined; }); @@ -2876,7 +2877,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const icon = this.starterContainers[speciesIndex].icon; if (this.isUpgradeAnimationEnabled()) { - this.scene.tweens.getTweensOf(icon).forEach(tween => tween.pause()); + globalScene.tweens.getTweensOf(icon).forEach(tween => tween.pause()); // Reset the position of the icon icon.x = -2; icon.y = 2; @@ -2890,7 +2891,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { let props: DexAttrProps; if (starterIndex > -1) { - props = this.scene.gameData.getSpeciesDexAttrProps(species, this.starterAttr[starterIndex]); + props = globalScene.gameData.getSpeciesDexAttrProps(species, this.starterAttr[starterIndex]); this.setSpeciesDetails(species, { shiny: props.shiny, formIndex: props.formIndex, @@ -2901,10 +2902,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler { }); } else { const defaultDexAttr = this.getCurrentDexProps(species.speciesId); - const defaultAbilityIndex = starterAttributes?.ability ?? this.scene.gameData.getStarterSpeciesDefaultAbilityIndex(species); + const defaultAbilityIndex = starterAttributes?.ability ?? globalScene.gameData.getStarterSpeciesDefaultAbilityIndex(species); // load default nature from stater save data, if set - const defaultNature = starterAttributes?.nature || this.scene.gameData.getSpeciesDefaultNature(species); - props = this.scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const defaultNature = starterAttributes?.nature || globalScene.gameData.getSpeciesDefaultNature(species); + props = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); if (starterAttributes?.variant && !isNaN(starterAttributes.variant)) { if (props.shiny) { props.variant = starterAttributes.variant as Variant; @@ -2928,7 +2929,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonSprite.clearTint(); if (this.pokerusSpecies.includes(species)) { - handleTutorial(this.scene, Tutorial.Pokerus); + handleTutorial(Tutorial.Pokerus); } } else { this.pokemonGrowthRateText.setText(""); @@ -2946,10 +2947,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonCandyContainer.setVisible(false); this.pokemonFormText.setVisible(false); - const defaultDexAttr = this.scene.gameData.getSpeciesDefaultDexAttr(species, true, true); - const defaultAbilityIndex = this.scene.gameData.getStarterSpeciesDefaultAbilityIndex(species); - const defaultNature = this.scene.gameData.getSpeciesDefaultNature(species); - const props = this.scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, true, true); + const defaultAbilityIndex = globalScene.gameData.getStarterSpeciesDefaultAbilityIndex(species); + const defaultNature = globalScene.gameData.getSpeciesDefaultNature(species); + const props = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); this.setSpeciesDetails(species, { shiny: props.shiny, @@ -2995,9 +2996,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler { setSpeciesDetails(species: PokemonSpecies, options: SpeciesDetails = {}): void { let { shiny, formIndex, female, variant, abilityIndex, natureIndex } = options; const forSeen: boolean = options.forSeen ?? false; - const oldProps = species ? this.scene.gameData.getSpeciesDexAttrProps(species, this.dexAttrCursor) : null; - const oldAbilityIndex = this.abilityCursor > -1 ? this.abilityCursor : this.scene.gameData.getStarterSpeciesDefaultAbilityIndex(species); - const oldNatureIndex = this.natureCursor > -1 ? this.natureCursor : this.scene.gameData.getSpeciesDefaultNature(species); + const oldProps = species ? globalScene.gameData.getSpeciesDexAttrProps(species, this.dexAttrCursor) : null; + const oldAbilityIndex = this.abilityCursor > -1 ? this.abilityCursor : globalScene.gameData.getStarterSpeciesDefaultAbilityIndex(species); + const oldNatureIndex = this.natureCursor > -1 ? this.natureCursor : globalScene.gameData.getSpeciesDefaultNature(species); this.dexAttrCursor = 0n; this.abilityCursor = -1; this.natureCursor = -1; @@ -3010,9 +3011,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler { if (this.activeTooltip === "CANDY") { if (this.lastSpecies && this.pokemonCandyContainer.visible) { const { currentFriendship, friendshipCap } = this.getFriendship(this.lastSpecies.speciesId); - this.scene.ui.editTooltip("", `${currentFriendship}/${friendshipCap}`); + globalScene.ui.editTooltip("", `${currentFriendship}/${friendshipCap}`); } else { - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); } } @@ -3028,7 +3029,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.dexAttrCursor |= (shiny !== undefined ? !shiny : !(shiny = oldProps?.shiny)) ? DexAttr.NON_SHINY : DexAttr.SHINY; this.dexAttrCursor |= (female !== undefined ? !female : !(female = oldProps?.female)) ? DexAttr.MALE : DexAttr.FEMALE; this.dexAttrCursor |= (variant !== undefined ? !variant : !(variant = oldProps?.variant)) ? DexAttr.DEFAULT_VARIANT : variant === 1 ? DexAttr.VARIANT_2 : DexAttr.VARIANT_3; - this.dexAttrCursor |= this.scene.gameData.getFormAttr(formIndex !== undefined ? formIndex : (formIndex = oldProps!.formIndex)); // TODO: is this bang correct? + this.dexAttrCursor |= globalScene.gameData.getFormAttr(formIndex !== undefined ? formIndex : (formIndex = oldProps!.formIndex)); // TODO: is this bang correct? this.abilityCursor = abilityIndex !== undefined ? abilityIndex : (abilityIndex = oldAbilityIndex); this.natureCursor = natureIndex !== undefined ? natureIndex : (natureIndex = oldNatureIndex); const [ isInParty, partyIndex ]: [boolean, number] = this.isInParty(species); // we use this to firstly check if the pokemon is in the party, and if so, to get the party index in order to update the icon image @@ -3052,15 +3053,15 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.speciesStarterMoves = []; if (species) { - const dexEntry = this.scene.gameData.dexData[species.speciesId]; - const abilityAttr = this.scene.gameData.starterData[species.speciesId].abilityAttr; + const dexEntry = globalScene.gameData.dexData[species.speciesId]; + const abilityAttr = globalScene.gameData.starterData[species.speciesId].abilityAttr; - const caughtAttr = this.scene.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0); + const caughtAttr = globalScene.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0); if (!dexEntry.caughtAttr) { - const props = this.scene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)); - const defaultAbilityIndex = this.scene.gameData.getStarterSpeciesDefaultAbilityIndex(species); - const defaultNature = this.scene.gameData.getSpeciesDefaultNature(species); + const props = globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)); + const defaultAbilityIndex = globalScene.gameData.getStarterSpeciesDefaultAbilityIndex(species); + const defaultNature = globalScene.gameData.getSpeciesDefaultNature(species); if (shiny === undefined || shiny !== props.shiny) { shiny = props.shiny; @@ -3099,7 +3100,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.assetLoadCancelled = assetLoadCancelled; if (shouldUpdateSprite) { - species.loadAssets(this.scene, female!, formIndex, shiny, variant, true).then(() => { // TODO: is this bang correct? + species.loadAssets(female!, formIndex, shiny, variant, true).then(() => { // TODO: is this bang correct? if (assetLoadCancelled.value) { return; } @@ -3116,7 +3117,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } const isValidForChallenge = new BooleanHolder(true); - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, species, isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(species, this.dexAttrCursor), !!this.starterSpecies.length); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, species, isValidForChallenge, globalScene.gameData.getSpeciesDexAttrProps(species, this.dexAttrCursor), !!this.starterSpecies.length); const currentFilteredContainer = this.filteredStarterContainers.find(p => p.species.speciesId === species.speciesId); if (currentFilteredContainer) { const starterSprite = currentFilteredContainer.icon as Phaser.GameObjects.Sprite; @@ -3153,8 +3154,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.canCycleAbility = [ hasAbility1, hasAbility2, hasHiddenAbility ].filter(a => a).length > 1; this.canCycleForm = species.forms.filter(f => f.isStarterSelectable || !pokemonFormChanges[species.speciesId]?.find(fc => fc.formKey)) - .map((_, f) => dexEntry.caughtAttr & this.scene.gameData.getFormAttr(f)).filter(f => f).length > 1; - this.canCycleNature = this.scene.gameData.getNaturesForAttr(dexEntry.natureAttr).length > 1; + .map((_, f) => dexEntry.caughtAttr & globalScene.gameData.getFormAttr(f)).filter(f => f).length > 1; + this.canCycleNature = globalScene.gameData.getNaturesForAttr(dexEntry.natureAttr).length > 1; } @@ -3175,20 +3176,20 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonAbilityText.setColor(this.getTextColor(!isHidden ? TextStyle.SUMMARY_ALT : TextStyle.SUMMARY_GOLD)); this.pokemonAbilityText.setShadowColor(this.getTextColor(!isHidden ? TextStyle.SUMMARY_ALT : TextStyle.SUMMARY_GOLD, true)); - const passiveAttr = this.scene.gameData.starterData[species.speciesId].passiveAttr; + const passiveAttr = globalScene.gameData.starterData[species.speciesId].passiveAttr; const passiveAbility = allAbilities[starterPassiveAbilities[this.lastSpecies.speciesId]]; if (this.pokemonAbilityText.visible) { if (this.activeTooltip === "ABILITY") { - this.scene.ui.editTooltip(`${ability.name}`, `${ability.description}`); + globalScene.ui.editTooltip(`${ability.name}`, `${ability.description}`); } this.pokemonAbilityText.on("pointerover", () => { - this.scene.ui.showTooltip(`${ability.name}`, `${ability.description}`, true); + globalScene.ui.showTooltip(`${ability.name}`, `${ability.description}`, true); this.activeTooltip = "ABILITY"; }); this.pokemonAbilityText.on("pointerout", () => { - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); this.activeTooltip = undefined; }); } @@ -3210,16 +3211,16 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonPassiveText.setShadowColor(this.getTextColor(textStyle, true)); if (this.activeTooltip === "PASSIVE") { - this.scene.ui.editTooltip(`${passiveAbility.name}`, `${passiveAbility.description}`); + globalScene.ui.editTooltip(`${passiveAbility.name}`, `${passiveAbility.description}`); } if (this.pokemonPassiveText.visible) { this.pokemonPassiveText.on("pointerover", () => { - this.scene.ui.showTooltip(`${passiveAbility.name}`, `${passiveAbility.description}`, true); + globalScene.ui.showTooltip(`${passiveAbility.name}`, `${passiveAbility.description}`, true); this.activeTooltip = "PASSIVE"; }); this.pokemonPassiveText.on("pointerout", () => { - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); this.activeTooltip = undefined; }); } @@ -3235,10 +3236,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } else if (this.activeTooltip === "PASSIVE") { // No passive and passive tooltip is active > hide it - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); } - this.pokemonNatureText.setText(getNatureName(natureIndex as unknown as Nature, true, true, false, this.scene.uiTheme)); + this.pokemonNatureText.setText(getNatureName(natureIndex as unknown as Nature, true, true, false, globalScene.uiTheme)); let levelMoves: LevelMoves; if (pokemonFormLevelMoves.hasOwnProperty(species.speciesId) && formIndex && pokemonFormLevelMoves[species.speciesId].hasOwnProperty(formIndex)) { @@ -3249,19 +3250,19 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.speciesStarterMoves.push(...levelMoves.filter(lm => lm[0] > 0 && lm[0] <= 5).map(lm => lm[1])); if (speciesEggMoves.hasOwnProperty(species.speciesId)) { for (let em = 0; em < 4; em++) { - if (this.scene.gameData.starterData[species.speciesId].eggMoves & (1 << em)) { + if (globalScene.gameData.starterData[species.speciesId].eggMoves & (1 << em)) { this.speciesStarterMoves.push(speciesEggMoves[species.speciesId][em]); } } } - const speciesMoveData = this.scene.gameData.starterData[species.speciesId].moveset; + const speciesMoveData = globalScene.gameData.starterData[species.speciesId].moveset; const moveData: StarterMoveset | null = speciesMoveData ? Array.isArray(speciesMoveData) ? speciesMoveData : speciesMoveData[formIndex!] // TODO: is this bang correct? : null; - const availableStarterMoves = this.speciesStarterMoves.concat(speciesEggMoves.hasOwnProperty(species.speciesId) ? speciesEggMoves[species.speciesId].filter((_, em: integer) => this.scene.gameData.starterData[species.speciesId].eggMoves & (1 << em)) : []); + const availableStarterMoves = this.speciesStarterMoves.concat(speciesEggMoves.hasOwnProperty(species.speciesId) ? speciesEggMoves[species.speciesId].filter((_, em: integer) => globalScene.gameData.starterData[species.speciesId].eggMoves & (1 << em)) : []); this.starterMoveset = (moveData || (this.speciesStarterMoves.slice(0, 4) as StarterMoveset)).filter(m => availableStarterMoves.find(sm => sm === m)) as StarterMoveset; // Consolidate move data if it contains an incompatible move if (this.starterMoveset.length < 4 && this.starterMoveset.length < availableStarterMoves.length) { @@ -3318,7 +3319,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { for (let em = 0; em < 4; em++) { const eggMove = hasEggMoves ? allMoves[speciesEggMoves[species.speciesId][em]] : null; - const eggMoveUnlocked = eggMove && this.scene.gameData.starterData[species.speciesId].eggMoves & (1 << em); + const eggMoveUnlocked = eggMove && globalScene.gameData.starterData[species.speciesId].eggMoves & (1 << em); this.pokemonEggMoveBgs[em].setFrame(Type[eggMove ? eggMove.type : Type.UNKNOWN].toString().toLowerCase()); this.pokemonEggMoveLabels[em].setText(eggMove && eggMoveUnlocked ? eggMove.name : "???"); } @@ -3358,7 +3359,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { for (let s = 0; s < this.starterSpecies.length; s++) { const species = this.starterSpecies[s]; const currentDexAttr = this.getCurrentDexProps(species.speciesId); - const props = this.scene.gameData.getSpeciesDexAttrProps(species, currentDexAttr); + const props = globalScene.gameData.getSpeciesDexAttrProps(species, currentDexAttr); this.starterIcons[s].setTexture(species.getIconAtlasKey(props.formIndex, props.shiny, props.variant)); this.starterIcons[s].setFrame(species.getIconId(props.female, props.formIndex, props.shiny, props.variant)); this.checkIconId(this.starterIcons[s], species, props.female, props.formIndex, props.shiny, props.variant); @@ -3404,7 +3405,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { updateStarterValueLabel(starter: StarterContainer): void { const speciesId = starter.species.speciesId; const baseStarterValue = speciesStarterCosts[speciesId]; - const starterValue = this.scene.gameData.getSpeciesStarterValue(speciesId); + const starterValue = globalScene.gameData.getSpeciesStarterValue(speciesId); starter.cost = starterValue; let valueStr = starterValue.toString(); if (valueStr.startsWith("0.")) { @@ -3431,7 +3432,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } tryUpdateValue(add?: integer, addingToParty?: boolean): boolean { - const value = this.starterSpecies.map(s => s.generation).reduce((total: integer, gen: integer, i: integer) => total += this.scene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0); + const value = this.starterSpecies.map(s => s.generation).reduce((total: integer, gen: integer, i: integer) => total += globalScene.gameData.getSpeciesStarterValue(this.starterSpecies[i].speciesId), 0); const newValue = value + (add || 0); const valueLimit = this.getValueLimit(); const overLimit = newValue > valueLimit; @@ -3443,14 +3444,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.valueLimitLabel.setColor(this.getTextColor(!overLimit ? TextStyle.TOOLTIP_CONTENT : TextStyle.SUMMARY_PINK)); this.valueLimitLabel.setShadowColor(this.getTextColor(!overLimit ? TextStyle.TOOLTIP_CONTENT : TextStyle.SUMMARY_PINK, true)); if (overLimit) { - this.scene.time.delayedCall(fixedInt(500), () => this.tryUpdateValue()); + globalScene.time.delayedCall(fixedInt(500), () => this.tryUpdateValue()); return false; } let isPartyValid: boolean = this.isPartyValid(); // this checks to see if the party is valid if (addingToParty) { // this does a check to see if the pokemon being added is valid; if so, it will update the isPartyValid boolean const isNewPokemonValid = new BooleanHolder(true); const species = this.filteredStarterContainers[this.cursor].species; - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, species, isNewPokemonValid, this.scene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), false); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, species, isNewPokemonValid, globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), false); isPartyValid = isPartyValid || isNewPokemonValid.value; } @@ -3460,7 +3461,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const remainValue = valueLimit - newValue; for (let s = 0; s < this.allSpecies.length; s++) { /** Cost of pokemon species */ - const speciesStarterValue = this.scene.gameData.getSpeciesStarterValue(this.allSpecies[s].speciesId); + const speciesStarterValue = globalScene.gameData.getSpeciesStarterValue(this.allSpecies[s].speciesId); /** {@linkcode Phaser.GameObjects.Sprite} object of Pokémon for setting the alpha value */ const speciesSprite = this.starterContainers[s].icon; @@ -3476,7 +3477,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { * we change to can AddParty value to true since the user has enough cost to choose this pokemon and this pokemon registered too. */ const isValidForChallenge = new BooleanHolder(true); - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, this.allSpecies[s], isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(this.allSpecies[s], this.getCurrentDexProps(this.allSpecies[s].speciesId)), isPartyValid); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, this.allSpecies[s], isValidForChallenge, globalScene.gameData.getSpeciesDexAttrProps(this.allSpecies[s], this.getCurrentDexProps(this.allSpecies[s].speciesId)), isPartyValid); const canBeChosen = remainValue >= speciesStarterValue && isValidForChallenge.value; @@ -3515,15 +3516,15 @@ export default class StarterSelectUiHandler extends MessageUiHandler { ui.showText(i18next.t("starterSelectUiHandler:confirmExit"), null, () => { ui.setModeWithoutClear(Mode.CONFIRM, () => { ui.setMode(Mode.STARTER_SELECT); - this.scene.clearPhaseQueue(); - if (this.scene.gameMode.isChallenge) { - this.scene.pushPhase(new SelectChallengePhase(this.scene)); - this.scene.pushPhase(new EncounterPhase(this.scene, false)); + globalScene.clearPhaseQueue(); + if (globalScene.gameMode.isChallenge) { + globalScene.pushPhase(new SelectChallengePhase()); + globalScene.pushPhase(new EncounterPhase()); } else { - this.scene.pushPhase(new TitlePhase(this.scene)); + globalScene.pushPhase(new TitlePhase()); } this.clearText(); - this.scene.getCurrentPhase()?.end(); + globalScene.getCurrentPhase()?.end(); }, cancel, null, null, 19); }); @@ -3551,7 +3552,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { ui.showText(i18next.t("starterSelectUiHandler:confirmStartTeam"), null, () => { ui.setModeWithoutClear(Mode.CONFIRM, () => { const startRun = () => { - this.scene.money = this.scene.gameMode.getStartingMoney(); + globalScene.money = globalScene.gameMode.getStartingMoney(); ui.setMode(Mode.STARTER_SELECT); const thisObj = this; const originalStarterSelectCallback = this.starterSelectCallback; @@ -3562,7 +3563,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { species: starterSpecies, dexAttr: thisObj.starterAttr[i], abilityIndex: thisObj.starterAbilityIndexes[i], - passive: !(thisObj.scene.gameData.starterData[starterSpecies.speciesId].passiveAttr ^ (PassiveAttr.ENABLED | PassiveAttr.UNLOCKED)), + passive: !(globalScene.gameData.starterData[starterSpecies.speciesId].passiveAttr ^ (PassiveAttr.ENABLED | PassiveAttr.UNLOCKED)), nature: thisObj.starterNatures[i] as Nature, moveset: thisObj.starterMovesets[i], pokerus: thisObj.pokerusSpecies.includes(starterSpecies), @@ -3588,7 +3589,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { for (let s = 0; s < this.starterSpecies.length; s++) { const isValidForChallenge = new BooleanHolder(true); const species = this.starterSpecies[s]; - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, species, isValidForChallenge, this.scene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), false); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_CHOICE, species, isValidForChallenge, globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), false); canStart = canStart || isValidForChallenge.value; } return canStart; @@ -3603,7 +3604,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { */ getCurrentDexProps(speciesId: number): bigint { let props = 0n; - const caughtAttr = this.scene.gameData.dexData[speciesId].caughtAttr; + const caughtAttr = globalScene.gameData.dexData[speciesId].caughtAttr; /* this checks the gender of the pokemon; this works by checking a) that the starter preferences for the species exist, and if so, is it female. If so, it'll add DexAttr.FEMALE to our temp props * It then checks b) if the caughtAttr for the pokemon is female and NOT male - this means that the ONLY gender we've gotten is female, and we need to add DexAttr.FEMALE to our temp props @@ -3641,7 +3642,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.form)) * DexAttr.DEFAULT_FORM; } else { // Get the first unlocked form - props += this.scene.gameData.getFormAttr(this.scene.gameData.getFormIndex(caughtAttr)); + props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr)); } return props; @@ -3703,7 +3704,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.cursor = -1; this.hideInstructions(); this.activeTooltip = undefined; - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); this.starterSelectContainer.setVisible(false); this.blockInput = false; diff --git a/src/ui/stats-container.ts b/src/ui/stats-container.ts index 7e026ede83e2..bbf3146624bc 100644 --- a/src/ui/stats-container.ts +++ b/src/ui/stats-container.ts @@ -1,8 +1,8 @@ import BBCodeText from "phaser3-rex-plugins/plugins/gameobjects/tagtext/bbcodetext/BBCodeText"; -import BattleScene from "../battle-scene"; import { TextStyle, addBBCodeTextObject, addTextObject, getTextColor } from "./text"; import { PERMANENT_STATS, getStatKey } from "#app/enums/stat"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; const ivChartSize = 24; @@ -21,8 +21,8 @@ export class StatsContainer extends Phaser.GameObjects.Container { private ivChart: Phaser.GameObjects.Polygon; private ivStatValueTexts: BBCodeText[]; - constructor(scene: BattleScene, x: number, y: number, showDiff?: boolean) { - super(scene, x, y); + constructor(x: number, y: number, showDiff?: boolean) { + super(globalScene, x, y); this.showDiff = !!showDiff; @@ -32,21 +32,21 @@ export class StatsContainer extends Phaser.GameObjects.Container { setup() { this.setName("stats"); const ivChartBgData = new Array(6).fill(null).map((_, i: integer) => [ ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][0], ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][1] ] ).flat(); - const ivChartBg = this.scene.add.polygon(48, 44, ivChartBgData, 0xd8e0f0, 0.625); + const ivChartBg = globalScene.add.polygon(48, 44, ivChartBgData, 0xd8e0f0, 0.625); ivChartBg.setOrigin(0, 0); - const ivChartBorder = this.scene.add.polygon(ivChartBg.x, ivChartBg.y, ivChartBgData) + const ivChartBorder = globalScene.add.polygon(ivChartBg.x, ivChartBg.y, ivChartBgData) .setStrokeStyle(1, 0x484050); ivChartBorder.setOrigin(0, 0); const ivChartBgLines = [[ 0, -1, 0, 1 ], [ -0.825, -0.5, 0.825, 0.5 ], [ 0.825, -0.5, -0.825, 0.5 ]].map(coords => { - const line = new Phaser.GameObjects.Line(this.scene, ivChartBg.x, ivChartBg.y, ivChartSize * coords[0], ivChartSize * coords[1], ivChartSize * coords[2], ivChartSize * coords[3], 0xffffff) + const line = new Phaser.GameObjects.Line(globalScene, ivChartBg.x, ivChartBg.y, ivChartSize * coords[0], ivChartSize * coords[1], ivChartSize * coords[2], ivChartSize * coords[3], 0xffffff) .setLineWidth(0.5); line.setOrigin(0, 0); return line; }); - this.ivChart = this.scene.add.polygon(ivChartBg.x, ivChartBg.y, defaultIvChartData, 0x98d8a0, 0.75); + this.ivChart = globalScene.add.polygon(ivChartBg.x, ivChartBg.y, defaultIvChartData, 0x98d8a0, 0.75); this.ivChart.setOrigin(0, 0); this.add(ivChartBg); @@ -58,7 +58,6 @@ export class StatsContainer extends Phaser.GameObjects.Container { for (const s of PERMANENT_STATS) { const statLabel = addTextObject( - this.scene, ivChartBg.x + (ivChartSize) * ivChartStatCoordMultipliers[s][0] * 1.325 + (this.showDiff ? 0 : ivLabelOffset[s]), ivChartBg.y + (ivChartSize) * ivChartStatCoordMultipliers[s][1] * 1.325 - 4 + (this.showDiff ? 0 : ivChartLabelyOffset[s]), i18next.t(getStatKey(s)), @@ -66,7 +65,7 @@ export class StatsContainer extends Phaser.GameObjects.Container { ); statLabel.setOrigin(0.5); - this.ivStatValueTexts[s] = addBBCodeTextObject(this.scene, statLabel.x - (this.showDiff ? 0 : ivLabelOffset[s]), statLabel.y + 8, "0", TextStyle.TOOLTIP_CONTENT); + this.ivStatValueTexts[s] = addBBCodeTextObject(statLabel.x - (this.showDiff ? 0 : ivLabelOffset[s]), statLabel.y + 8, "0", TextStyle.TOOLTIP_CONTENT); this.ivStatValueTexts[s].setOrigin(0.5); @@ -79,7 +78,7 @@ export class StatsContainer extends Phaser.GameObjects.Container { if (ivs) { const ivChartData = new Array(6).fill(null).map((_, i) => [ (ivs[ivChartStatIndexes[i]] / 31) * ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][0], (ivs[ivChartStatIndexes[i]] / 31) * ivChartSize * ivChartStatCoordMultipliers[ivChartStatIndexes[i]][1] ] ).flat(); const lastIvChartData = this.statsIvsCache || defaultIvChartData; - const perfectIVColor: string = getTextColor(TextStyle.SUMMARY_GOLD, false, (this.scene as BattleScene).uiTheme); + const perfectIVColor: string = getTextColor(TextStyle.SUMMARY_GOLD, false, globalScene.uiTheme); this.statsIvsCache = ivChartData.slice(0); this.ivStatValueTexts.map((t: BBCodeText, i: integer) => { @@ -93,7 +92,7 @@ export class StatsContainer extends Phaser.GameObjects.Container { } if (this.showDiff && originalIvs) { if (originalIvs[i] < ivs[i]) { - label += ` ([color=${getTextColor(TextStyle.SUMMARY_BLUE, false, (this.scene as BattleScene).uiTheme)}][shadow=${getTextColor(TextStyle.SUMMARY_BLUE, true, (this.scene as BattleScene).uiTheme)}]+${ivs[i] - originalIvs[i]}[/shadow][/color])`; + label += ` ([color=${getTextColor(TextStyle.SUMMARY_BLUE, false, globalScene.uiTheme)}][shadow=${getTextColor(TextStyle.SUMMARY_BLUE, true, globalScene.uiTheme)}]+${ivs[i] - originalIvs[i]}[/shadow][/color])`; } else { label += " (-)"; } @@ -108,7 +107,7 @@ export class StatsContainer extends Phaser.GameObjects.Container { Phaser.Display.Color.IntegerToColor(newColor) ] : null; - this.scene.tweens.addCounter({ + globalScene.tweens.addCounter({ from: 0, to: 1, duration: 1000, diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index 63ef6155fbc0..1149813e9dc7 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -1,4 +1,5 @@ -import BattleScene, { starterColors } from "#app/battle-scene"; +import { starterColors } from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { Mode } from "#app/ui/ui"; import UiHandler from "#app/ui/ui-handler"; import * as Utils from "#app/utils"; @@ -111,177 +112,177 @@ export default class SummaryUiHandler extends UiHandler { private selectedMoveIndex: integer; private selectCallback: Function | null; - constructor(scene: BattleScene) { - super(scene, Mode.SUMMARY); + constructor() { + super(Mode.SUMMARY); } setup() { const ui = this.getUi(); - this.summaryContainer = this.scene.add.container(0, 0); + this.summaryContainer = globalScene.add.container(0, 0); this.summaryContainer.setVisible(false); ui.add(this.summaryContainer); - const summaryBg = this.scene.add.image(0, 0, "summary_bg"); + const summaryBg = globalScene.add.image(0, 0, "summary_bg"); summaryBg.setOrigin(0, 1); this.summaryContainer.add(summaryBg); - this.tabSprite = this.scene.add.sprite(134, (-summaryBg.displayHeight) + 16, "summary_tabs_1"); + this.tabSprite = globalScene.add.sprite(134, (-summaryBg.displayHeight) + 16, "summary_tabs_1"); this.tabSprite.setOrigin(1, 1); this.summaryContainer.add(this.tabSprite); - const summaryLabel = addTextObject(this.scene, 4, -165, i18next.t("pokemonSummary:pokemonInfo"), TextStyle.SUMMARY); + const summaryLabel = addTextObject(4, -165, i18next.t("pokemonSummary:pokemonInfo"), TextStyle.SUMMARY); summaryLabel.setOrigin(0, 1); this.summaryContainer.add(summaryLabel); - this.shinyOverlay = this.scene.add.image(6, -54, "summary_overlay_shiny"); + this.shinyOverlay = globalScene.add.image(6, -54, "summary_overlay_shiny"); this.shinyOverlay.setOrigin(0, 1); this.shinyOverlay.setVisible(false); this.summaryContainer.add(this.shinyOverlay); - this.numberText = addTextObject(this.scene, 17, -149, "0000", TextStyle.SUMMARY); + this.numberText = addTextObject(17, -149, "0000", TextStyle.SUMMARY); this.numberText.setOrigin(0, 1); this.summaryContainer.add(this.numberText); - this.pokemonSprite = this.scene.initPokemonSprite(this.scene.add.sprite(56, -106, "pkmn__sub"), undefined, false, true); + this.pokemonSprite = globalScene.initPokemonSprite(globalScene.add.sprite(56, -106, "pkmn__sub"), undefined, false, true); this.summaryContainer.add(this.pokemonSprite); - this.nameText = addTextObject(this.scene, 6, -54, "", TextStyle.SUMMARY); + this.nameText = addTextObject(6, -54, "", TextStyle.SUMMARY); this.nameText.setOrigin(0, 0); this.summaryContainer.add(this.nameText); - this.splicedIcon = this.scene.add.sprite(0, -54, "icon_spliced"); + this.splicedIcon = globalScene.add.sprite(0, -54, "icon_spliced"); this.splicedIcon.setVisible(false); this.splicedIcon.setOrigin(0, 0); this.splicedIcon.setScale(0.75); this.splicedIcon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 12, 15), Phaser.Geom.Rectangle.Contains); this.summaryContainer.add(this.splicedIcon); - this.shinyIcon = this.scene.add.image(0, -54, "shiny_star"); + this.shinyIcon = globalScene.add.image(0, -54, "shiny_star"); this.shinyIcon.setVisible(false); this.shinyIcon.setOrigin(0, 0); this.shinyIcon.setScale(0.75); this.shinyIcon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 12, 15), Phaser.Geom.Rectangle.Contains); this.summaryContainer.add(this.shinyIcon); - this.fusionShinyIcon = this.scene.add.image(0, 0, "shiny_star_2"); + this.fusionShinyIcon = globalScene.add.image(0, 0, "shiny_star_2"); this.fusionShinyIcon.setVisible(false); this.fusionShinyIcon.setOrigin(0, 0); this.fusionShinyIcon.setScale(0.75); this.summaryContainer.add(this.fusionShinyIcon); - this.pokeball = this.scene.add.sprite(6, -19, "pb"); + this.pokeball = globalScene.add.sprite(6, -19, "pb"); this.pokeball.setOrigin(0, 1); this.summaryContainer.add(this.pokeball); - this.candyIcon = this.scene.add.sprite(13, -140, "candy"); + this.candyIcon = globalScene.add.sprite(13, -140, "candy"); this.candyIcon.setScale(0.8); this.summaryContainer.add(this.candyIcon); - this.candyOverlay = this.scene.add.sprite(13, -140, "candy_overlay"); + this.candyOverlay = globalScene.add.sprite(13, -140, "candy_overlay"); this.candyOverlay.setScale(0.8); this.summaryContainer.add(this.candyOverlay); - this.candyShadow = this.scene.add.sprite(13, -140, "candy"); + this.candyShadow = globalScene.add.sprite(13, -140, "candy"); this.candyShadow.setTint(0x000000); this.candyShadow.setAlpha(0.50); this.candyShadow.setScale(0.8); this.candyShadow.setInteractive(new Phaser.Geom.Rectangle(0, 0, 30, 16), Phaser.Geom.Rectangle.Contains); this.summaryContainer.add(this.candyShadow); - this.candyCountText = addTextObject(this.scene, 20, -146, "x0", TextStyle.WINDOW_ALT, { fontSize: "76px" }); + this.candyCountText = addTextObject(20, -146, "x0", TextStyle.WINDOW_ALT, { fontSize: "76px" }); this.candyCountText.setOrigin(0, 0); this.summaryContainer.add(this.candyCountText); - this.friendshipIcon = this.scene.add.sprite(13, -60, "friendship"); + this.friendshipIcon = globalScene.add.sprite(13, -60, "friendship"); this.friendshipIcon.setScale(0.8); this.summaryContainer.add(this.friendshipIcon); - this.friendshipOverlay = this.scene.add.sprite(13, -60, "friendship_overlay"); + this.friendshipOverlay = globalScene.add.sprite(13, -60, "friendship_overlay"); this.friendshipOverlay.setScale(0.8); this.summaryContainer.add(this.friendshipOverlay); - this.friendshipShadow = this.scene.add.sprite(13, -60, "friendship"); + this.friendshipShadow = globalScene.add.sprite(13, -60, "friendship"); this.friendshipShadow.setTint(0x000000); this.friendshipShadow.setAlpha(0.50); this.friendshipShadow.setScale(0.8); this.friendshipShadow.setInteractive(new Phaser.Geom.Rectangle(0, 0, 50, 16), Phaser.Geom.Rectangle.Contains); this.summaryContainer.add(this.friendshipShadow); - this.friendshipText = addTextObject(this.scene, 20, -66, "x0", TextStyle.WINDOW_ALT, { fontSize: "76px" }); + this.friendshipText = addTextObject(20, -66, "x0", TextStyle.WINDOW_ALT, { fontSize: "76px" }); this.friendshipText.setOrigin(0, 0); this.summaryContainer.add(this.friendshipText); - this.championRibbon = this.scene.add.image(88, -146, "champion_ribbon"); + this.championRibbon = globalScene.add.image(88, -146, "champion_ribbon"); this.championRibbon.setOrigin(0, 0); //this.championRibbon.setScale(0.8); this.championRibbon.setScale(1.25); this.summaryContainer.add(this.championRibbon); this.championRibbon.setVisible(false); - this.levelText = addTextObject(this.scene, 36, -17, "", TextStyle.SUMMARY_ALT); + this.levelText = addTextObject(36, -17, "", TextStyle.SUMMARY_ALT); this.levelText.setOrigin(0, 1); this.summaryContainer.add(this.levelText); - this.genderText = addTextObject(this.scene, 96, -17, "", TextStyle.SUMMARY); + this.genderText = addTextObject(96, -17, "", TextStyle.SUMMARY); this.genderText.setOrigin(0, 1); this.summaryContainer.add(this.genderText); - this.statusContainer = this.scene.add.container(-106, -16); + this.statusContainer = globalScene.add.container(-106, -16); - const statusBg = this.scene.add.image(0, 0, "summary_status"); + const statusBg = globalScene.add.image(0, 0, "summary_status"); statusBg.setOrigin(0, 0); this.statusContainer.add(statusBg); - const statusLabel = addTextObject(this.scene, 3, 0, i18next.t("pokemonSummary:status"), TextStyle.SUMMARY); + const statusLabel = addTextObject(3, 0, i18next.t("pokemonSummary:status"), TextStyle.SUMMARY); statusLabel.setOrigin(0, 0); this.statusContainer.add(statusLabel); - this.status = this.scene.add.sprite(91, 4, Utils.getLocalizedSpriteKey("statuses")); + this.status = globalScene.add.sprite(91, 4, Utils.getLocalizedSpriteKey("statuses")); this.status.setOrigin(0.5, 0); this.statusContainer.add(this.status); this.summaryContainer.add(this.statusContainer); - this.moveEffectContainer = this.scene.add.container(106, -62); + this.moveEffectContainer = globalScene.add.container(106, -62); this.summaryContainer.add(this.moveEffectContainer); - const moveEffectBg = this.scene.add.image(0, 0, "summary_moves_effect"); + const moveEffectBg = globalScene.add.image(0, 0, "summary_moves_effect"); moveEffectBg.setOrigin(0, 0); this.moveEffectContainer.add(moveEffectBg); - const moveEffectLabels = addTextObject(this.scene, 8, 12, i18next.t("pokemonSummary:powerAccuracyCategory"), TextStyle.SUMMARY); + const moveEffectLabels = addTextObject(8, 12, i18next.t("pokemonSummary:powerAccuracyCategory"), TextStyle.SUMMARY); moveEffectLabels.setLineSpacing(9); moveEffectLabels.setOrigin(0, 0); this.moveEffectContainer.add(moveEffectLabels); - this.movePowerText = addTextObject(this.scene, 99, 27, "0", TextStyle.WINDOW_ALT); + this.movePowerText = addTextObject(99, 27, "0", TextStyle.WINDOW_ALT); this.movePowerText.setOrigin(1, 1); this.moveEffectContainer.add(this.movePowerText); - this.moveAccuracyText = addTextObject(this.scene, 99, 43, "0", TextStyle.WINDOW_ALT); + this.moveAccuracyText = addTextObject(99, 43, "0", TextStyle.WINDOW_ALT); this.moveAccuracyText.setOrigin(1, 1); this.moveEffectContainer.add(this.moveAccuracyText); - this.moveCategoryIcon = this.scene.add.sprite(99, 57, "categories"); + this.moveCategoryIcon = globalScene.add.sprite(99, 57, "categories"); this.moveCategoryIcon.setOrigin(1, 1); this.moveEffectContainer.add(this.moveCategoryIcon); const getSummaryPageBg = () => { - const ret = this.scene.add.sprite(0, 0, this.getPageKey(0)); + const ret = globalScene.add.sprite(0, 0, this.getPageKey(0)); ret.setOrigin(0, 1); return ret; }; - this.summaryContainer.add((this.summaryPageContainer = this.scene.add.container(106, 0))); + this.summaryContainer.add((this.summaryPageContainer = globalScene.add.container(106, 0))); this.summaryPageContainer.add(getSummaryPageBg()); this.summaryPageContainer.setVisible(false); - this.summaryContainer.add((this.summaryPageTransitionContainer = this.scene.add.container(106, 0))); + this.summaryContainer.add((this.summaryPageTransitionContainer = globalScene.add.container(106, 0))); this.summaryPageTransitionContainer.add(getSummaryPageBg()); this.summaryPageTransitionContainer.setVisible(false); } @@ -306,7 +307,7 @@ export default class SummaryUiHandler extends UiHandler { this.pokemon = args[0] as PlayerPokemon; this.summaryUiMode = args.length > 1 ? args[1] as SummaryUiMode : SummaryUiMode.DEFAULT; this.playerParty = args[4] ?? true; - this.scene.ui.bringToTop(this.summaryContainer); + globalScene.ui.bringToTop(this.summaryContainer); this.summaryContainer.setVisible(true); this.cursor = -1; @@ -348,17 +349,17 @@ export default class SummaryUiHandler extends UiHandler { this.splicedIcon.setPositionRelative(this.nameText, this.nameText.displayWidth + 2, 3); this.splicedIcon.setVisible(isFusion); if (this.splicedIcon.visible) { - this.splicedIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", `${this.pokemon?.species.getName(this.pokemon.formIndex)}/${this.pokemon?.fusionSpecies?.getName(this.pokemon?.fusionFormIndex)}`, true)); - this.splicedIcon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.splicedIcon.on("pointerover", () => globalScene.ui.showTooltip("", `${this.pokemon?.species.getName(this.pokemon.formIndex)}/${this.pokemon?.fusionSpecies?.getName(this.pokemon?.fusionFormIndex)}`, true)); + this.splicedIcon.on("pointerout", () => globalScene.ui.hideTooltip()); } - if (this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId()].classicWinCount > 0 && this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId(true)].classicWinCount > 0) { + if (globalScene.gameData.starterData[this.pokemon.species.getRootSpeciesId()].classicWinCount > 0 && globalScene.gameData.starterData[this.pokemon.species.getRootSpeciesId(true)].classicWinCount > 0) { this.championRibbon.setVisible(true); } else { this.championRibbon.setVisible(false); } - let currentFriendship = this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId()].friendship; + let currentFriendship = globalScene.gameData.starterData[this.pokemon.species.getRootSpeciesId()].friendship; if (!currentFriendship || currentFriendship === undefined) { currentFriendship = 0; } @@ -367,17 +368,17 @@ export default class SummaryUiHandler extends UiHandler { const candyCropY = 16 - (16 * (currentFriendship / friendshipCap)); if (this.candyShadow.visible) { - this.candyShadow.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true)); - this.candyShadow.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.candyShadow.on("pointerover", () => globalScene.ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true)); + this.candyShadow.on("pointerout", () => globalScene.ui.hideTooltip()); } - this.candyCountText.setText(`x${this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId()].candyCount}`); + this.candyCountText.setText(`x${globalScene.gameData.starterData[this.pokemon.species.getRootSpeciesId()].candyCount}`); this.candyShadow.setCrop(0, 0, 16, candyCropY); if (this.friendshipShadow.visible) { - this.friendshipShadow.on("pointerover", () => this.scene.ui.showTooltip("", `${i18next.t("pokemonSummary:friendship")}`, true)); - this.friendshipShadow.on("pointerout", () => this.scene.ui.hideTooltip()); + this.friendshipShadow.on("pointerover", () => globalScene.ui.showTooltip("", `${i18next.t("pokemonSummary:friendship")}`, true)); + this.friendshipShadow.on("pointerout", () => globalScene.ui.hideTooltip()); } this.friendshipText.setText(`${this.pokemon?.friendship || "0"} / 255`); @@ -395,8 +396,8 @@ export default class SummaryUiHandler extends UiHandler { const shinyDescriptor = doubleShiny || baseVariant ? `${baseVariant === 2 ? i18next.t("common:epicShiny") : baseVariant === 1 ? i18next.t("common:rareShiny") : i18next.t("common:commonShiny")}${doubleShiny ? `/${this.pokemon.fusionVariant === 2 ? i18next.t("common:epicShiny") : this.pokemon.fusionVariant === 1 ? i18next.t("common:rareShiny") : i18next.t("common:commonShiny")}` : ""}` : ""; - this.shinyIcon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip("", `${i18next.t("common:shinyOnHover")}${shinyDescriptor ? ` (${shinyDescriptor})` : ""}`, true)); - this.shinyIcon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + this.shinyIcon.on("pointerover", () => globalScene.ui.showTooltip("", `${i18next.t("common:shinyOnHover")}${shinyDescriptor ? ` (${shinyDescriptor})` : ""}`, true)); + this.shinyIcon.on("pointerout", () => globalScene.ui.hideTooltip()); } this.fusionShinyIcon.setPosition(this.shinyIcon.x, this.shinyIcon.y); @@ -560,7 +561,7 @@ export default class SummaryUiHandler extends UiHandler { break; } const isDown = button === Button.DOWN; - const party = this.scene.getPlayerParty(); + const party = globalScene.getPlayerParty(); const partyMemberIndex = this.pokemon ? party.indexOf(this.pokemon) : -1; if ((isDown && partyMemberIndex < party.length - 1) || (!isDown && partyMemberIndex)) { const page = this.cursor; @@ -621,7 +622,7 @@ export default class SummaryUiHandler extends UiHandler { } if (moveDescriptionLineCount > 3) { - this.descriptionScrollTween = this.scene.tweens.add({ + this.descriptionScrollTween = globalScene.tweens.add({ targets: this.moveDescriptionText, delay: Utils.fixedInt(2000), loop: -1, @@ -632,7 +633,7 @@ export default class SummaryUiHandler extends UiHandler { } if (!this.moveCursorObj) { - this.moveCursorObj = this.scene.add.sprite(-2, 0, "summary_moves_cursor", "highlight"); + this.moveCursorObj = globalScene.add.sprite(-2, 0, "summary_moves_cursor", "highlight"); this.moveCursorObj.setOrigin(0, 1); this.movesContainer.add(this.moveCursorObj); } @@ -643,12 +644,12 @@ export default class SummaryUiHandler extends UiHandler { this.moveCursorBlinkTimer.destroy(); } this.moveCursorObj.setVisible(true); - this.moveCursorBlinkTimer = this.scene.time.addEvent({ + this.moveCursorBlinkTimer = globalScene.time.addEvent({ loop: true, delay: Utils.fixedInt(600), callback: () => { this.moveCursorObj?.setVisible(false); - this.scene.time.delayedCall(Utils.fixedInt(100), () => { + globalScene.time.delayedCall(Utils.fixedInt(100), () => { if (!this.moveCursorObj) { return; } @@ -658,7 +659,7 @@ export default class SummaryUiHandler extends UiHandler { }); if (this.selectedMoveIndex > -1) { if (!this.selectedMoveCursorObj) { - this.selectedMoveCursorObj = this.scene.add.sprite(-2, 0, "summary_moves_cursor", "select"); + this.selectedMoveCursorObj = globalScene.add.sprite(-2, 0, "summary_moves_cursor", "select"); this.selectedMoveCursorObj.setOrigin(0, 1); this.movesContainer.add(this.selectedMoveCursorObj); this.movesContainer.moveBelow(this.selectedMoveCursorObj, this.moveCursorObj); @@ -684,7 +685,7 @@ export default class SummaryUiHandler extends UiHandler { } else { this.populatePageContainer(this.summaryPageContainer); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.summaryPageTransitionContainer, x: forward ? "-=214" : "+=214", duration: 250, @@ -737,27 +738,27 @@ export default class SummaryUiHandler extends UiHandler { switch (page) { case Page.PROFILE: - const profileContainer = this.scene.add.container(0, -pageBg.height); + const profileContainer = globalScene.add.container(0, -pageBg.height); pageContainer.add(profileContainer); // TODO: should add field for original trainer name to Pokemon object, to support gift/traded Pokemon from MEs - const trainerText = addBBCodeTextObject(this.scene, 7, 12, `${i18next.t("pokemonSummary:ot")}/${getBBCodeFrag(loggedInUser?.username || i18next.t("pokemonSummary:unknown"), this.scene.gameData.gender === PlayerGender.FEMALE ? TextStyle.SUMMARY_PINK : TextStyle.SUMMARY_BLUE)}`, TextStyle.SUMMARY_ALT); + const trainerText = addBBCodeTextObject(7, 12, `${i18next.t("pokemonSummary:ot")}/${getBBCodeFrag(loggedInUser?.username || i18next.t("pokemonSummary:unknown"), globalScene.gameData.gender === PlayerGender.FEMALE ? TextStyle.SUMMARY_PINK : TextStyle.SUMMARY_BLUE)}`, TextStyle.SUMMARY_ALT); trainerText.setOrigin(0, 0); profileContainer.add(trainerText); - const trainerIdText = addTextObject(this.scene, 174, 12, this.scene.gameData.trainerId.toString(), TextStyle.SUMMARY_ALT); + const trainerIdText = addTextObject(174, 12, globalScene.gameData.trainerId.toString(), TextStyle.SUMMARY_ALT); trainerIdText.setOrigin(0, 0); profileContainer.add(trainerIdText); - const typeLabel = addTextObject(this.scene, 7, 28, `${i18next.t("pokemonSummary:type")}/`, TextStyle.WINDOW_ALT); + const typeLabel = addTextObject(7, 28, `${i18next.t("pokemonSummary:type")}/`, TextStyle.WINDOW_ALT); typeLabel.setOrigin(0, 0); profileContainer.add(typeLabel); const getTypeIcon = (index: integer, type: Type, tera: boolean = false) => { const xCoord = typeLabel.width * typeLabel.scale + 9 + 34 * index; const typeIcon = !tera - ? this.scene.add.sprite(xCoord, 42, Utils.getLocalizedSpriteKey("types"), Type[type].toLowerCase()) - : this.scene.add.sprite(xCoord, 42, "type_tera"); + ? globalScene.add.sprite(xCoord, 42, Utils.getLocalizedSpriteKey("types"), Type[type].toLowerCase()) + : globalScene.add.sprite(xCoord, 42, "type_tera"); if (tera) { typeIcon.setScale(0.5); const typeRgb = getTypeRgb(type); @@ -777,18 +778,18 @@ export default class SummaryUiHandler extends UiHandler { } if (this.pokemon?.getLuck()) { - const luckLabelText = addTextObject(this.scene, 141, 28, i18next.t("common:luckIndicator"), TextStyle.SUMMARY_ALT); + const luckLabelText = addTextObject(141, 28, i18next.t("common:luckIndicator"), TextStyle.SUMMARY_ALT); luckLabelText.setOrigin(0, 0); profileContainer.add(luckLabelText); - const luckText = addTextObject(this.scene, 141 + luckLabelText.displayWidth + 2, 28, this.pokemon.getLuck().toString(), TextStyle.SUMMARY); + const luckText = addTextObject(141 + luckLabelText.displayWidth + 2, 28, this.pokemon.getLuck().toString(), TextStyle.SUMMARY); luckText.setOrigin(0, 0); luckText.setTint(getVariantTint((Math.min(this.pokemon.getLuck() - 1, 2)) as Variant)); profileContainer.add(luckText); } this.abilityContainer = { - labelImage: this.scene.add.image(0, 0, "summary_profile_ability"), + labelImage: globalScene.add.image(0, 0, "summary_profile_ability"), ability: this.pokemon?.getAbility(true)!, // TODO: is this bang correct? nameText: null, descriptionText: null }; @@ -797,14 +798,14 @@ export default class SummaryUiHandler extends UiHandler { // Only add to the array and set up displaying a passive if it's unlocked if (this.pokemon?.hasPassive()) { this.passiveContainer = { - labelImage: this.scene.add.image(0, 0, "summary_profile_passive"), + labelImage: globalScene.add.image(0, 0, "summary_profile_passive"), ability: this.pokemon.getPassiveAbility(), nameText: null, descriptionText: null }; allAbilityInfo.push(this.passiveContainer); // Sets up the pixel button prompt image - this.abilityPrompt = this.scene.add.image(0, 0, !this.scene.inputController?.gamepadSupport ? "summary_profile_prompt_z" : "summary_profile_prompt_a"); + this.abilityPrompt = globalScene.add.image(0, 0, !globalScene.inputController?.gamepadSupport ? "summary_profile_prompt_z" : "summary_profile_prompt_a"); this.abilityPrompt.setPosition(8, 43); this.abilityPrompt.setVisible(true); this.abilityPrompt.setOrigin(0, 0); @@ -817,16 +818,16 @@ export default class SummaryUiHandler extends UiHandler { abilityInfo.labelImage.setOrigin(0, 0); profileContainer.add(abilityInfo.labelImage); - abilityInfo.nameText = addTextObject(this.scene, 7, 66, abilityInfo.ability?.name!, TextStyle.SUMMARY_ALT); // TODO: is this bang correct? + abilityInfo.nameText = addTextObject(7, 66, abilityInfo.ability?.name!, TextStyle.SUMMARY_ALT); // TODO: is this bang correct? abilityInfo.nameText.setOrigin(0, 1); profileContainer.add(abilityInfo.nameText); - abilityInfo.descriptionText = addTextObject(this.scene, 7, 69, abilityInfo.ability?.description!, TextStyle.WINDOW_ALT, { wordWrap: { width: 1224 }}); // TODO: is this bang correct? + abilityInfo.descriptionText = addTextObject(7, 69, abilityInfo.ability?.description!, TextStyle.WINDOW_ALT, { wordWrap: { width: 1224 }}); // TODO: is this bang correct? abilityInfo.descriptionText.setOrigin(0, 0); profileContainer.add(abilityInfo.descriptionText); // Sets up the mask that hides the description text to give an illusion of scrolling - const descriptionTextMaskRect = this.scene.make.graphics({}); + const descriptionTextMaskRect = globalScene.make.graphics({}); descriptionTextMaskRect.setScale(6); descriptionTextMaskRect.fillStyle(0xFFFFFF); descriptionTextMaskRect.beginPath(); @@ -841,7 +842,7 @@ export default class SummaryUiHandler extends UiHandler { // Animates the description text moving upwards if (abilityDescriptionLineCount > 2) { abilityInfo.descriptionText.setY(69); - this.descriptionScrollTween = this.scene.tweens.add({ + this.descriptionScrollTween = globalScene.tweens.add({ targets: abilityInfo.descriptionText, delay: Utils.fixedInt(2000), loop: -1, @@ -869,12 +870,12 @@ export default class SummaryUiHandler extends UiHandler { natureFragment: i18next.t(`pokemonSummary:natureFragment.${rawNature}`, { nature: nature }) }); - const memoText = addBBCodeTextObject(this.scene, 7, 113, String(memoString), TextStyle.WINDOW_ALT); + const memoText = addBBCodeTextObject(7, 113, String(memoString), TextStyle.WINDOW_ALT); memoText.setOrigin(0, 0); profileContainer.add(memoText); break; case Page.STATS: - const statsContainer = this.scene.add.container(0, -pageBg.height); + const statsContainer = globalScene.add.container(0, -pageBg.height); pageContainer.add(statsContainer); PERMANENT_STATS.forEach((stat, s) => { @@ -884,7 +885,7 @@ export default class SummaryUiHandler extends UiHandler { const natureStatMultiplier = getNatureStatMultiplier(this.pokemon?.getNature()!, s); // TODO: is this bang correct? - const statLabel = addTextObject(this.scene, 27 + 115 * colIndex + (colIndex === 1 ? 5 : 0), 56 + 16 * rowIndex, statName, natureStatMultiplier === 1 ? TextStyle.SUMMARY : natureStatMultiplier > 1 ? TextStyle.SUMMARY_PINK : TextStyle.SUMMARY_BLUE); + const statLabel = addTextObject(27 + 115 * colIndex + (colIndex === 1 ? 5 : 0), 56 + 16 * rowIndex, statName, natureStatMultiplier === 1 ? TextStyle.SUMMARY : natureStatMultiplier > 1 ? TextStyle.SUMMARY_PINK : TextStyle.SUMMARY_BLUE); statLabel.setOrigin(0.5, 0); statsContainer.add(statLabel); @@ -892,24 +893,24 @@ export default class SummaryUiHandler extends UiHandler { ? Utils.formatStat(this.pokemon?.getStat(stat)!) // TODO: is this bang correct? : `${Utils.formatStat(this.pokemon?.hp!, true)}/${Utils.formatStat(this.pokemon?.getMaxHp()!, true)}`; // TODO: are those bangs correct? - const statValue = addTextObject(this.scene, 120 + 88 * colIndex, 56 + 16 * rowIndex, statValueText, TextStyle.WINDOW_ALT); + const statValue = addTextObject(120 + 88 * colIndex, 56 + 16 * rowIndex, statValueText, TextStyle.WINDOW_ALT); statValue.setOrigin(1, 0); statsContainer.add(statValue); }); - const itemModifiers = (this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier + const itemModifiers = (globalScene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.pokemonId === this.pokemon?.id, this.playerParty) as PokemonHeldItemModifier[]) .sort(modifierSortFunc); itemModifiers.forEach((item, i) => { - const icon = item.getIcon(this.scene, true); + const icon = item.getIcon(true); icon.setPosition((i % 17) * 12 + 3, 14 * Math.floor(i / 17) + 15); statsContainer.add(icon); icon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 32, 32), Phaser.Geom.Rectangle.Contains); - icon.on("pointerover", () => (this.scene as BattleScene).ui.showTooltip(item.type.name, item.type.getDescription(this.scene), true)); - icon.on("pointerout", () => (this.scene as BattleScene).ui.hideTooltip()); + icon.on("pointerover", () => globalScene.ui.showTooltip(item.type.name, item.type.getDescription(), true)); + icon.on("pointerout", () => globalScene.ui.hideTooltip()); }); const pkmLvl = this.pokemon?.level!; // TODO: is this bang correct? @@ -917,32 +918,32 @@ export default class SummaryUiHandler extends UiHandler { const pkmExp = this.pokemon?.exp!; // TODO: is this bang correct? const pkmSpeciesGrowthRate = this.pokemon?.species.growthRate!; // TODO: is this bang correct? const relLvExp = getLevelRelExp(pkmLvl + 1, pkmSpeciesGrowthRate); - const expRatio = pkmLvl < this.scene.getMaxExpLevel() ? pkmLvlExp / relLvExp : 0; + const expRatio = pkmLvl < globalScene.getMaxExpLevel() ? pkmLvlExp / relLvExp : 0; - const expLabel = addTextObject(this.scene, 6, 112, i18next.t("pokemonSummary:expPoints"), TextStyle.SUMMARY); + const expLabel = addTextObject(6, 112, i18next.t("pokemonSummary:expPoints"), TextStyle.SUMMARY); expLabel.setOrigin(0, 0); statsContainer.add(expLabel); - const nextLvExpLabel = addTextObject(this.scene, 6, 128, i18next.t("pokemonSummary:nextLv"), TextStyle.SUMMARY); + const nextLvExpLabel = addTextObject(6, 128, i18next.t("pokemonSummary:nextLv"), TextStyle.SUMMARY); nextLvExpLabel.setOrigin(0, 0); statsContainer.add(nextLvExpLabel); - const expText = addTextObject(this.scene, 208, 112, pkmExp.toString(), TextStyle.WINDOW_ALT); + const expText = addTextObject(208, 112, pkmExp.toString(), TextStyle.WINDOW_ALT); expText.setOrigin(1, 0); statsContainer.add(expText); - const nextLvExp = pkmLvl < this.scene.getMaxExpLevel() + const nextLvExp = pkmLvl < globalScene.getMaxExpLevel() ? getLevelTotalExp(pkmLvl + 1, pkmSpeciesGrowthRate) - pkmExp : 0; - const nextLvExpText = addTextObject(this.scene, 208, 128, nextLvExp.toString(), TextStyle.WINDOW_ALT); + const nextLvExpText = addTextObject(208, 128, nextLvExp.toString(), TextStyle.WINDOW_ALT); nextLvExpText.setOrigin(1, 0); statsContainer.add(nextLvExpText); - const expOverlay = this.scene.add.image(140, 145, "summary_stats_overlay_exp"); + const expOverlay = globalScene.add.image(140, 145, "summary_stats_overlay_exp"); expOverlay.setOrigin(0, 0); statsContainer.add(expOverlay); - const expMaskRect = this.scene.make.graphics({}); + const expMaskRect = globalScene.make.graphics({}); expMaskRect.setScale(6); expMaskRect.fillStyle(0xFFFFFF); expMaskRect.beginPath(); @@ -953,18 +954,18 @@ export default class SummaryUiHandler extends UiHandler { expOverlay.setMask(expMask); break; case Page.MOVES: - this.movesContainer = this.scene.add.container(5, -pageBg.height + 26); + this.movesContainer = globalScene.add.container(5, -pageBg.height + 26); pageContainer.add(this.movesContainer); - this.extraMoveRowContainer = this.scene.add.container(0, 64); + this.extraMoveRowContainer = globalScene.add.container(0, 64); this.extraMoveRowContainer.setVisible(false); this.movesContainer.add(this.extraMoveRowContainer); - const extraRowOverlay = this.scene.add.image(-2, 1, "summary_moves_overlay_row"); + const extraRowOverlay = globalScene.add.image(-2, 1, "summary_moves_overlay_row"); extraRowOverlay.setOrigin(0, 1); this.extraMoveRowContainer.add(extraRowOverlay); - const extraRowText = addTextObject(this.scene, 35, 0, this.summaryUiMode === SummaryUiMode.LEARN_MOVE && this.newMove ? this.newMove.name : i18next.t("pokemonSummary:cancel"), + const extraRowText = addTextObject(35, 0, this.summaryUiMode === SummaryUiMode.LEARN_MOVE && this.newMove ? this.newMove.name : i18next.t("pokemonSummary:cancel"), this.summaryUiMode === SummaryUiMode.LEARN_MOVE ? TextStyle.SUMMARY_PINK : TextStyle.SUMMARY); extraRowText.setOrigin(0, 1); this.extraMoveRowContainer.add(extraRowText); @@ -975,45 +976,45 @@ export default class SummaryUiHandler extends UiHandler { if (this.newMove && this.pokemon) { const spriteKey = Utils.getLocalizedSpriteKey("types"); const moveType = this.pokemon.getMoveType(this.newMove); - const newMoveTypeIcon = this.scene.add.sprite(0, 0, spriteKey, Type[moveType].toLowerCase()); + const newMoveTypeIcon = globalScene.add.sprite(0, 0, spriteKey, Type[moveType].toLowerCase()); newMoveTypeIcon.setOrigin(0, 1); this.extraMoveRowContainer.add(newMoveTypeIcon); } - const ppOverlay = this.scene.add.image(163, -1, "summary_moves_overlay_pp"); + const ppOverlay = globalScene.add.image(163, -1, "summary_moves_overlay_pp"); ppOverlay.setOrigin(0, 1); this.extraMoveRowContainer.add(ppOverlay); const pp = Utils.padInt(this.newMove?.pp!, 2, " "); // TODO: is this bang correct? - const ppText = addTextObject(this.scene, 173, 1, `${pp}/${pp}`, TextStyle.WINDOW); + const ppText = addTextObject(173, 1, `${pp}/${pp}`, TextStyle.WINDOW); ppText.setOrigin(0, 1); this.extraMoveRowContainer.add(ppText); } - this.moveRowsContainer = this.scene.add.container(0, 0); + this.moveRowsContainer = globalScene.add.container(0, 0); this.movesContainer.add(this.moveRowsContainer); for (let m = 0; m < 4; m++) { const move: PokemonMove | null = this.pokemon && this.pokemon.moveset.length > m ? this.pokemon?.moveset[m] : null; - const moveRowContainer = this.scene.add.container(0, 16 * m); + const moveRowContainer = globalScene.add.container(0, 16 * m); this.moveRowsContainer.add(moveRowContainer); if (move && this.pokemon) { const spriteKey = Utils.getLocalizedSpriteKey("types"); const moveType = this.pokemon.getMoveType(move.getMove()); - const typeIcon = this.scene.add.sprite(0, 0, spriteKey, Type[moveType].toLowerCase()); + const typeIcon = globalScene.add.sprite(0, 0, spriteKey, Type[moveType].toLowerCase()); typeIcon.setOrigin(0, 1); moveRowContainer.add(typeIcon); } - const moveText = addTextObject(this.scene, 35, 0, move ? move.getName() : "-", TextStyle.SUMMARY); + const moveText = addTextObject(35, 0, move ? move.getName() : "-", TextStyle.SUMMARY); moveText.setOrigin(0, 1); moveRowContainer.add(moveText); - const ppOverlay = this.scene.add.image(163, -1, "summary_moves_overlay_pp"); + const ppOverlay = globalScene.add.image(163, -1, "summary_moves_overlay_pp"); ppOverlay.setOrigin(0, 1); moveRowContainer.add(ppOverlay); - const ppText = addTextObject(this.scene, 173, 1, "--/--", TextStyle.WINDOW); + const ppText = addTextObject(173, 1, "--/--", TextStyle.WINDOW); ppText.setOrigin(0, 1); if (move) { @@ -1025,10 +1026,10 @@ export default class SummaryUiHandler extends UiHandler { moveRowContainer.add(ppText); } - this.moveDescriptionText = addTextObject(this.scene, 2, 84, "", TextStyle.WINDOW_ALT, { wordWrap: { width: 1212 }}); + this.moveDescriptionText = addTextObject(2, 84, "", TextStyle.WINDOW_ALT, { wordWrap: { width: 1212 }}); this.movesContainer.add(this.moveDescriptionText); - const moveDescriptionTextMaskRect = this.scene.make.graphics({}); + const moveDescriptionTextMaskRect = globalScene.make.graphics({}); moveDescriptionTextMaskRect.setScale(6); moveDescriptionTextMaskRect.fillStyle(0xFFFFFF); moveDescriptionTextMaskRect.beginPath(); @@ -1046,7 +1047,7 @@ export default class SummaryUiHandler extends UiHandler { return; } this.statusVisible = true; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.statusContainer, x: 0, duration: instant ? 0 : 250, @@ -1059,7 +1060,7 @@ export default class SummaryUiHandler extends UiHandler { return; } this.statusVisible = false; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.statusContainer, x: -106, duration: instant ? 0 : 250, @@ -1122,7 +1123,7 @@ export default class SummaryUiHandler extends UiHandler { return; } this.moveEffectsVisible = true; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.moveEffectContainer, x: 6, duration: instant ? 0 : 250, @@ -1135,7 +1136,7 @@ export default class SummaryUiHandler extends UiHandler { return; } this.moveEffectsVisible = false; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.moveEffectContainer, x: 106, duration: instant ? 0 : 250, diff --git a/src/ui/target-select-ui-handler.ts b/src/ui/target-select-ui-handler.ts index 249ae7b8b015..0d240d7f22d8 100644 --- a/src/ui/target-select-ui-handler.ts +++ b/src/ui/target-select-ui-handler.ts @@ -1,5 +1,4 @@ import { BattlerIndex } from "../battle"; -import BattleScene from "../battle-scene"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; import * as Utils from "../utils"; @@ -9,6 +8,7 @@ import { Moves } from "#enums/moves"; import Pokemon from "#app/field/pokemon"; import { ModifierBar } from "#app/modifier/modifier"; import { SubstituteTag } from "#app/data/battler-tags"; +import { globalScene } from "#app/global-scene"; export type TargetSelectCallback = (targets: BattlerIndex[]) => void; @@ -26,8 +26,8 @@ export default class TargetSelectUiHandler extends UiHandler { private enemyModifiers: ModifierBar; private targetBattleInfoMoveTween: Phaser.Tweens.Tween[] = []; - constructor(scene: BattleScene) { - super(scene, Mode.TARGET_SELECT); + constructor() { + super(Mode.TARGET_SELECT); this.cursor = -1; } @@ -44,7 +44,7 @@ export default class TargetSelectUiHandler extends UiHandler { this.fieldIndex = args[0] as integer; this.move = args[1] as Moves; this.targetSelectCallback = args[2] as TargetSelectCallback; - const user = this.scene.getPlayerField()[this.fieldIndex]; + const user = globalScene.getPlayerField()[this.fieldIndex]; const moveTargets = getMoveTargets(user, this.move); this.targets = moveTargets.targets; @@ -54,7 +54,7 @@ export default class TargetSelectUiHandler extends UiHandler { return false; } - this.enemyModifiers = this.scene.getModifierBar(true); + this.enemyModifiers = globalScene.getModifierBar(true); if (this.fieldIndex === BattlerIndex.PLAYER) { this.resetCursor(this.cursor0, user); @@ -132,8 +132,8 @@ export default class TargetSelectUiHandler extends UiHandler { } setCursor(cursor: integer): boolean { - const singleTarget = this.scene.getField()[cursor]; - const multipleTargets = this.targets.map(index => this.scene.getField()[index]); + const singleTarget = globalScene.getField()[cursor]; + const multipleTargets = this.targets.map(index => globalScene.getField()[index]); this.targetsHighlighted = this.isMultipleTargets ? multipleTargets : [ singleTarget ]; @@ -147,7 +147,7 @@ export default class TargetSelectUiHandler extends UiHandler { } } - this.targetFlashTween = this.scene.tweens.add({ + this.targetFlashTween = globalScene.tweens.add({ targets: this.targetsHighlighted, key: { start: 1, to: 0.25 }, loop: -1, @@ -173,7 +173,7 @@ export default class TargetSelectUiHandler extends UiHandler { const targetsBattleInfo = this.targetsHighlighted.map(target => target.getBattleInfo()); targetsBattleInfo.map(info => { - this.targetBattleInfoMoveTween.push(this.scene.tweens.add({ + this.targetBattleInfoMoveTween.push(globalScene.tweens.add({ targets: [ info ], y: { start: info.getBaseY(), to: info.getBaseY() + 1 }, loop: -1, diff --git a/src/ui/test-dialogue-ui-handler.ts b/src/ui/test-dialogue-ui-handler.ts index bf0e7f6723f0..c799707f3f48 100644 --- a/src/ui/test-dialogue-ui-handler.ts +++ b/src/ui/test-dialogue-ui-handler.ts @@ -10,8 +10,8 @@ export default class TestDialogueUiHandler extends FormModalUiHandler { keys: string[]; - constructor(scene, mode) { - super(scene, mode); + constructor(mode) { + super(mode); } setup() { diff --git a/src/ui/text.ts b/src/ui/text.ts index 17ae02be9eff..461556c9e856 100644 --- a/src/ui/text.ts +++ b/src/ui/text.ts @@ -3,7 +3,7 @@ import { UiTheme } from "#enums/ui-theme"; import Phaser from "phaser"; import BBCodeText from "phaser3-rex-plugins/plugins/gameobjects/tagtext/bbcodetext/BBCodeText"; import InputText from "phaser3-rex-plugins/plugins/inputtext"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { ModifierTier } from "../modifier/modifier-tier"; import i18next from "#app/plugins/i18n"; @@ -52,10 +52,10 @@ export interface TextStyleOptions { shadowYpos: number } -export function addTextObject(scene: Phaser.Scene, x: number, y: number, content: string, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): Phaser.GameObjects.Text { - const { scale, styleOptions, shadowColor, shadowXpos, shadowYpos } = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions); +export function addTextObject(x: number, y: number, content: string, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): Phaser.GameObjects.Text { + const { scale, styleOptions, shadowColor, shadowXpos, shadowYpos } = getTextStyleOptions(style, globalScene.uiTheme, extraStyleOptions); - const ret = scene.add.text(x, y, content, styleOptions); + const ret = globalScene.add.text(x, y, content, styleOptions); ret.setScale(scale); ret.setShadow(shadowXpos, shadowYpos, shadowColor); if (!(styleOptions as Phaser.Types.GameObjects.Text.TextStyle).lineSpacing) { @@ -69,8 +69,8 @@ export function addTextObject(scene: Phaser.Scene, x: number, y: number, content return ret; } -export function setTextStyle(obj: Phaser.GameObjects.Text, scene: Phaser.Scene, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle) { - const { scale, styleOptions, shadowColor, shadowXpos, shadowYpos } = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions); +export function setTextStyle(obj: Phaser.GameObjects.Text, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle) { + const { scale, styleOptions, shadowColor, shadowXpos, shadowYpos } = getTextStyleOptions(style, globalScene.uiTheme, extraStyleOptions); obj.setScale(scale); obj.setShadow(shadowXpos, shadowYpos, shadowColor); if (!(styleOptions as Phaser.Types.GameObjects.Text.TextStyle).lineSpacing) { @@ -82,11 +82,11 @@ export function setTextStyle(obj: Phaser.GameObjects.Text, scene: Phaser.Scene, } } -export function addBBCodeTextObject(scene: Phaser.Scene, x: number, y: number, content: string, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): BBCodeText { - const { scale, styleOptions, shadowColor, shadowXpos, shadowYpos } = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions); +export function addBBCodeTextObject(x: number, y: number, content: string, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): BBCodeText { + const { scale, styleOptions, shadowColor, shadowXpos, shadowYpos } = getTextStyleOptions(style, globalScene.uiTheme, extraStyleOptions); - const ret = new BBCodeText(scene, x, y, content, styleOptions as BBCodeText.TextStyle); - scene.add.existing(ret); + const ret = new BBCodeText(globalScene, x, y, content, styleOptions as BBCodeText.TextStyle); + globalScene.add.existing(ret); ret.setScale(scale); ret.setShadow(shadowXpos, shadowYpos, shadowColor); if (!(styleOptions as BBCodeText.TextStyle).lineSpacing) { @@ -100,11 +100,11 @@ export function addBBCodeTextObject(scene: Phaser.Scene, x: number, y: number, c return ret; } -export function addTextInputObject(scene: Phaser.Scene, x: number, y: number, width: number, height: number, style: TextStyle, extraStyleOptions?: InputText.IConfig): InputText { - const { scale, styleOptions } = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions); +export function addTextInputObject(x: number, y: number, width: number, height: number, style: TextStyle, extraStyleOptions?: InputText.IConfig): InputText { + const { scale, styleOptions } = getTextStyleOptions(style, globalScene.uiTheme, extraStyleOptions); - const ret = new InputText(scene, x, y, width, height, styleOptions as InputText.IConfig); - scene.add.existing(ret); + const ret = new InputText(globalScene, x, y, width, height, styleOptions as InputText.IConfig); + globalScene.add.existing(ret); ret.setScale(scale); return ret; diff --git a/src/ui/time-of-day-widget.ts b/src/ui/time-of-day-widget.ts index 66fe5cc9ac32..2a33b4753857 100644 --- a/src/ui/time-of-day-widget.ts +++ b/src/ui/time-of-day-widget.ts @@ -1,13 +1,11 @@ import * as Utils from "../utils"; -import BattleScene from "#app/battle-scene"; +import { globalScene } from "#app/global-scene"; import { BattleSceneEventType } from "../events/battle-scene"; import { EaseType } from "#enums/ease-type"; import { TimeOfDay } from "#enums/time-of-day"; /** A small self contained UI element that displays the time of day as an icon */ export default class TimeOfDayWidget extends Phaser.GameObjects.Container { - /** An alias for the scene typecast to a {@linkcode BattleScene} */ - private battleScene: BattleScene; /** The {@linkcode Phaser.GameObjects.Sprite} that represents the foreground of the current time of day */ private readonly timeOfDayIconFgs: Phaser.GameObjects.Sprite[] = new Array(2); @@ -42,19 +40,18 @@ export default class TimeOfDayWidget extends Phaser.GameObjects.Container { public set parentVisible(visible: boolean) { if (visible && !this._parentVisible) { // Only resume the tweens if parent is newly visible this.timeOfDayIcons?.forEach( - icon => this.scene.tweens.getTweensOf(icon).forEach( + icon => globalScene.tweens.getTweensOf(icon).forEach( tween => tween.resume())); } this._parentVisible = visible; } - constructor(scene: Phaser.Scene, x: number = 0, y: number = 0) { - super(scene, x, y); - this.battleScene = this.scene as BattleScene; + constructor(x: number = 0, y: number = 0) { + super(globalScene, x, y); - this.setVisible(this.battleScene.showTimeOfDayWidget); - if (!this.battleScene.showTimeOfDayWidget) { + this.setVisible(globalScene.showTimeOfDayWidget); + if (!globalScene.showTimeOfDayWidget) { return; } @@ -62,14 +59,14 @@ export default class TimeOfDayWidget extends Phaser.GameObjects.Container { this.timeOfDayIconPairs.forEach( (icons, key) => { for (let i = 0; i < icons.length; i++) { - icons[i] = this.scene.add.sprite(0, 0, "dawn_icon_" + key).setOrigin(); + icons[i] = globalScene.add.sprite(0, 0, "dawn_icon_" + key).setOrigin(); } }); // Store a flat array of all icons for later this.timeOfDayIcons = [ this.timeOfDayIconBgs, this.timeOfDayIconMgs, this.timeOfDayIconFgs ].flat(); this.add(this.timeOfDayIcons); - this.battleScene.eventTarget.addEventListener(BattleSceneEventType.ENCOUNTER_PHASE, this.onEncounterPhaseEvent); + globalScene.eventTarget.addEventListener(BattleSceneEventType.ENCOUNTER_PHASE, this.onEncounterPhaseEvent); } /** @@ -136,13 +133,13 @@ export default class TimeOfDayWidget extends Phaser.GameObjects.Container { /** Adds the proper tween for all icons */ private tweenTimeOfDayIcon() { - this.scene.tweens.killTweensOf(this.timeOfDayIcons); + globalScene.tweens.killTweensOf(this.timeOfDayIcons); this.resetIcons(); // Tween based on the player setting - (this.battleScene.timeOfDayAnimation === EaseType.BACK ? this.getBackTween() : this.getBounceTween()) - .forEach(tween => this.scene.tweens.add(tween)); + (globalScene.timeOfDayAnimation === EaseType.BACK ? this.getBackTween() : this.getBounceTween()) + .forEach(tween => globalScene.tweens.add(tween)); // Swaps all elements of the icon arrays by shifting the first element onto the end of the array // This ensures index[0] is always the new time of day icon and index[1] is always the current one @@ -158,7 +155,7 @@ export default class TimeOfDayWidget extends Phaser.GameObjects.Container { * @param event {@linkcode Event} being sent */ private onEncounterPhase(event: Event) { - const newTime = this.battleScene.arena.getTimeOfDay(); + const newTime = globalScene.arena.getTimeOfDay(); if (this.currentTime === newTime) { return; diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index aec80f049c9b..538f78e877e1 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -1,4 +1,3 @@ -import BattleScene from "../battle-scene"; import OptionSelectUiHandler from "./settings/option-select-ui-handler"; import { Mode } from "./ui"; import * as Utils from "../utils"; @@ -8,6 +7,7 @@ import i18next from "i18next"; import { TimedEventDisplay } from "#app/timed-event-manager"; import { version } from "../../package.json"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; +import { globalScene } from "#app/global-scene"; export default class TitleUiHandler extends OptionSelectUiHandler { /** If the stats can not be retrieved, use this fallback value */ @@ -22,8 +22,8 @@ export default class TitleUiHandler extends OptionSelectUiHandler { private titleStatsTimer: NodeJS.Timeout | null; - constructor(scene: BattleScene, mode: Mode = Mode.TITLE) { - super(scene, mode); + constructor(mode: Mode = Mode.TITLE) { + super(mode); } setup() { @@ -31,25 +31,24 @@ export default class TitleUiHandler extends OptionSelectUiHandler { const ui = this.getUi(); - this.titleContainer = this.scene.add.container(0, -(this.scene.game.canvas.height / 6)); + this.titleContainer = globalScene.add.container(0, -(globalScene.game.canvas.height / 6)); this.titleContainer.setName("title"); this.titleContainer.setAlpha(0); ui.add(this.titleContainer); - const logo = this.scene.add.image((this.scene.game.canvas.width / 6) / 2, 8, "logo"); + const logo = globalScene.add.image((globalScene.game.canvas.width / 6) / 2, 8, "logo"); logo.setOrigin(0.5, 0); this.titleContainer.add(logo); - if (this.scene.eventManager.isEventActive()) { - this.eventDisplay = new TimedEventDisplay(this.scene, 0, 0, this.scene.eventManager.activeEvent()); + if (globalScene.eventManager.isEventActive()) { + this.eventDisplay = new TimedEventDisplay(0, 0, globalScene.eventManager.activeEvent()); this.eventDisplay.setup(); this.titleContainer.add(this.eventDisplay); } this.playerCountLabel = addTextObject( - this.scene, - (this.scene.game.canvas.width / 6) - 2, - (this.scene.game.canvas.height / 6) - 13 - 576 * getTextStyleOptions(TextStyle.WINDOW, this.scene.uiTheme).scale, + (globalScene.game.canvas.width / 6) - 2, + (globalScene.game.canvas.height / 6) - 13 - 576 * getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale, `? ${i18next.t("menu:playersOnline")}`, TextStyle.MESSAGE, { fontSize: "54px" } @@ -57,14 +56,14 @@ export default class TitleUiHandler extends OptionSelectUiHandler { this.playerCountLabel.setOrigin(1, 0); this.titleContainer.add(this.playerCountLabel); - this.splashMessageText = addTextObject(this.scene, logo.x + 64, logo.y + logo.displayHeight - 8, "", TextStyle.MONEY, { fontSize: "54px" }); + this.splashMessageText = addTextObject(logo.x + 64, logo.y + logo.displayHeight - 8, "", TextStyle.MONEY, { fontSize: "54px" }); this.splashMessageText.setOrigin(0.5, 0.5); this.splashMessageText.setAngle(-20); this.titleContainer.add(this.splashMessageText); const originalSplashMessageScale = this.splashMessageText.scale; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.splashMessageText, duration: Utils.fixedInt(350), scale: originalSplashMessageScale * 1.25, @@ -72,7 +71,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { yoyo: true, }); - this.appVersionText = addTextObject(this.scene, logo.x - 60, logo.y + logo.displayHeight + 4, "", TextStyle.MONEY, { fontSize: "54px" }); + this.appVersionText = addTextObject(logo.x - 60, logo.y + logo.displayHeight + 4, "", TextStyle.MONEY, { fontSize: "54px" }); this.appVersionText.setOrigin(0.5, 0.5); this.appVersionText.setAngle(0); this.titleContainer.add(this.appVersionText); @@ -104,8 +103,8 @@ export default class TitleUiHandler extends OptionSelectUiHandler { const ui = this.getUi(); - if (this.scene.eventManager.isEventActive()) { - this.eventDisplay.setWidth(this.scene.scaledCanvas.width - this.optionSelectBg.width - this.optionSelectBg.x); + if (globalScene.eventManager.isEventActive()) { + this.eventDisplay.setWidth(globalScene.scaledCanvas.width - this.optionSelectBg.width - this.optionSelectBg.x); this.eventDisplay.show(); } @@ -115,7 +114,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { this.updateTitleStats(); }, 60000); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.titleContainer, ui.getMessageHandler().bg ], duration: Utils.fixedInt(325), alpha: (target: any) => target === this.titleContainer ? 1 : 0, @@ -136,7 +135,7 @@ export default class TitleUiHandler extends OptionSelectUiHandler { this.titleStatsTimer && clearInterval(this.titleStatsTimer); this.titleStatsTimer = null; - this.scene.tweens.add({ + globalScene.tweens.add({ targets: [ this.titleContainer, ui.getMessageHandler().bg ], duration: Utils.fixedInt(325), alpha: (target: any) => target === this.titleContainer ? 0 : 1, diff --git a/src/ui/ui-handler.ts b/src/ui/ui-handler.ts index bb7b1e038dbe..fdbe11eddb3f 100644 --- a/src/ui/ui-handler.ts +++ b/src/ui/ui-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import { TextStyle, getTextColor } from "./text"; import { Mode } from "./ui"; import { Button } from "#enums/buttons"; @@ -7,17 +7,14 @@ import { Button } from "#enums/buttons"; * A basic abstract class to act as a holder and processor for UI elements. */ export default abstract class UiHandler { - protected scene: BattleScene; protected mode: integer | null; protected cursor: integer = 0; public active: boolean = false; /** - * @param {BattleScene} scene The same scene as everything else. - * @param {Mode} mode The mode of the UI element. These should be unique. + * @param mode The mode of the UI element. These should be unique. */ - constructor(scene: BattleScene, mode: Mode | null = null) { - this.scene = scene; + constructor(mode: Mode | null = null) { this.mode = mode; } @@ -32,11 +29,11 @@ export default abstract class UiHandler { abstract processInput(button: Button): boolean; getUi() { - return this.scene.ui; + return globalScene.ui; } getTextColor(style: TextStyle, shadow: boolean = false): string { - return getTextColor(style, shadow, this.scene.uiTheme); + return getTextColor(style, shadow, globalScene.uiTheme); } getCursor(): integer { @@ -58,7 +55,7 @@ export default abstract class UiHandler { * @param cursorStyle cursor style to apply */ protected setMouseCursorStyle(cursorStyle: "pointer" | "default") { - this.scene.input.manager.canvas.style.cursor = cursorStyle; + globalScene.input.manager.canvas.style.cursor = cursorStyle; } clear() { diff --git a/src/ui/ui-theme.ts b/src/ui/ui-theme.ts index 89c56384bd08..0d42815f8429 100644 --- a/src/ui/ui-theme.ts +++ b/src/ui/ui-theme.ts @@ -1,6 +1,6 @@ import { UiTheme } from "#enums/ui-theme"; import { legacyCompatibleImages } from "#app/scene-base"; -import BattleScene from "../battle-scene"; +import { globalScene } from "#app/global-scene"; export enum WindowVariant { NORMAL, @@ -36,14 +36,14 @@ const windowTypeControlColors = { } }; -export function addWindow(scene: BattleScene, x: number, y: number, width: number, height: number, mergeMaskTop?: boolean, mergeMaskLeft?: boolean, maskOffsetX?: number, maskOffsetY?: number, windowVariant?: WindowVariant): Phaser.GameObjects.NineSlice { +export function addWindow(x: number, y: number, width: number, height: number, mergeMaskTop?: boolean, mergeMaskLeft?: boolean, maskOffsetX?: number, maskOffsetY?: number, windowVariant?: WindowVariant): Phaser.GameObjects.NineSlice { if (windowVariant === undefined) { windowVariant = WindowVariant.NORMAL; } - const borderSize = scene.uiTheme ? 6 : 8; + const borderSize = globalScene.uiTheme ? 6 : 8; - const window = scene.add.nineslice(x, y, `window_${scene.windowType}${getWindowVariantSuffix(windowVariant)}`, undefined, width, height, borderSize, borderSize, borderSize, borderSize); + const window = globalScene.add.nineslice(x, y, `window_${globalScene.windowType}${getWindowVariantSuffix(windowVariant)}`, undefined, width, height, borderSize, borderSize, borderSize, borderSize); window.setOrigin(0, 0); if (mergeMaskLeft || mergeMaskTop || maskOffsetX || maskOffsetY) { @@ -54,7 +54,7 @@ export function addWindow(scene: BattleScene, x: number, y: number, width: numbe * height: bottom */ const maskRect = new Phaser.GameObjects.Rectangle( - scene, + globalScene, 6 * (x - (mergeMaskLeft ? 2 : 0) - (maskOffsetX || 0)), 6 * (y + (mergeMaskTop ? 2 : 0) + (maskOffsetY || 0)), width - (mergeMaskLeft ? 2 : 0), @@ -70,7 +70,7 @@ export function addWindow(scene: BattleScene, x: number, y: number, width: numbe return window; } -export function updateWindowType(scene: BattleScene, windowTypeIndex: integer): void { +export function updateWindowType(windowTypeIndex: integer): void { const windowObjects: [Phaser.GameObjects.NineSlice, WindowVariant][] = []; const themedObjects: (Phaser.GameObjects.Image | Phaser.GameObjects.NineSlice)[] = []; const traverse = (object: any) => { @@ -96,12 +96,12 @@ export function updateWindowType(scene: BattleScene, windowTypeIndex: integer): } }; - traverse(scene); + traverse(globalScene); - scene.windowType = windowTypeIndex; + globalScene.windowType = windowTypeIndex; const rootStyle = document.documentElement.style; - [ "base", "light", "dark" ].map((k, i) => rootStyle.setProperty(`--color-${k}`, windowTypeControlColors[scene.uiTheme][windowTypeIndex - 1][i])); + [ "base", "light", "dark" ].map((k, i) => rootStyle.setProperty(`--color-${k}`, windowTypeControlColors[globalScene.uiTheme][windowTypeIndex - 1][i])); const windowKey = `window_${windowTypeIndex}`; @@ -114,11 +114,11 @@ export function updateWindowType(scene: BattleScene, windowTypeIndex: integer): } } -export function addUiThemeOverrides(scene: BattleScene): void { - const originalAddImage = scene.add.image; - scene.add.image = function (x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.Image { +export function addUiThemeOverrides(): void { + const originalAddImage = globalScene.add.image; + globalScene.add.image = function (x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.Image { let legacy = false; - if (typeof texture === "string" && scene.uiTheme && legacyCompatibleImages.includes(texture)) { + if (typeof texture === "string" && globalScene.uiTheme && legacyCompatibleImages.includes(texture)) { legacy = true; texture += "_legacy"; } @@ -133,10 +133,10 @@ export function addUiThemeOverrides(scene: BattleScene): void { return ret; }; - const originalAddSprite = scene.add.sprite; - scene.add.sprite = function (x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.Sprite { + const originalAddSprite = globalScene.add.sprite; + globalScene.add.sprite = function (x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.Sprite { let legacy = false; - if (typeof texture === "string" && scene.uiTheme && legacyCompatibleImages.includes(texture)) { + if (typeof texture === "string" && globalScene.uiTheme && legacyCompatibleImages.includes(texture)) { legacy = true; texture += "_legacy"; } @@ -151,10 +151,10 @@ export function addUiThemeOverrides(scene: BattleScene): void { return ret; }; - const originalAddNineslice = scene.add.nineslice; - scene.add.nineslice = function (x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number, width?: number, height?: number, leftWidth?: number, rightWidth?: number, topHeight?: number, bottomHeight?: number): Phaser.GameObjects.NineSlice { + const originalAddNineslice = globalScene.add.nineslice; + globalScene.add.nineslice = function (x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number, width?: number, height?: number, leftWidth?: number, rightWidth?: number, topHeight?: number, bottomHeight?: number): Phaser.GameObjects.NineSlice { let legacy = false; - if (typeof texture === "string" && scene.uiTheme && legacyCompatibleImages.includes(texture)) { + if (typeof texture === "string" && globalScene.uiTheme && legacyCompatibleImages.includes(texture)) { legacy = true; texture += "_legacy"; } diff --git a/src/ui/ui.ts b/src/ui/ui.ts index fc8fa94c8488..fab102e2f8e9 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -1,4 +1,4 @@ -import { default as BattleScene } from "../battle-scene"; +import { globalScene } from "#app/global-scene"; import UiHandler from "./ui-handler"; import BattleMessageUiHandler from "./battle-message-ui-handler"; import CommandUiHandler from "./command-ui-handler"; @@ -156,55 +156,55 @@ export default class UI extends Phaser.GameObjects.Container { private overlayActive: boolean; - constructor(scene: BattleScene) { - super(scene, 0, scene.game.canvas.height / 6); + constructor() { + super(globalScene, 0, globalScene.game.canvas.height / 6); this.mode = Mode.MESSAGE; this.modeChain = []; this.handlers = [ - new BattleMessageUiHandler(scene), - new TitleUiHandler(scene), - new CommandUiHandler(scene), - new FightUiHandler(scene), - new BallUiHandler(scene), - new TargetSelectUiHandler(scene), - new ModifierSelectUiHandler(scene), - new SaveSlotSelectUiHandler(scene), - new PartyUiHandler(scene), - new SummaryUiHandler(scene), - new StarterSelectUiHandler(scene), - new EvolutionSceneHandler(scene), - new EggHatchSceneHandler(scene), - new EggSummaryUiHandler(scene), - new ConfirmUiHandler(scene), - new OptionSelectUiHandler(scene), - new MenuUiHandler(scene), - new OptionSelectUiHandler(scene, Mode.MENU_OPTION_SELECT), + new BattleMessageUiHandler(), + new TitleUiHandler(), + new CommandUiHandler(), + new FightUiHandler(), + new BallUiHandler(), + new TargetSelectUiHandler(), + new ModifierSelectUiHandler(), + new SaveSlotSelectUiHandler(), + new PartyUiHandler(), + new SummaryUiHandler(), + new StarterSelectUiHandler(), + new EvolutionSceneHandler(), + new EggHatchSceneHandler(), + new EggSummaryUiHandler(), + new ConfirmUiHandler(), + new OptionSelectUiHandler(), + new MenuUiHandler(), + new OptionSelectUiHandler(Mode.MENU_OPTION_SELECT), // settings - new SettingsUiHandler(scene), - new SettingsDisplayUiHandler(scene), - new SettingsAudioUiHandler(scene), - new SettingsGamepadUiHandler(scene), - new GamepadBindingUiHandler(scene), - new SettingsKeyboardUiHandler(scene), - new KeyboardBindingUiHandler(scene), - new AchvsUiHandler(scene), - new GameStatsUiHandler(scene), - new EggListUiHandler(scene), - new EggGachaUiHandler(scene), - new LoginFormUiHandler(scene), - new RegistrationFormUiHandler(scene), - new LoadingModalUiHandler(scene), - new SessionReloadModalUiHandler(scene), - new UnavailableModalUiHandler(scene), - new GameChallengesUiHandler(scene), - new RenameFormUiHandler(scene), - new RunHistoryUiHandler(scene), - new RunInfoUiHandler(scene), - new TestDialogueUiHandler(scene, Mode.TEST_DIALOGUE), - new AutoCompleteUiHandler(scene), - new AdminUiHandler(scene), - new MysteryEncounterUiHandler(scene), + new SettingsUiHandler(), + new SettingsDisplayUiHandler(), + new SettingsAudioUiHandler(), + new SettingsGamepadUiHandler(), + new GamepadBindingUiHandler(), + new SettingsKeyboardUiHandler(), + new KeyboardBindingUiHandler(), + new AchvsUiHandler(), + new GameStatsUiHandler(), + new EggListUiHandler(), + new EggGachaUiHandler(), + new LoginFormUiHandler(), + new RegistrationFormUiHandler(), + new LoadingModalUiHandler(), + new SessionReloadModalUiHandler(), + new UnavailableModalUiHandler(), + new GameChallengesUiHandler(), + new RenameFormUiHandler(), + new RunHistoryUiHandler(), + new RunInfoUiHandler(), + new TestDialogueUiHandler(Mode.TEST_DIALOGUE), + new AutoCompleteUiHandler(), + new AdminUiHandler(), + new MysteryEncounterUiHandler(), ]; } @@ -213,38 +213,38 @@ export default class UI extends Phaser.GameObjects.Container { for (const handler of this.handlers) { handler.setup(); } - this.overlay = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0); + this.overlay = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0); this.overlay.setName("rect-ui-overlay"); this.overlay.setOrigin(0, 0); - (this.scene as BattleScene).uiContainer.add(this.overlay); + globalScene.uiContainer.add(this.overlay); this.overlay.setVisible(false); this.setupTooltip(); - this.achvBar = new AchvBar(this.scene as BattleScene); + this.achvBar = new AchvBar; this.achvBar.setup(); - (this.scene as BattleScene).uiContainer.add(this.achvBar); + globalScene.uiContainer.add(this.achvBar); - this.savingIcon = new SavingIconHandler(this.scene as BattleScene); + this.savingIcon = new SavingIconHandler; this.savingIcon.setup(); - (this.scene as BattleScene).uiContainer.add(this.savingIcon); + globalScene.uiContainer.add(this.savingIcon); } private setupTooltip() { - this.tooltipContainer = this.scene.add.container(0, 0); + this.tooltipContainer = globalScene.add.container(0, 0); this.tooltipContainer.setName("tooltip"); this.tooltipContainer.setVisible(false); - this.tooltipBg = addWindow(this.scene as BattleScene, 0, 0, 128, 31); + this.tooltipBg = addWindow(0, 0, 128, 31); this.tooltipBg.setName("window-tooltip-bg"); this.tooltipBg.setOrigin(0, 0); - this.tooltipTitle = addTextObject(this.scene, 64, 4, "", TextStyle.TOOLTIP_TITLE); + this.tooltipTitle = addTextObject(64, 4, "", TextStyle.TOOLTIP_TITLE); this.tooltipTitle.setName("text-tooltip-title"); this.tooltipTitle.setOrigin(0.5, 0); - this.tooltipContent = addTextObject(this.scene, 6, 16, "", TextStyle.TOOLTIP_CONTENT); + this.tooltipContent = addTextObject(6, 16, "", TextStyle.TOOLTIP_CONTENT); this.tooltipContent.setName("text-tooltip-content"); this.tooltipContent.setWordWrapWidth(850); @@ -252,7 +252,7 @@ export default class UI extends Phaser.GameObjects.Container { this.tooltipContainer.add(this.tooltipTitle); this.tooltipContainer.add(this.tooltipContent); - (this.scene as BattleScene).uiContainer.add(this.tooltipContainer); + globalScene.uiContainer.add(this.tooltipContainer); } getHandler(): H { @@ -268,12 +268,11 @@ export default class UI extends Phaser.GameObjects.Container { return false; } - const battleScene = this.scene as BattleScene; if ([ Mode.CONFIRM, Mode.COMMAND, Mode.FIGHT, Mode.MESSAGE ].includes(this.mode)) { - battleScene?.processInfoButton(pressed); + globalScene?.processInfoButton(pressed); return true; } - battleScene?.processInfoButton(false); + globalScene?.processInfoButton(false); return true; } @@ -318,11 +317,10 @@ export default class UI extends Phaser.GameObjects.Container { } showDialogue(keyOrText: string, name: string | undefined, delay: integer | null = 0, callback: Function, callbackDelay?: integer, promptDelay?: integer): void { - const battleScene = this.scene as BattleScene; // Get localized dialogue (if available) let hasi18n = false; let text = keyOrText; - const genderIndex = battleScene.gameData.gender ?? PlayerGender.UNSET; + const genderIndex = globalScene.gameData.gender ?? PlayerGender.UNSET; const genderStr = PlayerGender[genderIndex].toLowerCase(); if (i18next.exists(keyOrText) ) { @@ -339,7 +337,7 @@ export default class UI extends Phaser.GameObjects.Container { } } let showMessageAndCallback = () => { - hasi18n && battleScene.gameData.saveSeenDialogue(keyOrText); + hasi18n && globalScene.gameData.saveSeenDialogue(keyOrText); callback(); }; if (text.indexOf("$") > -1) { @@ -360,10 +358,8 @@ export default class UI extends Phaser.GameObjects.Container { } shouldSkipDialogue(i18nKey: string): boolean { - const battleScene = this.scene as BattleScene; - if (i18next.exists(i18nKey) ) { - if (battleScene.skipSeenDialogues && battleScene.gameData.getSeenDialogues()[i18nKey] === true) { + if (globalScene.skipSeenDialogues && globalScene.gameData.getSeenDialogues()[i18nKey] === true) { return true; } } @@ -378,9 +374,9 @@ export default class UI extends Phaser.GameObjects.Container { this.tooltipContainer.setVisible(true); this.editTooltip(title, content); if (overlap) { - (this.scene as BattleScene).uiContainer.moveAbove(this.tooltipContainer, this); + globalScene.uiContainer.moveAbove(this.tooltipContainer, this); } else { - (this.scene as BattleScene).uiContainer.moveBelow(this.tooltipContainer, this); + globalScene.uiContainer.moveBelow(this.tooltipContainer, this); } } @@ -401,9 +397,9 @@ export default class UI extends Phaser.GameObjects.Container { update(): void { if (this.tooltipContainer.visible) { - const isTouch = (this.scene as BattleScene).inputMethod === "touch"; - const pointerX = this.scene.game.input.activePointer.x; - const pointerY = this.scene.game.input.activePointer.y; + const isTouch = globalScene.inputMethod === "touch"; + const pointerX = globalScene.game.input.activePointer.x; + const pointerY = globalScene.game.input.activePointer.y; const tooltipWidth = this.tooltipBg.width; const tooltipHeight = this.tooltipBg.height; const padding = 2; @@ -414,16 +410,16 @@ export default class UI extends Phaser.GameObjects.Container { if (isTouch) { // If we are in the top left quadrant on mobile, move the tooltip to the top right corner - if (pointerX <= this.scene.game.canvas.width / 2 && pointerY <= this.scene.game.canvas.height / 2) { - x = this.scene.game.canvas.width / 6 - tooltipWidth - padding; + if (pointerX <= globalScene.game.canvas.width / 2 && pointerY <= globalScene.game.canvas.height / 2) { + x = globalScene.game.canvas.width / 6 - tooltipWidth - padding; } } else { // If the tooltip would go offscreen on the right, or is close to it, move to the left of the cursor - if (x + tooltipWidth + padding > this.scene.game.canvas.width / 6) { + if (x + tooltipWidth + padding > globalScene.game.canvas.width / 6) { x = Math.max(padding, pointerX / 6 - tooltipWidth - padding); } // If the tooltip would go offscreen at the bottom, or is close to it, move above the cursor - if (y + tooltipHeight + padding > this.scene.game.canvas.height / 6) { + if (y + tooltipHeight + padding > globalScene.game.canvas.height / 6) { y = Math.max(padding, pointerY / 6 - tooltipHeight - padding); } } @@ -451,11 +447,11 @@ export default class UI extends Phaser.GameObjects.Container { } playSelect(): void { - (this.scene as BattleScene).playSound("ui/select"); + globalScene.playSound("ui/select"); } playError(): void { - (this.scene as BattleScene).playSound("ui/error"); + globalScene.playSound("ui/error"); } fadeOut(duration: integer): Promise { @@ -466,7 +462,7 @@ export default class UI extends Phaser.GameObjects.Container { this.overlayActive = true; this.overlay.setAlpha(0); this.overlay.setVisible(true); - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.overlay, alpha: 1, duration: duration, @@ -481,7 +477,7 @@ export default class UI extends Phaser.GameObjects.Container { if (!this.overlayActive) { return resolve(); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.overlay, alpha: 0, duration: duration, @@ -508,7 +504,7 @@ export default class UI extends Phaser.GameObjects.Container { } if (chainMode && this.mode && !clear) { this.modeChain.push(this.mode); - (this.scene as BattleScene).updateGameInfo(); + globalScene.updateGameInfo(); } this.mode = mode; const touchControls = document?.getElementById("touchControls"); @@ -523,7 +519,7 @@ export default class UI extends Phaser.GameObjects.Container { && (noTransitionModes.indexOf(this.mode) === -1 && noTransitionModes.indexOf(mode) === -1))) || (chainMode && noTransitionModes.indexOf(mode) === -1))) { this.fadeOut(250).then(() => { - this.scene.time.delayedCall(100, () => { + globalScene.time.delayedCall(100, () => { doSetMode(); this.fadeIn(250); }); @@ -556,7 +552,7 @@ export default class UI extends Phaser.GameObjects.Container { resetModeChain(): void { this.modeChain = []; - (this.scene as BattleScene).updateGameInfo(); + globalScene.updateGameInfo(); } revertMode(): Promise { @@ -570,7 +566,7 @@ export default class UI extends Phaser.GameObjects.Container { const doRevertMode = () => { this.getHandler().clear(); this.mode = this.modeChain.pop()!; // TODO: is this bang correct? - (this.scene as BattleScene).updateGameInfo(); + globalScene.updateGameInfo(); const touchControls = document.getElementById("touchControls"); if (touchControls) { touchControls.dataset.uiMode = Mode[this.mode]; @@ -580,7 +576,7 @@ export default class UI extends Phaser.GameObjects.Container { if (noTransitionModes.indexOf(lastMode) === -1) { this.fadeOut(250).then(() => { - this.scene.time.delayedCall(100, () => { + globalScene.time.delayedCall(100, () => { doRevertMode(); this.fadeIn(250); }); @@ -612,11 +608,10 @@ export default class UI extends Phaser.GameObjects.Container { * @returns gamepad type */ public getGamepadType(): string { - const scene = this.scene as BattleScene; - if (scene.inputMethod === "gamepad") { - return scene.inputController.getConfig(scene.inputController.selectedDevice[Device.GAMEPAD]).padType; + if (globalScene.inputMethod === "gamepad") { + return globalScene.inputController.getConfig(globalScene.inputController.selectedDevice[Device.GAMEPAD]).padType; } else { - return scene.inputMethod; + return globalScene.inputMethod; } } } diff --git a/src/ui/unavailable-modal-ui-handler.ts b/src/ui/unavailable-modal-ui-handler.ts index 92b1c2f1b4ec..417270aea1ba 100644 --- a/src/ui/unavailable-modal-ui-handler.ts +++ b/src/ui/unavailable-modal-ui-handler.ts @@ -1,10 +1,10 @@ -import BattleScene from "../battle-scene"; import { ModalConfig, ModalUiHandler } from "./modal-ui-handler"; import { addTextObject, TextStyle } from "./text"; import { Mode } from "./ui"; import { updateUserInfo } from "#app/account"; import * as Utils from "#app/utils"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; export default class UnavailableModalUiHandler extends ModalUiHandler { private reconnectTimer: NodeJS.Timeout | null; @@ -16,8 +16,8 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { private readonly randVarianceTime = 1000 * 10; - constructor(scene: BattleScene, mode: Mode | null = null) { - super(scene, mode); + constructor(mode: Mode | null = null) { + super(mode); this.reconnectDuration = this.minTime; } @@ -44,7 +44,7 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { setup(): void { super.setup(); - const label = addTextObject(this.scene, this.getWidth() / 2, this.getHeight() / 2, i18next.t("menu:errorServerDown"), TextStyle.WINDOW, { fontSize: "48px", align: "center" }); + const label = addTextObject(this.getWidth() / 2, this.getHeight() / 2, i18next.t("menu:errorServerDown"), TextStyle.WINDOW, { fontSize: "48px", align: "center" }); label.setOrigin(0.5, 0.5); this.modalContainer.add(label); @@ -55,11 +55,11 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { if (response[0] || [ 200, 400 ].includes(response[1])) { this.reconnectTimer = null; this.reconnectDuration = this.minTime; - this.scene.playSound("se/pb_bounce_1"); + globalScene.playSound("se/pb_bounce_1"); this.reconnectCallback(); } else if (response[1] === 401) { Utils.removeCookie(Utils.sessionIdKey); - this.scene.reset(true, true); + globalScene.reset(true, true); } else { this.reconnectDuration = Math.min(this.reconnectDuration * 2, this.maxTime); // Set a max delay so it isn't infinite this.reconnectTimer =