Files
ZYZ/shared/domain/activityField/qixiField.ts

104 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 节日活动 - 七夕鹊桥
import { ActivityModelType } from '../../db/Activity';
import { ActivityQixiRecModelType, QixiRecord } from '../../db/ActivityQixiRec';
import { ActivityBase } from './activityField';
// 后台格式
interface QixiDataInDb {
buyCost: string; // 购买一次宴请次数的消耗type&id&count
dailyBuyCnt: number; // 每天可以购买的次数
freeCnt: number; // 每天可以免费划船的次数
maxProgress: number; // 最大进度
rewards: string; // 奖励
countdown: number;
}
export class QixiData extends ActivityBase {
buyCost: string; // 购买一次次数的消耗type&id&count
dailyBuyCnt: number; // 每天可以购买的次数
freeCntDaily: number; // 每天可以免费的次数
maxProgress: number; // 最大进度
rewards: string; // 奖励
countdown: number; // 倒计时
freeCnt: number = 0; // 累积到现在可以免费的次数
maxBuyCnt: number = 0; // 累积到现在可以购买的次数
buyCnt: number = 0; // 累积到现在已经购买了的次数
todayPlayCnt: number = 0; // 今天玩的次数
playCnt: number = 0; // 总玩的次数
progress: number = 0; // 当前的进度条
recordTodayIndex: number = 0;
records: QixiRecord[] = [];
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
super(activityData, createTime, serverTime)
this.initData(activityData.data)
}
public initData(data: string): void {
let dataObj: QixiDataInDb = JSON.parse(data);
if (!dataObj) return;
this.countdown = dataObj.countdown;
this.buyCost = dataObj.buyCost || '&';
this.dailyBuyCnt = dataObj.dailyBuyCnt || 0;
this.freeCntDaily = dataObj.freeCnt || 0;
this.maxProgress = dataObj.maxProgress || 0;
this.rewards = dataObj.rewards || '&';
this.freeCnt = this.freeCntDaily * this.todayIndex;
this.maxBuyCnt = this.todayIndex * this.dailyBuyCnt;
this.recordTodayIndex = this.todayIndex;
}
public setPlayerRecords(playerData: ActivityQixiRecModelType) {
this.updatePlayerRecord(playerData);
if(this.progress >= this.maxProgress) this.progress = 0;
}
public updatePlayerRecord(playerData: ActivityQixiRecModelType) {
if (!playerData) return;
this.buyCnt = playerData.buyCnt || 0;
this.todayPlayCnt = 0;
this.playCnt = 0;
this.recordTodayIndex = this.todayIndex;
if(playerData.record) {
playerData.record.sort((a, b) => a.time.getTime() - b.time.getTime());
for(let data of playerData.record) {
let { todayIndex, afterProgress, progress, hasPass, isSkip } = data;
if(afterProgress >= this.maxProgress) {
if(todayIndex == this.todayIndex && hasPass) this.todayPlayCnt ++;
if(hasPass) this.playCnt ++;
}
if(!isSkip) this.progress = afterProgress||progress;
this.records.push(data);
}
if(this.todayPlayCnt >= this.freeCntDaily && this.playCnt < this.freeCnt) {
for(let i = 1; i <= this.todayIndex; i++) {
let times = playerData.record.filter(cur => cur.todayIndex == i && cur.hasPass && cur.afterProgress >= this.maxProgress).length;
if(times < this.freeCntDaily) {
this.recordTodayIndex = i; break;
}
}
}
}
}
public getShowResult() {
return {
...this.getBaseKeys(),
buyCost: this.buyCost,
dailyBuyCnt: this.dailyBuyCnt,
freeCnt: this.freeCnt,
maxBuyCnt: this.maxBuyCnt,
buyCnt: this.buyCnt,
todayPlayCnt: this.todayPlayCnt,
playCnt: this.playCnt,
maxProgress: this.maxProgress,
progress: this.progress,
rewards: this.rewards,
countdown: this.countdown,
}
}
}