装备宝石合成接口调整

This commit is contained in:
mamengke01
2020-12-23 14:47:29 +08:00
parent 9746f53570
commit aba010e192

View File

@@ -1,8 +1,10 @@
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, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
import { resResult, parseGoodStr, getRandomByLen, deepCopy, mergeSameGoods, 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 Role from "../../../db/Role";
@@ -464,55 +466,27 @@ export class EquipHandler {
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
}
//宝石合成
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;
//宝石合成(一键放入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;
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let goodInfo = getGoodById(jewel);
let { type } = ITID.get(goodInfo.itid);
if (type != CONSUME_TYPE.JEWEL)
let good = ITID.get(goodInfo.itid);
if (good.type != CONSUME_TYPE.JEWEL)
return resResult(STATUS.WRONG_PARMS);
//检查宝石消耗是否合法TODO
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)
let needConsumes = checkMaterialEnough(consumes, jewel, count);
if (!needConsumes)
return resResult(STATUS.WRONG_PARMS);
let res = await handleCost(roleId, sid, consumes.concat(speConsumes));
let res = await handleCost(roleId, sid, needConsumes);
if (!res)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
return resResult(STATUS.SUCCESS, { goods: result });
if (type == 1)
return resResult(STATUS.SUCCESS, { goods: result });
return resResult(STATUS.SUCCESS);
}
//宝石卸下
@@ -539,4 +513,39 @@ export class EquipHandler {
}
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
}
//宝石购买并合成
public async composeAndPurchaseJewel(msg: { jewel: number, count: number, consumes: Array<{ id: number, count: number }>, purchaseGoods: Array<{ id: number, count: number }>}, session: BackendSession) {
let { count, consumes, jewel, purchaseGoods } = 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)
return resResult(STATUS.WRONG_PARMS);
//检查宝石消耗是否合法TODO
consumes.concat(purchaseGoods)
let needConsumes = checkMaterialEnough(consumes, jewel, count);
if (!needConsumes)
return resResult(STATUS.WRONG_PARMS);
await addItems(roleId, roleName, sid, purchaseGoods);
let res = await handleCost(roleId, sid, needConsumes);
if (!res)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
return resResult(STATUS.SUCCESS);
}
public async purchaseGoods(msg: { purchaseGoods: Array<{ id: number, count: number }>}, session: BackendSession) {
let { purchaseGoods } = msg;
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let result = await addItems(roleId, roleName, sid, purchaseGoods );
if(!result) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
return resResult(STATUS.SUCCESS);
}
}