fix(map,card): 优化卡牌抽取逻辑,新增去重机制
1. 为drawCardsByRule新增unique参数,实现抽取卡牌不重复 2. 修复 fallback 抽取时的重复问题,优先选择未抽到过的卡牌 3. 修复驻场技能卡的图标显示逻辑,使用FieldSkillSet配置
This commit is contained in:
@@ -290,14 +290,19 @@ const weightedPick = (cards: CardConfig[]): CardConfig | null => {
|
||||
return cards[cards.length - 1]
|
||||
}
|
||||
|
||||
/** 连续抽取 count 张卡,允许重复 */
|
||||
const pickCards = (cards: CardConfig[], count: number): CardConfig[] => {
|
||||
/** 连续抽取 count 张卡,允许重复或通过 unique 剔除重复 */
|
||||
const pickCards = (cards: CardConfig[], count: number, unique: boolean = false): CardConfig[] => {
|
||||
if (cards.length === 0 || count <= 0) return []
|
||||
const selected: CardConfig[] = []
|
||||
let available = [...cards]
|
||||
while (selected.length < count) {
|
||||
const pick = weightedPick(cards)
|
||||
if (available.length === 0) break
|
||||
const pick = weightedPick(available)
|
||||
if (!pick) break
|
||||
selected.push(pick)
|
||||
if (unique) {
|
||||
available = available.filter(c => c.uuid !== pick.uuid)
|
||||
}
|
||||
}
|
||||
return selected
|
||||
}
|
||||
@@ -345,6 +350,7 @@ export const drawCardsByRule = (
|
||||
heroLv?: number
|
||||
targetPoolLv?: number
|
||||
wave?: number
|
||||
unique?: boolean
|
||||
} = {}
|
||||
): CardConfig[] => {
|
||||
const count = Math.max(0, Math.floor(options.count ?? 4))
|
||||
@@ -394,6 +400,6 @@ export const drawCardsByRule = (
|
||||
})
|
||||
}
|
||||
|
||||
const picked = pickCards(pool, count)
|
||||
const picked = pickCards(pool, count, options.unique)
|
||||
return picked
|
||||
}
|
||||
|
||||
@@ -906,7 +906,8 @@ export class MissionCardComp extends CCComp {
|
||||
const cards = drawCardsByRule(this.poolLv, {
|
||||
count: 3,
|
||||
type: targetType,
|
||||
wave: currentWave
|
||||
wave: currentWave,
|
||||
unique: true // 保证技能牌不重复
|
||||
});
|
||||
|
||||
if (cards.length >= 3) return cards.slice(0, 3);
|
||||
@@ -915,10 +916,18 @@ export class MissionCardComp extends CCComp {
|
||||
const fallback = drawCardsByRule(this.poolLv, {
|
||||
count: 3,
|
||||
type: targetType,
|
||||
wave: currentWave
|
||||
wave: currentWave,
|
||||
unique: true
|
||||
});
|
||||
if (fallback.length === 0) break;
|
||||
filled.push(fallback[filled.length % fallback.length]);
|
||||
|
||||
// 如果池子数量不足,只能被迫允许重复,但尽量拿没被抽到的
|
||||
const fPick = fallback.find(c => !filled.some(fc => fc.uuid === c.uuid));
|
||||
if (fPick) {
|
||||
filled.push(fPick);
|
||||
} else {
|
||||
filled.push(fallback[filled.length % fallback.length]);
|
||||
}
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { CardConfig, CardType, CKind, CardPoolList } from "../common/config/CardSet";
|
||||
import { CardBgComp } from "./CardBgComp";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { FieldSkillSet, SkillSet } from "../common/config/SkillSet";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
@@ -272,7 +272,14 @@ export class SCardComp extends CCComp {
|
||||
if (iconNode) {
|
||||
iconNode.setScale(new Vec3(1, 1, 1));
|
||||
this.clearIconAnimation(iconNode);
|
||||
const iconId = skill?.icon || `${s_uuid}`;
|
||||
// 驻场技能卡(skill=undefined 但有 field)使用 FieldSkillSet 中的图标
|
||||
let iconId: string;
|
||||
if (!this.cardData.skill && this.cardData.field && this.cardData.field.length > 0) {
|
||||
const fieldUuid = this.cardData.field[0];
|
||||
iconId = FieldSkillSet[fieldUuid]?.icon || `${fieldUuid}`;
|
||||
} else {
|
||||
iconId = skill?.icon || `${s_uuid}`;
|
||||
}
|
||||
this.updateIcon(iconNode, iconId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user