🐞 fix(gvg): 修复零散小问题

This commit is contained in:
luying
2023-03-01 19:43:10 +08:00
parent bea3361cbe
commit 0f28628a64
8 changed files with 31 additions and 16 deletions

View File

@@ -134,10 +134,19 @@ export class GVGBattleHandler {
// 进入城池之前的检查
async checkMyTeam(msg: { cityId: number }, session: BackendSession) {
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const guildCode = session.get('guildCode');
const { cityId } = msg;
let hasSettled = false, otherCityId = 0;
const teams = await GVGTeamModel.findByRole(roleId, 'cityId');
let { configId, period } = getGVGPeriodData();
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);
let groupKey = await getGroupKey(serverId);
let teams = await refreshTeams(configId, groupKey, roleId, myLeague);
// 玩家队伍信息中城池id不一致说明玩家已经进入了其他城池
for(let { cityId: teamCityId } of teams) {
if(teamCityId > 0 && teamCityId != cityId) {
@@ -384,6 +393,9 @@ export class GVGBattleHandler {
// addTeamSettleRec(curTeam);
await sendMessageToGVGAreaByTeamWithSuc(groupKey, curTeam.areaId, PUSH_ROUTE.GVG_AREA_POINT_CHANGE, {
cityId: curTeam.cityId, areaId: curTeam.areaId, point: new GVGTeamInListOnPoint(curTeam.pointId, true, curTeam)
});
return resResult(STATUS.SUCCESS, { curTeam: new MyTeamInfo(curTeam) });
}
@@ -408,6 +420,9 @@ export class GVGBattleHandler {
let teamObj = getGVGBattleData(groupKey);
teamObj.teamSettle(roleId, teamCode, 0);
await sendMessageToGVGAreaByTeamWithSuc(groupKey, curTeam.areaId, PUSH_ROUTE.GVG_AREA_POINT_CHANGE, {
cityId: curTeam.cityId, areaId: curTeam.areaId, point: new GVGTeamInListOnPoint(myTeam.pointId, true, curTeam)
});
return resResult(STATUS.SUCCESS, { curTeam: new MyTeamInfo(curTeam) });
}
@@ -474,7 +489,9 @@ export class GVGBattleHandler {
}
if(defenseTeam.curTeamBreak) {
let attackScore = calBattleScoreByCe(isSuccess, defenseTeam.lineupCe);
let attackCurTeamBreak = attackTeam.curTeamBreak;
attackTeam = await GVGTeamModel.addScore(attackTeam.teamCode, attackScore, 0);
attackTeam.curTeamBreak = attackCurTeamBreak;
await redisAddBattleScore(attackTeam, attackScore);
}

View File

@@ -170,12 +170,12 @@ class GVGBattleData {
return teams;
}
public findSettledPointMapByLeague() {
public findSettledPointMapByLeague(cityId: number) {
let pointByLeague = new Map<string, number[]>();
for(let [_roleId, pointIds] of this.rolePoints) {
for(let [pointId, teamCode] of pointIds) {
let team = this.teams.get(teamCode);
if(pointId > 0 && team && team.leagueCode) {
if(pointId > 0 && team && team.leagueCode && team.cityId == cityId) {
if(!pointByLeague.has(team.leagueCode)) pointByLeague.set(team.leagueCode, []);
pointByLeague.get(team.leagueCode).push(team.pointId);
};

View File

@@ -404,10 +404,10 @@ export async function catapultHurt() {
cityId: catapult.cityId, areaId, attackType: GVG_ATTACK_TYPE.CATAPULT, teams: myTeams
});
}
await sendMessageToGVGCityWithSuc(teamObj.groupKey, catapult.cityId, PUSH_ROUTE.GVG_SPINE_ATTACKED, {
cityId: catapult.cityId, areaId, teamCode: catapult.teamCode, attackType: GVG_ATTACK_TYPE.CATAPULT, spines: teams.map(team => new GVGAttackSpine(team, catapult.captapultAtk))
});
}
await sendMessageToGVGCityWithSuc(teamObj.groupKey, catapult.cityId, PUSH_ROUTE.GVG_SPINE_ATTACKED, {
cityId: catapult.cityId, areaId, teamCode: catapult.teamCode, attackType: GVG_ATTACK_TYPE.CATAPULT, spines: teams.map(team => new GVGAttackSpine(team, catapult.captapultAtk))
});
}
}
}
@@ -440,7 +440,7 @@ export async function redisAddSettleScore(gvgTeam: GVGTeamType, incScore: number
// 获取排行榜
export async function getBattleRanksByCity(configId: number, groupKey: string, cityId: number, myLeague?: GVGLeagueType) {
let teamObj = getGVGBattleData(groupKey);
let pointByLeague = teamObj.findSettledPointMapByLeague();
let pointByLeague = teamObj.findSettledPointMapByLeague(cityId);
let r = new Rank(REDIS_KEY.GVG_BATTLE_LEAGUE_RANK_BY_CITY, { configId, groupKey, cityId });
r.setGenerFieldsFun((obj => {
if(obj instanceof LeagueRankInfo) {
@@ -591,7 +591,6 @@ async function addGuardCity(configId: number, groupKey: string, cityId: number,
await GVGCityModel.guardCity(configId, groupKey, cityId, league);
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, leagueCode, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward }, league);
await addCityGuardMessage(league, cityId);
await GVGLeagueModel.removeAuto(leagueCode);
}
// —————————— 定时器相关 end —————————— //

View File

@@ -43,7 +43,8 @@ export async function createNewGVGConfig() {
let autoLeagues = await GVGLeagueModel.findAutoCreateLeague();
let needDissmissLeagueId: string[] = [], needDissmissLeagueCodes: string[] = [];
for(let league of autoLeagues) {
if(!await GVGCityModel.checkLeagueHasGuard(config.configId, league.leagueCode)) {
let groupKey = await getGroupKey(league.serverId);
if(!await GVGCityModel.checkLeagueHasGuard(config.configId, groupKey, league.leagueCode)) {
needDissmissLeagueId.push(league._id);
needDissmissLeagueCodes.push(league.leagueCode);
}

View File

@@ -78,8 +78,8 @@ export default class GVGCity extends BaseModel {
}
// 查询联军驻守情况
public static async checkLeagueHasGuard(configId: number, leagueCode: string) {
return await GVGCityModel.exists({ configId, guardLeague: leagueCode, hasGuard: true });
public static async checkLeagueHasGuard(configId: number, groupKey: string, leagueCode: string) {
return await GVGCityModel.exists({ configId: { $lte: configId }, groupKey, guardLeague: leagueCode, hasGuard: true });
}
// 查询联军驻守情况

View File

@@ -37,6 +37,7 @@ export default class GVGCityAreaPoint extends BaseModel {
public static async settlePoint(cityId: number, areaId: number, pointId: number, team: GVGTeamType) {
let { configId, groupKey, leagueCode, leagueName, roleId, roleName, teamCode } = team;
await GVGCityAreaPointModel.updateMany({ configId, groupKey, teamCode }, { $set: { teamCode: '', roleId: '', roleName: '', leagueCode: '', leagueName: '' } });
await GVGCityAreaPointModel.findOneAndUpdate({ configId, groupKey, pointId }, { $setOnInsert: { teamCode: '' }}, { upsert: true });
let result: GVGCityAreaPointType = await GVGCityAreaPointModel.findOneAndUpdate(
{ configId, groupKey, pointId, teamCode: '' },

View File

@@ -199,11 +199,6 @@ export default class GVGLeague extends BaseModel {
let leagues: GVGLeagueType[] = await GVGLeagueModel.find({ isAuto: true, status: 1 }).lean();
return leagues
}
public static async removeAuto(leagueCode: string) {
let league: GVGLeagueType = await GVGLeagueModel.findOneAndUpdate({ leagueCode }, { $set: { isAuto: false } }).lean();
return league
}
}
export const GVGLeagueModel = getModelForClass(GVGLeague);

View File

@@ -689,6 +689,7 @@ export class GVGAreaInMap {
// 地图右边列表上的队伍信息
export class GVGTeamInList {
areaId: number;
pointId: number;
teamCode: string;
roleName: string;
head: number;
@@ -705,6 +706,7 @@ export class GVGTeamInList {
constructor(team: GVGTeamType) {
if(!team) return;
this.areaId = team.areaId;
this.pointId = team.pointId;
this.teamCode = team.teamCode;
this.roleName = team.roleName;
this.head = team.head;