使用ecs系统进行重构
This commit is contained in:
47
assets/script/game/skill/SkillEffectSystem.ts
Normal file
47
assets/script/game/skill/SkillEffectSystem.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
@ecs.registerSystem()
|
||||
export class SkillEffectSystem extends ecs.System {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(SkillEffectComp, CollisionResultComp);
|
||||
}
|
||||
|
||||
update(skills: ecs.Entity[]) {
|
||||
skills.forEach(skill => {
|
||||
const effect = skill.get(SkillEffectComp);
|
||||
const targets = skill.get(CollisionResultComp).targets;
|
||||
|
||||
targets.forEach(hero => {
|
||||
// 应用即时伤害
|
||||
if (effect.effectType === 'instant') {
|
||||
this.applyInstantDamage(hero, effect.damage);
|
||||
}
|
||||
// 应用持续效果
|
||||
else if (effect.effectType === 'dot') {
|
||||
this.applyDOT(hero, effect);
|
||||
}
|
||||
});
|
||||
|
||||
// 清除碰撞结果
|
||||
skill.remove(CollisionResultComp);
|
||||
});
|
||||
}
|
||||
|
||||
private applyInstantDamage(hero: ecs.Entity, damage: number) {
|
||||
const model = hero.get(HeroModelComp);
|
||||
model.hp -= damage;
|
||||
|
||||
// 触发受击事件
|
||||
oops.message.dispatch('HeroDamaged', {
|
||||
hero,
|
||||
damage,
|
||||
currentHp: model.hp
|
||||
});
|
||||
}
|
||||
|
||||
private applyDOT(hero: ecs.Entity, effect: SkillEffectComp) {
|
||||
// 添加持续伤害组件
|
||||
hero.add(DOTComp, {
|
||||
damagePerSec: effect.damage,
|
||||
duration: effect.duration
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user