500抽:活动格式
This commit is contained in:
@@ -2,8 +2,7 @@ import { Application, BackendSession, HandlerService, } from "pinus";
|
||||
import { resResult, shouldRefresh, getRandSingleEelm, getGachaRemainFloor } from "../../../pubUtils/util";
|
||||
import { STATUS, GACHA_TYPE, HERO_QUALITY_TYPE, TASK_TYPE, ITEM_CHANGE_REASON, } from "../../../consts";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { GachaData, GachaResultIndb } from "../../../domain/activityField/gachaField";
|
||||
import { SimpleResult, UserGachaModel } from "../../../db/UserGacha";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, getGuideGachaId, GachaResults, getDicGachaByGachaCnt, getNormalGachaId } from "../../../services/activity/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
@@ -15,6 +14,7 @@ import { getActivityById } from "../../../services/activity/activityService";
|
||||
import { checkTaskInGacha } from "../../../services/task/taskService";
|
||||
import { createHeroes } from "../../../services/role/createHero";
|
||||
import { getRoleCreateTime, getServerCreateTime } from "../../../services/redisService";
|
||||
import { getGuideGachaData } from "../../../services/activity/guideGachaService";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -99,7 +99,6 @@ export class GachaHandler {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
gachaId, activityId,
|
||||
freeCount, refFreeTime: userGacha.refFreeTime, count: userGacha.count, point: userGacha.point, floor, hope,
|
||||
guideResultCount: userGacha.guideResultCount,
|
||||
// heroes: resultHeroes,
|
||||
addHeros: heroes,
|
||||
result: resultList,
|
||||
@@ -301,22 +300,14 @@ export class GachaHandler {
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async getGuideGachaData(msg: {}, session: BackendSession) {
|
||||
const { } = msg;
|
||||
async getGuideGachaData(msg: { activityId: number }, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
let { gachaHasGuide } = await RoleModel.findByRoleId(roleId, 'gachaHasGuide');
|
||||
let guideCount = 0, guideResultList = [], candidates = [];
|
||||
if(!gachaHasGuide) {
|
||||
let gachaId = getGuideGachaId();
|
||||
const userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
({ guideCount = 0, guideResultList = [], candidates = [] } = userGacha);
|
||||
}
|
||||
const serverId: number = session.get('serverId');
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
guideCount,
|
||||
latest: guideResultList,
|
||||
candidates
|
||||
});
|
||||
const { activityId } = msg;
|
||||
let playerData = await getGuideGachaData(serverId, activityId, roleId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { playerData });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,35 +316,35 @@ export class GachaHandler {
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async guidePull(msg: {}, session: BackendSession) {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const sid: string = session.get('sid');
|
||||
const count = 10;
|
||||
const gachaId = getGuideGachaId();
|
||||
const dicGacha = gameData.gacha.get(gachaId);
|
||||
async guidePull(msg: { activityId: number; }, session: BackendSession) {
|
||||
// const { } = msg;
|
||||
// const roleId: string = session.get('roleId');
|
||||
// const sid: string = session.get('sid');
|
||||
// const count = 10;
|
||||
// const gachaId = getGuideGachaId();
|
||||
// const dicGacha = gameData.gacha.get(gachaId);
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
let { guideCount = 0 } = userGacha;
|
||||
if(guideCount >= RECRUIT.RECRUIT_FIRST_RECRUIT) return resResult(STATUS.GACHA_GUIDE_PULL_CNT_LACK);
|
||||
// let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
// let { guideCount = 0 } = userGacha;
|
||||
// if(guideCount >= RECRUIT.RECRUIT_FIRST_RECRUIT) return resResult(STATUS.GACHA_GUIDE_PULL_CNT_LACK);
|
||||
|
||||
if(guideCount == 0) {
|
||||
// 消耗东西
|
||||
let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.GACHA_PULL);
|
||||
if (!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
}
|
||||
// if(guideCount == 0) {
|
||||
// // 消耗东西
|
||||
// let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
// let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.GACHA_PULL);
|
||||
// if (!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
// }
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaPull = new GachaPull(dicGacha, userGacha);
|
||||
let { resultList } = gachaPull.pull(count, userHeroes);
|
||||
// let userHeroes = await HeroModel.findByRole(roleId);
|
||||
// let gachaPull = new GachaPull(dicGacha, userGacha);
|
||||
// let { resultList } = gachaPull.pull(count, userHeroes);
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultList: resultList, guideCount: guideCount + 1 })
|
||||
// userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultList: resultList, guideCount: guideCount + 1 })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
guideCount: userGacha.guideCount,
|
||||
latest: userGacha.guideResultList
|
||||
});
|
||||
// return resResult(STATUS.SUCCESS, {
|
||||
// guideCount: userGacha.guideCount,
|
||||
// latest: userGacha.guideResultList
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,28 +354,28 @@ export class GachaHandler {
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async saveToCandidates(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const gachaId = getGuideGachaId();
|
||||
// const { id } = msg;
|
||||
// const roleId: string = session.get('roleId');
|
||||
// const gachaId = getGuideGachaId();
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
let { guideResultList, candidates = [], guideCount } = userGacha;
|
||||
// let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
// let { guideResultList, candidates = [], guideCount } = userGacha;
|
||||
|
||||
let index = candidates.findIndex(cur => cur.id == id);
|
||||
if(index == -1) {
|
||||
candidates.push({
|
||||
id, guideCount, list: guideResultList
|
||||
});
|
||||
} else {
|
||||
candidates[index].list = guideResultList;
|
||||
candidates[index].guideCount = guideCount;
|
||||
}
|
||||
// let index = candidates.findIndex(cur => cur.id == id);
|
||||
// if(index == -1) {
|
||||
// candidates.push({
|
||||
// id, guideCount, list: guideResultList
|
||||
// });
|
||||
// } else {
|
||||
// candidates[index].list = guideResultList;
|
||||
// candidates[index].guideCount = guideCount;
|
||||
// }
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { candidates })
|
||||
// userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { candidates })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
candidates: userGacha.candidates
|
||||
});
|
||||
// return resResult(STATUS.SUCCESS, {
|
||||
// candidates: userGacha.candidates
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,61 +385,61 @@ export class GachaHandler {
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async decide(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const serverId: number = session.get('serverId');
|
||||
const sid: string = session.get('sid');
|
||||
const count = 10;
|
||||
const gachaId = getGuideGachaId();
|
||||
const dicGacha = gameData.gacha.get(gachaId);
|
||||
// const { id } = msg;
|
||||
// const roleId: string = session.get('roleId');
|
||||
// const roleName: string = session.get('roleName');
|
||||
// const serverId: number = session.get('serverId');
|
||||
// const sid: string = session.get('sid');
|
||||
// const count = 10;
|
||||
// const gachaId = getGuideGachaId();
|
||||
// const dicGacha = gameData.gacha.get(gachaId);
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(role.gachaHasGuide) {
|
||||
return resResult(STATUS.GACHA_GUIDE_HAS_DONE);
|
||||
}
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
let { guideResultList = [], candidates = [], } = userGacha;
|
||||
// let role = await RoleModel.findByRoleId(roleId);
|
||||
// if(role.gachaHasGuide) {
|
||||
// return resResult(STATUS.GACHA_GUIDE_HAS_DONE);
|
||||
// }
|
||||
// let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
// let { guideResultList = [], candidates = [], } = userGacha;
|
||||
|
||||
let simpleResult: SimpleResult[] = []
|
||||
if(id == 0) {
|
||||
if(guideResultList.length <= 0) {
|
||||
return resResult(STATUS.GACHA_GUIDE_NOT_DO);
|
||||
}
|
||||
simpleResult = guideResultList;
|
||||
} else {
|
||||
let candidate = candidates.find(cur => cur.id == id);
|
||||
if(!candidate) return resResult(STATUS.WRONG_PARMS);
|
||||
simpleResult = candidate.list;
|
||||
}
|
||||
// let simpleResult: SimpleResult[] = []
|
||||
// if(id == 0) {
|
||||
// if(guideResultList.length <= 0) {
|
||||
// return resResult(STATUS.GACHA_GUIDE_NOT_DO);
|
||||
// }
|
||||
// simpleResult = guideResultList;
|
||||
// } else {
|
||||
// let candidate = candidates.find(cur => cur.id == id);
|
||||
// if(!candidate) return resResult(STATUS.WRONG_PARMS);
|
||||
// simpleResult = candidate.list;
|
||||
// }
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let results = new GachaResults();
|
||||
results.addBySimpleResult(simpleResult);
|
||||
let { items, heroInfo, resultList } = results.transferToFinalResult(userHeroes);
|
||||
// let userHeroes = await HeroModel.findByRole(roleId);
|
||||
// let results = new GachaResults();
|
||||
// results.addBySimpleResult(simpleResult);
|
||||
// let { items, heroInfo, resultList } = results.transferToFinalResult(userHeroes);
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultCount: count });
|
||||
// userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultCount: count });
|
||||
|
||||
// 给东西
|
||||
// console.log('****', heroInfo)
|
||||
let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
// 更新数据
|
||||
role = await RoleModel.updateRoleInfo(roleId, { gachaHasGuide: true });
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, 0, count, resultList);
|
||||
// // 给东西
|
||||
// // console.log('****', heroInfo)
|
||||
// let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
// await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
// // 更新数据
|
||||
// role = await RoleModel.updateRoleInfo(roleId, { gachaHasGuide: true });
|
||||
// await UserGachaRecModel.createRec(roleId, gachaId, 0, count, resultList);
|
||||
|
||||
// 任务
|
||||
if(dicGacha.isTask) await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, true);
|
||||
// // 任务
|
||||
// if(dicGacha.isTask) await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, true);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
hasInit: !!role.gachaHasGuide,
|
||||
guideResultCount: userGacha.guideResultCount,
|
||||
count: userGacha.count,
|
||||
gachaId,
|
||||
// heroes: resultHeroes,
|
||||
addHeros: heroes,
|
||||
result: resultList
|
||||
});
|
||||
// return resResult(STATUS.SUCCESS, {
|
||||
// hasInit: !!role.gachaHasGuide,
|
||||
// guideResultCount: userGacha.guideResultCount,
|
||||
// count: userGacha.count,
|
||||
// gachaId,
|
||||
// // heroes: resultHeroes,
|
||||
// addHeros: heroes,
|
||||
// result: resultList
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import { PopUpShopItemShow } from '../../domain/activityField/popUpShopField';
|
||||
import { sendMessageToGuildWithSuc, sendMessageToUserWithSuc } from '../pushService';
|
||||
import { UserOrderModelType } from '../../db/UserOrder';
|
||||
import { isArray } from 'underscore';
|
||||
import { getGuideGachaData } from './guideGachaService';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -212,7 +213,15 @@ export async function getActivity(serverId: number, roleId: string, guildCode: s
|
||||
case ACTIVITY_TYPE.GUILD_PAY:
|
||||
{
|
||||
activityData = await getGuildPayDataShow(serverId, activityId, roleId, guildCode);
|
||||
break
|
||||
}
|
||||
case ACTIVITY_TYPE.GUIDE_GACHA:
|
||||
{
|
||||
activityData = await getGuideGachaData(serverId, activityId, roleId);
|
||||
break
|
||||
}
|
||||
case ACTIVITY_TYPE.SHOP:
|
||||
break
|
||||
default: {
|
||||
console.log('未知活动类型.........', activityType)
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GachaData, Floor as UserFloor, Hope as UserHope, GachaListReturn, GachaResultIndb } from "../../domain/activityField/gachaField";;
|
||||
import { Floor as UserFloor, Hope as UserHope, GachaListReturn, GachaResultIndb } from "../../domain/activityField/gachaField";;
|
||||
import { DicGacha } from "../../pubUtils/dictionary/DicGacha";
|
||||
import { UserGachaType, UserGachaModel, SimpleResult } from "../../db/UserGacha";
|
||||
import { UserGachaType, UserGachaModel } from "../../db/UserGacha";
|
||||
import { shouldRefresh, getRandEelm, getRandEelmWithWeight, getRandSingleIndex, getRandSingleEelm } from "../../pubUtils/util";
|
||||
import { REFRESH_TIME, GACHA_FLOOR_TYPE, HERO_QUALITY_TYPE, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR, TIME_OUTPUT_TYPE, GACHA_TYPE, GACHA_PLAN_TYPE } from "../../consts";
|
||||
import { getTimeFunD, getZeroPointD } from "../../pubUtils/timeUtil";
|
||||
@@ -11,6 +11,7 @@ import { HeroType } from "../../db/Hero";
|
||||
import { getActivityById } from "./activityService";
|
||||
import { transPiece } from "../role/util";
|
||||
import { getRoleCreateTime, getServerCreateTime } from "../redisService";
|
||||
import { SimpleResult } from "../../domain/activityField/guideGachaField";
|
||||
|
||||
/**
|
||||
* 获取招募列表
|
||||
@@ -31,26 +32,6 @@ export async function getGachaList(roleId: string) {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取活动页签里的限时卡池
|
||||
*
|
||||
* @param roleId 玩家id
|
||||
* @param aid 活动id
|
||||
*/
|
||||
export async function getLimitGacha(serverId: number, roleId: string, activityId: number) {
|
||||
|
||||
let activityData = await getActivityById(activityId);
|
||||
if (!activityData) return false;
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let gachaData = new GachaData(activityData, createTime, serverTime);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaData.gachaId, activityId);
|
||||
userGacha = await refreshGacha(gameData.gacha.get(gachaData.gachaId), userGacha);
|
||||
gachaData.setUserGacha(userGacha);
|
||||
return gachaData
|
||||
}
|
||||
|
||||
export function getGuideGachaId() {
|
||||
let ids = gameData.gachaByType.get(GACHA_TYPE.GUIDE);
|
||||
return ids[0];
|
||||
|
||||
15
game-server/app/services/activity/guideGachaService.ts
Normal file
15
game-server/app/services/activity/guideGachaService.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { UserGachaModel } from "../../db/UserGacha";
|
||||
import { GuideGachaData } from "../../domain/activityField/guideGachaField";
|
||||
import { getRoleCreateTime, getServerCreateTime } from "../redisService";
|
||||
import { getActivityById } from "./activityService";
|
||||
|
||||
export async function getGuideGachaData(serverId: number, activityId: number, roleId: string) {
|
||||
let activityData = await getActivityById(activityId);
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new GuideGachaData(activityData, createTime, serverTime);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, playerData.gachaId, activityId);
|
||||
playerData.setPlayerData(userGacha);
|
||||
if(playerData.hasChoosen) return null
|
||||
return playerData;
|
||||
}
|
||||
@@ -645,7 +645,8 @@ export function checkRouteParam(route: string, msg: any) {
|
||||
if(!checkNaturalArray(heroes)) return false;
|
||||
if (heroes.length > LINEUP_NUM) return false;
|
||||
for(let { actorId, order } of heroes) {
|
||||
if(!checkNaturalNumbers(actorId, order)) return false;
|
||||
if(!checkNaturalNumbers(actorId)) return false;
|
||||
if(!checkNumberIfExist(order)) return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -156,10 +156,9 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio
|
||||
case 'pvp': // pvp
|
||||
return await getPvpEntryData(roleId);
|
||||
case 'gacha':
|
||||
const { gachaHasGuide } = role;
|
||||
const gachalist = await getGachaList(roleId);
|
||||
const visitList = await getVisitedHeroList(roleId);
|
||||
return { hasInit: !!gachaHasGuide, gachalist, visitList }
|
||||
return { hasInit: true, gachalist, visitList }
|
||||
case 'school':
|
||||
return await getSchoolList(roleId);
|
||||
case 'guild':
|
||||
|
||||
@@ -57,6 +57,7 @@ export enum ACTIVITY_TYPE {
|
||||
TASK_PASS = 42, // 战令活动
|
||||
GUILD_PAY = 43, // 军团充值人数
|
||||
SHOP = 44, // 限时商店
|
||||
GUIDE_GACHA = 45, // 500抽
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,4 +218,9 @@ export enum DAILY_COIN_BOX_STATUS {
|
||||
CAN_NOT_OPEN = 0, // 不可打开
|
||||
CAN_OPEN = 1, // 可以打开
|
||||
RECEIVED = 2, // 已领取
|
||||
}
|
||||
|
||||
export enum GUIDE_GACHA_STAGE {
|
||||
PULL = 1, // 抽卡阶段
|
||||
DECIDE = 2, // 决定阶段
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { getZeroPointD } from '../pubUtils/timeUtil';
|
||||
import { RECRUIT } from '../pubUtils/dicParam';
|
||||
import { Candidate, SimpleResult } from '../domain/activityField/guideGachaField';
|
||||
|
||||
export class Floor {
|
||||
@prop({ required: true })
|
||||
@@ -36,28 +37,6 @@ class Turntable {
|
||||
hasGet: boolean; // 是否得到
|
||||
}
|
||||
|
||||
export class SimpleResult {
|
||||
@prop({ required: true })
|
||||
planId: number;
|
||||
@prop({ required: true })
|
||||
hid: number;
|
||||
@prop({ required: true })
|
||||
isTransfer: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 特殊引导候选列表
|
||||
* @memberof UserGacha
|
||||
*/
|
||||
class Candidate {
|
||||
@prop({ required: true })
|
||||
id: number; // 列表id
|
||||
@prop({ required: true })
|
||||
guideCount: number; // 引导次数
|
||||
@prop({ required: true, type: SimpleResult, _id: false })
|
||||
list: SimpleResult[]; // 是否得到
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家抽卡表
|
||||
**/
|
||||
@@ -115,15 +94,12 @@ export default class UserGacha extends BaseModel {
|
||||
|
||||
// 初始特殊引导
|
||||
@prop({ required: true, default: 0 })
|
||||
guideCount: number; // 预抽卡次数
|
||||
pullCnt: number; // 预抽卡次数
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
guideResultCount: number; // 预抽卡次数
|
||||
|
||||
@prop({ required: true, type: SimpleResult, default: [], _id: false })
|
||||
@prop({ required: true, type: () => SimpleResult, default: [], _id: false })
|
||||
guideResultList: SimpleResult[]; // 预抽卡结果
|
||||
|
||||
@prop({ required: true, type: Candidate, default: [], _id: false })
|
||||
@prop({ required: true, type: () => Candidate, default: [], _id: false })
|
||||
candidates: Candidate[]; // 预抽卡候选
|
||||
|
||||
public static async findAllByRole(roleId: string) {
|
||||
|
||||
@@ -1,47 +1,9 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityBase } from './activityField';
|
||||
import { prop } from '@typegoose/typegoose';
|
||||
import { UserGachaType } from '../../db/UserGacha';
|
||||
import { getTimeFun } from '../../pubUtils/timeUtil';
|
||||
import { DicGacha } from '../../pubUtils/dictionary/DicGacha';
|
||||
import { gameData } from '../../pubUtils/data';
|
||||
import { getGachaRemainFloor } from '../../pubUtils/util';
|
||||
|
||||
|
||||
// 抽卡数据
|
||||
export class GachaData extends ActivityBase {
|
||||
gachaId: number = 0;
|
||||
heroes: Array<number> = [];
|
||||
|
||||
pickHero: number;
|
||||
freeCount: number;
|
||||
refFreeTime: number = 0;
|
||||
count: number;
|
||||
floor: Floor[];
|
||||
|
||||
public initData(data: string) {
|
||||
let obj = JSON.parse(data);
|
||||
this.gachaId = obj.gachaId;
|
||||
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) {
|
||||
let f = getTimeFun(userGacha.refFreeTime);
|
||||
this.refFreeTime = <number>f.getAfterDayWithHour(dicGacha.free.day);
|
||||
}
|
||||
this.count = userGacha.count;
|
||||
this.floor = userGacha.floor;
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 保底记录
|
||||
* @memberof UserGacha
|
||||
@@ -88,7 +50,6 @@ export class GachaListReturn {
|
||||
freeCount: number = 0; // 免费次数
|
||||
refFreeTime: number = 0; // 免费次数下次刷新时间
|
||||
count: number = 0; // 整体已抽卡次数
|
||||
guideResultCount: number = 0; // 引导已抽卡次数
|
||||
remainFloor: number = 0; // 还剩多少次可以保底
|
||||
hope: Hope[] = []; // 心愿单
|
||||
point: number = 0; // 积分
|
||||
@@ -110,7 +71,6 @@ export class GachaListReturn {
|
||||
this.point = userGacha.point;
|
||||
this.turntable = userGacha.turntable;
|
||||
this.pickHero = userGacha.pickHero;
|
||||
this.guideResultCount = userGacha.guideResultCount||0;
|
||||
}
|
||||
this.remainFloor = getGachaRemainFloor(this.gachaId, userGacha?.floor||[]);
|
||||
}
|
||||
|
||||
67
shared/domain/activityField/guideGachaField.ts
Normal file
67
shared/domain/activityField/guideGachaField.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityBase } from './activityField';
|
||||
import { prop } from '@typegoose/typegoose';
|
||||
import { getTimeFunM } from '../../pubUtils/timeUtil';
|
||||
import { UserGachaType } from '../../db/UserGacha';
|
||||
import { GUIDE_GACHA_STAGE } from '../../consts';
|
||||
|
||||
|
||||
|
||||
export class SimpleResult {
|
||||
@prop({ required: true })
|
||||
planId: number;
|
||||
@prop({ required: true })
|
||||
hid: number;
|
||||
@prop({ required: true })
|
||||
isTransfer: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 特殊引导候选列表
|
||||
* @memberof UserGacha
|
||||
*/
|
||||
export class Candidate {
|
||||
@prop({ required: true })
|
||||
id: number; // 列表id
|
||||
@prop({ required: true })
|
||||
isChosen: boolean; // 是否被选中
|
||||
@prop({ required: true })
|
||||
pullCnt: number; // 引导第几次保存的
|
||||
@prop({ required: true, type: () => SimpleResult, _id: false })
|
||||
list: SimpleResult[]; // 列表
|
||||
}
|
||||
|
||||
interface GuideGachaDataInDb {
|
||||
gachaId: number; // 抽卡卡池id
|
||||
chooseTime: number; // 开始后几天内可以选卡
|
||||
}
|
||||
|
||||
// 抽卡数据
|
||||
export class GuideGachaData extends ActivityBase {
|
||||
gachaId: number = 0;
|
||||
stage: GUIDE_GACHA_STAGE = GUIDE_GACHA_STAGE.PULL;
|
||||
chooseTime: number = 0;
|
||||
pullCnt: number = 0;
|
||||
hasChoosen: boolean = false;
|
||||
candidates: Candidate[] = [];
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime);
|
||||
this.initData(activityData.data);
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let obj: GuideGachaDataInDb = JSON.parse(data);
|
||||
this.gachaId = obj.gachaId;
|
||||
this.chooseTime = <number>getTimeFunM(this.beginTime).getAfterDayWithHour(obj.chooseTime);
|
||||
this.stage = Date.now() < this.chooseTime? GUIDE_GACHA_STAGE.PULL: GUIDE_GACHA_STAGE.DECIDE;
|
||||
}
|
||||
|
||||
public setPlayerData(userGacha: UserGachaType) {
|
||||
if(userGacha) {
|
||||
this.pullCnt = userGacha.pullCnt;
|
||||
this.candidates = userGacha.candidates;
|
||||
this.hasChoosen = userGacha.candidates.findIndex(cur => cur.isChosen) != -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user