装备:分解装备获得奖励合起来

This commit is contained in:
luying
2021-08-09 16:12:47 +08:00
parent e045c304ac
commit fbe9e08aa1
5 changed files with 21 additions and 18 deletions
@@ -3,7 +3,7 @@ import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SY
import { ItemInter } from "../../../pubUtils/interface"; import { ItemInter } from "../../../pubUtils/interface";
import { resResult, parseGoodStr } from "../../../pubUtils/util"; 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 { EquipModel, EquipType } from "../../../db/Equip";
import { HeroModel, EPlace } from "../../../db/Hero"; import { HeroModel, EPlace } from "../../../db/Hero";
import Role from "../../../db/Role"; import Role from "../../../db/Role";
@@ -59,7 +59,7 @@ export class EquipHandler {
cost = cost.concat(targetGood.composeMaterial); cost = cost.concat(targetGood.composeMaterial);
let specialMaterial = targetGood.specialMaterial; let specialMaterial = targetGood.specialMaterial;
let costCount = 0; let costCount = 0;
let equips = await EquipModel.getEquips(originalEquip); let equips = await EquipModel.getEquips(roleId, originalEquip);
for (let equip of equips) { for (let equip of equips) {
let { id, seqId, holes } = equip; let { id, seqId, holes } = equip;
if (specialMaterial.ids.includes(id)) { if (specialMaterial.ids.includes(id)) {
@@ -532,7 +532,7 @@ export class EquipHandler {
if(originalEquip.length > BAG.BAG_RESOLVE_UPLIMITED) { if(originalEquip.length > BAG.BAG_RESOLVE_UPLIMITED) {
return resResult(STATUS.EQUIP_DECOMPOSE_IS_UPLIMIT); 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) if (equips.length < originalEquip.length)
return resResult(STATUS.EQUIP_NOT_FIND); return resResult(STATUS.EQUIP_NOT_FIND);
let goods: Array<{ id: number, count: number }> = []; let goods: Array<{ id: number, count: number }> = [];
@@ -547,7 +547,9 @@ export class EquipHandler {
let holes = equip.holes || []; let holes = equip.holes || [];
for (let { jewel } of 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); goods = goods.concat(goodInfo.decomposeItem);
cost.push({ seqId: equip.seqId, id: equip.id, count: 1 }); cost.push({ seqId: equip.seqId, id: equip.id, count: 1 });
@@ -555,9 +557,10 @@ export class EquipHandler {
let costResult = await handleCost(roleId, sid, cost); // 删掉装备 let costResult = await handleCost(roleId, sid, cost); // 删掉装备
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
await addItems(roleId, roleName, sid, jewels); // 把原本镶嵌在装备上的宝石返还了 await addItems(roleId, roleName, sid, jewels); // 把原本镶嵌在装备上的宝石返还了
let result = await addItems(roleId, roleName, sid, goods); let result = await addItems(roleId, roleName, sid, goods);
return resResult(STATUS.SUCCESS, { goods: result }); return resResult(STATUS.SUCCESS, { goods: combineItems(result) });
} }
+7 -7
View File
@@ -38,7 +38,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
} }
//检查装备是否存在 //检查装备是否存在
if (equips.length > 0) { if (equips.length > 0) {
resEquips = await EquipModel.getEquips(equipSeqIds); resEquips = await EquipModel.getEquips(roleId, equipSeqIds);
if (resEquips.length < equips.length) if (resEquips.length < equips.length)
return false; return false;
} }
@@ -109,7 +109,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
for (let equip of equipInfos) { for (let equip of equipInfos) {
showItems.push({ seqId: equip.seqId, id: equip.id, count: 1, isBag: true }); 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 }); 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) { 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; return showItems;
} }
function combineEquips(equips: { id?: number }[]) { export function combineItems(items: { id?: number, count?: number }[]) {
let result: { 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); let index = result.findIndex(cur => cur.id == id);
if(index == -1) { if(index == -1) {
result.push({ id, count: 1 }); result.push({ id, count });
} else { } else {
result[index].count ++; result[index].count += count;
} }
} }
return result; return result;
+2 -2
View File
@@ -135,8 +135,8 @@ export default class Equip extends BaseModel {
return result; return result;
} }
public static async getEquips(ids: Array<number>) { public static async getEquips(roleId: string, ids: Array<number>) {
let result: EquipType[] = await EquipModel.find({ seqId: { $in: ids } }); let result: EquipType[] = await EquipModel.find({ roleId, seqId: { $in: ids } });
return result; return result;
} }
+3 -3
View File
@@ -44,7 +44,7 @@ export default class ServerStategy extends BaseModel {
public static async findByCondition(page: number, pageSize: number, sortField: string, sortOrder: string, form: { id?: number, name?: string, isDefault?: boolean } = {}) { public static async findByCondition(page: number, pageSize: number, sortField: string, sortOrder: string, form: { id?: number, name?: string, isDefault?: boolean } = {}) {
let searchObj = ServerStategyModel.getSearchObj(form); let searchObj = this.getSearchObj(form);
let sort = {}; let sort = {};
if (sortField && sortOrder) { if (sortField && sortOrder) {
if (sortOrder == 'ascend') { if (sortOrder == 'ascend') {
@@ -60,7 +60,7 @@ export default class ServerStategy extends BaseModel {
public static async countByCondition(form: { id?: number, name?: string, isDefault?: boolean } = {}) { public static async countByCondition(form: { id?: number, name?: string, isDefault?: boolean } = {}) {
let searchObj = ServerStategyModel.getSearchObj(form); let searchObj = this.getSearchObj(form);
const result = await ServerStategyModel.count(searchObj); const result = await ServerStategyModel.count(searchObj);
return result; return result;
} }
@@ -76,7 +76,7 @@ export default class ServerStategy extends BaseModel {
id = await CounterModel.getNewCounter(COUNTER.SERVER_STATEGY); id = await CounterModel.getNewCounter(COUNTER.SERVER_STATEGY);
} }
if(values.isDefault) { if(values.isDefault) {
await ServerStategyModel.unsetDefault(); await this.unsetDefault();
} }
delete values.id; delete values.id;
let rec: ServerStategyType = await ServerStategyModel.findOneAndUpdate({ id }, { $set: {...values, updatedBy: uid}, $setOnInsert: { createdBy: uid } }, let rec: ServerStategyType = await ServerStategyModel.findOneAndUpdate({ id }, { $set: {...values, updatedBy: uid}, $setOnInsert: { createdBy: uid } },
+1 -1
View File
@@ -8,7 +8,7 @@ export interface RewardInter {
} }
export interface ItemInter { export interface ItemInter {
id?: number; id: number;
count?: number; count?: number;
seqId?: number; seqId?: number;
type?: number; type?: number;