优化: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
+27 -32
View File
@@ -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)