62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
// 百家争鸣活动 - 祈灵
|
|
import { ActivityModelType } from '../../db/Activity';
|
|
import { ActivityAuthorGachaRecModelType } from '../../db/AuthorGachaRec';
|
|
import { ActivityBase } from './activityField';
|
|
|
|
// 后台格式
|
|
interface AuthorGachaDataInDb {
|
|
gachaId: number; // 卡池
|
|
box: {
|
|
count: number; // 次数
|
|
rewards: string; // type&id&count, type: 1-武将 2-道具 3-礼包
|
|
isSpecial: boolean; // 重要节点奖励标记
|
|
hasReceived?: boolean; // 是否获得
|
|
}[];
|
|
}
|
|
|
|
export class AuthorGachaData extends ActivityBase {
|
|
gachaId: number;
|
|
box: AuthorGachaDataInDb['box'] = [];
|
|
|
|
gachaCnt: number = 0;
|
|
record: number[] = [];
|
|
|
|
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
|
super(activityData, createTime, serverTime)
|
|
this.initData(activityData.data)
|
|
}
|
|
|
|
public initData(data: string): void {
|
|
let dataObj: AuthorGachaDataInDb = JSON.parse(data);
|
|
if (!dataObj) return;
|
|
|
|
this.gachaId = dataObj.gachaId;
|
|
this.box = dataObj.box;
|
|
}
|
|
|
|
public setPlayerRecords(playerData: ActivityAuthorGachaRecModelType) {
|
|
this.updatePlayerRecord(playerData);
|
|
}
|
|
|
|
public updatePlayerRecord(playerData: ActivityAuthorGachaRecModelType) {
|
|
if (!playerData) return;
|
|
this.gachaCnt = playerData?.gachaCnt || 0;
|
|
this.record = playerData?.record || [];
|
|
}
|
|
|
|
public getShowResult() {
|
|
let box: AuthorGachaDataInDb['box'] = [];
|
|
for (let { count, rewards, isSpecial = false } of this.box) {
|
|
let hasReceived = false;
|
|
if (this.record.indexOf(count) != -1) hasReceived = true;
|
|
box.push({ count, rewards, hasReceived, isSpecial })
|
|
}
|
|
|
|
return {
|
|
...this.getBaseKeys(),
|
|
gachaId: this.gachaId,
|
|
authorGachaCnt: this.gachaCnt,
|
|
box,
|
|
}
|
|
}
|
|
} |