优化:创建武将从util放到game-server的service

This commit is contained in:
陆莹
2022-03-16 20:42:46 +08:00
parent 73e5ec2698
commit 4e110afc70
11 changed files with 439 additions and 428 deletions

View File

@@ -3,17 +3,15 @@ import { CeAttrDataRole, RoleModel } from '@db/Role';
import { HeroModel } from '@db/Hero';
import { Service } from 'egg';
import { STATUS, ITEM_CHANGE_REASON, REDIS_KEY, WAR_TYPE } from '@consts';
import { ITID } from '@consts';
import { STATUS, REDIS_KEY, WAR_TYPE } from '@consts';
import { ItemModel } from '@db/Item';
import { gameData, getExpByLv } from '@pubUtils/data';
import { gameData } from '@pubUtils/data';
import { AttributeCal } from '@domain/roleField/attribute';
import { smsModel } from '@db/Sms';
import { isString } from 'underscore';
import { addSkin, addBags } from '@pubUtils/itemUtils';
import { GiftCodeModel } from '@db/GiftCode';
import { GiftCodeDetailModel } from '@db/GiftCodeDetail';
import { CreateHeroes, deletRole } from '@pubUtils/roleUtil';
import { deletRole } from '@pubUtils/roleUtil';
import { RScriptRecordModel } from '@db/RScriptRecord';
import { DicWar } from '@pubUtils/dictionary/DicWar';
import { SearchHeroParam, SearchUserParam, SearchGiftCodeParam, SearchGiftCodeDetailParam, SearchItemParam, SearchGuildParam } from '@domain/backEndField/search';
@@ -143,127 +141,127 @@ export default class GMUsers extends Service {
return ctx.service.utils.resResult(STATUS.SUCCESS, { list, total })
}
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);
}
// 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);
// }
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});
}
// 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);
// 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)
}
}
// } else {
// return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, '未找到角色' + roleId)
// }
// }
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
}
// return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
// }
public async createItem(uids: Array<string>, _itemid: string, _itemcount: string) {
const { ctx } = this;
console.log('gm createItem', uids, _itemid, _itemcount);
let itemids = (_itemid as string).split('&').map(cur => parseInt(cur));
for (let itemid of itemids) {
if (isNaN(itemid)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
}
let itemcount = parseInt(_itemcount);
if (isNaN(itemcount)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
// public async createItem(uids: Array<string>, _itemid: string, _itemcount: string) {
// const { ctx } = this;
// console.log('gm createItem', uids, _itemid, _itemcount);
// let itemids = (_itemid as string).split('&').map(cur => parseInt(cur));
// for (let itemid of itemids) {
// if (isNaN(itemid)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
// }
// let itemcount = parseInt(_itemcount);
// if (isNaN(itemcount)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
let flag = 0, msg = '创建失败';
let datas: {id: number, count: number }[] = []
for (let itemid of itemids) {
let dicGoods = gameData.goods.get(itemid);
let itidObj = ITID.get(dicGoods.itid);
// let flag = 0, msg = '创建失败';
// let datas: {id: number, count: number }[] = []
// for (let itemid of itemids) {
// let dicGoods = gameData.goods.get(itemid);
// let itidObj = ITID.get(dicGoods.itid);
if (!dicGoods) {
flag = 1, msg = "未找到道具" + itemid;
} else if (!itidObj) {
flag = 1, msg = "未找到道具" + itemid;
} else {
datas.push({ id: itemid, count: itemcount });
}
}
if(flag == 0) {
for (let roleId of uids) {
let role = await RoleModel.findByRoleId(roleId);
if (role) {
await addBags(roleId, role.roleName, datas, ITEM_CHANGE_REASON.DEBUG);
} else {
flag = 1, msg = '未找到角色' + roleId;
}
}
}
// if (!dicGoods) {
// flag = 1, msg = "未找到道具" + itemid;
// } else if (!itidObj) {
// flag = 1, msg = "未找到道具" + itemid;
// } else {
// datas.push({ id: itemid, count: itemcount });
// }
// }
// if(flag == 0) {
// for (let roleId of uids) {
// let role = await RoleModel.findByRoleId(roleId);
// if (role) {
// await addBags(roleId, role.roleName, datas, ITEM_CHANGE_REASON.DEBUG);
// } else {
// flag = 1, msg = '未找到角色' + roleId;
// }
// }
// }
if (flag) {
return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, msg);
} else {
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
}
}
// if (flag) {
// return ctx.service.utils.resResult(STATUS.GM_CREATE_ERROR, null, msg);
// } else {
// return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
// }
// }
public async addGold(uids: Array<string>, _count: string) {
const { ctx } = this;
console.log('gm addGold', uids, _count);
let count = parseInt(_count);
if (isNaN(count)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
for (let roleId of uids) {
await RoleModel.addGoldFree(roleId, count);
}
// public async addGold(uids: Array<string>, _count: string) {
// const { ctx } = this;
// console.log('gm addGold', uids, _count);
// let count = parseInt(_count);
// if (isNaN(count)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
// for (let roleId of uids) {
// await RoleModel.addGoldFree(roleId, count);
// }
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
}
// return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
// }
public async addCoin(uids: Array<string>, _count: string) {
const { ctx } = this;
console.log('gm addCoin', uids, _count);
let count = parseInt(_count);
if (isNaN(count)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
for (let roleId of uids) {
await RoleModel.addCoin(roleId, count);
}
// public async addCoin(uids: Array<string>, _count: string) {
// const { ctx } = this;
// console.log('gm addCoin', uids, _count);
// let count = parseInt(_count);
// if (isNaN(count)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
// for (let roleId of uids) {
// await RoleModel.addCoin(roleId, count);
// }
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
}
public async addSkin(uids: Array<string>, _id: string) {
const { ctx } = this;
console.log('gm addSkin', uids, _id);
let id = parseInt(_id);
if (isNaN(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
for (let roleId of uids) {
let role = await RoleModel.findByRoleId(roleId);
await addSkin(roleId, role.roleName, id, false);
}
// return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
// }
// public async addSkin(uids: Array<string>, _id: string) {
// const { ctx } = this;
// console.log('gm addSkin', uids, _id);
// let id = parseInt(_id);
// if (isNaN(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
// for (let roleId of uids) {
// let role = await RoleModel.findByRoleId(roleId);
// await addSkin(roleId, role.roleName, id, false);
// }
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
}
// return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
// }
public async levelUp(uids: Array<string>, _lv: string) {
const { ctx } = this;
console.log('gm levelUp', uids, _lv);
let lv = parseInt(_lv);
if (isNaN(lv)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
for (let roleId of uids) {
let exp = getExpByLv(lv - 1);
await RoleModel.levelup(roleId, lv, exp ? exp.sum : 0);
}
// public async levelUp(uids: Array<string>, _lv: string) {
// const { ctx } = this;
// console.log('gm levelUp', uids, _lv);
// let lv = parseInt(_lv);
// if (isNaN(lv)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
// for (let roleId of uids) {
// let exp = getExpByLv(lv - 1);
// await RoleModel.levelup(roleId, lv, exp ? exp.sum : 0);
// }
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
}
// return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });
// }
// public async getHeroList(roleId: string) {
// const {ctx} = this;