✨ feat(pvp): 巅峰演武战区化
This commit is contained in:
@@ -27,6 +27,8 @@ import { getVipPvpChallengeMaxCnt } from './activity/monthlyTicketService';
|
||||
import { getHeroesAttributes } from './playerCeService';
|
||||
import { setPvpSettleSeasonNumToRemote } from './timeTaskService';
|
||||
import { ArtifactModel } from '../db/Artifact';
|
||||
import { getPVPGroupIdOfServer, getPvpServersByGroupId } from './serverService';
|
||||
import { findKeys } from './redisService';
|
||||
|
||||
/**
|
||||
* 返回对手三人信息
|
||||
@@ -61,15 +63,16 @@ export async function getEnemies(oppPlayers: OppPlayer[], winStreakNum: number)
|
||||
* @param pLv 我的排名
|
||||
*/
|
||||
export async function refreshEnemies(role: RoleType, seasonNum: number, sumScore: number, score: number, pLv: number) {
|
||||
let { roleId } = role;
|
||||
let { roleId, serverId } = role;
|
||||
let groupId = await getPVPGroupIdOfServer(serverId);
|
||||
let chosenOpps: string[] = [];
|
||||
let pvpHistoryOppParam: PvpOppCreateParam[] = [];
|
||||
let opp = dicPvpOpponent.values()
|
||||
for (let dicOpp of opp) {
|
||||
let pvpHistoryOpp: PvpOppCreateParam; // 是否筛选成功
|
||||
if (sumScore >= PVP.PVP_MATCH_ROBOT) {
|
||||
pvpHistoryOpp = await matchPlayer(seasonNum, chosenOpps, roleId, pLv, dicOpp); // 按照等级匹配对手
|
||||
if (!pvpHistoryOpp) pvpHistoryOpp = await matchPlayerByRank(seasonNum, chosenOpps, roleId, dicOpp.id); // 当前后分数段没有时,返回前一名的玩家
|
||||
pvpHistoryOpp = await matchPlayer(groupId, seasonNum, chosenOpps, roleId, pLv, dicOpp); // 按照等级匹配对手
|
||||
if (!pvpHistoryOpp) pvpHistoryOpp = await matchPlayerByRank(groupId, seasonNum, chosenOpps, roleId, dicOpp.id); // 当前后分数段没有时,返回前一名的玩家
|
||||
if (!pvpHistoryOpp) pvpHistoryOpp = await matchRobot(chosenOpps, role, score, dicOpp);
|
||||
} else {
|
||||
pvpHistoryOpp = await matchRobot(chosenOpps, role, score, dicOpp);
|
||||
@@ -97,9 +100,9 @@ export async function refreshEnemies(role: RoleType, seasonNum: number, sumScore
|
||||
return oppPlayers;
|
||||
}
|
||||
|
||||
export async function matchPlayerByRank(seasonNum: number, chosenOpps: string[], roleId: string, pos: number) {
|
||||
export async function matchPlayerByRank(groupId: number, seasonNum: number, chosenOpps: string[], roleId: string, pos: number) {
|
||||
// console.log('matchPlayerByRank', JSON.stringify(oppPlayers))
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
let ridRanks = new Array<number>(); // 已经被使用了的排名
|
||||
for (let curRoleId of chosenOpps) {
|
||||
let rankLv = await r.getMyRank({ roleId: robotIdComBack(curRoleId) });
|
||||
@@ -167,18 +170,19 @@ export async function matchPlayerByRank(seasonNum: number, chosenOpps: string[],
|
||||
|
||||
let pvpdefense = await PvpDefenseModel.findByRoleIdIncludeAll(oppRoleId);
|
||||
if (!pvpdefense || pvpdefense.seasonNum != seasonNum || !pvpdefense.hasDefense) return null;
|
||||
let pvpHistoryOpp = await generPlayerOppHis(pvpdefense, roleId, pos);
|
||||
let pvpHistoryOpp = await generPlayerOppHis(pvpdefense, roleId, pos, groupId);
|
||||
if (!pvpHistoryOpp) return null;
|
||||
|
||||
chosenOpps.push(pvpHistoryOpp.oppRoleId);
|
||||
return pvpHistoryOpp;
|
||||
}
|
||||
|
||||
async function matchPlayer(seasonNum: number, chosenOpps: string[], roleId: string, pLv: number, dicOpp: DicPvpOpponent) {
|
||||
async function matchPlayer(groupId: number, seasonNum: number, chosenOpps: string[], roleId: string, pLv: number, dicOpp: DicPvpOpponent) {
|
||||
// console.log('matchPlayer', JSON.stringify(oppPlayers))
|
||||
|
||||
let serverIds = await getPvpServersByGroupId(groupId);
|
||||
let { id: pos, minLv, maxLv } = dicOpp
|
||||
let range = await PvpDefenseModel.findByTeamLv(seasonNum, pLv + minLv, pLv + maxLv);
|
||||
let range = await PvpDefenseModel.findByTeamLv(serverIds, seasonNum, pLv + minLv, pLv + maxLv);
|
||||
range = range.filter(cur => {
|
||||
return chosenOpps.indexOf(makeRobotId(cur.roleId)) == -1;
|
||||
});
|
||||
@@ -193,7 +197,7 @@ async function matchPlayer(seasonNum: number, chosenOpps: string[], roleId: stri
|
||||
index = getRandSingleIndex(range.length);
|
||||
result = range[index];
|
||||
}
|
||||
let pvpHistoryOpp = await generPlayerOppHis(result, roleId, pos);
|
||||
let pvpHistoryOpp = await generPlayerOppHis(result, roleId, pos, groupId);
|
||||
if (!pvpHistoryOpp) return null;
|
||||
|
||||
chosenOpps.push(pvpHistoryOpp.oppRoleId);
|
||||
@@ -206,14 +210,14 @@ async function matchPlayer(seasonNum: number, chosenOpps: string[], roleId: stri
|
||||
* @param roleId 自己的玩家id
|
||||
* @param pos 刷新这个对手的位置
|
||||
*/
|
||||
async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos: number) {
|
||||
async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos: number, groupId: number) {
|
||||
let { heroScores, defense } = pvpdefense;
|
||||
if(!defense) return false;
|
||||
let { warId, heroes: defenseHeroes } = defense;
|
||||
let role = <RoleType>pvpdefense.role;
|
||||
|
||||
let seasonNum: number = pinus.app.get('pvpSeasonNum');
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
let rankLv = await r.getMyRank({ roleId: role.roleId });
|
||||
let dbHeroes = await HeroModel.findByRole(role.roleId, [{ field: 'ce', sortBy: -1 }]);
|
||||
let heroes = new Array<PvpEnemies>();
|
||||
@@ -565,14 +569,18 @@ export async function generPVPOppRecInfo(isSuccess: boolean, curOpp: OppPlayer,
|
||||
let resultMaxRank = getPvpRankMaxRewardsBySeasonNum(pvpConfig.seasonNum);//根据排行榜的奖励表,获得最大排名挡位的最小值,其余不在结算中结算的玩家按照最大排名挡位在登录或进入pvp时结算
|
||||
if(!resultMaxRank) return;
|
||||
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: pvpConfig.seasonNum }, false, resultMaxRank.min - 1);
|
||||
let allRank = <RoleRankInfo[]>(await r.getRankByRange());
|
||||
console.log('******** allRank', 0, resultMaxRank.min - 2, allRank)
|
||||
for(let { rank, roleId } of allRank) {
|
||||
console.log('******** pvpSeasonEnd: ', rank, roleId);
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
let { pvpSeasonResult } = await sendPVPRewardToUser(pvpDefense, pvpConfig.seasonNum, pvpConfig.seasonEndTime);
|
||||
reportTAEvent(roleId, TA_EVENT.PVP_SEASON_END, { top_rank: rank, hero_score: pvpSeasonResult.heroScores })
|
||||
let pvpKeys = await findKeys(`${REDIS_KEY.PVP_RANK}:${pvpConfig.seasonNum}:`);
|
||||
for(let key of pvpKeys) {
|
||||
let [,, groupId] = key.split(':');
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: pvpConfig.seasonNum, groupId: parseInt(groupId) }, false, resultMaxRank.min - 1);
|
||||
let allRank = <RoleRankInfo[]>(await r.getRankByRange());
|
||||
console.log('******** allRank', 0, resultMaxRank.min - 2, allRank)
|
||||
for(let { rank, roleId } of allRank) {
|
||||
console.log('******** pvpSeasonEnd: ', rank, roleId);
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
let { pvpSeasonResult } = await sendPVPRewardToUser(pvpDefense, pvpConfig.seasonNum, pvpConfig.seasonEndTime);
|
||||
reportTAEvent(roleId, TA_EVENT.PVP_SEASON_END, { top_rank: rank, hero_score: pvpSeasonResult.heroScores })
|
||||
}
|
||||
}
|
||||
await PvpDefenseModel.resetDefense();
|
||||
let settledPvpConfig = await PVPConfigModel.setReward(pvpConfig.seasonNum);
|
||||
@@ -648,8 +656,9 @@ async function resetPvpScores(pvpDefense: PvpDefenseType, pvpSeasonResult: PvpSe
|
||||
* @param rankLv
|
||||
*/
|
||||
export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum: number, seasonEndTime: number, rankLv?: number) {
|
||||
let groupId = await getPVPGroupIdOfServer(pvpDefense.serverId);
|
||||
if (!rankLv) {
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
rankLv = await r.getMyRank({ roleId: pvpDefense.roleId });// 获得排行榜排名
|
||||
}
|
||||
let pvpRankReward: DicRankRewads = getPvpRankRewardsByRank(seasonNum, rankLv);
|
||||
@@ -681,7 +690,7 @@ export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum:
|
||||
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 });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: seasonNum + 1, groupId });
|
||||
await r.setRankWithRoleInfo(pvpDefense.roleId, newScore, Date.now());
|
||||
}
|
||||
|
||||
@@ -719,9 +728,7 @@ export async function generPvpLineupCe(roleId: string, lineupCe: LineupCe[], att
|
||||
|
||||
|
||||
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 { seasonEndTime, seasonStartTime, seasonRewardTime } = getPvpTime();
|
||||
let now = nowSeconds();
|
||||
if(now >= seasonStartTime && now < seasonEndTime) {
|
||||
return PVP_SEASON_STATUS.START;
|
||||
@@ -732,6 +739,28 @@ export function getPvpSeasonStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
interface PvpTime {
|
||||
seasonEndTime: number, seasonStartTime: number, seasonRewardTime: number
|
||||
}
|
||||
export function getPvpTime(): PvpTime {
|
||||
return {
|
||||
seasonEndTime: pinus.app.get('pvpSeasonEndTime'),
|
||||
seasonStartTime: pinus.app.get('pvpSeasonStartTime'),
|
||||
seasonRewardTime: pinus.app.get('pvpSeasonRewardTime')
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPvpTimeFromRemote(): Promise<PvpTime> {
|
||||
let serverType = pinus.app.getServerType();
|
||||
if(serverType == 'battle') {
|
||||
return getPvpTime();
|
||||
} else {
|
||||
let battleServers = pinus.app.getServersByType('battle');
|
||||
let server = getRandSingleEelm(battleServers);
|
||||
return await pinus.app.rpc.battle.battleRemote.getPvpTime.toServer(server.id);
|
||||
}
|
||||
}
|
||||
|
||||
export function checkPvpSeasonIsStart() {
|
||||
let status = getPvpSeasonStatus();
|
||||
return status == PVP_SEASON_STATUS.START;
|
||||
|
||||
Reference in New Issue
Block a user