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

This commit is contained in:
luying
2023-02-24 21:02:51 +08:00
parent 99b19ee566
commit 86af54a50d
3 changed files with 32 additions and 31 deletions
+12 -15
View File
@@ -317,22 +317,19 @@ export default class GVGTeam extends BaseModel {
// 投石车伤害
public static async attackByCatapult(teamCodes: string[], inc: number, rebirthAreaId: number) {
await GVGTeamModel.updateMany({ teamCode: { $in: teamCodes } }, { $inc: { durability: -inc } });
let brokenTeams: GVGTeamType[] = await GVGTeamModel.find({ teamCode: { $in: teamCodes }, durability: { $lte: 0 } }).lean();
if(brokenTeams.length > 0) {
await GVGTeamModel.bulkWrite(brokenTeams.map(({ teamCode, maxDurability }) => {
return { updateOne: { filter: { teamCode }, update: { $set: { areaId: rebirthAreaId, pointId: 0, durability: maxDurability } }}}
}));
}
let teams: GVGTeamType[] = await GVGTeamModel.find({ teamCode: { $in: teamCodes } }).lean();
return teams.map(team => {
let originTeam = brokenTeams.find(origin => origin.teamCode == team.teamCode);
if(originTeam) {
team.originPointId = originTeam.originPointId;
team.curTeamBreak = originTeam.curTeamBreak;
let teams: GVGTeamType[] = [];
for(let teamCode of teamCodes) {
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: -inc } }, { new: true }).lean();
let originPointId = team.pointId;
if(team.durability <= 0) {
team = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId: rebirthAreaId, pointId: 0, durability: team.maxDurability } }, { new: true }).lean();
team.originPointId = originPointId;
team.curTeamBreak = true;
}
return team
})
teams.push(team);
}
return teams
}
// 加积分