Add event publishing for inventory and combat interactions
This commit is contained in:
@@ -34,5 +34,8 @@ public class DamageSystem : ISystem
|
||||
{
|
||||
var targetAttributes = _world.GetComponent<AttributeComponent>(e.Target);
|
||||
targetAttributes?.ModifyValue(Attribute.Health, -e.Amount);
|
||||
|
||||
var newHealth = targetAttributes?.GetValue(Attribute.Health) ?? 0f;
|
||||
_world.PublishEvent(new EntityDamagedEvent(e.Target, newHealth, e.Amount));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using GameCore.Combat.Interfaces;
|
||||
using GameCore.Events;
|
||||
using GameCore.Inventory;
|
||||
|
||||
namespace GameCore.Combat.Effects;
|
||||
@@ -8,7 +9,12 @@ public class ConsumeAmmoCost(string ammoId, int amount) : ICostEffect
|
||||
public void Execute(EffectContext context)
|
||||
{
|
||||
var inventory = context.World.GetComponent<InventoryComponent>(context.Owner);
|
||||
inventory?.RemoveItem(ammoId, amount);
|
||||
if (inventory == null) return;
|
||||
|
||||
inventory.RemoveItem(ammoId, amount);
|
||||
|
||||
var newQuantity = inventory.GetItemCount(ammoId);
|
||||
context.World.PublishEvent(new InventoryItemChangedEvent(context.Owner, ammoId, newQuantity));
|
||||
}
|
||||
|
||||
public bool CanAfford(EffectContext context)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using GameCore.Combat.Interfaces;
|
||||
using GameCore.Events;
|
||||
using GameCore.Input;
|
||||
|
||||
namespace GameCore.Combat.Effects;
|
||||
@@ -12,8 +13,11 @@ public class HitscanEffect(float range) : IEffect
|
||||
|
||||
if (input == null || weapon == null) return;
|
||||
|
||||
var targetPos = input.MuzzlePosition + input.MuzzleDirection * range;
|
||||
var hit = context.World.WorldQuery.Raycast(input.MuzzlePosition, targetPos, context.Owner);
|
||||
var fromPos = input.MuzzlePosition;
|
||||
var targetPos = fromPos + input.MuzzleDirection * range;
|
||||
var hit = context.World.WorldQuery.Raycast(fromPos, targetPos, context.Owner);
|
||||
|
||||
context.World.PublishEvent(new HitscanImpactEvent(context.Owner, fromPos, targetPos, hit));
|
||||
|
||||
if (hit.DidHit)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using GameCore.Combat.Effects;
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Events;
|
||||
using GameCore.Physics;
|
||||
|
||||
namespace GameCore.Combat;
|
||||
@@ -24,6 +25,7 @@ public class ProjectileSystem : ISystem
|
||||
var hit = world.WorldQuery.Raycast(position.Position, newPosition, projectileData.Owner);
|
||||
if (hit.DidHit)
|
||||
{
|
||||
world.PublishEvent(new ProjectileImpactEvent(projectile, hit));
|
||||
var hitContext = new EffectContext
|
||||
{
|
||||
World = world,
|
||||
|
||||
Reference in New Issue
Block a user