🐞 fix(抽卡): 首次十连必出ssr
This commit is contained in:
@@ -3,7 +3,7 @@ import { resResult, shouldRefresh, getRandSingleEelm, getGachaRemainFloor } from
|
||||
import { STATUS, GACHA_TYPE, HERO_QUALITY_TYPE, TASK_TYPE, ITEM_CHANGE_REASON, } from "../../../consts";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, GachaResults, getDicGachaByGachaCnt, getNormalGachaId } from "../../../services/activity/gachaService";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, GachaResults, getDicGachaByGachaCnt, getNormalGachaId, getDicGachas } from "../../../services/activity/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { handleCost, addItems } from "../../../services/role/rewardService";
|
||||
@@ -16,6 +16,9 @@ import { createHeroes } from "../../../services/role/createHero";
|
||||
import { getGuideGachaData } from "../../../services/activity/gachaService";
|
||||
import { getPlayerNewHeroGachaData } from "../../../services/activity/newHeroService";
|
||||
import { isHeroHidden } from "../../../services/dataService";
|
||||
import { GachaResultIndb } from "../../../domain/activityField/gachaField";
|
||||
import { CreateHeroParam } from "../../../domain/roleField/hero";
|
||||
import { ItemInter, RewardInter } from "../../../pubUtils/interface";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -58,34 +61,45 @@ export class GachaHandler {
|
||||
if (!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, activityId);
|
||||
userGacha = await refreshGacha(dicGacha, userGacha);
|
||||
let { freeCount, point, pickHero, refFreeTime, count: historyCount } = userGacha;
|
||||
let { freeCount, pickHero, count: historyCount, hope, floor } = userGacha;
|
||||
if ((dicGacha.gachaType == GACHA_TYPE.ASSIGN || dicGacha.gachaType == GACHA_TYPE.ACTIVITY) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
|
||||
dicGacha = getDicGachaByGachaCnt(dicGacha, historyCount);
|
||||
if (!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicGacha.count.includes(count)) return resResult(STATUS.GACHA_IS_LOCK);
|
||||
|
||||
let gachaPull = new GachaPull(dicGacha, userGacha);
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let { resultList, heroInfo, items } = gachaPull.pull(count, userHeroes);
|
||||
let { hope, floor } = gachaPull.getUserGachaParam();
|
||||
|
||||
let costNum = count;
|
||||
if (count == 1 && dicGacha.free.count > 0) { // 单抽的时候免费
|
||||
if (count > dicGacha.free.count - freeCount) {
|
||||
costNum = count - dicGacha.free.count + freeCount;
|
||||
freeCount = dicGacha.free.count;
|
||||
} else {
|
||||
costNum = 0;
|
||||
freeCount += count;
|
||||
let resultList: GachaResultIndb[] = [], heroInfo: CreateHeroParam[] = [], items: RewardInter[] = [], consume: ItemInter[] = [];
|
||||
for(let { dic, min, max } of getDicGachas(dicGacha.gachaType, historyCount, count)) {
|
||||
console.log('##########', dic, min, max)
|
||||
let _count = max + 1 - min;
|
||||
let gachaPull = new GachaPull(dic, { hope, floor, pickHero });
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
let { resultList: _resultList, heroInfo: _heroInfo, items: _items } = gachaPull.pull(_count, userHeroes);
|
||||
let { hope: _hope, floor: _floor } = gachaPull.getUserGachaParam();
|
||||
resultList.push(..._resultList); heroInfo.push(..._heroInfo); items.push(..._items);
|
||||
hope = _hope; floor = _floor;
|
||||
|
||||
let costNum = _count;
|
||||
if (count == 1 && dic.free.count > 0) { // 单抽的时候免费
|
||||
if (count > dic.free.count - freeCount) {
|
||||
costNum = _count - dic.free.count + freeCount;
|
||||
freeCount = dic.free.count;
|
||||
} else {
|
||||
costNum = 0;
|
||||
freeCount += _count;
|
||||
}
|
||||
}
|
||||
// 消耗东西
|
||||
if (costNum > 0) {
|
||||
let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * costNum } });
|
||||
consume.push(...cost);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('##### consume', consume)
|
||||
|
||||
// 消耗东西
|
||||
if (costNum > 0) {
|
||||
let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * costNum } });
|
||||
let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.GACHA_PULL);
|
||||
if (consume.length > 0) {
|
||||
let costResult = await handleCost(roleId, sid, consume, ITEM_CHANGE_REASON.GACHA_PULL);
|
||||
if (!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
// 给东西
|
||||
// console.log('****', heroInfo)
|
||||
let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
@@ -474,7 +488,7 @@ export class GachaHandler {
|
||||
function cal(num: number) {
|
||||
for(let i = 0; i < 200; i++) {
|
||||
console.log(num, i)
|
||||
let gachaPull = new GachaPull(dicGacha, { ...new UserGachaModel().toJSON(), floor, hope, pickHero: 1 });
|
||||
let gachaPull = new GachaPull(dicGacha, { floor, hope, pickHero: 1 });
|
||||
let { resultList } = gachaPull.pull(10, []);
|
||||
let { hope: _hope, floor: _floor } = gachaPull.getUserGachaParam();
|
||||
floor = _floor;
|
||||
|
||||
Reference in New Issue
Block a user