This commit is contained in:
mamengke01
2020-12-24 10:06:12 +08:00
parent 50e1e98daf
commit cc1a91ed09
5 changed files with 175 additions and 89 deletions

View File

@@ -7,6 +7,7 @@ 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";
import Role from "../../../db/Role";
import { calPlayerCeAndSave } from "../../../services/playerCeService";
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../../../pubUtils/data";
@@ -525,13 +526,18 @@ export class EquipHandler {
if (good.type != CONSUME_TYPE.JEWEL)
return resResult(STATUS.WRONG_PARMS);
//检查宝石消耗是否合法TODO
consumes.concat(purchaseGoods)
let needConsumes = checkMaterialEnough(consumes, jewel, count);
if (!purchaseGoods)
purchaseGoods = [];
let needConsumes = checkMaterialEnough(consumes.concat(purchaseGoods), 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.WRONG_PARMS);
let items:Array<{id: number, count: number, ratio?:number}> = [];
for (let item of purchaseGoods) {
items.push({id: item.id, count: item.count, ratio: 1})
}
items = items.concat(needConsumes);
let {hasError} = await ItemModel.decreaseItems(roleId, items);
if (!!hasError)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
return resResult(STATUS.SUCCESS);
@@ -548,4 +554,44 @@ 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');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let goodInfo = getGoodById(jewel);
let good = ITID.get(goodInfo.itid);
let needUpdate = false;
let consumes: Array<{id: number, count: number, ratio?: number}> = [];
if (good.type != CONSUME_TYPE.JEWEL)
return resResult(STATUS.WRONG_PARMS);
let equip;
if (!!eid) {
equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes,{id});
if (index) {
equip.holes[id].jewel = jewel;
needUpdate = true;
consumes.push({id:jewel, 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);
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 });
} else {
result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
}
return resResult(STATUS.SUCCESS, { goods: result });
}
}