Fixed Tomato farming (again)
This commit is contained in:
@@ -81,7 +81,7 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
|
||||
if (item == null || PlantingPlaceholder.GetChildCount() > 0)
|
||||
if (item == null || PlantingPlaceholder.GetChildCount() > 0 || item.amount == 0)
|
||||
return success;
|
||||
|
||||
string prefabPath = ItemRepository.TryGetPrefabPath(item.blueprint);
|
||||
@@ -98,7 +98,8 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
{
|
||||
plantBehaviour.Field = this;
|
||||
}
|
||||
|
||||
|
||||
InventoryManager.Instance.playerInventory.RemoveItem(currentSlotIndex);
|
||||
success = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
public enum InventoryActionResult
|
||||
{
|
||||
Success,
|
||||
DestinationDoesNotExists,
|
||||
DestinationDoesNotExist,
|
||||
DestinationFull,
|
||||
SourceDoesNotExists,
|
||||
SourceDoesNotExist,
|
||||
SourceIsEmpty
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ public partial class InventoryInstance : Node
|
||||
[Signal]
|
||||
public delegate void InventoryContentsChangedEventHandler();
|
||||
|
||||
/// <summary>
|
||||
/// The total amount of Inventoryslots in the inventory (empty and occupied).
|
||||
/// </summary>
|
||||
[Export]
|
||||
public int SlotAmount
|
||||
{
|
||||
@@ -49,7 +52,7 @@ public partial class InventoryInstance : Node
|
||||
private InventoryActionResult AddItemAndStackRecursive(ItemInstance newItem, int slotSearch)
|
||||
{
|
||||
if (newItem.blueprint == null || newItem.amount == 0)
|
||||
return InventoryActionResult.SourceDoesNotExists;
|
||||
return InventoryActionResult.SourceDoesNotExist;
|
||||
|
||||
var slotIndex = -1;
|
||||
// find stackable slot
|
||||
@@ -97,7 +100,7 @@ public partial class InventoryInstance : Node
|
||||
if (inventorySlot < 0 || inventorySlot >= _slots.Count)
|
||||
{
|
||||
itemInstance = null;
|
||||
return InventoryActionResult.SourceDoesNotExists;
|
||||
return InventoryActionResult.SourceDoesNotExist;
|
||||
}
|
||||
|
||||
if (_slots[inventorySlot].IsEmpty())
|
||||
@@ -107,6 +110,10 @@ public partial class InventoryInstance : Node
|
||||
}
|
||||
|
||||
itemInstance = _slots[inventorySlot].itemInstance;
|
||||
if (itemInstance == null)
|
||||
return InventoryActionResult.SourceDoesNotExist;
|
||||
|
||||
itemInstance.amount -= 1;
|
||||
_slots[inventorySlot].itemInstance = null;
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
return InventoryActionResult.Success;
|
||||
@@ -120,7 +127,7 @@ public partial class InventoryInstance : Node
|
||||
public InventoryActionResult AddItemToSlot(ItemInstance itemInstance, int destinationSlot)
|
||||
{
|
||||
if (destinationSlot < 0 || destinationSlot >= _slots.Count)
|
||||
return InventoryActionResult.DestinationDoesNotExists;
|
||||
return InventoryActionResult.DestinationDoesNotExist;
|
||||
|
||||
if (!_slots[destinationSlot].IsEmpty())
|
||||
return InventoryActionResult.DestinationFull;
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
#nullable enable
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a virtual object wrapper for an item instance.
|
||||
/// Can return the containing item or null.
|
||||
/// </summary>
|
||||
public class InventorySlot
|
||||
{
|
||||
/// <summary>
|
||||
/// The inventory item instance that may or may not be bound to this slot.
|
||||
/// </summary>
|
||||
public ItemInstance? itemInstance;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this slot is currently occupied by an item instance.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return itemInstance == null;
|
||||
|
||||
Reference in New Issue
Block a user