diff --git a/game-server/app/services/activity/giftPackageService.ts b/game-server/app/services/activity/giftPackageService.ts index 1c68cb69b..9cc654099 100644 --- a/game-server/app/services/activity/giftPackageService.ts +++ b/game-server/app/services/activity/giftPackageService.ts @@ -9,6 +9,7 @@ import { decodeArrayListStr, resResult } from '../../pubUtils/util'; import { createHeroes } from '../role/createHero'; import { GuildModel } from '../../db/Guild'; import { pushGuildInfoUpdate } from '../guildService'; +import { combineItems } from '../role/util'; @@ -22,7 +23,7 @@ import { pushGuildInfoUpdate } from '../guildService'; */ export async function useGiftPackage(roleId: string, roleName: string, sid: string, serverId: number, guildCode: string, giftID: number, selected: Array = [], giftCount: number) { console.log("bbbbbbbb", giftID, selected) - let result = { goods: [], addHeros: [] } + let result: { goods: {id: number, count: number, seqId?: number, isBag?: boolean}[], addHeros: any[]} = { goods: [], addHeros: [] } let giftPackageData = gameData.giftPackage.get(giftID); if (!giftPackageData) { return resResult(STATUS.SUCCESS, result); @@ -105,17 +106,7 @@ export async function addReward(roleId: string, roleName: string, sid: string, s addHeros = addHeros.concat(heroResult.heroes); } - let newGoods: RewardInter[] = []; - for (let item of goods) { - let index = newGoods.findIndex(obj => { return obj.id == item.id }); - if (index != -1) { - newGoods[index].count += item.count; - } else { - newGoods.push({ id: item.id, count: item.count }) - } - } - - return { goods: newGoods, addHeros } + return { goods: combineItems(goods), addHeros } } //表中的奖励数据(包括礼包)转换成具体对应奖励物品的实例 diff --git a/game-server/app/services/role/util.ts b/game-server/app/services/role/util.ts index c94fb6e3a..c84c21532 100644 --- a/game-server/app/services/role/util.ts +++ b/game-server/app/services/role/util.ts @@ -93,33 +93,20 @@ export function getCoinEventProperties(inc: number, count: number, reason: ITEM_ return { item_id: id, item_name: dicGoods.name, item_itid: dicGoods.itid, change_count: inc, change_after: count, change_reason: reason } } -export function combineItems(items: { id?: number, count?: number }[]) { - let result: { id: number, count: number }[] = []; - for(let { id, count = 1 } of items) { - let index = result.findIndex(cur => cur.id == id); - if(index == -1) { - result.push({ id, count }); - } else { - result[index].count += count; - } - } - return result; -} - -export function combineItemAndJewels(items: { id?: number, count?: number }[]) { - let result: { id: number, count: number }[] = []; - for(let { id, count = 1 } of items) { +export function combineItems(items: { id?: number, count?: number, seqId?: number, isBag?: boolean }[]) { + let result: { id: number, count: number, seqId?: number, isBag?: boolean }[] = []; + for(let { id, count = 1, seqId, isBag } of items) { let dicGoods = gameData.goods.get(id); let dicItid = ITID.get(dicGoods.itid); if(dicItid.table != 'jewel') { let index = result.findIndex(cur => cur.id == id); if(index == -1) { - result.push({ id, count }); + result.push({ id, count, seqId, isBag }); } else { result[index].count += count; } } else { - result.push({ id, count }); + result.push({ id, count, seqId, isBag }); } } return result; diff --git a/game-server/app/services/warRewardService.ts b/game-server/app/services/warRewardService.ts index 96b86ecfb..02a9829bb 100644 --- a/game-server/app/services/warRewardService.ts +++ b/game-server/app/services/warRewardService.ts @@ -12,7 +12,7 @@ import { gameData } from '../pubUtils/data'; import { DicWar } from '../pubUtils/dictionary/DicWar'; import { RewardInter } from '../pubUtils/interface'; import { getZeroPointD } from '../pubUtils/timeUtil'; -import { combineItemAndJewels } from './role/util'; +import { combineItems } from './role/util'; export class WarReward { private roleId: string; @@ -154,7 +154,7 @@ export class WarReward { let rewards = this.rewards; if(combine) { - rewards = combineItemAndJewels(rewards); + rewards = combineItems(rewards); } await addItems(this.roleId, this.roleName, this.sid, rewards, getReasonByWarType(this.warInfo.warType)); return rewards;