🦄 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();
}