refactor(CardSet): 简化卡牌池配置逻辑,移除动态权重计算

- 将多等级权重累积逻辑改为仅使用符合条件的最大等级配置
- 移除基于解锁等级的动态权重计算,统一使用默认权重
- 保持99级配置的兜底机制,确保低等级时的正常功能
This commit is contained in:
panw
2026-01-30 16:46:34 +08:00
parent c3fa6b6210
commit c902d9ca0a

View File

@@ -172,51 +172,33 @@ function getDefaultPool(type: CardType, level: number = 1): IPoolItem[] {
}
if (configMap) {
// 收集所有已解锁的ID (去重)
const unlockedIds = new Set<number>();
// 1. 遍历所有等级配置,收集 <= level 的项
// 1. 找到符合条件的最大等级 Key (<= level 且 != 99)
let targetKey = -1;
let maxLv = -1;
Object.keys(configMap).forEach(lvlStr => {
const lv = parseInt(lvlStr);
// 忽略 99 (默认全开) 这种特殊标记,只处理正常等级逻辑
if (lv <= level && lv !== 99) {
const ids = configMap![lv];
if (ids) {
// 计算权重:等级越高,权重越高
// 基础权重 defaultWeight
// 额外权重:(解锁等级 / 当前等级) * 基础权重 * 2
// 例如当前10级
// 1级卡权重: 100 + (1/10)*200 = 120
// 9级卡权重: 100 + (9/10)*200 = 280
// 这样新解锁的卡牌出现概率显著高于旧卡牌
const extraWeight = Math.floor((lv / Math.max(1, level)) * defaultWeight * 2);
const finalWeight = defaultWeight + extraWeight;
ids.forEach(id => {
// 如果已经存在(可能在低等级也配置了),取最大权重
const existing = items.find(i => i.id === id);
if (existing) {
existing.weight = Math.max(existing.weight, finalWeight);
} else {
items.push({ id, weight: finalWeight });
}
unlockedIds.add(id);
});
if (lv !== 99 && lv <= level) {
if (lv > maxLv) {
maxLv = lv;
targetKey = lv;
}
}
});
// 2. 如果当前等级没有任何解锁项,且存在 99 号默认配置,则回退使用 99 号配置
// 这种行为保持了原有逻辑的"兜底"特性,但更智能
if (unlockedIds.size === 0 && configMap[99]) {
// 2. 如果找到了目标等级配置,则使用该配置
if (targetKey !== -1 && configMap[targetKey]) {
const ids = configMap[targetKey];
ids.forEach(id => {
items.push({ id, weight: defaultWeight });
});
}
// 3. 如果没找到(等级过低),且存在 99 号默认配置,则使用 99 号配置
else if (configMap[99]) {
configMap[99].forEach(id => {
items.push({ id, weight: defaultWeight });
unlockedIds.add(id);
});
}
// 3. 构建结果 (items 已经在循环中构建好了,这里不需要再从 unlockedIds 重新构建)
// unlockedIds.forEach(id => items.push({ id, weight: defaultWeight }));
} else {
// 兜底逻辑:如果该类型没有配置表 (理论上不应发生,除非新增类型未配置)
// 这里保留原有的全量兜底逻辑作为最后的防线