Skip to content

Commit

Permalink
Fix SR gacha lottery weight not capping
Browse files Browse the repository at this point in the history
  • Loading branch information
stdcall0 committed Apr 15, 2024
1 parent 1fa720c commit 301d42f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions components/lottery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class Lottery<ObjType> {
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;
Expand All @@ -34,7 +34,11 @@ export default class Lottery<ObjType> {
}

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;
Expand Down
8 changes: 4 additions & 4 deletions model/starrail/gacha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 301d42f

Please sign in to comment.