From 8e6cbad3fc755cede25e102cb1c0d5b9a9cf6c8c Mon Sep 17 00:00:00 2001 From: Puchimono <74605022+puchidev@users.noreply.github.com> Date: Tue, 25 Jun 2024 23:14:28 +0900 Subject: [PATCH] [Bug] Legendary pull rate fix from Leg. up machine (#2587) --- src/data/egg.ts | 3 ++- src/test/eggs/egg.test.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/data/egg.ts b/src/data/egg.ts index 3bfd39382b5..eba3bab0d87 100644 --- a/src/data/egg.ts +++ b/src/data/egg.ts @@ -140,8 +140,9 @@ export class Egg { constructor(eggOptions?: IEggOptions) { //if (eggOptions.tier && eggOptions.species) throw Error("Error egg can't have species and tier as option. only choose one of them.") - this._tier = eggOptions.tier ?? (Overrides.EGG_TIER_OVERRIDE ?? this.rollEggTier()); this._sourceType = eggOptions.sourceType ?? undefined; + // Ensure _sourceType is defined before invoking rollEggTier(), as it is referenced + this._tier = eggOptions.tier ?? (Overrides.EGG_TIER_OVERRIDE ?? this.rollEggTier()); // If egg was pulled, check if egg pity needs to override the egg tier if (eggOptions.pulled) { // Needs this._tier and this._sourceType to work diff --git a/src/test/eggs/egg.test.ts b/src/test/eggs/egg.test.ts index 07678e7e1ea..a098620f5eb 100644 --- a/src/test/eggs/egg.test.ts +++ b/src/test/eggs/egg.test.ts @@ -1,4 +1,4 @@ -import {afterEach, beforeAll, beforeEach, describe, expect, it} from "vitest"; +import {afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import BattleScene from "../../battle-scene"; import { Egg, getLegendaryGachaSpeciesForTimestamp } from "#app/data/egg.js"; import { Species } from "#enums/species"; @@ -8,6 +8,7 @@ import { EggTier } from "#app/enums/egg-type.js"; import { VariantTier } from "#app/enums/variant-tiers.js"; import GameManager from "../utils/gameManager"; import EggData from "#app/system/egg-data.js"; +import * as Utils from "#app/utils.js"; describe("Egg Generation Tests", () => { let phaserGame: Phaser.Game; @@ -21,6 +22,7 @@ describe("Egg Generation Tests", () => { afterEach(() => { game.phaseInterceptor.restoreOg(); + vi.restoreAllMocks(); }); beforeEach(async() => { @@ -288,4 +290,17 @@ describe("Egg Generation Tests", () => { expect(scene.gameData.gameStats.legendaryEggsPulled).toBe(startingLegendaryEggsPulled + 1); }); + it("should increase legendary egg rate", () => { + vi.spyOn(Utils, "randInt").mockReturnValue(1); + + const scene = game.scene; + const expectedTier1 = EggTier.MASTER; + const expectedTier2 = EggTier.ULTRA; + + const result1 = new Egg({scene, sourceType: EggSourceType.GACHA_LEGENDARY, pulled: true}).tier; + const result2 = new Egg({scene, sourceType: EggSourceType.GACHA_MOVE, pulled: true}).tier; + + expect(result1).toBe(expectedTier1); + expect(result2).toBe(expectedTier2); + }); });