🐞 fix(gvg): 修复离开战场逻辑
This commit is contained in:
@@ -224,9 +224,9 @@ export class EntryHandler {
|
||||
await leaveGVGAreaChannel(roleId, sid);
|
||||
await leaveGVGAreaTeamChannel(roleId, sid);
|
||||
await leaveGVGCityTeamChannel(roleId, sid);
|
||||
await pinus.app.rpc.guild?.guildRemote.leaveCity.broadcast(roleId, true);
|
||||
await pinus.app.rpc.guild?.guildRemote.leaveCity.broadcast(true, roleId, serverId, guildCode);
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
console.error(e.stack);
|
||||
}
|
||||
RoleModel.updateRoleInfo(roleId, { quitTime: nowSeconds() });
|
||||
// if(teamCode) { // 如果有寻宝中的队伍,那么等于战败
|
||||
|
||||
@@ -200,7 +200,7 @@ export class GVGBattleHandler {
|
||||
if (originCityId != cityId) {
|
||||
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
||||
if(gvgUserData?.cityId > 0) { // 如果leaveCity没有退出成功,玩家还遗留在上一座城中,做一下处理
|
||||
await GVGCityModel.decreasePlayer(configId, groupKey, gvgUserData.cityId, roleId);
|
||||
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);
|
||||
@@ -250,7 +250,7 @@ export class GVGBattleHandler {
|
||||
}
|
||||
|
||||
// 更新玩家城池和队伍城池
|
||||
await leaveCity(roleId, false);
|
||||
await leaveCity(false, roleId, serverId, guildCode, myLeague);
|
||||
|
||||
await leaveGVGAreaChannel(roleId, sid);
|
||||
await leaveGVGAreaTeamChannel(roleId, sid);
|
||||
|
||||
@@ -10,6 +10,7 @@ import { getGVGConfig, setGVGConfig, setGVGServerGroup } from '../../../services
|
||||
import { GVGConfigType } from '../../../db/GVGConfig';
|
||||
import { catapultHurt, gvgBattleEnd, gvgBattleSeconds, gvgBattleStart, initCatapult, leaveCity } from '../../../services/gvg/gvgBattleService';
|
||||
import { clearBattleMemory } from '../../../services/gvg/gvgBattleMemory';
|
||||
import { GVGLeagueType } from '../../../db/GVGLeague';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -169,9 +170,9 @@ export class GuildRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public async leaveCity(roleId: string, isForce: boolean) {
|
||||
public async leaveCity(isForce: boolean, roleId: string, serverId: number, guildCode: string, myLeague?: GVGLeagueType) {
|
||||
try {
|
||||
return leaveCity(roleId, isForce);
|
||||
return leaveCity(isForce, roleId, serverId, guildCode, myLeague);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { getGVGBattleData, getGVGBattleMap } from "./gvgBattleMemory";
|
||||
import { GVGCityMapInfo, GVGTeamInList, GVGTeamInListOnPoint, GVGTeamSpineInMap } from "../../domain/gvgField/returnData";
|
||||
import { GVG } from "../../pubUtils/dicParam";
|
||||
import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
import { getGroupKey, getGVGConfig } from "./gvgService";
|
||||
import { GVGLeaguePrepareModel } from "../../db/GVGLeaguePrepare";
|
||||
import { pinus } from "pinus";
|
||||
import { dispatch } from "../../pubUtils/dispatcher";
|
||||
@@ -57,7 +57,7 @@ export async function getGVGCitiesInfo(configId: number, groupKey: string, leagu
|
||||
if(league) {
|
||||
let players = (city.players||[]).filter(cur => cur.leagueCode == league.leagueCode);
|
||||
obj.setTeamCnt(players.length);
|
||||
let r = new Rank(REDIS_KEY.GVG_BATTLE_LEAGUE_RANK_BY_CITY, { configId, groupKey });
|
||||
let r = new Rank(REDIS_KEY.GVG_BATTLE_LEAGUE_RANK_BY_CITY, { configId, groupKey, cityId: city.cityId });
|
||||
let score = await r.getMyScore({ leagueCode: league.leagueCode });
|
||||
obj.setScore(score||0);
|
||||
}
|
||||
@@ -131,23 +131,21 @@ export function calBattleScoreByCe(isSuccess: boolean, lineupCe: number) {
|
||||
return isSuccess? winScore: 0;
|
||||
}
|
||||
|
||||
export async function leaveCity(roleId: string, isForce: boolean) {
|
||||
export async function leaveCity(isForce: boolean, roleId: string, serverId: number, guildCode: string, myLeague?: GVGLeagueType) {
|
||||
if(!myLeague) myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
||||
if(!myLeague) return;
|
||||
let groupKey = await getGroupKey(serverId);
|
||||
let { configId } = getGVGConfig();
|
||||
let teams = await GVGTeamModel.findByRole(roleId);
|
||||
let hasPoint = false, myTeam: GVGTeamType;
|
||||
for(let team of teams) {
|
||||
if(team.pointId > 0) hasPoint = true;
|
||||
myTeam = team;
|
||||
}
|
||||
let hasPoint = !!teams.find(team => team.pointId > 0);
|
||||
|
||||
if(isForce || !hasPoint) {
|
||||
let leaveResult = await GVGTeamModel.leaveCity(roleId);
|
||||
if(leaveResult) {
|
||||
await GVGCityModel.decreasePlayer(myTeam.configId, myTeam.groupKey, myTeam.cityId, roleId);
|
||||
await GVGUserDataModel.changeCity(myTeam.configId, myTeam.leagueCode, roleId, 0);
|
||||
// 处理内存数据
|
||||
let teamObj = getGVGBattleData(myTeam.groupKey);
|
||||
teamObj.leaveCity(roleId);
|
||||
}
|
||||
await GVGTeamModel.leaveCity(roleId);
|
||||
await GVGCityModel.decreasePlayer(configId, groupKey, roleId);
|
||||
await GVGUserDataModel.changeCity(configId, myLeague.leagueCode, roleId, 0);
|
||||
// 处理内存数据
|
||||
let teamObj = getGVGBattleData(groupKey);
|
||||
teamObj.leaveCity(roleId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,11 +54,16 @@ export default class GVGCity extends BaseModel {
|
||||
}
|
||||
|
||||
// 减少人数
|
||||
public static async decreasePlayer(configId: number, groupKey: string, cityId: number, roleId: string) {
|
||||
public static async decreasePlayerByCity(configId: number, groupKey: string, cityId: number, roleId: string) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupKey, cityId, 'players.roleId': roleId }, { $inc: { userCnt: -1 }, $pull: { players: { roleId } }}, { new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
public static async decreasePlayer(configId: number, groupKey: string, roleId: string) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupKey, 'players.roleId': roleId }, { $inc: { userCnt: -1 }, $pull: { players: { roleId } }}, { new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
// 添加人数
|
||||
public static async increaseTeam(configId: number, groupKey: string, cityId: number, roleId: string) {
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, groupKey, cityId, 'players.roleId': roleId }, { $inc: { 'players.$.teamCnt': 1 }}, { new: true }).lean();
|
||||
@@ -79,7 +84,7 @@ export default class GVGCity extends BaseModel {
|
||||
// 查询联军驻守情况
|
||||
public static async findGuardCity(configId: number, groupKey: string, select = '') {
|
||||
let cities: GVGCityType[] = await GVGCityModel.find({ configId: configId + 1, groupKey, hasGuard: true }).select(select).lean();
|
||||
if(cities.length == 0) cities = await GVGCityModel.find({ configId, groupKey, hasGuard: true }).select(select).lean();
|
||||
if(cities) cities = await GVGCityModel.find({ configId, groupKey }).select(select).lean();
|
||||
return cities
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user