Miner tile

This commit is contained in:
2025-08-29 16:59:59 +08:00
parent 7720e74a3d
commit 56cd4c2db2
9 changed files with 105 additions and 23 deletions

View File

@@ -2,7 +2,7 @@ using Godot;
namespace AceFieldNewHorizon.Scripts.System;
public partial class ItemPickup : Node2D
public partial class ItemPickup : Area2D
{
public const string PickupGroupName = "ItemPickupTarget";
@@ -19,8 +19,7 @@ public partial class ItemPickup : Node2D
// Called when the node enters the scene tree
public override void _Ready()
{
var area = GetNode<Area2D>("Area2D");
area.BodyEntered += OnBodyEntered;
BodyEntered += OnBodyEntered;
_sprite = GetNode<Sprite2D>("Sprite2D");
UpdateTexture();
@@ -114,7 +113,29 @@ public partial class ItemPickup : Node2D
if (body.IsInGroup(PickupGroupName))
{
if (body.HasMethod("AddItem"))
body.Call("AddItem", ItemId, Quantity);
{
// First check if we can merge with existing items
if (body.HasMethod("HasItem"))
{
var hasItem = (bool)body.Call("HasItem", ItemId);
if (hasItem && body.HasMethod("GetItemQuantity"))
{
// Get current quantity and add to it
var currentQuantity = (int)body.Call("GetItemQuantity", ItemId);
body.Call("SetItemQuantity", ItemId, currentQuantity + Quantity);
}
else
{
// No existing item, add as new
body.Call("AddItem", ItemId, Quantity);
}
}
else
{
// Fallback to original behavior if HasItem method doesn't exist
body.Call("AddItem", ItemId, Quantity);
}
}
if (!Infinite)
QueueFree(); // remove the pickup from the world