@@ -1,7 +1,7 @@
import { scheduleJob , Job , } from 'node-schedule' ;
import { PVPConfigModel , PVPConfigType } from '../db/SystemConfig' ;
import { nowSeconds , getTimeFun } from '../pubUtils/timeUtil' ;
import { nowSeconds , getTimeFun , getSeconds } from '../pubUtils/timeUtil' ;
import { getTodayGuildActivity , gameData } from '../pubUtils/data' ;
import { pvpSeasonEnd } from './pvpService' ;
import { getAllOnlineRoles , getAllServers , delGuildActivityRank } from './redisService' ;
@@ -23,6 +23,7 @@ import { initMarquee, initMaintenance } from './gmService';
import moment = require ( 'moment' ) ;
import { CounterModel } from '../db/Counter' ;
import { reportOneOnline } from './authenticateService' ;
import { PVP } from '../pubUtils/dicParam' ;
const PER_SECOND = 1 * 1000 ;
const PER_DAY = 24 * 60 * 60 ;
@@ -71,7 +72,13 @@ export async function init() {
}
function getSeasonContinueDay ( seasonNum : number ) {
const pvpSeasonDuring = [ { seasonNum : 1 , day : 7 } , { seasonNum : 2 , day : 15 } , { seasonNum : 3 , day : 30 } , ] ;
const pvpSeasonDuring = PVP . PVP_SEASON_DAYS . split ( '|' ) . map ( cur = > {
let arr = cur . split ( '&' ) ;
let seasonNum = parseInt ( arr [ 0 ] ) ;
let day = parseInt ( arr [ 1 ] ) ;
if ( isNaN ( seasonNum ) || isNaN ( day ) ) return null ;
return { seasonNum , day }
} ) . filter ( cur = > ! ! cur ) ;
let maxDay = 0 ;
for ( let { seasonNum : dicSeasonNum , day } of pvpSeasonDuring ) {
@@ -86,9 +93,12 @@ async function setPvpSeasonJob() {
}
async function setPvpSeason ( isForce? : boolean , hour? : number ) {
let during = hour ? hour * PER_HOUR : null ;
console . log ( ` ******** setPvpSeason1: isForce- ${ isForce } , hour- ${ hour } ` )
let during = hour ? hour * PER_HOUR : null ; // 下一次重置赛季天数
let oldPvpConfig = await PVPConfigModel . findCurPVPConfig ( ) ;
let pvpConfig = oldPvpConfig ;
console . log ( ` ******** setPvpSeason2: during- ${ during } , seasonEndTime- ${ pvpConfig ? . seasonEndTime } , now- ${ nowSeconds ( ) } ` )
if ( ! pvpConfig || pvpConfig . seasonEndTime <= nowSeconds ( ) || isForce ) {
if ( pvpConfig && ! pvpConfig . hasSettleReward ) {
await pvpSeasonEnd ( pvpConfig ) ;
@@ -96,13 +106,28 @@ async function setPvpSeason(isForce?: boolean, hour?: number) {
let lastSeasonNum = pvpConfig ? pvpConfig.seasonNum : 0 ;
let lastSeasonEndTime = pvpConfig ? pvpConfig.seasonEndTime : 0 ;
console . log ( ` ******** setPvpSeason3: lastSeasonNum- ${ lastSeasonNum } , lastSeasonEndTime- ${ lastSeasonEndTime } ` )
let newSeasonStartTime = lastSeasonEndTime ;
let newSeasonStartTime = lastSeasonEndTime + PER_MINUTE ;
if ( ! during ) during = getSeasonContinueDay ( lastSeasonNum + 1 ) * PER_DAY ;
let rewardTime = SETTLE_DIFF_SECONDS ;
if ( nowSeconds ( ) - lastSeasonEndTime > during ) {
if ( nowSeconds ( ) - newSeasonStartTime > during ) {
newSeasonStartTime = < number > getTimeFun ( ) . getDayZeroPoint ( 0 ) ;
}
console . log ( ` ******** setPvpSeason4: newSeasonStartTime- ${ newSeasonStartTime } , during- ${ during } ` )
if ( isForce ) { // debug使用,如果seasonEndTime是未来的,强行结束掉,新赛季从现在开始
if ( newSeasonStartTime > nowSeconds ( ) ) {
newSeasonStartTime = nowSeconds ( ) ;
}
} else { // 不是用debug的情况,如果(因为debug) newSeasonStartTime不是每天0点结算,那么改成lastSeasonEndTime之后的0点开始
let d = new Date ( newSeasonStartTime * 1000 ) ;
if ( d . getHours ( ) != 0 ) {
d . setHours ( 0 , 0 , 0 , 0 ) ;
newSeasonStartTime = getSeconds ( d ) ;
}
}
console . log ( ` ******** setPvpSeason5: isForce- ${ isForce } , newSeasonStartTime- ${ newSeasonStartTime } ` )
let newSeasonNum = await CounterModel . getNewCounter ( COUNTER . PVP_SEASON_NUM ) ;
pvpConfig = await PVPConfigModel . createPVPConfig ( newSeasonNum , newSeasonStartTime , newSeasonStartTime + during - rewardTime , newSeasonStartTime + during - PER_MINUTE ) ;
}
@@ -125,6 +150,7 @@ async function setPvpSeasonMakeRewardJob(pvpConfig: PVPConfigType) {
if ( ! ! seasonMakeRewardTimJobId ) {
seasonMakeRewardTimJobId . cancel ( ) ;
}
if ( ! pvpConfig ) return ;
if ( pvpConfig . seasonRewardTime < nowSeconds ( ) && ! pvpConfig . hasSettleReward ) { // 未发奖励
await pvpSeasonEnd ( pvpConfig ) ;
} else {
@@ -147,7 +173,7 @@ async function setNextSeasonJob(pvpConfig: PVPConfigType) {
* @param hour
*/
export async function resetPvpSeasonTime ( hour : number ) {
return await setPvpSeason ( true ) ;
return await setPvpSeason ( true , hour ) ;
}
export async function reportOnlineSchedule() {