pvp:修改接口
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
import { PvpDefenseModel, PvpDefenseType, pvpUpdateInter } from '../db/PvpDefense';
|
||||
import { Defense, Attack, LineupCe, OppPlayer, HeroScore, HeroReward, OppPlayerReturn } from '../domain/battleField/pvp';
|
||||
import { Defense, Attack, LineupCe, OppPlayer, HeroScore, HeroReward, OppPlayerReturn, AttackHero, DefenseHero } from '../domain/battleField/pvp';
|
||||
import { RoleType, CeAttrDataRole } from '../db/Role';
|
||||
import { PVP_HERO_POS, REDIS_KEY, PVP_CONST, COUNTER, TASK_TYPE, MAIL_TYPE } from '../consts';
|
||||
import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent";
|
||||
@@ -11,7 +11,7 @@ import { PVP } from '../pubUtils/dicParam';
|
||||
import { PVPConfigModel, PVPConfigType } from '../db/SystemConfig'
|
||||
import { nowSeconds, getTimeFun } from '../pubUtils/timeUtil';
|
||||
import { HeroesRecord } from '../db/PvpRecord';
|
||||
import { HeroModel, CeAttrData } from '../db/Hero';
|
||||
import { HeroModel, CeAttrData, HeroType } from '../db/Hero';
|
||||
import { AttributeCal } from '../domain/roleField/attribute';
|
||||
import { PvpEnemies, PvpHeroInfo, PvpOtherHeroes } from '../domain/dbGeneral';
|
||||
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
|
||||
@@ -37,6 +37,8 @@ export async function getEnemies(oppPlayers: OppPlayer[], winStreakNum: number)
|
||||
for (let oppPlayer of oppPlayers) {
|
||||
let dicOpponent = dicPvpOpponent.get(oppPlayer.pos);
|
||||
let oppDef = <PvpHistoryOppType>oppPlayer.oppDef; // select 'oppRoleId pos roleName head frame spine rankLv pLv defCe'
|
||||
console.log('*******', oppDef)
|
||||
|
||||
if (oppDef) delete oppDef.heroes;
|
||||
result.push({
|
||||
...oppDef,
|
||||
@@ -239,10 +241,10 @@ async function matchRobot(oppPlayers: OppPlayer[], role: RoleType, pLv: number,
|
||||
let dicHero = gameData.hero.get(actorId);
|
||||
if (!dicHero) continue;
|
||||
let heroInfo = new PvpHeroInfo();
|
||||
heroInfo.setRobotInfo(h, actorId, myLv, dicHero.initialStars, dicHero.quality);
|
||||
heroInfo.setRobotInfo(actorId, myLv);
|
||||
let { attribute, ce } = getRobotAttribute(h.attribute, h.enemyCount, [], pLv, myCe, PVP_CONST.ENEMY_CE, ratio);
|
||||
defCe += ce;
|
||||
heroInfo.setAttribute(attribute);
|
||||
heroInfo.setAttribute("1&3500|2&500|4&400|5&400|9&0|10&0|11&0|12&0|13&0|14&10000|18&0");
|
||||
let enemy = new PvpEnemies(h, heroInfo, 0, ce);
|
||||
heroes.push(enemy);
|
||||
}
|
||||
@@ -253,7 +255,7 @@ async function matchRobot(oppPlayers: OppPlayer[], role: RoleType, pLv: number,
|
||||
if (hisPLv < 1) hisPLv = 1
|
||||
|
||||
let pvpHistoryOpp = await PvpHistoryOppModel.createPvpOpp({
|
||||
roleId, oppRoleId, roleName, pos, defCe, pLv: hisPLv, lv: myLv, heroes, rankLv: 0
|
||||
roleId, oppRoleId, roleName, pos, defCe, pLv: hisPLv, lv: myLv, heroes, rankLv: 0, warId: result.war_id, buff: getRandSingleEelm(result.mapseid)||0,
|
||||
});
|
||||
|
||||
oppPlayers.push({
|
||||
@@ -289,8 +291,9 @@ export function getLvByScore(heroScores: HeroScore[]) {
|
||||
}
|
||||
|
||||
export function refChallengeCnt(challengeCnt: number, challengeRefTime: number, seasonEndTime: number) {
|
||||
let hasChanged = false;
|
||||
if (challengeCnt >= PVP.PVP_CHALLENGE_COUNTS) {
|
||||
return { challengeCnt, challengeRefTime };
|
||||
return { hasChanged, challengeCnt, challengeRefTime };
|
||||
}
|
||||
let period = PVP.PVP_CHALLENGE_NORMALTIMES * 60;
|
||||
if (getTimeFun(seasonEndTime).checkDay()) {
|
||||
@@ -301,9 +304,10 @@ export function refChallengeCnt(challengeCnt: number, challengeRefTime: number,
|
||||
if (num > 0) {
|
||||
challengeCnt += num;
|
||||
challengeRefTime = challengeRefTime + period * num;
|
||||
hasChanged = true;
|
||||
}
|
||||
challengeCnt = challengeCnt > PVP.PVP_CHALLENGE_COUNTS ? PVP.PVP_CHALLENGE_COUNTS : challengeCnt;
|
||||
return { challengeCnt, challengeRefTime };
|
||||
return { hasChanged, challengeCnt, challengeRefTime };
|
||||
}
|
||||
|
||||
export function comsumeChallengeCnt(challengeCnt: number, challengeRefTime: number, seasonEndTime: number) {
|
||||
@@ -328,15 +332,15 @@ export async function sendLastSeasonRewardIfNotSent(pvpDefense: PvpDefenseType)
|
||||
}
|
||||
|
||||
// 获取刷新对手次数及消耗
|
||||
export function refreshRefOppCnt(refOppCnt: number, refDaily: Date) {
|
||||
export function refreshRefOppCnt(refOppCnt: number, setAttackCnt: number, refDaily: Date) {
|
||||
let curTime = new Date();
|
||||
let shouldRefOpp = shouldRefresh(refDaily, curTime);
|
||||
if (shouldRefOpp) {
|
||||
refOppCnt = 0; refDaily = curTime;
|
||||
refOppCnt = 0; setAttackCnt = 0; refDaily = curTime;
|
||||
}
|
||||
return {
|
||||
shouldRefOpp,
|
||||
refOppCnt, refDaily,
|
||||
refOppCnt, refDaily, setAttackCnt,
|
||||
consume: gameData.pvpRefreshConsume.get(refOppCnt + 1)
|
||||
}
|
||||
}
|
||||
@@ -405,6 +409,7 @@ export async function generMyRecInfo(heroScores: HeroScore[], winStreakNum: numb
|
||||
const plusScore = getPlusScore(winStreakNum);
|
||||
let pLv = getLvByScore(heroScores);
|
||||
|
||||
// TODO 这里heroScore可以改为不改变原数据,而创建新数据的方式
|
||||
let myHeroRecords = new Array<HeroesRecord>();
|
||||
let showHeroScores = new Array<{ hid: number, addScore: number, plusScore: number, score: number }>();
|
||||
let addSumScore = 0;
|
||||
@@ -450,7 +455,7 @@ export async function generMyRecInfo(heroScores: HeroScore[], winStreakNum: numb
|
||||
score: isSuccess ? addSumScore : 0
|
||||
}
|
||||
|
||||
return { attackInfo, showHeroScores, addSumScore }
|
||||
return { attackInfo, showHeroScores, addSumScore, newHeroScore: heroScores }
|
||||
}
|
||||
|
||||
// 获取对手战报记录
|
||||
@@ -571,10 +576,28 @@ export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum:
|
||||
return pvpSeasonResult;
|
||||
}
|
||||
|
||||
function getScore(arr, score) {
|
||||
for (let item of arr) {
|
||||
if ((item.max >= score || item.max == -1) && score >= item.min) {
|
||||
return item;
|
||||
export async function generPvpLineupCe(roleId: string, lineupCe: LineupCe[], newHeroes: AttackHero[]|DefenseHero[], dbHeroes: HeroType[]) {
|
||||
let newHids: number[] = []; // 本次新增武将
|
||||
let newLineupCe: { hid: number, ce: number }[] = []; // 新生成的lineupCe字段
|
||||
for(let { actorId } of newHeroes) {
|
||||
let n = newLineupCe.find(cur => cur.hid == actorId);
|
||||
if(!n) {
|
||||
let lineup = lineupCe.find(cur => cur.hid == actorId);
|
||||
if(lineup) {
|
||||
newLineupCe.push(lineup);
|
||||
} else {
|
||||
let dbHero = dbHeroes.find(cur => cur.hid == actorId);
|
||||
if(dbHero) {
|
||||
newLineupCe.push({ hid: actorId, ce: dbHero.ce });
|
||||
} else {
|
||||
newHids.push(actorId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let heroes = await HeroModel.findByHidRange(newHids, roleId, 'hid ce', true);
|
||||
for(let { hid, ce } of heroes) {
|
||||
newLineupCe.push({ hid, ce });
|
||||
}
|
||||
return newLineupCe;
|
||||
}
|
||||
@@ -930,17 +930,18 @@ 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 { seasonNum } = await PVPConfigModel.findCurPVPConfig();
|
||||
console.log('execute season resetPvpRanks seasonNum = ' + seasonNum);
|
||||
let ranks = await PvpDefenseModel.getRank(seasonNum);//获得全服前1000名的排名,加入到redis中
|
||||
let r = new Rank(type, {});
|
||||
r.setIsInit(true);
|
||||
for (let { roleId, role: _role, score, updatedAt } of ranks) {
|
||||
let role = <RoleType>_role;
|
||||
if (!role) {
|
||||
continue;
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
if(pvpConfig) {
|
||||
let ranks = await PvpDefenseModel.getRank(pvpConfig.seasonNum);//获得全服前1000名的排名,加入到redis中
|
||||
let r = new Rank(type, {});
|
||||
r.setIsInit(true);
|
||||
for (let { roleId, role: _role, score, updatedAt } of ranks) {
|
||||
let role = <RoleType>_role;
|
||||
if (!role) {
|
||||
continue;
|
||||
}
|
||||
await r.setRankWithRoleInfo(roleId, score, updatedAt.getTime(), role);
|
||||
}
|
||||
await r.setRankWithRoleInfo(roleId, score, updatedAt.getTime(), role);
|
||||
}
|
||||
} else if (type == REDIS_KEY.TOP_LINEUP_RANK) {
|
||||
let serverId = args.serverId;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import { scheduleJob, Job, } from 'node-schedule';
|
||||
import { PVPConfigModel, PVPConfigType } from '../db/SystemConfig';
|
||||
import { nowSeconds, getTimeFun, getZeroPoint } from '../pubUtils/timeUtil';
|
||||
import { nowSeconds, getTimeFun } from '../pubUtils/timeUtil';
|
||||
import { getTodayGuildActivity, gameData } from '../pubUtils/data';
|
||||
import { pvpSeasonEnd } from './pvpService';
|
||||
import { getAllOnlineRoles, getAllServers, delGuildActivityRank } from './redisService';
|
||||
@@ -83,7 +83,7 @@ function getSeasonContinueDay(seasonNum: number) {
|
||||
async function setPvpSeason() {
|
||||
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
|
||||
if(!pvpConfig || pvpConfig.seasonEndTime <= nowSeconds() ) {
|
||||
if(!pvpConfig.hasSettleReward) {
|
||||
if(pvpConfig && !pvpConfig.hasSettleReward) {
|
||||
await pvpSeasonEnd(pvpConfig);
|
||||
}
|
||||
|
||||
@@ -94,9 +94,10 @@ async function setPvpSeason() {
|
||||
let during = getSeasonContinueDay(lastSeasonNum + 1) * PER_DAY;
|
||||
let rewardTime = SETTLE_DIFF_SECONDS;
|
||||
if(nowSeconds() - lastSeasonEndTime > during) {
|
||||
newSeasonStartTime = getZeroPoint();
|
||||
newSeasonStartTime = <number>getTimeFun().getDayZeroPoint(0);
|
||||
}
|
||||
pvpConfig = await PVPConfigModel.createPVPConfig(lastSeasonNum + 1, newSeasonStartTime, newSeasonStartTime + during - rewardTime, newSeasonStartTime + during - PER_MINUTE);
|
||||
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 setNextSeasonJob(pvpConfig);
|
||||
@@ -128,7 +129,7 @@ async function setNextSeasonJob(pvpConfig: PVPConfigType) {
|
||||
* @param hour
|
||||
*/
|
||||
export async function resetPvpSeasonTime(hour: number) {
|
||||
await PVPConfigModel.setCurPvpConfig({ seasonEndTime: getZeroPoint() });
|
||||
await PVPConfigModel.setCurPvpConfig({ seasonEndTime: <number>getTimeFun().getDayZeroPoint(0) });
|
||||
return await setPvpSeason();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user