优化:gm-server创建武将
This commit is contained in:
@@ -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 长度
|
||||
|
||||
@@ -23,7 +23,7 @@ import Counter from '@db/Counter';
|
||||
import { STATUS, HERO_SYSTEM_TYPE } from '@consts';
|
||||
import { ITID, COUNTER } from '@consts';
|
||||
import { ItemModel } from '@db/Item';
|
||||
import { gameData, getHeroExpByLv, getExpByLv } from '@pubUtils/data';
|
||||
import { gameData, getExpByLv } from '@pubUtils/data';
|
||||
import { calPlayerCeAndSave, calculatetopLineup, calEquipSeids } from '@pubUtils/playerCe';
|
||||
import { SchoolModel } from '@db/School';
|
||||
import { AttributeCal } from '@domain/roleField/attribute';
|
||||
@@ -32,9 +32,10 @@ import { isString } from 'underscore';
|
||||
import { FriendShipModel } from '@db/FriendShip';
|
||||
import { FriendApplyModel } from '@db/FriendApply';
|
||||
import { FriendRelationModel } from '@db/FriendRelation';
|
||||
import { createHero as pubCreateHero, addSkin, addEquips, addBags } from '@pubUtils/itemUtils';
|
||||
import { addSkin, addEquips, addBags } from '@pubUtils/itemUtils';
|
||||
import { GiftCodeModel } from '@db/GiftCode';
|
||||
import { GiftCodeDetailModel } from '@db/GiftCodeDetail';
|
||||
import { CreateHeroes } from '@pubUtils/roleUtil';
|
||||
// import { resResult } from '@pubUtils/util';
|
||||
|
||||
// import * as fs from 'fs';
|
||||
@@ -240,38 +241,32 @@ export default class GMUsers extends Service {
|
||||
|
||||
public async createHero(uids: Array<string>, _hid: string, _hlv: string) {
|
||||
const { ctx } = this;
|
||||
console.log('gm createHero', uids, _hid, _hlv);
|
||||
let hlv = parseInt(_hlv);
|
||||
if (isNaN(hlv)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
let hids = (_hid as string).split('&').map(cur => parseInt(cur));
|
||||
for (let hid of hids) {
|
||||
if (isNaN(hid)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let heroInfos = new Array();
|
||||
for (let roleId of uids) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if (role) {
|
||||
for (let hid of hids) {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (hero) continue;
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
if (!dicHero) continue;
|
||||
const heroInfo = {
|
||||
roleId, roleName: role.roleName, hid, serverId: role.serverId,
|
||||
lv: hlv, exp: getHeroExpByLv(hlv - 1) || 0
|
||||
}
|
||||
heroInfos.push(heroInfo);
|
||||
}
|
||||
} else {
|
||||
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, '未找到角色' + roleId)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (let heroInfo of heroInfos) {
|
||||
await pubCreateHero(heroInfo.roleId, heroInfo.roleName, heroInfo.serverId, heroInfo);
|
||||
console.log('gm createHero', uids, _hid, _hlv);
|
||||
let hlv = parseInt(_hlv);
|
||||
if (isNaN(hlv)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
let hids = (_hid as string).split('&').map(cur => parseInt(cur));
|
||||
for (let hid of hids) {
|
||||
if (isNaN(hid)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
for (let roleId of uids) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if (role) {
|
||||
let heroInfos = new Map();
|
||||
for (let hid of hids) {
|
||||
let heroInfo = ctx.service.utils.getInitHeroById(hid);
|
||||
heroInfos.set(hid, {...heroInfo});
|
||||
}
|
||||
|
||||
let createHero = new CreateHeroes(roleId, role.roleName, role.serverId);
|
||||
await createHero.createWithHeroInfo(heroInfos);
|
||||
|
||||
} else {
|
||||
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, '未找到角色' + roleId)
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
|
||||
} catch (e) {
|
||||
console.error(e.stack)
|
||||
|
||||
Reference in New Issue
Block a user