mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-23 15:03:24 +02:00
Convert uses of StatusEffect[] to Uint8Array
This commit is contained in:
parent
fd4c037959
commit
ccaef59660
@ -64,6 +64,7 @@ import type {
|
|||||||
} from "#types/ability-types";
|
} from "#types/ability-types";
|
||||||
import type { Localizable } from "#types/locales";
|
import type { Localizable } from "#types/locales";
|
||||||
import type { Closed, Exact } from "#types/type-helpers";
|
import type { Closed, Exact } from "#types/type-helpers";
|
||||||
|
import type { GenericUint8Array, ReadonlyGenericInt8Array, ReadonlyGenericUint8Array } from "#types/typed-arrays";
|
||||||
import { coerceArray } from "#utils/array";
|
import { coerceArray } from "#utils/array";
|
||||||
import type { Constructor } from "#utils/common";
|
import type { Constructor } from "#utils/common";
|
||||||
import { BooleanHolder, NumberHolder, randSeedFloat, randSeedInt, randSeedItem, toDmgValue } from "#utils/common";
|
import { BooleanHolder, NumberHolder, randSeedFloat, randSeedInt, randSeedItem, toDmgValue } from "#utils/common";
|
||||||
@ -1210,13 +1211,13 @@ export class PostDefendTerrainChangeAbAttr extends PostDefendAbAttr {
|
|||||||
|
|
||||||
export class PostDefendContactApplyStatusEffectAbAttr extends PostDefendAbAttr {
|
export class PostDefendContactApplyStatusEffectAbAttr extends PostDefendAbAttr {
|
||||||
private chance: number;
|
private chance: number;
|
||||||
private effects: StatusEffect[];
|
private readonly effects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
constructor(chance: number, ...effects: StatusEffect[]) {
|
constructor(chance: number, ...effects: StatusEffect[]) {
|
||||||
super(true);
|
super(true);
|
||||||
|
|
||||||
this.chance = chance;
|
this.chance = chance;
|
||||||
this.effects = effects;
|
this.effects = new Uint8Array(effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ pokemon, move, opponent: attacker }: PostMoveInteractionAbAttrParams): boolean {
|
override canApply({ pokemon, move, opponent: attacker }: PostMoveInteractionAbAttrParams): boolean {
|
||||||
@ -2180,14 +2181,14 @@ export class PostAttackStealHeldItemAbAttr extends PostAttackAbAttr {
|
|||||||
export class PostAttackApplyStatusEffectAbAttr extends PostAttackAbAttr {
|
export class PostAttackApplyStatusEffectAbAttr extends PostAttackAbAttr {
|
||||||
private contactRequired: boolean;
|
private contactRequired: boolean;
|
||||||
private chance: number;
|
private chance: number;
|
||||||
private effects: StatusEffect[];
|
private readonly effects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
constructor(contactRequired: boolean, chance: number, ...effects: StatusEffect[]) {
|
constructor(contactRequired: boolean, chance: number, ...effects: StatusEffect[]) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.contactRequired = contactRequired;
|
this.contactRequired = contactRequired;
|
||||||
this.chance = chance;
|
this.chance = chance;
|
||||||
this.effects = effects;
|
this.effects = new Uint8Array(effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply(params: PostMoveInteractionAbAttrParams): boolean {
|
override canApply(params: PostMoveInteractionAbAttrParams): boolean {
|
||||||
@ -2940,7 +2941,7 @@ export class PostSummonTerrainChangeAbAttr extends PostSummonAbAttr {
|
|||||||
* Heals a status effect if the Pokemon is afflicted with it upon switch in (or gain)
|
* Heals a status effect if the Pokemon is afflicted with it upon switch in (or gain)
|
||||||
*/
|
*/
|
||||||
export class PostSummonHealStatusAbAttr extends PostSummonRemoveEffectAbAttr {
|
export class PostSummonHealStatusAbAttr extends PostSummonRemoveEffectAbAttr {
|
||||||
private immuneEffects: StatusEffect[];
|
private readonly immuneEffects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
private statusHealed: StatusEffect;
|
private statusHealed: StatusEffect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2948,12 +2949,12 @@ export class PostSummonHealStatusAbAttr extends PostSummonRemoveEffectAbAttr {
|
|||||||
*/
|
*/
|
||||||
constructor(...immuneEffects: StatusEffect[]) {
|
constructor(...immuneEffects: StatusEffect[]) {
|
||||||
super();
|
super();
|
||||||
this.immuneEffects = immuneEffects;
|
this.immuneEffects = new Uint8Array(immuneEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override canApply({ pokemon }: AbAttrBaseParams): boolean {
|
public override canApply({ pokemon }: AbAttrBaseParams): boolean {
|
||||||
const status = pokemon.status?.effect;
|
const status = pokemon.status?.effect;
|
||||||
return status != null && (this.immuneEffects.length === 0 || this.immuneEffects.includes(status));
|
return status != null && this.immuneEffects.includes(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override apply({ pokemon }: AbAttrBaseParams): void {
|
public override apply({ pokemon }: AbAttrBaseParams): void {
|
||||||
@ -3049,7 +3050,7 @@ export class PostSummonCopyAbilityAbAttr extends PostSummonAbAttr {
|
|||||||
* Removes supplied status effects from the user's field.
|
* Removes supplied status effects from the user's field.
|
||||||
*/
|
*/
|
||||||
export class PostSummonUserFieldRemoveStatusEffectAbAttr extends PostSummonAbAttr {
|
export class PostSummonUserFieldRemoveStatusEffectAbAttr extends PostSummonAbAttr {
|
||||||
private statusEffect: StatusEffect[];
|
private readonly statusEffect: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param statusEffect - The status effects to be removed from the user's field.
|
* @param statusEffect - The status effects to be removed from the user's field.
|
||||||
@ -3057,7 +3058,7 @@ export class PostSummonUserFieldRemoveStatusEffectAbAttr extends PostSummonAbAtt
|
|||||||
constructor(...statusEffect: StatusEffect[]) {
|
constructor(...statusEffect: StatusEffect[]) {
|
||||||
super(false);
|
super(false);
|
||||||
|
|
||||||
this.statusEffect = statusEffect;
|
this.statusEffect = new Uint8Array(statusEffect);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ pokemon }: AbAttrBaseParams): boolean {
|
override canApply({ pokemon }: AbAttrBaseParams): boolean {
|
||||||
@ -3637,7 +3638,7 @@ export class PreSetStatusAbAttr extends AbAttr {
|
|||||||
* Provides immunity to status effects to specified targets.
|
* Provides immunity to status effects to specified targets.
|
||||||
*/
|
*/
|
||||||
export class PreSetStatusEffectImmunityAbAttr extends PreSetStatusAbAttr {
|
export class PreSetStatusEffectImmunityAbAttr extends PreSetStatusAbAttr {
|
||||||
protected immuneEffects: StatusEffect[];
|
protected readonly immuneEffects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param immuneEffects - An array of {@linkcode StatusEffect}s to prevent application.
|
* @param immuneEffects - An array of {@linkcode StatusEffect}s to prevent application.
|
||||||
@ -3646,7 +3647,7 @@ export class PreSetStatusEffectImmunityAbAttr extends PreSetStatusAbAttr {
|
|||||||
constructor(...immuneEffects: StatusEffect[]) {
|
constructor(...immuneEffects: StatusEffect[]) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.immuneEffects = immuneEffects;
|
this.immuneEffects = new Uint8Array(immuneEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ effect, cancelled }: PreSetStatusAbAttrParams): boolean {
|
override canApply({ effect, cancelled }: PreSetStatusAbAttrParams): boolean {
|
||||||
@ -3705,7 +3706,7 @@ export interface UserFieldStatusEffectImmunityAbAttrParams extends AbAttrBasePar
|
|||||||
*/
|
*/
|
||||||
export class UserFieldStatusEffectImmunityAbAttr extends CancelInteractionAbAttr {
|
export class UserFieldStatusEffectImmunityAbAttr extends CancelInteractionAbAttr {
|
||||||
private declare readonly _: never;
|
private declare readonly _: never;
|
||||||
protected immuneEffects: StatusEffect[];
|
protected readonly immuneEffects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param immuneEffects - An array of {@linkcode StatusEffect}s to prevent application.
|
* @param immuneEffects - An array of {@linkcode StatusEffect}s to prevent application.
|
||||||
@ -3714,7 +3715,7 @@ export class UserFieldStatusEffectImmunityAbAttr extends CancelInteractionAbAttr
|
|||||||
constructor(...immuneEffects: StatusEffect[]) {
|
constructor(...immuneEffects: StatusEffect[]) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.immuneEffects = immuneEffects;
|
this.immuneEffects = new Uint8Array(immuneEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ effect, cancelled }: UserFieldStatusEffectImmunityAbAttrParams): boolean {
|
override canApply({ effect, cancelled }: UserFieldStatusEffectImmunityAbAttrParams): boolean {
|
||||||
@ -3998,7 +3999,7 @@ export class BlockNonDirectDamageAbAttr extends CancelInteractionAbAttr {
|
|||||||
* This attribute will block any status damage that you put in the parameter.
|
* This attribute will block any status damage that you put in the parameter.
|
||||||
*/
|
*/
|
||||||
export class BlockStatusDamageAbAttr extends CancelInteractionAbAttr {
|
export class BlockStatusDamageAbAttr extends CancelInteractionAbAttr {
|
||||||
private effects: StatusEffect[];
|
private readonly effects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param effects - The status effect(s) that will be blocked from damaging the ability pokemon
|
* @param effects - The status effect(s) that will be blocked from damaging the ability pokemon
|
||||||
@ -4006,7 +4007,7 @@ export class BlockStatusDamageAbAttr extends CancelInteractionAbAttr {
|
|||||||
constructor(...effects: StatusEffect[]) {
|
constructor(...effects: StatusEffect[]) {
|
||||||
super(false);
|
super(false);
|
||||||
|
|
||||||
this.effects = effects;
|
this.effects = new Uint8Array(effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ pokemon, cancelled }: AbAttrParamsWithCancel): boolean {
|
override canApply({ pokemon, cancelled }: AbAttrParamsWithCancel): boolean {
|
||||||
@ -4539,7 +4540,7 @@ export class PostTurnAbAttr extends AbAttr {
|
|||||||
* @sealed
|
* @sealed
|
||||||
*/
|
*/
|
||||||
export class PostTurnStatusHealAbAttr extends PostTurnAbAttr {
|
export class PostTurnStatusHealAbAttr extends PostTurnAbAttr {
|
||||||
private effects: StatusEffect[];
|
private readonly effects: GenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param effects - The status effect(s) that will qualify healing the ability pokemon
|
* @param effects - The status effect(s) that will qualify healing the ability pokemon
|
||||||
@ -4547,7 +4548,7 @@ export class PostTurnStatusHealAbAttr extends PostTurnAbAttr {
|
|||||||
constructor(...effects: StatusEffect[]) {
|
constructor(...effects: StatusEffect[]) {
|
||||||
super(false);
|
super(false);
|
||||||
|
|
||||||
this.effects = effects;
|
this.effects = new Uint8Array(effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ pokemon }: AbAttrBaseParams): boolean {
|
override canApply({ pokemon }: AbAttrBaseParams): boolean {
|
||||||
@ -5808,14 +5809,14 @@ export interface IgnoreTypeStatusEffectImmunityAbAttrParams extends AbAttrParams
|
|||||||
* @sealed
|
* @sealed
|
||||||
*/
|
*/
|
||||||
export class IgnoreTypeStatusEffectImmunityAbAttr extends AbAttr {
|
export class IgnoreTypeStatusEffectImmunityAbAttr extends AbAttr {
|
||||||
private statusEffect: StatusEffect[];
|
private readonly statusEffect: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
private defenderType: PokemonType[];
|
private readonly defenderType: ReadonlyGenericInt8Array<PokemonType>;
|
||||||
|
|
||||||
constructor(statusEffect: StatusEffect[], defenderType: PokemonType[]) {
|
constructor(statusEffect: StatusEffect[], defenderType: PokemonType[]) {
|
||||||
super(false);
|
super(false);
|
||||||
|
|
||||||
this.statusEffect = statusEffect;
|
this.statusEffect = new Uint8Array(statusEffect);
|
||||||
this.defenderType = defenderType;
|
this.defenderType = new Int8Array(defenderType);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ statusEffect, defenderType, cancelled }: IgnoreTypeStatusEffectImmunityAbAttrParams): boolean {
|
override canApply({ statusEffect, defenderType, cancelled }: IgnoreTypeStatusEffectImmunityAbAttrParams): boolean {
|
||||||
|
@ -95,6 +95,7 @@ import i18next from "i18next";
|
|||||||
import { applyChallenges } from "#utils/challenge-utils";
|
import { applyChallenges } from "#utils/challenge-utils";
|
||||||
import { MovePhaseTimingModifier } from "#enums/move-phase-timing-modifier";
|
import { MovePhaseTimingModifier } from "#enums/move-phase-timing-modifier";
|
||||||
import type { AbstractConstructor } from "#types/type-helpers";
|
import type { AbstractConstructor } from "#types/type-helpers";
|
||||||
|
import type { ReadonlyGenericUint8Array } from "#types/typed-arrays";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function used to conditionally determine execution of a given {@linkcode MoveAttr}.
|
* A function used to conditionally determine execution of a given {@linkcode MoveAttr}.
|
||||||
@ -2595,11 +2596,11 @@ export class StatusEffectAttr extends MoveEffectAttr {
|
|||||||
* Used for {@linkcode Moves.TRI_ATTACK} and {@linkcode Moves.DIRE_CLAW}.
|
* Used for {@linkcode Moves.TRI_ATTACK} and {@linkcode Moves.DIRE_CLAW}.
|
||||||
*/
|
*/
|
||||||
export class MultiStatusEffectAttr extends StatusEffectAttr {
|
export class MultiStatusEffectAttr extends StatusEffectAttr {
|
||||||
public effects: StatusEffect[];
|
public readonly effects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
constructor(effects: StatusEffect[], selfTarget?: boolean) {
|
constructor(effects: StatusEffect[], selfTarget?: boolean) {
|
||||||
super(effects[0], selfTarget);
|
super(effects[0], selfTarget);
|
||||||
this.effects = effects;
|
this.effects = new Uint8Array(effects);
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
|
||||||
@ -2925,7 +2926,7 @@ export class StealEatBerryAttr extends EatBerryAttr {
|
|||||||
*/
|
*/
|
||||||
export class HealStatusEffectAttr extends MoveEffectAttr {
|
export class HealStatusEffectAttr extends MoveEffectAttr {
|
||||||
/** List of Status Effects to cure */
|
/** List of Status Effects to cure */
|
||||||
private effects: StatusEffect[];
|
private readonly effects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param selfTarget - Whether this move targets the user
|
* @param selfTarget - Whether this move targets the user
|
||||||
@ -2933,7 +2934,7 @@ export class HealStatusEffectAttr extends MoveEffectAttr {
|
|||||||
*/
|
*/
|
||||||
constructor(selfTarget: boolean, effects: StatusEffect | StatusEffect[]) {
|
constructor(selfTarget: boolean, effects: StatusEffect | StatusEffect[]) {
|
||||||
super(selfTarget, { lastHitOnly: true });
|
super(selfTarget, { lastHitOnly: true });
|
||||||
this.effects = coerceArray(effects)
|
this.effects = new Uint8Array(coerceArray(effects));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ import { WeatherType } from "#enums/weather-type";
|
|||||||
import type { PlayerPokemon } from "#field/pokemon";
|
import type { PlayerPokemon } from "#field/pokemon";
|
||||||
import { AttackTypeBoosterModifier } from "#modifiers/modifier";
|
import { AttackTypeBoosterModifier } from "#modifiers/modifier";
|
||||||
import type { AttackTypeBoosterModifierType } from "#modifiers/modifier-type";
|
import type { AttackTypeBoosterModifierType } from "#modifiers/modifier-type";
|
||||||
|
import type { ReadonlyGenericUint8Array } from "#types/typed-arrays";
|
||||||
import { coerceArray } from "#utils/array";
|
import { coerceArray } from "#utils/array";
|
||||||
|
|
||||||
export interface EncounterRequirement {
|
export interface EncounterRequirement {
|
||||||
@ -696,7 +697,7 @@ export class AbilityRequirement extends EncounterPokemonRequirement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class StatusEffectRequirement extends EncounterPokemonRequirement {
|
export class StatusEffectRequirement extends EncounterPokemonRequirement {
|
||||||
requiredStatusEffect: StatusEffect[];
|
requiredStatusEffect: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
minNumberOfPokemon: number;
|
minNumberOfPokemon: number;
|
||||||
invertQuery: boolean;
|
invertQuery: boolean;
|
||||||
|
|
||||||
@ -704,7 +705,7 @@ export class StatusEffectRequirement extends EncounterPokemonRequirement {
|
|||||||
super();
|
super();
|
||||||
this.minNumberOfPokemon = minNumberOfPokemon;
|
this.minNumberOfPokemon = minNumberOfPokemon;
|
||||||
this.invertQuery = invertQuery;
|
this.invertQuery = invertQuery;
|
||||||
this.requiredStatusEffect = coerceArray(statusEffect);
|
this.requiredStatusEffect = new Uint8Array(coerceArray(statusEffect));
|
||||||
}
|
}
|
||||||
|
|
||||||
override meetsRequirement(): boolean {
|
override meetsRequirement(): boolean {
|
||||||
|
@ -11,6 +11,7 @@ import type { TimeOfDay } from "#enums/time-of-day";
|
|||||||
import { WeatherType } from "#enums/weather-type";
|
import { WeatherType } from "#enums/weather-type";
|
||||||
import type { Pokemon } from "#field/pokemon";
|
import type { Pokemon } from "#field/pokemon";
|
||||||
import type { PokemonFormChangeItemModifier } from "#modifiers/modifier";
|
import type { PokemonFormChangeItemModifier } from "#modifiers/modifier";
|
||||||
|
import type { ReadonlyGenericUint8Array } from "#types/typed-arrays";
|
||||||
import { coerceArray } from "#utils/array";
|
import { coerceArray } from "#utils/array";
|
||||||
import type { Constructor } from "#utils/common";
|
import type { Constructor } from "#utils/common";
|
||||||
import { toCamelCase } from "#utils/strings";
|
import { toCamelCase } from "#utils/strings";
|
||||||
@ -122,12 +123,12 @@ export class SpeciesFormChangeActiveTrigger extends SpeciesFormChangeTrigger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SpeciesFormChangeStatusEffectTrigger extends SpeciesFormChangeTrigger {
|
export class SpeciesFormChangeStatusEffectTrigger extends SpeciesFormChangeTrigger {
|
||||||
public statusEffects: StatusEffect[];
|
public readonly statusEffects: ReadonlyGenericUint8Array<StatusEffect>;
|
||||||
public invert: boolean;
|
public invert: boolean;
|
||||||
|
|
||||||
constructor(statusEffects: StatusEffect | StatusEffect[], invert = false) {
|
constructor(statusEffects: StatusEffect | StatusEffect[], invert = false) {
|
||||||
super();
|
super();
|
||||||
this.statusEffects = coerceArray(statusEffects);
|
this.statusEffects = new Uint8Array(coerceArray(statusEffects));
|
||||||
this.invert = invert;
|
this.invert = invert;
|
||||||
// this.description = i18next.t("pokemonEvolutions:forms.statusEffect");
|
// this.description = i18next.t("pokemonEvolutions:forms.statusEffect");
|
||||||
}
|
}
|
||||||
|
7
src/typings/phaser/index.d.ts
vendored
7
src/typings/phaser/index.d.ts
vendored
@ -54,6 +54,13 @@ declare module "phaser" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Math {
|
||||||
|
interface RandomDataGenerator {
|
||||||
|
pick<T>(array: ArrayLike<T>): T;
|
||||||
|
weightedPick<T>(array: ArrayLike<T>): T;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace Input {
|
namespace Input {
|
||||||
namespace Gamepad {
|
namespace Gamepad {
|
||||||
interface GamepadPlugin {
|
interface GamepadPlugin {
|
||||||
|
@ -125,11 +125,11 @@ export function randSeedFloat(): number {
|
|||||||
return Phaser.Math.RND.frac();
|
return Phaser.Math.RND.frac();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randItem<T>(items: T[]): T {
|
export function randItem<T>(items: ArrayLike<T>): T {
|
||||||
return items.length === 1 ? items[0] : items[randInt(items.length)];
|
return items.length === 1 ? items[0] : items[randInt(items.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randSeedItem<T>(items: T[]): T {
|
export function randSeedItem<T>(items: ArrayLike<T>): T {
|
||||||
return items.length === 1 ? items[0] : Phaser.Math.RND.pick(items);
|
return items.length === 1 ? items[0] : Phaser.Math.RND.pick(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user