diff --git a/game-server/app/servers/battle/handler/pvpHandler.ts b/game-server/app/servers/battle/handler/pvpHandler.ts index d3c666acc..5034daf49 100644 --- a/game-server/app/servers/battle/handler/pvpHandler.ts +++ b/game-server/app/servers/battle/handler/pvpHandler.ts @@ -18,7 +18,6 @@ import { BattleRecordModel } from '../../../db/BattleRecord'; import { PvpRecordModel, HeroesRecord } from '../../../db/PvpRecord'; import { existsRank, initRank, getRank, setRank, getMyRank } from '../../../services/redisService'; import { handleCost } from '../../../services/rewardService'; -import { matchPlayerByRank } from '../../../services/pvpService'; export default function(app: Application) { return new PvpHandler(app); diff --git a/game-server/app/services/expeditionService.ts b/game-server/app/services/expeditionService.ts index 1fbe62e5d..51a50661f 100644 --- a/game-server/app/services/expeditionService.ts +++ b/game-server/app/services/expeditionService.ts @@ -1,6 +1,6 @@ import { ExpeditionPointModel } from '../db/ExpeditionPoint'; -import Role, { RoleModel } from '../db/Role'; +import Role, { RoleModel, RoleType } from '../db/Role'; import { PvpDefenseModel } from '../db/PvpDefense'; import { getWarJsons, getGamedata, getExpeditionById } from '../pubUtils/gamedata'; @@ -8,12 +8,15 @@ import { decodeStr, resResult, setLocalHours, shouldRefresh } from '../pubUtils/ import { EXPEDITION_CONST, HERO_CE_RATIO, getAttrCeRatio } from '../consts'; import { getAtrrNameById} from '../consts'; import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord'; +import { HeroType } from '../db/Hero'; +import { gameData } from '../pubUtils/data'; +import { getPlayerAttribute, getRobotAttribute } from './pvpService'; export async function findOrCreateEnemies(roleId: string, myCe: number, expeditionCode: string, expeditionId: number, battleStatus: number) { let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId); if(!expeditionWarRecord) { // 如果没有信息 - let curDicExpedition = getExpeditionById(expeditionId); + let curDicExpedition = gameData.expedition.get(expeditionId); if(curDicExpedition) { let enemyObj = { @@ -71,18 +74,34 @@ export async function matchPlayers(roleId: string, scale: number, range: number, let index = Math.floor(Math.random() * resultRange.length); let result = resultRange[index]; let {roleId, heroes, defCe } = result; + let role = result.role; + let { globalCeAttr } = role; enemyObj.enemyFrom = 1; enemyObj.enemyId = roleId; enemyObj.ce = defCe; - // TODO 修改获取attribute let heroIndex = 0; - for(let enemy of dicWarJson) { - if(enemy.relation == 2) { + for(let json of dicWarJson) { + if(json.relation == 2) { let hero = heroes[heroIndex]; if(hero) { - enemyObj.enemies.push({...enemy, ...hero}); + let h = hero.hero; + let { star, lv, ceAttr } = h; + let dicHero = gameData.hero.get(hero.actorId); + let newAttribute = getPlayerAttribute(ceAttr, globalCeAttr); + let heroInfo = { + actorId: hero.actorId, + actorName: dicHero.name, + skill:0, + seid:'&', + star, + spine: 0, + attribute: newAttribute, + lv + }; + + enemyObj.enemies.push({...json, ...heroInfo}); heroIndex ++; } } @@ -95,30 +114,28 @@ export async function matchPlayers(roleId: string, scale: number, range: number, } // 匹配机器人 -export async function matchRobots(scale: number, myCe: number, robotCe: number, warJsonIndex:any, lv: number, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array, ce: number }) { - let {json: dicWarJson, fileName } = getWarJsons(warJsonIndex); +export async function matchRobots(scale: number, myCe: number, robotCe: number, warJsonIndex: number, lv: number, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array, ce: number }) { + let dicWarJson = gameData.warJson.get(warJsonIndex); if(dicWarJson) { enemyObj.enemyFrom = 2; - enemyObj.enemyId = fileName + ''; + enemyObj.enemyId = warJsonIndex + ''; let allCe = 0; let ratio = myCe / HERO_CE_RATIO / HERO_CE_RATIO / robotCe * scale; // 玩家战力/机器人初始战力*系数 - for(let enemy of dicWarJson) { - if(enemy.relation == 2) { - let attribute = decodeWarJsonAttribute(enemy.attribute); // 格式:{'hp':1000, ...} - for(let value in attribute) { - attribute[value] *= ratio; - attribute[value] = Math.round(attribute[value]); - } + for(let json of dicWarJson) { + if(json.relation == 2) { + const { attribute } = json; + + let newAttribute = getRobotAttribute(attribute, myCe, robotCe, scale); let ce = 0; - for(let attrName in attribute) { - ce += attribute[attrName] * getAttrCeRatio(attrName)||0; + for(let attrName in newAttribute) { + ce += newAttribute[attrName] * getAttrCeRatio(attrName)||0; } - enemyObj.enemies.push({...enemy, attribute, lv}); + enemyObj.enemies.push({...json, attribute: newAttribute, lv}); allCe += ce; } } - console.log(JSON.stringify(enemyObj.enemies)) + enemyObj.ce = Math.floor(allCe); return true diff --git a/game-server/app/services/pvpService.ts b/game-server/app/services/pvpService.ts index 831a7e064..32be1f0bc 100644 --- a/game-server/app/services/pvpService.ts +++ b/game-server/app/services/pvpService.ts @@ -7,7 +7,7 @@ import { PVP_HERO_POS, ROBOT_NAME, REDIS_KEY, PVP_CONST } from '../consts'; import { setPvpDefResult } from '../services/timeTaskService'; import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent"; import { getRandomIndexByLen, genCode, getRandomByLen, shouldRefresh, reduceCe } from '../pubUtils/util'; -import { oppPlayersInter, RankParam, pvpEndParamInter, oppHeroesDefenseInter } from '../pubUtils/interface'; +import { oppPlayersInter, RankParam, pvpEndParamInter, oppHeroesDefenseInter, Attributes } from '../pubUtils/interface'; import { gameData, getPLvByScore } from "../pubUtils/data"; import { PVP } from '../pubUtils/dicParam'; import { SystemConfigModel } from '../db/SystemConfig' @@ -15,7 +15,7 @@ import { setRank, getMyRank, getFieldByRank } from './redisService'; import { nowSeconds, checkTodayTime } from '../pubUtils/timeUtil'; import { HeroesRecord } from '../db/PvpRecord'; import { HeroModel, HeroType } from '../db/Hero'; -import { CeAttrNumber } from '../db/generalField'; +import { CeAttrNumber, CeAttr, CeAttrRole } from '../db/generalField'; import { DicWarJson } from '../pubUtils/dictionary/DicWarJson'; const _ = require('underscore'); @@ -369,15 +369,9 @@ export async function getRobotLineup(mapWarJson: DicWarJson[], curOpp: OppPlayer for(let json of dicWarJson) { let curDicMapJson = mapWarJson.find(cur => cur.dataId == json.dataId); const { actorId, actorName, attribute, skill, seid, star, spine, relation } = json; - console.log(JSON.stringify(json)) - if(relation == 2 && actorId > 0) { // 默认格子 - let newAttribute = new CeAttrNumber(); - for(let attrName in newAttribute) { - newAttribute[attrName] = Math.floor(attribute[attrName] * reduceCe(topFiveCe) / PVP_CONST.ENEMY_CE * dicOpp.ratio); - } - newAttribute['speed'] = 0; - newAttribute['ap'] = 0; + if(relation == 2 && actorId > 0) { // 默认格子 + let newAttribute = getRobotAttribute(attribute, topFiveCe, PVP_CONST.ENEMY_CE, dicOpp.ratio); let heroInfo = { actorId, actorName, skill, seid, star, spine, attribute: newAttribute, lv }; heroes.push({ ...curDicMapJson, ...heroInfo @@ -400,16 +394,7 @@ export async function getPlayerLineup(mapWarJson: DicWarJson[], curOpp: OppPlaye let dicHero = gameData.hero.get(actorId); let h = hero; let { ceAttr } = h; - let newAttribute = new CeAttrNumber(); - for(let attrName in newAttribute) { - let { base, ratioUp, fixUp, equipUp } = ceAttr[attrName]; - let { ratioUp: ratioUp2, fixUp: fixUp2 } = globalCeAttr[attrName]; - let result = base * ( 1 + ratioUp + ratioUp2) + fixUp + fixUp2 + equipUp; - newAttribute[attrName] += reduceCe(result); - } - newAttribute['speed'] = 0; - newAttribute['ap'] = 0; - + let newAttribute = getPlayerAttribute(ceAttr, globalCeAttr); let heroInfo = { outIndex: order, actorId, actorName: dicHero.name, skill:0, seid:'&', star: h.star, spine: 0, attribute: newAttribute, lv: h.lv }; heroes.push({ ...curDicMapJson, ...heroInfo @@ -419,6 +404,34 @@ export async function getPlayerLineup(mapWarJson: DicWarJson[], curOpp: OppPlaye return heroes } +// 按比例计算出兵表中的属性 +export function getRobotAttribute(attribute: Attributes, ce: number, enemyCe: number, ratio: number) { + + let newAttribute = new CeAttrNumber(); + for(let attrName in newAttribute) { + newAttribute[attrName] = Math.floor(attribute[attrName] * reduceCe(ce) / enemyCe * ratio); + } + newAttribute['speed'] = 0; + newAttribute['ap'] = 0; + + return newAttribute; +} + +// 计算玩家的属性 +export function getPlayerAttribute(ceAttr: CeAttr, globalCeAttr: CeAttrRole) { + let newAttribute = new CeAttrNumber(); + for(let attrName in newAttribute) { + let { base, ratioUp, fixUp, equipUp } = ceAttr[attrName]; + let { ratioUp: ratioUp2, fixUp: fixUp2 } = globalCeAttr[attrName]; + let result = base * ( 1 + ratioUp + ratioUp2) + fixUp + fixUp2 + equipUp; + newAttribute[attrName] += reduceCe(result); + } + newAttribute['speed'] = 0; + newAttribute['ap'] = 0; + + return newAttribute; +} + // 获取我方战报记录 export async function generMyRecInfo(heroScores: HeroScores[], winStreakNum: number, role: RoleType, isSuccess: boolean, pos: number, myHeroes: pvpEndParamInter[]) { diff --git a/shared/db/PvpDefense.ts b/shared/db/PvpDefense.ts index ca47dc165..05aba19b3 100644 --- a/shared/db/PvpDefense.ts +++ b/shared/db/PvpDefense.ts @@ -154,7 +154,10 @@ export default class PvpDefense extends BaseModel { } public static async findByScale(roleId: string, min: number, max: number, lean = true) { - const result: PvpDefenseType[] = await PvpDefenseModel.find({ roleId: { $ne: roleId }, defCe: { $lte: max, $gte: min } }).sort({ updatedAt: -1 }).limit(100).lean(lean); + const result: PvpDefenseType[] = await PvpDefenseModel.find({ roleId: { $ne: roleId }, defCe: { $lte: max, $gte: min } }) + .populate('role', 'headHid sHid topFiveCe roleId roleName') + .populate('heroes.hero') + .sort({ updatedAt: -1 }).limit(100).lean(lean); return result; }