🦄 refactor(热更新): 分割状态代码和功能代码

This commit is contained in:
luying
2023-05-05 15:42:00 +08:00
parent 50a24cb4b8
commit a362a397b5
39 changed files with 676 additions and 622 deletions
@@ -1,17 +1,10 @@
// 存在激战期的内存数据
import { pinus } from "pinus";
import { GVG_CATAPULT, GVG_PERIOD } from "../../consts";
import { GVGTeamModel, GVGTeamType } from "../../db/GVGTeam";
import { GVG_CATAPULT } from "../../consts";
import { GVGTeamType } from "../../db/GVGTeam";
import { GVGTeamMem } from "../../domain/battleField/gvgBattle";
import { dispatch } from "../../pubUtils/dispatcher";
import { getGVGPeriodData } from "./gvgService";
import { redisClient } from "../redisService";
// 积分点占领情况,groupId_serverType_cityId -> GVGBattleData
const gvgBattleMap: Map<string, GVGBattleData> = new Map();
class GVGBattleData {
export class GVGBattleData {
public groupKey: string; // 战区
private teams: Map<string, GVGTeamMem> = new Map(); // 队伍, teamCode => team
@@ -224,34 +217,4 @@ class GVGBattleData {
public setLeagueTech(leagueCode: string, activeTech: number[]) {
this.leagueActiveTech.set(leagueCode, activeTech);
}
}
export function getGVGBattleData(groupKey: string) {
if(!gvgBattleMap.has(groupKey)) {
gvgBattleMap.set(groupKey, new GVGBattleData(groupKey));
}
return gvgBattleMap.get(groupKey);
}
export function getGVGBattleMap() {
return gvgBattleMap;
}
export async function initTeamToMem() {
let sid = pinus.app.getServerId();
let servers = pinus.app.getServersByType('guild');
let { configId, period } = getGVGPeriodData();
if(period != GVG_PERIOD.BATTLE) return;
let teams = await GVGTeamModel.findByConfigId(configId);
for(let team of teams) {
if(team.isBroken) continue;
if((await dispatch(redisClient(), team.cityId.toString(), servers, 'guild'))?.id == sid) {
let teamObj = getGVGBattleData(team.groupKey);
teamObj.enterCity(team);
}
}
}
export function clearBattleMemory() {
gvgBattleMap.clear();
}
@@ -6,7 +6,7 @@ import { gameData, getGVGBattleRankReward } from "../../pubUtils/data";
import { COUNTER, GVG_AREA_TYPE, GVG_ATTACK_TYPE, GVG_BATTLE_RANK_TYPE, GVG_PERIOD, GVG_POINT_TYPE, GVG_TECH_TYPE, MAIL_TYPE, PUSH_ROUTE, REDIS_KEY, STATUS } from "../../consts";
import { getTimeFun, nowSeconds } from "../../pubUtils/timeUtil";
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
import { getGVGBattleData, getGVGBattleMap } from "./gvgBattleMemory";
import { getGVGBattleData, getGVGBattleMap } from "../memoryCache/gvgBattleData";
import { GVGAttackSpine, GVGCityMapInfo, GVGTeamInList, GVGTeamInListOnPoint, GVGTeamSpineInMap } from "../../domain/gvgField/returnData";
import { GVG } from "../../pubUtils/dicParam";
import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
@@ -516,6 +516,7 @@ export async function gvgBattleSeconds() {
await redisAddSettleScore(team, addScore);
}
}
// 向下推送区域数据
let spinesByCity = new Map<number, GVGTeamSpineInMap[]>();
for(let areaId of teamObj.findAreas()) {
@@ -758,4 +759,19 @@ export async function getBattleRank(redisKey: REDIS_KEY, keyParam: KeyNameParam,
}
}
return { ranks, myRank }
}
export async function initTeamToMem() {
let sid = pinus.app.getServerId();
let servers = pinus.app.getServersByType('guild');
let { configId, period } = getGVGPeriodData();
if(period != GVG_PERIOD.BATTLE) return;
let teams = await GVGTeamModel.findByConfigId(configId);
for(let team of teams) {
if(team.isBroken) continue;
if((await dispatch(redisClient(), team.cityId.toString(), servers, 'guild'))?.id == sid) {
let teamObj = getGVGBattleData(team.groupKey);
teamObj.enterCity(team);
}
}
}
@@ -16,9 +16,8 @@ import { LeagueLeader } from "../../domain/rank";
import { GVG } from "../../pubUtils/dicParam";
import { getZeroPointD } from "../../pubUtils/timeUtil";
import { resResult } from "../../pubUtils/util";
import { sendMessageToUserWithSuc } from "../pushService";
import { updateUserInfo } from "../redisService";
import { getGVGBattleData } from "./gvgBattleMemory";
import { getGVGBattleData } from "../memoryCache/gvgBattleData";
import { guildJoinLeagueRecord } from "./gvgRecService";
import { calLeagueCe, getCurPeriod, getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType } from "./gvgService";