🐞 fix(gvg): 激战期投石车推送

This commit is contained in:
luying
2023-02-24 20:59:54 +08:00
parent 99b19ee566
commit 86af54a50d
3 changed files with 32 additions and 31 deletions

View File

@@ -33,15 +33,17 @@ class GVGBattleData {
} }
public findCatapultAttackTeam(areaIds: number[], leagueCode: string) { public findCatapultAttackTeam(areaIds: number[], leagueCode: string) {
let teams: string[] = []; let teamsByArea = new Map<number, string[]>();
for(let areaId of areaIds) { for(let areaId of areaIds) {
let teams: string[] = [];
let teamCodes = this.areaToTeams.get(areaId)||new Set(); let teamCodes = this.areaToTeams.get(areaId)||new Set();
for(let teamCode of teamCodes) { for(let teamCode of teamCodes) {
let team = this.teams.get(teamCode); let team = this.teams.get(teamCode);
if(team && team.leagueCode != leagueCode && !team.isRobot) teams.push(teamCode); if(team && team.leagueCode != leagueCode && !team.isRobot) teams.push(teamCode);
} }
teamsByArea.set(areaId, teams);
} }
return teams; return teamsByArea;
} }
public leaveCity(roleId: string) { public leaveCity(roleId: string) {

View File

@@ -318,21 +318,23 @@ export async function catapultHurt() {
if(catapult.isBroken) continue; if(catapult.isBroken) continue;
let dicArea = gameData.gvgArea.get(catapult.areaId); let dicArea = gameData.gvgArea.get(catapult.areaId);
let relateArea = dicArea?.relateArea||[]; let relateArea = dicArea?.relateArea||[];
let teamCodes = teamObj.findCatapultAttackTeam(relateArea, catapult.leagueCode); let teamCodeByArea = teamObj.findCatapultAttackTeam(relateArea, catapult.leagueCode);
let dicGVGCity = gameData.gvgCity.get(catapult.cityId); let dicGVGCity = gameData.gvgCity.get(catapult.cityId);
let teams = await GVGTeamModel.attackByCatapult(teamCodes, catapult.captapultAtk, dicGVGCity.attackBirth); for(let [ areaId, teamCodes ] of teamCodeByArea) {
teamObj.battleEnd(teams); let teams = await GVGTeamModel.attackByCatapult(teamCodes, catapult.captapultAtk, dicGVGCity.attackBirth);
if(teams.length > 0) { teamObj.battleEnd(teams);
await sendMessageToGVGAreaByTeamWithSuc(teamObj.groupKey, catapult.areaId, PUSH_ROUTE.GVG_TEAM_ATTACKED, { if(teams.length > 0) {
cityId: catapult.cityId, areaId: catapult.areaId, attackType: 1, teams: teams.map(team => new GVGTeamInList(team)) await sendMessageToGVGAreaByTeamWithSuc(teamObj.groupKey, areaId, PUSH_ROUTE.GVG_TEAM_ATTACKED, {
}); cityId: catapult.cityId, areaId, attackType: 1, teams: teams.map(team => new GVGTeamInList(team))
await sendMessageToGVGAreaWithSuc(teamObj.groupKey, catapult.areaId, PUSH_ROUTE.GVG_SPINE_ATTACKED, { });
cityId: catapult.cityId, areaId: catapult.areaId, attackType: 1, teams: teams.map(team => new GVGAttackSpine(team, catapult.captapultAtk)) await sendMessageToGVGCityWithSuc(teamObj.groupKey, catapult.cityId, PUSH_ROUTE.GVG_SPINE_ATTACKED, {
}); cityId: catapult.cityId, areaId, attackType: 1, teams: teams.map(team => new GVGAttackSpine(team, catapult.captapultAtk))
for(let team of teams) { });
await pushTeamBeHurtMessage(team); for(let team of teams) {
if(team.curTeamBreak && team.originPointId > 0) { await pushTeamBeHurtMessage(team);
await GVGCityAreaPointModel.leavePoint(configId, teamObj.groupKey, team.originPointId); if(team.curTeamBreak && team.originPointId > 0) {
await GVGCityAreaPointModel.leavePoint(configId, teamObj.groupKey, team.originPointId);
}
} }
} }
} }

View File

@@ -317,22 +317,19 @@ export default class GVGTeam extends BaseModel {
// 投石车伤害 // 投石车伤害
public static async attackByCatapult(teamCodes: string[], inc: number, rebirthAreaId: number) { public static async attackByCatapult(teamCodes: string[], inc: number, rebirthAreaId: number) {
await GVGTeamModel.updateMany({ teamCode: { $in: teamCodes } }, { $inc: { durability: -inc } }); let teams: GVGTeamType[] = [];
let brokenTeams: GVGTeamType[] = await GVGTeamModel.find({ teamCode: { $in: teamCodes }, durability: { $lte: 0 } }).lean(); for(let teamCode of teamCodes) {
if(brokenTeams.length > 0) { let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: -inc } }, { new: true }).lean();
await GVGTeamModel.bulkWrite(brokenTeams.map(({ teamCode, maxDurability }) => { let originPointId = team.pointId;
return { updateOne: { filter: { teamCode }, update: { $set: { areaId: rebirthAreaId, pointId: 0, durability: maxDurability } }}} if(team.durability <= 0) {
})); team = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId: rebirthAreaId, pointId: 0, durability: team.maxDurability } }, { new: true }).lean();
} team.originPointId = originPointId;
let teams: GVGTeamType[] = await GVGTeamModel.find({ teamCode: { $in: teamCodes } }).lean(); team.curTeamBreak = true;
return teams.map(team => {
let originTeam = brokenTeams.find(origin => origin.teamCode == team.teamCode);
if(originTeam) {
team.originPointId = originTeam.originPointId;
team.curTeamBreak = originTeam.curTeamBreak;
} }
return team teams.push(team);
}) }
return teams
} }
// 加积分 // 加积分