fix 远征相应获取属性逻辑
This commit is contained in:
@@ -18,7 +18,6 @@ import { BattleRecordModel } from '../../../db/BattleRecord';
|
|||||||
import { PvpRecordModel, HeroesRecord } from '../../../db/PvpRecord';
|
import { PvpRecordModel, HeroesRecord } from '../../../db/PvpRecord';
|
||||||
import { existsRank, initRank, getRank, setRank, getMyRank } from '../../../services/redisService';
|
import { existsRank, initRank, getRank, setRank, getMyRank } from '../../../services/redisService';
|
||||||
import { handleCost } from '../../../services/rewardService';
|
import { handleCost } from '../../../services/rewardService';
|
||||||
import { matchPlayerByRank } from '../../../services/pvpService';
|
|
||||||
|
|
||||||
export default function(app: Application) {
|
export default function(app: Application) {
|
||||||
return new PvpHandler(app);
|
return new PvpHandler(app);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { ExpeditionPointModel } from '../db/ExpeditionPoint';
|
import { ExpeditionPointModel } from '../db/ExpeditionPoint';
|
||||||
import Role, { RoleModel } from '../db/Role';
|
import Role, { RoleModel, RoleType } from '../db/Role';
|
||||||
import { PvpDefenseModel } from '../db/PvpDefense';
|
import { PvpDefenseModel } from '../db/PvpDefense';
|
||||||
|
|
||||||
import { getWarJsons, getGamedata, getExpeditionById } from '../pubUtils/gamedata';
|
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 { EXPEDITION_CONST, HERO_CE_RATIO, getAttrCeRatio } from '../consts';
|
||||||
import { getAtrrNameById} from '../consts';
|
import { getAtrrNameById} from '../consts';
|
||||||
import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord';
|
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) {
|
export async function findOrCreateEnemies(roleId: string, myCe: number, expeditionCode: string, expeditionId: number, battleStatus: number) {
|
||||||
|
|
||||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||||
if(!expeditionWarRecord) { // 如果没有信息
|
if(!expeditionWarRecord) { // 如果没有信息
|
||||||
let curDicExpedition = getExpeditionById(expeditionId);
|
let curDicExpedition = gameData.expedition.get(expeditionId);
|
||||||
if(curDicExpedition) {
|
if(curDicExpedition) {
|
||||||
|
|
||||||
let enemyObj = {
|
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 index = Math.floor(Math.random() * resultRange.length);
|
||||||
let result = resultRange[index];
|
let result = resultRange[index];
|
||||||
let {roleId, heroes, defCe } = result;
|
let {roleId, heroes, defCe } = result;
|
||||||
|
let role = <RoleType>result.role;
|
||||||
|
let { globalCeAttr } = role;
|
||||||
|
|
||||||
enemyObj.enemyFrom = 1;
|
enemyObj.enemyFrom = 1;
|
||||||
enemyObj.enemyId = roleId;
|
enemyObj.enemyId = roleId;
|
||||||
enemyObj.ce = defCe;
|
enemyObj.ce = defCe;
|
||||||
|
|
||||||
// TODO 修改获取attribute
|
|
||||||
let heroIndex = 0;
|
let heroIndex = 0;
|
||||||
for(let enemy of dicWarJson) {
|
for(let json of dicWarJson) {
|
||||||
if(enemy.relation == 2) {
|
if(json.relation == 2) {
|
||||||
let hero = heroes[heroIndex];
|
let hero = heroes[heroIndex];
|
||||||
if(hero) {
|
if(hero) {
|
||||||
enemyObj.enemies.push({...enemy, ...hero});
|
let h = <HeroType>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 ++;
|
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<any>, ce: number }) {
|
export async function matchRobots(scale: number, myCe: number, robotCe: number, warJsonIndex: number, lv: number, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array<any>, ce: number }) {
|
||||||
let {json: dicWarJson, fileName } = getWarJsons(warJsonIndex);
|
let dicWarJson = gameData.warJson.get(warJsonIndex);
|
||||||
if(dicWarJson) {
|
if(dicWarJson) {
|
||||||
enemyObj.enemyFrom = 2;
|
enemyObj.enemyFrom = 2;
|
||||||
enemyObj.enemyId = fileName + '';
|
enemyObj.enemyId = warJsonIndex + '';
|
||||||
|
|
||||||
let allCe = 0;
|
let allCe = 0;
|
||||||
let ratio = myCe / HERO_CE_RATIO / HERO_CE_RATIO / robotCe * scale; // 玩家战力/机器人初始战力*系数
|
let ratio = myCe / HERO_CE_RATIO / HERO_CE_RATIO / robotCe * scale; // 玩家战力/机器人初始战力*系数
|
||||||
for(let enemy of dicWarJson) {
|
for(let json of dicWarJson) {
|
||||||
if(enemy.relation == 2) {
|
if(json.relation == 2) {
|
||||||
let attribute = decodeWarJsonAttribute(enemy.attribute); // 格式:{'hp':1000, ...}
|
const { attribute } = json;
|
||||||
for(let value in attribute) {
|
|
||||||
attribute[value] *= ratio;
|
let newAttribute = getRobotAttribute(attribute, myCe, robotCe, scale);
|
||||||
attribute[value] = Math.round(attribute[value]);
|
|
||||||
}
|
|
||||||
let ce = 0;
|
let ce = 0;
|
||||||
for(let attrName in attribute) {
|
for(let attrName in newAttribute) {
|
||||||
ce += attribute[attrName] * getAttrCeRatio(attrName)||0;
|
ce += newAttribute[attrName] * getAttrCeRatio(attrName)||0;
|
||||||
}
|
}
|
||||||
enemyObj.enemies.push({...enemy, attribute, lv});
|
enemyObj.enemies.push({...json, attribute: newAttribute, lv});
|
||||||
allCe += ce;
|
allCe += ce;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(JSON.stringify(enemyObj.enemies))
|
|
||||||
enemyObj.ce = Math.floor(allCe);
|
enemyObj.ce = Math.floor(allCe);
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { PVP_HERO_POS, ROBOT_NAME, REDIS_KEY, PVP_CONST } from '../consts';
|
|||||||
import { setPvpDefResult } from '../services/timeTaskService';
|
import { setPvpDefResult } from '../services/timeTaskService';
|
||||||
import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent";
|
import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent";
|
||||||
import { getRandomIndexByLen, genCode, getRandomByLen, shouldRefresh, reduceCe } from '../pubUtils/util';
|
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 { gameData, getPLvByScore } from "../pubUtils/data";
|
||||||
import { PVP } from '../pubUtils/dicParam';
|
import { PVP } from '../pubUtils/dicParam';
|
||||||
import { SystemConfigModel } from '../db/SystemConfig'
|
import { SystemConfigModel } from '../db/SystemConfig'
|
||||||
@@ -15,7 +15,7 @@ import { setRank, getMyRank, getFieldByRank } from './redisService';
|
|||||||
import { nowSeconds, checkTodayTime } from '../pubUtils/timeUtil';
|
import { nowSeconds, checkTodayTime } from '../pubUtils/timeUtil';
|
||||||
import { HeroesRecord } from '../db/PvpRecord';
|
import { HeroesRecord } from '../db/PvpRecord';
|
||||||
import { HeroModel, HeroType } from '../db/Hero';
|
import { HeroModel, HeroType } from '../db/Hero';
|
||||||
import { CeAttrNumber } from '../db/generalField';
|
import { CeAttrNumber, CeAttr, CeAttrRole } from '../db/generalField';
|
||||||
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
|
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
|
||||||
const _ = require('underscore');
|
const _ = require('underscore');
|
||||||
|
|
||||||
@@ -369,15 +369,9 @@ export async function getRobotLineup(mapWarJson: DicWarJson[], curOpp: OppPlayer
|
|||||||
for(let json of dicWarJson) {
|
for(let json of dicWarJson) {
|
||||||
let curDicMapJson = mapWarJson.find(cur => cur.dataId == json.dataId);
|
let curDicMapJson = mapWarJson.find(cur => cur.dataId == json.dataId);
|
||||||
const { actorId, actorName, attribute, skill, seid, star, spine, relation } = json;
|
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 };
|
let heroInfo = { actorId, actorName, skill, seid, star, spine, attribute: newAttribute, lv };
|
||||||
heroes.push({
|
heroes.push({
|
||||||
...curDicMapJson, ...heroInfo
|
...curDicMapJson, ...heroInfo
|
||||||
@@ -400,16 +394,7 @@ export async function getPlayerLineup(mapWarJson: DicWarJson[], curOpp: OppPlaye
|
|||||||
let dicHero = gameData.hero.get(actorId);
|
let dicHero = gameData.hero.get(actorId);
|
||||||
let h = <HeroType>hero;
|
let h = <HeroType>hero;
|
||||||
let { ceAttr } = h;
|
let { ceAttr } = h;
|
||||||
let newAttribute = new CeAttrNumber();
|
let newAttribute = getPlayerAttribute(ceAttr, globalCeAttr);
|
||||||
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 heroInfo = { outIndex: order, actorId, actorName: dicHero.name, skill:0, seid:'&', star: h.star, spine: 0, attribute: newAttribute, lv: h.lv };
|
let heroInfo = { outIndex: order, actorId, actorName: dicHero.name, skill:0, seid:'&', star: h.star, spine: 0, attribute: newAttribute, lv: h.lv };
|
||||||
heroes.push({
|
heroes.push({
|
||||||
...curDicMapJson, ...heroInfo
|
...curDicMapJson, ...heroInfo
|
||||||
@@ -419,6 +404,34 @@ export async function getPlayerLineup(mapWarJson: DicWarJson[], curOpp: OppPlaye
|
|||||||
return heroes
|
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[]) {
|
export async function generMyRecInfo(heroScores: HeroScores[], winStreakNum: number, role: RoleType, isSuccess: boolean, pos: number, myHeroes: pvpEndParamInter[]) {
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,10 @@ export default class PvpDefense extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async findByScale(roleId: string, min: number, max: number, lean = true) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user