feat(hero): add hero upgrade function

1. 新增英雄升级相关UI控件与事件流程
2. 实现升级消耗计算与统一扣费逻辑
3. 添加升级预览确认弹窗与属性成长展示
4. 开放tryUpgradeHeroByEid与applyHeroLevel为公共方法
This commit is contained in:
panFD
2026-08-04 22:18:20 +08:00
parent 153e0e9a1f
commit 4938e8468e
5 changed files with 153 additions and 4 deletions

View File

@@ -371,6 +371,7 @@ export class MissionCardComp extends CCComp {
oops.message.on(GameEvent.ShowSmallTip, this.onShowSmallTip, this);
oops.message.on(GameEvent.CardUsed, this.onCardUsed, this);
oops.message.on(GameEvent.HeroBoxEmptyClick, this.onHeroBoxEmptyClick, this);
oops.message.on(GameEvent.HeroUpgrade, this.onHeroUpgrade, this);
/** 按钮触控事件:抽卡 */
this.cards_chou?.on(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
@@ -614,6 +615,7 @@ export class MissionCardComp extends CCComp {
oops.message.off(GameEvent.ShowSmallTip, this.onShowSmallTip, this);
oops.message.off(GameEvent.CardUsed, this.onCardUsed, this);
oops.message.off(GameEvent.HeroBoxEmptyClick, this.onHeroBoxEmptyClick, this);
oops.message.off(GameEvent.HeroUpgrade, this.onHeroUpgrade, this);
if (this.cards_chou && this.cards_chou.isValid) {
this.cards_chou.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
this.cards_chou.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
@@ -694,6 +696,28 @@ export class MissionCardComp extends CCComp {
this.refreshHeroBoxSlots();
}
/**
* 英雄面板升级请求回调(由 HeroBoxComp 确认弹窗后派发)。
* 扣费成功后按 eid 精确升级;金币不足或不可升级时 toast 提示。
*/
private onHeroUpgrade(event: string, args: any) {
const payload = args ?? event;
const eid: number = payload?.eid ?? 0;
if (!eid) return;
const actor = this.queryAliveHeroActors().find(item => item.eid === eid);
if (!actor) return;
if (actor.model.lv >= FightSet.HERO_MAX_LV) {
oops.gui.toast(`已达最高等级`);
return;
}
// 统一经济管理入口:按当前等级扣费
if (!MissionEconomy.executeUpgradeCost(actor.model.lv)) {
oops.gui.toast(`金币不足`);
return;
}
this.tryUpgradeHeroByEid(eid);
}
/** 英雄升级事件回调:刷新英雄信息盒显示 */
private onHeroLvUp() {
this.refreshHeroBoxSlots();
@@ -1818,7 +1842,7 @@ export class MissionCardComp extends CCComp {
* @param heroEid 要升级的英雄实体 eid
* @returns true = 升级成功
*/
private tryUpgradeHeroByEid(heroEid: number): boolean {
public tryUpgradeHeroByEid(heroEid: number): boolean {
if (!heroEid) return false;
const actor = this.queryAliveHeroActors().find(item => item.eid === heroEid);
if (!actor) return false;
@@ -1835,7 +1859,7 @@ export class MissionCardComp extends CCComp {
* 应用英雄等级变化(属性按 HERO_LV_MULTIPLIER 重新计算)。
* 沿用旧版本 SkillLvUp 的技能等级映射规则。
*/
private applyHeroLevel(model: HeroAttrsComp, targetLv: number) {
public applyHeroLevel(model: HeroAttrsComp, targetLv: number) {
const hero = HeroInfo[model.hero_uuid];
if (!hero) return;
const nextLv = Math.max(1, Math.min(FightSet.HERO_MAX_LV, Math.floor(targetLv)));