添加远征匹配玩家方法
This commit is contained in:
@@ -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