196 lines
4.3 KiB
C#
196 lines
4.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// BaseSlot.cs
|
|
public class Slot : ScriptableObject
|
|
{
|
|
public enum SlotType
|
|
{
|
|
Inventory,
|
|
Toolbar,
|
|
Equipment,
|
|
Crafting,
|
|
Box,
|
|
Shop,
|
|
Quest
|
|
}
|
|
|
|
public GameItem item;
|
|
public int quantity;
|
|
public int slotId = -1;
|
|
public bool isLocked;
|
|
public SlotType slotType;
|
|
public List<GameItem.ItemType> allowedItemTypes = new();
|
|
public List<EquipmentItem.Slot> allowedEquipmentSlots = new();
|
|
|
|
public bool isSelected;
|
|
|
|
public Slot()
|
|
{
|
|
item = null;
|
|
quantity = 0;
|
|
isLocked = false;
|
|
}
|
|
|
|
public virtual void Initialize(GameItem gameItem, int qty)
|
|
{
|
|
item = gameItem;
|
|
quantity = qty;
|
|
}
|
|
|
|
public virtual void AssignGameItem(GameItem gameItem, int qty = 1)
|
|
{
|
|
item = gameItem;
|
|
quantity = qty;
|
|
}
|
|
|
|
public virtual void AddQuantity(int amount)
|
|
{
|
|
quantity += amount;
|
|
}
|
|
|
|
public virtual void RemoveQuantity(int amount)
|
|
{
|
|
quantity -= amount;
|
|
}
|
|
|
|
public virtual void SetQuantity(int amount)
|
|
{
|
|
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.name : string.Empty;
|
|
}
|
|
|
|
public virtual float GetItemValue()
|
|
{
|
|
return item != null ? item.itemValue : 0f;
|
|
}
|
|
|
|
public bool IsSlotType<T>() where T : Slot
|
|
{
|
|
return this is T;
|
|
}
|
|
|
|
public void SetSlotType(SlotType type)
|
|
{
|
|
slotType = type;
|
|
}
|
|
|
|
public void SetSlotId(int id)
|
|
{
|
|
slotId = id;
|
|
}
|
|
|
|
public void SetLocked(bool locked)
|
|
{
|
|
isLocked = locked;
|
|
}
|
|
|
|
public void SetAllowedItemTypes(List<GameItem.ItemType> types)
|
|
{
|
|
allowedItemTypes = types;
|
|
}
|
|
|
|
public void AddAllowedItemType(GameItem.ItemType type)
|
|
{
|
|
allowedItemTypes.Add(type);
|
|
}
|
|
|
|
public void RemoveAllowedItemType(GameItem.ItemType type)
|
|
{
|
|
allowedItemTypes.Remove(type);
|
|
}
|
|
|
|
public bool IsAllowedItemType(GameItem.ItemType type)
|
|
{
|
|
return allowedItemTypes.Contains(type);
|
|
}
|
|
|
|
|
|
public void ClearAllowedItemTypes()
|
|
{
|
|
allowedItemTypes.Clear();
|
|
}
|
|
|
|
public List<GameItem.ItemType> GetAllowedItemTypes()
|
|
{
|
|
return allowedItemTypes;
|
|
}
|
|
|
|
public void ClearSlot()
|
|
{
|
|
item = null;
|
|
quantity = 0;
|
|
}
|
|
|
|
public bool IsAllowedItemTypes(GameItem.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<EquipmentItem.Slot> slots)
|
|
{
|
|
allowedEquipmentSlots = slots;
|
|
}
|
|
|
|
public void AddAllowedEquipmentSlot(EquipmentItem.Slot slot)
|
|
{
|
|
allowedEquipmentSlots.Add(slot);
|
|
}
|
|
|
|
public void RemoveAllowedEquipmentSlot(EquipmentItem.Slot slot)
|
|
{
|
|
allowedEquipmentSlots.Remove(slot);
|
|
}
|
|
|
|
public bool IsAllowedEquipmentSlot(EquipmentItem.Slot 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;
|
|
}
|
|
} |