数数:消耗来源
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ITID, CONSUME_TYPE, ITEM_TABLE, REDIS_KEY, TASK_TYPE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD_TYPE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE } from './../consts';
|
||||
import { ITID, CONSUME_TYPE, ITEM_TABLE, REDIS_KEY, TASK_TYPE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD_TYPE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE, ITEM_CHANGE_REASON } from './../consts';
|
||||
import { EquipModel, EquipType } from './../db/Equip';
|
||||
import { getRandSingleEelm, resResult } from '../pubUtils/util';
|
||||
import { RoleModel, RoleType } from '../db/Role';
|
||||
@@ -93,7 +93,7 @@ export class CheckMeterial {
|
||||
}
|
||||
|
||||
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>, reason: ITEM_CHANGE_REASON) {
|
||||
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
let { items, equips, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
|
||||
@@ -118,7 +118,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
if (items.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, items);
|
||||
if (hasError) return false;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result }), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result.map(cur => ({...cur, reason })) }), uids);
|
||||
}
|
||||
|
||||
//删除装备
|
||||
@@ -144,8 +144,8 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
}
|
||||
|
||||
|
||||
await EquipModel.deleteEquips(roleId, equipSeqIds);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips: equipSeqIds }), uids);
|
||||
let equips = await EquipModel.deleteEquips(roleId, equipSeqIds);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips: equips.map(equip => ({ seqId: equip.seqId, id: equip.id, inc: -1, reason })) }), uids);
|
||||
}
|
||||
|
||||
//消耗玩家货币
|
||||
@@ -161,7 +161,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
}
|
||||
|
||||
// TODO: sid 在方法内部获取,且不一定存在
|
||||
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<ItemInter>) {
|
||||
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<ItemInter>, reason: ITEM_CHANGE_REASON) {
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
let { items, equips, gold, coin, ap, skins, figures } = sortItems(goods, HANDLE_REWARD_TYPE.RECEIVE);
|
||||
let showItems: { id: number, seqId?: number, count: number, isBag?: boolean }[] = [];
|
||||
@@ -178,7 +178,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
}
|
||||
|
||||
// 直接加的
|
||||
let { equips: equipInfos, pushMessages } = await addEquips(roleId, roleName, <{id: number, hid?: number}[]>incEquips);
|
||||
let { equips: equipInfos, pushMessages } = await addEquips(roleId, roleName, <{id: number, hid?: number}[]>incEquips, reason);
|
||||
for (let equip of equipInfos) {
|
||||
showItems.push({ seqId: equip.seqId, id: equip.id, count: 1, isBag: true });
|
||||
}
|
||||
@@ -202,7 +202,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
|
||||
// 2. 道具处理
|
||||
if(items.length > 0) {
|
||||
let { items: itemInfos } = await addBags(roleId, roleName, items);
|
||||
let { items: itemInfos } = await addBags(roleId, roleName, items, reason);
|
||||
for (let item of items) {
|
||||
showItems.push({ id: item.id, count: item.count });
|
||||
}
|
||||
@@ -239,7 +239,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = []; // 头像变化推送信息
|
||||
if(skins.length > 0) {
|
||||
let heroskins: {skins: HeroSkin[], hid: number}[] = []; // 皮肤推送信息
|
||||
let skinInfos: {id: number, hid: number }[] = [];
|
||||
let skinInfos: {id: number, hid: number, inc: number, reason: number }[] = [];
|
||||
let calAllHeroResult = undefined; // 全局战力变化推送
|
||||
|
||||
for (let skinId of skins) {//皮肤推送
|
||||
@@ -251,7 +251,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
heroskins.push({ skins: result.hero.skins, hid: result.hero.hid });
|
||||
if(result.calAllHeroResult) calAllHeroResult = result.calAllHeroResult;
|
||||
}
|
||||
skinInfos.push({ id: skinId, hid: result.hero?.hid||0 })
|
||||
skinInfos.push({ id: skinId, hid: result.hero?.hid||0, inc: 1, reason })
|
||||
}
|
||||
}
|
||||
if (!!skinInfos.length) {
|
||||
@@ -263,7 +263,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
|
||||
// 5. 获得头像和相框等
|
||||
if(figures.length > 0) {
|
||||
let figureInfo = await addFigure(roleId, figures);
|
||||
let figureInfo = await addFigure(roleId, figures, reason);
|
||||
if(figureInfo) figureInfos.push(figureInfo);
|
||||
for (let id of figures) {//皮肤推送
|
||||
showItems.push({ id, count: 1 });
|
||||
@@ -390,17 +390,6 @@ function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
||||
return { items, equips, gold, coin, ap, skins, figures }
|
||||
}
|
||||
|
||||
export async function decreaseItems(roleId: string, sid: string, bags: Array<{ id: number, count: number, ratio?: number }>) {
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
if (bags.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, bags);
|
||||
if (hasError) return true;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result }), uids);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
let equipIds: Array<number> = [];
|
||||
let itemIds: Array<number> = [];
|
||||
@@ -507,7 +496,7 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
}
|
||||
|
||||
if (pieces.length > 0) {
|
||||
let goods = await addItems(roleId, roleName, sid, pieces);
|
||||
let goods = await addItems(roleId, roleName, sid, pieces, ITEM_CHANGE_REASON.HERO_TRANSFER_PIECE);
|
||||
resultItems = goods;
|
||||
}
|
||||
return { heroes, resultHeroes, goods: resultItems }
|
||||
|
||||
Reference in New Issue
Block a user