|
|
|
@@ -7,7 +7,7 @@ import { pushCalPlayerCe, pushCalAllHeroCe, calPlayerCeAndSave } from './playerC
|
|
|
|
|
import { ItemModel, ItemType } from '../db/Item';
|
|
|
|
|
import { STATUS } from '../consts/statusCode';
|
|
|
|
|
import { pinus } from 'pinus';
|
|
|
|
|
import { addEquips, addBags, addSkin, addFigure, unlockFigure as pubUnlockFigure, transPiece, getGoldObject, getCoinObject, getApObject } from '../pubUtils/itemUtils';
|
|
|
|
|
import { addJewels, addBags, addSkin, addFigure, unlockFigure as pubUnlockFigure, transPiece, getGoldObject, getCoinObject, getApObject } from '../pubUtils/itemUtils';
|
|
|
|
|
import { ItemInter, RewardInter, } from '../pubUtils/interface';
|
|
|
|
|
import { gameData } from '../pubUtils/data';
|
|
|
|
|
import { uniq } from 'underscore';
|
|
|
|
@@ -27,6 +27,7 @@ import { getInitHeroById } from './roleService';
|
|
|
|
|
import { getActivities } from './activity/activityService';
|
|
|
|
|
import { reportTAEvent, reportTAUserSet } from './sdkService';
|
|
|
|
|
import { saveCoinChangeLog, saveFigureInfoLog, saveGoldChangeLog, saveItemChangeLog } from '../pubUtils/logUtil';
|
|
|
|
|
import { JewelModel, JewelType } from '../db/Jewel';
|
|
|
|
|
|
|
|
|
|
export class CheckMeterial {
|
|
|
|
|
private roleId: string;
|
|
|
|
@@ -98,9 +99,9 @@ export class CheckMeterial {
|
|
|
|
|
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);
|
|
|
|
|
let equipSeqIds = equips.map(cur => cur.seqId);
|
|
|
|
|
let resEquips: EquipType[] = [];
|
|
|
|
|
let { items, jewels, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
|
|
|
|
|
let jewelSeqIds = jewels.map(cur => cur.seqId);
|
|
|
|
|
let resJewels: JewelType[] = [];
|
|
|
|
|
|
|
|
|
|
// 检查货币是否充足
|
|
|
|
|
let role = await RoleModel.findByRoleId(roleId);
|
|
|
|
@@ -111,9 +112,9 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
|
|
|
|
if(originGold < 0 || originCoin < 0) return false;
|
|
|
|
|
}
|
|
|
|
|
//检查装备是否存在
|
|
|
|
|
if (equips.length > 0) {
|
|
|
|
|
resEquips = await EquipModel.getEquips(roleId, equipSeqIds);
|
|
|
|
|
if (resEquips.length < equips.length)
|
|
|
|
|
if (jewels.length > 0) {
|
|
|
|
|
resJewels = await JewelModel.findbySeqIds(jewelSeqIds);
|
|
|
|
|
if (resJewels.length < jewels.length)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//检查并修改道具
|
|
|
|
@@ -125,33 +126,31 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除装备
|
|
|
|
|
// if (resEquips.length > 0) {
|
|
|
|
|
// let heroMap = new Map<number, { hero: HeroType, equips: EquipType[]}>();
|
|
|
|
|
// for(let equip of resEquips) {
|
|
|
|
|
// if(equip.hid > 0) {
|
|
|
|
|
// if(!heroMap.has(equip.hid)) {
|
|
|
|
|
// let hero = await HeroModel.findByHidAndRoleWithEquip(equip.hid, roleId);
|
|
|
|
|
// heroMap.set(equip.hid, { hero, equips: [] });
|
|
|
|
|
// }
|
|
|
|
|
// heroMap.get(equip.hid).equips.push(equip);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// for(let [_hid, {hero, equips} ] of heroMap) {
|
|
|
|
|
// let oldCount = hero.ePlace.filter(cur => cur.equip).length;
|
|
|
|
|
// let args = calEquipSeids(hero);
|
|
|
|
|
// for(let equip of equips) {
|
|
|
|
|
// hero = await HeroModel.removeEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
|
|
|
|
|
// }
|
|
|
|
|
if (resJewels.length > 0) {
|
|
|
|
|
let heroMap = new Map<number, { hero: HeroType, jewels: JewelType[]}>();
|
|
|
|
|
for(let jewel of resJewels) {
|
|
|
|
|
if(jewel.hid > 0) {
|
|
|
|
|
if(!heroMap.has(jewel.hid)) {
|
|
|
|
|
let hero = await HeroModel.findByHidAndRole(jewel.hid, roleId);
|
|
|
|
|
heroMap.set(jewel.hid, { hero, jewels: [] });
|
|
|
|
|
}
|
|
|
|
|
heroMap.get(jewel.hid).jewels.push(jewel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(let [_hid, {hero, jewels} ] of heroMap) {
|
|
|
|
|
// TODO 脱下天晶石
|
|
|
|
|
// for(let equip of jewels) {
|
|
|
|
|
// hero = await HeroModel.putOffJewel(roleId, hero.hid, equip.ePlaceId, equip._id);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
|
|
|
|
|
// await checkTaskWithHero(roleId, sid, TASK_TYPE.EQUIP_BY_HERO, hero, [-1, oldCount]);
|
|
|
|
|
// }
|
|
|
|
|
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let equips = await EquipModel.deleteEquips(roleId, equipSeqIds);
|
|
|
|
|
// saveItemChangeLog(roleId, equips.map(equip => ({ id: equip.id, count: equip.count, inc: -1 })), reason);
|
|
|
|
|
// pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equipInfos: equips.map(equip => ({ seqId: equip.seqId, id: equip.id, inc: -1, reason })) }), uids);
|
|
|
|
|
// }
|
|
|
|
|
let jewels = await JewelModel.deleteBySeqIds(roleId, jewelSeqIds);
|
|
|
|
|
saveItemChangeLog(roleId, jewels.map(jewel => ({ id: jewel.id, count: 1, inc: -1 })), reason);
|
|
|
|
|
pinus.app.get('channelService').pushMessageByUids('onJewelDel', resResult(STATUS.SUCCESS, { jewels: jewels.map(jewel => ({ seqId: jewel.seqId, id: jewel.id, inc: -1, reason })) }), uids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//消耗玩家货币
|
|
|
|
|
if (gold.length > 0 || coin.length > 0) {
|
|
|
|
@@ -181,41 +180,39 @@ 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>, reason: ITEM_CHANGE_REASON) {
|
|
|
|
|
let uids = [{ uid: roleId, sid }];
|
|
|
|
|
let { items, equips, gold, coin, ap, skins, figures } = sortItems(goods, HANDLE_REWARD_TYPE.RECEIVE);
|
|
|
|
|
let { items, jewels, gold, coin, ap, skins, figures } = sortItems(goods, HANDLE_REWARD_TYPE.RECEIVE);
|
|
|
|
|
let showItems: { id: number, seqId?: number, count: number, isBag?: boolean }[] = [];
|
|
|
|
|
let role = await RoleModel.findByRoleId(roleId);
|
|
|
|
|
// 1. 装备处理
|
|
|
|
|
if(equips.length > 0) {
|
|
|
|
|
let { equipCount = 0 } = role;
|
|
|
|
|
let incEquips = equips, mailEquips: { id?: number, hid?: number, seqId?: number }[] = [];
|
|
|
|
|
if(equips.length + equipCount > BAG.BAG_EQUIP_UPLIMITED) { // 装备上限
|
|
|
|
|
let inc = BAG.BAG_EQUIP_UPLIMITED - equipCount;
|
|
|
|
|
if(jewels.length > 0) {
|
|
|
|
|
let { jewelCount = 0 } = role;
|
|
|
|
|
let incJewels = jewels, mailJewels: { id?: number, hid?: number, seqId?: number }[] = [];
|
|
|
|
|
if(jewels.length + jewelCount > BAG.BAG_EQUIP_UPLIMITED) { // 装备上限
|
|
|
|
|
let inc = BAG.BAG_EQUIP_UPLIMITED - jewelCount;
|
|
|
|
|
if(inc < 0) inc = 0;
|
|
|
|
|
incEquips = equips.slice(0, inc);
|
|
|
|
|
mailEquips = equips.slice(inc);
|
|
|
|
|
incJewels = jewels.slice(0, inc);
|
|
|
|
|
mailJewels = jewels.slice(inc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 直接加的
|
|
|
|
|
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 });
|
|
|
|
|
let { jewels: jewelInfos, pushMessages } = await addJewels(roleId, roleName, <{id: number, hid?: number}[]>incJewels, reason);
|
|
|
|
|
for (let jewel of jewelInfos) {
|
|
|
|
|
showItems.push({ seqId: jewel.seqId, id: jewel.id, count: 1, isBag: true });
|
|
|
|
|
}
|
|
|
|
|
for(let equip of combineItems(mailEquips)) {
|
|
|
|
|
showItems.push({ id: equip.id, count: equip.count, isBag: false });
|
|
|
|
|
for(let jewel of combineItems(mailJewels)) {
|
|
|
|
|
showItems.push({ id: jewel.id, count: jewel.count, isBag: false });
|
|
|
|
|
}
|
|
|
|
|
//装备推送
|
|
|
|
|
if (!!equipInfos.length)
|
|
|
|
|
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, { equipInfos }), uids);
|
|
|
|
|
if (!!jewelInfos.length)
|
|
|
|
|
pinus.app.get('channelService').pushMessageByUids('onJewelAdd', resResult(STATUS.SUCCESS, { jewelInfos }), uids);
|
|
|
|
|
pushTaskUpdate(roleId, sid, pushMessages);
|
|
|
|
|
//统计装备
|
|
|
|
|
if (equipInfos.length > 0) {
|
|
|
|
|
let { serverId } = await RoleModel.findByRoleId(roleId);
|
|
|
|
|
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY_COUNT, equipInfos.length, { equips: equipInfos.map(obj => { return { quality: obj.quality } }) })
|
|
|
|
|
saveItemChangeLog(roleId, equipInfos, reason);
|
|
|
|
|
if (jewelInfos.length > 0) {
|
|
|
|
|
saveItemChangeLog(roleId, jewelInfos, reason);
|
|
|
|
|
}
|
|
|
|
|
// 发邮件的
|
|
|
|
|
if(mailEquips.length > 0) {
|
|
|
|
|
await sendMailByContent(MAIL_TYPE.EQUIP_OVER, roleId, { goods: combineItems(mailEquips) });
|
|
|
|
|
if(mailJewels.length > 0) {
|
|
|
|
|
await sendMailByContent(MAIL_TYPE.EQUIP_OVER, roleId, { goods: combineItems(mailJewels) });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -335,12 +332,12 @@ export function combineItems(items: { id?: number, count?: number }[]) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function combineItemAndEquips(items: { id?: number, count?: number }[]) {
|
|
|
|
|
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 != 'equip') {
|
|
|
|
|
if(dicItid.table != 'jewel') {
|
|
|
|
|
let index = result.findIndex(cur => cur.id == id);
|
|
|
|
|
if(index == -1) {
|
|
|
|
|
result.push({ id, count });
|
|
|
|
@@ -356,7 +353,7 @@ export function combineItemAndEquips(items: { id?: number, count?: number }[]) {
|
|
|
|
|
|
|
|
|
|
function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
|
|
|
|
let items: { id: number, count: number }[] = []; // 可叠加道具
|
|
|
|
|
let equips: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
|
|
|
|
|
let jewels: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
|
|
|
|
|
let gold: { count: number, isPay: boolean }[] = []; // 金币
|
|
|
|
|
let coin: number[] = [];
|
|
|
|
|
let ap: number = 0;
|
|
|
|
@@ -376,14 +373,14 @@ function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let { type, table, isCurrency } = dicItid;
|
|
|
|
|
if(table == ITEM_TABLE.EQUIP) { // 装备
|
|
|
|
|
if(table == ITEM_TABLE.JEWEL) { // 装备
|
|
|
|
|
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
|
|
|
|
|
for(let i = 0; i < good.count; i++) {
|
|
|
|
|
equips.push({ id: good.id, hid: good.hid })
|
|
|
|
|
jewels.push({ id: good.id, hid: good.hid })
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if(!!good.seqId) {
|
|
|
|
|
equips.push({ seqId: good.seqId });
|
|
|
|
|
jewels.push({ seqId: good.seqId });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (table == ITEM_TABLE.ITEM) { // 可叠加道具
|
|
|
|
@@ -429,11 +426,11 @@ function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { items, equips, gold, coin, ap, skins, figures }
|
|
|
|
|
return { items, jewels, gold, coin, ap, skins, figures }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
|
|
|
|
let equipIds: Array<number> = [];
|
|
|
|
|
let jewelSeqIds: Array<number> = [];
|
|
|
|
|
let itemIds: Array<number> = [];
|
|
|
|
|
let hids: Array<number> = [];
|
|
|
|
|
goodIds = uniq(goodIds);
|
|
|
|
@@ -442,7 +439,7 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
|
|
|
|
if (!!goodInfo) {
|
|
|
|
|
let { table } = ITID.get(goodInfo.itid);
|
|
|
|
|
if (table == ITEM_TABLE.EQUIP) {
|
|
|
|
|
equipIds.push(goodId);
|
|
|
|
|
jewelSeqIds.push(goodId);
|
|
|
|
|
} else if (table == ITEM_TABLE.ITEM) {
|
|
|
|
|
itemIds.push(goodId);
|
|
|
|
|
}
|
|
|
|
@@ -450,12 +447,12 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//检查装备是否存在
|
|
|
|
|
if (!!equipIds.length) {
|
|
|
|
|
let resEquips = await EquipModel.getEquipsByIds(roleId, equipIds);
|
|
|
|
|
resEquips = uniq(resEquips, function (resEquip) {
|
|
|
|
|
if (!!jewelSeqIds.length) {
|
|
|
|
|
let resJewels = await JewelModel.findbySeqIds(jewelSeqIds);
|
|
|
|
|
resJewels = uniq(resJewels, function (resEquip) {
|
|
|
|
|
return resEquip.id;
|
|
|
|
|
});
|
|
|
|
|
if (resEquips.length < equipIds.length)
|
|
|
|
|
if (resJewels.length < jewelSeqIds.length)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//检查并修改道具
|
|
|
|
|