[Ability] Implement Screen Cleaner (#2346)

* implement screen cleaner

* add documentation

* add unit tests

* rename arena to arenaTag
This commit is contained in:
Adrian T 2024-06-18 03:37:11 +08:00 committed by GitHub
parent 35d0d2f4e6
commit 57b5c33c4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 106 additions and 1 deletions

View File

@ -1632,6 +1632,28 @@ export class PostSummonAbAttr extends AbAttr {
return false;
}
}
/**
* Removes specified arena tags when a Pokemon is summoned.
*/
export class PostSummonRemoveArenaTagAbAttr extends PostSummonAbAttr {
private arenaTags: ArenaTagType[];
/**
* @param arenaTags {@linkcode ArenaTagType[]} - the arena tags to be removed
*/
constructor(arenaTags: ArenaTagType[]) {
super(true);
this.arenaTags = arenaTags;
}
applyPostSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise<boolean> {
for (const arenaTag of this.arenaTags) {
pokemon.scene.arena.removeTag(arenaTag);
}
return true;
}
}
export class PostSummonMessageAbAttr extends PostSummonAbAttr {
private messageFunc: (pokemon: Pokemon) => string;
@ -4642,7 +4664,7 @@ export function initAbilities() {
new Ability(Abilities.MIMICRY, 8)
.unimplemented(),
new Ability(Abilities.SCREEN_CLEANER, 8)
.unimplemented(),
.attr(PostSummonRemoveArenaTagAbAttr, [ArenaTagType.AURORA_VEIL, ArenaTagType.LIGHT_SCREEN, ArenaTagType.REFLECT]),
new Ability(Abilities.STEELY_SPIRIT, 8)
.attr(MoveTypePowerBoostAbAttr, Type.STEEL)
.partial(),

View File

@ -0,0 +1,83 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser";
import GameManager from "#app/test/utils/gameManager";
import * as overrides from "#app/overrides";
import { Species } from "#enums/species";
import { PostSummonPhase, TurnEndPhase, } from "#app/phases";
import { Moves } from "#enums/moves";
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Abilities } from "#enums/abilities";
import { ArenaTagType } from "#app/enums/arena-tag-type.js";
describe("Abilities - Screen Cleaner", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true);
vi.spyOn(overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.SCREEN_CLEANER);
});
it("removes Aurora Veil", async () => {
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.HAIL]);
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.AURORA_VEIL, Moves.AURORA_VEIL, Moves.AURORA_VEIL, Moves.AURORA_VEIL]);
await game.startBattle([Species.MAGIKARP, Species.MAGIKARP]);
game.doAttack(getMovePosition(game.scene, 0, Moves.HAIL));
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.scene.arena.getTag(ArenaTagType.AURORA_VEIL)).toBeDefined();
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.phaseInterceptor.to(PostSummonPhase);
expect(game.scene.arena.getTag(ArenaTagType.AURORA_VEIL)).toBeUndefined();
});
it("removes Light Screen", async () => {
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.LIGHT_SCREEN, Moves.LIGHT_SCREEN, Moves.LIGHT_SCREEN, Moves.LIGHT_SCREEN]);
await game.startBattle([Species.MAGIKARP, Species.MAGIKARP]);
game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH));
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.scene.arena.getTag(ArenaTagType.LIGHT_SCREEN)).toBeDefined();
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.phaseInterceptor.to(PostSummonPhase);
expect(game.scene.arena.getTag(ArenaTagType.LIGHT_SCREEN)).toBeUndefined();
});
it("removes Reflect", async () => {
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.REFLECT, Moves.REFLECT, Moves.REFLECT, Moves.REFLECT]);
await game.startBattle([Species.MAGIKARP, Species.MAGIKARP]);
game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH));
await game.phaseInterceptor.to(TurnEndPhase);
expect(game.scene.arena.getTag(ArenaTagType.REFLECT)).toBeDefined();
await game.toNextTurn();
game.doSwitchPokemon(1);
await game.phaseInterceptor.to(PostSummonPhase);
expect(game.scene.arena.getTag(ArenaTagType.REFLECT)).toBeUndefined();
});
});