添加装备一键强化到指定等级逻辑
This commit is contained in:
@@ -147,6 +147,64 @@ export class EquipHandler {
|
||||
|
||||
}
|
||||
|
||||
// 装备栏一键强化至相应等级
|
||||
public async strengthenAll(msg: { hid: number, lv: number }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
// let roleName: string = session.get('roleName');
|
||||
let sid: string = session.get('sid');
|
||||
|
||||
let { hid, lv: maxLv } = msg; // lv: 升到哪一级
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let { ePlace, lv: playerLv } = hero; // 装备栏
|
||||
let strengthenArr = ePlace.filter(cur => cur.equip);
|
||||
|
||||
if (strengthenArr.length <= 0) {
|
||||
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
|
||||
}
|
||||
let minLv = strengthenArr[0].lv; // 从最低装备的等级开始
|
||||
for (let { lv } of strengthenArr) {
|
||||
if (lv < minLv) minLv = lv;
|
||||
}
|
||||
|
||||
let { coin } = await Role.findByRoleId(roleId);
|
||||
|
||||
if (maxLv > playerLv) {
|
||||
return resResult(STATUS.ROLE_EQUIP_REACH_MAX);
|
||||
}
|
||||
let costCoin = 0; // 消耗铜币
|
||||
for (let i = minLv; i < maxLv; i++) {
|
||||
for (let s of strengthenArr) {
|
||||
if (s.lv == i) {
|
||||
let cost = gameData.strengthenCost.get(i + 1);
|
||||
costCoin += cost;
|
||||
|
||||
s.lv++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (costCoin > coin) {
|
||||
return resResult(STATUS.ROLE_COIN_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
let result = await handleCost(roleId, sid, [{
|
||||
id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN),
|
||||
count: costCoin
|
||||
}]);
|
||||
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
hero.ePlace = ePlace;
|
||||
|
||||
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP_BASE);
|
||||
const curHero = {
|
||||
hid,
|
||||
ePlace: strengthenArr
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { curHero });
|
||||
|
||||
}
|
||||
// 装备栏精炼
|
||||
public async refine(msg: { hid: number, ePlaceId: number, material: { id: number, count: number }[] }, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
|
||||
@@ -87,7 +87,7 @@ export default class Equip extends BaseModel {
|
||||
const equip: EquipType = await EquipModel.findOneAndUpdate({ seqId }, update, {upsert: true, new: true}).lean(lean);
|
||||
if(equipInfo.hid > 0) {
|
||||
await HeroModel.findOneAndUpdate(
|
||||
{ roleId: equipInfo.roleId, hid: equipInfo.hid, 'ePlace.id': 1 },
|
||||
{ roleId: equipInfo.roleId, hid: equipInfo.hid, 'ePlace.id': equipInfo.ePlaceId },
|
||||
{$set: {'ePlace.$.equip': equip._id}},
|
||||
{new: true}).lean(lean);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user