Exemple #1
0
        public Item Equip(Item equippable, EquipmentSlot slot)
        {
            if (equippable.SlotKind != slot.Kind || !Slots.Contains(slot))
            {
                return(null);
            }

            Item previousItem = null;

            if (SlotsInUse.Contains(slot))
            {
                previousItem = _equipped[slot];
            }


            _equipped[slot] = equippable;
            SlotsInUse.Add(slot);

            OnEquipped?.Invoke(slot, equippable);

            if (previousItem != null)
            {
                OnUnequipped?.Invoke(slot, previousItem);
            }

            return(previousItem);
        }
Exemple #2
0
    public void Unequip(EquipSlot slot)
    {
        Equipable e = _equipment[(int)slot];

        _equipment[(int)slot]?.OnUnequip();
        _equipment[(int)slot] = null;

        OnUnequipped?.Invoke(e);
    }
Exemple #3
0
        public bool Unequip()
        {
            if (IsEmpty)
            {
                return(false);
            }
            IWeapon prevWeapon = Weapon;

            Weapon = null;
            OnUnequipped?.Invoke(prevWeapon);
            return(true);
        }