皮肤:修改存储逻辑
This commit is contained in:
@@ -7,7 +7,7 @@ import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeServi
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { pinus } from 'pinus';
|
||||
import { addEquips, addBags, addSkins, addFigure, unlockFigure as pubUnlockFigure, createHeroes as pubCreateHeroes, transPiece } from '../pubUtils/itemUtils';
|
||||
import { addEquips, addBags, addSkin, addFigure, unlockFigure as pubUnlockFigure, createHeroes as pubCreateHeroes, transPiece } from '../pubUtils/itemUtils';
|
||||
import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { uniq, indexOf, findIndex } from 'underscore';
|
||||
@@ -16,6 +16,7 @@ import { Figure } from '../domain/dbGeneral';
|
||||
import { Rank } from './rankService';
|
||||
import { checkActivityTask, pushActivityUpdate, pushTaskUpdate } from './taskService';
|
||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
import { HeroSkin } from '../db/Hero';
|
||||
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
let currencysMap: any = {};
|
||||
@@ -81,7 +82,7 @@ function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencys
|
||||
} else {
|
||||
bags.push(good);
|
||||
}
|
||||
} else if (table == ITEM_TABLE.HERO) {
|
||||
} else if (table == ITEM_TABLE.SKIN) {
|
||||
return false
|
||||
} else if (table == ITEM_TABLE.ROLE) {
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
@@ -152,31 +153,44 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: bagInfos }), uids);
|
||||
|
||||
|
||||
let figureInfo = await addFigure(roleId, figures);
|
||||
for (let id of figures) {//皮肤推送
|
||||
showItems.push({ id, count: 1 });
|
||||
}
|
||||
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
}
|
||||
|
||||
let skinInfos = [];
|
||||
let addSkinIds = [];
|
||||
let skinInfos: {skins: HeroSkin[], hid: number}[] = []; // 皮肤推送信息
|
||||
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = []; // 头像变化推送信息
|
||||
let calAllHeroResult = undefined; // 全局战力变化推送
|
||||
|
||||
for (let skinId of skins) {//皮肤推送
|
||||
let result = await addSkins(roleId, skinId);
|
||||
let result = await addSkin(roleId, roleName, skinId, false);
|
||||
console.log(result)
|
||||
if (!!result) {
|
||||
showItems.push({ id: skinId, count: 1 });
|
||||
skinInfos.push(result);
|
||||
addSkinIds.push(skinId);
|
||||
figureInfos.push(result.figureInfo);
|
||||
if(result.hero) {
|
||||
skinInfos.push({ skins: result.hero.skins, hid: result.hero.hid });
|
||||
if(result.calAllHeroResult) calAllHeroResult = result.calAllHeroResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!!skinInfos.length) {
|
||||
let unlockedType = addSkinIds.map(cur => { return { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur } });
|
||||
await unlockFigure(sid, roleId, unlockedType);
|
||||
calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds);
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, { skinInfos }), uids);
|
||||
pushHeroSkinMsg(skinInfos, uids); // 推送onHeroSkinChange
|
||||
}
|
||||
// 推送全局加成信息
|
||||
if(calAllHeroResult) await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
|
||||
// 获得头像和相框等
|
||||
if(!!figures && figures.length > 0) {
|
||||
let figureInfo = await addFigure(roleId, figures);
|
||||
if(figureInfo) figureInfos.push(figureInfo);
|
||||
for (let id of figures) {//皮肤推送
|
||||
showItems.push({ id, count: 1 });
|
||||
}
|
||||
}
|
||||
|
||||
// 获得头像或相框或形象推送
|
||||
if(!!figureInfos && figureInfos.length > 0) {
|
||||
for(let figureInfo of figureInfos) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
}
|
||||
}
|
||||
|
||||
return showItems;
|
||||
}
|
||||
|
||||
@@ -203,7 +217,7 @@ function sortItems(goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<
|
||||
bags.push({ id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid || 0, type });
|
||||
}
|
||||
|
||||
} else if (table == ITEM_TABLE.HERO) {
|
||||
} else if (table == ITEM_TABLE.SKIN) {
|
||||
if (type == CONSUME_TYPE.SKIN) {
|
||||
let index = indexOf(skins, good.id);
|
||||
if (index == -1) {
|
||||
@@ -333,7 +347,7 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
let resultHeroes: HeroType[] = [], resultItems: ItemInter[] = [];
|
||||
if (newHeroInfo.length > 0) {
|
||||
|
||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResults, taskPushMessage, activityTaskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
||||
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
||||
@@ -343,9 +357,7 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
for (let calHeroResult of calHeroResults) {
|
||||
await pushCalPlayerCe(roleId, sid, calHeroResult);
|
||||
}
|
||||
for (let calAllHeroResult of calAllHeroResults) {
|
||||
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
}
|
||||
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
pushActivityUpdate(roleId, sid, null, activityTaskPushMessage);
|
||||
@@ -362,4 +374,26 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
export async function createHero(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[], heroInfo: CreateHeroParam) {
|
||||
let result = await createHeroes(roleId, roleName, sid, serverId, funcs, [heroInfo]);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 皮肤数据变化去重、推送
|
||||
* @param skinInfos 推送的皮肤
|
||||
* @param uids 玩家
|
||||
*/
|
||||
function pushHeroSkinMsg(skinInfos: {skins: HeroSkin[], hid: number}[], uids: {uid: string, sid: string}[]) {
|
||||
let pushSkinInfos: {skins: HeroSkin[], hid: number}[] = []; // 可能会有重复的
|
||||
for(let { skins, hid } of skinInfos) {
|
||||
let index = pushSkinInfos.findIndex(cur => cur.hid == hid);
|
||||
if(index == -1) {
|
||||
pushSkinInfos.push({skins, hid});
|
||||
} else {
|
||||
if(skins.length > pushSkinInfos[index].skins.length) {
|
||||
pushSkinInfos[index] = {skins, hid};
|
||||
}
|
||||
}
|
||||
}
|
||||
if(pushSkinInfos.length > 0) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, { skinInfos }), uids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user