战场:悔棋
This commit is contained in:
@@ -25,6 +25,8 @@ import { getSelfServiceShopActivityData } from '../../../services/activity/selfS
|
|||||||
import { challengeDailyGK } from '../../../services/activity/dailyGKService';
|
import { challengeDailyGK } from '../../../services/activity/dailyGKService';
|
||||||
import { challengeNewHeroGK } from '../../../services/activity/newHeroGKService';
|
import { challengeNewHeroGK } from '../../../services/activity/newHeroGKService';
|
||||||
import { reportTAEvent } from '../../../services/sdkService';
|
import { reportTAEvent } from '../../../services/sdkService';
|
||||||
|
import { getVipRegretCnt } from '../../../services/activity/monthlyTicketService';
|
||||||
|
import { isNumber } from 'underscore';
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
new HandlerService(app, {});
|
new HandlerService(app, {});
|
||||||
@@ -381,4 +383,43 @@ export class NormalBattleHandler {
|
|||||||
}
|
}
|
||||||
return resResult(STATUS.SUCCESS, { list });
|
return resResult(STATUS.SUCCESS, { list });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取悔棋次数
|
||||||
|
async getRegretCnt(msg: { warId: number, battleCode: string }, session: BackendSession) {
|
||||||
|
|
||||||
|
const { warId, battleCode } = msg;
|
||||||
|
let roleId: string = session.get('roleId');
|
||||||
|
let vipStartTime: number = session.get('vipStartTime');
|
||||||
|
|
||||||
|
let battleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode);
|
||||||
|
if(!battleRecord || battleRecord.roleId != roleId || battleRecord.battleId != warId) {
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
}
|
||||||
|
let maxRegretCnt = getVipRegretCnt(vipStartTime);
|
||||||
|
return resResult(STATUS.SUCCESS, { regretCnt: battleRecord.regretCnt||0, maxRegretCnt });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录悔棋次数
|
||||||
|
async incRegretCnt(msg: { warId: number, battleCode: string, count: number }, session: BackendSession) {
|
||||||
|
|
||||||
|
const { warId, battleCode, count } = msg;
|
||||||
|
let roleId: string = session.get('roleId');
|
||||||
|
let vipStartTime: number = session.get('vipStartTime');
|
||||||
|
if(!isNumber(count) || count <= 0) {
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
}
|
||||||
|
|
||||||
|
let battleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode);
|
||||||
|
if(!battleRecord || battleRecord.roleId != roleId || battleRecord.battleId != warId) {
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
}
|
||||||
|
let maxRegretCnt = getVipRegretCnt(vipStartTime);
|
||||||
|
let regretCnt = battleRecord.regretCnt||0;
|
||||||
|
if(regretCnt + count > maxRegretCnt) {
|
||||||
|
return resResult(STATUS.BATTLE_REGRET_MAX);
|
||||||
|
}
|
||||||
|
battleRecord = await BattleRecordModel.incRegretCnt(battleCode, count);
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, { regretCnt: battleRecord.regretCnt||0, maxRegretCnt });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,4 +202,12 @@ export function getVipDungeonCnt(vipStartTime: number) {
|
|||||||
count += VIP.VIP_DUNGEON_CONST_FREE_ADD;
|
count += VIP.VIP_DUNGEON_CONST_FREE_ADD;
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getVipRegretCnt(vipStartTime: number) {
|
||||||
|
let count = VIP.VIP_REGRET_CNT_WITHOUT_VIP;
|
||||||
|
if(vipStartTime > 0) {
|
||||||
|
count = VIP.VIP_REGRET_CNT_WITH_VIP;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,7 @@ export const STATUS = {
|
|||||||
BATTLE_CONSUMES_NOT_ENOUGH: { code: 20007, simStr: '道具不足' },
|
BATTLE_CONSUMES_NOT_ENOUGH: { code: 20007, simStr: '道具不足' },
|
||||||
BATTLE_END_WRONG_TYPE: { code: 20008, simStr: '此类型无法使用通用结算' },
|
BATTLE_END_WRONG_TYPE: { code: 20008, simStr: '此类型无法使用通用结算' },
|
||||||
BATTLE_GOLD_NOT_ENOUGH: { code: 20009, simStr: '元宝不足' },
|
BATTLE_GOLD_NOT_ENOUGH: { code: 20009, simStr: '元宝不足' },
|
||||||
|
BATTLE_REGRET_MAX: { code: 20010, simStr: '悔棋步数达上限' },
|
||||||
|
|
||||||
// 主线 20100 - 20199
|
// 主线 20100 - 20199
|
||||||
BATTLE_INFO_VALIDATE_ERR: { code: 20101, simStr: '关卡信息不同' },
|
BATTLE_INFO_VALIDATE_ERR: { code: 20101, simStr: '关卡信息不同' },
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ export default class BattleRecord extends BaseModel {
|
|||||||
@prop({ required: true, _id: false })
|
@prop({ required: true, _id: false })
|
||||||
record: Record; // 使用的武将等记录
|
record: Record; // 使用的武将等记录
|
||||||
|
|
||||||
|
@prop({ required: true, default: 0 })
|
||||||
|
regretCnt: number; // 悔棋次数
|
||||||
|
|
||||||
public static async getBattleRecordByCode(battleCode: string, lean = true) {
|
public static async getBattleRecordByCode(battleCode: string, lean = true) {
|
||||||
const result: BattleRecordType = await BattleRecordModel.findOne({ battleCode }).lean(lean);
|
const result: BattleRecordType = await BattleRecordModel.findOne({ battleCode }).lean(lean);
|
||||||
@@ -97,6 +98,11 @@ export default class BattleRecord extends BaseModel {
|
|||||||
let result: BattleRecordType = await BattleRecordModel.findOneAndUpdate({ battleCode }, { $inc: { 'record.bossDamage': damage } }, { new: true }).lean();
|
let result: BattleRecordType = await BattleRecordModel.findOneAndUpdate({ battleCode }, { $inc: { 'record.bossDamage': damage } }, { new: true }).lean();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async incRegretCnt(battleCode: string, count: number) {
|
||||||
|
let result: BattleRecordType = await BattleRecordModel.findOneAndUpdate({ battleCode }, { $inc: { regretCnt: count } }, { new: true }).lean();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BattleRecordModel = getModelForClass(BattleRecord);
|
export const BattleRecordModel = getModelForClass(BattleRecord);
|
||||||
|
|||||||
Reference in New Issue
Block a user