装备:分解装备获得奖励合起来
This commit is contained in:
@@ -3,7 +3,7 @@ import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SY
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
|
||||
import { resResult, parseGoodStr } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost, decreaseItems } from "../../../services/rewardService";
|
||||
import { addItems, handleCost, decreaseItems, combineItems } from "../../../services/rewardService";
|
||||
import { EquipModel, EquipType } from "../../../db/Equip";
|
||||
import { HeroModel, EPlace } from "../../../db/Hero";
|
||||
import Role from "../../../db/Role";
|
||||
@@ -59,7 +59,7 @@ export class EquipHandler {
|
||||
cost = cost.concat(targetGood.composeMaterial);
|
||||
let specialMaterial = targetGood.specialMaterial;
|
||||
let costCount = 0;
|
||||
let equips = await EquipModel.getEquips(originalEquip);
|
||||
let equips = await EquipModel.getEquips(roleId, originalEquip);
|
||||
for (let equip of equips) {
|
||||
let { id, seqId, holes } = equip;
|
||||
if (specialMaterial.ids.includes(id)) {
|
||||
@@ -532,7 +532,7 @@ export class EquipHandler {
|
||||
if(originalEquip.length > BAG.BAG_RESOLVE_UPLIMITED) {
|
||||
return resResult(STATUS.EQUIP_DECOMPOSE_IS_UPLIMIT);
|
||||
}
|
||||
let equips = await EquipModel.getEquips(originalEquip);
|
||||
let equips = await EquipModel.getEquips(roleId, originalEquip);
|
||||
if (equips.length < originalEquip.length)
|
||||
return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
let goods: Array<{ id: number, count: number }> = [];
|
||||
@@ -547,7 +547,9 @@ export class EquipHandler {
|
||||
|
||||
let holes = equip.holes || [];
|
||||
for (let { jewel } of holes) {
|
||||
jewels.push({ id: jewel, count: 1 });
|
||||
if(jewel) {
|
||||
jewels.push({ id: jewel, count: 1 });
|
||||
}
|
||||
}
|
||||
goods = goods.concat(goodInfo.decomposeItem);
|
||||
cost.push({ seqId: equip.seqId, id: equip.id, count: 1 });
|
||||
@@ -555,9 +557,10 @@ export class EquipHandler {
|
||||
let costResult = await handleCost(roleId, sid, cost); // 删掉装备
|
||||
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
|
||||
await addItems(roleId, roleName, sid, jewels); // 把原本镶嵌在装备上的宝石返还了
|
||||
let result = await addItems(roleId, roleName, sid, goods);
|
||||
return resResult(STATUS.SUCCESS, { goods: result });
|
||||
return resResult(STATUS.SUCCESS, { goods: combineItems(result) });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
}
|
||||
//检查装备是否存在
|
||||
if (equips.length > 0) {
|
||||
resEquips = await EquipModel.getEquips(equipSeqIds);
|
||||
resEquips = await EquipModel.getEquips(roleId, equipSeqIds);
|
||||
if (resEquips.length < equips.length)
|
||||
return false;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
for (let equip of equipInfos) {
|
||||
showItems.push({ seqId: equip.seqId, id: equip.id, count: 1, isBag: true });
|
||||
}
|
||||
for(let equip of combineEquips(mailEquips)) {
|
||||
for(let equip of combineItems(mailEquips)) {
|
||||
showItems.push({ id: equip.id, count: equip.count, isBag: false });
|
||||
}
|
||||
//装备推送
|
||||
@@ -123,7 +123,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
}
|
||||
// 发邮件的
|
||||
if(mailEquips.length > 0) {
|
||||
await sendMailByContent(MAIL_TYPE.EQUIP_OVER, roleId, { goods: combineEquips(mailEquips) });
|
||||
await sendMailByContent(MAIL_TYPE.EQUIP_OVER, roleId, { goods: combineItems(mailEquips) });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,14 +195,14 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
return showItems;
|
||||
}
|
||||
|
||||
function combineEquips(equips: { id?: number }[]) {
|
||||
export function combineItems(items: { id?: number, count?: number }[]) {
|
||||
let result: { id: number, count: number }[] = [];
|
||||
for(let { id } of equips) {
|
||||
for(let { id, count = 1 } of items) {
|
||||
let index = result.findIndex(cur => cur.id == id);
|
||||
if(index == -1) {
|
||||
result.push({ id, count: 1 });
|
||||
result.push({ id, count });
|
||||
} else {
|
||||
result[index].count ++;
|
||||
result[index].count += count;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user