mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 20:05:55 +00:00
Health and shield extensions for player
This commit is contained in:
parent
62a77f5f78
commit
5dec57e711
6 changed files with 63 additions and 8 deletions
|
|
@ -7,11 +7,33 @@ public partial class ActorResourceProvider : Node2D
|
|||
[Export]
|
||||
public string ResourceName { get; private set; }
|
||||
|
||||
[Export]
|
||||
public float MaxResource { get; set; } = 10f;
|
||||
public float MaxResource
|
||||
{
|
||||
get => _maxResource;
|
||||
set
|
||||
{
|
||||
if (_maxResource == value) return;
|
||||
|
||||
if (value > _currentResource)
|
||||
{
|
||||
EmitSignal(SignalName.ResourceIncreased, _currentResource, _currentResource, value);
|
||||
}
|
||||
else if (value < _currentResource)
|
||||
{
|
||||
EmitSignal(SignalName.ResourceDecreased, _currentResource, _currentResource, value);
|
||||
}
|
||||
|
||||
_maxResource = value;
|
||||
|
||||
EmitSignal(SignalName.ResourceChanged, _currentResource, value);
|
||||
}
|
||||
}
|
||||
|
||||
private float _currentResource = 0f;
|
||||
|
||||
[Export]
|
||||
private float _maxResource = 10f;
|
||||
|
||||
[Signal]
|
||||
public delegate void ResourceChangedEventHandler(float newValue, float maxValue);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,23 @@ public partial class PlayerDamageReceiver : Area2D
|
|||
public bool Invulnerable { get; private set; } = false;
|
||||
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.Player;
|
||||
|
||||
[ExportCategory("Extensions")]
|
||||
[Export] public StringName HealthExtendName { get; private set; } = "HEALTH_EXTEND";
|
||||
[Export] public StringName ShieldExtendName { get; private set; } = "SHIELD_EXTEND";
|
||||
|
||||
[Export] public float BaseHealth { get; private set; } = 32f;
|
||||
[Export] public float BaseShield { get; private set; } = 32f;
|
||||
|
||||
[Export] public float HealthExtendAmount { get; private set; } = 4f;
|
||||
[Export] public float ShieldExtendAmount { get; private set; } = 4f;
|
||||
|
||||
[ExportCategory("Providers")]
|
||||
[Export]
|
||||
private ActorResourceProvider _healthProvider;
|
||||
[Export]
|
||||
private ActorResourceProvider _shieldProvider;
|
||||
|
||||
|
||||
[ExportCategory("Damage Types")]
|
||||
[Export] public StringName AcidGroupName { get; private set; } = "Acid";
|
||||
|
||||
[Signal]
|
||||
|
|
@ -81,6 +93,27 @@ public partial class PlayerDamageReceiver : Area2D
|
|||
//if (!Enabled) return;
|
||||
EmitSignal(SignalName.Death);
|
||||
};
|
||||
|
||||
// Set max resources based on inventory
|
||||
SetMaxResources();
|
||||
|
||||
InventoryManager.Instance.ItemAdded += (item, amount) =>
|
||||
{
|
||||
if (item.ItemKey != HealthExtendName && item.ItemKey != ShieldExtendName) return;
|
||||
|
||||
SetMaxResources();
|
||||
};
|
||||
}
|
||||
|
||||
private void SetMaxResources()
|
||||
{
|
||||
var healthExtends = InventoryManager.Instance.GetItemCount(HealthExtendName);
|
||||
|
||||
var shieldExtends = InventoryManager.Instance.GetItemCount(ShieldExtendName);
|
||||
|
||||
_healthProvider.MaxResource = BaseHealth + (healthExtends * HealthExtendAmount);
|
||||
|
||||
_shieldProvider.MaxResource = BaseShield + (shieldExtends * ShieldExtendAmount);
|
||||
}
|
||||
|
||||
public void RefillHealth()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue