强化装备栏

This commit is contained in:
luying
2020-12-17 21:37:05 +08:00
parent b3ec0c85da
commit d2097a4264
9 changed files with 133 additions and 18 deletions

View File

@@ -1,11 +1,14 @@
import { Application, BackendSession } from "pinus";
import { resResult } from "../../../pubUtils/util";
import { STATUS } from "../../../consts";
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE } from "../../../consts";
import { addItems, handleCost } from "../../../services/rewardService";
import { gameData } from "../../../pubUtils/data";
import { ItemInter } from "../../../pubUtils/interface";
import { EquipModel } from "../../../db/Equip";
import { GOOD_TYPE } from "../../../consts/consts";
import { HeroModel, EPlace } from "../../../db/Hero";
import Role from "../../../db/Role";
import { calPlayerCeAndSave } from "../../../services/playerCeService";
export default function(app: Application) {
return new EquipHandler(app);
@@ -49,17 +52,75 @@ export class EquipHandler {
count: targetGood.pieces
});
}
console.log(JSON.stringify(cost))
let result = await handleCost(roleId, sid, cost);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let items = [{id: gid, count: 1}];
let items = [{type: GOOD_TYPE.EQUIP, id: gid, count: 1}];
let goods = await addItems(roleId, roleName, sid, items);
return resResult(STATUS.SUCCESS, { goods });
}
// TODO 装备栏强化
public async strengthen(msg: { }, session: BackendSession) {
public async strengthen(msg: { hid: number, ePlaceId: number, type: number }, session: BackendSession) {
let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let {hid, ePlaceId, type} = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
let { ePlace = new Array<EPlace>() } = hero; // 装备栏
let strengthenArr = new Array<EPlace>();
if(type == EQUIP_STRENGTHEN_TYPE.SINGLE || type == EQUIP_STRENGTHEN_TYPE.SINGLE_QUICK) { // 单装备强化
strengthenArr = ePlace.filter(cur => cur.id == ePlaceId && cur.equip);
} else if (type == EQUIP_STRENGTHEN_TYPE.ALL_QUICK) { // 全六件(装备中)的强化
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, lv: playerLv} = await Role.findByRoleId(roleId);
let maxLv = type == EQUIP_STRENGTHEN_TYPE.SINGLE?minLv + 1:playerLv;
let costCoin = 0; // 消耗铜币
let flag = false; // 铜币不足
for(let i = minLv; i < maxLv; i++) {
for(let s of strengthenArr) {
if(s.lv == i) {
let cost = gameData.strengthenCost.get(i + 1);
if(!cost) {flag = true; break;}
if(coin < costCoin + cost) { flag = true; break;}
costCoin += cost;
s.lv++;
}
}
if(flag) break;
}
if(costCoin <= 0) { // 连一级都不够升
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.EPLACE_STRENGTHEN);
const curHero = {
hid,
ePlace: strengthenArr
}
return resResult(STATUS.SUCCESS, {curHero});
}