示例#1
0
        public void Unequip(Item item, Item target = null)
        {
            if (item.IsEmpty)
            {
                throw new Exception("Trying to unequip empty item.");
            }

            if (item.IsAnySkillOnCooldown())
            {
                throw new SkillIsOnCooldownException();
            }

            var slot = FindContainingSlot(item);

            if (slot == null)
            {
                throw new Exception($"Item {item.Name} #{item.GetHashCode()} is not equipped.");
            }

            item.Equipment = null;

            if (target == null || target.Inventory == null)
            {
                item.Inventory.Pickup(slot.Item);
            }
            else
            {
                target.Inventory.Pickup(slot.Item, target);
            }

            slot.Clear();

            RemoveItemBonuses(item, slot);
            RemoveVisuals(item, slot);

            item.EquipmentSlot = null;

            ItemUnequipped?.Invoke(item);
        }
示例#2
0
 private void OnItemUnequipped()
 {
     ItemUnequipped?.Invoke(this, EventArgs.Empty);
 }