🐞 fix(活动): 小游戏次数表现

This commit is contained in:
luying
2023-03-27 14:33:44 +08:00
parent a7a51907d1
commit 9513848141
2 changed files with 21 additions and 3 deletions

View File

@@ -86,7 +86,7 @@ export class ForgeHandler {
let playerRecord = await ActivityMiniGameModel.incScore(serverId, activityId, playerData.roundIndex, roleId, score, playerData.nextRefreshTime);
if(!record) return resResult(STATUS.ACTIVITY_MINI_GAME_RECORD_NOT_FOUND);
playerData.setPlayerData(playerRecord);
playerData.incPlayerCnt();
playerData.incPlayCnt();
let rewards = stringToRewardParam(playerData.reward, playerData.nextRefreshTime);
let { goods } = await addReward(roleId, roleName, sid, serverId, rewards, ITEM_CHANGE_REASON.ACT_MINI_GAME_REWARD);

View File

@@ -51,8 +51,10 @@ export class MiniGameData extends ActivityBase {
freeCnt: number = 0; // 今天的免费次数
maxBuyCnt: number = 0; // 今天可以购买的次数
box: MiniGameBox[] = []; // 宝箱
buyCounts: MiniGameBuyCountInDb[];
playCnt: number = 0; // 已玩次数,当 playCnt < freeCnt + buyCnt 时可以玩
todayPlayCnt: number = 0; // 今日已挑战次数
buyCnt: number = 0; // 已购买次数
score: number = 0; // 当前总分
@@ -69,6 +71,7 @@ export class MiniGameData extends ActivityBase {
this.consume = dataObj.consume;
this.reward = dataObj.reward;
this.buyCounts = dataObj.buyCounts;
for(let { day, buyCnt, freeCnt } of (dataObj.buyCounts||[])) {
if(day == this.todayIndex) this.freeCnt = freeCnt;
if(day <= this.todayIndex) this.maxBuyCnt += buyCnt;
@@ -89,11 +92,26 @@ export class MiniGameData extends ActivityBase {
}
public setPlayerRecords(records: ActivityMiniGameRecModelType[]) {
this.playCnt = records.length;
let recByDay = new Map<number, ActivityMiniGameRecModelType[]>(); // day => recs
for(let record of records) {
if(record.todayIndex == this.todayIndex) {
this.todayPlayCnt ++;
this.playCnt++; // playCnt 当天玩的部分
}
if(!recByDay.has(record.todayIndex)) recByDay.set(record.todayIndex, []);
recByDay.get(record.todayIndex).push(record);
}
for(let { day, freeCnt } of this.buyCounts) {
if(this.todayIndex > day) {
let curRecords = recByDay.get(day)||[];
if(curRecords.length > freeCnt) this.playCnt += curRecords.length - freeCnt;// playCnt 前几天不免费的部分
}
}
}
public incPlayerCnt() {
public incPlayCnt() {
this.playCnt++;
this.todayPlayCnt++;
}
public findBox(boxId: number) {