物品返回格式

This commit is contained in:
mamengke01
2020-12-21 16:05:40 +08:00
parent 10aeebc6d4
commit 86ff7e5dfd
5 changed files with 726 additions and 710 deletions
@@ -1,7 +1,7 @@
import { Application, BackendSession } from "pinus"; 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 { 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 { 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 { addItems, handleCost } from "../../../services/rewardService";
import { EquipModel, RandSe } from "../../../db/Equip"; import { EquipModel, RandSe } from "../../../db/Equip";
import { HeroModel, EPlace } from "../../../db/Hero"; import { HeroModel, EPlace } from "../../../db/Hero";
@@ -351,11 +351,13 @@ export class EquipHandler {
if (!hero) if (!hero)
return resResult(STATUS.HERO_NOT_FIND); return resResult(STATUS.HERO_NOT_FIND);
if (type == 1) { if (type == 1) {
if (goodInfo.lvLimited > hero.lv)
return resResult(STATUS.EQUIP_LEVEL_LIMIT);
let { jobid } = gameData.hero.get(hid); let { jobid } = gameData.hero.get(hid);
let { job_class } = getHeroJob(jobid); let { job_class } = getHeroJob(jobid);
let { classId } = getHeroEquipByClassId(goodInfo.itid); let { classId } = getHeroEquipByClassId(goodInfo.itid);
// if (_.indexOf(classId, job_class) < 0) if (_.indexOf(classId, job_class) < 0)
// return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO); return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO);
if (!!equip.hid) if (!!equip.hid)
return resResult(STATUS.EQUIP_IS_EQUIPED); return resResult(STATUS.EQUIP_IS_EQUIPED);
let index = _.findIndex(hero.ePlace, {id: ePlaceId}); 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) { 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} = msg; let { count, consumes, jewel, speConsumes} = msg;
let roleId: string = session.get('roleId'); let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName'); let roleName: string = session.get('roleName');
let sid: string = session.get('sid'); let sid: string = session.get('sid');
@@ -452,22 +454,35 @@ export class EquipHandler {
let {type} = ITID.get(goodInfo.itid); let {type} = ITID.get(goodInfo.itid);
if (type != CONSUME_TYPE.JEWEL) if (type != CONSUME_TYPE.JEWEL)
return resResult(STATUS.WRONG_PARMS); return resResult(STATUS.WRONG_PARMS);
if (!goodInfo.composeMaterial)
return resResult(STATUS.WRONG_PARMS);
//检查宝石消耗是否合法TODO //检查宝石消耗是否合法TODO
let comJewelMap = {}; let comJewelMap = {};
for (let {id, count} of goodInfo.composeMaterial) { let ways = [deepCopy(speConsumes)];
for (let {id, count} of consumes) {
let jewel = getJewelById(id); let jewel = getJewelById(id);
if (!jewel) { if (!jewel) {
return resResult(STATUS.WRONG_PARMS); 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]; 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); comJewelMap[jewel.nextJewelId] = count + (comJewelMap[jewel.nextJewelId]||0);
} }
if (comJewelMap[jewel] != count || Object.keys(comJewelMap).length != 1) if (comJewelMap[jewel] != count || Object.keys(comJewelMap).length != 1)
return resResult(STATUS.WRONG_PARMS); return resResult(STATUS.WRONG_PARMS);
let res = await handleCost(roleId, sid, consumes); let res = await handleCost(roleId, sid, consumes.concat(speConsumes));
if (!res) if (!res)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let result = await addItems(roleId, roleName, sid, [{id: jewel, count: count}]); let result = await addItems(roleId, roleName, sid, [{id: jewel, count: count}]);
@@ -49,7 +49,7 @@ export class HeroHandler {
if(!result) { if(!result) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
} }
return resResult(STATUS.SUCCESS,{result}); return resResult(STATUS.SUCCESS,{goods: result});
} }
+2 -1
View File
@@ -163,7 +163,8 @@ export const STATUS = {
EQUIP_HOLE_IS_NOT_DUG: {code: 30505, simStr: '装备未打过孔' }, EQUIP_HOLE_IS_NOT_DUG: {code: 30505, simStr: '装备未打过孔' },
JEWEL_IS_NOT_FIND: {code: 30506, simStr: '宝石不存在' }, JEWEL_IS_NOT_FIND: {code: 30506, simStr: '宝石不存在' },
EQUIP_NOT_FILL_HOLE: {code: 30506, simStr: '未穿戴宝石' }, EQUIP_NOT_FILL_HOLE: {code: 30506, simStr: '未穿戴宝石' },
EQUIP_NOT_EQUIPED_HERO: {code: 30502, simStr: '装备不能被该武将穿戴'}, EQUIP_NOT_EQUIPED_HERO: {code: 30507, simStr: '装备不能被该武将穿戴'},
EQUIP_LEVEL_LIMIT: {code: 30508, simStr: '装备穿戴等级限制'},
// 社交相关状态 40000 - 49999 // 社交相关状态 40000 - 49999
// 运营模块相关状态 50000 - 59999 // 运营模块相关状态 50000 - 59999
+2 -2
View File
@@ -15,7 +15,7 @@ export interface DicGoods {
// 物品名 // 物品名
readonly name: string; readonly name: string;
// 等级限制 // 等级限制
readonly lvLimted: number; readonly lvLimited: number;
// 合成装备需要的碎片数 // 合成装备需要的碎片数
readonly pieces: number; readonly pieces: number;
// 对应的碎片id // 对应的碎片id
@@ -63,7 +63,7 @@ type KeysEnum<T> = { [P in keyof Required<T>]: true };
const DicGoodsKeys: KeysEnum<DicGoods> = { const DicGoodsKeys: KeysEnum<DicGoods> = {
good_id: true, good_id: true,
name: true, name: true,
lvLimted: true, lvLimited: true,
pieces: true, pieces: true,
composeMaterial: true, composeMaterial: true,
specialMaterial: true, specialMaterial: true,
File diff suppressed because it is too large Load Diff