feat(map): 新增英雄出售事件并更新场上英雄数量UI
- 新增GameEvent.HeroSell事件枚举,在英雄出售时派发通知 - 在HInfoComp中添加事件派发代码,在MissionCardComp中注册监听更新UI - 调整英雄统计逻辑与事件派发逻辑,简化最大英雄数量获取函数 - 为多款英雄预制体添加影子显示组件
This commit is contained in:
@@ -63,6 +63,7 @@ export enum GameEvent {
|
||||
HeroUnlock = "HeroUnlock",
|
||||
MonDead = "MonDead",
|
||||
HeroDead = "HeroDead",
|
||||
HeroSell = "HeroSell",
|
||||
GOLD_UPDATE = "GOLD_UPDATE",
|
||||
DIAMOND_UPDATE = "DIAMOND_UPDATE",
|
||||
MEAT_UPDATE = "MEAT_UPDATE",
|
||||
|
||||
@@ -300,12 +300,6 @@ export class BattleEntityLifecycleSystem extends ecs.ComblockSystem
|
||||
const label = this.resolveLabel(heroAttrs);
|
||||
if (heroAttrs) {
|
||||
mLogger.log(heroAttrs.debugMode, 'BattleEntityLifecycle', `${label}离开世界: ${heroAttrs.hero_name}`);
|
||||
if (heroAttrs.fac === FacSet.HERO) {
|
||||
oops.message.dispatchEvent(GameEvent.HeroDead, {
|
||||
eid: e.eid,
|
||||
model: heroAttrs
|
||||
});
|
||||
}
|
||||
} else {
|
||||
mLogger.log(true, 'BattleEntityLifecycle', `${label}离开世界: 实体ID ${e.eid}`);
|
||||
}
|
||||
|
||||
@@ -309,6 +309,9 @@ export class HInfoComp extends CCComp {
|
||||
// 使用统一经济管理入口出售英雄(按等级计算卖价)
|
||||
MissionEconomy.executeSellHero(heroLv);
|
||||
|
||||
// 派发英雄出售事件,通知 MissionCardComp 更新场上英雄数量
|
||||
oops.message.dispatchEvent(GameEvent.HeroSell, { eid: this.eid });
|
||||
|
||||
this.isClosing = true;
|
||||
oops.gui.remove(UIID.HInfo);
|
||||
}
|
||||
|
||||
@@ -257,6 +257,7 @@ export class MissionCardComp extends CCComp {
|
||||
oops.message.on(GameEvent.CoinAdd, this.onCoinAdd, this);
|
||||
oops.message.on(GameEvent.MasterCalled, this.onMasterCalled, this);
|
||||
oops.message.on(GameEvent.HeroDead, this.onHeroDead, this);
|
||||
oops.message.on(GameEvent.HeroSell, this.onHeroSell, this);
|
||||
oops.message.on(GameEvent.UseHeroCard, this.onUseHeroCard, this);
|
||||
oops.message.on(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
||||
oops.message.on(GameEvent.CardPoolUpgrade, this.onCardPoolUpgrade, this);
|
||||
@@ -337,6 +338,7 @@ export class MissionCardComp extends CCComp {
|
||||
oops.message.off(GameEvent.CoinAdd, this.onCoinAdd, this);
|
||||
oops.message.off(GameEvent.MasterCalled, this.onMasterCalled, this);
|
||||
oops.message.off(GameEvent.HeroDead, this.onHeroDead, this);
|
||||
oops.message.off(GameEvent.HeroSell, this.onHeroSell, this);
|
||||
oops.message.off(GameEvent.UseHeroCard, this.onUseHeroCard, this);
|
||||
oops.message.off(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
||||
oops.message.off(GameEvent.CardPoolUpgrade, this.onCardPoolUpgrade, this);
|
||||
@@ -372,6 +374,11 @@ export class MissionCardComp extends CCComp {
|
||||
this.updateHeroNumUI(true, false);
|
||||
}
|
||||
|
||||
/** 英雄被出售事件回调:更新英雄数量 UI */
|
||||
private onHeroSell() {
|
||||
this.updateHeroNumUI(true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用英雄卡的 guard 校验(由 CardComp 通过 UseHeroCard 事件调用):
|
||||
* - 当前英雄数 < 上限 → 允许使用。
|
||||
@@ -847,7 +854,7 @@ export class MissionCardComp extends CCComp {
|
||||
let count = 0;
|
||||
ecs.query(ecs.allOf(HeroAttrsComp)).forEach((entity: ecs.Entity) => {
|
||||
const model = entity.get(HeroAttrsComp);
|
||||
if (model && model.fac === FacSet.HERO && !model.is_dead) {
|
||||
if (model && model.fac === FacSet.HERO ) {
|
||||
count++;
|
||||
}
|
||||
});
|
||||
@@ -972,8 +979,8 @@ export class MissionCardComp extends CCComp {
|
||||
|
||||
|
||||
private getMissionHeroMaxNum(): number {
|
||||
const missionData = this.getMissionData();
|
||||
return Math.max(FightSet.HERO_MAX_NUM, Math.floor(missionData?.hero_max_num ?? FightSet.HERO_MAX_NUM));
|
||||
|
||||
return FightSet.HERO_MAX_NUM
|
||||
}
|
||||
|
||||
private syncMissionHeroData(count?: number) {
|
||||
|
||||
Reference in New Issue
Block a user