Code Farm economy rebalance: market saturation, infrastructure/defense/cosmetics, mastery track, secondary leaderboards, admin eras, underdog bonus and weekly contracts

Every purchase/upgrade path (new and pre-existing) is now race-safe against concurrent requests via atomic conditional SQL updates.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 23:55:46 +02:00
co-authored by Claude Sonnet 5
parent 024edb5291
commit 34f76aad65
54 changed files with 3886 additions and 164 deletions
+85 -15
View File
@@ -41,11 +41,18 @@ and a level at which it unlocks. Slower crops pay far more per build.
| 🦀 Rust Engine | 200 | 30m | 520 | 60 | 4 |
| λ Compiler | 500 | 1h | 1380 | 150 | 6 |
| ⚙️ Kernel | 1200 | 2h | 3600 | 400 | 8 |
| 🕸️ Distributed System | 5000 | 4h | 9500 | 900 | Mastery |
| 🧠 ML Pipeline | 12000 | 6h | 21000 | 1800 | Mastery |
| 🔐 Security Fortress | 30000 | 8h | 48000 | 3200 | Mastery, raid-immune |
The three Mastery-tier crops unlock once you have earned at least one Mastery point (see
Mastery, below), on top of the usual level requirement. Security Fortress can never be raided.
Build time is the base time divided by the farm build speed (CI tier and the growth perk, below),
so a higher tier finishes everything proportionally faster. Coin and experience rewards shown in
the API already include your perks and refactor bonus, so read them from the live state rather
than from this table.
the API already include your perks, refactor bonus, and the current Market Saturation factor, so
read them from the live state rather than from this table. Each crop in the state also carries a
`market_state` of `normal`, `saturated`, or `boosted`.
## Plots
@@ -129,11 +136,56 @@ visitors, so popular farms fill up. Each plot reports `can_water`, `watered_coun
## Raiding a ready build (competition)
If an owner leaves a build **ready** without harvesting it, another member can raid it, but only
after a **60 second protection window** has passed since the build became ready. The raider
receives **half** the build's coin value and the owner loses the build entirely. The owner is told
their farm was raided but the raider's identity is never revealed. Each plot reports `can_steal`
and `steal_coins` (the payout a raid would give), and `ready_at` lets you compute when the
protection window ends. Harvest your own ready builds promptly to keep them safe.
after a protection window (60 seconds by default, longer with Branch Protection or a Defense
building) has passed since the build became ready. The raider receives a fraction of the build's
coin value (half by default, less with the owner's defenses, floored so a raid never pays nothing)
and the owner loses the build entirely - except a Security Fortress build, which can never be
raided. The owner is told their farm was raided but the raider's identity is never revealed. You
can raid a given neighbour only once per hour. Raiding a farm with **10x** your own coins grants you
a 24-hour **Underdog** boost (+25% harvest coins). Each plot reports `can_steal` and `steal_coins`
(the payout a raid would give), and `ready_at` lets you compute when the protection window ends.
Harvest your own ready builds promptly to keep them safe, or invest in Defense (below).
## Market Saturation
The game tracks the last 48 hours of league-wide harvests of each crop. When a crop is being
farmed heavily, its payout drops in steps (down to 40% of normal); while that is happening, the
four starter crops (Shell Script, Python Script, Web App, Go Service) get a relief buff of up to
+15%. This rewards diversifying what you plant instead of printing one crop nonstop. Nothing else
about the crop changes - cost, build time, and unlock level are unaffected.
## Infrastructure, Defense, and Cosmetics (coin sinks)
Once you are earning more coins than you can spend on plots and perks, three permanent systems
give large coins a purpose:
- **Infrastructure** - one-time, prestige-gated buildings bought with `POST /game/infrastructure/buy`:
**Private Registry** (Rust, Compiler, and Kernel crops grow 15% faster, prestige 3+), **Canary
Deployments** (every harvest has a 12% chance to double and a 6% chance to only refund its
planting cost, prestige 8+), and **Observability Suite** (raises the minimum coins you keep when
raided from 10% to 30%, prestige 15+).
- **Defense** - an upgradeable building (`POST /game/defense/upgrade`) that lowers your raid losses
and lengthens your protection window with every tier. Unlike a one-time purchase, it costs a
**daily coin upkeep** proportional to your balance; if you do not have enough coins to cover it,
the tier decays by one level automatically. This is the sink that scales with wealth.
- **Cosmetics** - purely cosmetic titles and plot skins bought with coins (`POST /game/cosmetics/buy`)
and equipped (`POST /game/cosmetics/equip`). Zero gameplay effect; an equipped title shows next
to your name on the leaderboard.
## Mastery (beyond prestige)
Refactoring past **prestige 50** starts earning a second currency: one Mastery point immediately,
then one more every 10 further prestige. Mastery points never expire, and once you have earned at
least one, the three Mastery-tier crops above stay unlocked even if you later spend the point.
Spend Mastery points with `POST /game/mastery` on three permanent upgrades:
| Mastery upgrade | Effect | Max level |
|------------------|--------|:---------:|
| 🔁 Continuous Delivery | Auto-replant the same crop right after harvest, if affordable | 1 |
| 📊 Farm Analytics | Unlocks lifetime stats on your farm | 1 |
| 📜 Legacy Contracts | Unlocks a weekly contract slot paying Stars and a temporary coin boost | 1 |
The state reports `mastery_points`, `mastery_points_earned_total`, and each upgrade's level and cost.
## Refactor (prestige)
@@ -162,10 +214,10 @@ five:
The live state reports your `stars` balance and each legacy upgrade's current level and the exact
star cost of its next level.
## Leaderboard and scoring
## Leaderboards and scoring
The leaderboard ranks the top farms by a composite score. Refactors dominate the formula, then
lifetime harvests, level, and everything else:
The default leaderboard ranks the top farms by a composite score. Refactors dominate the formula,
then lifetime harvests, level, and everything else:
```
score = xp
@@ -178,7 +230,19 @@ score = xp
+ min(streak, 30) * 15
```
Read the top farms with `GET {{ base }}/game/leaderboard` (public, no account needed).
Read the top farms with `GET {{ base }}/game/leaderboard` (public, no account needed). Add
`?board=` to switch boards - `score` (default), `prestige`, `harvests` (this week only), `raids`
(average coins per successful raid over the last 30 days, minimum 3 qualifying raids), `time_to_kernel`
(fastest to harvest a Kernel after your last refactor), `fair_play` (rewards recent activity over
hoarding coins), and `era` (the current Era's board, empty when no Era is running - see below).
## Eras (seasons)
Administrators can occasionally start an **Era**: a fresh, visible "this season" leaderboard
(`board=era`) that everyone starts at zero on, while their real coins, prestige, Stars, Legacy, and
Mastery are completely untouched. When an Era ends, the top 10 by Era score earn permanent Stars
(and sometimes an Era-exclusive cosmetic). The state reports `era_active`, `era_name`, `era_coins`,
and `era_harvests` when one is running.
## Live updates
@@ -199,7 +263,7 @@ your **API key** in an `X-API-KEY` header (or `Authorization: Bearer`). Your key
| Method | Path | Purpose |
|--------|------|---------|
| `GET` | `/game/state` | Your full farm state (always JSON). |
| `GET` | `/game/leaderboard` | Top farms (public). |
| `GET` | `/game/leaderboard` | Top farms (public). Accepts `?board=`. |
| `GET` | `/game/farm/{username}` | Another member's farm. |
| `POST` | `/game/plant` | Plant `crop` in `slot`. |
| `POST` | `/game/harvest` | Harvest the build in `slot`. |
@@ -208,15 +272,21 @@ your **API key** in an `X-API-KEY` header (or `Authorization: Bearer`). Your key
| `POST` | `/game/upgrade` | Raise the CI tier. |
| `POST` | `/game/perk` | Upgrade `perk` (`yield`, `growth`, `discount`, `xp`). |
| `POST` | `/game/daily` | Claim the daily bonus. |
| `POST` | `/game/quests/claim` | Claim a completed quest by `quest` kind. |
| `POST` | `/game/quests/claim` | Claim a completed quest by `quest` kind, optional `scope` (`daily` or `weekly`). |
| `POST` | `/game/prestige` | Refactor at level 10 or above. |
| `POST` | `/game/legacy` | Buy a legacy upgrade (`key`) with stars. |
| `POST` | `/game/mastery` | Buy a Mastery upgrade (`key`) with Mastery points. |
| `POST` | `/game/infrastructure/buy` | Buy an Infrastructure building (`key`) with coins. |
| `POST` | `/game/defense/upgrade` | Buy the next Defense tier with coins. |
| `POST` | `/game/cosmetics/buy` | Buy a cosmetic (`key`) with coins. |
| `POST` | `/game/cosmetics/equip` | Equip an owned title cosmetic (`key`). |
| `POST` | `/game/farm/{username}/water` | Water a neighbour's build in `slot`. |
| `POST` | `/game/farm/{username}/steal` | Raid a neighbour's unprotected ready build in `slot`. |
POST bodies are form encoded (`application/x-www-form-urlencoded`). Form fields are `slot` (an
integer plot index), `crop`, `perk`, `quest`, and `key` (a legacy upgrade) where the table notes them. Every POST returns
the full farm under `farm`, so one call both performs the action and gives you the new state.
integer plot index), `crop`, `perk`, `quest`, `scope`, and `key` (a legacy/Mastery/Infrastructure/cosmetic
key) where the table notes them. Every POST returns the full farm under `farm`, so one call both
performs the action and gives you the new state.
### Reading the state