Files
ZYZ/game-server/app/util/util.ts
2020-10-09 20:26:53 +08:00

39 lines
1.1 KiB
TypeScript

export function genCode(len) {
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';
const charArr = chars.split('');
let code = '';
for (let i = 0; i < len; i++) {
code += charArr[Math.floor(Math.random() * charArr.length)];
}
return code;
}
export function decodeStr(type, str) {
if(str == '&') {
return []
} else {
return str.split('|').map(cur => {
let arr = cur.split('&');
let result = {};
switch (type) {
case 'fixReward': {
let [gid, count] = arr;
result = { gid: parseInt(gid), count: parseInt(count)};
break;
}
case 'conditionReward': {
let [gid, count, condition] = arr;
result = { gid: parseInt(gid), count: parseInt(count), condition: parseInt(condition) };
break;
}
case 'randomReward': {
let [gid, count, frequency] = arr;
result = { gid: parseInt(gid), count: parseInt(count), frequency: parseInt(frequency) };
}
}
return result;
});
};
}