修改远征创建记录逻辑
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { DailyRecordModel } from '../../../db/DailyRecord';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { getGamedata } from '../../../pubUtils/gamedata';
|
||||
import { WAR_TYPE, GOLD_COST_RATIO } from '../../../consts/consts';
|
||||
import { GOLD_COST_RATIO } from '../../../consts/consts';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult, calculateNum } from '../../../pubUtils/util';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
@@ -20,8 +19,7 @@ export class DailyBattleHandler {
|
||||
async getData(msg: { }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
const BattleRecord = await BattleRecordModel.getBattleList(roleId, WAR_TYPE.DAILY);
|
||||
|
||||
let {warStar} = await RoleModel.findByRoleId(roleId);
|
||||
let dicDaily = getGamedata('dic_zyz_daily');
|
||||
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
|
||||
|
||||
@@ -32,13 +30,13 @@ export class DailyBattleHandler {
|
||||
for(let {war_id, dailyType, cost, gk_name, previousGk } of dicDailyWar) {
|
||||
if(dailyType == type) {
|
||||
let status = 0, star = 0;
|
||||
let curBattle = BattleRecord.find(cur => cur.battleId == war_id);
|
||||
let curBattle = warStar.find(cur => cur.id == war_id);
|
||||
if(curBattle) {
|
||||
status = 2;
|
||||
star = curBattle.star;
|
||||
} else {
|
||||
if (previousGk) {
|
||||
let preBattleRecord = BattleRecord.find(cur => cur.battleId == previousGk);
|
||||
let preBattleRecord = warStar.find(cur => cur.id == previousGk);
|
||||
if(preBattleRecord) {
|
||||
status = 1;
|
||||
} else {
|
||||
@@ -54,6 +52,7 @@ export class DailyBattleHandler {
|
||||
}
|
||||
}
|
||||
let checkDailyResult = await getDailyNum(refreshResult, timesPerDay, timesCanBuy);
|
||||
checkDailyResult['count'] = checkDailyResult.battleCount;
|
||||
result.push({
|
||||
type, name, ...checkDailyResult,
|
||||
wars
|
||||
@@ -94,6 +93,7 @@ export class DailyBattleHandler {
|
||||
let newDailyRecord = await DailyRecordModel.increseBuyCount(roleId, type, count);
|
||||
|
||||
let checkDailyResult = await getDailyNum(newDailyRecord, timesPerDay, timesCanBuy);
|
||||
checkDailyResult['count'] = checkDailyResult.battleCount;
|
||||
return resResult(STATUS.SUCCESS, { type, ...checkDailyResult, buyCost});
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { ExpeditionWarRecordModel } from '../../../db/ExpeditionWarRecord';
|
||||
import { ExpeditionPointModel } from '../../../db/ExpeditionPoint';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { calculateSumCE, genCode } from '../../../pubUtils/util';
|
||||
import { matchPlayers, matchRobots, getPointRewardStatus, getCEScaleAndRange, getResetRemainCnt } from '../../../services/expeditionService';
|
||||
import { getPointRewardStatus, getResetRemainCnt, findOrCreateEnemies } from '../../../services/expeditionService';
|
||||
import { EXPEDITION_CONST } from '../../../consts/consts';
|
||||
import { WarReward } from '../../../services/warRewardService';
|
||||
import { handleFixedReward } from '../../../services/rewardService';
|
||||
@@ -34,11 +34,12 @@ export class ExpeditionBattleHandler {
|
||||
// 获取远征关卡状态
|
||||
let expeditionRecord = await ExpeditionRecordModel.getCurRecord(roleId);
|
||||
if(!expeditionRecord) { // 首次新建一条记录
|
||||
// 我方战力(暂定)
|
||||
// 我方战力
|
||||
let myCe = await calculateSumCE(roleId, 1, { num: 5 });
|
||||
expeditionRecord = await ExpeditionRecordModel.createRecord({
|
||||
roleId, roleName, heroes: [], myCe
|
||||
});
|
||||
await findOrCreateEnemies(roleId, myCe, expeditionRecord.expeditionCode, 1);
|
||||
}
|
||||
|
||||
// 每一关的挑战状态
|
||||
@@ -89,12 +90,18 @@ export class ExpeditionBattleHandler {
|
||||
let { expeditionCode, heroes } = await ExpeditionRecordModel.createRecord({
|
||||
roleId, roleName, heroes: [], myCe
|
||||
});
|
||||
await findOrCreateEnemies(roleId, myCe, expeditionCode, 1);
|
||||
await RoleModel.increaseExpeditionResetCnt(roleId, needRefresh, curTime);
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCode(expeditionCode);
|
||||
let curLv = 0;
|
||||
if(expeditionWarRecord.length > 0) {
|
||||
curLv = expeditionWarRecord[expeditionWarRecord.length - 1].expeditionId;
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
curLv: 0,
|
||||
expeditionWarRecord: [],
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
heroes,
|
||||
resetCnt: resetCnt - 1
|
||||
});
|
||||
@@ -112,40 +119,22 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
let { myCe } = await ExpeditionRecordModel.getExpeditionRecordByCode(expeditionCode);
|
||||
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionWarRecord) { // 如果没有信息
|
||||
let enemyObj = {
|
||||
enemyFrom: 0,
|
||||
enemyId: '',
|
||||
enemies: new Array()
|
||||
};
|
||||
|
||||
let dicExpedition = getGamedata('dic_expedition');
|
||||
let curDicExpedition = dicExpedition.find(cur => cur.id == expeditionId);
|
||||
// 获取系数和步长
|
||||
let {scale, range, lv} = await getCEScaleAndRange(roleId, curDicExpedition);
|
||||
// 优先匹配其他玩家
|
||||
let flag = await matchPlayers(roleId, scale, range, myCe, curDicExpedition.json, enemyObj);
|
||||
// 当数量不够时使用机器人匹配
|
||||
if(!flag) {
|
||||
flag = await matchRobots(scale, myCe, curDicExpedition.ce, curDicExpedition.json, lv, enemyObj);
|
||||
}
|
||||
if(!flag) {
|
||||
return resResult(STATUS.EXPEDITION_MATCH_NO_PLAYER);
|
||||
}
|
||||
// 保存
|
||||
let {warId} = curDicExpedition;
|
||||
expeditionWarRecord = await ExpeditionWarRecordModel.saveRecord(expeditionCode, expeditionId, {
|
||||
roleId, battleId: warId, ...enemyObj
|
||||
});
|
||||
let curExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId);
|
||||
if(!curExpeditionWarRecord) {
|
||||
return resResult(STATUS.EXPEDITION_MATCH_NO_PLAYER);
|
||||
}
|
||||
let { battleId, enemyFrom, enemies, battleStatus, ce: curCe } = curExpeditionWarRecord;
|
||||
let nextCe = 0; // 下一关战力
|
||||
let nextExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId + 1);
|
||||
if(nextExpeditionWarRecord) nextCe = nextExpeditionWarRecord.ce;
|
||||
|
||||
let { battleId, enemyFrom, enemies, battleStatus } = expeditionWarRecord;
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId, battleId,
|
||||
battleStatus,
|
||||
enemyFrom,
|
||||
enemies
|
||||
enemies,
|
||||
curCe,
|
||||
nextCe
|
||||
});
|
||||
}
|
||||
|
||||
@@ -282,51 +271,11 @@ export class ExpeditionBattleHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取战斗宝箱
|
||||
* 领取宝箱,更新远征状态
|
||||
*/
|
||||
async battleReward(msg: { expeditionCode: string, expeditionId: number }, session: BackendSession) {
|
||||
|
||||
const { expeditionCode, expeditionId } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
// 检查expeditionWarRecord的battleStatus
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionWarRecord) {
|
||||
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
|
||||
}
|
||||
if(expeditionWarRecord.battleStatus != 1) {
|
||||
return resResult(STATUS.EXPEDITION_WRONG_STATUS_WHEN_RECEIVE);
|
||||
}
|
||||
if(expeditionWarRecord.received) {
|
||||
return resResult(STATUS.EXPEDITION_WRONG_RECEIVE_STATUS);
|
||||
}
|
||||
// 设置expeditionWarRecord的received和rewards
|
||||
let dicExpedition = getGamedata('dic_expedition');
|
||||
let curDicExpedition = dicExpedition.find(cur => cur.id == expeditionId);
|
||||
if(!curDicExpedition) {
|
||||
return resResult(STATUS.EXPEDITION_MISS_INFO);
|
||||
}
|
||||
|
||||
let result = await ExpeditionWarRecordModel.updateBoxStatus(expeditionCode, expeditionId, true, curDicExpedition.reward);
|
||||
let { battleId, battleCode, battleStatus, received } = result;
|
||||
// 获取东西
|
||||
let goods = await handleFixedReward(roleId, roleName, curDicExpedition.reward, 1);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId,
|
||||
battleId, battleCode, battleStatus, received,
|
||||
...goods
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取点数宝箱
|
||||
* 领取点数宝箱,不扣除点数,那么就需要记录领取状态并且有返回
|
||||
*/
|
||||
async pointReward(msg: { point }, session: BackendSession) {
|
||||
async pointReward(msg: { point: number }, session: BackendSession) {
|
||||
|
||||
const { point } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
@@ -353,51 +302,28 @@ export class ExpeditionBattleHandler {
|
||||
}
|
||||
|
||||
// 标记状态
|
||||
await ExpeditionPointModel.updatePointStatus(roleId, point, curDicExpeditionPoint.reward);
|
||||
let {rewards: resultRewards} = await ExpeditionPointModel.updatePointStatus(roleId, point, curDicExpeditionPoint.reward);
|
||||
let hasReceivedAll = true, maxPoint = 0;
|
||||
for(let dic of dicExpeditionPoint) {
|
||||
let curReward = resultRewards.find(cur => cur.point == dic.point);
|
||||
if(!curReward || !curReward.received) {
|
||||
hasReceivedAll = false;
|
||||
}
|
||||
if(dic.point > maxPoint) maxPoint = dic.point;
|
||||
}
|
||||
if(hasReceivedAll) { // 全部领取了,刷新
|
||||
await ExpeditionPointModel.completeStatus(roleId);
|
||||
await RoleModel.increaseExpeditionPoint(roleId, maxPoint * -1);
|
||||
}
|
||||
let pointRewards = await getPointRewardStatus(roleId);
|
||||
|
||||
let goods = await handleFixedReward(roleId, roleName, curDicExpeditionPoint.reward, 1);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
costPoint: hasReceivedAll?maxPoint: 0,
|
||||
pointRewards,
|
||||
...goods
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新点数宝箱
|
||||
* 扣除远征点数,并刷新箱子状态
|
||||
*/
|
||||
async resetPointReward(msg: { }, session: BackendSession) {
|
||||
|
||||
let roleId = session.get('roleId');
|
||||
// let roleName = session.get('roleName');
|
||||
|
||||
let pointStatusInDatabase = await ExpeditionPointModel.getExpeditionPoint(roleId);
|
||||
if(!pointStatusInDatabase) {
|
||||
return resResult(STATUS.EXPEDITION_POINT_RECORD_NOT_FOUND);
|
||||
}
|
||||
let { rewards } = pointStatusInDatabase;
|
||||
let dicExpeditionPoint = getGamedata('dic_expedition_point');
|
||||
let flag = true, maxPoint = 0;
|
||||
for(let dic of dicExpeditionPoint) {
|
||||
let curReward = rewards.find(cur => cur.point == dic.point);
|
||||
if(!curReward || !curReward.received) {
|
||||
flag = false;
|
||||
}
|
||||
if(dic.point > maxPoint) maxPoint = dic.point;
|
||||
}
|
||||
if(!flag) {
|
||||
return resResult(STATUS.EXPEDITION_POINT_NEED_ALL_RECEIVED);
|
||||
}
|
||||
|
||||
// 刷新
|
||||
await ExpeditionPointModel.completeStatus(roleId);
|
||||
await RoleModel.increaseExpeditionPoint(roleId, maxPoint * -1);
|
||||
|
||||
let pointRewards = await getPointRewardStatus(roleId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
pointRewards
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user