格式化

This commit is contained in:
mamengke01
2020-12-21 17:43:16 +08:00
parent a330ad557c
commit d1925a221a

View File

@@ -13,7 +13,7 @@ import { ITID, SPEICAL_ITEM } from "../../../consts/constModules/itemConst";
const _ = require('underscore');
export default function(app: Application) {
export default function (app: Application) {
return new EquipHandler(app);
}
@@ -24,41 +24,41 @@ export class EquipHandler {
// test接口添加任意道具
public async addItem(msg: { id: number, count: number}, session: BackendSession) {
public async addItem(msg: { id: number, count: number }, session: BackendSession) {
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let {id, count} = msg;
let goods = await addItems(roleId, roleName, sid, [{id, count}]);
let { id, count } = msg;
let goods = await addItems(roleId, roleName, sid, [{ id, count }]);
return resResult(STATUS.SUCCESS, { goods });
}
// 合成装备
public async composeEquip(msg: { gid: number, originalEquip: number[]}, session: BackendSession) {
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 { gid, originalEquip } = msg;
let targetGood = gameData.goods.get(gid);
if(!targetGood) return resResult(STATUS.ROLE_INFO_NOT_FOUND);
if (!targetGood) return resResult(STATUS.ROLE_INFO_NOT_FOUND);
let cost = new Array<ItemInter>();
if(targetGood.suitId > 0) { // 套装
if (targetGood.suitId > 0) { // 套装
cost = cost.concat(targetGood.composeMaterial);
let specialMaterial = targetGood.specialMaterial;
let costCount = 0;
let equips = await EquipModel.getEquips(originalEquip);
for(let {id, seqId} of equips) {
if(specialMaterial.ids.includes(id)) {
for (let { id, seqId } of equips) {
if (specialMaterial.ids.includes(id)) {
costCount++;
cost.push({id, seqId, count: 1 });
cost.push({ id, seqId, count: 1 });
}
}
if(specialMaterial.count > costCount) {
if (specialMaterial.count > costCount) {
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
}
@@ -69,9 +69,9 @@ export class EquipHandler {
});
}
let result = await handleCost(roleId, sid, cost);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let items = [{ id: gid, count: 1}];
let items = [{ id: gid, count: 1 }];
let goods = await addItems(roleId, roleName, sid, items);
return resResult(STATUS.SUCCESS, { goods });
}
@@ -82,48 +82,48 @@ export class EquipHandler {
// let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let {hid, ePlaceId, type} = msg;
let { hid, ePlaceId, type } = msg;
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
let { ePlace, lv: playerLv } = hero; // 装备栏
let strengthenArr = new Array<EPlace>();
if(type == EQUIP_STRENGTHEN_TYPE.SINGLE || type == EQUIP_STRENGTHEN_TYPE.SINGLE_QUICK) { // 单装备强化
if (type == EQUIP_STRENGTHEN_TYPE.SINGLE || type == EQUIP_STRENGTHEN_TYPE.SINGLE_QUICK) { // 单装备强化
strengthenArr = ePlace.filter(cur => cur.id == ePlaceId && cur.equip);
} else if (type == EQUIP_STRENGTHEN_TYPE.ALL_QUICK) { // 全六件(装备中)的强化
strengthenArr = ePlace.filter(cur => cur.equip);
}
if(strengthenArr.length <= 0) {
if (strengthenArr.length <= 0) {
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
}
let minLv = strengthenArr[0].lv; // 从最低装备的等级开始
for(let {lv} of strengthenArr) {
if(lv < minLv) minLv = lv;
for (let { lv } of strengthenArr) {
if (lv < minLv) minLv = lv;
}
let {coin} = await Role.findByRoleId(roleId);
let maxLv = type == EQUIP_STRENGTHEN_TYPE.SINGLE?minLv + 1:playerLv;
if(maxLv > playerLv) maxLv = playerLv;
if(minLv >= maxLv) {
let { coin } = await Role.findByRoleId(roleId);
let maxLv = type == EQUIP_STRENGTHEN_TYPE.SINGLE ? minLv + 1 : playerLv;
if (maxLv > playerLv) maxLv = playerLv;
if (minLv >= maxLv) {
return resResult(STATUS.ROLE_EQUIP_REACH_MAX);
}
let costCoin = 0; // 消耗铜币
let flag = false; // 铜币不足
for(let i = minLv; i < maxLv; i++) {
for(let s of strengthenArr) {
if(s.lv == i) {
for (let i = minLv; i < maxLv; i++) {
for (let s of strengthenArr) {
if (s.lv == i) {
let cost = gameData.strengthenCost.get(i + 1);
if(!cost) {flag = true; break;}
if(coin < costCoin + cost) { flag = true; break;}
if (!cost) { flag = true; break; }
if (coin < costCoin + cost) { flag = true; break; }
costCoin += cost;
s.lv++;
}
}
if(flag) break;
if (flag) break;
}
if(costCoin <= 0) { // 连一级都不够升
if (costCoin <= 0) { // 连一级都不够升
return resResult(STATUS.ROLE_COIN_NOT_ENOUGH);
}
@@ -131,59 +131,59 @@ export class EquipHandler {
id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN),
count: costCoin
}]);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
hero.ePlace = ePlace;
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP);
const curHero = {
const curHero = {
hid,
ePlace: strengthenArr
}
return resResult(STATUS.SUCCESS, {curHero});
return resResult(STATUS.SUCCESS, { curHero });
}
// 装备栏精炼
public async refine(msg: { hid: number, ePlaceId: number, material: {id: number, count: number}[] }, session: BackendSession) {
public async refine(msg: { hid: number, ePlaceId: number, material: { id: number, count: number }[] }, session: BackendSession) {
let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let {hid, ePlaceId, material} = msg;
let { hid, ePlaceId, material } = msg;
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
let { ePlace } = hero; // 装备栏
let curEplace = ePlace.find(cur => cur.id == ePlaceId);
if(!curEplace) {
if (!curEplace) {
return resResult(STATUS.ROLE_EQUIP_PLACE_NOT_ENOUGH);
}
let {lv, refineLv } = curEplace; // 强化等级,精炼等级,精炼次数
let { lv, refineLv } = curEplace; // 强化等级,精炼等级,精炼次数
if(lv < HERO_GROW_MAX.EQUIP_STRENGTHEN) {
if (lv < HERO_GROW_MAX.EQUIP_STRENGTHEN) {
return resResult(STATUS.ROLE_EQUIP_NOT_REACH_MAX);
}
if(refineLv >= HERO_GROW_MAX.EQUIP_REFINE) {
if (refineLv >= HERO_GROW_MAX.EQUIP_REFINE) {
return resResult(STATUS.ROLE_EQUIP_REACH_MAX);
}
// 是否成功精炼
let dicRefine = gameData.refine.get(refineLv + 1);
if(!dicRefine) {
if (!dicRefine) {
return resResult(STATUS.ROLE_INFO_NOT_FOUND)
}
let {successRate} = dicRefine;
for(let {id, count} of material) {
let { successRate } = dicRefine;
for (let { id, count } of material) {
let dicGoods = gameData.goods.get(id);
if(!dicGoods) return resResult(STATUS.ROLE_INFO_NOT_FOUND);
if(!SPEICAL_ITEM.REFINE_ADD_RATE.includes(id)) {
if (!dicGoods) return resResult(STATUS.ROLE_INFO_NOT_FOUND);
if (!SPEICAL_ITEM.REFINE_ADD_RATE.includes(id)) {
return resResult(STATUS.ROLE_WRONG_ITEM)
}
successRate += count * dicGoods.value;
if(isNaN(successRate)) console.error(id, count, dicGoods.value);
if (isNaN(successRate)) console.error(id, count, dicGoods.value);
}
let ran = Math.floor(Math.random() * 100);
@@ -191,14 +191,14 @@ export class EquipHandler {
// 消耗道具提升成功率 每个道具提升10%成功率
// 精炼
if(isSuccess) {
if (isSuccess) {
curEplace.refineLv++;
}
// 消耗
let cost = dicRefine.material.concat(material);
let result = await handleCost(roleId, sid, cost);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP);
@@ -206,7 +206,7 @@ export class EquipHandler {
hid,
ePlace: curEplace
}
return resResult(STATUS.SUCCESS, { isSuccess, curHero});
return resResult(STATUS.SUCCESS, { isSuccess, curHero });
}
// 装备洗炼锁定
@@ -215,18 +215,18 @@ export class EquipHandler {
// let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let {eid, id, lock} = msg;
let { eid, id, lock } = msg;
let equip = await EquipModel.findbySeqId(eid);
if(!equip) return resResult(STATUS.EQUIP_NOT_FIND);
if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
let {randSe} = equip;
if(!randSe || randSe.length <=0 ) {
let { randSe } = equip;
if (!randSe || randSe.length <= 0) {
return resResult(STATUS.EQUIP_HAVE_NO_RANDSE);
}
if(lock) { // 仅在上锁时消耗,根据已有的锁的数量判断消耗
if (lock) { // 仅在上锁时消耗,根据已有的锁的数量判断消耗
let lockNum = randSe.filter(cur => cur.locked).length;
let consumes:Array<{id: number, count: number}> = [];
let consumes: Array<{ id: number, count: number }> = [];
if (lockNum == 0) {
consumes = parseReward(EQUIP.EQUIP_ONE_LOCKED);
} else if (lockNum == 1) {
@@ -237,14 +237,14 @@ export class EquipHandler {
return resResult(STATUS.ROLE_ALL_SE_LOCK);
}
let result = await handleCost(roleId, sid, consumes);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
}
let result = await EquipModel.lock(roleId, eid, id, lock);
if(!result) {
if (!result) {
return resResult(STATUS.EQUIP_HAVE_NO_RANDSE);
}
return resResult(STATUS.SUCCESS, {curEquip: result});
return resResult(STATUS.SUCCESS, { curEquip: result });
}
@@ -254,42 +254,42 @@ export class EquipHandler {
// let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let {eid } = msg;
let { eid } = msg;
let equip = await EquipModel.findbySeqId(eid);
if(!equip) return resResult(STATUS.EQUIP_NOT_FIND);
if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
let {id, randSe } = equip;
if(!randSe || randSe.length <=0 ) {
let { id, randSe } = equip;
if (!randSe || randSe.length <= 0) {
return resResult(STATUS.EQUIP_HAVE_NO_RANDSE);
}
let dicGoods = gameData.goods.get(id);
if(!dicGoods) return resResult(STATUS.ROLE_INFO_NOT_FOUND);
let {randomEffect} = dicGoods;
let dicGoods = gameData.goods.get(id);
if (!dicGoods) return resResult(STATUS.ROLE_INFO_NOT_FOUND);
let { randomEffect } = dicGoods;
let pool = randomEffect.map(cur => gameData.randomEffectPool.get(cur));
let chosen = randSe.map(cur => cur.seid); // 上一轮和这一轮随机出来的
let hasReset = false, lockNum = 0;
for(let i = 0; i < randSe.length; i++) {
if(!randSe[i].locked) {
for (let i = 0; i < randSe.length; i++) {
if (!randSe[i].locked) {
let newPool = pool.filter(cur => !chosen.includes(cur.id));
let random = getRandomByLen(newPool);
if(!random) {break};
if (!random) { break };
let rand = 0;
if(random.id > 0) rand = Math.floor(Math.random() * (random.Max - random.Min) + random.Min);
if (random.id > 0) rand = Math.floor(Math.random() * (random.Max - random.Min) + random.Min);
randSe[i].seid = random.id;
randSe[i].rand = rand;
hasReset = true;
} else {
lockNum ++;
lockNum++;
}
}
if(!hasReset) {
if (!hasReset) {
return resResult(STATUS.ROLE_EQUIP_CANNOT_RESTRENGTHEN);
}
// 消耗
let consumes:Array<{id: number, count: number}> = [];
let consumes: Array<{ id: number, count: number }> = [];
if (lockNum == 0) {
consumes = parseReward(EQUIP.EQUIP_ONE_REFORGED);
} else if (lockNum == 1) {
@@ -299,9 +299,9 @@ export class EquipHandler {
} else {
consumes = parseReward(EQUIP.EQUIP_FOUR_REFORGED);
}
let result = await handleCost(roleId, sid, consumes);
if(!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let equipResult = await EquipModel.updateEquipInfo(eid, { randSe })
let curEquip = {
@@ -309,7 +309,7 @@ export class EquipHandler {
id: equipResult.id,
randSe: equipResult.randSe
}
return resResult(STATUS.SUCCESS,{curEquip});
return resResult(STATUS.SUCCESS, { curEquip });
}
@@ -322,92 +322,92 @@ export class EquipHandler {
let equips = await EquipModel.getEquips(originalEquip);
if (equips.length < originalEquip.length)
return resResult(STATUS.EQUIP_NOT_FIND);
let goods:Array<{id:number, count:number}> = [];
let goods: Array<{ id: number, count: number }> = [];
for (let equip of equips) {
if (!!equip.hid)
if (!!equip.hid)
return resResult(STATUS.EQUIP_IS_EQUIPED_NOT_DECOMPOSE);
let goodInfo = getGoodById(equip.id);
if (!goodInfo)
if (!goodInfo)
return resResult(STATUS.EQUIP_NOT_FIND);
goods.concat(goodInfo.decomposeItem);
}
let uids = [{uid: roleId, sid}];
let uids = [{ uid: roleId, sid }];
await EquipModel.deleteEquips(originalEquip);
this.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, [originalEquip]), uids);
let result = await addItems(roleId, roleName, sid, goods);
return resResult(STATUS.SUCCESS,{goods:result});
let result = await addItems(roleId, roleName, sid, goods);
return resResult(STATUS.SUCCESS, { goods: result });
}
//穿戴或卸载装备 1-穿上装备(包括替换) 2-脱下装备
public async putOnOrOff(msg: {eid: number, hid: number, type: number}, session: BackendSession) {
public async putOnOrOff(msg: { eid: number, hid: number, type: number }, session: BackendSession) {
let { eid, hid, type } = msg;
let roleId: string = session.get('roleId');
let equip = await EquipModel.getEquip(eid);
let goodInfo = getGoodById(equip.id);
let obj = ITID.get(goodInfo.itid);
let ePlaceId = obj.type;
let curEquips:Array<{seqId: number, hid: number, ePlaceId: number }> = [];
let curEquips: Array<{ seqId: number, hid: number, ePlaceId: number }> = [];
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
if (type == 1) {
if (goodInfo.lvLimited > hero.lv)
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)
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});
if (!!equip.hid)
return resResult(STATUS.EQUIP_IS_EQUIPED);
let index = _.findIndex(hero.ePlace, { id: ePlaceId });
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let objectId = <string>hero.ePlace[index].equip;
if (!!objectId) {
let lastEquip = await EquipModel.updateEquipInfobyObjectId(objectId, {hid:0, ePlaceId: 0});
let lastEquip = await EquipModel.updateEquipInfobyObjectId(objectId, { hid: 0, ePlaceId: 0 });
curEquips.push({
seqId: lastEquip.seqId,
hid: lastEquip.hid,
ePlaceId: lastEquip.ePlaceId
seqId: lastEquip.seqId,
hid: lastEquip.hid,
ePlaceId: lastEquip.ePlaceId
});
}
await HeroModel.addEquip(roleId, hid, ePlaceId, equip._id);
await HeroModel.addEquip(roleId, hid, ePlaceId, equip._id);
curEquips.push({
seqId: eid,
hid: hid,
ePlaceId: ePlaceId
});
seqId: eid,
hid: hid,
ePlaceId: ePlaceId
});
} else if (type == 2) {
if (!equip.hid)
if (!equip.hid)
return resResult(STATUS.EQUIP_NOT_EQUIPED);
let index = _.findIndex(hero.ePlace, {id: ePlaceId});
let index = _.findIndex(hero.ePlace, { id: ePlaceId });
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
return resResult(STATUS.WRONG_PARMS);
hero.ePlace[index].equip = null;
await HeroModel.updateHeroInfo(roleId, hid, {ePlace:hero.ePlace});
equip = await EquipModel.updateEquipInfo(eid, {hid:0, ePlaceId: 0});
await HeroModel.updateHeroInfo(roleId, hid, { ePlace: hero.ePlace });
equip = await EquipModel.updateEquipInfo(eid, { hid: 0, ePlaceId: 0 });
curEquips.push({
seqId: equip.seqId,
hid: equip.hid,
ePlaceId: equip.ePlaceId
seqId: equip.seqId,
hid: equip.hid,
ePlaceId: equip.ePlaceId
});
}
return resResult(STATUS.SUCCESS,{curEquips:curEquips});
return resResult(STATUS.SUCCESS, { curEquips: curEquips });
}
//装备打孔
public async digHole(msg: {eid: number, id: number}, session: BackendSession) {
public async digHole(msg: { eid: number, id: number }, session: BackendSession) {
let { eid, id } = msg;
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes, {id});
let index = _.findIndex(equip.holes, { id });
if (index < 0)
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
if (equip.holes[index].isOpen)
return resResult(STATUS.EQUIP_HOLE_IS_DUG);
let consumes:Array<{id: number, count: number}> = [];
let consumes: Array<{ id: number, count: number }> = [];
if (id == 1) {
consumes = parseReward(EQUIP.EQUIP_ONE_HOLE);
} else if (id == 2) {
@@ -418,52 +418,52 @@ export class EquipHandler {
let result = await handleCost(roleId, sid, consumes);
if (!result)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
equip.holes[index].isOpen = true;
await EquipModel.updateEquipInfo(eid, {holes: equip.holes});
return resResult(STATUS.SUCCESS,{curEquip:{seqId: eid, holes: equip.holes}});
equip.holes[index].isOpen = true;
await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
}
//宝石镶嵌
public async fillHole(msg: {eid: number, id: number, jewel: number}, session: BackendSession) {
let { eid, id, jewel} = msg;
public async fillHole(msg: { eid: number, id: number, jewel: number }, session: BackendSession) {
let { eid, id, jewel } = msg;
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let consumes:Array<{id: number, count: number}> = [];
let consumes: Array<{ id: number, count: number }> = [];
let equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes, {id});
let index = _.findIndex(equip.holes, { id });
if (index > 0)
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
if (!equip.holes[index].isOpen)
return resResult(STATUS.EQUIP_HOLE_IS_NOT_DUG);
consumes.push({id: jewel, count: 1});
consumes.push({ id: jewel, count: 1 });
let result = await handleCost(roleId, sid, consumes);
if (!result)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
equip.holes[index].jewel = jewel;
await EquipModel.updateEquipInfo(eid, {holes: equip.holes});
return resResult(STATUS.SUCCESS,{curEquip:{seqId: eid, holes: equip.holes}});
await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
}
//宝石合成
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;
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');
let goodInfo = getGoodById(jewel);
let {type} = ITID.get(goodInfo.itid);
let { type } = ITID.get(goodInfo.itid);
if (type != CONSUME_TYPE.JEWEL)
return resResult(STATUS.WRONG_PARMS);
//检查宝石消耗是否合法TODO
let comJewelMap = {};
let ways = [deepCopy(speConsumes)];
for (let {id, count} of consumes) {
for (let { id, count } of consumes) {
let jewelInfo = getJewelById(id);
if (!jewelInfo) {
return resResult(STATUS.WRONG_PARMS);
}
count = Math.floor((count + (comJewelMap[jewelInfo.good_id]||0))/jewelInfo.count);
}
count = Math.floor((count + (comJewelMap[jewelInfo.good_id] || 0)) / jewelInfo.count);
if (count < 1) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
@@ -473,45 +473,45 @@ export class EquipHandler {
ways = [];
for (let id of jewelInfo.specialMaterial.ids) {
for (let way of copyWays) {
let index = _.findIndex(way, {id});
let index = _.findIndex(way, { id });
if (index && way[index].count >= speCount) {
way[index].count = way[index].count - speCount;
ways.push(way);
}
}
}
if (!ways.length)
if (!ways.length)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
delete comJewelMap[jewelInfo.good_id];
comJewelMap[jewelInfo.nextJewelId] = count + (comJewelMap[jewelInfo.nextJewelId]||0);
comJewelMap[jewelInfo.nextJewelId] = count + (comJewelMap[jewelInfo.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);
let res = await handleCost(roleId, sid, consumes.concat(speConsumes));
if (!res)
if (!res)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let result = await addItems(roleId, roleName, sid, [{id: jewel, count: count}]);
return resResult(STATUS.SUCCESS,{goods:result});
let result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);
return resResult(STATUS.SUCCESS, { goods: result });
}
//宝石卸下
public async putOffHole(msg: {eid: number, id: number}, session: BackendSession) {
let { eid, id} = msg;
public async putOffHole(msg: { eid: number, id: number }, session: BackendSession) {
let { eid, id } = msg;
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let goods:Array<{id: number, count: number}> = [];
let goods: Array<{ id: number, count: number }> = [];
let equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes, {id});
let index = _.findIndex(equip.holes, { id });
if (index > 0)
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
if (!equip.holes[index].jewel)
return resResult(STATUS.EQUIP_NOT_FILL_HOLE);
goods.push({id: equip.holes[index].jewel, count: 1});
goods.push({ id: equip.holes[index].jewel, count: 1 });
equip.holes[index].jewel = 0;
await EquipModel.updateEquipInfo(eid, {holes: equip.holes});
await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
await addItems(roleId, roleName, sid, goods);
return resResult(STATUS.SUCCESS,{curEquip:{seqId: eid, holes: equip.holes}});
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
}
}