抽卡:提供内部接口

This commit is contained in:
luying
2021-04-23 20:48:03 +08:00
parent 5c24e28d06
commit 2df7a9f1a0
4 changed files with 37 additions and 24 deletions
@@ -131,9 +131,14 @@ export class GachaHandler {
// 任务 // 任务
await checkTask(roleId, sid, funcs, TASK_TYPE.GASHA, count, true, {}); await checkTask(roleId, sid, funcs, TASK_TYPE.GASHA, count, true, {});
let resultRefFreeTime = 0;
if(dicGacha.free.count > 0) {
resultRefFreeTime = getAfterDateByDay(refFreeTime, dicGacha.free.day);
}
return resResult(STATUS.SUCCESS, { return resResult(STATUS.SUCCESS, {
gachaId, activityId, gachaId, activityId,
freeCount, refFreeTime: getAfterDateByDay(refFreeTime, dicGacha.free.day), count, point, floor, freeCount, refFreeTime: resultRefFreeTime, count, point, floor,
heroes, result: resultList heroes, result: resultList
}); });
} }
+9 -20
View File
@@ -1,39 +1,28 @@
import { GachaData, Floor, GachaResult, Hope } from "../domain/activityField/gachaField";; import { GachaData, Floor, GachaResult, Hope } from "../domain/activityField/gachaField";;
import { ActivityModelType, ActivityModel } from "../db/Activity"; import { ActivityModel } from "../db/Activity";
import { DicGacha } from "../pubUtils/dictionary/DicGacha"; import { DicGacha } from "../pubUtils/dictionary/DicGacha";
import { UserGachaType, UserGachaModel } from "../db/UserGacha"; import { UserGachaType, UserGachaModel } from "../db/UserGacha";
import { shouldRefresh, getRandEelm, decodeArrayListStr, getRandomWithWeight, decodeIdCntArrayStr } from "../pubUtils/util"; import { shouldRefresh, getRandEelm, getRandomWithWeight } from "../pubUtils/util";
import { REFRESH_HOUR, GACHA_ID, GACHA_TO_FLOOR, GACHA_FLOOR_TYPE, GACHA_CONTENT_TYPE, HERO_QUALITY_TYPE, GACHA_OCCUPY_HID, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR } from "../consts"; import { REFRESH_HOUR, GACHA_TO_FLOOR, GACHA_FLOOR_TYPE, GACHA_CONTENT_TYPE, HERO_QUALITY_TYPE, GACHA_OCCUPY_HID, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR } from "../consts";
import { getNextDayByGap, getTodayZeroDate } from "../pubUtils/timeUtil"; import { getNextDayByGap, getTodayZeroDate } from "../pubUtils/timeUtil";
import { gameData, getDicGachaFloor } from "../pubUtils/data"; import { gameData, getDicGachaFloor } from "../pubUtils/data";
import { RECRUIT } from "../pubUtils/dicParam";
/** /**
* 获取活动页签里的限时卡池 * 获取活动页签里的限时卡池
* *
* @param roleId 玩家id
* @param aid 活动id * @param aid 活动id
*/ */
export async function getLimitGacha(activityId: number) { export async function getLimitGacha(roleId: string, activityId: number) {
let activityData = await ActivityModel.findActivity(activityId, true); let activityData = await ActivityModel.findActivity(activityId, true);
if(!activityData) return false; if(!activityData) return false;
let gachaData = new GachaData(activityData); let gachaData = new GachaData(activityData);
let userGacha = await UserGachaModel.findByRole(roleId, gachaData.gachaId, activityId);
let { heroes, gachaId } = gachaData; userGacha = await refreshGacha(gameData.gacha.get(gachaData.gachaId), userGacha);
gachaData.setUserGacha(userGacha);
return { return gachaData
gachaId,
heroes,
pickHero: 0,
freeCount: 0,
refFreeTime: 0,
count: 0,
floor: [{
id: 3,
count: 0
}]
}
} }
/** /**
@@ -320,7 +320,6 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
let newHeroInfo: CreateHeroParam[] = [], pieces: ItemInter[] = []; let newHeroInfo: CreateHeroParam[] = [], pieces: ItemInter[] = [];
for(let h of heroInfo) { for(let h of heroInfo) {
console.log('*****', JSON.stringify([...userHeroesMap]), h.hid)
if(userHeroesMap.has(h.hid)) { if(userHeroesMap.has(h.hid)) {
let {pieceId, count} = transPiece(h.hid); let {pieceId, count} = transPiece(h.hid);
pieces.push({ id: pieceId, count }); pieces.push({ id: pieceId, count });
+22 -2
View File
@@ -2,10 +2,11 @@ import { ActivityModelType } from '../../db/Activity';
import { ActivityBase } from './activityField'; import { ActivityBase } from './activityField';
import { prop } from '@typegoose/typegoose'; import { prop } from '@typegoose/typegoose';
import { UserGachaType } from '../../db/UserGacha'; import { UserGachaType } from '../../db/UserGacha';
import { getSeconds, getAfterDateByDay } from '../../pubUtils/timeUtil'; import { getAfterDateByDay } from '../../pubUtils/timeUtil';
import { DicGacha } from '../../pubUtils/dictionary/DicGacha'; import { DicGacha } from '../../pubUtils/dictionary/DicGacha';
import { getFloorStatus } from '../../services/gachaService'; import { getFloorStatus } from '../../services/gachaService';
import { GACHA_OCCUPY_HID } from '../../consts'; import { GACHA_OCCUPY_HID } from '../../consts';
import { gameData } from '../../pubUtils/data';
// 抽卡数据 // 抽卡数据
@@ -13,12 +14,29 @@ export class GachaData extends ActivityBase {
gachaId: number = 0; gachaId: number = 0;
heroes: Array<number> = []; heroes: Array<number> = [];
pickHero: number;
freeCount: number;
refFreeTime: number = 0;
count: number;
floor: Floor[];
public initData(data: string) { public initData(data: string) {
let obj = JSON.parse(data); let obj = JSON.parse(data);
this.gachaId = obj.gachaId; this.gachaId = obj.gachaId;
this.heroes = obj.heroes; this.heroes = obj.heroes;
} }
public setUserGacha(userGacha: UserGachaType) {
let dicGacha = gameData.gacha.get(this.gachaId);
this.pickHero = userGacha.pickHero;
this.freeCount = userGacha.freeCount;
if(dicGacha.free.count > 0) {
this.refFreeTime = getAfterDateByDay(userGacha.refFreeTime, dicGacha.free.day);
}
this.count = userGacha.count;
this.floor = userGacha.floor;
}
constructor(activityData: ActivityModelType) { constructor(activityData: ActivityModelType) {
super(activityData) super(activityData)
} }
@@ -78,7 +96,9 @@ export class GachaListReturn {
if(userGacha) { if(userGacha) {
this.freeCount = userGacha.freeCount; this.freeCount = userGacha.freeCount;
this.refFreeTime = getAfterDateByDay(userGacha.refFreeTime, dicGacha.free.day); if(dicGacha.free.count > 0) {
this.refFreeTime = getAfterDateByDay(userGacha.refFreeTime, dicGacha.free.day);
}
this.count = userGacha.count; this.count = userGacha.count;
this.floor = getFloorStatus(dicGacha.id, userGacha.floor); this.floor = getFloorStatus(dicGacha.id, userGacha.floor);
this.hope = userGacha.hope; this.hope = userGacha.hope;