活动:任务接口添加serverId接口
This commit is contained in:
@@ -16,7 +16,7 @@ import { checkBattleHeroes, roleLevelup } from '../../../services/normalBattleSe
|
||||
import { checkTask, checkTaskInBattleEnd } from '../../../services/taskService';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
|
||||
export default function(app: Application) {
|
||||
export default function (app: Application) {
|
||||
return new ExpeditionBattleHandler(app);
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
/**
|
||||
* 获取初始数据
|
||||
* 获取当前远征挑战情况,远征点数,点数宝箱领取情况 */
|
||||
async getStatus(msg: { }, session: BackendSession) {
|
||||
* 获取当前远征挑战情况,远征点数,点数宝箱领取情况 */
|
||||
async getStatus(msg: {}, session: BackendSession) {
|
||||
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
|
||||
// 获取远征关卡状态
|
||||
let expeditionRecord = await ExpeditionRecordModel.getCurRecord(roleId);
|
||||
if(!expeditionRecord) { // 首次新建一条记录
|
||||
if (!expeditionRecord) { // 首次新建一条记录
|
||||
// 我方战力
|
||||
let myCe = await calculateSumCE(roleId, 1, { num: LINEUP_NUM });
|
||||
expeditionRecord = await ExpeditionRecordModel.createRecord({
|
||||
@@ -47,39 +47,39 @@ export class ExpeditionBattleHandler {
|
||||
let { expeditionCode, heroes } = expeditionRecord;
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCode(expeditionCode);
|
||||
let curLv = 0;
|
||||
if(expeditionWarRecord.length > 0) {
|
||||
if (expeditionWarRecord.length > 0) {
|
||||
curLv = expeditionWarRecord[expeditionWarRecord.length - 1].expeditionId;
|
||||
}
|
||||
|
||||
// 重置次数
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let curTime = new Date();
|
||||
let {resetCnt} = await getResetRemainCnt(curTime, roleId, role);
|
||||
let { resetCnt } = await getResetRemainCnt(curTime, roleId, role);
|
||||
|
||||
// 点数,和宝箱领取状态
|
||||
let pointRewards = await getPointRewardStatus(roleId, role);
|
||||
let pointRewards = await getPointRewardStatus(roleId, role);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
pointRewards,
|
||||
heroes: heroes.map(cur => {return {"dataId": cur.seqId, "hp": cur.hp, "ap": cur.ap}}),
|
||||
resetCnt
|
||||
expeditionCode,
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
pointRewards,
|
||||
heroes: heroes.map(cur => { return { "dataId": cur.seqId, "hp": cur.hp, "ap": cur.ap } }),
|
||||
resetCnt
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置远征本
|
||||
* 每天5点可以重置远征本 */
|
||||
async resetStatus(msg: { }, session: BackendSession) {
|
||||
* 每天5点可以重置远征本 */
|
||||
async resetStatus(msg: {}, session: BackendSession) {
|
||||
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
|
||||
let curTime = new Date();
|
||||
let {needRefresh, resetCnt} = await getResetRemainCnt(curTime, roleId);
|
||||
if(resetCnt <= 0) {
|
||||
let { needRefresh, resetCnt } = await getResetRemainCnt(curTime, roleId);
|
||||
if (resetCnt <= 0) {
|
||||
return resResult(STATUS.EXPEDITION_RESET_NUM_NOT_ENOUGH)
|
||||
}
|
||||
|
||||
@@ -91,20 +91,20 @@ export class ExpeditionBattleHandler {
|
||||
let { expeditionCode, heroes } = await ExpeditionRecordModel.createRecord({
|
||||
roleId, roleName, heroes: [], myCe
|
||||
});
|
||||
await findOrCreateEnemies(roleId, myCe, expeditionCode, 1, EXPEDITION_WAR_RECORD_STATUS.WAITING);
|
||||
await findOrCreateEnemies(roleId, myCe, expeditionCode, 1, EXPEDITION_WAR_RECORD_STATUS.WAITING);
|
||||
await RoleModel.increaseExpeditionResetCnt(roleId, needRefresh, curTime);
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCode(expeditionCode);
|
||||
let curLv = 0;
|
||||
if(expeditionWarRecord.length > 0) {
|
||||
if (expeditionWarRecord.length > 0) {
|
||||
curLv = expeditionWarRecord[expeditionWarRecord.length - 1].expeditionId;
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
heroes,
|
||||
resetCnt: resetCnt - 1
|
||||
expeditionCode,
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
heroes,
|
||||
resetCnt: resetCnt - 1
|
||||
});
|
||||
}
|
||||
|
||||
@@ -121,15 +121,15 @@ export class ExpeditionBattleHandler {
|
||||
let { myCe } = await ExpeditionRecordModel.getExpeditionRecordByCode(expeditionCode);
|
||||
|
||||
let curExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId, EXPEDITION_WAR_RECORD_STATUS.WAITING);
|
||||
if(!curExpeditionWarRecord) {
|
||||
if (!curExpeditionWarRecord) {
|
||||
return resResult(STATUS.EXPEDITION_MATCH_NO_PLAYER);
|
||||
}
|
||||
let { battleId, enemyFrom, enemies, battleStatus, ce: curCe } = curExpeditionWarRecord;
|
||||
let nextCe = 0; // 下一关战力
|
||||
|
||||
if(gameData.expedition.has(expeditionId + 1)) {
|
||||
|
||||
if (gameData.expedition.has(expeditionId + 1)) {
|
||||
let nextExpeditionWarRecord = await findOrCreateEnemies(roleId, myCe, expeditionCode, expeditionId + 1, EXPEDITION_WAR_RECORD_STATUS.HIDE);
|
||||
if(nextExpeditionWarRecord) nextCe = nextExpeditionWarRecord.ce;
|
||||
if (nextExpeditionWarRecord) nextCe = nextExpeditionWarRecord.ce;
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -146,36 +146,36 @@ export class ExpeditionBattleHandler {
|
||||
* 进入战斗
|
||||
* 记录我军数据,生成战斗唯一表示,记录状态
|
||||
*/
|
||||
async checkBattle(msg: { expeditionCode: string, expeditionId: number, battleId: number, heroes: Array<number> }, session: BackendSession) {
|
||||
async checkBattle(msg: { expeditionCode: string, expeditionId: number, battleId: number, heroes: Array<number> }, session: BackendSession) {
|
||||
const { expeditionCode, expeditionId, battleId, heroes: seqIds = [] } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = gameData.war.get(battleId);
|
||||
if(!warInfo) {
|
||||
if (!warInfo) {
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
|
||||
let apJson = await getAp(Date.now(), roleId);
|
||||
let {ap} = apJson;
|
||||
if(ap < warInfo.cost) {
|
||||
let { ap } = apJson;
|
||||
if (ap < warInfo.cost) {
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 前置关卡是否挑战过
|
||||
let previousGk = warInfo.previousGk;
|
||||
if(previousGk) {
|
||||
if (previousGk) {
|
||||
let preBattle = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, previousGk, 1);
|
||||
if(!preBattle) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
if (!preBattle) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
}
|
||||
|
||||
let { isOK, heroes } = await checkBattleHeroes(roleId, seqIds);
|
||||
if(!isOK) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
||||
if (!isOK) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
||||
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionWarRecord ) {
|
||||
if (!expeditionWarRecord) {
|
||||
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
|
||||
}
|
||||
if(expeditionWarRecord.battleStatus == EXPEDITION_WAR_RECORD_STATUS.SUCCESS) {
|
||||
if (expeditionWarRecord.battleStatus == EXPEDITION_WAR_RECORD_STATUS.SUCCESS) {
|
||||
return resResult(STATUS.EXPEDITION_DUPLICATE_CHALLENGE);
|
||||
}
|
||||
|
||||
@@ -193,12 +193,12 @@ export class ExpeditionBattleHandler {
|
||||
let result = await ExpeditionWarRecordModel.updateBattleCode(expeditionCode, expeditionId, EXPEDITION_WAR_RECORD_STATUS.WAITING, battleCode);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
expeditionId,
|
||||
battleId,
|
||||
battleCode,
|
||||
battleStatus: result.battleStatus,
|
||||
apJson
|
||||
expeditionCode,
|
||||
expeditionId,
|
||||
battleId,
|
||||
battleCode,
|
||||
battleStatus: result.battleStatus,
|
||||
apJson
|
||||
});
|
||||
}
|
||||
|
||||
@@ -206,77 +206,78 @@ export class ExpeditionBattleHandler {
|
||||
* 战斗结算
|
||||
* 结算战斗奖励,更新远征状态
|
||||
*/
|
||||
async battleEnd(msg: { expeditionCode: string, expeditionId: number, battleCode: string, battleId: number, isSuccess: boolean, heroes: Array<{dataId: number, hp: number, ap: number}>, enemies: Array<{dataId: number, hp: number, ap: number}>, star: number }, session: BackendSession) {
|
||||
async battleEnd(msg: { expeditionCode: string, expeditionId: number, battleCode: string, battleId: number, isSuccess: boolean, heroes: Array<{ dataId: number, hp: number, ap: number }>, enemies: Array<{ dataId: number, hp: number, ap: number }>, star: number }, session: BackendSession) {
|
||||
|
||||
const { expeditionCode, battleCode, battleId, expeditionId, isSuccess, heroes = [], star, enemies } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
const serverId = session.get('serverId');
|
||||
let sid = session.get('sid');
|
||||
let funcs: number[] = session.get('funcs');
|
||||
|
||||
let warInfo = gameData.war.get(battleId);
|
||||
if(!warInfo) {
|
||||
if (!warInfo) {
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
|
||||
const BattleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode);
|
||||
if(!BattleRecord || BattleRecord.status != 0) {
|
||||
if (!BattleRecord || BattleRecord.status != 0) {
|
||||
return resResult(STATUS.BATTLE_STATUS_WRONG);
|
||||
}
|
||||
|
||||
let flag = 1; // 对比hero信息
|
||||
let { record: { heroes: dbHeroes, seqIds: dbSeqIds } } = BattleRecord;
|
||||
for(let {dataId} of heroes) {
|
||||
if(dbSeqIds.indexOf(dataId) == -1) flag = 0;
|
||||
for (let { dataId } of heroes) {
|
||||
if (dbSeqIds.indexOf(dataId) == -1) flag = 0;
|
||||
}
|
||||
if(!flag) {
|
||||
if (!flag) {
|
||||
return resResult(STATUS.BATTLE_INFO_VALIDATE_ERR);
|
||||
}
|
||||
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, sid, funcs, -1 * warInfo.cost); // 扣除体力
|
||||
if(!apJson) {
|
||||
if (!apJson) {
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 检查record
|
||||
let expeditionRecord = await ExpeditionRecordModel.getExpeditionRecordByCode(expeditionCode);
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionRecord|| !expeditionWarRecord) {
|
||||
if (!expeditionRecord || !expeditionWarRecord) {
|
||||
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
|
||||
}
|
||||
// 更新我方剩余血量
|
||||
await ExpeditionRecordModel.updateHeroStatus(expeditionCode, expeditionRecord.heroes, heroes);
|
||||
// 更新敌人剩余状态及战斗状态
|
||||
let battleStatus = isSuccess?EXPEDITION_WAR_RECORD_STATUS.SUCCESS:EXPEDITION_WAR_RECORD_STATUS.FAIL;
|
||||
let battleStatus = isSuccess ? EXPEDITION_WAR_RECORD_STATUS.SUCCESS : EXPEDITION_WAR_RECORD_STATUS.FAIL;
|
||||
expeditionWarRecord = await ExpeditionWarRecordModel.updateEnemiesStatus(expeditionCode, expeditionId, battleStatus, enemies);
|
||||
// 更新battleRecord状态
|
||||
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: { status: isSuccess?1: 2, star }
|
||||
$set: { status: isSuccess ? 1 : 2, star }
|
||||
}, true);
|
||||
// 更新点数
|
||||
let role = await RoleModel.increaseExpeditionPoint(roleId, isSuccess?EXPEDITION_CONST.INCREASE_POINT:0);
|
||||
let role = await RoleModel.increaseExpeditionPoint(roleId, isSuccess ? EXPEDITION_CONST.INCREASE_POINT : 0);
|
||||
let { expeditionPoint = 0 } = role;
|
||||
|
||||
// 关卡奖励
|
||||
let warReward = new WarReward(roleId, roleName, sid, battleId, isSuccess);
|
||||
let reward = await warReward.saveReward(1);
|
||||
|
||||
let actordata = await roleLevelup(roleId, isSuccess?warInfo.kingExp:0, session);// 主公升级经验
|
||||
if(isSuccess) {
|
||||
|
||||
let actordata = await roleLevelup(roleId, isSuccess ? warInfo.kingExp : 0, session);// 主公升级经验
|
||||
if (isSuccess) {
|
||||
// 更新下一关状态
|
||||
await ExpeditionWarRecordModel.updateStatus(expeditionCode, expeditionId + 1, EXPEDITION_WAR_RECORD_STATUS.WAITING);
|
||||
await ExpeditionWarRecordModel.updateStatus(expeditionCode, expeditionId + 1, EXPEDITION_WAR_RECORD_STATUS.WAITING);
|
||||
}
|
||||
await checkTaskInBattleEnd(roleId, sid, funcs, battleId, dbHeroes, star);
|
||||
|
||||
await checkTaskInBattleEnd(serverId, roleId, sid, funcs, battleId, dbHeroes, star);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId,
|
||||
battleCode, battleId,
|
||||
battleStatus: expeditionWarRecord.battleStatus,
|
||||
battleGoods: reward,
|
||||
apJson,
|
||||
expeditionPoint,
|
||||
...actordata
|
||||
expeditionCode, expeditionId,
|
||||
battleCode, battleId,
|
||||
battleStatus: expeditionWarRecord.battleStatus,
|
||||
battleGoods: reward,
|
||||
apJson,
|
||||
expeditionPoint,
|
||||
...actordata
|
||||
});
|
||||
}
|
||||
|
||||
@@ -293,40 +294,40 @@ export class ExpeditionBattleHandler {
|
||||
const funcs: number[] = session.get('funcs');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let {expeditionPoint} = role;
|
||||
let { expeditionPoint } = role;
|
||||
let dicExpeditionPoint = gameData.expeditionPoint;
|
||||
let curDicExpeditionPoint = dicExpeditionPoint.get(point);
|
||||
if(!curDicExpeditionPoint) {
|
||||
if (!curDicExpeditionPoint) {
|
||||
return resResult(STATUS.EXPEDITION_MISS_POINT_INFO);
|
||||
}
|
||||
|
||||
if(point > expeditionPoint) {
|
||||
if (point > expeditionPoint) {
|
||||
return resResult(STATUS.EXPEDITION_POINT_NOT_ENOUGH);
|
||||
}
|
||||
let pointStatusInDatabase = await ExpeditionPointModel.getExpeditionPoint(roleId);
|
||||
if(pointStatusInDatabase) {
|
||||
let {rewards} = pointStatusInDatabase;
|
||||
if (pointStatusInDatabase) {
|
||||
let { rewards } = pointStatusInDatabase;
|
||||
let curReward = rewards.find(cur => cur.point == point);
|
||||
if(curReward && curReward.received) {
|
||||
if (curReward && curReward.received) {
|
||||
return resResult(STATUS.EXPEDITION_WRONG_RECEIVE_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
// 标记状态
|
||||
let {rewards: resultRewards} = await ExpeditionPointModel.updatePointStatus(roleId, point, curDicExpeditionPoint.reward);
|
||||
let { rewards: resultRewards } = await ExpeditionPointModel.updatePointStatus(roleId, point, curDicExpeditionPoint.reward);
|
||||
let hasReceivedAll = true, maxPoint = 0;
|
||||
for(let [ point ] of dicExpeditionPoint) {
|
||||
for (let [point] of dicExpeditionPoint) {
|
||||
let curReward = resultRewards.find(cur => cur.point == point);
|
||||
if(!curReward || !curReward.received) {
|
||||
if (!curReward || !curReward.received) {
|
||||
hasReceivedAll = false;
|
||||
}
|
||||
if(point > maxPoint) maxPoint = point;
|
||||
if (point > maxPoint) maxPoint = point;
|
||||
}
|
||||
if(hasReceivedAll) { // 全部领取了,刷新
|
||||
if (hasReceivedAll) { // 全部领取了,刷新
|
||||
await ExpeditionPointModel.completeStatus(roleId);
|
||||
await RoleModel.increaseExpeditionPoint(roleId, maxPoint * -1);
|
||||
}
|
||||
let pointRewards = await getPointRewardStatus(roleId);
|
||||
let pointRewards = await getPointRewardStatus(roleId);
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.BATTLE_EXPEDITION_BOX, 1, true, { point });
|
||||
@@ -334,7 +335,7 @@ export class ExpeditionBattleHandler {
|
||||
let goods = await addItems(roleId, roleName, sid, curDicExpeditionPoint.reward);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
costPoint: hasReceivedAll?maxPoint: 0,
|
||||
costPoint: hasReceivedAll ? maxPoint : 0,
|
||||
pointRewards,
|
||||
goods
|
||||
})
|
||||
|
||||
@@ -271,7 +271,7 @@ export class GuildTrainHandler {
|
||||
}
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GUILD_TRAIN, 1, true, {});
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.GUILD_TRAIN, 1)
|
||||
await accomplishTask(serverId, roleId, TASK_TYPE.GUILD_TRAIN, 1)
|
||||
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { BattleSweepRecordModel } from '../../../db/BattleSweepRecord';
|
||||
import { genCode } from '../../../pubUtils/util';
|
||||
import { WAR_TYPE, EVENT_STATUS, FUNC_OPT_TYPE, MSG_SOURCE, REDIS_KEY, TASK_TYPE } from '../../../consts';
|
||||
import { checkDaily, checkDailyAndIncrease } from '../../../services/dailyBattleService';
|
||||
import { checkTowerWar, towerBattleEnd } from '../../../services/battleService';
|
||||
import { checkTowerWar, towerBattleEnd } from '../../../services/battleService';
|
||||
import { WarReward } from '../../../services/warRewardService';
|
||||
import { getAp, setAp } from '../../../services/actionPointService';
|
||||
import { setBattleStatus, checkEventBattle } from '../../../services/eventSercive';
|
||||
@@ -21,7 +21,7 @@ import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { Rank } from '../../../services/rankService';
|
||||
import { checkTaskWithWar, checkTaskInBattleEnd } from '../../../services/taskService';
|
||||
|
||||
export default function(app: Application) {
|
||||
export default function (app: Application) {
|
||||
return new NormalBattleHandler(app);
|
||||
}
|
||||
|
||||
@@ -30,57 +30,57 @@ export class NormalBattleHandler {
|
||||
}
|
||||
|
||||
// 获取关卡列表
|
||||
async checkBattle(msg: {battleId: number, heroes: Array<number> }, session: BackendSession) {
|
||||
async checkBattle(msg: { battleId: number, heroes: Array<number> }, session: BackendSession) {
|
||||
const { battleId, heroes: seqIds = [] } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = gameData.war.get(battleId);
|
||||
if(!warInfo) {
|
||||
if (!warInfo) {
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
let apJson = await getAp(Date.now(), roleId);
|
||||
let {ap} = apJson;
|
||||
if(ap < warInfo.cost) {
|
||||
let { ap } = apJson;
|
||||
if (ap < warInfo.cost) {
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 前置关卡是否挑战过
|
||||
let previousGk = warInfo.previousGk;
|
||||
if(previousGk) {
|
||||
let {warStar} = await RoleModel.findByRoleId(roleId);
|
||||
if (previousGk) {
|
||||
let { warStar } = await RoleModel.findByRoleId(roleId);
|
||||
let preBattle = warStar.findIndex(cur => cur.id == previousGk);
|
||||
if(preBattle == -1) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
if (preBattle == -1) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
}
|
||||
|
||||
let { isOK, heroes } = await checkBattleHeroes(roleId, seqIds);
|
||||
if(!isOK) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
||||
if (!isOK) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
||||
|
||||
const battleCode = genCode(8); // 关卡唯一值
|
||||
let dailyNum = {};
|
||||
let towerData = {};
|
||||
let dungeonNum = {};
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
if (warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDaily(roleId, battleId, 1);
|
||||
if(checkResult.status == -1) {
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dailyNum = Object.assign(dailyNum, checkResult.data);
|
||||
} else if (warInfo.warType == WAR_TYPE.TOWER) {
|
||||
let checkResult = await checkTowerWar(roleId, battleId, heroes);
|
||||
if(checkResult.status == -1) {
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
towerData = Object.assign(towerData, checkResult.data);
|
||||
} else if (warInfo.warType == WAR_TYPE.EVENT) {
|
||||
} else if (warInfo.warType == WAR_TYPE.EVENT) {
|
||||
// 记录事件状态
|
||||
let eventStatus = session.get('eventStatus')||EVENT_STATUS.WAITING;
|
||||
let checkResult = await checkEventBattle( roleId, eventStatus, battleId, battleCode);
|
||||
if(checkResult.status == -1) {
|
||||
let eventStatus = session.get('eventStatus') || EVENT_STATUS.WAITING;
|
||||
let checkResult = await checkEventBattle(roleId, eventStatus, battleId, battleCode);
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
} else if (warInfo.warType == WAR_TYPE.MYSTERY || warInfo.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
let checkResult = await checkDungeonNum(roleId, 1);
|
||||
if(checkResult.status == -1) {
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dungeonNum = Object.assign(dungeonNum, checkResult.data);
|
||||
@@ -96,7 +96,7 @@ export class NormalBattleHandler {
|
||||
}
|
||||
}, true);
|
||||
|
||||
let {status} = BattleRecord;
|
||||
let { status } = BattleRecord;
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -105,30 +105,30 @@ export class NormalBattleHandler {
|
||||
}
|
||||
|
||||
// 关卡列表
|
||||
async getBattleList(msg: {type: number }, session: BackendSession) {
|
||||
async getBattleList(msg: { type: number }, session: BackendSession) {
|
||||
const { type } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let {warStar} = role;
|
||||
let { warStar } = role;
|
||||
|
||||
let scripts = await RScriptRecordModel.findbyRole(roleId, type);
|
||||
let scripts = await RScriptRecordModel.findbyRole(roleId, type);
|
||||
|
||||
let result = []; // 去重
|
||||
for(let {battleId, scriptBefore = '', scriptAfter = ''} of scripts) {
|
||||
|
||||
for (let { battleId, scriptBefore = '', scriptAfter = '' } of scripts) {
|
||||
|
||||
result.push({
|
||||
battleId,
|
||||
status: 0,
|
||||
star: 0,
|
||||
scriptBefore,
|
||||
scriptBefore,
|
||||
scriptAfter
|
||||
});
|
||||
}
|
||||
for(let {id, star, warType} of warStar) {
|
||||
if(warType == type) {
|
||||
for (let { id, star, warType } of warStar) {
|
||||
if (warType == type) {
|
||||
let curResult = result.find(cur => cur.battleId == id);
|
||||
if(curResult) {
|
||||
if (curResult) {
|
||||
curResult.status = 1;
|
||||
curResult.star = star;
|
||||
} else {
|
||||
@@ -136,13 +136,13 @@ export class NormalBattleHandler {
|
||||
battleId: id,
|
||||
status: 1,
|
||||
star,
|
||||
scriptBefore: '',
|
||||
scriptBefore: '',
|
||||
scriptAfter: ''
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
result = result.sort((a, b) => {return a.battleId - b.battleId});
|
||||
result = result.sort((a, b) => { return a.battleId - b.battleId });
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
list: result
|
||||
@@ -150,7 +150,7 @@ export class NormalBattleHandler {
|
||||
}
|
||||
|
||||
// 关卡结算,记录使用的武将,获得奖励
|
||||
async battleEnd(msg: {battleCode: string, battleId: number, isSuccess: boolean, star: number, heroes: Array<any>, }, session: BackendSession) {
|
||||
async battleEnd(msg: { battleCode: string, battleId: number, isSuccess: boolean, star: number, heroes: Array<any>, }, session: BackendSession) {
|
||||
const { battleCode, battleId, isSuccess, heroes = [], star } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
@@ -158,7 +158,7 @@ export class NormalBattleHandler {
|
||||
const funcs: number[] = session.get('funcs');
|
||||
let serverId = session.get('serverId');
|
||||
let warInfo = gameData.war.get(battleId);
|
||||
if(!warInfo) {
|
||||
if (!warInfo) {
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
// 寻宝不使用通用战斗模块结算
|
||||
@@ -167,22 +167,22 @@ export class NormalBattleHandler {
|
||||
}
|
||||
|
||||
const BattleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode, true);
|
||||
if(!BattleRecord || BattleRecord.status != 0) {
|
||||
if (!BattleRecord || BattleRecord.status != 0) {
|
||||
return resResult(STATUS.BATTLE_STATUS_WRONG);
|
||||
}
|
||||
|
||||
let flag = 1; // 对比hero信息
|
||||
let { record: { heroes: dbHeroes, seqIds: dbSeqIds } } = BattleRecord;
|
||||
for(let seqId of dbSeqIds) {
|
||||
if(dbSeqIds.indexOf(seqId) == -1) flag = 0;
|
||||
for (let seqId of dbSeqIds) {
|
||||
if (dbSeqIds.indexOf(seqId) == -1) flag = 0;
|
||||
}
|
||||
if(!flag) {
|
||||
if (!flag) {
|
||||
return resResult(STATUS.BATTLE_INFO_VALIDATE_ERR);
|
||||
}
|
||||
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, sid, funcs, -1 * warInfo.cost); // 扣除体力
|
||||
if(!apJson) {
|
||||
if (!apJson) {
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
@@ -192,64 +192,64 @@ export class NormalBattleHandler {
|
||||
let towerStatus = null;
|
||||
let dungeonNum = {};
|
||||
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
if (warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, 1, false);
|
||||
if(checkResult.status == -1) {
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult;
|
||||
}
|
||||
dailyNum = Object.assign(dailyNum, checkResult.data)
|
||||
} else if (warInfo.warType == WAR_TYPE.EVENT) {
|
||||
} else if (warInfo.warType == WAR_TYPE.EVENT) {
|
||||
// 记录事件状态
|
||||
await setBattleStatus(session, roleId, battleId, isSuccess, battleCode);
|
||||
} else if (warInfo.warType == WAR_TYPE.TOWER) {
|
||||
let towerEndResult = await towerBattleEnd(sid, funcs, roleId, serverId, battleCode, battleId, isSuccess, heroes);
|
||||
if(towerEndResult) {
|
||||
if(towerEndResult.status == -1) {
|
||||
if (towerEndResult) {
|
||||
if (towerEndResult.status == -1) {
|
||||
return towerEndResult.resResult;
|
||||
}
|
||||
towerStatus = towerEndResult.data.towerStatus;
|
||||
if(towerEndResult.data.towerReward)
|
||||
if (towerEndResult.data.towerReward)
|
||||
warReward.setFixReward(towerEndResult.data.towerReward)
|
||||
pushTowerMsg(roleId, roleName, serverId, MSG_SOURCE.TOWER_SUC, towerEndResult.data.newRec.lv);
|
||||
}
|
||||
} else if (warInfo.warType == WAR_TYPE.MYSTERY || warInfo.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
let checkResult = await checkDungeonAndIncrease(roleId, 1, false);
|
||||
let role = await RoleModel.saveDungeonHero(roleId, battleId, heroes, isSuccess);
|
||||
if(role) {
|
||||
if (role) {
|
||||
let r = new Rank(REDIS_KEY.DUNGEON_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, role.dungeonWarId, role.dungeonUpdatedAt, role);
|
||||
}
|
||||
|
||||
if(checkResult.status == -1) {
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult;
|
||||
}
|
||||
dungeonNum = Object.assign(dungeonNum, checkResult.data)
|
||||
} else if (warInfo.warType == WAR_TYPE.NORMAL) {
|
||||
let role = await RoleModel.updateMainWarId(roleId, battleId, nowSeconds());
|
||||
if(role) {
|
||||
if (role) {
|
||||
let r = new Rank(REDIS_KEY.MAIN_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, role.mainWarId, role.mainUpdatedAt, role);
|
||||
}
|
||||
} else if (warInfo.warType == WAR_TYPE.MAIN_ELITE) {
|
||||
let role = await RoleModel.updateMainEliteWarId(roleId, battleId, nowSeconds());
|
||||
if(role) {
|
||||
if (role) {
|
||||
let r = new Rank(REDIS_KEY.MAIN_ELITE_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, role.mainEliteWarId, role.mainEliteUpdatedAt, role);
|
||||
}
|
||||
}
|
||||
|
||||
if(isSuccess) { // 挑战胜利
|
||||
if (isSuccess) { // 挑战胜利
|
||||
// 是否首通
|
||||
let {warStar} = await RoleModel.findByRoleId(roleId);
|
||||
let { warStar } = await RoleModel.findByRoleId(roleId);
|
||||
let condition1 = warStar.find(cur => cur.id == battleId);
|
||||
if(!condition1) {
|
||||
if (!condition1) {
|
||||
await switchOnFunc(roleId, FUNC_OPT_TYPE.BATTLE_END, battleId, session);
|
||||
warReward.setCondition(0, true);
|
||||
pushMysteryFirstMsg(roleId, roleName, serverId, warInfo.warType, warInfo.war_id);
|
||||
pushVestigeFirstMsg(roleId, roleName, serverId, warInfo.warType, warInfo.war_id);
|
||||
}
|
||||
// 是否首次3星
|
||||
if(star == 3 && (!condition1 || condition1.star != 3)) {
|
||||
if (star == 3 && (!condition1 || condition1.star != 3)) {
|
||||
warReward.setCondition(1, true);
|
||||
}
|
||||
|
||||
@@ -259,13 +259,13 @@ export class NormalBattleHandler {
|
||||
let reward = await warReward.saveReward(1);
|
||||
|
||||
const updateResult = await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: { status: isSuccess?1:2, star, record: { heroes } }
|
||||
$set: { status: isSuccess ? 1 : 2, star, record: { heroes } }
|
||||
}, true);
|
||||
let { status } = updateResult;
|
||||
|
||||
let actordata = await roleLevelup(roleId, isSuccess?warInfo.kingExp:0, session);// 主公升级经验
|
||||
let actordata = await roleLevelup(roleId, isSuccess ? warInfo.kingExp : 0, session);// 主公升级经验
|
||||
|
||||
await checkTaskInBattleEnd(roleId, sid, funcs, battleId, dbHeroes, star);
|
||||
await checkTaskInBattleEnd(serverId, roleId, sid, funcs, battleId, dbHeroes, star);
|
||||
// 返回值:
|
||||
// towerStatus: false-本层未通过, true-本层已通过
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -277,43 +277,43 @@ export class NormalBattleHandler {
|
||||
});
|
||||
}
|
||||
|
||||
async battleSweep(msg: {battleId: number, count: number }, session: BackendSession) {
|
||||
|
||||
async battleSweep(msg: { battleId: number, count: number }, session: BackendSession) {
|
||||
|
||||
const { battleId, count } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
let funcs: number[] = session.get('funcs');
|
||||
let warInfo = gameData.war.get(battleId);
|
||||
if(!warInfo) {
|
||||
if (!warInfo) {
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
// 校验是否三星通关过
|
||||
let { warStar } = await RoleModel.findByRoleId(roleId);
|
||||
let curWar = warStar.find(cur => cur.id == battleId);
|
||||
if(!curWar || curWar.star != 3) {
|
||||
if (!curWar || curWar.star != 3) {
|
||||
return resResult(STATUS.BATTLE_SWEEP_CONDITION_STAR);
|
||||
}
|
||||
|
||||
// 扣体力
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, sid, funcs, -1 * warInfo.cost * count); // 扣除体力
|
||||
if(!apJson) {
|
||||
if (!apJson) {
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 扫荡次数
|
||||
let dailyNum = {};
|
||||
let dungeonNum = {};
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
if (warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, count, true);
|
||||
if(checkResult.status == -1) {
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dailyNum = Object.assign(dailyNum, checkResult.data)
|
||||
} else if(warInfo.warType == WAR_TYPE.MYSTERY|| warInfo.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
} else if (warInfo.warType == WAR_TYPE.MYSTERY || warInfo.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
let checkResult = await checkDungeonAndIncrease(roleId, count, true);
|
||||
if(checkResult.status == -1) {
|
||||
if (checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dungeonNum = Object.assign(dungeonNum, checkResult.data)
|
||||
@@ -328,7 +328,7 @@ export class NormalBattleHandler {
|
||||
// 扫荡记录
|
||||
await BattleSweepRecordModel.saveBattleSweepRecordById(roleId, battleId, {
|
||||
$set: {
|
||||
roleName,
|
||||
roleName,
|
||||
warName: warInfo.gk_name,
|
||||
warType: warInfo.warType
|
||||
},
|
||||
@@ -339,23 +339,23 @@ export class NormalBattleHandler {
|
||||
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_MAIN_SWEEP, battleId, [], count, 0);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleId, count,
|
||||
battleGoods: result,
|
||||
apJson,
|
||||
dailyNum, dungeonNum,
|
||||
...actordata
|
||||
battleId, count,
|
||||
battleGoods: result,
|
||||
apJson,
|
||||
dailyNum, dungeonNum,
|
||||
...actordata
|
||||
});
|
||||
}
|
||||
|
||||
async saveScript(msg: {battleId: number, type: number, script: string }, session: BackendSession) {
|
||||
async saveScript(msg: { battleId: number, type: number, script: string }, session: BackendSession) {
|
||||
|
||||
const { battleId, type, script } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let warInfo = gameData.war.get(battleId);
|
||||
let result = await RScriptRecordModel.setScript(roleId, battleId, warInfo.warType, type, script);
|
||||
if(result) {
|
||||
if(!result.scriptBefore) result.scriptBefore = '';
|
||||
if(!result.scriptAfter) result.scriptAfter = '';
|
||||
if (result) {
|
||||
if (!result.scriptBefore) result.scriptBefore = '';
|
||||
if (!result.scriptAfter) result.scriptAfter = '';
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
} else {
|
||||
console.error('script not created');
|
||||
@@ -364,19 +364,19 @@ export class NormalBattleHandler {
|
||||
|
||||
}
|
||||
|
||||
async getScriptByBattle(msg: {battleIds: Array<number> }, session: BackendSession) {
|
||||
async getScriptByBattle(msg: { battleIds: Array<number> }, session: BackendSession) {
|
||||
|
||||
const { battleIds } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let list = new Array();
|
||||
for(let battleId of battleIds) {
|
||||
for (let battleId of battleIds) {
|
||||
let result = await RScriptRecordModel.findbyRoleAndBattle(roleId, battleId);
|
||||
if(result) {
|
||||
let {scriptBefore = '', scriptAfter = ''} = result;
|
||||
if (result) {
|
||||
let { scriptBefore = '', scriptAfter = '' } = result;
|
||||
|
||||
list.push({battleId, scriptBefore, scriptAfter});
|
||||
list.push({ battleId, scriptBefore, scriptAfter });
|
||||
} else {
|
||||
list.push({battleId, scriptBefore: '', scriptAfter: ''});
|
||||
list.push({ battleId, scriptBefore: '', scriptAfter: '' });
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { list });
|
||||
|
||||
Reference in New Issue
Block a user