diff --git a/src/data/egg.ts b/src/data/egg.ts index a47c9d9b2b0..3bfd39382b5 100644 --- a/src/data/egg.ts +++ b/src/data/egg.ts @@ -141,17 +141,15 @@ export class Egg { //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; // 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 this.checkForPityTierOverrides(eggOptions.scene); } this._id = eggOptions.id ?? Utils.randInt(EGG_SEED, EGG_SEED * this._tier); - // Increase pull statistics AFTER the ID was generated beacuse it will be used to check for mahnaphy egg - if (eggOptions.pulled) { - this.increasePullStatistic(eggOptions.scene); - } this._sourceType = eggOptions.sourceType ?? undefined; this._hatchWaves = eggOptions.hatchWaves ?? this.getEggTierDefaultHatchWaves(); this._timestamp = eggOptions.timestamp ?? new Date().getTime(); @@ -177,6 +175,7 @@ export class Egg { // Needs this._tier so it needs to be generated afer the tier override if bought from same species this._eggMoveIndex = eggOptions.eggMoveIndex ?? this.rollEggMoveIndex(); if (eggOptions.pulled) { + this.increasePullStatistic(eggOptions.scene); this.addEggToGameData(eggOptions.scene); } } diff --git a/src/test/eggs/egg.test.ts b/src/test/eggs/egg.test.ts index 90cd898e431..07678e7e1ea 100644 --- a/src/test/eggs/egg.test.ts +++ b/src/test/eggs/egg.test.ts @@ -226,4 +226,66 @@ describe("Egg Generation Tests", () => { expect(result.hatchWaves).toBe(legacyEgg.hatchWaves); expect(result.sourceType).toBe(legacyEgg.gachaType); }); + it("should increase egg pity", () => { + const scene = game.scene; + const startPityValues = [...scene.gameData.eggPity]; + + new Egg({scene, sourceType: EggSourceType.GACHA_MOVE, pulled: true, tier: EggTier.COMMON}); + + expect(scene.gameData.eggPity[EggTier.GREAT]).toBe(startPityValues[EggTier.GREAT] + 1); + expect(scene.gameData.eggPity[EggTier.ULTRA]).toBe(startPityValues[EggTier.ULTRA] + 1); + expect(scene.gameData.eggPity[EggTier.MASTER]).toBe(startPityValues[EggTier.MASTER] + 1); + }); + it("should increase legendary egg pity by two", () => { + const scene = game.scene; + const startPityValues = [...scene.gameData.eggPity]; + + new Egg({scene, sourceType: EggSourceType.GACHA_LEGENDARY, pulled: true, tier: EggTier.COMMON}); + + expect(scene.gameData.eggPity[EggTier.GREAT]).toBe(startPityValues[EggTier.GREAT] + 1); + expect(scene.gameData.eggPity[EggTier.ULTRA]).toBe(startPityValues[EggTier.ULTRA] + 1); + expect(scene.gameData.eggPity[EggTier.MASTER]).toBe(startPityValues[EggTier.MASTER] + 2); + }); + it("should not increase manaphy egg count if bulbasaurs are pulled", () => { + const scene = game.scene; + const startingManaphyEggCount = scene.gameData.gameStats.manaphyEggsPulled; + + for (let i = 0; i < 200; i++) { + new Egg({scene, sourceType: EggSourceType.GACHA_MOVE, pulled: true, species: Species.BULBASAUR}); + } + + expect(scene.gameData.gameStats.manaphyEggsPulled).toBe(startingManaphyEggCount); + }); + it("should increase manaphy egg count", () => { + const scene = game.scene; + const startingManaphyEggCount = scene.gameData.gameStats.manaphyEggsPulled; + + new Egg({scene, sourceType: EggSourceType.GACHA_MOVE, pulled: true, id: 204, tier: EggTier.COMMON}); + + expect(scene.gameData.gameStats.manaphyEggsPulled).toBe(startingManaphyEggCount + 1); + }); + it("should increase rare eggs pulled statistic", () => { + const scene = game.scene; + const startingRareEggsPulled = scene.gameData.gameStats.rareEggsPulled; + + new Egg({scene, sourceType: EggSourceType.GACHA_MOVE, pulled: true, tier: EggTier.GREAT}); + + expect(scene.gameData.gameStats.rareEggsPulled).toBe(startingRareEggsPulled + 1); + }); + it("should increase epic eggs pulled statistic", () => { + const scene = game.scene; + const startingEpicEggsPulled = scene.gameData.gameStats.epicEggsPulled; + + new Egg({scene, sourceType: EggSourceType.GACHA_MOVE, pulled: true, tier: EggTier.ULTRA}); + + expect(scene.gameData.gameStats.epicEggsPulled).toBe(startingEpicEggsPulled + 1); + }); + it("should increase legendary eggs pulled statistic", () => { + const scene = game.scene; + const startingLegendaryEggsPulled = scene.gameData.gameStats.legendaryEggsPulled; + + new Egg({scene, sourceType: EggSourceType.GACHA_MOVE, pulled: true, tier: EggTier.MASTER}); + + expect(scene.gameData.gameStats.legendaryEggsPulled).toBe(startingLegendaryEggsPulled + 1); + }); });