抽卡:逻辑修复

This commit is contained in:
luying
2022-05-20 13:16:22 +08:00
parent 72739ee9cf
commit 14788c23b5
3 changed files with 25 additions and 12 deletions

View File

@@ -333,8 +333,12 @@ export class GachaHandler {
async getGuideGachaData(msg: {}, session: BackendSession) {
const { } = msg;
const roleId: string = session.get('roleId');
const userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
let { guideCount = 0, guideResultList = [], candidates = [] } = userGacha;
let { gachaHasGuide } = await RoleModel.findByRoleId(roleId, 'gachaHasGuide');
let guideCount = 0, guideResultList = [], candidates = [];
if(!gachaHasGuide) {
const userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
({ guideCount = 0, guideResultList = [], candidates = [] } = userGacha);
}
return resResult(STATUS.SUCCESS, {
guideCount,
@@ -370,7 +374,7 @@ export class GachaHandler {
let userHeroes = await HeroModel.findByRole(roleId);
let gachaPull = new GachaPull(gachaId);
gachaPull.setByUserGacha({...dicGacha, floorReward: 0}, userGacha, true);
gachaPull.setByUserGacha(dicGacha, userGacha, true);
let { resultList } = gachaPull.pull(count, userHeroes);
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultList: resultList, guideCount: guideCount + 1 })

View File

@@ -190,8 +190,8 @@ class GachaResults {
export class GachaPull {
private gachaType: GACHA_ID; // 抽卡类型
// 字典
private dicFloor: Map<GACHA_FLOOR_TYPE, number>; // 保底次数
private percent: { id: number, weight: number, goodId?: number }[];
private dicFloor: Map<GACHA_FLOOR_TYPE, number> = new Map(); // 保底次数
private percent: { id: number, weight: number, goodId?: number }[] = [];
private bigReward: { id: number, weight: number, goodId?: number }; // 保底的一项percent中的一项
// 玩家数据
private player: PlayerGachaRecord;
@@ -262,6 +262,7 @@ export class GachaPull {
break;
case GACHA_FLOOR_TYPE.ASSIGN:
this.setAssignFloor(floorCount);
break;
}
}
}
@@ -292,18 +293,20 @@ export class GachaPull {
public setAssignFloor(dicFloorCount: number) {
let floorType = GACHA_FLOOR_TYPE.ASSIGN;
let { floorCount: historyCount, hasGetFloor } = this.player.getFloorCountByFloorType(floorType);
console.log('#### gachaResult', this.result.list)
for(let gachaResult of this.result.list) {
let isTarget = this.bigReward.id == gachaResult.contentId;
console.log('#### setAssignFloor', historyCount, dicFloorCount, isTarget)
if(++historyCount >= dicFloorCount || isTarget) {
console.log('#### setAssignFloor', isTarget, hasGetFloor)
if(hasGetFloor) { // 已经获得过一次保底了, 不给,换个给
gachaResult.setContentId(getGachaContentOfHeroQuality(HERO_QUALITY_TYPE.PURPLE));
} else {
gachaResult.setContentId(this.bigReward.id, this.bigReward.goodId);
hasGetFloor = false;
hasGetFloor = true;
}
gachaResult.setContentId(this.bigReward.id, this.bigReward.goodId);
historyCount = 0;
}
console.log('#### setAssignFloor after', historyCount, dicFloorCount)
if(historyCount >= dicFloorCount) {
hasGetFloor = false;
historyCount = 0;
@@ -342,8 +345,11 @@ export class GachaPull {
public pullBySimpleResult(simpleResult: {contentId: number, hid: number }[], userHeroes: HeroType[]) {
let results = simpleResult.map(obj => {
return new GachaResult(obj.contentId, obj.hid);
let gachaResult = new GachaResult(obj.contentId);
gachaResult.setHidOrGid(obj.hid);
return gachaResult;
});
return this.transferToFinalResult(results, userHeroes);
}
@@ -398,7 +404,8 @@ class ContentDetail {
}
public getResult() {
switch(this.contentId) {
let { type } = gameData.gachaContent.get(this.contentId);
switch(type) {
case GACHA_CONTENT_TYPE.HERO:
return this.randomHeroByQuality(this.param[0]);
case GACHA_CONTENT_TYPE.HERO_PIECE:
@@ -407,6 +414,8 @@ class ContentDetail {
return this.randomStoneByLv(this.param[0]);
case GACHA_CONTENT_TYPE.ITEMS:
return getRandSingleEelm(this.param);
default:
return 0
}
}

View File

@@ -141,13 +141,13 @@ export class GachaResult {
}
setHidOrGid(id: number, count?: number) {
let dicGachaContent = gameData.gachaContent.get(id);
let dicGachaContent = gameData.gachaContent.get(this.contentId);
if(!dicGachaContent) return;
if(dicGachaContent.type == GACHA_CONTENT_TYPE.HERO) {
this.setHero(id);
} else {
this.setItem(id, count);
this.setItem(id, count||dicGachaContent.count);
}
}