import { ExpeditionPointModel } from '../db/ExpeditionPoint'; import { RoleModel } from '../db/Role'; import { getWarJsons, getGamedata } from '../pubUtils/gamedata'; import { decodeStr } 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 }) { let min = myCe * scale * (1 - range/100); let max = myCe * scale * (1 + range/100); console.log(min, max, enemyObj); return false } // 匹配机器人 export async function matchRobots(scale: number, myCe: number, robotCe: number, warJsonIndex:any, lv: number, enemyObj: {enemyFrom: number, enemyId: string, enemies: Array }) { let {json: dicWarJson, fileName } = getWarJsons(warJsonIndex); if(dicWarJson) { enemyObj.enemyFrom = 2; enemyObj.enemyId = fileName; 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]); } enemyObj.enemies.push({...enemy, attribute, lv}); } return true } else { return false } } // 远征匹配系数表 export async function getCEScaleAndRange(roleId: string, curDicExpedition: any) { // 匹配,判断是不是新手期 const role = await RoleModel.findByRoleId(roleId); let now = new Date(); let today = now.setHours(0,0,0,0); let isNew = today - role.createdAt.getTime() <= 3*24*60*60*1000; let scale = isNew?curDicExpedition.CEScaleNew:curDicExpedition.CEScale; let range = isNew?curDicExpedition.CERangeNew:curDicExpedition.CERange; return {scale, range, lv: role.lv} } // 远征表属性解码 export function decodeWarJsonAttribute(attribute) { let arr = decodeStr('attribute', attribute); let obj = {}; for(let {id, value} of arr) { let field = WAR_JSON_ATTRIBUTE_TYPE[id]; if(field) { obj[field] = value; } } return obj } // 远征累计点数获取 export async function getPointRewardStatus(roleId: string) { let role = await RoleModel.findByRoleId(roleId); let {expeditionPoint = 0} = role; let dicExpeditionPoint = getGamedata('dic_expedition_point'); let pointRewards = { expeditionPoint, rewards: dicExpeditionPoint.map(cur => { return { point: cur.point, received: false } }) }; let pointStatusInDatabase = await ExpeditionPointModel.getExpeditionPoint(roleId); if(pointStatusInDatabase) { let { rewards = [] } = pointStatusInDatabase; pointRewards.rewards.forEach(cur => { let obj = rewards.find(ccur => ccur.point == cur.point); if(obj) cur.received = obj.received; }); } return pointRewards }