fix(战斗系统): 修复伤害数值出错问题

- 修复在DamageEvent接口和DamageQueueComp缺少ext_dmg和dmg_ratio字段问题
- 修复HeroAtkSystem的伤害计算逻辑
- 优化HeroViewComp的hp_show和mp_show方法,直接使用model数据
- 默认显示血条并增加调试日志输出
- 移除冗余的debug日志,优化伤害计算流程
This commit is contained in:
2025-11-28 09:59:01 +08:00
parent 40c430546c
commit 7a7a6fa02c
4 changed files with 55 additions and 40 deletions

View File

@@ -26,6 +26,7 @@ export interface BuffInfo {
@ccclass('HeroViewComp') // 定义Cocos Creator 组件
@ecs.register('HeroView', false) // 定义ECS 组件
export class HeroViewComp extends CCComp {
private debugMode: boolean = false; // 是否启用调试模式
// ==================== View 层属性(表现相关)====================
as: HeroSpine = null!
status:String = "idle"
@@ -89,7 +90,8 @@ export class HeroViewComp extends CCComp {
this.top_node.getChildByName("hp").active = true;
this.top_node.getChildByName("mp").active = true;
// 初始隐藏血条(被攻击后才显示)
this.top_node.active = false;
this.top_node.active = true;
}
/** 初始化 UI 节点引用 */
@@ -136,8 +138,8 @@ export class HeroViewComp extends CCComp {
// ✅ 更新 UI 显示(数据由 HeroAttrSystem 更新)
// 移除了每帧调用的 hp_show改为仅在需要时调用
this.hp_show(this.model.hp, this.model.Attrs[Attrs.HP_MAX]);
this.mp_show(this.model.mp, this.model.Attrs[Attrs.MP_MAX]);
this.hp_show();
this.mp_show();
this.show_shield(this.model.shield, this.model.Attrs[Attrs.SHIELD_MAX]);
}
@@ -155,20 +157,23 @@ export class HeroViewComp extends CCComp {
}
/** 显示血量 */
private hp_show(hp: number, hp_max: number) {
private hp_show() {
// 不再基于血量是否满来决定显示状态,只更新进度条
if(!this.top_node.active) return;
let hp_progress = hp / hp_max;
this.top_node.getChildByName("hp").getComponent(ProgressBar).progress = hp_progress;
let hp=this.model.hp;
let hp_max=this.model.Attrs[Attrs.HP_MAX];
console.log("hp_show",hp,hp_max)
this.top_node.getChildByName("hp").getComponent(ProgressBar).progress = hp / hp_max;;
this.scheduleOnce(() => {
this.top_node.getChildByName("hp").getChildByName("hpb").getComponent(ProgressBar).progress = hp_progress;
this.top_node.getChildByName("hp").getChildByName("hpb").getComponent(ProgressBar).progress = hp / hp_max;;
}, 0.15);
}
/** 显示魔法值 */
private mp_show(mp: number, mp_max: number) {
private mp_show() {
if(!this.top_node.active) return
let mp=this.model.mp;
let mp_max=this.model.Attrs[Attrs.MP_MAX];
console.log("mp_show",mp,mp_max)
this.top_node.getChildByName("mp").getComponent(ProgressBar).progress = mp / mp_max;
this.scheduleOnce(() => {
this.top_node.getChildByName("mp").getChildByName("mpb").getComponent(ProgressBar).progress = mp / mp_max;
@@ -288,13 +293,13 @@ export class HeroViewComp extends CCComp {
this.heathed();
this.hp_tip(TooltipTypes.health, hp.toFixed(0));
this.top_node.active=true
this.hp_show(this.model.hp, this.model.Attrs[Attrs.HP_MAX]);
this.hp_show();
}
mp_add(mp: number = 0) {
// 生命值更新由 Model 层处理,这里只负责视图表现
this.hp_tip(TooltipTypes.addmp, mp.toFixed(0));
this.top_node.active=true
this.mp_show(this.model.mp, this.model.Attrs[Attrs.MP_MAX]);
this.mp_show();
}
alive(){
@@ -439,7 +444,7 @@ export class HeroViewComp extends CCComp {
private showDamageImmediate(damage: number, isCrit: boolean, anm:string="atked") {
if (!this.model) return;
this.hp_show(this.model.hp, this.model.Attrs[Attrs.HP_MAX]);
this.hp_show();
this.in_atked(anm, this.model.fac==FacSet.HERO?1:-1);
if (isCrit) {
this.hp_tip(TooltipTypes.crit, damage.toFixed(0));