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";
|
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";
|
2024-05-09 06:37:51 +01:00
|
|
|
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;
|
2024-04-13 23:59:58 +01:00
|
|
|
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;
|
2024-04-03 04:00:56 +01:00
|
|
|
public natureOverride: Nature | -1;
|
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;
|
2024-04-26 22:32:28 +01:00
|
|
|
public luck: integer;
|
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;
|
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;
|
|
|
|
|
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;
|
2024-04-13 23:59:58 +01:00
|
|
|
this.passive = source.passive;
|
2023-04-28 20:03:42 +01:00
|
|
|
this.shiny = source.shiny;
|
2024-04-13 23:59:58 +01:00
|
|
|
this.variant = source.variant;
|
2023-04-28 20:03:42 +01:00
|
|
|
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;
|
2024-04-03 04:00:56 +01:00
|
|
|
this.natureOverride = source.natureOverride !== undefined ? source.natureOverride : -1;
|
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-04-26 23:27:00 +01:00
|
|
|
this.luck = source.luck !== undefined ? source.luck : (source.shiny ? (source.variant + 1) : 0);
|
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;
|
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
|
|
|
|
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-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));
|
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;
|
2024-05-09 06:37:51 +01:00
|
|
|
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;
|
2024-05-09 06:37:51 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
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)
|
2024-03-25 14:16:29 +00:00
|
|
|
: 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
|
|
|
}
|
|
|
|
}
|