diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index 8942cfe4b..501b87a84 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -54,6 +54,18 @@ export abstract class ArenaTag { ? allMoves[this.sourceMove].name : null; } + + /** + * When given an arena tag or json representing one, load the data for it. + * This is meant to be inherited from by any arena tag with custom attributes + * @param {ArenaTag | any} source An arena tag, or json representing one + */ + loadTag(source: ArenaTag | any): void { + this.turnCount = source.turnCount; + this.sourceMove = source.sourceMove; + this.sourceId = source.sourceId; + this.side = source.side; + } } export class MistTag extends ArenaTag { @@ -169,6 +181,17 @@ class WishTag extends ArenaTag { arena.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(), this.healHp, null, true, false)); } } + + /** + * Given a WishTag or json representing one, load the data for it. + * @param {WishTag | any} source A WishTag + */ + loadTag(source: WishTag | any): void { + super.loadTag(source); + this.battlerIndex = source.battlerIndex as BattlerIndex; + this.triggerMessage = source.triggerMessage; + this.healHp = source.healHp; + } } export class WeakenMoveTypeTag extends ArenaTag { @@ -188,6 +211,15 @@ export class WeakenMoveTypeTag extends ArenaTag { return false; } + + /** + * Given a WeakenMoveTypeTag or json representing one, load the data for it. + * @param {WeakenMoveTypeTag | any} source A WeakenMoveTypeTag + */ + loadTag(source: WeakenMoveTypeTag | any): void { + super.loadTag(source); + this.weakenedType = source.weakenedType as Type; + } } class MudSportTag extends WeakenMoveTypeTag { @@ -252,6 +284,16 @@ export class ArenaTrapTag extends ArenaTag { getMatchupScoreMultiplier(pokemon: Pokemon): number { return pokemon.isGrounded() ? 1 : Phaser.Math.Linear(0, 1 / Math.pow(2, this.layers), Math.min(pokemon.getHpRatio(), 0.5) * 2); } + + /** + * Given an ArenaTrapTag or json representing one, load the data for it. + * @param {ArenaTrapTag | any} source An ArenaTrapTag + */ + loadTag(source: ArenaTrapTag | any): void { + super.loadTag(source); + this.layers = source.layers; + this.maxLayers = source.maxLayers; + } } class SpikesTag extends ArenaTrapTag { @@ -331,6 +373,15 @@ class ToxicSpikesTag extends ArenaTrapTag { return 1.25; return super.getMatchupScoreMultiplier(pokemon); } + + /** + * Given a ToxicSpikesTag or json representing one, load the data for it. + * @param {ToxicSpikesTag | any} source A ToxicSpikesTag + */ + loadTag(source: ToxicSpikesTag | any): void { + super.loadTag(source); + this.neutralized = source.neutralized; + } } class DelayedAttackTag extends ArenaTag { @@ -352,6 +403,15 @@ class DelayedAttackTag extends ArenaTag { } onRemove(arena: Arena): void { } + + /** + * Given a DelayedAttackTag or json representing one, load the data for it. + * @param {DelayedAttackTag | any} source A DelayedAttackTag + */ + loadTag(source: DelayedAttackTag | any): void { + super.loadTag(source); + this.targetIndex = source.targetIndex; + } } class StealthRockTag extends ArenaTrapTag { @@ -496,7 +556,7 @@ class TailwindTag extends ArenaTag { } } -export function getArenaTag(tagType: ArenaTagType, turnCount: integer, sourceMove: Moves, sourceId: integer, targetIndex?: BattlerIndex, side: ArenaTagSide = ArenaTagSide.BOTH): ArenaTag { +export function getArenaTag(tagType: ArenaTagType, turnCount: integer, sourceMove: Moves, sourceId: integer, side: ArenaTagSide = ArenaTagSide.BOTH, targetIndex?: BattlerIndex): ArenaTag { switch (tagType) { case ArenaTagType.MIST: return new MistTag(turnCount, sourceId, side); @@ -531,3 +591,14 @@ export function getArenaTag(tagType: ArenaTagType, turnCount: integer, sourceMov return new TailwindTag(turnCount, sourceId, side); } } + +/** + * When given an arena tag or json representing one, creates the actual ArenaTag object with the same data loaded. + * @param {ArenaTag | any} source An arena tag, or json representing one. + * @return {ArenaTag} The valid arena tag with correct data loaded. + */ +export function loadArenaTag(source: ArenaTag | any): ArenaTag { + const tag = getArenaTag(source.tagType, source.turnCount, source.sourceMove, source.sourceId, source.side, source?.targetIndex); + tag.loadTag(source); + return tag; +} \ No newline at end of file diff --git a/src/field/arena.ts b/src/field/arena.ts index a2bde9422..105cf17cb 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -497,7 +497,7 @@ export class Arena { return false; } - const newTag = getArenaTag(tagType, turnCount || 0, sourceMove, sourceId, targetIndex, side); + const newTag = getArenaTag(tagType, turnCount || 0, sourceMove, sourceId, side, targetIndex); this.tags.push(newTag); newTag.onAdd(this); diff --git a/src/system/arena-data.ts b/src/system/arena-data.ts index 4d5fb10e8..78b9c7471 100644 --- a/src/system/arena-data.ts +++ b/src/system/arena-data.ts @@ -1,5 +1,5 @@ import { Arena } from "../field/arena"; -import { ArenaTag } from "../data/arena-tag"; +import { ArenaTag, loadArenaTag } from "../data/arena-tag"; import { Biome } from "../data/enums/biome"; import { Weather } from "../data/weather"; @@ -12,6 +12,10 @@ export default class ArenaData { const sourceArena = source instanceof Arena ? source as Arena : null; this.biome = sourceArena ? sourceArena.biomeType : source.biome; this.weather = sourceArena ? sourceArena.weather : source.weather ? new Weather(source.weather.weatherType, source.weather.turnsLeft) : undefined; - this.tags = sourceArena ? sourceArena.tags : []; + const arenaTags: ArenaTag[] = sourceArena ? sourceArena.tags : source.tags; + this.tags = []; + for (let tag of arenaTags) { + this.tags.push(loadArenaTag(tag)) + } } } \ No newline at end of file diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 7f6e1475b..8e63848f2 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -688,8 +688,7 @@ export class GameData { }); scene.arena.weather = sessionData.arena.weather; - // TODO - //scene.arena.tags = sessionData.arena.tags; + scene.arena.tags = sessionData.arena.tags; const modifiersModule = await import('../modifier/modifier');