Made arena tag layers readonly; cleaned up callsites

This commit is contained in:
Bertie690 2025-08-20 17:15:47 -04:00
parent 17c96a5260
commit 0b4a6edc7c
4 changed files with 20 additions and 13 deletions

View File

@ -1114,10 +1114,7 @@ export class PostDefendApplyArenaTrapTagAbAttr extends PostDefendAbAttr {
override canApply({ pokemon, opponent: attacker, move }: PostMoveInteractionAbAttrParams): boolean { override canApply({ pokemon, opponent: attacker, move }: PostMoveInteractionAbAttrParams): boolean {
const tag = globalScene.arena.getTag(this.arenaTagType) as EntryHazardTag; const tag = globalScene.arena.getTag(this.arenaTagType) as EntryHazardTag;
return ( return this.condition(pokemon, attacker, move) && (!tag || tag.canAdd());
this.condition(pokemon, attacker, move) &&
(!globalScene.arena.getTag(this.arenaTagType) || tag.layers < tag.maxLayers)
);
} }
override apply({ simulated, pokemon }: PostMoveInteractionAbAttrParams): void { override apply({ simulated, pokemon }: PostMoveInteractionAbAttrParams): void {

View File

@ -747,8 +747,10 @@ export abstract class EntryHazardTag extends SerializableArenaTag {
/** /**
* The current number of layers this tag has. * The current number of layers this tag has.
* Starts at 1 and increases each time the trap is laid. * Starts at 1 and increases each time the trap is laid.
* Intended to be mutable within the class itself and readonly outside of it
* @protected
*/ */
public layers = 1; public readonly layers: number = 1;
/** The maximum number of layers this tag can have. */ /** The maximum number of layers this tag can have. */
public abstract get maxLayers(): number; public abstract get maxLayers(): number;
/** Whether this tag should only affect grounded targets; default `true` */ /** Whether this tag should only affect grounded targets; default `true` */
@ -762,6 +764,14 @@ export abstract class EntryHazardTag extends SerializableArenaTag {
// TODO: Add a `canAdd` field to arena tags to remove need for callers to check layer counts // TODO: Add a `canAdd` field to arena tags to remove need for callers to check layer counts
/**
* Check if this tag can have more layers added to it.
* @returns Whether this tag can have another layer added to it.
*/
public canAdd(): boolean {
return this.layers < this.maxLayers;
}
/** /**
* Add a new layer to this tag upon overlap, triggering the tag's normal {@linkcode onAdd} effects upon doing so. * Add a new layer to this tag upon overlap, triggering the tag's normal {@linkcode onAdd} effects upon doing so.
*/ */
@ -769,7 +779,7 @@ export abstract class EntryHazardTag extends SerializableArenaTag {
if (!this.canAdd()) { if (!this.canAdd()) {
return; return;
} }
this.layers++; (this as Mutable<this>).layers++;
this.onAdd(); this.onAdd();
} }
@ -809,7 +819,7 @@ export abstract class EntryHazardTag extends SerializableArenaTag {
public loadTag<T extends this>(source: BaseArenaTag & Pick<T, "tagType" | "layers">): void { public loadTag<T extends this>(source: BaseArenaTag & Pick<T, "tagType" | "layers">): void {
super.loadTag(source); super.loadTag(source);
this.layers = source.layers; (this as Mutable<this>).layers = source.layers;
} }
} }
@ -906,7 +916,7 @@ class SpikesTag extends DamagingTrapTag {
*/ */
class StealthRockTag extends DamagingTrapTag { class StealthRockTag extends DamagingTrapTag {
public readonly tagType = ArenaTagType.STEALTH_ROCK; public readonly tagType = ArenaTagType.STEALTH_ROCK;
public override get maxLayers() { override get maxLayers() {
return 1 as const; return 1 as const;
} }
protected override get groundedOnly() { protected override get groundedOnly() {
@ -997,7 +1007,7 @@ class ToxicSpikesTag extends EntryHazardTag {
*/ */
class StickyWebTag extends EntryHazardTag { class StickyWebTag extends EntryHazardTag {
public readonly tagType = ArenaTagType.STICKY_WEB; public readonly tagType = ArenaTagType.STICKY_WEB;
public override get maxLayers() { override get maxLayers() {
return 1 as const; return 1 as const;
} }
@ -1061,7 +1071,7 @@ class StickyWebTag extends EntryHazardTag {
*/ */
class ImprisonTag extends EntryHazardTag { class ImprisonTag extends EntryHazardTag {
public readonly tagType = ArenaTagType.IMPRISON; public readonly tagType = ArenaTagType.IMPRISON;
public override get maxLayers() { override get maxLayers() {
return 1 as const; return 1 as const;
} }

View File

@ -6156,7 +6156,7 @@ export class AddArenaTrapTagAttr extends AddArenaTagAttr {
if (!tag) { if (!tag) {
return true; return true;
} }
return tag.layers < tag.maxLayers; return tag.canAdd();
}; };
} }
} }
@ -6182,7 +6182,7 @@ export class AddArenaTrapTagHitAttr extends AddArenaTagAttr {
if (!tag) { if (!tag) {
return true; return true;
} }
return tag.layers < tag.maxLayers; return tag.canAdd();
} }
return false; return false;
} }

View File

@ -737,7 +737,7 @@ export class Arena {
existingTag.onOverlap(globalScene.getPokemonById(sourceId)); existingTag.onOverlap(globalScene.getPokemonById(sourceId));
if (existingTag instanceof EntryHazardTag) { if (existingTag instanceof EntryHazardTag) {
const { tagType, side, turnCount, layers, maxLayers } = existingTag as EntryHazardTag; const { tagType, side, turnCount, layers, maxLayers } = existingTag;
this.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, layers, maxLayers)); this.eventTarget.dispatchEvent(new TagAddedEvent(tagType, side, turnCount, layers, maxLayers));
} }