[Bug] Fix super luck implementation (#5625)

* Fix super luck implementation

* Use numberholder instead of booleanholder

* Update tsdoc for getCritStage
This commit is contained in:
Sirz Benjie 2025-04-04 19:40:25 -05:00 committed by GitHub
parent 420c2e37c2
commit 9e4162d429
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 12 deletions

View File

@ -3499,8 +3499,18 @@ export class BonusCritAbAttr extends AbAttr {
constructor() {
super(false);
}
override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: any[]): void {
(args[0] as Utils.BooleanHolder).value = true;
/**
* Apply the bonus crit ability by increasing the value in the provided number holder by 1
*
* @param pokemon The pokemon with the BonusCrit ability (unused)
* @param passive Unused
* @param simulated Unused
* @param cancelled Unused
* @param args Args[0] is a number holder containing the crit stage.
*/
override apply(pokemon: Pokemon, passive: boolean, simulated: boolean, cancelled: Utils.BooleanHolder, args: [Utils.NumberHolder, ...any]): void {
(args[0] as Utils.NumberHolder).value += 1;
}
}

View File

@ -1340,8 +1340,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
}
/**
* Retrieves the critical-hit stage considering the move used and the Pokemon
* who used it.
* Calculate the critical-hit stage of a move used against this pokemon by
* the given source
*
* @param source the {@linkcode Pokemon} who using the move
* @param move the {@linkcode Move} being used
* @returns the final critical-hit stage value
@ -1360,14 +1361,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
source.isPlayer(),
critStage,
);
const bonusCrit = new Utils.BooleanHolder(false);
//@ts-ignore
if (applyAbAttrs(BonusCritAbAttr, source, null, false, bonusCrit)) {
// TODO: resolve ts-ignore. This is a promise. Checking a promise is bogus.
if (bonusCrit.value) {
critStage.value += 1;
}
}
applyAbAttrs(BonusCritAbAttr, source, null, false, critStage)
const critBoostTag = source.getTag(CritBoostTag);
if (critBoostTag) {
if (critBoostTag instanceof DragonCheerTag) {

View File

@ -0,0 +1,43 @@
import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import { Species } from "#enums/species";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Abilities - Super Luck", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([Moves.TACKLE])
.ability(Abilities.SUPER_LUCK)
.battleType("single")
.disableCrits()
.enemySpecies(Species.MAGIKARP)
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset(Moves.SPLASH);
});
it("should increase the crit stage of a user by 1", async () => {
await game.classicMode.startBattle([Species.MAGIKARP]);
const enemy = game.scene.getEnemyPokemon()!;
const fn = vi.spyOn(enemy, "getCritStage");
game.move.select(Moves.TACKLE);
await game.phaseInterceptor.to("BerryPhase");
expect(fn).toHaveReturnedWith(1);
fn.mockRestore();
});
});