✨ feat(百家争鸣):祈灵 更新至 eb9f941ae
This commit is contained in:
61
shared/domain/activityField/authorGachaField.ts
Normal file
61
shared/domain/activityField/authorGachaField.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
// 百家争鸣活动 - 祈灵
|
||||
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-礼包
|
||||
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 } of this.box) {
|
||||
let hasReceived = false;
|
||||
if (this.record.indexOf(count) != -1) hasReceived = true;
|
||||
box.push({ count, rewards, hasReceived })
|
||||
}
|
||||
|
||||
return {
|
||||
...this.getBaseKeys(),
|
||||
gachaId: this.gachaId,
|
||||
authorGachaCnt: this.gachaCnt,
|
||||
box,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user