70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import { Service } from 'egg';
|
|
import * as pubUtils from '../pubUtils/util';
|
|
import * as pubGamedata from '../pubUtils/gamedata'
|
|
import { HeroType } from '@db/Hero';
|
|
import { calPlayerCeAndSave } from '@pubUtils/playerCe';
|
|
import { addSkins, addBags, addEquips } from '@pubUtils/itemUtils';
|
|
import { BagInter, EquipInter } from '@pubUtils/interface';
|
|
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);
|
|
}
|
|
|
|
public calPlayerCeAndSave(roleId: string, heros: HeroType[], type: number, args: number[]) {
|
|
return calPlayerCeAndSave(roleId, heros, type, args)
|
|
}
|
|
|
|
public addSkins(roleId: string, id: number) {
|
|
return addSkins(roleId, id);
|
|
}
|
|
|
|
public addBags(roleId: string, roleName: string, data: BagInter) {
|
|
return addBags(roleId, roleName, data);
|
|
}
|
|
|
|
public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
|
return addEquips(roleId, roleName, weapon);
|
|
}
|
|
}
|