Add base damage test

This commit is contained in:
innerthunder 2024-09-11 16:00:37 -07:00
parent 17b7615d76
commit 2c636c0a35

View File

@ -5,7 +5,7 @@ import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Battle Mechanics - Damage Calculation", () => {
let phaserGame: Phaser.Game;
@ -34,6 +34,20 @@ describe("Battle Mechanics - Damage Calculation", () => {
.moveset([Moves.TACKLE, Moves.DRAGON_RAGE, Moves.FISSURE, Moves.JUMP_KICK]);
});
it("Tackle deals expected base damage", async () => {
await game.classicMode.startBattle([Species.CHARIZARD]);
const playerPokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(playerPokemon, "getEffectiveStat").mockReturnValue(80);
const enemyPokemon = game.scene.getEnemyPokemon()!;
vi.spyOn(enemyPokemon, "getEffectiveStat").mockReturnValue(90);
// expected base damage = [(2*level/5 + 2) * power * playerATK / enemyDEF / 50] + 2
// = 31.8666...
expect(enemyPokemon.getAttackDamage(playerPokemon, allMoves[Moves.TACKLE]).damage).toBeCloseTo(31);
});
it("Attacks deal 1 damage at minimum", async () => {
game.override
.startingLevel(1)