📦 Economy — Model¶
🎯 Purpose¶
This folder contains the value types, enums, and shared helpers used across the Economy subsystem.
These types are public and are intended for use in gameplay code, UI, analytics, tests, and integrations.
They contain minimal shared logic (for example result helpers and sourceId construction), plus data contracts shared across economy flows.
🧩 What Lives Here¶
Value types¶
ChargeLine¶
Represents a single money line.
- Fields:
(id, amount) idis trimmed and lowercased during construction- Validity is exposed via
IsValid(idnon-empty andamount > 0) - Used in
PriceBundle.Money
ItemLine¶
Represents a single item line.
- Fields:
(guid, quantity) guidis trimmed during construction- Validity is exposed via
IsValid(guidnon-empty andquantity > 0) - Used in
PriceBundle.Items
PriceBundle¶
Bundle of optional money and/or item lines.
-
Structure:
-
IReadOnlyList<ChargeLine> Money IReadOnlyList<ItemLine> Items-
Helper factory methods:
-
MoneyOnly(moneyLines) ItemsOnly(itemLines)- Used across economy flows
PriceBundle does not clone or freeze the provided lists.
Callers should treat them as read-only; mutating them may affect consumers of the bundle.
A PriceBundle may contain:
- Money only
- Items only
- Both money and items
Results¶
EcoOpResult¶
Represents the outcome of an economy operation.
Fields¶
Success—boolCode—EcoOpCodeMessage— optional string
Features¶
- Factory helpers such as
Ok(),Fail(),InvalidArgs(),ServiceMissing()and others - Deconstruction support
- No implicit
boolconversion - Equality and hashing support
Use EcoOpResult for branching on operation outcomes.
Inspect Success, Code, or IsOk / IsFail.
Message is intended for diagnostics or UI and should not be used for gameplay branching.
EcoOpCode¶
Shared result codes used across Economy operations.
Examples include:
OkInvalidArgsServiceMissingContainerMissingResolverMissingInsufficientFundsNoSpaceNotOwnedPolicyBlockedOverflowEscrowUnavailableUnknownError
EcoOpResultComparers¶
Reusable comparers for EcoOpResult.
ByCode— comparesSuccessandCode, ignoringMessage
Useful for:
- Unit tests
- Dictionaries and sets
- Deduplicating results where message text is not relevant
Reasons and sources¶
EcoReasons¶
Shared reason strings for economy telemetry and logging.
Using consistent reason strings helps avoid fragmentation across systems.
EcoSource¶
Helper for building canonical sourceId strings.
- Combines vendor and request identifiers
- Trims whitespace
- Replaces delimiter characters
- Applies per-part length limits
- Returns
nullwhen both inputs are empty
Validation and policies¶
LedgerPreflightMode¶
Controls UX preflight behaviour for IValueLedger.CanPay().
StrictPolicyApproved
This affects preflight behaviour only.
It does not change the authoritative behaviour of Pay().
Exact behaviour depends on the IValueLedger implementation.
🧠 Usage Guidance¶
- Use
PriceBundleto represent costs and payouts - Inspect
EcoOpResultfor branching on operation outcomes - Use shared
reasonvalues fromEcoReasonsfor consistent telemetry - Use
EcoSourcewhen constructingsourceIdvalues - Use
EcoOpResultComparers.ByCodewhen message text is not relevant
🔗 Related Documentation¶
- Abstractions README
- Facade README
- Adapters README
- Diagnostics README