Files
pixelheros/assets/script/game/common/config/CardSet.ts
walkpan 5ce7fb1a3b refactor: 移除Buff和Debuff卡牌类型及相关逻辑
- 删除CardType枚举中的Buff和Debuff类型
- 更新卡池描述从"英雄、技能、Buff、Debuff"改为"英雄、技能、功能"
- 移除normalizeTypeFilter函数中处理Buff/Debuff类型的特殊逻辑
2026-03-29 16:22:29 +08:00

196 lines
6.9 KiB
TypeScript

import * as exp from "constants"
/** 卡牌大类定义 */
export enum CardType {
Hero = 1,
Skill = 2,
Special = 3,
}
/** 卡池等级定义 */
export enum CardKind {
LV1 = 1,
LV2 = 2,
LV3 = 3,
LV4 = 4,
LV5 = 5,
LV6 = 6,
}
/** 通用卡牌配置 */
export interface CardConfig {
uuid: number
type: CardType
cost: number
weight: number
lv: CardKind
hero_lv?: number
}
export const CardsUpSet: Record<number, number> = {
1: 50,
2: 100,
3: 150,
4: 200,
5: 250,
}
/**初始coin数 */
export const CardInitCoins = 4
/** 卡池升级每波减免金额 */
export const CARD_POOL_UPGRADE_DISCOUNT_PER_WAVE = 10
/** 卡池默认初始等级 */
export const CARD_POOL_INIT_LEVEL = CardKind.LV1
/** 卡池等级上限 */
export const CARD_POOL_MAX_LEVEL = CardKind.LV6
/** 英雄最高等级限制 */
export const CARD_HERO_MAX_LEVEL = 3
/** 基础卡池(英雄、技能、功能) */
export const CardPoolList: CardConfig[] = [
{ uuid: 5001, type: CardType.Hero, cost: 3, weight: 25, lv: 1, hero_lv: 1 },
{ uuid: 5101, type: CardType.Hero, cost: 3, weight: 25, lv: 1, hero_lv: 1 },
{ uuid: 5201, type: CardType.Hero, cost: 3, weight: 25, lv: 1, hero_lv: 1 },
{ uuid: 5301, type: CardType.Hero, cost: 3, weight: 25, lv: 1, hero_lv: 1 },
{ uuid: 5003, type: CardType.Hero, cost: 3, weight: 25, lv: 2, hero_lv: 1 },
{ uuid: 5012, type: CardType.Hero, cost: 3, weight: 25, lv: 2, hero_lv: 1 },
{ uuid: 5302, type: CardType.Hero, cost: 3, weight: 25, lv: 2, hero_lv: 1 },
{ uuid: 5001, type: CardType.Hero, cost: 3, weight: 25, lv: 3, hero_lv: 2 },
{ uuid: 5101, type: CardType.Hero, cost: 3, weight: 25, lv: 3, hero_lv: 2 },
{ uuid: 5201, type: CardType.Hero, cost: 3, weight: 25, lv: 3, hero_lv: 2 },
{ uuid: 5301, type: CardType.Hero, cost: 3, weight: 25, lv: 3, hero_lv: 2 },
{ uuid: 5002, type: CardType.Hero, cost: 3, weight: 25, lv: 3, hero_lv: 1 },
{ uuid: 5013, type: CardType.Hero, cost: 3, weight: 25, lv: 3, hero_lv: 1 },
{ uuid: 5202, type: CardType.Hero, cost: 3, weight: 25, lv: 3, hero_lv: 1 },
{ uuid: 5003, type: CardType.Hero, cost: 3, weight: 25, lv: 4, hero_lv: 2 },
{ uuid: 5012, type: CardType.Hero, cost: 3, weight: 25, lv: 4, hero_lv: 2 },
{ uuid: 5302, type: CardType.Hero, cost: 3, weight: 25, lv: 4, hero_lv: 2 },
{ uuid: 5004, type: CardType.Hero, cost: 3, weight: 25, lv: 4, hero_lv: 1 },
{ uuid: 5104, type: CardType.Hero, cost: 3, weight: 25, lv: 4, hero_lv: 1 },
{ uuid: 5303, type: CardType.Hero, cost: 3, weight: 25, lv: 4, hero_lv: 1 },
{ uuid: 5001, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 3 },
{ uuid: 5101, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 3 },
{ uuid: 5201, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 3 },
{ uuid: 5301, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 3 },
{ uuid: 5002, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 2 },
{ uuid: 5013, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 2 },
{ uuid: 5202, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 2 },
{ uuid: 5105, type: CardType.Hero, cost: 3, weight: 25, lv: 5, hero_lv: 1 },
{ uuid: 5003, type: CardType.Hero, cost: 3, weight: 25, lv: 6, hero_lv: 3 },
{ uuid: 5012, type: CardType.Hero, cost: 3, weight: 25, lv: 6, hero_lv: 3 },
{ uuid: 5302, type: CardType.Hero, cost: 3, weight: 25, lv: 6, hero_lv: 3 },
{ uuid: 5304, type: CardType.Hero, cost: 3, weight: 25, lv: 6, hero_lv: 1 },
{ uuid: 7001, type: CardType.Special, cost: 1, weight: 20, lv: 1 },
]
/** 功能卡效果类型 */
export enum SpecialEffectType {
DrawHero = 1,
RepeatNextUse = 2,
}
/** 功能卡效果参数 */
export interface SpecialCardEffect {
type: SpecialEffectType
drawHeroCount?: number
drawHeroLv?: CardKind
repeatNextUseTimes?: number
}
/** 功能卡完整配置 */
export interface SpecialCardConfig extends CardConfig {
name: string
info: string
effect: SpecialCardEffect
}
/** 功能卡定义表 */
export const SpecialCardList: Record<number, SpecialCardConfig> = {
7001: { uuid: 7001,type: CardType.Special,cost: 6,weight: 20,lv: CardKind.LV1,name:"哈哈",info: "抽取4张等级3的英雄",
effect: {type: SpecialEffectType.DrawHero,drawHeroCount: 4,drawHeroLv: CardKind.LV3,},
},
7002: { uuid: 7002,type: CardType.Special,cost: 5,weight: 20,lv: CardKind.LV2,name:"哈哈哈", info: "重复使用下一张卡1次",
effect: {type: SpecialEffectType.RepeatNextUse,repeatNextUseTimes: 1,},
},
}
/** 规范等级到合法区间 [LV1, LV6] */
const clampCardLv = (lv: number): CardKind => {
const value = Math.floor(lv)
if (value < CARD_POOL_INIT_LEVEL) return CARD_POOL_INIT_LEVEL
if (value > CARD_POOL_MAX_LEVEL) return CARD_POOL_MAX_LEVEL
return value as CardKind
}
/** 单次按权重抽取一张卡 */
const weightedPick = (cards: CardConfig[]): CardConfig | null => {
if (cards.length === 0) return null
const totalWeight = cards.reduce((total, card) => total + card.weight, 0)
let random = Math.random() * totalWeight
for (const card of cards) {
random -= card.weight
if (random <= 0) return card
}
return cards[cards.length - 1]
}
/** 连续抽取 count 张卡,允许重复 */
const pickCards = (cards: CardConfig[], count: number): CardConfig[] => {
if (cards.length === 0 || count <= 0) return []
const selected: CardConfig[] = []
while (selected.length < count) {
const pick = weightedPick(cards)
if (!pick) break
selected.push(pick)
}
return selected
}
/** 获取指定等级可出现的基础卡池 */
export const getCardPoolByLv = (lv: number, onlyCurrentLv: boolean = false): CardConfig[] => {
const cardLv = clampCardLv(lv)
if (onlyCurrentLv) {
return CardPoolList.filter(card => card.lv === cardLv)
}
return CardPoolList.filter(card => card.lv <= cardLv)
}
const normalizeTypeFilter = (type: CardType | CardType[]): Set<CardType> => {
const list = Array.isArray(type) ? type : [type]
return new Set<CardType>(list)
}
/** 常规发牌:前 2 英雄 + 后 2 其他;支持按类型和等级模式过滤 */
export const getCardsByLv = (
lv: number,
type?: CardType | CardType[],
onlyCurrentLv: boolean = false
): CardConfig[] => {
const pool = getCardPoolByLv(lv, onlyCurrentLv)
if (type !== undefined) {
const typeSet = normalizeTypeFilter(type)
const filteredPool = pool.filter(card => typeSet.has(card.type))
return pickCards(filteredPool, 4)
}
const heroPool = pool.filter(card => card.type === CardType.Hero)
const otherPool = pool.filter(card => card.type !== CardType.Hero)
const heroes = pickCards(heroPool, 2)
const others = pickCards(otherPool, 2)
return [...heroes, ...others]
}