装备:分解装备获得奖励合起来
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;
|
||||
|
||||
@@ -135,8 +135,8 @@ export default class Equip extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getEquips(ids: Array<number>) {
|
||||
let result: EquipType[] = await EquipModel.find({ seqId: { $in: ids } });
|
||||
public static async getEquips(roleId: string, ids: Array<number>) {
|
||||
let result: EquipType[] = await EquipModel.find({ roleId, seqId: { $in: ids } });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 } = {}) {
|
||||
|
||||
let searchObj = ServerStategyModel.getSearchObj(form);
|
||||
let searchObj = this.getSearchObj(form);
|
||||
let sort = {};
|
||||
if (sortField && sortOrder) {
|
||||
if (sortOrder == 'ascend') {
|
||||
@@ -60,7 +60,7 @@ export default class ServerStategy extends BaseModel {
|
||||
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export default class ServerStategy extends BaseModel {
|
||||
id = await CounterModel.getNewCounter(COUNTER.SERVER_STATEGY);
|
||||
}
|
||||
if(values.isDefault) {
|
||||
await ServerStategyModel.unsetDefault();
|
||||
await this.unsetDefault();
|
||||
}
|
||||
delete values.id;
|
||||
let rec: ServerStategyType = await ServerStategyModel.findOneAndUpdate({ id }, { $set: {...values, updatedBy: uid}, $setOnInsert: { createdBy: uid } },
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface RewardInter {
|
||||
}
|
||||
|
||||
export interface ItemInter {
|
||||
id?: number;
|
||||
id: number;
|
||||
count?: number;
|
||||
seqId?: number;
|
||||
type?: number;
|
||||
|
||||
Reference in New Issue
Block a user