远征本主界面及匹配机器人
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { getGamedata } from '../../../util/gamedata';
|
||||
import { ExpeditionRecordModel } from '../../../db/ExpeditionRecord';
|
||||
import { ExpeditionWarRecordModel } from '../../../db/ExpeditionWarRecord';
|
||||
import { ExpeditionPointModel } from '../../../db/ExpeditionPoint';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { calculateSumCE, genCode } from '../../../util/util';
|
||||
import { matchPlayers, matchRobots } from './battleUtils';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ExpeditionBattleHandler(app);
|
||||
}
|
||||
|
||||
export class ExpeditionBattleHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取初始数据
|
||||
* 获取当前远征挑战情况,远征点数,点数宝箱领取情况 */
|
||||
async getStatus(msg: { }, session: BackendSession) {
|
||||
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
|
||||
// 每日刷新,刷新关卡进度,宝箱进度,武将状态
|
||||
let now = new Date();
|
||||
let today = now.setHours(0, 0, 0, 0);
|
||||
let expeditionRecord = await ExpeditionRecordModel.getTodayRecord(roleId, today);
|
||||
if(!expeditionRecord) { // 每天新建一条记录
|
||||
let code = genCode(8);
|
||||
expeditionRecord = await ExpeditionRecordModel.createTodayRecord(code, {
|
||||
roleId, roleName, time: today, heroes: []
|
||||
});
|
||||
}
|
||||
|
||||
// 每一关的挑战状态
|
||||
let { expeditionCode, heroes } = expeditionRecord;
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCode(expeditionCode);
|
||||
let curLv = 0;
|
||||
if(expeditionWarRecord.length > 0) {
|
||||
curLv = expeditionRecord[expeditionWarRecord.length - 1].expeditionId;
|
||||
}
|
||||
|
||||
// 点数,和宝箱领取状态
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let {expeditionPoint} = 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 = rewards.map(cur => {
|
||||
return { point: cur.point, received: cur.received }
|
||||
})
|
||||
}
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
expeditionCode,
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
pointRewards,
|
||||
heroes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取敌军数据
|
||||
* 匹配其他玩家,或机器人数据
|
||||
*/
|
||||
async getEnemies(msg: { expeditionCode: string, expeditionId: number }, session: BackendSession) {
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
// const roleName = session.get('roleName');
|
||||
const { expeditionCode, expeditionId } = msg;
|
||||
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionWarRecord) { // 如果没有信息
|
||||
|
||||
// 计算我方战斗力(最高五人)
|
||||
let myCe = await calculateSumCE(roleId, 1, { num: 5 });
|
||||
console.log('****myCe', myCe);
|
||||
let enemyObj = {
|
||||
enemyFrom: 0,
|
||||
enemyId: '',
|
||||
enemies: new Array()
|
||||
};
|
||||
|
||||
let dicExpedition = getGamedata('dic_expedition');
|
||||
let curDicExpedition = dicExpedition.find(cur => cur.id == expeditionId);
|
||||
|
||||
// 匹配,判断是不是新手期
|
||||
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;
|
||||
|
||||
// 优先匹配其他玩家
|
||||
let flag = await matchPlayers(scale, range, myCe, enemyObj);
|
||||
|
||||
// 当数量不够时使用机器人匹配
|
||||
if(!flag) {
|
||||
flag = await matchRobots(scale, myCe, curDicExpedition.ce, curDicExpedition.json, role, enemyObj);
|
||||
}
|
||||
|
||||
console.log('**********flag', flag)
|
||||
if(!flag) {
|
||||
return {code: 202, data:'无法匹配对手'};
|
||||
}
|
||||
// 保存
|
||||
let {warId} = curDicExpedition;
|
||||
expeditionWarRecord = await ExpeditionWarRecordModel.saveRecord(expeditionCode, expeditionId, {
|
||||
roleId, battleId: warId, ...enemyObj
|
||||
});
|
||||
}
|
||||
|
||||
let { battleId, enemyFrom, enemies, battleStatus } = expeditionWarRecord;
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
expeditionCode, expeditionId, battleId,
|
||||
battleStatus,
|
||||
enemyFrom,
|
||||
enemies
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入战斗
|
||||
* 记录我军数据,生成战斗唯一表示,记录状态
|
||||
*/
|
||||
async checkBattle(msg: { }, session: BackendSession) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 战斗结算
|
||||
* 结算战斗奖励,更新远征状态
|
||||
*/
|
||||
async battleEnd(msg: { }, session: BackendSession) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取战斗宝箱
|
||||
* 领取宝箱,更新远征状态
|
||||
*/
|
||||
async battleReward(msg: { }, session: BackendSession) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取点数宝箱
|
||||
* 领取点数宝箱,不扣除点数,那么就需要记录领取状态并且有返回
|
||||
*/
|
||||
async pointReward(msg: { }, session: BackendSession) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新点数宝箱
|
||||
* 扣除远征点数,并刷新箱子状态
|
||||
*/
|
||||
async resetPointReward(msg: { }, session: BackendSession) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user