pvp随机地图
This commit is contained in:
@@ -2,12 +2,70 @@
|
||||
* 体力系统
|
||||
*/
|
||||
|
||||
import { scheduleJob, cancelJob } from 'pinus-scheduler';
|
||||
|
||||
import { scheduleJob } from 'pinus-scheduler';
|
||||
import { SystemConfigModel } from '../db/SystemConfig';
|
||||
import PvpDefenseType,{ PvpDefenseModel } from '../db/pvpDefense';
|
||||
import { PVP } from '../pubUtils/dicParam';
|
||||
import { nowSeconds, getTodayZeroPoint } from '../pubUtils/timeUtil';
|
||||
import { getPvpGkWarIds } from '../pubUtils/data';
|
||||
import { getRandomArr } from '../pubUtils/util';
|
||||
const _ = require('underscore');
|
||||
const PER_SECOND = 1 * 1000;
|
||||
const PER_DAY = 24 * 60 * 60;
|
||||
const SETTLE_DIFF = 29 * 60;
|
||||
const LIMIT_NUM = 1000;
|
||||
export async function init() {
|
||||
scheduleJob("0 31 23 * * *", setPvpSeasonResult, {name:'setPvpSeasonResult'})
|
||||
let seasonEndTime = 0;
|
||||
let systemConfig = await SystemConfigModel.findSystemConfig();
|
||||
if (!systemConfig) {
|
||||
let warIds = getPvpGkWarIds();
|
||||
let warId = warIds[0];//TODO随机地图
|
||||
seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
|
||||
await SystemConfigModel.createSystemConfig( seasonEndTime, warId );
|
||||
} else {
|
||||
seasonEndTime = systemConfig.seasonEndTime;
|
||||
if (systemConfig.seasonEndTime - SETTLE_DIFF <= nowSeconds()) {
|
||||
await setPvpSeasonResult();
|
||||
seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
|
||||
systemConfig.seasonNum++;
|
||||
await SystemConfigModel.updateSystemConfig({ seasonEndTime, seasonNum: systemConfig.seasonNum});
|
||||
}
|
||||
}
|
||||
let settleTime = seasonEndTime - SETTLE_DIFF - nowSeconds();
|
||||
// setTimeout(setPvpSeasonResult, settleTime * PER_SECOND);
|
||||
scheduleJob("0 0 0 * * 1", resetPvpWarId)
|
||||
}
|
||||
|
||||
export async function setPvpSeasonResult() {
|
||||
|
||||
console.log('setPvpSeasonResult');
|
||||
let pvpDefenses = await PvpDefenseModel.getPvpDef(LIMIT_NUM);
|
||||
for (let pvpDefense of pvpDefenses) {
|
||||
await setPvpDefResult(pvpDefense);
|
||||
}
|
||||
await setNextPvpTime();
|
||||
}
|
||||
|
||||
async function setPvpDefResult(pvpDefense: PvpDefenseType) {
|
||||
await PvpDefenseModel.updateInfo(pvpDefense.roleId, {score:100, pLv: 1});
|
||||
|
||||
}
|
||||
|
||||
export async function resetPvpWarId() {
|
||||
console.log('resetPvpWarId');
|
||||
let systemConfig = await SystemConfigModel.findSystemConfig();
|
||||
let warIds = getPvpGkWarIds();
|
||||
let index = _.indexOf(warIds, systemConfig.warId);
|
||||
if (index != -1) {
|
||||
warIds.splice(index, 1);
|
||||
}
|
||||
let res = getRandomArr(warIds, 1);
|
||||
let warId = res[0];//TODO随机地图
|
||||
await SystemConfigModel.updateSystemConfig({ warId });
|
||||
}
|
||||
|
||||
async function setNextPvpTime() {
|
||||
let seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
|
||||
await SystemConfigModel.updateSeason(seasonEndTime);
|
||||
let settleTime = seasonEndTime - SETTLE_DIFF - nowSeconds();
|
||||
setTimeout(setPvpSeasonResult, settleTime * PER_SECOND);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user