step 8.2: done

This commit is contained in:
bepis
2026-10-21 08:05:25 +11:00
parent fcf2ea2d21
commit b8fef0629b
6 changed files with 308 additions and 36 deletions
+37 -33
View File
@@ -4,8 +4,8 @@
> If this file disagrees with the code, trust the code and fix this file.
## 1. Where we are
- **Last completed step:** 7.3 (Expedition UI: start panel, progress bar, claim button) — TICKED in STATUS.md
- **Next step:** 8.1 — Leaderboard: `GET /api/leaderboard?type=level|gold|kills` top 50, with pagination param.
- **Last completed step:** 8.2 (Public profile: `GET /api/heroes/:name`) — TICKED in STATUS.md
- **Next step:** 8.3 — UI page for public hero profile.
- **Updated:** 2026-10-21
- **Was the last session cut off mid-task?** No
@@ -14,38 +14,39 @@
|---|---|
| `npm install` | succeeds |
| `npm run migrate` | applies 001–006 / "nothing to do" |
| `npm test` | **153 passing, 0 failing** (85 unit + 68 integration) |
| `npm test` | **167 passing, 0 failing** (85 unit + 72 integration) |
## 3. What exists now (files that matter)
- `src/db/migrations/005_expeditions.sql` — `expedition_defs` + `expeditions` tables, unique active-expedition index, 3 seed definitions.
- `src/services/expeditionService.js` — `startExpedition`, `getActive`, `claimExpedition`, `listDefinitions`. Uses WeakMap stmt cache.
- `src/routes/expeditions.js` — `POST /api/expeditions/start`, `GET /api/expeditions/active`, `POST /api/expeditions/claim`, `GET /api/expeditions/defs`.
- `src/game/energy.js` — `computeEnergy` now uses `now()` from utils/time.
- `src/services/characterService.js` — `createCharacter`, `getCharacterProfile`, `getCharacterIdForUser`.
- `src/services/huntService.js` — `hunt(characterId, zoneId, {rng, now})`; ONE transaction; test-injectable.
- `src/services/inventoryService.js` — `listInventory`, `equipItem`, `unequipItem`, `useConsumable`. Uses WeakMap stmt cache.
- `src/services/shopService.js` — `getStock`, `buyItem`, `sellItem`. Uses WeakMap stmt cache.
- `src/game/combat.js` — `resolveCombat(hero, monster, rng)`; both sides attack each round, faster first.
- `src/game/stats.js` — `calcDerived()` is the ONLY derived-stat formula. Also re-exports xpToNext/checkLevelUp.
- `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/services/heroProfileService.js` — `getHeroProfile(heroName)`: case-insensitive lookup, returns name/class/level/xp/gold/str/agi/int/vit/kills/deaths/equipment (equipped item names by slot). Uses WeakMap stmt cache.
- `src/routes/heroProfile.js` — `GET /api/heroes/:name` (public, no auth). Returns 404 if hero not found.
- `src/services/leaderboardService.js` — `getLeaderboard(type, page, limit)`.
- `src/routes/leaderboard.js` — `GET /api/leaderboard?type=level|gold|kills&page=1`.
- `src/services/expeditionService.js` — start, getActive, claim, listDefinitions.
- `src/routes/expeditions.js` — 4 expedition endpoints.
- `src/services/shopService.js` — getStock, buyItem, sellItem.
- `src/routes/shop.js` — GET/POST shop endpoints.
- `src/services/inventoryService.js` — listInventory, equipItem, unequipItem, useConsumable.
- `src/services/huntService.js` — hunt (one transaction).
- `src/services/characterService.js` — createCharacter, getCharacterProfile, getCharacterIdForUser.
- `src/services/authService.js` — register, verifyLogin.
- `src/game/combat.js` — resolveCombat.
- `src/game/stats.js` — calcDerived, xpToNext, checkLevelUp.
- `src/game/energy.js` — computeEnergy.
- `src/utils/time.js` — now()/setNow()/resetNow().
- `public/game.html` — dashboard with stats panel, tabbed action panel (Hunt/Inventory/Expedition).
- `public/js/game.js` — full hunt UI + inventory UI + expedition UI (start panel, progress bar, claim button, auto-refresh).
- `public/css/main.css` — expedition UI styles (cards, progress bar, buttons).
- `public/shop.html` — dedicated shop page with buy/sell tabs.
- `tests/integration/expeditions.test.js` — 13 integration tests.
- `tests/integration/shop.test.js` — 16 integration tests.
- `tests/integration/shop-page.test.js` — 5 integration tests.
- `tests/integration/inventory.test.js` — 20 integration tests.
- `public/js/game.js` — hunt UI + inventory UI + expedition UI.
- `public/shop.html` — dedicated shop page.
- `tests/integration/hero-profile.test.js` — 5 integration tests.
## 4. Half-finished / fragile things
- No leaderboard UI yet (Phase 8).
- No public profile UI page (step 8.3 next).
- HP never regenerates naturally; only level-up restores it.
- No restart-persistence test for sessions.
- `npm run seed` script in package.json points to nonexistent `scripts/seed.js`.
- Equipment bonuses not yet passed into combat (Issue #5 in STATUS.md).
- No shop link in game.html top-bar navigation.
- Starter gear (GAME_DESIGN.md §Items) documented but not auto-created on character creation.
- `GET /api/zones` documented in API.md but not implemented (Issue #2).
## 5. Decisions & deviations from the docs
- D-004..D-007 in `docs/DECISIONS.md` (combat rounds, equipment counted once, session store, clock).
@@ -55,8 +56,8 @@
- Qty decrement avoids CHECK constraint violation: delete directly when qty==1, decrement when qty>1.
- **D-008:** Shop materials with buy_price=0 sell at `floor(default_rate * character_level / item_min_level)`.
- **D-009:** `sellItem` checks equipped_slot before material type.
- **D-010:** `startExpedition` checks active-expedition before energy (so 409 ACTIVE_EXPEDITION takes priority over 422 INSUFFICIENT_ENERGY).
- **D-011:** `computeEnergy` uses `now()` from utils/time instead of `Date.now()` directly, so test time overrides work.
- **D-010:** `startExpedition` checks active-expedition before energy.
- **D-011:** `computeEnergy` uses `now()` from utils/time.
## 6. Gotchas learned
- `npm test` must be `node --test` with NO path/glob; files must be named `*.test.js`.
@@ -67,14 +68,17 @@
- SQL `SELECT id` from inventory returns the auto-increment row id; rename with `AS inventory_id` when you also need `item_id`.
- Transaction callback args must match the call order exactly.
- Error responses from route-level `AppError`s do NOT include `data` field.
- `setNow` affects ALL `now()` calls including those in service logic — for tests that need to verify time-based behavior, manipulate the DB directly instead.
- `setNow` affects ALL `now()` calls including those in service logic.
- Shop API returns `{ ok: true, data: { stock: [...], character: {...} } }` — field is `stock`, not `stocks`.
- Shop stock items have flat fields (`itemId`, `buyPrice`), not nested (`item.id`).
- New characters have NO inventory items (starter gear not auto-created yet).
- Hero profile endpoint is PUBLIC — no `requireAuth` middleware.
## 7. Next-step briefing (8.1)
- **Goal:** Leaderboard endpoint — `GET /api/leaderboard?type=level|gold|kills` top 50, with `?page=N` pagination.
- **Docs:** GAME_DESIGN.md §Leaderboards, DATABASE.
- **Files to create:** `src/services/leaderboardService.js`, `src/routes/leaderboard.js`.
- **Files to modify:** `src/app.js` (register route).
- **API:** `GET /api/leaderboard?type=level|gold|kills&page=1` — returns ranked list of heroes (name, level/gold/kills) with pagination metadata.
## 7. Next-step briefing (8.3)
- **Goal:** Public profile UI page — a standalone HTML page showing the hero profile returned by `GET /api/heroes/:name`.
- **Docs:** GAME_DESIGN.md §Leaderboards, UI_GUIDE.
- **Files to create:** `public/profile.html`, `public/js/profile.js`.
- **No new backend needed** — the API endpoint already exists.
## 8. Open Known Issues
STATUS.md issues 1–6 (balance, dangling `seed` script, restart test, equipment-in-combat, HP regen, zone min_level balance).