mwg API
    Preparing search index...

    Interface InventoryItem

    Items a character carries: stacking, weight, and containers within containers.

    A slot holds a quantity of one kind of item rather than one entry per item, which is what stacking means in practice - forty arrows are one inventory slot, not forty. Weight and capacity are optional: a game that does not track carry weight simply never sets a capacity, and every check trivially passes.

    import { Inventory } from '@datamoc/mw_games/actors';

    const bag = new Inventory({ capacity: 50 });
    bag.add({ id: 'potion', quantity: 3, stackable: true, weight: 0.5 });
    bag.add({ id: 'potion', quantity: 2, stackable: true, weight: 0.5 }); // merges into one stack of 5

    const potion = bag.find('potion');
    console.log(potion?.quantity, bag.totalWeight);
    interface InventoryItem {
        affix?: string;
        blessed?: boolean;
        category?: string;
        contents?: Inventory;
        cursed?: boolean;
        durability?: number;
        id: string;
        identified?: boolean;
        instanceId?: string;
        level?: number;
        maxDurability?: number;
        quantity: number;
        stackable?: boolean;
        weight?: number;
    }
    Index
    affix?: string

    a named affix - an enchantment, glyph, augment or curse id from an AffixTable

    blessed?: boolean
    category?: string

    A kind-level grouping - 'herb', 'runestone', 'potion' - so a recipe can ask for "any herb" rather than one exact id. Like stackable and weight it describes the item's kind, so it comes from the game's item definitions on load and is not part of a save.

    contents?: Inventory

    a container - a bag, a chest - whose own weight adds to whatever is inside it

    cursed?: boolean
    durability?: number

    remaining durability; omit for an item that cannot wear out at all

    id: string

    identifies the kind of item; two stackable entries with the same id (and instanceId) merge

    identified?: boolean

    an unidentified potion, a cursed ring the player does not yet know is cursed

    instanceId?: string

    Distinguishes otherwise-identical instances of the same item id - two "sword"s, one enchanted and one not, or two enchanted differently - so they never silently merge into one stack the way plain quantity stacking assumes every unit of an id is interchangeable. Omitted (the default, and the only behaviour before this existed), every stackable item of an id still merges into a single stack.

    level?: number

    an enchantment or upgrade level above the item's base, such as a weapon's "+2"

    maxDurability?: number
    quantity: number
    stackable?: boolean
    weight?: number