合成装备
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);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE, COUNTER, CONSUME_TYPE, getCurNameById } from './../consts/consts';
|
||||
import { GOOD_TYPE, ITID, CURRENCY, CURRENCY_TYPE, CONSUME_TYPE, getCurNameById } from './../consts/consts';
|
||||
import { EquipModel } from './../db/Equip';
|
||||
import { CounterModel } from './../db/Counter';
|
||||
import { decodeStr, resResult } from '../pubUtils/util';
|
||||
import { getGoodById } from '../pubUtils/gamedata';
|
||||
import { RoleModel } from '../db/Role';
|
||||
@@ -9,7 +8,7 @@ import { ItemModel } from '../db/Item';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { pinus } from 'pinus';
|
||||
import { addEquips, addBags, addSkins } from '../pubUtils/itemUtils';
|
||||
import { EquipInter } from '../pubUtils/interface';
|
||||
import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
const _ = require('underscore');
|
||||
|
||||
@@ -126,9 +125,8 @@ async function rewardCurrency (roleId: string, dicGood: any, data: {id:number,cn
|
||||
});
|
||||
return goods;
|
||||
}
|
||||
interface Item {id?: number, count?: number, seqId?: number, type?: number};
|
||||
interface Bag {id: number, itemName: string, count: number, type: number, hid:number};
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<Item>) {
|
||||
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
let currencysMap: any = {};
|
||||
let equips: Array<number> = [];
|
||||
let bags: Array<{id: number, count: number}> = [];
|
||||
@@ -173,7 +171,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<Item>
|
||||
return true;
|
||||
}
|
||||
|
||||
function sortConsumes(goods: Array<Item>, bags: Array<Item>, currencysMap: any, equips: Array<number>) {
|
||||
function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencysMap: any, equips: Array<number>) {
|
||||
for (let good of goods) {
|
||||
if (good.type == GOOD_TYPE.EQUIP) { // 装备
|
||||
if (!!good.seqId) {
|
||||
@@ -206,11 +204,11 @@ function sortConsumes(goods: Array<Item>, bags: Array<Item>, currencysMap: any,
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<Item>) {
|
||||
let showItems: Array<Item> = [];
|
||||
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<ItemInter>) {
|
||||
let showItems: Array<ItemInter> = [];
|
||||
let currencysMap: any = {};
|
||||
let equips: Array<EquipInter> = [];
|
||||
let bags: Array<Bag> = [];
|
||||
let bags: Array<BagInter> = [];
|
||||
let skins: Array<number> = [];
|
||||
let uids = [{uid: roleId, sid}];
|
||||
sortItems(goods, bags, skins, currencysMap, equips, showItems);
|
||||
@@ -263,7 +261,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
return showItems;
|
||||
}
|
||||
|
||||
function sortItems (goods: Array<Item>, bags: Array<Bag>, skins: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<Item>) {
|
||||
function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<ItemInter>) {
|
||||
for (let good of goods) {
|
||||
let goodInfo = gameData.goods.get(good.id);
|
||||
if (goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
|
||||
|
||||
Reference in New Issue
Block a user