public bool AddItem(Item item) // inventory on player and then call when wanting to add item { if (item.maxSize == 1) { PlaceEmpty(item); return(true); } else { foreach (GameObject slot in allSlots) { slot tmp = slot.GetComponent <slot>(); if (!tmp.IsEmpty) { if (tmp.CurrentItem.type == item.type && tmp.CanStack) { tmp.AddItem(item); return(true); } } } if (emptySlots > 0) { PlaceEmpty(item); } } return(false); }
private bool PlaceEmpty(Item item) // finds next empty slot to place items in returns false if no slot { if (emptySlots > 0) { foreach (GameObject slot in allSlots) { slot tmp = slot.GetComponent <slot>(); if (tmp.IsEmpty) { if (tmp.name == "Spell" && item.isSpell()) // checks if its a slot spell and item is a spell { Debug.Log("slot is spell and item is spell"); if (SceneManager.GetActiveScene().name == "fire_dungeon" && !GameSaver.liveSave.bossKilled[0]) { GameSaver.liveSave.firstFire = true; } if (SceneManager.GetActiveScene().name == "water_dungeon" && !GameSaver.liveSave.bossKilled[1]) { GameSaver.liveSave.firstIce = true; } if (SceneManager.GetActiveScene().name == "maze_dungeon" && !GameSaver.liveSave.bossKilled[2]) { GameSaver.liveSave.firstPush = true; } tmp.AddItem(item); emptySlots--; return(true); } else if (tmp.name == "Slot" && !item.isSpell()) { Debug.Log("slot is slot and item is not spell"); tmp.AddItem(item); emptySlots--; return(true); } } } } return(false); }