Simulation: Building Timers (BETA)
Add timed actions to your game: building upgrades, crafting, research, or any action that takes real time to complete. Includes build queues (one upgrade at a time), passive resource generation, and collecting completed results.
This is a self-contained recipe. Everything you need, config, client code, and patterns, is on this page.
Where Config Goes
All JSON config on this page is simulation config: server-authoritative state, actions, and rewards. The CLI uploads it automatically when you rundot deploy.
Recommended: rundot/simulation/
Place simulation config in the rundot/simulation/ directory, one file per system. Each file holds raw simulation content with no {"simulation": {...}} wrapper (the directory implies it). Files are deep-merged alphabetically at deploy time with collision detection.
my-game/
├── rundot/
│ └── simulation/
│ └── buildings.json ← raw content, no "simulation" wrapper
├── game.config.prod.json ← game ID + build settings only (separate)
└── package.jsonCommit
rundot/to your repo, it's project config likepackage.json, not a build artifact. It's env-agnostic and takes priority over legacyconfig.{local,staging}.json.game.config.prod.jsonis for CLI metadata only; simulation config does not go there.
Also supported: legacy config.json / config/
Legacy layouts keep working indefinitely. Run rundot migrate-config (with --dry-run to preview) to move them into rundot/simulation/ automatically.
What You'll Build
Buildings that take real time to upgrade (e.g., 5 minutes, scaling with level)
A build queue that limits players to one upgrade at a time
Passive resource generators (produce bricks/coins over time)
Collecting accumulated resources from generators
Countdown timers in the client UI
Server Configuration
Building Entities
Each building is an entity. Its quantity represents its level.
Key fields:
stackable: true: quantity represents the building's levelrequiresManualCollection: true: timed recipe outputs are held until the player explicitly collectsmetadata.baseCost/costMultiplier: used in formula-based input costsmetadata.baseDuration: used in formula-based recipe duration
Building Upgrade Recipe (Entity-Scoped)
A single recipe handles all building upgrades. {{entity}} resolves to the specific building at execution time.
How this works:
concurrency: "global:building_upgrade": only one building upgrade can run at a time across all buildings. Starting a second upgrade fails.guards.alreadyConstructed: the building must exist (level ≥ 1) before it can be upgradedduration: scales with level:baseDuration + level * baseDuration. A building withbaseDuration: 180000(3 min) at level 3 takes 3 + 3×3 = 12 minutes.inputs.currency_bricks: cost scales exponentially:floor(100 * 1.6 ^ level)outputs.{{entity}}: 1: increments the building's level by 1
Resource Generation (Auto-Restart Timer)
A generator building produces resources on a repeating timer:
Key pattern:
brick_generationauto-restarts every 5 minutes, producing bricks intopending_bricksbased on the quarry's generation ratemaxRestartConditionwithmaxValueFormulastops generation when storage is fullcollect_bricksis an instant recipe that transfers pending bricks to the player's currency (capped by storage)
Auto-Recalculating Derived Stats (Triggers)
When a building is upgraded, recalculate dependent stats automatically:
These recipes fire automatically whenever the watched entity changes. The output formula computes the delta needed to reach the new correct value.
Client-Side Implementation
Step 1: Read Building State
Step 2: Check Upgrade Cost and Availability
getRecipeRequirementsAsync takes a single Recipe object ({ recipeId, entity?, batchAmount?, nonce? }):
Step 3: Start an Upgrade
Scoped recipes return only { success, message }; they do not return a run id directly. After starting an upgrade, fetch the active run via getActiveRunsAsync() (or the activeRuns subscription in Step 4) and match on recipeId + entity to get the run's id and expiresAt.
Step 4: Track Active Upgrades and Show Countdown
Step 5: Collect Completed Upgrades
When the timer finishes, the upgrade must be collected before the level increases:
You can also check for completed-but-uncollected runs on app launch:
Step 6: Collect Generated Resources
Cooldown Timers
For actions that can be performed once per time period (not building upgrades, more like "claim daily reward" or "free booster every 4 hours"):
The reward is granted immediately via beginEffects. The recipe's 24-hour duration acts as a cooldown; attempting to execute again before it expires returns an error.
Common Variations
Multiple Build Queues
Allow N simultaneous upgrades (e.g., 2 builder slots):
Instant Finish with Premium Currency
Let players skip the timer:
Level-Gated Buildings
Use guards to require a minimum town hall level before upgrading:
Reset Progress / Cancel All Timers
resetStateAsync wipes the current player's simulation state in one call: it clears inventory, cancels every active run (so all in-flight building timers stop at once), and removes slot assignments. Handy for a "reset progress" button or dev tooling. Pass initializeRecipe to run a setup recipe right after the reset (overrides any lifecycle.onReset).
Best Practices
Use
concurrency: "global:<key>"to enforce build queue limits across all building types.Use entity-scoped recipes (
{{entity}}) with formulas for scaling costs and durations: one recipe handles all buildings.Store cost/duration parameters in entity
metadataso formulas can read them dynamically.Use
triggerrecipes for derived stats so they auto-recalculate when dependencies change.Use
requiresManualCollection: trueon building entities so players see an upgrade-complete animation before the level updates.Separate pending and collected resources (e.g.,
pending_bricksvscurrency_bricks) so players must interact with the generator to claim.Subscribe to
activeRunsfor countdown timers; don't calculate durations client-side.Check for uncollected completed runs on app launch to handle upgrades that finished while offline.
Last updated