From dcdc270f44fa0cb31b4d3ea5c20e7c123d586b4b Mon Sep 17 00:00:00 2001 From: Xavion3 Date: Mon, 6 May 2024 09:37:15 +1000 Subject: [PATCH] Save battler tags Also saves the rest of the summonData except for transform specific things. --- src/data/battler-tags.ts | 81 +++++++++++++++++++++++++++++++++++++- src/field/pokemon.ts | 4 ++ src/system/pokemon-data.ts | 14 ++++++- 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index 183306d5066..34a2e7b4881 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -68,6 +68,12 @@ export class BattlerTag { ? allMoves[this.sourceMove].name : null; } + + loadTag(source: BattlerTag | any): void { + this.turnCount = source.turnCount; + this.sourceMove = source.sourceMove; + this.sourceId = source.sourceId; + } } export interface WeatherBattlerTag { @@ -299,6 +305,11 @@ export class SeedTag extends BattlerTag { super(BattlerTagType.SEEDED, BattlerTagLapseType.TURN_END, 1, Moves.LEECH_SEED, sourceId); } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.sourceIndex = source.sourceIndex; + } + canAdd(pokemon: Pokemon): boolean { return !pokemon.isOfType(Type.GRASS); } @@ -404,6 +415,11 @@ export class EncoreTag extends BattlerTag { super(BattlerTagType.ENCORE, BattlerTagLapseType.AFTER_MOVE, 3, Moves.ENCORE, sourceId); } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.moveId = source.moveId as Moves; + } + canAdd(pokemon: Pokemon): boolean { if (pokemon.isMax()) return false; @@ -553,6 +569,11 @@ export abstract class DamagingTrapTag extends TrappedTag { this.commonAnim = commonAnim; } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.commonAnim = source.commonAnim as CommonAnim; + } + canAdd(pokemon: Pokemon): boolean { return !pokemon.isOfType(Type.GHOST) && !pokemon.findTag(t => t instanceof DamagingTrapTag); } @@ -709,6 +730,11 @@ export class ContactDamageProtectedTag extends ProtectedTag { this.damageRatio = damageRatio; } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.damageRatio = source.damageRatio; + } + lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = super.lapse(pokemon, lapseType); @@ -735,6 +761,12 @@ export class ContactStatChangeProtectedTag extends ProtectedTag { this.levels = levels; } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.stat = source.stat as BattleStat; + this.levels = source.levels; + } + lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { const ret = super.lapse(pokemon, lapseType); @@ -855,6 +887,11 @@ export class AbilityBattlerTag extends BattlerTag { this.ability = ability; } + + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.ability = source.ability as Abilities; + } } export class TruantTag extends AbilityBattlerTag { @@ -912,6 +949,12 @@ export class HighestStatBoostTag extends AbilityBattlerTag { super(tagType, ability, BattlerTagLapseType.CUSTOM, 1); } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.stat = source.stat as Stat; + this.multiplier = this.multiplier; + } + onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); @@ -953,6 +996,11 @@ export class WeatherHighestStatBoostTag extends HighestStatBoostTag implements W super(tagType, ability); this.weatherTypes = weatherTypes; } + + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.weatherTypes = source.weatherTypes.map(w => w as WeatherType); + } } export class TerrainHighestStatBoostTag extends HighestStatBoostTag implements TerrainBattlerTag { @@ -962,6 +1010,11 @@ export class TerrainHighestStatBoostTag extends HighestStatBoostTag implements T super(tagType, ability); this.terrainTypes = terrainTypes; } + + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.terrainTypes = source.terrainTypes.map(w => w as TerrainType); + } } export class HideSpriteTag extends BattlerTag { @@ -989,6 +1042,11 @@ export class TypeImmuneTag extends BattlerTag { constructor(tagType: BattlerTagType, sourceMove: Moves, immuneType: Type, length: number) { super(tagType, BattlerTagLapseType.TURN_END, 1, sourceMove); } + + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.immuneType = source.immuneType as Type; + } } export class MagnetRisenTag extends TypeImmuneTag { @@ -1010,6 +1068,11 @@ export class TypeBoostTag extends BattlerTag { this.oneUse = oneUse; } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.boostedType = source.boostedType as Type; + } + lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean { return lapseType !== BattlerTagLapseType.CUSTOM || super.lapse(pokemon, lapseType); } @@ -1056,6 +1119,11 @@ export class SaltCuredTag extends BattlerTag { super(BattlerTagType.SALT_CURED, BattlerTagLapseType.TURN_END, 1, Moves.SALT_CURE, sourceId); } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.sourceIndex = source.sourceIndex; + } + onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); @@ -1091,6 +1159,11 @@ export class CursedTag extends BattlerTag { super(BattlerTagType.CURSED, BattlerTagLapseType.TURN_END, 1, Moves.CURSE, sourceId); } + loadTag(source: BattlerTag | any): void { + super.loadTag(source); + this.sourceIndex = source.sourceIndex; + } + onAdd(pokemon: Pokemon): void { super.onAdd(pokemon); @@ -1231,4 +1304,10 @@ export function getBattlerTag(tagType: BattlerTagType, turnCount: integer, sourc return new BattlerTag(tagType, BattlerTagLapseType.CUSTOM, turnCount, sourceMove, sourceId); } } - \ No newline at end of file + +export function loadBattlerTag(source: BattlerTag | any): BattlerTag { + const tag = getBattlerTag(source.tagType, source.turnCount, source.sourceMove, source.sourceId); + tag.loadTag(source); + return tag; +} + diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 606185e0984..308318de0ba 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -3186,4 +3186,8 @@ export class PokemonMove { getName(): string { return this.getMove().name; } + + static loadMove(source: PokemonMove | any): PokemonMove { + return new PokemonMove(source.moveId, source.ppUsed, source.ppUp, source.virtual); + } } diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index b9589020e9b..dfbb9be570b 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -11,6 +11,7 @@ import Pokemon, { EnemyPokemon, PokemonMove, PokemonSummonData } from "../field/ import { TrainerSlot } from "../data/trainer-config"; import { Moves } from "../data/enums/moves"; import { Variant } from "#app/data/variant"; +import { loadBattlerTag } from '../data/battler-tags'; export default class PokemonData { public id: integer; @@ -112,9 +113,18 @@ export default class PokemonData { if (!forHistory && source.summonData) { this.summonData.battleStats = source.summonData.battleStats; this.summonData.moveQueue = source.summonData.moveQueue; - this.summonData.tags = []; // TODO - this.summonData.moveset = source.summonData.moveset; + 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)); this.summonData.types = source.summonData.types; + + if (source.summonData.tags) + this.summonData.tags = source.summonData.tags?.map(t => loadBattlerTag(t)); + else + this.summonData.tags = []; } } }