Files
ZYZ/shared/domain/activityField/newHeroGiftField.ts
2022-08-04 17:28:35 +08:00

91 lines
2.9 KiB
TypeScript

import { ActivityModelType } from '../../db/Activity';
import { ActivityNewHeroGiftModelType } from '../../db/ActivityNewHeroGift';
import { ActivityBase } from './activityField';
/******* 存在数据库里的数据 *******/
interface NewHeroGiftExplain {
index: number;
explain: string;
}
interface NewHeroGiftRewardInDb {
index: number; // 下标
cover: string; // 翻牌背面的图片文件名
reward: string; // 奖励 type&id&count
countMax: number; // 最多抽出次数
}
interface NewHeroGiftDataInDb {
hid: number; // 左侧的立绘武将
position: string; // 位置 x&y
explain: NewHeroGiftExplain[]; // 玩法说明
rewards: NewHeroGiftRewardInDb[]; // 奖励
consumePoint: number; // 每转一次消耗的点数
}
/******* 返回给客户端的数据 *******/
class NewHeroGiftReward {
index: number; // 下标
cover: string; // 翻牌背面的图片文件名
reward: string; // 奖励 type&id&count
countMax: number; // 最多抽出次数
buyCount: number = 0; // 转出的次数
constructor(data: NewHeroGiftRewardInDb) {
this.index = data.index;
this.cover = data.cover;
this.reward = data.reward;
this.countMax = data.countMax;
}
addBuyCount() {
this.buyCount++;
}
}
export class NewHeroGiftData extends ActivityBase {
hid: number; // 左侧的立绘武将
position: string; // 位置 x&y
consumePoint: number; // 每转一次消耗的点数
explain: NewHeroGiftExplain[]; // 玩法说明
rewards: NewHeroGiftReward[] = []; // 奖励
totalPoint: number = 0; // 已获得的点数
consumeTotalPoint: number = 0; // 总消耗的点数
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
super(activityData, createTime, serverTime)
this.initData(activityData.data)
}
public initData(data: string) {
let dataObj: NewHeroGiftDataInDb = JSON.parse(data);
this.hid = dataObj.hid;
this.position = dataObj.position;
this.consumePoint = dataObj.consumePoint;
this.explain = dataObj.explain
let arr = dataObj.rewards||[];
for (let obj of arr) {
this.rewards.push(new NewHeroGiftReward(obj))
}
}
public findItem(index: number) {
return this.rewards.find(obj => { return obj && obj.index === index });
}
//解析玩家购买记录
public setPlayerRecords(data: ActivityNewHeroGiftModelType) {
if (!data) {
return;
}
this.totalPoint = data.totalPoint||0;
let records = data.records||[];
for (let obj of records) {
let item = this.findItem(obj.index);
if(item) item.addBuyCount();
this.consumeTotalPoint += obj.point;
}
}
}