Skip to content

Economy – Adapters – Inventory

⚠️ Implementation glue – not supported public API

This folder contains the inventory integration layer for the Economy subsystem. It adapts an IInventoryService container into the IItemStore abstraction used by Shop, Crafting, and Reward flows.

All types documented here live under: RevGaming.RevFramework.Economy.Internal.Adapters.Inventory

They are implementation details. Gameplay code should depend on IItemStore, not on the concrete adapter defined here.


Purpose

Provide a safe, rollback-aware bridge between the Inventory module and Economy item operations.

This adapter allows the Economy system to:

  • Perform item add/remove operations
  • Perform ownership and capacity preflight checks
  • Participate in deterministic rollback flows

…without taking a hard dependency on any particular inventory implementation.


Component

Inventory-backed item store

The built-in inventory adapter provides an internal implementation of IItemStore backed by an IInventoryService and a named container (for example, "Backpack").

Behaviour

  • Preflight checks
  • HasSpaceFor(item) — verifies capacity for exactly the requested quantity.
  • CanRemove(item) — verifies ownership and quantity.

  • Runtime operations

  • Add(item, reason) — adds items via the underlying inventory container.
  • Remove(item, reason) — removes items via the underlying inventory container.

  • Item definition resolver required

  • A resolver (guid → ItemDefinition) is required for Add() operations.
  • Missing or unknown GUIDs result in EcoOpCode.ResolverMissing.

Error handling

Inventory-layer failures are mapped into Economy result codes:

  • Missing inventory service or owner → EcoOpCode.ServiceMissing
  • Missing container → EcoOpCode.ContainerMissing
  • Missing resolver or unknown item GUID → EcoOpCode.ResolverMissing
  • Invalid or empty item lines → EcoOpCode.InvalidArgs

These codes propagate upward through Economy services unchanged.


Telemetry

  • Item operations do not propagate sourceId (a limitation of the IItemStore abstraction).
  • The reason string is forwarded to the underlying inventory container, if it supports telemetry or logging.
  • Correlation with currency operations should be performed at the service layer.

Usage

You normally do not construct inventory adapters manually.

They are wired automatically by EconomyBootstrap when building an inventory-enabled economy pipeline:

var (shop, rewards, crafting, ledger, store) =
    EconomyBootstrap.BuildForPlayer(
        player,
        currencyService,
        inventoryService,
        guidResolver,
        "Backpack",
        policy
    );

The returned IItemStore is then used internally by: - Shop services - Crafting services - Reward services (for item rewards)

If you remove the built-in inventory adapter, you must supply your own implementation of IItemStore.


Stability

  • Inventory adapters are replaceable via the abstraction layer.
  • They are not part of the public gameplay API.
  • Behaviour is stable within a major version; internal structure may evolve.
  • Always depend on IItemStore, never on concrete adapter types.

See also

  • Economy – Abstractions
  • Economy – Adapters (Overview)
  • Economy – Adapters – Currency
  • Economy – Services