Example #1
0
        public void EquipIntoSlot(Item item, EquipmentSlot slot)
        {
            if (this.experience != null && item.RequiredLevel > this.experience.Experience.Level)
            {
                return;
            }

            if (item.IsEmpty)
            {
                Debug.LogError("Trying to equip empty item.");
                return;
            }

            if (!slot.CanEquip(item))
            {
                Debug.LogError($"Can't equip item {item.Name} into slot with type {slot.Type}");
                return;
            }

            if (IsEquipped(item))
            {
                Unequip(item);
            }

            if (!slot.IsEmpty)
            {
                Unequip(slot.Item);
            }

            item.Type.EquipmentStrategy.Prepare(item, slot, this);
            item.EquipmentSlot = slot;
            item.Equipment     = this;

            item.Inventory?.Remove(item);
            item.Inventory = this.inventory;

            slot.Put(item);

            ApplyItemBonuses(item, slot);
            ApplyVisuals(item, slot);

            ItemEquipped?.Invoke(item);
        }