[Refactor] Remove isNullOrUndefined in favor of loose check against null (#6549)

* Remove `isNullOrUndefined` in favor of loose check against null

* Fix missing method call

* Remove isNullOrUndefined import
This commit is contained in:
Sirz Benjie 2025-09-12 14:53:27 -05:00 committed by GitHub
parent a6fb32b32b
commit c7a2c666af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
62 changed files with 315 additions and 410 deletions

View File

@ -138,7 +138,6 @@ import {
formatMoney,
getIvsFromId,
isBetween,
isNullOrUndefined,
NumberHolder,
randomString,
randSeedInt,
@ -867,7 +866,7 @@ export class BattleScene extends SceneBase {
* this is weird and causes a lot of random jank
*/
getPokemonById(pokemonId: number | undefined): Pokemon | null {
if (isNullOrUndefined(pokemonId)) {
if (pokemonId == null) {
return null;
}
@ -1319,7 +1318,7 @@ export class BattleScene extends SceneBase {
if (
!this.gameMode.hasTrainers
|| Overrides.BATTLE_TYPE_OVERRIDE === BattleType.WILD
|| (Overrides.DISABLE_STANDARD_TRAINERS_OVERRIDE && isNullOrUndefined(trainerData))
|| (Overrides.DISABLE_STANDARD_TRAINERS_OVERRIDE && trainerData == null)
) {
newBattleType = BattleType.WILD;
} else {
@ -1383,7 +1382,7 @@ export class BattleScene extends SceneBase {
newDouble = false;
}
if (!isNullOrUndefined(Overrides.BATTLE_STYLE_OVERRIDE)) {
if (Overrides.BATTLE_STYLE_OVERRIDE != null) {
let doubleOverrideForWave: "single" | "double" | null = null;
switch (Overrides.BATTLE_STYLE_OVERRIDE) {
@ -1572,7 +1571,7 @@ export class BattleScene extends SceneBase {
// Give trainers with specialty types an appropriately-typed form for Wormadam, Rotom, Arceus, Oricorio, Silvally, or Paldean Tauros.
!isEggPhase
&& this.currentBattle?.battleType === BattleType.TRAINER
&& !isNullOrUndefined(this.currentBattle.trainer)
&& this.currentBattle.trainer != null
&& this.currentBattle.trainer.config.hasSpecialtyType()
) {
if (species.speciesId === SpeciesId.WORMADAM) {
@ -2692,7 +2691,7 @@ export class BattleScene extends SceneBase {
}
} else if (modifier instanceof FusePokemonModifier) {
args.push(this.getPokemonById(modifier.fusePokemonId) as PlayerPokemon);
} else if (modifier instanceof RememberMoveModifier && !isNullOrUndefined(cost)) {
} else if (modifier instanceof RememberMoveModifier && cost != null) {
args.push(cost);
}
@ -3007,7 +3006,7 @@ export class BattleScene extends SceneBase {
}
if (
modifier instanceof PokemonHeldItemModifier
&& !isNullOrUndefined(modifier.getSpecies())
&& modifier.getSpecies() != null
&& !this.getPokemonById(modifier.pokemonId)?.hasSpecies(modifier.getSpecies()!)
) {
modifiers.splice(m--, 1);
@ -3573,7 +3572,7 @@ export class BattleScene extends SceneBase {
// Loading override or session encounter
let encounter: MysteryEncounter | null;
if (
!isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_OVERRIDE)
Overrides.MYSTERY_ENCOUNTER_OVERRIDE != null
&& allMysteryEncounters.hasOwnProperty(Overrides.MYSTERY_ENCOUNTER_OVERRIDE)
) {
encounter = allMysteryEncounters[Overrides.MYSTERY_ENCOUNTER_OVERRIDE];
@ -3584,7 +3583,7 @@ export class BattleScene extends SceneBase {
encounter = allMysteryEncounters[encounterType ?? -1];
return encounter;
} else {
encounter = !isNullOrUndefined(encounterType) ? allMysteryEncounters[encounterType] : null;
encounter = encounterType != null ? allMysteryEncounters[encounterType] : null;
}
// Check for queued encounters first
@ -3643,7 +3642,7 @@ export class BattleScene extends SceneBase {
? MysteryEncounterTier.ULTRA
: MysteryEncounterTier.ROGUE;
if (!isNullOrUndefined(Overrides.MYSTERY_ENCOUNTER_TIER_OVERRIDE)) {
if (Overrides.MYSTERY_ENCOUNTER_TIER_OVERRIDE != null) {
tier = Overrides.MYSTERY_ENCOUNTER_TIER_OVERRIDE;
}

View File

@ -67,7 +67,6 @@ import type { Constructor } from "#utils/common";
import {
BooleanHolder,
coerceArray,
isNullOrUndefined,
NumberHolder,
randSeedFloat,
randSeedInt,
@ -1040,7 +1039,7 @@ export class PostDefendStatStageChangeAbAttr extends PostDefendAbAttr {
if (this.allOthers) {
const ally = pokemon.getAlly();
const otherPokemon = !isNullOrUndefined(ally) ? pokemon.getOpponents().concat([ally]) : pokemon.getOpponents();
const otherPokemon = ally != null ? pokemon.getOpponents().concat([ally]) : pokemon.getOpponents();
for (const other of otherPokemon) {
globalScene.phaseManager.unshiftNew(
"StatStageChangePhase",
@ -1473,7 +1472,7 @@ export class PostDefendMoveDisableAbAttr extends PostDefendAbAttr {
override canApply({ move, opponent: attacker, pokemon }: PostMoveInteractionAbAttrParams): boolean {
return (
isNullOrUndefined(attacker.getTag(BattlerTagType.DISABLED))
attacker.getTag(BattlerTagType.DISABLED) == null
&& move.doesFlagEffectApply({ flag: MoveFlags.MAKES_CONTACT, user: attacker, target: pokemon })
&& (this.chance === -1 || pokemon.randBattleSeedInt(100) < this.chance)
);
@ -2810,7 +2809,7 @@ export class PostSummonAllyHealAbAttr extends PostSummonAbAttr {
override apply({ pokemon, simulated }: AbAttrBaseParams): void {
const target = pokemon.getAlly();
if (!simulated && !isNullOrUndefined(target)) {
if (!simulated && target != null) {
globalScene.phaseManager.unshiftNew(
"PokemonHealPhase",
target.getBattlerIndex(),
@ -2841,7 +2840,7 @@ export class PostSummonClearAllyStatStagesAbAttr extends PostSummonAbAttr {
override apply({ pokemon, simulated }: AbAttrBaseParams): void {
const target = pokemon.getAlly();
if (!simulated && !isNullOrUndefined(target)) {
if (!simulated && target != null) {
for (const s of BATTLE_STATS) {
target.setStatStage(s, 0);
}
@ -2960,13 +2959,13 @@ export class PostSummonHealStatusAbAttr extends PostSummonRemoveEffectAbAttr {
public override canApply({ pokemon }: AbAttrBaseParams): boolean {
const status = pokemon.status?.effect;
return !isNullOrUndefined(status) && (this.immuneEffects.length === 0 || this.immuneEffects.includes(status));
return status != null && (this.immuneEffects.length === 0 || this.immuneEffects.includes(status));
}
public override apply({ pokemon }: AbAttrBaseParams): void {
// TODO: should probably check against simulated...
const status = pokemon.status?.effect;
if (!isNullOrUndefined(status)) {
if (status != null) {
this.statusHealed = status;
pokemon.resetStatus(false);
pokemon.updateInfo();
@ -3102,7 +3101,7 @@ export class PostSummonCopyAllyStatsAbAttr extends PostSummonAbAttr {
}
const ally = pokemon.getAlly();
return !(isNullOrUndefined(ally) || ally.getStatStages().every(s => s === 0));
return !(ally == null || ally.getStatStages().every(s => s === 0));
}
override apply({ pokemon, simulated }: AbAttrBaseParams): void {
@ -3110,7 +3109,7 @@ export class PostSummonCopyAllyStatsAbAttr extends PostSummonAbAttr {
return;
}
const ally = pokemon.getAlly();
if (!isNullOrUndefined(ally)) {
if (ally != null) {
for (const s of BATTLE_STATS) {
pokemon.setStatStage(s, ally.getStatStage(s));
}
@ -3240,7 +3239,7 @@ export class CommanderAbAttr extends AbAttr {
const ally = pokemon.getAlly();
return (
globalScene.currentBattle?.double
&& !isNullOrUndefined(ally)
&& ally != null
&& ally.species.speciesId === SpeciesId.DONDOZO
&& !(ally.isFainted() || ally.getTag(BattlerTagType.COMMANDED))
);
@ -3284,7 +3283,7 @@ export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr {
}
override canApply({ pokemon }: AbAttrBaseParams): boolean {
return !isNullOrUndefined(pokemon.status);
return pokemon.status != null;
}
override apply({ pokemon, simulated }: AbAttrBaseParams): void {
@ -3564,7 +3563,7 @@ export class ProtectStatAbAttr extends PreStatStageChangeAbAttr {
}
override canApply({ stat, cancelled }: PreStatStageChangeAbAttrParams): boolean {
return !cancelled.value && (isNullOrUndefined(this.protectedStat) || stat === this.protectedStat);
return !cancelled.value && (this.protectedStat == null || stat === this.protectedStat);
}
/**
@ -3800,11 +3799,7 @@ export class ConditionalUserFieldProtectStatAbAttr extends PreStatStageChangeAbA
if (!target) {
return false;
}
return (
!cancelled.value
&& (isNullOrUndefined(this.protectedStat) || stat === this.protectedStat)
&& this.condition(target)
);
return !cancelled.value && (this.protectedStat == null || stat === this.protectedStat) && this.condition(target);
}
/**
@ -4561,7 +4556,7 @@ export class PostTurnStatusHealAbAttr extends PostTurnAbAttr {
}
override canApply({ pokemon }: AbAttrBaseParams): boolean {
return !isNullOrUndefined(pokemon.status) && this.effects.includes(pokemon.status.effect) && !pokemon.isFullHp();
return pokemon.status != null && this.effects.includes(pokemon.status.effect) && !pokemon.isFullHp();
}
override apply({ simulated, passive, pokemon }: AbAttrBaseParams): void {
@ -4896,7 +4891,7 @@ export class PostTurnHurtIfSleepingAbAttr extends PostTurnAbAttr {
*/
export class FetchBallAbAttr extends PostTurnAbAttr {
override canApply({ simulated, pokemon }: AbAttrBaseParams): boolean {
return !simulated && !isNullOrUndefined(globalScene.currentBattle.lastUsedPokeball) && !!pokemon.isPlayer;
return !simulated && globalScene.currentBattle.lastUsedPokeball != null && !!pokemon.isPlayer;
}
/**
@ -6261,7 +6256,7 @@ class ForceSwitchOutHelper {
true,
500,
);
if (globalScene.currentBattle.double && !isNullOrUndefined(allyPokemon)) {
if (globalScene.currentBattle.double && allyPokemon != null) {
globalScene.redirectPokemonMoves(switchOutTarget, allyPokemon);
}
}
@ -7113,7 +7108,7 @@ export function initAbilities() {
.attr(PostDefendMoveDisableAbAttr, 30)
.bypassFaint(),
new Ability(AbilityId.HEALER, 5)
.conditionalAttr(pokemon => !isNullOrUndefined(pokemon.getAlly()) && randSeedInt(10) < 3, PostTurnResetStatusAbAttr, true),
.conditionalAttr(pokemon => pokemon.getAlly() != null && randSeedInt(10) < 3, PostTurnResetStatusAbAttr, true),
new Ability(AbilityId.FRIEND_GUARD, 5)
.attr(AlliedFieldDamageReductionAbAttr, 0.75)
.ignorable(),

View File

@ -14,7 +14,7 @@ import { TimeOfDay } from "#enums/time-of-day";
import { WeatherType } from "#enums/weather-type";
import type { Pokemon } from "#field/pokemon";
import type { SpeciesStatBoosterItem, SpeciesStatBoosterModifierType } from "#modifiers/modifier-type";
import { coerceArray, isNullOrUndefined, randSeedInt } from "#utils/common";
import { coerceArray, randSeedInt } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import { toCamelCase } from "#utils/strings";
import i18next from "i18next";
@ -128,7 +128,7 @@ export class SpeciesEvolutionCondition {
}
public get description(): string[] {
if (!isNullOrUndefined(this.desc)) {
if (this.desc != null) {
return this.desc;
}
this.desc = this.data.map(cond => {
@ -161,7 +161,7 @@ export class SpeciesEvolutionCondition {
case EvoCondKey.HELD_ITEM:
return i18next.t(`pokemonEvolutions:heldItem.${toCamelCase(cond.itemKey)}`);
}
}).filter(s => !isNullOrUndefined(s)); // Filter out stringless conditions
}).filter(s => s != null); // Filter out stringless conditions
return this.desc;
}
@ -233,7 +233,7 @@ export class SpeciesFormEvolution {
this.evoFormKey = evoFormKey;
this.level = level;
this.item = item || EvolutionItem.NONE;
if (!isNullOrUndefined(condition)) {
if (condition != null) {
this.condition = new SpeciesEvolutionCondition(...coerceArray(condition));
}
this.wildDelay = wildDelay ?? SpeciesWildEvolutionDelay.NONE;
@ -291,8 +291,8 @@ export class SpeciesFormEvolution {
return (
pokemon.level >= this.level &&
// Check form key, using the fusion's form key if we're checking the fusion
(isNullOrUndefined(this.preFormKey) || (forFusion ? pokemon.getFusionFormKey() : pokemon.getFormKey()) === this.preFormKey) &&
(isNullOrUndefined(this.condition) || this.condition.conditionsFulfilled(pokemon)) &&
(this.preFormKey == null || (forFusion ? pokemon.getFusionFormKey() : pokemon.getFormKey()) === this.preFormKey) &&
(this.condition == null || this.condition.conditionsFulfilled(pokemon)) &&
((item ?? EvolutionItem.NONE) === (this.item ?? EvolutionItem.NONE))
);
}
@ -305,11 +305,11 @@ export class SpeciesFormEvolution {
*/
public isValidItemEvolution(pokemon: Pokemon, forFusion = false): boolean {
return (
!isNullOrUndefined(this.item) &&
this.item != null &&
pokemon.level >= this.level &&
// Check form key, using the fusion's form key if we're checking the fusion
(isNullOrUndefined(this.preFormKey) || (forFusion ? pokemon.getFusionFormKey() : pokemon.getFormKey()) === this.preFormKey) &&
(isNullOrUndefined(this.condition) || this.condition.conditionsFulfilled(pokemon))
(this.preFormKey == null || (forFusion ? pokemon.getFusionFormKey() : pokemon.getFormKey()) === this.preFormKey) &&
(this.condition == null || this.condition.conditionsFulfilled(pokemon))
);
}

View File

@ -7,7 +7,7 @@ import { AnimBlendType, AnimFocus, AnimFrameTarget, ChargeAnim, CommonAnim } fro
import { MoveFlags } from "#enums/move-flags";
import { MoveId } from "#enums/move-id";
import type { Pokemon } from "#field/pokemon";
import { coerceArray, getFrameMs, isNullOrUndefined, type nil } from "#utils/common";
import { coerceArray, getFrameMs, type nil } from "#utils/common";
import { getEnumKeys, getEnumValues } from "#utils/enums";
import { toKebabCase } from "#utils/strings";
import Phaser from "phaser";
@ -388,7 +388,7 @@ class AnimTimedAddBgEvent extends AnimTimedBgEvent {
moveAnim.bgSprite.setAlpha(this.opacity / 255);
globalScene.field.add(moveAnim.bgSprite);
const fieldPokemon = globalScene.getEnemyPokemon(false) ?? globalScene.getPlayerPokemon(false);
if (!isNullOrUndefined(priority)) {
if (priority != null) {
globalScene.field.moveTo(moveAnim.bgSprite as Phaser.GameObjects.GameObject, priority);
} else if (fieldPokemon?.isOnField()) {
globalScene.field.moveBelow(moveAnim.bgSprite as Phaser.GameObjects.GameObject, fieldPokemon);
@ -524,7 +524,7 @@ export async function initEncounterAnims(encounterAnim: EncounterAnim | Encounte
const encounterAnimNames = getEnumKeys(EncounterAnim);
const encounterAnimFetches: Promise<Map<EncounterAnim, AnimConfig>>[] = [];
for (const anim of anims) {
if (encounterAnims.has(anim) && !isNullOrUndefined(encounterAnims.get(anim))) {
if (encounterAnims.has(anim) && encounterAnims.get(anim) != null) {
continue;
}
encounterAnimFetches.push(
@ -1240,7 +1240,7 @@ export abstract class BattleAnim {
const graphicIndex = graphicFrameCount++;
const moveSprite = sprites[graphicIndex];
if (!isNullOrUndefined(frame.priority)) {
if (frame.priority != null) {
const setSpritePriority = (priority: number) => {
if (existingFieldSprites.length > priority) {
// Move to specified priority index

View File

@ -49,7 +49,7 @@ import type {
TypeBoostTagType,
} from "#types/battler-tags";
import type { Mutable } from "#types/type-helpers";
import { BooleanHolder, coerceArray, getFrameMs, isNullOrUndefined, NumberHolder, toDmgValue } from "#utils/common";
import { BooleanHolder, coerceArray, getFrameMs, NumberHolder, toDmgValue } from "#utils/common";
import { toCamelCase } from "#utils/strings";
/**
@ -378,7 +378,7 @@ export class DisabledTag extends MoveRestrictionBattlerTag {
// Disable fails against struggle or an empty move history
// TODO: Confirm if this is redundant given Disable/Cursed Body's disable conditions
const move = pokemon.getLastNonVirtualMove();
if (isNullOrUndefined(move) || move.move === MoveId.STRUGGLE) {
if (move == null || move.move === MoveId.STRUGGLE) {
return;
}
@ -451,7 +451,7 @@ export class GorillaTacticsTag extends MoveRestrictionBattlerTag {
override canAdd(pokemon: Pokemon): boolean {
// Choice items ignore struggle, so Gorilla Tactics should too
const lastSelectedMove = pokemon.getLastNonVirtualMove();
return !isNullOrUndefined(lastSelectedMove) && lastSelectedMove.move !== MoveId.STRUGGLE;
return lastSelectedMove != null && lastSelectedMove.move !== MoveId.STRUGGLE;
}
/**
@ -1305,7 +1305,7 @@ export class EncoreTag extends MoveRestrictionBattlerTag {
override lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
if (lapseType === BattlerTagLapseType.CUSTOM) {
const encoredMove = pokemon.getMoveset().find(m => m.moveId === this.moveId);
return !isNullOrUndefined(encoredMove) && encoredMove.getPpRatio() > 0;
return encoredMove != null && encoredMove.getPpRatio() > 0;
}
return super.lapse(pokemon, lapseType);
}

View File

@ -7,7 +7,7 @@ import { BiomeId } from "#enums/biome-id";
import { PartyMemberStrength } from "#enums/party-member-strength";
import { SpeciesId } from "#enums/species-id";
import type { Starter } from "#ui/starter-select-ui-handler";
import { isNullOrUndefined, randSeedGauss, randSeedInt, randSeedItem } from "#utils/common";
import { randSeedGauss, randSeedInt, randSeedItem } from "#utils/common";
import { getEnumValues } from "#utils/enums";
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
@ -32,7 +32,7 @@ export function getDailyRunStarters(seed: string): Starter[] {
const startingLevel = globalScene.gameMode.getStartingLevel();
const eventStarters = getDailyEventSeedStarters(seed);
if (!isNullOrUndefined(eventStarters)) {
if (eventStarters != null) {
starters.push(...eventStarters);
return;
}
@ -127,7 +127,7 @@ const dailyBiomeWeights: BiomeWeights = {
export function getDailyStartingBiome(): BiomeId {
const eventBiome = getDailyEventSeedBiome(globalScene.seed);
if (!isNullOrUndefined(eventBiome)) {
if (eventBiome != null) {
return eventBiome;
}

View File

@ -7,7 +7,7 @@ import { PokemonType } from "#enums/pokemon-type";
import type { Pokemon } from "#field/pokemon";
import { applyMoveAttrs } from "#moves/apply-attrs";
import type { Move, MoveTargetSet, UserMoveConditionFunc } from "#moves/move";
import { isNullOrUndefined, NumberHolder } from "#utils/common";
import { NumberHolder } from "#utils/common";
/**
* Return whether the move targets the field
@ -78,7 +78,7 @@ export function getMoveTargets(user: Pokemon, move: MoveId, replaceTarget?: Move
case MoveTarget.OTHER:
case MoveTarget.ALL_NEAR_OTHERS:
case MoveTarget.ALL_OTHERS:
set = !isNullOrUndefined(ally) ? opponents.concat([ally]) : opponents;
set = ally != null ? opponents.concat([ally]) : opponents;
multiple = moveTarget === MoveTarget.ALL_NEAR_OTHERS || moveTarget === MoveTarget.ALL_OTHERS;
break;
case MoveTarget.NEAR_ENEMY:
@ -95,22 +95,22 @@ export function getMoveTargets(user: Pokemon, move: MoveId, replaceTarget?: Move
return { targets: [-1 as BattlerIndex], multiple: false };
case MoveTarget.NEAR_ALLY:
case MoveTarget.ALLY:
set = !isNullOrUndefined(ally) ? [ally] : [];
set = ally != null ? [ally] : [];
break;
case MoveTarget.USER_OR_NEAR_ALLY:
case MoveTarget.USER_AND_ALLIES:
case MoveTarget.USER_SIDE:
set = !isNullOrUndefined(ally) ? [user, ally] : [user];
set = ally != null ? [user, ally] : [user];
multiple = moveTarget !== MoveTarget.USER_OR_NEAR_ALLY;
break;
case MoveTarget.ALL:
case MoveTarget.BOTH_SIDES:
set = (!isNullOrUndefined(ally) ? [user, ally] : [user]).concat(opponents);
set = (ally != null ? [user, ally] : [user]).concat(opponents);
multiple = true;
break;
case MoveTarget.CURSE:
{
const extraTargets = !isNullOrUndefined(ally) ? [ally] : [];
const extraTargets = ally != null ? [ally] : [];
set = user.getTypes(true).includes(PokemonType.GHOST) ? opponents.concat(extraTargets) : [user];
}
break;

View File

@ -88,7 +88,7 @@ import type { AttackMoveResult } from "#types/attack-move-result";
import type { Localizable } from "#types/locales";
import type { ChargingMove, MoveAttrMap, MoveAttrString, MoveClassMap, MoveKindString, MoveMessageFunc } from "#types/move-types";
import type { TurnMove } from "#types/turn-move";
import { BooleanHolder, coerceArray, type Constructor, isNullOrUndefined, NumberHolder, randSeedFloat, randSeedInt, randSeedItem, toDmgValue } from "#utils/common";
import { BooleanHolder, coerceArray, type Constructor, NumberHolder, randSeedFloat, randSeedInt, randSeedItem, toDmgValue } from "#utils/common";
import { getEnumValues } from "#utils/enums";
import { toCamelCase, toTitleCase } from "#utils/strings";
import i18next from "i18next";
@ -835,7 +835,7 @@ export abstract class Move implements Localizable {
applyAbAttrs("VariableMovePowerAbAttr", abAttrParams);
const ally = source.getAlly();
if (!isNullOrUndefined(ally)) {
if (ally != null) {
applyAbAttrs("AllyMoveCategoryPowerBoostAbAttr", {...abAttrParams, pokemon: ally});
}
@ -965,7 +965,7 @@ export abstract class Move implements Localizable {
// ...and cannot enhance Pollen Puff when targeting an ally.
const ally = user.getAlly();
const exceptPollenPuffAlly: boolean = this.id === MoveId.POLLEN_PUFF && !isNullOrUndefined(ally) && targets.includes(ally.getBattlerIndex())
const exceptPollenPuffAlly: boolean = this.id === MoveId.POLLEN_PUFF && ally != null && targets.includes(ally.getBattlerIndex())
return (!restrictSpread || !isMultiTarget)
&& !this.isChargingMove()
@ -2114,7 +2114,7 @@ export class FlameBurstAttr extends MoveEffectAttr {
const targetAlly = target.getAlly();
const cancelled = new BooleanHolder(false);
if (!isNullOrUndefined(targetAlly)) {
if (targetAlly != null) {
applyAbAttrs("BlockNonDirectDamageAbAttr", {pokemon: targetAlly, cancelled});
}
@ -2127,7 +2127,7 @@ export class FlameBurstAttr extends MoveEffectAttr {
}
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number {
return !isNullOrUndefined(target.getAlly()) ? -5 : 0;
return target.getAlly() != null ? -5 : 0;
}
}
@ -3156,7 +3156,7 @@ export class WeatherInstantChargeAttr extends InstantChargeAttr {
super((user, move) => {
const currentWeather = globalScene.arena.weather;
if (isNullOrUndefined(currentWeather?.weatherType)) {
if (currentWeather?.weatherType == null) {
return false;
} else {
return !currentWeather?.isEffectSuppressed()
@ -6293,7 +6293,7 @@ export class RevivalBlessingAttr extends MoveEffectAttr {
pokemon.heal(Math.min(toDmgValue(0.5 * pokemon.getMaxHp()), pokemon.getMaxHp()));
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:revivalBlessing", { pokemonName: getPokemonNameWithAffix(pokemon) }), 0, true);
const allyPokemon = user.getAlly();
if (globalScene.currentBattle.double && globalScene.getEnemyParty().length > 1 && !isNullOrUndefined(allyPokemon)) {
if (globalScene.currentBattle.double && globalScene.getEnemyParty().length > 1 && allyPokemon != null) {
// Handle cases where revived pokemon needs to get switched in on same turn
if (allyPokemon.isFainted() || allyPokemon === pokemon) {
// Enemy switch phase should be removed and replaced with the revived pkmn switching in
@ -6462,7 +6462,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:fled", { pokemonName: getPokemonNameWithAffix(switchOutTarget) }), null, true, 500);
// in double battles redirect potential moves off fled pokemon
if (globalScene.currentBattle.double && !isNullOrUndefined(allyPokemon)) {
if (globalScene.currentBattle.double && allyPokemon != null) {
globalScene.redirectPokemonMoves(switchOutTarget, allyPokemon);
}
}
@ -7122,7 +7122,7 @@ export class CopyMoveAttr extends CallMoveAttr {
getCondition(): MoveConditionFunc {
return (_user, target, _move) => {
const lastMove = this.mirrorMove ? target.getLastNonVirtualMove(false, false)?.move : globalScene.currentBattle.lastMove;
return !isNullOrUndefined(lastMove) && !this.invalidMoves.has(lastMove);
return lastMove != null && !this.invalidMoves.has(lastMove);
};
}
}
@ -7169,7 +7169,7 @@ export class RepeatMoveAttr extends MoveEffectAttr {
&& firstTarget !== target.getAlly()
) {
const ally = firstTarget.getAlly();
if (!isNullOrUndefined(ally) && ally.isActive()) {
if (ally != null && ally.isActive()) {
moveTargets = [ ally.getBattlerIndex() ];
}
}
@ -7476,7 +7476,7 @@ export class SketchAttr extends MoveEffectAttr {
}
const targetMove = target.getLastNonVirtualMove();
return !isNullOrUndefined(targetMove)
return targetMove != null
&& !invalidSketchMoves.has(targetMove.move)
&& user.getMoveset().every(m => m.moveId !== targetMove.move)
};
@ -7533,7 +7533,7 @@ export class AbilityCopyAttr extends MoveEffectAttr {
user.setTempAbility(target.getAbility());
const ally = user.getAlly();
if (this.copyToPartner && globalScene.currentBattle?.double && !isNullOrUndefined(ally) && ally.hp) { // TODO is this the best way to check that the ally is active?
if (this.copyToPartner && globalScene.currentBattle?.double && ally != null && ally.hp) { // TODO is this the best way to check that the ally is active?
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:copiedTargetAbility", { pokemonName: getPokemonNameWithAffix(ally), targetName: getPokemonNameWithAffix(target), abilityName: allAbilities[target.getAbility().id].name }));
ally.setTempAbility(target.getAbility());
}
@ -8054,7 +8054,7 @@ const failIfGhostTypeCondition: MoveConditionFunc = (user: Pokemon, target: Poke
const failIfNoTargetHeldItemsCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => target.getHeldItems().filter(i => i.isTransferable)?.length > 0;
const attackedByItemMessageFunc = (user: Pokemon, target: Pokemon, move: Move) => {
if (isNullOrUndefined(target)) { // Fix bug when used against targets that have both fainted
if (target == null) { // Fix bug when used against targets that have both fainted
return "";
}
const heldItems = target.getHeldItems().filter(i => i.isTransferable);
@ -8611,7 +8611,7 @@ export function initMoves() {
.attr(AddBattlerTagAttr, BattlerTagType.DISABLED, false, true)
.condition((_user, target, _move) => {
const lastNonVirtualMove = target.getLastNonVirtualMove();
return !isNullOrUndefined(lastNonVirtualMove) && lastNonVirtualMove.move !== MoveId.STRUGGLE;
return lastNonVirtualMove != null && lastNonVirtualMove.move !== MoveId.STRUGGLE;
})
.ignoresSubstitute()
.reflectable(),
@ -9955,7 +9955,7 @@ export function initMoves() {
.condition(failOnGravityCondition)
.condition((_user, target, _move) => ![ SpeciesId.DIGLETT, SpeciesId.DUGTRIO, SpeciesId.ALOLA_DIGLETT, SpeciesId.ALOLA_DUGTRIO, SpeciesId.SANDYGAST, SpeciesId.PALOSSAND, SpeciesId.WIGLETT, SpeciesId.WUGTRIO ].includes(target.species.speciesId))
.condition((_user, target, _move) => !(target.species.speciesId === SpeciesId.GENGAR && target.getFormKey() === "mega"))
.condition((_user, target, _move) => isNullOrUndefined(target.getTag(BattlerTagType.INGRAIN)) && isNullOrUndefined(target.getTag(BattlerTagType.IGNORE_FLYING)))
.condition((_user, target, _move) => target.getTag(BattlerTagType.INGRAIN) == null && target.getTag(BattlerTagType.IGNORE_FLYING) == null)
.attr(AddBattlerTagAttr, BattlerTagType.TELEKINESIS, false, true, 3)
.attr(AddBattlerTagAttr, BattlerTagType.FLOATING, false, true, 3)
.reflectable(),

View File

@ -48,7 +48,7 @@ import { getRandomPartyMemberFunc, trainerConfigs } from "#trainers/trainer-conf
import { TrainerPartyCompoundTemplate, TrainerPartyTemplate } from "#trainers/trainer-party-template";
import type { OptionSelectItem } from "#ui/abstract-option-select-ui-handler";
import { MoveInfoOverlay } from "#ui/move-info-overlay";
import { isNullOrUndefined, randSeedInt, randSeedShuffle } from "#utils/common";
import { randSeedInt, randSeedShuffle } from "#utils/common";
import i18next from "i18next";
/** the i18n namespace for the encounter */
@ -571,7 +571,7 @@ function getTrainerConfigForWave(waveIndex: number) {
.setPartyMemberFunc(
4,
getRandomPartyMemberFunc([pool3Mon.species], TrainerSlot.TRAINER, true, p => {
if (!isNullOrUndefined(pool3Mon.formIndex)) {
if (pool3Mon.formIndex != null) {
p.formIndex = pool3Mon.formIndex;
p.generateAndPopulateMoveset();
p.generateName();
@ -603,7 +603,7 @@ function getTrainerConfigForWave(waveIndex: number) {
.setPartyMemberFunc(
3,
getRandomPartyMemberFunc([pool3Mon.species], TrainerSlot.TRAINER, true, p => {
if (!isNullOrUndefined(pool3Mon.formIndex)) {
if (pool3Mon.formIndex != null) {
p.formIndex = pool3Mon.formIndex;
p.generateAndPopulateMoveset();
p.generateName();
@ -613,7 +613,7 @@ function getTrainerConfigForWave(waveIndex: number) {
.setPartyMemberFunc(
4,
getRandomPartyMemberFunc([pool3Mon2.species], TrainerSlot.TRAINER, true, p => {
if (!isNullOrUndefined(pool3Mon2.formIndex)) {
if (pool3Mon2.formIndex != null) {
p.formIndex = pool3Mon2.formIndex;
p.generateAndPopulateMoveset();
p.generateName();
@ -648,7 +648,7 @@ function getTrainerConfigForWave(waveIndex: number) {
.setPartyMemberFunc(
3,
getRandomPartyMemberFunc([pool3Mon.species], TrainerSlot.TRAINER, true, p => {
if (!isNullOrUndefined(pool3Mon.formIndex)) {
if (pool3Mon.formIndex != null) {
p.formIndex = pool3Mon.formIndex;
p.generateAndPopulateMoveset();
p.generateName();
@ -687,7 +687,7 @@ function getTrainerConfigForWave(waveIndex: number) {
.setPartyMemberFunc(
2,
getRandomPartyMemberFunc([pool3Mon.species], TrainerSlot.TRAINER, true, p => {
if (!isNullOrUndefined(pool3Mon.formIndex)) {
if (pool3Mon.formIndex != null) {
p.formIndex = pool3Mon.formIndex;
p.generateAndPopulateMoveset();
p.generateName();
@ -697,7 +697,7 @@ function getTrainerConfigForWave(waveIndex: number) {
.setPartyMemberFunc(
3,
getRandomPartyMemberFunc([pool3Mon2.species], TrainerSlot.TRAINER, true, p => {
if (!isNullOrUndefined(pool3Mon2.formIndex)) {
if (pool3Mon2.formIndex != null) {
p.formIndex = pool3Mon2.formIndex;
p.generateAndPopulateMoveset();
p.generateName();

View File

@ -15,7 +15,7 @@ import { getRandomPlayerPokemon, getRandomSpeciesByStarterCost } from "#mystery-
import type { MysteryEncounter } from "#mystery-encounters/mystery-encounter";
import { MysteryEncounterBuilder } from "#mystery-encounters/mystery-encounter";
import { MysteryEncounterOptionBuilder } from "#mystery-encounters/mystery-encounter-option";
import { isNullOrUndefined, randSeedInt } from "#utils/common";
import { randSeedInt } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
/** i18n namespace for encounter */
@ -192,7 +192,7 @@ export const DarkDealEncounter: MysteryEncounter = MysteryEncounterBuilder.withE
};
}),
};
if (!isNullOrUndefined(bossSpecies.forms) && bossSpecies.forms.length > 0) {
if (bossSpecies.forms != null && bossSpecies.forms.length > 0) {
pokemonConfig.formIndex = 0;
}
const config: EnemyPartyConfig = {

View File

@ -45,7 +45,7 @@ import {
TypeRequirement,
} from "#mystery-encounters/mystery-encounter-requirements";
import { FIRE_RESISTANT_ABILITIES } from "#mystery-encounters/requirement-groups";
import { isNullOrUndefined, randSeedInt } from "#utils/common";
import { randSeedInt } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
/** the i18n namespace for the encounter */
@ -238,7 +238,7 @@ export const FieryFalloutEncounter: MysteryEncounter = MysteryEncounterBuilder.w
// Burn random member
const burnable = nonFireTypes.filter(
p => isNullOrUndefined(p.status) || isNullOrUndefined(p.status.effect) || p.status.effect === StatusEffect.NONE,
p => p.status == null || p.status.effect == null || p.status.effect === StatusEffect.NONE,
);
if (burnable?.length > 0) {
const roll = randSeedInt(burnable.length);

View File

@ -43,7 +43,7 @@ import { PartySizeRequirement } from "#mystery-encounters/mystery-encounter-requ
import { PokemonData } from "#system/pokemon-data";
import { MusicPreference } from "#system/settings";
import type { OptionSelectItem } from "#ui/abstract-option-select-ui-handler";
import { isNullOrUndefined, NumberHolder, randInt, randSeedInt, randSeedItem, randSeedShuffle } from "#utils/common";
import { NumberHolder, randInt, randSeedInt, randSeedItem, randSeedShuffle } from "#utils/common";
import { getEnumKeys } from "#utils/enums";
import { getRandomLocaleEntry } from "#utils/i18n";
import { getPokemonSpecies } from "#utils/pokemon-utils";
@ -537,7 +537,7 @@ function generateTradeOption(alreadyUsedSpecies: PokemonSpecies[], originalBst?:
bstCap = originalBst + 100;
bstMin = originalBst - 100;
}
while (isNullOrUndefined(newSpecies)) {
while (newSpecies == null) {
// Get all non-legendary species that fall within the Bst range requirements
let validSpecies = allSpecies.filter(s => {
const isLegendaryOrMythical = s.legendary || s.subLegendary || s.mythical;
@ -550,7 +550,7 @@ function generateTradeOption(alreadyUsedSpecies: PokemonSpecies[], originalBst?:
if (validSpecies?.length > 20) {
validSpecies = randSeedShuffle(validSpecies);
newSpecies = validSpecies.pop();
while (isNullOrUndefined(newSpecies) || alreadyUsedSpecies.includes(newSpecies)) {
while (newSpecies == null || alreadyUsedSpecies.includes(newSpecies)) {
newSpecies = validSpecies.pop();
}
} else {

View File

@ -28,7 +28,7 @@ import { MysteryEncounterBuilder } from "#mystery-encounters/mystery-encounter";
import { MysteryEncounterOptionBuilder } from "#mystery-encounters/mystery-encounter-option";
import { MoneyRequirement } from "#mystery-encounters/mystery-encounter-requirements";
import { PokemonData } from "#system/pokemon-data";
import { isNullOrUndefined, randSeedInt, randSeedItem } from "#utils/common";
import { randSeedInt, randSeedItem } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
/** the i18n namespace for this encounter */
@ -81,7 +81,7 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = MysteryEncounterBui
let tries = 0;
// Reroll any species that don't have HAs
while ((isNullOrUndefined(species.abilityHidden) || species.abilityHidden === AbilityId.NONE) && tries < 5) {
while ((species.abilityHidden == null || species.abilityHidden === AbilityId.NONE) && tries < 5) {
species = getSalesmanSpeciesOffer();
tries++;
}
@ -110,7 +110,7 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = MysteryEncounterBui
*/
if (
r === 0
|| ((isNullOrUndefined(species.abilityHidden) || species.abilityHidden === AbilityId.NONE)
|| ((species.abilityHidden == null || species.abilityHidden === AbilityId.NONE)
&& validEventEncounters.length === 0)
) {
// If you roll 1%, give shiny Magikarp with random variant
@ -118,7 +118,7 @@ export const ThePokemonSalesmanEncounter: MysteryEncounter = MysteryEncounterBui
pokemon = new PlayerPokemon(species, 5, 2, undefined, undefined, true);
} else if (
validEventEncounters.length > 0
&& (r <= EVENT_THRESHOLD || isNullOrUndefined(species.abilityHidden) || species.abilityHidden === AbilityId.NONE)
&& (r <= EVENT_THRESHOLD || species.abilityHidden == null || species.abilityHidden === AbilityId.NONE)
) {
tries = 0;
do {

View File

@ -28,7 +28,7 @@ import { MysteryEncounterOptionBuilder } from "#mystery-encounters/mystery-encou
import { PokemonData } from "#system/pokemon-data";
import type { HeldModifierConfig } from "#types/held-modifier-config";
import type { OptionSelectItem } from "#ui/abstract-option-select-ui-handler";
import { isNullOrUndefined, randSeedShuffle } from "#utils/common";
import { randSeedShuffle } from "#utils/common";
import { getEnumValues } from "#utils/enums";
import i18next from "i18next";
@ -324,7 +324,7 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
// Only update the fusion's dex data if the Pokemon is already caught in dex (ignore rentals)
const rootFusionSpecies = playerPokemon.fusionSpecies?.getRootSpeciesId();
if (
!isNullOrUndefined(rootFusionSpecies)
rootFusionSpecies != null
&& speciesStarterCosts.hasOwnProperty(rootFusionSpecies)
&& !!globalScene.gameData.dexData[rootFusionSpecies].caughtAttr
) {

View File

@ -32,7 +32,7 @@ import { MysteryEncounterOptionBuilder } from "#mystery-encounters/mystery-encou
import { MoveRequirement, PersistentModifierRequirement } from "#mystery-encounters/mystery-encounter-requirements";
import { CHARMING_MOVES } from "#mystery-encounters/requirement-groups";
import { PokemonData } from "#system/pokemon-data";
import { isNullOrUndefined, randSeedInt } from "#utils/common";
import { randSeedInt } from "#utils/common";
/** the i18n namespace for the encounter */
const namespace = "mysteryEncounters/uncommonBreed";
@ -167,7 +167,7 @@ export const UncommonBreedEncounter: MysteryEncounter = MysteryEncounterBuilder.
const encounter = globalScene.currentBattle.mysteryEncounter!;
const eggMove = encounter.misc.eggMove;
if (!isNullOrUndefined(eggMove)) {
if (eggMove != null) {
// Check what type of move the egg move is to determine target
const pokemonMove = new PokemonMove(eggMove);
const move = pokemonMove.getMove();

View File

@ -41,7 +41,7 @@ import { PokemonData } from "#system/pokemon-data";
import { trainerConfigs } from "#trainers/trainer-config";
import { TrainerPartyTemplate } from "#trainers/trainer-party-template";
import type { HeldModifierConfig } from "#types/held-modifier-config";
import { isNullOrUndefined, NumberHolder, randSeedInt, randSeedShuffle } from "#utils/common";
import { NumberHolder, randSeedInt, randSeedShuffle } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
/** i18n namespace for encounter */
@ -634,7 +634,7 @@ function getTransformedSpecies(
alreadyUsedSpecies: PokemonSpecies[],
): PokemonSpecies {
let newSpecies: PokemonSpecies | undefined;
while (isNullOrUndefined(newSpecies)) {
while (newSpecies == null) {
const bstCap = originalBst + bstSearchRange[1];
const bstMin = Math.max(originalBst + bstSearchRange[0], 0);
@ -655,7 +655,7 @@ function getTransformedSpecies(
if (validSpecies?.length > 20) {
validSpecies = randSeedShuffle(validSpecies);
newSpecies = validSpecies.pop();
while (isNullOrUndefined(newSpecies) || alreadyUsedSpecies.includes(newSpecies)) {
while (newSpecies == null || alreadyUsedSpecies.includes(newSpecies)) {
newSpecies = validSpecies.pop();
}
} else {
@ -771,12 +771,12 @@ async function addEggMoveToNewPokemonMoveset(
if (eggMoves) {
const eggMoveIndices = randSeedShuffle([0, 1, 2, 3]);
let randomEggMoveIndex = eggMoveIndices.pop();
let randomEggMove = !isNullOrUndefined(randomEggMoveIndex) ? eggMoves[randomEggMoveIndex] : null;
let randomEggMove = randomEggMoveIndex != null ? eggMoves[randomEggMoveIndex] : null;
let retries = 0;
while (retries < 3 && (!randomEggMove || newPokemon.moveset.some(m => m.moveId === randomEggMove))) {
// If Pokemon already knows this move, roll for another egg move
randomEggMoveIndex = eggMoveIndices.pop();
randomEggMove = !isNullOrUndefined(randomEggMoveIndex) ? eggMoves[randomEggMoveIndex] : null;
randomEggMove = randomEggMoveIndex != null ? eggMoves[randomEggMoveIndex] : null;
retries++;
}
@ -791,11 +791,7 @@ async function addEggMoveToNewPokemonMoveset(
}
// For pokemon that the player owns (including ones just caught), unlock the egg move
if (
!forBattle
&& !isNullOrUndefined(randomEggMoveIndex)
&& !!globalScene.gameData.dexData[speciesRootForm].caughtAttr
) {
if (!forBattle && randomEggMoveIndex != null && !!globalScene.gameData.dexData[speciesRootForm].caughtAttr) {
await globalScene.gameData.setEggMoveUnlocked(getPokemonSpecies(speciesRootForm), randomEggMoveIndex, true);
}
}

View File

@ -12,7 +12,7 @@ import {
MoneyRequirement,
TypeRequirement,
} from "#mystery-encounters/mystery-encounter-requirements";
import { isNullOrUndefined, randSeedInt } from "#utils/common";
import { randSeedInt } from "#utils/common";
// biome-ignore lint/suspicious/noConfusingVoidType: void unions in callbacks are OK
export type OptionPhaseCallback = () => Promise<void | boolean>;
@ -62,7 +62,7 @@ export class MysteryEncounterOption implements IMysteryEncounterOption {
onPostOptionPhase?: OptionPhaseCallback;
constructor(option: IMysteryEncounterOption | null) {
if (!isNullOrUndefined(option)) {
if (option != null) {
Object.assign(this, option);
}
this.hasDexProgress = this.hasDexProgress ?? false;

View File

@ -15,7 +15,7 @@ import { WeatherType } from "#enums/weather-type";
import type { PlayerPokemon } from "#field/pokemon";
import { AttackTypeBoosterModifier } from "#modifiers/modifier";
import type { AttackTypeBoosterModifierType } from "#modifiers/modifier-type";
import { coerceArray, isNullOrUndefined } from "#utils/common";
import { coerceArray } from "#utils/common";
export interface EncounterRequirement {
meetsRequirement(): boolean; // Boolean to see if a requirement is met
@ -219,7 +219,7 @@ export class WaveRangeRequirement extends EncounterSceneRequirement {
}
override meetsRequirement(): boolean {
if (!isNullOrUndefined(this.waveRange) && this.waveRange[0] <= this.waveRange[1]) {
if (this.waveRange != null && this.waveRange[0] <= this.waveRange[1]) {
const waveIndex = globalScene.currentBattle.waveIndex;
if (
(waveIndex >= 0 && this.waveRange[0] >= 0 && this.waveRange[0] > waveIndex)
@ -275,11 +275,7 @@ export class TimeOfDayRequirement extends EncounterSceneRequirement {
override meetsRequirement(): boolean {
const timeOfDay = globalScene.arena?.getTimeOfDay();
return !(
!isNullOrUndefined(timeOfDay)
&& this.requiredTimeOfDay?.length > 0
&& !this.requiredTimeOfDay.includes(timeOfDay)
);
return !(timeOfDay != null && this.requiredTimeOfDay?.length > 0 && !this.requiredTimeOfDay.includes(timeOfDay));
}
override getDialogueToken(_pokemon?: PlayerPokemon): [string, string] {
@ -298,7 +294,7 @@ export class WeatherRequirement extends EncounterSceneRequirement {
override meetsRequirement(): boolean {
const currentWeather = globalScene.arena.weather?.weatherType;
return !(
!isNullOrUndefined(currentWeather)
currentWeather != null
&& this.requiredWeather?.length > 0
&& !this.requiredWeather.includes(currentWeather!)
);
@ -307,7 +303,7 @@ export class WeatherRequirement extends EncounterSceneRequirement {
override getDialogueToken(_pokemon?: PlayerPokemon): [string, string] {
const currentWeather = globalScene.arena.weather?.weatherType;
let token = "";
if (!isNullOrUndefined(currentWeather)) {
if (currentWeather != null) {
token = WeatherType[currentWeather].replace("_", " ").toLocaleLowerCase();
}
return ["weather", token];
@ -331,7 +327,7 @@ export class PartySizeRequirement extends EncounterSceneRequirement {
}
override meetsRequirement(): boolean {
if (!isNullOrUndefined(this.partySizeRange) && this.partySizeRange[0] <= this.partySizeRange[1]) {
if (this.partySizeRange != null && this.partySizeRange[0] <= this.partySizeRange[1]) {
const partySize = this.excludeDisallowedPokemon
? globalScene.getPokemonAllowedInBattle().length
: globalScene.getPlayerParty().length;
@ -363,7 +359,7 @@ export class PersistentModifierRequirement extends EncounterSceneRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredHeldItemModifiers?.length < 0) {
if (partyPokemon == null || this.requiredHeldItemModifiers?.length < 0) {
return false;
}
let modifierCount = 0;
@ -396,7 +392,7 @@ export class MoneyRequirement extends EncounterSceneRequirement {
override meetsRequirement(): boolean {
const money = globalScene.money;
if (isNullOrUndefined(money)) {
if (money == null) {
return false;
}
@ -429,7 +425,7 @@ export class SpeciesRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredSpecies?.length < 0) {
if (partyPokemon == null || this.requiredSpecies?.length < 0) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -469,7 +465,7 @@ export class NatureRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredNature?.length < 0) {
if (partyPokemon == null || this.requiredNature?.length < 0) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -484,7 +480,7 @@ export class NatureRequirement extends EncounterPokemonRequirement {
}
override getDialogueToken(pokemon?: PlayerPokemon): [string, string] {
if (!isNullOrUndefined(pokemon?.nature) && this.requiredNature.includes(pokemon.nature)) {
if (pokemon?.nature != null && this.requiredNature.includes(pokemon.nature)) {
return ["nature", Nature[pokemon.nature]];
}
return ["nature", ""];
@ -508,7 +504,7 @@ export class TypeRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
let partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon)) {
if (partyPokemon == null) {
return false;
}
@ -561,7 +557,7 @@ export class MoveRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredMoves?.length < 0) {
if (partyPokemon == null || this.requiredMoves?.length < 0) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -612,7 +608,7 @@ export class CompatibleMoveRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredMoves?.length < 0) {
if (partyPokemon == null || this.requiredMoves?.length < 0) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -668,7 +664,7 @@ export class AbilityRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredAbilities?.length < 0) {
if (partyPokemon == null || this.requiredAbilities?.length < 0) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -692,7 +688,7 @@ export class AbilityRequirement extends EncounterPokemonRequirement {
override getDialogueToken(pokemon?: PlayerPokemon): [string, string] {
const matchingAbility = this.requiredAbilities.find(a => pokemon?.hasAbility(a, false));
if (!isNullOrUndefined(matchingAbility)) {
if (matchingAbility != null) {
return ["ability", allAbilities[matchingAbility].name];
}
return ["ability", ""];
@ -713,7 +709,7 @@ export class StatusEffectRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredStatusEffect?.length < 0) {
if (partyPokemon == null || this.requiredStatusEffect?.length < 0) {
return false;
}
const x = this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -727,11 +723,7 @@ export class StatusEffectRequirement extends EncounterPokemonRequirement {
return this.requiredStatusEffect.some(statusEffect => {
if (statusEffect === StatusEffect.NONE) {
// StatusEffect.NONE also checks for null or undefined status
return (
isNullOrUndefined(pokemon.status)
|| isNullOrUndefined(pokemon.status.effect)
|| pokemon.status.effect === statusEffect
);
return pokemon.status == null || pokemon.status.effect == null || pokemon.status.effect === statusEffect;
}
return pokemon.status?.effect === statusEffect;
});
@ -742,11 +734,7 @@ export class StatusEffectRequirement extends EncounterPokemonRequirement {
return !this.requiredStatusEffect.some(statusEffect => {
if (statusEffect === StatusEffect.NONE) {
// StatusEffect.NONE also checks for null or undefined status
return (
isNullOrUndefined(pokemon.status)
|| isNullOrUndefined(pokemon.status.effect)
|| pokemon.status.effect === statusEffect
);
return pokemon.status == null || pokemon.status.effect == null || pokemon.status.effect === statusEffect;
}
return pokemon.status?.effect === statusEffect;
});
@ -756,9 +744,7 @@ export class StatusEffectRequirement extends EncounterPokemonRequirement {
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
);
return pokemon?.status == null || pokemon.status.effect == null || pokemon.status.effect === a;
}
return pokemon!.status?.effect === a;
});
@ -788,7 +774,7 @@ export class CanFormChangeWithItemRequirement extends EncounterPokemonRequiremen
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon) || this.requiredFormChangeItem?.length < 0) {
if (partyPokemon == null || this.requiredFormChangeItem?.length < 0) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -847,7 +833,7 @@ export class HeldItemRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon)) {
if (partyPokemon == null) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -911,7 +897,7 @@ export class AttackTypeBoosterHeldItemTypeRequirement extends EncounterPokemonRe
override meetsRequirement(): boolean {
const partyPokemon = globalScene.getPlayerParty();
if (isNullOrUndefined(partyPokemon)) {
if (partyPokemon == null) {
return false;
}
return this.queryParty(partyPokemon).length >= this.minNumberOfPokemon;
@ -978,7 +964,7 @@ export class LevelRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
// Party Pokemon inside required level range
if (!isNullOrUndefined(this.requiredLevelRange) && this.requiredLevelRange[0] <= this.requiredLevelRange[1]) {
if (this.requiredLevelRange != null && this.requiredLevelRange[0] <= this.requiredLevelRange[1]) {
const partyPokemon = globalScene.getPlayerParty();
const pokemonInRange = this.queryParty(partyPokemon);
if (pokemonInRange.length < this.minNumberOfPokemon) {
@ -1019,10 +1005,7 @@ export class FriendshipRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
// Party Pokemon inside required friendship range
if (
!isNullOrUndefined(this.requiredFriendshipRange)
&& this.requiredFriendshipRange[0] <= this.requiredFriendshipRange[1]
) {
if (this.requiredFriendshipRange != null && this.requiredFriendshipRange[0] <= this.requiredFriendshipRange[1]) {
const partyPokemon = globalScene.getPlayerParty();
const pokemonInRange = this.queryParty(partyPokemon);
if (pokemonInRange.length < this.minNumberOfPokemon) {
@ -1071,7 +1054,7 @@ export class HealthRatioRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
// Party Pokemon's health inside required health range
if (!isNullOrUndefined(this.requiredHealthRange) && this.requiredHealthRange[0] <= this.requiredHealthRange[1]) {
if (this.requiredHealthRange != null && this.requiredHealthRange[0] <= this.requiredHealthRange[1]) {
const partyPokemon = globalScene.getPlayerParty();
const pokemonInRange = this.queryParty(partyPokemon);
if (pokemonInRange.length < this.minNumberOfPokemon) {
@ -1098,7 +1081,7 @@ export class HealthRatioRequirement extends EncounterPokemonRequirement {
override getDialogueToken(pokemon?: PlayerPokemon): [string, string] {
const hpRatio = pokemon?.getHpRatio();
if (!isNullOrUndefined(hpRatio)) {
if (hpRatio != null) {
return ["healthRatio", Math.floor(hpRatio * 100).toString() + "%"];
}
return ["healthRatio", ""];
@ -1119,7 +1102,7 @@ export class WeightRequirement extends EncounterPokemonRequirement {
override meetsRequirement(): boolean {
// Party Pokemon's weight inside required weight range
if (!isNullOrUndefined(this.requiredWeightRange) && this.requiredWeightRange[0] <= this.requiredWeightRange[1]) {
if (this.requiredWeightRange != null && this.requiredWeightRange[0] <= this.requiredWeightRange[1]) {
const partyPokemon = globalScene.getPlayerParty();
const pokemonInRange = this.queryParty(partyPokemon);
if (pokemonInRange.length < this.minNumberOfPokemon) {

View File

@ -1,7 +1,6 @@
import { BASE_MYSTERY_ENCOUNTER_SPAWN_WEIGHT } from "#app/constants";
import type { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
import type { MysteryEncounterType } from "#enums/mystery-encounter-type";
import { isNullOrUndefined } from "#utils/common";
export class SeenEncounterData {
type: MysteryEncounterType;
@ -28,7 +27,7 @@ export class MysteryEncounterSaveData {
queuedEncounters: QueuedEncounter[] = [];
constructor(data?: MysteryEncounterSaveData) {
if (!isNullOrUndefined(data)) {
if (data != null) {
Object.assign(this, data);
}

View File

@ -25,7 +25,7 @@ import {
StatusEffectRequirement,
WaveRangeRequirement,
} from "#mystery-encounters/mystery-encounter-requirements";
import { coerceArray, isNullOrUndefined, randSeedInt } from "#utils/common";
import { coerceArray, randSeedInt } from "#utils/common";
import { capitalizeFirstLetter } from "#utils/strings";
export interface EncounterStartOfBattleEffect {
@ -275,7 +275,7 @@ export class MysteryEncounter implements IMysteryEncounter {
private seedOffset?: any;
constructor(encounter: IMysteryEncounter | null) {
if (!isNullOrUndefined(encounter)) {
if (encounter != null) {
Object.assign(this, encounter);
}
this.encounterTier = this.encounterTier ?? MysteryEncounterTier.COMMON;

View File

@ -3,7 +3,7 @@ import type { MoveId } from "#enums/move-id";
import type { PlayerPokemon } from "#field/pokemon";
import { PokemonMove } from "#moves/pokemon-move";
import { EncounterPokemonRequirement } from "#mystery-encounters/mystery-encounter-requirements";
import { coerceArray, isNullOrUndefined } from "#utils/common";
import { coerceArray } from "#utils/common";
/**
* {@linkcode CanLearnMoveRequirement} options
@ -44,7 +44,7 @@ export class CanLearnMoveRequirement extends EncounterPokemonRequirement {
.getPlayerParty()
.filter(pkm => (this.includeFainted ? pkm.isAllowedInChallenge() : pkm.isAllowedInBattle()));
if (isNullOrUndefined(partyPokemon) || this.requiredMoves?.length < 0) {
if (partyPokemon == null || this.requiredMoves?.length < 0) {
return false;
}

View File

@ -1,7 +1,6 @@
import { globalScene } from "#app/global-scene";
import type { TextStyle } from "#enums/text-style";
import { getTextWithColors } from "#ui/text";
import { isNullOrUndefined } from "#utils/common";
import i18next from "i18next";
/**
@ -11,7 +10,7 @@ import i18next from "i18next";
* @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(keyOrString?: string, primaryStyle?: TextStyle): string | null {
if (isNullOrUndefined(keyOrString)) {
if (keyOrString == null) {
return null;
}

View File

@ -49,7 +49,7 @@ import type { HeldModifierConfig } from "#types/held-modifier-config";
import type { OptionSelectConfig, OptionSelectItem } from "#ui/abstract-option-select-ui-handler";
import type { PartyOption, PokemonSelectFilter } from "#ui/party-ui-handler";
import { PartyUiMode } from "#ui/party-ui-handler";
import { coerceArray, isNullOrUndefined, randomString, randSeedInt, randSeedItem } from "#utils/common";
import { coerceArray, randomString, randSeedInt, randSeedItem } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import i18next from "i18next";
@ -143,7 +143,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
const trainerType = partyConfig?.trainerType;
const partyTrainerConfig = partyConfig?.trainerConfig;
let trainerConfig: TrainerConfig;
if (!isNullOrUndefined(trainerType) || partyTrainerConfig) {
if (trainerType != null || partyTrainerConfig) {
globalScene.currentBattle.mysteryEncounter!.encounterMode = MysteryEncounterMode.TRAINER_BATTLE;
if (globalScene.currentBattle.trainer) {
globalScene.currentBattle.trainer.setVisible(false);
@ -154,7 +154,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
const doubleTrainer = trainerConfig.doubleOnly || (trainerConfig.hasDouble && !!partyConfig.doubleBattle);
doubleBattle = doubleTrainer;
const trainerFemale = isNullOrUndefined(partyConfig.female) ? !!randSeedInt(2) : partyConfig.female;
const trainerFemale = partyConfig.female == null ? !!randSeedInt(2) : partyConfig.female;
const newTrainer = new Trainer(
trainerConfig.trainerType,
doubleTrainer ? TrainerVariant.DOUBLE : trainerFemale ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT,
@ -202,7 +202,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
let dataSource: PokemonData | undefined;
let isBoss = false;
if (!loaded) {
if ((!isNullOrUndefined(trainerType) || trainerConfig) && battle.trainer) {
if ((trainerType != null || trainerConfig) && battle.trainer) {
// Allows overriding a trainer's pokemon to use specific species/data
if (partyConfig?.pokemonConfigs && e < partyConfig.pokemonConfigs.length) {
const config = partyConfig.pokemonConfigs[e];
@ -258,7 +258,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
enemyPokemon.resetSummonData();
}
if ((!loaded && isNullOrUndefined(partyConfig.countAsSeen)) || partyConfig.countAsSeen) {
if ((!loaded && partyConfig.countAsSeen == null) || partyConfig.countAsSeen) {
globalScene.gameData.setPokemonSeen(enemyPokemon, true, !!(trainerType || trainerConfig));
}
@ -266,7 +266,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
const config = partyConfig.pokemonConfigs[e];
// Set form
if (!isNullOrUndefined(config.nickname)) {
if (config.nickname != null) {
enemyPokemon.nickname = btoa(unescape(encodeURIComponent(config.nickname)));
}
@ -276,22 +276,22 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
}
// Set form
if (!isNullOrUndefined(config.formIndex)) {
if (config.formIndex != null) {
enemyPokemon.formIndex = config.formIndex;
}
// Set shiny
if (!isNullOrUndefined(config.shiny)) {
if (config.shiny != null) {
enemyPokemon.shiny = config.shiny;
}
// Set Variant
if (enemyPokemon.shiny && !isNullOrUndefined(config.variant)) {
if (enemyPokemon.shiny && config.variant != null) {
enemyPokemon.variant = config.variant;
}
// Set custom mystery encounter data fields (such as sprite scale, custom abilities, types, etc.)
if (!isNullOrUndefined(config.customPokemonData)) {
if (config.customPokemonData != null) {
enemyPokemon.customPokemonData = config.customPokemonData;
}
@ -300,7 +300,7 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
let segments =
config.bossSegments
?? globalScene.getEncounterBossSegments(globalScene.currentBattle.waveIndex, level, enemySpecies, true);
if (!isNullOrUndefined(config.bossSegmentModifier)) {
if (config.bossSegmentModifier != null) {
segments += config.bossSegmentModifier;
}
enemyPokemon.setBoss(true, segments);
@ -335,18 +335,18 @@ export async function initBattleWithEnemyConfig(partyConfig: EnemyPartyConfig):
}
// Set ability
if (!isNullOrUndefined(config.abilityIndex)) {
if (config.abilityIndex != null) {
enemyPokemon.abilityIndex = config.abilityIndex;
}
// Set gender
if (!isNullOrUndefined(config.gender)) {
if (config.gender != null) {
enemyPokemon.gender = config.gender!;
enemyPokemon.summonData.gender = config.gender;
}
// Set AI type
if (!isNullOrUndefined(config.aiType)) {
if (config.aiType != null) {
enemyPokemon.aiType = config.aiType;
}

View File

@ -35,7 +35,7 @@ import type { PartyOption } from "#ui/party-ui-handler";
import { PartyUiMode } from "#ui/party-ui-handler";
import { SummaryUiMode } from "#ui/summary-ui-handler";
import { applyChallenges } from "#utils/challenge-utils";
import { BooleanHolder, isNullOrUndefined, randSeedInt } from "#utils/common";
import { BooleanHolder, randSeedInt } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import i18next from "i18next";
@ -276,7 +276,7 @@ export function getRandomSpeciesByStarterCost(
if (types && types.length > 0) {
filteredSpecies = filteredSpecies.filter(
s => types.includes(s[0].type1) || (!isNullOrUndefined(s[0].type2) && types.includes(s[0].type2)),
s => types.includes(s[0].type1) || (s[0].type2 != null && types.includes(s[0].type2)),
);
}

View File

@ -28,7 +28,7 @@ import type { Variant, VariantSet } from "#sprites/variant";
import { populateVariantColorCache, variantColorCache, variantData } from "#sprites/variant";
import type { Localizable } from "#types/locales";
import type { StarterMoveset } from "#types/save-data";
import { isNullOrUndefined, randSeedFloat, randSeedGauss, randSeedInt } from "#utils/common";
import { randSeedFloat, randSeedGauss, randSeedInt } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import { toCamelCase, toPascalCase } from "#utils/strings";
import { argbFromRgba, QuantizerCelebi, rgbaFromArgb } from "@material/material-color-utilities";
@ -197,7 +197,7 @@ export abstract class PokemonSpeciesForm {
* @returns The id of the ability
*/
getPassiveAbility(formIndex?: number): AbilityId {
if (isNullOrUndefined(formIndex)) {
if (formIndex == null) {
formIndex = this.formIndex;
}
let starterSpeciesId = this.speciesId;
@ -551,7 +551,7 @@ export abstract class PokemonSpeciesForm {
const spriteKey = this.getSpriteKey(female, formIndex, shiny, variant, back);
globalScene.loadPokemonAtlas(spriteKey, this.getSpriteAtlasPath(female, formIndex, shiny, variant, back));
globalScene.load.audio(this.getCryKey(formIndex), `audio/${this.getCryKey(formIndex)}.m4a`);
if (!isNullOrUndefined(variant)) {
if (variant != null) {
await this.loadVariantColors(spriteKey, female, variant, back, formIndex);
}
return new Promise<void>(resolve => {
@ -579,7 +579,7 @@ export abstract class PokemonSpeciesForm {
const spritePath = this.getSpriteAtlasPath(female, formIndex, shiny, variant, back)
.replace("variant/", "")
.replace(/_[1-3]$/, "");
if (!isNullOrUndefined(variant)) {
if (variant != null) {
loadPokemonVariantAssets(spriteKey, spritePath, variant).then(() => resolve());
}
});
@ -791,7 +791,7 @@ export class PokemonSpecies extends PokemonSpeciesForm implements Localizable {
* @returns A randomly rolled gender based on this Species' {@linkcode malePercent}.
*/
generateGender(): Gender {
if (isNullOrUndefined(this.malePercent)) {
if (this.malePercent == null) {
return Gender.GENDERLESS;
}

View File

@ -16,7 +16,6 @@ import type { AttackMoveResult } from "#types/attack-move-result";
import type { IllusionData } from "#types/illusion-data";
import type { TurnMove } from "#types/turn-move";
import type { CoerceNullPropertiesToUndefined } from "#types/type-helpers";
import { isNullOrUndefined } from "#utils/common";
import { getPokemonSpeciesForm } from "#utils/pokemon-utils";
/**
@ -64,14 +63,14 @@ function deserializePokemonSpeciesForm(value: SerializedSpeciesForm | PokemonSpe
// @ts-expect-error: We may be deserializing a PokemonSpeciesForm, but we catch later on
let { id, formIdx } = value;
if (isNullOrUndefined(id) || isNullOrUndefined(formIdx)) {
if (id == null || formIdx == null) {
// @ts-expect-error: Typescript doesn't know that in block, `value` must be a PokemonSpeciesForm
id = value.speciesId;
// @ts-expect-error: Same as above (plus we are accessing a protected property)
formIdx = value._formIndex;
}
// If for some reason either of these fields are null/undefined, we cannot reconstruct the species form
if (isNullOrUndefined(id) || isNullOrUndefined(formIdx)) {
if (id == null || formIdx == null) {
return null;
}
return getPokemonSpeciesForm(id, formIdx);
@ -151,13 +150,13 @@ export class PokemonSummonData {
public moveHistory: TurnMove[] = [];
constructor(source?: PokemonSummonData | SerializedPokemonSummonData) {
if (isNullOrUndefined(source)) {
if (source == null) {
return;
}
// TODO: Rework this into an actual generic function for use elsewhere
for (const [key, value] of Object.entries(source)) {
if (isNullOrUndefined(value) && this.hasOwnProperty(key)) {
if (value == null && this.hasOwnProperty(key)) {
continue;
}
@ -171,7 +170,7 @@ export class PokemonSummonData {
const illusionData = {
...value,
};
if (!isNullOrUndefined(illusionData.fusionSpecies)) {
if (illusionData.fusionSpecies != null) {
switch (typeof illusionData.fusionSpecies) {
case "object":
illusionData.fusionSpecies = allSpecies[illusionData.fusionSpecies.speciesId];
@ -224,18 +223,18 @@ export class PokemonSummonData {
CoerceNullPropertiesToUndefined<PokemonSummonData>,
"speciesForm" | "fusionSpeciesForm" | "illusion"
>),
speciesForm: isNullOrUndefined(speciesForm)
? undefined
: { id: speciesForm.speciesId, formIdx: speciesForm.formIndex },
fusionSpeciesForm: isNullOrUndefined(fusionSpeciesForm)
? undefined
: { id: fusionSpeciesForm.speciesId, formIdx: fusionSpeciesForm.formIndex },
illusion: isNullOrUndefined(illusion)
? undefined
: {
...(this.illusion as Omit<typeof illusion, "fusionSpecies">),
fusionSpecies: illusionSpeciesForm?.speciesId,
},
speciesForm: speciesForm == null ? undefined : { id: speciesForm.speciesId, formIdx: speciesForm.formIndex },
fusionSpeciesForm:
fusionSpeciesForm == null
? undefined
: { id: fusionSpeciesForm.speciesId, formIdx: fusionSpeciesForm.formIndex },
illusion:
illusion == null
? undefined
: {
...(this.illusion as Omit<typeof illusion, "fusionSpecies">),
fusionSpecies: illusionSpeciesForm?.speciesId,
},
};
// Replace `null` with `undefined`, as `undefined` never gets serialized
for (const [key, value] of Object.entries(t)) {
@ -278,7 +277,7 @@ export class PokemonBattleData {
public berriesEaten: BerryType[] = [];
constructor(source?: PokemonBattleData | Partial<PokemonBattleData>) {
if (!isNullOrUndefined(source)) {
if (source != null) {
this.hitCount = source.hitCount ?? 0;
this.hasEatenBerry = source.hasEatenBerry ?? false;
this.berriesEaten = source.berriesEaten ?? [];

View File

@ -41,7 +41,7 @@ import type {
TrainerConfigs,
TrainerTierPools,
} from "#types/trainer-funcs";
import { coerceArray, isNullOrUndefined, randSeedInt, randSeedIntRange, randSeedItem } from "#utils/common";
import { coerceArray, randSeedInt, randSeedIntRange, randSeedItem } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import { toCamelCase, toTitleCase } from "#utils/strings";
import i18next from "i18next";
@ -474,7 +474,7 @@ export class TrainerConfig {
.fill(null)
.map((_, i) => i)
.filter(i => shedinjaCanTera || party[i].species.speciesId !== SpeciesId.SHEDINJA); // Shedinja can only Tera on Bug specialty type (or no specialty type)
const setPartySlot = !isNullOrUndefined(slot) ? Phaser.Math.Wrap(slot, 0, party.length) : -1; // If we have a tera slot defined, wrap it to party size.
const setPartySlot = slot != null ? Phaser.Math.Wrap(slot, 0, party.length) : -1; // If we have a tera slot defined, wrap it to party size.
for (let t = 0; t < Math.min(count(), party.length); t++) {
const randomIndex =
partyMemberIndexes.indexOf(setPartySlot) > -1 ? setPartySlot : randSeedItem(partyMemberIndexes);
@ -537,7 +537,7 @@ export class TrainerConfig {
initI18n();
}
if (!isNullOrUndefined(specialtyType)) {
if (specialtyType != null) {
this.setSpecialtyType(specialtyType);
}
@ -612,7 +612,7 @@ export class TrainerConfig {
signatureSpecies.forEach((speciesPool, s) => {
this.setPartyMemberFunc(-(s + 1), getRandomPartyMemberFunc(coerceArray(speciesPool)));
});
if (!isNullOrUndefined(specialtyType)) {
if (specialtyType != null) {
this.setSpeciesFilter(p => p.isOfType(specialtyType));
this.setSpecialtyType(specialtyType);
}
@ -717,7 +717,7 @@ export class TrainerConfig {
});
// Set species filter and specialty type if provided, otherwise filter by base total.
if (!isNullOrUndefined(specialtyType)) {
if (specialtyType != null) {
this.setSpeciesFilter(p => p.isOfType(specialtyType) && p.baseTotal >= ELITE_FOUR_MINIMUM_BST);
this.setSpecialtyType(specialtyType);
} else {
@ -895,7 +895,7 @@ export class TrainerConfig {
* @returns `true` if `specialtyType` is defined and not {@link PokemonType.UNKNOWN}
*/
hasSpecialtyType(): boolean {
return !isNullOrUndefined(this.specialtyType) && this.specialtyType !== PokemonType.UNKNOWN;
return this.specialtyType != null && this.specialtyType !== PokemonType.UNKNOWN;
}
/**
@ -2942,7 +2942,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.SLOWBRO, SpeciesId.GALAR_SLOWBRO], TrainerSlot.TRAINER, true, p => {
// Tera Ice Slowbro/G-Slowbro
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.ICE_BEAM)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.ICE_BEAM)) {
// Check if Ice Beam is in the moveset, if not, replace the third move with Ice Beam.
p.moveset[2] = new PokemonMove(MoveId.ICE_BEAM);
}
@ -2967,7 +2967,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.STEELIX], TrainerSlot.TRAINER, true, p => {
// Tera Fighting Steelix
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.BODY_PRESS)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.BODY_PRESS)) {
// Check if Body Press is in the moveset, if not, replace the third move with Body Press.
p.moveset[2] = new PokemonMove(MoveId.BODY_PRESS);
}
@ -2992,7 +2992,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.ARBOK, SpeciesId.WEEZING], TrainerSlot.TRAINER, true, p => {
// Tera Ghost Arbok/Weezing
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -3018,7 +3018,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.GYARADOS, SpeciesId.AERODACTYL], TrainerSlot.TRAINER, true, p => {
// Tera Dragon Gyarados/Aerodactyl
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -3079,7 +3079,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.GENGAR], TrainerSlot.TRAINER, true, p => {
// Tera Dark Gengar
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.DARK_PULSE)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.DARK_PULSE)) {
// Check if Dark Pulse is in the moveset, if not, replace the third move with Dark Pulse.
p.moveset[2] = new PokemonMove(MoveId.DARK_PULSE);
}
@ -3163,7 +3163,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.DHELMISE], TrainerSlot.TRAINER, true, p => {
// Tera Dragon Dhelmise
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -3193,7 +3193,7 @@ export const trainerConfigs: TrainerConfigs = {
p.setBoss(true, 2);
p.abilityIndex = 1; // Sniper
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.X_SCISSOR)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.X_SCISSOR)) {
// Check if X-Scissor is in the moveset, if not, replace the third move with X-Scissor.
p.moveset[2] = new PokemonMove(MoveId.X_SCISSOR);
}
@ -3232,7 +3232,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.STEELIX, SpeciesId.LOPUNNY], TrainerSlot.TRAINER, true, p => {
// Tera Fire Steelix/Lopunny
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -3375,7 +3375,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.CERULEDGE], TrainerSlot.TRAINER, true, p => {
// Tera Steel Ceruledge
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.IRON_HEAD)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.IRON_HEAD)) {
// Check if Iron Head is in the moveset, if not, replace the third move with Iron Head.
p.moveset[2] = new PokemonMove(MoveId.IRON_HEAD);
}
@ -3413,7 +3413,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.INCINEROAR], TrainerSlot.TRAINER, true, p => {
// Tera Fighting Incineroar
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.CROSS_CHOP)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.CROSS_CHOP)) {
// Check if Cross Chop is in the moveset, if not, replace the third move with Cross Chop.
p.moveset[2] = new PokemonMove(MoveId.CROSS_CHOP);
}
@ -3486,7 +3486,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.DECIDUEYE], TrainerSlot.TRAINER, true, p => {
// Tera Flying Decidueye
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.BRAVE_BIRD)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.BRAVE_BIRD)) {
// Check if Brave Bird is in the moveset, if not, replace the third move with Brave Bird.
p.moveset[2] = new PokemonMove(MoveId.BRAVE_BIRD);
}
@ -3511,7 +3511,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.TOXICROAK], TrainerSlot.TRAINER, true, p => {
// Tera Dark Toxicroak
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.SUCKER_PUNCH)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.SUCKER_PUNCH)) {
// Check if Sucker Punch is in the moveset, if not, replace the third move with Sucker Punch.
p.moveset[2] = new PokemonMove(MoveId.SUCKER_PUNCH);
}
@ -3536,7 +3536,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.EISCUE], TrainerSlot.TRAINER, true, p => {
// Tera Water Eiscue
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.LIQUIDATION)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.LIQUIDATION)) {
// Check if Liquidation is in the moveset, if not, replace the third move with Liquidation.
p.moveset[2] = new PokemonMove(MoveId.LIQUIDATION);
}
@ -3598,7 +3598,7 @@ export const trainerConfigs: TrainerConfigs = {
// Tera Dragon Torkoal
p.abilityIndex = 1; // Drought
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -3695,7 +3695,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.EXEGGUTOR], TrainerSlot.TRAINER, true, p => {
// Tera Fire Exeggutor
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -3705,7 +3705,7 @@ export const trainerConfigs: TrainerConfigs = {
3,
getRandomPartyMemberFunc([SpeciesId.TALONFLAME], TrainerSlot.TRAINER, true, p => {
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.SUNNY_DAY)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.SUNNY_DAY)) {
// Check if Sunny Day is in the moveset, if not, replace the third move with Sunny Day.
p.moveset[2] = new PokemonMove(MoveId.SUNNY_DAY);
}
@ -3728,7 +3728,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.REUNICLUS], TrainerSlot.TRAINER, true, p => {
// Tera Steel Reuniclus
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.FLASH_CANNON)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.FLASH_CANNON)) {
// Check if Flash Cannon is in the moveset, if not, replace the third move with Flash Cannon.
p.moveset[2] = new PokemonMove(MoveId.FLASH_CANNON);
}
@ -3756,7 +3756,7 @@ export const trainerConfigs: TrainerConfigs = {
// Tera Fairy Excadrill
p.setBoss(true, 2);
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -3771,7 +3771,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.SCEPTILE], TrainerSlot.TRAINER, true, p => {
// Tera Dragon Sceptile
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.DUAL_CHOP)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.DUAL_CHOP)) {
// Check if Dual Chop is in the moveset, if not, replace the third move with Dual Chop.
p.moveset[2] = new PokemonMove(MoveId.DUAL_CHOP);
}
@ -3841,7 +3841,7 @@ export const trainerConfigs: TrainerConfigs = {
p.formIndex = 1; // Partner Pikachu
p.gender = Gender.MALE;
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.VOLT_TACKLE)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.VOLT_TACKLE)) {
// Check if Volt Tackle is in the moveset, if not, replace the first move with Volt Tackle.
p.moveset[0] = new PokemonMove(MoveId.VOLT_TACKLE);
}
@ -4072,7 +4072,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.KELDEO], TrainerSlot.TRAINER, true, p => {
p.pokeball = PokeballType.ROGUE_BALL;
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.SECRET_SWORD)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.SECRET_SWORD)) {
// Check if Secret Sword is in the moveset, if not, replace the third move with Secret Sword.
p.moveset[2] = new PokemonMove(MoveId.SECRET_SWORD);
}
@ -4401,7 +4401,7 @@ export const trainerConfigs: TrainerConfigs = {
5,
getRandomPartyMemberFunc([SpeciesId.KINGAMBIT], TrainerSlot.TRAINER, true, p => {
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -4480,7 +4480,7 @@ export const trainerConfigs: TrainerConfigs = {
4,
getRandomPartyMemberFunc([SpeciesId.TERAPAGOS], TrainerSlot.TRAINER, true, p => {
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_STARSTORM)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_STARSTORM)) {
// Check if Tera Starstorm is in the moveset, if not, replace the first move with Tera Starstorm.
p.moveset[0] = new PokemonMove(MoveId.TERA_STARSTORM);
}
@ -4494,7 +4494,7 @@ export const trainerConfigs: TrainerConfigs = {
p.setBoss(true, 2);
p.teraType = PokemonType.FIGHTING;
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TERA_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TERA_BLAST)) {
// Check if Tera Blast is in the moveset, if not, replace the third move with Tera Blast.
p.moveset[2] = new PokemonMove(MoveId.TERA_BLAST);
}
@ -5054,7 +5054,7 @@ export const trainerConfigs: TrainerConfigs = {
2,
getRandomPartyMemberFunc([SpeciesId.HONCHKROW], TrainerSlot.TRAINER, true, p => {
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.SUCKER_PUNCH)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.SUCKER_PUNCH)) {
// Check if Sucker Punch is in the moveset, if not, replace the third move with Sucker Punch.
p.moveset[2] = new PokemonMove(MoveId.SUCKER_PUNCH);
}
@ -5517,7 +5517,7 @@ export const trainerConfigs: TrainerConfigs = {
p.formIndex = randSeedInt(18); // Random Silvally Form
p.generateAndPopulateMoveset();
p.pokeball = PokeballType.ROGUE_BALL;
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.MULTI_ATTACK)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.MULTI_ATTACK)) {
// Check if Multi Attack is in the moveset, if not, replace the first move with Multi Attack.
p.moveset[0] = new PokemonMove(MoveId.MULTI_ATTACK);
}
@ -5590,7 +5590,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.GOLISOPOD], TrainerSlot.TRAINER, true, p => {
p.setBoss(true, 2);
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.FIRST_IMPRESSION)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.FIRST_IMPRESSION)) {
// Check if First Impression is in the moveset, if not, replace the third move with First Impression.
p.moveset[2] = new PokemonMove(MoveId.FIRST_IMPRESSION);
p.gender = Gender.MALE;
@ -5607,7 +5607,7 @@ export const trainerConfigs: TrainerConfigs = {
getRandomPartyMemberFunc([SpeciesId.GOLISOPOD], TrainerSlot.TRAINER, true, p => {
p.setBoss(true, 2);
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.FIRST_IMPRESSION)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.FIRST_IMPRESSION)) {
// Check if First Impression is in the moveset, if not, replace the third move with First Impression.
p.moveset[2] = new PokemonMove(MoveId.FIRST_IMPRESSION);
p.abilityIndex = 2; // Anticipation
@ -5643,7 +5643,7 @@ export const trainerConfigs: TrainerConfigs = {
p.generateAndPopulateMoveset();
p.pokeball = PokeballType.ROGUE_BALL;
p.formIndex = randSeedInt(4, 1); // Shock, Burn, Chill, or Douse Drive
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.TECHNO_BLAST)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.TECHNO_BLAST)) {
// Check if Techno Blast is in the moveset, if not, replace the third move with Techno Blast.
p.moveset[2] = new PokemonMove(MoveId.TECHNO_BLAST);
}
@ -5778,7 +5778,7 @@ export const trainerConfigs: TrainerConfigs = {
p.setBoss(true, 2);
p.abilityIndex = 2; // Pixilate
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.HYPER_VOICE)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.HYPER_VOICE)) {
// Check if Hyper Voice is in the moveset, if not, replace the second move with Hyper Voice.
p.moveset[1] = new PokemonMove(MoveId.HYPER_VOICE);
p.gender = Gender.FEMALE;
@ -5807,7 +5807,7 @@ export const trainerConfigs: TrainerConfigs = {
p.setBoss(true, 2);
p.abilityIndex = 2; // Pixilate
p.generateAndPopulateMoveset();
if (!p.moveset.some(move => !isNullOrUndefined(move) && move.moveId === MoveId.HYPER_VOICE)) {
if (!p.moveset.some(move => move != null && move.moveId === MoveId.HYPER_VOICE)) {
// Check if Hyper Voice is in the moveset, if not, replace the second move with Hyper Voice.
p.moveset[1] = new PokemonMove(MoveId.HYPER_VOICE);
p.gender = Gender.FEMALE;

View File

@ -36,7 +36,7 @@ import type { Pokemon } from "#field/pokemon";
import { FieldEffectModifier } from "#modifiers/modifier";
import type { Move } from "#moves/move";
import type { AbstractConstructor } from "#types/type-helpers";
import { type Constructor, isNullOrUndefined, NumberHolder, randSeedInt } from "#utils/common";
import { type Constructor, NumberHolder, randSeedInt } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
export class Arena {
@ -339,7 +339,7 @@ export class Arena {
const weatherDuration = new NumberHolder(0);
if (!isNullOrUndefined(user)) {
if (user != null) {
weatherDuration.value = 5;
globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, weatherDuration);
}
@ -420,7 +420,7 @@ export class Arena {
const terrainDuration = new NumberHolder(0);
if (!isNullOrUndefined(user)) {
if (user != null) {
terrainDuration.value = 5;
globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, terrainDuration);
}

View File

@ -5,7 +5,6 @@ import { getSpriteKeysFromSpecies } from "#mystery-encounters/encounter-pokemon-
import type { MysteryEncounter } from "#mystery-encounters/mystery-encounter";
import { loadPokemonVariantAssets } from "#sprites/pokemon-sprite";
import type { Variant } from "#sprites/variant";
import { isNullOrUndefined } from "#utils/common";
import type { GameObjects } from "phaser";
type PlayAnimationConfig = Phaser.Types.Animations.PlayAnimationConfig;
@ -98,7 +97,7 @@ export class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Container {
...config,
};
if (!isNullOrUndefined(result.species)) {
if (result.species != null) {
const keys = getSpriteKeysFromSpecies(result.species, undefined, undefined, result.isShiny, result.variant);
result.spriteKey = keys.spriteKey;
result.fileRoot = keys.fileRoot;
@ -205,12 +204,12 @@ export class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Container {
n++;
}
if (!isNullOrUndefined(pokemonShinySparkle)) {
if (pokemonShinySparkle != null) {
// Offset the sparkle to match the Pokemon's position
pokemonShinySparkle.setPosition(sprite.x, sprite.y);
}
if (!isNullOrUndefined(alpha)) {
if (alpha != null) {
sprite.setAlpha(alpha);
tintSprite.setAlpha(alpha);
}
@ -234,7 +233,7 @@ export class MysteryEncounterIntroVisuals extends Phaser.GameObjects.Container {
this.spriteConfigs.forEach(config => {
if (config.isPokemon) {
globalScene.loadPokemonAtlas(config.spriteKey, config.fileRoot);
if (config.isShiny && !isNullOrUndefined(config.variant)) {
if (config.isShiny && config.variant != null) {
shinyPromises.push(loadPokemonVariantAssets(config.spriteKey, config.fileRoot, config.variant));
}
} else if (config.isItem) {

View File

@ -159,7 +159,6 @@ import {
fixedInt,
getIvsFromId,
isBetween,
isNullOrUndefined,
NumberHolder,
randSeedFloat,
randSeedInt,
@ -886,7 +885,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
return this.fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
})
.then(c => {
if (!isNullOrUndefined(c)) {
if (c != null) {
variantColorCache[cacheKey] = c;
}
});
@ -1475,7 +1474,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
}
const ally = this.getAlly();
if (!isNullOrUndefined(ally)) {
if (ally != null) {
applyAbAttrs("AllyStatMultiplierAbAttr", {
pokemon: ally,
stat,
@ -1658,7 +1657,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
if (useIllusion && this.summonData.illusion) {
return this.summonData.illusion.gender;
}
if (!ignoreOverride && !isNullOrUndefined(this.summonData.gender)) {
if (!ignoreOverride && this.summonData.gender != null) {
return this.summonData.gender;
}
return this.gender;
@ -1674,7 +1673,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
if (useIllusion && this.summonData.illusion?.fusionGender) {
return this.summonData.illusion.fusionGender;
}
if (!ignoreOverride && !isNullOrUndefined(this.summonData.fusionGender)) {
if (!ignoreOverride && this.summonData.fusionGender != null) {
return this.summonData.fusionGender;
}
return this.fusionGender;
@ -1793,7 +1792,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
* @returns Whether this Pokemon has this species as either its base or fusion counterpart.
*/
hasSpecies(species: SpeciesId, formKey?: string): boolean {
if (isNullOrUndefined(formKey)) {
if (formKey == null) {
return this.species.speciesId === species || this.fusionSpecies?.speciesId === species;
}
@ -1941,7 +1940,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
secondType = fusionType1;
}
if (secondType === PokemonType.UNKNOWN && isNullOrUndefined(fusionType2)) {
if (secondType === PokemonType.UNKNOWN && fusionType2 == null) {
// If second pokemon was monotype and shared its primary type
secondType =
customTypes
@ -2024,12 +2023,12 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
return allAbilities[Overrides.ENEMY_ABILITY_OVERRIDE];
}
if (this.isFusion()) {
if (!isNullOrUndefined(this.fusionCustomPokemonData?.ability) && this.fusionCustomPokemonData.ability !== -1) {
if (this.fusionCustomPokemonData?.ability != null && this.fusionCustomPokemonData.ability !== -1) {
return allAbilities[this.fusionCustomPokemonData.ability];
}
return allAbilities[this.getFusionSpeciesForm(ignoreOverride).getAbility(this.fusionAbilityIndex)];
}
if (!isNullOrUndefined(this.customPokemonData.ability) && this.customPokemonData.ability !== -1) {
if (this.customPokemonData.ability != null && this.customPokemonData.ability !== -1) {
return allAbilities[this.customPokemonData.ability];
}
let abilityId = this.getSpeciesForm(ignoreOverride).getAbility(this.abilityIndex);
@ -2053,7 +2052,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
if (Overrides.ENEMY_PASSIVE_ABILITY_OVERRIDE && this.isEnemy()) {
return allAbilities[Overrides.ENEMY_PASSIVE_ABILITY_OVERRIDE];
}
if (!isNullOrUndefined(this.customPokemonData.passive) && this.customPokemonData.passive !== -1) {
if (this.customPokemonData.passive != null && this.customPokemonData.passive !== -1) {
return allAbilities[this.customPokemonData.passive];
}
@ -2237,7 +2236,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
public getWeight(): number {
const autotomizedTag = this.getTag(AutotomizedTag);
let weightRemoved = 0;
if (!isNullOrUndefined(autotomizedTag)) {
if (autotomizedTag != null) {
weightRemoved = 100 * autotomizedTag.autotomizeCount;
}
const minWeight = 0.1;
@ -2384,7 +2383,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
cancelled?: BooleanHolder,
useIllusion = false,
): TypeDamageMultiplier {
if (!isNullOrUndefined(this.turnData?.moveEffectiveness)) {
if (this.turnData?.moveEffectiveness != null) {
return this.turnData?.moveEffectiveness;
}
@ -3606,7 +3605,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
});
const ally = this.getAlly();
if (!isNullOrUndefined(ally)) {
if (ally != null) {
const ignore =
this.hasAbilityWithAttr("MoveAbilityBypassAbAttr") || sourceMove.hasFlag(MoveFlags.IGNORE_ABILITIES);
applyAbAttrs("AllyStatMultiplierAbAttr", {
@ -4022,7 +4021,7 @@ export abstract class Pokemon extends Phaser.GameObjects.Container {
const ally = this.getAlly();
/** Additionally apply friend guard damage reduction if ally has it. */
if (globalScene.currentBattle.double && !isNullOrUndefined(ally) && ally.isActive(true)) {
if (globalScene.currentBattle.double && ally != null && ally.isActive(true)) {
applyAbAttrs("AlliedFieldDamageReductionAbAttr", {
...abAttrParams,
// Same parameters as before, except we are applying the ally's ability
@ -6397,13 +6396,13 @@ export class EnemyPokemon extends Pokemon {
if (
speciesId in Overrides.ENEMY_FORM_OVERRIDES
&& !isNullOrUndefined(Overrides.ENEMY_FORM_OVERRIDES[speciesId])
&& Overrides.ENEMY_FORM_OVERRIDES[speciesId] != null
&& this.species.forms[Overrides.ENEMY_FORM_OVERRIDES[speciesId]]
) {
this.formIndex = Overrides.ENEMY_FORM_OVERRIDES[speciesId];
} else if (globalScene.gameMode.isDaily && globalScene.gameMode.isWaveFinal(globalScene.currentBattle.waveIndex)) {
const eventBoss = getDailyEventSeedBoss(globalScene.seed);
if (!isNullOrUndefined(eventBoss)) {
if (eventBoss != null) {
this.formIndex = eventBoss.formIndex;
}
}

View File

@ -14,7 +14,7 @@ import { SpeciesId } from "#enums/species-id";
import type { Arena } from "#field/arena";
import { classicFixedBattles, type FixedBattleConfigs } from "#trainers/fixed-battle-configs";
import { applyChallenges } from "#utils/challenge-utils";
import { BooleanHolder, isNullOrUndefined, randSeedInt, randSeedItem } from "#utils/common";
import { BooleanHolder, randSeedInt, randSeedItem } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import i18next from "i18next";
@ -146,7 +146,7 @@ export class GameMode implements GameModeConfig {
* - Town
*/
getStartingBiome(): BiomeId {
if (!isNullOrUndefined(Overrides.STARTING_BIOME_OVERRIDE)) {
if (Overrides.STARTING_BIOME_OVERRIDE != null) {
return Overrides.STARTING_BIOME_OVERRIDE;
}
@ -234,7 +234,7 @@ export class GameMode implements GameModeConfig {
getOverrideSpecies(waveIndex: number): PokemonSpecies | null {
if (this.isDaily && this.isWaveFinal(waveIndex)) {
const eventBoss = getDailyEventSeedBoss(globalScene.seed);
if (!isNullOrUndefined(eventBoss)) {
if (eventBoss != null) {
// Cannot set form index here, it will be overriden when adding it as enemy pokemon.
return getPokemonSpecies(eventBoss.speciesId);
}

View File

@ -31,7 +31,6 @@ import {
} from "#modifiers/modifier-pools";
import { WeightedModifierType } from "#modifiers/modifier-type";
import type { WeightedModifierTypeWeightFunc } from "#types/modifier-types";
import { isNullOrUndefined } from "#utils/common";
/**
* Initialize the wild modifier pool
@ -409,7 +408,7 @@ function initUltraModifierPool() {
if (!isHoldingOrb) {
const moveset = p
.getMoveset(true)
.filter(m => !isNullOrUndefined(m))
.filter(m => m != null)
.map(m => m.moveId);
const canSetStatus = p.canSetStatus(StatusEffect.TOXIC, true, true, null, true);
@ -455,7 +454,7 @@ function initUltraModifierPool() {
if (!isHoldingOrb) {
const moveset = p
.getMoveset(true)
.filter(m => !isNullOrUndefined(m))
.filter(m => m != null)
.map(m => m.moveId);
const canSetStatus = p.canSetStatus(StatusEffect.BURN, true, true, null, true);

View File

@ -119,15 +119,7 @@ import type { PokemonMoveSelectFilter, PokemonSelectFilter } from "#ui/party-ui-
import { PartyUiHandler } from "#ui/party-ui-handler";
import { getModifierTierTextTint } from "#ui/text";
import { applyChallenges } from "#utils/challenge-utils";
import {
BooleanHolder,
formatMoney,
isNullOrUndefined,
NumberHolder,
padInt,
randSeedInt,
randSeedItem,
} from "#utils/common";
import { BooleanHolder, formatMoney, NumberHolder, padInt, randSeedInt, randSeedItem } from "#utils/common";
import { getEnumKeys, getEnumValues } from "#utils/enums";
import { getModifierPoolForType, getModifierType } from "#utils/modifier-utils";
import { toCamelCase } from "#utils/strings";
@ -263,7 +255,7 @@ export class ModifierType {
this.tier = modifier.modifierType.tier;
return this;
}
if (isNullOrUndefined(defaultTier)) {
if (defaultTier == null) {
// If weight is 0, keep track of the first tier where the item was found
defaultTier = modifier.modifierType.tier;
}
@ -2920,7 +2912,7 @@ export function getPartyLuckValue(party: Pokemon[]): number {
globalScene.executeWithSeedOffset(
() => {
const eventLuck = getDailyEventSeedLuck(globalScene.seed);
if (!isNullOrUndefined(eventLuck)) {
if (eventLuck != null) {
DailyLuck.value = eventLuck;
return;
}

View File

@ -42,7 +42,7 @@ import type {
import type { VoucherType } from "#system/voucher";
import type { ModifierInstanceMap, ModifierString } from "#types/modifier-types";
import { addTextObject } from "#ui/text";
import { BooleanHolder, hslToHex, isNullOrUndefined, NumberHolder, randSeedFloat, toDmgValue } from "#utils/common";
import { BooleanHolder, hslToHex, NumberHolder, randSeedFloat, toDmgValue } from "#utils/common";
import { getModifierType } from "#utils/modifier-utils";
import i18next from "i18next";
@ -2113,10 +2113,7 @@ export class PokemonHpRestoreModifier extends ConsumablePokemonModifier {
* @returns `true` if the {@linkcode PokemonHpRestoreModifier} should be applied
*/
override shouldApply(playerPokemon?: PlayerPokemon, multiplier?: number): boolean {
return (
super.shouldApply(playerPokemon)
&& (this.fainted || (!isNullOrUndefined(multiplier) && typeof multiplier === "number"))
);
return super.shouldApply(playerPokemon) && (this.fainted || (multiplier != null && typeof multiplier === "number"));
}
/**
@ -2753,10 +2750,10 @@ export class PokemonMultiHitModifier extends PokemonHeldItemModifier {
return false;
}
if (!isNullOrUndefined(count)) {
if (count != null) {
return this.applyHitCountBoost(count);
}
if (!isNullOrUndefined(damageMultiplier)) {
if (damageMultiplier != null) {
return this.applyDamageModifier(pokemon, damageMultiplier);
}

View File

@ -17,7 +17,6 @@ import type { EnemyPokemon, PlayerPokemon, Pokemon } from "#field/pokemon";
import { PokemonInstantReviveModifier } from "#modifiers/modifier";
import { PokemonMove } from "#moves/pokemon-move";
import { PokemonPhase } from "#phases/pokemon-phase";
import { isNullOrUndefined } from "#utils/common";
import i18next from "i18next";
export class FaintPhase extends PokemonPhase {
@ -187,7 +186,7 @@ export class FaintPhase extends PokemonPhase {
// in double battles redirect potential moves off fainted pokemon
const allyPokemon = pokemon.getAlly();
if (globalScene.currentBattle.double && !isNullOrUndefined(allyPokemon)) {
if (globalScene.currentBattle.double && allyPokemon != null) {
globalScene.redirectPokemonMoves(pokemon, allyPokemon);
}

View File

@ -40,7 +40,7 @@ import { DamageAchv } from "#system/achv";
import type { DamageResult } from "#types/damage-result";
import type { TurnMove } from "#types/turn-move";
import type { nil } from "#utils/common";
import { BooleanHolder, isNullOrUndefined, NumberHolder } from "#utils/common";
import { BooleanHolder, NumberHolder } from "#utils/common";
import i18next from "i18next";
export type HitCheckEntry = [HitCheckResult, TypeDamageMultiplier];
@ -740,7 +740,7 @@ export class MoveEffectPhase extends PokemonPhase {
(attr: MoveAttr) =>
attr.is("MoveEffectAttr")
&& attr.trigger === triggerType
&& (isNullOrUndefined(selfTarget) || attr.selfTarget === selfTarget)
&& (selfTarget == null || attr.selfTarget === selfTarget)
&& (!attr.firstHitOnly || this.firstHit)
&& (!attr.lastHitOnly || this.lastHit)
&& (!attr.firstTargetOnly || (firstTarget ?? true)),
@ -765,7 +765,7 @@ export class MoveEffectPhase extends PokemonPhase {
*/
protected applyMoveEffects(target: Pokemon, effectiveness: TypeDamageMultiplier, firstTarget: boolean): void {
const user = this.getUserPokemon();
if (isNullOrUndefined(user)) {
if (user == null) {
return;
}

View File

@ -14,7 +14,7 @@ import type { OptionSelectSettings } from "#mystery-encounters/encounter-phase-u
import { transitionMysteryEncounterIntroVisuals } from "#mystery-encounters/encounter-phase-utils";
import type { MysteryEncounterOption, OptionPhaseCallback } from "#mystery-encounters/mystery-encounter-option";
import { SeenEncounterData } from "#mystery-encounters/mystery-encounter-save-data";
import { isNullOrUndefined, randSeedItem } from "#utils/common";
import { randSeedItem } from "#utils/common";
import i18next from "i18next";
/**
@ -93,7 +93,7 @@ export class MysteryEncounterPhase extends Phase {
if (option.onPreOptionPhase) {
globalScene.executeWithSeedOffset(async () => {
return await option.onPreOptionPhase!().then(result => {
if (isNullOrUndefined(result) || result) {
if (result == null || result) {
this.continueEncounter();
}
});
@ -578,7 +578,7 @@ export class PostMysteryEncounterPhase extends Phase {
if (this.onPostOptionSelect) {
globalScene.executeWithSeedOffset(async () => {
return await this.onPostOptionSelect!().then(result => {
if (isNullOrUndefined(result) || result) {
if (result == null || result) {
this.continueEncounter();
}
});

View File

@ -4,7 +4,6 @@ import { PokemonAnimType } from "#enums/pokemon-anim-type";
import { SpeciesId } from "#enums/species-id";
import type { Pokemon } from "#field/pokemon";
import { BattlePhase } from "#phases/battle-phase";
import { isNullOrUndefined } from "#utils/common";
export class PokemonAnimPhase extends BattlePhase {
public readonly phaseName = "PokemonAnimPhase";
@ -52,7 +51,7 @@ export class PokemonAnimPhase extends BattlePhase {
private doSubstituteAddAnim(): void {
const substitute = this.pokemon.getTag(SubstituteTag);
if (isNullOrUndefined(substitute)) {
if (substitute == null) {
this.end();
return;
}
@ -336,7 +335,7 @@ export class PokemonAnimPhase extends BattlePhase {
// Note: unlike the other Commander animation, this is played through the
// Dondozo instead of the Tatsugiri.
const tatsugiri = this.pokemon.getAlly();
if (isNullOrUndefined(tatsugiri)) {
if (tatsugiri == null) {
console.warn("Aborting COMMANDER_REMOVE anim: Tatsugiri is undefined");
this.end();
return;

View File

@ -5,7 +5,7 @@ import type { PlayerPokemon } from "#field/pokemon";
import { BattlePhase } from "#phases/battle-phase";
import type { PartyOption } from "#ui/party-ui-handler";
import { PartyUiHandler, PartyUiMode } from "#ui/party-ui-handler";
import { isNullOrUndefined, toDmgValue } from "#utils/common";
import { toDmgValue } from "#utils/common";
import i18next from "i18next";
/**
@ -42,11 +42,7 @@ export class RevivalBlessingPhase extends BattlePhase {
);
const allyPokemon = this.user.getAlly();
if (
globalScene.currentBattle.double
&& globalScene.getPlayerParty().length > 1
&& !isNullOrUndefined(allyPokemon)
) {
if (globalScene.currentBattle.double && globalScene.getPlayerParty().length > 1 && allyPokemon != null) {
if (slotIndex <= 1) {
// Revived ally pokemon
globalScene.phaseManager.unshiftNew(

View File

@ -27,7 +27,7 @@ import { BattlePhase } from "#phases/battle-phase";
import type { ModifierSelectUiHandler } from "#ui/modifier-select-ui-handler";
import { SHOP_OPTIONS_ROW_LIMIT } from "#ui/modifier-select-ui-handler";
import { PartyOption, PartyUiHandler, PartyUiMode } from "#ui/party-ui-handler";
import { isNullOrUndefined, NumberHolder } from "#utils/common";
import { NumberHolder } from "#utils/common";
import i18next from "i18next";
export type ModifierSelectCallback = (rowCursor: number, cursor: number) => boolean;
@ -429,7 +429,7 @@ export class SelectModifierPhase extends BattlePhase {
}
let multiplier = 1;
if (!isNullOrUndefined(this.customModifierSettings?.rerollMultiplier)) {
if (this.customModifierSettings?.rerollMultiplier != null) {
if (this.customModifierSettings.rerollMultiplier < 0) {
// Completely overrides reroll cost to -1 and early exits
return -1;

View File

@ -10,7 +10,6 @@ import { overrideHeldItems, overrideModifiers } from "#modifiers/modifier";
import { SaveSlotUiMode } from "#ui/save-slot-select-ui-handler";
import type { Starter } from "#ui/starter-select-ui-handler";
import { applyChallenges } from "#utils/challenge-utils";
import { isNullOrUndefined } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import SoundFade from "phaser3-rex-plugins/plugins/soundfade";
@ -51,7 +50,7 @@ export class SelectStarterPhase extends Phase {
let starterFormIndex = Math.min(starterProps.formIndex, Math.max(starter.species.forms.length - 1, 0));
if (
starter.species.speciesId in Overrides.STARTER_FORM_OVERRIDES
&& !isNullOrUndefined(Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId])
&& Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId] != null
&& starter.species.forms[Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId]!]
) {
starterFormIndex = Overrides.STARTER_FORM_OVERRIDES[starter.species.speciesId]!;
@ -89,7 +88,7 @@ export class SelectStarterPhase extends Phase {
starterPokemon.nickname = starter.nickname;
}
if (!isNullOrUndefined(starter.teraType)) {
if (starter.teraType != null) {
starterPokemon.teraType = starter.teraType;
} else {
starterPokemon.teraType = starterPokemon.species.type1;

View File

@ -13,7 +13,7 @@ import type { Pokemon } from "#field/pokemon";
import { ResetNegativeStatStageModifier } from "#modifiers/modifier";
import { PokemonPhase } from "#phases/pokemon-phase";
import type { ConditionalUserFieldProtectStatAbAttrParams, PreStatStageChangeAbAttrParams } from "#types/ability-types";
import { BooleanHolder, isNullOrUndefined, NumberHolder } from "#utils/common";
import { BooleanHolder, NumberHolder } from "#utils/common";
import i18next from "i18next";
export type StatStageChangeCallback = (
@ -153,7 +153,7 @@ export class StatStageChangePhase extends PokemonPhase {
applyAbAttrs("ConditionalUserFieldProtectStatAbAttr", abAttrParams);
// TODO: Consider skipping this call if `cancelled` is false.
const ally = pokemon.getAlly();
if (!isNullOrUndefined(ally)) {
if (ally != null) {
applyAbAttrs("ConditionalUserFieldProtectStatAbAttr", { ...abAttrParams, pokemon: ally });
}

View File

@ -18,7 +18,7 @@ import { vouchers } from "#system/voucher";
import type { SessionSaveData } from "#types/save-data";
import type { OptionSelectConfig, OptionSelectItem } from "#ui/abstract-option-select-ui-handler";
import { SaveSlotUiMode } from "#ui/save-slot-select-ui-handler";
import { isLocal, isLocalServerConnected, isNullOrUndefined } from "#utils/common";
import { isLocal, isLocalServerConnected } from "#utils/common";
import i18next from "i18next";
export class TitlePhase extends Phase {
@ -289,7 +289,7 @@ export class TitlePhase extends Phase {
} else {
// Grab first 10 chars of ISO date format (YYYY-MM-DD) and convert to base64
let seed: string = btoa(new Date().toISOString().substring(0, 10));
if (!isNullOrUndefined(Overrides.DAILY_RUN_SEED_OVERRIDE)) {
if (Overrides.DAILY_RUN_SEED_OVERRIDE != null) {
seed = Overrides.DAILY_RUN_SEED_OVERRIDE;
}
generateDaily(seed);

View File

@ -2,7 +2,6 @@ import { globalScene } from "#app/global-scene";
import { VariantTier } from "#enums/variant-tier";
import type { Pokemon } from "#field/pokemon";
import { hasExpSprite } from "#sprites/sprite-utils";
import { isNullOrUndefined } from "#utils/common";
export type Variant = 0 | 1 | 2;
@ -138,7 +137,7 @@ export async function populateVariantColorCache(
return fallbackVariantColor(cacheKey, spritePath, useExpSprite, battleSpritePath, error);
})
.then(c => {
if (!isNullOrUndefined(c)) {
if (c != null) {
variantColorCache[cacheKey] = c;
}
});

View File

@ -2,7 +2,6 @@ import { globalScene } from "#app/global-scene";
import { pokemonPrevolutions } from "#balance/pokemon-evolutions";
import type { SpeciesId } from "#enums/species-id";
import type { RibbonFlag } from "#system/ribbons/ribbon-data";
import { isNullOrUndefined } from "#utils/common";
/**
* Award one or more ribbons to a species and its pre-evolutions
@ -14,7 +13,7 @@ export function awardRibbonsToSpeciesLine(id: SpeciesId, ribbons: RibbonFlag): v
const dexData = globalScene.gameData.dexData;
dexData[id].ribbons.award(ribbons);
// Mark all pre-evolutions of the Pokémon with the same ribbon flags.
for (let prevoId = pokemonPrevolutions[id]; !isNullOrUndefined(prevoId); prevoId = pokemonPrevolutions[prevoId]) {
for (let prevoId = pokemonPrevolutions[id]; prevoId != null; prevoId = pokemonPrevolutions[prevoId]) {
dexData[prevoId].ribbons.award(ribbons);
}
}

View File

@ -8,7 +8,6 @@ import type { SessionSaveData, SystemSaveData } from "#types/save-data";
import type { SessionSaveMigrator } from "#types/session-save-migrator";
import type { SettingsSaveMigrator } from "#types/settings-save-migrator";
import type { SystemSaveMigrator } from "#types/system-save-migrator";
import { isNullOrUndefined } from "#utils/common";
/**
* Migrate ability starter data if empty for caught species.
@ -82,7 +81,7 @@ const fixLegendaryStats: SystemSaveMigrator = {
const fixStarterData: SystemSaveMigrator = {
version: "1.0.4",
migrate: (data: SystemSaveData): void => {
if (!isNullOrUndefined(data.starterData)) {
if (data.starterData != null) {
for (const starterId of defaultStarterSpecies) {
if (data.starterData[starterId]?.abilityAttr) {
data.starterData[starterId].abilityAttr |= AbilityAttr.ABILITY_1;
@ -198,7 +197,7 @@ const migrateCustomPokemonData: SessionSaveMigrator = {
pokemon["fusionMysteryEncounterPokemonData"] = null;
}
pokemon.customPokemonData = pokemon.customPokemonData ?? new CustomPokemonData();
if (!isNullOrUndefined(pokemon["natureOverride"]) && pokemon["natureOverride"] >= 0) {
if (pokemon["natureOverride"] != null && pokemon["natureOverride"] >= 0) {
pokemon.customPokemonData.nature = pokemon["natureOverride"];
pokemon["natureOverride"] = -1;
}

View File

@ -3,7 +3,6 @@ import { DexAttr } from "#enums/dex-attr";
import type { SessionSaveData, SystemSaveData } from "#types/save-data";
import type { SessionSaveMigrator } from "#types/session-save-migrator";
import type { SystemSaveMigrator } from "#types/system-save-migrator";
import { isNullOrUndefined } from "#utils/common";
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
/**
@ -68,13 +67,13 @@ const migrateTera: SessionSaveMigrator = {
}
data.party.forEach(p => {
if (isNullOrUndefined(p.teraType)) {
if (p.teraType == null) {
p.teraType = getPokemonSpeciesForm(p.species, p.formIndex).type1;
}
});
data.enemyParty.forEach(p => {
if (isNullOrUndefined(p.teraType)) {
if (p.teraType == null) {
p.teraType = getPokemonSpeciesForm(p.species, p.formIndex).type1;
}
});

View File

@ -9,7 +9,6 @@ import { TextStyle } from "#enums/text-style";
import { WeatherType } from "#enums/weather-type";
import { addTextObject } from "#ui/text";
import type { nil } from "#utils/common";
import { isNullOrUndefined } from "#utils/common";
import i18next from "i18next";
export enum EventType {
@ -428,7 +427,7 @@ export class TimedEventManager {
getEventBannerLangs(): string[] {
const ret: string[] = [];
ret.push(...timedEvents.find(te => this.isActive(te) && !isNullOrUndefined(te.availableLangs))?.availableLangs!);
ret.push(...timedEvents.find(te => this.isActive(te) && te.availableLangs != null)?.availableLangs!);
return ret;
}
@ -437,7 +436,7 @@ export class TimedEventManager {
timedEvents
.filter(te => this.isActive(te))
.map(te => {
if (!isNullOrUndefined(te.eventEncounters)) {
if (te.eventEncounters != null) {
ret.push(...te.eventEncounters);
}
});
@ -452,7 +451,7 @@ export class TimedEventManager {
let multiplier = CLASSIC_CANDY_FRIENDSHIP_MULTIPLIER;
const classicFriendshipEvents = timedEvents.filter(te => this.isActive(te));
for (const fe of classicFriendshipEvents) {
if (!isNullOrUndefined(fe.classicFriendshipMultiplier) && fe.classicFriendshipMultiplier > multiplier) {
if (fe.classicFriendshipMultiplier != null && fe.classicFriendshipMultiplier > multiplier) {
multiplier = fe.classicFriendshipMultiplier;
}
}
@ -476,7 +475,7 @@ export class TimedEventManager {
timedEvents
.filter(te => this.isActive(te))
.map(te => {
if (!isNullOrUndefined(te.delibirdyBuff)) {
if (te.delibirdyBuff != null) {
ret.push(...te.delibirdyBuff);
}
});
@ -492,7 +491,7 @@ export class TimedEventManager {
timedEvents
.filter(te => this.isActive(te))
.map(te => {
if (!isNullOrUndefined(te.weather)) {
if (te.weather != null) {
ret.push(...te.weather);
}
});
@ -504,7 +503,7 @@ export class TimedEventManager {
timedEvents
.filter(te => this.isActive(te))
.map(te => {
if (!isNullOrUndefined(te.mysteryEncounterTierChanges)) {
if (te.mysteryEncounterTierChanges != null) {
ret.push(...te.mysteryEncounterTierChanges);
}
});
@ -514,7 +513,7 @@ export class TimedEventManager {
getEventMysteryEncountersDisabled(): MysteryEncounterType[] {
const ret: MysteryEncounterType[] = [];
timedEvents
.filter(te => this.isActive(te) && !isNullOrUndefined(te.mysteryEncounterTierChanges))
.filter(te => this.isActive(te) && te.mysteryEncounterTierChanges != null)
.map(te => {
te.mysteryEncounterTierChanges?.map(metc => {
if (metc.disable) {
@ -531,7 +530,7 @@ export class TimedEventManager {
): MysteryEncounterTier {
let ret = normal;
timedEvents
.filter(te => this.isActive(te) && !isNullOrUndefined(te.mysteryEncounterTierChanges))
.filter(te => this.isActive(te) && te.mysteryEncounterTierChanges != null)
.map(te => {
te.mysteryEncounterTierChanges?.map(metc => {
if (metc.mysteryEncounter === encounterType) {
@ -544,7 +543,7 @@ export class TimedEventManager {
getEventLuckBoost(): number {
let ret = 0;
const luckEvents = timedEvents.filter(te => this.isActive(te) && !isNullOrUndefined(te.luckBoost));
const luckEvents = timedEvents.filter(te => this.isActive(te) && te.luckBoost != null);
for (const le of luckEvents) {
ret += le.luckBoost!;
}
@ -556,7 +555,7 @@ export class TimedEventManager {
timedEvents
.filter(te => this.isActive(te))
.map(te => {
if (!isNullOrUndefined(te.luckBoostedSpecies)) {
if (te.luckBoostedSpecies != null) {
ret.push(...te.luckBoostedSpecies.filter(s => !ret.includes(s)));
}
});
@ -576,7 +575,7 @@ export class TimedEventManager {
getFixedBattleEventRewards(wave: number): string[] {
const ret: string[] = [];
timedEvents
.filter(te => this.isActive(te) && !isNullOrUndefined(te.classicWaveRewards))
.filter(te => this.isActive(te) && te.classicWaveRewards != null)
.map(te => {
ret.push(...te.classicWaveRewards!.filter(cwr => cwr.wave === wave).map(cwr => cwr.type));
});
@ -586,7 +585,7 @@ export class TimedEventManager {
// Gets the extra shiny chance for trainers due to event (odds/65536)
getClassicTrainerShinyChance(): number {
let ret = 0;
const tsEvents = timedEvents.filter(te => this.isActive(te) && !isNullOrUndefined(te.trainerShinyChance));
const tsEvents = timedEvents.filter(te => this.isActive(te) && te.trainerShinyChance != null);
tsEvents.map(t => (ret += t.trainerShinyChance!));
return ret;
}
@ -594,7 +593,7 @@ export class TimedEventManager {
getEventBgmReplacement(bgm: string): string {
let ret = bgm;
timedEvents.map(te => {
if (this.isActive(te) && !isNullOrUndefined(te.music)) {
if (this.isActive(te) && te.music != null) {
te.music.map(mr => {
if (mr[0] === bgm) {
console.log(`it is ${te.name} so instead of ${mr[0]} we play ${mr[1]}`);

View File

@ -3,7 +3,6 @@ import type { PokemonSpecies } from "#data/pokemon-species";
import { TextStyle } from "#enums/text-style";
import type { Variant } from "#sprites/variant";
import { addTextObject } from "#ui/text";
import { isNullOrUndefined } from "#utils/common";
interface SpeciesDetails {
shiny?: boolean;
@ -177,16 +176,16 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, false, true);
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
if (!isNullOrUndefined(formIndex)) {
if (formIndex != null) {
defaultProps.formIndex = formIndex;
}
if (!isNullOrUndefined(shiny)) {
if (shiny != null) {
defaultProps.shiny = shiny;
}
if (!isNullOrUndefined(variant)) {
if (variant != null) {
defaultProps.variant = variant;
}
if (!isNullOrUndefined(female)) {
if (female != null) {
defaultProps.female = female;
}

View File

@ -13,7 +13,7 @@ import { PartyUiMode } from "#ui/party-ui-handler";
import { addBBCodeTextObject, getBBCodeFrag } from "#ui/text";
import { UiHandler } from "#ui/ui-handler";
import { addWindow, WindowVariant } from "#ui/ui-theme";
import { fixedInt, isNullOrUndefined } from "#utils/common";
import { fixedInt } from "#utils/common";
import i18next from "i18next";
import type BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext";
@ -95,12 +95,10 @@ export class MysteryEncounterUiHandler extends UiHandler {
super.show(args);
this.overrideSettings = (args[0] as OptionSelectSettings) ?? {};
const showDescriptionContainer = isNullOrUndefined(this.overrideSettings?.hideDescription)
? true
: !this.overrideSettings.hideDescription;
const slideInDescription = isNullOrUndefined(this.overrideSettings?.slideInDescription)
? true
: this.overrideSettings.slideInDescription;
const showDescriptionContainer =
this.overrideSettings?.hideDescription == null ? true : !this.overrideSettings.hideDescription;
const slideInDescription =
this.overrideSettings?.slideInDescription == null ? true : this.overrideSettings.slideInDescription;
const startingCursorIndex = this.overrideSettings?.startingCursorIndex ?? 0;
this.cursorContainer.setVisible(true);
@ -567,7 +565,7 @@ export class MysteryEncounterUiHandler extends UiHandler {
}
this.tooltipContainer.setVisible(true);
if (isNullOrUndefined(cursor) || cursor > this.optionsContainer.length - 2) {
if (cursor == null || cursor > this.optionsContainer.length - 2) {
// Ignore hovers on view party button
// Hide dex progress if visible
this.showHideDexProgress(false);

View File

@ -54,7 +54,7 @@ import { PokedexInfoOverlay } from "#ui/pokedex-info-overlay";
import { StatsContainer } from "#ui/stats-container";
import { addBBCodeTextObject, addTextObject, getTextColor, getTextStyleOptions } from "#ui/text";
import { addWindow } from "#ui/ui-theme";
import { BooleanHolder, getLocalizedSpriteKey, isNullOrUndefined, padInt, rgbHexToRgba } from "#utils/common";
import { BooleanHolder, getLocalizedSpriteKey, padInt, rgbHexToRgba } from "#utils/common";
import { getEnumValues } from "#utils/enums";
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
import { toCamelCase, toTitleCase } from "#utils/strings";
@ -2424,11 +2424,7 @@ export class PokedexPageUiHandler extends MessageUiHandler {
// We will only update the sprite if there is a change to form, shiny/variant
// or gender for species with gender sprite differences
const shouldUpdateSprite =
(species?.genderDiffs && !isNullOrUndefined(female))
|| !isNullOrUndefined(formIndex)
|| !isNullOrUndefined(shiny)
|| !isNullOrUndefined(variant)
|| forceUpdate;
(species?.genderDiffs && female != null) || formIndex != null || shiny != null || variant != null || forceUpdate;
if (this.activeTooltip === "CANDY") {
if (this.species && this.pokemonCandyContainer.visible) {

View File

@ -6,7 +6,6 @@ import { FilterTextRow } from "#ui/filter-text";
import type { InputFieldConfig } from "#ui/form-modal-ui-handler";
import { FormModalUiHandler } from "#ui/form-modal-ui-handler";
import type { ModalConfig } from "#ui/modal-ui-handler";
import { isNullOrUndefined } from "#utils/common";
import i18next from "i18next";
export class PokedexScanUiHandler extends FormModalUiHandler {
@ -132,7 +131,7 @@ export class PokedexScanUiHandler extends FormModalUiHandler {
return {
label: value,
handler: () => {
if (!isNullOrUndefined(evt.data) || evt.inputType?.toLowerCase() === "deletecontentbackward") {
if (evt.data != null || evt.inputType?.toLowerCase() === "deletecontentbackward") {
inputObject.setText(value);
}
ui.revertMode();

View File

@ -13,7 +13,7 @@ import { MessageUiHandler } from "#ui/message-ui-handler";
import { RunDisplayMode } from "#ui/run-info-ui-handler";
import { addTextObject } from "#ui/text";
import { addWindow } from "#ui/ui-theme";
import { fixedInt, formatLargeNumber, getPlayTimeString, isNullOrUndefined } from "#utils/common";
import { fixedInt, formatLargeNumber, getPlayTimeString } from "#utils/common";
import i18next from "i18next";
const SESSION_SLOTS_COUNT = 5;
@ -405,7 +405,7 @@ export class SaveSlotSelectUiHandler extends MessageUiHandler {
}
this.setArrowVisibility(hasData);
}
if (!isNullOrUndefined(prevSlotIndex)) {
if (prevSlotIndex != null) {
this.revertSessionSlot(prevSlotIndex);
}

View File

@ -66,7 +66,6 @@ import {
BooleanHolder,
fixedInt,
getLocalizedSpriteKey,
isNullOrUndefined,
NumberHolder,
padInt,
randIntRange,
@ -2548,7 +2547,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
case Button.CYCLE_TERA:
if (this.canCycleTera) {
const speciesForm = getPokemonSpeciesForm(this.lastSpecies.speciesId, starterAttributes.form ?? 0);
if (speciesForm.type1 === this.teraCursor && !isNullOrUndefined(speciesForm.type2)) {
if (speciesForm.type1 === this.teraCursor && speciesForm.type2 != null) {
starterAttributes.tera = speciesForm.type2;
originalStarterAttributes.tera = starterAttributes.tera;
this.setSpeciesDetails(this.lastSpecies, {
@ -2790,7 +2789,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
*/
switchMoveHandler(targetIndex: number, newMove: MoveId, previousMove: MoveId) {
const starterMoveset = this.starterMoveset;
if (isNullOrUndefined(starterMoveset)) {
if (starterMoveset == null) {
console.warn("Trying to update a non-existing moveset");
return;
}
@ -3687,7 +3686,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
);
}
if (!isNullOrUndefined(props.formIndex)) {
if (props.formIndex != null) {
// If switching forms while the pokemon is in the team, update its moveset
this.updateSelectedStarterMoveset(species.speciesId);
}
@ -3809,10 +3808,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
// We will only update the sprite if there is a change to form, shiny/variant
// or gender for species with gender sprite differences
const shouldUpdateSprite =
(species?.genderDiffs && !isNullOrUndefined(female))
|| !isNullOrUndefined(formIndex)
|| !isNullOrUndefined(shiny)
|| !isNullOrUndefined(variant);
(species?.genderDiffs && female != null) || formIndex != null || shiny != null || variant != null;
const isFreshStartChallenge = globalScene.gameMode.hasChallenge(Challenges.FRESH_START);
@ -3850,7 +3846,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
); // TODO: is this bang correct?
this.abilityCursor = abilityIndex !== undefined ? abilityIndex : (abilityIndex = oldAbilityIndex);
this.natureCursor = natureIndex !== undefined ? natureIndex : (natureIndex = oldNatureIndex);
this.teraCursor = !isNullOrUndefined(teraType) ? teraType : (teraType = oldTeraType);
this.teraCursor = teraType != null ? teraType : (teraType = oldTeraType);
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
if (isInParty) {
this.updatePartyIcon(species, partyIndex);
@ -3991,7 +3987,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
this.canCycleTera =
!this.statsMode
&& this.allowTera
&& !isNullOrUndefined(getPokemonSpeciesForm(species.speciesId, formIndex ?? 0).type2)
&& getPokemonSpeciesForm(species.speciesId, formIndex ?? 0).type2 != null
&& !globalScene.gameMode.hasChallenge(Challenges.FRESH_START);
}
@ -4592,7 +4588,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
this.canCycleTera =
!this.statsMode
&& this.allowTera
&& !isNullOrUndefined(getPokemonSpeciesForm(this.lastSpecies.speciesId, formIndex ?? 0).type2)
&& getPokemonSpeciesForm(this.lastSpecies.speciesId, formIndex ?? 0).type2 != null
&& !globalScene.gameMode.hasChallenge(Challenges.FRESH_START);
this.updateInstructions();
}

View File

@ -27,15 +27,7 @@ import { getVariantTint } from "#sprites/variant";
import { achvs } from "#system/achv";
import { addBBCodeTextObject, addTextObject, getBBCodeFrag, getTextColor } from "#ui/text";
import { UiHandler } from "#ui/ui-handler";
import {
fixedInt,
formatStat,
getLocalizedSpriteKey,
getShinyDescriptor,
isNullOrUndefined,
padInt,
rgbHexToRgba,
} from "#utils/common";
import { fixedInt, formatStat, getLocalizedSpriteKey, getShinyDescriptor, padInt, rgbHexToRgba } from "#utils/common";
import { getEnumValues } from "#utils/enums";
import { toCamelCase, toTitleCase } from "#utils/strings";
import { argbFromRgba } from "@material/material-color-utilities";
@ -895,10 +887,7 @@ export class SummaryUiHandler extends UiHandler {
profileContainer.add(luckText);
}
if (
globalScene.gameData.achvUnlocks.hasOwnProperty(achvs.TERASTALLIZE.id)
&& !isNullOrUndefined(this.pokemon)
) {
if (globalScene.gameData.achvUnlocks.hasOwnProperty(achvs.TERASTALLIZE.id) && this.pokemon != null) {
const teraIcon = globalScene.add.sprite(123, 26, "button_tera");
teraIcon.setName("terastallize-icon");
teraIcon.setFrame(PokemonType[this.pokemon.getTeraType()].toLowerCase());

View File

@ -8,7 +8,7 @@ import type { Pokemon } from "#field/pokemon";
import type { ModifierBar } from "#modifiers/modifier";
import { getMoveTargets } from "#moves/move-utils";
import { UiHandler } from "#ui/ui-handler";
import { fixedInt, isNullOrUndefined } from "#utils/common";
import { fixedInt } from "#utils/common";
export type TargetSelectCallback = (targets: BattlerIndex[]) => void;
@ -71,7 +71,7 @@ export class TargetSelectUiHandler extends UiHandler {
*/
resetCursor(cursorN: number, user: Pokemon): void {
if (
!isNullOrUndefined(cursorN)
cursorN != null
&& ([BattlerIndex.PLAYER, BattlerIndex.PLAYER_2].includes(cursorN) || user.tempSummonData.waveTurnCount === 1)
) {
// Reset cursor on the first turn of a fight or if an ally was targeted last turn
@ -90,13 +90,10 @@ export class TargetSelectUiHandler extends UiHandler {
this.targetSelectCallback(button === Button.ACTION ? targetIndexes : []);
success = true;
if (this.fieldIndex === BattlerIndex.PLAYER) {
if (isNullOrUndefined(this.cursor0) || this.cursor0 !== this.cursor) {
if (this.cursor0 == null || this.cursor0 !== this.cursor) {
this.cursor0 = this.cursor;
}
} else if (
this.fieldIndex === BattlerIndex.PLAYER_2
&& (isNullOrUndefined(this.cursor1) || this.cursor1 !== this.cursor)
) {
} else if (this.fieldIndex === BattlerIndex.PLAYER_2 && (this.cursor1 == null || this.cursor1 !== this.cursor)) {
this.cursor1 = this.cursor;
}
} else if (this.isMultipleTargets) {

View File

@ -4,7 +4,6 @@ import type { OptionSelectItem } from "#ui/abstract-option-select-ui-handler";
import type { InputFieldConfig } from "#ui/form-modal-ui-handler";
import { FormModalUiHandler } from "#ui/form-modal-ui-handler";
import type { ModalConfig } from "#ui/modal-ui-handler";
import { isNullOrUndefined } from "#utils/common";
import i18next from "i18next";
export class TestDialogueUiHandler extends FormModalUiHandler {
@ -18,7 +17,7 @@ export class TestDialogueUiHandler extends FormModalUiHandler {
.map((t, i) => {
const value = Object.values(object)[i];
if (typeof value === "object" && !isNullOrUndefined(value)) {
if (typeof value === "object" && value != null) {
// we check for not null or undefined here because if the language json file has a null key, the typeof will still be an object, but that object will be null, causing issues
// If the value is an object, execute the same process
// si el valor es un objeto ejecuta el mismo proceso
@ -27,7 +26,7 @@ export class TestDialogueUiHandler extends FormModalUiHandler {
t => t.length > 0,
);
}
if (typeof value === "string" || isNullOrUndefined(value)) {
if (typeof value === "string" || value == null) {
// we check for null or undefined here as per above - the typeof is still an object but the value is null so we need to exit out of this and pass the null key
// Return in the format expected by i18next
@ -109,7 +108,7 @@ export class TestDialogueUiHandler extends FormModalUiHandler {
handler: () => {
// this is here to make sure that if you try to backspace then enter, the last known evt.data (backspace) is picked up
// this is because evt.data is null for backspace, so without this, the autocomplete windows just closes
if (!isNullOrUndefined(evt.data) || evt.inputType?.toLowerCase() === "deletecontentbackward") {
if (evt.data != null || evt.inputType?.toLowerCase() === "deletecontentbackward") {
const separatedArray = inputObject.text.split(" ");
separatedArray[separatedArray.length - 1] = value;
inputObject.setText(separatedArray.join(" "));

View File

@ -458,15 +458,6 @@ export function truncateString(str: string, maxLength = 10) {
return str;
}
/**
* Report whether a given value is nullish (`null`/`undefined`).
* @param val - The value whose nullishness is being checked
* @returns `true` if `val` is either `null` or `undefined`
*/
export function isNullOrUndefined(val: any): val is null | undefined {
return val === null || val === undefined;
}
/**
* This function is used in the context of a Pokémon battle game to calculate the actual integer damage value from a float result.
* Many damage calculation formulas involve various parameters and result in float values.

View File

@ -6,7 +6,6 @@ import { SpeciesId } from "#enums/species-id";
import { StatusEffect } from "#enums/status-effect";
import type { Pokemon } from "#field/pokemon";
import { GameManager } from "#test/test-utils/game-manager";
import { isNullOrUndefined } from "#utils/common";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
@ -37,7 +36,7 @@ describe("Abilities - Healer", () => {
// Mock healer to have a 100% chance of healing its ally
vi.spyOn(allAbilities[AbilityId.HEALER].getAttrs("PostTurnResetStatusAbAttr")[0], "getCondition").mockReturnValue(
(pokemon: Pokemon) => !isNullOrUndefined(pokemon.getAlly()),
(pokemon: Pokemon) => pokemon.getAlly() != null,
);
});

View File

@ -202,7 +202,7 @@ describe("Egg Generation Tests", () => {
const scene = game.scene;
const eggMoveIndex = new Egg({ scene }).eggMoveIndex;
const result = !Utils.isNullOrUndefined(eggMoveIndex) && eggMoveIndex >= 0 && eggMoveIndex <= 3;
const result = eggMoveIndex != null && eggMoveIndex >= 0 && eggMoveIndex <= 3;
expect(result).toBe(true);
});

View File

@ -17,7 +17,6 @@ import type { MessageUiHandler } from "#ui/message-ui-handler";
import type { MysteryEncounterUiHandler } from "#ui/mystery-encounter-ui-handler";
import type { OptionSelectUiHandler } from "#ui/option-select-ui-handler";
import type { PartyUiHandler } from "#ui/party-ui-handler";
import { isNullOrUndefined } from "#utils/common";
import { expect, vi } from "vitest";
/**
@ -147,7 +146,7 @@ export async function runSelectMysteryEncounterOption(
break;
}
if (!isNullOrUndefined(secondaryOptionSelect?.pokemonNo)) {
if (secondaryOptionSelect?.pokemonNo != null) {
await handleSecondaryOptionSelect(game, secondaryOptionSelect.pokemonNo, secondaryOptionSelect.optionNo);
} else {
uiHandler.processInput(Button.ACTION);
@ -174,7 +173,7 @@ async function handleSecondaryOptionSelect(game: GameManager, pokemonNo: number,
partyUiHandler.processInput(Button.ACTION);
// If there is a second choice to make after selecting a Pokemon
if (!isNullOrUndefined(optionNo)) {
if (optionNo != null) {
// Wait for Summary menu to close and second options to spawn
const secondOptionUiHandler = game.scene.ui.handlers[UiMode.OPTION_SELECT] as OptionSelectUiHandler;
vi.spyOn(secondOptionUiHandler, "show");

View File

@ -52,7 +52,6 @@ import type { ModifierSelectUiHandler } from "#ui/modifier-select-ui-handler";
import type { PartyUiHandler } from "#ui/party-ui-handler";
import type { StarterSelectUiHandler } from "#ui/starter-select-ui-handler";
import type { TargetSelectUiHandler } from "#ui/target-select-ui-handler";
import { isNullOrUndefined } from "#utils/common";
import fs from "node:fs";
import { AES, enc } from "crypto-js";
import { expect, vi } from "vitest";
@ -240,7 +239,7 @@ export class GameManager {
* @returns A Promise that resolves when the EncounterPhase ends.
*/
async runToMysteryEncounter(encounterType?: MysteryEncounterType, species?: SpeciesId[]) {
if (!isNullOrUndefined(encounterType)) {
if (encounterType != null) {
this.override.disableTrainerWaves();
this.override.mysteryEncounter(encounterType);
}
@ -272,7 +271,7 @@ export class GameManager {
);
await this.phaseInterceptor.to("EncounterPhase");
if (!isNullOrUndefined(encounterType)) {
if (encounterType != null) {
expect(this.scene.currentBattle?.mysteryEncounter?.encounterType).toBe(encounterType);
}
}