物品返回格式
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, GOOD_TYPE, HERO_GROW_MAX } from "../../../consts";
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
import { resResult, parseReward, getRandomByLen, getItems } from "../../../pubUtils/util";
|
||||
import { resResult, parseReward, getRandomByLen, deepCopy } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost } from "../../../services/rewardService";
|
||||
import { EquipModel, RandSe } from "../../../db/Equip";
|
||||
import { HeroModel, EPlace } from "../../../db/Hero";
|
||||
@@ -351,11 +351,13 @@ export class EquipHandler {
|
||||
if (!hero)
|
||||
return resResult(STATUS.HERO_NOT_FIND);
|
||||
if (type == 1) {
|
||||
if (goodInfo.lvLimited > hero.lv)
|
||||
return resResult(STATUS.EQUIP_LEVEL_LIMIT);
|
||||
let { jobid } = gameData.hero.get(hid);
|
||||
let { job_class } = getHeroJob(jobid);
|
||||
let { classId } = getHeroEquipByClassId(goodInfo.itid);
|
||||
// if (_.indexOf(classId, job_class) < 0)
|
||||
// return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO);
|
||||
if (_.indexOf(classId, job_class) < 0)
|
||||
return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO);
|
||||
if (!!equip.hid)
|
||||
return resResult(STATUS.EQUIP_IS_EQUIPED);
|
||||
let index = _.findIndex(hero.ePlace, {id: ePlaceId});
|
||||
@@ -443,8 +445,8 @@ export class EquipHandler {
|
||||
}
|
||||
|
||||
//宝石合成
|
||||
public async composeJewel(msg: {jewel: number, count: number, consumes: Array<{id:number, count:number}>}, session: BackendSession) {
|
||||
let { count, consumes, jewel} = msg;
|
||||
public async composeJewel(msg: {jewel: number, count: number, consumes: Array<{id:number, count:number}>, speConsumes: Array<{id:number, count:number}>}, session: BackendSession) {
|
||||
let { count, consumes, jewel, speConsumes} = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleName: string = session.get('roleName');
|
||||
let sid: string = session.get('sid');
|
||||
@@ -452,22 +454,35 @@ export class EquipHandler {
|
||||
let {type} = ITID.get(goodInfo.itid);
|
||||
if (type != CONSUME_TYPE.JEWEL)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (!goodInfo.composeMaterial)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
//检查宝石消耗是否合法TODO
|
||||
let comJewelMap = {};
|
||||
for (let {id, count} of goodInfo.composeMaterial) {
|
||||
let ways = [deepCopy(speConsumes)];
|
||||
for (let {id, count} of consumes) {
|
||||
let jewel = getJewelById(id);
|
||||
if (!jewel) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
count = (jewel.count + (comJewelMap[jewel.good_id]||0))/count;
|
||||
let copyWays = deepCopy(ways);
|
||||
ways = [];
|
||||
count = (count + (comJewelMap[jewel.good_id]||0))/jewel.count;
|
||||
delete comJewelMap[jewel.good_id];
|
||||
let speCount = jewel.specialMaterial.count * count;
|
||||
for (let id of jewel.specialMaterial.ids) {
|
||||
for (let way of copyWays) {
|
||||
let index = _.findIndex(way, {id});
|
||||
if (index && way[index].count >= speCount) {
|
||||
way[index].count = way[index].count - speCount;
|
||||
ways.push(way);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ways.length)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
comJewelMap[jewel.nextJewelId] = count + (comJewelMap[jewel.nextJewelId]||0);
|
||||
}
|
||||
if (comJewelMap[jewel] != count || Object.keys(comJewelMap).length != 1)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let res = await handleCost(roleId, sid, consumes);
|
||||
let res = await handleCost(roleId, sid, consumes.concat(speConsumes));
|
||||
if (!res)
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
let result = await addItems(roleId, roleName, sid, [{id: jewel, count: count}]);
|
||||
|
||||
Reference in New Issue
Block a user