From a8c9065d5796eb12b371d64b8419ef56e2fdcd6e Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Sat, 17 Aug 2024 09:49:42 -0700 Subject: [PATCH] [Bug] Lock Capsule no longer treats common items as free (#3591) * Fixed null check to actually check for null and not 0 * Add test and `startingModifier()` override helper function * Add tsdoc --- src/modifier/modifier-type.ts | 2 +- src/phases.ts | 2 +- src/test/items/lock_capsule.test.ts | 47 +++++++++++++++++++++++ src/test/utils/helpers/overridesHelper.ts | 11 ++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/test/items/lock_capsule.test.ts diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index a791f543d9c..365fc433d2f 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -2209,7 +2209,7 @@ export function getDefaultModifierTypeForTier(tier: ModifierTier): ModifierType } export class ModifierTypeOption { - public type: ModifierType | null; + public type: ModifierType; public upgradeCount: integer; public cost: integer; diff --git a/src/phases.ts b/src/phases.ts index cafaa4bd02b..6a9e25b8b5e 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -5580,7 +5580,7 @@ export class SelectModifierPhase extends BattlePhase { } else if (lockRarities) { const tierValues = [50, 125, 300, 750, 2000]; for (const opt of typeOptions) { - baseValue += opt.type?.tier ? tierValues[opt.type.tier] : 0; + baseValue += tierValues[opt.type.tier ?? 0]; } } else { baseValue = 250; diff --git a/src/test/items/lock_capsule.test.ts b/src/test/items/lock_capsule.test.ts new file mode 100644 index 00000000000..32103a6d780 --- /dev/null +++ b/src/test/items/lock_capsule.test.ts @@ -0,0 +1,47 @@ +import GameManager from "#test/utils/gameManager"; +import Phase from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +import { Abilities } from "#app/enums/abilities.js"; +import { Moves } from "#app/enums/moves.js"; +import { getMovePosition } from "../utils/gameManagerUtils"; +import { SelectModifierPhase } from "#app/phases.js"; +import { ModifierTypeOption, modifierTypes } from "#app/modifier/modifier-type.js"; + +describe("Items - Lock Capsule", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phase.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + + game.override + .battleType("single") + .startingLevel(200) + .moveset([Moves.SURF]) + .enemyAbility(Abilities.BALL_FETCH) + .startingModifier([{name: "LOCK_CAPSULE"}]); + }); + + it("doesn't set the cost of common tier items to 0", async() => { + await game.startBattle(); + + game.doAttack(getMovePosition(game.scene, 0, Moves.SURF)); + await game.phaseInterceptor.to(SelectModifierPhase, false); + + const rewards = game.scene.getCurrentPhase() as SelectModifierPhase; + const potion = new ModifierTypeOption(modifierTypes.POTION(), 0, 40); // Common tier item + const rerollCost = rewards.getRerollCost([potion, potion, potion], true); + + expect(rerollCost).toBe(150); + }, 20000); +}); diff --git a/src/test/utils/helpers/overridesHelper.ts b/src/test/utils/helpers/overridesHelper.ts index dbcb02825f2..d5eaee003db 100644 --- a/src/test/utils/helpers/overridesHelper.ts +++ b/src/test/utils/helpers/overridesHelper.ts @@ -84,6 +84,17 @@ export class OverridesHelper extends GameManagerHelper { return this; } + /** + * Override the player's starting modifiers + * @param modifiers the modifiers to set + * @returns this + */ + startingModifier(modifiers: ModifierOverride[]): this { + vi.spyOn(Overrides, "STARTING_MODIFIER_OVERRIDE", "get").mockReturnValue(modifiers); + this.log(`Player starting modifiers set to: ${modifiers}`); + return this; + } + /** * Override the player (pokemon) {@linkcode Abilities | ability} * @param ability the (pokemon) {@linkcode Abilities | ability} to set