🐞 fix(gvg): 修复队伍进出城池内存更新

This commit is contained in:
luying
2023-02-23 17:50:50 +08:00
parent 7300efd263
commit c3d86076ec
9 changed files with 324 additions and 216 deletions

View File

@@ -2,12 +2,12 @@ import { GVGRecModel, GVGRecType } from '../../../db/GVGRec';
import { GVGAreaInMap, GVGTeamInList, GVGTeamInListOnPoint, GVGTeamSpineInMap, LeagueGood, MyTeamInfo, MyTeamSimpleInfo } from '../../../domain/gvgField/returnData';
import { GVGTeamModel, GVGTeamType, GVGTeamUpdate } from '../../../db/GVGTeam';
import { GVGUserDataModel } from '../../../db/GVGUserData';
import { GVGCityModel } from '../../../db/GVGCity';
import { GVGCityModel, GVGCityType } from '../../../db/GVGCity';
import { Application, BackendSession, ChannelService, HandlerService, pinus } from "pinus";
import { resResult, genCode } from "../../../pubUtils/util";
import { GVGLeagueModel } from '../../../db/GVGLeague';
import { getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
import { redisAddBattleScore, battleEndSendMessage, calBattleScoreByCe, checkAreaIsInCity, checkGVGBattleStart, checkMoveStatus, getBattleRanksByCity, getBirthAreaOfCity, getGVGWarId, getOppHeroes, getTechKnifeHurt, getTechReviveMinus, initRobots, pushTeamMoveMessage, getGVGCitiesInfo, leaveCity } from '../../../services/gvg/gvgBattleService';
import { redisAddBattleScore, battleEndSendMessage, calBattleScoreByCe, checkAreaIsInCity, checkGVGBattleStart, checkMoveStatus, getBattleRanksByCity, getBirthAreaOfCity, getGVGWarId, getOppHeroes, getTechKnifeHurt, getTechReviveMinus, initRobots, pushTeamMoveMessage, getGVGCitiesInfo, leaveCity, refreshTeams } from '../../../services/gvg/gvgBattleService';
import { getGVGBattleData } from '../../../services/gvg/gvgBattleMemory';
import { GVGBattleRecModel } from '../../../db/GVGBattleRec';
import { getFightTimeByPeriod } from '../../../services/gvg/gvgFightService';
@@ -15,7 +15,7 @@ import { gameData, getReviveGold } from '../../../pubUtils/data';
import { getAllServerName } from '../../../services/redisService';
import { checkBattleHeroesByHid } from '../../../services/normalBattleService';
import { SaveTeamParam, SaveTeamUpdateParam } from '../../../domain/gvgField/gvgDb';
import { GVG_AREA_TYPE, GVG_ITEM, GVG_REC_TYPE, ITEM_CHANGE_REASON, REDIS_KEY, STATUS } from '../../../consts';
import { GVG_AREA_TYPE, GVG_ITEM, GVG_PERIOD, GVG_REC_TYPE, ITEM_CHANGE_REASON, REDIS_KEY, STATUS } from '../../../consts';
import { GVGHeroInfo } from '../../../domain/dbGeneral';
import { ArtifactModel } from '../../../db/Artifact';
import { getHeroesAttributes } from '../../../services/playerCeService';
@@ -65,7 +65,7 @@ export class GVGBattleHandler {
const { cityId, index, head, spine, frame, lineup } = msg;
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
@@ -130,8 +130,9 @@ export class GVGBattleHandler {
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
let groupKey = await getGroupKey(serverId);
const city = await GVGCityModel.findByCityId(configId, groupKey, cityId);
const { guardLeague: leagueCode = '', guardLeagueName: name = '', guardLeagueIcon: icon = 0, players = [] } = city||{};
let guardCity = await GVGCityModel.findByCityId(configId + 1, groupKey, cityId);
if(!guardCity) guardCity = await GVGCityModel.findByCityId(configId, groupKey, cityId);
const { guardLeague: leagueCode = '', guardLeagueName: name = '', guardLeagueIcon: icon = 0, players = [] } = guardCity||{};
let ourTeamCnt = 0, oppTeamCnt = 0;
for(let { leagueCode, teamCnt } of players) {
@@ -176,7 +177,7 @@ export class GVGBattleHandler {
const { cityId } = msg;
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let groupKey = await getGroupKey(serverId);
@@ -185,39 +186,41 @@ export class GVGBattleHandler {
// 初始化本城池的守擂机器人
await initRobots(configId, groupKey, cityId);
let teams = await GVGTeamModel.findByRole(roleId, '-_id');
// 每赛季初自己的几支队伍恢复耐久、城市、顺便更新一下自己的玩家名、联军
let updateArr: GVGTeamUpdate[] = [], originCityId = 0;
for(let team of teams) {
if(team.configId != configId) {
let { teamCode, maxDurability } = team;
updateArr.push({ teamCode, durability: maxDurability, cityId: 0, areaId: 0, pointId: 0, roleName, guildCode, leagueCode: myLeague.leagueCode, leagueName: myLeague.name, groupKey });
}
if(team.cityId) originCityId = team.cityId;
}
if(updateArr.length > 0) teams = await GVGTeamModel.refreshByConfig(roleId, updateArr);
let teams = await refreshTeams(configId, groupKey, roleId, roleName, guildCode, myLeague);
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
let originCityId = gvgUserData?.cityId||0;
// 检测是否已经在城池中,玩家不在这个城池中时进行处理
let city: GVGCityType;
if (originCityId != cityId) {
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
if(gvgUserData?.cityId > 0) { // 如果leaveCity没有退出成功玩家还遗留在上一座城中做一下处理
await GVGCityModel.decreasePlayerByCity(configId, groupKey, gvgUserData.cityId, roleId);
city = await GVGCityModel.decreasePlayerByCity(configId, groupKey, gvgUserData.cityId, roleId);
}
const roleTeamCnt = await GVGTeamModel.getTeamCntByRole(roleId);
let city = await GVGCityModel.increasePlayer(configId, groupKey, cityId, roleId, myLeague.leagueCode, roleTeamCnt);
city = await GVGCityModel.increasePlayer(configId, groupKey, cityId, roleId, myLeague.leagueCode, roleTeamCnt);
if(!city) return resResult(STATUS.GVG_BATTLE_CITY_FULL);
gvgUserData = await GVGUserDataModel.changeCity(configId, myLeague.leagueCode, roleId, cityId);
}
let teamResult: MyTeamInfo[] = [];
for(let team of teams) { // 有可能多个编队有的在城池中(驻守),有点不在(新编)
let originCityId = team.cityId||0;
if(originCityId == cityId) {
teamResult.push(new MyTeamInfo(team));
continue;
};
if(!city) city = await GVGCityModel.findByCityId(configId, groupKey, cityId);
let areaId = getBirthAreaOfCity(city, myLeague.leagueCode);
teams = await GVGTeamModel.enterCity(roleId, cityId, areaId, groupKey);
team = await GVGTeamModel.enterCity(team.teamCode, cityId, areaId, groupKey);
if(!team) continue;
// 更新内存队伍信息
let teamObj = getGVGBattleData(groupKey);
teamObj.enterCity(...teams);
teamObj.enterCity(team);
teamResult.push(new MyTeamInfo(team))
}
// const recs = await GVGRecModel.findBattleRecByCity(configId, groupKey, cityId);
const teamResult = teams.map(team => new MyTeamInfo(team));
const { ranks, myRank } = await getBattleRanksByCity(configId, groupKey, cityId, myLeague);
await leaveGVGCityTeamChannel(roleId, sid);
await addRoleToGVGCityChannel(roleId, groupKey, cityId, sid);
@@ -378,7 +381,7 @@ export class GVGBattleHandler {
const { cityId, areaId, pointId, teamCode } = msg;
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let groupKey = await getGroupKey(serverId);
@@ -407,7 +410,7 @@ export class GVGBattleHandler {
const { pointId, teamCode } = msg;
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let groupKey = await getGroupKey(serverId);
@@ -433,7 +436,7 @@ export class GVGBattleHandler {
const { teamCode, oppoTeamCode } = msg;
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let groupKey = await getGroupKey(serverId);
@@ -512,7 +515,7 @@ export class GVGBattleHandler {
if(itemId != GVG_ITEM.KNIFE) return resResult(STATUS.GVG_ITEM_CANNOT_USE);
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let groupKey = await getGroupKey(serverId);