pokerogue/src/system/pokemon-data.ts

141 lines
5.9 KiB
TypeScript
Raw Normal View History

import { BattleType } from "../battle";
2023-04-28 20:03:42 +01:00
import BattleScene from "../battle-scene";
import { Biome } from "../data/enums/biome";
2023-04-28 20:03:42 +01:00
import { Gender } from "../data/gender";
2024-01-06 03:24:05 +00:00
import { Nature } from "../data/nature";
2023-04-28 20:03:42 +01:00
import { PokeballType } from "../data/pokeball";
import { getPokemonSpecies } from "../data/pokemon-species";
import { Species } from "../data/enums/species";
2023-04-28 20:03:42 +01:00
import { Status } from "../data/status-effect";
2024-03-01 01:08:50 +00:00
import Pokemon, { EnemyPokemon, PokemonMove, PokemonSummonData } from "../field/pokemon";
import { TrainerSlot } from "../data/trainer-config";
2024-03-25 18:47:41 +00:00
import { Moves } from "../data/enums/moves";
2024-04-19 03:52:26 +01:00
import { Variant } from "#app/data/variant";
import { loadBattlerTag } from '../data/battler-tags';
2023-04-28 20:03:42 +01:00
export default class PokemonData {
public id: integer;
public player: boolean;
public species: Species;
public formIndex: integer;
public abilityIndex: integer;
public passive: boolean;
2023-04-28 20:03:42 +01:00
public shiny: boolean;
2024-04-19 03:52:26 +01:00
public variant: Variant;
2023-04-28 20:03:42 +01:00
public pokeball: PokeballType;
public level: integer;
public exp: integer;
public levelExp: integer;
public gender: Gender;
public hp: integer;
public stats: integer[];
public ivs: integer[];
2024-01-06 03:24:05 +00:00
public nature: Nature;
public natureOverride: Nature | -1;
2023-04-28 20:03:42 +01:00
public moveset: PokemonMove[];
public status: Status;
public friendship: integer;
2024-01-05 16:29:34 +00:00
public metLevel: integer;
public metBiome: Biome | -1;
public luck: integer;
public pauseEvolutions: boolean;
public pokerus: boolean;
2023-04-28 20:03:42 +01:00
2023-11-04 04:32:12 +00:00
public fusionSpecies: Species;
public fusionFormIndex: integer;
public fusionAbilityIndex: integer;
public fusionShiny: boolean;
2024-04-19 03:52:26 +01:00
public fusionVariant: Variant;
2023-11-04 04:32:12 +00:00
public fusionGender: Gender;
2024-04-26 23:27:00 +01:00
public fusionLuck: integer;
2023-11-04 04:32:12 +00:00
2024-01-08 04:17:24 +00:00
public boss: boolean;
2023-04-28 20:03:42 +01:00
public summonData: PokemonSummonData;
constructor(source: Pokemon | any, forHistory: boolean = false) {
2023-04-28 20:03:42 +01:00
const sourcePokemon = source instanceof Pokemon ? source as Pokemon : null;
this.id = source.id;
this.player = sourcePokemon ? sourcePokemon.isPlayer() : source.player;
this.species = sourcePokemon ? sourcePokemon.species.speciesId : source.species;
this.formIndex = Math.max(Math.min(source.formIndex, getPokemonSpecies(this.species).forms.length - 1), 0);
2023-04-28 20:03:42 +01:00
this.abilityIndex = source.abilityIndex;
this.passive = source.passive;
2023-04-28 20:03:42 +01:00
this.shiny = source.shiny;
this.variant = source.variant;
2023-04-28 20:03:42 +01:00
this.pokeball = source.pokeball;
this.level = source.level;
this.exp = source.exp;
if (!forHistory)
this.levelExp = source.levelExp;
2023-04-28 20:03:42 +01:00
this.gender = source.gender;
if (!forHistory)
this.hp = source.hp;
2023-04-28 20:03:42 +01:00
this.stats = source.stats;
this.ivs = source.ivs;
2024-01-06 03:24:05 +00:00
this.nature = source.nature !== undefined ? source.nature : 0 as Nature;
this.natureOverride = source.natureOverride !== undefined ? source.natureOverride : -1;
this.friendship = source.friendship !== undefined ? source.friendship : getPokemonSpecies(this.species).baseFriendship;
2024-01-05 16:29:34 +00:00
this.metLevel = source.metLevel || 5;
this.metBiome = source.metBiome !== undefined ? source.metBiome : -1;
2024-04-26 23:27:00 +01:00
this.luck = source.luck !== undefined ? source.luck : (source.shiny ? (source.variant + 1) : 0);
if (!forHistory)
this.pauseEvolutions = !!source.pauseEvolutions;
this.pokerus = !!source.pokerus;
2023-04-28 20:03:42 +01:00
2023-11-04 04:32:12 +00:00
this.fusionSpecies = sourcePokemon ? sourcePokemon.fusionSpecies?.speciesId : source.fusionSpecies;
this.fusionFormIndex = source.fusionFormIndex;
this.fusionAbilityIndex = source.fusionAbilityIndex;
this.fusionShiny = source.fusionShiny;
2024-04-19 03:52:26 +01:00
this.fusionVariant = source.fusionVariant;
2023-11-04 04:32:12 +00:00
this.fusionGender = source.fusionGender;
2024-04-26 23:27:00 +01:00
this.fusionLuck = source.fusionLuck !== undefined ? source.fusionLuck : (source.fusionShiny ? source.fusionVariant + 1 : 0);
2023-11-04 04:32:12 +00:00
if (!forHistory)
this.boss = (source instanceof EnemyPokemon && !!source.bossSegments) || (!this.player && !!source.boss);
2024-01-08 04:17:24 +00:00
2023-04-28 20:03:42 +01:00
if (sourcePokemon) {
this.moveset = sourcePokemon.moveset;
if (!forHistory) {
this.status = sourcePokemon.status;
if (this.player)
this.summonData = sourcePokemon.summonData;
}
2023-04-28 20:03:42 +01:00
} else {
2024-03-25 18:47:41 +00:00
this.moveset = (source.moveset || [ new PokemonMove(Moves.TACKLE), new PokemonMove(Moves.GROWL) ]).filter(m => m).map((m: any) => new PokemonMove(m.moveId, m.ppUsed, m.ppUp));
if (!forHistory) {
this.status = source.status
? new Status(source.status.effect, source.status.turnCount, source.status.cureTurn)
: undefined;
}
2023-04-28 20:03:42 +01:00
this.summonData = new PokemonSummonData();
if (!forHistory && source.summonData) {
2023-04-28 20:03:42 +01:00
this.summonData.battleStats = source.summonData.battleStats;
this.summonData.moveQueue = source.summonData.moveQueue;
this.summonData.disabledMove = source.summonData.disabledMove;
this.summonData.disabledTurns = source.summonData.disabledTurns;
this.summonData.abilitySuppressed = source.summonData.abilitySuppressed;
this.summonData.ability = source.summonData.ability;
this.summonData.moveset = source.summonData.moveset?.map(m => PokemonMove.loadMove(m));
2023-04-28 20:03:42 +01:00
this.summonData.types = source.summonData.types;
if (source.summonData.tags)
this.summonData.tags = source.summonData.tags?.map(t => loadBattlerTag(t));
else
this.summonData.tags = [];
2023-04-28 20:03:42 +01:00
}
}
}
toPokemon(scene: BattleScene, battleType?: BattleType, partyMemberIndex: integer = 0, double: boolean = false): Pokemon {
2023-04-28 20:03:42 +01:00
const species = getPokemonSpecies(this.species);
const ret: Pokemon = this.player
2024-04-19 03:52:26 +01:00
? scene.addPlayerPokemon(species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this)
: scene.addEnemyPokemon(species, this.level, battleType === BattleType.TRAINER ? !double || !(partyMemberIndex % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER : TrainerSlot.NONE, this.boss, this);
if (this.summonData)
ret.primeSummonData(this.summonData);
return ret;
2023-04-28 20:03:42 +01:00
}
}