Save battler tags (#516)

* Save battler tags

Also saves the rest of the summonData except for transform specific things.

* Add missing values for type boost tag.

* Add intellisense comments
pull/673/head
Xavion3 2024-05-09 15:37:51 +10:00 committed by GitHub
parent a48a12ec0b
commit e6ba60364e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 165 additions and 3 deletions

View File

@ -68,6 +68,17 @@ export class BattlerTag {
? allMoves[this.sourceMove].name ? allMoves[this.sourceMove].name
: null; : null;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* This is meant to be inherited from by any battler tag with custom attributes
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
this.turnCount = source.turnCount;
this.sourceMove = source.sourceMove;
this.sourceId = source.sourceId;
}
} }
export interface WeatherBattlerTag { export interface WeatherBattlerTag {
@ -299,6 +310,15 @@ export class SeedTag extends BattlerTag {
super(BattlerTagType.SEEDED, BattlerTagLapseType.TURN_END, 1, Moves.LEECH_SEED, sourceId); super(BattlerTagType.SEEDED, BattlerTagLapseType.TURN_END, 1, Moves.LEECH_SEED, sourceId);
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.sourceIndex = source.sourceIndex;
}
canAdd(pokemon: Pokemon): boolean { canAdd(pokemon: Pokemon): boolean {
return !pokemon.isOfType(Type.GRASS); return !pokemon.isOfType(Type.GRASS);
} }
@ -404,6 +424,15 @@ export class EncoreTag extends BattlerTag {
super(BattlerTagType.ENCORE, BattlerTagLapseType.AFTER_MOVE, 3, Moves.ENCORE, sourceId); super(BattlerTagType.ENCORE, BattlerTagLapseType.AFTER_MOVE, 3, Moves.ENCORE, sourceId);
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.moveId = source.moveId as Moves;
}
canAdd(pokemon: Pokemon): boolean { canAdd(pokemon: Pokemon): boolean {
if (pokemon.isMax()) if (pokemon.isMax())
return false; return false;
@ -553,6 +582,15 @@ export abstract class DamagingTrapTag extends TrappedTag {
this.commonAnim = commonAnim; this.commonAnim = commonAnim;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.commonAnim = source.commonAnim as CommonAnim;
}
canAdd(pokemon: Pokemon): boolean { canAdd(pokemon: Pokemon): boolean {
return !pokemon.isOfType(Type.GHOST) && !pokemon.findTag(t => t instanceof DamagingTrapTag); return !pokemon.isOfType(Type.GHOST) && !pokemon.findTag(t => t instanceof DamagingTrapTag);
} }
@ -709,6 +747,15 @@ export class ContactDamageProtectedTag extends ProtectedTag {
this.damageRatio = damageRatio; this.damageRatio = damageRatio;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.damageRatio = source.damageRatio;
}
lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
const ret = super.lapse(pokemon, lapseType); const ret = super.lapse(pokemon, lapseType);
@ -735,6 +782,16 @@ export class ContactStatChangeProtectedTag extends ProtectedTag {
this.levels = levels; this.levels = levels;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.stat = source.stat as BattleStat;
this.levels = source.levels;
}
lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
const ret = super.lapse(pokemon, lapseType); const ret = super.lapse(pokemon, lapseType);
@ -855,6 +912,15 @@ export class AbilityBattlerTag extends BattlerTag {
this.ability = ability; this.ability = ability;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.ability = source.ability as Abilities;
}
} }
export class TruantTag extends AbilityBattlerTag { export class TruantTag extends AbilityBattlerTag {
@ -912,6 +978,16 @@ export class HighestStatBoostTag extends AbilityBattlerTag {
super(tagType, ability, BattlerTagLapseType.CUSTOM, 1); super(tagType, ability, BattlerTagLapseType.CUSTOM, 1);
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.stat = source.stat as Stat;
this.multiplier = this.multiplier;
}
onAdd(pokemon: Pokemon): void { onAdd(pokemon: Pokemon): void {
super.onAdd(pokemon); super.onAdd(pokemon);
@ -953,6 +1029,15 @@ export class WeatherHighestStatBoostTag extends HighestStatBoostTag implements W
super(tagType, ability); super(tagType, ability);
this.weatherTypes = weatherTypes; this.weatherTypes = weatherTypes;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.weatherTypes = source.weatherTypes.map(w => w as WeatherType);
}
} }
export class TerrainHighestStatBoostTag extends HighestStatBoostTag implements TerrainBattlerTag { export class TerrainHighestStatBoostTag extends HighestStatBoostTag implements TerrainBattlerTag {
@ -962,6 +1047,15 @@ export class TerrainHighestStatBoostTag extends HighestStatBoostTag implements T
super(tagType, ability); super(tagType, ability);
this.terrainTypes = terrainTypes; this.terrainTypes = terrainTypes;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.terrainTypes = source.terrainTypes.map(w => w as TerrainType);
}
} }
export class HideSpriteTag extends BattlerTag { export class HideSpriteTag extends BattlerTag {
@ -989,6 +1083,15 @@ export class TypeImmuneTag extends BattlerTag {
constructor(tagType: BattlerTagType, sourceMove: Moves, immuneType: Type, length: number) { constructor(tagType: BattlerTagType, sourceMove: Moves, immuneType: Type, length: number) {
super(tagType, BattlerTagLapseType.TURN_END, 1, sourceMove); super(tagType, BattlerTagLapseType.TURN_END, 1, sourceMove);
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.immuneType = source.immuneType as Type;
}
} }
export class MagnetRisenTag extends TypeImmuneTag { export class MagnetRisenTag extends TypeImmuneTag {
@ -1010,6 +1113,17 @@ export class TypeBoostTag extends BattlerTag {
this.oneUse = oneUse; this.oneUse = oneUse;
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.boostedType = source.boostedType as Type;
this.boostValue = source.boostValue;
this.oneUse = source.oneUse;
}
lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
return lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); return lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType);
} }
@ -1056,6 +1170,15 @@ export class SaltCuredTag extends BattlerTag {
super(BattlerTagType.SALT_CURED, BattlerTagLapseType.TURN_END, 1, Moves.SALT_CURE, sourceId); super(BattlerTagType.SALT_CURED, BattlerTagLapseType.TURN_END, 1, Moves.SALT_CURE, sourceId);
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.sourceIndex = source.sourceIndex;
}
onAdd(pokemon: Pokemon): void { onAdd(pokemon: Pokemon): void {
super.onAdd(pokemon); super.onAdd(pokemon);
@ -1091,6 +1214,15 @@ export class CursedTag extends BattlerTag {
super(BattlerTagType.CURSED, BattlerTagLapseType.TURN_END, 1, Moves.CURSE, sourceId); super(BattlerTagType.CURSED, BattlerTagLapseType.TURN_END, 1, Moves.CURSE, sourceId);
} }
/**
* When given a battler tag or json representing one, load the data for it.
* @param {BattlerTag | any} source A battler tag
*/
loadTag(source: BattlerTag | any): void {
super.loadTag(source);
this.sourceIndex = source.sourceIndex;
}
onAdd(pokemon: Pokemon): void { onAdd(pokemon: Pokemon): void {
super.onAdd(pokemon); super.onAdd(pokemon);
@ -1231,4 +1363,15 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: integer, sourc
return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId); return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId);
} }
} }
/**
* When given a battler tag or json representing one, creates an actual BattlerTag object with the same data.
* @param {BattlerTag | any} source A battler tag
* @return {BattlerTag} The valid battler tag
*/
export function loadBattlerTag(source: BattlerTag | any): BattlerTag {
const tag = getBattlerTag(source.tagType, source.turnCount, source.sourceMove, source.sourceId);
tag.loadTag(source);
return tag;
}

