装备:合成地玉石

This commit is contained in:
luying
2022-02-17 15:48:37 +08:00
parent ee32f1cdee
commit 17b437a618
5 changed files with 242 additions and 659 deletions

View File

@@ -11,7 +11,7 @@ import { calPlayerCeAndSave } from "../../../services/playerCeService";
import { getGoodById, gameData, getEquipByJobClassAndEPlace, getNextEquipQuality, getEquipQualityIdByEquipIdAndPoint, getEquipStarIdByEquipId, getNextEquipStar } from "../../../pubUtils/data";
import { BAG, EQUIP } from "../../../pubUtils/dicParam";
import { ITID, QUALITY_TYPE, equipTypeToSortAttr, IT_TYPE, QUENCH_TYPE, REFINE_TYPE } from "../../../consts";
import { checkMaterialEnough, checkEquipCanPut, quenchOnce, checkQuenchMaxByQualityAndGrade, getRandSeResult, refineOnce, checkRefineReachNextLv, calEquipCe, updateEplace, updateEplaces, checkJewelCanPutOnEquip, updateStone, checkStoneCanPutOnEquip } from "../../../services/equipService";
import { checkEquipCanPut, quenchOnce, checkQuenchMaxByQualityAndGrade, getRandSeResult, refineOnce, checkRefineReachNextLv, calEquipCe, updateEplace, updateEplaces, checkJewelCanPutOnEquip, updateStone, checkStoneCanPutOnEquip } from "../../../services/equipService";
import { findIndex, isNumber, pick } from 'underscore';
import { pushEquipRefineSucMsg, pushNormalEquipMsg, pushNormalItemMsg } from "../../../services/chatService";
@@ -199,6 +199,10 @@ export class EquipHandler {
if(update.quality == curEquip.quality && update.qualityStage == curEquip.qualityStage) {
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
}
let consumes = check.getConsume();
let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_QUALITYUP);
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let isUpQuality = update.quality != curEquip.quality;
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, update);
@@ -266,6 +270,9 @@ export class EquipHandler {
if(update.star == curEquip.star && update.starStage == curEquip.starStage) {
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
}
let consumes = check.getConsume();
let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_STARUP);
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let { newEplace, updatedEplace } = updateEplace(hero.ePlace, ePlaceId, update);
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_STAR, sid, roleId, hero, { ePlace: newEplace }, [ePlaceId]);
@@ -608,7 +615,7 @@ export class EquipHandler {
for (let { id, count } of origin) {
let dicGoods = getGoodById(id);
if (!dicGoods) return resResult(STATUS.DIC_DATA_NOT_FOUND);
if (!dicGoods.decomposeItem) return resResult(STATUS.CONSUME_TYPE_ERR);
if (!dicGoods.decomposeItem || dicGoods.decomposeItem.length <= 0) return resResult(STATUS.CONSUME_TYPE_ERR);
for(let result of dicGoods.decomposeItem) {
goods.push({ id: result.id, count: result.count * count });
@@ -652,521 +659,23 @@ export class EquipHandler {
return resResult(STATUS.SUCCESS, { goods: combineItems(result) });
}
// //穿戴或卸载装备 1-穿上装备(包括替换) 2-脱下装备
// public async putOnOrOff(msg: { eid: number, hid: number, type: number }, session: BackendSession) {
// let { eid, hid, type } = msg;
// let roleId: string = session.get('roleId');
// let serverId: number = session.get('serverId');
// let sid: string = session.get('sid');
//宝石合成
public async composeStone(msg: { id: number, count: number }, session: BackendSession) {
let { id, count } = msg;
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let check = new CheckMeterial(roleId);
let isEnough = await check.composeStone(id, count);
if(!isEnough) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
// // 原武将heroA原武将穿戴着的装备a将要穿戴的装备b装备b被装备着的武将B
// let heroA = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
// if (!heroA) return resResult(STATUS.HERO_NOT_FIND);
// let oldCountA = heroA.ePlace.filter(cur => cur.equip).length;
// let oldCountB = 0;
// let equip = await EquipModel.getEquip(eid); // 装备1-equipB 2-equipA
// if(!equip) return resResult(STATUS.EQUIP_NOT_FIND);
// let argsA = calEquipSeids(heroA);
// let heroB: HeroType, equipA: EquipType, equipB: EquipType, argsB: number[] = [];
// let heroAPutNum = 0, heroBPutTNum = 0; // 1多一件 0没变化 -1少一件
// let goodInfo = getGoodById(equip.id);
// let obj = ITID.get(goodInfo.itid);
// let eplaceId = obj.type; // 位置
// if (type == 1) {
// equipB = equip; // 要穿上的装备
// if (equipB.hid == hid) return resResult(STATUS.WRONG_PARMS);
// if(!checkEquipCanPut(heroA, equipB.id)) return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO);
// let index = heroA.ePlace.findIndex(cur => cur.id == eplaceId);
// if (index == -1) return resResult(STATUS.WRONG_PARMS);
// equipA = <EquipType>heroA.ePlace[index].equip; // 要脱下的装备
// if(equipB.hid > 0) {
// heroB = await HeroModel.findByHidAndRoleWithEquip(equipB.hid, roleId);
// argsB = calEquipSeids(heroB);
// oldCountB = heroB.ePlace.filter(cur => cur.equip).length;
// }
// if(equipA) {
// if(equipB.hid > 0) {
// if(checkEquipCanPut(heroB, equipA.id)) { // A=>b & B=>a
// equipA = await EquipModel.putOnOrOff(equipA._id, equipB.hid);
// heroB = await HeroModel.addEquip(roleId, heroB.hid, eplaceId, equipA._id);
// } else { // A=>b & B=>0 & 0=>a
// equipA = await EquipModel.putOnOrOff(equipA._id, 0);
// heroB = await HeroModel.removeEquip(roleId, equipB.hid, eplaceId);
// heroBPutTNum = -1;
// }
// } else { // A=>b & 0=>a
// equipA = await EquipModel.putOnOrOff(equipA._id, 0);
// }
// } else {
// if(equipB.hid > 0) { // A=>b & B=>0
// heroB = await HeroModel.removeEquip(roleId, equipB.hid, eplaceId);
// heroBPutTNum = -1;
// }
// // A=>b
// heroAPutNum = 1;
// }
// heroA = await HeroModel.addEquip(roleId, heroA.hid, eplaceId, equipB._id);
// equipB = await EquipModel.putOnOrOff(equipB._id, heroA.hid);
// } else if (type == 2) { // A=>0 & 0=>a
// if (!equip.hid) return resResult(STATUS.EQUIP_NOT_EQUIPED);
// equipA = await EquipModel.putOnOrOff(equip._id, 0);
// heroA = await HeroModel.removeEquip(roleId, heroA.hid, eplaceId);
// heroAPutNum = -1;
// }
// if(heroA) {
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, heroA, {}, argsA);
// if(heroAPutNum != 0) {
// await checkTaskWithHero(roleId, sid, TASK_TYPE.EQUIP_BY_HERO, heroA, [heroAPutNum, oldCountA]);
// }
// }
// if(heroB) {
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, heroB, {}, argsB);
// if(heroBPutTNum != 0) await checkTaskWithHero(roleId, sid, TASK_TYPE.EQUIP_BY_HERO, heroA, [heroBPutTNum, oldCountB]);
// }
// if(heroAPutNum + heroBPutTNum != 0) {
// await checkTask(roleId, sid, TASK_TYPE.EQUIP_SUM, heroAPutNum + heroBPutTNum, true, {});
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_SUM, heroAPutNum + heroBPutTNum)
// }
// let curEquips: Array<{ seqId: number, hid: number }> = [];
// if(equipA) {
// curEquips.push(pick(equipA, ['seqId', 'hid']));
// if(equipA.hid == 0) {
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_QUALITY, equipA, [-1]); // equipA必然是脱如果hid不为0说明从一个人穿到另一个人不算任务
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equipA.quality });
// }
// }
// if(equipB) {
// curEquips.push(pick(equipB, ['seqId', 'hid']));
// if(equipB.hid != 0) {
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_QUALITY, equipB, [1]); // equipB必然是穿如果hid为0说明没有变化不算任务
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equipB.quality });
// }
// }
// if(type == 1) {
// let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(heroA)//英雄满装备且都镶嵌相同阶数的宝石
// if (isTask) {
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
// }
// }
// return resResult(STATUS.SUCCESS, { curEquips: curEquips });
// }
// // 一次性装备上
// public async putOnOnce(msg: { hid: number }, session: BackendSession) {
// let { hid } = msg;
// let roleId: string = session.get('roleId');
// const serverId = session.get('serverId');
// let sid: string = session.get('sid');
let consumes = check.getConsume();
let costResult = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.COMPOSE_STONE);
if (!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
// let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
// if (!hero) return resResult(STATUS.HERO_NOT_FIND);
// let args = calEquipSeids(hero);
let goods = await addItems(roleId, roleName, sid, [{ id, count }], ITEM_CHANGE_REASON.COMPOSE_STONE);
return resResult(STATUS.SUCCESS, goods);
}
// let dicHero = gameData.hero.get(hid);
// if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
// let dicJob = gameData.job.get(dicHero.jobid);
// let allEquips = await EquipModel.findNotWearEquips(roleId);
// let sortEquips = allEquips.map(equip => {
// let { id, quality, ePlaceId, randMain } = equip;
// let { goodsAbility, lvLimited } = gameData.goods.get(id);
// let ce = calEquipCe(goodsAbility, randMain);
// return { id, quality, ce, equip, goodsAbility, lvLimited, ePlaceId }
// });
// let { ePlace, lv } = hero;
// let oldCount = ePlace.filter(cur => cur.equip).length;
// let curEquips: Array<{ seqId: number, hid: number }> = [];
// let equips: EquipType[] = [];
// for (let curEPlace of ePlace) {
// if (!curEPlace.equip) { // 未装备
// let sortAttrId = equipTypeToSortAttr.get(curEPlace.id);
// let sortedAndSuitEquips = sortEquips.filter(equipInfos => { // 筛选可穿的
// let { id, lvLimited, ePlaceId } = equipInfos;
// return lv >= lvLimited && checkEquipCanPut(hero, id) && curEPlace.id == ePlaceId;
// });
// // console.log('sortedAndSuitEquips', JSON.stringify(sortedAndSuitEquips, null, 4))
// sortedAndSuitEquips = sortedAndSuitEquips.sort((a, b) => { // 排序按:战力 => 根据位置看个别属性 => 品质
// if (b.ce - a.ce != 0) return b.ce - a.ce;
// let abilityA = a.goodsAbility.get(sortAttrId) || 0;
// let abilityB = b.goodsAbility.get(sortAttrId) || 0;
// if (abilityA - abilityB != 0) return abilityB - abilityA;
// return b.quality - a.quality;
// });
// if (sortedAndSuitEquips.length > 0) {
// let { equip } = sortedAndSuitEquips.shift();
// hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
// equip = await EquipModel.putOnOrOff(equip._id, hero.hid);
// if (!!equip) {
// curEquips.push(pick(equip, ['seqId', 'hid']));
// equips.push(equip);
// }
// }
// }
// }
// if (curEquips.length > 0) {
// //任务
// await checkTaskWithHero(roleId, sid, TASK_TYPE.EQUIP_BY_HERO, hero, [1, oldCount]);
// await checkTask(roleId, sid, TASK_TYPE.EQUIP_SUM, curEquips.length, true, {});
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_SUM, curEquips.length);
// for(let equip of equips) {
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_QUALITY, equip, [1]); // equipA必然是脱如果hid不为0说明从一个人穿到另一个人不算任务
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equip.quality });
// }
// //英雄满装备且都镶嵌相同阶数的宝石
// let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(hero)
// if (isTask) {
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
// }
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
// }
// return resResult(STATUS.SUCCESS, { curEquips });
// }
// //装备打孔
// public async digHole(msg: { eid: number, id: number }, session: BackendSession) {
// let { eid, id } = msg;
// let roleId: string = session.get('roleId');
// let sid: string = session.get('sid');
// let equip = await EquipModel.getEquip(eid);
// let index = findIndex(equip.holes, { id });
// if (index < 0)
// return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
// if (equip.holes[index].isOpen)
// return resResult(STATUS.EQUIP_HOLE_IS_DUG);
// let consumes: Array<{ id: number, count: number }> = [];
// if (id == 1) {
// consumes = parseGoodStr(EQUIP.EQUIP_ONE_HOLE);
// } else if (id == 2) {
// consumes = parseGoodStr(EQUIP.EQUIP_TWO_HOLE);
// } else if (id == 3) {
// consumes = parseGoodStr(EQUIP.EQUIP_THREE_HOLE);
// }
// let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_DIG_HOLE);
// if (!result)
// return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// equip.holes[index].isOpen = true;
// await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
// return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
// }
// //宝石镶嵌
// public async fillHole(msg: { eid: number, id: number, jewel: number }, session: BackendSession) {
// let { eid, id, jewel } = msg;
// let roleId: string = session.get('roleId');
// const serverId = session.get('serverId');
// let sid: string = session.get('sid');
// let consumes: Array<{ id: number, count: number }> = [];
// let goods: Array<{ id: number, count: number }> = [];
// let equip = await EquipModel.getEquip(eid);
// let oldJewelCount = equip.holes.filter(cur => cur.jewel > 0).length;
// let { itid } = getGoodById(equip.id);
// let { equipJewel } = ITID.get(itid);
// let jewelInfo = getGoodById(jewel);
// if (jewelInfo.itid != equipJewel)
// return resResult(STATUS.EQUIP_NOT_MATCH_JEWEL);
// let index = findIndex(equip.holes, { id });
// if (index < 0)
// return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
// if (!equip.holes[index].isOpen)
// return resResult(STATUS.EQUIP_HOLE_IS_NOT_DUG);
// let oldJewel = equip.holes[index].jewel;
// if (!!oldJewel)
// goods.push({ id: oldJewel, count: 1 });
// consumes.push({ id: jewel, count: 1 });
// let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_FILL_HOLE);
// if (!result)
// return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// equip.holes[index].jewel = jewel;
// await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
// let roleName: string = session.get('roleName');
// if (goods.length)
// await addItems(roleId, roleName, sid, goods, ITEM_CHANGE_REASON.TAKE_OUT_JEWEL);
// if (!!equip.hid) {
// let hero = await HeroModel.findByHidAndRoleWithEquip(equip.hid, roleId);
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_ON, sid, roleId, hero, {}, [jewel, oldJewel]);
// //任务
// //英雄满装备且都镶嵌相同阶数的宝石
// let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(hero)
// if (isTask) {
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
// }
// }
// // 任务
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_JEWEL, equip, [oldJewelCount]);
// await checkTaskWithArgs(roleId, sid, TASK_TYPE.EQUIP_JEWEL_STAGE, [jewel, oldJewel]);
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_JEWEL_SUM, equip, [oldJewelCount]);
// //成长任务
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_JEWEL_SUM, 1)
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_JEWEL_STAGE, 1, { stage: jewelInfo.lvLimited })
// 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;
// let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
// let serverId: number = session.get('serverId');
// 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);
// let needConsumes = checkMaterialEnough(consumes, jewel, count);//检查是否可以合成,并返回最终需要消耗的材料
// if (!needConsumes)
// return resResult(STATUS.WRONG_PARMS);
// let res = await handleCost(roleId, sid, needConsumes, ITEM_CHANGE_REASON.JEWEL_COMPOSE);
// if (!res)
// return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// let result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }], ITEM_CHANGE_REASON.JEWEL_COMPOSE);
// if (goodInfo.lvLimited >= JEWEL_PUSH_LV) {
// pushNormalItemMsg(roleId, roleName, serverId, MSG_SOURCE.JEWEL_COMPOSE, jewel, goodInfo.name);
// }
// if (type == 1)
// return resResult(STATUS.SUCCESS, { goods: result });
// return resResult(STATUS.SUCCESS);
// }
// //宝石卸下
// public async putOffHole(msg: { eid: number, id: number }, session: BackendSession) {
// let { eid, id } = msg;
// let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
// let sid: string = session.get('sid');
// let goods: Array<{ id: number, count: number }> = [];
// let equip = await EquipModel.getEquip(eid);
// let oldJewelCount = equip.holes.filter(cur => cur.jewel > 0).length;
// let index = findIndex(equip.holes, { id });
// if (index < 0)
// return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
// let jewel = equip.holes[index].jewel;
// if (!jewel)
// return resResult(STATUS.EQUIP_NOT_FILL_HOLE);
// goods.push({ id: jewel, count: 1 });
// equip.holes[index].jewel = 0;
// await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
// await addItems(roleId, roleName, sid, goods, ITEM_CHANGE_REASON.TAKE_OUT_JEWEL);
// if (!!equip.hid) {
// let hero = await HeroModel.findByHidAndRole(equip.hid, roleId);
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_OFF, sid, roleId, hero, {}, [jewel]);
// }
// // 任务
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_JEWEL, equip, [oldJewelCount]);
// await checkTaskWithArgs(roleId, sid, TASK_TYPE.EQUIP_JEWEL_STAGE, [0, jewel]);
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_JEWEL_SUM, equip, [oldJewelCount]);
// 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');
// const serverId = session.get('serverId');
// let goodInfo = getGoodById(jewel);
// let good = ITID.get(goodInfo.itid);
// if (good.type != CONSUME_TYPE.JEWEL)
// return resResult(STATUS.WRONG_PARMS);
// if (!purchaseGoods) //需要购买才可进行合成的物品
// purchaseGoods = [];
// if (!consumes)
// consumes = [];
// let needConsumes = checkMaterialEnough(consumes.concat(purchaseGoods), jewel, count);//检查是否可以合成,并返回最终需要消耗的材料
// if (!needConsumes)
// return resResult(STATUS.WRONG_PARMS);
// let items: ItemInter[] = [];
// for (let item of purchaseGoods) {
// items.push({ id: item.id, count: item.count })//加上购买的数量
// }
// items = items.concat(needConsumes);
// let costResult = await handleCost(roleId, sid, items, ITEM_CHANGE_REASON.JEWEL_COMPOSE);//合并消耗是否足够
// if (!costResult)
// return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// await addItems(roleId, roleName, sid, [{ id: jewel, count: count }], ITEM_CHANGE_REASON.JEWEL_COMPOSE);
// if (goodInfo.lvLimited >= JEWEL_PUSH_LV) {
// pushNormalItemMsg(roleId, roleName, serverId, MSG_SOURCE.JEWEL_COMPOSE, jewel, goodInfo.name);
// }
// return resResult(STATUS.SUCCESS);
// }
// /**
// * 临时使用的购买物品,后应该在商店中购买
// * @param msg
// * @param session
// */
// 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, ITEM_CHANGE_REASON.DEBUG);
// if (!result) {
// return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// }
// return resResult(STATUS.SUCCESS);
// }
// /**
// * 合成下一级宝石并穿戴(装备镶嵌界面)
// * @param msg
// * @param session
// */
// public async composeNextLevelJewel(msg: { jewel: number, count: number, eid: number, id: number }, session: BackendSession) {
// let { count, jewel, eid, id } = msg;
// let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
// let sid: string = session.get('sid');
// let serverId = session.get('serverId');
// let goodInfo = getGoodById(jewel);
// let good = ITID.get(goodInfo.itid);
// let needUpdate = false;
// let oldJewel: number;
// let consumes: Array<{ id: number, count: number }> = [];
// if (good.type != CONSUME_TYPE.JEWEL || !eid || eid < 0)
// return resResult(STATUS.WRONG_PARMS);
// let equip = await EquipModel.getEquip(eid);
// if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
// let oldJewelCount = equip.holes.filter(cur => cur.jewel > 0).length;
// let index = findIndex(equip.holes, { id });
// //装备上该位置有穿戴该宝石,且在合成的材料中
// if (!!equip.holes[index] && equip.holes[index].jewel == goodInfo.composeMaterial[0].id) {
// oldJewel = equip.holes[index].jewel;
// equip.holes[index].jewel = jewel;//合成后的新宝石穿戴到装备上
// needUpdate = true;
// consumes.push({ id: goodInfo.composeMaterial[0].id, count: 1 });//ratio1表示可以释放掉一颗宝石
// }
// consumes = consumes.concat(goodInfo.composeMaterial);
// if (goodInfo.specialMaterial.count) {
// consumes.push({ id: goodInfo.specialMaterial.ids[0], count: goodInfo.specialMaterial.count })
// }
// let costResult = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.JEWEL_COMPOSE);//检查是消耗是否足够
// if (!costResult)
// return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// if (goodInfo.lvLimited >= JEWEL_PUSH_LV) {
// pushNormalItemMsg(roleId, roleName, serverId, MSG_SOURCE.JEWEL_COMPOSE, jewel, goodInfo.name);
// }
// let result = {};
// if (needUpdate) {
// //穿戴宝石
// equip = await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
// if (!!equip.hid) {
// let hero = await HeroModel.findByHidAndRoleWithEquip(equip.hid, roleId);
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_ON, sid, roleId, hero, {}, [jewel, oldJewel]);
// //任务
// //英雄满装备且都镶嵌相同阶数的宝石
// let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(hero)
// if (isTask) {
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
// }
// }
// // 任务
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_JEWEL, equip, [oldJewelCount]);
// await checkTaskWithArgs(roleId, sid, TASK_TYPE.EQUIP_JEWEL_STAGE, [jewel, oldJewel]);
// await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_JEWEL_SUM, equip, [oldJewelCount]);
// //成长任务
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_JEWEL_SUM, count)
// return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
// } else {
// result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }], ITEM_CHANGE_REASON.JEWEL_COMPOSE);
// return resResult(STATUS.SUCCESS, { goods: [{ id: jewel, count }] });
// }
// }
// /**
// * @description 藏宝图合成
// * @param {{target: number, original: Array<{id: number, count: number}>}} msg
// * @param {BackendSession} session
// * @returns
// * @memberof ComBattleHandler
// */
// async composeBlueprt(msg: { target: number, original: Array<{ id: number, count: number }> }, session: BackendSession) {
// const roleId = session.get('roleId');
// const roleName = session.get('roleName');
// const sid = session.get('sid');
// const serverId = session.get('serverId');
// const { target, original } = msg;
// // 原材料检查
// let originalQuality: number, originalSum: number = 0;
// for (let { id, count } of original) {
// const goodInfo = gameData.goods.get(id);
// if (!originalQuality) originalQuality = goodInfo.quality;
// if (originalQuality != goodInfo.quality) {
// return resResult(STATUS.COM_BLUEPRT_QUALITY_ERROR);
// }
// if (goodInfo.itid == IT_TYPE.BLUEPRT) {
// originalSum += count;
// }
// }
// const dicCompose = gameData.blurprtCompose.get(originalQuality);
// if (!dicCompose) {
// return resResult(STATUS.COM_BLUEPRT_QUALITY_CANNOT_COMPOSE);
// }
// if (originalSum != dicCompose.blueprtNum) {
// return resResult(STATUS.COM_BLUEPRT_COUNT_ERROR);
// }
// let dicTargetInfo = gameData.goods.get(target);
// if (!dicTargetInfo) return resResult(STATUS.WRONG_PARMS);
// if (dicTargetInfo.quality != dicCompose.targetQuality) return resResult(STATUS.COM_BLUEPRT_QUALITY_ERROR);
// // 消耗藏宝图和寻宝币
// let costResult = await handleCost(roleId, sid, [...original, ...dicCompose.coinNum], ITEM_CHANGE_REASON.BLUEPRT_COMPOSE);
// if (!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
// const reward = [{ id: target, count: 1 }];
// const goods = await addItems(roleId, roleName, sid, reward, ITEM_CHANGE_REASON.BLUEPRT_COMPOSE);
// if (dicCompose.targetQuality >= QUALITY_TYPE.ORANGE) {
// const { name } = gameData.goods.get(target);
// pushNormalItemMsg(roleId, roleName, serverId, MSG_SOURCE.ORANGE_BLUEPRT_COMPOSE, target, name);
// }
// await checkTask(roleId, sid, TASK_TYPE.COM_BATTLE_BLUEPRT, 1, true, { quality: dicCompose.targetQuality });
// await checkActivityTask(serverId, sid, roleId, TASK_TYPE.COM_BATTLE_BLUEPRT, 1, { quality: dicCompose.targetQuality })
// return resResult(STATUS.SUCCESS, { goods, costGold: 0 });
// }
}

