mwg API
    Preparing search index...

    Class EquipmentSlots<Slot, Item>

    Equipment slots, defined per game rather than fixed by the framework - 'leftHand' and 'rightHand', or 'weapon' / 'armor' / 'amulet', or a dozen Diablo-style slots. Whatever an item's modifiers are, equipping it applies them to the given StatBlock and unequipping removes exactly those - tagged by the item itself as their source, so two rings of the same kind never remove each other's bonus by mistake.

    import { EquipmentSlots, StatBlock } from '@datamoc/mw_games/actors';

    const stats = new StatBlock({ base: { attack: 3 } });
    const equipment = new EquipmentSlots<'weapon' | 'armor', { modifiers?: import('@datamoc/mw_games/actors').Modifier[] }>(
    ['weapon', 'armor'],
    stats
    );

    const sword = { modifiers: [{ stat: 'attack', op: 'add' as const, value: 5 }] };
    equipment.equip('weapon', sword);
    console.log(stats.get('attack')); // 8

    equipment.unequip('weapon');
    console.log(stats.get('attack')); // 3

    Type Parameters

    Index
    • Parameters

      Returns Item | undefined

      the item that was previously in this slot, if any - or undefined without changing anything when the slot is locked

    • true when the slot holds something that refuses to come off - check this, since a refused unequip is otherwise indistinguishable from an empty slot

      Parameters

      Returns boolean

    • Which slot holds which item, by whatever id identify gives each one.

      An item is a game's own object here (Item is a type parameter, and EquippableItem requires only modifiers), so this framework has no idea what identifies one. The caller says, usually with the same id its item table is keyed by.

      Parameters

      • identify: (item: Item) => string

      Returns SavedEquipment<Slot>

    • Rebuilds the slots and re-equips everything, so each item's modifiers land back on the StatBlock exactly as they were.

      That reapplication is the point: StatBlock.toJSON deliberately saves no modifiers, precisely because whatever applied them puts them back on load. A locked item is restored rather than refused - a cursed ring the character was already wearing is still on their finger after a reload, and equip's refusal is about putting one on, which is not what this is doing.

      Type Parameters

      Parameters

      • defs: {
            locked?: (slot: Slot, item: Item) => boolean;
            resolve: (id: string) => Item;
            slots: readonly Slot[];
            stats?: StatBlock | null;
        }
        • Optionallocked?: (slot: Slot, item: Item) => boolean
        • resolve: (id: string) => Item

          turns a saved id back into the game's own item object

        • slots: readonly Slot[]
        • Optionalstats?: StatBlock | null
      • data: SavedEquipment<Slot>

      Returns EquipmentSlots<Slot, Item>