diff --git a/game-server/app/servers/battle/handler/pvpHandler.ts b/game-server/app/servers/battle/handler/pvpHandler.ts index 6dacd17b3..df4a153a1 100644 --- a/game-server/app/servers/battle/handler/pvpHandler.ts +++ b/game-server/app/servers/battle/handler/pvpHandler.ts @@ -60,7 +60,7 @@ export class PvpHandler { if(refOppObj.shouldRefOpp) { if(pvpDefense.attack) { let role = pvpDefense.role; - let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.score, pvpDefense.attack.pLv||1); + let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.attack.score, pvpDefense.attack.pLv||1); update.oppPlayers = oppPlayers; } update = { ...update, ...refOppObj } @@ -116,7 +116,7 @@ export class PvpHandler { // 刷新对手 let role = pvpDefense.role; let { seasonNum } = await PVPConfigModel.findCurPVPConfig(); - let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.score, pvpDefense.attack.pLv||1); + let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.attack.score, pvpDefense.attack.pLv||1); pvpDefense = await PvpDefenseModel.updateInfoAndInclude(roleId, { oppPlayers, ...refOppObj }); @@ -244,7 +244,7 @@ export class PvpHandler { // 刷新对手 let { seasonNum, seasonEndTime } = await PVPConfigModel.findCurPVPConfig(); - let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.score, pvpDefense.attack.pLv||1); + let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.attack.score, pvpDefense.attack.pLv||1); update.oppPlayers = oppPlayers; // 更新battleRecord @@ -313,7 +313,7 @@ export class PvpHandler { let refChallengeObj = refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime); // 刷对手 let role = pvpDefense.role; - let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.score, pvpDefense.attack?.pLv||1); + let oppPlayers = await refreshEnemies(role, seasonNum, pvpDefense.attack.score, pvpDefense.attack?.pLv||1); // 更新挑战阵容 let score = 0; for(let { actorId } of heroes) { diff --git a/game-server/app/services/pvpService.ts b/game-server/app/services/pvpService.ts index fb89fe9c5..302430ee8 100644 --- a/game-server/app/services/pvpService.ts +++ b/game-server/app/services/pvpService.ts @@ -6,7 +6,7 @@ import { PVP_HERO_POS, REDIS_KEY, PVP_CONST, COUNTER, TASK_TYPE, MAIL_TYPE } fro 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 } from "../pubUtils/data"; +import { gameData, getPLvByScore, getPvpHeroRewardsByScore, getPvpRankRewardsByRank, getPvpDifficultByScore } from "../pubUtils/data"; import { PVP } from '../pubUtils/dicParam'; import { PVPConfigModel, PVPConfigType } from '../db/SystemConfig' import { nowSeconds, getTimeFun } from '../pubUtils/timeUtil'; @@ -67,9 +67,9 @@ export async function refreshEnemies(role: RoleType, seasonNum: number, score: n if (score >= 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, pLv, dicOpp); + if (!flag) flag = await matchRobot(oppPlayers, role, score, dicOpp); } else { - flag = await matchRobot(oppPlayers, role, pLv, dicOpp); + flag = await matchRobot(oppPlayers, role, score, dicOpp); } if (!flag) continue; } @@ -189,6 +189,7 @@ async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos let dbHeroes = await HeroModel.findByRole(role.roleId, [{ field: 'ce', sortBy: -1 }]); let heroes = new Array(); let otherHeroes = new Array(); // 阵容外的所有武将信息 + let defCe = 0; for (let dbHero of dbHeroes) { let h = defenseHeroes.find(cur => cur.actorId == dbHero.hid); // 阵容里是否有这个武将 let hs = heroScores.find(cur => cur.hid == dbHero.hid); // 这个武将是否有这个得分 @@ -203,6 +204,7 @@ async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos heroInfo.setAttribute(attribute); let enemy = new PvpEnemies(warJson, heroInfo, hs ? hs.score : 0, ce); heroes.push(enemy); + defCe += ce; } } else { let heroInfo = new PvpOtherHeroes(hs ? hs.score : 0); @@ -214,21 +216,18 @@ async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos otherHeroes.sort((a, b) => b.score - a.score); let pvpHistoryOpp = await PvpHistoryOppModel.createPvpOpp({ - ...pvpdefense, ...role, pos, rankLv, heroes, otherHeroes, roleId, oppRoleId: makeRobotId(pvpdefense.roleId) + ...defense, defCe, ...role, pos, rankLv, heroes, otherHeroes, roleId, oppRoleId: makeRobotId(pvpdefense.roleId) }); return pvpHistoryOpp; } -async function matchRobot(oppPlayers: OppPlayer[], role: RoleType, pLv: number, dicOpp: DicPvpOpponent) { +async function matchRobot(oppPlayers: OppPlayer[], role: RoleType, score: number, dicOpp: DicPvpOpponent) { // console.log('matchRobot', JSON.stringify(oppPlayers)) - let { lv: myLv, topLineupCe: myCe, roleId } = role; + let { lv: myLv, roleId } = role; let { id: pos, minLv, maxLv, ratio } = dicOpp; - let range = gameData.pvpWar; - if (range.length <= 0) return false; - let index = getRandSingleIndex(range.length); - let result = range[index]; + let result = getRandSingleEelm(gameData.pvpWar); if (!result) return false; let robotWarjson = gameData.warJson.get(result.war_id); @@ -241,16 +240,17 @@ async function matchRobot(oppPlayers: OppPlayer[], role: RoleType, pLv: number, let dicHero = gameData.hero.get(actorId); if (!dicHero) continue; let heroInfo = new PvpHeroInfo(); - heroInfo.setRobotInfo(actorId, myLv); - let { attribute, ce } = getRobotAttribute(h.attribute, h.enemyCount, [], pLv, myCe, PVP_CONST.ENEMY_CE, ratio); + let { attribute, ce, lv } = getRobotAttribute(actorId, ratio, score); + heroInfo.setRobotInfo(actorId, lv); defCe += ce; - heroInfo.setAttribute("1&3500|2&500|4&400|5&400|9&0|10&0|11&0|12&0|13&0|14&10000|18&0"); + heroInfo.setAttribute(attribute); let enemy = new PvpEnemies(h, heroInfo, 0, ce); heroes.push(enemy); } let oppRoleId = generateRobotRoleId(); let roleName = getChineseName(); + let pLv = getPLvByScore(score); let hisPLv = Math.floor(pLv + (minLv + maxLv) / 2); if (hisPLv < 1) hisPLv = 1 @@ -353,25 +353,17 @@ export function refreshRefOppCnt(refOppCnt: number, setAttackCnt: number, refDai * @param enemyCe 出兵表对手战力 * @param ratio 系数 */ -export function getRobotAttribute(mainAttrs: { id: number, val: number }[], enemyCount: number, subAttrs: {id: number, val: number}[], lv: number, ce: number, enemyCe: number, ratio: number) { +export function getRobotAttribute(hid: number, posRatio: number, score: number) { + + let difficultRatio = getPvpDifficultByScore(score); + let dicHero = gameData.hero.get(hid); let newAttribute = new AttributeCal(); - newAttribute.setLv(lv); - newAttribute.setByWarJson(subAttrs); // 次级属性 - let subAttrCe = newAttribute.calSubAttrCeAndReduce() * enemyCount; - if(ce * ratio > subAttrCe) { - let mainAttrCe = ce * ratio - subAttrCe; - newAttribute.setByWarJson(mainAttrs, mainAttrCe / enemyCe); - let attrArr = newAttribute.getReduceAttributesToString(); - let newCe = newAttribute.calCelAndReduce(); - return { attribute: attrArr, ce: newCe }; - } else { - newAttribute = new AttributeCal(); - newAttribute.setByWarJson(mainAttrs, ce * ratio / enemyCe); - let attrArr = newAttribute.getReduceAttributesToString(); - let newCe = newAttribute.calCelAndReduce(); - return { attribute: attrArr, ce: newCe }; - } + newAttribute.setLv(difficultRatio.enemyLv); + newAttribute.setByMap(dicHero.baseAbilityArr, difficultRatio.value / 10000 * posRatio); + let attrArr = newAttribute.getReduceAttributesToString(); + let newCe = newAttribute.calCelAndReduce(); + return { attribute: attrArr, ce: newCe, lv: difficultRatio.enemyLv }; } /** diff --git a/shared/consts/constModules/sysConst.ts b/shared/consts/constModules/sysConst.ts index aeef17b92..66956c1e3 100644 --- a/shared/consts/constModules/sysConst.ts +++ b/shared/consts/constModules/sysConst.ts @@ -472,6 +472,7 @@ export const FILENAME = { DIC_EXPEDITION_SUB_ATTR: 'dic_expedition_subattr', DIC_AUCTION_BASIC_POOL: 'dic_zyz_auction_basicPool', DIC_AUCTION_REWARD: 'dic_zyz_auctionReward', + DIC_PVP_DIFFICULTRATIO: 'dic_zyz_pvp_difficultRatio', } export const WAR_RELATE_TABLES = [ diff --git a/shared/domain/battleField/pvp.ts b/shared/domain/battleField/pvp.ts index 6d20a7993..433d83f2c 100644 --- a/shared/domain/battleField/pvp.ts +++ b/shared/domain/battleField/pvp.ts @@ -1,3 +1,6 @@ +import { PvpEnemies, PvpOtherHeroes } from '@domain/dbGeneral'; +import { DicPvpOpponent } from '@pubUtils/dictionary/DicPvpOpponent'; +import { DicWar } from '@pubUtils/dictionary/DicWar'; import { prop, Ref, mongoose } from '@typegoose/typegoose'; import Hero, { HeroType } from '../../db/Hero'; import { PvpDefenseType } from '../../db/PvpDefense'; diff --git a/shared/pubUtils/data.ts b/shared/pubUtils/data.ts index 3e7c9248f..2cdffac70 100644 --- a/shared/pubUtils/data.ts +++ b/shared/pubUtils/data.ts @@ -93,6 +93,7 @@ import { dicHoliday, loadHoliday } from './dictionary/DicHoliday'; import { dicExpeditionSubAttr, loadExpeditionSubAttr } from './dictionary/DicExpeditionSubAttr'; import { dicAuctionPool, loadAuctionReward } from './dictionary/DicAuctionReward'; import { dicGuildTrainInfo, loadGuildTrainInfo } from './dictionary/DicGuildTrainInfo'; +import { dicPvpDifficultRatio, loadPvpDifficultRatio } from './dictionary/DicPvpDifficultRatio'; import { pick } from "underscore"; export const gameData = { @@ -151,6 +152,7 @@ export const gameData = { pvpTeamLevel: dicPvpTeamLevel, pvpWar: dicWarPvp, pvpRefreshConsume: dicPvpRefreshConsume, + pvpDifficultRatio: dicPvpDifficultRatio, maxPvpRefreshCnt: maxPvpRefreshCnt, pvpHeroRewards: dicHeroRewads, pvpRankRewards: dicRankRewads, @@ -793,6 +795,15 @@ export function getGuildTrainGkInfo(trainId: number, heroId: number) { return gameData.guildTrainInfo.get(`${trainId}_${heroId}`); } +export function getPvpDifficultByScore(score: number) { + for(let obj of gameData.pvpDifficultRatio) { + if(obj.teamLineupMin <= score && (obj.teamLineupMax >= score || obj.teamLineupMax == -1)) { + return obj; + } + } + return null; +} + function loadEquipAttributeRatio() { let arr = decodeArrayListStr(param.ATTRIBUTE.ATTRIBUTE_EQUIP_RATIO); for(let [id, ratio] of arr) { @@ -923,6 +934,7 @@ function loadDatas() { loadExpeditionSubAttr(); loadAuctionReward(); loadGuildTrainInfo(); + loadPvpDifficultRatio(); } // 重载dicParam diff --git a/shared/pubUtils/dictionary/DicPvpDifficultRatio.ts b/shared/pubUtils/dictionary/DicPvpDifficultRatio.ts new file mode 100644 index 000000000..1348b2978 --- /dev/null +++ b/shared/pubUtils/dictionary/DicPvpDifficultRatio.ts @@ -0,0 +1,22 @@ +import { readFileAndParse, parseGoodStr } from '../util' +import { FILENAME } from '../../consts' + +export interface DicPvpDifficultRatio { + readonly id: number; + readonly teamLineupMin: number; + readonly teamLineupMax: number; + readonly value: number; + readonly enemyLv: number; + +} + +export const dicPvpDifficultRatio = new Array(); +export function loadPvpDifficultRatio() { + dicPvpDifficultRatio.splice(0, dicPvpDifficultRatio.length); + let arr = readFileAndParse(FILENAME.DIC_PVP_DIFFICULTRATIO); + + arr.forEach(o => { + dicPvpDifficultRatio.push(o); + }); + arr = undefined; +} \ No newline at end of file