Money (Cash)
This is the full list of what the API gives you, one section for each part of the economy. Text in brackets at the end of a note is extra detail for experienced modders, and you can skip it on a first read.
Cash is the player’s wallet. You can read the balance, check whether the player can afford something, give money, spend money, and get told when either balance changes.
Cash the wallet
Call Balance(currency) to read a balance, Has to check the player can afford something, and Give or TrySpend to change it.
public static class Cash
{
public static event Action<MoneyChangedArgs> MoneyChanged;
public static bool IsAvailable { get; }
public static float Balance(MoneyCurrency currency);
public static bool Has(MoneyCurrency currency, float amount);
public static bool Give(MoneyCurrency currency, float amount);
public static bool TrySpend(MoneyCurrency currency, float amount);
public static int RmToOc(float rm);
public static float OcToRm(int oc);
}
| Method | Returns | What it does |
|---|---|---|
Balance(currency) | float | The balance in that currency. 0 while money is not loaded. |
Has(currency, amount) | bool | true when the wallet holds at least that much. |
Give(currency, amount) | bool | Adds money to the wallet. true when it was added. |
TrySpend(currency, amount) | bool | Takes money only if the wallet covers it. true when it was taken. |
RmToOc(rm) | int | Converts an RM amount to OC at the game’s rate, dropping any fraction. |
OcToRm(oc) | float | Converts an OC amount to RM at the game’s rate, rounded to 0.1. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when the money change could not be set up. |
| Event | Gives you | When it fires |
|---|---|---|
MoneyChanged | MoneyChangedArgs | A balance has changed. |
MoneyChangedArgs what you get when a balance changes
Cash.MoneyChanged passes you one of these each time a balance changes. Before and After are the balance either side of the change.
public sealed class MoneyChangedArgs
{
public MoneyCurrency Currency { get; }
public float Before { get; }
public float After { get; }
}
| Property | Type | What it means |
|---|---|---|
Currency | MoneyCurrency | Which balance changed. |
Before | float | The balance before the change. |
After | float | The balance after the change. |
MoneyCurrency the two currencies
The Cash calls take one of these to say which balance they mean. OC is the everyday coin and RM is real money.
public enum MoneyCurrency
{
OC = 0,
RM = 1
}
| Value | Meaning |
|---|---|
OC | Open Sewer Coins, the everyday coins. |
RM | Real Money. |
Things to know
MoneyChangedfires once for each currency whose balance changed, whatever caused the change. That covers shops, banking, money in the mail, dialogue, and your ownGiveandTrySpend. It does not fire when a save loads, because loading sets the balance directly. (it is raised for every change made through the game’sMoney.AddMoney(float, Currency)orMoney.RemoveMoney(float, Currency).)MoneyChangedhandlers run right away, except during a trade with a trader. In a trader trade, the event is held until the trade is finished, and a trade that is cancelled raises none. See Traders. (the handlers run synchronously insideMoney.AddMoneyorRemoveMoney.)GiveandTrySpendround the amount the way the game does. OC amounts lose any fraction, and RM amounts are rounded to 0.1, because the game counts RM in tenths.Givemakes money out of nothing, so use it for rewards. It is not a transfer from anywhere.Hasistruewhen the wallet holds at leastamount. It isfalsefor an amount of 0 or less, or above 16,000,000.RmToOcandOcToRmconvert one currency into the other at the game’s own rate. They give 0 while the game’s money is not loaded. (they callMoney.RmToOcConvert(which cuts off the fraction) andMoney.OcToRmConvert(which rounds to 0.1).)Cashreplaces the olderWalletand covers both currencies. It uses the same 16,000,000 limit for one call asWallet, and is a little stricter.Walletstays for code that only needs OC. (WalletacceptsHas(0)and negative amounts inHas;Cash.Hasrefuses them.)
Limits
MoneyChangedhandlers that callGiveorTrySpendraiseMoneyChangedagain, and the framework stops it after 8 levels (see Handlers that call back into the framework).- An amount that rounds to 0 is refused. A single call can move at most 16,000,000.
Giverefuses an amount that would push the balance past what the game can store. That is about 2.1 billion OC or about 214 million RM. Past that, the game’s number would wrap around and turn negative. (the limits areint.MaxValuefor OC and 214748364 for RM.)GiveandTrySpendreturnfalsewhile a save is loading or being written, and when the game is not ready to move money. The main menu is one such time. (“not ready” means there is noMoney,InteractObjectsorNotificationsinstance.)Balancefor OC is a decimal number, and is only exact up to 16,777,216. For big OC balances, useCash.Ocinstead (see Cash.Oc and Cash.Rm).