[Bug] Fix Dry Skin and ReceivedMoveDamageMultiplierAbAttr abilities (#2592)

* Dry skin and ReceivedMoveDamageMultiplierAbAttr bug fix: first cut

* Dry skin and ReceivedMoveDamageMultiplierAbAttr bug fix: removed redundant branch

* Dry skin and ReceivedMoveDamageMultiplierAbAttr bug fix: reworded test cases that had typos anyway

* Dry skin and ReceivedMoveDamageMultiplierAbAttr bug fix: renamed PreDefendMovePowerToOneAbAttr (Disguise) to mention damage rather than power

* Dry skin and ReceivedMoveDamageMultiplierAbAttr bug fix: renamed powerMultiplier to damageMultiplier in ReceivedMoveDamageMultiplierAbAttr
This commit is contained in:
Corrade 2024-06-26 03:23:48 +10:00 committed by GitHub
parent ea510571d4
commit e70113073f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 172 additions and 22 deletions

View File

@ -301,18 +301,18 @@ export class StabBoostAbAttr extends AbAttr {
export class ReceivedMoveDamageMultiplierAbAttr extends PreDefendAbAttr {
protected condition: PokemonDefendCondition;
private powerMultiplier: number;
private damageMultiplier: number;
constructor(condition: PokemonDefendCondition, powerMultiplier: number) {
constructor(condition: PokemonDefendCondition, damageMultiplier: number) {
super();
this.condition = condition;
this.powerMultiplier = powerMultiplier;
this.damageMultiplier = damageMultiplier;
}
applyPreDefend(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: Move, cancelled: Utils.BooleanHolder, args: any[]): boolean {
if (this.condition(pokemon, attacker, move)) {
(args[0] as Utils.NumberHolder).value *= this.powerMultiplier;
(args[0] as Utils.NumberHolder).value *= this.damageMultiplier;
return true;
}
@ -321,12 +321,12 @@ export class ReceivedMoveDamageMultiplierAbAttr extends PreDefendAbAttr {
}
export class ReceivedTypeDamageMultiplierAbAttr extends ReceivedMoveDamageMultiplierAbAttr {
constructor(moveType: Type, powerMultiplier: number) {
super((user, target, move) => move.type === moveType, powerMultiplier);
constructor(moveType: Type, damageMultiplier: number) {
super((user, target, move) => move.type === moveType, damageMultiplier);
}
}
export class PreDefendMovePowerToOneAbAttr extends ReceivedMoveDamageMultiplierAbAttr {
export class PreDefendMoveDamageToOneAbAttr extends ReceivedMoveDamageMultiplierAbAttr {
constructor(condition: PokemonDefendCondition) {
super(condition, 1);
}
@ -2726,15 +2726,11 @@ export class PostWeatherLapseDamageAbAttr extends PostWeatherLapseAbAttr {
}
applyPostWeatherLapse(pokemon: Pokemon, passive: boolean, weather: Weather, args: any[]): boolean {
if (pokemon.getHpRatio() < 1) {
const scene = pokemon.scene;
const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name;
scene.queueMessage(getPokemonMessage(pokemon, ` is hurt\nby its ${abilityName}!`));
pokemon.damageAndUpdate(Math.ceil(pokemon.getMaxHp() / (16 / this.damageFactor)), HitResult.OTHER);
return true;
}
return false;
const scene = pokemon.scene;
const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name;
scene.queueMessage(getPokemonMessage(pokemon, ` is hurt\nby its ${abilityName}!`));
pokemon.damageAndUpdate(Math.ceil(pokemon.getMaxHp() / (16 / this.damageFactor)), HitResult.OTHER);
return true;
}
}
@ -4721,7 +4717,7 @@ export function initAbilities() {
.attr(NoFusionAbilityAbAttr)
.bypassFaint(),
new Ability(Abilities.DISGUISE, 7)
.attr(PreDefendMovePowerToOneAbAttr, (target, user, move) => target.formIndex === 0 && target.getAttackTypeEffectiveness(move.type, user) > 0)
.attr(PreDefendMoveDamageToOneAbAttr, (target, user, move) => target.formIndex === 0 && target.getAttackTypeEffectiveness(move.type, user) > 0)
.attr(PostSummonFormChangeAbAttr, p => p.battleData.hitCount === 0 ? 0 : 1)
.attr(PostBattleInitFormChangeAbAttr, () => 0)
.attr(PostDefendFormChangeAbAttr, p => p.battleData.hitCount === 0 ? 0 : 1)

View File

@ -1954,11 +1954,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
}
applyMoveAttrs(ModifiedDamageAttr, source, this, move, damage);
applyPreDefendAbAttrs(ReceivedMoveDamageMultiplierAbAttr, this, source, move, cancelled, power);
if (power.value === 0) {
damage.value = 0;
}
applyPreDefendAbAttrs(ReceivedMoveDamageMultiplierAbAttr, this, source, move, cancelled, damage);
console.log("damage", damage.value, move.name, power.value, sourceAtk, targetDef);

View File

@ -0,0 +1,158 @@
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 { TurnEndPhase } from "#app/phases";
import { Moves } from "#enums/moves";
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
import { Abilities } from "#enums/abilities";
describe("Abilities - Dry Skin", () => {
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, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.DRY_SKIN);
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]);
});
it("during sunlight, lose 1/8 of maximum health at the end of each turn", async () => {
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SUNNY_DAY, Moves.SPLASH]);
await game.startBattle();
const enemy = game.scene.getEnemyPokemon();
expect(enemy).not.toBe(undefined);
// first turn
let previousEnemyHp = enemy.hp;
game.doAttack(getMovePosition(game.scene, 0, Moves.SUNNY_DAY));
await game.phaseInterceptor.to(TurnEndPhase);
expect(enemy.hp).toBeLessThan(previousEnemyHp);
// second turn
previousEnemyHp = enemy.hp;
game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH));
await game.phaseInterceptor.to(TurnEndPhase);
expect(enemy.hp).toBeLessThan(previousEnemyHp);
});
it("during rain, gain 1/8 of maximum health at the end of each turn", async () => {
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.RAIN_DANCE, Moves.SPLASH]);
await game.startBattle();
const enemy = game.scene.getEnemyPokemon();
expect(enemy).not.toBe(undefined);
enemy.hp = 1;
// first turn
let previousEnemyHp = enemy.hp;
game.doAttack(getMovePosition(game.scene, 0, Moves.RAIN_DANCE));
await game.phaseInterceptor.to(TurnEndPhase);
expect(enemy.hp).toBeGreaterThan(previousEnemyHp);
// second turn
previousEnemyHp = enemy.hp;
game.doAttack(getMovePosition(game.scene, 0, Moves.SPLASH));
await game.phaseInterceptor.to(TurnEndPhase);
expect(enemy.hp).toBeGreaterThan(previousEnemyHp);
});
it("opposing fire attacks do 25% more damage", async () => {
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.EMBER]);
// ensure the enemy doesn't die to this
vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(30);
await game.startBattle();
const enemy = game.scene.getEnemyPokemon();
expect(enemy).not.toBe(undefined);
// first turn
game.doAttack(getMovePosition(game.scene, 0, Moves.EMBER));
await game.phaseInterceptor.to(TurnEndPhase);
const fireDamageTakenWithDrySkin = enemy.getMaxHp() - enemy.hp;
expect(enemy.hp > 0);
enemy.hp = enemy.getMaxHp();
vi.spyOn(overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.NONE);
// second turn
game.doAttack(getMovePosition(game.scene, 0, Moves.EMBER));
await game.phaseInterceptor.to(TurnEndPhase);
const fireDamageTakenWithoutDrySkin = enemy.getMaxHp() - enemy.hp;
expect(fireDamageTakenWithDrySkin).toBeGreaterThan(fireDamageTakenWithoutDrySkin);
});
it("opposing water attacks heal 1/4 of maximum health and deal no damage", async () => {
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.WATER_GUN]);
await game.startBattle();
const enemy = game.scene.getEnemyPokemon();
expect(enemy).not.toBe(undefined);
enemy.hp = 1;
game.doAttack(getMovePosition(game.scene, 0, Moves.WATER_GUN));
await game.phaseInterceptor.to(TurnEndPhase);
expect(enemy.hp).toBeGreaterThan(1);
});
it("opposing water attacks do not heal if they were protected from", async () => {
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.WATER_GUN]);
await game.startBattle();
const enemy = game.scene.getEnemyPokemon();
expect(enemy).not.toBe(undefined);
enemy.hp = 1;
vi.spyOn(overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.PROTECT, Moves.PROTECT, Moves.PROTECT, Moves.PROTECT]);
game.doAttack(getMovePosition(game.scene, 0, Moves.WATER_GUN));
await game.phaseInterceptor.to(TurnEndPhase);
expect(enemy.hp).toBe(1);
});
it("multi-strike water attacks only heal once", async () => {
vi.spyOn(overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.WATER_GUN, Moves.WATER_SHURIKEN]);
await game.startBattle();
const enemy = game.scene.getEnemyPokemon();
expect(enemy).not.toBe(undefined);
enemy.hp = 1;
// first turn
game.doAttack(getMovePosition(game.scene, 0, Moves.WATER_SHURIKEN));
await game.phaseInterceptor.to(TurnEndPhase);
const healthGainedFromWaterShuriken = enemy.hp - 1;
enemy.hp = 1;
// second turn
game.doAttack(getMovePosition(game.scene, 0, Moves.WATER_GUN));
await game.phaseInterceptor.to(TurnEndPhase);
const healthGainedFromWaterGun = enemy.hp - 1;
expect(healthGainedFromWaterShuriken).toBe(healthGainedFromWaterGun);
});
});