宝石合成并穿戴

This commit is contained in:
mamengke01
2020-12-24 11:38:29 +08:00
parent 6a11bfb170
commit c3a1d68aae
3 changed files with 46 additions and 27 deletions
@@ -3,7 +3,7 @@ import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SY
import { ItemInter } from "../../../pubUtils/interface";
import { resResult, parseGoodStr, getRandomByLen, deepCopy, mergeSameGoods, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
import { addItems, handleCost } from "../../../services/rewardService";
import { addItems, handleCost, decreaseItems } from "../../../services/rewardService";
import { checkMaterialEnough } from "../../../services/equipService";
import { EquipModel, RandSe } from "../../../db/Equip";
import { HeroModel, EPlace } from "../../../db/Hero";
@@ -536,7 +536,7 @@ export class EquipHandler {
items.push({id: item.id, count: item.count, ratio: 1})
}
items = items.concat(needConsumes);
let {hasError} = await ItemModel.decreaseItems(roleId, items);
let hasError = await decreaseItems(roleId, sid, items);
if (!!hasError)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
@@ -554,7 +554,7 @@ export class EquipHandler {
}
return resResult(STATUS.SUCCESS);
}
//合成下一级宝石(装备镶嵌界面)
//合成下一级宝石并穿戴(装备镶嵌界面)
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');
@@ -570,28 +570,26 @@ export class EquipHandler {
if (!!eid) {
equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes,{id});
if (index) {
equip.holes[id].jewel = jewel;
if (!!equip.holes[index] && equip.holes[index].jewel == goodInfo.composeMaterial[0].id) {
equip.holes[index].jewel = jewel;
needUpdate = true;
consumes.push({id:jewel, count: 1, ratio: 1});
consumes.push({id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1});
}
}
consumes = consumes.concat(goodInfo.composeMaterial);
if (goodInfo.specialMaterial.count) {
consumes.push({id: goodInfo.specialMaterial.ids[0], count: goodInfo.specialMaterial.count})
}
let { hasError } = await ItemModel.decreaseItems(roleId, consumes);
let hasError = await decreaseItems(roleId, sid, consumes);
if (!!hasError)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let res = await handleCost(roleId, sid, consumes);
if (!res)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let result = {};
if (needUpdate) {
await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
} else {
result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
return resResult(STATUS.SUCCESS, { goods: [{id: jewel, count}] });
}
return resResult(STATUS.SUCCESS, { goods: result });
}
}
@@ -207,4 +207,13 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
}
}
}
}
export async function decreaseItems(roleId: string, sid: string, bags: Array<{id: number, count:number, ratio?: number}>) {
let uids = [{uid: roleId, sid}];
if(bags.length > 0) {
let {hasError, result} = await ItemModel.decreaseItems(roleId, bags);
if(hasError) return true;
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: result} ), uids);
}
}