Traveller/scripts/item/SingleItemStack.cs

65 lines
1.3 KiB
C#
Raw Normal View History

using System;
using ColdMint.scripts.inventory;
using Godot;
namespace ColdMint.scripts.item;
/// <summary>
/// <para>Item stack of single item</para>
/// </summary>
//maybe we'd move this into inventory namespace
public class SingleItemStack(IItem item) : IItemStack
{
public IItem Item { get; init; } = item;
public string Id => Item.Id;
public int MaxQuantity => 1;
public int Quantity { get; set; } = 1;
public Texture2D Icon => Item.Icon;
public string Name => Item.Name;
public string? Description => Item.Description;
public bool CanAddItem(IItem item) => false;
public bool AddItem(IItem item) => false;
public int CanTakeFrom(IItemStack itemStack) => 0;
2024-06-12 17:51:51 +00:00
public bool TakeFrom(IItemStack itemStack) => false;
public IItem? GetItem()
{
return Quantity == 1 ? Item : null;
}
public IItem? PickItem()
{
Quantity = 0;
return Item;
}
public IItemStack? PickItems(int value)
{
if (value == 0) return null;
else
{
Quantity = 0;
return new SingleItemStack(Item);
}
}
public int RemoveItem(int number)
{
if (number == 0) return 0;
Quantity = 0;
Item.Destroy();
return Math.Max(number - 1, 0);
}
public void ClearStack()
{
RemoveItem(1);
}
}