mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 18:05:54 +00:00
Ammo UI system
This commit is contained in:
parent
70c514f1a9
commit
5eb7b578bc
22 changed files with 238 additions and 87 deletions
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue