Ammo UI system

This commit is contained in:
Marco 2025-02-11 11:50:45 +01:00
commit 5eb7b578bc
22 changed files with 238 additions and 87 deletions

View file

@ -30,6 +30,8 @@ public partial class Weapon : Node2D
private Node2D _bulletsContainer;
private GameManager _gameManager;
private InventoryManager _inventoryManager;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@ -37,21 +39,31 @@ public partial class Weapon : Node2D
_muzzle = GetNode<Marker2D>("./Muzzle");
_cooldownTimer = GetNode<Timer>("./ShootTimer");
_gameManager = GetNode<GameManager>("/root/GameScene");
_gameManager = this.GetGameManager();
_inventoryManager = this.GetInventoryManager();
}
public void Reload()
{
_cooldownTimer.Start(WeaponData.ReloadTime);
if (WeaponData.InfiniteAmmo)
if (WeaponData.InfiniteAmmo || string.IsNullOrWhiteSpace(WeaponData.AmmoKey))
{
LoadedAmmo = WeaponData.BulletCapacity;
}
else
{
// TODO: Calculate subtraction, etc
LoadedAmmo = WeaponData.BulletCapacity;
// if (_inventoryManager.GetItemCount(WeaponData.AmmoKey) <= 0) return;
var ammoToLoad = _inventoryManager.RemoveItem(WeaponData.AmmoKey, WeaponData.BulletCapacity);
if (ammoToLoad > 0)
{
LoadedAmmo = ammoToLoad;
}
else
{
GD.Print("Out of ammo");
}
}
}