Skip to content

Commit

Permalink
Fix Contrary & Simple, Verify with Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xsn34kzx committed Aug 20, 2024
1 parent e3059fd commit 27a971e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/phases/stat-stage-change-phase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BattleScene from "#app/battle-scene.js";
import { BattlerIndex } from "#app/battle.js";
import { applyPreStatStageChangeAbAttrs, ProtectStatAbAttr, applyAbAttrs, StatMultiplierAbAttr, StatStageChangeCopyAbAttr, applyPostStatStageChangeAbAttrs, PostStatStageChangeAbAttr } from "#app/data/ability.js";
import { applyPreStatStageChangeAbAttrs, ProtectStatAbAttr, applyAbAttrs, StatStageChangeMultiplierAbAttr, StatStageChangeCopyAbAttr, applyPostStatStageChangeAbAttrs, PostStatStageChangeAbAttr } from "#app/data/ability.js";
import { MistTag, ArenaTagSide } from "#app/data/arena-tag.js";
import Pokemon from "#app/field/pokemon.js";
import { getPokemonNameWithAffix } from "#app/messages.js";
Expand Down Expand Up @@ -59,7 +59,7 @@ export class StatStageChangePhase extends PokemonPhase {
const stages = new Utils.IntegerHolder(this.stages);

if (!this.ignoreAbilities) {
applyAbAttrs(StatMultiplierAbAttr, pokemon, null, stages);
applyAbAttrs(StatStageChangeMultiplierAbAttr, pokemon, null, stages);
}

const relLevels = filteredStats.map(s => (stages.value >= 1 ? Math.min(pokemon.getStatStage(s) + stages.value, 6) : Math.max(pokemon.getStatStage(s) + stages.value, -6)) - pokemon.getStatStage(s));
Expand Down
41 changes: 41 additions & 0 deletions src/test/abilities/contrary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Stat } from "#enums/stat";
import GameManager from "#test/utils/gameManager";
import { Abilities } from "#enums/abilities";
import { Species } from "#enums/species";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { SPLASH_ONLY } from "../utils/testUtils";

describe("Abilities - Contrary", () => {
let phaserGame: Phaser.Game;
let game: GameManager;

beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});

afterEach(() => {
game.phaseInterceptor.restoreOg();
});

beforeEach(() => {
game = new GameManager(phaserGame);
game.override.battleType("single");
game.override.enemySpecies(Species.BULBASAUR);
game.override.enemyAbility(Abilities.CONTRARY);
game.override.ability(Abilities.INTIMIDATE);
game.override.enemyMoveset(SPLASH_ONLY);
});

it("should invert stat changes when applied", async() => {
await game.startBattle([
Species.SLOWBRO
]);

const enemyPokemon = game.scene.getEnemyPokemon()!;

expect(enemyPokemon.getStatStage(Stat.ATK)).toBe(1);
}, 20000);
});
41 changes: 41 additions & 0 deletions src/test/abilities/simple.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Stat } from "#enums/stat";
import GameManager from "#test/utils/gameManager";
import { Abilities } from "#enums/abilities";
import { Species } from "#enums/species";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { SPLASH_ONLY } from "../utils/testUtils";

describe("Abilities - Simple", () => {
let phaserGame: Phaser.Game;
let game: GameManager;

beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});

afterEach(() => {
game.phaseInterceptor.restoreOg();
});

beforeEach(() => {
game = new GameManager(phaserGame);
game.override.battleType("single");
game.override.enemySpecies(Species.BULBASAUR);
game.override.enemyAbility(Abilities.SIMPLE);
game.override.ability(Abilities.INTIMIDATE);
game.override.enemyMoveset(SPLASH_ONLY);
});

it("should double stat changes when applied", async() => {
await game.startBattle([
Species.SLOWBRO
]);

const enemyPokemon = game.scene.getEnemyPokemon()!;

expect(enemyPokemon.getStatStage(Stat.ATK)).toBe(-2);
}, 20000);
});

0 comments on commit 27a971e

Please sign in to comment.