pvp:修复赛季显示

This commit is contained in:
luying
2021-11-02 11:36:14 +08:00
parent 4c80a22ccf
commit 14027b1732
4 changed files with 43 additions and 9 deletions
+3 -1
View File
@@ -122,7 +122,9 @@ app.configure(ALL_ENVS, 'guild', function () {
})
app.configure(ALL_ENVS, 'systimer', function () {
timeTaskService.init();
app.afterStart(() => {
timeTaskService.init();
});
});
@@ -85,7 +85,7 @@ export class PvpHandler {
let pvpSeasonResult = await PvpSeasonResultModel.getPvpSeasonResult(roleId);
if (!!pvpSeasonResult && !!pvpSeasonResult.show) {
result.setPvpSeasonResult(pvpSeasonResult);
await PvpSeasonResultModel.updatePvpSeasonResult(roleId, pvpSeasonResult.seasonNum, { show: false });
await PvpSeasonResultModel.setShow(roleId);
}
// 拍卖
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
@@ -340,7 +340,7 @@ export class PvpHandler {
// 次数
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);
}
refOppObj.setAttackCnt ++;
+32 -6
View File
@@ -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的情况,如果(因为debugnewSeasonStartTime不是每天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() {
+6
View File
@@ -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);
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) {
let result: PvpSeasonResultType = await PvpSeasonResultModel.findOne({ roleId, show: true }).lean();
return result;