[BUG] Legendary egg pity & manaphy counter fix + Egg unit tests (#2534)

* Fixed bug that legendary egg pity only increased by one if egg pulled out of legendary gacha

* Removed debug logs

* Added new unit tests. Fixed bug that sometimes common eggs do count as manaphy eggs.
This commit is contained in:
sirzento 2024-06-23 18:40:37 +02:00 committed by GitHub
parent 7f15efcd34
commit 0bd25e925e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 4 deletions

View File

@ -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.") //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._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 egg was pulled, check if egg pity needs to override the egg tier
if (eggOptions.pulled) { if (eggOptions.pulled) {
// Needs this._tier and this._sourceType to work
this.checkForPityTierOverrides(eggOptions.scene); this.checkForPityTierOverrides(eggOptions.scene);
} }
this._id = eggOptions.id ?? Utils.randInt(EGG_SEED, EGG_SEED * this._tier); 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._sourceType = eggOptions.sourceType ?? undefined;
this._hatchWaves = eggOptions.hatchWaves ?? this.getEggTierDefaultHatchWaves(); this._hatchWaves = eggOptions.hatchWaves ?? this.getEggTierDefaultHatchWaves();
this._timestamp = eggOptions.timestamp ?? new Date().getTime(); 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 // Needs this._tier so it needs to be generated afer the tier override if bought from same species
this._eggMoveIndex = eggOptions.eggMoveIndex ?? this.rollEggMoveIndex(); this._eggMoveIndex = eggOptions.eggMoveIndex ?? this.rollEggMoveIndex();
if (eggOptions.pulled) { if (eggOptions.pulled) {
this.increasePullStatistic(eggOptions.scene);
this.addEggToGameData(eggOptions.scene); this.addEggToGameData(eggOptions.scene);
} }
} }

View File

@ -226,4 +226,66 @@ describe("Egg Generation Tests", () => {
expect(result.hatchWaves).toBe(legacyEgg.hatchWaves); expect(result.hatchWaves).toBe(legacyEgg.hatchWaves);
expect(result.sourceType).toBe(legacyEgg.gachaType); 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);
});
}); });