import { ActivityModelType } from '../../db/Activity'; import { ActivityBase } from './activityField'; import { prop } from '@typegoose/typegoose'; import { getTimeFunM } from '../../pubUtils/timeUtil'; import { UserGachaType } from '../../db/UserGacha'; import { GUIDE_GACHA_STAGE } from '../../consts'; export class SimpleResult { @prop({ required: true }) planId: number; @prop({ required: true }) hid: number; @prop({ required: true }) isTransfer: boolean; } /** * @description 特殊引导候选列表 * @memberof UserGacha */ export class Candidate { @prop({ required: true }) id: number; // 列表id @prop({ required: true }) isChosen: boolean; // 是否被选中 @prop({ required: true }) pullCnt: number; // 引导第几次保存的 @prop({ required: true, type: () => SimpleResult, _id: false }) list: SimpleResult[]; // 列表 } interface GuideGachaDataInDb { gachaId: number; // 抽卡卡池id chooseTime: number; // 开始后几天内可以选卡 } // 抽卡数据 export class GuideGachaData extends ActivityBase { gachaId: number = 0; stage: GUIDE_GACHA_STAGE = GUIDE_GACHA_STAGE.PULL; chooseTime: number = 0; pullCnt: number = 0; hasChoosen: boolean = false; candidates: Candidate[] = []; constructor(activityData: ActivityModelType, createTime: number, serverTime: number) { super(activityData, createTime, serverTime); this.initData(activityData.data); } public initData(data: string) { let obj: GuideGachaDataInDb = JSON.parse(data); this.gachaId = obj.gachaId; this.chooseTime = getTimeFunM(this.beginTime).getAfterDayWithHour(obj.chooseTime); this.stage = Date.now() < this.chooseTime? GUIDE_GACHA_STAGE.PULL: GUIDE_GACHA_STAGE.DECIDE; } public setPlayerData(userGacha: UserGachaType) { if(userGacha) { this.pullCnt = userGacha.pullCnt; this.candidates = userGacha.candidates; this.hasChoosen = userGacha.candidates.findIndex(cur => cur.isChosen) != -1; } } }