2024-09-13 22:54:22 -07:00
|
|
|
import { allMoves } from "#app/data/move";
|
2025-02-20 18:16:41 -06:00
|
|
|
import type { EnemyPersistentModifier } from "#app/modifier/modifier";
|
|
|
|
import { modifierTypes } from "#app/modifier/modifier-type";
|
2024-08-22 14:39:11 +09:00
|
|
|
import { Abilities } from "#enums/abilities";
|
2024-08-22 06:49:33 -07:00
|
|
|
import { ArenaTagType } from "#enums/arena-tag-type";
|
2024-08-22 14:39:11 +09:00
|
|
|
import { Moves } from "#enums/moves";
|
|
|
|
import { Species } from "#enums/species";
|
2025-02-22 22:52:07 -06:00
|
|
|
import GameManager from "#test/testUtils/gameManager";
|
2024-08-22 14:39:11 +09:00
|
|
|
import Phaser from "phaser";
|
2024-09-13 22:54:22 -07:00
|
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
2024-08-22 14:39:11 +09:00
|
|
|
|
2024-09-13 22:54:22 -07:00
|
|
|
describe("Battle Mechanics - Damage Calculation", () => {
|
2024-08-22 14:39:11 +09:00
|
|
|
let phaserGame: Phaser.Game;
|
|
|
|
let game: GameManager;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
phaserGame = new Phaser.Game({
|
|
|
|
type: Phaser.HEADLESS,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
game.phaseInterceptor.restoreOg();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
game = new GameManager(phaserGame);
|
2024-09-13 22:54:22 -07:00
|
|
|
game.override
|
|
|
|
.battleType("single")
|
|
|
|
.enemySpecies(Species.SNORLAX)
|
|
|
|
.enemyAbility(Abilities.BALL_FETCH)
|
|
|
|
.enemyMoveset(Moves.SPLASH)
|
|
|
|
.startingLevel(100)
|
|
|
|
.enemyLevel(100)
|
|
|
|
.disableCrits()
|
2024-10-04 13:08:31 +08:00
|
|
|
.moveset([ Moves.TACKLE, Moves.DRAGON_RAGE, Moves.FISSURE, Moves.JUMP_KICK ]);
|
2024-09-13 22:54:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Tackle deals expected base damage", async () => {
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.classicMode.startBattle([ Species.CHARIZARD ]);
|
2024-09-13 22:54:22 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
.enemySpecies(Species.AGGRON);
|
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.classicMode.startBattle([ Species.MAGIKARP ]);
|
2024-09-13 22:54:22 -07:00
|
|
|
|
|
|
|
const aggron = game.scene.getEnemyPokemon()!;
|
|
|
|
|
|
|
|
game.move.select(Moves.TACKLE);
|
|
|
|
|
|
|
|
await game.phaseInterceptor.to("BerryPhase", false);
|
|
|
|
|
|
|
|
// Lvl 1 0 Atk Magikarp Tackle vs. 0 HP / 0 Def Aggron: 1-1 (0.3 - 0.3%) -- possibly the worst move ever
|
|
|
|
expect(aggron.hp).toBe(aggron.getMaxHp() - 1);
|
|
|
|
});
|
|
|
|
|
2025-02-20 18:16:41 -06:00
|
|
|
it("Attacks deal 1 damage at minimum even with many tokens", async () => {
|
|
|
|
game.override
|
|
|
|
.startingLevel(1)
|
|
|
|
.enemySpecies(Species.AGGRON)
|
|
|
|
.enemyAbility(Abilities.STURDY)
|
|
|
|
.enemyLevel(10000);
|
|
|
|
|
|
|
|
await game.classicMode.startBattle([ Species.SHUCKLE ]);
|
|
|
|
|
|
|
|
const dmg_redux_modifier = modifierTypes.ENEMY_DAMAGE_REDUCTION().newModifier() as EnemyPersistentModifier;
|
|
|
|
dmg_redux_modifier.stackCount = 1000;
|
|
|
|
await game.scene.addEnemyModifier(modifierTypes.ENEMY_DAMAGE_REDUCTION().newModifier() as EnemyPersistentModifier);
|
|
|
|
|
|
|
|
const aggron = game.scene.getEnemyPokemon()!;
|
|
|
|
|
|
|
|
game.move.select(Moves.TACKLE);
|
|
|
|
|
|
|
|
await game.phaseInterceptor.to("BerryPhase", false);
|
|
|
|
|
|
|
|
expect(aggron.hp).toBe(aggron.getMaxHp() - 1);
|
|
|
|
});
|
|
|
|
|
2024-09-13 22:54:22 -07:00
|
|
|
it("Fixed-damage moves ignore damage multipliers", async () => {
|
|
|
|
game.override
|
|
|
|
.enemySpecies(Species.DRAGONITE)
|
|
|
|
.enemyAbility(Abilities.MULTISCALE);
|
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.classicMode.startBattle([ Species.MAGIKARP ]);
|
2024-09-13 22:54:22 -07:00
|
|
|
|
|
|
|
const magikarp = game.scene.getPlayerPokemon()!;
|
|
|
|
const dragonite = game.scene.getEnemyPokemon()!;
|
|
|
|
|
|
|
|
expect(dragonite.getAttackDamage(magikarp, allMoves[Moves.DRAGON_RAGE]).damage).toBe(40);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("One-hit KO moves ignore damage multipliers", async () => {
|
|
|
|
game.override
|
|
|
|
.enemySpecies(Species.AGGRON)
|
|
|
|
.enemyAbility(Abilities.MULTISCALE);
|
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.classicMode.startBattle([ Species.MAGIKARP ]);
|
2024-09-13 22:54:22 -07:00
|
|
|
|
|
|
|
const magikarp = game.scene.getPlayerPokemon()!;
|
|
|
|
const aggron = game.scene.getEnemyPokemon()!;
|
|
|
|
|
|
|
|
expect(aggron.getAttackDamage(magikarp, allMoves[Moves.FISSURE]).damage).toBe(aggron.hp);
|
2024-08-22 14:39:11 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
it("When the user fails to use Jump Kick with Wonder Guard ability, the damage should be 1.", async () => {
|
2024-09-13 22:54:22 -07:00
|
|
|
game.override
|
|
|
|
.enemySpecies(Species.GASTLY)
|
|
|
|
.ability(Abilities.WONDER_GUARD);
|
2024-08-22 14:39:11 +09:00
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.classicMode.startBattle([ Species.SHEDINJA ]);
|
2024-08-22 14:39:11 +09:00
|
|
|
|
|
|
|
const shedinja = game.scene.getPlayerPokemon()!;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.JUMP_KICK);
|
2024-08-22 14:39:11 +09:00
|
|
|
|
2024-11-25 14:15:39 -08:00
|
|
|
await game.phaseInterceptor.to("DamageAnimPhase");
|
2024-08-22 14:39:11 +09:00
|
|
|
|
|
|
|
expect(shedinja.hp).toBe(shedinja.getMaxHp() - 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("Charizard with odd HP survives Stealth Rock damage twice", async () => {
|
|
|
|
game.scene.arena.addTag(ArenaTagType.STEALTH_ROCK, 1, Moves.STEALTH_ROCK, 0);
|
2024-09-13 22:54:22 -07:00
|
|
|
game.override
|
|
|
|
.seed("Charizard Stealth Rock test")
|
|
|
|
.enemySpecies(Species.CHARIZARD)
|
|
|
|
.enemyAbility(Abilities.BLAZE);
|
2024-08-22 14:39:11 +09:00
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
await game.classicMode.startBattle([ Species.PIKACHU ]);
|
2024-08-22 14:39:11 +09:00
|
|
|
|
|
|
|
const charizard = game.scene.getEnemyPokemon()!;
|
|
|
|
|
2024-09-13 22:54:22 -07:00
|
|
|
if (charizard.getMaxHp() % 2 === 1) {
|
|
|
|
expect(charizard.hp).toBeGreaterThan(charizard.getMaxHp() / 2);
|
|
|
|
} else {
|
|
|
|
expect(charizard.hp).toBe(charizard.getMaxHp() / 2);
|
|
|
|
}
|
2024-08-22 14:39:11 +09:00
|
|
|
});
|
|
|
|
});
|