pvp:重写pvp定时器任务逻辑
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
|
||||
import { scheduleJob, Job, scheduledJobs } from 'node-schedule';
|
||||
import { SystemConfigModel } from '../db/SystemConfig';
|
||||
import PvpDefenseType,{ PvpDefenseModel } from '../db/PvpDefense';
|
||||
import { scheduleJob, Job, scheduledJobs } from 'node-schedule';
|
||||
import { PVPConfigModel } from '../db/SystemConfig';
|
||||
import PvpDefenseType, { PvpDefenseModel } from '../db/PvpDefense';
|
||||
import { PVP } from '../pubUtils/dicParam';
|
||||
import { nowSeconds, getAge, getTimeFun } from '../pubUtils/timeUtil';
|
||||
import { getPvpGkWarIds, getPvpRankRewards, getPvpHeroRewards, getResultMaxRank, getTodayGuildActivity } from '../pubUtils/data';
|
||||
import { deepCopy, resResult, getRandSingleEelm } from '../pubUtils/util';
|
||||
import { getLvByScore } from './pvpService';
|
||||
import { getAllOnlineRoles, getAllServers, initSingleRank, delGuildActivityRank } from './redisService';
|
||||
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE, TIME_OUTPUT_TYPE, REFRESH_TIME, SEND_NAME } from '../consts';
|
||||
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE, TIME_OUTPUT_TYPE, REFRESH_TIME, SEND_NAME, SERVER_OPEN_TIME, COUNTER } from '../consts';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { MailModel, MailType } from '../db/Mail';
|
||||
import { pinus } from 'pinus';
|
||||
@@ -28,44 +28,41 @@ import { Rank } from './rankService';
|
||||
import { checkTask } from './taskService';
|
||||
import { everydayRefresh } from './connectorService';
|
||||
import { initMarquee, initMaintenance } from './gmService';
|
||||
import moment = require('moment');
|
||||
import { CounterModel } from '../db/Counter';
|
||||
|
||||
const PER_SECOND = 1 * 1000;
|
||||
const PER_DAY = 24 * 60 * 60;
|
||||
const SETTLE_DIFF = 29 * 60;
|
||||
const pageNum = 500;
|
||||
const PER_MINUTE = 1 * 60;
|
||||
var seasonJobId: Job;
|
||||
var seasonMakeRewardTimJobId: Job;
|
||||
var warJobId: Job;
|
||||
var seasonEndTimeJobId: Job;
|
||||
var seasonRefreshTimeJobId: Job;
|
||||
let guildWeeklyJobId: Job;
|
||||
let guildActSecondsJobId: Job; // 军团活动开启后每10(or 1)秒循环的定时任务,到结束活动清除
|
||||
let guildActEndJobId: Job; // 军团活动开启后每10(or 1)秒循环的定时任务,到结束活动清除
|
||||
let pvpMakeRewardInterval = null;
|
||||
let pvpRefreshInterval = null;
|
||||
|
||||
/**
|
||||
* 服务器启动即开启定时任务,结算时常是23-24点,实际结算的时间点是23:31分钟
|
||||
*/
|
||||
export async function init() {
|
||||
let seasonEndTime = 0;
|
||||
let systemConfig = await SystemConfigModel.findSystemConfig();//系统全局参数表
|
||||
if (!systemConfig) {
|
||||
console.log('create season seasonNum = '+ systemConfig?.seasonNum);
|
||||
let warIds = getPvpGkWarIds();
|
||||
let warId = warIds[0];
|
||||
seasonEndTime = <number>getTimeFun().getAfterDay(PVP.PVP_SEASON_DAYS);
|
||||
systemConfig = await SystemConfigModel.createSystemConfig( seasonEndTime, warId );
|
||||
} else {
|
||||
seasonEndTime = systemConfig.seasonEndTime;
|
||||
if (systemConfig.seasonEndTime - SETTLE_DIFF <= nowSeconds()) {//服务器启动时,检查当前时间是否大于实际结算的时间,若大于则重新开启定时任务,若小于则按照结束时间开启定时任务
|
||||
seasonEndTime = <number>getTimeFun().getAfterDay(PVP.PVP_SEASON_DAYS);
|
||||
console.log('update season seasonNum = '+ systemConfig.seasonNum);
|
||||
systemConfig.seasonNum++;//赛季值增加1
|
||||
await SystemConfigModel.updateSystemConfig({ seasonEndTime, seasonNum: systemConfig.seasonNum, oldSeasonEndTime: systemConfig.seasonEndTime});
|
||||
await setPvpSeasonResult({name: 'simpleJobExample' + systemConfig.seasonNum, notSetNext: true, notPush: true });
|
||||
}
|
||||
}
|
||||
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
|
||||
seasonJobId = scheduleJob('setPvpSeasonResult', settleTime, setPvpSeasonSchdule);//设置实际赛季结算时间
|
||||
let systemConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
|
||||
let seasonEndTime = systemConfig ? systemConfig.seasonEndTime : <number>getTimeFun(moment(SERVER_OPEN_TIME).startOf('d').add(-1, 'minute').toDate()).getAfterDay(PVP.PVP_SEASON_DAYS);
|
||||
if (nowSeconds() > seasonEndTime) {//停服太长,数据配置问题导致数据太老,需要刷新赛季数据
|
||||
while (nowSeconds() > seasonEndTime) {
|
||||
seasonEndTime = <number>getTimeFun(seasonEndTime).getAfterDay(PVP.PVP_SEASON_DAYS);
|
||||
}
|
||||
}
|
||||
if (!systemConfig || seasonEndTime != systemConfig.seasonEndTime) {
|
||||
systemConfig = await createNewPvpSeasonData(seasonEndTime)
|
||||
}
|
||||
|
||||
await resetPVPTimer(seasonEndTime);
|
||||
|
||||
seasonEndTimeJobId = scheduleJob('resetRank', seasonEndTime * PER_SECOND, resetPvpRanks);//由于24之后,才展示结算之后的信息,为保排行榜信息一致性,设置实际重置排行榜的时间为12点
|
||||
warJobId = scheduleJob("0 0 0 * * 1", resetPvpWarId);//每周1零点重置地图
|
||||
await resetPvpRanks();//服务器重启,重置排行榜的信息
|
||||
|
||||
@@ -92,29 +89,76 @@ export async function init() {
|
||||
await initMaintenance();
|
||||
}
|
||||
|
||||
function setPvpSeasonSchdule() {
|
||||
setPvpSeasonResult();
|
||||
async function resetPVPTimer(seasonEndTime: number) {
|
||||
if (!!seasonMakeRewardTimJobId) {
|
||||
seasonMakeRewardTimJobId.cancel();
|
||||
clearInterval(pvpMakeRewardInterval);
|
||||
}
|
||||
if (!!seasonRefreshTimeJobId) {
|
||||
seasonRefreshTimeJobId.cancel();
|
||||
clearInterval(pvpRefreshInterval);
|
||||
}
|
||||
if (seasonEndTime - SETTLE_DIFF - nowSeconds() < 0) {//23:30-24:00之间,已经过了结算时间,还未开启新赛季
|
||||
console.log('立刻结算奖励:', nowSeconds());
|
||||
await pvpSeasonEnd();
|
||||
//定时结算奖励
|
||||
seasonMakeRewardTimJobId = scheduleJob('seasonMakeRewardTimJobId', (seasonEndTime - SETTLE_DIFF - nowSeconds()) * PER_SECOND + PVP.PVP_SEASON_DAYS * PER_DAY * PER_SECOND, pvpMakeRewardTimer);//
|
||||
} else {
|
||||
//定时结算奖励
|
||||
seasonMakeRewardTimJobId = scheduleJob('seasonMakeRewardTimJobId', (seasonEndTime - SETTLE_DIFF - nowSeconds()) * PER_SECOND, pvpMakeRewardTimer);//
|
||||
};
|
||||
//定时开启新赛季
|
||||
seasonRefreshTimeJobId = scheduleJob('seasonRefreshTimeJobId', (seasonEndTime - nowSeconds()) * PER_SECOND, pvpRefreshTimer);//
|
||||
}
|
||||
|
||||
//pvp结算奖励定时器
|
||||
async function pvpMakeRewardTimer() {
|
||||
pvpMakeRewardInterval = setInterval(async () => {
|
||||
console.log('定时结算奖励:', nowSeconds());
|
||||
await pvpSeasonEnd()
|
||||
}, PVP.PVP_SEASON_DAYS * PER_DAY * PER_SECOND)
|
||||
}
|
||||
|
||||
//pvp刷新开始新赛季定时器
|
||||
async function pvpRefreshTimer() {
|
||||
pvpRefreshInterval = setInterval(async () => {
|
||||
console.log('定时开启新赛季:', nowSeconds());
|
||||
await createNextPvpSeason();
|
||||
}, PVP.PVP_SEASON_DAYS * PER_DAY * PER_SECOND)
|
||||
}
|
||||
|
||||
//创建下个新赛季
|
||||
export async function createNextPvpSeason() {
|
||||
let systemConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
let seasonEndTime = systemConfig ? systemConfig.seasonEndTime : <number>getTimeFun(moment(SERVER_OPEN_TIME).startOf('d').add(-1, 'minute').toDate()).getAfterDay(PVP.PVP_SEASON_DAYS);
|
||||
if (nowSeconds() > seasonEndTime) {//停服太长,数据配置问题导致数据太老,需要刷新赛季数据
|
||||
while (nowSeconds() > seasonEndTime) {
|
||||
seasonEndTime = <number>getTimeFun(seasonEndTime).getAfterDay(PVP.PVP_SEASON_DAYS);
|
||||
}
|
||||
}
|
||||
systemConfig = await createNewPvpSeasonData(seasonEndTime)
|
||||
await resetPvpRanks()
|
||||
return systemConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* pvp定时任务赛季结算
|
||||
* @param obj
|
||||
*/
|
||||
export async function setPvpSeasonResult(obj?:{ name:string, notSetNext?: boolean, notPush?: boolean }) {
|
||||
console.log('exce setPvpSeasonResult'+ obj?.name);
|
||||
let { seasonNum, seasonEndTime, oldSeasonEndTime } = await setNextPvpTime(obj?.notSetNext);//设置下个结算任务
|
||||
export async function pvpSeasonEnd(obj?: { name: string, notSetNext?: boolean, notPush?: boolean }) {
|
||||
console.log('exce pvpSeasonEnd' + obj?.name);
|
||||
let systemConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
let resultMaxRank = getResultMaxRank();//根据排行榜的奖励表,获得最大排名挡位的最小值,其余不在结算中结算的玩家按照最大排名挡位在登录或进入pvp时结算
|
||||
let maxPage = (resultMaxRank.min + 1000) / pageNum; //保底结算玩家数量
|
||||
let lastPageNum = resultMaxRank.min % pageNum;
|
||||
for (let page = 0; page < maxPage + 1; page++) {
|
||||
let pvpDefenses = await PvpDefenseModel.getPvpDef(pageNum, page == maxPage?lastPageNum:page);
|
||||
let pvpDefenses = await PvpDefenseModel.getPvpDef(pageNum, page == maxPage ? lastPageNum : page);
|
||||
for (let pvpDefense of pvpDefenses) {
|
||||
if (pvpDefense.seasonNum !== seasonNum) {
|
||||
await setPvpDefResultOnTime(pvpDefense, seasonNum, oldSeasonEndTime, obj?.notPush);
|
||||
if (pvpDefense.seasonNum !== systemConfig.seasonNum) {
|
||||
await setPvpDefResultOnTime(pvpDefense, systemConfig.seasonNum, systemConfig.seasonEndTime, obj?.notPush);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { seasonNum, seasonEndTime, oldSeasonEndTime};
|
||||
}
|
||||
/**
|
||||
* pvp定时任务结算获得添加邮件信息
|
||||
@@ -125,11 +169,11 @@ export async function setPvpSeasonResult(obj?:{ name:string, notSetNext?: boolea
|
||||
export async function setPvpDefResultOnTime(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime: number, notPush?: boolean) {
|
||||
//检查并返回排名结算以及武将功勋结算
|
||||
let { score, pLv, heroScores, challengeCnt, challengeRefTime, rankGoods, heroGoods, rankLv } = await checkResult(pvpDefense, seasonNum, oldSeasonEndTime);
|
||||
pvpDefense = await PvpDefenseModel.updateInfo(pvpDefense.roleId, {score, pLv, heroScores, seasonNum, challengeCnt, challengeRefTime});
|
||||
pvpDefense = await PvpDefenseModel.updateInfo(pvpDefense.roleId, { score, pLv, heroScores, seasonNum, challengeCnt, challengeRefTime });
|
||||
//下发邮件
|
||||
if (!!rankGoods.length) //排名奖励
|
||||
await sendMailByContent(MAIL_TYPE.PVP_RANK_REWARD, pvpDefense.roleId, {
|
||||
params: [JSON.stringify(seasonNum), (rankLv>1000?'999+':JSON.stringify(rankLv))],
|
||||
params: [JSON.stringify(seasonNum), (rankLv > 1000 ? '999+' : JSON.stringify(rankLv))],
|
||||
goods: rankGoods, endTime: oldSeasonEndTime, notPush
|
||||
});
|
||||
if (!!heroGoods.length) //武将功勋奖励
|
||||
@@ -146,7 +190,7 @@ export async function setPvpDefResultOnTime(pvpDefense: PvpDefenseType, seasonNu
|
||||
* @param oldSeasonEndTime
|
||||
* @param rankLv
|
||||
*/
|
||||
export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime:number, rankLv?:number) {
|
||||
export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime: number, rankLv?: number) {
|
||||
let pvpRankRewards = getPvpRankRewards();
|
||||
let pvpHeroRewards = getPvpHeroRewards();
|
||||
if (!rankLv) {
|
||||
@@ -162,7 +206,7 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number,
|
||||
pvpRankReward = getResultMaxRank();//最大排名等级挡位信息
|
||||
}
|
||||
let rankGoods = [];
|
||||
if(pvpRankReward) {
|
||||
if (pvpRankReward) {
|
||||
rankGoods = pvpRankReward.reward;//排名奖励
|
||||
}
|
||||
let heroGoods = [];
|
||||
@@ -181,20 +225,24 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number,
|
||||
});
|
||||
}
|
||||
}
|
||||
score += heroScore.score;
|
||||
score += heroScore.score;
|
||||
}
|
||||
let pLv = getLvByScore(pvpDefense.heroScores);
|
||||
//pvp锁定的信息存入赛季结算表中
|
||||
await PvpSeasonResultModel.updatePvpSeasonResult(pvpDefense.roleId, {
|
||||
oldSeasonData:{refOppCnt: pvpDefense.refOppCnt, rankLv, score: pvpDefense.score, pLv: oldPLv, heroScores: oldHeroScores,
|
||||
await PvpSeasonResultModel.updatePvpSeasonResult(pvpDefense.roleId, {
|
||||
oldSeasonData: {
|
||||
refOppCnt: pvpDefense.refOppCnt, rankLv, score: pvpDefense.score, pLv: oldPLv, heroScores: oldHeroScores,
|
||||
seasonNum: pvpDefense.seasonNum, challengeCnt, challengeRefTime, seasonEndTime: oldSeasonEndTime
|
||||
}, heroGoods, rankGoods, show: true });//结算修改玩家pvp信息
|
||||
}, heroGoods, rankGoods, show: true
|
||||
});//结算修改玩家pvp信息
|
||||
// 更新任务
|
||||
await checkTask(pvpDefense.roleId, null, null, TASK_TYPE.PVP_HERO_SCORE, 0, false, { heroScores: pvpDefense.heroScores });
|
||||
await checkTask(pvpDefense.roleId, null, null, TASK_TYPE.PVP_RANK, 1, false, { rankLv });
|
||||
return { rankLv, score, pLv, heroScores: pvpDefense.heroScores, seasonNum, challengeCnt:PVP.PVP_CHALLENGE_COUNTS, challengeRefTime:0, oldSeasonEndTime, heroGoods:heroGoods.map(({id, count})=>{
|
||||
return {id, count};
|
||||
}), rankGoods};
|
||||
return {
|
||||
rankLv, score, pLv, heroScores: pvpDefense.heroScores, seasonNum, challengeCnt: PVP.PVP_CHALLENGE_COUNTS, challengeRefTime: 0, oldSeasonEndTime, heroGoods: heroGoods.map(({ id, count }) => {
|
||||
return { id, count };
|
||||
}), rankGoods
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 个人pvp结算,结算中未结算的,都按照最大排名挡位结算
|
||||
@@ -202,60 +250,64 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number,
|
||||
* @param seasonNum
|
||||
* @param oldSeasonEndTime
|
||||
*/
|
||||
export async function setPvpDefResult(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime:number) {
|
||||
export async function setPvpDefResult(pvpDefense: PvpDefenseType, seasonNum: number, oldSeasonEndTime: number) {
|
||||
let role = await RoleModel.findByRoleId(pvpDefense.roleId);
|
||||
if (!role) {
|
||||
return;
|
||||
}
|
||||
let resultMaxRank = getResultMaxRank();
|
||||
let rankLv = resultMaxRank.min; //最大排名挡位结算
|
||||
let {score, pLv, heroScores, challengeCnt, challengeRefTime, rankGoods, heroGoods } = await checkResult(pvpDefense, seasonNum, oldSeasonEndTime, rankLv);
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(pvpDefense.roleId, {score, pLv, heroScores, seasonNum, challengeCnt, challengeRefTime});
|
||||
let { score, pLv, heroScores, challengeCnt, challengeRefTime, rankGoods, heroGoods } = await checkResult(pvpDefense, seasonNum, oldSeasonEndTime, rankLv);
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(pvpDefense.roleId, { score, pLv, heroScores, seasonNum, challengeCnt, challengeRefTime });
|
||||
let { roleId } = role;
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, {});
|
||||
r.setRankWithRoleInfo(pvpDefense.roleId, pvpDefense.score, pvpDefense.updatedAt.getTime(), role, true);
|
||||
//下发邮件
|
||||
if (!!rankGoods.length)
|
||||
if (!!rankGoods.length)
|
||||
await sendMailByContent(MAIL_TYPE.PVP_RANK_REWARD, roleId, { params: [JSON.stringify(seasonNum), '999+'], goods: rankGoods, endTime: oldSeasonEndTime });
|
||||
if (!!heroGoods.length)
|
||||
if (!!heroGoods.length)
|
||||
await sendMailByContent(MAIL_TYPE.PVP_RESULT, roleId, { params: [JSON.stringify(seasonNum)], goods: heroGoods, endTime: oldSeasonEndTime });
|
||||
return pvpDefense;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每周重置地图
|
||||
* 新pvp赛季数据
|
||||
*/
|
||||
export async function resetPvpWarId() {
|
||||
// console.log('resetPvpWarId');
|
||||
let systemConfig = await SystemConfigModel.findSystemConfig();
|
||||
export async function createNewPvpSeasonData(seasonEndTime: number) {
|
||||
console.log('createNewPvpSeasonData');
|
||||
let seasonNum = await CounterModel.getNewCounter(COUNTER.PVP_SEASON_NUM);
|
||||
// let seasonEndTime: number = <number>getTimeFun(oldEndTime).getAfterDay(PVP.PVP_SEASON_DAYS);
|
||||
let warId = getPvpWarId(-1);
|
||||
let systemConfig = await PVPConfigModel.createPVPConfig(seasonNum, seasonEndTime, warId);
|
||||
return systemConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机地图Id
|
||||
*/
|
||||
function getPvpWarId(oldWarId: number): number {
|
||||
let warIds: number[] = deepCopy(getPvpGkWarIds());
|
||||
let index = indexOf(warIds, systemConfig.warId);
|
||||
let index = indexOf(warIds, oldWarId);
|
||||
if (index != -1) {
|
||||
warIds.splice(index, 1);
|
||||
}
|
||||
let warId = getRandSingleEelm(warIds);
|
||||
return await SystemConfigModel.updateSystemConfig({ warId });
|
||||
console.log('getPvpWarId', oldWarId, warId);
|
||||
return warId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置下个定时结算
|
||||
* @param notSetNext
|
||||
* 每周重置地图
|
||||
*/
|
||||
async function setNextPvpTime(notSetNext: boolean) {
|
||||
let { seasonEndTime, seasonNum } = await SystemConfigModel.findSystemConfig();
|
||||
if (!!notSetNext) {
|
||||
return { seasonEndTime, seasonNum , oldSeasonEndTime: 0};
|
||||
}
|
||||
let oldSeasonEndTime = seasonEndTime;
|
||||
seasonEndTime = <number>getTimeFun().getAfterDay(PVP.PVP_SEASON_DAYS + 1);
|
||||
await SystemConfigModel.updateSeason(seasonEndTime, oldSeasonEndTime);
|
||||
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
|
||||
seasonJobId = scheduleJob('setPvpSeasonResult', settleTime, setPvpSeasonSchdule);
|
||||
seasonEndTimeJobId = scheduleJob('resetRank', seasonEndTime* PER_SECOND, resetPvpRanks);
|
||||
return { seasonEndTime, seasonNum: seasonNum + 1, oldSeasonEndTime };
|
||||
export async function resetPvpWarId() {
|
||||
let systemConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
let warId = getPvpWarId(systemConfig.warId)
|
||||
return await PVPConfigModel.updatePVPConfig(systemConfig.seasonNum, { warId });
|
||||
}
|
||||
|
||||
function getScore(arr, score) {
|
||||
for (let item of arr) {
|
||||
if ((item.max >= score||item.max == -1) && score >= item.min) {
|
||||
if ((item.max >= score || item.max == -1) && score >= item.min) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -265,67 +317,51 @@ function getScore(arr, score) {
|
||||
* @param hour
|
||||
*/
|
||||
export async function resetPvpSeasonTime(hour: number) {
|
||||
if (!!seasonJobId) {
|
||||
seasonJobId.cancel();
|
||||
}
|
||||
let seasonEndTime = 0;
|
||||
let seasonNum = 1;
|
||||
if (!!seasonEndTimeJobId) {
|
||||
seasonEndTimeJobId.cancel();
|
||||
}
|
||||
let systemConfig = await SystemConfigModel.findSystemConfig();
|
||||
if (!systemConfig) {
|
||||
let warIds = getPvpGkWarIds();
|
||||
let warId = warIds[0];
|
||||
seasonEndTime = <number>getTimeFun().getTimeWithHour(REFRESH_TIME - hour);
|
||||
systemConfig = await SystemConfigModel.createSystemConfig( seasonEndTime, warId );
|
||||
} else {
|
||||
seasonEndTime = <number>getTimeFun().getTimeWithHour(REFRESH_TIME - hour);
|
||||
seasonNum = systemConfig.seasonNum + 1;
|
||||
await SystemConfigModel.updateSystemConfig({ seasonEndTime, seasonNum, oldSeasonEndTime: 0});
|
||||
await setPvpSeasonResult({name: 'simpleJobExample' + systemConfig.seasonNum, notSetNext: true });
|
||||
await resetPvpRanks();
|
||||
}
|
||||
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
|
||||
console.log('settleTime = ' + settleTime)
|
||||
seasonJobId = scheduleJob('setPvpSeasonResult', settleTime, setPvpSeasonSchdule);
|
||||
return { seasonEndTime, seasonNum };
|
||||
let systemConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
|
||||
let seasonEndTime = <number>getTimeFun().getTimeWithHour(REFRESH_TIME - hour);
|
||||
systemConfig = await createNewPvpSeasonData(seasonEndTime);
|
||||
await resetPVPTimer(seasonEndTime);
|
||||
await resetPvpRanks();
|
||||
console.log('settleTime = ' + systemConfig.seasonNum)
|
||||
|
||||
return { seasonEndTime, seasonNum: systemConfig.seasonNum };
|
||||
}
|
||||
|
||||
|
||||
async function resetPvpRanks() {
|
||||
export async function resetPvpRanks() {
|
||||
await initSingleRank(REDIS_KEY.PVP_RANK);
|
||||
}
|
||||
|
||||
export async function reportOnlineSchedule() {
|
||||
let allRoles = await getAllOnlineRoles();
|
||||
console.log('reportOnlineSchedule all roles count: ', allRoles.length)
|
||||
for(let { roleId, userCode, sid, pkgName } of allRoles) {
|
||||
for (let { roleId, userCode, sid, pkgName } of allRoles) {
|
||||
let result = reportOneOnline(roleId, userCode, sid, pkgName);
|
||||
if(!result) continue;
|
||||
if (!result) continue;
|
||||
}
|
||||
}
|
||||
|
||||
export async function reportOneOnline(roleId: string, userCode: string, sid: string, pkgName: string) {
|
||||
|
||||
let result = await reportOnline(userCode, pkgName); // 连接sdk
|
||||
if(!result || result.code == -1) return false;
|
||||
if (!result || result.code == -1) return false;
|
||||
|
||||
let user = await UserModel.findUserByUserCode(userCode);
|
||||
if(!user) return false;
|
||||
if (!user) return false;
|
||||
let { reportTime = new Date(), lastLoginTime = new Date(), guestTime, isGuest, hasAuthenticated, birthday } = user;
|
||||
|
||||
|
||||
let age = getAge(birthday);
|
||||
let isAdult = age >= ADULT_AGE;
|
||||
|
||||
if(isGuest || !hasAuthenticated) {
|
||||
let lastTime = lastLoginTime > reportTime? lastLoginTime.getTime(): reportTime.getTime();
|
||||
let guestTimeInc = Math.floor((Date.now() - lastTime)/1000);
|
||||
if (isGuest || !hasAuthenticated) {
|
||||
let lastTime = lastLoginTime > reportTime ? lastLoginTime.getTime() : reportTime.getTime();
|
||||
let guestTimeInc = Math.floor((Date.now() - lastTime) / 1000);
|
||||
user = await UserModel.updatePlayTime(userCode, guestTimeInc, result.total); // 记录时间
|
||||
|
||||
guestTime = user.guestTime;
|
||||
|
||||
if ( guestTime > GUEST_MAX_TIME ) {
|
||||
if (guestTime > GUEST_MAX_TIME) {
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
isGuest,
|
||||
guestTime, // 游客已体验时间
|
||||
@@ -333,10 +369,10 @@ export async function reportOneOnline(roleId: string, userCode: string, sid: str
|
||||
isAdult, // 是否已成年
|
||||
todayPlayTime: result.total, // 今天已游戏时长
|
||||
type: ADDICTION_PREVENTION_CODE.GUEST,
|
||||
} ), [{uid: roleId, sid: sid}]);
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
}
|
||||
} else {
|
||||
if(result.code != ADDICTION_PREVENTION_CODE.SUCCESS && result.age != -1) { // 未成年人防沉迷
|
||||
if (result.code != ADDICTION_PREVENTION_CODE.SUCCESS && result.age != -1) { // 未成年人防沉迷
|
||||
user = await UserModel.updatePlayTime(userCode, 0, result.total, result.code); // 记录时间
|
||||
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
@@ -346,7 +382,7 @@ export async function reportOneOnline(roleId: string, userCode: string, sid: str
|
||||
isAdult, // 是否已成年
|
||||
todayPlayTime: result.total, // 今天已游戏时长
|
||||
type: result.code
|
||||
} ), [{uid: roleId, sid: sid}]);
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,32 +393,32 @@ export async function reportOneOnline(roleId: string, userCode: string, sid: str
|
||||
async function guildActivitySchedule() {
|
||||
/***********guildActivitySchedule***********/
|
||||
|
||||
let dicGuildActivity = getTodayGuildActivity();
|
||||
let dicGuildActivity = getTodayGuildActivity();
|
||||
await delGuildActivityRank(dicGuildActivity.id);
|
||||
|
||||
scheduleJob('guildActivityStart', `${dicGuildActivity.startSeconds} ${dicGuildActivity.startMinute} ${dicGuildActivity.startTime} * * ?`, guildActivityStartSchedule);
|
||||
|
||||
let statusResult = getGuildActivityByDic(dicGuildActivity);
|
||||
if(!statusResult) return;
|
||||
if (!statusResult) return;
|
||||
|
||||
if(statusResult.status == GUILD_ACTIVITY_STATUS.START) {
|
||||
if (statusResult.status == GUILD_ACTIVITY_STATUS.START) {
|
||||
// 断掉活动续期
|
||||
if(!guildActSecondsJobId) {
|
||||
if(dicGuildActivity.id == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
if (!guildActSecondsJobId) {
|
||||
if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
guildActSecondsJobId = scheduleJob('guildActivitySeconds', `*/10 * * * * *`, gateActivitySeconds);
|
||||
} else if(dicGuildActivity.id == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
} else if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
guildActSecondsJobId = scheduleJob('guildActivitySeconds', `*/10 * * * * *`, cityActivitySeconds);
|
||||
} else if(dicGuildActivity.id == GUILD_ACTIVITY_TYPE.RACE_ACTIVITY) {
|
||||
} else if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.RACE_ACTIVITY) {
|
||||
guildActSecondsJobId = scheduleJob('guildActivitySeconds', `*/1 * * * * *`, raceActivitySeconds);
|
||||
}
|
||||
}
|
||||
|
||||
if(!guildActEndJobId) {
|
||||
if(dicGuildActivity.id == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
if (!guildActEndJobId) {
|
||||
if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
guildActEndJobId = scheduleJob('guildActivityEnd', statusResult.time, gateActivityEnd);
|
||||
} else if(dicGuildActivity.id == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
} else if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
guildActEndJobId = scheduleJob('guildActivityEnd', statusResult.time, cityActivityEnd);
|
||||
} else if(dicGuildActivity.id == GUILD_ACTIVITY_TYPE.RACE_ACTIVITY) {
|
||||
} else if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.RACE_ACTIVITY) {
|
||||
guildActEndJobId = scheduleJob('guildActivityEnd', statusResult.time, raceActivityEnd);
|
||||
}
|
||||
}
|
||||
@@ -396,15 +432,15 @@ async function guildActivityStartSchedule() {
|
||||
|
||||
export async function guildActivityStart(dicGuildActivity?: DicGuildActivity) {
|
||||
console.log('*******开始军团晚间活动****')
|
||||
if(!dicGuildActivity) dicGuildActivity = getTodayGuildActivity();
|
||||
if(!dicGuildActivity) return;
|
||||
if (!dicGuildActivity) dicGuildActivity = getTodayGuildActivity();
|
||||
if (!dicGuildActivity) return;
|
||||
|
||||
if(guildActSecondsJobId||guildActEndJobId) {
|
||||
if (guildActSecondsJobId || guildActEndJobId) {
|
||||
return false
|
||||
}
|
||||
|
||||
let servers = await getAllServers(); // 玩家serverId列表
|
||||
if(dicGuildActivity.id == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
guildActSecondsJobId = scheduleJob('guildActivitySeconds', '*/10 * * * * *', gateActivitySeconds);
|
||||
// 结束时间
|
||||
guildActEndJobId = scheduleJob('guildActivityEnd', Date.now() + dicGuildActivity.duringTime * 1000, gateActivityEnd);
|
||||
@@ -416,7 +452,7 @@ export async function guildActivityStart(dicGuildActivity?: DicGuildActivity) {
|
||||
|
||||
// 开始活动
|
||||
let guildServers = pinus.app.getServersByType('guild');
|
||||
for(let serverId of servers) {
|
||||
for (let serverId of servers) {
|
||||
let sid = dispatch(serverId.toString(), guildServers);
|
||||
await pinus.app.rpc.guild.guildActivityRemote.raceActivityStart.toServer(sid.id, serverId);
|
||||
}
|
||||
@@ -426,7 +462,7 @@ export async function guildActivityStart(dicGuildActivity?: DicGuildActivity) {
|
||||
guildActEndJobId = scheduleJob('guildActivityEnd', Date.now() + dicGuildActivity.duringTime * 1000, raceActivityEnd);
|
||||
}
|
||||
|
||||
for(let serverId of servers) {
|
||||
for (let serverId of servers) {
|
||||
await sendGuildActivityStatus(serverId);
|
||||
}
|
||||
return true;
|
||||
@@ -439,15 +475,15 @@ export async function gateActivityEnd() {
|
||||
console.log('*****gateActivityEnd');
|
||||
await sendEndMsgToAll();
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
for(let { id } of servers) {
|
||||
for (let { id } of servers) {
|
||||
await pinus.app.rpc.guild.guildActivityRemote.guildActivityEnd.toServer(id, GUILD_ACTIVITY_TYPE.GATE_ACTIVITY);
|
||||
}
|
||||
|
||||
if(guildActSecondsJobId) {
|
||||
if (guildActSecondsJobId) {
|
||||
guildActSecondsJobId.cancel();
|
||||
guildActSecondsJobId = undefined;
|
||||
}
|
||||
if(guildActEndJobId) {
|
||||
if (guildActEndJobId) {
|
||||
guildActEndJobId.cancel();
|
||||
guildActEndJobId = undefined;
|
||||
}
|
||||
@@ -457,7 +493,7 @@ export async function gateActivityEnd() {
|
||||
export async function gateActivitySeconds() {
|
||||
console.log('*****gateActivitySeconds')
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
for(let { id } of servers) {
|
||||
for (let { id } of servers) {
|
||||
await pinus.app.rpc.guild.guildActivityRemote.sendRankToGuilds.toServer(id, GUILD_ACTIVITY_TYPE.GATE_ACTIVITY);
|
||||
}
|
||||
}
|
||||
@@ -468,20 +504,20 @@ export async function cityActivityEnd() {
|
||||
console.log('*****cityActivityEnd');
|
||||
await sendEndMsgToAll();
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
for(let { id } of servers) {
|
||||
for (let { id } of servers) {
|
||||
await pinus.app.rpc.guild.guildActivityRemote.guildActivityEnd.toServer(id, GUILD_ACTIVITY_TYPE.CITY_ACTIVITY);
|
||||
}
|
||||
|
||||
// 发完之后再做下周自动宣战
|
||||
let serverlists = await getAllServers();
|
||||
for(let serverId of serverlists) {
|
||||
for (let serverId of serverlists) {
|
||||
await autoDeclare(serverId);
|
||||
}
|
||||
if(guildActSecondsJobId) {
|
||||
if (guildActSecondsJobId) {
|
||||
guildActSecondsJobId.cancel();
|
||||
guildActSecondsJobId = undefined;
|
||||
}
|
||||
if(guildActEndJobId) {
|
||||
if (guildActEndJobId) {
|
||||
guildActEndJobId.cancel();
|
||||
guildActEndJobId = undefined;
|
||||
}
|
||||
@@ -491,7 +527,7 @@ export async function cityActivityEnd() {
|
||||
export async function cityActivitySeconds() {
|
||||
console.log('*****cityActivitySeconds')
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
for(let { id } of servers) {
|
||||
for (let { id } of servers) {
|
||||
await pinus.app.rpc.guild.guildActivityRemote.sendRankToGuilds.toServer(id, GUILD_ACTIVITY_TYPE.CITY_ACTIVITY);
|
||||
}
|
||||
}
|
||||
@@ -502,15 +538,17 @@ export async function raceActivityEnd() {
|
||||
console.log('*****raceActivityEnd');
|
||||
await sendEndMsgToAll();
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
for(let { id } of servers) {
|
||||
for (let { id } of servers) {
|
||||
await pinus.app.rpc.guild.guildActivityRemote.guildActivityEnd.toServer(id, GUILD_ACTIVITY_TYPE.RACE_ACTIVITY);
|
||||
}
|
||||
|
||||
if(guildActSecondsJobId) {
|
||||
if (guildActSecondsJobId) {
|
||||
guildActSecondsJobId.cancel();
|
||||
guildActSecondsJobId = undefined;
|
||||
}
|
||||
if(guildActEndJobId) {
|
||||
if (guildActEndJobId) {
|
||||
|
||||
|
||||
guildActEndJobId.cancel();
|
||||
guildActEndJobId = undefined;
|
||||
}
|
||||
@@ -521,7 +559,7 @@ export async function raceActivitySeconds() {
|
||||
console.log('*****raveActivitySeconds')
|
||||
let servers = await getAllServers(); // 玩家serverId列表
|
||||
let guildServers = pinus.app.getServersByType('guild');
|
||||
for(let serverId of servers) {
|
||||
for (let serverId of servers) {
|
||||
let sid = dispatch(serverId.toString(), guildServers);
|
||||
await pinus.app.rpc.guild.guildActivityRemote.calWoodenHorseAndSend.toServer(sid.id, serverId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user