Files
ZYZ/shared/domain/activityField/timeLimitRankField.ts
2022-03-04 09:47:24 +08:00

91 lines
3.0 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 { pick } from 'underscore';
import { RANK_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityTurntableModelType, TurntableRecord } from '../../db/ActivityTurntableRec';
import { RewardInter } from '../../pubUtils/interface';
import { getRandEelmWithWeight, parseGoodStr } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
interface TimeLimitRewardInDb {
rank: number; // 第几名
rewards: string; // type&id&count
}
interface TimeLimitInDb {
rankType: number; // 排行榜类型
hid: number; // 如果有单个武将排行这里写武将id
rankEndTime: number; // 排行榜统计结束时间。13位时间戳之后会在后台加时间筛选在此之前先找wo
sendMailTime: number; // 发送奖励时间。13位时间戳
rankRewards: TimeLimitRewardInDb[]; // 不同排名的奖励
tabName: string; // 排行榜标签名
}
export class TimeLimitRankReward {
rank: number
rewards: string;
constructor(data: TimeLimitRewardInDb) {
this.rank = data.rank;
this.rewards = data.rewards;
}
}
// 新云转盘活动数据
export class TimeLimitRankData extends ActivityBase {
rankType: number; // 排行榜类型
hid: number; // 如果有单个武将排行这里写武将id
rankEndTime: number; // 排行榜统计结束时间。13位时间戳之后会在后台加时间筛选在此之前先找wo
sendMailTime: number; // 发送奖励时间。13位时间戳
rankRewards: TimeLimitRankReward[] = []; // 不同排名的奖励
tabName: string; // 标签名
// 是否可以记录
public canRecord() {
return this.beginTime <= Date.now() && this.rankEndTime >= Date.now();
}
public getRewardByRank(rank: number) {
let result: TimeLimitRankReward;
for(let reward of this.rankRewards) {
if(reward.rank > rank) break;
result = reward;
}
return result;
}
public needSnapshot() {
switch(this.rankType) {
case RANK_TYPE.GUILD_FUND:
return false;
default:
return true;
}
}
public initData(data: string) {
let dataObj: TimeLimitInDb = JSON.parse(data);
this.rankType = dataObj.rankType;
this.hid = dataObj.hid;
this.rankEndTime = dataObj.rankEndTime;
this.sendMailTime = dataObj.sendMailTime;
for(let rank of dataObj.rankRewards) {
this.rankRewards.push(new TimeLimitRankReward(rank));
}
this.tabName = dataObj.tabName;
}
public getShowResult() {
return {
...this.getBaseKeys(),
rankType: this.rankType,
rankEndTime: this.rankEndTime,
tabName: this.tabName,
}
}
constructor(activityData: ActivityModelType, createTime: number) {
super(activityData, createTime)
this.initData(activityData.data)
}
}