-
How i can translate System to Friflo ECS? private class DamageSystem : IEcsRunSystem
{
private readonly EcsWorld _world;
private readonly EcsFilter _attackFilter;
private readonly EcsFilter _filter;
private readonly EcsPool<Attack<int>> _attackPool;
private readonly EcsPool<Health> _healthPool;
private readonly EcsPool<Damage> _damagePool;
public DamageSystem(EcsWorld world)
{
_world = world;
_attackFilter = world.Filter<Attack<int>>().End();
_filter = world.Filter<Health>().Inc<Damage>().Exc<Dead>().End();
_attackPool = world.GetPool<Attack<int>>();
_healthPool = world.GetPool<Health>();
_damagePool = world.GetPool<Damage>();
}
public void Run(IEcsSystems _)
{
foreach (var entity in _attackFilter)
{
ref var attack = ref _attackPool.Get(entity);
if (attack.Ticks-- > 0)
continue;
var target = attack.Target;
var attackDamage = attack.Damage;
_world.DelEntity(entity);
if (!_filter.HasEntity(target))
continue;
ref var health = ref _healthPool.Get(target);
var damage = _damagePool.Get(target);
var totalDamage = attackDamage - damage.Defence;
health.Hp -= totalDamage;
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
friflo
Jun 28, 2024
Replies: 2 comments 14 replies
-
I'm trying to do something like: private class DamageSystem : QuerySystem<Comp<Attack<Entity>>>
{
public DamageSystem() =>
Filter.WithoutAnyTags(Tags.Get<Tag<Dead>>());
protected override void OnUpdate() =>
Query.ForEachEntity((ref Comp<Attack<Entity>> attack, Entity entity) =>
{
if (attack.V.Ticks-- > 0)
return;
CommandBuffer.DeleteEntity(entity.Id);
var target = attack.V.Target;
if (Query.Store.HasTag<Dead>(target))
return;
ref var health = ref Query.Store.Get<Health>(target, out var result);
if (!result)
return;
if (!Query.Store.TryGet(target, out Damage damage))
return;
var totalDamage = attack.V.Damage - damage.Defence;
health.Hp -= totalDamage;
});
} |
Beta Was this translation helpful? Give feedback.
10 replies
-
Hi, only fyi. When I added Leopotam.EcsLite I instantaneously remembered this discussion. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Understand.
Your initial example used a simple
foreach
.So you can use
query.Entites
.So something like.