refactor(card): 升级动态升级卡的英雄绑定逻辑

将动态升级卡从绑定英雄UUID改为绑定实体EID,适配ECS实体管理模式:
1. 更新CardConfig定义,替换target_hero_uuid为target_hero_eid
2. 新增EID反查UUID的工具方法,适配渲染和交互逻辑
3. 修改抽卡、卡牌点击和使用的全流程逻辑
4. 优化升级卡生成和匹配的稳定性
This commit is contained in:
panFD
2026-07-21 00:03:44 +08:00
parent 48e0ab06c5
commit 8818ec9c3f
4 changed files with 73 additions and 66 deletions

View File

@@ -526,9 +526,12 @@ export class CardComp extends CCComp {
this.showCallBtn();
oops.message.dispatchEvent(GameEvent.CardSelected, this);
// 英雄卡 / 升级卡打开信息面板(点击替代长按)
const isUpgradeCard = this.card_type === CardType.SpecialUpgrade && !!this.cardData?.target_hero_uuid;
const isUpgradeCard = this.card_type === CardType.SpecialUpgrade && !!this.cardData?.target_hero_eid;
if (this.card_type === CardType.Hero || isUpgradeCard) {
const heroUuid = isUpgradeCard ? (this.cardData!.target_hero_uuid as number) : this.card_uuid;
// 升级卡通过 eid 反查实体得到 hero_uuid若实体已不存在则降级为本卡 uuid
const heroUuid = isUpgradeCard
? (this.queryHeroUuidByEid(this.cardData!.target_hero_eid as number) ?? this.card_uuid)
: this.card_uuid;
const heroLv = Math.max(1, this.cardData?.hero_lv ?? 1);
const poolLv = Math.max(1, this.cardData?.base_pool_lv ?? this.cardData?.pool_lv ?? 1);
oops.gui.remove(UIID.HInfo);
@@ -536,6 +539,20 @@ export class CardComp extends CCComp {
}
}
/**
* 通过 eid 反查场上英雄实体的 hero_uuid。
* 用于动态升级卡渲染:升级卡绑定的是 eid但显示需要 HeroInfo[uuid]。
* @returns 找到则返回 hero_uuid找不到实体已销毁等返回 null
*/
private queryHeroUuidByEid(eid: number): number | null {
if (!eid) return null;
const entity = ecs.getEntityByEid(eid);
if (!entity) return null;
const model = entity.get(HeroAttrsComp);
if (!model) return null;
return model.hero_uuid ?? null;
}
/**
* 其他卡牌被点击时联动隐藏本卡 call_btn。
* @param event 事件名ListenerFunc 约定的第一个参数)
@@ -639,11 +656,14 @@ export class CardComp extends CCComp {
this.node.setPosition(this.restPosition.x, this.restPosition.y, this.restPosition.z);
// 渲染参数动态升级卡SpecialUpgrade + target_hero_uuid按英雄卡样式渲染
// 使用 target_hero_uuid 对应的英雄信息(名称/AP/HP/动画),等级显示为目标等级
const isUpgradeCard = this.card_type === CardType.SpecialUpgrade && !!this.cardData.target_hero_uuid;
// 渲染参数动态升级卡SpecialUpgrade + target_hero_eid按英雄卡样式渲染
// 通过 target_hero_eid 反查实体得到 hero_uuid再用 HeroInfo 渲染名称/AP/HP/动画
const isUpgradeCard = this.card_type === CardType.SpecialUpgrade && !!this.cardData.target_hero_eid;
const renderType: CardType = isUpgradeCard ? CardType.Hero : this.card_type;
const renderUuid: number = isUpgradeCard ? (this.cardData.target_hero_uuid as number) : this.card_uuid;
// 升级卡通过 eid 反查实体得到 hero_uuid若实体已不存在则降级为本卡 uuid
const renderUuid: number = isUpgradeCard
? (this.queryHeroUuidByEid(this.cardData.target_hero_eid as number) ?? this.card_uuid)
: this.card_uuid;
const renderKind: CKind = isUpgradeCard ? CKind.Hero : this.cardData.kind;
// ---- 卡牌种类标识(近战 / 远程 / 辅助等) ----