抽卡:获取抽卡列表

This commit is contained in:
luying
2021-04-21 21:10:26 +08:00
parent bc40d90f00
commit 9335b1adab
9 changed files with 434 additions and 9 deletions
+44 -1
View File
@@ -1,5 +1,10 @@
import { GachaData } from "../domain/activityField/gachaField";;
import { GachaData, Floor } from "../domain/activityField/gachaField";;
import { ActivityModelType, ActivityModel } from "../db/Activity";
import { DicGacha } from "../pubUtils/dictionary/DicGacha";
import { UserGachaType, UserGachaModel } from "../db/UserGacha";
import { shouldRefresh } from "../pubUtils/util";
import { REFRESH_HOUR, GACHA_ID, GACHA_TO_FLOOR } from "../consts";
import { getNextDayByGap } from "../pubUtils/timeUtil";
/**
* 获取活动页签里的限时卡池
@@ -27,4 +32,42 @@ export async function getLimitGacha(activityId: number) {
count: 0
}]
}
}
/**
* 刷新免费次数
* @param dicGacha
* @param userGacha
*/
export async function refreshFreeCount(dicGacha: DicGacha, userGacha: UserGachaType) {
let { day, count } = dicGacha.free;
if(count > 0) {
return userGacha;
}
let { roleId, gachaId, refFreeTime } = userGacha;
if(shouldRefresh(refFreeTime, new Date(), REFRESH_HOUR, day)) {
let ref = getNextDayByGap(refFreeTime, new Date(), day);
userGacha = await UserGachaModel.refreshFreeCount(roleId, gachaId, 0, ref);
}
return userGacha
}
/**
* @description 获取保底状态
* @param type 招募类型
* @param floor 玩家保底
*/
export function getFloorStatus(type: number, floor: Floor[]) {
let floorMap = new Map<number, number>();
for(let { id, count } of floor) {
floorMap.set(id, count);
}
let dicFloorType = GACHA_TO_FLOOR.get(type);
return dicFloorType.map(id => {
return {
id,
count: floorMap.get(id)||0
}
});
}