Add weapon acquisition and swapping systems with data handling
This commit is contained in:
42
GameCore/Player/EquipmentSystem.cs
Normal file
42
GameCore/Player/EquipmentSystem.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user