抽卡:获取抽卡列表
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, GACHA_ID } from "../../../consts";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { GachaListReturn } from "../../../domain/activityField/gachaField";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshFreeCount } from "../../../services/gachaService";
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GachaHandler(app);
|
||||
}
|
||||
|
||||
export class GachaHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取抽卡列表 元宝招募、友情点招募、求贤若渴
|
||||
* @param {{}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async getGachaList(msg: {}, session: BackendSession) {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
let userGachaList = await UserGachaModel.findAllByRole(roleId);
|
||||
let list: GachaListReturn[] = [];
|
||||
for(let [id, dicGacha] of gameData.gacha) {
|
||||
if(id == GACHA_ID.TIMELIMIT) continue; // 不包括限时
|
||||
|
||||
let userGacha = userGachaList.find(cur => cur.gachaId == id);
|
||||
userGacha = await refreshFreeCount(dicGacha, userGacha);
|
||||
let param = new GachaListReturn(dicGacha, userGacha);
|
||||
list.push(param);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { list });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 抽卡,所有抽卡类型都
|
||||
* @param {{ gachaId: number, activityId: number, count: number }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async pull(msg: { gachaId: number, activityId: number, count: number }, session: BackendSession) {
|
||||
const { gachaId, activityId, count } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 设置心愿单
|
||||
* @param {{ gachaId: number, hope: { id: number, hid: number }[] }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async setHope(msg: { gachaId: number, hope: { id: number, hid: number }[] }, session: BackendSession) {
|
||||
const { gachaId, hope } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 转盘
|
||||
* @param {{ gachaId: number }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async drawTurnTable(msg: { gachaId: number }, session: BackendSession) {
|
||||
const { gachaId } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 求贤若渴&限时招募里面设置pick武将
|
||||
* @param {{ gachaId: number, pickHero: number }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async setPickHero(msg: { gachaId: number, pickHero: number }, session: BackendSession) {
|
||||
const { gachaId, pickHero } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user