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
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user