合成装备
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS } from "../../../consts";
|
||||
import { addItems } from "../../../services/rewardService";
|
||||
import { addItems, handleCost } from "../../../services/rewardService";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
import { EquipModel } from "../../../db/Equip";
|
||||
import { GOOD_TYPE } from "../../../consts/consts";
|
||||
|
||||
export default function(app: Application) {
|
||||
return new EquipHandler(app);
|
||||
@@ -19,7 +23,35 @@ export class EquipHandler {
|
||||
let sid: string = session.get('sid');
|
||||
// 消耗材料
|
||||
// 获得装备
|
||||
let {gid, } = msg;
|
||||
let {gid, originalEquip} = msg;
|
||||
let targetGood = gameData.goods.get(gid);
|
||||
if(!targetGood) return resResult(STATUS.ROLE_INFO_NOT_FOUND);
|
||||
|
||||
let cost = new Array<ItemInter>();
|
||||
if(targetGood.suitId > 0) { // 套装
|
||||
cost.concat(targetGood.composeMaterial);
|
||||
let specialMaterial = targetGood.specialMaterial;
|
||||
let costCount = 0;
|
||||
let equips = await EquipModel.getEquips(roleId, originalEquip);
|
||||
for(let {id, seqId} of equips) {
|
||||
if(specialMaterial.ids.includes(id)) {
|
||||
costCount++;
|
||||
cost.push({id, seqId, count: 1, type: GOOD_TYPE.EQUIP });
|
||||
}
|
||||
}
|
||||
if(specialMaterial.count > costCount) {
|
||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
} else { // 普通装备
|
||||
cost.push({
|
||||
id: targetGood.pieceId,
|
||||
count: targetGood.pieces
|
||||
});
|
||||
}
|
||||
console.log(JSON.stringify(cost))
|
||||
let result = await handleCost(roleId, sid, cost);
|
||||
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let items = [{id: gid, count: 1}];
|
||||
let goods = await addItems(roleId, roleName, sid, items);
|
||||
|
||||
Reference in New Issue
Block a user