pvp:修复赛季显示
This commit is contained in:
@@ -122,8 +122,10 @@ app.configure(ALL_ENVS, 'guild', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.configure(ALL_ENVS, 'systimer', function () {
|
app.configure(ALL_ENVS, 'systimer', function () {
|
||||||
|
app.afterStart(() => {
|
||||||
timeTaskService.init();
|
timeTaskService.init();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function errorHandler(err: Error, msg: any, resp: any,
|
function errorHandler(err: Error, msg: any, resp: any,
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export class PvpHandler {
|
|||||||
let pvpSeasonResult = await PvpSeasonResultModel.getPvpSeasonResult(roleId);
|
let pvpSeasonResult = await PvpSeasonResultModel.getPvpSeasonResult(roleId);
|
||||||
if (!!pvpSeasonResult && !!pvpSeasonResult.show) {
|
if (!!pvpSeasonResult && !!pvpSeasonResult.show) {
|
||||||
result.setPvpSeasonResult(pvpSeasonResult);
|
result.setPvpSeasonResult(pvpSeasonResult);
|
||||||
await PvpSeasonResultModel.updatePvpSeasonResult(roleId, pvpSeasonResult.seasonNum, { show: false });
|
await PvpSeasonResultModel.setShow(roleId);
|
||||||
}
|
}
|
||||||
// 拍卖
|
// 拍卖
|
||||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||||
@@ -340,7 +340,7 @@ export class PvpHandler {
|
|||||||
|
|
||||||
// 次数
|
// 次数
|
||||||
let refOppObj = refreshRefOppCnt(pvpDefense);
|
let refOppObj = refreshRefOppCnt(pvpDefense);
|
||||||
if(refOppObj.setAttackCnt >= PVP.PVP_BUY_SET_ATTACK_CNT + refOppObj.buyAttackCnt) {
|
if(refOppObj.setAttackCnt >= PVP.PVP_SET_ATTACK_FREE_CNT + refOppObj.buyAttackCnt) {
|
||||||
return resResult(STATUS.PVP_SET_ATTACK_CNT_NOT_ENOUGH);
|
return resResult(STATUS.PVP_SET_ATTACK_CNT_NOT_ENOUGH);
|
||||||
}
|
}
|
||||||
refOppObj.setAttackCnt ++;
|
refOppObj.setAttackCnt ++;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { scheduleJob, Job, } from 'node-schedule';
|
import { scheduleJob, Job, } from 'node-schedule';
|
||||||
import { PVPConfigModel, PVPConfigType } from '../db/SystemConfig';
|
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 { getTodayGuildActivity, gameData } from '../pubUtils/data';
|
||||||
import { pvpSeasonEnd } from './pvpService';
|
import { pvpSeasonEnd } from './pvpService';
|
||||||
import { getAllOnlineRoles, getAllServers, delGuildActivityRank } from './redisService';
|
import { getAllOnlineRoles, getAllServers, delGuildActivityRank } from './redisService';
|
||||||
@@ -23,6 +23,7 @@ import { initMarquee, initMaintenance } from './gmService';
|
|||||||
import moment = require('moment');
|
import moment = require('moment');
|
||||||
import { CounterModel } from '../db/Counter';
|
import { CounterModel } from '../db/Counter';
|
||||||
import { reportOneOnline } from './authenticateService';
|
import { reportOneOnline } from './authenticateService';
|
||||||
|
import { PVP } from '../pubUtils/dicParam';
|
||||||
|
|
||||||
const PER_SECOND = 1 * 1000;
|
const PER_SECOND = 1 * 1000;
|
||||||
const PER_DAY = 24 * 60 * 60;
|
const PER_DAY = 24 * 60 * 60;
|
||||||
@@ -71,7 +72,13 @@ export async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSeasonContinueDay(seasonNum: number) {
|
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;
|
let maxDay = 0;
|
||||||
for(let {seasonNum: dicSeasonNum, day } of pvpSeasonDuring) {
|
for(let {seasonNum: dicSeasonNum, day } of pvpSeasonDuring) {
|
||||||
@@ -86,9 +93,12 @@ async function setPvpSeasonJob() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setPvpSeason(isForce?: boolean, hour?: number) {
|
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 oldPvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||||
let pvpConfig = oldPvpConfig;
|
let pvpConfig = oldPvpConfig;
|
||||||
|
console.log(`******** setPvpSeason2: during-${during}, seasonEndTime-${pvpConfig?.seasonEndTime}, now-${nowSeconds()}`)
|
||||||
if(!pvpConfig || pvpConfig.seasonEndTime <= nowSeconds() || isForce) {
|
if(!pvpConfig || pvpConfig.seasonEndTime <= nowSeconds() || isForce) {
|
||||||
if(pvpConfig && !pvpConfig.hasSettleReward) {
|
if(pvpConfig && !pvpConfig.hasSettleReward) {
|
||||||
await pvpSeasonEnd(pvpConfig);
|
await pvpSeasonEnd(pvpConfig);
|
||||||
@@ -96,13 +106,28 @@ async function setPvpSeason(isForce?: boolean, hour?: number) {
|
|||||||
|
|
||||||
let lastSeasonNum = pvpConfig? pvpConfig.seasonNum: 0;
|
let lastSeasonNum = pvpConfig? pvpConfig.seasonNum: 0;
|
||||||
let lastSeasonEndTime = pvpConfig? pvpConfig.seasonEndTime: 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;
|
if(!during) during = getSeasonContinueDay(lastSeasonNum + 1) * PER_DAY;
|
||||||
let rewardTime = SETTLE_DIFF_SECONDS;
|
let rewardTime = SETTLE_DIFF_SECONDS;
|
||||||
if(nowSeconds() - lastSeasonEndTime > during) {
|
if(nowSeconds() - newSeasonStartTime > during) {
|
||||||
newSeasonStartTime = <number>getTimeFun().getDayZeroPoint(0);
|
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);
|
let newSeasonNum = await CounterModel.getNewCounter(COUNTER.PVP_SEASON_NUM);
|
||||||
pvpConfig = await PVPConfigModel.createPVPConfig(newSeasonNum, newSeasonStartTime, newSeasonStartTime + during - rewardTime, newSeasonStartTime + during - PER_MINUTE);
|
pvpConfig = await PVPConfigModel.createPVPConfig(newSeasonNum, newSeasonStartTime, newSeasonStartTime + during - rewardTime, newSeasonStartTime + during - PER_MINUTE);
|
||||||
}
|
}
|
||||||
@@ -125,6 +150,7 @@ async function setPvpSeasonMakeRewardJob(pvpConfig: PVPConfigType) {
|
|||||||
if (!!seasonMakeRewardTimJobId) {
|
if (!!seasonMakeRewardTimJobId) {
|
||||||
seasonMakeRewardTimJobId.cancel();
|
seasonMakeRewardTimJobId.cancel();
|
||||||
}
|
}
|
||||||
|
if(!pvpConfig) return;
|
||||||
if(pvpConfig.seasonRewardTime < nowSeconds() && !pvpConfig.hasSettleReward) { // 未发奖励
|
if(pvpConfig.seasonRewardTime < nowSeconds() && !pvpConfig.hasSettleReward) { // 未发奖励
|
||||||
await pvpSeasonEnd(pvpConfig);
|
await pvpSeasonEnd(pvpConfig);
|
||||||
} else {
|
} else {
|
||||||
@@ -147,7 +173,7 @@ async function setNextSeasonJob(pvpConfig: PVPConfigType) {
|
|||||||
* @param hour
|
* @param hour
|
||||||
*/
|
*/
|
||||||
export async function resetPvpSeasonTime(hour: number) {
|
export async function resetPvpSeasonTime(hour: number) {
|
||||||
return await setPvpSeason(true);
|
return await setPvpSeason(true, hour);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function reportOnlineSchedule() {
|
export async function reportOnlineSchedule() {
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ export default class PvpSeasonResult extends BaseModel {
|
|||||||
let result: PvpSeasonResultType = await PvpSeasonResultModel.findOneAndUpdate({roleId, seasonNum}, {$set: update}, {upsert: true, new: true}).lean(lean);
|
let result: PvpSeasonResultType = await PvpSeasonResultModel.findOneAndUpdate({roleId, seasonNum}, {$set: update}, {upsert: true, new: true}).lean(lean);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async setShow(roleId: string) {
|
||||||
|
let result = await PvpSeasonResultModel.updateMany({ roleId, show: true }, { show: false }).lean();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static async getPvpSeasonResult(roleId: string) {
|
public static async getPvpSeasonResult(roleId: string) {
|
||||||
let result: PvpSeasonResultType = await PvpSeasonResultModel.findOne({ roleId, show: true }).lean();
|
let result: PvpSeasonResultType = await PvpSeasonResultModel.findOne({ roleId, show: true }).lean();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user