Files
ZYZ/game-server/app/servers/role/handler/equipHandler.ts
2020-12-17 20:07:53 +08:00

110 lines
3.3 KiB
TypeScript

import { Application, BackendSession } from "pinus";
import { resResult } from "../../../pubUtils/util";
import { STATUS } from "../../../consts";
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);
}
export class EquipHandler {
constructor(private app: Application) {
}
// TODO 合成装备
public async composeEquip(msg: { gid: number, originalEquip: number[]}, session: BackendSession) {
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
// 消耗材料
// 获得装备
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);
return resResult(STATUS.SUCCESS, { goods });
}
// TODO 装备栏强化
public async strengthen(msg: { }, session: BackendSession) {
}
// TODO 装备栏精炼
public async refine(msg: { }, session: BackendSession) {
}
// TODO 装备洗炼锁定
public async lockRandSe(msg: { }, session: BackendSession) {
}
// TODO 装备洗炼
public async reStrengthen(msg: { }, session: BackendSession) {
}
//===================================================================
//TODO 分解装备
public async decomposeEquips(msg: { }, session: BackendSession) {
}
//TODO 穿戴装备
public async wearEquips(msg: { }, session: BackendSession) {
}
//TODO 卸下装备
public async removeEquips(msg: { }, session: BackendSession) {
}
//TODO 装备打孔
public async unlockEquipHole(msg: { }, session: BackendSession) {
}
//TODO 宝石镶嵌
public async setEquipGemstone(msg: { }, session: BackendSession) {
}
//TODO 宝石合成
public async composeGemstone(msg: { }, session: BackendSession) {
}
}