✨ feat(抽卡): 宝物抽卡逻辑

This commit is contained in:
luying
2023-09-21 11:13:07 +08:00
parent 2dd4f15f9a
commit 32d5d23025
4 changed files with 17 additions and 5 deletions
@@ -1,7 +1,7 @@
import { Application, BackendSession, HandlerService, } from "pinus"; import { Application, BackendSession, HandlerService, } from "pinus";
import { resResult, shouldRefresh, getRandSingleEelm, getGachaRemainFloor } from "../../../pubUtils/util"; import { resResult, shouldRefresh, getRandSingleEelm, getGachaRemainFloor } from "../../../pubUtils/util";
import { STATUS, GACHA_TYPE, HERO_QUALITY_TYPE, TASK_TYPE, ITEM_CHANGE_REASON, } from "../../../consts"; 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 { UserGachaModel } from "../../../db/UserGacha";
import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, GachaResults, getDicGachaByGachaCnt, getNormalGachaId, getDicGachas } from "../../../services/activity/gachaService"; import { refreshGacha, getGachaList, getVisitedHeroList, GachaPull, GachaResults, getDicGachaByGachaCnt, getNormalGachaId, getDicGachas } from "../../../services/activity/gachaService";
import { RoleModel } from "../../../db/Role"; import { RoleModel } from "../../../db/Role";
@@ -144,18 +144,26 @@ export class GachaHandler {
async setHope(msg: { gachaId: number, hope: { id: number, hid: number }[] }, session: BackendSession) { async setHope(msg: { gachaId: number, hope: { id: number, hid: number }[] }, session: BackendSession) {
const { gachaId, hope } = msg; const { gachaId, hope } = msg;
const roleId: string = session.get('roleId'); 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) { for (let { hid } of hope) {
if (hid != 0) { if (dicGacha.gachaType == GACHA_TYPE.NORMAL && hid != 0) {
let dicRecruit = gameData.recruit.get(hid); let dicRecruit = gameData.recruit.get(hid);
if (!dicRecruit || !dicRecruit.canHope) { if (!dicRecruit || !dicRecruit.canHope) {
return resResult(STATUS.GACHA_HOPE_NOT_GOLD); 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 userGacha = await UserGachaModel.findByRole(roleId, gachaId, 0);
let { hope: userHope = []} = await refreshGacha(gameData.gacha.get(gachaId), userGacha); 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); let curHope = userHope.find(cur => cur.id == id);
if(curHope) { if(curHope) {
if(curHope.hasGet) { if(curHope.hasGet) {
@@ -464,7 +464,7 @@ export class GachaPull {
// 心愿单 // 心愿单
private processHope() { 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) { for(let gachaResult of this.result.list) {
if(gachaResult.heroQuality != HERO_QUALITY_TYPE.GOLD) continue; // 只有橙将 if(gachaResult.heroQuality != HERO_QUALITY_TYPE.GOLD) continue; // 只有橙将
let { dic: { id: randHopePosition } } = getRandEelmWithWeight(gameData.gachaHope); let { dic: { id: randHopePosition } } = getRandEelmWithWeight(gameData.gachaHope);
+1
View File
@@ -969,6 +969,7 @@ export enum GACHA_TYPE {
GUIDE = 4, // 限时 GUIDE = 4, // 限时
ACTIVITY = 5, // 新武将活动 ACTIVITY = 5, // 新武将活动
TAUTOR = 6, // 百家争鸣祈灵 TAUTOR = 6, // 百家争鸣祈灵
ARTIFACT = 7, // 宝物招募
} }
export enum GACHA_PLAN_TYPE { export enum GACHA_PLAN_TYPE {
@@ -30,6 +30,8 @@ export interface DicArtifact {
readonly lvAttrPlan: number; readonly lvAttrPlan: number;
// 升品配置方案 // 升品配置方案
readonly qualityAttrPlan: number; readonly qualityAttrPlan: number;
// 是否可以许愿
readonly canHope: number;
} }
type KeysEnum<T> = { [P in keyof Required<T>]: true }; type KeysEnum<T> = { [P in keyof Required<T>]: true };
@@ -47,6 +49,7 @@ const DicArtifactKeys: KeysEnum<DicArtifact> = {
seids: true, seids: true,
lvAttrPlan: true, lvAttrPlan: true,
qualityAttrPlan: true, qualityAttrPlan: true,
canHope: true
} }
export const dicArtifact = new Map<number, DicArtifact>(); export const dicArtifact = new Map<number, DicArtifact>();
export const dicArtifactByGid = new Map<number, number>(); export const dicArtifactByGid = new Map<number, number>();