优化:gm-server创建武将

This commit is contained in:
luying
2021-09-02 20:33:00 +08:00
parent e572cb2fa5
commit 62e32a4eb3
11 changed files with 372 additions and 191 deletions
+31
View File
@@ -1,11 +1,42 @@
import { Service } from 'egg';
import * as pubUtils from '@pubUtils/util';
import { HeroUpdate } from '@db/Hero';
import { SkinUpdate } from '@db/Skin';
import { getInitRoleInfo } from '@pubUtils/roleUtil';
const csprng = require('csprng');
/**
* Utils Service
*/
export default class Utils extends Service {
constructor(args) {
super(args);
this.setInitRole();
}
private initHeroes: Map<number, HeroUpdate> = new Map(); // hid => hero
private initSkins: Map<number, SkinUpdate> = new Map(); // hid => skin
public setInitRole() {
let result = getInitRoleInfo();
let { heroes, skins } = result;
for(let hero of heroes) {
this.initHeroes.set(hero.hid, hero);
}
for(let skin of skins) {
this.initSkins.set(skin.hid, skin);
}
}
public getInitHeroById(hid: number) {
return {
heroInfo: this.initHeroes.get(hid),
skinInfo: this.initSkins.get(hid)
}
}
/**
* 生成 len 长度的随机字符串
* @param len 长度