2024-06-11 16:51:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using Godot;
|
2024-06-10 15:08:48 +00:00
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.item;
|
|
|
|
|
|
|
|
|
|
public interface IItemStack
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>ID of items inside current stack</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
string Id { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Max number of current stack</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
int MaxQuantity { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Quantity of current stack</para>
|
|
|
|
|
/// </summary>
|
2024-06-11 16:51:40 +00:00
|
|
|
|
int Quantity { get; }
|
|
|
|
|
|
2024-06-10 15:08:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Icon of current item</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
Texture2D Icon { get; }
|
2024-06-11 16:51:40 +00:00
|
|
|
|
|
2024-06-10 15:08:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Display name of current item</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
string Name { get; }
|
2024-06-11 16:51:40 +00:00
|
|
|
|
|
2024-06-10 15:08:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Description of current item, which may show in inventory</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
string? Description { get; }
|
2024-06-11 16:51:40 +00:00
|
|
|
|
|
|
|
|
|
|
2024-06-11 18:22:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Removes the specified number of items from current item stack</para>
|
|
|
|
|
/// <para>在当前物品堆移除指定数量的物品</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="number"></param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// <para>The remaining number, if the number of items in the current item stack is less than the specified number. Otherwise,0</para>
|
|
|
|
|
/// <para>若物品槽内物品少于指定的数量,返回相差的数量。否则返回0</para>
|
|
|
|
|
/// </returns>
|
|
|
|
|
public int RemoveItem(int number);
|
|
|
|
|
|
2024-06-11 16:51:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new ItemStack with the given item as the first item
|
|
|
|
|
/// </summary>
|
2024-06-11 17:57:55 +00:00
|
|
|
|
public static IItemStack FromItem(IItem_New item) => ItemTypeManager.MaxStackQuantityOf(item.Id) switch
|
2024-06-11 16:51:40 +00:00
|
|
|
|
{
|
2024-06-11 17:57:55 +00:00
|
|
|
|
1 => new SingleItemStack(item),
|
|
|
|
|
> 1 => throw new NotImplementedException(),
|
|
|
|
|
var other => throw new ArgumentException($"item {item} of type '{item.Id}' has unexpected max stack quantity {other}")
|
2024-06-11 16:51:40 +00:00
|
|
|
|
};
|
2024-06-10 15:08:48 +00:00
|
|
|
|
}
|