lib/inventory.js
function equipFromInventory (attributes, index, slotName) {
        if (index >= attributes.inventory.length) {
            throw new InventoryIndexError(index);
        }

        var item = attributes.inventory[index];

        if (!slotName) {
            slotName = item.slot;
        }

        if (!slotName) {
            throw new UnequippableItemError(item.name);
        }

        if (!(slotName in attributes.equipped)) {
            throw new SlotNameError(slotName);
        }

        if (item.slot !== slotName) {
            throw new InvalidSlotError(item.slot, slotName);
        }

        if (!requirements.met(attributes, item.requirements)) {
            throw new RequirementsNotMetError();
        }

        if (attributes.equipped[slotName]) {
            unEquip(attributes, slotName);
        }

        attributes.inventory.splice(index, 1);
        attributes.equipped[slotName] = item;

        return attributes;
    }
function equipFromInventory (attributes, index, slotName) {
        if (index >= attributes.inventory.length) {
            throw new InventoryIndexError(index);
        }

        var item = attributes.inventory[index];

        if (!slotName) {
            slotName = item.slot;
        }

        if (!slotName) {
            throw new UnequippableItemError(item.name);
        }

        if (!(slotName in attributes.equipped)) {
            throw new SlotNameError(slotName);
        }

        if (item.slot !== slotName) {
            throw new InvalidSlotError(item.slot, slotName);
        }

        if (!requirements.met(attributes, item.requirements)) {
            throw new RequirementsNotMetError();
        }

        if (attributes.equipped[slotName]) {
            unEquip(attributes, slotName);
        }

        attributes.inventory.splice(index, 1);
        attributes.equipped[slotName] = item;

        return attributes;
    }
function equipFromInventory ( attributes , index , slotName ) { if ( index >= attributes . inventory . length ) { throw new InventoryIndexError ( index ) ; } var item = attributes . inventory [ index ] ; if ( ! slotName ) { slotName = item . slot ; } if ( ! slotName ) { throw new UnequippableItemError ( item . name ) ; } if ( ! ( slotName in attributes . equipped ) ) { throw new SlotNameError ( slotName ) ; } if ( item . slot !== slotName ) { throw new InvalidSlotError ( item . slot , slotName ) ; } if ( ! requirements . met ( attributes , item . requirements ) ) { throw new RequirementsNotMetError ( ) ; } if ( attributes . equipped [ slotName ] ) { unEquip ( attributes , slotName ) ; } attributes . inventory . splice ( index , 1 ) ; attributes . equipped [ slotName ] = item ; return attributes ; }
Equips item which is located in inventory by given index
@param {Attributes} attributes which object should be operated.
@param {number} index inventory slot number
@param {String} slotName where to equip
Equips item which is located in inventory by given index