Skip to content

Commit

Permalink
#314 Fixed gamble
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoAbove committed Sep 22, 2023
1 parent 58182b3 commit 94c8f24
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/services/SeedInfo/infoHandler/InfoProviders/Perk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ export class PerkInfoProvider extends InfoProvider {
}
let rerollRes = this._getReroll(res.length);
if (gambleSelected) {
const p1 = this._getNextPerk(perkDeck);
const p2 = this._getNextPerk(perkDeck);
const [p1, p2] = this.getGamble(perkDeck);
rerollRes.push(p1);
rerollRes.push(p2);
picksForWorld[i].push(p1, p2);
Expand All @@ -342,8 +341,7 @@ export class PerkInfoProvider extends InfoProvider {
}
} else {
if (gambleSelected) {
const p1 = this._getNextPerk(perkDeck);
const p2 = this._getNextPerk(perkDeck);
const [p1, p2] = this.getGamble(perkDeck);
res.push(p1);
res.push(p2);
picksForWorld[i].push(p1, p2);
Expand Down Expand Up @@ -386,6 +384,24 @@ export class PerkInfoProvider extends InfoProvider {
return hydrated;
}

getGamble(perkDeck: any[]): [string, string] {
// This naive approach works perfectly
// because of the deduplication of perks
// see MIN_DISTANCE_BETWEEN_DUPLICATE_PERKS

let p1 = this._getNextPerk(perkDeck);
if (p1 === "GAMBLE") {
p1 = this._getNextPerk(perkDeck);
}

let p2 = this._getNextPerk(perkDeck);
if (p2 === "GAMBLE") {
p2 = this._getNextPerk(perkDeck);
}

return [p1, p2];
}

provideStateless(state: IPerkChangeAction[], preview?: boolean) {
let lotteries = 0;
const perkState: Map<number, string[][]> = new Map();
Expand Down Expand Up @@ -435,8 +451,7 @@ export class PerkInfoProvider extends InfoProvider {

if (perk === "GAMBLE") {
const perkDeck = this.getPerkDeck();
const p1 = this._getNextPerk(perkDeck);
const p2 = this._getNextPerk(perkDeck);
const [p1, p2] = this.getGamble(perkDeck);
const l = perks[row].length;
perks[row].push(p1, p2);
selected[row][l] = p1;
Expand Down

0 comments on commit 94c8f24

Please sign in to comment.