133 lines
5.3 KiB
TypeScript
133 lines
5.3 KiB
TypeScript
import { ITID, CONSUME_TYPE, ITEM_TABLE, CURRENCY, CURRENCY_TYPE, HANDLE_REWARD_TYPE, ITEM_CHANGE_REASON, CURRENCY_BY_TYPE } from '../../consts';
|
|
import { ItemInter, RewardInter, } from '../../pubUtils/interface';
|
|
import { gameData } from '../../pubUtils/data';
|
|
import { errlogger } from '../../util/logger';
|
|
|
|
export function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
|
let items: { id: number, count: number }[] = []; // 可叠加道具
|
|
let jewels: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
|
|
let gold: { count: number, isPay: boolean }[] = []; // 金币
|
|
let coin: number[] = [];
|
|
let ap: number = 0;
|
|
let skins: number[] = [];
|
|
let figures: number[] = [];
|
|
|
|
for(let good of goods) {
|
|
if(good.count == 0) continue;
|
|
let dicGood = gameData.goods.get(good.id);
|
|
if(!dicGood) {
|
|
errlogger.error(`物品 ${good.id} 未配置`);
|
|
continue;
|
|
}
|
|
let dicItid = ITID.get(dicGood.itid);
|
|
if(!dicItid) {
|
|
errlogger.error(`itid ${dicGood.itid} 未配置`);
|
|
continue;
|
|
}
|
|
let { type, table, isCurrency } = dicItid;
|
|
if(table == ITEM_TABLE.JEWEL) { // 装备
|
|
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
|
|
for(let i = 0; i < good.count; i++) {
|
|
jewels.push({ id: good.id, hid: good.hid })
|
|
}
|
|
} else {
|
|
if(!!good.seqId) {
|
|
jewels.push({ seqId: good.seqId });
|
|
}
|
|
}
|
|
} else if (table == ITEM_TABLE.ITEM) { // 可叠加道具
|
|
let index = items.findIndex(cur => cur.id == good.id);
|
|
if(index > 0) {
|
|
items[index].count += good.count;
|
|
} else {
|
|
items.push({ id: good.id, count: good.count });
|
|
}
|
|
} else if (table == ITEM_TABLE.SKIN) { // 皮肤,不可重复获得,不可删
|
|
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
|
|
let index = skins.indexOf(good.id);
|
|
if (index == -1) {
|
|
skins.push(good.id);
|
|
}
|
|
}
|
|
} else if (table == ITEM_TABLE.ROLE) {
|
|
if(isCurrency) { // 3种货币
|
|
let dicCurrency = CURRENCY.get(good.id);
|
|
if(dicCurrency) {
|
|
if(dicCurrency.type == CURRENCY_TYPE.GOLD) { // 金币,区分付费和免费,默认免费
|
|
let index = gold.findIndex(cur => cur.isPay == !!good.isPay);
|
|
if(index > 0) {
|
|
gold[index].count += good.count;
|
|
} else {
|
|
gold.push({ count: good.count, isPay: !!good.isPay });
|
|
}
|
|
} else if (dicCurrency.type == CURRENCY_TYPE.COIN) { // 铜钱
|
|
coin.push(good.count);
|
|
} else if (dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 体力
|
|
ap += good.count;
|
|
}
|
|
}
|
|
} else {
|
|
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE) { // 头像等,不可重复获得,不可删
|
|
let index = figures.indexOf(good.id);
|
|
if (index == -1) {
|
|
figures.push(good.id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return { items, jewels, gold, coin, ap, skins, figures }
|
|
}
|
|
|
|
export function getGoldEventProperties(inc: number, count: number, reason: ITEM_CHANGE_REASON) {
|
|
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
|
|
let dicGoods = gameData.goods.get(id);
|
|
return { item_id: id, item_name: dicGoods.name, item_itid: dicGoods.itid, change_count: inc, change_after: count, change_reason: reason }
|
|
}
|
|
|
|
export function getCoinEventProperties(inc: number, count: number, reason: ITEM_CHANGE_REASON) {
|
|
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
|
|
let dicGoods = gameData.goods.get(id);
|
|
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) {
|
|
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 });
|
|
} else {
|
|
result[index].count += count;
|
|
}
|
|
} else {
|
|
result.push({ id, count });
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
export function transPiece(hid: number) {
|
|
let dicHero = gameData.hero.get(hid);
|
|
let count = gameData.heroTransPiece.get(dicHero.quality);
|
|
return { pieceId: dicHero.pieceId, count }
|
|
} |