From aba010e192805e55da232d14d53534e196d3810d Mon Sep 17 00:00:00 2001 From: mamengke01 <794347210@qq.com> Date: Wed, 23 Dec 2020 14:47:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E5=A4=87=E5=AE=9D=E7=9F=B3=E5=90=88?= =?UTF-8?q?=E6=88=90=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/servers/role/handler/equipHandler.ts | 89 ++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/game-server/app/servers/role/handler/equipHandler.ts b/game-server/app/servers/role/handler/equipHandler.ts index ebd09bd2b..2f9286407 100644 --- a/game-server/app/servers/role/handler/equipHandler.ts +++ b/game-server/app/servers/role/handler/equipHandler.ts @@ -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); + } } \ No newline at end of file