Skip to content

RevFramework – Sample Scene: 01_Currency_PolicyCaps

Namespace: RevGaming.RevFramework.Runtime.Currency.Samples.Scenes


🎯 Purpose

Demonstrate how to enforce minimum and maximum wallet limits using a Currency Policy.
This scene shows how balance caps affect credit, debit, set, and transfer operations, and how Clamp and Fail modes change behaviour.


🧩 What This Scene Teaches

  • How to define per-currency rules (min, max, and mode).
  • The difference between Clamp and Fail policy modes.
  • How to preview and apply operations under policy constraints.
  • How Set, Credit, Debit, and Transfer operations interact with caps.
  • How to compute and preview effective transfer amounts using CurrencyServiceExtensions.

🕹️ How to Use

  1. Enter Play Mode.
  2. Open the CurrencyPolicyCapsPanel (F8).
  3. Use the arrow buttons to cycle through currencies.
  4. Observe the current policy rule (min, max, and mode).
  5. Test various operations:
  6. Set → Assign an absolute value.
  7. Credit / Debit → Apply changes and observe how caps respond.
  8. Transfer → Move value between A → B and see both wallets validated under the same rule.
  9. Adjust CurrencyPolicy asset values live and see changes reflected in real-time.

🔐 Authority (Important)

This sample scene includes a CurrencyAuthorityBinder configured for single-player use:

  • CurrencyAuthorityBinder
  • alwaysTrue = true

This allows all currency mutations so the demo works out of the box.

Why this exists

RevFramework currency mutations are authority-gated by default.

  • If no authority is present, all mutations are blocked.
  • This is intentional and required for multiplayer safety.

Multiplayer note

For multiplayer or server-authoritative games:

  • Do not use CurrencyAuthorityBinder
  • Implement your own ICurrencyAuthority
  • Validate all currency mutations on the server/host

This scene uses the permissive binder only to demonstrate behaviour in a local, single-player context.


💡 Key Takeaways

  • Each currency can define independent min/max bounds and behaviour.
  • Clamp Mode: Automatically adjusts values to remain within limits.
  • Fail Mode: Rejects operations and returns a CurOpResult with a failure code.
  • Transfers apply caps to both source and destination wallets.
  • Policies are data-driven — tweak the CurrencyPolicy asset, no code changes required.
  • Cap logic is fully compatible with all decorators and services (e.g., Audit, Authority, Idempotency).

⚙️ Stack Composition

Bootstrap: CurrencyServiceBootstrap
Service Stack:
SceneCurrencyService → CappedCurrencyService → AuditedCurrencyService → AuthorityCurrencyService

(Authority provided by CurrencyAuthorityBinder, no idempotency in this scene) Teaching Panel: CurrencyPolicyCapsPanel
Supporting Assets:
- CurrencyPolicy (ScriptableObject defining rules)
- CurrencySet (for currency lookup)

Scene Path:

Assets/RevFramework/Runtime/Systems/Currency/Samples/Scenes/01_Currency_PolicyCaps/


⚠️ Gotchas

  • Policies are evaluated per operation — ensure you’re testing both Credit and Set paths.
  • A max of 0 means “no upper bound,” not “block all.”
  • If a currency is not listed in the policy, it’s unrestricted.
  • For debugging, check the console logs for returned CurOpResult.Code.
  • Clamp mode may silently adjust values — use Fail mode when you need strict enforcement.

  • 00_Currency_Basics — Fundamentals of wallet operations.
  • DecoratorsCappedCurrencyService internals.
  • CoreCurrencyPolicyUtil, CurrencyFactories.
  • DefinitionsCurrencyDefinition, CurrencySet for UI and persistence.