131 lines
3.8 KiB
C#
131 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using FishNet.Object;
|
|
using Types;
|
|
using Types.Items;
|
|
using Types.UI;
|
|
using UnityEngine;
|
|
|
|
namespace Managers.Item
|
|
{
|
|
public class InventoryManager : NetworkBehaviour, IItemManager<GameSlot>
|
|
{
|
|
public PlayerManager playerManager;
|
|
public readonly Dictionary<int, GameSlot> Slots = new();
|
|
|
|
private void Start()
|
|
{
|
|
Debug.Log("InventoryManager Start");
|
|
}
|
|
|
|
public GameSlot GetSlot(int slotId)
|
|
{
|
|
return Slots.GetValueOrDefault(slotId, null);
|
|
}
|
|
|
|
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.GameItem;
|
|
Debug.Log("Added item to slot: " + slot.position + " / " + item.GameItem.itemName + " / " +
|
|
item.GameItem.quantity);
|
|
return;
|
|
}
|
|
|
|
Debug.LogWarning("No empty slots available to add item: " + item.GameItem.itemName);*/
|
|
}
|
|
|
|
public void AddItemToSlot(GameItem item, int slotId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void AddSlot(GameSlot gameSlot)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
/*[ServerRpc]
|
|
public void AddSlot(Slot slot)
|
|
{
|
|
Slots[slot.position] = slot;
|
|
}
|
|
|
|
[ServerRpc]
|
|
public void AddItemToSlot(SyncGameItem item, int slotId)
|
|
{
|
|
/*if (Slots.TryGetValue(slotId, out var slot))
|
|
slot.item = item.GameItem;
|
|
else
|
|
Debug.LogWarning("Slot not found: " + slotId);#1#
|
|
}
|
|
|
|
[ServerRpc]
|
|
public void RemoveItemFromSlot(SyncGameItem item)
|
|
{
|
|
/*foreach (var slot in Slots.Values)
|
|
if (slot.item == item.GameItem)
|
|
{
|
|
slot.item = null;
|
|
Debug.Log("Removed item from slot: " + item.GameItem.itemName);
|
|
return;
|
|
}
|
|
|
|
Debug.LogWarning("Item not found in any slot: " + item.GameItem.itemName);#1#
|
|
}*/
|
|
|
|
public void RemoveItemInSlot(int slotId)
|
|
{
|
|
if (Slots.TryGetValue(slotId, out var slot))
|
|
slot.Item = null;
|
|
else
|
|
Debug.LogWarning("Slot not found: " + slotId);
|
|
}
|
|
|
|
/*public void Initialize(PlayerData playerData)
|
|
{
|
|
// create player slots for inventory
|
|
Slots.Clear();
|
|
for (var i = 0; i < playerData.inventorySize; i++)
|
|
{
|
|
var slot = ScriptableObject.CreateInstance<Slot>();
|
|
slot.position = i;
|
|
slot.item = playerData.InventorySlots[i].item;
|
|
AddSlot(slot);
|
|
}*/
|
|
|
|
// Debug.Log("Completed Initialized items in InventoryManager");
|
|
public void Initialize(GamePlayer getGamePlayerData)
|
|
{
|
|
//
|
|
}
|
|
}
|
|
} |