RevFramework – Integration Scene: 01_Economy_WithInventory¶
Goal¶
Teach full Economy orchestration across money and inventory:
Player owner → ICurrencyService + IInventoryService → IValueLedger + IItemStore → Shop / Sell / Craft / Reward → EcoOpResult.
What This Scene Demonstrates¶
This scene shows Economy coordinating Currency and Inventory through public abstractions.
The flow is:
Player → Currency service + Inventory service → EconomyInventoryBootstrap → IValueLedger / IItemStore → Economy service call → EcoOpResult
- Currency owns value mutation
- Inventory owns item ownership, removal, delivery, and space checks
- Economy orchestrates money and item services
- Preflight checks guide button state only
- Execution result is truth
- Rollback behaviour is operation-specific
- Failure injection is teaching-only, but it still wraps public contracts
This is an integration scene.
No Economy internals are used as supported integration points.
What To Look For¶
Use the EconomyWithInventoryPanel to observe full money + item flows.
-
Binding State
-
Player is the owner of both wallet and inventory container
- Currency is the assigned
ICurrencyService - Inventory is the assigned
IInventoryService - Container identifies the target inventory container, such as
Backpack -
ItemGuidMapresolves item guid strings intoItemDefinitionassets -
Balances
-
Reads watched currency ids from the currency service
- Shows whether money changed after Buy, Sell, Craft, or Reward
-
The log also reports a balance delta per operation, which is the part that makes rollback legible: a Buy that refunded and a Buy that never charged end on the same number, and only the delta line distinguishes money moved and came back from money never moved
-
Container Preview
-
Reads the live inventory container
- Shows item stacks currently owned by the player
-
Use this with balances to verify actual mutation results
-
Preflight
-
CanPay,CanRemove, andHasSpaceForare UX checks only - Buttons may disable when preflight expects failure
-
Final truth still comes from
EcoOpResult -
Rollback
-
Buy can refund money and rollback delivery failures
- Sell can restore removed items if payout fails
- Craft can refund money and restore ingredients if result delivery fails
-
Reward grants money first, then items; money is not rolled back if item grants fail
-
Failure Injection (wrapped)
-
Buy delivery failure wraps
IItemStore.Add - Sell payout failure wraps
IValueLedger.Grant - Craft result failure wraps
IItemStore.Add - These wrappers are teaching-only and exist to make rollback visible
-
What they prove: the rollback path runs when a dependency reports failure
-
Real Failure (not wrapped)
-
Saturate Container Before Execute fills the live container through the real
IInventoryServicebefore the operation runs - Preflight passes, the container genuinely fills, and delivery then fails because there is no space — nothing is wrapped and nothing is faked
- What it proves: the system fails the way a player's full backpack makes it fail
- Composes with the toggles above, so both kinds of failure can be shown side by side
-
Needs a blocker item assigned.
Blocker Quantity Per Pressdefaults to 999 — see the capacity note under How To Use -
Log
-
Shows operation summaries and source correlation
- Use it alongside balances and container preview
Sample Scope¶
This scene covers:
- Economy + Inventory integration
- Public
IValueLedgerandIItemStoreusage - Buy flow with money and item delivery
- Sell flow with item removal and money payout
- Reward flow with money and/or item payout
- UX preflight checks
- Operation-specific rollback behaviour
- Teaching-only failure injection through public wrappers
- Real failure through container saturation, with nothing wrapped
- Per-operation balance deltas
- Source/correlation id generation using
EcoSource.Build
Craft is supported by the panel but not configured in this scene
The panel implements the full Craft flow — costs, ingredients, result delivery, and the Force Add Fail (Craft) toggle — and the sections below describe all of it.
This scene ships with Craft Cost and Craft Result left empty, so the Craft button stays disabled and the Craft toggle has nothing to act on. That keeps the teaching focus on Buy, Sell and Reward; crafting has its own scene and video.
To try Craft here, fill in Craft Cost and Craft Result on the panel. Nothing else needs changing.
This scene does NOT cover:
- Crafting integration (covered in a dedicated scene/video)
- Crafting system authoring in depth
- Inventory item definition design in depth
- Multiplayer replication or networking
- Backend transaction coordination
- Production logging pipelines
- Save/load persistence for economy state
Those are covered by other systems or project-level integration work.
Authority Note¶
This scene may include a permissive sample authority setup so it runs without additional configuration.
Networking Reminder¶
RevFramework does not include networking.
For multiplayer projects, Economy actions must be validated and executed through your own authority and networking layer. Preflight is not authority, and rollback shown here is local service behaviour, not network transaction coordination.
How To Use¶
- Enter Play Mode.
- Open the
EconomyWithInventoryPanel. -
Confirm the required bindings:
-
Player owner is assigned
ICurrencyServiceis assignedIInventoryServiceis assigned- Container name matches the player inventory container
- Assign an
ItemGuidMapif item additions, craft results, or item rewards should succeed. - Use supporting panels or gameplay to seed money and items if needed.
- Check Balances and Container Preview before running an action.
-
Run one of the actions:
-
Buy
- Sell
- Craft
- Reward
- Inspect the returned
EcoOpResult. - Check balances and container preview to verify what actually changed.
-
Enable failure injection toggles to observe rollback paths:
- Force Deliver Fail for Buy
- Force Payout Fail for Sell
- Force Add Fail for Craft — requires Craft Cost and Craft Result to be filled in first
- Then enable Saturate Container Before Execute and run the same action again, to see the identical rollback happen without anything being wrapped.
- Check the Log for operation summaries, source correlation, and the per-operation balance delta.
Seeing Real Failure¶
The wrapped toggles and the saturation toggle answer two different questions, which is why both exist:
| Wrapped toggles | Saturate Container | |
|---|---|---|
| How failure happens | A stub IItemStore / IValueLedger returns failure | The real container genuinely runs out of space |
| What it proves | Rollback runs when a dependency says no | The system fails the way a player's full backpack makes it fail |
| Preflight | Passes — the wrapper is invisible to it | Passes, then the panel fills the container before executing |
Container capacity decides whether this works
Saturation adds Blocker Quantity Per Press (default 999) of the blocker item through the real IInventoryService. If the container is large or effectively unbounded, one press will not fill it, preflight still holds, and nothing fails — the demo silently does nothing.
Give the demo container a small fixed capacity, or raise the quantity until one press saturates it. The log reports either Container saturated with … or a NoSpace code, and NoSpace here means it is already full — which is the intended state, not an error.
Also assign a blocker item. Without one the toggle is inert and the log says so.
Failure Behaviour¶
Failures are shown through dependency guards, disabled action reasons, result banners, toast messages, logs, and EcoOpResult.
Common causes:
-
Play Mode required
-
The panel reads and mutates live currency and inventory services
-
Fix: enter Play Mode
-
Missing Player Owner
-
No player owner is assigned
-
Fix: assign Player so the panel knows which wallet and container to use
-
Missing Currency Service
-
No
ICurrencyServiceis assigned -
Fix: assign a MonoBehaviour implementing
ICurrencyService -
Missing Inventory Service
-
No
IInventoryServiceis assigned -
Fix: assign a MonoBehaviour implementing
IInventoryService -
Economy Services Not Built
-
EconomyInventoryBootstrapdid not produce the required public services -
Fix: check player, currency service, inventory service, container, policy, and preflight mode
-
No ItemGuidMap assigned
-
Item guid strings may not resolve to
ItemDefinitionassets -
Fix: assign
ItemGuidMapif item delivery should succeed -
Container not found
-
The selected owner/container id does not resolve to an inventory container
-
Fix: check the container name or create the container before running item flows
-
Buy unavailable
-
The player cannot pay, lacks required item costs, or has no space for delivery
-
Fix: adjust balance, price, item ownership, inventory space, policy, or preflight mode
-
Sell unavailable
-
No sell items are configured, payout is missing, or the player does not own the items
-
Fix: configure Sell Items, configure Sell Payout, or add the items to the container
-
Craft unavailable
-
Craft Cost and Craft Result ship empty in this scene, so the button stays disabled — the panel supports Craft fully, this scene just does not configure it
-
Fix: fill in Craft Cost and Craft Result to enable it here, or use the dedicated Crafting integration scene/video
-
Reward unavailable
-
Payout is empty or item reward space check fails
-
Fix: configure money/item payout or free inventory space
-
Injected failure
-
A teaching-only wrapper deliberately failed a public dependency call
-
Fix: disable the relevant force-fail toggle or use the result/log to study rollback behaviour
-
Real failure after saturation
-
The container was filled before execution, so delivery had nowhere to go. This is the toggle working, not a fault
-
Fix: disable Saturate Container Before Execute, or clear the blocker items, to run the success path again
-
Saturation appears to do nothing
-
No blocker item assigned, or the container is larger than
Blocker Quantity Per Presscan fill -
Fix: assign a blocker item, give the container a smaller capacity, or raise the quantity. The log reports which of the two happened
-
Execution fails after preflight passes
-
The live service rejected the operation during execution
- Fix: trust
EcoOpResult; inspect balances, container state, policy, authority, service composition, and failure injection toggles
Behind The Scenes¶
The panel uses public Economy, Currency, and Inventory APIs:
-
EconomyInventoryBootstrap.BuildForPlayer -
builds public Economy services from player, currency, inventory, resolver, container, policy, and preflight mode
-
IValueLedger -
money preflight and money mutation support
-
IItemStore -
item space checks, item removal, and item delivery support
-
IShopService -
Buy -
Sell -
ICraftingService -
Craft -
IRewardService -
Grant -
ICurrencyService -
owns actual currency balances
-
IInventoryService -
owns actual inventory containers and item state
-
GiveExactis also how the saturation toggle fills the container — the same public entry point any game would use, not a test hook -
ItemGuidMap -
resolves item guid strings into
ItemDefinitionassets -
LedgerPreflightMode -
changes preflight behaviour
-
CurrencyPolicy -
optionally affects currency preflight and effective debits
-
EcoSource.Build -
builds stable source/correlation ids
-
EcoOpResult -
Success CodeMessage
Teaching-only failure wrappers are used only to force visible rollback paths through public IValueLedger and IItemStore contracts.
Container saturation uses no wrapper at all — it calls the real IInventoryService and lets the container fill up, so the failure that follows is the system's own.
The panel does not use Economy internals as supported extension points.
Key Takeaway¶
Economy coordinates systems.
Currency owns money. Inventory owns items.
Preflight guides the UI, but the executed EcoOpResult tells the truth.