pokerogue/src/system/pokemon-data.ts

117 lines
4.6 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";
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 shiny: boolean;
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;
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 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;
public fusionGender: Gender;
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.shiny = source.shiny;
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.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;
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;
this.fusionGender = source.fusionGender;
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 {
this.moveset = source.moveset.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.tags = []; // TODO
this.summonData.moveset = source.summonData.moveset;
2023-04-28 20:03:42 +01:00
this.summonData.types = source.summonData.types;
}
}
}
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
? scene.addPlayerPokemon(species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, 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
}
}