feat(重阳集会): 添加纯净召唤接口

This commit is contained in:
zhangxk
2023-09-13 10:42:17 +08:00
parent a0e169d8b3
commit 9f99203d06
5 changed files with 59 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ import { ActivityChongYangRecModel } from '../../../db/ActivityChongYangRec';
import { RewardInter } from '../../../pubUtils/interface';
import { stringToRewardParam } from '../../../services/activity/giftPackageService';
import { addItems } from '../../../services/role/rewardService';
import { getZeroPoint } from '../../../pubUtils/timeUtil';
export default function (app: Application) {
@@ -46,7 +47,7 @@ export class ChongYangHandler {
const gameCode = genCode(10);
await ActivityChongYangRecModel.gameRecord(serverId, activityId, playerData.roundIndex, roleId, {
todayIndex: playerData.todayIndex, gameCode, time: new Date(), rewards: '', isSuccess: false, dayIndex,
todayIndex: playerData.todayIndex, gameCode, time: new Date(), rewards: '', isSuccess: false, dayIndex, isSkip: false
});
return resResult(STATUS.SUCCESS, { activityId, gameCode });
@@ -71,20 +72,16 @@ export class ChongYangHandler {
let curRecord = playerData.gameRecords.find(cur => cur.gameCode == gameCode);
if (!curRecord) return resResult(STATUS.ACTIVITY_CHONGYANG_GAMECODE_NOT_FOUND);
if (curRecord.isSuccess) return resResult(STATUS.ACTIVITY_CHONGYANG_GAMECODE_NOT_FOUND);
if (curRecord.isSuccess) return resResult(STATUS.ACTIVITY_CHONGYANG_GAMECODE_USE);
let rewards: string = '';
let isReward = playerData.gameRecords.find(cur => cur.dayIndex == dayIndex && cur.isSuccess);
if (isReward == undefined) rewards = scene.rewards;
let playerRecord = await ActivityChongYangRecModel.gameEnd(serverId, activityId, playerData.roundIndex, roleId, gameCode, isSuccess, new Date(), rewards);
let playerRecord = await ActivityChongYangRecModel.gameEnd(serverId, activityId, playerData.roundIndex, roleId, gameCode, isSuccess, new Date(), scene.rewards);
if (!playerRecord) return resResult(STATUS.ACTIVITY_CHONGYANG_GAMECODE_NOT_FOUND);
playerData = await getPlayerChongYangData(activityId, serverId, roleId);
scene = playerData.sceneMap.get(dayIndex);
let goods: RewardInter[] = [];
if (isSuccess) {
goods = await addItems(roleId, roleName, sid, stringToRewardParam(rewards), ITEM_CHANGE_REASON.CHONGYANG_REWARD)
goods = await addItems(roleId, roleName, sid, stringToRewardParam(scene.rewards), ITEM_CHANGE_REASON.CHONGYANG_REWARD)
}
return resResult(STATUS.SUCCESS, {
@@ -108,7 +105,7 @@ export class ChongYangHandler {
if (!scene) return resResult(STATUS.ACTIVITY_MISSING);
// 检测购买次数
if (scene.buyCnt >= scene.dailyBuyCnt || scene.buyCnt + count > scene.dailyBuyCnt) return resResult(STATUS.ACTIVITY_CHONGYANG_BUY_COUNT_OVER);
if (scene.buyCnt + count > scene.dailyBuyCnt) return resResult(STATUS.ACTIVITY_CHONGYANG_BUY_COUNT_OVER);
// 检测解锁
if (dayIndex > playerData.dayIndexUnlock) return resResult(STATUS.ACTIVITY_CHONGYANG_LOCK);
@@ -121,4 +118,45 @@ export class ChongYangHandler {
return resResult(STATUS.SUCCESS, { activityId, dailyBuyCnt: scene.dailyBuyCnt, buyCnt: scene.buyCnt, });
}
async gameSweep(msg: { activityId: number, dayIndex: number, count: number }, session: BackendSession) {
const { activityId, dayIndex, count } = 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 getPlayerChongYangData(activityId, serverId, roleId);
if (!playerData || !playerData.sceneMap) return resResult(STATUS.ACTIVITY_MISSING);
let scene = playerData.sceneMap.get(dayIndex);
if (!scene) return resResult(STATUS.ACTIVITY_MISSING);
// 检测挑战次数
if (scene.playCnt + count > scene.maxPlayCnt) return resResult(STATUS.ACTIVITY_CHONGYANG_NO_NUM);
// 检测解锁
if (dayIndex > playerData.dayIndexUnlock) return resResult(STATUS.ACTIVITY_CHONGYANG_LOCK);
// 检测通关
let isHasPass = playerData.gameRecords.find(cur => cur.dayIndex == dayIndex && cur.isSuccess && !cur.isSkip && (getZeroPoint()*1000 <= cur.time.getTime()));
if (!isHasPass) return resResult(STATUS.ACTIVITY_CHONGYANG_GAMESWEEP_LOCK);
let rewards: RewardInter[] = [];
for (let i = 0; i < count; i++) {
await ActivityChongYangRecModel.gameRecord(serverId, activityId, playerData.roundIndex, roleId, {
todayIndex: playerData.todayIndex, gameCode: 'sweep', time: new Date(), rewards: scene.rewards, isSuccess: true, dayIndex, isSkip: true
});
rewards.push(...stringToRewardParam(scene.rewards));
}
let goods = await addItems(roleId, roleName, sid, rewards, ITEM_CHANGE_REASON.CHONGYANG_REWARD)
playerData = await getPlayerChongYangData(activityId, serverId, roleId);
scene = playerData.sceneMap.get(dayIndex);
return resResult(STATUS.SUCCESS, {
activityId,
playCnt: scene.playCnt,
maxPlayCnt: scene.maxPlayCnt,
goods
});
}
}