125 lines
6.7 KiB
TypeScript
125 lines
6.7 KiB
TypeScript
|
|
import { EPlace, HeroType } from '../db/Hero';
|
|
import { GuildType } from '../db/Guild';
|
|
import { CHANNEL_PREFIX, HERO_GROW_MAX, HERO_INITIAL_QUALITY, MSG_SOURCE, MSG_TYPE, ON_GROUP_MSG_ROUTE, STATUS, WAR_TYPE } from '../consts';
|
|
import { createGroupMsg, pushGroupMsgToRoom } from './chatService';
|
|
import { pick } from 'lodash';
|
|
import { isArray, isString } from 'underscore';
|
|
import { pinus } from 'pinus';
|
|
import { resResult } from '../pubUtils/util';
|
|
import { BossInstanceType } from '../db/BossInstance';
|
|
|
|
async function pushNormalHeroInfoBySource(roleId: string, roleName: string, serverId: number | string, source: number, heroInfo: Partial<HeroType>) {
|
|
const hero = pick(heroInfo, ['hName', 'hid', 'seqId', 'quality', 'star', 'starStage', 'colorStar', 'colorStarStage']);
|
|
const content = JSON.stringify({ roleId, roleName, hero });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, source, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
}
|
|
|
|
export async function pushHeroQualityUpMsg(roleId: string, roleName: string, serverId: number | string, heroInfo: Partial<HeroType>) {
|
|
await pushNormalHeroInfoBySource(roleId, roleName, serverId, MSG_SOURCE.HERO_QUALITY_UP, heroInfo);
|
|
}
|
|
|
|
export async function pushComposeOrangeHero(roleId: string, roleName: string, serverId: number | string, heroInfo: Partial<HeroType>) {
|
|
if (heroInfo.quality < HERO_INITIAL_QUALITY.ORANGE) {
|
|
return;
|
|
}
|
|
await pushNormalHeroInfoBySource(roleId, roleName, serverId, MSG_SOURCE.COMPOSE_ORANGE_HERO, heroInfo);
|
|
}
|
|
|
|
export async function pushHeroStarMax(roleId: string, roleName: string, serverId: number | string, heroInfo: Partial<HeroType>) {
|
|
if (heroInfo.star !== HERO_GROW_MAX.STAR) {
|
|
return;
|
|
}
|
|
await pushNormalHeroInfoBySource(roleId, roleName, serverId, MSG_SOURCE.HERO_STAR_MAX, heroInfo);
|
|
}
|
|
|
|
export async function pushComBtlTeamMsg(teamCode: string, roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.TEAM, teamCode, type, source, content, targetRoleId, targetMsgCode);
|
|
if (!msgData) return null;
|
|
const channel = pinus.app.get('channelService').getChannel(teamCode);
|
|
channel.pushMessage(ON_GROUP_MSG_ROUTE, resResult(STATUS.SUCCESS, msgData));
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushGuildNoticeUpdateMsg(roleId: string, roleName: string, guildInfo: Partial<GuildType>) {
|
|
const { code, notice } = guildInfo;
|
|
if (!code || !isString(notice)) return null;
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.GUILD, code, MSG_TYPE.TEXT, MSG_SOURCE.GUILD_NOTICE, notice, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushGuildUpStructureMsg(roleId: string, roleName: string, guildInfo: Partial<GuildType>) {
|
|
const { code, structure } = guildInfo;
|
|
if (!code || !structure || !isArray(structure)) return null;
|
|
const guild = pick(guildInfo, ['code', 'structure']);
|
|
const content = JSON.stringify({ roleId, roleName, guild });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.GUILD, code, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GUILD_STRUCTURE_LV_UP, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushGuildTrainSucMsg(roleId: string, roleName: string, guildCode: string, hid: number) {
|
|
if (!guildCode) return null;
|
|
const content = JSON.stringify({ roleId, roleName, hid });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.GUILD, guildCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GUILD_TRAIN_SUC, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushGuildBossSucMsg(roleId: string, roleName: string, guildCode: string, bossInstance: BossInstanceType) {
|
|
const boss = pick(bossInstance, ['warId', 'bossLv']);
|
|
const content = JSON.stringify({ roleId, roleName, boss });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.GUILD, guildCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GUILD_BOSS_SUC, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushEquipRefineSucMsg(roleId: string, roleName: string, serverId: number, eplace: Partial<EPlace>) {
|
|
const data = pick(eplace, ['id', 'lv', 'refineLv']);
|
|
const content = JSON.stringify({ roleId, roleName, eplace: data });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, MSG_SOURCE.EQUIP_REFINE_SUC, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushNormalEquipMsg(roleId: string, roleName: string, serverId: number, source: number, id: number, name: string) {
|
|
const content = JSON.stringify({ roleId, roleName, equip: { id, name } });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, source, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushTowerMsg(roleId: string, roleName: string, serverId: number, source: number, lv: number) {
|
|
if (!shouldPushTowerMsg(lv)) return null;
|
|
const content = JSON.stringify({ roleId, roleName, lv });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, source, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
async function pushGKFirstMsg(roleId: string, roleName: string, serverId: number, source: number, warType: number, warId: number) {
|
|
const content = JSON.stringify({ roleId, roleName, warInfo: { warType, warId } });
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, source, content, null, null);
|
|
await pushGroupMsgToRoom(msgData);
|
|
return msgData;
|
|
}
|
|
|
|
export async function pushMysteryFirstMsg(roleId: string, roleName: string, serverId: number, warType: number, warId: number) {
|
|
if (warType !== WAR_TYPE.MYSTERY) return null;
|
|
const result = await pushGKFirstMsg(roleId, roleName, serverId, MSG_SOURCE.MYSTERY_FIRST_SUC, warType, warId);
|
|
return result;
|
|
}
|
|
|
|
export async function pushVestigeFirstMsg(roleId: string, roleName: string, serverId: number, warType: number, warId: number) {
|
|
if (warType !== WAR_TYPE.VESTIGE) return null;
|
|
const result = await pushGKFirstMsg(roleId, roleName, serverId, MSG_SOURCE.VESTIGE_FIRST_SUC, warType, warId);
|
|
return result;
|
|
}
|
|
|
|
function shouldPushTowerMsg(lv: number) {
|
|
// 100 层之后每 50 层触发
|
|
return lv >= 100 && lv % 50 === 0;
|
|
}
|