93 lines
3.6 KiB
TypeScript
93 lines
3.6 KiB
TypeScript
// 节日活动 - 重阳集会
|
||
import { ActivityModelType } from '../../db/Activity';
|
||
import { ActivityChongYangRecModelType, ChongYangBuyRecord, ChongYangGameRecord } from '../../db/ActivityChongYangRec';
|
||
import { ActivityBase } from './activityField';
|
||
|
||
// 后台格式
|
||
interface ChongYangSceneDataInDb {
|
||
dayIndex: number; // 第几天(层)
|
||
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; // 累计到现在可以游戏的最大次数
|
||
isPushBuyRecord?: boolean; //
|
||
|
||
}
|
||
|
||
|
||
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 } = obj;
|
||
|
||
let maxFreeCnt = dailyFreeCnt;
|
||
this.sceneMap.set(dayIndex, { ...obj, buyCnt: 0, playCnt: 0, maxPlayCnt: maxFreeCnt, isPushBuyRecord: true });
|
||
}
|
||
}
|
||
|
||
public setPlayerRecords(playerData: ActivityChongYangRecModelType) {
|
||
this.updatePlayerRecord(playerData);
|
||
}
|
||
|
||
public updatePlayerRecord(playerData: ActivityChongYangRecModelType) {
|
||
if (!playerData) return;
|
||
let dayIndexUnlockAndSuccess = 0;
|
||
if (playerData.gameRecords) {
|
||
this.gameRecords = playerData.gameRecords;
|
||
for (const { isSuccess, dayIndex } of playerData.gameRecords) {
|
||
if (isSuccess) {
|
||
dayIndexUnlockAndSuccess = Math.max(dayIndexUnlockAndSuccess, dayIndex);
|
||
|
||
let scene = this.sceneMap.get(dayIndex);
|
||
scene.playCnt += 1;
|
||
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;
|
||
}
|
||
|
||
}
|
||
|
||
public getShowResult() {
|
||
return {
|
||
...this.getBaseKeys(),
|
||
scenes: [...this.sceneMap.values()],
|
||
dayIndexUnlock: this.dayIndexUnlock,
|
||
}
|
||
}
|
||
} |