Add attribute system with core stats and gameplay components
This commit is contained in:
48
GameCore/Combat/Effects/BulkProjectileEffect.cs
Normal file
48
GameCore/Combat/Effects/BulkProjectileEffect.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using GameCore.Combat.Interfaces;
|
||||
using GameCore.Events;
|
||||
using GameCore.Input;
|
||||
using GameCore.Movement;
|
||||
|
||||
namespace GameCore.Combat.Effects;
|
||||
|
||||
public class BulkProjectileEffect(string archetypeId, int count, float spreadAngle, float speed) : IEffect
|
||||
{
|
||||
private static readonly Random _random = new();
|
||||
|
||||
public void Execute(EffectContext context)
|
||||
{
|
||||
var ownerInput = context.World.GetComponent<InputStateComponent>(context.Owner);
|
||||
if (ownerInput == null)
|
||||
return;
|
||||
|
||||
var ownerRotation = context.World.GetComponent<RotationComponent>(context.Owner);
|
||||
if (ownerRotation == null) return;
|
||||
|
||||
var spreadRadians = spreadAngle * (float)System.Math.PI / 180f;
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var direction = ownerInput.MuzzleDirection;
|
||||
|
||||
if (spreadRadians > 0f)
|
||||
{
|
||||
var randomYaw = ((float)_random.NextDouble() * 2f - 1f) * spreadRadians;
|
||||
var randomPitch = ((float)_random.NextDouble() * 2f - 1f) * spreadRadians;
|
||||
|
||||
direction = context.World.WorldQuery.RotateVectorByYaw(direction, randomYaw);
|
||||
direction.Y += (float)System.Math.Sin(randomPitch);
|
||||
direction = direction.Normalize();
|
||||
}
|
||||
|
||||
var initialVelocity = direction * speed;
|
||||
|
||||
context.World.PublishEvent(new SpawnEntityEvent(
|
||||
archetypeId,
|
||||
ownerInput.MuzzlePosition,
|
||||
ownerRotation.Rotation,
|
||||
context.Owner,
|
||||
initialVelocity
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
15
GameCore/Combat/Effects/DamageEffect.cs
Normal file
15
GameCore/Combat/Effects/DamageEffect.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using GameCore.Combat.Interfaces;
|
||||
using GameCore.Events;
|
||||
|
||||
namespace GameCore.Combat.Effects;
|
||||
|
||||
public class DamageEffect(float amount) : IEffect
|
||||
{
|
||||
public void Execute(EffectContext context)
|
||||
{
|
||||
if (context.Target == null)
|
||||
return;
|
||||
|
||||
context.World.PublishEvent(new DamageDealtEvent(context.Target.Value, amount));
|
||||
}
|
||||
}
|
||||
10
GameCore/Combat/Effects/EffectContext.cs
Normal file
10
GameCore/Combat/Effects/EffectContext.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using GameCore.ECS;
|
||||
|
||||
namespace GameCore.Combat.Effects;
|
||||
|
||||
public class EffectContext
|
||||
{
|
||||
public Entity Owner;
|
||||
public Entity? Target;
|
||||
public World World;
|
||||
}
|
||||
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