step 7.1: done
This commit is contained in:
+23
-28
@@ -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:** 6.3 (Shop tests: sell equipped item rejection + concurrent double-buy safety) — TICKED in STATUS.md
|
||||
- **Next step:** 7.1 — Migration `005_expeditions.sql`. Expedition definitions in seed data.
|
||||
- **Last completed step:** 7.1 (Migration `005_expeditions.sql` with seed data) — TICKED in STATUS.md
|
||||
- **Next step:** 7.2 — `POST /api/expeditions/start`, `GET /api/expeditions/active`, `POST /api/expeditions/claim`. Only one active expedition per hero. Claim rejected before `ends_at`.
|
||||
- **Updated:** 2026-10-21
|
||||
- **Was the last session cut off mid-task?** No
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
| Command | Expected |
|
||||
|---|---|
|
||||
| `npm install` | succeeds |
|
||||
| `npm run migrate` | applies 001–004 and 006 / "nothing to do" |
|
||||
| `npm run migrate` | applies 001–006 / "nothing to do" |
|
||||
| `npm test` | **139 passing, 0 failing** (85 unit + 54 integration) |
|
||||
|
||||
## 3. What exists now (files that matter)
|
||||
- `src/db/migrations/005_expeditions.sql` — NEW: `expedition_defs` + `expeditions` tables, unique active-expedition index, 3 seed definitions (Scout 10min, Raid 1h, Delve 4h).
|
||||
- `src/game/stats.js` — `calcDerived()` is the ONLY derived-stat formula. Also re-exports xpToNext/checkLevelUp.
|
||||
- `src/game/combat.js` — `resolveCombat(hero, monster, rng)`; both sides attack each round, faster first.
|
||||
- `src/services/huntService.js` — `hunt(characterId, zoneId, {rng, now})`; ONE transaction; test-injectable.
|
||||
@@ -24,7 +25,7 @@
|
||||
- `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` — `getStock`, `buyItem`, `sellItem`. Uses WeakMap stmt cache. Sell value = 40% of buy_price (materials use rarity default). **Equipped items rejected in sellItem (check moved before material type check).**
|
||||
- `src/services/shopService.js` — `getStock`, `buyItem`, `sellItem`. Uses WeakMap stmt cache. Sell value = 40% of buy_price.
|
||||
- `src/routes/shop.js` — `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.
|
||||
@@ -32,24 +33,22 @@
|
||||
- `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` — 16 integration tests (stock, level gating, buy, sell, equipped rejection, concurrent double-buy, round-trip).
|
||||
- `tests/integration/shop-page.test.js` — 5 integration tests (stock listing, levelOk, sell pricing, buy/sell round-trip).
|
||||
- `tests/integration/inventory.test.js` — 20 integration tests (13 equip/unequip + 7 consumable).
|
||||
- `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/shop.html` — dedicated shop page with buy/sell tabs.
|
||||
- `public/js/shop.js` — shop page JS: render stock, render materials, buy/sell handlers, tab switching, auth guard.
|
||||
- `public/game.html` — dashboard with stats panel, tabbed action panel (Hunt/Inventory), equipment panel, inventory grid.
|
||||
- `public/js/shop.js` — shop page JS.
|
||||
- `public/game.html` — dashboard with stats panel, tabbed action panel (Hunt/Inventory).
|
||||
- `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 link in game.html top-bar navigation (users must navigate manually to /shop.html).
|
||||
- No expedition UI yet (Phase 7).
|
||||
- No shop link in game.html top-bar navigation.
|
||||
- No expedition service/routes yet (step 7.2).
|
||||
- No leaderboard UI yet (Phase 8).
|
||||
- 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).
|
||||
- Step 7.1: need migration `005_expeditions.sql` with expedition table + seed data.
|
||||
|
||||
## 5. Decisions & deviations from the docs
|
||||
- D-004..D-007 in `docs/DECISIONS.md` (combat rounds, equipment counted once, session store, clock).
|
||||
@@ -57,29 +56,25 @@
|
||||
- Inventory response uses `itemId` (item.id) and `inventoryId` (inventory row id) to avoid confusion.
|
||||
- Consumable effect parsing: regex `^(heal|energy):(\d+)$` on items.effect field.
|
||||
- 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).
|
||||
- **D-009:** `sellItem` checks equipped_slot before material type, so equipped items are always rejected regardless of item type.
|
||||
- **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.
|
||||
- Expedition seed data: 3 definitions (Scout 10min/10energy/1min, Raid 1h/30energy/3min, Delve 4h/60energy/5min) with XP 30-300 and gold 5-150.
|
||||
|
||||
## 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.
|
||||
- `npm test` must be `node --test` with NO path/glob; files must be named `*.test.js`.
|
||||
- better-sqlite3-session-store ignores `clear:false`; that's why the timer is unref'd.
|
||||
- Statement caches are per-DB-handle (WeakMap) in huntService; copy that pattern for new services.
|
||||
- Verify test COUNT, not just "all passing".
|
||||
- Node.js `fetch` doesn't persist cookies across calls — extract `Set-Cookie` header and pass manually in integration tests.
|
||||
- Express query params are strings, not numbers — use `zod.coerce.number()` for numeric query params.
|
||||
- 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 } }`.
|
||||
- Transaction callback args must match the call order exactly.
|
||||
- Error responses from route-level `AppError`s do NOT include `data` field.
|
||||
|
||||
## 7. Next-step briefing (7.1)
|
||||
- **Goal:** Migration `005_expeditions.sql` — create expeditions table and seed expedition definitions.
|
||||
- **Docs:** GAME_DESIGN.md §Expeditions, DATABASE.md.
|
||||
- **Files to create:** `src/db/migrations/005_expeditions.sql`.
|
||||
- **Key schema:** expeditions table (id, character_id, expedition_id, started_at, ends_at, claimed boolean FK constraints). Only one active expedition per hero at a time.
|
||||
- **Seed data:** expedition definitions in the same migration (INSERT OR IGNORE).
|
||||
## 7. Next-step briefing (7.2)
|
||||
- **Goal:** Expedition API: start, active, claim endpoints.
|
||||
- **Docs:** GAME_DESIGN.md §Expeditions, DATABASE.md (005_expeditions.sql schema already created).
|
||||
- **Files to create:** `src/services/expeditionService.js`, `src/routes/expeditions.js`.
|
||||
- **Key logic:** `startExpedition(characterId, defId)` — checks no active expedition, checks energy, deducts energy, inserts row with started_at/ends_at. `getActive(characterId)` — returns unclaimed expedition. `claimExpedition(characterId, expeditionId)` — checks ends_at <= now, checks claimed_at IS NULL, sets claimed_at, grants XP+gold(+loot for 1h+). All in transactions.
|
||||
|
||||
## 8. Open Known Issues
|
||||
STATUS.md issues 1–6 (balance, dangling `seed` script, restart test, equipment-in-combat, HP regen, zone min_level balance).
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
## Current Focus
|
||||
- **Phase:** 7
|
||||
- **Step:** 7.1
|
||||
- **Step:** 7.2
|
||||
- **Blocked?** No
|
||||
- **Last verified working command:** `npm test` — 139/139 passing (85 unit + 54 integration), 2026-10-21 step 6.3
|
||||
- **Last verified working command:** `npm test` — 139/139 passing (85 unit + 54 integration), 2026-10-21 step 7.1
|
||||
|
||||
## Project Health
|
||||
| Item | State |
|
||||
@@ -91,7 +91,7 @@
|
||||
*Acceptance:* sell equipped item → 400 VALIDATION_ERROR; concurrent double-buy → exactly one succeeds with INSUFFICIENT_GOLD for the other; insufficient gold already covered. *Verified:* 2 new integration tests added to shop.test.js; `sellItem` check moved before material type check so equipped items are rejected regardless of type.
|
||||
|
||||
## Phase 7 — Expeditions (Offline Progress) (docs: GAME_DESIGN §Time, §Expeditions)
|
||||
- [ ] **7.1** Migration `005_expeditions.sql`. Expedition definitions in seed data.
|
||||
- [x] **7.1** Migration `005_expeditions.sql`. Expedition definitions in seed data.
|
||||
- [ ] **7.2** `POST /api/expeditions/start`, `GET /api/expeditions/active`, `POST /api/expeditions/claim`. Only one active expedition per hero. Claim rejected before `ends_at`.
|
||||
- [ ] **7.3** UI: start panel, progress bar, claim button.
|
||||
*Acceptance:* start → close browser → return after duration → claim → rewards granted exactly once.
|
||||
@@ -148,11 +148,12 @@ Severity: `blocker` / `major` / `minor` / `cosmetic`. Status: `open` / `fixing`
|
||||
## Test Summary
|
||||
| Suite | Passing | Failing | Last run |
|
||||
|---|---|---|---|
|
||||
| unit | 85 | 0 | 2026-10-21 step 6.1 |
|
||||
| integration | 54 | 0 | 2026-10-21 step 6.3 |
|
||||
| unit | 85 | 0 | 2026-10-21 step 7.1 |
|
||||
| integration | 54 | 0 | 2026-10-21 step 7.1 |
|
||||
|
||||
## Session Log
|
||||
_Format:_ `YYYY-MM-DD | step | what changed | result`
|
||||
- 2026-10-21 | 7.1 | Created migration `005_expeditions.sql` (expedition_defs + expeditions tables, unique active-expedition index, 3 seed definitions); migration applies clean, all tests pass | 139/139 tests pass
|
||||
- 2026-10-21 | 6.3 | Added 2 integration tests to shop.test.js (sell equipped item rejection, concurrent double-buy safety); moved equipped check before material type check in sellItem so equipped items are rejected regardless of type | 139/139 tests pass
|
||||
- 2026-10-21 | 6.2 | Created shop UI: `public/shop.html` + `public/js/shop.js` (buy/sell tabs, level-gated stock display, material sell list, toast notifications); 5 integration tests for shop page API coverage | 137/137 tests pass
|
||||
- 2026-10-21 | 6.1 | Ticked step 6.1 — acceptance criteria verified: GET /api/shop, POST /api/shop/buy, POST /api/shop/sell all implemented with 40% sell value and gold-negative protection; 14 integration tests all passing | 132/132 tests pass
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
-- 005_expeditions.sql — Expedition system: definitions and player expedition records.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS expedition_defs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
min_level INTEGER NOT NULL,
|
||||
duration_sec INTEGER NOT NULL,
|
||||
energy_cost INTEGER NOT NULL,
|
||||
xp_reward INTEGER NOT NULL,
|
||||
gold_min INTEGER NOT NULL,
|
||||
gold_max INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS expeditions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
character_id INTEGER NOT NULL REFERENCES characters(id) ON DELETE CASCADE,
|
||||
def_id INTEGER NOT NULL REFERENCES expedition_defs(id),
|
||||
started_at INTEGER NOT NULL,
|
||||
ends_at INTEGER NOT NULL,
|
||||
claimed_at INTEGER -- NULL until claimed
|
||||
);
|
||||
|
||||
-- At most one unclaimed (active) expedition per character.
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_one_active_expedition
|
||||
ON expeditions(character_id) WHERE claimed_at IS NULL;
|
||||
|
||||
-- ===== EXPEDITION DEFINITIONS =====
|
||||
-- "Scout the Old Road" — 10 min, low risk/reward
|
||||
INSERT OR IGNORE INTO expedition_defs (id, slug, name, description, min_level, duration_sec, energy_cost, xp_reward, gold_min, gold_max) VALUES
|
||||
(1, 'scout-old-road', 'Scout the Old Road', 'Patrol the abandoned trade route north of Cindergate.', 1, 600, 10, 30, 5, 15),
|
||||
-- "Raid the Bandit Camp" — 1 hour, medium risk/reward (+ loot roll)
|
||||
(2, 'raid-bandit-camp', 'Raid the Bandit Camp', 'Launch a coordinated strike on the bandit encampment in Gloomroot.', 3, 3600, 30, 100, 20, 60),
|
||||
-- "Delve the Hollow" — 4 hours, high risk/reward (+ loot roll)
|
||||
(3, 'delve-the-hollow', 'Delve the Hollow', 'Explore the ancient ruins beneath the Ashfang Crags.', 5, 14400, 60, 300, 50, 150);
|
||||
Reference in New Issue
Block a user