主线,每日,奇遇,远征修改错误码
This commit is contained in:
@@ -3,6 +3,8 @@ import { DailyRecordModel } from '../../../db/DailyRecord';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { getGamedata } from '../../../pubUtils/gamedata';
|
||||
import { WAR_TYPE } from '../../../consts/consts';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new DailyBattleHandler(app);
|
||||
@@ -57,7 +59,7 @@ export class DailyBattleHandler {
|
||||
});
|
||||
}
|
||||
|
||||
return { code: 200, data: result }
|
||||
return resResult(STATUS.SUCCESS, { list: result });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import { RoleModel } from '../../../db/Role';
|
||||
import { EVENT_STATUS, EVENT_RECORD_STATUS } from '../../../consts/consts';
|
||||
import { checkEvent, getEventTime, refreshEvent, checkEventStatus, getEventSuccessStatus } from '../../../services/eventSercive';
|
||||
import { handleFixedReward } from '../../../services/rewardService';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new EventBattleHandler(app);
|
||||
@@ -22,7 +24,6 @@ export class EventBattleHandler {
|
||||
|
||||
let now = new Date();
|
||||
let t = getEventTime(now);
|
||||
console.log(t, eventStatus)
|
||||
|
||||
let event: Array<EventRecord>;
|
||||
if (eventStatus == EVENT_STATUS.STARTING) {
|
||||
@@ -35,12 +36,7 @@ export class EventBattleHandler {
|
||||
event = await refreshEvent(num, roleId, roleName, t);
|
||||
}
|
||||
}
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
event
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { list: event });
|
||||
}
|
||||
|
||||
// 获取关卡列表
|
||||
@@ -52,22 +48,24 @@ export class EventBattleHandler {
|
||||
|
||||
let event = await EventRecordModel.getEventRecordByCode(roleId, eventCode);
|
||||
if(!event) {
|
||||
return { code: 202, data: '未找到记录' }
|
||||
return resResult(STATUS.EVENT_RECORD_NOT_FOUND);
|
||||
}
|
||||
let { status, type, eventId: dataEventId, question } = event;
|
||||
|
||||
let flag = checkEventStatus(type, status);
|
||||
if(!flag) {
|
||||
return { code: 202, data: '状态错误' }
|
||||
return resResult(STATUS.EVENT_STATUS_ERROR);
|
||||
}
|
||||
let isSuccess = getEventSuccessStatus(type, status, {id:question?question.id:0, answer});
|
||||
|
||||
|
||||
if(dataEventId != eventId) {
|
||||
return { code: 202, data: '事件id错误' }
|
||||
return resResult(STATUS.EVENT_WRONG_ID);
|
||||
}
|
||||
let dicEvent = getGamedata('dic_zyz_event');
|
||||
let curEvent = dicEvent.find(cur => cur.eventID == eventId);
|
||||
if(!curEvent) {
|
||||
return { code: 202, data: '未找到该事件' };
|
||||
return resResult(STATUS.EVENT_INFO_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 保存状态
|
||||
@@ -83,15 +81,12 @@ export class EventBattleHandler {
|
||||
}
|
||||
// 推送消息刷新
|
||||
await checkEvent(this.app, session, true);
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
isSuccess,
|
||||
eventCode: result.eventCode,
|
||||
eventId: result.eventId,
|
||||
status: result.status,
|
||||
goods
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import { EXPEDITION_INCREASE_POINT } from '../../../consts/consts';
|
||||
import { WarReward } from '../../../services/warRewardService';
|
||||
import { handleFixedReward } from '../../../services/rewardService';
|
||||
import { getAp, setAp } from '../../../services/actionPointService';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ExpeditionBattleHandler(app);
|
||||
@@ -50,16 +52,13 @@ export class ExpeditionBattleHandler {
|
||||
// 点数,和宝箱领取状态
|
||||
let pointRewards = await getPointRewardStatus(roleId);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
pointRewards,
|
||||
heroes
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +93,7 @@ export class ExpeditionBattleHandler {
|
||||
flag = await matchRobots(scale, myCe, curDicExpedition.ce, curDicExpedition.json, lv, enemyObj);
|
||||
}
|
||||
if(!flag) {
|
||||
return {code: 202, data:'无法匹配对手'};
|
||||
return resResult(STATUS.EXPEDITION_MATCH_NO_PLAYER);
|
||||
}
|
||||
// 保存
|
||||
let {warId} = curDicExpedition;
|
||||
@@ -104,15 +103,12 @@ export class ExpeditionBattleHandler {
|
||||
}
|
||||
|
||||
let { battleId, enemyFrom, enemies, battleStatus } = expeditionWarRecord;
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
expeditionCode, expeditionId, battleId,
|
||||
battleStatus,
|
||||
enemyFrom,
|
||||
enemies
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId, battleId,
|
||||
battleStatus,
|
||||
enemyFrom,
|
||||
enemies
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,28 +121,28 @@ export class ExpeditionBattleHandler {
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
|
||||
let apJson = await getAp(Date.now(), roleId);
|
||||
let {ap} = apJson;
|
||||
if(ap < warInfo.cost) {
|
||||
return { code: 202, data: "体力不足" }
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 前置关卡是否挑战过
|
||||
let previousGk = warInfo.previousGk;
|
||||
if(previousGk) {
|
||||
let preBattle = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, previousGk, 1);
|
||||
if(!preBattle) return {code: 202, data: '需要完成上一关才可以挑战'};
|
||||
if(!preBattle) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
}
|
||||
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionWarRecord ) {
|
||||
return {code: 202, data: '需要先匹配好对手'}
|
||||
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
|
||||
}
|
||||
if(expeditionWarRecord.battleStatus == 1) {
|
||||
return {code: 202, data: '已挑战过这一关'}
|
||||
return resResult(STATUS.EXPEDITION_DUPLICATE_CHALLENGE);
|
||||
}
|
||||
|
||||
const battleCode = genCode(8);
|
||||
@@ -162,17 +158,14 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
let result = await ExpeditionWarRecordModel.updateStatus(expeditionCode, expeditionId, 0, battleCode);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
expeditionId,
|
||||
battleId,
|
||||
battleCode,
|
||||
battleStatus: result.battleStatus,
|
||||
apJson
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +180,7 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
warInfo['cost'] = 0;
|
||||
@@ -195,7 +188,7 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
const BattleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode);
|
||||
if(!BattleRecord || BattleRecord.status != 0) {
|
||||
return { code: 202, data: '关卡状态错误' }
|
||||
return resResult(STATUS.BATTLE_STATUS_WRONG);
|
||||
}
|
||||
|
||||
let flag = 1; // 对比hero信息
|
||||
@@ -204,20 +197,20 @@ export class ExpeditionBattleHandler {
|
||||
if(dbHeroes.indexOf(actorId) == -1) flag = 0;
|
||||
}
|
||||
if(!flag) {
|
||||
return { code: 202, data: '关卡信息不同' }
|
||||
return resResult(STATUS.BATTLE_INFO_VALIDATE_ERR);
|
||||
}
|
||||
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, -1 * warInfo.cost); // 扣除体力
|
||||
if(!apJson) {
|
||||
return { code: 202, data: '体力不足' }
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 检查record
|
||||
let expeditionRecord = await ExpeditionRecordModel.getExpeditionRecordByCode(expeditionCode);
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionRecord|| !expeditionWarRecord) {
|
||||
return { code: 202, data:'未找到该记录' }
|
||||
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
|
||||
}
|
||||
// 更新我方剩余血量
|
||||
await ExpeditionRecordModel.updateHeroStatus(expeditionCode, expeditionRecord.heroes, heroes);
|
||||
@@ -235,17 +228,14 @@ export class ExpeditionBattleHandler {
|
||||
let warReward = new WarReward(roleId, roleName, battleId, isSuccess);
|
||||
let reward = await warReward.saveReward(1);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId,
|
||||
battleCode, battleId,
|
||||
battleStatus: expeditionWarRecord.battleStatus,
|
||||
goods: reward,
|
||||
apJson,
|
||||
expeditionPoint
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,19 +250,19 @@ export class ExpeditionBattleHandler {
|
||||
// 检查expeditionWarRecord的battleStatus
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if(!expeditionWarRecord) {
|
||||
return {code: 202, data: '未找到该关卡'}
|
||||
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
|
||||
}
|
||||
if(expeditionWarRecord.battleStatus != 1) {
|
||||
return {code: 202, data: '需要战斗胜利后才可以领取'}
|
||||
return resResult(STATUS.EXPEDITION_WRONG_STATUS_WHEN_RECEIVE);
|
||||
}
|
||||
if(expeditionWarRecord.received) {
|
||||
return {code: 202, data: '已经领取过了'}
|
||||
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 {code: 202, data: '未找到该配置'}
|
||||
return resResult(STATUS.EXPEDITION_MISS_INFO);
|
||||
}
|
||||
|
||||
let result = await ExpeditionWarRecordModel.updateBoxStatus(expeditionCode, expeditionId, true, curDicExpedition.reward);
|
||||
@@ -280,14 +270,11 @@ export class ExpeditionBattleHandler {
|
||||
// 获取东西
|
||||
let goods = await handleFixedReward(roleId, roleName, curDicExpedition.reward, 1);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode, expeditionId,
|
||||
battleId, battleCode, battleStatus, received,
|
||||
goods
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -306,18 +293,18 @@ export class ExpeditionBattleHandler {
|
||||
let dicExpeditionPoint = getGamedata('dic_expedition_point');
|
||||
let curDicExpeditionPoint = dicExpeditionPoint.find(cur => cur.point == point);
|
||||
if(!curDicExpeditionPoint) {
|
||||
return {code: 202, data: '该点数不能领取奖励'}
|
||||
return resResult(STATUS.EXPEDITION_MISS_POINT_INFO);
|
||||
}
|
||||
|
||||
if(point > expeditionPoint) {
|
||||
return {code: 202, data: '点数不足'};
|
||||
return resResult(STATUS.EXPEDITION_POINT_NOT_ENOUGH);
|
||||
}
|
||||
let pointStatusInDatabase = await ExpeditionPointModel.getExpeditionPoint(roleId);
|
||||
if(pointStatusInDatabase) {
|
||||
let {rewards} = pointStatusInDatabase;
|
||||
let curReward = rewards.find(cur => cur.point == point);
|
||||
if(curReward && curReward.received) {
|
||||
return {code: 202, data: '已领取过'}
|
||||
return resResult(STATUS.EXPEDITION_WRONG_RECEIVE_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,13 +313,10 @@ export class ExpeditionBattleHandler {
|
||||
let pointRewards = await getPointRewardStatus(roleId);
|
||||
let goods = await handleFixedReward(roleId, roleName, curDicExpeditionPoint.reward, 1);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
pointRewards,
|
||||
goods
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
pointRewards,
|
||||
goods
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,7 +330,7 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
let pointStatusInDatabase = await ExpeditionPointModel.getExpeditionPoint(roleId);
|
||||
if(!pointStatusInDatabase) {
|
||||
return {code: 202, data: '已刷新'}
|
||||
return resResult(STATUS.EXPEDITION_POINT_RECORD_NOT_FOUND);
|
||||
}
|
||||
let { rewards } = pointStatusInDatabase;
|
||||
let dicExpeditionPoint = getGamedata('dic_expedition_point');
|
||||
@@ -359,7 +343,7 @@ export class ExpeditionBattleHandler {
|
||||
if(dic.point > maxPoint) maxPoint = dic.point;
|
||||
}
|
||||
if(!flag) {
|
||||
return {code: 202, data: '宝箱需要领取完才可以刷新'}
|
||||
return resResult(STATUS.EXPEDITION_POINT_NEED_ALL_RECEIVED);
|
||||
}
|
||||
|
||||
// 刷新
|
||||
@@ -368,11 +352,8 @@ export class ExpeditionBattleHandler {
|
||||
|
||||
let pointRewards = await getPointRewardStatus(roleId);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
pointRewards
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
pointRewards
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import { checkTowerWar, towerBattleEnd } from '../../../services/battleService';
|
||||
import { WarReward } from '../../../services/warRewardService';
|
||||
import { getAp, setAp } from '../../../services/actionPointService';
|
||||
import { setBattleStatus, startEvent } from '../../../services/eventSercive';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new NormalBattleHandler(app);
|
||||
@@ -25,7 +27,7 @@ export class NormalBattleHandler {
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
warInfo['cost'] = 0;
|
||||
@@ -34,14 +36,14 @@ export class NormalBattleHandler {
|
||||
let apJson = await getAp(Date.now(), roleId);
|
||||
let {ap} = apJson;
|
||||
if(ap < warInfo.cost) {
|
||||
return { code: 202, data: "体力不足" }
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 前置关卡是否挑战过
|
||||
let previousGk = warInfo.previousGk;
|
||||
if(previousGk) {
|
||||
let preBattle = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, previousGk, 1);
|
||||
if(!preBattle) return {code: 202, data: '需要完成上一关才可以挑战'};
|
||||
if(!preBattle) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
}
|
||||
|
||||
let dailyNum = {};
|
||||
@@ -49,13 +51,13 @@ export class NormalBattleHandler {
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDaily(roleId, battleId, 1);
|
||||
if(checkResult.status == -1) {
|
||||
return {code: 202, data: checkResult.msg}
|
||||
return checkResult.resResult
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
} else if (warInfo.warType == WAR_TYPE.TOWER) {
|
||||
let checkResult = await checkTowerWar(roleId, battleId, heroes);
|
||||
if(checkResult.status) {
|
||||
return {code: 202, data: checkResult.msg}
|
||||
return checkResult.resResult
|
||||
}
|
||||
towerData = Object.assign(towerData, checkResult.data);
|
||||
}
|
||||
@@ -73,12 +75,9 @@ export class NormalBattleHandler {
|
||||
let {status} = BattleRecord;
|
||||
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
battleId, battleCode, status, apJson, dailyNum, towerData
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleId, battleCode, status, apJson, dailyNum, towerData
|
||||
});
|
||||
}
|
||||
|
||||
// 关卡列表
|
||||
@@ -95,7 +94,9 @@ export class NormalBattleHandler {
|
||||
}
|
||||
}
|
||||
|
||||
return { code: 200, data: result }
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
list: result
|
||||
});
|
||||
}
|
||||
|
||||
// 关卡结算,记录使用的武将,获得奖励
|
||||
@@ -107,7 +108,7 @@ export class NormalBattleHandler {
|
||||
let sid = session.get('sid');
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
warInfo['cost'] = 0;
|
||||
@@ -115,7 +116,7 @@ export class NormalBattleHandler {
|
||||
|
||||
const BattleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode, true);
|
||||
if(!BattleRecord || BattleRecord.status != 0) {
|
||||
return { code: 202, data: '关卡状态错误' }
|
||||
return resResult(STATUS.BATTLE_STATUS_WRONG);
|
||||
}
|
||||
|
||||
let flag = 1; // 对比hero信息
|
||||
@@ -124,13 +125,13 @@ export class NormalBattleHandler {
|
||||
if(dbHeroes.indexOf(hid) == -1) flag = 0;
|
||||
}
|
||||
if(!flag) {
|
||||
return { code: 202, data: '关卡信息不同' }
|
||||
return resResult(STATUS.BATTLE_INFO_VALIDATE_ERR);
|
||||
}
|
||||
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, -1 * warInfo.cost); // 扣除体力
|
||||
if(!apJson) {
|
||||
return { code: 202, data: '体力不足' }
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
let channelService = this.app.get('channelService');
|
||||
@@ -143,7 +144,7 @@ export class NormalBattleHandler {
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, 1, false);
|
||||
if(checkResult.status == -1) {
|
||||
return {code: 202, data: checkResult.msg}
|
||||
return checkResult.resResult;
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
} else if (warInfo.warType == WAR_TYPE.EVENT) {
|
||||
@@ -152,7 +153,7 @@ export class NormalBattleHandler {
|
||||
} else if (warInfo.warType == WAR_TYPE.TOWER) {
|
||||
let towerEndResult = await towerBattleEnd(channelService, sid, roleId, battleCode, battleId, isSuccess, heroes);
|
||||
if(towerEndResult.status == -1) {
|
||||
return {code: 202, data: towerEndResult.msg};
|
||||
return towerEndResult.resResult;
|
||||
}
|
||||
towerRec = towerEndResult.data.newRec;
|
||||
towerBonus = towerEndResult.data.bonusReward;
|
||||
@@ -189,15 +190,12 @@ export class NormalBattleHandler {
|
||||
// 返回值:
|
||||
// towerStatus: false-本层未通过, true-本层已通过
|
||||
// towerBonus: 天梯每隔几层的额外宝箱
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
battleCode, battleId, status, towerStatus,
|
||||
goods: reward, towerBonus, towerReward,
|
||||
apJson,
|
||||
dailyNum
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleCode, battleId, status, towerStatus,
|
||||
goods: reward, towerBonus, towerReward,
|
||||
apJson,
|
||||
dailyNum
|
||||
});
|
||||
}
|
||||
|
||||
async battleSweep(msg: {battleId: number, count: number }, session: BackendSession) {
|
||||
@@ -207,12 +205,12 @@ export class NormalBattleHandler {
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
// 校验是否三星通关过
|
||||
let condition1 = await BattleRecordModel.getBattleRecordByIdAndStar(roleId, battleId, 3);
|
||||
if(!condition1) {
|
||||
return { code: 202, data: "需要3星通过关卡才可以扫荡" }
|
||||
return resResult(STATUS.BATTLE_SWEEP_CONDITION_STAR);
|
||||
}
|
||||
|
||||
// 扣体力
|
||||
@@ -222,7 +220,7 @@ export class NormalBattleHandler {
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, -1 * warInfo.cost * count); // 扣除体力
|
||||
if(!apJson) {
|
||||
return { code: 202, data: '体力不足' }
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
|
||||
// 扫荡次数
|
||||
@@ -230,7 +228,7 @@ export class NormalBattleHandler {
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, count, true);
|
||||
if(checkResult.status == -1) {
|
||||
return {code: 202, data: checkResult.msg}
|
||||
return checkResult.resResult
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
}
|
||||
@@ -249,15 +247,12 @@ export class NormalBattleHandler {
|
||||
$inc: { count }
|
||||
});
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleId, count,
|
||||
goods: result,
|
||||
apJson,
|
||||
dailyNum
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import { RoleModel } from './../db/Role';
|
||||
import { getHeroInfoById, getJobInfoById, getTowerDataByLv } from "../pubUtils/gamedata"
|
||||
import { decodeArrayStr, shouldRefresh } from '../pubUtils/util';
|
||||
import { handleFixedReward } from './rewardService';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
|
||||
const battleIdStr = `${battleId}`;
|
||||
@@ -15,22 +17,22 @@ export async function checkTowerWar(roleId: string, battleId: number, heroes: Ar
|
||||
const towerInfo = getTowerDataByLv(towerLv);
|
||||
if (!towerInfo) {
|
||||
console.error(`天梯层数异常,lv ${towerLv} by ${roleId}`);
|
||||
return { status: -1, msg: '天梯层数异常' };
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_INFO_NOT_FOUND) };
|
||||
}
|
||||
const warIds = decodeArrayStr(towerInfo.warIds) || [];
|
||||
if (warIds.indexOf(battleIdStr) === -1) {
|
||||
return { status: -1, msg: '战斗 Id 异常' };
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_WRONG_BATTLE_ID) };
|
||||
}
|
||||
|
||||
let { heroes: recHeroes = [], warStatus = [] } = await TowerRecordModel.getRecordByLv(roleId, towerLv);
|
||||
for (let hid of heroes) {
|
||||
if (recHeroes.indexOf(hid) !== -1) {
|
||||
return { status: -1, msg: '使用了重复的武将' };
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_DUPLICATE_HERO) };
|
||||
}
|
||||
}
|
||||
const curWarStatus = warStatus.find(elem => elem.warId == battleId);
|
||||
if (curWarStatus.status) {
|
||||
return {status: -1, msg: '天梯关卡不能重复挑战'};
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_DUPLICATE_CHALLENGE) };
|
||||
}
|
||||
|
||||
return { status: 0, data: {
|
||||
@@ -42,13 +44,13 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
|
||||
if (succeed) {
|
||||
let battleRec = await BattleRecordModel.getBattleRecordByCode(battleCode);
|
||||
if (battleRec.battleId != battleId) {
|
||||
return { status: -1, msg: '战斗数据错误' };
|
||||
return { status: -1, resResult: resResult(STATUS.BATTLE_ID_NOT_MATCH) };
|
||||
}
|
||||
let { towerLv, roleName } = await RoleModel.findByRoleId(roleId);
|
||||
let { warStatus, heroes: recHeroes } = await TowerRecordModel.getRecordByLv(roleId, towerLv);
|
||||
for (let hid of heroes) {
|
||||
if (recHeroes.indexOf(hid) !== -1) {
|
||||
return { status: -1, msg: '使用了重复的武将' };
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_DUPLICATE_CHALLENGE) };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,21 +4,23 @@
|
||||
|
||||
import { DailyRecordModel } from '../db/DailyRecord';
|
||||
import { getGamedata } from '../pubUtils/gamedata';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
// 检查每日本次数checkBattle使用
|
||||
export async function checkDaily(roleId: string, battleId: number, inc: number) {
|
||||
let dicDaily = getGamedata('dic_zyz_daily');
|
||||
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
|
||||
let dailyWar = dicDailyWar.find(cur => cur.war_id == battleId);
|
||||
if(!dailyWar) return { status: -1, msg: '未找到该关卡' };
|
||||
if(!dailyWar) return { status: -1, resResult: resResult(STATUS.DAILY_WAR_NOT_FOUND) };
|
||||
let type = dailyWar.dailyType;
|
||||
|
||||
let curDaily = dicDaily.find(cur => cur.dailyType == type);
|
||||
if(!curDaily) return { status: -1, msg: '未找到该类型' };
|
||||
if(!curDaily) return { status: -1, resResult: resResult(STATUS.DAILY_TYPE_NOT_FOUND) };
|
||||
let dailyRecord = await DailyRecordModel.refreshRecord(roleId, type);
|
||||
let { count } = dailyRecord;
|
||||
if(count + inc > curDaily.sum ) {
|
||||
return { status: -1, msg: '次数不足' }
|
||||
return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) }
|
||||
}
|
||||
return {status: 1, type, count, sum: curDaily.sum};
|
||||
}
|
||||
@@ -28,11 +30,11 @@ export async function checkDailyAndIncrease(roleId: string, battleId: number, in
|
||||
let dicDaily = getGamedata('dic_zyz_daily');
|
||||
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
|
||||
let dailyWar = dicDailyWar.find(cur => cur.war_id == battleId);
|
||||
if(!dailyWar) return { status: -1, msg: '未找到该关卡' };
|
||||
if(!dailyWar) return { status: -1, resResult: resResult(STATUS.DAILY_WAR_NOT_FOUND) };
|
||||
let type = dailyWar.dailyType;
|
||||
|
||||
let curDaily = dicDaily.find(cur => cur.dailyType == type);
|
||||
if(!curDaily) return { status: -1, msg: '未找到该类型' };
|
||||
if(!curDaily) return { status: -1, resResult: resResult(STATUS.DAILY_TYPE_NOT_FOUND) };
|
||||
|
||||
let dailyRecord: any;
|
||||
if(isRef) {
|
||||
@@ -42,7 +44,7 @@ export async function checkDailyAndIncrease(roleId: string, battleId: number, in
|
||||
}
|
||||
let { count } = dailyRecord;
|
||||
if(count + inc > curDaily.sum ) {
|
||||
return { status: -1, msg: '次数不足' }
|
||||
return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) }
|
||||
}
|
||||
let result = await DailyRecordModel.increseDailyCount(roleId, type, inc);
|
||||
return {status: 1, type, count: result.count, sum: curDaily.sum};
|
||||
|
||||
@@ -14,12 +14,42 @@ export const STATUS = {
|
||||
DUP_LOGIN: { code: 10006, simStr: '重复登录' },
|
||||
// 战斗相关状态 20000 - 29999
|
||||
// 战斗通用 20000 - 20099
|
||||
BATTLE_MISS_INFO: { code: 20001, simStr: '缺少关卡信息' },
|
||||
BATTLE_ACTION_POINT_LACK: { code: 20002, simStr: '体力不足' },
|
||||
BATTLE_NEED_PREVIOUS_GK: { code: 20003, simStr: '需要完成上一关才可以挑战' },
|
||||
BATTLE_ID_NOT_MATCH: { code: 20004, simStr: '战斗数据错误' },
|
||||
BATTLE_STATUS_WRONG: { code: 20005, simStr: '关卡状态错误' },
|
||||
|
||||
// 主线 20100 - 20199
|
||||
BATTLE_INFO_VALIDATE_ERR: { code: 20101, simStr: '关卡信息不同' },
|
||||
BATTLE_SWEEP_CONDITION_STAR: { code: 20102, simStr: '需要3星通过关卡才可以扫荡' },
|
||||
// 每日 20200 - 20299
|
||||
DAILY_WAR_NOT_FOUND: { code: 20201, simStr: '未找到该关卡' },
|
||||
DAILY_TYPE_NOT_FOUND: { code: 20202, simStr: '未找到该类型' },
|
||||
DAILY_TIMES_LACK: { code: 20203, simStr: '次数不足' },
|
||||
// 奇遇 20300 - 20399
|
||||
EVENT_RECORD_NOT_FOUND: { code: 20301, simStr: '未找到记录' },
|
||||
EVENT_STATUS_ERROR: { code: 20302, simStr: '状态错误' },
|
||||
EVENT_WRONG_ID: { code: 20303, simStr: '事件id错误' },
|
||||
EVENT_INFO_NOT_FOUND: { code: 20304, simStr: '未找到该事件' },
|
||||
// 远征 20400 - 20499
|
||||
EXPEDITION_MATCH_NO_PLAYER: { code: 20401, simStr: '无法匹配对手' },
|
||||
EXPEDITION_MISS_WAR_RECORD: { code: 20402, simStr: '未找到该远征记录' },
|
||||
EXPEDITION_DUPLICATE_CHALLENGE: { code: 20403, simStr: '已挑战过这一关' },
|
||||
EXPEDITION_WRONG_STATUS_WHEN_RECEIVE: { code: 20404, simStr: '需要战斗胜利后才可以领取' },
|
||||
EXPEDITION_WRONG_RECEIVE_STATUS: { code: 20405, simStr: '已经领取过了' },
|
||||
EXPEDITION_MISS_INFO: { code: 20406, simStr: '未找到该配置' },
|
||||
EXPEDITION_MISS_POINT_INFO: { code: 20407, simStr: '该点数不能领取奖励' },
|
||||
EXPEDITION_POINT_NOT_ENOUGH: { code: 20408, simStr: '点数不足' },
|
||||
EXPEDITION_POINT_RECORD_NOT_FOUND: { code: 20409, simStr: '点数宝箱已刷新' },
|
||||
EXPEDITION_POINT_NEED_ALL_RECEIVED: { code: 20410, simStr: '宝箱需要领取完才可以刷新' },
|
||||
// 天梯 20500 - 20599
|
||||
TOWER_RESET_ERR: { code: 20501, simStr: '只能重置当前层' }
|
||||
TOWER_RESET_ERR: { code: 20501, simStr: '只能重置当前层' },
|
||||
TOWER_INFO_NOT_FOUND: { code: 20502, simStr: '天梯层数异常' },
|
||||
TOWER_WRONG_BATTLE_ID: { code: 20503, simStr: '战斗 Id 异常' },
|
||||
TOWER_DUPLICATE_HERO: { code: 20504, simStr: '使用了重复的武将' },
|
||||
TOWER_DUPLICATE_CHALLENGE: { code: 20505, simStr: '天梯关卡不能重复挑战' },
|
||||
|
||||
// 养成相关状态 30000 - 39999
|
||||
// 社交相关状态 40000 - 49999
|
||||
// 运营模块相关状态 50000 - 59999
|
||||
|
||||
@@ -33,37 +33,37 @@ const moment = require('moment');
|
||||
switch (type) {
|
||||
case 'fixReward': {
|
||||
let [gid, count] = arr;
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('格式错误');
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('data table format wrong');
|
||||
result = { gid: parseInt(gid), count: parseInt(count)};
|
||||
break;
|
||||
}
|
||||
case 'conditionReward': {
|
||||
let [gid, count, condition] = arr;
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('格式错误');
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('data table format wrong');
|
||||
result = { gid: parseInt(gid), count: parseInt(count), condition: parseInt(condition) };
|
||||
break;
|
||||
}
|
||||
case 'randomReward': {
|
||||
let [gid, count, frequency] = arr;
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('格式错误');
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('data table format wrong');
|
||||
result = { gid: parseInt(gid), count: parseInt(count), frequency: parseInt(frequency) };
|
||||
break;
|
||||
}
|
||||
case 'eventSuitLevel': {
|
||||
let [min, max] = arr;
|
||||
if(isNaN(min) || isNaN(max)) throw new Error('格式错误');
|
||||
if(isNaN(min) || isNaN(max)) throw new Error('data table format wrong');
|
||||
result = { min: parseInt(min), max: parseInt(max) };
|
||||
break;
|
||||
}
|
||||
case 'attribute': {
|
||||
let [id, value] = arr;
|
||||
if(isNaN(id) || isNaN(value)) throw new Error('格式错误');
|
||||
if(isNaN(id) || isNaN(value)) throw new Error('data table format wrong');
|
||||
result = { id: parseInt(id), value: parseInt(value) };
|
||||
break;
|
||||
}
|
||||
case 'position': {
|
||||
let [x, y] = arr;
|
||||
if(isNaN(x) || isNaN(y)) throw new Error('格式错误');
|
||||
if(isNaN(x) || isNaN(y)) throw new Error('data table format wrong');
|
||||
result = { x: parseInt(x), y: parseInt(y) };
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user