feat(活动): 鹊桥活动添加接口

This commit is contained in:
luying
2023-07-21 14:12:55 +08:00
parent 8d9322fed4
commit d57e38dc6c
4 changed files with 48 additions and 3 deletions

View File

@@ -112,6 +112,44 @@ export class EntertainHandler {
});
}
/**
* @description 扫荡
* @param {{ activityId: number }} msg
* @param {BackendSession} session
* @memberof EntertainHandler
*/
async gameSweep(msg: { activityId: number }, session: BackendSession) {
const { activityId } = msg;
const roleId: string = session.get('roleId');
const roleName: string = session.get('roleName');
const serverId: number = session.get('serverId');
const sid: string = session.get('sid');
let playerData = await getPlayerQixiData(activityId, serverId, roleId);
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
// 挑战次数
if(playerData.playCnt >= playerData.freeCnt + playerData.buyCnt) return resResult(STATUS.ACTIVITY_QIXI_NO_NUM);
if(playerData.todayPlayCnt <= 0) return resResult(STATUS.ACTIVITY_QIXI_CANNOT_SWEEP);
let playerRecord = await ActivityQixiRecModel.record(serverId, activityId, playerData.roundIndex, roleId, {
todayIndex: playerData.recordTodayIndex, gameCode: '', time: new Date(), rewards: playerData.rewards, progress: 0, afterProgress: playerData.maxProgress, hasPass: true, isSkip: true
});
if(!playerRecord) return resResult(STATUS.ACTIVITY_QIXI_GAMECODE_NOT_FOUND);
playerData.updatePlayerRecord(playerRecord);
let rewards = stringToRewardParam(playerData.rewards);
let goods = await addItems(roleId, roleName, sid, rewards, ITEM_CHANGE_REASON.QIXI_REWARD)
return resResult(STATUS.SUCCESS, {
activityId,
todayPlayCnt: playerData.todayPlayCnt,
playCnt: playerData.playCnt,
freeCnt: playerData.freeCnt,
progress: playerData.progress,
goods
});
}
/**
* @description 购买次数
* @param {{ activityId: number, id: number, count: number}} msg

View File

@@ -703,6 +703,7 @@ export const STATUS = {
ACTIVITY_QIXI_GAMECODE_HAS_PLAY: { code: 50079, simStr: '该挑战已结算过' },
ACTIVITY_QIXI_BUY_COUNT_OVER: { code: 50080, simStr: '购买挑战次数不足' },
ACTIVITY_QIXI_CANNOT_BUY: { code: 50081, simStr: '不可在免费次数未用完的时候购买次数' },
ACTIVITY_QIXI_CANNOT_SWEEP: { code: 50082, simStr: '必须在当天手动玩一次后才可以碾压' },
// GM后台相关状态 60000 - 69999

View File

@@ -19,7 +19,9 @@ export class QixiRecord {
@prop({ required: true })
rewards: string; // 奖励
@prop({ required: true })
hasPass: boolean; // 奖励
hasPass: boolean; // 是否通过
@prop({ required: true })
isSkip?: boolean; // 是否跳过
}
@index({ roleId: 1, activityId: 1 })

View File

@@ -11,6 +11,7 @@ interface QixiDataInDb {
freeCnt: number; // 每天可以免费划船的次数
maxProgress: number; // 最大进度
rewards: string; // 奖励
countdown: number;
}
export class QixiData extends ActivityBase {
@@ -19,6 +20,7 @@ export class QixiData extends ActivityBase {
freeCntDaily: number; // 每天可以免费的次数
maxProgress: number; // 最大进度
rewards: string; // 奖励
countdown: number; // 倒计时
freeCnt: number = 0; // 累积到现在可以免费的次数
maxBuyCnt: number = 0; // 累积到现在可以购买的次数
@@ -39,6 +41,7 @@ export class QixiData extends ActivityBase {
let dataObj: QixiDataInDb = JSON.parse(data);
if (!dataObj) return;
this.countdown = dataObj.countdown;
this.buyCost = dataObj.buyCost || '&';
this.dailyBuyCnt = dataObj.dailyBuyCnt || 0;
this.freeCntDaily = dataObj.freeCnt || 0;
@@ -63,10 +66,10 @@ export class QixiData extends ActivityBase {
if(playerData.record) {
playerData.record.sort((a, b) => a.time.getTime() - b.time.getTime());
for(let data of playerData.record) {
let { todayIndex, afterProgress, progress, hasPass } = data;
let { todayIndex, afterProgress, progress, hasPass, isSkip } = data;
if(todayIndex == this.todayIndex && hasPass) this.todayPlayCnt ++;
if(hasPass) this.playCnt ++;
this.progress = afterProgress||progress;
if(!isSkip) this.progress = afterProgress||progress;
this.records.push(data);
}
if(this.todayPlayCnt >= this.freeCntDaily && this.playCnt < this.freeCnt) {
@@ -93,6 +96,7 @@ export class QixiData extends ActivityBase {
maxProgress: this.maxProgress,
progress: this.progress,
rewards: this.rewards,
countdown: this.countdown,
}
}
}