feat(gvg): 定时器

This commit is contained in:
luying
2023-02-17 11:00:25 +08:00
parent 7543baa8cb
commit 605ee869a9
12 changed files with 210 additions and 56 deletions
+24 -6
View File
@@ -253,30 +253,42 @@ export default class GVGTeam extends BaseModel {
}
// 结算挑战方
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number) {
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: hpInc, playerScore: playerScoreInc } }, { new: true }).lean();
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number) {
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: hpInc, score: playerScoreInc } }, { new: true }).lean();
if(team.durability <= 0) {
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId);
}
return team;
}
originPointId: number;
// 结算防守方
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number) {
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { defenseTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, lockTime: 0, lockTeamCode: '' }, $inc: { durability: hpInc, playerScore: playerScoreInc } }, { new: true }).lean();
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number) {
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { defenseTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, lockTime: 0, lockTeamCode: '' }, $inc: { durability: hpInc, score: playerScoreInc } }, { new: true }).lean();
if(team.durability <= 0) {
let originPointId = team.pointId;
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId);
team.originPointId = originPointId;
}
return team;
}
curTeamBreak: boolean;
// 队伍进入修整器
public static async teamBreak(teamCode: string, isRobot: boolean, maxDurability: number, areaId: number) {
if(!isRobot) {
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { restartTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, stopMoveTime: nowSeconds(), areaId, durability: maxDurability } }, { new: true }).lean();
team.curTeamBreak = true;
return team;
} else {
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { durability: 0, isBroken: true } }, { new: true }).lean();
team.curTeamBreak = true;
return team;
}
}
public static async findByAreaId(groupId: number, serverType: number, cityId: number, areaId: number) {
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, areaId, stopMoveTime: { $lte: nowSeconds() } }).lean();
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, areaId, stopMoveTime: { $lte: nowSeconds() }, isBroken: false }).lean();
return team;
}
@@ -287,7 +299,7 @@ export default class GVGTeam extends BaseModel {
// 这个编队上是否已经有队伍了
public static async checkPoint(configId: number, groupId: number, serverType: number, pointId: number) {
return await GVGTeamModel.exists({ configId, groupId, serverType, pointId });
return await GVGTeamModel.exists({ configId, groupId, serverType, pointId, isBroken: false });
}
// 投石车伤害
@@ -303,6 +315,12 @@ export default class GVGTeam extends BaseModel {
let teams: GVGTeamType[] = await GVGTeamModel.find({ batchCode }).lean();
return teams
}
// 加积分
public static async addScore(teamCode: string, incScore: number) {
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { score: incScore } }, { new: true }).lean();
return team;
}
}