mwg API
    Preparing search index...

    Class Inventory

    Index
    capacity?: number
    • Finds the first item of a kind, or the matching instance when instanceId is supplied.

      Parameters

      • id: string
      • OptionalinstanceId: string

      Returns InventoryItem | undefined

    • removes up to quantity (default: the whole stack); the slot disappears once empty

      Parameters

      • id: string
      • Optionalquantity: number
      • OptionalinstanceId: string

      Returns void

    • Takes up to quantity from one stack and returns an item snapshot suitable for adding to another inventory. All instance state travels with it; only the quantity is split.

      Parameters

      • id: string
      • quantity: number = 1
      • OptionalinstanceId: string

      Returns InventoryItem | undefined

    • What a save has to remember about one slot: its id, how many, and every field that can diverge between two items sharing that id.

      The split is the whole design question here. stackable and weight describe the kind of item and live in a game's own item table, so they are supplied fresh on load like every other definition in this framework, and a game that rebalances an item's weight sees the new value on an old save rather than the stale one baked into it. Everything else - an enchantment level, wear, a rolled affix, whether it has been identified, the instanceId keeping two otherwise-identical swords apart - belongs to the individual item and is exactly what would be lost if a save recorded only "3 x potion".

      Returns SavedInventory

    • Rebuilds an inventory, taking each item's kind-level fields from defs.

      Throws on an id defs does not know, rather than restoring a weightless unstackable ghost of it: a save naming an item the game no longer has is a real problem, and finding out at load is far cheaper than finding out when a carry-weight check silently disagrees.

      Parameters

      Returns Inventory