使用ecs系统进行重构
This commit is contained in:
27
assets/script/game/skill/DOTSystem.ts
Normal file
27
assets/script/game/skill/DOTSystem.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
@ecs.registerSystem()
|
||||
export class DOTSystem extends ecs.System {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(DOTComp);
|
||||
}
|
||||
|
||||
update(entities: ecs.Entity[]) {
|
||||
const delta = oops.timer.delta;
|
||||
|
||||
entities.forEach(hero => {
|
||||
const dot = hero.get(DOTComp);
|
||||
dot.duration -= delta;
|
||||
|
||||
// 每秒伤害
|
||||
if (dot.accumulator >= 1) {
|
||||
hero.get(HeroModelComp).hp -= dot.damagePerSec;
|
||||
dot.accumulator -= 1;
|
||||
}
|
||||
dot.accumulator += delta;
|
||||
|
||||
// 效果结束
|
||||
if (dot.duration <= 0) {
|
||||
hero.remove(DOTComp);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user