From 5fed690187f094d81604d8191d343c5057cf0116 Mon Sep 17 00:00:00 2001 From: Bertie690 <136088738+Bertie690@users.noreply.github.com> Date: Sat, 30 Nov 2024 04:47:47 -0500 Subject: [PATCH] [Bug] Fixed Super Fang interaction with Multi Lens (#4914) Co-authored-by: Jannik Tappert <38758606+CodeTappert@users.noreply.github.com> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/data/move.ts | 28 ++++++++++++++-- src/field/pokemon.ts | 4 +-- src/test/items/multi_lens.test.ts | 53 +++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index 9696e2e4d53..944b5c230a6 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1385,14 +1385,38 @@ export class UserHpDamageAttr extends FixedDamageAttr { } export class TargetHalfHpDamageAttr extends FixedDamageAttr { + // the initial amount of hp the target had before the first hit + // used for multi lens + private initialHp: number; constructor() { super(0); } apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - (args[0] as Utils.IntegerHolder).value = Utils.toDmgValue(target.hp / 2); + // first, determine if the hit is coming from multi lens or not + const lensCount = user.getHeldItems().find(i => i instanceof PokemonMultiHitModifier)?.getStackCount() ?? 0; + if (lensCount <= 0) { + // no multi lenses; we can just halve the target's hp and call it a day + (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(target.hp / 2); + return true; + } - return true; + // figure out what hit # we're on + switch (user.turnData.hitCount - user.turnData.hitsLeft) { + case 0: + // first hit of move; update initialHp tracker + this.initialHp = target.hp; + default: + // multi lens added hit; use initialHp tracker to ensure correct damage + (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(this.initialHp / 2); + return true; + break; + case lensCount + 1: + // parental bond added hit; calc damage as normal + (args[0] as Utils.NumberHolder).value = Utils.toDmgValue(target.hp / 2); + return true; + break; + } } getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number { diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 961cb943731..397bf2cbf36 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2618,8 +2618,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { }; } - // If the attack deals fixed damaged, return a result with that much damage - const fixedDamage = new Utils.IntegerHolder(0); + // If the attack deals fixed damage, return a result with that much damage + const fixedDamage = new Utils.NumberHolder(0); applyMoveAttrs(FixedDamageAttr, source, this, move, fixedDamage); if (fixedDamage.value) { const multiLensMultiplier = new Utils.NumberHolder(1); diff --git a/src/test/items/multi_lens.test.ts b/src/test/items/multi_lens.test.ts index c5e60c9f9e5..f4b4c5712ee 100644 --- a/src/test/items/multi_lens.test.ts +++ b/src/test/items/multi_lens.test.ts @@ -135,4 +135,57 @@ describe("Items - Multi Lens", () => { expect(damageResults[0]).toBe(Math.floor(playerPokemon.level * 0.75)); expect(damageResults[1]).toBe(Math.floor(playerPokemon.level * 0.25)); }); + + it("should result in correct damage for hp% attacks with 1 lens", async () => { + game.override.startingHeldItems([{ name: "MULTI_LENS", count: 1 }]) + .moveset(Moves.SUPER_FANG) + .ability(Abilities.COMPOUND_EYES) + .enemyLevel(1000) + .enemySpecies(Species.BLISSEY); // allows for unrealistically high levels of accuracy + + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + const enemyPokemon = game.scene.getEnemyPokemon()!; + + game.move.select(Moves.SUPER_FANG); + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + await game.phaseInterceptor.to("MoveEndPhase"); + expect(enemyPokemon.getHpRatio()).toBeCloseTo(0.5, 5); + }); + + it("should result in correct damage for hp% attacks with 2 lenses", async () => { + game.override.startingHeldItems([{ name: "MULTI_LENS", count: 2 }]) + .moveset(Moves.SUPER_FANG) + .ability(Abilities.COMPOUND_EYES) + .enemyMoveset(Moves.SPLASH) + .enemyLevel(1000) + .enemySpecies(Species.BLISSEY); // allows for unrealistically high levels of accuracy + + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + const enemyPokemon = game.scene.getEnemyPokemon()!; + + game.move.select(Moves.SUPER_FANG); + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + await game.phaseInterceptor.to("MoveEndPhase"); + expect(enemyPokemon.getHpRatio()).toBeCloseTo(0.5, 5); + }); + it("should result in correct damage for hp% attacks with 2 lenses + Parental Bond", async () => { + game.override.startingHeldItems([{ name: "MULTI_LENS", count: 2 }]) + .moveset(Moves.SUPER_FANG) + .ability(Abilities.PARENTAL_BOND) + .passiveAbility(Abilities.COMPOUND_EYES) + .enemyMoveset(Moves.SPLASH) + .enemyLevel(1000) + .enemySpecies(Species.BLISSEY); // allows for unrealistically high levels of accuracy + + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + const enemyPokemon = game.scene.getEnemyPokemon()!; + + game.move.select(Moves.SUPER_FANG); + await game.setTurnOrder([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]); + await game.phaseInterceptor.to("MoveEndPhase"); + expect(enemyPokemon.getHpRatio()).toBeCloseTo(0.25, 5); + }); });