feat(HeroAtkSystem): Integrate visual feedback for attack and death events

- Added HeroViewComp integration to trigger visual effects during attacks and upon hero death.
- Updated doAttack method to call do_atked and do_dead methods in HeroViewComp for enhanced visual representation.
- Cleaned up console log messages for better clarity in debugging.
This commit is contained in:
2025-10-30 11:06:58 +08:00
parent 29e8b7e8e7
commit 1281cbd32d
2 changed files with 61 additions and 44 deletions

View File

@@ -4,6 +4,7 @@ import { Attrs } from "../common/config/HeroAttrs";
import { FightSet } from "../common/config/Mission";
import { SkillSet } from "../common/config/SkillSet";
import { HeroAttrsComp } from "./HeroAttrsComp";
import { HeroViewComp } from "./HeroViewComp";
/** 业务层对象 */
@ecs.register('HeroAtk')
@@ -46,6 +47,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
*/
public doAttack(target: ecs.Entity, remainingDamage: number, attackerAttrs: any, skillId: number): number {
const targetModel = target.get(HeroAttrsComp);
const targetView = target.get(HeroViewComp);
if (!targetModel || targetModel.is_dead) return 0;
// 获取技能配置
@@ -56,6 +58,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
// 闪避判定
if (this.checkDodge(targetModel)) {
// TODO: 触发闪避视图表现
return 0;
}
@@ -75,17 +78,26 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
if (damage <= 0) return 0;
// 应用伤害
// 应用伤害到数据层
targetModel.hp -= damage;
targetModel.atked_count++;
// ✅ 触发视图层表现(伤害数字、受击动画、后退)
if (targetView) {
targetView.do_atked(damage, isCrit, skillId);
}
// 检查死亡
if (targetModel.hp <= 0) {
this.doDead(target);
// ✅ 触发死亡视图表现
if (targetView) {
targetView.do_dead();
}
}
if (this.debugMode) {
console.log(`[HeroBattleSystem] ${targetModel.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`);
console.log(`[HeroAtkSystem] ${targetModel.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`);
}
return damage;