Merge branch 'statusCode' of gitlab.trgame.cn:zyztech/zyz_server
Conflicts: game-server/app/servers/battle/handler/eventBattleHandler.ts
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { STATUS } from './../../../consts/statusCode';
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -31,13 +33,7 @@ export class ComBattleHandler {
|
||||
sid: tsid
|
||||
}]);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
users,
|
||||
battleId
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { users, battleId });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,17 +55,11 @@ export class ComBattleHandler {
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
} else {
|
||||
return {
|
||||
code: 202,
|
||||
data: '不能重复加入'
|
||||
};
|
||||
return resResult(STATUS.COM_BATTLE_DUP_ENTER);
|
||||
}
|
||||
channel.pushMessage('onAddBattle', {users});
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: users
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { users });
|
||||
}
|
||||
|
||||
async hurtHp(msg: {battleId: string, bossHurt: number, actorHurt: [{ actorId: number, actorHurt: number}]}, session: BackendSession) {
|
||||
@@ -87,9 +77,6 @@ export class ComBattleHandler {
|
||||
}
|
||||
channel.pushMessage('bossHp', {bossHp: this.bossHp}, undefined);
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: this.bossHp
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { bossHp: this.bossHp});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, checkQuizParam } 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,25 +48,27 @@ 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;
|
||||
|
||||
if(!checkEventStatus(type, status)) {
|
||||
return { code: 202, data: '状态错误' }
|
||||
let flag = checkEventStatus(type, status);
|
||||
if(!flag) {
|
||||
return resResult(STATUS.EVENT_STATUS_ERROR);
|
||||
}
|
||||
if(!checkQuizParam(answer, question)) {
|
||||
return { code: 202, data: '参数错误' }
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let isSuccess = getEventSuccessStatus(type, status, 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);
|
||||
}
|
||||
|
||||
// 保存状态
|
||||
@@ -86,15 +84,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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { STATUS } from './../../../consts/statusCode';
|
||||
import { TOWER_TASK_CONST } from './../../../consts/consts';
|
||||
import { TowerTaskRecModel } from './../../../db/TowerTaskRec';
|
||||
import { HangUpSpdUpRecModel } from './../../../db/HangUpSpdUpRec';
|
||||
@@ -6,7 +7,7 @@ import { RoleModel } from './../../../db/Role';
|
||||
import { TowerRecordModel } from './../../../db/TowerRecord';
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { getTaskById, getTaskIdByQuality, getTowerDataByLv } from '../../../pubUtils/gamedata';
|
||||
import { decodeArrayStr, decodeIdCntArrayStr, getRandEelm } from '../../../pubUtils/util';
|
||||
import { decodeArrayStr, decodeIdCntArrayStr, getRandEelm, resResult } from '../../../pubUtils/util';
|
||||
import { calcuHangUpReward, checkTaskConditions } from '../../../services/battleService';
|
||||
import { handleFixedReward } from '../../../services/rewardService';
|
||||
|
||||
@@ -36,18 +37,15 @@ export class TowerBattleHandler {
|
||||
const sts = decodeArrayStr(warIds).map(id => {
|
||||
return {warId: parseInt(id), status: false};
|
||||
});
|
||||
await TowerRecordModel.createRecord({roleId, lv: towerLv, warStatus: sts});
|
||||
return { code: 201, data: '天梯记录异常' };
|
||||
towerRec = await TowerRecordModel.createRecord({roleId, lv: towerLv, warStatus: sts});
|
||||
// return { code: 201, data: '天梯记录异常' };
|
||||
}
|
||||
const data = {
|
||||
curLv: towerLv,
|
||||
usedHeroes: towerRec.heroes,
|
||||
progress: towerRec.warStatus
|
||||
};
|
||||
return {
|
||||
code: 200,
|
||||
data
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,34 +57,23 @@ export class TowerBattleHandler {
|
||||
let roleId = session.get('roleId');
|
||||
let { towerLv } = await RoleModel.findByRoleId(roleId);
|
||||
if (msg.towerLv !== towerLv) {
|
||||
return {code: 201, data: '只能重置当前层'};
|
||||
return resResult(STATUS.TOWER_RESET_ERR);
|
||||
}
|
||||
const record = await TowerRecordModel.resetRecordByLv(roleId, towerLv);
|
||||
if (!record) {
|
||||
return { code: 201, data: '重置错误'};
|
||||
return resResult(STATUS.TOWER_NOT_FOUND);
|
||||
}
|
||||
return { code: 200, data: { record } };
|
||||
return resResult(STATUS.SUCCESS, record);
|
||||
}
|
||||
|
||||
async checkHangUpRewards(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
const { multi, timeReward } = await calcuHangUpReward(roleId);
|
||||
if (multi == 0) {
|
||||
return {
|
||||
code: 201,
|
||||
data: {
|
||||
msg: '尚未到可收取时间',
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.TOWER_HANG_UP_NOT_VALID);
|
||||
}
|
||||
const rewards = decodeIdCntArrayStr(timeReward, multi);
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
msg: '成功',
|
||||
rewards: Array.from(rewards, item => ({[item[0]]: item[1]}))
|
||||
}
|
||||
};
|
||||
return resResult(STATUS.SUCCESS, {rewards: Array.from(rewards, item => ({[item[0]]: item[1]}))});
|
||||
}
|
||||
|
||||
async recHangUpRewards(msg: {}, session: BackendSession) {
|
||||
@@ -94,64 +81,32 @@ export class TowerBattleHandler {
|
||||
let roleName = session.get('roleName');
|
||||
const { multi, timeReward, endLv, endTime } = await calcuHangUpReward(roleId);
|
||||
if (multi == 0) {
|
||||
return {
|
||||
code: 201,
|
||||
data: {
|
||||
msg: '尚未到可收取时间',
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.TOWER_HANG_UP_NOT_VALID);
|
||||
}
|
||||
const goods = await handleFixedReward(roleId, roleName, timeReward, multi);
|
||||
const newRec = await HangUpRecordModel.updateRec(roleId, roleName, endLv, endTime);
|
||||
return {
|
||||
code : 200,
|
||||
data: {
|
||||
msg: '成功',
|
||||
goods, hangUpRec: newRec
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { goods, hangUpRec: newRec });
|
||||
}
|
||||
|
||||
async hangUpSpeedUp(msg: {speedUpCnt: number}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
if (msg.speedUpCnt <= 0) {
|
||||
return {
|
||||
code: 201,
|
||||
data: {
|
||||
msg: '加速参数错误',
|
||||
}
|
||||
};
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
const curTime = new Date();
|
||||
const { multi, timeReward, endLv } = await calcuHangUpReward(roleId, true, msg.speedUpCnt, curTime);
|
||||
if (multi <= 0) {
|
||||
return {
|
||||
code: 201,
|
||||
data: {
|
||||
msg: '今日加速次数不足'
|
||||
}
|
||||
};
|
||||
resResult(STATUS.TOWER_NOT_ENOUGH_HANG_UP_TIME);
|
||||
}
|
||||
|
||||
const role = await RoleModel.hangUpSpdUp(roleId, multi, curTime);
|
||||
if (!role) {
|
||||
return {
|
||||
code: 201,
|
||||
data: {
|
||||
msg: '不满足加速条件'
|
||||
}
|
||||
};
|
||||
return resResult(STATUS.TOWER_HANG_UP_FAILED);
|
||||
}
|
||||
const spdUpRec = await HangUpSpdUpRecModel.updateRec(roleId, roleName, multi, endLv);
|
||||
const goods = await handleFixedReward(roleId, roleName, timeReward, multi);
|
||||
return {
|
||||
code : 200,
|
||||
data: {
|
||||
msg: '成功',
|
||||
goods, rewardLv: endLv, spdUpRec
|
||||
}
|
||||
};
|
||||
return resResult(STATUS.SUCCESS, { goods, rewardLv: endLv, spdUpRec });
|
||||
}
|
||||
|
||||
async getTasks(msg: {}, session: BackendSession) {
|
||||
@@ -167,20 +122,14 @@ export class TowerBattleHandler {
|
||||
})
|
||||
curTasks = await TowerTaskRecModel.createTasks(roleId, roleName, taskIds);
|
||||
}
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
msg: '成功',
|
||||
curTasks
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { curTasks });
|
||||
}
|
||||
|
||||
async sendTaskHero(msg: {batchCode: string, tasks: Array<{taskCode: string, heroes: Array<number>}>}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
const curTasks = await TowerTaskRecModel.getCurTasks(roleId);
|
||||
if (!curTasks || curTasks.length == 0) {
|
||||
return { code: 201, data: {msg: '没有可用派遣任务'}};
|
||||
return resResult(STATUS.TOWER_TASK_NOT_FOUND);
|
||||
}
|
||||
let usedHeroes = [];
|
||||
const tasksCode = [];
|
||||
@@ -190,7 +139,7 @@ export class TowerBattleHandler {
|
||||
});
|
||||
for (let task of msg.tasks) {
|
||||
if (task.heroes.length > TOWER_TASK_CONST.MAX_HEROES_NUM) {
|
||||
return { code: 201, data: {msg: '一个任务最多派遣三个武将'}};
|
||||
return resResult(STATUS.TOWER_TASK_MAX_HERO);
|
||||
}
|
||||
if (usedHeroes.length > 0) {
|
||||
let used = false;
|
||||
@@ -200,25 +149,19 @@ export class TowerBattleHandler {
|
||||
}
|
||||
})
|
||||
if (used) {
|
||||
return { code: 201, data: {msg: '武将已经派遣到其他任务'}};
|
||||
return resResult(STATUS.TOWER_TASK_HERO_HAS_USED);
|
||||
}
|
||||
}
|
||||
if (tasksCode.indexOf(task.taskCode) === -1) {
|
||||
return { code: 201, data: {msg: '未找到此任务编号'}};
|
||||
return resResult(STATUS.TOWER_TASK_CODE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
const curTime = new Date();
|
||||
const recs = await TowerTaskRecModel.sendHeroes(roleId, msg.batchCode, msg.tasks, curTime);
|
||||
if (!recs || recs.length === 0) {
|
||||
return { code: 201, data: {msg: '任务更新失败,请检查任务编号'}};
|
||||
}
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
msg: '派遣成功',
|
||||
tasks: recs
|
||||
}
|
||||
return resResult(STATUS.TOWER_TASK_SEND_ERR);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { tasks: recs });
|
||||
}
|
||||
|
||||
async settleTask(msg: {batchCode: string, taskCode: string}, session: BackendSession) {
|
||||
@@ -230,13 +173,13 @@ export class TowerBattleHandler {
|
||||
const curTime = new Date();
|
||||
const curTasks = await TowerTaskRecModel.getCurTasks(roleId);
|
||||
if (!curTasks || curTasks.length == 0) {
|
||||
return { code: 201, data: {msg: '没有可用派遣任务'}};
|
||||
return resResult(STATUS.TOWER_TASK_NOT_FOUND);
|
||||
}
|
||||
const compTasks = [];
|
||||
let goods = [];
|
||||
for (let task of curTasks) {
|
||||
if (task.batchCode !== msg.batchCode) {
|
||||
return { code: 201, data: {msg: '派遣编码错误'}};
|
||||
return resResult(STATUS.TOWER_TASK_BATCH_NOT_FOUND);
|
||||
}
|
||||
if ((allFlag || task.taskCode === msg.taskCode) && task.status === 1) {
|
||||
let {completeTime, reward, bonusCondition, bonus} = getTaskById(task.taskId);
|
||||
@@ -253,12 +196,6 @@ export class TowerBattleHandler {
|
||||
}
|
||||
}
|
||||
await TowerTaskRecModel.finishTask(msg.batchCode, compTasks);
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
msg: '成功',
|
||||
compTasks, goods
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { compTasks, goods });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { STATUS } from './../../../consts/statusCode';
|
||||
import { EquipModel } from './../../../db/Equip';
|
||||
import { RoleModel } from './../../../db/Role';
|
||||
import { UserModel } from '../../../db/User';
|
||||
import { Application, Session } from 'pinus';
|
||||
import {FrontendSession} from 'pinus';
|
||||
import { HeroModel } from './../../../db/Hero';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new EntryHandler(app);
|
||||
@@ -19,42 +21,28 @@ export class EntryHandler {
|
||||
* @param {Object} msg request message
|
||||
* @param {Object} session current session object
|
||||
*/
|
||||
async enter(msg: { rid: string, username: string, token: string, serverId: number }, session: FrontendSession) {
|
||||
async enter(msg: { token: string, serverId: number }, session: FrontendSession) {
|
||||
let self = this;
|
||||
let rid = msg.rid;
|
||||
let serverId = msg.serverId;
|
||||
let uid = msg.username + '*' + rid;
|
||||
let sessionService = self.app.get('sessionService');
|
||||
|
||||
let user = await UserModel.findUserByToken(msg.token);
|
||||
if (!user) {
|
||||
console.log('user token not found');
|
||||
return {
|
||||
code: 500,
|
||||
error: true,
|
||||
data: 'user token not found'
|
||||
};
|
||||
return resResult(STATUS.TOKEN_ERR);
|
||||
}
|
||||
|
||||
let role = await RoleModel.findByUid(user.uid, serverId);
|
||||
if (!role) {
|
||||
return {
|
||||
code: 201,
|
||||
error: true,
|
||||
data: '用户还未创建角色',
|
||||
}
|
||||
return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
}
|
||||
// duplicate log in
|
||||
if (!!sessionService.getByUid(role.roleId)) {
|
||||
console.log('uid not found');
|
||||
return {
|
||||
code: 500,
|
||||
error: true
|
||||
};
|
||||
console.log('duplicate log in', role.roleId);
|
||||
return resResult(STATUS.DUP_LOGIN);
|
||||
}
|
||||
|
||||
await session.abind(role.roleId);
|
||||
session.set('rid', rid);
|
||||
session.set('uid', role.roleId);
|
||||
session.set('roleId', role.roleId);
|
||||
session.set('roleName', role.roleName);
|
||||
@@ -64,11 +52,11 @@ export class EntryHandler {
|
||||
session.push('roleId', () => {});
|
||||
session.push('roleName', () => {});
|
||||
session.push('eventStatus', () => {});
|
||||
session.push('rid', function (err) {
|
||||
if (err) {
|
||||
console.error('set rid for session service failed! error is : %j', err.stack);
|
||||
}
|
||||
});
|
||||
// session.push('rid', function (err) {
|
||||
// if (err) {
|
||||
// console.error('set rid for session service failed! error is : %j', err.stack);
|
||||
// }
|
||||
// });
|
||||
session.on('closed', this.onUserLeave.bind(this));
|
||||
|
||||
let channelService = self.app.get('channelService');
|
||||
@@ -79,16 +67,12 @@ export class EntryHandler {
|
||||
|
||||
// put user into channel
|
||||
await self.app.rpc.battle.eventBattleRemote.add.route(session)(role.roleId, self.app.get('serverId'), true);
|
||||
let users = await self.app.rpc.chat.chatRemote.add.route(session)(role.roleId, self.app.get('serverId'), rid, true);
|
||||
// let users = await self.app.rpc.chat.chatRemote.add.route(session)(role.roleId, self.app.get('serverId'), rid, true);
|
||||
let heros = await HeroModel.findByRole(role.roleId);
|
||||
let equips = await EquipModel.findbyRole(role.roleId);
|
||||
role['heros'] = heros;
|
||||
role['equips'] = equips;
|
||||
return {
|
||||
status: 200,
|
||||
users: users,
|
||||
role
|
||||
};
|
||||
return resResult(STATUS.SUCCESS, { role });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { STATUS } from './../../../consts/statusCode';
|
||||
import { dispatch } from '../../../util/dispatcher';
|
||||
import { Application , BackendSession} from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GateHandler(app);
|
||||
@@ -16,26 +18,18 @@ export class GateHandler {
|
||||
* @param {Object} session
|
||||
*
|
||||
*/
|
||||
async queryEntry(msg: {uid: string}, session: BackendSession) {
|
||||
let uid = msg.uid;
|
||||
if (!uid) {
|
||||
return {
|
||||
code: 500
|
||||
};
|
||||
async queryEntry(msg: {userCode: string}, session: BackendSession) {
|
||||
let { userCode } = msg;
|
||||
if (!userCode) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
// get all connectors
|
||||
let connectors = this.app.getServersByType('connector');
|
||||
if (!connectors || connectors.length === 0) {
|
||||
return {
|
||||
code: 500
|
||||
};
|
||||
return resResult(STATUS.CONNECTOR_ERR);
|
||||
}
|
||||
// select connector
|
||||
let res = dispatch(uid, connectors);
|
||||
return {
|
||||
code: 200,
|
||||
host: res.clientHost,
|
||||
port: res.clientPort
|
||||
};
|
||||
let res = dispatch(userCode, connectors);
|
||||
return resResult(STATUS.SUCCESS, {host: res.clientHost, port: res.clientPort});
|
||||
}
|
||||
}
|
||||
@@ -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};
|
||||
|
||||
@@ -10,7 +10,7 @@ export function chat(session: Session, msg: any, app: Application, cb: (err: Err
|
||||
return;
|
||||
}
|
||||
|
||||
let res = dispatch(session.get('rid'), chatServers);
|
||||
let res = dispatch(session.get('roleId'), chatServers);
|
||||
cb(null, res.id);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ export function battle(session: Session, msg: any, app: Application, cb: (err: E
|
||||
return;
|
||||
}
|
||||
|
||||
let res = dispatch(session.get('rid'), battleServers);
|
||||
let res = dispatch(session.get('roleId'), battleServers);
|
||||
cb(null, res.id);
|
||||
}
|
||||
@@ -4,20 +4,63 @@ export const STATUS = {
|
||||
WRONG_PARMS: { code: 1, simStr: '参数错误' },
|
||||
TOKEN_ERR: { code: 2, simStr: 'token失效' },
|
||||
INTERNAL_ERR: { code: 3, simStr: '内部错误' },
|
||||
CONNECTOR_ERR: { code: 4, simStr: '连接服配置错误'},
|
||||
// 账号相关状态 10000 - 19999
|
||||
SMS_IN_60S: { code: 10001, simStr: '60秒内只能发送一次' },
|
||||
SMS_CNT_LIMIT: { code: 10002, simStr: '今日短信条数已达上限' },
|
||||
SMS_INVALID: { code: 10003, simStr: '验证码无效' },
|
||||
SERVER_NOT_FOUND: { code: 10004, simStr: '未找到服务器列表' },
|
||||
ROLE_NOT_FOUND: { code: 10005, simStr: '未找到角色' },
|
||||
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: '天梯关卡不能重复挑战' },
|
||||
TOWER_NOT_FOUND: { code: 20506, simStr: '没有找到合适的天梯记录' },
|
||||
TOWER_HANG_UP_NOT_VALID: { code: 20507, simStr: '尚未到可收取时间' },
|
||||
TOWER_NOT_ENOUGH_HANG_UP_TIME: { code: 20508, simStr: '今日加速次数不足' },
|
||||
TOWER_HANG_UP_FAILED: { code: 20509, simStr: '不满足加速条件' },
|
||||
TOWER_TASK_NOT_FOUND: { code: 20510, simStr: '没有可用派遣任务' },
|
||||
TOWER_TASK_MAX_HERO: { code: 20511, simStr: '超过派遣武将最大人数' },
|
||||
TOWER_TASK_HERO_HAS_USED: { code: 20512, simStr: '武将已经派遣到其他任务' },
|
||||
TOWER_TASK_CODE_NOT_FOUND: { code: 20513, simStr: '未找到此任务编号' },
|
||||
TOWER_TASK_SEND_ERR: { code: 20514, simStr: '任务派遣失败,请检查任务编号' },
|
||||
TOWER_TASK_BATCH_NOT_FOUND: { code: 20515, simStr: '派遣编码错误' },
|
||||
// 共斗 20600 - 20699
|
||||
COM_BATTLE_DUP_ENTER: { code: 20601, simStr: '不能重复加入' },
|
||||
// 养成相关状态 30000 - 39999
|
||||
// 社交相关状态 40000 - 49999
|
||||
// 运营模块相关状态 50000 - 59999
|
||||
|
||||
@@ -3,6 +3,9 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
|
||||
class ServerInfo {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
|
||||
@prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@@ -55,7 +58,7 @@ export default class Game extends BaseModel {
|
||||
public static async getServerListByType(serverType: string) {
|
||||
let game = await GameModel.findOne().lean();
|
||||
if (!game) {
|
||||
const serverInfo: ServerInfo = { name: '常山少年', host: 'pinus_test.trgame.cn', port: 3014, status: 1, createTime: new Date(), serverType: 'official' };
|
||||
const serverInfo: ServerInfo = { id: 1, name: '常山少年', host: 'pinus_test.trgame.cn', port: 3014, status: 1, createTime: new Date(), serverType: 'official' };
|
||||
const iconUrl = `https://download.tgamebox.cn/avatar/${APP_ID}/1.png`;
|
||||
game = await GameModel.findOneAndUpdate(
|
||||
{},
|
||||
|
||||
@@ -48,14 +48,15 @@ export default class Sms extends BaseModel {
|
||||
}
|
||||
|
||||
public async cntLimit(cnt: number) {
|
||||
console.log('hasSendToday:', this.hasSendToday());
|
||||
if (await this.hasSendToday() && this.countToday >= cnt) {
|
||||
console.log('hasSendToday:', this.hasSendToday(), this.countToday, cnt);
|
||||
if (this.hasSendToday() && this.countToday >= cnt) {
|
||||
return true;
|
||||
}
|
||||
this.countToday = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public async hasSendToday() {
|
||||
public hasSendToday() {
|
||||
console.log(moment(this.updateTime).format('YYYY-MM-DD'), moment(Date.now()).format('YYYY-MM-DD'));
|
||||
return moment(this.updateTime).format('YYYY-MM-DD') === moment(Date.now()).format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { COUNTER } from './../consts/consts';
|
||||
import { CounterModel } from './Counter';
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
|
||||
/**
|
||||
* 用户字段接口
|
||||
@@ -16,6 +17,9 @@ export default class User extends BaseModel {
|
||||
@prop({ required: true })
|
||||
username: string;
|
||||
|
||||
@prop({ required: true })
|
||||
userCode: string; // 用户唯一字符串标识
|
||||
|
||||
@prop({ required: true })
|
||||
token: string;
|
||||
|
||||
@@ -65,8 +69,9 @@ export default class User extends BaseModel {
|
||||
let update = {};
|
||||
if (!user) {
|
||||
const uid = await CounterModel.getNewCounter(COUNTER.UID);
|
||||
const userCode = genCode(8);
|
||||
const doc = new UserModel();
|
||||
update = Object.assign(update, { platform, pkgName, serverType, createTime: curTime, uid, username: `用户${uid}` }, doc.toJSON());
|
||||
update = Object.assign(update, { platform, pkgName, serverType, createTime: curTime, uid, userCode, username: `用户${uid}` }, doc.toJSON());
|
||||
}
|
||||
update = Object.assign(update, { token, lastLoginTime: curTime });
|
||||
user = await UserModel.findOneAndUpdate({ tel }, update, { upsert: true, new: true }).lean(lean);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -184,5 +184,8 @@ export function getRandEelm(source: Array<any> = [], cnt = 1): Array<any> {
|
||||
|
||||
export function resResult(status: {code: number, simStr: string}, data = null, customMsg = '') {
|
||||
const { code, simStr } = status;
|
||||
if (code !== STATUS.SUCCESS.code) {
|
||||
console.log(`normal err, code: ${code}, des: ${customMsg || simStr}`);
|
||||
}
|
||||
return {code, msg: customMsg || simStr, data};
|
||||
}
|
||||
@@ -99,7 +99,7 @@ export default class Auth extends Service {
|
||||
// 用户注册登录
|
||||
const token = ctx.service.utils.generateStr(256);
|
||||
const user = await UserModel.updateToken(tel, token, platform, pkgName, serverType);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { token, uid: user?.uid });
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { token, userCode: user?.userCode });
|
||||
}
|
||||
|
||||
public async checkRole(serverId: number) {
|
||||
|
||||
Reference in New Issue
Block a user