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

This commit is contained in:
luying
2023-02-17 11:00:23 +08:00
parent 4359bfd9cc
commit 7543baa8cb
17 changed files with 304 additions and 52 deletions
+13 -1
View File
@@ -75,6 +75,7 @@ export enum GVG_ITEM {
PRODUCE_COIN = 10, // 内政令
FIGHT_COIN = 11, // 征战令
BATTLE_FEAT = 12, // 战功
KNIFE = 14, // 诸葛连弩
}
export enum GVG_RESOURCE_TYPE {
@@ -130,4 +131,15 @@ export enum VESTIGE_STATUS {
CHECK = 1, // 出兵中
BATTLE = 2, // 战斗中
COMPLETE = 3, // 战斗结束
}
}
export enum GVG_AREA_TYPE {
DEFENSER = 1, // 1-守方备战区
ATTACKER = 2, // 2-攻方备战区
BIG = 3, // 3-大据点区
MIDDLE = 4, // 4-中据点区
SMALL = 5, // 5-小据点区
CATAPULT = 6, // 6-投石车区
}
export const GVG_CATAPULT = 'catapult';
+1
View File
@@ -1116,6 +1116,7 @@ export enum ITEM_CHANGE_REASON {
GVG_VESTIGE_START = 170, // gvg征战中原挑战
GVG_VESTIGE_END = 171, // gvg征战中原挑战
GVG_VESTIGE_RECEIVE_RANK = 172, // gvg征战中原领取排行榜奖励
GVG_TECH_SEND_KNIFE = 173, // gvg点科技树发放诸葛连弩
}
export enum TA_EVENT {
+6
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
}
}
+5
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);
+49 -2
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
}
}
+9 -28
View File
@@ -1,4 +1,5 @@
import GVGTeam, { GVGTeamType } from "../../db/GVGTeam";
import { nowSeconds } from "../../pubUtils/timeUtil";
// 积分点分类统计,1-3级积分点代表从小到大
export class LeagueCityPoint {
@@ -25,27 +26,14 @@ export class GVGTeamMem extends GVGTeam {
constructor(team: GVGTeamType) {
super();
this.roleId = team.roleId;
this.roleName = team.roleName;
this.serverId = team.serverId;
this.teamCode = team.teamCode;
this.index = team.index;
this.leagueCode = team.leagueCode;
this.guildCode = team.guildCode;
this.areaId = team.areaId;
this.fromAreaId = team.fromAreaId;
this.cityId = team.cityId;
this.pointId = team.pointId;
this.head = team.head;
this.spine = team.spine;
this.frame = team.frame;
this.durability = team.durability;
this.restartTime = team.restartTime;
this.attackTime = team.attackTime;
this.defenseTime = team.defenseTime;
this.startMoveTime = team.startMoveTime;
this.stopMoveTime = team.stopMoveTime;
this.score = team.score;
this.updateTeam(team);
}
public updateTeam(team: GVGTeamType) {
for(let key in team) {
this[key] = team[key];
}
this.isMoving = this.stopMoveTime > nowSeconds();
}
public setCity(cityId: number, areaId = 0, pointId = 0) {
@@ -60,11 +48,4 @@ export class GVGTeamMem extends GVGTeam {
this.startMoveTime = startMoveTime;
this.stopMoveTime = stopMoveTime;
}
public battleEnd(team: GVGTeamType) {
this.durability = team.durability;
this.restartTime = team.restartTime;
this.defenseTime = team.defenseTime;
this.stopMoveTime = team.stopMoveTime;
}
}
+28
View File
@@ -623,6 +623,10 @@ export class GVGTeamSpineInMap {
isMoving: boolean = false;
pointId: number = 0;
fromAreaId: number = 0;
teamCode: string = '';
leagueCode: string = '';
leagueName: string = '';
constructor(obj: GVGTeamMem, serverNames: {[serverId: string]: string}) {
this.spine = obj.spine;
@@ -633,6 +637,9 @@ export class GVGTeamSpineInMap {
this.isMoving = nowSeconds() < this.stopMoveTime;
this.pointId = obj.pointId;
this.fromAreaId = obj.fromAreaId;
this.teamCode = obj.teamCode;
this.leagueCode = obj.leagueCode;
this.leagueName = obj.leagueName;
}
}
@@ -680,6 +687,27 @@ export class GVGTeamInListOnPoint extends GVGTeamInList {
}
}
export class MyTeamSimpleInfo {
teamCode: string; // 队伍唯一id
index: number; // 队伍位置
head: number; // 保存头像
frame: number; // 保存相框
spine: number; // 保存形象
lineup: {
actorId: number; // 武将
dataId: number; // 出兵表上的位置
order: number; // 行动
}[];
constructor(team: GVGTeamType) {
this.teamCode = team.teamCode;
this.index = team.index;
this.head = team.head;
this.frame = team.spine;
this.lineup = team.lineup.map(({ actorId, dataId, outIndex }) => ({ actorId, dataId, order: outIndex }));
}
}
// 更新自己队伍时候的比较详细点的数据
export class MyTeamInfo {
teamCode: string; // 队伍唯一id
+4 -3
View File
@@ -371,14 +371,15 @@ export const ARTIFACT = {
};
export const GUIDE = {
GUIDE_FINGER_GK: 104, // 需要手指软引导的关卡
GUIDE_DEFEAT_GK: 104, // 通过该关卡后开启首次失败引导
};
export const GVG = {
GVG_LEAGUE_COMPOSE: 3, // 一个联军有最多多少军团组成
GVG_CROSS_SERVICE_STARTTIME: 4, // 开服几周后开始跨服玩法
GVG_ROLE_TOTAL_RATIO: 1.2, // 贤臣+猛将总人数上限系数
GVG_ROLE_RATIO: 1.2, // 贤臣/猛将各职能选择人数上限系数
GVG_PRODUCER_GET: '10&4|11&2', // 贤臣每天发多少令
GVG_FIGHTER_GET: '10&2|11&4', // 猛将每天发多少令
GVG_ROLE_RATIO: 1, // 贤臣/猛将各职能选择人数上限系数
GVG_PRODUCER_GET: '10&6|11&2', // 贤臣每天发多少令
GVG_FIGHTER_GET: '10&2|11&6', // 猛将每天发多少令
GVG_LEAGUE_TECH_LIST: 3, // 科技树解锁队列数量
GVG_LEAGUE_ACTIVE_POINT: '1&2|2&2|3&2|4&2', // 活跃的来源
GVG_SERVICETYPE_VESTIGE: '1&1|2&3', // 单服和跨服随机出几个遗迹点