From 301d42faed63edd43004bd860206df96bcca7161 Mon Sep 17 00:00:00 2001 From: __stdcall Date: Mon, 15 Apr 2024 18:51:31 +0800 Subject: [PATCH] Fix SR gacha lottery weight not capping --- components/lottery.ts | 8 ++++++-- model/starrail/gacha.ts | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/lottery.ts b/components/lottery.ts index 3d33790..c76bed1 100644 --- a/components/lottery.ts +++ b/components/lottery.ts @@ -7,7 +7,7 @@ export default class Lottery { probPrefix: number[]; probTotal: number; - constructor(objList: ObjType[], probList?: number[]) { + constructor(objList: ObjType[], probList?: number[], public probCeil: number = 0) { if (typeof probList === 'undefined') { this.length = objList.length; this.objList = objList; @@ -34,7 +34,11 @@ export default class Lottery { } choiceIndex(): number { - let r = lodash.random(0, this.probTotal, true); + let r : number; + if (this.probCeil > 0 && this.probCeil < this.probTotal) + r = lodash.random(0, this.probCeil, true); + else + r = lodash.random(0, this.probTotal, true); let i = lodash.sortedIndex(this.probPrefix, r); if (i >= this.length) i = this.length - 1; return i; diff --git a/model/starrail/gacha.ts b/model/starrail/gacha.ts index 1df6a2e..c042c87 100644 --- a/model/starrail/gacha.ts +++ b/model/starrail/gacha.ts @@ -92,14 +92,14 @@ export class Gacha { const five = this.s.last5 <= 72 ? 60 : 60 + 600 * (this.s.last5 - 72); const four = this.s.last4 <= 7 ? 510 : 510 + 5100 * (this.s.last4 - 7); return [ - five - 1, // 5* - four - 1, // 4* - 9430 - 1 // 3* + five, // 5* + four, // 4* + 9430 // 3* ]; } next(pool: GachaPool): GachaResult { - const lot = new Lottery([5, 4, 3], this.weight); + const lot = new Lottery([5, 4, 3], this.weight, 10000); const sub = lot.choice(); if (sub == 5) {