From 27e40d85264493df7ad1adc0feadeb5da87dc692 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Sun, 17 Mar 2024 23:47:46 -0400 Subject: [PATCH] Add Toxic Spikes neutralization --- src/data/arena-tag.ts | 20 ++++++++++++++++++-- src/field/arena.ts | 15 ++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index 87a2d201ef1..e1620c767fb 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -141,7 +141,7 @@ export class ArenaTrapTag extends ArenaTag { } } - apply(arena: Arena, args: any[]): boolean { + apply(arena: Arena, args: any[]): boolean { const pokemon = args[0] as Pokemon; if (this.sourceId === pokemon.id || (this.side === ArenaTagSide.PLAYER) !== pokemon.isPlayer()) return false; @@ -181,8 +181,11 @@ class SpikesTag extends ArenaTrapTag { } class ToxicSpikesTag extends ArenaTrapTag { + private neutralized: boolean; + constructor(sourceId: integer, side: ArenaTagSide) { super(ArenaTagType.TOXIC_SPIKES, Moves.TOXIC_SPIKES, sourceId, side, 2); + this.neutralized = false; } onAdd(arena: Arena): void { @@ -192,10 +195,23 @@ class ToxicSpikesTag extends ArenaTrapTag { arena.scene.queueMessage(`${this.getMoveName()} were scattered\nall around ${source.getOpponentDescriptor()}'s feet!`); } + onRemove(arena: Arena): void { + if (!this.neutralized) + super.onRemove(arena); + } + activateTrap(pokemon: Pokemon): boolean { if (!pokemon.status && pokemon.isGrounded()) { const toxic = this.layers > 1; - return pokemon.trySetStatus(!toxic ? StatusEffect.POISON : StatusEffect.TOXIC, true, null, `the ${this.getMoveName()}`); + if (pokemon.trySetStatus(!toxic ? StatusEffect.POISON : StatusEffect.TOXIC, true, null, `the ${this.getMoveName()}`)) + return true; + else if (pokemon.isOfType(Type.POISON)) { + this.neutralized = true; + if (pokemon.scene.arena.removeTag(this.tagType)) { + pokemon.scene.queueMessage(`The ${this.getMoveName()} were\nneutralized by ${pokemon.name}.`); + return true; + } + } } return false; diff --git a/src/field/arena.ts b/src/field/arena.ts index 813762d6597..8ccdf08e2d4 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -470,13 +470,22 @@ export class Arena { } lapseTags(): void { - const tags = this.tags; - tags.filter(t => !(t.lapse(this))).forEach(t => { + this.tags.filter(t => !(t.lapse(this))).forEach(t => { t.onRemove(this); - tags.splice(tags.indexOf(t), 1); + this.tags.splice(this.tags.indexOf(t), 1); }); } + removeTag(tagType: ArenaTagType): boolean { + const tags = this.tags; + const tag = tags.find(t => t.tagType === tagType); + if (tag) { + tag.onRemove(this); + tags.splice(tags.indexOf(tag), 1); + } + return !!tag; + } + removeAllTags(): void { while (this.tags.length) { this.tags[0].onRemove(this);