> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pcm.game/llms.txt
> Use this file to discover all available pages before exploring further.

# Sprint 16: The Pill Box & Grand Consensus

> Deploying the premium non-market economy, high-friction UI, and the ideological defection mechanics.

# Sprint 16: The Pill Box & Grand Consensus

With the Global Market and Gacha loops deployed in Sprint 15, Sprint 16 focuses on the development of the **Pill Box HUD, Personal Bunker**, and the high-friction, zero-trust mechanics governing the premium non-market currency: **Based Pills**. The objective is to implement a robust, transaction-safe ledgers, dual consumption pathways (ideological defection and card forging), and couple them with elite, interactive interfaces on the frontend.

## 🛠 Context & Required Rules for AI Agents

1. **Atomic Consumption (Zero-Trust):** All Based Pill consumption pathways must execute inside `prisma.$transaction` blocks with pessimistic raw SQL `SELECT ... FOR UPDATE` row locks on the player wallet to prevent double-spending under concurrent serverless workloads.
2. **High-Friction Safety Guards:** Destructive or high-impact actions like ideological defection and permanent asset forging must be protected by explicit, case-sensitive text confirmation inputs ("DEFECT" and "FORGE") on the client-side to eliminate accidental clicks.
3. **Database Ledger Integrity:** Every transaction must emit a permanent, audit-ready receipt log containing the precise player ID, transaction type, currency ticker (`BASED_PILL`), and asset adjustments.

***

## 🗺 Sprint 16 Roadmap

### \[x] Phase 0: Schema Expansion

* **Objective:** Support the premium Based Pill ledger currency inside Neon Postgres database registers.
* **Tasks:**
  * Add explicitly stored `based_pills` integer property to the `PlayerWallet` schema in `schema.prisma`.
  * Regenerate Prisma client models and run database migration syncs.

### \[x] Phase 1: Consensus Mint (Resolution Engine)

* **Objective:** Physical minting and ledgering of Based Pills during a Grand Consensus event.
* **Tasks:**
  * Update `backend/src/routes/resolve.js` post-match resolution engine.
  * Dynamically award 1 Based Pill during full consensus (4/4 matching coordinates), incrementing the player's wallet inside the transaction.
  * Automatically append a structured transaction receipt into the global audit logs.

### \[x] Phase 2: Consumption API

* **Objective:** Build atomic endpoints to consume Based Pills for game-theoretic and tactical adjustments.
* **Tasks:**
  * Build `POST /inventory/defect` to allow players to consume 1 Based Pill, re-map their matchmaker faction alignment, and swap standard payouts to target currencies.
  * Build `POST /inventory/forge` to allow players to consume 1 Based Pill, permanently forging an owned card asset with a `1.5000x` multiplier upgrade.
  * Secure both endpoints using the `bouncer` JWT token validation middleware.

### \[x] Phase 3: Bunker UI & Pill Box HUD

* **Objective:** Design the premium Personal Bunker and public intimidation indicators.
* **Tasks:**
  * Update the global `<WalletOverlay />` to render glowing, animated Based Pill rows in both the inline dashboard and floating dropdown drawers.
  * Inject the "Pill Box" public intimidation HUD block in the Matrix selection entryway page.
  * Scaffold `/bunker` displaying active allegiances, live inventories, owned cards registry, and high-friction confirmation modals requiring case-sensitive type confirmations before committing ledger changes.

***

## 🏁 Retrospective & Conclusion

Sprint 16 successfully hardened the PCMTG transactional economy. By combining **zero-trust PostgreSQL raw row locks (`FOR UPDATE`)** with **high-friction "Type-to-Confirm" client inputs**, we have constructed a cheat-proof, user-safe operational model. Automated integration tests successfully proved that concurrent, fraudulent double-spends and duplicate card-forge upgrades are fully blocked by our database state machine.
