🐞 fix(gvg): 投石车定时任务

This commit is contained in:
luying
2023-02-15 22:03:05 +08:00
parent 4359bfd9cc
commit 7543baa8cb
17 changed files with 304 additions and 52 deletions

View File

@@ -75,6 +75,12 @@ export default class GVGCity extends BaseModel {
const cities: GVGCityType[] = await GVGCityModel.find({ configId, groupId, serverType, hasGuard: true }).lean();
return cities
}
// 查询有联军驻守的城池
public static async findAllGuardCities(configId: number) {
const cities: GVGCityType[] = await GVGCityModel.find({ configId, hasGuard: true }).lean();
return cities
}
}

View File

@@ -141,6 +141,11 @@ export default class GVGLeaguePrepare extends BaseModel {
const result: GVGLeaguePrepareType = await GVGLeaguePrepareModel.findOneAndUpdate({ configId, leagueCode }, { $set: { lv }}, { new: true }).lean();
return result;
}
public static async findByConfigId(configId: number) {
const result: GVGLeaguePrepareType[] = await GVGLeaguePrepareModel.aggregate([{ $match: {configId} }]);
return result;
}
}
export const GVGLeaguePrepareModel = getModelForClass(GVGLeaguePrepare);

View File

@@ -3,10 +3,11 @@ import BaseModel from "./BaseModel";
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { genCode } from "../pubUtils/util";
import { nowSeconds } from "../pubUtils/timeUtil";
import { GVG } from "../pubUtils/dicParam";
import { EXTERIOR, GVG } from "../pubUtils/dicParam";
import { DicGVGAreaPoint } from "../pubUtils/dictionary/DicGVGAreaPoint";
import { InitTeamParam, SaveTeamUpdateParam } from "../domain/gvgField/gvgDb";
import { GVGHeroInfo } from "../domain/dbGeneral";
import { GVG_CATAPULT } from "../consts";
@index({ roleId: 1, index: 1 })
@index({ teamCode: 1 })
@@ -106,12 +107,18 @@ export default class GVGTeam extends BaseModel {
@prop({ required: true, default: false })
isRobot: boolean; // 是否是机器人
@prop({ required: true, default: false })
captapultAtk: number; // 投石车的攻击力
@prop({ required: true, default: false })
isCatapult: boolean; // 是否是投石车
@prop({ required: true, default: false })
isBroken: boolean; // 机器人是否被击破,如果没有被击破,那么这个位置上就还是机器人,如果被击破了,这个位置就空出给玩家
@prop({ required: false })
batchCode: string; // 批量编号
// 创建队伍
public static async saveTeam(roleId: string, index: number, updateParam: SaveTeamUpdateParam, initParam: InitTeamParam) {
const doc = new GVGTeamModel();
@@ -192,7 +199,10 @@ export default class GVGTeam extends BaseModel {
return {
updateOne: {
filter: { groupId, serverType, cityId, areaId, pointId },
update: { $setOnInsert: { teamCode: genCode(8), maxDurability: durability, roleName: name, head, spine, lineupCe: ce, isRobot: true, isBroken: false, startMoveTime: 0, stopMoveTime: 0 }, $set: { configId, durability } },
update: { $setOnInsert: {
teamCode: genCode(8), maxDurability: durability, roleName: name, head, spine, frame: EXTERIOR.EXTERIOR_FACECASE, lineupCe: ce, isRobot: true,
isBroken: false, startMoveTime: 0, stopMoveTime: 0, guildCode: '', leagueCode: '', leagueName: ''
}, $set: { configId, durability } },
upsert: true
}
}
@@ -200,6 +210,30 @@ export default class GVGTeam extends BaseModel {
return await this.findRobotTeams(groupId, serverType, cityId);
}
public static async findCatapultTeams(groupId: number, serverType: number, cityId: number) {
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, isRobot: true, isCatapult: true }).lean();
return team;
}
// 生成投石车
public static async initCatapult(configId: number, groupId: number, serverType: number, cityId: number, leagueCode: string, leagueName: string, areaIds: number[], atk: number, durability: number) {
await GVGTeamModel.bulkWrite(areaIds.map(areaId => {
return {
updateOne: {
filter: { groupId, serverType, cityId, areaId },
update: { $setOnInsert: {
teamCode: genCode(8), maxDurability: durability, captapultAtk: atk, leagueCode, leagueName,
roleName: GVG.GVG_CATAPULT_NAME, head: GVG.GVG_CATAPULT_HEAD, spine: GVG.GVG_CATAPULT_SPINE, frame: EXTERIOR.EXTERIOR_FACECASE, lineupCe: GVG.GVG_CATAPULT_CE,
isRobot: true, isCatapult: true,
isBroken: false, startMoveTime: 0, stopMoveTime: 0, guildCode: '', pointId: 0, roleId: GVG_CATAPULT
}, $set: { configId, durability } },
upsert: true
}
}
}));
return await this.findCatapultTeams(groupId, serverType, cityId);
}
// 攻击方攻击cd
public static async battleStartLockAttack(teamCode: string) {
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { attackTime: nowSeconds() + GVG.GVG_DEFAULT_ATTACK_CD } }, { new: true }).lean();
@@ -256,6 +290,19 @@ export default class GVGTeam extends BaseModel {
return await GVGTeamModel.exists({ configId, groupId, serverType, pointId });
}
// 投石车伤害
public static async attackByCatapult(teamCodes: string[], inc: number, rebirthAreaId: number) {
let batchCode = genCode(8);
await GVGTeamModel.updateMany({ teamCode: { $in: teamCodes } }, { $inc: { durability: -inc }, $set: { batchCode } });
let brokenTeams: GVGTeamType[] = await GVGTeamModel.find({ batchCode, 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({ batchCode }).lean();
return teams
}
}