[UI/UX] Show correct max duration in flyout (#6566)

* Fix terrain & weather max duration flyout

* show correct max duration for tags

* maka maxDuration optional in arenaEvent constructor

* Apply suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
Fabi 2025-09-18 22:35:22 +02:00 committed by GitHub
parent 0e87391b20
commit 7d83a3a24a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 45 additions and 22 deletions

View File

@ -84,6 +84,10 @@ interface BaseArenaTag {
* The tag's remaining duration. Setting to any number `<=0` will make the tag's duration effectively infinite. * The tag's remaining duration. Setting to any number `<=0` will make the tag's duration effectively infinite.
*/ */
turnCount: number; turnCount: number;
/**
* The tag's max duration.
*/
maxDuration: number;
/** /**
* The {@linkcode MoveId} that created this tag, or `undefined` if not set by a move. * The {@linkcode MoveId} that created this tag, or `undefined` if not set by a move.
*/ */
@ -110,12 +114,14 @@ export abstract class ArenaTag implements BaseArenaTag {
/** The type of the arena tag */ /** The type of the arena tag */
public abstract readonly tagType: ArenaTagType; public abstract readonly tagType: ArenaTagType;
public turnCount: number; public turnCount: number;
public maxDuration: number;
public sourceMove?: MoveId; public sourceMove?: MoveId;
public sourceId: number | undefined; public sourceId: number | undefined;
public side: ArenaTagSide; public side: ArenaTagSide;
constructor(turnCount: number, sourceMove?: MoveId, sourceId?: number, side: ArenaTagSide = ArenaTagSide.BOTH) { constructor(turnCount: number, sourceMove?: MoveId, sourceId?: number, side: ArenaTagSide = ArenaTagSide.BOTH) {
this.turnCount = turnCount; this.turnCount = turnCount;
this.maxDuration = turnCount;
this.sourceMove = sourceMove; this.sourceMove = sourceMove;
this.sourceId = sourceId; this.sourceId = sourceId;
this.side = side; this.side = side;
@ -164,6 +170,7 @@ export abstract class ArenaTag implements BaseArenaTag {
*/ */
loadTag<const T extends this>(source: BaseArenaTag & Pick<T, "tagType">): void { loadTag<const T extends this>(source: BaseArenaTag & Pick<T, "tagType">): void {
this.turnCount = source.turnCount; this.turnCount = source.turnCount;
this.maxDuration = source.maxDuration;
this.sourceMove = source.sourceMove; this.sourceMove = source.sourceMove;
this.sourceId = source.sourceId; this.sourceId = source.sourceId;
this.side = source.side; this.side = source.side;

View File

@ -22,10 +22,12 @@ export interface SerializedTerrain {
export class Terrain { export class Terrain {
public terrainType: TerrainType; public terrainType: TerrainType;
public turnsLeft: number; public turnsLeft: number;
public maxDuration: number;
constructor(terrainType: TerrainType, turnsLeft?: number) { constructor(terrainType: TerrainType, turnsLeft = 0, maxDuration: number = turnsLeft) {
this.terrainType = terrainType; this.terrainType = terrainType;
this.turnsLeft = turnsLeft || 0; this.turnsLeft = turnsLeft;
this.maxDuration = maxDuration;
} }
lapse(): boolean { lapse(): boolean {

View File

@ -19,10 +19,12 @@ export interface SerializedWeather {
export class Weather { export class Weather {
public weatherType: WeatherType; public weatherType: WeatherType;
public turnsLeft: number; public turnsLeft: number;
public maxDuration: number;
constructor(weatherType: WeatherType, turnsLeft?: number) { constructor(weatherType: WeatherType, turnsLeft = 0, maxDuration: number = turnsLeft) {
this.weatherType = weatherType; this.weatherType = weatherType;
this.turnsLeft = !this.isImmutable() ? turnsLeft || 0 : 0; this.turnsLeft = this.isImmutable() ? 0 : turnsLeft;
this.maxDuration = this.isImmutable() ? 0 : maxDuration;
} }
lapse(): boolean { lapse(): boolean {

View File

@ -20,10 +20,13 @@ export enum ArenaEventType {
export class ArenaEvent extends Event { export class ArenaEvent extends Event {
/** The total duration of the {@linkcode ArenaEventType} */ /** The total duration of the {@linkcode ArenaEventType} */
public duration: number; public duration: number;
constructor(eventType: ArenaEventType, duration: number) { /** The maximum duration of the {@linkcode ArenaEventType} */
public maxDuration: number;
constructor(eventType: ArenaEventType, duration: number, maxDuration: number = duration) {
super(eventType); super(eventType);
this.duration = duration; this.duration = duration;
this.maxDuration = maxDuration;
} }
} }
/** Container class for {@linkcode ArenaEventType.WEATHER_CHANGED} events */ /** Container class for {@linkcode ArenaEventType.WEATHER_CHANGED} events */
@ -32,8 +35,8 @@ export class WeatherChangedEvent extends ArenaEvent {
public oldWeatherType: WeatherType; public oldWeatherType: WeatherType;
/** The {@linkcode WeatherType} being set */ /** The {@linkcode WeatherType} being set */
public newWeatherType: WeatherType; public newWeatherType: WeatherType;
constructor(oldWeatherType: WeatherType, newWeatherType: WeatherType, duration: number) { constructor(oldWeatherType: WeatherType, newWeatherType: WeatherType, duration: number, maxDuration?: number) {
super(ArenaEventType.WEATHER_CHANGED, duration); super(ArenaEventType.WEATHER_CHANGED, duration, maxDuration);
this.oldWeatherType = oldWeatherType; this.oldWeatherType = oldWeatherType;
this.newWeatherType = newWeatherType; this.newWeatherType = newWeatherType;
@ -45,8 +48,8 @@ export class TerrainChangedEvent extends ArenaEvent {
public oldTerrainType: TerrainType; public oldTerrainType: TerrainType;
/** The {@linkcode TerrainType} being set */ /** The {@linkcode TerrainType} being set */
public newTerrainType: TerrainType; public newTerrainType: TerrainType;
constructor(oldTerrainType: TerrainType, newTerrainType: TerrainType, duration: number) { constructor(oldTerrainType: TerrainType, newTerrainType: TerrainType, duration: number, maxDuration?: number) {
super(ArenaEventType.TERRAIN_CHANGED, duration); super(ArenaEventType.TERRAIN_CHANGED, duration, maxDuration);
this.oldTerrainType = oldTerrainType; this.oldTerrainType = oldTerrainType;
this.newTerrainType = newTerrainType; this.newTerrainType = newTerrainType;
@ -68,10 +71,11 @@ export class TagAddedEvent extends ArenaEvent {
arenaTagType: ArenaTagType, arenaTagType: ArenaTagType,
arenaTagSide: ArenaTagSide, arenaTagSide: ArenaTagSide,
duration: number, duration: number,
maxDuration?: number,
arenaTagLayers?: number, arenaTagLayers?: number,
arenaTagMaxLayers?: number, arenaTagMaxLayers?: number,
) { ) {
super(ArenaEventType.TAG_ADDED, duration); super(ArenaEventType.TAG_ADDED, duration, maxDuration);
this.arenaTagType = arenaTagType; this.arenaTagType = arenaTagType;
this.arenaTagSide = arenaTagSide; this.arenaTagSide = arenaTagSide;

View File

@ -344,7 +344,7 @@ export class Arena {
globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, weatherDuration); globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, weatherDuration);
} }
this.weather = weather ? new Weather(weather, weatherDuration.value) : null; this.weather = weather ? new Weather(weather, weatherDuration.value, weatherDuration.value) : null;
this.eventTarget.dispatchEvent( this.eventTarget.dispatchEvent(
new WeatherChangedEvent(oldWeatherType, this.weather?.weatherType!, this.weather?.turnsLeft!), new WeatherChangedEvent(oldWeatherType, this.weather?.weatherType!, this.weather?.turnsLeft!),
); // TODO: is this bang correct? ); // TODO: is this bang correct?
@ -425,7 +425,7 @@ export class Arena {
globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, terrainDuration); globalScene.applyModifier(FieldEffectModifier, user.isPlayer(), user, terrainDuration);
} }
this.terrain = terrain ? new Terrain(terrain, terrainDuration.value) : null; this.terrain = terrain ? new Terrain(terrain, terrainDuration.value, terrainDuration.value) : null;
this.eventTarget.dispatchEvent( this.eventTarget.dispatchEvent(
new TerrainChangedEvent(oldTerrainType, this.terrain?.terrainType!, this.terrain?.turnsLeft!), new TerrainChangedEvent(oldTerrainType, this.terrain?.terrainType!, this.terrain?.turnsLeft!),
@ -705,8 +705,8 @@ export class Arena {
existingTag.onOverlap(this, globalScene.getPokemonById(sourceId)); existingTag.onOverlap(this, globalScene.getPokemonById(sourceId));
if (existingTag instanceof EntryHazardTag) { if (existingTag instanceof EntryHazardTag) {
const { tagType, side, turnCount, layers, maxLayers } = existingTag as EntryHazardTag; const { tagType, side, turnCount, maxDuration, layers, maxLayers } = existingTag as EntryHazardTag;
this.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, layers, maxLayers)); this.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, maxDuration, layers, maxLayers));
} }
return false; return false;
@ -721,7 +721,7 @@ export class Arena {
const { layers = 0, maxLayers = 0 } = newTag instanceof EntryHazardTag ? newTag : {}; const { layers = 0, maxLayers = 0 } = newTag instanceof EntryHazardTag ? newTag : {};
this.eventTarget.dispatchEvent( this.eventTarget.dispatchEvent(
new TagAddedEvent(newTag.tagType, newTag.side, newTag.turnCount, layers, maxLayers), new TagAddedEvent(newTag.tagType, newTag.side, newTag.turnCount, newTag.maxDuration, layers, maxLayers),
); );
} }

View File

@ -47,8 +47,12 @@ export class ArenaData {
} }
this.biome = source.biome; this.biome = source.biome;
this.weather = source.weather ? new Weather(source.weather.weatherType, source.weather.turnsLeft) : null; this.weather = source.weather
this.terrain = source.terrain ? new Terrain(source.terrain.terrainType, source.terrain.turnsLeft) : null; ? new Weather(source.weather.weatherType, source.weather.turnsLeft, source.weather.maxDuration)
: null;
this.terrain = source.terrain
? new Terrain(source.terrain.terrainType, source.terrain.turnsLeft, source.terrain.maxDuration)
: null;
this.positionalTags = source.positionalTags ?? []; this.positionalTags = source.positionalTags ?? [];
} }
} }

View File

@ -1021,6 +1021,7 @@ export class GameData {
WeatherType.NONE, WeatherType.NONE,
globalScene.arena.weather?.weatherType!, globalScene.arena.weather?.weatherType!,
globalScene.arena.weather?.turnsLeft!, globalScene.arena.weather?.turnsLeft!,
globalScene.arena.weather?.maxDuration!,
), ),
); // TODO: is this bang correct? ); // TODO: is this bang correct?
@ -1030,6 +1031,7 @@ export class GameData {
TerrainType.NONE, TerrainType.NONE,
globalScene.arena.terrain?.terrainType!, globalScene.arena.terrain?.terrainType!,
globalScene.arena.terrain?.turnsLeft!, globalScene.arena.terrain?.turnsLeft!,
globalScene.arena.terrain?.maxDuration!,
), ),
); // TODO: is this bang correct? ); // TODO: is this bang correct?
@ -1039,12 +1041,14 @@ export class GameData {
if (globalScene.arena.tags) { if (globalScene.arena.tags) {
for (const tag of globalScene.arena.tags) { for (const tag of globalScene.arena.tags) {
if (tag instanceof EntryHazardTag) { if (tag instanceof EntryHazardTag) {
const { tagType, side, turnCount, layers, maxLayers } = tag as EntryHazardTag; const { tagType, side, turnCount, maxDuration, layers, maxLayers } = tag as EntryHazardTag;
globalScene.arena.eventTarget.dispatchEvent( globalScene.arena.eventTarget.dispatchEvent(
new TagAddedEvent(tagType, side, turnCount, layers, maxLayers), new TagAddedEvent(tagType, side, turnCount, maxDuration, layers, maxLayers),
); );
} else { } else {
globalScene.arena.eventTarget.dispatchEvent(new TagAddedEvent(tag.tagType, tag.side, tag.turnCount)); globalScene.arena.eventTarget.dispatchEvent(
new TagAddedEvent(tag.tagType, tag.side, tag.turnCount, tag.maxDuration),
);
} }
} }
} }

View File

@ -317,7 +317,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container {
this.fieldEffectInfo.push({ this.fieldEffectInfo.push({
name, name,
effectType: arenaEffectType, effectType: arenaEffectType,
maxDuration: tagAddedEvent.duration, maxDuration: tagAddedEvent.maxDuration,
duration: tagAddedEvent.duration, duration: tagAddedEvent.duration,
tagType: tagAddedEvent.arenaTagType, tagType: tagAddedEvent.arenaTagType,
}); });
@ -353,7 +353,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container {
), ),
effectType: effectType:
fieldEffectChangedEvent instanceof WeatherChangedEvent ? ArenaEffectType.WEATHER : ArenaEffectType.TERRAIN, fieldEffectChangedEvent instanceof WeatherChangedEvent ? ArenaEffectType.WEATHER : ArenaEffectType.TERRAIN,
maxDuration: fieldEffectChangedEvent.duration, maxDuration: fieldEffectChangedEvent.maxDuration,
duration: fieldEffectChangedEvent.duration, duration: fieldEffectChangedEvent.duration,
}; };