Add attribute system with core stats and gameplay components
This commit is contained in:
30
GameCore/Combat/Effects/HitscanEffect.cs
Normal file
30
GameCore/Combat/Effects/HitscanEffect.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using GameCore.Combat.Interfaces;
|
||||
using GameCore.Input;
|
||||
|
||||
namespace GameCore.Combat.Effects;
|
||||
|
||||
public class HitscanEffect(float range) : IEffect
|
||||
{
|
||||
public void Execute(EffectContext context)
|
||||
{
|
||||
var input = context.World.GetComponent<InputStateComponent>(context.Owner);
|
||||
var weapon = context.World.GetComponent<WeaponComponent>(context.Owner);
|
||||
|
||||
if (input == null || weapon == null) return;
|
||||
|
||||
var targetPos = input.MuzzlePosition + input.MuzzleDirection * range;
|
||||
var hit = context.World.WorldQuery.Raycast(input.MuzzlePosition, targetPos, context.Owner);
|
||||
|
||||
if (hit.DidHit)
|
||||
{
|
||||
var hitContext = new EffectContext
|
||||
{
|
||||
World = context.World,
|
||||
Owner = context.Owner,
|
||||
Target = hit.HitEntity
|
||||
};
|
||||
|
||||
foreach (var effect in weapon.OnHitEffects) effect.Execute(hitContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user