View File

@@ -33,6 +33,7 @@ import { updateEplaces } from './equipService';
export class CheckMeterial {
private roleId: string;
private itemsIndb: Map<number, number> = new Map(); // 玩家已有的东西
private notEnoughItems: Map<number, number> = new Map(); // 缺少的数量
private consumes: ItemInter[] = []; // 消耗,正向数
private goldId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
@@ -51,18 +52,36 @@ export class CheckMeterial {
}
}
private pushToNotEnoughItems(id: number, count: number) {
if(!this.notEnoughItems.has(id)) {
this.notEnoughItems.set(id, 0);
}
this.notEnoughItems.set(id, this.notEnoughItems.get(id) + count);
}
private getNotEnoughItems() {
let map = new Map<number, number>();
for(let [ id, count ] of this.notEnoughItems) {
map.set(id, count);
}
return map;
}
public async decrease(goods: {id: number, count: number}[]) {
this.notEnoughItems.clear();
let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
let isEnough = true;
for(let { id, count} of items) {
if(!this.itemsIndb.has(id)) {
let item = await ItemModel.findbyRoleAndGidAndCount(this.roleId, id, count);
let item = await ItemModel.findbyRoleAndGid(this.roleId, id);
if(!item) {
this.pushToNotEnoughItems(id, count);
isEnough = false; break;
}
this.itemsIndb.set(id, item.count);
}
if(this.itemsIndb.get(id) < count) {
this.pushToNotEnoughItems(id, count - this.itemsIndb.get(id));
isEnough = false; break;
}
this.itemsIndb.set(id, this.itemsIndb.get(id) - count);
@@ -75,7 +94,10 @@ export class CheckMeterial {
this.itemsIndb.set(this.coinId, role.coin);
}
let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0);
if(this.itemsIndb.get(this.goldId) < goldCost) isEnough = false;
if(this.itemsIndb.get(this.goldId) < goldCost) {
this.pushToNotEnoughItems(this.goldId, goldCost - this.itemsIndb.get(this.goldId));
isEnough = false;
}
}
if(isEnough && coin.length > 0) {
if(!this.itemsIndb.has(this.coinId)) {
@@ -84,13 +106,57 @@ export class CheckMeterial {
this.itemsIndb.set(this.coinId, role.coin);
}
let coinCost = coin.reduce((pre, cur) => pre + cur, 0);
if(this.itemsIndb.get(this.coinId) < coinCost) isEnough = false;
if(this.itemsIndb.get(this.coinId) < coinCost) {
this.pushToNotEnoughItems(this.coinId, coinCost - this.itemsIndb.get(this.coinId));
isEnough = false;
}
}
if(isEnough) this.consumes.push(...goods);
return isEnough;
}
private getMaterialEnough(materials: RewardInter[], notEnoughItems: Map<number, number>) {
let newMaterials: RewardInter[] = [];
for(let {id, count} of materials) {
if(notEnoughItems.has(id)) {
newMaterials.push({ id, count: count - notEnoughItems.get(id) });
} else {
newMaterials.push({ id, count });
}
}
return newMaterials;
}
// 检查地玉石是否可以合成
public async composeStone(id: number, count: number) {
let dicStone = gameData.stone.get(id);
if(!dicStone || dicStone.composeMaterial.length <= 0) return false; // 1阶石头不能再从下合成返回不行
let materials = dicStone.composeMaterial.map(cur => ({...cur, count: cur.count * count }));
console.log('#######materials', materials)
let isEnough = await this.decrease(materials);
console.log('#####isEnough', isEnough, this.notEnoughItems)
if(!isEnough) {
let notEnoughItems = this.getNotEnoughItems();
let newMaterials = this.getMaterialEnough(materials, notEnoughItems);
console.log('#######newMaterials', newMaterials, this.notEnoughItems)
let isEnough = await this.decrease(newMaterials); // 消耗掉除了不足的部分以外的其他部分
if(!isEnough) return false;
let isAllOK = true; // 如果有石头不足向下补充isAllOK标识不足的都能补充上
for(let [id, count] of notEnoughItems) {
let isEnough = await this.composeStone(id, count);
console.log('####')
if(!isEnough) {
isAllOK = false; break;
}
}
return isAllOK;
} else {
return true;
}
}
public getConsume() {
return this.consumes;
}

View File

@@ -935,6 +935,9 @@ export enum ITEM_CHANGE_REASON {
GET_HERO_UNLOCK_SKIN = 134, // 获得武将解锁皮肤
AP_RECOVERY = 135, // 自然恢复体力
LV_UP = 136, // 升级恢复
EQUIP_QUALITYUP = 137, // 装备升品
EQUIP_STARUP = 138, // 装备升星
COMPOSE_STONE = 139, // 合成地玉石
}
export enum TA_EVENT {

View File

@@ -45,6 +45,11 @@ export default class Item extends BaseModel {
return items;
}
public static async findbyRoleAndGid(roleId: string, id: number, lean = true) {
const items: ItemType = await ItemModel.findOne({ roleId, id }).select('id count type').lean(lean);
return items;
}
public static async increaseItem(roleId: string, id: number, count: number, itemInfo: { roleId: string, roleName: string, id: number, itemName: string, type: number, hid?: number }) {
const doc = new ItemModel();
const setOnInsert = Object.assign(doc.toJSON(), itemInfo);

File diff suppressed because it is too large Load Diff