88 lines
3.7 KiB
TypeScript
88 lines
3.7 KiB
TypeScript
// 节日活动 - 重阳集会
|
|
import { ActivityModelType } from '../../db/Activity';
|
|
import { ActivityChongYangRecModelType, ChongYangBuyRecord, ChongYangGameRecord } from '../../db/ActivityChongYangRec';
|
|
import { ActivityBase } from './activityField';
|
|
|
|
// 后台格式
|
|
interface ChongYangSceneDataInDb {
|
|
dayIndex: number; // 第几天(层)
|
|
sceneId: number; // 场景id
|
|
img: string; // 场景图片
|
|
buyCost: string; // 购买一次次数的消耗,type&id&count
|
|
dailyBuyCnt: number; // 每天可以购买的次数
|
|
dailyFreeCnt: number; // 每天可以免费的次数
|
|
rewards: string; // 每局的奖励 type&id&count
|
|
}
|
|
|
|
interface ChongYangDataReturn extends ChongYangSceneDataInDb {
|
|
// maxFreeCnt: number; // 累计到现在可以免费的次数
|
|
// freeCnt: number; // 累计到现在已经使用免费的次数
|
|
// maxBuyCnt: number; // 累积到现在可以购买的次数
|
|
buyCnt: number; // 累积到现在已经购买了的次数,buyCnt < maxBuyCnt 的时候才能购买
|
|
playCnt: number; // 累计到现在游戏的次数
|
|
maxPlayCnt: number; // 累计到现在可以游戏的最大次数
|
|
|
|
}
|
|
|
|
|
|
export class ChongYangData extends ActivityBase {
|
|
sceneMap = new Map<number, ChongYangDataReturn>();
|
|
gameRecords: ChongYangGameRecord[] = [];
|
|
buyRecords: ChongYangBuyRecord[] = [];
|
|
dayIndexUnlock: number = 1; //当前开启到了第几天
|
|
|
|
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
|
super(activityData, createTime, serverTime)
|
|
this.initData(activityData.data)
|
|
}
|
|
|
|
public initData(data: string): void {
|
|
let chongyangData: ChongYangSceneDataInDb[] = JSON.parse(data);
|
|
if (!chongyangData || chongyangData.length == 0) return;
|
|
for (const obj of chongyangData) {
|
|
const { dayIndex, dailyFreeCnt, dailyBuyCnt } = obj;
|
|
|
|
let maxFreeCnt = dailyFreeCnt;
|
|
this.sceneMap.set(dayIndex, { ...obj, buyCnt: 0, playCnt: 0, maxPlayCnt: maxFreeCnt });
|
|
}
|
|
}
|
|
|
|
public setPlayerRecords(playerData: ActivityChongYangRecModelType) {
|
|
this.updatePlayerRecord(playerData);
|
|
}
|
|
|
|
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;
|
|
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 (this.todayIndex > this.dayIndexUnlock && this.dayIndexUnlock == dayIndexUnlockAndSuccess) {
|
|
this.dayIndexUnlock += 1;
|
|
}
|
|
|
|
}
|
|
|
|
public getShowResult() {
|
|
return {
|
|
...this.getBaseKeys(),
|
|
scenes: [...this.sceneMap.values()],
|
|
dayIndexUnlock: this.dayIndexUnlock,
|
|
}
|
|
}
|
|
} |