50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { Service } from 'egg';
|
|
import * as pubUtils from '../pubUtils/util';
|
|
import * as pubGamedata from '../pubUtils/gamedata'
|
|
const csprng = require('csprng');
|
|
|
|
/**
|
|
* Utils Service
|
|
*/
|
|
export default class Utils extends Service {
|
|
/**
|
|
* 生成 len 长度的随机字符串
|
|
* @param len 长度
|
|
* @param radix 基数
|
|
*/
|
|
public generateStr(len: number, radix = 36) {
|
|
return `${csprng(len, radix)}`;
|
|
}
|
|
|
|
public genCode(len: number) {
|
|
return pubUtils.genCode(len)
|
|
}
|
|
|
|
public getGamedata(key: string) {
|
|
return pubGamedata.getGamedata(key);
|
|
}
|
|
|
|
public getHeroById(hid: number) {
|
|
return pubGamedata.getHeroInfoById(hid);
|
|
}
|
|
public getWarById(warid: number) {
|
|
return pubGamedata.getWarById(warid);
|
|
}
|
|
|
|
public getGoodById(gid: number) {
|
|
return pubGamedata.getGoodById(gid);
|
|
}
|
|
|
|
public calculateCE(heroInfo: {hid: number, lv: number }) {
|
|
return pubUtils.calculateCE(heroInfo)
|
|
}
|
|
|
|
public getExpByLv(lv: number) {
|
|
return pubGamedata.getExpByLv(lv);
|
|
}
|
|
|
|
public resResult(status: {code: number, simStr: string}, data?, customMsg?: string) {
|
|
return pubUtils.resResult(status, data, customMsg);
|
|
}
|
|
}
|