Bash.tv → GitHub → itch.io

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 GitHub

Game 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

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.