예제 #1
0
    public void EquipmentDequip()
    {
        // Add the two equippables.
        equips.Equip(ring);
        equips.Equip(chestPlate);

        // Attempt to remove from an empty slot, should return null.
        Assert.IsNull(equips.DeEquip(EquipmentManager.EquipSlot.GLOVES));

        // Remove from the ring slot, should be the ring item.
        EquippableItem ringAgain = equips.DeEquip(EquipmentManager.EquipSlot.RING);

        Assert.IsNotNull(ringAgain);
        Assert.IsNull(equips.GetEquippedItem(EquipmentManager.EquipSlot.RING));
    }
예제 #2
0
    /// <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");
        }
    }