添加远征匹配玩家方法
This commit is contained in:
@@ -77,6 +77,7 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
// 计算我方战斗力(最高五人)
|
||||
let myCe = await calculateSumCE(roleId, 1, { num: 5 });
|
||||
console.log(myCe);
|
||||
let enemyObj = {
|
||||
enemyFrom: 0,
|
||||
enemyId: '',
|
||||
@@ -88,7 +89,7 @@ export class ExpeditionBattleHandler {
|
||||
// 获取系数和步长
|
||||
let {scale, range, lv} = await getCEScaleAndRange(roleId, curDicExpedition);
|
||||
// 优先匹配其他玩家
|
||||
let flag = await matchPlayers(scale, range, myCe, enemyObj);
|
||||
let flag = await matchPlayers(roleId, scale, range, myCe, curDicExpedition.json, enemyObj);
|
||||
// 当数量不够时使用机器人匹配
|
||||
if(!flag) {
|
||||
flag = await matchRobots(scale, myCe, curDicExpedition.ce, curDicExpedition.json, lv, enemyObj);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { BattleSweepRecordModel } from '../../../db/BattleSweepRecord';
|
||||
import { getWarById, } from '../../../pubUtils/gamedata';
|
||||
import { genCode } from '../../../pubUtils/util';
|
||||
import { WAR_TYPE } from '../../../consts/consts';
|
||||
import { WAR_TYPE, EVENT_STATUS } from '../../../consts/consts';
|
||||
import { checkDaily, checkDailyAndIncrease } from '../../../services/dailyBattleService';
|
||||
import { checkTowerWar, towerBattleEnd } from '../../../services/battleService';
|
||||
import { WarReward } from '../../../services/warRewardService';
|
||||
@@ -70,7 +70,8 @@ export class NormalBattleHandler {
|
||||
towerData = Object.assign(towerData, checkResult.data);
|
||||
} else if (warInfo.warType == WAR_TYPE.EVENT) {
|
||||
// 记录事件状态
|
||||
let checkResult = await checkEventBattle( roleId, session.get('eventStatus'), battleId, battleCode);
|
||||
let eventStatus = session.get('eventStatus')||EVENT_STATUS.WAITING;
|
||||
let checkResult = await checkEventBattle( roleId, eventStatus, battleId, battleCode);
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
|
||||
@@ -1,20 +1,44 @@
|
||||
|
||||
import { ExpeditionPointModel } from '../db/ExpeditionPoint';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { PvpDefenseModel } from '../db/PvpDefense';
|
||||
|
||||
import { getWarJsons, getGamedata } from '../pubUtils/gamedata';
|
||||
import { decodeStr } from '../pubUtils/util';
|
||||
import { decodeStr, resResult } from '../pubUtils/util';
|
||||
import { WAR_JSON_ATTRIBUTE_TYPE } from '../consts/consts';
|
||||
|
||||
|
||||
// 匹配玩家
|
||||
export async function matchPlayers(scale: number, range: number, myCe: number ,enemyObj: {enemyFrom: number, enemyId: string, enemies: Array<any> }) {
|
||||
export async function matchPlayers(roleId: string, scale: number, range: number, myCe: number, warJsonIndex:any, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array<any> }) {
|
||||
let {json: dicWarJson } = getWarJsons(warJsonIndex);
|
||||
|
||||
let min = myCe * scale * (1 - range/100);
|
||||
let max = myCe * scale * (1 + range/100);
|
||||
console.log(min, max, enemyObj);
|
||||
|
||||
return false
|
||||
let resultRange = await PvpDefenseModel.findByScale(roleId, min, max);
|
||||
if(resultRange.length > 0) {
|
||||
let index = Math.floor(Math.random() * resultRange.length);
|
||||
let result = resultRange[index];
|
||||
let {roleId, heroes } = result;
|
||||
|
||||
enemyObj.enemyFrom = 1;
|
||||
enemyObj.enemyId = roleId;
|
||||
|
||||
let heroIndex = 0;
|
||||
for(let enemy of dicWarJson) {
|
||||
if(enemy.relation == 2) {
|
||||
let hero = heroes[heroIndex];
|
||||
if(hero) {
|
||||
enemyObj.enemies.push({...enemy, ...hero});
|
||||
heroIndex ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配机器人
|
||||
@@ -26,12 +50,14 @@ export async function matchRobots(scale: number, myCe: number, robotCe: number,
|
||||
|
||||
let ratio = myCe / robotCe * scale; // 玩家战力/机器人初始战力*系数
|
||||
for(let enemy of dicWarJson) {
|
||||
let attribute = decodeWarJsonAttribute(enemy.attribute); // 格式:{'hp':1000, ...}
|
||||
for(let value in attribute) {
|
||||
attribute[value] *= ratio;
|
||||
attribute[value] = Math.round(attribute[value]);
|
||||
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]);
|
||||
}
|
||||
enemyObj.enemies.push({...enemy, attribute, lv});
|
||||
}
|
||||
enemyObj.enemies.push({...enemy, attribute, lv});
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -55,7 +81,10 @@ export async function getCEScaleAndRange(roleId: string, curDicExpedition: any)
|
||||
// 远征表属性解码
|
||||
export function decodeWarJsonAttribute(attribute) {
|
||||
let arr = decodeStr('attribute', attribute);
|
||||
let obj = {};
|
||||
let obj = {}
|
||||
for(let key in WAR_JSON_ATTRIBUTE_TYPE) {
|
||||
obj[WAR_JSON_ATTRIBUTE_TYPE[key]] = 0; // 初始化
|
||||
}
|
||||
for(let {id, value} of arr) {
|
||||
let field = WAR_JSON_ATTRIBUTE_TYPE[id];
|
||||
if(field) {
|
||||
|
||||
Reference in New Issue
Block a user