diff --git a/src/battle-scene.ts b/src/battle-scene.ts index a759cbb84c2..f676ba63306 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1526,8 +1526,6 @@ export default class BattleScene extends SceneBase { this.currentBattle.mysteryEncounterType = mysteryEncounterType; } - //this.pushPhase(new TrainerMessageTestPhase(this, TrainerType.RIVAL, TrainerType.RIVAL_2, TrainerType.RIVAL_3, TrainerType.RIVAL_4, TrainerType.RIVAL_5, TrainerType.RIVAL_6)); - if (!waveIndex && lastBattle) { const isWaveIndexMultipleOfTen = !(lastBattle.waveIndex % 10); const isEndlessOrDaily = this.gameMode.hasShortBiomes || this.gameMode.isDaily; diff --git a/src/phases/add-enemy-buff-modifier-phase.ts b/src/phases/add-enemy-buff-modifier-phase.ts index 7d91e64382a..16ed78e6d0d 100644 --- a/src/phases/add-enemy-buff-modifier-phase.ts +++ b/src/phases/add-enemy-buff-modifier-phase.ts @@ -9,10 +9,6 @@ import { Phase } from "#app/phase"; import { globalScene } from "#app/global-scene"; export class AddEnemyBuffModifierPhase extends Phase { - constructor() { - super(); - } - start() { super.start(); diff --git a/src/phases/attempt-run-phase.ts b/src/phases/attempt-run-phase.ts index dab5b8789da..e5691f5fb8e 100644 --- a/src/phases/attempt-run-phase.ts +++ b/src/phases/attempt-run-phase.ts @@ -1,10 +1,10 @@ import { applyAbAttrs, applyPreLeaveFieldAbAttrs, PreLeaveFieldAbAttr, RunSuccessAbAttr } from "#app/data/ability"; -import { Stat } from "#app/enums/stat"; -import { StatusEffect } from "#app/enums/status-effect"; +import { Stat } from "#enums/stat"; +import { StatusEffect } from "#enums/status-effect"; import type { PlayerPokemon, EnemyPokemon } from "#app/field/pokemon"; import type Pokemon from "#app/field/pokemon"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { BattleEndPhase } from "./battle-end-phase"; import { NewBattlePhase } from "./new-battle-phase"; import { PokemonPhase } from "./pokemon-phase"; @@ -22,7 +22,7 @@ export class AttemptRunPhase extends PokemonPhase { const playerPokemon = this.getPokemon(); - const escapeChance = new Utils.NumberHolder(0); + const escapeChance = new NumberHolder(0); this.attemptRunAway(playerField, enemyField, escapeChance); @@ -63,7 +63,7 @@ export class AttemptRunPhase extends PokemonPhase { this.end(); } - attemptRunAway(playerField: PlayerPokemon[], enemyField: EnemyPokemon[], escapeChance: Utils.NumberHolder) { + attemptRunAway(playerField: PlayerPokemon[], enemyField: EnemyPokemon[], escapeChance: NumberHolder) { /** Sum of the speed of all enemy pokemon on the field */ const enemySpeed = enemyField.reduce( (total: number, enemyPokemon: Pokemon) => total + enemyPokemon.getStat(Stat.SPD), diff --git a/src/phases/battle-end-phase.ts b/src/phases/battle-end-phase.ts index e6a0c66548e..ff17b17ab8b 100644 --- a/src/phases/battle-end-phase.ts +++ b/src/phases/battle-end-phase.ts @@ -26,13 +26,15 @@ export class BattleEndPhase extends BattlePhase { return true; }); // `phaseQueuePrepend` is private, so we have to use this inefficient loop. - while (globalScene.tryRemoveUnshiftedPhase(phase => { - if (phase instanceof BattleEndPhase) { - this.isVictory ||= phase.isVictory; - return true; - } - return false; - })) {} + while ( + globalScene.tryRemoveUnshiftedPhase(phase => { + if (phase instanceof BattleEndPhase) { + this.isVictory ||= phase.isVictory; + return true; + } + return false; + }) + ) {} globalScene.gameData.gameStats.battles++; if ( diff --git a/src/phases/battle-phase.ts b/src/phases/battle-phase.ts index 72bcc85bc62..d70b3909639 100644 --- a/src/phases/battle-phase.ts +++ b/src/phases/battle-phase.ts @@ -3,13 +3,13 @@ import { TrainerSlot } from "#enums/trainer-slot"; import { Phase } from "#app/phase"; export class BattlePhase extends Phase { - constructor() { - super(); - } - showEnemyTrainer(trainerSlot: TrainerSlot = TrainerSlot.NONE): void { - const sprites = globalScene.currentBattle.trainer?.getSprites()!; // TODO: is this bang correct? - const tintSprites = globalScene.currentBattle.trainer?.getTintSprites()!; // TODO: is this bang correct? + if (!globalScene.currentBattle.trainer) { + console.warn("Enemy trainer is missing!"); + return; + } + const sprites = globalScene.currentBattle.trainer.getSprites(); + const tintSprites = globalScene.currentBattle.trainer.getTintSprites(); for (let i = 0; i < sprites.length; i++) { const visible = !trainerSlot || !i === (trainerSlot === TrainerSlot.TRAINER) || sprites.length < 2; [sprites[i], tintSprites[i]].map(sprite => { diff --git a/src/phases/berry-phase.ts b/src/phases/berry-phase.ts index 0048f8cd2f2..e5614739903 100644 --- a/src/phases/berry-phase.ts +++ b/src/phases/berry-phase.ts @@ -4,7 +4,7 @@ import { BerryUsedEvent } from "#app/events/battle-scene"; import { getPokemonNameWithAffix } from "#app/messages"; import { BerryModifier } from "#app/modifier/modifier"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { BooleanHolder } from "#app/utils"; import { FieldPhase } from "./field-phase"; import { CommonAnimPhase } from "./common-anim-phase"; import { globalScene } from "#app/global-scene"; @@ -20,7 +20,7 @@ export class BerryPhase extends FieldPhase { }, pokemon.isPlayer()); if (hasUsableBerry) { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); pokemon.getOpponents().map(opp => applyAbAttrs(PreventBerryUseAbAttr, opp, cancelled)); if (cancelled.value) { @@ -44,7 +44,7 @@ export class BerryPhase extends FieldPhase { globalScene.updateModifiers(pokemon.isPlayer()); - applyAbAttrs(HealFromBerryUseAbAttr, pokemon, new Utils.BooleanHolder(false)); + applyAbAttrs(HealFromBerryUseAbAttr, pokemon, new BooleanHolder(false)); } } }); diff --git a/src/phases/common-anim-phase.ts b/src/phases/common-anim-phase.ts index d32e93ea6aa..5be5e112389 100644 --- a/src/phases/common-anim-phase.ts +++ b/src/phases/common-anim-phase.ts @@ -6,13 +6,18 @@ import { PokemonPhase } from "./pokemon-phase"; export class CommonAnimPhase extends PokemonPhase { private anim: CommonAnim | null; - private targetIndex: number | undefined; + private targetIndex?: BattlerIndex; private playOnEmptyField: boolean; - constructor(battlerIndex?: BattlerIndex, targetIndex?: BattlerIndex, anim?: CommonAnim, playOnEmptyField = false) { + constructor( + battlerIndex?: BattlerIndex, + targetIndex?: BattlerIndex, + anim: CommonAnim | null = null, + playOnEmptyField = false, + ) { super(battlerIndex); - this.anim = anim!; // TODO: is this bang correct? + this.anim = anim; this.targetIndex = targetIndex; this.playOnEmptyField = playOnEmptyField; } diff --git a/src/phases/damage-anim-phase.ts b/src/phases/damage-anim-phase.ts index 703cd3d160e..696a2e55b6f 100644 --- a/src/phases/damage-anim-phase.ts +++ b/src/phases/damage-anim-phase.ts @@ -10,11 +10,16 @@ export class DamageAnimPhase extends PokemonPhase { private damageResult: DamageResult; private critical: boolean; - constructor(battlerIndex: BattlerIndex, amount: number, damageResult?: DamageResult, critical = false) { + constructor( + battlerIndex: BattlerIndex, + amount: number, + damageResult: DamageResult = HitResult.EFFECTIVE, + critical = false, + ) { super(battlerIndex); this.amount = amount; - this.damageResult = damageResult || HitResult.EFFECTIVE; + this.damageResult = damageResult; this.critical = critical; } diff --git a/src/phases/egg-hatch-phase.ts b/src/phases/egg-hatch-phase.ts index 49a408e8699..07eeeb0f8ae 100644 --- a/src/phases/egg-hatch-phase.ts +++ b/src/phases/egg-hatch-phase.ts @@ -11,7 +11,7 @@ import PokemonInfoContainer from "#app/ui/pokemon-info-container"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; import SoundFade from "phaser3-rex-plugins/plugins/soundfade"; -import * as Utils from "#app/utils"; +import { fixedInt, getFrameMs, randInt } from "#app/utils"; import type { EggLapsePhase } from "./egg-lapse-phase"; import type { EggHatchData } from "#app/data/egg-hatch-data"; import { doShinySparkleAnim } from "#app/field/anims"; @@ -306,17 +306,17 @@ export class EggHatchPhase extends Phase { this.canSkip = false; this.hatched = true; if (this.evolutionBgm) { - SoundFade.fadeOut(globalScene, this.evolutionBgm, Utils.fixedInt(100)); + SoundFade.fadeOut(globalScene, this.evolutionBgm, fixedInt(100)); } for (let e = 0; e < 5; e++) { - globalScene.time.delayedCall(Utils.fixedInt(375 * e), () => + globalScene.time.delayedCall(fixedInt(375 * e), () => globalScene.playSound("se/egg_hatch", { volume: 1 - e * 0.2 }), ); } this.eggLightraysOverlay.setVisible(true); this.eggLightraysOverlay.play("egg_lightrays"); globalScene.tweens.add({ - duration: Utils.fixedInt(125), + duration: fixedInt(125), targets: this.eggHatchOverlay, alpha: 1, ease: "Cubic.easeIn", @@ -325,7 +325,7 @@ export class EggHatchPhase extends Phase { this.canSkip = true; }, }); - globalScene.time.delayedCall(Utils.fixedInt(1500), () => { + globalScene.time.delayedCall(fixedInt(1500), () => { this.canSkip = false; if (!this.skipped) { this.doReveal(); @@ -363,46 +363,43 @@ export class EggHatchPhase extends Phase { this.pokemonSprite.setPipelineData("shiny", this.pokemon.shiny); this.pokemonSprite.setPipelineData("variant", this.pokemon.variant); this.pokemonSprite.setVisible(true); - globalScene.time.delayedCall(Utils.fixedInt(250), () => { + globalScene.time.delayedCall(fixedInt(250), () => { this.eggsToHatchCount--; this.eggHatchHandler.eventTarget.dispatchEvent(new EggCountChangedEvent(this.eggsToHatchCount)); this.pokemon.cry(); if (isShiny) { - globalScene.time.delayedCall(Utils.fixedInt(500), () => { + globalScene.time.delayedCall(fixedInt(500), () => { doShinySparkleAnim(this.pokemonShinySparkle, this.pokemon.variant); }); } - globalScene.time.delayedCall( - Utils.fixedInt(!this.skipped ? (!isShiny ? 1250 : 1750) : !isShiny ? 250 : 750), - () => { - this.infoContainer.show(this.pokemon, false, this.skipped ? 2 : 1); + globalScene.time.delayedCall(fixedInt(!this.skipped ? (!isShiny ? 1250 : 1750) : !isShiny ? 250 : 750), () => { + this.infoContainer.show(this.pokemon, false, this.skipped ? 2 : 1); - globalScene.playSoundWithoutBgm("evolution_fanfare"); + globalScene.playSoundWithoutBgm("evolution_fanfare"); - globalScene.ui.showText( - i18next.t("egg:hatchFromTheEgg", { - pokemonName: this.pokemon.species.getExpandedSpeciesName(), - }), - 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); - globalScene.ui.showText("", 0); - this.end(); - }); + globalScene.ui.showText( + i18next.t("egg:hatchFromTheEgg", { + pokemonName: this.pokemon.species.getExpandedSpeciesName(), + }), + 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); + globalScene.ui.showText("", 0); + this.end(); }); - }, - null, - true, - 3000, - ); - }, - ); + }); + }, + null, + true, + 3000, + ); + }); }); globalScene.tweens.add({ - duration: Utils.fixedInt(this.skipped ? 500 : 3000), + duration: fixedInt(this.skipped ? 500 : 3000), targets: this.eggHatchOverlay, alpha: 0, ease: "Cubic.easeOut", @@ -427,9 +424,9 @@ export class EggHatchPhase extends Phase { doSpray(intensity: number, offsetY?: number) { globalScene.tweens.addCounter({ repeat: intensity, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { - this.doSprayParticle(Utils.randInt(8), offsetY || 0); + this.doSprayParticle(randInt(8), offsetY || 0); }, }); } @@ -448,12 +445,12 @@ export class EggHatchPhase extends Phase { let f = 0; let yOffset = 0; - const speed = 3 - Utils.randInt(8); - const amp = 24 + Utils.randInt(32); + const speed = 3 - randInt(8); + const amp = 24 + randInt(32); const particleTimer = globalScene.tweens.addCounter({ repeat: -1, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { updateParticle(); }, diff --git a/src/phases/encounter-phase.ts b/src/phases/encounter-phase.ts index ad2bf689e38..9e5edf3e1d9 100644 --- a/src/phases/encounter-phase.ts +++ b/src/phases/encounter-phase.ts @@ -43,10 +43,10 @@ import { getNatureName } from "#app/data/nature"; export class EncounterPhase extends BattlePhase { private loaded: boolean; - constructor(loaded?: boolean) { + constructor(loaded = false) { super(); - this.loaded = !!loaded; + this.loaded = loaded; } start() { diff --git a/src/phases/evolution-phase.ts b/src/phases/evolution-phase.ts index bb283fa8139..203c7542eff 100644 --- a/src/phases/evolution-phase.ts +++ b/src/phases/evolution-phase.ts @@ -5,7 +5,7 @@ import { globalScene } from "#app/global-scene"; import type { SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions"; import { FusionSpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions"; import type EvolutionSceneHandler from "#app/ui/evolution-scene-handler"; -import * as Utils from "#app/utils"; +import { fixedInt, getFrameMs, randInt } from "#app/utils"; import { Mode } from "#app/ui/ui"; import { cos, sin } from "#app/field/anims"; import type { PlayerPokemon } from "#app/field/pokemon"; @@ -332,9 +332,9 @@ export class EvolutionPhase extends Phase { () => this.end(), null, true, - Utils.fixedInt(4000), + fixedInt(4000), ); - globalScene.time.delayedCall(Utils.fixedInt(4250), () => globalScene.playBgm()); + globalScene.time.delayedCall(fixedInt(4250), () => globalScene.playBgm()); }); }); }; @@ -392,7 +392,7 @@ export class EvolutionPhase extends Phase { globalScene.tweens.addCounter({ repeat: 64, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { if (f < 64) { if (!(f & 7)) { @@ -411,7 +411,7 @@ export class EvolutionPhase extends Phase { globalScene.tweens.addCounter({ repeat: 96, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { if (f < 96) { if (f < 6) { @@ -461,7 +461,7 @@ export class EvolutionPhase extends Phase { globalScene.tweens.addCounter({ repeat: 48, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { if (!f) { for (let i = 0; i < 16; i++) { @@ -482,14 +482,14 @@ export class EvolutionPhase extends Phase { globalScene.tweens.addCounter({ repeat: 48, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { if (!f) { for (let i = 0; i < 8; i++) { this.doSprayParticle(i); } } else if (f < 50) { - this.doSprayParticle(Utils.randInt(8)); + this.doSprayParticle(randInt(8)); } f++; }, @@ -506,7 +506,7 @@ export class EvolutionPhase extends Phase { const particleTimer = globalScene.tweens.addCounter({ repeat: -1, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { updateParticle(); }, @@ -543,7 +543,7 @@ export class EvolutionPhase extends Phase { const particleTimer = globalScene.tweens.addCounter({ repeat: -1, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { updateParticle(); }, @@ -575,7 +575,7 @@ export class EvolutionPhase extends Phase { const particleTimer = globalScene.tweens.addCounter({ repeat: -1, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { updateParticle(); }, @@ -605,12 +605,12 @@ export class EvolutionPhase extends Phase { let f = 0; let yOffset = 0; - const speed = 3 - Utils.randInt(8); - const amp = 48 + Utils.randInt(64); + const speed = 3 - randInt(8); + const amp = 48 + randInt(64); const particleTimer = globalScene.tweens.addCounter({ repeat: -1, - duration: Utils.getFrameMs(1), + duration: getFrameMs(1), onRepeat: () => { updateParticle(); }, diff --git a/src/phases/exp-phase.ts b/src/phases/exp-phase.ts index 092482d4c18..b7d62c92bcf 100644 --- a/src/phases/exp-phase.ts +++ b/src/phases/exp-phase.ts @@ -2,7 +2,7 @@ import { globalScene } from "#app/global-scene"; import { getPokemonNameWithAffix } from "#app/messages"; import { ExpBoosterModifier } from "#app/modifier/modifier"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { PlayerPartyMemberPokemonPhase } from "./player-party-member-pokemon-phase"; import { LevelUpPhase } from "./level-up-phase"; @@ -19,7 +19,7 @@ export class ExpPhase extends PlayerPartyMemberPokemonPhase { super.start(); const pokemon = this.getPokemon(); - const exp = new Utils.NumberHolder(this.expValue); + const exp = new NumberHolder(this.expValue); globalScene.applyModifiers(ExpBoosterModifier, true, exp); exp.value = Math.floor(exp.value); globalScene.ui.showText( diff --git a/src/phases/form-change-phase.ts b/src/phases/form-change-phase.ts index e0ec4e87600..bf94284b117 100644 --- a/src/phases/form-change-phase.ts +++ b/src/phases/form-change-phase.ts @@ -1,5 +1,5 @@ import { globalScene } from "#app/global-scene"; -import * as Utils from "../utils"; +import { fixedInt } from "#app/utils"; import { achvs } from "../system/achv"; import type { SpeciesFormChange } from "../data/pokemon-forms"; import { getSpeciesFormChangeMessage } from "../data/pokemon-forms"; @@ -9,7 +9,7 @@ import type PartyUiHandler from "../ui/party-ui-handler"; import { getPokemonNameWithAffix } from "../messages"; import { EndEvolutionPhase } from "./end-evolution-phase"; import { EvolutionPhase } from "./evolution-phase"; -import { BattlerTagType } from "#app/enums/battler-tag-type"; +import { BattlerTagType } from "#enums/battler-tag-type"; import { SpeciesFormKey } from "#enums/species-form-key"; export class FormChangePhase extends EvolutionPhase { @@ -151,9 +151,9 @@ export class FormChangePhase extends EvolutionPhase { () => this.end(), null, true, - Utils.fixedInt(delay), + fixedInt(delay), ); - globalScene.time.delayedCall(Utils.fixedInt(delay + 250), () => + globalScene.time.delayedCall(fixedInt(delay + 250), () => globalScene.playBgm(), ); }); diff --git a/src/phases/game-over-phase.ts b/src/phases/game-over-phase.ts index f105b625cc8..1ccdc9c7106 100644 --- a/src/phases/game-over-phase.ts +++ b/src/phases/game-over-phase.ts @@ -20,7 +20,7 @@ import { UnlockPhase } from "#app/phases/unlock-phase"; import { achvs, ChallengeAchv } from "#app/system/achv"; import { Unlockables } from "#app/system/unlockables"; import { Mode } from "#app/ui/ui"; -import * as Utils from "#app/utils"; +import { isLocal, isLocalServerConnected } from "#app/utils"; import { PlayerGender } from "#enums/player-gender"; import { TrainerType } from "#enums/trainer-type"; import i18next from "i18next"; @@ -219,7 +219,7 @@ export class GameOverPhase extends BattlePhase { /* Added a local check to see if the game is running offline 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) { + if (!isLocal || isLocalServerConnected) { pokerogueApi.savedata.session .newclear({ slot: globalScene.sessionSlotId, diff --git a/src/phases/login-phase.ts b/src/phases/login-phase.ts index 5cce6ca0298..846482ff726 100644 --- a/src/phases/login-phase.ts +++ b/src/phases/login-phase.ts @@ -5,26 +5,26 @@ import { Phase } from "#app/phase"; import { handleTutorial, Tutorial } from "#app/tutorial"; import { Mode } from "#app/ui/ui"; import i18next, { t } from "i18next"; -import * as Utils from "#app/utils"; +import { getCookie, sessionIdKey, executeIf, removeCookie } from "#app/utils"; import { SelectGenderPhase } from "./select-gender-phase"; import { UnavailablePhase } from "./unavailable-phase"; export class LoginPhase extends Phase { private showText: boolean; - constructor(showText?: boolean) { + constructor(showText = true) { super(); - this.showText = showText === undefined || !!showText; + this.showText = showText; } start(): void { super.start(); - const hasSession = !!Utils.getCookie(Utils.sessionIdKey); + const hasSession = !!getCookie(sessionIdKey); globalScene.ui.setMode(Mode.LOADING, { buttonActions: [] }); - Utils.executeIf(bypassLogin || hasSession, updateUserInfo).then(response => { + executeIf(bypassLogin || hasSession, updateUserInfo).then(response => { const success = response ? response[0] : false; const statusCode = response ? response[1] : null; if (!success) { @@ -38,7 +38,7 @@ export class LoginPhase extends Phase { const loadData = () => { updateUserInfo().then(success => { if (!success[0]) { - Utils.removeCookie(Utils.sessionIdKey); + removeCookie(sessionIdKey); globalScene.reset(true, true); return; } @@ -60,7 +60,7 @@ export class LoginPhase extends Phase { globalScene.ui.playSelect(); updateUserInfo().then(success => { if (!success[0]) { - Utils.removeCookie(Utils.sessionIdKey); + removeCookie(sessionIdKey); globalScene.reset(true, true); return; } @@ -89,7 +89,7 @@ export class LoginPhase extends Phase { ], }); } else if (statusCode === 401) { - Utils.removeCookie(Utils.sessionIdKey); + removeCookie(sessionIdKey); globalScene.reset(true, true); } else { globalScene.unshiftPhase(new UnavailablePhase()); diff --git a/src/phases/message-phase.ts b/src/phases/message-phase.ts index cff7249fcfa..f6777579857 100644 --- a/src/phases/message-phase.ts +++ b/src/phases/message-phase.ts @@ -3,9 +3,9 @@ import { Phase } from "#app/phase"; export class MessagePhase extends Phase { private text: string; - private callbackDelay: number | null; - private prompt: boolean | null; - private promptDelay: number | null; + private callbackDelay?: number | null; + private prompt?: boolean | null; + private promptDelay?: number | null; private speaker?: string; constructor( @@ -18,9 +18,9 @@ export class MessagePhase extends Phase { super(); this.text = text; - this.callbackDelay = callbackDelay!; // TODO: is this bang correct? - this.prompt = prompt!; // TODO: is this bang correct? - this.promptDelay = promptDelay!; // TODO: is this bang correct? + this.callbackDelay = callbackDelay; + this.prompt = prompt; + this.promptDelay = promptDelay; this.speaker = speaker; } diff --git a/src/phases/money-reward-phase.ts b/src/phases/money-reward-phase.ts index 56f46d25f77..ae8dc90616d 100644 --- a/src/phases/money-reward-phase.ts +++ b/src/phases/money-reward-phase.ts @@ -2,7 +2,7 @@ import { globalScene } from "#app/global-scene"; import { ArenaTagType } from "#app/enums/arena-tag-type"; import { MoneyMultiplierModifier } from "#app/modifier/modifier"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { BattlePhase } from "./battle-phase"; export class MoneyRewardPhase extends BattlePhase { @@ -15,7 +15,7 @@ export class MoneyRewardPhase extends BattlePhase { } start() { - const moneyAmount = new Utils.NumberHolder(globalScene.getWaveMoneyAmount(this.moneyMultiplier)); + const moneyAmount = new NumberHolder(globalScene.getWaveMoneyAmount(this.moneyMultiplier)); globalScene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount); diff --git a/src/phases/move-anim-test-phase.ts b/src/phases/move-anim-test-phase.ts deleted file mode 100644 index e8b7c0c8fa7..00000000000 --- a/src/phases/move-anim-test-phase.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { globalScene } from "#app/global-scene"; -import { initMoveAnim, loadMoveAnimAssets, MoveAnim } from "#app/data/battle-anims"; -import { allMoves, SelfStatusMove } from "#app/data/moves/move"; -import { Moves } from "#app/enums/moves"; -import * as Utils from "#app/utils"; -import { BattlePhase } from "./battle-phase"; - -export class MoveAnimTestPhase extends BattlePhase { - private moveQueue: Moves[]; - - constructor(moveQueue?: Moves[]) { - super(); - - this.moveQueue = moveQueue || Utils.getEnumValues(Moves).slice(1); - } - - start() { - const moveQueue = this.moveQueue.slice(0); - this.playMoveAnim(moveQueue, true); - } - - playMoveAnim(moveQueue: Moves[], player: boolean) { - const moveId = player ? moveQueue[0] : moveQueue.shift(); - if (moveId === undefined) { - this.playMoveAnim(this.moveQueue.slice(0), true); - return; - } - if (player) { - console.log(Moves[moveId]); - } - - initMoveAnim(moveId).then(() => { - loadMoveAnimAssets([moveId], true).then(() => { - 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 { - this.playMoveAnim(moveQueue, true); - } - }); - }); - }); - } -} diff --git a/src/phases/move-end-phase.ts b/src/phases/move-end-phase.ts index f3a40ce69bd..53856956401 100644 --- a/src/phases/move-end-phase.ts +++ b/src/phases/move-end-phase.ts @@ -5,7 +5,7 @@ import type { BattlerIndex } from "#app/battle"; export class MoveEndPhase extends PokemonPhase { private wasFollowUp: boolean; - constructor(battlerIndex: BattlerIndex, wasFollowUp: boolean = false) { + constructor(battlerIndex: BattlerIndex, wasFollowUp = false) { super(battlerIndex); this.wasFollowUp = wasFollowUp; } diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 33e772eb2ea..82b73f681a0 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -227,7 +227,7 @@ export class MovePhase extends BattlePhase { (!this.pokemon.randSeedInt(4) || Overrides.STATUS_ACTIVATION_OVERRIDE === true) && Overrides.STATUS_ACTIVATION_OVERRIDE !== false; break; - case StatusEffect.SLEEP: + case StatusEffect.SLEEP: { applyMoveAttrs(BypassSleepAttr, this.pokemon, null, this.move.getMove()); const turnsRemaining = new NumberHolder(this.pokemon.status.sleepTurnsRemaining ?? 0); applyAbAttrs( @@ -242,6 +242,7 @@ export class MovePhase extends BattlePhase { healed = this.pokemon.status.sleepTurnsRemaining <= 0; activated = !healed && !this.pokemon.getTag(BattlerTagType.BYPASS_SLEEP); break; + } case StatusEffect.FREEZE: healed = !!this.move diff --git a/src/phases/mystery-encounter-phases.ts b/src/phases/mystery-encounter-phases.ts index eb187617e69..f42290ff872 100644 --- a/src/phases/mystery-encounter-phases.ts +++ b/src/phases/mystery-encounter-phases.ts @@ -26,8 +26,7 @@ import { TrainerSlot } from "#enums/trainer-slot"; import { IvScannerModifier } from "../modifier/modifier"; import { Phase } from "../phase"; import { Mode } from "../ui/ui"; -import * as Utils from "../utils"; -import { isNullOrUndefined } from "../utils"; +import { isNullOrUndefined, randSeedItem } from "#app/utils"; /** * Will handle (in order): @@ -387,7 +386,7 @@ export class MysteryEncounterBattlePhase extends Phase { const trainer = globalScene.currentBattle.trainer; let message: string; globalScene.executeWithSeedOffset( - () => (message = Utils.randSeedItem(encounterMessages)), + () => (message = randSeedItem(encounterMessages)), globalScene.currentBattle.mysteryEncounter?.getSeedOffset(), ); message = message!; // tell TS compiler it's defined now diff --git a/src/phases/new-biome-encounter-phase.ts b/src/phases/new-biome-encounter-phase.ts index bb1fe54fe9f..3449a562c4a 100644 --- a/src/phases/new-biome-encounter-phase.ts +++ b/src/phases/new-biome-encounter-phase.ts @@ -4,10 +4,6 @@ import { getRandomWeatherType } from "#app/data/weather"; import { NextEncounterPhase } from "./next-encounter-phase"; export class NewBiomeEncounterPhase extends NextEncounterPhase { - constructor() { - super(); - } - doEncounter(): void { globalScene.playBgm(undefined, true); diff --git a/src/phases/next-encounter-phase.ts b/src/phases/next-encounter-phase.ts index e53f775f083..e5e61312c3b 100644 --- a/src/phases/next-encounter-phase.ts +++ b/src/phases/next-encounter-phase.ts @@ -2,10 +2,6 @@ import { globalScene } from "#app/global-scene"; import { EncounterPhase } from "./encounter-phase"; export class NextEncounterPhase extends EncounterPhase { - constructor() { - super(); - } - start() { super.start(); } diff --git a/src/phases/party-heal-phase.ts b/src/phases/party-heal-phase.ts index a9b24309e24..137af9f3a2d 100644 --- a/src/phases/party-heal-phase.ts +++ b/src/phases/party-heal-phase.ts @@ -1,5 +1,5 @@ import { globalScene } from "#app/global-scene"; -import * as Utils from "#app/utils"; +import { fixedInt } from "#app/utils"; import { BattlePhase } from "./battle-phase"; export class PartyHealPhase extends BattlePhase { @@ -28,7 +28,7 @@ export class PartyHealPhase extends BattlePhase { pokemon.updateInfo(true); } const healSong = globalScene.playSoundWithoutBgm("heal"); - globalScene.time.delayedCall(Utils.fixedInt(healSong.totalDuration * 1000), () => { + globalScene.time.delayedCall(fixedInt(healSong.totalDuration * 1000), () => { healSong.destroy(); if (this.resumeBgm && bgmPlaying) { globalScene.playBgm(); diff --git a/src/phases/pokemon-anim-phase.ts b/src/phases/pokemon-anim-phase.ts index b9c91508b5a..f0693a52aaa 100644 --- a/src/phases/pokemon-anim-phase.ts +++ b/src/phases/pokemon-anim-phase.ts @@ -8,18 +8,18 @@ import { Species } from "#enums/species"; export class PokemonAnimPhase extends BattlePhase { /** The type of animation to play in this phase */ - private key: PokemonAnimType; + protected key: PokemonAnimType; /** The Pokemon to which this animation applies */ - private pokemon: Pokemon; + protected pokemon: Pokemon; /** Any other field sprites affected by this animation */ - private fieldAssets: Phaser.GameObjects.Sprite[]; + protected fieldAssets: Phaser.GameObjects.Sprite[]; - constructor(key: PokemonAnimType, pokemon: Pokemon, fieldAssets?: Phaser.GameObjects.Sprite[]) { + constructor(key: PokemonAnimType, pokemon: Pokemon, fieldAssets: Phaser.GameObjects.Sprite[] = []) { super(); this.key = key; this.pokemon = pokemon; - this.fieldAssets = fieldAssets ?? []; + this.fieldAssets = fieldAssets; } start(): void { diff --git a/src/phases/pokemon-heal-phase.ts b/src/phases/pokemon-heal-phase.ts index ecfe99389eb..651c625b23a 100644 --- a/src/phases/pokemon-heal-phase.ts +++ b/src/phases/pokemon-heal-phase.ts @@ -8,7 +8,7 @@ import { getPokemonNameWithAffix } from "#app/messages"; import { HealingBoosterModifier } from "#app/modifier/modifier"; import { HealAchv } from "#app/system/achv"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { CommonAnimPhase } from "./common-anim-phase"; import { BattlerTagType } from "#app/enums/battler-tag-type"; import type { HealBlockTag } from "#app/data/battler-tags"; @@ -72,11 +72,11 @@ export class PokemonHealPhase extends CommonAnimPhase { return super.end(); } if (healOrDamage) { - const hpRestoreMultiplier = new Utils.NumberHolder(1); + const hpRestoreMultiplier = new NumberHolder(1); if (!this.revive) { globalScene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier); } - const healAmount = new Utils.NumberHolder(Math.floor(this.hpHealed * hpRestoreMultiplier.value)); + const healAmount = new NumberHolder(Math.floor(this.hpHealed * hpRestoreMultiplier.value)); if (healAmount.value < 0) { pokemon.damageAndUpdate(healAmount.value * -1, { result: HitResult.INDIRECT }); healAmount.value = 0; diff --git a/src/phases/pokemon-phase.ts b/src/phases/pokemon-phase.ts index 3ca5f09f953..8c30512cdc4 100644 --- a/src/phases/pokemon-phase.ts +++ b/src/phases/pokemon-phase.ts @@ -11,11 +11,14 @@ export abstract class PokemonPhase extends FieldPhase { constructor(battlerIndex?: BattlerIndex | number) { super(); - if (battlerIndex === undefined) { - battlerIndex = globalScene + battlerIndex = + battlerIndex ?? + globalScene .getField() - .find(p => p?.isActive())! - .getBattlerIndex(); // TODO: is the bang correct here? + .find(p => p?.isActive())! // TODO: is the bang correct here? + .getBattlerIndex(); + if (battlerIndex === undefined) { + console.warn("There are no Pokemon on the field!"); // TODO: figure out a suitable fallback behavior } this.battlerIndex = battlerIndex; diff --git a/src/phases/post-game-over-phase.ts b/src/phases/post-game-over-phase.ts index f86ec8496e0..753251e992f 100644 --- a/src/phases/post-game-over-phase.ts +++ b/src/phases/post-game-over-phase.ts @@ -4,12 +4,12 @@ import type { EndCardPhase } from "./end-card-phase"; import { TitlePhase } from "./title-phase"; export class PostGameOverPhase extends Phase { - private endCardPhase: EndCardPhase | null; + private endCardPhase?: EndCardPhase; constructor(endCardPhase?: EndCardPhase) { super(); - this.endCardPhase = endCardPhase!; // TODO: is this bang correct? + this.endCardPhase = endCardPhase; } start() { diff --git a/src/phases/post-turn-status-effect-phase.ts b/src/phases/post-turn-status-effect-phase.ts index f6341666e7e..619ef22d01e 100644 --- a/src/phases/post-turn-status-effect-phase.ts +++ b/src/phases/post-turn-status-effect-phase.ts @@ -13,7 +13,7 @@ import { getStatusEffectActivationText } from "#app/data/status-effect"; import { BattleSpec } from "#app/enums/battle-spec"; import { StatusEffect } from "#app/enums/status-effect"; import { getPokemonNameWithAffix } from "#app/messages"; -import * as Utils from "#app/utils"; +import { BooleanHolder, NumberHolder } from "#app/utils"; import { PokemonPhase } from "./pokemon-phase"; export class PostTurnStatusEffectPhase extends PokemonPhase { @@ -26,7 +26,7 @@ export class PostTurnStatusEffectPhase extends PokemonPhase { const pokemon = this.getPokemon(); if (pokemon?.isActive(true) && pokemon.status && pokemon.status.isPostTurn() && !pokemon.switchOutStatus) { pokemon.status.incrementTurn(); - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled); applyAbAttrs(BlockStatusDamageAbAttr, pokemon, cancelled); @@ -34,7 +34,7 @@ export class PostTurnStatusEffectPhase extends PokemonPhase { globalScene.queueMessage( getStatusEffectActivationText(pokemon.status.effect, getPokemonNameWithAffix(pokemon)), ); - const damage = new Utils.NumberHolder(0); + const damage = new NumberHolder(0); switch (pokemon.status.effect) { case StatusEffect.POISON: damage.value = Math.max(pokemon.getMaxHp() >> 3, 1); diff --git a/src/phases/reload-session-phase.ts b/src/phases/reload-session-phase.ts index 3a4a4e0e3a5..a7ac0002b03 100644 --- a/src/phases/reload-session-phase.ts +++ b/src/phases/reload-session-phase.ts @@ -1,15 +1,15 @@ import { globalScene } from "#app/global-scene"; import { Phase } from "#app/phase"; import { Mode } from "#app/ui/ui"; -import * as Utils from "#app/utils"; +import { fixedInt } from "#app/utils"; export class ReloadSessionPhase extends Phase { - private systemDataStr: string | null; + private systemDataStr?: string; constructor(systemDataStr?: string) { super(); - this.systemDataStr = systemDataStr ?? null; + this.systemDataStr = systemDataStr; } start(): void { @@ -18,7 +18,7 @@ export class ReloadSessionPhase extends Phase { let delayElapsed = false; let loaded = false; - globalScene.time.delayedCall(Utils.fixedInt(1500), () => { + globalScene.time.delayedCall(fixedInt(1500), () => { if (loaded) { this.end(); } else { diff --git a/src/phases/scan-ivs-phase.ts b/src/phases/scan-ivs-phase.ts index 2a2d68591ca..aaeeb7f84f8 100644 --- a/src/phases/scan-ivs-phase.ts +++ b/src/phases/scan-ivs-phase.ts @@ -8,6 +8,7 @@ import i18next from "i18next"; import { PokemonPhase } from "./pokemon-phase"; export class ScanIvsPhase extends PokemonPhase { + // biome-ignore lint/complexity/noUselessConstructor: This changes `battlerIndex` to be required constructor(battlerIndex: BattlerIndex) { super(battlerIndex); } @@ -24,7 +25,8 @@ export class ScanIvsPhase extends PokemonPhase { const uiTheme = globalScene.uiTheme; // Assuming uiTheme is accessible for (let e = 0; e < enemyField.length; e++) { enemyIvs = enemyField[e].ivs; - 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 + // we are using getRootSpeciesId() here because we want to check against the baby form, not the mid form if it exists + const currentIvs = globalScene.gameData.dexData[enemyField[e].species.getRootSpeciesId()].ivs; 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++) { diff --git a/src/phases/select-biome-phase.ts b/src/phases/select-biome-phase.ts index 6a11967832a..2d67cb87405 100644 --- a/src/phases/select-biome-phase.ts +++ b/src/phases/select-biome-phase.ts @@ -5,15 +5,11 @@ import { MoneyInterestModifier, MapModifier } from "#app/modifier/modifier"; import type { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; import { Mode } from "#app/ui/ui"; import { BattlePhase } from "./battle-phase"; -import * as Utils from "#app/utils"; +import { randSeedInt } from "#app/utils"; import { PartyHealPhase } from "./party-heal-phase"; import { SwitchBiomePhase } from "./switch-biome-phase"; export class SelectBiomePhase extends BattlePhase { - constructor() { - super(); - } - start() { super.start(); @@ -40,7 +36,7 @@ export class SelectBiomePhase extends BattlePhase { let biomes: Biome[] = []; globalScene.executeWithSeedOffset(() => { biomes = (biomeLinks[currentBiome] as (Biome | [Biome, number])[]) - .filter(b => !Array.isArray(b) || !Utils.randSeedInt(b[1])) + .filter(b => !Array.isArray(b) || !randSeedInt(b[1])) .map(b => (!Array.isArray(b) ? b : b[0])); }, globalScene.currentBattle.waveIndex); if (biomes.length > 1 && globalScene.findModifier(m => m instanceof MapModifier)) { @@ -51,7 +47,7 @@ export class SelectBiomePhase extends BattlePhase { ? [biomeLinks[currentBiome] as Biome] : (biomeLinks[currentBiome] as (Biome | [Biome, number])[]) ) - .filter((b, _i) => !Array.isArray(b) || !Utils.randSeedInt(b[1])) + .filter(b => !Array.isArray(b) || !randSeedInt(b[1])) .map(b => (Array.isArray(b) ? b[0] : b)); }, globalScene.currentBattle.waveIndex); const biomeSelectItems = biomeChoices.map(b => { @@ -70,7 +66,7 @@ export class SelectBiomePhase extends BattlePhase { delay: 1000, }); } else { - setNextBiome(biomes[Utils.randSeedInt(biomes.length)]); + setNextBiome(biomes[randSeedInt(biomes.length)]); } } else if (biomeLinks.hasOwnProperty(currentBiome)) { setNextBiome(biomeLinks[currentBiome] as Biome); diff --git a/src/phases/select-challenge-phase.ts b/src/phases/select-challenge-phase.ts index 2a6797d3556..5e6f20f93ee 100644 --- a/src/phases/select-challenge-phase.ts +++ b/src/phases/select-challenge-phase.ts @@ -3,10 +3,6 @@ import { Phase } from "#app/phase"; import { Mode } from "#app/ui/ui"; export class SelectChallengePhase extends Phase { - constructor() { - super(); - } - start() { super.start(); diff --git a/src/phases/select-gender-phase.ts b/src/phases/select-gender-phase.ts index 1c86536de53..4da60b38aa1 100644 --- a/src/phases/select-gender-phase.ts +++ b/src/phases/select-gender-phase.ts @@ -6,10 +6,6 @@ import { Mode } from "#app/ui/ui"; import i18next from "i18next"; export class SelectGenderPhase extends Phase { - constructor() { - super(); - } - start(): void { super.start(); diff --git a/src/phases/select-modifier-phase.ts b/src/phases/select-modifier-phase.ts index 11d448876d3..27ab7e374a2 100644 --- a/src/phases/select-modifier-phase.ts +++ b/src/phases/select-modifier-phase.ts @@ -26,7 +26,6 @@ import { SHOP_OPTIONS_ROW_LIMIT } from "#app/ui/modifier-select-ui-handler"; import PartyUiHandler, { PartyUiMode, PartyOption } from "#app/ui/party-ui-handler"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; -import * as Utils from "#app/utils"; import { BattlePhase } from "./battle-phase"; import Overrides from "#app/overrides"; import type { CustomModifierSettings } from "#app/modifier/modifier-type"; @@ -67,7 +66,7 @@ export class SelectModifierPhase extends BattlePhase { if (!this.isCopy) { regenerateModifierPoolThresholds(party, this.getPoolType(), this.rerollCount); } - const modifierCount = new Utils.NumberHolder(3); + const modifierCount = new NumberHolder(3); if (this.isPlayer()) { globalScene.applyModifiers(ExtraModifierModifier, true, modifierCount); globalScene.applyModifiers(TempExtraModifierModifier, true, modifierCount); diff --git a/src/phases/select-starter-phase.ts b/src/phases/select-starter-phase.ts index b3ebe6731c9..c6ded6be7af 100644 --- a/src/phases/select-starter-phase.ts +++ b/src/phases/select-starter-phase.ts @@ -15,10 +15,6 @@ import SoundFade from "phaser3-rex-plugins/plugins/soundfade"; import * as Utils from "../utils"; export class SelectStarterPhase extends Phase { - constructor() { - super(); - } - start() { super.start(); diff --git a/src/phases/select-target-phase.ts b/src/phases/select-target-phase.ts index 2042d0a3fcf..035eaff41fa 100644 --- a/src/phases/select-target-phase.ts +++ b/src/phases/select-target-phase.ts @@ -8,6 +8,7 @@ import i18next from "#app/plugins/i18n"; import { allMoves } from "#app/data/moves/move"; export class SelectTargetPhase extends PokemonPhase { + // biome-ignore lint/complexity/noUselessConstructor: This makes `fieldIndex` required constructor(fieldIndex: number) { super(fieldIndex); } diff --git a/src/phases/shiny-sparkle-phase.ts b/src/phases/shiny-sparkle-phase.ts index 2540d98fb79..87a7db29cf6 100644 --- a/src/phases/shiny-sparkle-phase.ts +++ b/src/phases/shiny-sparkle-phase.ts @@ -3,6 +3,7 @@ import type { BattlerIndex } from "#app/battle"; import { PokemonPhase } from "./pokemon-phase"; export class ShinySparklePhase extends PokemonPhase { + // biome-ignore lint/complexity/noUselessConstructor: This makes `battlerIndex` required constructor(battlerIndex: BattlerIndex) { super(battlerIndex); } diff --git a/src/phases/show-party-exp-bar-phase.ts b/src/phases/show-party-exp-bar-phase.ts index 568b8b615c8..139f4efcc49 100644 --- a/src/phases/show-party-exp-bar-phase.ts +++ b/src/phases/show-party-exp-bar-phase.ts @@ -2,7 +2,7 @@ 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"; -import * as Utils from "#app/utils"; +import { NumberHolder } from "#app/utils"; import { HidePartyExpBarPhase } from "./hide-party-exp-bar-phase"; import { LevelUpPhase } from "./level-up-phase"; import { PlayerPartyMemberPokemonPhase } from "./player-party-member-pokemon-phase"; @@ -20,7 +20,7 @@ export class ShowPartyExpBarPhase extends PlayerPartyMemberPokemonPhase { super.start(); const pokemon = this.getPokemon(); - const exp = new Utils.NumberHolder(this.expValue); + const exp = new NumberHolder(this.expValue); globalScene.applyModifiers(ExpBoosterModifier, true, exp); exp.value = Math.floor(exp.value); diff --git a/src/phases/show-trainer-phase.ts b/src/phases/show-trainer-phase.ts index 740c11f5c5d..b6c1e345c70 100644 --- a/src/phases/show-trainer-phase.ts +++ b/src/phases/show-trainer-phase.ts @@ -3,10 +3,6 @@ import { PlayerGender } from "#app/enums/player-gender"; import { BattlePhase } from "./battle-phase"; export class ShowTrainerPhase extends BattlePhase { - constructor() { - super(); - } - start() { super.start(); diff --git a/src/phases/summon-missing-phase.ts b/src/phases/summon-missing-phase.ts index 32bc7495dce..a692455ce47 100644 --- a/src/phases/summon-missing-phase.ts +++ b/src/phases/summon-missing-phase.ts @@ -4,10 +4,6 @@ import { SummonPhase } from "./summon-phase"; import { globalScene } from "#app/global-scene"; export class SummonMissingPhase extends SummonPhase { - constructor(fieldIndex: number) { - super(fieldIndex); - } - preSummon(): void { globalScene.ui.showText( i18next.t("battle:sendOutPokemon", { diff --git a/src/phases/switch-summon-phase.ts b/src/phases/switch-summon-phase.ts index 16868bf9bc0..e0903ada275 100644 --- a/src/phases/switch-summon-phase.ts +++ b/src/phases/switch-summon-phase.ts @@ -23,11 +23,11 @@ export class SwitchSummonPhase extends SummonPhase { /** * Constructor for creating a new SwitchSummonPhase - * @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 + * @param switchType - The type of switch behavior + * @param fieldIndex - Position on the battle field + * @param slotIndex - The index of pokemon (in party of 6) to switch into + * @param doReturn - Whether to render "comeback" dialogue + * @param player - (Optional) `true` if the switch is from the player */ constructor(switchType: SwitchType, fieldIndex: number, slotIndex: number, doReturn: boolean, player?: boolean) { super(fieldIndex, player !== undefined ? player : true); diff --git a/src/phases/test-message-phase.ts b/src/phases/test-message-phase.ts deleted file mode 100644 index d5e74efd490..00000000000 --- a/src/phases/test-message-phase.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { MessagePhase } from "./message-phase"; - -export class TestMessagePhase extends MessagePhase { - constructor(message: string) { - super(message, null, true); - } -} diff --git a/src/phases/title-phase.ts b/src/phases/title-phase.ts index dc455a0a62a..108366d4774 100644 --- a/src/phases/title-phase.ts +++ b/src/phases/title-phase.ts @@ -18,7 +18,7 @@ import { vouchers } from "#app/system/voucher"; import type { OptionSelectConfig, OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; import { SaveSlotUiMode } from "#app/ui/save-slot-select-ui-handler"; import { Mode } from "#app/ui/ui"; -import * as Utils from "#app/utils"; +import { isLocal, isLocalServerConnected, isNullOrUndefined } from "#app/utils"; import i18next from "i18next"; import { CheckSwitchPhase } from "./check-switch-phase"; import { EncounterPhase } from "./encounter-phase"; @@ -29,16 +29,10 @@ import { globalScene } from "#app/global-scene"; import Overrides from "#app/overrides"; export class TitlePhase extends Phase { - private loaded: boolean; + private loaded = false; private lastSessionData: SessionSaveData; public gameMode: GameModes; - constructor() { - super(); - - this.loaded = false; - } - start(): void { super.start(); @@ -282,7 +276,7 @@ export class TitlePhase extends Phase { }; // If Online, calls seed fetch from db to generate daily run. If Offline, generates a daily run based on current date. - if (!Utils.isLocal || Utils.isLocalServerConnected) { + if (!isLocal || isLocalServerConnected) { fetchDailyRunSeed() .then(seed => { if (seed) { @@ -296,7 +290,7 @@ export class TitlePhase extends Phase { }); } else { let seed: string = btoa(new Date().toISOString().substring(0, 10)); - if (!Utils.isNullOrUndefined(Overrides.DAILY_RUN_SEED_OVERRIDE)) { + if (!isNullOrUndefined(Overrides.DAILY_RUN_SEED_OVERRIDE)) { seed = Overrides.DAILY_RUN_SEED_OVERRIDE; } generateDaily(seed); diff --git a/src/phases/trainer-message-test-phase.ts b/src/phases/trainer-message-test-phase.ts deleted file mode 100644 index 23c2c86361c..00000000000 --- a/src/phases/trainer-message-test-phase.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { globalScene } from "#app/global-scene"; -import { trainerConfigs } from "#app/data/trainers/trainer-config"; -import type { TrainerType } from "#app/enums/trainer-type"; -import { BattlePhase } from "./battle-phase"; -import { TestMessagePhase } from "./test-message-phase"; - -export class TrainerMessageTestPhase extends BattlePhase { - private trainerTypes: TrainerType[]; - - constructor(...trainerTypes: TrainerType[]) { - super(); - - this.trainerTypes = trainerTypes; - } - - start() { - super.start(); - - const testMessages: string[] = []; - - for (const t of Object.keys(trainerConfigs)) { - const type = Number.parseInt(t); - if (this.trainerTypes.length && !this.trainerTypes.find(tt => tt === (type as TrainerType))) { - continue; - } - const config = trainerConfigs[type]; - [ - config.encounterMessages, - config.femaleEncounterMessages, - config.victoryMessages, - config.femaleVictoryMessages, - config.defeatMessages, - config.femaleDefeatMessages, - ].map(messages => { - if (messages?.length) { - testMessages.push(...messages); - } - }); - } - - for (const message of testMessages) { - globalScene.pushPhase(new TestMessagePhase(message)); - } - - this.end(); - } -} diff --git a/src/phases/trainer-victory-phase.ts b/src/phases/trainer-victory-phase.ts index a024885121f..637ddea8b56 100644 --- a/src/phases/trainer-victory-phase.ts +++ b/src/phases/trainer-victory-phase.ts @@ -3,7 +3,7 @@ import { TrainerType } from "#app/enums/trainer-type"; import { modifierTypes } from "#app/modifier/modifier-type"; import { vouchers } from "#app/system/voucher"; import i18next from "i18next"; -import * as Utils from "#app/utils"; +import { randSeedItem } from "#app/utils"; import { BattlePhase } from "./battle-phase"; import { ModifierRewardPhase } from "./modifier-reward-phase"; import { MoneyRewardPhase } from "./money-reward-phase"; @@ -14,10 +14,6 @@ import { achvs } from "#app/system/achv"; import { timedEventManager } from "#app/global-event-manager"; export class TrainerVictoryPhase extends BattlePhase { - constructor() { - super(); - } - start() { globalScene.disableMenu = true; @@ -82,7 +78,7 @@ export class TrainerVictoryPhase extends BattlePhase { const victoryMessages = globalScene.currentBattle.trainer?.getVictoryMessages()!; // TODO: is this bang correct? let message: string; globalScene.executeWithSeedOffset( - () => (message = Utils.randSeedItem(victoryMessages)), + () => (message = randSeedItem(victoryMessages)), globalScene.currentBattle.waveIndex, ); message = message!; // tell TS compiler it's defined now diff --git a/src/phases/turn-end-phase.ts b/src/phases/turn-end-phase.ts index ddfc0955508..9b84ea05e58 100644 --- a/src/phases/turn-end-phase.ts +++ b/src/phases/turn-end-phase.ts @@ -18,10 +18,6 @@ import { PokemonHealPhase } from "./pokemon-heal-phase"; import { globalScene } from "#app/global-scene"; export class TurnEndPhase extends FieldPhase { - constructor() { - super(); - } - start() { super.start(); diff --git a/src/phases/turn-init-phase.ts b/src/phases/turn-init-phase.ts index 3104b65eb3f..0c110024af7 100644 --- a/src/phases/turn-init-phase.ts +++ b/src/phases/turn-init-phase.ts @@ -15,10 +15,6 @@ import { TurnStartPhase } from "./turn-start-phase"; import { globalScene } from "#app/global-scene"; export class TurnInitPhase extends FieldPhase { - constructor() { - super(); - } - start() { super.start(); diff --git a/src/phases/turn-start-phase.ts b/src/phases/turn-start-phase.ts index 34dd7df3e89..d5b4160fe1b 100644 --- a/src/phases/turn-start-phase.ts +++ b/src/phases/turn-start-phase.ts @@ -6,7 +6,7 @@ import type Pokemon from "#app/field/pokemon"; import { PokemonMove } from "#app/field/pokemon"; import { BypassSpeedChanceModifier } from "#app/modifier/modifier"; import { Command } from "#app/ui/command-ui-handler"; -import * as Utils from "#app/utils"; +import { randSeedShuffle, BooleanHolder } from "#app/utils"; import { AttemptCapturePhase } from "./attempt-capture-phase"; import { AttemptRunPhase } from "./attempt-run-phase"; import { BerryPhase } from "./berry-phase"; @@ -24,10 +24,6 @@ import { globalScene } from "#app/global-scene"; import { TeraPhase } from "./tera-phase"; export class TurnStartPhase extends FieldPhase { - constructor() { - super(); - } - /** * This orders the active Pokemon on the field by speed into an BattlerIndex array and returns that array. * It also checks for Trick Room and reverses the array if it is present. @@ -43,14 +39,14 @@ export class TurnStartPhase extends FieldPhase { // was varying based on how long since you last reloaded globalScene.executeWithSeedOffset( () => { - orderedTargets = Utils.randSeedShuffle(orderedTargets); + orderedTargets = randSeedShuffle(orderedTargets); }, globalScene.currentBattle.turn, globalScene.waveSeed, ); // Next, a check for Trick Room is applied to determine sort order. - const speedReversed = new Utils.BooleanHolder(false); + const speedReversed = new BooleanHolder(false); globalScene.arena.applyTags(TrickRoomTag, false, speedReversed); // Adjust the sort function based on whether Trick Room is active. @@ -80,8 +76,8 @@ export class TurnStartPhase extends FieldPhase { .getField(true) .filter(p => p.summonData) .map(p => { - const bypassSpeed = new Utils.BooleanHolder(false); - const canCheckHeldItems = new Utils.BooleanHolder(true); + const bypassSpeed = new BooleanHolder(false); + const canCheckHeldItems = new BooleanHolder(true); applyAbAttrs(BypassSpeedChanceAbAttr, p, null, false, bypassSpeed); applyAbAttrs(PreventBypassSpeedChanceAbAttr, p, null, false, bypassSpeed, canCheckHeldItems); if (canCheckHeldItems.value) { diff --git a/src/phases/unavailable-phase.ts b/src/phases/unavailable-phase.ts index c0b5d4224c5..33042739971 100644 --- a/src/phases/unavailable-phase.ts +++ b/src/phases/unavailable-phase.ts @@ -4,10 +4,6 @@ import { Mode } from "#app/ui/ui"; import { LoginPhase } from "./login-phase"; export class UnavailablePhase extends Phase { - constructor() { - super(); - } - start(): void { globalScene.ui.setMode(Mode.UNAVAILABLE, () => { globalScene.unshiftPhase(new LoginPhase(true)); diff --git a/src/phases/weather-effect-phase.ts b/src/phases/weather-effect-phase.ts index d7a1f193029..5284c9fba85 100644 --- a/src/phases/weather-effect-phase.ts +++ b/src/phases/weather-effect-phase.ts @@ -15,7 +15,7 @@ import { BattlerTagType } from "#app/enums/battler-tag-type"; import { WeatherType } from "#app/enums/weather-type"; import type Pokemon from "#app/field/pokemon"; import { HitResult } from "#app/field/pokemon"; -import * as Utils from "#app/utils"; +import { BooleanHolder, toDmgValue } from "#app/utils"; import { CommonAnimPhase } from "./common-anim-phase"; export class WeatherEffectPhase extends CommonAnimPhase { @@ -35,14 +35,13 @@ export class WeatherEffectPhase extends CommonAnimPhase { this.weather = globalScene?.arena?.weather; if (!this.weather) { - this.end(); - return; + return this.end(); } this.setAnimation(CommonAnim.SUNNY + (this.weather.weatherType - 1)); if (this.weather.isDamaging()) { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); this.executeForAll((pokemon: Pokemon) => applyPreWeatherEffectAbAttrs(SuppressWeatherEffectAbAttr, pokemon, this.weather, cancelled), @@ -50,7 +49,7 @@ export class WeatherEffectPhase extends CommonAnimPhase { if (!cancelled.value) { const inflictDamage = (pokemon: Pokemon) => { - const cancelled = new Utils.BooleanHolder(false); + const cancelled = new BooleanHolder(false); applyPreWeatherEffectAbAttrs(PreWeatherDamageAbAttr, pokemon, this.weather, cancelled); applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled); @@ -63,9 +62,9 @@ export class WeatherEffectPhase extends CommonAnimPhase { return; } - const damage = Utils.toDmgValue(pokemon.getMaxHp() / 16); + const damage = toDmgValue(pokemon.getMaxHp() / 16); - globalScene.queueMessage(getWeatherDamageMessage(this.weather?.weatherType!, pokemon)!); // TODO: are those bangs correct? + globalScene.queueMessage(getWeatherDamageMessage(this.weather!.weatherType, pokemon) ?? ""); pokemon.damageAndUpdate(damage, { result: HitResult.INDIRECT, ignoreSegments: true }); };