evershade/Assets/Data/ScriptableObjects/World/BoxInteractable.cs

129 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
// BaseSlot.cs
[CreateAssetMenu(fileName = "BoxInteractable", menuName = "Game Data/Farming/Box Interactable")]
public class BoxInteractable : Interactable
{
public Sprite openBoxSprite;
public Sprite closedBoxSprite;
public readonly Dictionary<int, Slot> Slots = new();
public BoxInteractable()
{
type = InteractableType.Box;
}
public Sprite display { get; set; }
public int id { get; set; }
public float interactRange { get; set; }
public string objectName { get; set; }
public Vector2Int size { get; set; }
public InteractableType type { get; set; }
public ToolItem.ToolType[] validToolTypes { get; set; }
public void OnEnter2D(Collider2D collider)
{
Debug.Log("Box OnEnter2D");
}
public void OnExit2D(Collider2D collider)
{
Debug.Log("Box OnExit2D");
}
public bool IsPlayerInInteractRange(Vector2 playerPosition, Vector2 itemPosition)
{
throw new NotImplementedException();
}
public bool IsToolRequired()
{
throw new NotImplementedException();
}
public void OnInteract()
{
Debug.Log("Box OnInteract");
}
public void Interact()
{
Debug.Log("Box Interact");
}
public void OnDayChange()
{
// do nothing it's a box!
}
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.slotId + " / " + 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(Slot slot)
{
Slots[slot.slotId] = slot;
}
public Slot GetSlot(int slotId)
{
return Slots.GetValueOrDefault(slotId, null);
}
public Slot GetValueOrDefault(int slotId, object o)
{
if (Slots.TryGetValue(slotId, out var slot))
return slot;
return null;
}
}