/** * entry触发后引起的下发 */ import { getMails } from './mailService'; import { recentGuildMsgs, recentPrivateChatInfos, recentSysMsgs, recentWorldMsgs } from './chatService'; import { getCurTask } from './taskService'; import { RoleType } from '../db/Role'; import { FrontendOrBackendSession, pinus } from 'pinus'; import { resResult } from '../pubUtils/util'; import { STATUS, USER_GUILD_SELECT, GUILD_SELECT } from '../consts'; import { getAllShopList } from './shopService'; import { getGeneralRank } from './rankService'; import { getFriendList, getApplyList } from './friendService'; import { getDailyBattleList } from './dailyBattleService'; import { getExpeditionStatus } from './expeditionService'; import { getTowerStatus, getHungupRewards, getTasks } from './battleService'; import { getAllAssistCnt } from './comBattleService'; import { getDungeonData } from './dungeonService'; import { PvpSeasonResultModel } from '../db/PvpSeasonResult'; import { nowSeconds } from '../pubUtils/timeUtil'; import { getGachaList } from './gachaService'; import { getSchoolList } from './roleService'; import { addRoleToGuildChannel } from './chatChannelService'; import { getMyGuildInfo, getGuildWithRefActive, getUserGuildWithRefActive, getWishPool } from './guildService'; import { getAuction } from './auctionService'; import { getGuildTrainInstance } from './guildTrainService'; import { BossInstanceModel } from '../db/BossInstance'; import { getBossInstanceInfo } from './guildBossService'; import { getEvent } from './eventSercive'; import { getBattleListOfMain } from './normalBattleService'; export async function pushData(role: RoleType, session: FrontendOrBackendSession) { try{ const { roleId, serverId, roleName, guildCode } = role; const sid = session.get('sid'); pushEntryStart(roleId, sid); // 商店 const shop = await getAllShopList(roleId); pushEntryData('shop', roleId, sid, shop); // 排行榜 const rank = await getGeneralRank(role, serverId); pushEntryData('rank', roleId, sid, rank); // 邮件 const mails = await getMails(roleId, serverId); pushEntryData('mail', roleId, sid, mails); // 好友 const friendList = await getFriendList(role); const applyList = await getApplyList(roleId); pushEntryData('friend', roleId, sid, { friendList, applyList }); // 每日关卡 const daily = await getDailyBattleList(role); pushEntryData('daily', roleId, sid, daily); // 远征 const expedition = await getExpeditionStatus(roleId, roleName); pushEntryData('expedition', roleId, sid, expedition); // 镇念塔 const tower = await getTowerEntryData(role); pushEntryData('tower', roleId, sid, tower); // 寻宝 const assistCnt = await getAllAssistCnt(roleId); pushEntryData('comBattle', roleId, sid, { assistCnt }) // 秘境 const dungeon = await getDungeonData(role); pushEntryData('dungeon', roleId, sid, dungeon); // PVP const hasSeasonReward = await getPvpEntryData(roleId); pushEntryData('pvp', roleId, sid, { hasSeasonReward }); // 招募 const gacha = await getGachaList(roleId); pushEntryData('gacha', roleId, sid, gacha); // 百家学宫 const school = await getSchoolList(roleId); pushEntryData('school', roleId, sid, school); // 军团 const { hasGuild, guild, userGuild, guildResult } = await getGuildEntryData(role, sid, session); if(hasGuild) { pushEntryData('guild', roleId, sid, guildResult); // 拍卖 const auction = await getAuction(guildCode, session); pushEntryData('auction', roleId, sid, auction); // 练兵场 const train = await getGuildTrainInstance(roleId, guild, userGuild); pushEntryData('train', roleId, sid, train); // 演武台boss const bossInstance = await BossInstanceModel.findBossInstance(guild.code); if(bossInstance) { const boss = await getBossInstanceInfo(bossInstance, roleId); pushEntryData('boss', roleId, sid, boss); } // 许愿池 const wishPool = await getWishPool(userGuild); pushEntryData('wishPool', roleId, sid, wishPool); } // 任务 const { mainTask, dailyTask, achievement } = await getCurTask(role.roleId, session); pushEntryData('task', roleId, sid, { mainTask, dailyTask, achievement }); // 聊天 const worldMsgs = await recentWorldMsgs(serverId); const sysMsgs = await recentSysMsgs(serverId); const guildMsgs = await recentGuildMsgs(guildCode); const recentPrivateChats = await recentPrivateChatInfos(roleId, roleName); pushEntryData('chat', roleId, sid, { worldMsgs, sysMsgs, guildMsgs, recentPrivateChats }); // 奇遇 const event = await getEvent(role.eventStatus, roleId, roleName); pushEntryData('event', roleId, sid, event); // 主线关卡列表 const battle = await getBattleListOfMain(role); pushEntryData('battle', roleId, sid, battle); pushEntryEnd(roleId, sid); }catch(e) { console.error(e.stack); } } function pushEntryData(type: string, roleId: string, sid: string, param: T) { let uids = [{ uid: roleId, sid }]; let data = { type }; data[type] = param; pinus.app.channelService.pushMessageByUids('onEntryData', resResult(STATUS.SUCCESS, data), uids);//通知在线玩家练兵场重置, } function pushEntryStart(roleId: string, sid: string) { let uids = [{ uid: roleId, sid }]; pinus.app.channelService.pushMessageByUids('onEntryDataStart', resResult(STATUS.SUCCESS), uids);//通知在线玩家练兵场重置, } function pushEntryEnd(roleId: string, sid: string) { let uids = [{ uid: roleId, sid }]; pinus.app.channelService.pushMessageByUids('onEntryDataEnd', resResult(STATUS.SUCCESS), uids);//通知在线玩家练兵场重置, } /** * 镇念塔初始数据 * @param role */ async function getTowerEntryData(role: RoleType) { const { roleId } = role; const status = await getTowerStatus(role); const hungUp = await getHungupRewards(roleId); const tasks = await getTasks(role); if(hungUp.status == -1) { return { status, hungUp: {}, tasks } } else { return { status, hungUp: hungUp.data, tasks } } } /** * 获取是否存在pvp赛季奖励 * @param roleId */ async function getPvpEntryData(roleId: string) { let pvpSeasonResult = await PvpSeasonResultModel.getPvpSeasonResult(roleId); if(!pvpSeasonResult) return false; let { oldSeasonData, show} = pvpSeasonResult; // 旧赛季结算的时候,会在pvpSeasonResult表中存上一赛季的时间,并更新show字段 return oldSeasonData.seasonEndTime <= nowSeconds() && show; } /** * 获取军团信息,并加入军团频道 * @param role * @param sid * @param session */ async function getGuildEntryData(role: RoleType, sid: string, session: FrontendOrBackendSession) { if (role.hasGuild) { let userGuild = await getUserGuildWithRefActive(role.roleId, 'job auth guildCode receivedActive activeRecord activeDaily activeWeekly wishDntCnt wishGoods'); if (userGuild) { let guild = await getGuildWithRefActive(userGuild.guildCode, role.serverId); if (guild) { addRoleToGuildChannel(role.roleId, sid, userGuild.guildCode); let result = await getMyGuildInfo(role.roleId, sid, userGuild, guild, role.serverId, session); return { hasGuild: true, guild, userGuild, guildResult: result}; } } } return { hasGuild: false } }