Add Toxic Spikes neutralization

This commit is contained in:
Flashfyre 2024-03-17 23:47:46 -04:00
parent 4432522e15
commit 27e40d8526
2 changed files with 30 additions and 5 deletions

View File

@ -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;

View File

@ -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);