重置时间

This commit is contained in:
mamengke01
2021-01-12 17:42:11 +08:00
parent 95e9b016c1
commit 24b7a9f888
4 changed files with 23 additions and 14 deletions
+15 -11
View File
@@ -2,7 +2,7 @@
* 体力系统
*/
import { scheduleJob, } from 'node-schedule';
import { scheduleJob, Job } from 'node-schedule';
import { SystemConfigModel } from '../db/SystemConfig';
import PvpDefenseType,{ PvpDefenseModel } from '../db/PvpDefense';
import { PVP } from '../pubUtils/dicParam';
@@ -17,12 +17,13 @@ import { RoleModel } from '../db/Role';
import { MailModel, MailType } from '../db/Mail';
import { pinus } from 'pinus';
import { indexOf } from 'underscore';
import { JsxEmit } from 'typescript';
const PER_SECOND = 1 * 1000;
const PER_DAY = 24 * 60 * 60;
const SETTLE_DIFF = 29 * 60;
const LIMIT_NUM = 1000;
let seasonJobId;
let warJobId;
var seasonJobId;
var warJobId;
export async function init() {
let seasonEndTime = 0;
let systemConfig = await SystemConfigModel.findSystemConfig();
@@ -34,7 +35,7 @@ export async function init() {
} else {
seasonEndTime = systemConfig.seasonEndTime;
if (systemConfig.seasonEndTime - SETTLE_DIFF <= nowSeconds()) {
await setPvpSeasonResult({name: 'simpleJobExample' + systemConfig.seasonNum});
await setPvpSeasonResult({name: 'simpleJobExample' + systemConfig.seasonNum, notSetNext: true });
seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
systemConfig.seasonNum++;
await SystemConfigModel.updateSystemConfig({ seasonEndTime, seasonNum: systemConfig.seasonNum});
@@ -43,19 +44,18 @@ export async function init() {
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
seasonJobId = scheduleJob(settleTime, setPvpSeasonResult);
warJobId = scheduleJob("0 0 0 * * 1", resetPvpWarId);
console.log ('seasonJobId = = = = = = = = =' + seasonJobId);
}
export async function setPvpSeasonResult(obj:{ name:string }) {
export async function setPvpSeasonResult(obj:{ name:string, notSetNext?: boolean }) {
console.log('exce setPvpSeasonResult'+ obj.name);
let { seasonNum, seasonEndTime } = await setNextPvpTime();
let { seasonNum, seasonEndTime } = await setNextPvpTime(obj.notSetNext);
for (let page = 0; page < 3; page++) {
let pvpDefenses = await PvpDefenseModel.getPvpDef(500, page);
let addMails = new Array<MailType>();
let pushMessage = new Array<any>();
for (let pvpDefense of pvpDefenses) {
if (pvpDefense.seasonNum !== seasonNum) {
await setPvpDefResultOnTime(pvpDefense, seasonNum, seasonEndTime, addMails,pushMessage);
await setPvpDefResultOnTime(pvpDefense, seasonNum, seasonEndTime, addMails, pushMessage);
}
}
await MailModel.addMails(addMails);
@@ -145,7 +145,11 @@ export async function resetPvpWarId() {
return await SystemConfigModel.updateSystemConfig({ warId });
}
async function setNextPvpTime() {
async function setNextPvpTime(notSetNext: boolean) {
if (!!notSetNext) {
let systemConfig = await SystemConfigModel.findSystemConfig();
return systemConfig;
}
let seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
let systemConfig = await SystemConfigModel.updateSeason(seasonEndTime);
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
@@ -171,12 +175,12 @@ export async function resetPvpSeasonTime(day: number) {
let warId = warIds[0];//TODO随机地图
seasonEndTime = day * PER_DAY + getTodayZeroPoint();
systemConfig = await SystemConfigModel.createSystemConfig( seasonEndTime, warId );
} else {
} else {
seasonEndTime = day * PER_DAY + getTodayZeroPoint();
seasonNum = systemConfig.seasonNum + 1;
await SystemConfigModel.updateSystemConfig({ seasonEndTime, seasonNum: seasonNum});
}
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
seasonJobId = scheduleJob(settleTime, setPvpSeasonResult)
seasonJobId = scheduleJob(settleTime, setPvpSeasonResult);
return { seasonEndTime, seasonNum };
}