✨ feat(gvg): 添加推送
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
import { addRedisChannel, redisChannelServer } from './redisService';
|
||||
import { addGVGHistoryAreas, addGVGHistoryAreaTeam, addRedisChannel, getGVGHistoryAreas, getGVGHistoryAreaTeam, redisChannelServer } from './redisService';
|
||||
import { groupRoomId } from './chatService';
|
||||
import { pinus } from 'pinus';
|
||||
import { crc32 } from 'crc';
|
||||
@@ -61,6 +61,20 @@ export async function addRoleToGroupShopChannel(roleId: string, sid: string) {
|
||||
await addRoleToChannel(roomId, roleId, sid);
|
||||
}
|
||||
|
||||
export async function addRoleToAreaChannel(roleId: string, groupId: number, serverType: number, areaIds: number[], sid: string) {
|
||||
for(let areaId of areaIds) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREAS, `${groupId}_${serverType}_${areaId}`);
|
||||
await addRoleToChannel(roomId, roleId, sid);
|
||||
}
|
||||
await addGVGHistoryAreas(roleId, groupId, serverType, areaIds);
|
||||
}
|
||||
|
||||
export async function addRoleToAreaTeamChannel(roleId: string, groupId: number, serverType: number, areaId: number, sid: string) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREA_BY_TEAM, `${groupId}_${serverType}_${areaId}`);
|
||||
await addRoleToChannel(roomId, roleId, sid);
|
||||
await addGVGHistoryAreaTeam(roleId, groupId, serverType, areaId);
|
||||
}
|
||||
|
||||
async function leaveChannel(roomId: string, roleId: string, sid: string) {
|
||||
const channelSid = await channelServer(roomId);
|
||||
await pinus.app.rpc.chat.chatRemote.leaveChannel.toServer(channelSid, roomId, roleId, sid);
|
||||
@@ -102,6 +116,22 @@ export async function leaveGuildChannel(roleId: string, sid: string, guildCode:
|
||||
await leaveChannel(roomId, roleId, sid);
|
||||
}
|
||||
|
||||
export async function leaveGVGAreaChannel(roleId: string, sid: string) {
|
||||
let keys = await getGVGHistoryAreas(roleId)||[];
|
||||
for(let key of keys) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREAS, key);
|
||||
await leaveChannel(roomId, roleId, sid);
|
||||
}
|
||||
}
|
||||
|
||||
export async function leaveGVGAreaTeamChannel(roleId: string, sid: string) {
|
||||
let channelName = await getGVGHistoryAreaTeam(roleId);
|
||||
if(channelName) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREA_BY_TEAM, channelName);
|
||||
await leaveChannel(roomId, roleId, sid);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getWorldChannelSid(serverId: number) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
const channelSid = await channelServer(roomId);
|
||||
@@ -138,6 +168,18 @@ export async function getGroupShopSid() {
|
||||
return channelSid;
|
||||
}
|
||||
|
||||
export async function getGVGAreaChannelSid(groupId: number, serverType: number, areaId: number) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREAS, `${groupId}_${serverType}_${areaId}`);
|
||||
const channelSid = await channelServer(roomId);
|
||||
return channelSid;
|
||||
}
|
||||
|
||||
export async function getGVGAreaTeamChannelSid(groupId: number, serverType: number, areaId: number) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREA_BY_TEAM, `${groupId}_${serverType}_${areaId}`);
|
||||
const channelSid = await channelServer(roomId);
|
||||
return channelSid;
|
||||
}
|
||||
|
||||
async function delChannel(roomId: string) {
|
||||
const channelSid = await channelServer(roomId);
|
||||
await pinus.app.rpc.chat.chatRemote.deleteChannel.toServer(channelSid, roomId);
|
||||
|
||||
@@ -17,7 +17,7 @@ class GVGBattleData {
|
||||
private teams: Map<string, GVGTeamMem> = new Map(); // 队伍, teamCode => team
|
||||
private rolePoints: Map<string, Map<number, string>> = new Map(); // roleId => pointId[],用于更新玩家的积分
|
||||
private roleToTeam: Map<string, string[]> = new Map(); // roleId => teamCode
|
||||
private areaToTeams: Map<number, Set<string>> = new Map(); // areaId => teamCode set,用于定时下发地图玩家数据
|
||||
public areaToTeams: Map<number, Set<string>> = new Map(); // areaId => teamCode set,用于定时下发地图玩家数据
|
||||
|
||||
constructor(groupId: number, serverType: number) {
|
||||
this.groupId = groupId;
|
||||
@@ -152,6 +152,10 @@ class GVGBattleData {
|
||||
}
|
||||
return teams;
|
||||
}
|
||||
|
||||
public findAreas() {
|
||||
return this.areaToTeams.keys();
|
||||
}
|
||||
}
|
||||
|
||||
export function getGVGBattleData(groupId: number, serverType: number) {
|
||||
@@ -168,7 +172,6 @@ export function getGVGBattleMap() {
|
||||
|
||||
export async function initTeamToMem() {
|
||||
let sid = pinus.app.getServerId();
|
||||
console.log('##### initTeamToMem', sid)
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
let { configId, period } = getGVGPeriodData();
|
||||
// if(period != GVG_PERIOD.BATTLE) return;
|
||||
|
||||
@@ -3,11 +3,11 @@ import { GVGLeagueType } from "../../db/GVGLeague";
|
||||
import { GVGTeamModel, GVGTeamType, GVGTeamUpdate } from "../../db/GVGTeam";
|
||||
import { GVGCityModel, GVGCityType } from "../../db/GVGCity";
|
||||
import { gameData } from "../../pubUtils/data";
|
||||
import { GVG_AREA_TYPE, GVG_TECH_TYPE, REDIS_KEY, STATUS } from "../../consts";
|
||||
import { GVG_AREA_TYPE, GVG_TECH_TYPE, PUSH_ROUTE, REDIS_KEY, STATUS } from "../../consts";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
|
||||
import { getGVGBattleData, getGVGBattleMap } from "./gvgBattleMemory";
|
||||
import { GVGCityMapInfo } from "../../domain/gvgField/returnData";
|
||||
import { GVGAreaInMap, GVGCityMapInfo, GVGTeamInList, GVGTeamInListOnPoint, GVGTeamSpineInMap } from "../../domain/gvgField/returnData";
|
||||
import { pick } from "underscore";
|
||||
import { GVG } from "../../pubUtils/dicParam";
|
||||
import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
|
||||
@@ -17,7 +17,8 @@ import { pinus } from "pinus";
|
||||
import { dispatch } from "../../pubUtils/dispatcher";
|
||||
import { Rank } from "../rankService";
|
||||
import { LeagueRankInfo } from "../../domain/rank";
|
||||
import { findKeys } from "../redisService";
|
||||
import { findKeys, getAllServerName } from "../redisService";
|
||||
import { sendMessageToChannel, sendMessageToGVGAreaByTeamWithSuc, sendMessageToGVGAreaWithSuc } from "../pushService";
|
||||
|
||||
|
||||
/**
|
||||
@@ -223,6 +224,12 @@ export async function catapultHurt() {
|
||||
let dicGVGCity = gameData.gvgCity.get(catapult.cityId);
|
||||
let teams = await GVGTeamModel.attackByCatapult(teamCodes, catapult.captapultAtk, dicGVGCity.attackBirth)
|
||||
teamObj.battleEnd(teams);
|
||||
await sendMessageToGVGAreaByTeamWithSuc(teamObj.groupId, teamObj.serverType, catapult.areaId, PUSH_ROUTE.GVG_TEAM_ATTACKED, {
|
||||
cityId: catapult.cityId, areaId: catapult.areaId, attackType: 1, teams: teams.map(team => new GVGTeamInList(team))
|
||||
});
|
||||
for(let team of teams) {
|
||||
await pushTeamBeHurtMessage(team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,8 +265,9 @@ export async function getBattleRanks(configId: number, groupId: number, serverTy
|
||||
|
||||
// 每5秒一次结算
|
||||
export async function gvgBattleSeconds() {
|
||||
// 每5秒给据点上的人加积分
|
||||
const serverNames = await getAllServerName();
|
||||
for(let [_key, teamObj] of getGVGBattleMap()) {
|
||||
// 每5秒给据点上的人加积分
|
||||
let teams = teamObj.findSettledPoint();
|
||||
for(let teamMem of teams) {
|
||||
if(teamMem.isBroken || teamMem.durability <= 0) continue;
|
||||
@@ -267,8 +275,15 @@ export async function gvgBattleSeconds() {
|
||||
let team = await GVGTeamModel.addScore(teamMem.teamCode, addScore);
|
||||
await addBattleRankScore(team, addScore);
|
||||
}
|
||||
// 向下推送区域数据
|
||||
for(let areaId of teamObj.findAreas()) {
|
||||
let dicArea = gameData.gvgArea.get(areaId);
|
||||
let teams = teamObj.findTeamsByArea(areaId);
|
||||
let result = teams.map(team => new GVGTeamSpineInMap(team, serverNames));
|
||||
sendMessageToGVGAreaWithSuc(teamObj.groupId, teamObj.serverType, areaId, PUSH_ROUTE.GVG_AREA_SPINE_CHANGE, { cityId: dicArea.cityId, areaId, spines: result });
|
||||
}
|
||||
|
||||
}
|
||||
// 向下推送区域数据
|
||||
|
||||
}
|
||||
|
||||
@@ -300,4 +315,50 @@ export async function gvgBattleEnd() {
|
||||
// 排行榜发放奖励
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// —————————— 定时器相关 end —————————— //
|
||||
|
||||
// —————————— 推送相关 —————————— //
|
||||
// 推送
|
||||
export async function battleEndSendMessage(groupId: number, serverType: number, cityId: number, defenseTeam: GVGTeamType, attackTeam: GVGTeamType) {
|
||||
// 推送伤害
|
||||
await sendMessageToGVGAreaByTeamWithSuc(groupId, serverType, defenseTeam.areaId, PUSH_ROUTE.GVG_TEAM_ATTACKED, {
|
||||
cityId, areaId: defenseTeam.areaId, attackType: 3, teams: [new GVGTeamInList(defenseTeam), new GVGTeamInList(attackTeam)]
|
||||
});
|
||||
await pushTeamBeHurtMessage(defenseTeam, attackTeam);
|
||||
await pushTeamBeHurtMessage(attackTeam);
|
||||
}
|
||||
|
||||
// 队伍移动
|
||||
export async function pushTeamBeHurtMessage(team: GVGTeamType, replaceTeam?: GVGTeamType) {
|
||||
|
||||
if(team.curTeamBreak && team.originPointId > 0) {
|
||||
await sendMessageToGVGAreaByTeamWithSuc(team.groupId, team.serverType, team.originPointId, PUSH_ROUTE.GVG_AREA_POINT_CHANGE, {
|
||||
cityId: team.cityId, areaId: team.originPointId, point: new GVGTeamInListOnPoint(team.originPointId, replaceTeam && !replaceTeam.curTeamBreak, replaceTeam)
|
||||
});
|
||||
}
|
||||
|
||||
await pushTeamMoveMessage(team);
|
||||
if(team.isRobot && team.isBroken) {
|
||||
await sendMessageToGVGAreaByTeamWithSuc(team.groupId, team.serverType, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
||||
cityId: team.cityId, areaId: team.areaId, teamCode: team.teamCode
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function pushTeamMoveMessage(team: GVGTeamType) {
|
||||
if(team.fromAreaId != team.areaId) {
|
||||
if(team.fromAreaId > 0) {
|
||||
await sendMessageToGVGAreaByTeamWithSuc(team.groupId, team.serverType, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
||||
cityId: team.cityId, areaId: team.fromAreaId, teamCode: team.teamCode
|
||||
});
|
||||
}
|
||||
if(team.areaId > 0) {
|
||||
await sendMessageToGVGAreaByTeamWithSuc(team.groupId, team.serverType, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_AREA_ADD, {
|
||||
cityId: team.cityId, areaId: team.fromAreaId, player: new GVGTeamInList(team)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// —————————— 推送相关 end —————————— //
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Channel, pinus } from "pinus";
|
||||
import { CHANNEL_PREFIX, PUSH_BATCH, PUSH_INTERVAL, PUSH_ROUTE, STATUS } from "../consts";
|
||||
import { genCode, resResult } from "../pubUtils/util";
|
||||
import { getCityChannelSid, getGuildChannelSid, getWorldChannelSid, groupRoomId, getGroupShopSid } from "./chatService";
|
||||
import { getCityChannelSid, getGuildChannelSid, getWorldChannelSid, groupRoomId, getGroupShopSid, getGVGAreaChannelSid, getGVGAreaTeamChannelSid } from "./chatService";
|
||||
import { getAllOnlineRoles, getAllServers, getRoleOnlineInfo } from "./redisService";
|
||||
import { errlogger, infologger } from '../util/logger';
|
||||
import { MsgEncrypt } from "../pubUtils/sysUtil";
|
||||
@@ -61,6 +61,18 @@ export async function sendMessageToGuild(guildCode: string, route: string, data:
|
||||
await pinus.app.rpc.chat.chatRemote.pushMessage.toServer(channelSid, roomId, route, data);
|
||||
}
|
||||
|
||||
export async function sendMessageToGVGAreaWithSuc(groupId: number, serverType: number, areaId: number, route: string, data: any) {
|
||||
let channelSid = await getGVGAreaChannelSid(groupId, serverType, areaId);
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREAS, `${groupId}_${serverType}_${areaId}`);
|
||||
await pinus.app.rpc.chat.chatRemote.pushMessage.toServer(channelSid, roomId, route, data);
|
||||
}
|
||||
|
||||
export async function sendMessageToGVGAreaByTeamWithSuc(groupId: number, serverType: number, areaId: number, route: string, data: any) {
|
||||
let channelSid = await getGVGAreaTeamChannelSid(groupId, serverType, areaId);
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.GVG_AREA_BY_TEAM, `${groupId}_${serverType}_${areaId}`);
|
||||
await pinus.app.rpc.chat.chatRemote.pushMessage.toServer(channelSid, roomId, route, data);
|
||||
}
|
||||
|
||||
export async function sendMessageToCityWithSuc(serverId: number, cityId: number, route: string, data: any) {
|
||||
await sendMessageToCity(serverId, cityId, route, resResult(STATUS.SUCCESS, data));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Rank, setRankRedisFromDb } from './rankService';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import moment = require('moment');
|
||||
import { getRedisSubChannel } from '../pubUtils/sdkUtil';
|
||||
import { getRandSingleEelm } from '../pubUtils/util';
|
||||
import { getRandSingleEelm, parseNumberList } from '../pubUtils/util';
|
||||
import { ActivityModel } from '../db/Activity';
|
||||
import { TimeLimitRankData } from '../domain/activityField/timeLimitRankField';
|
||||
import { ActivityTimeLimitRankModel } from '../db/ActivityTimeLimitRank';
|
||||
@@ -699,3 +699,46 @@ export async function setHistoryCity(roleId: string, cityId: number) {
|
||||
await redisClient().hsetAsync(REDIS_KEY.GA_HISTORY_CITY, `${roleId}`, cityId);
|
||||
}
|
||||
|
||||
// gvg激战期玩家之前所处的区域,用于退出的时候查询
|
||||
export async function getGVGHistoryAreas(roleId: string) {
|
||||
let areaIds = await redisClient().hgetAsync(REDIS_KEY.GVG_HISTORY_AREA, roleId);
|
||||
if(!areaIds) return []
|
||||
return areaIds.split('&');
|
||||
}
|
||||
|
||||
export async function addGVGHistoryAreas(roleId: string, groupId: number, serverType: number, areaIds: number[]) {
|
||||
let key = areaIds.map(areaId => `${groupId}_${serverType}_${areaId}`).join('&');
|
||||
const result = await redisClient().hsetAsync(REDIS_KEY.GVG_HISTORY_AREA, roleId, key);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function delGVGHistoryAreas(roleId: string) {
|
||||
const result = await redisClient().hdelAsync(REDIS_KEY.GVG_HISTORY_AREA, roleId);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function clearGVGHistoryAreas() {
|
||||
const result = await redisClient().delAsync(REDIS_KEY.GVG_HISTORY_AREA);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
export async function getGVGHistoryAreaTeam(roleId: string) {
|
||||
let channelName = await redisClient().hgetAsync(REDIS_KEY.GVG_HISTORY_AREA_TEAM, roleId);
|
||||
return channelName
|
||||
}
|
||||
|
||||
export async function addGVGHistoryAreaTeam(roleId: string, groupId: number, serverType: number, areaId: number) {
|
||||
const result = await redisClient().hsetAsync(REDIS_KEY.GVG_HISTORY_AREA_TEAM, roleId, `${groupId}_${serverType}_${areaId}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function delGVGHistoryAreaTeam(roleId: string) {
|
||||
const result = await redisClient().hdelAsync(REDIS_KEY.GVG_HISTORY_AREA_TEAM, roleId);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function clearGVGHistoryAreaTeam() {
|
||||
const result = await redisClient().delAsync(REDIS_KEY.GVG_HISTORY_AREA_TEAM);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user