[Feature] Add number of arena trap layers in menu flyout (#2059)

* add number of trap layers in menu flyout

* refactors

* change key type to effectType
This commit is contained in:
Adrian T 2024-06-19 12:29:56 +08:00 committed by GitHub
parent 9463da8797
commit be208d48b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 16 deletions

View File

@ -71,11 +71,18 @@ export class TagAddedEvent extends ArenaEvent {
public arenaTagType: ArenaTagType; public arenaTagType: ArenaTagType;
/** The {@linkcode ArenaTagSide} the tag is being placed on */ /** The {@linkcode ArenaTagSide} the tag is being placed on */
public arenaTagSide: ArenaTagSide; public arenaTagSide: ArenaTagSide;
constructor(arenaTagType: ArenaTagType, arenaTagSide: ArenaTagSide, duration: number) { /** The current number of layers of the arena trap. */
public arenaTagLayers: number;
/** The maximum amount of layers of the arena trap. */
public arenaTagMaxLayers: number;
constructor(arenaTagType: ArenaTagType, arenaTagSide: ArenaTagSide, duration: number, arenaTagLayers?: number, arenaTagMaxLayers?: number) {
super(ArenaEventType.TAG_ADDED, duration); super(ArenaEventType.TAG_ADDED, duration);
this.arenaTagType = arenaTagType; this.arenaTagType = arenaTagType;
this.arenaTagSide = arenaTagSide; this.arenaTagSide = arenaTagSide;
this.arenaTagLayers = arenaTagLayers;
this.arenaTagMaxLayers = arenaTagMaxLayers;
} }
} }
/** /**

View File

@ -7,7 +7,7 @@ import { CommonAnimPhase } from "../phases";
import { CommonAnim } from "../data/battle-anims"; import { CommonAnim } from "../data/battle-anims";
import { Type } from "../data/type"; import { Type } from "../data/type";
import Move from "../data/move"; import Move from "../data/move";
import { ArenaTag, ArenaTagSide, getArenaTag } from "../data/arena-tag"; import { ArenaTag, ArenaTagSide, ArenaTrapTag, getArenaTag } from "../data/arena-tag";
import { BattlerIndex } from "../battle"; import { BattlerIndex } from "../battle";
import { Terrain, TerrainType } from "../data/terrain"; import { Terrain, TerrainType } from "../data/terrain";
import { PostTerrainChangeAbAttr, PostWeatherChangeAbAttr, applyPostTerrainChangeAbAttrs, applyPostWeatherChangeAbAttrs } from "../data/ability"; import { PostTerrainChangeAbAttr, PostWeatherChangeAbAttr, applyPostTerrainChangeAbAttrs, applyPostWeatherChangeAbAttrs } from "../data/ability";
@ -553,6 +553,12 @@ export class Arena {
const existingTag = this.getTagOnSide(tagType, side); const existingTag = this.getTagOnSide(tagType, side);
if (existingTag) { if (existingTag) {
existingTag.onOverlap(this); existingTag.onOverlap(this);
if (existingTag instanceof ArenaTrapTag) {
const { tagType, side, turnCount, layers, maxLayers } = existingTag as ArenaTrapTag;
this.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, layers, maxLayers));
}
return false; return false;
} }
@ -560,7 +566,9 @@ export class Arena {
this.tags.push(newTag); this.tags.push(newTag);
newTag.onAdd(this, quiet); newTag.onAdd(this, quiet);
this.eventTarget.dispatchEvent(new TagAddedEvent(newTag.tagType, newTag.side, newTag.turnCount)); const { layers = 0, maxLayers = 0 } = newTag instanceof ArenaTrapTag ? newTag : {};
this.eventTarget.dispatchEvent(new TagAddedEvent(newTag.tagType, newTag.side, newTag.turnCount, layers, maxLayers));
return true; return true;
} }

View File

@ -1,6 +1,6 @@
import { addTextObject, TextStyle } from "./text"; import { addTextObject, TextStyle } from "./text";
import BattleScene from "#app/battle-scene.js"; import BattleScene from "#app/battle-scene.js";
import { ArenaTagSide } from "#app/data/arena-tag.js"; import { ArenaTagSide, ArenaTrapTag } from "#app/data/arena-tag.js";
import { WeatherType } from "#app/data/weather.js"; import { WeatherType } from "#app/data/weather.js";
import { TerrainType } from "#app/data/terrain.js"; import { TerrainType } from "#app/data/terrain.js";
import { addWindow, WindowVariant } from "./ui-theme"; import { addWindow, WindowVariant } from "./ui-theme";
@ -23,12 +23,14 @@ interface ArenaEffectInfo {
/** The enum string representation of the effect */ /** The enum string representation of the effect */
name: string; name: string;
/** {@linkcode ArenaEffectType} type of effect */ /** {@linkcode ArenaEffectType} type of effect */
type: ArenaEffectType, effecType: ArenaEffectType,
/** The maximum duration set by the effect */ /** The maximum duration set by the effect */
maxDuration: number; maxDuration: number;
/** The current duration left on the effect */ /** The current duration left on the effect */
duration: number; duration: number;
/** The arena tag type being added */
tagType?: ArenaTagType;
} }
export default class ArenaFlyout extends Phaser.GameObjects.Container { export default class ArenaFlyout extends Phaser.GameObjects.Container {
@ -213,7 +215,7 @@ export default class ArenaFlyout extends Phaser.GameObjects.Container {
// Creates a proxy object to decide which text object needs to be updated // Creates a proxy object to decide which text object needs to be updated
let textObject: Phaser.GameObjects.Text; let textObject: Phaser.GameObjects.Text;
switch (fieldEffectInfo.type) { switch (fieldEffectInfo.effecType) {
case ArenaEffectType.PLAYER: case ArenaEffectType.PLAYER:
textObject = this.flyoutTextPlayer; textObject = this.flyoutTextPlayer;
break; break;
@ -231,7 +233,7 @@ export default class ArenaFlyout extends Phaser.GameObjects.Container {
} }
textObject.text += this.formatText(fieldEffectInfo.name); textObject.text += this.formatText(fieldEffectInfo.name);
if (fieldEffectInfo.type === ArenaEffectType.TERRAIN) { if (fieldEffectInfo.effecType === ArenaEffectType.TERRAIN) {
textObject.text += " Terrain"; // Adds 'Terrain' since the enum does not contain it textObject.text += " Terrain"; // Adds 'Terrain' since the enum does not contain it
} }
@ -257,19 +259,42 @@ export default class ArenaFlyout extends Phaser.GameObjects.Container {
switch (arenaEffectChangedEvent.constructor) { switch (arenaEffectChangedEvent.constructor) {
case TagAddedEvent: case TagAddedEvent:
const tagAddedEvent = arenaEffectChangedEvent as TagAddedEvent; const tagAddedEvent = arenaEffectChangedEvent as TagAddedEvent;
const isArenaTrapTag = this.battleScene.arena.getTag(tagAddedEvent.arenaTagType) instanceof ArenaTrapTag;
let arenaEffectType: ArenaEffectType;
if (tagAddedEvent.arenaTagSide === ArenaTagSide.BOTH) {
arenaEffectType = ArenaEffectType.FIELD;
} else if (tagAddedEvent.arenaTagSide === ArenaTagSide.PLAYER) {
arenaEffectType = ArenaEffectType.PLAYER;
} else {
arenaEffectType = ArenaEffectType.ENEMY;
}
const existingTrapTagIndex = isArenaTrapTag ? this.fieldEffectInfo.findIndex(e => tagAddedEvent.arenaTagType === e.tagType && arenaEffectType === e.effecType) : -1;
let name: string = ArenaTagType[tagAddedEvent.arenaTagType];
if (isArenaTrapTag && tagAddedEvent.arenaTagMaxLayers > 1) {
if (existingTrapTagIndex !== -1) {
this.fieldEffectInfo[existingTrapTagIndex].name = `${name} (${tagAddedEvent.arenaTagLayers})`;
break;
} else {
name = `${name} (${tagAddedEvent.arenaTagLayers})`;
}
}
this.fieldEffectInfo.push({ this.fieldEffectInfo.push({
name: ArenaTagType[tagAddedEvent.arenaTagType], name,
type: tagAddedEvent.arenaTagSide === ArenaTagSide.BOTH effecType: arenaEffectType,
? ArenaEffectType.FIELD
: tagAddedEvent.arenaTagSide === ArenaTagSide.PLAYER
? ArenaEffectType.PLAYER
: ArenaEffectType.ENEMY,
maxDuration: tagAddedEvent.duration, maxDuration: tagAddedEvent.duration,
duration: tagAddedEvent.duration}); duration: tagAddedEvent.duration,
tagType: tagAddedEvent.arenaTagType
});
break; break;
case TagRemovedEvent: case TagRemovedEvent:
const tagRemovedEvent = arenaEffectChangedEvent as TagRemovedEvent; const tagRemovedEvent = arenaEffectChangedEvent as TagRemovedEvent;
foundIndex = this.fieldEffectInfo.findIndex(info => info.name === ArenaTagType[tagRemovedEvent.arenaTagType]); foundIndex = this.fieldEffectInfo.findIndex(info => info.tagType === tagRemovedEvent.arenaTagType);
if (foundIndex !== -1) { // If the tag was being tracked, remove it if (foundIndex !== -1) { // If the tag was being tracked, remove it
this.fieldEffectInfo.splice(foundIndex, 1); this.fieldEffectInfo.splice(foundIndex, 1);
} }
@ -290,7 +315,7 @@ export default class ArenaFlyout extends Phaser.GameObjects.Container {
fieldEffectChangedEvent instanceof WeatherChangedEvent fieldEffectChangedEvent instanceof WeatherChangedEvent
? WeatherType[fieldEffectChangedEvent.newWeatherType] ? WeatherType[fieldEffectChangedEvent.newWeatherType]
: TerrainType[fieldEffectChangedEvent.newTerrainType], : TerrainType[fieldEffectChangedEvent.newTerrainType],
type: fieldEffectChangedEvent instanceof WeatherChangedEvent effecType: fieldEffectChangedEvent instanceof WeatherChangedEvent
? ArenaEffectType.WEATHER ? ArenaEffectType.WEATHER
: ArenaEffectType.TERRAIN, : ArenaEffectType.TERRAIN,
maxDuration: fieldEffectChangedEvent.duration, maxDuration: fieldEffectChangedEvent.duration,