Пример #1
0
    public bool TryEquipItem(Item elt)
    {
        EquipSlot target = null;

        // check constraints
        switch (elt.myInfo.equipConstraint)
        {
        case "Single weapon":
            if (myRightHand.equippedItem != null)
            {
                myRightHand.UnequipItem();
            }
            break;
        }

        // determine target
        if (elt.myInfo.myType == "Weapon")
        {
            if (elt.myInfo.nbHands == 1) // il faut ajouter le test comme quoi un item sans faces <= 6 ne peut pas être équipé en secondaire !
            {
                if (myLeftHand.equippedItem == null)
                {
                    target = myLeftHand;
                }
                else if (myLeftHand.equippedItem.myInfo.nbHands == 2)
                {
                    myLeftHand.UnequipItem(); target = myLeftHand;
                }
                else if (myLeftHand.equippedItem.myInfo.nbHands == 1 && myRightHand.equippedItem == null && (elt.myDice == null || elt.myDice.GetMinValue() <= 6))
                {
                    target = myRightHand;
                }
            }
            else if (elt.myInfo.nbHands == 2)
            {
                myLeftHand.UnequipItem();
                myRightHand.UnequipItem();
                target = myLeftHand;
                BlockSlot(myRightHand, true);
            }
        }
        else if (elt.myInfo.myType == "Equipment")
        {
            if (elt.myInfo.target == "Body")
            {
                if (myBody.equippedItem != null)
                {
                    myBody.UnequipItem();
                }
                target = myBody;
            }
            else if (elt.myInfo.target == "Head")
            {
                if (myHead.equippedItem != null)
                {
                    myHead.UnequipItem();
                }
                target = myHead;
            }
            else if (elt.myInfo.target == "Necklace")
            {
                if (myNecklace.equippedItem != null)
                {
                    myNecklace.UnequipItem();
                }
                target = myNecklace;
            }
        }

        if (target != null)
        {
            foreach (EquipSlot slot in new List <EquipSlot> {
                myHead, myLeftHand, myRightHand, myBody, myNecklace
            })
            {
                if (slot.equippedItem != null && slot.equippedItem.myInfo.equipConstraint != null)
                {
                    switch (slot.equippedItem.myInfo.equipConstraint)
                    {
                    case "Single weapon":
                        if (target == myRightHand)
                        {
                            slot.UnequipItem();
                        }
                        break;
                    }
                }
            }

            EquipItem(elt, target);
        }
        return(target != null);
    }