Energy weapons

This commit is contained in:
Marco 2025-05-02 13:10:38 +02:00
commit 2f76d4742e
12 changed files with 144 additions and 24 deletions

View file

@ -12,6 +12,8 @@ public partial class PlayerStateMachine : StateMachineBase<PlayerState, Characte
[Export] public ActorResourceProvider MotivationResource { get; private set; }
[Export] public ActorResourceProvider Shield { get; private set; }
public void RefillHealth()
{
GD.Print("Refilling health");

View file

@ -20,6 +20,7 @@ public partial class WeaponResource : Resource
//[Export] public PackedScene DestructionParticlesScene { get; set; }
[Export] public int Priority { get; set; } = 0;
[Export] public int AmmoPerShot { get; set; } = 1;
[Export] public double RateOfFire = 0.4f;

View file

@ -50,6 +50,9 @@ public partial class Weapon : Node2D
private GameManager _gameManager;
private InventoryManager _inventoryManager;
private readonly StringName _shieldAmmoType = "SHIELD";
private bool UsesBattery => WeaponData.AmmoKey == _shieldAmmoType;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@ -79,8 +82,7 @@ public partial class Weapon : Node2D
}
else
{
// if (_inventoryManager.GetItemCount(WeaponData.AmmoKey) <= 0) return;
var ammoToLoad = _inventoryManager.RemoveItem(WeaponData.AmmoKey, WeaponData.BulletCapacity);
var ammoToLoad = _inventoryManager.RemoveItem(WeaponData.AmmoKey, WeaponData.BulletCapacity - LoadedAmmo);
if (ammoToLoad > 0)
{
@ -102,8 +104,21 @@ public partial class Weapon : Node2D
return;
}
// Check for battery if it's used
if (UsesBattery)
{
if (GameManager.Instance.Player.Shield.CurrentResource >= WeaponData.AmmoPerShot)
{
GameManager.Instance.Player.Shield.CurrentResource -= WeaponData.AmmoPerShot;
}
else
{
return;
}
}
// Out of ammo?
if (LoadedAmmo <= 0)
if (LoadedAmmo < WeaponData.AmmoPerShot)
{
if (WeaponData.AutoReload)
{
@ -160,7 +175,11 @@ public partial class Weapon : Node2D
bullet.Speed = WeaponData.BulletData.BulletSpeed;
}
LoadedAmmo -= 1;
if (!UsesBattery)
{
LoadedAmmo -= WeaponData.AmmoPerShot;
}
//_inventoryManager.NotifyLoadedAmmoChange(WeaponData.ItemKey, LoadedAmmo);
// if (!string.IsNullOrWhiteSpace(WeaponData?.AmmoKey))
// {