You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.0 KiB
C#

4 years ago
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SiegeSong;
namespace SiegeSong
{
public class Container : MonoBehaviour
{
//public int OwnerActorID;
public Dictionary<int, int> Contents = new Dictionary<int, int>();
public GameObject[] StartingItems;
public string Name;
public InventoryManager InventoryManager;
void Start()
{
foreach (var item in StartingItems)
{
var inventoryItem = item.GetComponent<InventoryItem>();
if (!Contents.ContainsKey(inventoryItem.ID))
Contents.Add(inventoryItem.ID, 1);
}
}
void Update()
{
}
public void AddItem(int itemID, int amount)
{
if (Contents.ContainsKey(itemID))
Contents[itemID] += amount;
else
Contents.Add(itemID, amount);
}
public void RemoveItem(int itemID, int amount)
{
if (Contents.ContainsKey(itemID))
{
var currentlyOwnedCount = Contents[itemID];
if (InventoryManager.EquipmentManager.LeftHandCurrentEquipIndex == itemID)
{
InventoryManager.EquipmentManager.LeftHandCurrentEquipIndex = 0;
}
if (InventoryManager.EquipmentManager.AbilityCurrentEquipIndex == itemID)
{
InventoryManager.EquipmentManager.AbilityCurrentEquipIndex = 0;
}
if (InventoryManager.EquipmentManager.RightHandCurrentEquipIndex == itemID)
{
InventoryManager.EquipmentManager.RightHandCurrentEquipIndex = 0;
}
if (InventoryManager.ApparrelManager.CurrentlyActiveIDs.Contains(itemID))
{
var newList = new List<int>();
for (var i = 0; i < InventoryManager.ApparrelManager.CurrentlyActiveIDs.Length; i++)
if (InventoryManager.ApparrelManager.CurrentlyActiveIDs[i] != itemID)
newList.Add(InventoryManager.ApparrelManager.CurrentlyActiveIDs[i]);
InventoryManager.ApparrelManager.CurrentlyActiveIDs = newList.ToArray();
InventoryManager.ApparrelManager.UpdateApparrel();
}
if (currentlyOwnedCount - amount > 0)
Contents[itemID] = currentlyOwnedCount - amount;
else
Contents.Remove(itemID);
}
}
public int GetIDByOwnedIndex(int index)
{
var i = 0;
if (Contents != null && Contents.Keys.Count > 0)
{
foreach (var key in Contents.Keys)
{
if (i == index)
return key;
i++;
}
}
return -1;
}
}
}