抽卡:修改抽卡奖池逻辑
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { Application, BackendSession, HandlerService, } from "pinus";
|
||||
import { resResult, shouldRefresh, getRandSingleEelm } from "../../../pubUtils/util";
|
||||
import { STATUS, GACHA_ID, HERO_QUALITY_TYPE, TASK_TYPE, ITEM_CHANGE_REASON, } from "../../../consts";
|
||||
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 { GachaResult, GachaData } from "../../../domain/activityField/gachaField";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, getAllHeroByQuality, GachaPull } from "../../../services/activity/gachaService";
|
||||
import { GachaData, GachaResultIndb } from "../../../domain/activityField/gachaField";
|
||||
import { SimpleResult, UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, getGuideGachaId, GachaResults, getDicGachaByGachaCnt } from "../../../services/activity/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { handleCost, addItems } from "../../../services/role/rewardService";
|
||||
@@ -61,11 +61,13 @@ export class GachaHandler {
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, activityId);
|
||||
userGacha = await refreshGacha(dicGacha, userGacha);
|
||||
let { freeCount, point, pickHero, refFreeTime, count: historyCount } = userGacha;
|
||||
if ((gachaId == GACHA_ID.ASSIGN || gachaId == GACHA_ID.TIMELIMIT) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
if ((gachaId == GACHA_TYPE.ASSIGN || gachaId == GACHA_TYPE.ACTIVITY) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
|
||||
dicGacha = getDicGachaByGachaCnt(dicGacha, historyCount);
|
||||
if (!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let gachaPull = new GachaPull(dicGacha, userGacha);
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaPull = new GachaPull(gachaId);
|
||||
gachaPull.setByUserGacha(dicGacha, userGacha, false);
|
||||
let { resultList, heroInfo, items } = gachaPull.pull(count, userHeroes);
|
||||
let { hope, floor } = gachaPull.getUserGachaParam();
|
||||
|
||||
@@ -95,14 +97,15 @@ export class GachaHandler {
|
||||
});
|
||||
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, activityId, count, resultList);
|
||||
await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, false);
|
||||
if(dicGacha.isTask) await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, false);
|
||||
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
|
||||
result: resultList,
|
||||
remainFloor: getGachaRemainFloor(gachaId, floor)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -166,11 +169,11 @@ export class GachaHandler {
|
||||
let { point, turntable, costPoint } = userGacha;
|
||||
if (point < RECRUIT.RECRUIT_BONUS_RECRUIT) return resResult(STATUS.GACHA_TURNTABLE_POINT_NOT_ENOUGH);
|
||||
|
||||
let turntablePool: { quality: number, count: number }[] = [];
|
||||
for (let { quality, count } of gameData.gachaTurntable) {
|
||||
let turntablePool: { quality: number, count: number, planId: number }[] = [];
|
||||
for (let { quality, count, planId } of gameData.gachaTurntable) {
|
||||
let myTurntable = turntable.find(cur => cur.quality == quality);
|
||||
if (!myTurntable || !myTurntable.hasGet) {
|
||||
turntablePool.push({ quality, count });
|
||||
turntablePool.push({ quality, count, planId });
|
||||
}
|
||||
}
|
||||
if (turntablePool.length <= 0) { // 重置
|
||||
@@ -178,32 +181,21 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
let randTurntable = getRandSingleEelm(turntablePool);
|
||||
let { quality, count } = randTurntable;
|
||||
// 根据品质查武将
|
||||
let pool = getAllHeroByQuality(quality);
|
||||
|
||||
let hero = getRandSingleEelm(pool);
|
||||
let contentId = gameData.gachaContentHero.get(hero);
|
||||
|
||||
// 获得或者转成碎片
|
||||
let heroInfo: { hid: number, count: number }[] = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
heroInfo.push({ hid: hero, count: 1 })
|
||||
}
|
||||
let { heroes, resultHeroes, goods } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
let resultList: GachaResult[] = [];
|
||||
for (let h of resultHeroes) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(h.hid, 1);
|
||||
resultList.push(result);
|
||||
}
|
||||
for (let g of goods) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(hero, 1);
|
||||
result.transferToPiece(g.id, g.count);
|
||||
resultList.push(result);
|
||||
}
|
||||
let { quality, count, planId } = randTurntable;
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaResults = new GachaResults();
|
||||
gachaResults.addPlan(planId);
|
||||
gachaResults.processDetail(null, count);
|
||||
let { items, heroInfo, resultList } = gachaResults.transferToFinalResult(userHeroes);
|
||||
|
||||
// 给东西
|
||||
// console.log('****', heroInfo)
|
||||
let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
// 更新数据
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, 0, count, resultList);
|
||||
|
||||
// 记录
|
||||
let myTurntable = turntable.find(cur => cur.quality == quality);
|
||||
if (!myTurntable) {
|
||||
@@ -235,13 +227,13 @@ export class GachaHandler {
|
||||
const { gachaId, activityId = 0, pickHero } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = session.get('serverId');
|
||||
if (gachaId != GACHA_ID.ASSIGN && gachaId != GACHA_ID.TIMELIMIT)
|
||||
if (gachaId != GACHA_TYPE.ASSIGN && gachaId != GACHA_TYPE.ACTIVITY)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let dicHero = gameData.hero.get(pickHero);
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let heroes: number[] = [];
|
||||
if (gachaId == GACHA_ID.TIMELIMIT) {
|
||||
if (gachaId == GACHA_TYPE.ACTIVITY) {
|
||||
let activityData = await getActivityById(activityId);
|
||||
if (!activityData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
@@ -299,7 +291,7 @@ export class GachaHandler {
|
||||
if (index == -1) return resResult(STATUS.GACHA_CAN_NOT_PICK);
|
||||
let { pieceId } = dicHero;
|
||||
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL, 0);
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_TYPE.NORMAL, 0);
|
||||
if (shouldRefresh(refVisitedTime, new Date())) {
|
||||
visitedHero = [];
|
||||
refVisitedTime = getZeroPointD();
|
||||
@@ -312,7 +304,7 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
visitedHero.push(hid);
|
||||
let userGacha = await UserGachaModel.updateInfo(roleId, GACHA_ID.NORMAL, 0, { visitedHero, refVisitedTime });
|
||||
let userGacha = await UserGachaModel.updateInfo(roleId, GACHA_TYPE.NORMAL, 0, { visitedHero, refVisitedTime });
|
||||
let goods = await addItems(roleId, roleName, sid, [{ id: pieceId, count: RECRUIT.RECRUIT_SHARD_LIMIT }], ITEM_CHANGE_REASON.VISIT_HERO);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -333,7 +325,7 @@ export class GachaHandler {
|
||||
let { gachaHasGuide } = await RoleModel.findByRoleId(roleId, 'gachaHasGuide');
|
||||
let guideCount = 0, guideResultList = [], candidates = [];
|
||||
if(!gachaHasGuide) {
|
||||
const userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
const userGacha = await UserGachaModel.findByRole(roleId, GACHA_TYPE.NORMAL);
|
||||
({ guideCount = 0, guideResultList = [], candidates = [] } = userGacha);
|
||||
}
|
||||
|
||||
@@ -354,11 +346,11 @@ export class GachaHandler {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const sid: string = session.get('sid');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
const count = 10;
|
||||
const gachaId = getGuideGachaId();
|
||||
const dicGacha = gameData.gacha.get(gachaId);
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_TYPE.NORMAL);
|
||||
let { guideCount = 0 } = userGacha;
|
||||
if(guideCount >= RECRUIT.RECRUIT_FIRST_RECRUIT) return resResult(STATUS.GACHA_GUIDE_PULL_CNT_LACK);
|
||||
|
||||
@@ -370,8 +362,7 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaPull = new GachaPull(gachaId);
|
||||
gachaPull.setByUserGacha(dicGacha, userGacha, true);
|
||||
let gachaPull = new GachaPull(dicGacha, userGacha);
|
||||
let { resultList } = gachaPull.pull(count, userHeroes);
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultList: resultList, guideCount: guideCount + 1 })
|
||||
@@ -391,9 +382,9 @@ export class GachaHandler {
|
||||
async saveToCandidates(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
const gachaId = getGuideGachaId();
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
let { guideResultList, candidates = [], guideCount } = userGacha;
|
||||
|
||||
let index = candidates.findIndex(cur => cur.id == id);
|
||||
@@ -425,17 +416,18 @@ export class GachaHandler {
|
||||
const roleName: string = session.get('roleName');
|
||||
const serverId: number = session.get('serverId');
|
||||
const sid: string = session.get('sid');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
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, GACHA_ID.NORMAL);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId);
|
||||
let { guideResultList = [], candidates = [], } = userGacha;
|
||||
|
||||
let simpleResult: { contentId: number, hid: number }[] = []
|
||||
let simpleResult: SimpleResult[] = []
|
||||
if(id == 0) {
|
||||
if(guideResultList.length <= 0) {
|
||||
return resResult(STATUS.GACHA_GUIDE_NOT_DO);
|
||||
@@ -448,8 +440,9 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let gachaPull = new GachaPull(gachaId);
|
||||
let { items, heroInfo, resultList } = gachaPull.pullBySimpleResult(simpleResult, userHeroes);
|
||||
let results = new GachaResults();
|
||||
results.addBySimpleResult(simpleResult);
|
||||
let { items, heroInfo, resultList } = results.transferToFinalResult(userHeroes);
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultCount: count });
|
||||
|
||||
@@ -462,7 +455,7 @@ export class GachaHandler {
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, 0, count, resultList);
|
||||
|
||||
// 任务
|
||||
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,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Application, BackendSession, HandlerService, } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, GACHA_ID, ITEM_CHANGE_REASON } from '../../../consts';
|
||||
import { STATUS, GACHA_TYPE, ITEM_CHANGE_REASON } from '../../../consts';
|
||||
import { getPlayerNewHeroGachaData } from '../../../services/activity/newHeroGachaService';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
@@ -62,50 +62,50 @@ export class NewHeroGachaHandler {
|
||||
* @param {BackendSession} session
|
||||
* @memberof NewHeroGachaHandler
|
||||
*/
|
||||
async pull(msg: { activityId: number, hid: number, count: number }, session: BackendSession) {
|
||||
const { activityId, hid, count } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
// async pull(msg: { activityId: number, hid: number, count: number }, session: BackendSession) {
|
||||
// const { activityId, hid, count } = msg;
|
||||
// const roleId = session.get('roleId');
|
||||
// const serverId = session.get('serverId');
|
||||
// const sid = session.get('sid');
|
||||
// const roleName = session.get('roleName');
|
||||
|
||||
if(count < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
// if(count < 0) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let playerData = await getPlayerNewHeroGachaData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
// let playerData = await getPlayerNewHeroGachaData(activityId, serverId, roleId)
|
||||
// if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
let item = playerData.findItem(hid);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
// let item = playerData.findItem(hid);
|
||||
// if (!item) {
|
||||
// return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
// }
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
// let userHeroes = await HeroModel.findByRole(roleId);
|
||||
|
||||
let gachaPull = new GachaPull(GACHA_ID.TIMELIMIT);
|
||||
gachaPull.setByActivity(item);
|
||||
let { items, heroInfo, resultList } = gachaPull.pull(count, userHeroes);
|
||||
let { hasGetFloor, floorCount } = gachaPull.getActivityParam();
|
||||
// let gachaPull = new GachaPull(GACHA_TYPE.TIMELIMIT);
|
||||
// gachaPull.setByActivity(item);
|
||||
// let { items, heroInfo, resultList } = gachaPull.pull(count, userHeroes);
|
||||
// let { hasGetFloor, floorCount } = gachaPull.getActivityParam();
|
||||
|
||||
// 消耗东西
|
||||
let cost = item.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL);
|
||||
if (!costResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
|
||||
// // 消耗东西
|
||||
// let cost = item.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
// let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL);
|
||||
// if (!costResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
|
||||
|
||||
//记录数据
|
||||
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, floorCount, JSON.stringify(resultList), hasGetFloor);
|
||||
// //记录数据
|
||||
// await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, floorCount, JSON.stringify(resultList), hasGetFloor);
|
||||
|
||||
// 给东西
|
||||
let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
//固定奖励
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.commonReward);
|
||||
let newRewardParamArr: Array<RewardParam> = rewardParamArr.map(obj => { return { id: obj.id, type: obj.type, count: obj.count * count } });
|
||||
let commonResult = await addReward(roleId, roleName, sid, serverId, newRewardParamArr, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL)
|
||||
// // 给东西
|
||||
// let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
// await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.GACHA_ITEMS);
|
||||
// //固定奖励
|
||||
// let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.commonReward);
|
||||
// let newRewardParamArr: Array<RewardParam> = rewardParamArr.map(obj => { return { id: obj.id, type: obj.type, count: obj.count * count } });
|
||||
// let commonResult = await addReward(roleId, roleName, sid, serverId, newRewardParamArr, ITEM_CHANGE_REASON.NEW_HERO_GACHA_PULL)
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
hid, activityId, count, randomReward: { heroes: resultHeroes.map(cur => ({hid: cur.hid})), result: resultList }, commonReward: commonResult
|
||||
// return resResult(STATUS.SUCCESS, {
|
||||
// hid, activityId, count, randomReward: { heroes: resultHeroes.map(cur => ({hid: cur.hid})), result: resultList }, commonReward: commonResult
|
||||
|
||||
});
|
||||
}
|
||||
// });
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user