Create Getters, Setters, and Types

This commit is contained in:
xsn34kzx 2024-08-09 14:06:12 -04:00
parent 762feea332
commit ed792d4066
3 changed files with 86 additions and 5 deletions

View File

@ -1,8 +1,24 @@
export enum Stat { export enum Stat {
/** Hit Points */
HP = 0, HP = 0,
/** Attack */
ATK, ATK,
/** Defense */
DEF, DEF,
/** Special Attack */
SPATK, SPATK,
/** Special Defense */
SPDEF, SPDEF,
/** Speed */
SPD, SPD,
/** Accuracy */
ACC,
/** Evasiveness */
EVA
} }
export type PermanentStat = Exclude<Stat, Stat.ACC | Stat.EVA>;
export type BattleStat = Exclude<Stat, Stat.HP>;
export type TempBattleStat = Exclude<BattleStat, Stat.EVA>;

View File

@ -18,7 +18,6 @@ import { Status, StatusEffect, getRandomStatus } from "../data/status-effect";
import { pokemonEvolutions, pokemonPrevolutions, SpeciesFormEvolution, SpeciesEvolutionCondition, FusionSpeciesFormEvolution } from "../data/pokemon-evolutions"; import { pokemonEvolutions, pokemonPrevolutions, SpeciesFormEvolution, SpeciesEvolutionCondition, FusionSpeciesFormEvolution } from "../data/pokemon-evolutions";
import { reverseCompatibleTms, tmSpecies, tmPoolTiers } from "../data/tms"; import { reverseCompatibleTms, tmSpecies, tmPoolTiers } from "../data/tms";
import { DamagePhase, FaintPhase, LearnMovePhase, MoveEffectPhase, ObtainStatusEffectPhase, StatChangePhase, SwitchSummonPhase, ToggleDoublePositionPhase, MoveEndPhase } from "../phases"; import { DamagePhase, FaintPhase, LearnMovePhase, MoveEffectPhase, ObtainStatusEffectPhase, StatChangePhase, SwitchSummonPhase, ToggleDoublePositionPhase, MoveEndPhase } from "../phases";
import { BattleStat } from "../data/battle-stat";
import { BattlerTag, BattlerTagLapseType, EncoreTag, GroundedTag, HighestStatBoostTag, TypeImmuneTag, getBattlerTag, SemiInvulnerableTag, TypeBoostTag, ExposedTag } from "../data/battler-tags"; import { BattlerTag, BattlerTagLapseType, EncoreTag, GroundedTag, HighestStatBoostTag, TypeImmuneTag, getBattlerTag, SemiInvulnerableTag, TypeBoostTag, ExposedTag } from "../data/battler-tags";
import { WeatherType } from "../data/weather"; import { WeatherType } from "../data/weather";
import { TempBattleStat } from "../data/temp-battle-stat"; import { TempBattleStat } from "../data/temp-battle-stat";
@ -51,6 +50,7 @@ import { Biome } from "#enums/biome";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { getPokemonNameWithAffix } from "#app/messages.js"; import { getPokemonNameWithAffix } from "#app/messages.js";
import { PermanentStat, BattleStat } from "#app/enums/stat";
export enum FieldPosition { export enum FieldPosition {
CENTER, CENTER,
@ -663,10 +663,74 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
}); });
} }
getStat(stat: Stat): integer { /**
* Retrieves the entire set of stats of the {@linkcode Pokemon}.
* @param ignoreOverride {@linkcode boolean} to prefer actual stats (`true` by default) or in-battle overriden stats (`false`)
* @returns the numeric values of the {@linkcode Pokemon}'s stats
*/
getStats(ignoreOverride: boolean = true): number[] {
if (!ignoreOverride && this.summonData?.stats) {
return this.summonData.stats;
}
return this.stats;
}
/**
* Retrieves the corresponding {@linkcode PermanentStat} of the {@linkcode Pokemon}.
* @param stat the desired {@linkcode PermanentStat}
* @param ignoreOverride {@linkcode boolean} to prefer actual stats (`true` by default) or in-battle overridden stats (`false`)
* @returns the numeric value of the desired {@linkcode Stat}
*/
getStat(stat: PermanentStat, ignoreOverride: boolean = true): number {
if (!ignoreOverride && this.summonData?.stats[stat] !== 0) {
return this.summonData.stats[stat];
}
return this.stats[stat]; return this.stats[stat];
} }
/**
* Writes the value to the corrseponding {@linkcode PermanentStat} of the {@linkcode Pokemon}.
*
* Note that this does nothing if {@linkcode value} is less than 0.
* @param stat the desired {@linkcode PermanentStat} to be overwritten
* @param value the desired numeric value
* @param ignoreOverride {@linkcode boolean} to write to actual stats (`true` by default) or in-battle overridden stats (`false`)
*/
setStat(stat: PermanentStat, value: number, ignoreOverride: boolean = true): void {
if (value >= 0) {
if (!ignoreOverride && this.summonData) {
this.summonData.stats[stat] = value;
} else {
this.stats[stat] = value;
}
}
}
/**
* Retrieves the in-battle stage of the {@linkcode BattleStat}.
* @param stat the {@linkcode BattleStat} whose stage is desired
* @returns the stage of the desired {@linkcode BattleStat} if available, 0 otherwise
*/
getStatStage(stat: BattleStat): number {
if (this.summonData) {
return this.summonData.statStages[stat - 1];
}
return 0;
}
/**
* Writes the value to the in-battle stage of the corresponding {@linkcode BattleStat} of the {@linkcode Pokemon}.
*
* Note that this does nothing if {@linkcode value} is less than -6 and greater than 6.
* @param stat the {@linkcode BattleStat} whose stage is to be overwritten
* @param value the desired numeric value
*/
setStatStage(stat: BattleStat, value: number): void {
if ((value >= -6) && (value >= 6) && this.summonData) {
this.summonData.statStages[stat - 1] = value;
}
}
getBattleStat(stat: Stat, opponent?: Pokemon, move?: Move, isCritical: boolean = false): integer { getBattleStat(stat: Stat, opponent?: Pokemon, move?: Move, isCritical: boolean = false): integer {
if (stat === Stat.HP) { if (stat === Stat.HP) {
return this.getStat(Stat.HP); return this.getStat(Stat.HP);
@ -4203,7 +4267,7 @@ export interface AttackMoveResult {
} }
export class PokemonSummonData { export class PokemonSummonData {
public battleStats: integer[] = [ 0, 0, 0, 0, 0, 0, 0 ]; public statStages: number[] = [ 0, 0, 0, 0, 0, 0, 0 ];
public moveQueue: QueuedMove[] = []; public moveQueue: QueuedMove[] = [];
public disabledMove: Moves = Moves.NONE; public disabledMove: Moves = Moves.NONE;
public disabledTurns: integer = 0; public disabledTurns: integer = 0;
@ -4216,7 +4280,7 @@ export class PokemonSummonData {
public ability: Abilities = Abilities.NONE; public ability: Abilities = Abilities.NONE;
public gender: Gender; public gender: Gender;
public fusionGender: Gender; public fusionGender: Gender;
public stats: integer[]; public stats: number[] = [ 0, 0, 0, 0, 0, 0 ];
public moveset: (PokemonMove | null)[]; public moveset: (PokemonMove | null)[];
// If not initialized this value will not be populated from save data. // If not initialized this value will not be populated from save data.
public types: Type[] = []; public types: Type[] = [];

View File

@ -122,7 +122,8 @@ export default class PokemonData {
this.summonData = new PokemonSummonData(); this.summonData = new PokemonSummonData();
if (!forHistory && source.summonData) { if (!forHistory && source.summonData) {
this.summonData.battleStats = source.summonData.battleStats; this.summonData.stats = source.summonData.stats;
this.summonData.statStages = source.summonData.statStages;
this.summonData.moveQueue = source.summonData.moveQueue; this.summonData.moveQueue = source.summonData.moveQueue;
this.summonData.disabledMove = source.summonData.disabledMove; this.summonData.disabledMove = source.summonData.disabledMove;
this.summonData.disabledTurns = source.summonData.disabledTurns; this.summonData.disabledTurns = source.summonData.disabledTurns;