fix(战斗系统): 修复角色状态切换和击退效果的问题

- 在HeroMove和MonMove系统中增加攻击状态检查,避免攻击时被错误切换为待机状态
- 为HeroAtkSystem添加受击者击退效果
- 优化HeroViewComp的击退逻辑,包括英雄和怪物,并修复重复触发问题
- 修复怪物死亡后状态切换问题
This commit is contained in:
walkpan
2026-01-03 13:41:08 +08:00
parent 1cce4ce361
commit 08c153ee5d
4 changed files with 34 additions and 13 deletions

View File

@@ -176,6 +176,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
TAttrsComp.hp -= damage; // 应用伤害到数据层
// 受击者产生击退效果
if (damage > 0 && targetView) {
targetView.back();
}
smc.updateHeroInfo(TAttrsComp); // 更新英雄数据到 VM
if (this.debugMode) {
const casterName = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_name || "未知";

View File

@@ -123,7 +123,9 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
move.direction = 1;
}
} else {
view.status_change("idle");
if (!model.is_atking) {
view.status_change("idle");
}
// 因为敌人在面前而暂时停止不设置moving为false保持检查状态
}
}

View File

@@ -316,6 +316,7 @@ export class HeroViewComp extends CCComp {
}
/** 状态切换(动画) */
status_change(type:string){
if(this.status === type) return;
this.status = type;
if(this.model.is_dead || this.model.is_reviving) return
if(type === "idle"){
@@ -453,10 +454,10 @@ export class HeroViewComp extends CCComp {
back(){
// 🔥 防止重复调用后退动画
if (this.isBackingUp) return;
this.isBackingUp = true; // 🔥 设置后退状态
if(this.model.fac==FacSet.MON) {
this.isBackingUp = true; // 🔥 设置后退状态
let tx=this.node.position.x+30
let tx=this.node.position.x+5
if(tx > 320) tx=320
tween(this.node)
.to(0.1, { position:v3(tx,this.node.position.y,0)})
@@ -465,12 +466,17 @@ export class HeroViewComp extends CCComp {
})
.start()
}
//英雄不再后退
// if(this.model.fac==FacSet.HERO) {
// let tx=this.node.position.x-30
// if(tx < -320) tx=-320
// tween(this.node).to(0.1, { position:v3(tx,this.node.position.y,0)}).start()
// }
if(this.model.fac==FacSet.HERO) {
let tx=this.node.position.x-5
if(tx < -320) tx=-320
tween(this.node)
.to(0.1, { position:v3(tx,this.node.position.y,0)})
.call(() => {
this.isBackingUp = false; // 🔥 动画完成后重置状态
})
.start()
}
}
// 伤害计算和战斗逻辑已迁移到 HeroBattleSystem

View File

@@ -41,12 +41,18 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
update(e: ecs.Entity) {
if (!smc.mission.play || smc.mission.pause) return;
const view = e.get(HeroViewComp);
// 如果英雄死亡停止怪物行动标志为true则停止怪物移动
if (smc.mission.stop_mon_action) return;
if (smc.mission.stop_mon_action) {
view.status_change("idle");
return;
}
const move = e.get(MonMoveComp);
const model = e.get(HeroAttrsComp);
const view = e.get(HeroViewComp);
// const view = e.get(HeroViewComp);
// 只处理怪物
if (model.fac !== FacSet.MON) return;
@@ -91,7 +97,9 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
move.moving = false;
}
} else {
view.status_change("idle");
if (!model.is_atking) {
view.status_change("idle");
}
}
}