Currency, shops, prices and resource balancing. Wallets with several currencies and a transaction log, all-or-nothing purchases, cost curves (linear, polynomial, exponential) for upgrades, buy-max and buy-x10 math, shops with stock, price growth, restocking and sell-back rates, sources and sinks, inflation and hoarding, and a simulator that shows how money flows over a session. Includes tested ...
Download skill (.zip) Files on GitHubGame economy
Drop-in: assets/economy.js (tests: all-or-nothing spending, exponential costs, buy-max, price growth, sold-out stock,
a 30-minute session simulation).
import { Wallet, cost, totalCost, maxAffordable, Shop, simulateEconomy } from "./core/economy.js";
const wallet = new Wallet({ gold: 0, gems: 0 });
wallet.earn("gold", 25, "enemy"); wallet.spend({ gold: 100 }, "sword"); // false if not enough (nothing spent)
const upgradeCost = cost.exponential(50, 1.15); // 50, 58, 66, 76 …
maxAffordable(upgradeCost, level, wallet.get("gold")) // { count, spent } for "Buy max"
const shop = new Shop({ potion: { price: { gold: 10 }, stock: 5, priceGrowth: 1.1 } }, { sellRate: 0.4, restockEvery: 120 });
Sources and sinks
Write them down: where money comes from (kills, quests, idle income, selling) and where it goes (upgrades, consumables, repairs, cosmetics, fees). An economy without enough sinks inflates: by the late game, everything is free and money is meaningless.
const sim = simulateEconomy({ minutes: 60, sources: [{ perMinute: (m, lv) => 20 + 8 * lv.miner }], sinks: [{ name: "miner", cost: cost.exponential(30, 1.25) }] });
// sim.timeline: money and purchases per minute; sim.idleMinutes: minutes with nothing to buy; sim.hoarding: true if money piles up
Rules of thumb
- First purchase within 1–2 minutes. Then a purchase every few minutes, with a big goal visible at all times.
- Exponential costs (×1.07–1.25 per level) against linear or polynomial income create a natural slowdown; add new income sources to restart growth (the idle game loop).
- Sell-back at 25–50% of the price, so buying is a decision.
- Premium or second currencies: rarer, for special things; never needed to finish a free game.
- Show prices you can’t afford dimmed with how much is missing. Count money up with a small animation.
- Large numbers: format them (
1.2K,3.4M,5.6e12) and consider a big-number library past ~1e15 (idle-game-development).
Check
Simulate, then play a full session (game-balance-testing) and watch for: minutes with nothing to buy, money that only goes up, and purchases nobody makes.