✨ feat(抽卡): 为了ur武将概率,修改抽卡卡池精度
This commit is contained in:
@@ -67,7 +67,7 @@ function parsePercent(str: string) {
|
||||
if (isNaN(parseInt(planId)) || isNaN(parseInt(weight))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ planId: parseInt(planId), weight: parseInt(weight) });
|
||||
result.push({ planId: parseInt(planId), weight: Math.floor(parseFloat(weight) * 10) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ export function getRandSingleIndex(len: number) {
|
||||
*/
|
||||
export function getRandEelmWithWeight<T extends { weight: number }>(randomList: T[]): { dic: T, index: number } {
|
||||
let len = randomList.reduce((pre, cur) => {
|
||||
return pre + cur.weight || 1;
|
||||
return pre + (cur.weight||0);
|
||||
}, 0);
|
||||
let index = Math.floor(Math.random() * len);
|
||||
let result = { dic: null, index: -1 };
|
||||
|
||||
Reference in New Issue
Block a user