feat(mission): 新增装备和商店刷新功能,重构抽卡逻辑

1. 新增按权重抽取装备卡的工具函数,支持去重后补齐
2. 重构任务界面卡牌组件:
   - 拆分英雄/装备/商店面板节点绑定,调整属性顺序
   - 新增装备和商店刷新按钮的交互逻辑
   - 替换原固定加载装备/商品列表为按权重随机抽取3个
3. 重构技能卡牌组件,改为技能商店卡项实现,简化原有逻辑
4. 修复prefab中的节点属性偏移和引用关系
This commit is contained in:
panFD
2026-07-25 21:44:17 +08:00
parent 9c520cf917
commit ffafefcc72
4 changed files with 393 additions and 387 deletions

View File

@@ -116,6 +116,46 @@ export const EquipPoolList: CardConfig[] = EquipRawList.map(data => ({
trigger_type: CardTriggerType.Field,
}));
/**
* 按权重抽取 N 张装备卡unique 保证一次刷新内不重复,不足时允许重复补齐)。
* @param count 需要抽取的数量
*/
export function drawEquipCards(count: number): CardConfig[] {
const safeCount = Math.max(0, Math.floor(count));
if (EquipPoolList.length === 0 || safeCount <= 0) return [];
const picked: CardConfig[] = [];
let available = [...EquipPoolList];
while (picked.length < safeCount) {
if (available.length === 0) break;
const pick = weightedPick(available);
if (!pick) break;
picked.push(pick);
available = available.filter(c => c.uuid !== pick.uuid);
}
// 不足时允许重复补齐
const filled = [...picked];
while (filled.length < safeCount) {
const fallback = weightedPick(EquipPoolList);
if (!fallback) break;
filled.push(fallback);
}
return filled;
}
/** 单次按权重抽取一张卡 */
function weightedPick(cards: CardConfig[]): CardConfig | null {
if (cards.length === 0) return null;
const totalWeight = cards.reduce((total, card) => total + (card.weight ?? 0), 0);
let random = Math.random() * totalWeight;
for (const card of cards) {
random -= (card.weight ?? 0);
if (random <= 0) return card;
}
return cards[cards.length - 1];
}
/**
* 按 UUID 查找装备卡配置
* @param uuid 装备卡 UUID