using Godot; using System; using System.Collections.Generic; public partial class BagItem { public ItemResource itemResource; public int amount; public string ItemName { get { return itemResource?.ItemName ?? "Unknown"; // 防止空引用 } } public string Description { get { return itemResource?.Description ?? "No description"; // 防止空引用 } } public void AddAmount(int value) { if (value < 0) { GD.PrintErr("Cannot add negative amount to BagItem."); return; } amount += value; } public void RemoveAmount(int value) { if (value < 0 || value > amount) { GD.PrintErr("Invalid amount to remove from BagItem."); return; } amount -= value; } }