抽卡:500抽逻辑完成
This commit is contained in:
@@ -4,6 +4,7 @@ import { prop } from '@typegoose/typegoose';
|
||||
import { getTimeFunM } from '../../pubUtils/timeUtil';
|
||||
import { UserGachaType } from '../../db/UserGacha';
|
||||
import { GUIDE_GACHA_STAGE } from '../../consts';
|
||||
import { RECRUIT } from '../../pubUtils/dicParam';
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +30,13 @@ export class Candidate {
|
||||
pullCnt: number; // 引导第几次保存的
|
||||
@prop({ required: true, type: () => SimpleResult, _id: false })
|
||||
list: SimpleResult[]; // 列表
|
||||
|
||||
constructor(id: number, pullCnt: number, result: SimpleResult[]) {
|
||||
this.id = id;
|
||||
this.isChosen = false;
|
||||
this.pullCnt = pullCnt;
|
||||
this.list = result;
|
||||
}
|
||||
}
|
||||
|
||||
interface GuideGachaDataInDb {
|
||||
@@ -43,6 +51,7 @@ export class GuideGachaData extends ActivityBase {
|
||||
chooseTime: number = 0;
|
||||
pullCnt: number = 0;
|
||||
hasChoosen: boolean = false;
|
||||
latest: SimpleResult[] = [];
|
||||
candidates: Candidate[] = [];
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
@@ -62,6 +71,47 @@ export class GuideGachaData extends ActivityBase {
|
||||
this.pullCnt = userGacha.pullCnt;
|
||||
this.candidates = userGacha.candidates;
|
||||
this.hasChoosen = userGacha.candidates.findIndex(cur => cur.isChosen) != -1;
|
||||
this.latest = userGacha.guideResultList;
|
||||
}
|
||||
}
|
||||
|
||||
public canPull() {
|
||||
return this.stage == GUIDE_GACHA_STAGE.PULL && this.pullCnt < RECRUIT.RECRUIT_FIRST_RECRUIT;
|
||||
}
|
||||
|
||||
public canDecide() {
|
||||
return this.stage == GUIDE_GACHA_STAGE.DECIDE && !this.hasChoosen;
|
||||
}
|
||||
|
||||
public chooseCandidate(id: number) {
|
||||
let candidate = this.candidates.find(cur => cur.id == id);
|
||||
if(!candidate) return false;
|
||||
candidate.isChosen = true;
|
||||
return candidate;
|
||||
}
|
||||
|
||||
public setCandidate(id: number) {
|
||||
if(!this.latest || this.latest.length == 0) return false;
|
||||
let newObj = new Candidate(id, this.pullCnt, this.latest);
|
||||
let index = this.candidates.findIndex(cur => cur.id == id);
|
||||
if(index == -1) {
|
||||
this.candidates.push(newObj);
|
||||
} else {
|
||||
this.candidates[index] = newObj;
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public autoSave() {
|
||||
if(this.pullCnt - this.candidates.length + RECRUIT.RECRUIT_FIRST_RECRUIT_SAVE > RECRUIT.RECRUIT_FIRST_RECRUIT) {
|
||||
for(let i = 1; i <= RECRUIT.RECRUIT_FIRST_RECRUIT_SAVE; i++) {
|
||||
let candidate = this.candidates.find(cur => cur.id == i);
|
||||
if(!candidate) {
|
||||
this.candidates.push(new Candidate(i, this.pullCnt, this.latest));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user