✨ feat(抽卡): 宝物抽卡逻辑
This commit is contained in:
@@ -1,7 +1,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 { gameData, getDefArtifactByGid } from "../../../pubUtils/data";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, GachaResults, getDicGachaByGachaCnt, getNormalGachaId, getDicGachas } from "../../../services/activity/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
@@ -144,18 +144,26 @@ export class GachaHandler {
|
||||
async setHope(msg: { gachaId: number, hope: { id: number, hid: number }[] }, session: BackendSession) {
|
||||
const { gachaId, hope } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
let dicGacha = gameData.gacha.get(gachaId);
|
||||
if (!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
for (let { hid } of hope) {
|
||||
if (hid != 0) {
|
||||
if (dicGacha.gachaType == GACHA_TYPE.NORMAL && hid != 0) {
|
||||
let dicRecruit = gameData.recruit.get(hid);
|
||||
if (!dicRecruit || !dicRecruit.canHope) {
|
||||
return resResult(STATUS.GACHA_HOPE_NOT_GOLD);
|
||||
}
|
||||
}
|
||||
if (dicGacha.gachaType == GACHA_TYPE.ARTIFACT && hid != 0) {
|
||||
let dicArtifact = getDefArtifactByGid(hid);
|
||||
if (!dicArtifact || !dicArtifact.canHope) {
|
||||
return resResult(STATUS.GACHA_HOPE_NOT_GOLD);
|
||||
}
|
||||
}
|
||||
}
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, 0);
|
||||
let { hope: userHope = []} = await refreshGacha(gameData.gacha.get(gachaId), userGacha);
|
||||
for (let { id, hid } of hope) {
|
||||
for (let { id, hid = 0 } of hope) {
|
||||
let curHope = userHope.find(cur => cur.id == id);
|
||||
if(curHope) {
|
||||
if(curHope.hasGet) {
|
||||
|
||||
@@ -118,7 +118,7 @@ class PlayerGachaRecord {
|
||||
let userHope = this.hope.find(cur => cur.hid == hid);
|
||||
if(userHope && !userHope.hasGet) userHope.hasGet = true;
|
||||
}
|
||||
|
||||
|
||||
public getUserGachaParam() {
|
||||
return { hope: this.hope, floor: this.floor }
|
||||
}
|
||||
@@ -464,7 +464,7 @@ export class GachaPull {
|
||||
|
||||
// 心愿单
|
||||
private processHope() {
|
||||
if(this.gachaType != GACHA_TYPE.NORMAL) return;
|
||||
if(this.gachaType != GACHA_TYPE.NORMAL && this.gachaType != GACHA_TYPE.ARTIFACT) return;
|
||||
for(let gachaResult of this.result.list) {
|
||||
if(gachaResult.heroQuality != HERO_QUALITY_TYPE.GOLD) continue; // 只有橙将
|
||||
let { dic: { id: randHopePosition } } = getRandEelmWithWeight(gameData.gachaHope);
|
||||
|
||||
@@ -969,6 +969,7 @@ export enum GACHA_TYPE {
|
||||
GUIDE = 4, // 限时
|
||||
ACTIVITY = 5, // 新武将活动
|
||||
TAUTOR = 6, // 百家争鸣祈灵
|
||||
ARTIFACT = 7, // 宝物招募
|
||||
}
|
||||
|
||||
export enum GACHA_PLAN_TYPE {
|
||||
|
||||
@@ -30,6 +30,8 @@ export interface DicArtifact {
|
||||
readonly lvAttrPlan: number;
|
||||
// 升品配置方案
|
||||
readonly qualityAttrPlan: number;
|
||||
// 是否可以许愿
|
||||
readonly canHope: number;
|
||||
}
|
||||
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
@@ -47,6 +49,7 @@ const DicArtifactKeys: KeysEnum<DicArtifact> = {
|
||||
seids: true,
|
||||
lvAttrPlan: true,
|
||||
qualityAttrPlan: true,
|
||||
canHope: true
|
||||
}
|
||||
export const dicArtifact = new Map<number, DicArtifact>();
|
||||
export const dicArtifactByGid = new Map<number, number>();
|
||||
|
||||
Reference in New Issue
Block a user