HJ_Server/src/public/scheduler/scheduler_zhanling.ts
2023-12-13 20:51:17 +08:00

43 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {PublicShared} from '../../shared/public/public';
import {Scheduler, schedulerType} from './scheduler';
export class SchedulerZhanLing extends Scheduler {
id: schedulerType = 'zhanling';
name = '战令';
async read() {
if (PublicShared.getOpenServerDay() < G.gc.zhanling.eventOpen.day) {
this.startTime = PublicShared.getToDayZeroTime(G.openTime) + G.gc.zhanling.eventOpen.day * 24 * 3600;
this.isReady = false;
return
}
let data = await this.db.findOne({type: this.id});
if (!data) {
// 开服时间整除战令周期
let round = Math.floor(PublicShared.getOpenServerDay() / G.gc.zhanling.eventOpen.day)
let prev_run_time = PublicShared.getToDayZeroTime(G.openTime) + round * G.gc.zhanling.eventOpen.day * 86400
this.db.updateOne({type: this.id}, {$set: {lastRunTime: prev_run_time, round: round}}, {upsert: true});
}
if (!data || G.time > PublicShared.getToDayZeroTime(data.lastRunTime) + 24 * 3600 * G.gc.zhanling.eventOpen.day) {
let round = Math.floor(PublicShared.getOpenServerDay() / G.gc.zhanling.eventOpen.day)
this.startTime = PublicShared.getToDayZeroTime(G.openTime) + (round + 1) * G.gc.zhanling.eventOpen.day * 86400
} else {
this.startTime = PublicShared.getToDayZeroTime(data.lastRunTime) + 24 * 3600 * G.gc.zhanling.eventOpen.day;
}
this.isReady = false;
}
async start() {
// 开服时间整除战令周期
let round = Math.floor(PublicShared.getOpenServerDay() / G.gc.zhanling.eventOpen.day)
// lastRunTime仅储存最大值问题记录: 本地多人启动服务时,有调用此定时器的情况下,时间会混乱。
await this.db.updateOne({type: this.id}, {$set: {round: round}, $max: {lastRunTime: G.time}}, {upsert: true});
this.startTime = PublicShared.getToDayZeroTime() + 24 * 3600 * G.gc.zhanling.eventOpen.day;
this.isStart = false;
G.mongodb.collection('zhanling').updateMany({type: 'round'}, {$set: {data: {}}});
}
}