View File

@ -3232,4 +3232,13 @@ export class PokemonMove {
getName(): string { getName(): string {
return this.getMove().name; return this.getMove().name;
} }
/**
* Copies an existing move or creates a valid PokemonMove object from json representing one
* @param {PokemonMove | any} source The data for the move to copy
* @return {PokemonMove} A valid pokemonmove object
*/
static loadMove(source: PokemonMove | any): PokemonMove {
return new PokemonMove(source.moveId, source.ppUsed, source.ppUp, source.virtual);
}
} }

View File

@ -11,6 +11,7 @@ import Pokemon, { EnemyPokemon, PokemonMove, PokemonSummonData } from "../field/
import { TrainerSlot } from "../data/trainer-config"; import { TrainerSlot } from "../data/trainer-config";
import { Moves } from "../data/enums/moves"; import { Moves } from "../data/enums/moves";
import { Variant } from "#app/data/variant"; import { Variant } from "#app/data/variant";
import { loadBattlerTag } from '../data/battler-tags';
export default class PokemonData { export default class PokemonData {
public id: integer; public id: integer;
@ -112,9 +113,18 @@ export default class PokemonData {
if (!forHistory && source.summonData) { if (!forHistory && source.summonData) {
this.summonData.battleStats = source.summonData.battleStats; this.summonData.battleStats = source.summonData.battleStats;
this.summonData.moveQueue = source.summonData.moveQueue; this.summonData.moveQueue = source.summonData.moveQueue;
this.summonData.tags = []; // TODO this.summonData.disabledMove = source.summonData.disabledMove;
this.summonData.moveset = source.summonData.moveset; 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));
this.summonData.types = source.summonData.types; this.summonData.types = source.summonData.types;
if (source.summonData.tags)
this.summonData.tags = source.summonData.tags?.map(t => loadBattlerTag(t));
else
this.summonData.tags = [];
} }
} }
} }