Add attribute system with core stats and gameplay components
This commit is contained in:
43
GameCore/Combat/ProjectileSystem.cs
Normal file
43
GameCore/Combat/ProjectileSystem.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using GameCore.Combat.Effects;
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Physics;
|
||||
|
||||
namespace GameCore.Combat;
|
||||
|
||||
public class ProjectileSystem : ISystem
|
||||
{
|
||||
public void Update(World world, float deltaTime)
|
||||
{
|
||||
var projectiles = world.GetEntitiesWith<ProjectileComponent>();
|
||||
foreach (var projectile in projectiles)
|
||||
{
|
||||
var velocity = world.GetComponent<VelocityComponent>(projectile);
|
||||
var position = world.GetComponent<PositionComponent>(projectile);
|
||||
var projectileData = world.GetComponent<ProjectileComponent>(projectile);
|
||||
|
||||
if (velocity == null || position == null || projectileData == null)
|
||||
continue;
|
||||
|
||||
var newPosition = position.Position + velocity.DesiredVelocity * deltaTime;
|
||||
|
||||
var hit = world.WorldQuery.Raycast(position.Position, newPosition, projectileData.Owner);
|
||||
if (hit.DidHit)
|
||||
{
|
||||
var hitContext = new EffectContext
|
||||
{
|
||||
World = world,
|
||||
Owner = projectileData.Owner,
|
||||
Target = hit.HitEntity
|
||||
};
|
||||
|
||||
foreach (var effect in projectileData.OnHitEffects) effect.Execute(hitContext);
|
||||
|
||||
world.AddComponent(projectile, new DeathComponent());
|
||||
continue;
|
||||
}
|
||||
|
||||
position.Position = newPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user