feat(重阳集会): 更新

This commit is contained in:
zhangxk
2023-09-12 20:14:41 +08:00
parent 742d48267a
commit ed8912e440
3 changed files with 24 additions and 13 deletions

View File

@@ -102,7 +102,6 @@ export class ChongYangHandler {
const sid = session.get('sid');
const serverId = session.get('serverId');
console.log('---------xxxxxxxxxxxxxx------------------buyCnt')
let playerData = await getPlayerChongYangData(activityId, serverId, roleId);
if (!playerData || !playerData.sceneMap) return resResult(STATUS.ACTIVITY_MISSING);
let scene = playerData.sceneMap.get(dayIndex);
@@ -114,7 +113,7 @@ export class ChongYangHandler {
if (dayIndex > playerData.dayIndexUnlock) return resResult(STATUS.ACTIVITY_CHONGYANG_LOCK);
// 保存数据
let playerRecord = await ActivityChongYangRecModel.buyCnt(serverId, activityId, playerData.roundIndex, roleId, dayIndex, count);
let playerRecord = await ActivityChongYangRecModel.buyCnt(serverId, activityId, playerData.roundIndex, roleId, { dayIndex, buyCnt: count }, scene.isPushBuyRecord);
if (!playerRecord) return resResult(STATUS.ACTIVITY_CHONGYANG_GAMECODE_NOT_FOUND);
playerData = await getPlayerChongYangData(activityId, serverId, roleId);

View File

@@ -53,13 +53,18 @@ export default class Activity_ChongYang_Rec extends BaseModel {
return result;
}
public static async gameRecord(serverId: number, activityId: number, roundIndex: number, roleId: string, gameRecords: ChongYangGameRecord) {
let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { gameRecords }, $setOnInsert: { buyCnt: 0 } }, { new: true, upsert: true }).lean();
public static async gameRecord(serverId: number, activityId: number, roundIndex: number, roleId: string, gameRecord: ChongYangGameRecord) {
let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { gameRecords: gameRecord } }, { new: true, upsert: true }).lean();
return result;
}
public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, dayIndex: number, count: number) {
let result: ActivityChongYangRecModelType = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'buyRecords.dayIndex': dayIndex }, { $inc: { 'buyRecords.$.buyCnt': count }, $setOnInsert: { gameRecord: [] } }, { new: true, upsert: true }).lean();
public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, buyRecord: ChongYangBuyRecord, isPushBuyRecord: boolean) {
let result: ActivityChongYangRecModelType;
if (isPushBuyRecord) {
result = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { buyRecords: buyRecord } }, { new: true, upsert: true }).lean();
} else {
result = await ActivityChongYangRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'buyRecords.dayIndex': buyRecord.dayIndex }, { $inc: { 'buyRecords.$.buyCnt': buyRecord.buyCnt } }, { new: true, upsert: true }).lean();
}
return result;
}

View File

@@ -21,6 +21,7 @@ interface ChongYangDataReturn extends ChongYangSceneDataInDb {
buyCnt: number; // 累积到现在已经购买了的次数buyCnt < maxBuyCnt 的时候才能购买
playCnt: number; // 累计到现在游戏的次数
maxPlayCnt: number; // 累计到现在可以游戏的最大次数
isPushBuyRecord?: boolean; //
}
@@ -43,7 +44,7 @@ export class ChongYangData extends ActivityBase {
const { dayIndex, dailyFreeCnt, dailyBuyCnt } = obj;
let maxFreeCnt = dailyFreeCnt;
this.sceneMap.set(dayIndex, { ...obj, buyCnt: 0, playCnt: 0, maxPlayCnt: maxFreeCnt });
this.sceneMap.set(dayIndex, { ...obj, buyCnt: 0, playCnt: 0, maxPlayCnt: maxFreeCnt, isPushBuyRecord: true });
}
}
@@ -54,23 +55,29 @@ export class ChongYangData extends ActivityBase {
public updatePlayerRecord(playerData: ActivityChongYangRecModelType) {
if (!playerData) return;
let dayIndexUnlockAndSuccess = 1;
let buyRecordMap = new Map<number, ChongYangBuyRecord>()
if (playerData.buyRecords) buyRecordMap = playerData.buyRecords.reduce((map, cur) => { map.set(cur.dayIndex, { ...cur }); return map; }, new Map<number, ChongYangBuyRecord>());
if (playerData.gameRecords) {
this.gameRecords = playerData.gameRecords;
for (let data of playerData.gameRecords) {
let { isSuccess, dayIndex } = data;
for (const { isSuccess, dayIndex } of playerData.gameRecords) {
if (isSuccess) {
dayIndexUnlockAndSuccess = Math.max(dayIndexUnlockAndSuccess, dayIndex);
let scene = this.sceneMap.get(dayIndex);
scene.buyCnt = buyRecordMap.get(dayIndex)?.buyCnt || 0;
scene.playCnt += 1;
scene.maxPlayCnt = scene.buyCnt + scene.dailyFreeCnt;
this.sceneMap.set(dayIndex, scene);
};
this.dayIndexUnlock = Math.max(this.dayIndexUnlock, dayIndex);
}
}
if (playerData.buyRecords) {
for (const { dayIndex, buyCnt = 0 } of playerData.buyRecords) {
let scene = this.sceneMap.get(dayIndex);
scene.isPushBuyRecord = false;
scene.buyCnt = buyCnt;
scene.maxPlayCnt = scene.buyCnt + scene.dailyFreeCnt;
this.sceneMap.set(dayIndex, scene);
}
}
if (this.todayIndex > this.dayIndexUnlock && this.dayIndexUnlock == dayIndexUnlockAndSuccess) {
this.dayIndexUnlock += 1;