/// <summary> /// Equips the item. /// </summary> /// <param name="obj">The GameObject (Player) that wants to execute this action.</param> /// <returns>Returns true if the item was equipped successfully, false otherwise.</returns> public override bool Execute(GameObject obj) { invPanel = GameObject.FindGameObjectWithTag("InventoryPanel").GetComponent <InventoryPanel>(); eqPanel = GameObject.FindGameObjectWithTag("EquipmentPanel").GetComponent <EquipmentPanel>(); EquipmentManager equipManager = eqPanel.Manager; UsableItem useItem = toEquip as UsableItem; EquippableItem equipItem = toEquip as EquippableItem; if (equipItem != null) { EquippableItem currentlyEquipped = equipManager.DeEquip(equipItem.Slot); Debug.Log(equipItem); invPanel.ManagedInventory.RemoveItem(toEquip); if (currentlyEquipped == null || invPanel.ManagedInventory.AddItem(currentlyEquipped) == null) { // eqPanel.Manager = equipManager; equipManager.Equip(equipItem); // this should not fail return(true); } else { invPanel.ManagedInventory.AddItem(equipItem); equipManager.Equip(currentlyEquipped); return(false); } } else if (useItem != null) { bool yay = false; for (int i = 0; i < equipManager.GetHotbarItemsSize(); i++) { yay = equipManager.AddHotBarItem(useItem, i); if (yay) { invPanel.ManagedInventory.RemoveItem(useItem); break; } } return(yay); } else { throw new UnityException("WTF are you trying to equip my man"); } }
public void EquipmentHotbarAdd() { // Test that the potion is slotted in slot 1. Assert.IsNull(equips.GetHotbarItem(1)); Assert.IsTrue(equips.AddHotBarItem(potion, 1)); UsableItem potionNew = equips.GetHotbarItem(1); Assert.IsNotNull(potionNew); // Test that two items cannot slot to the same location. Assert.IsFalse(equips.AddHotBarItem(weapon, 1)); // Test that the weapon can be slotted in slot 5 though. Assert.IsTrue(equips.AddHotBarItem(weapon, 5)); // Test that it cannot be slotted above the hotbar size. Assert.IsFalse(equips.AddHotBarItem(weapon, 11)); }