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':
|
||||
|
||||
Reference in New Issue
Block a user