fix(map): 修复抽卡重复英雄和英雄站位偏移问题
1. 新增英雄卡UUID去重逻辑,避免单次抽卡出现重复英雄 2. 调整英雄初始站位坐标,修正布局偏移问题 3. 统一代码格式,修复缩进和类型注解不规范问题
This commit is contained in:
@@ -98,7 +98,7 @@ export class MissionCardComp extends CCComp {
|
||||
/** 抽卡(刷新)按钮节点 */
|
||||
@property(Node)
|
||||
cards_chou: Node = null!
|
||||
|
||||
|
||||
/** 英雄卡牌池cards_node显示隐藏 */
|
||||
@property(Node)
|
||||
showHeros: Node = null!
|
||||
@@ -768,6 +768,7 @@ export class MissionCardComp extends CCComp {
|
||||
|
||||
const result: CardConfig[] = [];
|
||||
const usedUpgradeTargets = new Set<number>();
|
||||
const usedHeroUuids = new Set<number>();
|
||||
|
||||
// 必出 1 张升级卡,按 UUID 升序轮询,放在返回数组首位(对应最左侧卡槽)
|
||||
if (upgradeCards.length > 0) {
|
||||
@@ -778,23 +779,36 @@ export class MissionCardComp extends CCComp {
|
||||
usedUpgradeTargets.add(mandatory.target_hero_eid ?? 0);
|
||||
}
|
||||
|
||||
// 剩余张数从混合池抽取,排除已选升级卡 target_hero_eid
|
||||
// 剩余张数从混合池抽取,排除已选升级卡 target_hero_eid 和已选英雄卡 uuid
|
||||
const remainingCount = 3 - result.length;
|
||||
if (remainingCount > 0) {
|
||||
const remainingPool = mixedPool.filter(c => {
|
||||
if (c.type === CardType.SpecialUpgrade && c.target_hero_eid) {
|
||||
return !usedUpgradeTargets.has(c.target_hero_eid);
|
||||
}
|
||||
if (c.type === CardType.Hero) {
|
||||
return !usedHeroUuids.has(c.uuid);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const rest = this.pickMixedCards(remainingPool, remainingCount, upgradeCards);
|
||||
result.push(...rest);
|
||||
rest.forEach(c => {
|
||||
result.push(c);
|
||||
if (c.type === CardType.SpecialUpgrade && c.target_hero_eid) {
|
||||
usedUpgradeTargets.add(c.target_hero_eid);
|
||||
}
|
||||
if (c.type === CardType.Hero) {
|
||||
usedHeroUuids.add(c.uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 兜底:不足 3 张时循环补齐
|
||||
// 兜底:不足 3 张时从未使用的英雄卡中补齐,避免出现重复英雄
|
||||
while (result.length < 3) {
|
||||
if (mixedPool.length === 0) break;
|
||||
result.push(mixedPool[result.length % mixedPool.length]);
|
||||
const fillCard = availableHeroCards.find(c => !usedHeroUuids.has(c.uuid));
|
||||
if (!fillCard) break;
|
||||
result.push(fillCard);
|
||||
usedHeroUuids.add(fillCard.uuid);
|
||||
}
|
||||
return result.slice(0, 3);
|
||||
}
|
||||
@@ -802,17 +816,22 @@ export class MissionCardComp extends CCComp {
|
||||
/**
|
||||
* 从混合池中按权重抽取 n 张卡。
|
||||
* 升级卡之间强制 unique(同一个 target_hero_eid 只能出现一次)。
|
||||
* 英雄卡之间强制 unique(同一个 uuid 只能出现一次),避免同一次发牌出现重复英雄。
|
||||
*/
|
||||
private pickMixedCards(pool: CardConfig[], count: number, upgradeCards: CardConfig[]): CardConfig[] {
|
||||
if (pool.length === 0 || count <= 0) return [];
|
||||
const selected: CardConfig[] = [];
|
||||
const usedUpgradeTargets = new Set<number>();
|
||||
const usedHeroUuids = new Set<number>();
|
||||
|
||||
while (selected.length < count) {
|
||||
const available = pool.filter(c => {
|
||||
if (c.type === CardType.SpecialUpgrade && c.target_hero_eid) {
|
||||
return !usedUpgradeTargets.has(c.target_hero_eid);
|
||||
}
|
||||
if (c.type === CardType.Hero) {
|
||||
return !usedHeroUuids.has(c.uuid);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (available.length === 0) break;
|
||||
@@ -822,6 +841,9 @@ export class MissionCardComp extends CCComp {
|
||||
if (pick.type === CardType.SpecialUpgrade && pick.target_hero_eid) {
|
||||
usedUpgradeTargets.add(pick.target_hero_eid);
|
||||
}
|
||||
if (pick.type === CardType.Hero) {
|
||||
usedHeroUuids.add(pick.uuid);
|
||||
}
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
@@ -907,6 +929,7 @@ export class MissionCardComp extends CCComp {
|
||||
count: 3,
|
||||
type: CardType.Hero,
|
||||
heroType,
|
||||
unique: true, // 保证一次刷新内的英雄卡不重复
|
||||
});
|
||||
// 过滤掉场上已召唤英雄的普通英雄卡(已召唤的英雄不再重复刷出)
|
||||
const aliveHeroUuids = this.getAliveHeroUuids();
|
||||
|
||||
Reference in New Issue
Block a user