Compare commits

...

2 Commits

Author SHA1 Message Date
innerthunder
ed84c75f8e "killMoves" --> "koMoves" 2024-09-02 14:40:03 -07:00
innerthunder
eaca82cf55 Add tests to damage_calculation 2024-09-02 14:31:59 -07:00
2 changed files with 75 additions and 27 deletions

View File

@ -4025,7 +4025,7 @@ export class EnemyPokemon extends Pokemon {
* If there are any moves that can KO an opponent (i.e. a player Pokemon), * If there are any moves that can KO an opponent (i.e. a player Pokemon),
* those moves are the only ones considered for selection on this turn. * those moves are the only ones considered for selection on this turn.
*/ */
const killMoves = movePool.filter(pkmnMove => { const koMoves = movePool.filter(pkmnMove => {
if (!pkmnMove) { if (!pkmnMove) {
return false; return false;
} }
@ -4041,8 +4041,8 @@ export class EnemyPokemon extends Pokemon {
&& moveTargets.some(p => p.getAttackDamage(this, move, !p.battleData.abilityRevealed, false, isCritical).damage >= p.hp); && moveTargets.some(p => p.getAttackDamage(this, move, !p.battleData.abilityRevealed, false, isCritical).damage >= p.hp);
}, this); }, this);
if (killMoves.length > 0) { if (koMoves.length > 0) {
movePool = killMoves; movePool = koMoves;
} }
/** /**

View File

@ -1,5 +1,4 @@
import { DamagePhase } from "#app/phases/damage-phase.js"; import { allMoves } from "#app/data/move";
import { toDmgValue } from "#app/utils";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { ArenaTagType } from "#enums/arena-tag-type"; import { ArenaTagType } from "#enums/arena-tag-type";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
@ -9,7 +8,7 @@ import { SPLASH_ONLY } from "#test/utils/testUtils";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Round Down and Minimun 1 test in Damage Calculation", () => { describe("Battle Mechanics - Damage Calculation", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
let game: GameManager; let game: GameManager;
@ -25,24 +24,75 @@ describe("Round Down and Minimun 1 test in Damage Calculation", () => {
beforeEach(() => { beforeEach(() => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
game.override.battleType("single"); game.override
game.override.startingLevel(10); .battleType("single")
.enemySpecies(Species.SNORLAX)
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset(SPLASH_ONLY)
.startingLevel(100)
.enemyLevel(100)
.disableCrits();
});
it("Attacks deal 1 damage at minimum", async () => {
game.override
.startingLevel(1)
.enemySpecies(Species.AGGRON)
.moveset([Moves.TACKLE]);
await game.classicMode.startBattle([Species.MAGIKARP]);
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);
});
it("Fixed-damage moves ignore damage multipliers", async () => {
game.override
.enemySpecies(Species.DRAGONITE)
.enemyAbility(Abilities.MULTISCALE)
.moveset([Moves.DRAGON_RAGE]);
await game.classicMode.startBattle([Species.MAGIKARP]);
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)
.moveset([Moves.FISSURE]);
await game.classicMode.startBattle([Species.MAGIKARP]);
const magikarp = game.scene.getPlayerPokemon()!;
const aggron = game.scene.getEnemyPokemon()!;
expect(aggron.getAttackDamage(magikarp, allMoves[Moves.FISSURE]).damage).toBe(aggron.hp);
}); });
it("When the user fails to use Jump Kick with Wonder Guard ability, the damage should be 1.", async () => { it("When the user fails to use Jump Kick with Wonder Guard ability, the damage should be 1.", async () => {
game.override.enemySpecies(Species.GASTLY); game.override
game.override.enemyMoveset(SPLASH_ONLY); .enemySpecies(Species.GASTLY)
game.override.starterSpecies(Species.SHEDINJA); .moveset([Moves.JUMP_KICK])
game.override.moveset([Moves.JUMP_KICK]); .ability(Abilities.WONDER_GUARD);
game.override.ability(Abilities.WONDER_GUARD);
await game.startBattle(); await game.classicMode.startBattle([Species.SHEDINJA]);
const shedinja = game.scene.getPlayerPokemon()!; const shedinja = game.scene.getPlayerPokemon()!;
game.move.select(Moves.JUMP_KICK); game.move.select(Moves.JUMP_KICK);
await game.phaseInterceptor.to(DamagePhase); await game.phaseInterceptor.to("DamagePhase");
expect(shedinja.hp).toBe(shedinja.getMaxHp() - 1); expect(shedinja.hp).toBe(shedinja.getMaxHp() - 1);
}); });
@ -50,21 +100,19 @@ describe("Round Down and Minimun 1 test in Damage Calculation", () => {
it("Charizard with odd HP survives Stealth Rock damage twice", async () => { it("Charizard with odd HP survives Stealth Rock damage twice", async () => {
game.scene.arena.addTag(ArenaTagType.STEALTH_ROCK, 1, Moves.STEALTH_ROCK, 0); game.scene.arena.addTag(ArenaTagType.STEALTH_ROCK, 1, Moves.STEALTH_ROCK, 0);
game.override.seed("Charizard Stealth Rock test"); game.override
game.override.enemySpecies(Species.CHARIZARD); .seed("Charizard Stealth Rock test")
game.override.enemyAbility(Abilities.BLAZE); .enemySpecies(Species.CHARIZARD)
game.override.starterSpecies(Species.PIKACHU); .enemyAbility(Abilities.BLAZE);
game.override.enemyLevel(100);
await game.startBattle(); await game.classicMode.startBattle([Species.PIKACHU]);
const charizard = game.scene.getEnemyPokemon()!; const charizard = game.scene.getEnemyPokemon()!;
const maxHp = charizard.getMaxHp(); if (charizard.getMaxHp() % 2 === 1) {
const damage_prediction = toDmgValue(charizard.getMaxHp() / 2); expect(charizard.hp).toBeGreaterThan(charizard.getMaxHp() / 2);
const currentHp = charizard.hp; } else {
const expectedHP = maxHp - damage_prediction; expect(charizard.hp).toBe(charizard.getMaxHp() / 2);
}
expect(currentHp).toBe(expectedHP);
}); });
}); });