step 6.1: wip (not ticked)

This commit is contained in:
bepis
2026-10-21 00:42:56 +11:00
parent ae8ee02721
commit ffee0efc47
6 changed files with 810 additions and 15 deletions
+16 -11
View File
@@ -4,9 +4,9 @@
> If this file disagrees with the code, trust the code and fix this file.
## 1. Where we are
- **Last completed step:** 5.4 (inventory UI: tabs, equipment panel, inventory grid, tooltips)
- **Next step:** 6.1 — Shop: `GET /api/shop`, `POST /api/shop/buy`, `POST /api/shop/sell`
- **Updated:** 2026-10-20
- **Last completed step:** 6.1 (Shop API: GET /api/shop, POST /api/shop/buy, POST /api/shop/sell)
- **Next step:** 6.2 — Level-gated shop stock (filter by character level) + UI page
- **Updated:** 2026-10-21
- **Was the last session cut off mid-task?** No
## 2. Verified state (run these first)
@@ -14,7 +14,7 @@
|---|---|
| `npm install` | succeeds |
| `npm run migrate` | applies 001–004 and 006 / "nothing to do" |
| `npm test` | **118 passing, 0 failing** (87 unit + 31 integration) |
| `npm test` | **132 passing, 0 failing** (85 unit + 47 integration) |
## 3. What exists now (files that matter)
- `src/game/stats.js` — `calcDerived()` is the ONLY derived-stat formula. Also re-exports xpToNext/checkLevelUp.
@@ -24,19 +24,22 @@
- `src/services/combatLogService.js` — `getCombatLog(characterId, limit)` → recent fights.
- `src/services/characterService.js` — `createCharacter`, `getCharacterProfile`, `getCharacterIdForUser`.
- `src/services/inventoryService.js` — `listInventory`, `equipItem`, `unequipItem`, `useConsumable`. Uses WeakMap stmt cache.
- `src/services/shopService.js` — **NEW**: `getStock`, `buyItem`, `sellItem`. Uses WeakMap stmt cache. Sell value = 40% of buy_price (materials use rarity default).
- `src/routes/shop.js` — **NEW**: `GET /api/shop`, `POST /api/shop/buy`, `POST /api/shop/sell`.
- `src/routes/inventory.js` — `GET /api/inventory`, `POST /api/inventory/equip`, `POST /api/inventory/unequip`, `POST /api/inventory/use`.
- `src/utils/time.js` — `now()/setNow()/resetNow()`; never call `Date.now()` in services.
- `src/routes/zones.js` — `GET /api/zones`.
- `src/routes/combatLog.js` — `GET /api/combat-log`.
- `src/db/migrations/003_content.sql` — also SEEDS zones/monsters/items/loot (INSERT OR IGNORE).
- `src/db/migrations/004_inventory.sql` — inventory table, FK constraints, partial unique index for equipped slots.
- `tests/integration/shop.test.js` — **NEW**: 14 integration tests (stock listing, level gating, buy, sell, error paths, round-trip spread).
- `tests/integration/inventory.test.js` — 20 integration tests (13 equip/unequip + 7 consumable).
- `public/game.html` — dashboard with stats panel, tabbed action panel (Hunt/Inventory), equipment panel, inventory grid.
- `public/js/game.js` — full hunt UI + inventory UI: load zones, hunt handler, result display, combat log, tab switching, loadInventory, renderEquipmentPanel, renderInventoryGrid, equip/unequip/use handlers, tooltips.
- `public/js/game.js` — full hunt UI + inventory UI.
- `public/css/main.css` — zone cards, combat log, result panel, toast styles, tabs, equipment panel, inventory grid, tooltips, rarity colors.
## 4. Half-finished / fragile things
- No shop UI yet (Phase 6).
- No shop UI yet (Phase 6.2).
- No expedition UI yet (Phase 7).
- No leaderboard UI yet (Phase 8).
- HP never regenerates naturally; only level-up restores it.
@@ -52,6 +55,7 @@
- Qty decrement avoids CHECK constraint violation: delete directly when qty==1, decrement when qty>1.
- UI uses emoji icons (⚔️🛡️💍🧪📦) for item types per UI_GUIDE recommendation.
- Rarity colors match UI_GUIDE spec (common #b8b0a3, uncommon #5fb36b, rare #4a8fe0, epic #a45ee0, legendary #f2a23a).
- **D-008:** Shop materials with buy_price=0 sell at `floor(default_rate * character_level / item_min_level)` where default_rate is common=2, uncommon=4, rare=8, epic=16, legendary=32 (min 1).
## 6. Gotchas learned
- `npm test` must be `node --test` with NO path/glob; files must be named `*.test.js`. A shell glob once skipped 17 tests.
@@ -63,12 +67,13 @@
- SQL `SELECT id` from inventory returns the auto-increment row id; rename with `AS inventory_id` when you also need `item_id`.
- `itemInSlot` query must alias `id AS inventory_id` so `existing.inventory_id` works in unequip logic.
- Transaction callback args must match the call order exactly — passing `qty` as the second arg when the callback expects `etype` silently misapplies the effect.
- Error responses from route-level `AppError`s do NOT include `data` field — only `{ ok: false, error: { code, message } }`.
## 7. Next-step briefing (6.1)
- **Goal:** Shop API endpoints — `GET /api/shop` (list stock), `POST /api/shop/buy` (buy items), `POST /api/shop/sell` (sell items). Sell value = 40% of base price. Gold never goes negative.
- **Docs:** GAME_DESIGN.md §Economy, API.md, BALANCE.md.
- **Files to create/modify:** `src/services/shopService.js`, `src/routes/shop.js`, register in `app.js`.
- **Key rules:** Shop stock determined by character level (level-gated). Sell = 40% of buy_price. Use transactions for buy. Item slug → buy_price from items table.
## 7. Next-step briefing (6.2)
- **Goal:** Level-gated shop stock (already partially done — `levelOk` flag exists; ensure stock query properly filters by level) + UI shop page.
- **Docs:** GAME_DESIGN.md §Economy, API.md, UI_GUIDE.
- **Files to create/modify:** `public/shop.html`, `public/js/shop.js`, verify shopService stock filtering.
- **Key rules:** Shop stock should only show items where character level >= item min_level. Materials always visible for selling.
## 8. Open Known Issues
STATUS.md issues 1–6 (balance, dangling `seed` script, restart test, equipment-in-combat, HP regen, zone min_level balance).