2024-06-12 09:57:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2024-06-11 16:51:40 +00:00
|
|
|
|
using Godot;
|
|
|
|
|
|
2024-06-13 05:53:10 +00:00
|
|
|
|
namespace ColdMint.scripts.item.itemStacks;
|
2024-06-11 16:51:40 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-06-13 14:29:18 +00:00
|
|
|
|
/// <para>One of the basic item stacks, there are always one item in stack(Stack not supported)</para>
|
|
|
|
|
/// <para>单身狗物品堆,基础物品堆之一,堆中永远只会有一个物品(不支持堆叠)</para>
|
2024-06-11 16:51:40 +00:00
|
|
|
|
/// </summary>
|
2024-06-13 14:29:18 +00:00
|
|
|
|
/// <seealso cref="UniqueItemStack"/>
|
|
|
|
|
/// <seealso cref="CommonItemStack"/>
|
2024-06-12 19:07:55 +00:00
|
|
|
|
public class SingleItemStack(IItem item) : IItemStack
|
2024-06-11 16:51:40 +00:00
|
|
|
|
{
|
2024-06-12 19:07:55 +00:00
|
|
|
|
public IItem Item { get; init; } = item;
|
2024-06-11 16:51:40 +00:00
|
|
|
|
|
|
|
|
|
public int MaxQuantity => 1;
|
2024-06-13 05:53:10 +00:00
|
|
|
|
public int Quantity => 1;
|
2024-06-13 14:29:18 +00:00
|
|
|
|
public bool Empty { get; private set; }
|
2024-06-11 16:51:40 +00:00
|
|
|
|
public Texture2D Icon => Item.Icon;
|
|
|
|
|
public string Name => Item.Name;
|
|
|
|
|
public string? Description => Item.Description;
|
2024-06-12 09:57:38 +00:00
|
|
|
|
|
2024-06-12 19:07:55 +00:00
|
|
|
|
public bool CanAddItem(IItem item) => false;
|
2024-06-12 09:57:38 +00:00
|
|
|
|
|
2024-06-12 19:07:55 +00:00
|
|
|
|
public bool AddItem(IItem item) => false;
|
2024-06-12 09:57:38 +00:00
|
|
|
|
|
|
|
|
|
public int CanTakeFrom(IItemStack itemStack) => 0;
|
|
|
|
|
|
2024-06-12 17:51:51 +00:00
|
|
|
|
public bool TakeFrom(IItemStack itemStack) => false;
|
|
|
|
|
|
2024-06-12 19:07:55 +00:00
|
|
|
|
public IItem? GetItem()
|
2024-06-12 13:53:27 +00:00
|
|
|
|
{
|
2024-06-13 05:53:10 +00:00
|
|
|
|
return Empty ? null : Item;
|
2024-06-12 13:53:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 19:07:55 +00:00
|
|
|
|
public IItem? PickItem()
|
2024-06-12 13:53:27 +00:00
|
|
|
|
{
|
2024-06-13 05:53:10 +00:00
|
|
|
|
if (Empty) return null;
|
|
|
|
|
Empty = true;
|
2024-06-12 19:04:12 +00:00
|
|
|
|
return Item;
|
2024-06-12 13:53:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IItemStack? PickItems(int value)
|
|
|
|
|
{
|
2024-06-13 05:53:10 +00:00
|
|
|
|
if (value == 0 || Empty) return null;
|
|
|
|
|
|
|
|
|
|
Empty = true;
|
|
|
|
|
return new SingleItemStack(Item);
|
2024-06-12 13:53:27 +00:00
|
|
|
|
}
|
2024-06-12 09:57:38 +00:00
|
|
|
|
|
|
|
|
|
public int RemoveItem(int number)
|
|
|
|
|
{
|
2024-06-13 05:53:10 +00:00
|
|
|
|
if (number == 0 || Empty) return 0;
|
|
|
|
|
Empty = true;
|
2024-06-12 19:04:12 +00:00
|
|
|
|
Item.Destroy();
|
|
|
|
|
return Math.Max(number - 1, 0);
|
2024-06-12 09:57:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearStack()
|
|
|
|
|
{
|
2024-06-12 19:04:12 +00:00
|
|
|
|
RemoveItem(1);
|
2024-06-12 09:57:38 +00:00
|
|
|
|
}
|
2024-06-11 16:51:40 +00:00
|
|
|
|
}
|