Skip to content

Commit

Permalink
Implement Pity System (pagefaultgames#1752)
Browse files Browse the repository at this point in the history
* Implement Pity System

* Add comments and optimised worst case slightly
  • Loading branch information
Xavion3 authored Jun 3, 2024
1 parent 145a79f commit ff0e4fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/egg-hatch-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,19 @@ export class EggHatchPhase extends Phase {

const ignoredSpecies = [ Species.PHIONE, Species.MANAPHY, Species.ETERNATUS ];

const speciesPool = Object.keys(speciesStarters)
let speciesPool = Object.keys(speciesStarters)
.filter(s => speciesStarters[s] >= minStarterValue && speciesStarters[s] <= maxStarterValue)
.map(s => parseInt(s) as Species)
.filter(s => !pokemonPrevolutions.hasOwnProperty(s) && getPokemonSpecies(s).isObtainable() && ignoredSpecies.indexOf(s) === -1);

// If this is the 10th egg without unlocking something new, attempt to force it.
if (this.scene.gameData.unlockPity[this.egg.tier] >= 9) {
const lockedPool = speciesPool.filter(s => !this.scene.gameData.dexData[s].caughtAttr);
if (lockedPool.length) { // Skip this if everything is unlocked
speciesPool = lockedPool;
}
}

/**
* Pokemon that are cheaper in their tier get a weight boost. Regionals get a weight penalty
* 1 cost mons get 2x
Expand Down Expand Up @@ -536,6 +544,12 @@ export class EggHatchPhase extends Phase {
}
}

if (!!this.scene.gameData.dexData[species].caughtAttr) {
this.scene.gameData.unlockPity[this.egg.tier] = Math.min(this.scene.gameData.unlockPity[this.egg.tier] + 1, 10);
} else {
this.scene.gameData.unlockPity[this.egg.tier] = 0;
}

const pokemonSpecies = getPokemonSpecies(species);

ret = this.scene.addPlayerPokemon(pokemonSpecies, 1, undefined, undefined, undefined, false);
Expand Down
13 changes: 12 additions & 1 deletion src/system/game-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ interface SystemSaveData {
eggs: EggData[];
gameVersion: string;
timestamp: integer;
eggPity: integer[];
unlockPity: integer[];
}

export interface SessionSaveData {
Expand Down Expand Up @@ -248,6 +250,8 @@ export class GameData {
public voucherUnlocks: VoucherUnlocks;
public voucherCounts: VoucherCounts;
public eggs: Egg[];
public eggPity: integer[];
public unlockPity: integer[];

constructor(scene: BattleScene) {
this.scene = scene;
Expand All @@ -272,6 +276,8 @@ export class GameData {
[VoucherType.GOLDEN]: 0
};
this.eggs = [];
this.eggPity = [0, 0, 0, 0];
this.unlockPity = [0, 0, 0, 0];
this.initDexData();
this.initStarterData();
}
Expand All @@ -290,7 +296,9 @@ export class GameData {
voucherCounts: this.voucherCounts,
eggs: this.eggs.map(e => new EggData(e)),
gameVersion: this.scene.game.config.gameVersion,
timestamp: new Date().getTime()
timestamp: new Date().getTime(),
eggPity: this.eggPity.slice(0),
unlockPity: this.unlockPity.slice(0)
};
}

Expand Down Expand Up @@ -473,6 +481,9 @@ export class GameData {
? systemData.eggs.map(e => e.toEgg())
: [];

this.eggPity = systemData.eggPity ? systemData.eggPity.slice(0) : [0, 0, 0, 0];
this.unlockPity = systemData.unlockPity ? systemData.unlockPity.slice(0) : [0, 0, 0, 0];

this.dexData = Object.assign(this.dexData, systemData.dexData);
this.consolidateDexData(this.dexData);
this.defaultDexData = null;
Expand Down
14 changes: 14 additions & 0 deletions src/ui/egg-gacha-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,20 @@ export default class EggGachaUiHandler extends MessageUiHandler {
} else if (pullCount >= 10 && !tiers.filter(t => t >= EggTier.GREAT).length) {
tiers[Utils.randInt(tiers.length)] = EggTier.GREAT;
}
for (let i = 0; i < pullCount; i++) {
this.scene.gameData.eggPity[EggTier.GREAT] += 1;
this.scene.gameData.eggPity[EggTier.ULTRA] += 1;
this.scene.gameData.eggPity[EggTier.MASTER] += 1 + tierValueOffset;
// These numbers are roughly the 80% mark. That is, 80% of the time you'll get an egg before this gets triggered.
if (this.scene.gameData.eggPity[EggTier.MASTER] >= 412 && tiers[i] === EggTier.COMMON) {
tiers[i] = EggTier.MASTER;
} else if (this.scene.gameData.eggPity[EggTier.ULTRA] >= 59 && tiers[i] === EggTier.COMMON) {
tiers[i] = EggTier.ULTRA;
} else if (this.scene.gameData.eggPity[EggTier.GREAT] >= 9 && tiers[i] === EggTier.COMMON) {
tiers[i] = EggTier.GREAT;
}
this.scene.gameData.eggPity[tiers[i]] = 0;
}

const timestamp = new Date().getTime();

Expand Down

0 comments on commit ff0e4fb

Please sign in to comment.