106 lines
2.8 KiB
C#
106 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using Types.Items;
|
|
using Types.UI;
|
|
using UnityEngine;
|
|
|
|
// BaseSlot.cs
|
|
namespace Data.ScriptableObjects.World
|
|
{
|
|
[CreateAssetMenu(fileName = "BoxInteractable", menuName = "Game Data/Farming/Box Interactable")]
|
|
public class BoxInteractable : Interactable
|
|
{
|
|
public Sprite openBoxSprite;
|
|
public Sprite closedBoxSprite;
|
|
|
|
public readonly Dictionary<int, GameSlot> Slots = new();
|
|
|
|
public BoxInteractable()
|
|
{
|
|
type = InteractableType.Box;
|
|
}
|
|
|
|
public new void OnEnter2D(Collider2D collider)
|
|
{
|
|
Debug.Log("Box OnEnter2D");
|
|
}
|
|
|
|
public new void OnExit2D(Collider2D collider)
|
|
{
|
|
Debug.Log("Box OnExit2D");
|
|
}
|
|
|
|
|
|
public void Interact()
|
|
{
|
|
Debug.Log("Box Interact");
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
Debug.Log("Box Initialize");
|
|
}
|
|
|
|
public GameItem GetItemFromSlot(int slotId)
|
|
{
|
|
return Slots.TryGetValue(slotId, out var slot) ? slot.Item : null;
|
|
}
|
|
|
|
public void RemoveItemFromSlot(int slotId)
|
|
{
|
|
if (Slots.TryGetValue(slotId, out var slot))
|
|
slot.Item = null;
|
|
else
|
|
Debug.LogWarning("Slot not found: " + slotId);
|
|
}
|
|
|
|
public void AddItemToOpenSlot(GameItem item)
|
|
{
|
|
foreach (var slot in Slots.Values)
|
|
if (slot.IsEmpty())
|
|
{
|
|
slot.Item = item;
|
|
Debug.Log("Added item to slot: " + slot.Position + " / " + item.ItemName + " / " + item.Quantity);
|
|
return;
|
|
}
|
|
|
|
Debug.LogWarning("No empty slots available to add item: " + item.ItemName);
|
|
}
|
|
|
|
public void AddItemToSlot(GameItem item, int slotId)
|
|
{
|
|
if (Slots.TryGetValue(slotId, out var slot))
|
|
slot.Item = item;
|
|
else
|
|
Debug.LogWarning("Slot not found: " + slotId);
|
|
}
|
|
|
|
public void SwapItems(int slotId1, int slotId2)
|
|
{
|
|
if (Slots.TryGetValue(slotId1, out var slot1) &&
|
|
Slots.TryGetValue(slotId2, out var slot2))
|
|
(slot1.Item, slot2.Item) = (slot2.Item, slot1.Item);
|
|
}
|
|
|
|
public void RemoveSlot(int slotId)
|
|
{
|
|
Slots.Remove(slotId);
|
|
}
|
|
|
|
public void AddSlot(GameSlot gameSlot)
|
|
{
|
|
Slots[gameSlot.Position] = gameSlot;
|
|
}
|
|
|
|
public GameSlot GetSlot(int slotId)
|
|
{
|
|
return Slots.GetValueOrDefault(slotId, null);
|
|
}
|
|
|
|
public GameSlot GetValueOrDefault(int slotId, object o)
|
|
{
|
|
if (Slots.TryGetValue(slotId, out var slot))
|
|
return slot;
|
|
return null;
|
|
}
|
|
}
|
|
} |