Files
brick-framework/GameCore/Player/EquipmentSystem.cs

44 lines
1.3 KiB
C#

using GameCore.Combat;
using GameCore.Combat.Interfaces;
using GameCore.ECS;
using GameCore.ECS.Interfaces;
using GameCore.Events;
namespace GameCore.Player;
public class EquipmentSystem : ISystem
{
private readonly IWeaponDataService _weaponDataService;
private readonly World _world;
public EquipmentSystem(World world, IWeaponDataService weaponDataService)
{
_world = world;
_weaponDataService = weaponDataService;
_world.Subscribe<EquipWeaponEvent>(OnEquipWeapon);
}
public void Update(World world, float deltaTime)
{
}
private void OnEquipWeapon(EquipWeaponEvent e)
{
if (!_weaponDataService.TryGetWeaponData(e.NewWeaponItemId, out var newData)) return;
var weaponComponent = _world.GetComponent<WeaponComponent>(e.Owner);
if (weaponComponent == null)
{
weaponComponent = new WeaponComponent();
_world.AddComponent(e.Owner, weaponComponent);
}
weaponComponent.FireRate = newData.FireRate;
weaponComponent.FireCosts = newData.FireCosts;
weaponComponent.OnFireEffects = newData.OnFireEffects;
weaponComponent.OnHitEffects = newData.OnHitEffects;
weaponComponent.CooldownTimer = 0f;
_world.PublishEvent(new WeaponEquippedEvent(e.Owner, e.NewWeaponItemId));
}
}