✨ feat(gvg): 定时器
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import BaseModel from "./BaseModel";
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { LeagueRankInfo } from "../domain/rank";
|
||||
|
||||
class Player {
|
||||
@prop({ required: true })
|
||||
@@ -44,14 +45,6 @@ export default class GVGCity extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
userCnt: number; // 城池人数
|
||||
|
||||
// 创建城市
|
||||
public static async createCity(configId: number, groupId: number, serverType: number, cityId: number) {
|
||||
let doc = new GVGCityModel();
|
||||
let update = Object.assign(doc.toJSON(), { configId, cityId, groupId, serverType});
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, cityId, groupId, serverType }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
// 通过 cityId 获取城市
|
||||
public static async findByCityId(configId: number, groupId: number, serverType: number, cityId: number) {
|
||||
const city: GVGCityType = await GVGCityModel.findOne({ configId, groupId, serverType, cityId }).lean();
|
||||
@@ -81,6 +74,15 @@ export default class GVGCity extends BaseModel {
|
||||
const cities: GVGCityType[] = await GVGCityModel.find({ configId, hasGuard: true }).lean();
|
||||
return cities
|
||||
}
|
||||
|
||||
// 占领城池
|
||||
public static async guardCity(configId: number, groupId: number, serverType: number, cityId: number, league: LeagueRankInfo) {
|
||||
console.log('##### guardCity', configId, groupId, serverType, cityId)
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId: configId + 1, cityId, groupId, serverType }, { $set: {
|
||||
hasGuard: true, guardLeague: league.code, guardLeagueName: league.name, guardLeagueIcon: league.icon
|
||||
} }, { upsert: true, new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user