Add weapon acquisition and swapping systems with data handling

This commit is contained in:
2025-10-29 01:26:35 +01:00
parent 09fa293c81
commit 6d00b8d6ab
12 changed files with 185 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
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;
}
}