pvp:修复赛季相关
This commit is contained in:
@@ -21,9 +21,10 @@ import { PvpHistoryOppModel, PvpHistoryOppType } from '../db/PvpHistoryOpp';
|
||||
import { Rank } from './rankService';
|
||||
import { CounterModel } from '../db/Counter';
|
||||
import { DicRankRewads } from '../pubUtils/dictionary/DicPvpRankReward';
|
||||
import { PvpSeasonResultModel } from '../db/PvpSeasonResult';
|
||||
import { PvpSeasonResultModel, PvpSeasonResultType } from '../db/PvpSeasonResult';
|
||||
import { checkTask } from '../services/taskService';
|
||||
import { sendMailByContent } from './mailService';
|
||||
import { RoleRankInfo } from '../domain/rank';
|
||||
|
||||
/**
|
||||
* 返回对手三人信息
|
||||
@@ -57,13 +58,13 @@ export async function getEnemies(oppPlayers: OppPlayer[], winStreakNum: number)
|
||||
* @param score 我的军功
|
||||
* @param pLv 我的排名
|
||||
*/
|
||||
export async function refreshEnemies(role: RoleType, seasonNum: number, score: number, pLv: number) {
|
||||
export async function refreshEnemies(role: RoleType, seasonNum: number, sumScore: number, score: number, pLv: number) {
|
||||
let { roleId } = role;
|
||||
let oppPlayers: OppPlayer[] = [];
|
||||
let opp = dicPvpOpponent.values()
|
||||
for (let dicOpp of opp) {
|
||||
let flag = false; // 是否筛选成功
|
||||
if (score >= PVP_CONST.SCORE_LINE) { // 将这个放到const
|
||||
if (sumScore >= PVP_CONST.SCORE_LINE) { // 将这个放到const
|
||||
flag = await matchPlayer(seasonNum, oppPlayers, roleId, pLv, dicOpp); // 按照等级匹配对手
|
||||
if (!flag) flag = await matchPlayerByRank(seasonNum, oppPlayers, roleId, dicOpp.id); // 当前后分数段没有时,返回前一名的玩家
|
||||
if (!flag) flag = await matchRobot(oppPlayers, role, score, dicOpp);
|
||||
@@ -78,7 +79,7 @@ export async function refreshEnemies(role: RoleType, seasonNum: number, score: n
|
||||
|
||||
export async function matchPlayerByRank(seasonNum: number, oppPlayers: OppPlayer[], roleId: string, pos: number) {
|
||||
// console.log('matchPlayerByRank', JSON.stringify(oppPlayers))
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, {});
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let ridRanks = new Array<number>(); // 已经被使用了的排名
|
||||
for (let { roleId: curRoleId } of oppPlayers) {
|
||||
let rankLv = await r.getMyRank({ roleId: robotIdComBack(curRoleId) });
|
||||
@@ -183,7 +184,9 @@ async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos
|
||||
if(!defense) return false;
|
||||
let { warId, heroes: defenseHeroes } = defense;
|
||||
let role = <RoleType>pvpdefense.role;
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, {});
|
||||
|
||||
let seasonNum: number = pinus.app.get('pvpSeasonNum');
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let rankLv = await r.getMyRank({ roleId: role.roleId });
|
||||
let dbHeroes = await HeroModel.findByRole(role.roleId, [{ field: 'ce', sortBy: -1 }]);
|
||||
let heroes = new Array<PvpEnemies>();
|
||||
@@ -202,6 +205,7 @@ async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos
|
||||
let { attribute, ce } = getPlayerAttribute(dbHero.lv, dbHero.attr, role.attr);
|
||||
heroInfo.setAttribute(attribute);
|
||||
let enemy = new PvpEnemies(warJson, heroInfo, hs ? hs.score : 0, ce);
|
||||
enemy.setOutIndex(h.order);
|
||||
heroes.push(enemy);
|
||||
defCe += ce;
|
||||
}
|
||||
@@ -244,6 +248,7 @@ async function matchRobot(oppPlayers: OppPlayer[], role: RoleType, score: number
|
||||
defCe += ce;
|
||||
heroInfo.setAttribute(attribute);
|
||||
let enemy = new PvpEnemies(h, heroInfo, 0, ce);
|
||||
enemy.setOutIndex(h.outIndex);
|
||||
heroes.push(enemy);
|
||||
}
|
||||
|
||||
@@ -322,8 +327,8 @@ export function comsumeChallengeCnt(challengeCnt: number, challengeRefTime: numb
|
||||
}
|
||||
|
||||
export async function sendLastSeasonRewardIfNotSent(pvpDefense: PvpDefenseType) {
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig(); // 当前的pvp赛季
|
||||
if(pvpDefense.seasonNum != pvpConfig.seasonNum && pvpConfig.seasonEndTime < nowSeconds()) {
|
||||
let seasonNum: number = pinus.app.get('pvpSeasonNum');
|
||||
if(pvpDefense.seasonNum != seasonNum) {
|
||||
let oldPvpCongig = await PVPConfigModel.findPVPConfig(pvpDefense.seasonNum);
|
||||
pvpDefense = await sendPVPRewardToUser(pvpDefense, pvpDefense.seasonNum, oldPvpCongig.seasonEndTime);
|
||||
}
|
||||
@@ -510,19 +515,15 @@ export async function generPVPOppRecInfo(isSuccess: boolean, curOpp: OppPlayer,
|
||||
* @param obj
|
||||
*/
|
||||
export async function pvpSeasonEnd(pvpConfig: PVPConfigType) {
|
||||
const pageNum = 500;
|
||||
console.log('exce pvpSeasonEnd' + pvpConfig?.seasonNum);
|
||||
let systemConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
console.log('exce pvpSeasonEnd' + pvpConfig.seasonNum);
|
||||
let resultMaxRank = gameData.pvpRankMax.max;//根据排行榜的奖励表,获得最大排名挡位的最小值,其余不在结算中结算的玩家按照最大排名挡位在登录或进入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);
|
||||
for (let pvpDefense of pvpDefenses) {
|
||||
if (pvpDefense.seasonNum !== systemConfig.seasonNum) {
|
||||
await sendPVPRewardToUser(pvpDefense, systemConfig.seasonNum, systemConfig.seasonEndTime);
|
||||
}
|
||||
}
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: pvpConfig.seasonNum });
|
||||
let allRank = <RoleRankInfo[]>(await r.getRankByRank(0, resultMaxRank.min - 2));
|
||||
console.log('******** resultMaxRank', resultMaxRank.max)
|
||||
for(let { rank, roleId } of allRank) {
|
||||
console.log('******** pvpSeasonEnd: ', rank, roleId);
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
await sendPVPRewardToUser(pvpDefense, pvpConfig.seasonNum, pvpConfig.seasonEndTime);
|
||||
}
|
||||
await PVPConfigModel.setReward(pvpConfig.seasonNum);
|
||||
}
|
||||
@@ -549,7 +550,20 @@ export async function sendPVPRewardToUser(pvpDefense: PvpDefenseType, seasonNum:
|
||||
goods: heroGoods, endTime: seasonEndTime, notPush
|
||||
});
|
||||
|
||||
pvpDefense = await PvpDefenseModel.resetScores(pvpDefense.roleId, seasonNum + 1, pvpSeasonResult.newScore, pvpSeasonResult.newHeroScores);
|
||||
return await resetPvpScores(pvpDefense, seasonNum + 1, pvpSeasonResult);
|
||||
}
|
||||
|
||||
async function resetPvpScores(pvpDefense: PvpDefenseType, seasonNum: number, pvpSeasonResult: PvpSeasonResultType) {
|
||||
let { roleId, attack, defense } = pvpDefense;
|
||||
let { heroScores, score } = pvpSeasonResult;
|
||||
|
||||
let newAttack = <Attack>calLineupScore(attack, heroScores);
|
||||
let newDefense = <Defense>calLineupScore(defense, heroScores);
|
||||
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(roleId, {
|
||||
heroScores, score, attack: newAttack, defense: newDefense,
|
||||
seasonNum, challengeCnt: PVP.PVP_CHALLENGE_COUNTS, challengeRefTime: 0, winStreakNum: 0
|
||||
});
|
||||
return pvpDefense;
|
||||
}
|
||||
|
||||
@@ -562,7 +576,7 @@ export async function sendPVPRewardToUser(pvpDefense: PvpDefenseType, seasonNum:
|
||||
*/
|
||||
export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum: number, seasonEndTime: number, rankLv?: number) {
|
||||
if (!rankLv) {
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, {});
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
rankLv = await r.getMyRank({ roleId: pvpDefense.roleId });// 获得排行榜排名
|
||||
}
|
||||
let pvpRankReward: DicRankRewads = getPvpRankRewardsByRank(rankLv);
|
||||
@@ -589,6 +603,10 @@ export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum:
|
||||
let pvpSeasonResult = await PvpSeasonResultModel.updatePvpSeasonResult(pvpDefense.roleId, seasonNum, {
|
||||
...pvpDefense, rankLv, heroGoods, rankGoods, show: true, newScore, newHeroScores, seasonEndTime
|
||||
});//结算修改玩家pvp信息
|
||||
if(newScore > 0) {
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: seasonNum + 1 });
|
||||
await r.setRankWithRoleInfo(pvpDefense.roleId, newScore, Date.now());
|
||||
}
|
||||
|
||||
// 更新任务
|
||||
await checkTask(pvpDefense.roleId, null, TASK_TYPE.PVP_HERO_SCORE, 0, false, { heroScores: pvpDefense.heroScores });
|
||||
|
||||
@@ -930,10 +930,10 @@ export async function setRankRedisFromDb(type: string, args?: { serverId?: numbe
|
||||
await r.setRankWithGuildInfoArrParam(guild.code, [guild.lv, guild.activeWeekly, guild.activeUpdateTime], guild);
|
||||
}
|
||||
} else if (type == REDIS_KEY.PVP_RANK) {
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
if(pvpConfig) {
|
||||
let ranks = await PvpDefenseModel.getRank(pvpConfig.seasonNum);//获得全服前1000名的排名,加入到redis中
|
||||
let r = new Rank(type, {});
|
||||
let seasonNum: number = pinus.app.get('pvpSeasonNum');
|
||||
if(seasonNum > 0) {
|
||||
let ranks = await PvpDefenseModel.getRank(seasonNum);//获得全服前1000名的排名,加入到redis中
|
||||
let r = new Rank(type, { seasonNum });
|
||||
r.setIsInit(true);
|
||||
for (let { roleId, role: _role, score, updatedAt } of ranks) {
|
||||
let role = <RoleType>_role;
|
||||
|
||||
@@ -26,6 +26,7 @@ import { reportOneOnline } from './authenticateService';
|
||||
|
||||
const PER_SECOND = 1 * 1000;
|
||||
const PER_DAY = 24 * 60 * 60;
|
||||
const PER_HOUR = 1 * 60 * 60;
|
||||
const SETTLE_DIFF_SECONDS = 29 * 60;
|
||||
const PER_MINUTE = 1 * 60;
|
||||
var seasonMakeRewardTimJobId: Job;
|
||||
@@ -80,9 +81,15 @@ function getSeasonContinueDay(seasonNum: number) {
|
||||
return maxDay;
|
||||
}
|
||||
|
||||
async function setPvpSeason() {
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
if(!pvpConfig || pvpConfig.seasonEndTime <= nowSeconds() ) {
|
||||
async function setPvpSeasonJob() {
|
||||
await setPvpSeason();
|
||||
}
|
||||
|
||||
async function setPvpSeason(isForce?: boolean, hour?: number) {
|
||||
let during = hour? hour * PER_HOUR: null;
|
||||
let oldPvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
let pvpConfig = oldPvpConfig;
|
||||
if(!pvpConfig || pvpConfig.seasonEndTime <= nowSeconds() || isForce) {
|
||||
if(pvpConfig && !pvpConfig.hasSettleReward) {
|
||||
await pvpSeasonEnd(pvpConfig);
|
||||
}
|
||||
@@ -91,7 +98,7 @@ async function setPvpSeason() {
|
||||
let lastSeasonEndTime = pvpConfig? pvpConfig.seasonEndTime: 0;
|
||||
|
||||
let newSeasonStartTime = lastSeasonEndTime;
|
||||
let during = getSeasonContinueDay(lastSeasonNum + 1) * PER_DAY;
|
||||
if(!during) during = getSeasonContinueDay(lastSeasonNum + 1) * PER_DAY;
|
||||
let rewardTime = SETTLE_DIFF_SECONDS;
|
||||
if(nowSeconds() - lastSeasonEndTime > during) {
|
||||
newSeasonStartTime = <number>getTimeFun().getDayZeroPoint(0);
|
||||
@@ -99,8 +106,19 @@ async function setPvpSeason() {
|
||||
let newSeasonNum = await CounterModel.getNewCounter(COUNTER.PVP_SEASON_NUM);
|
||||
pvpConfig = await PVPConfigModel.createPVPConfig(newSeasonNum, newSeasonStartTime, newSeasonStartTime + during - rewardTime, newSeasonStartTime + during - PER_MINUTE);
|
||||
}
|
||||
await setPvpSeasonMakeRewardJob(pvpConfig);
|
||||
await setPvpSeasonMakeRewardJob(oldPvpConfig);
|
||||
await setNextSeasonJob(pvpConfig);
|
||||
setPvpSeasonNum(pvpConfig);
|
||||
return pvpConfig;
|
||||
}
|
||||
|
||||
function setPvpSeasonNum(pvpConfig: PVPConfigType) {
|
||||
if(pvpConfig) {
|
||||
pinus.app.set('pvpSeasonNum', pvpConfig.seasonNum);
|
||||
pinus.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
|
||||
pinus.app.rpc.battle.battleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
pinus.app.rpc.role.roleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
}
|
||||
}
|
||||
|
||||
async function setPvpSeasonMakeRewardJob(pvpConfig: PVPConfigType) {
|
||||
@@ -121,7 +139,7 @@ async function setNextSeasonJob(pvpConfig: PVPConfigType) {
|
||||
seasonRefreshTimeJobId.cancel();
|
||||
}
|
||||
//定时开启新赛季,比seasonEndTime多定一分钟,保证定时器时间没错
|
||||
seasonRefreshTimeJobId = scheduleJob('seasonRefreshTimeJobId', pvpConfig.seasonEndTime + PER_MINUTE, setPvpSeason);
|
||||
seasonRefreshTimeJobId = scheduleJob('seasonRefreshTimeJobId', pvpConfig.seasonEndTime + PER_MINUTE, setPvpSeasonJob);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,8 +147,7 @@ async function setNextSeasonJob(pvpConfig: PVPConfigType) {
|
||||
* @param hour
|
||||
*/
|
||||
export async function resetPvpSeasonTime(hour: number) {
|
||||
await PVPConfigModel.setCurPvpConfig({ seasonEndTime: <number>getTimeFun().getDayZeroPoint(0) });
|
||||
return await setPvpSeason();
|
||||
return await setPvpSeason(true);
|
||||
}
|
||||
|
||||
export async function reportOnlineSchedule() {
|
||||
|
||||
Reference in New Issue
Block a user