using System; using Godot; namespace ColdMint.scripts.item.itemStacks; /// /// Item stack in an inventory slot /// public interface IItemStack { /// /// Max number of current stack /// 当前物品堆的最大物品数量 /// int MaxQuantity { get; } /// /// Quantity of current stack /// 当前物品堆的物品数量 /// int Quantity { get; } /// /// True if this stack is empty /// 当物品堆空时为真 /// /// /// /// This attribute is used to check if the item stack is empty after the operation for subsequent processing,
/// i.e. there should not be any item stacks with this attribute true outside of the operation process ///
/// 此属性用于检查操作后该物品堆是否为空以便后续处理,也就是说在操作过程以外的时候不应当存在任何该属性为true的物品堆 ///
bool Empty { get; } /// /// Icon of current item stack /// 当前物品堆显示的图标 /// Texture2D Icon { get; } /// /// Display name of current item stack /// 当前物品堆显示的名称 /// string Name { get; } /// /// Description of current item stack, which may show in inventory /// 当前物品堆的描述,可能显示在物品栏中 /// string? Description { get; } /// /// Determine whether a specified item can be accommodated /// 判断能否容纳指定物品 /// /// public bool CanAddItem(IItem item); /// /// Hold a given item /// /// Item to hold by current stack /// Whether successful public bool AddItem(IItem item); /// /// 判断能从指定物品堆中接收的物品数量 /// /// /// 向该物品堆中放入物品的物品堆 /// Item stack to add to the current stack /// /// public int CanTakeFrom(IItemStack itemStack); /// /// 将指定物品堆中尽可能多的物品移动至当前物品堆中,被移入当前堆的物品应从原物品堆中移除。 /// /// /// 被移入当前堆的物品堆 /// /// /// 操作结束后原物品堆是否为空 /// public bool TakeFrom(IItemStack itemStack); /// /// Get item instance at the top of current stack without removing it from stack /// 获取当前物品堆顶部的物品实例而不取出该物品 /// /// /// public IItem? GetItem(); /// /// Pop the item instance at the top of current item stack and return it /// 取出当前物品堆顶部的物品实例并返回该物品 /// /// /// public IItem? PickItem(); /// /// Remove the specified number of items and return them as a new item stack /// 取出当前堆中指定数量的物品,并作为新的物品堆返回 /// /// /// /// Quantity to be taken out, inputs below zero represent all items /// 要取出的数量,小于0的输入代表全部物品 /// /// /// The item stack that is taken out, can be null if out nothing, should not be the current item stack itself /// 取出的物品堆,没有取出物品时可为null,不应是当前物品堆自身 /// public IItemStack? PickItems(int value); /// /// /// Removes the specified number of items from current item stack,removed items should be removed from the game
/// If you don't want remove them from game, consider and ///
/// /// 在当前物品堆移除指定数量的物品,被移除的物品应当从游戏中移除。
/// 如果您并不打算将它们从游戏中移除,请考虑使用 ///
///
/// /// Quantity to be removed, inputs below zero represent all items /// 要删除的数量,小于0的输入代表全部物品 /// /// /// The remaining number, if the number of items in the current item stack is less than the specified number. Otherwise,0 /// 若物品槽内物品少于指定的数量,返回相差的数量。否则返回0 /// public int RemoveItem(int number); /// /// Clear current stack, which means should remove all items inside current stack from the game here /// 清除当前物品堆,意味着从游戏中移除当前堆中的所有物品。 /// public void ClearStack(); /// /// Create a new ItemStack with the given item as the first item /// 以给定的物品为第一个物品创建物品堆 /// public static IItemStack FromItem(IItem item) => item.SpecialStack() ?? ItemTypeManager.MaxStackQuantityOf(item.Id) switch { 1 => new SingleItemStack(item), > 1 => item is ICommonItem commonItem ? new CommonItemStack(commonItem) : new UniqueItemStack(item), var other => throw new ArgumentException($"item {item} of type '{item.Id}' has unexpected max stack quantity {other}") }; }