🐞 fix(gvg): 修复城池驻守和机器人刷新逻辑
This commit is contained in:
@@ -7,7 +7,7 @@ import { Application, BackendSession, ChannelService, HandlerService, pinus } fr
|
|||||||
import { resResult, genCode } from "../../../pubUtils/util";
|
import { resResult, genCode } from "../../../pubUtils/util";
|
||||||
import { GVGLeagueModel } from '../../../db/GVGLeague';
|
import { GVGLeagueModel } from '../../../db/GVGLeague';
|
||||||
import { getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
|
import { getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
|
||||||
import { redisAddBattleScore, battleEndSendMessage, calBattleScoreByCe, checkAreaIsInCity, checkGVGBattleStart, checkMoveStatus, getBattleRanksByCity, getBirthAreaOfCity, getGVGWarId, getOppHeroes, getTechKnifeHurt, getTechReviveMinus, initRobots, pushTeamMoveMessage, getGVGCitiesInfo, leaveCity, refreshTeams } from '../../../services/gvg/gvgBattleService';
|
import { redisAddBattleScore, battleEndSendMessage, calBattleScoreByCe, checkAreaIsInCity, checkGVGBattleStart, checkMoveStatus, getBattleRanksByCity, getBirthAreaOfCity, getGVGWarId, getOppHeroes, getTechKnifeHurt, getTechReviveMinus, initRobots, pushTeamMoveMessage, getGVGCitiesInfo, leaveCity, refreshTeams, checkEnterCityTime } from '../../../services/gvg/gvgBattleService';
|
||||||
import { getGVGBattleData } from '../../../services/gvg/gvgBattleMemory';
|
import { getGVGBattleData } from '../../../services/gvg/gvgBattleMemory';
|
||||||
import { GVGBattleRecModel } from '../../../db/GVGBattleRec';
|
import { GVGBattleRecModel } from '../../../db/GVGBattleRec';
|
||||||
import { getFightTimeByPeriod } from '../../../services/gvg/gvgFightService';
|
import { getFightTimeByPeriod } from '../../../services/gvg/gvgFightService';
|
||||||
@@ -182,19 +182,21 @@ export class GVGBattleHandler {
|
|||||||
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
|
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
|
||||||
|
|
||||||
let groupKey = await getGroupKey(serverId);
|
let groupKey = await getGroupKey(serverId);
|
||||||
|
let city = await GVGCityModel.findByCityId(configId, groupKey, cityId);
|
||||||
|
|
||||||
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
||||||
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
|
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
|
||||||
|
|
||||||
|
if(!checkEnterCityTime(city, myLeague.leagueCode)) return resResult(STATUS.GVG_NOT_ENTER_CITY_TIME);
|
||||||
|
|
||||||
// 初始化本城池的守擂机器人
|
// 初始化本城池的守擂机器人
|
||||||
await initRobots(configId, groupKey, cityId);
|
await initRobots(configId, groupKey, city||{ cityId, guardLeague: '' });
|
||||||
// 每赛季初自己的几支队伍恢复耐久、城市、顺便更新一下自己的玩家名、联军
|
// 每赛季初自己的几支队伍恢复耐久、城市、顺便更新一下自己的玩家名、联军
|
||||||
let teams = await refreshTeams(configId, groupKey, roleId, roleName, guildCode, myLeague);
|
let teams = await refreshTeams(configId, groupKey, roleId, roleName, guildCode, myLeague);
|
||||||
|
|
||||||
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
||||||
let originCityId = gvgUserData?.cityId||0;
|
let originCityId = gvgUserData?.cityId||0;
|
||||||
// 检测是否已经在城池中,玩家不在这个城池中时进行处理
|
// 检测是否已经在城池中,玩家不在这个城池中时进行处理
|
||||||
let city: GVGCityType;
|
|
||||||
if (originCityId != cityId) {
|
if (originCityId != cityId) {
|
||||||
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
||||||
if(gvgUserData?.cityId > 0) { // 如果leaveCity没有退出成功,玩家还遗留在上一座城中,做一下处理
|
if(gvgUserData?.cityId > 0) { // 如果leaveCity没有退出成功,玩家还遗留在上一座城中,做一下处理
|
||||||
@@ -213,7 +215,6 @@ export class GVGBattleHandler {
|
|||||||
teamResult.push(new MyTeamInfo(team));
|
teamResult.push(new MyTeamInfo(team));
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if(!city) city = await GVGCityModel.findByCityId(configId, groupKey, cityId);
|
|
||||||
let areaId = getBirthAreaOfCity(city, myLeague.leagueCode);
|
let areaId = getBirthAreaOfCity(city, myLeague.leagueCode);
|
||||||
team = await GVGTeamModel.enterCity(team.teamCode, cityId, areaId, groupKey);
|
team = await GVGTeamModel.enterCity(team.teamCode, cityId, areaId, groupKey);
|
||||||
if(!team) continue;
|
if(!team) continue;
|
||||||
@@ -299,12 +300,13 @@ export class GVGBattleHandler {
|
|||||||
const { cityId, teamCode } = msg;
|
const { cityId, teamCode } = msg;
|
||||||
|
|
||||||
let groupKey = await getGroupKey(serverId);
|
let groupKey = await getGroupKey(serverId);
|
||||||
|
let { configId } = getGVGPeriodData();
|
||||||
|
|
||||||
let myTeam = await GVGTeamModel.findMyTeamByCode(roleId, teamCode);
|
let myTeam = await GVGTeamModel.findMyTeamByCode(roleId, teamCode);
|
||||||
if(!myTeam) return resResult(STATUS.GVG_TEAM_NOT_FOUND);
|
if(!myTeam) return resResult(STATUS.GVG_TEAM_NOT_FOUND);
|
||||||
if(myTeam.cityId != cityId) return resResult(STATUS.GVG_BATTLE_IS_NOT_IN_CITY);
|
if(myTeam.cityId != cityId) return resResult(STATUS.GVG_BATTLE_IS_NOT_IN_CITY);
|
||||||
|
|
||||||
let teams = await GVGTeamModel.findByAreaId(groupKey, cityId, myTeam.areaId);
|
let teams = await GVGTeamModel.findByAreaId(configId, groupKey, cityId, myTeam.areaId);
|
||||||
let points: GVGTeamInListOnPoint[] = [], players: GVGTeamInList[] = [];
|
let points: GVGTeamInListOnPoint[] = [], players: GVGTeamInList[] = [];
|
||||||
let pointIds = gameData.gvgPointByAreaId.get(myTeam.areaId)||[];
|
let pointIds = gameData.gvgPointByAreaId.get(myTeam.areaId)||[];
|
||||||
for(let pointId of pointIds) {
|
for(let pointId of pointIds) {
|
||||||
@@ -439,6 +441,8 @@ export class GVGBattleHandler {
|
|||||||
|
|
||||||
let { configId, period } = getGVGPeriodData();
|
let { configId, period } = getGVGPeriodData();
|
||||||
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
|
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
|
||||||
|
let { startFightTime } = getFightTimeByPeriod(period);
|
||||||
|
if(startFightTime > nowSeconds()) return resResult(STATUS.GVG_NOT_BATTLE_TIME);
|
||||||
|
|
||||||
let groupKey = await getGroupKey(serverId);
|
let groupKey = await getGroupKey(serverId);
|
||||||
|
|
||||||
@@ -636,7 +640,7 @@ export class GVGBattleHandler {
|
|||||||
let groupKey = await getGroupKey(serverId);
|
let groupKey = await getGroupKey(serverId);
|
||||||
let serverType = await getGVGServerType(serverId);
|
let serverType = await getGVGServerType(serverId);
|
||||||
|
|
||||||
const cities = await GVGCityModel.findByConfig(configId, groupKey);
|
const cities = await GVGCityModel.findByConfigAndGroup(configId, groupKey);
|
||||||
const points = await GVGCityAreaPointModel.findByConfig(configId, groupKey);
|
const points = await GVGCityAreaPointModel.findByConfig(configId, groupKey);
|
||||||
|
|
||||||
let result: { cityId: number, guardLeagueName: string, areas: { areaId: number, points: { pointId: number, guardLeagueName: string }[] }[] }[] = [];
|
let result: { cityId: number, guardLeagueName: string, areas: { areaId: number, points: { pointId: number, guardLeagueName: string }[] }[] }[] = [];
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { GVGLeagueModel, GVGLeagueType } from "../../db/GVGLeague";
|
|||||||
import { GVGTeamModel, GVGTeamType, GVGTeamUpdate } from "../../db/GVGTeam";
|
import { GVGTeamModel, GVGTeamType, GVGTeamUpdate } from "../../db/GVGTeam";
|
||||||
import { GVGCityModel, GVGCityType } from "../../db/GVGCity";
|
import { GVGCityModel, GVGCityType } from "../../db/GVGCity";
|
||||||
import { gameData, getGVGBattleRankReward } from "../../pubUtils/data";
|
import { gameData, getGVGBattleRankReward } from "../../pubUtils/data";
|
||||||
import { GVG_AREA_TYPE, GVG_BATTLE_RANK_TYPE, GVG_TECH_TYPE, MAIL_TYPE, PUSH_ROUTE, REDIS_KEY, STATUS } from "../../consts";
|
import { GVG_AREA_TYPE, GVG_BATTLE_RANK_TYPE, GVG_PERIOD, GVG_TECH_TYPE, MAIL_TYPE, PUSH_ROUTE, REDIS_KEY, STATUS } from "../../consts";
|
||||||
import { getTimeFun, nowSeconds } from "../../pubUtils/timeUtil";
|
import { getTimeFun, nowSeconds } from "../../pubUtils/timeUtil";
|
||||||
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
|
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
|
||||||
import { getGVGBattleData, getGVGBattleMap } from "./gvgBattleMemory";
|
import { getGVGBattleData, getGVGBattleMap } from "./gvgBattleMemory";
|
||||||
@@ -23,6 +23,7 @@ import { GVGCityAreaPointModel } from "../../db/GVGCityAreaPoint";
|
|||||||
import { addCityGuardMessage } from "./gvgRecService";
|
import { addCityGuardMessage } from "./gvgRecService";
|
||||||
import { GVGUserDataModel } from "../../db/GVGUserData";
|
import { GVGUserDataModel } from "../../db/GVGUserData";
|
||||||
import { RoleModel } from "../../db/Role";
|
import { RoleModel } from "../../db/Role";
|
||||||
|
import { getFightTimeByPeriod } from "./gvgFightService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取本联军上周占领的城池
|
* 获取本联军上周占领的城池
|
||||||
@@ -67,12 +68,33 @@ export function getGVGTeamMemInfo(team: GVGTeamType): GVGTeamMem {
|
|||||||
return teamMem;
|
return teamMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 重新进入城池/复活 所在的区域
|
||||||
|
* @param city GVGCity
|
||||||
|
* @param leagueCode 联军id
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export function getBirthAreaOfCity(city: GVGCityType, leagueCode: string) {
|
export function getBirthAreaOfCity(city: GVGCityType, leagueCode: string) {
|
||||||
let isGuard = city.guardLeague == leagueCode;
|
let isGuard = city.guardLeague == leagueCode;
|
||||||
let dicGVGCity = gameData.gvgCity.get(city.cityId);
|
let dicGVGCity = gameData.gvgCity.get(city.cityId);
|
||||||
return isGuard? dicGVGCity.defenseBirth: dicGVGCity.attackBirth;
|
return isGuard? dicGVGCity.defenseBirth: dicGVGCity.attackBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家是否可以进入城池
|
||||||
|
* @param city
|
||||||
|
* @param leagueCode
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function checkEnterCityTime(city: GVGCityType, leagueCode: string) {
|
||||||
|
let isGuard = city?.guardLeague == leagueCode;
|
||||||
|
let { startFightTime, endFightTime } = getFightTimeByPeriod(GVG_PERIOD.BATTLE);
|
||||||
|
if(isGuard && startFightTime - GVG.GVG_GUARD_START_TIME > nowSeconds()) return false;
|
||||||
|
if(!isGuard && startFightTime > nowSeconds()) return false;
|
||||||
|
if(endFightTime < nowSeconds()) return false;
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// guild.gvgBattleHandler.startMove 检测
|
// guild.gvgBattleHandler.startMove 检测
|
||||||
export function checkMoveStatus(team: GVGTeamType, cityId: number, areaId: number) {
|
export function checkMoveStatus(team: GVGTeamType, cityId: number, areaId: number) {
|
||||||
if(!team) return STATUS.GVG_BATTLE_TEAM_NOT_FOUND;
|
if(!team) return STATUS.GVG_BATTLE_TEAM_NOT_FOUND;
|
||||||
@@ -86,7 +108,9 @@ export function checkMoveStatus(team: GVGTeamType, cityId: number, areaId: numbe
|
|||||||
return STATUS.SUCCESS;
|
return STATUS.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initRobots(configId: number, groupKey: string, cityId: number) {
|
export async function initRobots(configId: number, groupKey: string, city: GVGCityType | { cityId: number, guardLeague: string }) {
|
||||||
|
let { cityId, guardLeague = '' } = city;
|
||||||
|
if(guardLeague) return [];
|
||||||
let robotTeams = await GVGTeamModel.findRobotTeams(groupKey, cityId);
|
let robotTeams = await GVGTeamModel.findRobotTeams(groupKey, cityId);
|
||||||
let updateDicPoints: DicGVGAreaPoint[] = [];
|
let updateDicPoints: DicGVGAreaPoint[] = [];
|
||||||
let { areaIds = []} = gameData.gvgCity.get(cityId);
|
let { areaIds = []} = gameData.gvgCity.get(cityId);
|
||||||
@@ -138,6 +162,16 @@ export async function refreshTeams(configId: number, groupKey: string, roleId: s
|
|||||||
return teams
|
return teams
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 离开城池
|
||||||
|
* 当玩家占领据点的时候,可以保留据点;不占领的时候,不保留;退出游戏的时候,全不保留
|
||||||
|
* @param isForce 是否是玩家关闭游戏的那种离开
|
||||||
|
* @param roleId
|
||||||
|
* @param serverId
|
||||||
|
* @param guildCode
|
||||||
|
* @param myLeague
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export async function leaveCity(isForce: boolean, roleId: string, serverId: number, guildCode: string, myLeague?: GVGLeagueType) {
|
export async function leaveCity(isForce: boolean, roleId: string, serverId: number, guildCode: string, myLeague?: GVGLeagueType) {
|
||||||
if(!myLeague) myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
if(!myLeague) myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
||||||
if(!myLeague) return;
|
if(!myLeague) return;
|
||||||
@@ -388,6 +422,7 @@ export async function gvgBattleSeconds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function gvgBattleEnd() {
|
export async function gvgBattleEnd() {
|
||||||
|
console.log('######### gvgBattleEnd #######')
|
||||||
let { configId } = getGVGConfig();
|
let { configId } = getGVGConfig();
|
||||||
let guardLeagueCnt = new Map<string, number>();
|
let guardLeagueCnt = new Map<string, number>();
|
||||||
|
|
||||||
@@ -397,6 +432,11 @@ export async function gvgBattleEnd() {
|
|||||||
let [,, groupKey, _cityId] = key.split(':');
|
let [,, groupKey, _cityId] = key.split(':');
|
||||||
return { groupKey, cityId: parseInt(_cityId) };
|
return { groupKey, cityId: parseInt(_cityId) };
|
||||||
}).sort((a, b) => b.cityId - a.cityId);
|
}).sort((a, b) => b.cityId - a.cityId);
|
||||||
|
let lastCities = await GVGCityModel.findByConfig(configId);
|
||||||
|
for(let { cityId, groupKey } of lastCities) {
|
||||||
|
let hasKey = rankKeys.find(cur => cur.cityId == cityId && cur.groupKey == groupKey);
|
||||||
|
if(!hasKey) rankKeys.push({ cityId, groupKey });
|
||||||
|
}
|
||||||
|
|
||||||
for(let { groupKey, cityId } of rankKeys) {
|
for(let { groupKey, cityId } of rankKeys) {
|
||||||
let dicCity = gameData.gvgCity.get(cityId);
|
let dicCity = gameData.gvgCity.get(cityId);
|
||||||
@@ -409,15 +449,25 @@ export async function gvgBattleEnd() {
|
|||||||
let rankInfo = <LeagueRankInfo>obj;
|
let rankInfo = <LeagueRankInfo>obj;
|
||||||
let cnt = guardLeagueCnt.get(rankInfo.code)||0;
|
let cnt = guardLeagueCnt.get(rankInfo.code)||0;
|
||||||
if(cnt < GVG.GVG_CITY_OCCUPIED_NUMBER) {
|
if(cnt < GVG.GVG_CITY_OCCUPIED_NUMBER) {
|
||||||
await GVGCityModel.guardCity(configId, groupKey, cityId, rankInfo);
|
await addGuardCity(configId, groupKey, cityId, rankInfo.code);
|
||||||
let dicCityAdd = gameData.gvgCityAdd.get(dicCity.cityType);
|
|
||||||
let league = await GVGLeagueModel.findByCodeWithoutPopulate(rankInfo.code);
|
|
||||||
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, rankInfo.code, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward }, league);
|
|
||||||
await addCityGuardMessage(league, cityId);
|
|
||||||
guardLeagueCnt.set(rankInfo.code, cnt + 1);
|
guardLeagueCnt.set(rankInfo.code, cnt + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let guardCity = lastCities.find(city => city.cityId == cityId && city.groupKey == groupKey);
|
||||||
|
if(guardCity) {
|
||||||
|
let cnt = guardLeagueCnt.get(guardCity.guardLeague)||0;
|
||||||
|
if(cnt < GVG.GVG_CITY_OCCUPIED_NUMBER) {
|
||||||
|
await addGuardCity(configId, groupKey, cityId, guardCity.guardLeague);
|
||||||
|
guardLeagueCnt.set(guardCity.guardLeague, cnt + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(let { cityId, groupKey, guardLeague } of lastCities) {
|
||||||
|
let hasKey = rankKeys.find(cur => cur.cityId == cityId && cur.groupKey == groupKey);
|
||||||
|
if(hasKey) continue;
|
||||||
|
await addGuardCity(configId, groupKey, cityId, guardLeague);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 联军排行榜发放奖励
|
// 联军排行榜发放奖励
|
||||||
@@ -450,6 +500,16 @@ export async function gvgBattleEnd() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function addGuardCity(configId: number, groupKey: string, cityId: number, leagueCode: string) {
|
||||||
|
let dicCity = gameData.gvgCity.get(cityId);
|
||||||
|
let dicCityAdd = gameData.gvgCityAdd.get(dicCity.cityType);
|
||||||
|
let league = await GVGLeagueModel.findByCodeWithoutPopulate(leagueCode);
|
||||||
|
await GVGCityModel.guardCity(configId, groupKey, cityId, league);
|
||||||
|
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, leagueCode, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward }, league);
|
||||||
|
await addCityGuardMessage(league, cityId);
|
||||||
|
await GVGLeagueModel.removeAuto(leagueCode);
|
||||||
|
}
|
||||||
|
|
||||||
// —————————— 定时器相关 end —————————— //
|
// —————————— 定时器相关 end —————————— //
|
||||||
|
|
||||||
// —————————— 推送相关 —————————— //
|
// —————————— 推送相关 —————————— //
|
||||||
|
|||||||
@@ -899,57 +899,59 @@ export async function initHiddenDataSchedule(isInit: boolean, data?: HiddenDataM
|
|||||||
// —————————————— 配表兼容 end —————————————— //
|
// —————————————— 配表兼容 end —————————————— //
|
||||||
|
|
||||||
// —————————————— gvg start —————————————— //
|
// —————————————— gvg start —————————————— //
|
||||||
|
let gvgBattleSecondJob: Job; // gvg每5秒的定时器
|
||||||
|
let gvgBattleCatapultJob: Job; // gvg投石车定时器
|
||||||
|
|
||||||
export async function initGVGConfigSchedule() {
|
export async function initGVGConfigSchedule() {
|
||||||
let config = await GVGConfigModel.findConfig();
|
let config = await GVGConfigModel.findConfig();
|
||||||
if(!config || nowSeconds() > config.scheduleTime) {
|
if(!config || nowSeconds() > config.scheduleTime) {
|
||||||
config = await createNewGVGConfig();
|
config = await createNewGVGConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(scheduledJobs[`gvgTeam`]) scheduledJobs[`gvgTeam`].cancel();
|
||||||
scheduleJob(`gvgTeam`, config.teamTime * 1000, async () => {
|
scheduleJob(`gvgTeam`, config.teamTime * 1000, async () => {
|
||||||
await pinus.app.rpc.guild.guildRemote.setGVGConfig.broadcast(config);
|
await pinus.app.rpc.guild.guildRemote.setGVGConfig.broadcast(config);
|
||||||
})
|
})
|
||||||
|
if(scheduledJobs[`gvgConfig`]) scheduledJobs[`gvgConfig`].cancel();
|
||||||
scheduleJob(`gvgConfig`, config.scheduleTime * 1000, createNewGVGConfig);
|
scheduleJob(`gvgConfig`, config.scheduleTime * 1000, createNewGVGConfig);
|
||||||
|
|
||||||
if(nowSeconds() > config.prepareTime) {
|
if(nowSeconds() > config.prepareTime) {
|
||||||
initLeaguePrepare();
|
initLeaguePrepare();
|
||||||
} else {
|
} else {
|
||||||
|
if(scheduledJobs[`gvgPrepare`]) scheduledJobs[`gvgPrepare`].cancel();
|
||||||
scheduleJob(`gvgPrepare`, config.prepareTime * 1000, initLeaguePrepare);
|
scheduleJob(`gvgPrepare`, config.prepareTime * 1000, initLeaguePrepare);
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleJob('gvgFightSchedule', '0 0 22 * * ?', saveVestigeRankSchedule);
|
if(scheduledJobs[`gvgFight`]) scheduledJobs[`gvgFight`].cancel();
|
||||||
|
scheduleJob(`gvgFight`, '0 0 22 * * ?', saveVestigeRankSchedule);
|
||||||
|
|
||||||
let { startFightTime, endFightTime } = getFightTimeByPeriod(GVG_PERIOD.BATTLE, config.battleTime);
|
let { startFightTime, endFightTime } = getFightTimeByPeriod(GVG_PERIOD.BATTLE, config.battleTime);
|
||||||
|
|
||||||
if(nowSeconds() > startFightTime && nowSeconds() < endFightTime) {
|
if(nowSeconds() > startFightTime - GVG.GVG_GUARD_START_TIME && nowSeconds() < endFightTime) {
|
||||||
if(gvgBattleSecondJob) gvgBattleSecondJob.cancel();
|
if(gvgBattleSecondJob) gvgBattleSecondJob.cancel();
|
||||||
gvgBattleSecondJob = scheduleJob('gvgBattleSecondJob', '*/5 * * * * *', gvgBattleSecondSchedule);
|
gvgBattleSecondJob = scheduleJob('gvgBattleSecond', '*/5 * * * * *', gvgBattleSecondSchedule);
|
||||||
if(gvgBattleCatapultJob) gvgBattleCatapultJob.cancel();
|
if(gvgBattleCatapultJob) gvgBattleCatapultJob.cancel();
|
||||||
gvgBattleCatapultJob = scheduleJob('gvgBattleCatapultJob', `*/${GVG.GVG_CATAPULT_TIME} * * * * *`, gvgBattleCatapult);
|
gvgBattleCatapultJob = scheduleJob('gvgBattleCatapult', `*/${GVG.GVG_CATAPULT_TIME} * * * * *`, gvgBattleCatapult);
|
||||||
} else {
|
} else {
|
||||||
scheduleJob(`gvgBattleStartSchedule`, (startFightTime - GVG.GVG_GUARD_START_TIME) * 1000, gvgBattleStartSchedule);
|
scheduleJob(`gvgBattleStartSchedule`, (startFightTime - GVG.GVG_GUARD_START_TIME) * 1000, gvgBattleStartSchedule);
|
||||||
}
|
}
|
||||||
|
if(scheduledJobs[`gvgBattleEndSchedule`]) scheduledJobs[`gvgBattleEndSchedule`].cancel();
|
||||||
scheduleJob(`gvgBattleEndSchedule`, endFightTime * 1000, gvgBattleEndSchedule);
|
scheduleJob(`gvgBattleEndSchedule`, endFightTime * 1000, gvgBattleEndSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
let gvgBattleSecondJob: Job; // gvg每5秒的定时器
|
|
||||||
let gvgBattleCatapultJob: Job; // gvg投石车定时器
|
|
||||||
|
|
||||||
// gvg激战期开始定时器
|
// gvg激战期开始定时器
|
||||||
export async function gvgBattleStartSchedule() {
|
export async function gvgBattleStartSchedule() {
|
||||||
|
console.log('##### gvgBattleStartSchedule', Date.now())
|
||||||
if(gvgBattleSecondJob) gvgBattleSecondJob.cancel();
|
if(gvgBattleSecondJob) gvgBattleSecondJob.cancel();
|
||||||
gvgBattleSecondJob = scheduleJob('gvgBattleSecondJob', '*/5 * * * * *', gvgBattleSecondSchedule);
|
gvgBattleSecondJob = scheduleJob('gvgBattleSecond', '*/5 * * * * *', gvgBattleSecondSchedule);
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
console.log('############')
|
|
||||||
if(gvgBattleCatapultJob) gvgBattleCatapultJob.cancel();
|
|
||||||
gvgBattleCatapultJob = scheduleJob('gvgBattleCatapultJob', `*/${GVG.GVG_CATAPULT_TIME} * * * * *`, gvgBattleCatapult);
|
|
||||||
// 初始化投石车
|
// 初始化投石车
|
||||||
let guildServers = pinus.app.getServersByType('guild');
|
let guildServers = pinus.app.getServersByType('guild');
|
||||||
if(guildServers.length > 0) {
|
if(guildServers.length > 0) {
|
||||||
pinus.app.rpc.guild.guildRemote.gvgBattleStart.toServer(getRandSingleEelm(guildServers).id);
|
pinus.app.rpc.guild.guildRemote.gvgBattleStart.toServer(getRandSingleEelm(guildServers).id);
|
||||||
}
|
}
|
||||||
|
if(gvgBattleCatapultJob) gvgBattleCatapultJob.cancel();
|
||||||
}, 60);
|
gvgBattleCatapultJob = scheduleJob('gvgBattleCatapult', `*/${GVG.GVG_CATAPULT_TIME} * * * * *`, gvgBattleCatapult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -345,6 +345,8 @@ export const STATUS = {
|
|||||||
GVG_NOT_BATTLE_PERIOD: { code: 21339, simStr: '您只能在激战期进行此操作' },
|
GVG_NOT_BATTLE_PERIOD: { code: 21339, simStr: '您只能在激战期进行此操作' },
|
||||||
GVG_FIELD_HAS_PLANT: { code: 21340, simStr: '该田已种植' },
|
GVG_FIELD_HAS_PLANT: { code: 21340, simStr: '该田已种植' },
|
||||||
GVG_NOT_JOIN_LEAGUE: { code: 21341, simStr: '您未加入联军' },
|
GVG_NOT_JOIN_LEAGUE: { code: 21341, simStr: '您未加入联军' },
|
||||||
|
GVG_NOT_ENTER_CITY_TIME: { code: 21342, simStr: '您此时不可进入城池' },
|
||||||
|
GVG_NOT_BATTLE_TIME: { code: 21343, simStr: '您此时只能进驻据点不可挑战' },
|
||||||
|
|
||||||
// GVG征战中原
|
// GVG征战中原
|
||||||
GVG_VESTIGE_ERR: { code: 21350, simStr: '今日未开放该遗迹' },
|
GVG_VESTIGE_ERR: { code: 21350, simStr: '今日未开放该遗迹' },
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import BaseModel from "./BaseModel";
|
import BaseModel from "./BaseModel";
|
||||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||||
import { LeagueRankInfo } from "../domain/rank";
|
import { GVGLeagueType } from "./GVGLeague";
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
@@ -96,17 +96,22 @@ export default class GVGCity extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 占领城池
|
// 占领城池
|
||||||
public static async guardCity(configId: number, groupKey: string, cityId: number, league: LeagueRankInfo) {
|
public static async guardCity(configId: number, groupKey: string, cityId: number, league: GVGLeagueType) {
|
||||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId: configId + 1, cityId, groupKey }, { $set: {
|
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId: configId + 1, cityId, groupKey }, { $set: {
|
||||||
hasGuard: true, guardLeague: league.code, guardLeagueName: league.name, guardLeagueIcon: league.icon
|
hasGuard: true, guardLeague: league.leagueCode, guardLeagueName: league.name, guardLeagueIcon: league.icon
|
||||||
}, $setOnInsert: { userCnt: 0, players: [] } }, { upsert: true, new: true }).lean();
|
}, $setOnInsert: { userCnt: 0, players: [] } }, { upsert: true, new: true }).lean();
|
||||||
return city;
|
return city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findByConfig(configId: number, groupKey: string) {
|
public static async findByConfigAndGroup(configId: number, groupKey: string) {
|
||||||
const cities: GVGCityType[] = await GVGCityModel.find({ configId, groupKey, hasGuard: true }).lean();
|
const cities: GVGCityType[] = await GVGCityModel.find({ configId, groupKey, hasGuard: true }).lean();
|
||||||
return cities
|
return cities
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async findByConfig(configId: number) {
|
||||||
|
const cities: GVGCityType[] = await GVGCityModel.find({ configId, hasGuard: true }).lean();
|
||||||
|
return cities
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -199,6 +199,11 @@ export default class GVGLeague extends BaseModel {
|
|||||||
let leagues: GVGLeagueType[] = await GVGLeagueModel.find({ isAuto: true, status: 1 }).lean();
|
let leagues: GVGLeagueType[] = await GVGLeagueModel.find({ isAuto: true, status: 1 }).lean();
|
||||||
return leagues
|
return leagues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async removeAuto(leagueCode: string) {
|
||||||
|
let league: GVGLeagueType = await GVGLeagueModel.findOneAndUpdate({ leagueCode }, { $set: { isAuto: false } }).lean();
|
||||||
|
return league
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GVGLeagueModel = getModelForClass(GVGLeague);
|
export const GVGLeagueModel = getModelForClass(GVGLeague);
|
||||||
|
|||||||
@@ -212,19 +212,15 @@ export default class GVGTeam extends BaseModel {
|
|||||||
|
|
||||||
// 每赛季初刷新机器人
|
// 每赛季初刷新机器人
|
||||||
public static async initRobots(configId: number, groupKey: string, cityId: number, dicPoints: DicGVGAreaPoint[], lv: number) {
|
public static async initRobots(configId: number, groupKey: string, cityId: number, dicPoints: DicGVGAreaPoint[], lv: number) {
|
||||||
await GVGTeamModel.bulkWrite(dicPoints.map(({ pointId, areaId, name, head, spine, ce, durability }) => {
|
let teams: GVGTeamType[] = [];
|
||||||
return {
|
for(let { pointId, areaId, name, head, spine, ce, durability } of dicPoints) {
|
||||||
updateOne: {
|
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ groupKey, cityId, areaId, pointId }, {
|
||||||
filter: { groupKey, cityId, areaId, pointId },
|
$setOnInsert: {teamCode: genCode(8), maxDurability: durability, roleName: name, head, spine, frame: EXTERIOR.EXTERIOR_FACECASE, lineupCe: ce, isRobot: true, lv, isBroken: false, startMoveTime: 0, stopMoveTime: 0, guildCode: '', leagueCode: '', leagueName: '', fromAreaId: areaId,
|
||||||
update: { $setOnInsert: {
|
}, $set: { configId, durability }
|
||||||
teamCode: genCode(8), maxDurability: durability, roleName: name, head, spine, frame: EXTERIOR.EXTERIOR_FACECASE, lineupCe: ce, isRobot: true, lv,
|
}, { new: true, upsert: true }).lean();
|
||||||
isBroken: false, startMoveTime: 0, stopMoveTime: 0, guildCode: '', leagueCode: '', leagueName: '', fromAreaId: areaId,
|
teams.push(team);
|
||||||
}, $set: { configId, durability } },
|
|
||||||
upsert: true
|
|
||||||
}
|
}
|
||||||
}
|
return teams;
|
||||||
}));
|
|
||||||
return await this.findRobotTeams(groupKey, cityId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findCatapultTeams(groupKey: string, cityId: number) {
|
public static async findCatapultTeams(groupKey: string, cityId: number) {
|
||||||
@@ -304,8 +300,8 @@ export default class GVGTeam extends BaseModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findByAreaId(groupKey: string, cityId: number, areaId: number) {
|
public static async findByAreaId(configId: number, groupKey: string, cityId: number, areaId: number) {
|
||||||
const team: GVGTeamType[] = await GVGTeamModel.find({ groupKey, cityId, areaId, stopMoveTime: { $lte: nowSeconds() }, isBroken: false }).lean();
|
const team: GVGTeamType[] = await GVGTeamModel.find({ configId, groupKey, cityId, areaId, stopMoveTime: { $lte: nowSeconds() }, isBroken: false }).lean();
|
||||||
return team;
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export interface DicGVGAreaPoint {
|
|||||||
// 位置
|
// 位置
|
||||||
readonly pointPosition: string;
|
readonly pointPosition: string;
|
||||||
// 守卫名
|
// 守卫名
|
||||||
readonly name: number;
|
readonly name: string;
|
||||||
// 守卫头像
|
// 守卫头像
|
||||||
readonly head: number;
|
readonly head: number;
|
||||||
// 守卫形象
|
// 守卫形象
|
||||||
|
|||||||
Reference in New Issue
Block a user