From 7f4bd1856869d7ae10fa8f07708fbd75c5bb7b1e Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 23 Nov 2026 12:00:20 +0100 Subject: pes --- scripts/items/ItemPickup.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/items/ItemPickup.cs (limited to 'scripts/items/ItemPickup.cs') diff --git a/scripts/items/ItemPickup.cs b/scripts/items/ItemPickup.cs new file mode 100644 index 0000000..df5d997 --- /dev/null +++ b/scripts/items/ItemPickup.cs @@ -0,0 +1,35 @@ +using Godot; + +public partial class ItemPickup : Area2D +{ + [Export] public ItemDefinition? Item { get; set; } + + public override void _Ready() + { + BodyEntered += OnBodyEntered; + } + + private void OnBodyEntered(Node2D body) + { + if (!body.IsInGroup("player") || Item == null) + { + return; + } + + PlayerBuildComponent? build = body.GetNodeOrNull("PlayerBuildComponent"); + if (build == null) + { + GD.PrintErr("[ItemPickup] PlayerBuildComponent missing on player."); + return; + } + + bool applied = Item.Type == ItemDefinition.ItemType.Passive + ? build.AddPassiveItem(Item) + : build.EquipWeaponItem(Item); + + if (applied) + { + QueueFree(); + } + } +} -- cgit v1.2.3