2023-10-28 15:51:34 +01:00
|
|
|
import { BattleType } from "../battle";
|
2023-04-28 20:03:42 +01:00
|
|
|
import BattleScene from "../battle-scene";
|
2024-01-13 17:24:24 +00:00
|
|
|
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";
|
2024-01-13 17:24:24 +00:00
|
|
|
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";
|
2024-03-21 04:57:28 +00:00
|
|
|
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;
|
2023-12-22 04:00:45 +00:00
|
|
|
public friendship: integer;
|
2024-01-05 16:29:34 +00:00
|
|
|
public metLevel: integer;
|
|
|
|
public metBiome: Biome | -1;
|
2023-12-14 17:55:11 +00:00
|
|
|
public pauseEvolutions: boolean;
|
2023-10-25 19:15:44 +01:00
|
|
|
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;
|
|
|
|
|
2024-01-13 17:24:24 +00:00
|
|
|
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;
|
2024-02-21 17:38:07 +00:00
|
|
|
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;
|
2024-01-13 17:24:24 +00:00
|
|
|
if (!forHistory)
|
|
|
|
this.levelExp = source.levelExp;
|
2023-04-28 20:03:42 +01:00
|
|
|
this.gender = source.gender;
|
2024-01-13 17:24:24 +00:00
|
|
|
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;
|
2023-12-22 04:00:45 +00:00
|
|
|
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-01-13 17:24:24 +00:00
|
|
|
if (!forHistory)
|
|
|
|
this.pauseEvolutions = !!source.pauseEvolutions;
|
2023-10-25 19:15:44 +01:00
|
|
|
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;
|
|
|
|
|
2024-01-13 17:24:24 +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;
|
2024-01-13 17:24:24 +00:00
|
|
|
if (!forHistory) {
|
|
|
|
this.status = sourcePokemon.status;
|
|
|
|
if (this.player)
|
|
|
|
this.summonData = sourcePokemon.summonData;
|
|
|
|
}
|
2023-04-28 20:03:42 +01:00
|
|
|
} else {
|
2024-03-02 14:46:08 +00:00
|
|
|
this.moveset = source.moveset.filter(m => m).map((m: any) => new PokemonMove(m.moveId, m.ppUsed, m.ppUp));
|
2024-01-13 17:24:24 +00:00
|
|
|
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();
|
2024-01-13 17:24:24 +00:00
|
|
|
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
|
2023-05-06 05:42:01 +01:00
|
|
|
this.summonData.moveset = source.summonData.moveset;
|
2023-04-28 20:03:42 +01:00
|
|
|
this.summonData.types = source.summonData.types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 16:34:19 +00: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);
|
2024-03-25 14:16:29 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|