🐞 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;
|
||||
|
||||
@@ -82,12 +82,10 @@ class PlayerGachaRecord {
|
||||
public floor: UserFloor[] = [];
|
||||
public pickHero: number = 0;
|
||||
|
||||
constructor(userGacha: UserGachaType ) {
|
||||
if(userGacha) {
|
||||
this.floor = userGacha.floor;
|
||||
this.hope = userGacha.hope;
|
||||
this.pickHero = userGacha.pickHero;
|
||||
}
|
||||
public setUserGacha(floor: UserFloor[], hope: UserHope[], pickHero: number ) {
|
||||
this.floor = floor;
|
||||
this.hope = hope;
|
||||
this.pickHero = pickHero;
|
||||
}
|
||||
|
||||
public getFloorCountById(id: number) {
|
||||
@@ -363,14 +361,15 @@ export class GachaPull {
|
||||
private floors: GachaFloor[] = []; // 保底次数
|
||||
private percent: GachaPercent;
|
||||
// 玩家数据
|
||||
private player: PlayerGachaRecord;
|
||||
private player: PlayerGachaRecord = new PlayerGachaRecord();
|
||||
// 结果
|
||||
private result = new GachaResults();
|
||||
|
||||
constructor(dicGacha: DicGacha, userGacha?: UserGachaType) {
|
||||
constructor(dicGacha: DicGacha, userGacha?: { floor: UserFloor[], hope: UserHope[], pickHero: number }) {
|
||||
this.gachaType = dicGacha.gachaType;
|
||||
this.percent = new GachaPercent(dicGacha.percent);
|
||||
this.player = new PlayerGachaRecord(userGacha);
|
||||
if(userGacha)
|
||||
this.player.setUserGacha(userGacha.floor, userGacha.hope, userGacha.pickHero);
|
||||
for(let id of dicGacha.floor) {
|
||||
let floor = new GachaFloor(id);
|
||||
if(floor && floor.id) this.floors.push(floor);
|
||||
@@ -543,6 +542,20 @@ export function getDicGachaByGachaCnt(dicGacha: DicGacha, historyCount: number)
|
||||
return null
|
||||
}
|
||||
|
||||
export function getDicGachas(gachaType: number, historyCount: number, count: number) {
|
||||
let dics: { dic: DicGacha, min: number, max: number }[] = [];
|
||||
let gachaIds = gameData.gachaByType.get(gachaType);
|
||||
for(let gachaId of gachaIds) {
|
||||
let dicGacha = gameData.gacha.get(gachaId);
|
||||
if(!dicGacha || (dicGacha.gachaCnt.min > dicGacha.gachaCnt.max && dicGacha.gachaCnt.max != -1)) continue;
|
||||
if((dicGacha.gachaCnt.max != -1 && dicGacha.gachaCnt.max <= historyCount) || dicGacha.gachaCnt.min > historyCount + count) continue; // dic的范围不包含
|
||||
let min = dicGacha.gachaCnt.min > historyCount + 1? dicGacha.gachaCnt.min: historyCount + 1;
|
||||
let max = (dicGacha.gachaCnt.max == -1 || dicGacha.gachaCnt.max > historyCount + count)? historyCount + count: dicGacha.gachaCnt.max;
|
||||
dics.push({ dic: dicGacha, min, max });
|
||||
}
|
||||
return dics.sort((a, b) => a.min - b.min);
|
||||
}
|
||||
|
||||
function isGachaCntIn(historyCount: number, min: number, max: number) {
|
||||
let nowCnt = historyCount + 1;
|
||||
return min <= nowCnt && (max >= nowCnt || max == -1);
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
"percent": "1&46|2&50|3&4",
|
||||
"percentShow": "&",
|
||||
"isTask": 1,
|
||||
"gachaCnt": "3&-1",
|
||||
"gachaCnt": "13&-1",
|
||||
"indirectId": 2,
|
||||
"showInMainPage": 1
|
||||
},
|
||||
@@ -118,5 +118,20 @@
|
||||
"gachaCnt": "1&-1",
|
||||
"indirectId": 0,
|
||||
"showInMainPage": 0
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"gachaType": 1,
|
||||
"floor": "1&7",
|
||||
"name": "元宝招募(10抽必出SSR",
|
||||
"count": "1&10",
|
||||
"free": "1&1",
|
||||
"cost": "22001&1",
|
||||
"percent": "1&46|2&50|3&4",
|
||||
"percentShow": "&",
|
||||
"isTask": 1,
|
||||
"gachaCnt": "3&12",
|
||||
"indirectId": 2,
|
||||
"showInMainPage": 0
|
||||
}
|
||||
]
|
||||
@@ -34,5 +34,11 @@
|
||||
"floorType": 5,
|
||||
"heroQuality": 4,
|
||||
"param": 1
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"floorType": 2,
|
||||
"heroQuality": 3,
|
||||
"param": 10
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user