道具使用:添加返回

This commit is contained in:
luying
2022-08-09 16:41:13 +08:00
parent ff5b28af7a
commit 5d9f59f4b3
3 changed files with 10 additions and 32 deletions

View File

@@ -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<number> = [], 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 }
}
//表中的奖励数据(包括礼包)转换成具体对应奖励物品的实例

View File

@@ -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;

View File

@@ -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;