96 lines
4.0 KiB
TypeScript
96 lines
4.0 KiB
TypeScript
// 节日活动 - 重阳集会
|
||
import { ActivityModelType } from '../../db/Activity';
|
||
import { ActivityNovemberRecModelType, NovemberRecord, } from '../../db/ActivityNovemberRec';
|
||
import { ActivityBase } from './activityField';
|
||
|
||
// 后台格式
|
||
interface NovemberDataInDb {
|
||
menuIds: number[]; // 菜谱id
|
||
buyCost: string; // 购买一次次数的消耗,type&id&count
|
||
dailyBuyCnt: number; // 每天可以购买的次数
|
||
dailyFreeCnt: number; // 每天可以免费的次数
|
||
successRewards: string;// 每局的成功奖励 type&id&count
|
||
failRewards: string; // 每局的失败安慰奖励 type&id&count
|
||
};
|
||
|
||
|
||
// interface NovemberDataReturn {
|
||
// buyCost: string; // 购买一次次数的消耗,type&id&count
|
||
// maxBuyCnt: number; // 累积到现在可以购买的次数
|
||
// buyCnt: number; // 累积到现在已经购买了的次数,buyCnt < maxBuyCnt 的时候才能购买
|
||
// freeCnt: number; // 累计到现在可以免费玩的次数
|
||
// todayPlayCnt: number; // 今天的次数,todayPlayCnt>0时才可以扫荡
|
||
// playCnt: number; // 总共的次数,playCnt < freeCnt + buyCnt的时候才能玩新的
|
||
|
||
// menuIds: number[]; // 菜谱id
|
||
// successRewards: string;// 每局的成功奖励 type&id&count
|
||
// failRewards: string; // 每局的失败安慰奖励 type&id&count
|
||
// }
|
||
|
||
|
||
export class NovemberData extends ActivityBase {
|
||
buyCost: string; // 购买一次次数的消耗,type&id&count
|
||
maxBuyCnt: number = 0; // 累积到现在可以购买的次数
|
||
buyCnt: number = 0; // 累积到现在已经购买了的次数,buyCnt < maxBuyCnt 的时候才能购买
|
||
freeCnt: number = 0; // 累计到现在可以免费玩的次数
|
||
todayPlayCnt: number = 0; // 今天的次数,todayPlayCnt>0时才可以扫荡
|
||
playCnt: number = 0; // 总共的次数,playCnt < freeCnt + buyCnt的时候才能玩新的
|
||
|
||
menuIds: number[] = []; // 菜谱id
|
||
successRewards: string;// 每局的成功奖励 type&id&count
|
||
failRewards: string; // 每局的失败安慰奖励 type&id&count
|
||
|
||
records: NovemberRecord[] = [];
|
||
|
||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||
super(activityData, createTime, serverTime)
|
||
this.initData(activityData.data)
|
||
}
|
||
|
||
public initData(data: string): void {
|
||
let novemberData: NovemberDataInDb = JSON.parse(data);
|
||
if (!novemberData) return;
|
||
|
||
this.buyCost = novemberData.buyCost || '&';
|
||
this.maxBuyCnt = (novemberData.dailyBuyCnt || 0) * this.todayIndex;
|
||
this.buyCnt = 0;
|
||
this.freeCnt = (novemberData.dailyFreeCnt) * this.todayIndex;
|
||
this.todayPlayCnt = 0;
|
||
this.playCnt = 0;
|
||
this.menuIds = novemberData.menuIds || [];
|
||
this.successRewards = novemberData.successRewards || '&';
|
||
this.failRewards = novemberData.failRewards || '&';
|
||
}
|
||
|
||
public setPlayerRecords(playerData: ActivityNovemberRecModelType) {
|
||
this.updatePlayerRecord(playerData);
|
||
}
|
||
|
||
public updatePlayerRecord(playerData: ActivityNovemberRecModelType) {
|
||
if (!playerData) return;
|
||
this.buyCnt = playerData?.buyCnt || 0
|
||
if (playerData.records) {
|
||
this.records = playerData?.records || [];
|
||
for (const data of playerData.records) {
|
||
let { todayIndex, isSuccess, hasPass } = data;
|
||
if (todayIndex == this.todayIndex && isSuccess) this.todayPlayCnt++;
|
||
if (isSuccess) this.playCnt++;
|
||
}
|
||
}
|
||
}
|
||
|
||
public getShowResult() {
|
||
return {
|
||
...this.getBaseKeys(),
|
||
buyCost: this.buyCost,
|
||
maxBuyCnt: this.maxBuyCnt,
|
||
buyCnt: this.buyCnt,
|
||
freeCnt: this.freeCnt,
|
||
todayPlayCnt: this.todayPlayCnt,
|
||
playCnt: this.playCnt,
|
||
menuIds: this.menuIds,
|
||
successRewards: this.successRewards,
|
||
failRewards: this.failRewards,
|
||
}
|
||
}
|
||
} |