军团活动:修改粮草先行道具分配
This commit is contained in:
+23
-3
@@ -237,8 +237,8 @@ export function getRandEelmWithWeight<T extends { weight: number }>(randomList:
|
||||
* 不改变原数组长度,将内部元素打乱
|
||||
* @param source
|
||||
*/
|
||||
export function sortArrRandom(source = []) {
|
||||
let arr = deepCopy(source);
|
||||
export function sortArrRandom<T>(source: T[] = []): T[] {
|
||||
let arr: T[] = deepCopy(source);
|
||||
return arr.sort(() => { return Math.random() - 0.5; });
|
||||
}
|
||||
|
||||
@@ -752,4 +752,24 @@ export function getWarTypeName(warType: number) {
|
||||
case WAR_TYPE.TRY: return '试用关卡';
|
||||
case WAR_TYPE.BOSS: return '演武台';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 一群人分总数固定的东西
|
||||
* @param total 总数
|
||||
* @param max 每个人能拿到的最大数量
|
||||
* @param memberCnt 人数
|
||||
*/
|
||||
export function getRandResultByMember(total: number, max: number, memberCnt: number) {
|
||||
let arr: number[] = [];
|
||||
for(let i = 1; i <= memberCnt; i++) {
|
||||
let randMax = total > max? max: total;
|
||||
let randMin = total - (memberCnt - i) * max;
|
||||
if(randMin < 0) randMin = 0;
|
||||
if(randMin > max) randMin = max;
|
||||
let rand = getRandValueByMinMax(randMin, randMax + 1, 0);
|
||||
arr.push(rand);
|
||||
total -= rand;
|
||||
}
|
||||
return { arr, remain: total }
|
||||
}
|
||||
Reference in New Issue
Block a user