evershade/Assets/Data/ScriptableObjects/UI/SlotSo.cs

244 lines
5.5 KiB
C#

using System.Collections.Generic;
using Types.Items;
using UnityEngine;
// BaseSlot.cs
namespace Data.ScriptableObjects.UI
{
public class SlotSo : ScriptableObject
{
public enum SlotType
{
Inventory,
Toolbar,
Equipment,
Crafting,
Box,
Shop,
Quest
}
public int position = -1;
public bool isLocked;
public SlotType slotType;
public List<EquipmentSlot> allowedEquipmentSlots = new();
public bool isSelected;
public int id;
public List<ItemType> allowedItemTypes = new();
public GameItem item;
public SlotSo()
{
item = null;
isLocked = false;
}
public SlotType GetSlotType()
{
return slotType;
}
public GameItem GetItem()
{
return item;
}
public int GetPositionId()
{
return position;
}
public virtual void Initialize(GameItem gameItem, int qty)
{
item = gameItem;
}
public virtual void AssignGameItem(GameItem gameItem, int qty = 1)
{
item = gameItem;
item.Quantity = qty;
}
public virtual void AddQuantity(int amount)
{
item.Quantity += amount;
}
public virtual void RemoveQuantity(int amount)
{
item.Quantity -= amount;
}
public int GetId()
{
return id;
}
public virtual void SetQuantity(int amount)
{
item.Quantity = amount;
}
public virtual bool IsEmpty()
{
return item == null;
}
public virtual Sprite GetIcon()
{
return item != null ? item.Icon : null;
}
public virtual string GetItemName()
{
return item != null ? item.ItemName : string.Empty;
}
public virtual float GetItemValue()
{
return item != null ? item.ItemValue : 0f;
}
public bool IsSlotType<T>() where T : SlotSo
{
return this is T;
}
public void SetSlotType(SlotType type)
{
slotType = type;
}
public void SetSlotId(int newId)
{
id = newId;
}
public void SetLocked(bool locked)
{
isLocked = locked;
}
public void SetAllowedItemTypes(List<ItemType> types)
{
allowedItemTypes = types;
}
public void AddAllowedItemType(ItemType type)
{
allowedItemTypes.Add(type);
}
public void RemoveAllowedItemType(ItemType type)
{
allowedItemTypes.Remove(type);
}
public bool IsAllowedItemType(ItemType type)
{
return allowedItemTypes.Contains(type);
}
public void ClearAllowedItemTypes()
{
allowedItemTypes.Clear();
}
public List<ItemType> GetAllowedItemTypes()
{
return allowedItemTypes;
}
public void ClearSlot()
{
item = null;
}
public bool IsAllowedItemTypes(ItemType type)
{
var isAllowed = false;
Debug.Log("Checking allowed item types");
Debug.Log("Allowed item types: " + allowedItemTypes + " / " + type);
// pretty print list
foreach (var allowedItemType in allowedItemTypes)
{
Debug.Log("-- allowed" + allowedItemType);
if (allowedItemType == type)
{
Debug.Log("Item type is allowed in slot: " + type);
isAllowed = true;
break;
}
}
return isAllowed;
}
public void SetAllowedEquipmentSlots(List<EquipmentSlot> slots)
{
allowedEquipmentSlots = slots;
}
public void AddAllowedEquipmentSlot(EquipmentSlot slot)
{
allowedEquipmentSlots.Add(slot);
}
public void RemoveAllowedEquipmentSlot(EquipmentSlot slot)
{
allowedEquipmentSlots.Remove(slot);
}
public bool IsAllowedEquipmentSlot(EquipmentSlot slot)
{
// if list is null, then all slots are allowed
if (allowedEquipmentSlots.Count == 0) return true;
var isAllowed = false;
Debug.Log("Checking allowed item types");
Debug.Log("Allowed item types: " + allowedEquipmentSlots + " / " + slot);
// pretty print list
foreach (var allowedEquipmentSlot in allowedEquipmentSlots)
{
Debug.Log("-- allowed" + allowedEquipmentSlots);
if (allowedEquipmentSlot == slot)
{
Debug.Log("Item type is allowed in slot: " + slot);
isAllowed = true;
break;
}
}
return isAllowed;
}
public void SetPosition(int i)
{
position = i;
}
public void SetItem(GameItem gameItem)
{
item = gameItem;
}
public int GetSlotId()
{
return position;
}
public void SetId(int i)
{
id = i;
}
}
}