✨ feat(gvg): 添加推送
This commit is contained in:
@@ -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 —————————— //
|
||||
Reference in New Issue
Block a user