抽卡:500抽逻辑完成
This commit is contained in:
@@ -434,9 +434,10 @@ export const STATUS = {
|
||||
GACHA_HAS_VISITED: { code: 31106, simStr: '该武将已拜访过' },
|
||||
GACHA_VISITED_COUNT_OVER: { code: 31107, simStr: '今天武将拜访已超过次数' },
|
||||
GACHA_HOPE_HAS_GET: { code: 31108, simStr: '该心愿已实现' },
|
||||
GACHA_GUIDE_PULL_CNT_LACK: { code: 31109, simStr: '预抽卡次数不足' },
|
||||
GACHA_GUIDE_NOT_DO: { code: 31110, simStr: '没有预抽卡过' },
|
||||
GACHA_GUIDE_HAS_DONE: { code: 31111, simStr: '不可多次预抽卡' },
|
||||
GACHA_GUIDE_PULL_CNT_LACK: { code: 31109, simStr: '暂时不可抽卡或抽卡次数不足' },
|
||||
GACHA_GUIDE_NOT_DO: { code: 31110, simStr: '没有抽卡过' },
|
||||
GACHA_GUIDE_HAS_DONE: { code: 31111, simStr: '未到达选择时间或已经选择过了' },
|
||||
GACHA_GUIDE_NO_CANDIDATE: { code: 31112, simStr: '该位置没有保存过数据' },
|
||||
// 礼包码 31201-31300
|
||||
GIFT_CODE_USED_NUM_MAX: { code: 31201, simStr: '礼包码使用次数超过' },
|
||||
YOU_HAVE_USED_THIS_CODE: { code: 31202, simStr: '您已使用过该码' },
|
||||
|
||||
@@ -115,14 +115,17 @@ export default class UserGacha extends BaseModel {
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async updateInfo(roleId: string, gachaId: number, activityId: number, update: UserGachaParam) {
|
||||
public static async updateInfo(roleId: string, gachaId: number, activityId: number, update: UserGachaParam, inc: { pullCnt?: number, count?: number } = {}) {
|
||||
const doc = new UserGachaModel();
|
||||
const setOnInsert = doc.toJSON();
|
||||
delete setOnInsert._id;
|
||||
for(let key in update) {
|
||||
delete setOnInsert[key];
|
||||
}
|
||||
let rec: UserGachaType = await UserGachaModel.findOneAndUpdate({ roleId, gachaId, activityId }, { $set: update, $setOnInsert: setOnInsert }, { new: true, upsert: true }).lean({ virtuals: true });
|
||||
for(let key in inc) {
|
||||
delete setOnInsert[key];
|
||||
}
|
||||
let rec: UserGachaType = await UserGachaModel.findOneAndUpdate({ roleId, gachaId, activityId }, { $set: update, $setOnInsert: setOnInsert, $inc: inc }, { new: true, upsert: true }).lean({ virtuals: true });
|
||||
return rec;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,5 +238,11 @@
|
||||
"activityType": 44,
|
||||
"name": "SHOP",
|
||||
"string": "限时商店"
|
||||
},
|
||||
{
|
||||
"id": 45,
|
||||
"activityType": 45,
|
||||
"name": "GUIDE_GACHA",
|
||||
"string": "500抽"
|
||||
}
|
||||
]
|
||||
@@ -1043,7 +1043,21 @@
|
||||
"gameCoin": 1
|
||||
},
|
||||
{
|
||||
"productID": "com.bantu.sgzzyz.yb61",
|
||||
"productID": "com.bantu.sgzzyz.yb61-1",
|
||||
"type": 44,
|
||||
"price": 98,
|
||||
"message": "商店",
|
||||
"gameCoin": 1
|
||||
},
|
||||
{
|
||||
"productID": "com.bantu.sgzzyz.yb61-2",
|
||||
"type": 44,
|
||||
"price": 98,
|
||||
"message": "商店",
|
||||
"gameCoin": 1
|
||||
},
|
||||
{
|
||||
"productID": "com.bantu.sgzzyz.yb61-3",
|
||||
"type": 44,
|
||||
"price": 98,
|
||||
"message": "商店",
|
||||
|
||||
@@ -22,5 +22,5 @@
|
||||
"DEBUG_TIME": 1,
|
||||
"CHECK_WORD": 1,
|
||||
"CAN_PAY": 1,
|
||||
"SKIP_ENCODE": 0
|
||||
"SKIP_ENCODE": 1
|
||||
}
|
||||
Reference in New Issue
Block a user