抽卡:添加抽卡接口
This commit is contained in:
@@ -189,11 +189,11 @@ export function decodeArrayListStr(str: string) {
|
||||
*/
|
||||
export function decodeIdCntArrayStr(str: string, multi: number) {
|
||||
const strArr = decodeArrayStr(str);
|
||||
console.log('decodeIdCntArrayStr: ', strArr);
|
||||
const strMap = new Map();
|
||||
// console.log('decodeIdCntArrayStr: ', strArr);
|
||||
const strMap = new Map<string, number>();
|
||||
strArr.forEach(item => {
|
||||
const kv = item.split('&');
|
||||
strMap.set(kv[0], multi ? Math.ceil(parseInt(kv[1]) * multi) : kv[1]);
|
||||
strMap.set(kv[0], multi ? Math.ceil(parseInt(kv[1]) * multi) : parseInt(kv[1]));
|
||||
});
|
||||
return strMap;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ export function getRandomIndexByLen(len: number) {
|
||||
return Math.floor(Math.random() * len);
|
||||
}
|
||||
|
||||
export function getRandomWithWeight(randomList: any) {
|
||||
export function getRandomWithWeight<T extends { weight: number }>(randomList: T[]): { dic: T, index: number } {
|
||||
let len = randomList.reduce((pre, cur) => {
|
||||
return pre + cur.weight || 1;
|
||||
}, 0);
|
||||
@@ -312,7 +312,7 @@ export function getRefTime(now = new Date(), checkHour: number, day = 0) {
|
||||
* @param source 原数组
|
||||
* @param cnt 返回随机元素个数
|
||||
*/
|
||||
export function getRandEelm(source: Array<any> = [], cnt = 1): Array<any> {
|
||||
export function getRandEelm<T>(source: Array<T> = [], cnt = 1): Array<T> {
|
||||
if (cnt > source.length || cnt == 0) return [];
|
||||
if (cnt === source.length) return source;
|
||||
let idxs = new Set();
|
||||
|
||||
Reference in New Issue
Block a user