Files
brick-framework/GameCore/Combat/ProjectileInitializationSystem.cs

33 lines
827 B
C#

using GameCore.ECS;
using GameCore.ECS.Interfaces;
using GameCore.Events;
namespace GameCore.Combat;
public class ProjectileInitializationSystem : ISystem
{
private readonly World _world;
public ProjectileInitializationSystem(World world)
{
_world = world;
_world.Subscribe<EntitySpawnedEvent>(OnEntitySpawned);
}
public void Update(World world, float deltaTime)
{
}
private void OnEntitySpawned(EntitySpawnedEvent e)
{
var projComp = _world.GetComponent<ProjectileComponent>(e.NewEntity);
if (projComp == null) return;
var ownerWeapon = _world.GetComponent<WeaponComponent>(e.Owner);
if (ownerWeapon != null)
{
projComp.Owner = e.Owner;
projComp.OnHitEffects = ownerWeapon.OnHitEffects;
}
}
}