|
|
|
|
@@ -7,7 +7,7 @@ import { COUNTER, GVG_AREA_TYPE, GVG_ATTACK_TYPE, GVG_BATTLE_RANK_TYPE, GVG_PERI
|
|
|
|
|
import { getTimeFun, nowSeconds } from "../../pubUtils/timeUtil";
|
|
|
|
|
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
|
|
|
|
|
import { getGVGBattleData, getGVGBattleMap } from "../memoryCache/gvgBattleData";
|
|
|
|
|
import { GVGAttackSpine, GVGCityMapInfo, GVGTeamInList, GVGTeamInListOnPoint, GVGTeamSpineInMap } from "../../domain/gvgField/returnData";
|
|
|
|
|
import { GVGAttackSpine, GVGCityMapInfo, GVGEnemies, GVGTeamInList, GVGTeamInListOnPoint, GVGTeamSpineInMap, GVGTeamSpineInfo, GVGWinStreakInfo } from "../../domain/gvgField/returnData";
|
|
|
|
|
import { GVG } from "../../pubUtils/dicParam";
|
|
|
|
|
import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
|
|
|
|
|
import { getGroupKey, getGVGConfig, getGVGConfigFromRemote, getGVGPeriodData, getGVGServerType } from "./gvgService";
|
|
|
|
|
@@ -16,7 +16,7 @@ import { pinus } from "pinus";
|
|
|
|
|
import { dispatch } from "../../pubUtils/dispatcher";
|
|
|
|
|
import { Rank } from "../rankService";
|
|
|
|
|
import { KeyNameParam, LeagueRankInfo, myIdInter, RoleRankInfo } from "../../domain/rank";
|
|
|
|
|
import { findKeys, getAllServerName, redisClient } from "../redisService";
|
|
|
|
|
import { findKeys, getAllServerName, getServerName, redisClient } from "../redisService";
|
|
|
|
|
import { sendMessageToGVGAreaByTeamWithSuc, sendMessageToGVGAreaWithSuc, sendMessageToGVGCityWithSuc, sendMessageToUserWithSuc } from "../pushService";
|
|
|
|
|
import { sendMailByContent, sendMailToLeagueByContent } from "../mailService";
|
|
|
|
|
import { GVGCityAreaPointModel } from "../../db/GVGCityAreaPoint";
|
|
|
|
|
@@ -24,13 +24,14 @@ import { addCityGuardMessage } from "./gvgRecService";
|
|
|
|
|
import { GVGUserDataModel } from "../../db/GVGUserData";
|
|
|
|
|
import { RoleModel } from "../../db/Role";
|
|
|
|
|
import { getFightTimeByPeriod } from "./gvgFightService";
|
|
|
|
|
import { getRandSingleEelm } from "../../pubUtils/util";
|
|
|
|
|
import { getRandSingleEelm, parseNumberList } from "../../pubUtils/util";
|
|
|
|
|
import { HeroModel, HeroType } from "../../db/Hero";
|
|
|
|
|
import { ArtifactModel } from "../../db/Artifact";
|
|
|
|
|
import { getHeroesAttributes } from "../playerCeService";
|
|
|
|
|
import { CounterModel } from "../../db/Counter";
|
|
|
|
|
import { getGroupIdOfServer } from "../serverService";
|
|
|
|
|
import { LineupHero } from "../../domain/roleField/hero";
|
|
|
|
|
import { gvgEndParamInter } from "../../pubUtils/interface";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取本联军上周占领的城池
|
|
|
|
|
@@ -253,9 +254,7 @@ export async function leaveCity(isForce: boolean, roleId: string, serverId: numb
|
|
|
|
|
await pinus.app.rpc.guild.guildRemote.leaveCityMem.broadcast(groupKey, roleId);
|
|
|
|
|
for(let team of teams) {
|
|
|
|
|
if(team.cityId > 0 && team.areaId > 0) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(groupKey, team.areaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
|
|
|
|
cityId: team.cityId, areaId: team.areaId, teamCode: team.teamCode
|
|
|
|
|
});
|
|
|
|
|
await sendAreaLeaveMsg(groupKey, team.areaId, team.cityId, team.teamCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -310,7 +309,7 @@ export function getGVGWarId(defenseTeam: GVGTeamType) {
|
|
|
|
|
|
|
|
|
|
// guild.gvgBattleHandler.battleStart 里的heroes返回
|
|
|
|
|
export function getOppHeroes(warId: number, isRobot: boolean, lineup: GVGHeroInfo[]) {
|
|
|
|
|
let heroes: PvpEnemies[] = [];
|
|
|
|
|
let heroes: GVGEnemies[] = [];
|
|
|
|
|
const dicWar = gameData.war.get(warId);
|
|
|
|
|
if(!dicWar) { console.error(`warId ${warId} not found`); return [] }
|
|
|
|
|
const dicWarJson = gameData.warJson.get(dicWar.dispatchJsonId)||[];
|
|
|
|
|
@@ -318,15 +317,15 @@ export function getOppHeroes(warId: number, isRobot: boolean, lineup: GVGHeroInf
|
|
|
|
|
if(!isRobot) {
|
|
|
|
|
let heroInfo = lineup.find(cur => cur.dataId == warJson.dataId);
|
|
|
|
|
if(!heroInfo) continue;
|
|
|
|
|
let hero = new PvpEnemies(warJson, heroInfo);
|
|
|
|
|
let hero = new GVGEnemies(warJson, heroInfo);
|
|
|
|
|
heroes.push(hero);
|
|
|
|
|
} else {
|
|
|
|
|
if(warJson.relation == 2) {
|
|
|
|
|
let dicHero = gameData.hero.get(warJson.actorId);
|
|
|
|
|
if(!dicHero) continue;
|
|
|
|
|
let heroInfo = new PvpHeroInfo();
|
|
|
|
|
let heroInfo = new GVGHeroInfo();
|
|
|
|
|
heroInfo.setRobotInfo(dicHero, warJson.lv);
|
|
|
|
|
let hero = new PvpEnemies(warJson, heroInfo);
|
|
|
|
|
let hero = new GVGEnemies(warJson, heroInfo);
|
|
|
|
|
heroes.push(hero);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -354,6 +353,38 @@ export function checkGVGBattleStart(roleId: string, attackTeam: GVGTeamType, def
|
|
|
|
|
return STATUS.SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getNewLineup(team: GVGTeamType, newInfo: gvgEndParamInter[]) {
|
|
|
|
|
if (team.isRobot) return { isAllDead: false, newLineup: team.lineup};
|
|
|
|
|
let isAllDead = team.curTeamBreak || checkAllDead(team.lineup, newInfo);
|
|
|
|
|
let newLineup: GVGHeroInfo[] = [];
|
|
|
|
|
for(let hero of team.lineup) {
|
|
|
|
|
if (isAllDead) {
|
|
|
|
|
hero.hp = "max";
|
|
|
|
|
hero.maxHp = "max";
|
|
|
|
|
hero.others = '';
|
|
|
|
|
} else {
|
|
|
|
|
let info = newInfo.find(cur => cur.actorId == hero.actorId);
|
|
|
|
|
if (info) {
|
|
|
|
|
hero.hp = info.hp;
|
|
|
|
|
hero.maxHp = info.maxHp;
|
|
|
|
|
hero.others = info.others;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newLineup.push(hero);
|
|
|
|
|
}
|
|
|
|
|
return { isAllDead, newLineup };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查本场战斗武将是否死光了
|
|
|
|
|
export function checkAllDead(oldLineup: GVGHeroInfo[], newInfo: gvgEndParamInter[]) {
|
|
|
|
|
for(let hero of oldLineup) {
|
|
|
|
|
let curInfo = newInfo.find(cur => cur.actorId == hero.actorId);
|
|
|
|
|
if (!curInfo || curInfo.hp > 0) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// —————————— 定时器相关 —————————— //
|
|
|
|
|
// gvg激战期开始定时器
|
|
|
|
|
export async function gvgBattleStart() {
|
|
|
|
|
@@ -553,9 +584,9 @@ export async function getPlayerRanksByCity(configId: number, groupKey: string, c
|
|
|
|
|
export async function gvgBattleSeconds() {
|
|
|
|
|
const { configId, period } = getGVGPeriodData();
|
|
|
|
|
let { startFightTime, endFightTime } = getFightTimeByPeriod(period);
|
|
|
|
|
const serverNames = await getAllServerName();
|
|
|
|
|
// const serverNames = await getAllServerName();
|
|
|
|
|
|
|
|
|
|
let spineCnt = await getSpineCnt();
|
|
|
|
|
// let spineCnt = await getSpineCnt();
|
|
|
|
|
let keys: { groupKey: string, cityId: number }[] = []
|
|
|
|
|
for(let [_key, teamObj] of getGVGBattleMap()) {
|
|
|
|
|
// console.log('#### gvgBattleSeconds groupKey: ', _key, 'areas', teamObj.findAreas(), 'appid', pinus.app.getServerId());
|
|
|
|
|
@@ -571,19 +602,19 @@ export async function gvgBattleSeconds() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 向下推送区域数据
|
|
|
|
|
let spinesByCity = new Map<number, GVGTeamSpineInMap[]>();
|
|
|
|
|
// let spinesByCity = new Map<number, GVGTeamSpineInMap[]>();
|
|
|
|
|
for(let areaId of teamObj.findAreas()) {
|
|
|
|
|
let dicArea = gameData.gvgArea.get(areaId);
|
|
|
|
|
let teams = teamObj.findTeamsByArea(areaId, spineCnt);
|
|
|
|
|
let spines = teams.map(team => new GVGTeamSpineInMap(team, serverNames));
|
|
|
|
|
if(!spinesByCity.has(dicArea.cityId)) spinesByCity.set(dicArea.cityId, []);
|
|
|
|
|
spinesByCity.get(dicArea.cityId).push(...spines);
|
|
|
|
|
// let teams = teamObj.findTeamsByArea(areaId, spineCnt);
|
|
|
|
|
// let spines = teams.map(team => new GVGTeamSpineInMap(team, serverNames));
|
|
|
|
|
// if(!spinesByCity.has(dicArea.cityId)) spinesByCity.set(dicArea.cityId, []);
|
|
|
|
|
// spinesByCity.get(dicArea.cityId).push(...spines);
|
|
|
|
|
let index = keys.findIndex(cur => cur.cityId == dicArea.cityId && cur.groupKey == teamObj.groupKey);
|
|
|
|
|
if(index == -1) keys.push({ groupKey: teamObj.groupKey, cityId: dicArea.cityId });
|
|
|
|
|
}
|
|
|
|
|
for(let [cityId, spines] of spinesByCity) {
|
|
|
|
|
if(spines.length > 0) await sendMessageToGVGCityWithSuc(teamObj.groupKey, cityId, PUSH_ROUTE.GVG_AREA_SPINE_CHANGE, { cityId, spines });
|
|
|
|
|
}
|
|
|
|
|
// for(let [cityId, spines] of spinesByCity) {
|
|
|
|
|
// if(spines.length > 0) await sendMessageToGVGCityWithSuc(teamObj.groupKey, cityId, PUSH_ROUTE.GVG_AREA_SPINE_CHANGE, { cityId, spines });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -768,23 +799,39 @@ export async function battleEndSendMessage(groupKey: string, cityId: number, def
|
|
|
|
|
});
|
|
|
|
|
if(!defenseTeam.isRobot) {
|
|
|
|
|
await sendMessageToUserWithSuc(defenseTeam.roleId, PUSH_ROUTE.GVG_MY_TEAM_ATTACKED, {
|
|
|
|
|
cityId, areaId, attackType, teams: [new GVGTeamInList(defenseTeam)]
|
|
|
|
|
cityId, areaId, attackType, teams: [new GVGTeamInList(defenseTeam, true)]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
await pushTeamBeHurtMessage(defenseTeam, attackTeam);
|
|
|
|
|
await pushTeamBeHurtMessage(attackTeam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendWinStreakMessage(groupKey: string, cityId: number, attackTeam: GVGTeamType, defenseTeam: GVGTeamType, isSuccess: boolean) {
|
|
|
|
|
if (attackTeam && !attackTeam.isRobot) {
|
|
|
|
|
let result = await GVGUserDataModel.setWinStreak(attackTeam.configId, attackTeam.leagueCode, attackTeam.roleId, isSuccess);
|
|
|
|
|
if (needSendMsg(result.winStreak)) {
|
|
|
|
|
await sendMessageToGVGCityWithSuc(groupKey, cityId, PUSH_ROUTE.GVG_WIN_STREAK, new GVGWinStreakInfo(attackTeam, result.winStreak));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (defenseTeam && !defenseTeam.isRobot) {
|
|
|
|
|
let result = await GVGUserDataModel.setWinStreak(defenseTeam.configId, defenseTeam.leagueCode, defenseTeam.roleId, !isSuccess);
|
|
|
|
|
if (needSendMsg(result.winStreak)) {
|
|
|
|
|
await sendMessageToGVGCityWithSuc(groupKey, cityId, PUSH_ROUTE.GVG_WIN_STREAK, new GVGWinStreakInfo(defenseTeam, result.winStreak));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function needSendMsg(winStreak: number) {
|
|
|
|
|
let arr = parseNumberList(GVG.WIN_STREAK_REPORT_LIMIT);
|
|
|
|
|
return arr.includes(winStreak);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 队伍移动
|
|
|
|
|
export async function pushTeamBeHurtMessage(team: GVGTeamType, replaceTeam?: GVGTeamType) {
|
|
|
|
|
if(team.curTeamBreak && team.originPointId > 0) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.fromAreaId, PUSH_ROUTE.GVG_AREA_POINT_CHANGE, {
|
|
|
|
|
cityId: team.cityId, areaId: team.fromAreaId, targetPointId: team.originPointId, originPointId: replaceTeam?.originPointId??0, point: new GVGTeamInListOnPoint(replaceTeam?.pointId||team.pointId, true, replaceTeam||team)
|
|
|
|
|
});
|
|
|
|
|
await sendAreaPointChange(team.groupKey, team.fromAreaId, team.cityId, team.originPointId, replaceTeam?.originPointId??0, replaceTeam||team);
|
|
|
|
|
if(replaceTeam && !replaceTeam.curTeamBreak && replaceTeam.originPointId > 0) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(replaceTeam.groupKey, replaceTeam.fromAreaId, PUSH_ROUTE.GVG_AREA_POINT_CHANGE, {
|
|
|
|
|
cityId: replaceTeam.cityId, areaId: replaceTeam.fromAreaId, targetPointId: replaceTeam.originPointId, originPointId: 0, point: new GVGTeamInListOnPoint(replaceTeam.pointId, true, replaceTeam)
|
|
|
|
|
});
|
|
|
|
|
await sendAreaPointChange(replaceTeam.groupKey, replaceTeam.fromAreaId, replaceTeam.cityId, replaceTeam.originPointId, 0, replaceTeam);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -792,28 +839,45 @@ export async function pushTeamBeHurtMessage(team: GVGTeamType, replaceTeam?: GVG
|
|
|
|
|
await pushTeamMoveMessage(team);
|
|
|
|
|
}
|
|
|
|
|
if(team.isRobot && team.isBroken) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
|
|
|
|
cityId: team.cityId, areaId: team.fromAreaId, teamCode: team.teamCode
|
|
|
|
|
});
|
|
|
|
|
await sendAreaLeaveMsg(team.groupKey, team.fromAreaId, team.cityId, team.teamCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function pushTeamMoveMessage(team: GVGTeamType) {
|
|
|
|
|
if(team.fromAreaId != team.areaId) {
|
|
|
|
|
if(team.fromAreaId > 0) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
|
|
|
|
cityId: team.cityId, areaId: team.fromAreaId, teamCode: team.teamCode
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if(team.areaId > 0) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.areaId, PUSH_ROUTE.GVG_PLAYER_AREA_ADD, {
|
|
|
|
|
cityId: team.cityId, areaId: team.areaId, fromAreaId: team.fromAreaId, player: new GVGTeamInList(team)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if(team.fromAreaId > 0) await sendAreaLeaveMsg(team.groupKey, team.fromAreaId, team.cityId, team.teamCode);
|
|
|
|
|
if(team.areaId > 0) await sendAreaAddMsg(team.groupKey, team.areaId, team.fromAreaId, team.cityId, team);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// —————————— 推送相关 end —————————— //
|
|
|
|
|
|
|
|
|
|
export async function sendAreaLeaveMsg(groupKey: string, areaId: number, cityId: number, teamCode: string) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(groupKey, areaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
|
|
|
|
cityId, areaId, teamCode
|
|
|
|
|
});
|
|
|
|
|
await sendMessageToGVGAreaWithSuc(groupKey, areaId, PUSH_ROUTE.GVG_SPINE_AREA_LEAVE, {
|
|
|
|
|
cityId, areaId, teamCode
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendAreaAddMsg(groupKey: string, areaId: number, fromAreaId: number, cityId: number, team: GVGTeamType) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(groupKey, areaId, PUSH_ROUTE.GVG_PLAYER_AREA_ADD, {
|
|
|
|
|
cityId, areaId, fromAreaId, player: new GVGTeamInList(team)
|
|
|
|
|
});
|
|
|
|
|
await sendMessageToGVGAreaWithSuc(groupKey, areaId, PUSH_ROUTE.GVG_SPINE_AREA_ADD, {
|
|
|
|
|
cityId, areaId, fromAreaId, spine: new GVGTeamSpineInfo(team, await getServerName(team.serverId))
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendAreaPointChange(groupKey: string, areaId: number, cityId: number, targetPointId: number, originPointId: number, team: GVGTeamType) {
|
|
|
|
|
await sendMessageToGVGAreaByTeamWithSuc(groupKey, areaId, PUSH_ROUTE.GVG_AREA_POINT_CHANGE, {
|
|
|
|
|
cityId, areaId, targetPointId, originPointId, point: new GVGTeamInListOnPoint(team.pointId, true, team)
|
|
|
|
|
});
|
|
|
|
|
await sendMessageToGVGAreaWithSuc(groupKey, areaId, PUSH_ROUTE.GVG_SPINE_POINT_CHANGE, {
|
|
|
|
|
cityId, areaId, targetPointId, originPointId, spine: new GVGTeamSpineInfo(team, await getServerName(team.serverId))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 外面页面上的排行榜
|
|
|
|
|
export async function getBattleRank(redisKey: REDIS_KEY, keyParam: KeyNameParam, myId: myIdInter) {
|
|
|
|
|
let r = new Rank(redisKey, keyParam);
|
|
|
|
|
|