巅峰演武:赛季优化修改
This commit is contained in:
@@ -193,6 +193,10 @@ async function treatStartLogic(app: _pinus.Application) {
|
||||
initGuildActivityIndexInPinus()
|
||||
.then(resetJoinWoodenHorse);
|
||||
}
|
||||
if(app.getServerType() == 'battle'|| app.getServerType() == 'role'|| app.getServerType() == 'connector') {
|
||||
timeTaskService.setPvpSeasonNum();
|
||||
timeTaskService.setPvpSettleSeasonNum();
|
||||
}
|
||||
|
||||
if(app.isMaster()) {
|
||||
redisService.initAllRank();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { Application, BackendSession, pinus, HandlerService, } from 'pinus';
|
||||
import { findIndex } from 'underscore';
|
||||
import { gameData, getPvpBoxBySeasonNumAndIndex } from '../../../pubUtils/data';
|
||||
import { refreshEnemies, getEnemies, refChallengeCnt, generPVPOppRecInfo, generMyRecInfo, sendLastSeasonRewardIfNotSent, refreshRefOppCnt, generPvpLineupCe, calLineupScore } from '../../../services/pvpService';
|
||||
import { refreshEnemies, getEnemies, refChallengeCnt, generPVPOppRecInfo, generMyRecInfo, sendLastSeasonRewardIfNotSent, refreshRefOppCnt, generPvpLineupCe, calLineupScore, checkPvpSeasonIsStart, checkPvpSeasonIsSummit } from '../../../services/pvpService';
|
||||
import { RoleModel, RoleType } from '../../../db/Role';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult, genCode, checkRoleIsRobot, robotIdComBack } from '../../../pubUtils/util';
|
||||
@@ -10,7 +10,7 @@ import { PvpDefenseModel, pvpUpdateInter } from '../../../db/PvpDefense';
|
||||
import { PvpSeasonResultModel } from '../../../db/PvpSeasonResult';
|
||||
import { Rank } from '../../../services/rankService';
|
||||
import { checkTask, checkTaskInPvpEnd } from '../../../services/task/taskService';
|
||||
import { Attack, Defense, DefenseHero, PvpDataReturn } from '../../../domain/battleField/pvp';
|
||||
import { Attack, Defense, DefenseHero, PvpDataReturn, pvpSaveDataReturn } from '../../../domain/battleField/pvp';
|
||||
import { DEBUG_MAGIC_WORD, FIGURE_UNLOCK_CONDITION, ITEM_CHANGE_REASON, LINEUP_NUM, REDIS_KEY, TASK_TYPE } from '../../../consts';
|
||||
import { PVP } from '../../../pubUtils/dicParam';
|
||||
import { addItems, getGoldObject, handleCost, unlockFigure } from '../../../services/role/rewardService';
|
||||
@@ -22,6 +22,8 @@ import { PvpRecordModel } from '../../../db/PvpRecord';
|
||||
import { pvpEndParamInter } from '../../../pubUtils/interface';
|
||||
import { getSeconds, nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { PlayerDetail, PlayerDetailHero } from '../../../domain/battleField/guild';
|
||||
import { PvpSaveDataModel } from '../../../db/PvpSaveData';
|
||||
import { PVPConfigModel } from '../../../db/PvpConfig';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -44,7 +46,9 @@ export class PvpHandler {
|
||||
// 如果没有发过,将上赛季的奖励发下
|
||||
pvpDefense = await sendLastSeasonRewardIfNotSent(pvpDefense);
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
let seasonStartTime: number = this.app.get('pvpSeasonStartTime');
|
||||
let seasonEndTime: number = this.app.get('pvpSeasonEndTime');
|
||||
let seasonRewardTime: number = this.app.get('pvpSeasonRewardTime');
|
||||
|
||||
let update: pvpUpdateInter = { };
|
||||
let result = new PvpDataReturn(); // 返回对象
|
||||
@@ -68,17 +72,16 @@ export class PvpHandler {
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(roleId, update);
|
||||
}
|
||||
|
||||
result.setPvpConfig(seasonNum, seasonEndTime);
|
||||
result.setPvpConfig(seasonNum, seasonStartTime, seasonEndTime, seasonRewardTime);
|
||||
result.setPvpDefense(pvpDefense);
|
||||
result.calHasSaveDefense();
|
||||
|
||||
let oppPlayersReturn = await getEnemies(pvpDefense.oppPlayers||[], pvpDefense.winStreakNum);
|
||||
result.setOppPlayers(oppPlayersReturn);
|
||||
// 赛季结算
|
||||
let pvpSeasonResult = await PvpSeasonResultModel.getPvpSeasonResult(roleId);
|
||||
if (!!pvpSeasonResult && !!pvpSeasonResult.show && pvpDefense.seasonNum == seasonNum) {
|
||||
if (!!pvpSeasonResult && !!pvpSeasonResult.show) {
|
||||
result.setPvpSeasonResult(pvpSeasonResult);
|
||||
result.setIsFirstEntry(true);
|
||||
update.isFirstEntry = false;
|
||||
await PvpSeasonResultModel.setShow(roleId);
|
||||
}
|
||||
// 拍卖
|
||||
@@ -153,6 +156,9 @@ export class PvpHandler {
|
||||
if (!warInfo) {
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
if(!checkPvpSeasonIsStart()) {
|
||||
return resResult(STATUS.PVP_SEASON_NOT_OPEN);
|
||||
}
|
||||
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
if (!pvpDefense) return resResult(STATUS.PVP_NOT_OPEN);
|
||||
@@ -375,6 +381,30 @@ export class PvpHandler {
|
||||
return resResult(STATUS.SUCCESS, pick(result, ['attack', 'oppPlayers', 'buyAttackCnt', 'setAttackCnt', 'challengeCnt', 'challengeRefTime']));
|
||||
}
|
||||
|
||||
// 获取存档列表
|
||||
async getSaveData(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
if(!pvpDefense) return resResult(STATUS.PVP_NOT_OPEN);
|
||||
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
if(!pvpConfig) return resResult(STATUS.PVP_SEASON_NOT_OPEN);
|
||||
|
||||
let saveDatas = await PvpSaveDataModel.findByRoleId(roleId);
|
||||
|
||||
let list: pvpSaveDataReturn[] = [];
|
||||
for(let warId of (pvpConfig.warIds||[])) {
|
||||
let data = new pvpSaveDataReturn(warId);
|
||||
let curSaveData = saveDatas.find(cur => cur.warId == warId);
|
||||
data.setUserSaveData(curSaveData);
|
||||
if(pvpDefense.defense?.warId == warId) {
|
||||
data.setAsUsing();
|
||||
}
|
||||
list.push(data);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { list });
|
||||
}
|
||||
|
||||
//3. 保存防守阵容
|
||||
async saveDefense(msg: { heroes: { actorId: number, dataId: number, order: number, ai: number }[], warId: number, buff: number }, session: BackendSession) {
|
||||
let { heroes, warId, buff } = msg;
|
||||
@@ -382,10 +412,14 @@ export class PvpHandler {
|
||||
if (heroes.length > LINEUP_NUM || heroes.length <= 0) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
if(checkPvpSeasonIsSummit()) {
|
||||
return resResult(STATUS.PVP_CAN_NOT_SAVE_DEFENSE);
|
||||
}
|
||||
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
if(!pvpDefense) return resResult(STATUS.PVP_NOT_OPEN);
|
||||
// 刷新次数
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
let seasonEndTime: number = this.app.get('pvpSeasonEndTime');
|
||||
let refChallengeObj = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, roleId, session.get('vipStartTime'));
|
||||
// 更新防守阵容
|
||||
@@ -417,8 +451,8 @@ export class PvpHandler {
|
||||
});
|
||||
let defense = new Defense(defenseHeroes, scores, warId, buff);
|
||||
let lineupCe = await generPvpLineupCe(roleId, pvpDefense.lineupCe, pvpDefense.attack?.heroes??[], defense.heroes, dbHeroes);
|
||||
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(roleId, { ...refChallengeObj, defense, lineupCe });
|
||||
await PvpSaveDataModel.createSaveData(roleId, warId, buff, defenseHeroes);
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(roleId, { ...refChallengeObj, defense, lineupCe, hasDefense: true, seasonNum });
|
||||
// 返回
|
||||
let result = new PvpDataReturn();
|
||||
result.setPvpDefense(pvpDefense);
|
||||
@@ -584,10 +618,8 @@ export class PvpHandler {
|
||||
return resResult(STATUS.SUCCESS, { score, hisScore, heroScores });
|
||||
}
|
||||
|
||||
async debugPvpSeasonResetTime(msg: { day: number }, session: BackendSession) {
|
||||
let { day: minute } = msg;
|
||||
let { seasonNum, seasonEndTime } = await pinus.app.rpc.systimer.systimerRemote.resetPvpSeasonTime.toServer('systimer-server-1', minute);
|
||||
return resResult(STATUS.SUCCESS, { seasonNum, seasonEndTime });
|
||||
async debugPvpSeasonResetTime(msg: {}, session: BackendSession) {
|
||||
return resResult(STATUS.DEBUG_FUNCTION_ERR);
|
||||
}
|
||||
|
||||
async debugAddChallengeCnt(msg: { challengeCnt: number }, session: BackendSession) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Application, ChannelService, FrontendSession, RemoterClass, HandlerService, } from 'pinus';
|
||||
import { PVPConfigModel, PVPConfigType } from '../../../db/SystemConfig';
|
||||
import { Application, ChannelService, HandlerService, } from 'pinus';
|
||||
import { PVPConfigModel, PVPConfigType } from '../../../db/PvpConfig';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { savePvpSeasonMemory } from '../../../services/log/memoryLogService';
|
||||
import { taflush } from '../../../services/sdkService';
|
||||
import { setPvpSeasonNum, setPvpSettleSeasonNum } from '../../../services/timeTaskService';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -17,7 +18,6 @@ export class BattleRemote {
|
||||
constructor(private app: Application) {
|
||||
this.app = app;
|
||||
this.channelService = app.get('channelService');
|
||||
this.initPvpSeasonNum();
|
||||
}
|
||||
|
||||
private channelService: ChannelService;
|
||||
@@ -91,26 +91,23 @@ export class BattleRemote {
|
||||
}
|
||||
|
||||
|
||||
public setPvpSeasonNum(pvpConfig: PVPConfigType) {
|
||||
public async setPvpSettleSeasonNum(pvpConfig: PVPConfigType) {
|
||||
try {
|
||||
if(pvpConfig) {
|
||||
this.app.set('pvpSeasonNum', pvpConfig.seasonNum);
|
||||
this.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
|
||||
}
|
||||
await setPvpSettleSeasonNum(pvpConfig);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async initPvpSeasonNum() {
|
||||
public async setPvpSeasonNum(pvpConfig: PVPConfigType) {
|
||||
try {
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
this.setPvpSeasonNum(pvpConfig);
|
||||
await setPvpSeasonNum(pvpConfig);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public setServerMainten(serverIds: number[], startTime: number, endTime: number) {
|
||||
try {
|
||||
setServerMainten(serverIds, startTime, endTime);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Application, ChannelService, FrontendSession, pinus, RemoterClass, HandlerService, } from 'pinus';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { Application, HandlerService, } from 'pinus';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
import { UserGuildType } from '../../../db/UserGuild';
|
||||
import { incServerNum, kickUser } from '../../../services/connectorService';
|
||||
import { PVPConfigModel, PVPConfigType } from '../../../db/SystemConfig';
|
||||
import { PVPConfigModel, PVPConfigType } from '../../../db/PvpConfig';
|
||||
import { setDicAuctionTime, setDicGuildActivity } from '../../../services/guildActivity/guildActivityService';
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { taflush } from '../../../services/sdkService';
|
||||
@@ -12,6 +10,7 @@ import { errlogger } from '../../../util/logger';
|
||||
import { setWeek } from '../../../pubUtils/timeUtil';
|
||||
import { savePvpSeasonMemory } from '../../../services/log/memoryLogService';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setPvpSeasonNum, setPvpSettleSeasonNum } from '../../../services/timeTaskService';
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
return new ConnectorRemote(app);
|
||||
@@ -21,7 +20,6 @@ export class ConnectorRemote {
|
||||
|
||||
constructor(private app: Application) {
|
||||
this.app = app;
|
||||
this.initPvpSeasonNum();
|
||||
}
|
||||
|
||||
public async remoteLogin(uid: string, message?: any) {
|
||||
@@ -105,21 +103,17 @@ export class ConnectorRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public setPvpSeasonNum(pvpConfig: PVPConfigType) {
|
||||
public async setPvpSeasonNum(pvpConfig: PVPConfigType) {
|
||||
try {
|
||||
if(pvpConfig) {
|
||||
this.app.set('pvpSeasonNum', pvpConfig.seasonNum);
|
||||
this.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
|
||||
}
|
||||
await setPvpSeasonNum(pvpConfig);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async initPvpSeasonNum() {
|
||||
public async setPvpSettleSeasonNum(pvpConfig: PVPConfigType) {
|
||||
try {
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
this.setPvpSeasonNum(pvpConfig);
|
||||
await setPvpSettleSeasonNum(pvpConfig);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { genCode, getRandSingleEelm, resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import moment = require('moment');
|
||||
import { CreateServerParam, UpdateRegionParams } from '../../../domain/backEndField/params';
|
||||
import { CreatePvpConfigParam, CreateServerParam, UpdateRegionParams } from '../../../domain/backEndField/params';
|
||||
import { RegionModel, RegionType } from '../../../db/Region';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
import { Maintenance, ServerlistModel, ServerlistUpdate } from '../../../db/Serverlist';
|
||||
@@ -11,6 +11,7 @@ import { createNewServer, sendOpenServerMail } from '../../../services/gmService
|
||||
import { isNumber } from 'util';
|
||||
import { MarqueeModel } from '../../../db/Marquee';
|
||||
import { setApiIsCloseToRemote } from '../../../services/chatService';
|
||||
import { PVPConfigModel } from '../../../db/PvpConfig';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GmHandler(app);
|
||||
@@ -180,4 +181,21 @@ export class GmHandler {
|
||||
setApiIsCloseToRemote(region.isCloseApi);
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
async savePvpConfig(msg: CreatePvpConfigParam, session: BackendSession) {
|
||||
let params = new CreatePvpConfigParam(msg);
|
||||
if(!params.checkParams()) return resResult(STATUS.WRONG_PARMS);
|
||||
if(params.seasonStartTime >= params.seasonEndTime) return resResult(STATUS.WRONG_PARMS, null, '开始时间不可晚于结束时间');
|
||||
if(params.seasonEndTime >= params.seasonRewardTime) return resResult(STATUS.WRONG_PARMS, null, '结束时间不可晚于奖励时间');
|
||||
|
||||
if(await PVPConfigModel.checkTime(params.seasonNum, params.seasonStartTime, params.seasonRewardTime)) {
|
||||
return resResult(STATUS.WRONG_PARMS, null, '不可与其他赛季时间重叠');
|
||||
}
|
||||
|
||||
let uid = session.get('uid');
|
||||
await PVPConfigModel.createPVPConfig(params.seasonNum, params.getUpdateParam(), uid);
|
||||
pinus.app.rpc.systimer.systimerRemote.setPvpSeasonSchedule.broadcast(true);
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { Application, BackendSession, pinus } from "pinus";
|
||||
import { gameData, hasShopType } from "../../../pubUtils/data";
|
||||
import { parseGoodStr, resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, GUILD_STRUCTURE, ITID, CONSUME_TYPE, HERO_QUALITY_TYPE, HERO_GROW_MAX, ITEM_CHANGE_REASON } from "../../../consts";
|
||||
@@ -51,6 +51,7 @@ export class ShopHandler {
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
let serverId = session.get('serverId');
|
||||
let seasonNum = pinus.app.get('pvpSeasonNum');
|
||||
|
||||
let { activityId = 0, shopItemId, count } = msg;
|
||||
|
||||
@@ -58,7 +59,7 @@ export class ShopHandler {
|
||||
if(!dicShopItem) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(dicShopItem['productID'] && dicShopItem['productID'] != '&') return resResult(STATUS.CAN_NOT_PURCHASE);
|
||||
|
||||
let userShop = await UserShopModel.findByRoleAndItem(roleId, activityId, dicShopItem);
|
||||
let userShop = await UserShopModel.findByRoleAndItem(roleId, activityId, dicShopItem, seasonNum);
|
||||
|
||||
let checkResult = await checkShopInPurchase(session, activityId, count, userShop?.count||0, dicShopItem);
|
||||
if(checkResult.code != STATUS.SUCCESS.code) {
|
||||
@@ -71,7 +72,7 @@ export class ShopHandler {
|
||||
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
// 次数
|
||||
userShop = await UserShopModel.purchase(roleId, roleName, activityId, dicShopItem, count);
|
||||
userShop = await UserShopModel.purchase(roleId, roleName, activityId, dicShopItem, count, seasonNum);
|
||||
if(!userShop) return resResult(STATUS.BUY_COUNT_OVER);
|
||||
|
||||
// 获得
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import { Application, ChannelService, HandlerService, } from 'pinus';
|
||||
// import { sendRolesMails } from '../../../services/mailService';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
import { HeroUpdate } from '../../../db/Hero';
|
||||
import { RoleUpdate } from '../../../db/Role';
|
||||
import { SkinUpdate } from '../../../db/Skin';
|
||||
import { RankFirstModel, RankFirstType } from '../../../db/RankFirst';
|
||||
import { Figure } from '../../../domain/dbGeneral';
|
||||
import { PVPConfigModel, PVPConfigType } from '../../../db/SystemConfig';
|
||||
import { PVPConfigModel, PVPConfigType } from '../../../db/PvpConfig';
|
||||
import { treatRoleName, taflush, sendSurveyMail } from '../../../services/sdkService';
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setPvpSeasonNum, setPvpSettleSeasonNum } from '../../../services/timeTaskService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -23,7 +20,6 @@ export class RoleRemote {
|
||||
this.app = app;
|
||||
// this.channelService = app.get('channelService');
|
||||
this.loadRankFirst();
|
||||
this.initPvpSeasonNum();
|
||||
}
|
||||
// private channelService: ChannelService;
|
||||
|
||||
@@ -74,21 +70,17 @@ export class RoleRemote {
|
||||
}
|
||||
|
||||
|
||||
public setPvpSeasonNum(pvpConfig: PVPConfigType) {
|
||||
public async setPvpSeasonNum(pvpConfig: PVPConfigType) {
|
||||
try {
|
||||
if(pvpConfig) {
|
||||
this.app.set('pvpSeasonNum', pvpConfig.seasonNum);
|
||||
this.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
|
||||
}
|
||||
await setPvpSeasonNum(pvpConfig);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async initPvpSeasonNum() {
|
||||
public async setPvpSettleSeasonNum(pvpConfig: PVPConfigType) {
|
||||
try {
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
this.setPvpSeasonNum(pvpConfig);
|
||||
await setPvpSettleSeasonNum(pvpConfig);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Application, ChannelService } from 'pinus';
|
||||
import { resetPvpSeasonTime, guildActivityStart, gateActivityEnd, cityActivityEnd, raceActivityEnd, guildActivitySchedule, auctionSchedule, initMaintenance, stopMaintenance, initAutoCreateServer, addMailsToSchedule, updateTimeLimitRank, setLadderCountDown, cancelLadderCountDown, initSumSchedule } from '../../../services/timeTaskService';
|
||||
import { guildActivityStart, gateActivityEnd, cityActivityEnd, raceActivityEnd, guildActivitySchedule, auctionSchedule, initMaintenance, stopMaintenance, initAutoCreateServer, addMailsToSchedule, updateTimeLimitRank, setLadderCountDown, cancelLadderCountDown, initSumSchedule, setPvpSeasonSchedule } from '../../../services/timeTaskService';
|
||||
import PvpDefenseType from '../../../db/PvpDefense';
|
||||
import { DicGuildActivity } from '../../../pubUtils/dictionary/DicGuildActivity';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
@@ -30,14 +30,6 @@ export class SystimerRemote {
|
||||
}
|
||||
private channelService: ChannelService;
|
||||
|
||||
public async resetPvpSeasonTime(day: number) {
|
||||
try {
|
||||
return await resetPvpSeasonTime(day);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async guildActivityStart(dicGuildActivity: DicGuildActivity) {
|
||||
try {
|
||||
return await guildActivityStart(dicGuildActivity);
|
||||
@@ -232,4 +224,12 @@ export class SystimerRemote {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async setPvpSeasonSchedule(fromBackend: boolean) {
|
||||
try {
|
||||
setPvpSeasonSchedule(fromBackend);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import { ComBattleTeamModel } from '../db/ComBattleTeam';
|
||||
import { INFO_WINDOW } from '../pubUtils/dicParam';
|
||||
import { getLadderData } from './ladderService';
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { PvpDataReturn } from '../domain/battleField/pvp';
|
||||
|
||||
/**
|
||||
* init: 初始的时候是否推送 true-推 false-不推
|
||||
@@ -260,11 +261,17 @@ async function getPvpEntryData(roleId: string) {
|
||||
pvpDefense = await sendLastSeasonRewardIfNotSent(pvpDefense);
|
||||
let seasonNum: number = pinus.app.get('pvpSeasonNum');
|
||||
let seasonEndTime: number = pinus.app.get('pvpSeasonEndTime');
|
||||
let seasonStartTime: number = pinus.app.get('pvpSeasonStartTime');
|
||||
let seasonRewardTime: number = pinus.app.get('pvpSeasonRewardTime');
|
||||
|
||||
let result = new PvpDataReturn(); // 返回对象
|
||||
result.setPvpConfig(seasonNum, seasonStartTime, seasonEndTime, seasonRewardTime);
|
||||
result.setPvpDefense(pvpDefense);
|
||||
result.calHasSaveDefense();
|
||||
let refChallengeObj = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, roleId);
|
||||
let { challengeCnt } = refChallengeObj;
|
||||
let { receivedBox, score, seasonWinNum } = pvpDefense;
|
||||
|
||||
return { challengeCnt, score, seasonWinNum, receivedBox, seasonNum, seasonEndTime }
|
||||
result.setChallengeCnt(challengeCnt);
|
||||
return pick(result, ['challengeCnt', 'score', 'seasonWinNum', 'receivedBox', 'hasSaveDefense', 'seasonNum', 'seasonEndTime', 'seasonStartTime', 'seasonRewardTime'])
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { STATUS, MAIL_TYPE, GUILD_AUTH, GUILD_JOB, REDIS_KEY, CHAT_SERVER, TASK_
|
||||
import { RoleModel, RoleType } from "../db/Role";
|
||||
import { UserGuildModel, UserGuildType, WishGood } from "../db/UserGuild";
|
||||
import { UserGuildApplyModel } from "../db/UserGuildApply";
|
||||
import { PVPConfigModel } from "../db/SystemConfig";
|
||||
import { getZeroPointD, getZeroPointOfTime, getZeroPointOfTimeD, nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { pinus, BackendSession, FrontendOrBackendSession } from "pinus";
|
||||
import { ARMY } from "../pubUtils/dicParam";
|
||||
|
||||
@@ -2,23 +2,21 @@
|
||||
import { PvpDefenseModel, PvpDefenseType, pvpUpdateInter } from '../db/PvpDefense';
|
||||
import { Defense, Attack, LineupCe, OppPlayer, HeroScore, HeroReward, OppPlayerReturn, AttackHero, DefenseHero } from '../domain/battleField/pvp';
|
||||
import { RoleType } from '../db/Role';
|
||||
import { REDIS_KEY, TASK_TYPE, MAIL_TYPE, TA_EVENT, ITID, getHeadItid, getFrameItid, getSpineItid } from '../consts';
|
||||
import { REDIS_KEY, TASK_TYPE, MAIL_TYPE, TA_EVENT, ITID, getHeadItid, getFrameItid, getSpineItid, PVP_SEASON_STATUS } from '../consts';
|
||||
import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent";
|
||||
import { getRandSingleIndex, genCode, shouldRefresh, getChineseName, makeRobotId, robotIdComBack, getRandSingleEelm } from '../pubUtils/util';
|
||||
import { pvpEndParamInter, RewardInter } from '../pubUtils/interface';
|
||||
import { gameData, getPLvByScore, getPvpHeroRewardsByScore, getPvpRankRewardsByRank, getPvpDifficultByScore, getPlvAndScore, getPvpBoxsBySeasonNum, getPvpRankMaxRewardsBySeasonNum, randomGoodsByItid } from "../pubUtils/data";
|
||||
import { EXTERIOR, PVP } from '../pubUtils/dicParam';
|
||||
import { PVPConfigModel, PVPConfigType } from '../db/SystemConfig'
|
||||
import { PVPConfigModel } from '../db/PvpConfig'
|
||||
import { nowSeconds, getTimeFun } from '../pubUtils/timeUtil';
|
||||
import { HeroesRecord, PvpRecordPlayerInfo } from '../db/PvpRecord';
|
||||
import { HeroModel, HeroType } from '../db/Hero';
|
||||
import { AttributeCal } from '../domain/roleField/attribute';
|
||||
import { PvpEnemies, PvpHeroInfo, PvpOtherHeroes } from '../domain/dbGeneral';
|
||||
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
|
||||
import { pinus } from 'pinus';
|
||||
import { PvpHistoryOppModel, PvpHistoryOppType, PvpOppCreateParam } from '../db/PvpHistoryOpp';
|
||||
import { Rank } from './rankService';
|
||||
import { CounterModel } from '../db/Counter';
|
||||
import { DicRankRewads } from '../pubUtils/dictionary/DicPvpRankReward';
|
||||
import { PvpSeasonResultModel, PvpSeasonResultType } from '../db/PvpSeasonResult';
|
||||
import { checkTask } from './task/taskService';
|
||||
@@ -27,6 +25,7 @@ import { RoleRankInfo } from '../domain/rank';
|
||||
import { reportTAEvent } from './sdkService';
|
||||
import { getVipPvpChallengeMaxCnt } from './activity/monthlyTicketService';
|
||||
import { getHeroesAttributes } from './playerCeService';
|
||||
import { setPvpSeasonNumToRemote, setPvpSettleSeasonNumToRemote } from './timeTaskService';
|
||||
|
||||
/**
|
||||
* 返回对手三人信息
|
||||
@@ -166,7 +165,7 @@ export async function matchPlayerByRank(seasonNum: number, chosenOpps: string[],
|
||||
oppRoleId = result[0];
|
||||
|
||||
let pvpdefense = await PvpDefenseModel.findByRoleIdIncludeAll(oppRoleId);
|
||||
if (!pvpdefense || pvpdefense.seasonNum != seasonNum) return null;
|
||||
if (!pvpdefense || pvpdefense.seasonNum != seasonNum || !pvpdefense.hasDefense) return null;
|
||||
let pvpHistoryOpp = await generPlayerOppHis(pvpdefense, roleId, pos);
|
||||
if (!pvpHistoryOpp) return null;
|
||||
|
||||
@@ -367,15 +366,21 @@ export async function comsumeChallengeCnt(challengeCnt: number, challengeRefTime
|
||||
}
|
||||
|
||||
export async function sendLastSeasonRewardIfNotSent(pvpDefense: PvpDefenseType) {
|
||||
let seasonNum: number = pinus.app.get('pvpSeasonNum');
|
||||
if(pvpDefense.seasonNum < seasonNum) {
|
||||
let oldPvpCongig = await PVPConfigModel.findPVPConfig(pvpDefense.seasonNum);
|
||||
let result = await sendPVPRewardToUser(pvpDefense, pvpDefense.seasonNum, oldPvpCongig.seasonEndTime);
|
||||
let seasonSettleNum: number = pinus.app.get('pvpSettleSeasonNum');
|
||||
console.log('##### sendLastSeasonRewardIfNotSent seasonSettleNum', seasonSettleNum)
|
||||
if(seasonSettleNum && !await checkHasSettled(seasonSettleNum, pvpDefense.roleId)) {
|
||||
let oldPvpCongig = await PVPConfigModel.findPVPConfig(seasonSettleNum);
|
||||
let result = await sendPVPRewardToUser(pvpDefense, seasonSettleNum, oldPvpCongig.seasonEndTime);
|
||||
pvpDefense = result.pvpDefense;
|
||||
}
|
||||
return pvpDefense;
|
||||
}
|
||||
|
||||
async function checkHasSettled(seasonSettleNum: number, roleId: string) {
|
||||
let hasData = await PvpSeasonResultModel.checkResultBySeasonNum(roleId, seasonSettleNum);
|
||||
return hasData;
|
||||
}
|
||||
|
||||
// 获取刷新对手次数及消耗
|
||||
export function refreshRefOppCnt(pvpDefense: PvpDefenseType) {
|
||||
let { refOppCnt = 0, setAttackCnt = 0, buyAttackCnt = 0, refDaily } = pvpDefense;
|
||||
@@ -563,7 +568,8 @@ export async function generPVPOppRecInfo(isSuccess: boolean, curOpp: OppPlayer,
|
||||
let { pvpSeasonResult } = await sendPVPRewardToUser(pvpDefense, pvpConfig.seasonNum, pvpConfig.seasonEndTime);
|
||||
reportTAEvent(roleId, TA_EVENT.PVP_SEASON_END, { top_rank: rank, hero_score: pvpSeasonResult.heroScores })
|
||||
}
|
||||
await PVPConfigModel.setReward(pvpConfig.seasonNum);
|
||||
let settledPvpConfig = await PVPConfigModel.setReward(pvpConfig.seasonNum);
|
||||
await setPvpSettleSeasonNumToRemote(settledPvpConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,7 +599,7 @@ export async function sendPVPRewardToUser(pvpDefense: PvpDefenseType, seasonNum:
|
||||
|
||||
return {
|
||||
pvpSeasonResult,
|
||||
pvpDefense: await resetPvpScores(pvpDefense, seasonNum + 1, pvpSeasonResult)
|
||||
pvpDefense: await resetPvpScores(pvpDefense, pvpSeasonResult)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,17 +618,16 @@ async function sendUnreceivedPvpBox(roleId: string, seasonNum: number, seasonWin
|
||||
}
|
||||
}
|
||||
|
||||
async function resetPvpScores(pvpDefense: PvpDefenseType, seasonNum: number, pvpSeasonResult: PvpSeasonResultType) {
|
||||
let { roleId, attack, defense } = pvpDefense;
|
||||
async function resetPvpScores(pvpDefense: PvpDefenseType, pvpSeasonResult: PvpSeasonResultType) {
|
||||
let { roleId, attack } = pvpDefense;
|
||||
let { newHeroScores, newScore } = pvpSeasonResult;
|
||||
let initCount = await getVipPvpChallengeMaxCnt(roleId)
|
||||
|
||||
let newAttack = <Attack>calLineupScore(attack, newHeroScores);
|
||||
let newDefense = <Defense>calLineupScore(defense, newHeroScores);
|
||||
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(roleId, {
|
||||
heroScores: newHeroScores, score: newScore, attack: newAttack, defense: newDefense,
|
||||
seasonNum, challengeCnt: initCount, challengeRefTime: 0, winStreakNum: 0, isFirstEntry: true,
|
||||
heroScores: newHeroScores, score: newScore, attack: newAttack, defense: null, hasDefense: false,
|
||||
challengeCnt: initCount, challengeRefTime: 0, winStreakNum: 0,
|
||||
seasonWinNum: 0, receivedBox: []
|
||||
});
|
||||
return pvpDefense;
|
||||
@@ -664,8 +669,9 @@ export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum:
|
||||
}
|
||||
|
||||
//pvp锁定的信息存入赛季结算表中
|
||||
let {receivedBox, score, seasonWinNum, heroScores } = pvpDefense;
|
||||
let pvpSeasonResult = await PvpSeasonResultModel.updatePvpSeasonResult(pvpDefense.roleId, seasonNum, {
|
||||
...pvpDefense, rankLv, heroGoods, rankGoods, show: true, newScore, newHeroScores, seasonEndTime
|
||||
receivedBox, score, seasonWinNum, heroScores, rankLv, heroGoods, rankGoods, show: true, newScore, newHeroScores, seasonEndTime
|
||||
});//结算修改玩家pvp信息
|
||||
if(newScore > 0) {
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: seasonNum + 1 });
|
||||
@@ -702,4 +708,29 @@ export async function generPvpLineupCe(roleId: string, lineupCe: LineupCe[], att
|
||||
newLineupCe.push({ hid, ce });
|
||||
}
|
||||
return newLineupCe;
|
||||
}
|
||||
|
||||
|
||||
export function getPvpSeasonStatus() {
|
||||
let seasonEndTime: number = pinus.app.get('pvpSeasonEndTime');
|
||||
let seasonStartTime: number = pinus.app.get('pvpSeasonStartTime');
|
||||
let seasonRewardTime: number = pinus.app.get('pvpSeasonRewardTime');
|
||||
let now = nowSeconds();
|
||||
if(now >= seasonStartTime && now < seasonEndTime) {
|
||||
return PVP_SEASON_STATUS.START;
|
||||
} else if (now >= seasonEndTime && now < seasonRewardTime) {
|
||||
return PVP_SEASON_STATUS.SUMMIT;
|
||||
} else {
|
||||
return PVP_SEASON_STATUS.WAITING;
|
||||
}
|
||||
}
|
||||
|
||||
export function checkPvpSeasonIsStart() {
|
||||
let status = getPvpSeasonStatus();
|
||||
return status == PVP_SEASON_STATUS.START;
|
||||
}
|
||||
|
||||
export function checkPvpSeasonIsSummit() {
|
||||
let status = getPvpSeasonStatus();
|
||||
return status == PVP_SEASON_STATUS.SUMMIT;
|
||||
}
|
||||
@@ -9,13 +9,14 @@ import { UserShopTypeModel, UserShopTypeType } from "../db/UserShopType";
|
||||
import { GuildModel } from "../db/Guild";
|
||||
import { RoleModel } from "../db/Role";
|
||||
import { DicShop } from "../pubUtils/dictionary/DicShop";
|
||||
import { BackendSession } from "pinus";
|
||||
import { BackendSession, pinus } from "pinus";
|
||||
import { ActivityModelType } from "../db/Activity";
|
||||
import { addItems } from "./role/rewardService";
|
||||
import { LadderMatchModel } from "../db/LadderMatch";
|
||||
|
||||
export async function getAllShopList(roleId: string, serverId: number) {
|
||||
let userShopRecs = await UserShopModel.findByRoleId(roleId);
|
||||
let seasonNum = pinus.app.get('pvpSeasonNum');
|
||||
let userShopRecs = await UserShopModel.findByRoleId(roleId, seasonNum);
|
||||
let userShopTypeRecs = await UserShopTypeModel.findByRoleId(roleId);
|
||||
let activities = await getShopActivityDatas(roleId, serverId);
|
||||
|
||||
@@ -30,7 +31,8 @@ export async function getAllShopList(roleId: string, serverId: number) {
|
||||
}
|
||||
|
||||
export async function getShopListByType(shop: number, type: number, roleId: string, serverId: number) {
|
||||
let userShopRecs = await UserShopModel.findByShopType(roleId, shop, type);
|
||||
let seasonNum = pinus.app.get('pvpSeasonNum');
|
||||
let userShopRecs = await UserShopModel.findByShopType(roleId, shop, type, seasonNum);
|
||||
let activities = await getShopActivityDatas(roleId, serverId);
|
||||
let activity = activities.find(cur => cur.shop == shop && cur.type == type);
|
||||
let readRecord = await UserShopTypeModel.findByType(roleId, shop, type);
|
||||
@@ -128,6 +130,7 @@ export async function checkShopInPurchase(session: BackendSession, activityId: n
|
||||
}
|
||||
|
||||
export async function checkShopCanBuyInOrder(roleId: string, serverId: number, activity: ActivityModelType, productID: string) {
|
||||
let seasonNum = pinus.app.get('pvpSeasonNum');
|
||||
let role = await RoleModel.findByRoleId(roleId, 'guildCode createTime vipStartTime');
|
||||
let { createTime, guildCode, vipStartTime } = role;
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
@@ -136,7 +139,7 @@ export async function checkShopCanBuyInOrder(roleId: string, serverId: number, a
|
||||
let dicItem = shopData.findByProductID(productID);
|
||||
if(!dicItem) return false;
|
||||
|
||||
let userShop = await UserShopModel.findByRoleAndItem(roleId, activity.activityId, dicItem);
|
||||
let userShop = await UserShopModel.findByRoleAndItem(roleId, activity.activityId, dicItem, seasonNum);
|
||||
let result = await checkShopItemCanBuy(activity.activityId, dicItem.id, roleId, serverId, guildCode, vipStartTime, 1, userShop?.count||0, dicItem);
|
||||
return result.code == STATUS.SUCCESS.code;
|
||||
}
|
||||
@@ -188,6 +191,7 @@ export async function checkShopItemCanBuy(activityId: number, shopItemId: number
|
||||
*
|
||||
*/
|
||||
export async function makeShopOrder(roleId: string, roleName: string, sid: string, serverId: number, activityId: number, productID: string) {
|
||||
let seasonNum = pinus.app.get('pvpSeasonNum');
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
if (!activityData) {
|
||||
return STATUS.ACTIVITY_MISSING;
|
||||
@@ -206,7 +210,7 @@ export async function checkShopItemCanBuy(activityId: number, shopItemId: number
|
||||
}];
|
||||
await addItems(roleId, roleName, sid, reward, ITEM_CHANGE_REASON.SHOP_PURCHASE);
|
||||
|
||||
await UserShopModel.purchase(roleId, roleName, activityId, dicItem, 1);
|
||||
await UserShopModel.purchase(roleId, roleName, activityId, dicItem, 1, seasonNum);
|
||||
return {
|
||||
code: 0,
|
||||
data: Object.assign({}, { item: { shop: dicItem.shop, type: dicItem.type, shopItemId: dicItem.id }, activityId: activityId })
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
import { scheduleJob, Job, scheduledJobs, } from 'node-schedule';
|
||||
import { PVPConfigModel, PVPConfigType } from '../db/SystemConfig';
|
||||
import { PVPConfigModel, PVPConfigType } from '../db/PvpConfig';
|
||||
import { nowSeconds, getTimeFun, getSeconds } from '../pubUtils/timeUtil';
|
||||
import { getTodayGuildActivity, gameData } from '../pubUtils/data';
|
||||
import { pvpSeasonEnd } from './pvpService';
|
||||
@@ -46,6 +46,7 @@ const PER_SECOND = 1 * 1000;
|
||||
const PER_DAY = 24 * 60 * 60;
|
||||
const PER_HOUR = 1 * 60 * 60;
|
||||
const PER_MINUTE = 1 * 60;
|
||||
var seasonEndJob: Job;
|
||||
var seasonMakeRewardTimJobId: Job;
|
||||
var seasonRefreshTimeJobId: Job;
|
||||
let guildWeeklyJobId: Job;
|
||||
@@ -61,7 +62,7 @@ export async function init() {
|
||||
console.log('******* init systimer *******')
|
||||
|
||||
// pvp赛季
|
||||
await setPvpSeason(true);
|
||||
await setPvpSeasonSchedule();
|
||||
|
||||
// 周功勋结算任务
|
||||
guildWeeklyJobId = scheduleJob('settleGuildWeekly', '0 0 0 * * 1', settleGuildWeekly);
|
||||
@@ -115,111 +116,115 @@ export async function everydayRefresh() {
|
||||
|
||||
|
||||
// —————————————— PVP 及赛季相关 —————————————— //
|
||||
function getSeasonContinueDay(seasonNum: number) {
|
||||
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) {
|
||||
if(seasonNum == dicSeasonNum) return day;
|
||||
if(maxDay < day) maxDay = day;
|
||||
export async function setPvpSeasonSchedule(fromBackend = false) {
|
||||
let pvpConfig = await PVPConfigModel.setCurrentPvp();
|
||||
await setSeasonEndJob(pvpConfig);
|
||||
await setPvpSeasonMakeRewardJob(pvpConfig); // 发送奖励定时器
|
||||
await setNextSeasonJob(pvpConfig); // 赛季开始定时器
|
||||
if(fromBackend) {
|
||||
setPvpSeasonNumToRemote(pvpConfig);
|
||||
setPvpSettleSeasonNumToRemote();
|
||||
} else {
|
||||
setPvpSeasonNum(pvpConfig);
|
||||
setPvpSettleSeasonNum();
|
||||
}
|
||||
return maxDay;
|
||||
}
|
||||
|
||||
async function setPvpSeasonJob() {
|
||||
await setPvpSeason(false);
|
||||
}
|
||||
|
||||
async function setPvpSeason(isFirst: boolean, isForce?: boolean, minute?: number) {
|
||||
console.log(`******** setPvpSeason1: isForce-${isForce}, minute-${minute}`)
|
||||
|
||||
let during = minute? minute * PER_MINUTE: null; // 下一次重置赛季天数
|
||||
let oldPvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
let pvpConfig = oldPvpConfig;
|
||||
console.log(`******** setPvpSeason2: during-${during}, seasonEndTime-${pvpConfig?.seasonEndTime}, now-${nowSeconds()}`)
|
||||
if(!pvpConfig || pvpConfig.seasonEndTime - PER_MINUTE <= nowSeconds() || isForce) {
|
||||
if(pvpConfig && !pvpConfig.hasSettleReward) {
|
||||
await pvpSeasonEnd(pvpConfig.seasonNum);
|
||||
}
|
||||
|
||||
let lastSeasonNum = pvpConfig? pvpConfig.seasonNum: 0;
|
||||
let lastSeasonEndTime = pvpConfig? pvpConfig.seasonEndTime: 0;
|
||||
console.log(`******** setPvpSeason3: lastSeasonNum-${lastSeasonNum}, lastSeasonEndTime-${lastSeasonEndTime}`)
|
||||
|
||||
let newSeasonStartTime = lastSeasonEndTime;
|
||||
if(!during) during = getSeasonContinueDay(lastSeasonNum + 1) * PER_DAY;
|
||||
let rewardTime = PVP.PVP_SEASON_REWARD_TIME_BEFORE * PER_MINUTE;
|
||||
if(nowSeconds() - newSeasonStartTime > during) {
|
||||
newSeasonStartTime = <number>getTimeFun().getDayZeroPoint(0);
|
||||
}
|
||||
console.log(`******** setPvpSeason4: newSeasonStartTime-${newSeasonStartTime}, during-${during}`)
|
||||
|
||||
if(isForce) { // debug使用,如果seasonEndTime是未来的,强行结束掉,新赛季从现在开始
|
||||
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);
|
||||
async function setSeasonEndJob(pvpConfig: PVPConfigType) {
|
||||
if (!!seasonEndJob) {
|
||||
seasonEndJob.cancel();
|
||||
}
|
||||
await setPvpSeasonMakeRewardJob(pvpConfig);
|
||||
await setNextSeasonJob(pvpConfig);
|
||||
setPvpSeasonNum(pvpConfig, isFirst);
|
||||
return pvpConfig;
|
||||
}
|
||||
|
||||
function setPvpSeasonNum(pvpConfig: PVPConfigType, isFirst = false) {
|
||||
if(pvpConfig) {
|
||||
pinus.app.set('pvpSeasonNum', pvpConfig.seasonNum);
|
||||
pinus.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
|
||||
if(!isFirst) {
|
||||
pinus.app.rpc.battle.battleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
pinus.app.rpc.role.roleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
pinus.app.rpc.connector.connectorRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
}
|
||||
if(!pvpConfig || pvpConfig.seasonEndTime < nowSeconds()) {
|
||||
pvpConfig = await PVPConfigModel.findPVPConfig(pvpConfig? pvpConfig.seasonNum + 1: 1);
|
||||
if(!pvpConfig) return;
|
||||
}
|
||||
console.log('####### setSeasonEndJob', JSON.stringify(pvpConfig))
|
||||
|
||||
seasonEndJob = scheduleJob('seasonEndJob', pvpConfig.seasonEndTime * 1000, async () => {
|
||||
console.log('************ setSeasonEndJob *********');
|
||||
setPvpSeasonNumToRemote(pvpConfig);
|
||||
let nextPvpConfig = await PVPConfigModel.findPVPConfig(pvpConfig.seasonNum + 1);
|
||||
await setSeasonEndJob(nextPvpConfig);
|
||||
});
|
||||
}
|
||||
|
||||
async function setPvpSeasonMakeRewardJob(pvpConfig: PVPConfigType) {
|
||||
if (!!seasonMakeRewardTimJobId) {
|
||||
seasonMakeRewardTimJobId.cancel();
|
||||
}
|
||||
if(!pvpConfig) return;
|
||||
if(pvpConfig.seasonRewardTime < nowSeconds() && !pvpConfig.hasSettleReward) { // 未发奖励
|
||||
await pvpSeasonEnd(pvpConfig.seasonNum);
|
||||
} else {
|
||||
seasonMakeRewardTimJobId = scheduleJob('seasonMakeRewardTimJobId', pvpConfig.seasonRewardTime * 1000, async () => {
|
||||
console.log('************ seasonMakeRewardTimJobId *********');
|
||||
await pvpSeasonEnd(pvpConfig.seasonNum);
|
||||
});
|
||||
if(!pvpConfig || pvpConfig.seasonRewardTime - 60 < nowSeconds()) {
|
||||
pvpConfig = await PVPConfigModel.findPVPConfig(pvpConfig? pvpConfig.seasonNum + 1: 1);
|
||||
if(!pvpConfig) return;
|
||||
}
|
||||
console.log('####### setPvpSeasonMakeRewardJob', JSON.stringify(pvpConfig))
|
||||
seasonMakeRewardTimJobId = scheduleJob('seasonMakeRewardTimJobId', pvpConfig.seasonRewardTime * 1000 - 60 * 1000, async () => {
|
||||
console.log('************ seasonMakeRewardTimJobId *********');
|
||||
await pvpSeasonEnd(pvpConfig.seasonNum);
|
||||
let nextPvpConfig = await PVPConfigModel.findPVPConfig(pvpConfig.seasonNum + 1);
|
||||
await setPvpSeasonMakeRewardJob(nextPvpConfig);
|
||||
});
|
||||
}
|
||||
|
||||
async function setNextSeasonJob(pvpConfig: PVPConfigType) {
|
||||
if (!!seasonRefreshTimeJobId) {
|
||||
seasonRefreshTimeJobId.cancel();
|
||||
}
|
||||
//定时开启新赛季,比seasonEndTime多定一分钟,保证定时器时间没错
|
||||
seasonRefreshTimeJobId = scheduleJob('seasonRefreshTimeJobId', (pvpConfig.seasonEndTime) * 1000, setPvpSeasonJob);
|
||||
if(!pvpConfig || pvpConfig.seasonStartTime < nowSeconds()) {
|
||||
pvpConfig = await PVPConfigModel.findPVPConfig(pvpConfig? pvpConfig.seasonNum + 1: 1);
|
||||
if(!pvpConfig) return;
|
||||
}
|
||||
console.log('####### setNextSeasonJob', JSON.stringify(pvpConfig))
|
||||
|
||||
seasonRefreshTimeJobId = scheduleJob('seasonRefreshTimeJobId', pvpConfig.seasonStartTime * 1000, async () => {
|
||||
console.log('************ setNextSeasonJob *********');
|
||||
setPvpSeasonNumToRemote(pvpConfig);
|
||||
await PVPConfigModel.setNextPvp(pvpConfig.seasonNum);
|
||||
let nextPvpConfig = await PVPConfigModel.findPVPConfig(pvpConfig.seasonNum + 1);
|
||||
await setNextSeasonJob(nextPvpConfig);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* debug接口
|
||||
* @param hour
|
||||
*/
|
||||
export async function resetPvpSeasonTime(minute: number) {
|
||||
return await setPvpSeason(false, true, minute);
|
||||
export async function setPvpSeasonNumToRemote(pvpConfig: PVPConfigType) {
|
||||
await setPvpSeasonNum(pvpConfig);
|
||||
await pinus.app.rpc.battle.battleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
await pinus.app.rpc.role.roleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
await pinus.app.rpc.connector.connectorRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
}
|
||||
|
||||
export async function setPvpSeasonNum(pvpConfig?: PVPConfigType) {
|
||||
if(!pvpConfig) {
|
||||
pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
if(!pvpConfig) return;
|
||||
}
|
||||
|
||||
let now = nowSeconds();
|
||||
pinus.app.set('pvpSeasonNum', pvpConfig.seasonNum);
|
||||
pinus.app.set('pvpSeasonStartTime', pvpConfig.seasonStartTime);
|
||||
pinus.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
|
||||
pinus.app.set('pvpSeasonRewardTime', pvpConfig.seasonRewardTime);
|
||||
if(pvpConfig.seasonEndTime <= now) { // 赛季结束,需要显示下一赛季的倒计时
|
||||
let nextPvpConfig = await PVPConfigModel.findPVPConfig(pvpConfig.seasonNum + 1);
|
||||
if(nextPvpConfig) {
|
||||
pinus.app.set('pvpSeasonStartTime', nextPvpConfig.seasonStartTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function setPvpSettleSeasonNumToRemote(settledPvpConfig?: PVPConfigType) {
|
||||
setPvpSettleSeasonNum(settledPvpConfig);
|
||||
await pinus.app.rpc.battle.battleRemote.setPvpSettleSeasonNum.broadcast(settledPvpConfig);
|
||||
await pinus.app.rpc.role.roleRemote.setPvpSettleSeasonNum.broadcast(settledPvpConfig);
|
||||
await pinus.app.rpc.connector.connectorRemote.setPvpSettleSeasonNum.broadcast(settledPvpConfig);
|
||||
}
|
||||
|
||||
export async function setPvpSettleSeasonNum(settledPvpConfig?: PVPConfigType) {
|
||||
if(!settledPvpConfig) {
|
||||
settledPvpConfig = await PVPConfigModel.getSettledConfig();
|
||||
if(!settledPvpConfig) return;
|
||||
}
|
||||
pinus.app.set('pvpSettleSeasonNum', settledPvpConfig.seasonNum);
|
||||
}
|
||||
|
||||
export async function reportOnlineSchedule() {
|
||||
|
||||
@@ -399,7 +399,6 @@ function getData(pinusClient, seasonEnd: boolean, cb) {
|
||||
expect(heroScore.hid).to.be.a('number');
|
||||
expect(heroScore.score).to.be.a('number');
|
||||
});
|
||||
expect(res.data.isFirstEntry).to.be.a('boolean');
|
||||
if (seasonEnd) {
|
||||
checkSeasonResult(res.data.seasonResult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user