mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-15 06:15:20 +01:00
[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:
parent
0e87391b20
commit
7d83a3a24a
@ -84,6 +84,10 @@ interface BaseArenaTag {
|
||||
* The tag's remaining duration. Setting to any number `<=0` will make the tag's duration effectively infinite.
|
||||
*/
|
||||
turnCount: number;
|
||||
/**
|
||||
* The tag's max duration.
|
||||
*/
|
||||
maxDuration: number;
|
||||
/**
|
||||
* 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 */
|
||||
public abstract readonly tagType: ArenaTagType;
|
||||
public turnCount: number;
|
||||
public maxDuration: number;
|
||||
public sourceMove?: MoveId;
|
||||
public sourceId: number | undefined;
|
||||
public side: ArenaTagSide;
|
||||
|
||||
constructor(turnCount: number, sourceMove?: MoveId, sourceId?: number, side: ArenaTagSide = ArenaTagSide.BOTH) {
|
||||
this.turnCount = turnCount;
|
||||
this.maxDuration = turnCount;
|
||||
this.sourceMove = sourceMove;
|
||||
this.sourceId = sourceId;
|
||||
this.side = side;
|
||||
@ -164,6 +170,7 @@ export abstract class ArenaTag implements BaseArenaTag {
|
||||
*/
|
||||
loadTag<const T extends this>(source: BaseArenaTag & Pick<T, "tagType">): void {
|
||||
this.turnCount = source.turnCount;
|
||||
this.maxDuration = source.maxDuration;
|
||||
this.sourceMove = source.sourceMove;
|
||||
this.sourceId = source.sourceId;
|
||||
this.side = source.side;
|
||||
|
||||
@ -22,10 +22,12 @@ export interface SerializedTerrain {
|
||||
export class Terrain {
|
||||
public terrainType: TerrainType;
|
||||
public turnsLeft: number;
|
||||
public maxDuration: number;
|
||||
|
||||
constructor(terrainType: TerrainType, turnsLeft?: number) {
|
||||
constructor(terrainType: TerrainType, turnsLeft = 0, maxDuration: number = turnsLeft) {
|
||||
this.terrainType = terrainType;
|
||||
this.turnsLeft = turnsLeft || 0;
|
||||
this.turnsLeft = turnsLeft;
|
||||
this.maxDuration = maxDuration;
|
||||
}
|
||||
|
||||
lapse(): boolean {
|
||||
|
||||
@ -19,10 +19,12 @@ export interface SerializedWeather {
|
||||
export class Weather {
|
||||
public weatherType: WeatherType;
|
||||
public turnsLeft: number;
|
||||
public maxDuration: number;
|
||||
|
||||
constructor(weatherType: WeatherType, turnsLeft?: number) {
|
||||
constructor(weatherType: WeatherType, turnsLeft = 0, maxDuration: number = turnsLeft) {
|
||||
this.weatherType = weatherType;
|
||||
this.turnsLeft = !this.isImmutable() ? turnsLeft || 0 : 0;
|
||||
this.turnsLeft = this.isImmutable() ? 0 : turnsLeft;
|
||||
this.maxDuration = this.isImmutable() ? 0 : maxDuration;
|
||||
}
|
||||
|
||||
lapse(): boolean {
|
||||
|
||||
@ -20,10 +20,13 @@ export enum ArenaEventType {
|
||||
export class ArenaEvent extends Event {
|
||||
/** The total duration of the {@linkcode ArenaEventType} */
|
||||
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);
|
||||
|
||||
this.duration = duration;
|
||||
this.maxDuration = maxDuration;
|
||||
}
|
||||
}
|
||||
/** Container class for {@linkcode ArenaEventType.WEATHER_CHANGED} events */
|
||||
@ -32,8 +35,8 @@ export class WeatherChangedEvent extends ArenaEvent {
|
||||
public oldWeatherType: WeatherType;
|
||||
/** The {@linkcode WeatherType} being set */
|
||||
public newWeatherType: WeatherType;
|
||||
constructor(oldWeatherType: WeatherType, newWeatherType: WeatherType, duration: number) {
|
||||
super(ArenaEventType.WEATHER_CHANGED, duration);
|
||||
constructor(oldWeatherType: WeatherType, newWeatherType: WeatherType, duration: number, maxDuration?: number) {
|
||||
super(ArenaEventType.WEATHER_CHANGED, duration, maxDuration);
|
||||
|
||||
this.oldWeatherType = oldWeatherType;
|
||||
this.newWeatherType = newWeatherType;
|
||||
@ -45,8 +48,8 @@ export class TerrainChangedEvent extends ArenaEvent {
|
||||
public oldTerrainType: TerrainType;
|
||||
/** The {@linkcode TerrainType} being set */
|
||||
public newTerrainType: TerrainType;
|
||||
constructor(oldTerrainType: TerrainType, newTerrainType: TerrainType, duration: number) {
|
||||
super(ArenaEventType.TERRAIN_CHANGED, duration);
|
||||
constructor(oldTerrainType: TerrainType, newTerrainType: TerrainType, duration: number, maxDuration?: number) {
|
||||
super(ArenaEventType.TERRAIN_CHANGED, duration, maxDuration);
|
||||
|
||||
this.oldTerrainType = oldTerrainType;
|
||||
this.newTerrainType = newTerrainType;
|
||||
@ -68,10 +71,11 @@ export class TagAddedEvent extends ArenaEvent {
|
||||
arenaTagType: ArenaTagType,
|
||||
arenaTagSide: ArenaTagSide,
|
||||
duration: number,
|
||||
maxDuration?: number,
|
||||
arenaTagLayers?: number,
|
||||
arenaTagMaxLayers?: number,
|
||||
) {
|
||||
super(ArenaEventType.TAG_ADDED, duration);
|
||||
super(ArenaEventType.TAG_ADDED, duration, maxDuration);
|
||||
|
||||
this.arenaTagType = arenaTagType;
|
||||
this.arenaTagSide = arenaTagSide;
|
||||
|
||||
@ -344,7 +344,7 @@ export class Arena {
|
||||
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(
|
||||
new WeatherChangedEvent(oldWeatherType, this.weather?.weatherType!, this.weather?.turnsLeft!),
|
||||
); // TODO: is this bang correct?
|
||||
@ -425,7 +425,7 @@ export class Arena {
|
||||
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(
|
||||
new TerrainChangedEvent(oldTerrainType, this.terrain?.terrainType!, this.terrain?.turnsLeft!),
|
||||
@ -705,8 +705,8 @@ export class Arena {
|
||||
existingTag.onOverlap(this, globalScene.getPokemonById(sourceId));
|
||||
|
||||
if (existingTag instanceof EntryHazardTag) {
|
||||
const { tagType, side, turnCount, layers, maxLayers } = existingTag as EntryHazardTag;
|
||||
this.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, layers, maxLayers));
|
||||
const { tagType, side, turnCount, maxDuration, layers, maxLayers } = existingTag as EntryHazardTag;
|
||||
this.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, maxDuration, layers, maxLayers));
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -721,7 +721,7 @@ export class Arena {
|
||||
const { layers = 0, maxLayers = 0 } = newTag instanceof EntryHazardTag ? newTag : {};
|
||||
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -47,8 +47,12 @@ export class ArenaData {
|
||||
}
|
||||
|
||||
this.biome = source.biome;
|
||||
this.weather = source.weather ? new Weather(source.weather.weatherType, source.weather.turnsLeft) : null;
|
||||
this.terrain = source.terrain ? new Terrain(source.terrain.terrainType, source.terrain.turnsLeft) : null;
|
||||
this.weather = source.weather
|
||||
? 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 ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1021,6 +1021,7 @@ export class GameData {
|
||||
WeatherType.NONE,
|
||||
globalScene.arena.weather?.weatherType!,
|
||||
globalScene.arena.weather?.turnsLeft!,
|
||||
globalScene.arena.weather?.maxDuration!,
|
||||
),
|
||||
); // TODO: is this bang correct?
|
||||
|
||||
@ -1030,6 +1031,7 @@ export class GameData {
|
||||
TerrainType.NONE,
|
||||
globalScene.arena.terrain?.terrainType!,
|
||||
globalScene.arena.terrain?.turnsLeft!,
|
||||
globalScene.arena.terrain?.maxDuration!,
|
||||
),
|
||||
); // TODO: is this bang correct?
|
||||
|
||||
@ -1039,12 +1041,14 @@ export class GameData {
|
||||
if (globalScene.arena.tags) {
|
||||
for (const tag of globalScene.arena.tags) {
|
||||
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(
|
||||
new TagAddedEvent(tagType, side, turnCount, layers, maxLayers),
|
||||
new TagAddedEvent(tagType, side, turnCount, maxDuration, layers, maxLayers),
|
||||
);
|
||||
} 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),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container {
|
||||
this.fieldEffectInfo.push({
|
||||
name,
|
||||
effectType: arenaEffectType,
|
||||
maxDuration: tagAddedEvent.duration,
|
||||
maxDuration: tagAddedEvent.maxDuration,
|
||||
duration: tagAddedEvent.duration,
|
||||
tagType: tagAddedEvent.arenaTagType,
|
||||
});
|
||||
@ -353,7 +353,7 @@ export class ArenaFlyout extends Phaser.GameObjects.Container {
|
||||
),
|
||||
effectType:
|
||||
fieldEffectChangedEvent instanceof WeatherChangedEvent ? ArenaEffectType.WEATHER : ArenaEffectType.TERRAIN,
|
||||
maxDuration: fieldEffectChangedEvent.duration,
|
||||
maxDuration: fieldEffectChangedEvent.maxDuration,
|
||||
duration: fieldEffectChangedEvent.duration,
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user