godot-4.5 #5

Merged
GKaszewski merged 6 commits from godot-4.5 into master 2026-01-31 13:06:44 +00:00
2 changed files with 32 additions and 12 deletions
Showing only changes of commit 07c919737a - Show all commits

View File

@@ -17,6 +17,12 @@ public partial class CollectableComponent : Node
[Signal] public delegate void CollectedEventHandler(float amount, CollectableType type, Node2D body); [Signal] public delegate void CollectedEventHandler(float amount, CollectableType type, Node2D body);
/// <summary>
/// Delegate for checking if collection should be allowed.
/// Return false to prevent collection.
/// </summary>
public Func<Node2D, bool> CanCollect { get; set; }
private FloatingTextManager _floatingTextManager; private FloatingTextManager _floatingTextManager;
public override void _Ready() public override void _Ready()
@@ -38,6 +44,9 @@ public partial class CollectableComponent : Node
{ {
if (!body.HasNode("CanPickUpComponent")) return; if (!body.HasNode("CanPickUpComponent")) return;
// Allow components to veto collection (e.g., full health for potions)
if (CanCollect != null && !CanCollect(body)) return;
if (Owner is Node2D ownerNode) if (Owner is Node2D ownerNode)
{ {
switch (Data.Type) switch (Data.Type)

View File

@@ -17,9 +17,20 @@ public partial class HealComponent : Node
return; return;
} }
// Register check to prevent collecting when at full health
Collectable.CanCollect = CanCollectHealth;
Collectable.Collected += OnCollected; Collectable.Collected += OnCollected;
} }
private bool CanCollectHealth(Node2D body)
{
var healthComponent = body.GetNodeOrNull<HealthComponent>("HealthComponent");
if (healthComponent == null) return true; // Allow collection if no health component
// Prevent collection if already at full health
return healthComponent.Health < healthComponent.MaxHealth;
}
private void OnCollected(float amount, CollectableType type, Node2D body) private void OnCollected(float amount, CollectableType type, Node2D body)
{ {
if (type != CollectableType.Health) return; if (type != CollectableType.Health) return;