战力显示缩小

This commit is contained in:
luying
2020-12-24 10:53:23 +08:00
parent cc1a91ed09
commit 4bfc92f8cf
6 changed files with 66 additions and 28 deletions

View File

@@ -1,10 +1,8 @@
import { Application, BackendSession } from "pinus";
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, GOOD_TYPE, HERO_GROW_MAX } from "../../../consts";
import { ItemInter } from "../../../pubUtils/interface";
import { resResult, parseGoodStr, getRandomByLen, deepCopy, mergeSameGoods, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
import { resResult, parseGoodStr, getRandomByLen, deepCopy, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
import { addItems, handleCost } from "../../../services/rewardService";
import { checkMaterialEnough } from "../../../services/equipService";
import { EquipModel, RandSe } from "../../../db/Equip";
import { HeroModel, EPlace } from "../../../db/Hero";
import { ItemModel } from "../../../db/Item";
@@ -444,7 +442,7 @@ export class EquipHandler {
if (jewelInfo.itid != equipJewel)
return resResult(STATUS.EQUIP_NOT_MATCH_JEWEL);
let index = _.findIndex(equip.holes, { id });
if (index > 0)
if (index < 0)
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
if (!equip.holes[index].isOpen)
return resResult(STATUS.EQUIP_HOLE_IS_NOT_DUG);
@@ -467,27 +465,55 @@ export class EquipHandler {
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
}
//宝石合成(一键放入type:1, 合成type:2)
public async composeJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, type: number }, session: BackendSession) {
let { count, consumes, jewel, type } = msg;
//宝石合成
public async composeJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, speConsumes: Array<{ id: number, count: number }> }, session: BackendSession) {
let { count, consumes, jewel, speConsumes } = msg;
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let goodInfo = getGoodById(jewel);
let good = ITID.get(goodInfo.itid);
if (good.type != CONSUME_TYPE.JEWEL)
let { type } = ITID.get(goodInfo.itid);
if (type != CONSUME_TYPE.JEWEL)
return resResult(STATUS.WRONG_PARMS);
//检查宝石消耗是否合法TODO
let needConsumes = checkMaterialEnough(consumes, jewel, count);
if (!needConsumes)
let comJewelMap = {};
let ways = [deepCopy(speConsumes)];
for (let { id, count } of consumes) {
let jewelInfo = getJewelById(id);
if (!jewelInfo) {
return resResult(STATUS.WRONG_PARMS);
}
count = Math.floor((count + (comJewelMap[jewelInfo.good_id] || 0)) / jewelInfo.count);
if (count < 1) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
let speCount = jewelInfo.specialMaterial.count * count;
if (jewelInfo.specialMaterial.ids.length) {
let copyWays = deepCopy(ways);
ways = [];
for (let id of jewelInfo.specialMaterial.ids) {
for (let way of copyWays) {
let index = _.findIndex(way, { id });
if (index && way[index].count >= speCount) {
way[index].count = way[index].count - speCount;
ways.push(way);
}
}
}
if (!ways.length)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
delete comJewelMap[jewelInfo.good_id];
comJewelMap[jewelInfo.nextJewelId] = count + (comJewelMap[jewelInfo.nextJewelId] || 0);
}
if (comJewelMap[jewel] != count || Object.keys(comJewelMap).length != 1)
return resResult(STATUS.WRONG_PARMS);
let res = await handleCost(roleId, sid, needConsumes);
let res = await handleCost(roleId, sid, consumes.concat(speConsumes));
if (!res)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
if (type == 1)
return resResult(STATUS.SUCCESS, { goods: result });
return resResult(STATUS.SUCCESS);
return resResult(STATUS.SUCCESS, { goods: result });
}
//宝石卸下
@@ -594,4 +620,5 @@ export class EquipHandler {
}
return resResult(STATUS.SUCCESS, { goods: result });
}
}