✨ feat(gvg): 添加联军频道
This commit is contained in:
@@ -18,6 +18,7 @@ import { comBtlLvInvalid } from './comBattleService';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { RegionModel } from '../db/Region';
|
||||
import { getGroupIdOfServer, getServersByGroupId } from './gvg/gvgService';
|
||||
import { GVGLeagueModel } from '../db/GVGLeague';
|
||||
|
||||
export * from './chatChannelService';
|
||||
export * from './sysChatService';
|
||||
@@ -75,8 +76,8 @@ async function createPrivateMsgData(roleId: string, roleName: string, type: numb
|
||||
/**
|
||||
* @description 生成群聊消息数据
|
||||
*/
|
||||
async function createGroupMsgData(roleId: string, roleName: string, channel: string, channelId: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
||||
const result: GroupMessageParam = {roleId, roleName, channel, channelId, type, source, content, targetRoleId, targetMsgCode};
|
||||
async function createGroupMsgData(roleId: string, roleName: string, channel: string, channelId: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string, otherInfo = '') {
|
||||
const result: GroupMessageParam = {roleId, roleName, channel, channelId, type, source, content, targetRoleId, targetMsgCode, otherInfo };
|
||||
result.roomId = groupRoomId(channel, channelId);
|
||||
await setupBaseMsgParm(result);
|
||||
return result;
|
||||
@@ -120,8 +121,8 @@ export async function createPrivateMsg(roleId: string, roleName: string, type: n
|
||||
* @param {string} targetMsgCode
|
||||
* @returns
|
||||
*/
|
||||
export async function createGroupMsg(roleId: string, roleName: string, channel: string, channelId: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
||||
const msgData: GroupMessageParam = await createGroupMsgData(roleId, roleName, channel, channelId, type, source, content, targetRoleId, targetMsgCode);
|
||||
export async function createGroupMsg(roleId: string, roleName: string, channel: string, channelId: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string, otherInfo = '') {
|
||||
const msgData: GroupMessageParam = await createGroupMsgData(roleId, roleName, channel, channelId, type, source, content, targetRoleId, targetMsgCode, otherInfo);
|
||||
const result: GroupMessageType = await GroupMessageModel.createMsg(msgData);
|
||||
return result;
|
||||
}
|
||||
@@ -170,7 +171,12 @@ export async function pushGroupMsgToRoom(msg: GroupMessageType) {
|
||||
for(let serverId of serverIds) {
|
||||
await sendMessageToServerWithSuc(serverId, PUSH_ROUTE.GROUP_MSG, { ...msg, roleInfo });
|
||||
}
|
||||
}
|
||||
} else if (msg.channel == CHANNEL_PREFIX.LEAGUE) {
|
||||
let guildCodes = msg.otherInfo? msg.otherInfo.split('|'): [];
|
||||
for(let guildCode of guildCodes) {
|
||||
await sendMessageToGuildWithSuc(guildCode, PUSH_ROUTE.GROUP_MSG, { ...msg, roleInfo });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function pushGroupMsgToAll(msg: GroupMessageType, filterCb?: ({ lv, topLineupCe }) => boolean) {
|
||||
@@ -231,7 +237,6 @@ async function recentGroupMsgs(roomId: string, count?: number) {
|
||||
*/
|
||||
export async function recentServerGroupMsgs(serverId: number, count?: number) {
|
||||
let groupId = await getGroupIdOfServer(serverId);
|
||||
console.log('####', groupId);
|
||||
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.GVG, groupId), count);
|
||||
return result;
|
||||
}
|
||||
@@ -273,6 +278,21 @@ export async function recentGuildMsgs(guildCode: string, count?: number) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取最近的联军聊天消息
|
||||
* @export
|
||||
* @param {string} guildCode 用区服编号做房间标识
|
||||
* @param {number} [count]
|
||||
* @returns
|
||||
*/
|
||||
export async function recentLeagueMsgs(guildCode: string, count?: number) {
|
||||
if(!guildCode) return [];
|
||||
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
||||
if(!myLeague) return [];
|
||||
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.LEAGUE, myLeague.leagueCode), count);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 创建新的私聊记录
|
||||
* @param {boolean} sender 给发送者还是接收者创建,发送者发消息的时候也阅读了消息
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* entry触发后引起的下发
|
||||
*/
|
||||
import { getMails } from './mailService';
|
||||
import { recentGuildMsgs, recentPrivateChatInfos, recentServerGroupMsgs, recentSysMsgs, recentWorldMsgs } from './chatService';
|
||||
import { recentGuildMsgs, recentLeagueMsgs, recentPrivateChatInfos, recentServerGroupMsgs, recentSysMsgs, recentWorldMsgs } from './chatService';
|
||||
import { getCurTask, getPvpTask } from './task/taskService';
|
||||
|
||||
import { RoleType } from '../db/Role';
|
||||
@@ -204,8 +204,9 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio
|
||||
const sysMsgs = await recentSysMsgs(serverId);
|
||||
const guildMsgs = await recentGuildMsgs(guildCode);
|
||||
const gvgMsgs = await recentServerGroupMsgs(serverId);
|
||||
const leagueMsgs = await recentLeagueMsgs(guildCode);
|
||||
const recentPrivateChats = await recentPrivateChatInfos(roleId, roleName);
|
||||
return { worldMsgs, sysMsgs, guildMsgs, gvgMsgs, recentPrivateChats };
|
||||
return { worldMsgs, sysMsgs, guildMsgs, gvgMsgs, leagueMsgs, recentPrivateChats };
|
||||
case 'event':
|
||||
return await getEvent(role.eventStatus, roleId, roleName);
|
||||
case 'battle':
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GVGTeamMem } from "../../domain/battleField/gvgBattle";
|
||||
import { GVGLeagueType } from "../../db/GVGLeague";
|
||||
import { GVGLeagueModel, GVGLeagueType } from "../../db/GVGLeague";
|
||||
import { GVGTeamModel, GVGTeamType, GVGTeamUpdate } from "../../db/GVGTeam";
|
||||
import { GVGCityModel, GVGCityType } from "../../db/GVGCity";
|
||||
import { gameData, getGVGBattleRankReward } from "../../pubUtils/data";
|
||||
@@ -20,6 +20,7 @@ import { findKeys, getAllServerName } from "../redisService";
|
||||
import { sendMessageToGVGAreaByTeamWithSuc, sendMessageToGVGAreaWithSuc, sendMessageToGVGCityWithSuc } from "../pushService";
|
||||
import { sendMailToLeagueByContent } from "../mailService";
|
||||
import { GVGCityAreaPointModel } from "../../db/GVGCityAreaPoint";
|
||||
import { addCityGuardMessage } from "./gvgRecService";
|
||||
|
||||
|
||||
/**
|
||||
@@ -380,7 +381,9 @@ export async function gvgBattleEnd() {
|
||||
if(cnt < GVG.GVG_CITY_OCCUPIED_NUMBER) {
|
||||
await GVGCityModel.guardCity(configId, groupKey, cityId, rankInfo);
|
||||
let dicCityAdd = gameData.gvgCityAdd.get(dicCity.cityType);
|
||||
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, rankInfo.code, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward });
|
||||
let league = await GVGLeagueModel.findByCodeWithoutPopulate(rankInfo.code);
|
||||
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, rankInfo.code, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward }, league);
|
||||
await addCityGuardMessage(league, cityId);
|
||||
guardLeagueCnt.set(rankInfo.code, cnt + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ import { getHeroesAttributes } from "../playerCeService";
|
||||
import { Rank } from "../rankService";
|
||||
import { findKeys, getAllServerName, redisClient } from "../redisService";
|
||||
import { combinePushItem } from "./gvgItemService";
|
||||
import { addVestigeLeagueRankRec } from "./gvgRecService";
|
||||
import { getGroupIdOfServer, getGroupKey, getGVGServerType } from "./gvgService";
|
||||
import { addVestigeLeagueRankRec, addVestigeRankMessage } from "./gvgRecService";
|
||||
import { getGroupIdOfServer, getGroupKey, getGVGServerType, getPeriodByTime } from "./gvgService";
|
||||
|
||||
// 备战期的遗迹和激战期的开始结束战斗时间
|
||||
export function getFightTimeByPeriod(period: GVG_PERIOD, time?: number) {
|
||||
@@ -390,6 +390,8 @@ export async function getVestigeRank(redisKey: REDIS_KEY, isSimple: boolean, key
|
||||
// systimer 服
|
||||
export async function saveVestigeRankSchedule() {
|
||||
let config = await GVGConfigModel.findConfig();
|
||||
let period = getPeriodByTime(config.teamTime, config.prepareTime, config.battleTime, config.scheduleTime);
|
||||
if(period != GVG_PERIOD.PREPARE) return;
|
||||
let day = getDayKeyInfo();
|
||||
let keys = await findKeys(`${REDIS_KEY.GVG_VESTIGE_LEAGUE}:${day}:`);
|
||||
for(let key of keys) {
|
||||
@@ -398,6 +400,7 @@ export async function saveVestigeRankSchedule() {
|
||||
let ranks = await r.getRankByRangeRaw();
|
||||
await GVGVestigeLeagueRankModel.saveRank(groupKey, ranks);
|
||||
await addVestigeLeagueRankRec(config.configId, groupKey, ranks);
|
||||
await addVestigeRankMessage(ranks);
|
||||
}
|
||||
|
||||
let memberKeys = await findKeys(`${REDIS_KEY.GVG_VESTIGE_MEMBER_ALL}:${day}:`);
|
||||
@@ -416,14 +419,14 @@ export function calVestigeLeagueBoxRewards(canReceiveRanks: GVGVestigeLeagueRank
|
||||
for(let { rank } of canReceiveRanks) {
|
||||
let dicRank = getGVGVestigeLeagueRank(rank);
|
||||
if(!dicRank) { console.error('dic_zyz_GVGVestigeLeagueRank error'); continue; }
|
||||
console.log('###### league', rank, dicRank)
|
||||
// console.log('###### league', rank, dicRank)
|
||||
combinePushItem(rewards, dicRank.rankReward);
|
||||
combinePushItem(leagueReward, dicRank.rankLeagueReward);
|
||||
}
|
||||
for(let { rank } of canReceivePlayerRanks) {
|
||||
let dicRank = getGVGVestigePlayerRank(rank);
|
||||
if(!dicRank) { console.error('dic_zyz_GVGVestigPlayerRank error'); continue; }
|
||||
console.log('###### player', rank, dicRank)
|
||||
// console.log('###### player', rank, dicRank)
|
||||
combinePushItem(rewards, dicRank.rankPlayerReward);
|
||||
combinePushItem(leagueReward, dicRank.rankPlayerLeagueReward);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ import { addGVGReward } from "./gvgItemService";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
import { getProduceCoinCnt } from "./gvgItemService";
|
||||
import { GVGVestigeRankModel } from "../../db/GVGVestigeRank";
|
||||
import { addResourceRecord } from "./gvgRecService";
|
||||
import { addLeagueLvUpMessage, addResourceRecord } from "./gvgRecService";
|
||||
import { GVGLeagueType } from "../../db/GVGLeague";
|
||||
|
||||
export function checkPreTech(techId: number, activeQueue: number[], techQueue: Tech[]) {
|
||||
const dicTech = gameData.gvgTech.get(techId);
|
||||
@@ -116,7 +117,8 @@ export function getMyContribute(userDailyData: GVGUserDailyDataType, myRanks: {v
|
||||
* @param count 数量
|
||||
* @returns
|
||||
*/
|
||||
export async function addResource(leagueCode: string, roleId: string, roleName: string, resourceType: GVG_RESOURCE_TYPE, count: number) {
|
||||
export async function addResource(myLeague: GVGLeagueType, roleId: string, roleName: string, resourceType: GVG_RESOURCE_TYPE, count: number) {
|
||||
let { leagueCode } = myLeague;
|
||||
let { configId } = getGVGConfig();
|
||||
let resources = getResourceCnt(resourceType, count);
|
||||
if(!resources) return false;
|
||||
@@ -124,6 +126,7 @@ export async function addResource(leagueCode: string, roleId: string, roleName:
|
||||
|
||||
// 联军更新资源
|
||||
let league = await GVGLeaguePrepareModel.addResource(configId, leagueCode, food, mineral, wood);
|
||||
let originLv = league?.lv||1;
|
||||
// 联军升级
|
||||
let lv = calLeagueLv(league.resources);
|
||||
league = await GVGLeaguePrepareModel.setLv(configId, leagueCode, lv);
|
||||
@@ -135,6 +138,7 @@ export async function addResource(leagueCode: string, roleId: string, roleName:
|
||||
|
||||
let myContribute = getMyContribute(userDailyData, myRanks);
|
||||
addResourceRecord(roleId, roleName, leagueCode, resourceType, count);
|
||||
if(lv > originLv) addLeagueLvUpMessage(roleId, roleName, myLeague, lv);
|
||||
|
||||
return { resources: league.resources, leagueLv: league.lv, myContribute }
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
|
||||
// 动态
|
||||
import { GVG_REC_ID, GVG_REC_TYPE, GVG_RESOURCE_TYPE } from "../../consts";
|
||||
import { CHANNEL_PREFIX, GVG_REC_ID, GVG_REC_TYPE, GVG_RESOURCE_TYPE, MSG_SOURCE, MSG_TYPE } from "../../consts";
|
||||
import { GVGBattleRecType } from "../../db/GVGBattleRec";
|
||||
import { GVGLeagueModel, GVGLeagueType } from "../../db/GVGLeague";
|
||||
import { GVGRecModel } from "../../db/GVGRec";
|
||||
import { GVGTeamType } from "../../db/GVGTeam";
|
||||
import { GVGVestigeRecType } from "../../db/GVGVestigeRec";
|
||||
import { gameData } from "../../pubUtils/data";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { createGroupMsg, pushGroupMsgToRoom } from "../chatService";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
|
||||
// 加入军团
|
||||
@@ -114,4 +116,47 @@ export async function addTeamSettleRec(team: GVGTeamType) {
|
||||
export async function addTeamLeaveRec(team: GVGTeamType, pointId: number) {
|
||||
let { roleId, roleName, leagueCode, configId, cityId, groupKey } = team;
|
||||
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, groupKey, type: GVG_REC_TYPE.BATTLE_BY_LEAGUE, recId: GVG_REC_ID.LEAGUE_TEAM_LEAVE, createTime: nowSeconds(), params: [`${roleName}`, getPointName(pointId)] });
|
||||
}
|
||||
|
||||
|
||||
// —————— 频道消息 ——————
|
||||
export async function addLeagueLvUpMessage(roleId: string, roleName: string, myLeague: GVGLeagueType, lv: number) {
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.LEAGUE, myLeague.leagueCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GVG_LV_UP, JSON.stringify({ leagueCode: myLeague.leagueCode, name: myLeague.name, lv }), '', '', getGuildCodeString(myLeague));
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
}
|
||||
|
||||
export async function changeNoticeMessage(roleId: string, roleName: string, myLeague: GVGLeagueType, notice: string) {
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.GVG, myLeague.leagueCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GVG_NOTICE, JSON.stringify({ leagueCode: myLeague.leagueCode, name: myLeague.name, notice }), '', '', getGuildCodeString(myLeague));
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
}
|
||||
|
||||
export function getGuildCodeString(myLeague: GVGLeagueType) {
|
||||
let guildCodes = myLeague?.guildCodes||[];
|
||||
return guildCodes.join('|')
|
||||
}
|
||||
|
||||
export async function addTechActivateMessage(roleId: string, roleName: string, myLeague: GVGLeagueType, techId: number) {
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.LEAGUE, myLeague.leagueCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GVG_LV_UP, JSON.stringify({ leagueCode: myLeague.leagueCode, name: myLeague.name, techId }), '', '', getGuildCodeString(myLeague));
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
}
|
||||
|
||||
export async function addTechUnlockMessage(roleId: string, roleName: string, myLeague: GVGLeagueType, techId: number) {
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.LEAGUE, myLeague.leagueCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GVG_LV_UP, JSON.stringify({ leagueCode: myLeague.leagueCode, name: myLeague.name, techId }), '', '', getGuildCodeString(myLeague));
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
}
|
||||
|
||||
export async function addVestigeRankMessage(ranks: { rank: number, field: string }[]) {
|
||||
let leagueCodes = ranks.map(cur => cur.field);
|
||||
let leagues = await GVGLeagueModel.findByCodesWithoutPopulate(leagueCodes, 'leagueCode name guildCodes');
|
||||
for(let { rank, field: leagueCode } of ranks) {
|
||||
let league = leagues.find(cur => cur.leagueCode == leagueCode);
|
||||
if(!league) continue;
|
||||
const msgData = await createGroupMsg('', '', CHANNEL_PREFIX.LEAGUE, leagueCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GVG_LV_UP, JSON.stringify({ leagueCode: league.leagueCode, name: league.name, rank }), '', '', getGuildCodeString(league));
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
}
|
||||
}
|
||||
|
||||
export async function addCityGuardMessage(myLeague: GVGLeagueType, cityId: number) {
|
||||
const msgData = await createGroupMsg('', '', CHANNEL_PREFIX.LEAGUE, myLeague.leagueCode, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GVG_LV_UP, JSON.stringify({ leagueCode: myLeague.leagueCode, name: myLeague.name, cityId }), '', '', getGuildCodeString(myLeague));
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
}
|
||||
@@ -148,6 +148,10 @@ export function getGVGPeriodData() {
|
||||
|
||||
export function getCurPeriod() {
|
||||
let { teamTime, prepareTime, battleTime, scheduleTime } = getGVGConfig();
|
||||
return getPeriodByTime(teamTime, prepareTime, battleTime, scheduleTime)
|
||||
}
|
||||
|
||||
export function getPeriodByTime(teamTime: number, prepareTime: number, battleTime: number, scheduleTime: number) {
|
||||
let now = nowSeconds();
|
||||
if(now >= teamTime && now < prepareTime) {
|
||||
return GVG_PERIOD.TEAM;
|
||||
|
||||
Reference in New Issue
Block a user