quest resource check fix

This commit is contained in:
2024-12-30 16:30:19 +05:30
parent edf82b4337
commit 7ea988ddeb
6 changed files with 158 additions and 172 deletions

View File

@@ -19,9 +19,9 @@ public class InventoryManager : MonoBehaviour
{
if (resetInventory)
{
resetInventory= false;
resetInventory = false;
foreach(InventorySlot slot in inventorySlots)
foreach (InventorySlot slot in inventorySlots)
{
slot.Clear();
}
@@ -30,40 +30,78 @@ public class InventoryManager : MonoBehaviour
public item GetItemByType(string type)
{
foreach(item i in lootsData.items)
foreach (item i in lootsData.items)
{
if(i.type == type)
if (i.type == type)
{
return i;
}
}
Debug.Log("Could not find anything for " + type);
Debug.Log("Could not find anything for " + type);
return null;
}
void Start(){
foreach(item i in startingItems){
void Start()
{
foreach (item i in startingItems)
{
AddInvItem(i);
}
}
public Dictionary<int, string> GetEntries(){
public Dictionary<int, string> GetEntries()
{
Dictionary<int, string> entries = new Dictionary<int, string>();
for(int i=0; i < inventorySlots.Length; i++){
for (int i = 0; i < inventorySlots.Length; i++)
{
ItemInventory itemInSlot = inventorySlots[i].GetComponentInChildren<ItemInventory>();
if(itemInSlot!= null && itemInSlot.item != null){
if (itemInSlot != null && itemInSlot.item != null)
{
entries.Add(i, itemInSlot.item.type);
}
}
return entries;
}
public int GetStock(string type)
{
int count = 0;
for (int i = 0; i < inventorySlots.Length; i++)
{
ItemInventory itemInSlot = inventorySlots[i].GetComponentInChildren<ItemInventory>();
if (itemInSlot != null && itemInSlot.item != null)
{
if (itemInSlot.item.type == type)
{
count++;
}
}
}
return count;
}
public void RemoveItem(string type)
{
for (int i = 0; i < inventorySlots.Length; i++)
{
ItemInventory itemInSlot = inventorySlots[i].GetComponentInChildren<ItemInventory>();
if (itemInSlot != null && itemInSlot.item != null)
{
if (itemInSlot.item.type == type)
{
Destroy(itemInSlot.gameObject);
return;
}
}
}
}
public void SetInventory(Dictionary<int, string> data)
{
Clear();
foreach(KeyValuePair<int, string> entry in data)
foreach (KeyValuePair<int, string> entry in data)
{
SpawnNewItem(GetItemByType(entry.Value), inventorySlots[entry.Key]);
}
@@ -71,12 +109,12 @@ public class InventoryManager : MonoBehaviour
public bool UseItem(item i)
{
if(pnet.health >= 100)
if (pnet.health >= 100)
{
return false;
}
pnet.SetHealth(pnet.health+i.healthIncrease);
pnet.SetHealth(pnet.health + i.healthIncrease);
pnet.SavePlayerData();
return true;
@@ -84,7 +122,8 @@ public class InventoryManager : MonoBehaviour
public item selectedItem;
public void SelectItem(item itemI){
public void SelectItem(item itemI)
{
selectedItem = itemI;
}
@@ -100,14 +139,17 @@ public class InventoryManager : MonoBehaviour
AddInvItem(GetItemByType(type));
}
public void AddInvItem (item item){
public void AddInvItem(item item)
{
//find an empty slot
for(int i = inventorySlots.Length-1; i >=0 ; i--){
for (int i = inventorySlots.Length - 1; i >= 0; i--)
{
InventorySlot slot = inventorySlots[i];
ItemInventory itemInSlot = slot.GetComponentInChildren<ItemInventory>();
if(itemInSlot == null){
SpawnNewItem(item , slot);
if (itemInSlot == null)
{
SpawnNewItem(item, slot);
return;
}
//implement check for slot full
@@ -116,30 +158,35 @@ public class InventoryManager : MonoBehaviour
Debug.Log("Slots are full");
}
public void Clear(){
for(int i=0; i < inventorySlots.Length; i++){
if(inventorySlots[i].transform.childCount > 0){
public void Clear()
{
for (int i = 0; i < inventorySlots.Length; i++)
{
if (inventorySlots[i].transform.childCount > 0)
{
Destroy(inventorySlots[i].transform.GetChild(0).gameObject);
}
}
}
void SpawnNewItem(item item , InventorySlot slot ){
GameObject newItemAdd = Instantiate(ItemInventoryPrefab , slot.transform);
void SpawnNewItem(item item, InventorySlot slot)
{
GameObject newItemAdd = Instantiate(ItemInventoryPrefab, slot.transform);
ItemInventory inventoryItemm = newItemAdd.GetComponent<ItemInventory>();
inventoryItemm.Set(item,this);
inventoryItemm.Set(item, this);
pnet.SavePlayerData();
}
}
}
[System.Serializable]
public class InventoryEntry{
public class InventoryEntry
{
public int slot;
public string item;
}