xonecas.ioDon't click! Sean Caetano Martin Sign in

tiny-adventure / commits / f0f76c6

Walking spends the day, camping heals once a night, and a wiped party loses the campaign

Every hex walked and every fight spends daylight. After dusk the party can make camp once, away from enemies, to heal and start a new day, with a campfire and night lighting on the board. Traders work only at spawns and cleared camps and villages. A lost fight ends the campaign on a defeat screen. Bands chase farther at night and calm down after the party backs off. Titles use the vendored MedievalSharp and body text uses Alegreya, both OFL, and every label is centred in its box from measured cap height. The wood frame is replaced by a ring of sea and peaks, and unexplored hexes sit dark and low until the party reveals them. The harness plays with one shared careful bot (20 of 20 seeds won through the API). Verified with scripts/verify.sh (0 failures at 6 resolutions) and a seed 7 playthrough (victory on day 6 in 11 battles, no console errors).

Co-Authored-By: Claude Opus 5.5

sacenox2 days agof0f76c61701865fa4510e8ed3aa730a92c07e37eparent 69776d046 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

README.md+7-6
@@ -1,6 +1,6 @@
11 # Tiny Adventure
22
3-A procedurally generated, tiny Dungeons and Dragons style campaign in the browser, played with painted miniatures on a tabletop board. A Go server generates the world from a seed. A Three.js client renders it. Fights play out automatically from unit stats, abilities and gear. Your decisions are when to fight, when to rest, and what to buy, sell and equip.
3+A procedurally generated, tiny Dungeons and Dragons style campaign in the browser, played with painted miniatures on a tabletop board. A Go server generates the world from a seed. A Three.js client renders it. Fights play out automatically from unit stats, abilities and gear. Your decisions are where to walk, when to fight, where to camp, and what to buy, sell and equip.
44
55 ## Run
66
@@ -32,22 +32,23 @@ The seed decides every system and its details:
3232 - Party: classes, stats, abilities and starting gear are rolled per seed.
3333 - Progression: enemy level grows with distance from the spawn. Gear comes from loot found on the map and from fights. XP comes from fights. The boss fight unlocks after every other main step is done.
3434
35-Beating the boss ends the campaign with a stats screen.
35+Beating the boss ends the campaign with a victory screen. If the whole party falls, it ends with a defeat screen.
3636
3737 ## Playing
3838
3939 - Click a hex to walk there. Roads are fast, hills, shallows and forest are slow. Right-drag or Q/E rotates, the wheel zooms.
4040 - The next main objective is always marked with a light beam and labelled with its level (`Lv N`), even in the fog. J opens the journal, which marks the next step.
4141 - Walking toward a place that is still held stops you next to it and shows its defenders, your chance to win, and how much health the fight should cost. Fight (Enter) or back off (Esc).
42-- Wounds carry from fight to fight. Shallows, mountains and harsh biomes wear the party down as it walks. Rest (C) at a spawn or any place you cleared. Spawns, camps and villages also trade potions and gear. P drinks a potion on the selected hero.
43-- Roaming bands chase a party that comes near. Some chests are guarded, trapped, or mimics. Lookouts reveal the land, shrines heal, and old caches grant XP.
42+- Every hex walked spends daylight, and fights take time too. After dusk, make camp (C) once to heal everyone and start a new day, away from enemies. Wounds carry until then. Shallows, mountains and harsh biomes wear the party down as it walks. P drinks a potion on the selected hero.
43+- Traders (T) work at the spawns and at camps and villages you cleared. They sell potions and gear.
44+- Roaming bands chase a party that comes near, from farther away at night. Backing off from a band shakes it off for a few moves. Some chests are guarded, trapped, or mimics. Lookouts reveal the land, shrines heal, and old caches grant XP.
4445 - Walking over loot picks it up. Items may carry a trait, such as fire, lifesteal or taunt, paid for with a lower stat. Enemies show their traits, weaknesses and resistances on the threat card. Prepare (G) opens the inventory with live odds, so you can gear for the fight in front of you.
45-- A lost fight carries the party back to the nearest camp, patched up, and costs a quarter of its gold. Heroes still earn half XP, more when they fought above their level.
46+- A lost fight ends the campaign.
4647 - M toggles sound.
4748
4849 ## Check
4950
50-`scripts/verify.sh <outdir> [seed]` runs the live-game harness at every resolution. `scripts/playthrough.sh <outdir> <seed> [width height name]` plays a whole campaign from the title to the end screen with real clicks, records it, and fails on a softlock, a state mismatch, a layout problem or a console error. See `docs/verification.md`.
51+`scripts/verify.sh <outdir> [seed]` runs the live-game harness at every resolution. `scripts/playthrough.sh <outdir> <seed> [width height name]` plays a whole campaign from the title to the end screen with real clicks, using the same careful bot as the verify fast-forward (`scripts/bot.mjs`), records it, and fails on a softlock, a state mismatch, a layout problem or a console error. See `docs/verification.md`.
5152
5253 ```
5354 go vet ./...
docs/api.md+16-9
@@ -55,15 +55,20 @@ Every endpoint except `/api/seed` and `/api/combat/log` returns a full `GameStat
5555 },
5656 "log": [],
5757 "phase": "explore",
58+ "clock": {"day": 1, "time": 0, "dayLength": 60, "nightLength": 30},
5859 "summary": {"battles": 0, "kills": 0, "loot": 0, "steps": 0, "seconds": 0}
5960 }
6061 ```
6162
62-Combat resolves instantly on the server, so `phase` is never left at `combat`. After a fight `encounter` (`Encounter`) and `log` describe it until the next move or interact. The next action after a defeat resumes `explore`. `summary.seconds` is the elapsed play time, frozen at victory. The boss POI only starts its fight once all other main steps are done. A `retrieve` step completes once its POI is cleared and the key item is in the inventory.
63+Combat resolves instantly on the server, so `phase` is never left at `combat`. After a fight `encounter` (`Encounter`) and `log` describe it until the next move or interact. `summary.seconds` is the elapsed play time, frozen at victory or defeat. The boss POI only starts its fight once all other main steps are done. A `retrieve` step completes once its POI is cleared and the key item is in the inventory.
6364
64-Optional fields: `encounter` (`Encounter`, present after a fight), `rewards` (`Rewards`, present after a won fight), `found` (items auto-collected by the latest move or interact, cleared on the next action), `threat` (`Threat`, see `/api/move`), `camp` (`Camp`, present while the party stands on a camp), `winner` (player id, set at `victory`).
65+Optional fields: `encounter` (`Encounter`, present after a fight), `rewards` (`Rewards`, present after a won fight), `found` (items auto-collected by the latest move or interact, cleared on the next action), `threat` (`Threat`, see `/api/move`), `shop` (`Shop`, present while the party stands where a trader works), `winner` (player id, set at `victory`).
6566
66-A lost fight sets `phase: "defeat"`, carries the party to the nearest camp at full health, takes a quarter of its gold, and grants half the fight's XP.
67+A lost fight sets `phase: "defeat"` and every hero's `hp` to 0. The campaign is over: every action except `/api/new` fails with 400.
68+
69+## Clock
70+
71+`clock.time` counts from 0 at dawn. Walking a hex spends its walking cost, and a fight spends 6. Night starts at `dayLength` and lasts `nightLength`. Dawn after a night with no rest starts the next `day` without healing. At night roaming bands move on every step and chase from farther away.
6772
6873 Each POI has a `level`, the enemy level of its fight. The boss is one level higher. Levels rise with the distance from the spawn, up to about 5 at the boss.
6974
@@ -77,6 +82,8 @@ The map is a board of pointy-top hexes in offset coordinates: odd rows sit half
7782 - Biomes: 0 to 8, named in `model.Biomes`.
7883 - Flags: bit 1 forest, bit 2 road.
7984
85+The outer two hexes of the map are deep water or peaks, so the board ends in sea or mountains.
86+
8087 Walking costs 1 on a road, 2 on a plain, 3 on shallows and hills, and 4 on mountains, plus 1 in forest. The server walks the cheapest path.
8188
8289 `bands` are enemies on the board:
@@ -85,7 +92,7 @@ Walking costs 1 on a road, 2 on a plain, 3 on shallows and hills, and 4 on mount
8592 - `guard` bands sit on a chest.
8693 - `mimic` bands are chests that bite.
8794
88-A cleared band stays `cleared`. A band that wins goes back home.
95+A cleared band stays `cleared`. Backing off from a band's threat sets its `calm` to 6: it neither chases nor stops the party for that many moves.
8996
9097 `landmarks` fire once, when the party steps on them:
9198
@@ -176,19 +183,19 @@ Assigns an ability to the unit's equipped ability slot, used by auto-combat.
176183
177184 Response: `GameState` with updated `party.units[].abilities`.
178185
179-## Camps
186+## Traders and camping
180187
181-Camps are the spawns and every cleared POI. While the party stands on one, `camp` is set. Spawns and cleared POIs of kind `camp` or `village` also trade:
188+Traders work at the spawns and at cleared POIs of kind `camp` or `village`. While the party stands on one, `shop` is set:
182189
183190 ```json
184-{"id": "sp1", "name": "shrine", "trade": true, "stock": [], "potionPrice": 15}
191+{"id": "sp1", "name": "wagon", "stock": [], "potionPrice": 15}
185192 ```
186193
187-`stock` holds three items rolled from the seed for that camp, one tier above its level. The rest of this section's endpoints fail with 400 away from a camp. Buy and sell also fail where `trade` is false.
194+`stock` holds three items rolled from the seed for that place, one tier above its level. Buy and sell fail with 400 away from a trader.
188195
189196 ### POST /api/rest
190197
191-Heals every hero to full. Body `{}`.
198+Makes camp where the party stands. Body `{}`. Heals every hero to full and starts the next day at `time` 0. Fails with 400 during the day, and with 400 when an uncleared POI or band is within one hex.
192199
193200 ### POST /api/buy
194201
docs/verification.md+8-7
@@ -12,10 +12,10 @@ Needs `go`, `node`, `ffmpeg` (for the recording), `python3`, and `agent-browser`
1212
1313 1. Builds and starts the server on a free port with `--seed`.
1414 2. Opens a headed Chrome on `DISPLAY` (default `:0`) with software WebGL flags, so a window appears on the desktop. Do not touch the desktop while it runs.
15-3. For each of 1280x720, 1920x1080, 2560x1440, 1366x768, 800x600 and 390x844, resets the campaign to the seed and plays through input only: clicks Begin, clicks a ground tile, presses I, J and Escape, then for each main-quest POI in order clicks it, waits for the threat card and clicks Fight. On the first card it clicks Prepare, checks the inventory opens with odds, and clicks back. A band that intercepts the walk is fought instead. When a hero is below half health it first walks to the nearest …
15+3. For each of 1280x720, 1920x1080, 2560x1440, 1366x768, 800x600 and 390x844, resets the campaign to the seed and plays through input only: clicks Begin, presses T at the wagon and clicks a potion, clicks a ground tile, presses I, J and Escape, then clicks the first main POI, clicks Prepare and back, and clicks Fight. Then the careful bot in `scripts/bot.mjs` plays a few steps with real clicks. Setup through the API walks until dusk, the page reloads, and the harness clicks Make camp and checks …
1616 4. Exits non-zero if any assertion failed.
1717
18-`VERIFY_ONLY=1280x720,390x844` limits the resolutions. `VERIFY_ATTEMPTS=n` caps POI clicks (default 14).
18+`VERIFY_ONLY=1280x720,390x844` limits the resolutions. `VERIFY_STEPS=n` caps the bot steps played through the UI at 1280x720 (default 10, 2 elsewhere).
1919
2020 ## Playthrough
2121
@@ -23,19 +23,19 @@ Needs `go`, `node`, `ffmpeg` (for the recording), `python3`, and `agent-browser`
2323 scripts/playthrough.sh <outdir> <seed> [width height name]
2424 ```
2525
26-Plays one full campaign on `<seed>` through input only: clicks Begin, opens the journal, then clicks the next main POI and Fight on its threat card until the end screen shows. Before each fight it clicks Prepare and clicks pack items that beat the equipped ones. Bands that intercept the walk are fought. When a hero is below half health it rests at the nearest camp first. After two defeats at one POI it walks to a lower level POI first. It records `<name>.webm`, saves screenshots and `<name>.md`/ …
26+Plays one full campaign on `<seed>` through input only, with the careful bot from `scripts/bot.mjs`: it fights a threat at 80% odds or better and backs off otherwise, levels up on easier places and bands, drinks or buys potions by day, and walks until dusk to make camp when hurt. On the first threat card it clicks Prepare and clicks pack items that beat the equipped ones. It records `<name>.webm`, saves screenshots and `<name>.md`/`<name>.json`, and exits non-zero on any failed step, a client an …
2727
2828 ## Output
2929
3030 - `report.md` and `report.json`: per resolution, a table of every interaction with the server state after it (from `/api/state`), the layout checks and console errors.
31-- `screens/<WxH>/NN-*.png`: title, explore, after-move, inventory, journal, threat, combat, camp, end.
31+- `screens/<WxH>/NN-*.png`: title, explore, trader, after-move, inventory, journal, threat, prepare, combat, night, camp, dawn, victory, new-game, defeat.
3232 - `recording.webm`: the whole 1280x720 session.
3333 - `server.log`.
3434
3535 ## Assertions
3636
3737 - After each input, `/api/state` must show the expected change (party moved, battle counted, mode changed) and the client party position from `window.__game.state()` must equal the server's.
38-- Layout, read from `window.__game.rects()` only: every `essential` rect is fully inside the viewport, and no two rects partly overlap (full containment is allowed). Checked on title, explore, inventory, journal, threat card, combat, camp and end screens.
38+- Layout, read from `window.__game.rects()` only: every `essential` rect is fully inside the viewport, and no two rects partly overlap (full containment is allowed). Checked on title, explore, inventory, journal, threat card, combat, trader, night HUD, victory and defeat screens.
3939 - The page must log no console errors or uncaught exceptions.
4040
4141 ## Reviewing the output
@@ -48,9 +48,10 @@ Defined in `web/js/debug.js`, installed after boot.
4848
4949 | Member | Meaning |
5050 | --- | --- |
51-| `mode` | `loading`, `title`, `explore`, `threat`, `prepare`, `combat`, `end` |
51+| `mode` | `loading`, `title`, `explore`, `threat`, `prepare`, `combat`, `camp`, `end` |
5252 | `busy` | true while a move, walk or fight animation runs |
53-| `state()` | phase, seed, party x/y/gold/potions/inventory/unit levels and hp, threat, camp, summary, winner |
53+| `state()` | phase, seed, party x/y/gold/potions/inventory/unit levels and hp, threat, shop, clock, summary, winner |
54+| `perf()` | frame time over the last 240 frames (`fps`, `p50`, `p95`, `max` in ms), draw calls, triangles and the GPU name |
5455 | `rects()` | `[{name, x, y, w, h, essential}]` in CSS pixels |
5556 | `setRects(fn)` | replace the rect provider (use when the UI is drawn in Three.js) |
5657 | `tileScreen(x, y)` | screen position of a tile, for real clicks |
internal/gen/rng.go+1-1
@@ -9,7 +9,7 @@ import (
99 )
1010
1111 func NewSeed() model.Seed {
12- return model.Seed(rand.New(rand.NewSource(time.Now().UnixNano())).Int63())
12+ return model.Seed(rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(1_000_000))
1313 }
1414
1515 func sub(seed model.Seed, tag string) *rand.Rand {
internal/model/clock.go+10-0
@@ -0,0 +1,10 @@
1+package model
2+
3+type Clock struct {
4+ Day int `json:"day"`
5+ Time int `json:"time"`
6+ DayLength int `json:"dayLength"`
7+ NightLength int `json:"nightLength"`
8+}
9+
10+func (c Clock) Night() bool { return c.Time >= c.DayLength }
internal/model/shop.go+1-2
@@ -1,9 +1,8 @@
11 package model
22
3-type Camp struct {
3+type Shop struct {
44 ID string `json:"id"`
55 Name string `json:"name"`
6- Trade bool `json:"trade,omitempty"`
76 Stock []Item `json:"stock"`
87 PotionPrice int `json:"potionPrice"`
98 }
internal/model/state.go+2-1
@@ -22,7 +22,8 @@ type GameState struct {
2222 Trail [][2]int `json:"trail,omitempty"`
2323 Notes []string `json:"notes,omitempty"`
2424 Threat *Threat `json:"threat,omitempty"`
25- Camp *Camp `json:"camp,omitempty"`
25+ Shop *Shop `json:"shop,omitempty"`
26+ Clock Clock `json:"clock"`
2627 Phase string `json:"phase"`
2728 Winner string `json:"winner,omitempty"`
2829 Summary Summary `json:"summary"`
internal/model/worldmap.go+1-0
@@ -57,6 +57,7 @@ type Band struct {
5757 HomeX int `json:"homeX"`
5858 HomeY int `json:"homeY"`
5959 Cleared bool `json:"cleared,omitempty"`
60+ Calm int `json:"calm,omitempty"`
6061 }
6162
6263 type Landmark struct {
internal/server/bands.go+27-6
@@ -7,9 +7,11 @@ import (
77 )
88
99 const (
10- aggro = 5
11- bandPace = 2
12- wanderOff = 3
10+ aggro = 5
11+ nightAggro = 8
12+ bandPace = 2
13+ wanderOff = 3
14+ shakeOff = 6
1315 )
1416
1517 func (g *game) band(id string) *model.Band {
@@ -36,9 +38,14 @@ func (g *game) occupied(x, y int) bool {
3638
3739 func (g *game) tickBands() string {
3840 g.ticks++
39- if g.ticks%bandPace != 0 {
41+ night := g.state.Clock.Night()
42+ if !night && g.ticks%bandPace != 0 {
4043 return g.contact()
4144 }
45+ reach := aggro
46+ if night {
47+ reach = nightAggro
48+ }
4249 r := sim.NewRNG(g.state.Seed ^ model.Seed(g.ticks)*6151)
4350 m := &g.state.Map
4451 px, py := g.state.Party.X, g.state.Party.Y
@@ -48,7 +55,7 @@ func (g *game) tickBands() string {
4855 continue
4956 }
5057 var next [2]int
51- if dist(b.X, b.Y, px, py) <= aggro {
58+ if b.Calm == 0 && dist(b.X, b.Y, px, py) <= reach {
5259 if path := world.Path(m, [2]int{b.X, b.Y}, [2]int{px, py}, g.occupied); len(path) > 1 {
5360 next = path[0]
5461 }
@@ -66,9 +73,23 @@ func (g *game) tickBands() string {
6673 return g.contact()
6774 }
6875
76+func (g *game) shake() {
77+ if b := g.band(g.threat); b != nil && b.Kind == "roam" {
78+ b.Calm = shakeOff
79+ }
80+}
81+
82+func (g *game) settle() {
83+ for i := range g.state.Map.Bands {
84+ if b := &g.state.Map.Bands[i]; b.Calm > 0 {
85+ b.Calm--
86+ }
87+ }
88+}
89+
6990 func (g *game) contact() string {
7091 for _, b := range g.state.Map.Bands {
71- if !b.Cleared && b.Kind == "roam" && dist(b.X, b.Y, g.state.Party.X, g.state.Party.Y) <= 1 {
92+ if !b.Cleared && b.Kind == "roam" && b.Calm == 0 && dist(b.X, b.Y, g.state.Party.X, g.state.Party.Y) <= 1 {
7293 return b.ID
7394 }
7495 }
internal/server/clock.go+63-0
@@ -0,0 +1,63 @@
1+package server
2+
3+import (
4+ "errors"
5+
6+ "tinyadventure/internal/model"
7+)
8+
9+const (
10+ dayLength = 60
11+ nightLength = 30
12+ fightTime = 6
13+)
14+
15+func newClock() model.Clock {
16+ return model.Clock{Day: 1, DayLength: dayLength, NightLength: nightLength}
17+}
18+
19+func (g *game) pass(t int) {
20+ c := &g.state.Clock
21+ dusk := c.Night()
22+ c.Time += t
23+ if c.Time >= c.DayLength+c.NightLength {
24+ c.Day++
25+ c.Time = 0
26+ g.note("Dawn breaks without rest")
27+ } else if !dusk && c.Night() {
28+ g.note("Night falls. Make camp, or press on in the dark")
29+ }
30+}
31+
32+func (g *game) rest() error {
33+ if g.finished() {
34+ return errors.New("campaign is over, start a new game")
35+ }
36+ c := &g.state.Clock
37+ if !c.Night() {
38+ return errors.New("too early to make camp: rest after dusk")
39+ }
40+ if g.blockerNear() {
41+ return errors.New("enemies are too close to make camp")
42+ }
43+ g.begin()
44+ g.healAll()
45+ c.Day++
46+ c.Time = 0
47+ return nil
48+}
49+
50+func (g *game) blockerNear() bool {
51+ px, py := g.state.Party.X, g.state.Party.Y
52+ for _, p := range g.state.Map.POIs {
53+ if !p.Cleared && dist(p.X, p.Y, px, py) <= 1 {
54+ return true
55+ }
56+ }
57+ for _, b := range g.state.Map.Bands {
58+ if !b.Cleared && dist(b.X, b.Y, px, py) <= 1 {
59+ return true
60+ }
61+ }
62+ return false
63+}
internal/server/danger_test.go+15-0
@@ -83,3 +83,18 @@ func TestLandmarksAndTraps(t *testing.T) {
8383 t.Fatal("rogue failed to disarm")
8484 }
8585 }
86+
87+func TestBackingOffShakesABandOff(t *testing.T) {
88+ g := openGame(30, 3)
89+ g.state.Party = party("fighter")
90+ g.state.Party.X, g.state.Party.Y = 10, 1
91+ g.state.Map.Bands = []model.Band{{ID: "b1", Kind: "roam", X: 11, Y: 1, HomeX: 11, HomeY: 1}}
92+ g.encs = map[string]model.Encounter{"b1": {ID: "enc-b1", POI: "b1"}}
93+ g.threat = "b1"
94+ if err := g.move(2, 1); err != nil {
95+ t.Fatal(err)
96+ }
97+ if g.threat != "" || g.state.Party.X > 5 {
98+ t.Fatalf("party stuck at %d with threat %q", g.state.Party.X, g.threat)
99+ }
100+}
internal/server/game.go+7-15
@@ -31,7 +31,7 @@ func newGame(player string, seed model.Seed) *game {
3131 state: model.GameState{
3232 Version: model.Version, PlayerID: player, Seed: seed,
3333 Campaign: w.Campaign, Map: w.Map, Party: w.Party,
34- Log: []model.CombatEvent{}, Phase: "explore",
34+ Log: []model.CombatEvent{}, Phase: "explore", Clock: newClock(),
3535 },
3636 encs: encs,
3737 spawn: w.Map.Spawns[0],
@@ -49,11 +49,11 @@ func (g *game) snapshot() model.GameState {
4949 }
5050 s.Summary.Seconds = int(end.Sub(g.started).Seconds())
5151 s.Threat = g.threatView()
52- s.Camp = g.campView()
52+ s.Shop = g.shopView()
5353 return s
5454 }
5555
56-func (g *game) finished() bool { return g.state.Phase == "victory" }
56+func (g *game) finished() bool { return g.state.Phase == "victory" || g.state.Phase == "defeat" }
5757
5858 func (g *game) begin() {
5959 g.state.Encounter = nil
@@ -63,9 +63,6 @@ func (g *game) begin() {
6363 g.state.Notes = nil
6464 g.state.Log = []model.CombatEvent{}
6565 g.threat = ""
66- if g.state.Phase == "defeat" {
67- g.state.Phase = "explore"
68- }
6966 }
7067
7168 func (g *game) poi(id string) *model.POI {
@@ -140,23 +137,18 @@ func (g *game) fight(id string, x, y int, win func()) {
140137 tier = max(tier, e.Level)
141138 }
142139 g.fights++
140+ g.pass(fightTime)
143141 r := sim.NewRNG(g.state.Seed + model.Seed(g.fights)*7919)
144142 res := sim.Fight(r, &g.state.Party, enc, tier)
145143 g.state.Log = res.Log
146144 g.state.Encounter = &enc
147145 g.state.Summary.Battles++
148146 if res.Outcome != sim.OutcomeVictory {
149- g.state.Phase = "defeat"
150- xp := sim.Rewards(r, enc, tier).XP / 2 / max(len(g.state.Party.Units), 1)
151147 for i := range g.state.Party.Units {
152- sim.Grant(&g.state.Party.Units[i], sim.CatchUp(max(1, xp), tier, g.state.Party.Units[i].Level))
153- }
154- g.state.Party.X, g.state.Party.Y = g.camp(x, y)
155- if b := g.band(id); b != nil {
156- b.X, b.Y = b.HomeX, b.HomeY
148+ g.state.Party.Units[i].Stats.HP = 0
157149 }
158- g.state.Party.Gold -= g.state.Party.Gold / 4
159- g.healAll()
150+ g.state.Phase = "defeat"
151+ g.ended = time.Now()
160152 return
161153 }
162154 g.state.Rewards = &res.Rewards
internal/server/move.go+3-0
@@ -40,6 +40,7 @@ func (g *game) move(tx, ty int) error {
4040 if g.finished() {
4141 return errors.New("campaign is over, start a new game")
4242 }
43+ g.shake()
4344 g.begin()
4445 steps, err := g.path(tx, ty)
4546 if err != nil {
@@ -53,9 +54,11 @@ func (g *game) move(tx, ty int) error {
5354 }
5455 g.state.Party.X, g.state.Party.Y = s[0], s[1]
5556 g.state.Trail = append(g.state.Trail, s)
57+ g.pass(g.state.Map.Cost(s[0], s[1]))
5658 g.pickup(s[0], s[1])
5759 g.visit(s[0], s[1])
5860 g.endure(s[0], s[1], lost)
61+ g.settle()
5962 if id := g.tickBands(); id != "" {
6063 g.threat = id
6164 break
internal/server/play_test.go+162-66
@@ -57,22 +57,46 @@ func TestRouteFallsBackThroughPOIInCorridor(t *testing.T) {
5757 }
5858 }
5959
60-func TestDefeatFallsBackToNearestCamp(t *testing.T) {
61- g := openGame(30, 3)
62- g.spawn = model.SpawnPoint{X: 0, Y: 0}
63- g.state.Map.Spawns = []model.SpawnPoint{g.spawn}
64- g.state.Map.POIs = []model.POI{{ID: "p1", X: 20, Y: 0, Cleared: true}, {ID: "p2", X: 25, Y: 0}}
65- if x, _ := g.camp(g.state.Map.POIs[1].X, g.state.Map.POIs[1].Y); x != 20 {
66- t.Fatalf("cleared place is a camp, got %d", x)
67- }
68- g.state.Map.POIs[0].Cleared = false
69- if x, _ := g.camp(g.state.Map.POIs[1].X, g.state.Map.POIs[1].Y); x != 0 {
70- t.Fatalf("uncleared place is no camp, got %d", x)
71- }
72- g.state.Party.X, g.state.Party.Y = 20, 0
73- g.state.Map.POIs[0].Cleared = true
74- if c := g.campView(); c == nil || c.Trade || g.buy("potion") == nil {
75- t.Fatalf("a cleared ruin offers rest but no trade: %+v", c)
60+func TestDefeatEndsTheCampaign(t *testing.T) {
61+ g := openGame(5, 1)
62+ g.state.Party = party("mage")
63+ g.state.Party.Units[0].Stats = model.Stats{HP: 1, MaxHP: 1, Attack: 1}
64+ g.state.Map.POIs = []model.POI{{ID: "p1", X: 1, Y: 0}}
65+ g.encs = map[string]model.Encounter{"p1": {ID: "e1", POI: "p1", Enemies: []model.Unit{{ID: "x", Name: "Ogre", Level: 5, Stats: model.Stats{HP: 500, MaxHP: 500, Attack: 50}, Abilities: sim.Abilities("strike")}}}}
66+ g.state.Clock = newClock()
67+ g.state.Campaign.Main.Steps = []model.MissionStep{{ID: "s1", POI: "p0"}}
68+ if err := g.interact("p1"); err != nil {
69+ t.Fatal(err)
70+ }
71+ if g.state.Phase != "defeat" || !g.finished() || g.move(4, 0) == nil {
72+ t.Fatalf("phase %s finished %v", g.state.Phase, g.finished())
73+ }
74+}
75+
76+func TestCampOnlyAtNightOncePerDay(t *testing.T) {
77+ g := openGame(80, 1)
78+ g.state.Party = party("fighter")
79+ g.state.Party.Units[0].Stats.HP = 10
80+ g.state.Clock = newClock()
81+ if g.rest() == nil {
82+ t.Fatal("made camp in daylight")
83+ }
84+ if err := g.move(31, 0); err != nil || !g.state.Clock.Night() || len(g.state.Notes) == 0 {
85+ t.Fatalf("clock %+v notes %v err %v", g.state.Clock, g.state.Notes, err)
86+ }
87+ if err := g.rest(); err != nil {
88+ t.Fatal(err)
89+ }
90+ c := g.state.Clock
91+ if c.Day != 2 || c.Time != 0 || g.state.Party.Units[0].Stats.HP != 100 {
92+ t.Fatalf("after camp %+v hp %d", c, g.state.Party.Units[0].Stats.HP)
93+ }
94+ if g.rest() == nil {
95+ t.Fatal("made camp twice")
96+ }
97+ g.move(79, 0)
98+ if g.state.Clock.Day != 3 {
99+ t.Fatalf("a night without camp must still end the day: %+v", g.state.Clock)
76100 }
77101 }
78102
@@ -94,31 +118,109 @@ func equipAll(g *game) {
94118 }
95119 }
96120
97-func TestMainRouteIsWinnableWithoutGrinding(t *testing.T) {
98- for seed := model.Seed(1); seed <= 40; seed++ {
99- g := newGame("local", seed)
100- defeats := 0
101- for moves := 0; moves < 60 && !g.finished(); moves++ {
102- equipAll(g)
103- var poi *model.POI
104- for _, s := range g.state.Campaign.Main.Steps {
105- if !s.Done {
106- poi = g.poi(s.POI)
107- break
108- }
121+func TestCarefulPlayWinsMostCampaigns(t *testing.T) {
122+ wins, total := 0, 30
123+ for seed := model.Seed(1); seed <= model.Seed(total); seed++ {
124+ if careful(newGame("local", seed)) {
125+ wins++
126+ }
127+ }
128+ if wins*100/total < 90 {
129+ t.Fatalf("careful play won %d of %d", wins, total)
130+ }
131+}
132+
133+const safeOdds = 85
134+
135+func careful(g *game) bool {
136+ for moves := 0; moves < 300 && !g.finished(); moves++ {
137+ equipAll(g)
138+ g.recover()
139+ id, x, y := g.target()
140+ if id == "" {
141+ g.waitForCamp()
142+ if id, x, y = g.target(); id == "" {
143+ return false
109144 }
110- if err := g.engage(poi); err != nil {
111- t.Fatalf("seed %d: %v", seed, err)
145+ }
146+ g.move(x, y)
147+ if g.threat == "" {
148+ continue
149+ }
150+ if g.threatView().Odds < safeOdds {
151+ g.waitForCamp()
152+ continue
153+ }
154+ g.interact(g.threat)
155+ }
156+ return g.state.Phase == "victory"
157+}
158+
159+func (g *game) nextMain() *model.POI {
160+ for _, s := range g.state.Campaign.Main.Steps {
161+ if !s.Done {
162+ return g.poi(s.POI)
163+ }
164+ }
165+ return nil
166+}
167+
168+func (g *game) odds(id string) int {
169+ keep := g.threat
170+ g.threat = id
171+ odds := g.threatView().Odds
172+ g.threat = keep
173+ return odds
174+}
175+
176+func (g *game) target() (string, int, int) {
177+ if p := g.nextMain(); g.bossGate(p) && g.odds(p.ID) >= safeOdds {
178+ return p.ID, p.X, p.Y
179+ }
180+ best, bx, by, bo := "", 0, 0, safeOdds-1
181+ for _, p := range g.state.Map.POIs {
182+ if !p.Cleared && g.bossGate(&p) {
183+ if o := g.odds(p.ID); o > bo {
184+ best, bx, by, bo = p.ID, p.X, p.Y, o
112185 }
113- if g.state.Phase == "defeat" {
114- defeats++
186+ }
187+ }
188+ for _, b := range g.state.Map.Bands {
189+ if !b.Cleared {
190+ if o := g.odds(b.ID); o > bo {
191+ best, bx, by, bo = b.ID, b.X, b.Y, o
115192 }
116- g.recover()
117193 }
118- if !g.finished() || defeats > 12 {
119- t.Fatalf("seed %d: finished=%v defeats=%d", seed, g.finished(), defeats)
194+ }
195+ return best, bx, by
196+}
197+
198+func (g *game) waitForCamp() error {
199+ if g.blockerNear() || g.contact() != "" {
200+ px, py := g.state.Party.X, g.state.Party.Y
201+ for y := py - 3; y <= py+3; y++ {
202+ for x := px - 3; x <= px+3; x++ {
203+ if d := dist(x, y, px, py); d >= 2 && d <= 3 && g.state.Map.In(x, y) && g.state.Map.Walkable(x, y) && g.blocker(x, y) == "" && g.calm(x, y) {
204+ g.move(x, y)
205+ y = py + 4
206+ break
207+ }
208+ }
120209 }
121210 }
211+ if !g.state.Clock.Night() {
212+ g.pass(g.state.Clock.DayLength - g.state.Clock.Time)
213+ }
214+ return g.rest()
215+}
216+
217+func (g *game) calm(x, y int) bool {
218+ for _, n := range [][2]int{{x, y}, {x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}, {x + 1, y + 1}, {x - 1, y - 1}, {x + 1, y - 1}, {x - 1, y + 1}} {
219+ if g.blocker(n[0], n[1]) != "" {
220+ return false
221+ }
222+ }
223+ return true
122224 }
123225
124226 func TestPOILevelsGrowTowardTheBoss(t *testing.T) {
@@ -163,14 +265,13 @@ func (g *game) recover() {
163265 if g.finished() || !g.hurt() {
164266 return
165267 }
166- near := g.sites()[0]
167- for _, s := range g.sites() {
168- if dist(s.x, s.y, g.state.Party.X, g.state.Party.Y) < dist(near.x, near.y, g.state.Party.X, g.state.Party.Y) {
169- near = s
170- }
268+ if g.state.Clock.Night() && g.rest() == nil {
269+ return
171270 }
172- if err := g.move(near.x, near.y); err == nil {
173- g.rest()
271+ for _, u := range g.state.Party.Units {
272+ if u.Stats.HP*2 < sim.Effective(u).MaxHP {
273+ g.drink(u.ID)
274+ }
174275 }
175276 }
176277
@@ -214,7 +315,7 @@ func TestBarredBossShowsAsBarred(t *testing.T) {
214315 }
215316 }
216317
217-func TestHPCarriesBetweenFightsAndRestHeals(t *testing.T) {
318+func TestHPCarriesBetweenFights(t *testing.T) {
218319 g := newGame("local", 7)
219320 full := g.state.Party.Units[0].Stats.HP
220321 if full != sim.Effective(g.state.Party.Units[0]).MaxHP {
@@ -224,49 +325,44 @@ func TestHPCarriesBetweenFightsAndRestHeals(t *testing.T) {
224325 if err := g.move(p.X, p.Y); err != nil {
225326 t.Fatal(err)
226327 }
227- sx, sy := g.state.Party.X, g.state.Party.Y
328+ before := g.state.Clock.Time
228329 if err := g.interact(p.ID); err != nil {
229330 t.Fatal(err)
230331 }
231- if err := g.move(sx, sy); err != nil {
232- t.Fatal(err)
332+ if g.state.Clock.Time != before+fightTime {
333+ t.Fatalf("a fight must spend time: %d -> %d", before, g.state.Clock.Time)
233334 }
234- if !g.hurt() && g.state.Party.Units[0].Stats.HP == full {
235- t.Skip("party took no damage")
236- }
237- if err := g.rest(); err == nil {
238- t.Fatal("rested away from a camp")
239- }
240- sp := g.state.Map.Spawns[0]
241- if err := g.move(sp.X, sp.Y); err != nil {
242- t.Fatal(err)
335+ total := 0
336+ for _, u := range g.state.Party.Units {
337+ total += sim.Effective(u).MaxHP - u.Stats.HP
243338 }
244- if err := g.rest(); err != nil {
245- t.Fatal(err)
339+ if total == 0 {
340+ t.Skip("party took no damage")
246341 }
342+ g.move(p.X+1, p.Y)
247343 for _, u := range g.state.Party.Units {
248- if u.Stats.HP != sim.Effective(u).MaxHP {
249- t.Fatalf("%s at %d after rest", u.Name, u.Stats.HP)
344+ if u.Stats.HP > sim.Effective(u).MaxHP {
345+ t.Fatal("hp above max")
250346 }
251347 }
252348 }
253349
254-func TestCampTradeAndPotions(t *testing.T) {
350+func TestShopTradeAndPotions(t *testing.T) {
255351 g := newGame("local", 7)
256352 g.state.Party.Gold = 1000
257353 st := g.snapshot()
258- if st.Camp == nil || len(st.Camp.Stock) != stockSize {
259- t.Fatalf("camp %+v", st.Camp)
354+ if st.Shop == nil || len(st.Shop.Stock) != stockSize {
355+ t.Fatalf("shop %+v", st.Shop)
260356 }
261- it := st.Camp.Stock[0]
357+ it := st.Shop.Stock[0]
262358 if it.Value <= 0 {
263359 t.Fatalf("stock item has no value: %+v", it)
264360 }
265361 if err := g.buy(it.ID); err != nil {
266362 t.Fatal(err)
267363 }
268- if g.state.Party.Gold != 1000-it.Value || len(g.campView().Stock) != stockSize-1 {
269- t.Fatalf("gold %d stock %d", g.state.Party.Gold, len(g.campView().Stock))
364+ if g.state.Party.Gold != 1000-it.Value || len(g.shopView().Stock) != stockSize-1 {
365+ t.Fatalf("gold %d stock %d", g.state.Party.Gold, len(g.shopView().Stock))
270366 }
271367 if err := g.sell(it.ID); err != nil {
272368 t.Fatal(err)
@@ -290,7 +386,7 @@ func TestCampTradeAndPotions(t *testing.T) {
290386 t.Fatal("bought a potion with no gold")
291387 }
292388 g.state.Party.X++
293- if g.snapshot().Camp != nil || g.buy("potion") == nil {
389+ if g.snapshot().Shop != nil || g.buy("potion") == nil {
294390 t.Fatal("trade away from camp")
295391 }
296392 }
internal/server/server_test.go+23-153
@@ -3,10 +3,8 @@ package server
33 import (
44 "bytes"
55 "encoding/json"
6- "fmt"
76 "net/http"
87 "net/http/httptest"
9- "sort"
108 "testing"
119
1210 "tinyadventure/internal/model"
@@ -34,162 +32,33 @@ func (c client) call(method, path string, body any, want int) model.GameState {
3432 return st
3533 }
3634
37-func lootNode(st model.GameState, id string) model.LootNode {
38- for _, l := range st.Map.Loot {
39- if l.ID == id {
40- return l
41- }
42- }
43- return model.LootNode{}
44-}
45-
46-func (c client) collectAt(st model.GameState, x, y int) model.GameState {
47- for _, l := range st.Map.Loot {
48- if l.X != x || l.Y != y || l.Collected {
49- continue
50- }
51- st = c.call("POST", "/api/move", model.MoveRequest{X: x, Y: y}, 200)
52- for tries := 0; tries < 6 && st.Threat != nil && st.Threat.Band != ""; tries++ {
53- st = c.call("POST", "/api/interact", model.InteractRequest{ID: st.Threat.Band}, 200)
54- st = c.restIfHurt(st)
55- st = c.call("POST", "/api/move", model.MoveRequest{X: x, Y: y}, 200)
56- }
57- if st.Party.X == x && st.Party.Y == y && !lootNode(st, l.ID).Collected {
58- st = c.call("POST", "/api/interact", model.InteractRequest{ID: l.ID}, 200)
59- }
60- }
61- return st
62-}
63-
64-func (c client) collectAll(st model.GameState) model.GameState {
65- for _, l := range st.Map.Loot {
66- if p := (&game{state: st}).poiAt(l.X, l.Y); p == nil {
67- st = c.collectAt(st, l.X, l.Y)
68- }
69- }
70- return st
71-}
72-
73-func (c client) equipBest(st model.GameState) model.GameState {
74- score := func(it model.Item) int {
75- b := it.Bonus
76- return b.MaxHP/3 + b.Attack + b.Defense + b.Magic + b.Speed/2
77- }
78- for _, u := range st.Party.Units {
79- for _, it := range st.Party.Inventory {
80- if it.Key || it.Slot == "" {
81- continue
82- }
83- if old := u.Gear[it.Slot]; old == nil || score(*old) < score(it) {
84- st = c.call("POST", "/api/equip", model.EquipRequest{Unit: u.ID, Item: it.ID}, 200)
85- break
86- }
87- }
88- }
89- return st
90-}
91-
92-func (c client) restIfHurt(st model.GameState) model.GameState {
93- g := &game{state: st}
94- if !g.hurt() {
95- return st
96- }
97- sp := st.Map.Spawns[0]
98- for _, s := range g.sites() {
99- if dist(s.x, s.y, st.Party.X, st.Party.Y) < dist(sp.X, sp.Y, st.Party.X, st.Party.Y) {
100- sp = model.SpawnPoint{X: s.x, Y: s.y}
101- }
102- }
103- for tries := 0; tries < 6; tries++ {
104- st = c.call("POST", "/api/move", model.MoveRequest{X: sp.X, Y: sp.Y}, 200)
105- if st.Threat == nil || st.Threat.Band == "" {
106- break
107- }
108- st = c.call("POST", "/api/interact", model.InteractRequest{ID: st.Threat.Band}, 200)
109- }
110- if st.Party.X != sp.X || st.Party.Y != sp.Y {
111- return st
112- }
113- return c.call("POST", "/api/rest", nil, 200)
114-}
115-
116-func TestFullCampaign(t *testing.T) {
117- for _, seed := range []model.Seed{7, 21, 1234, 987654321} {
118- t.Run(fmt.Sprint(seed), func(t *testing.T) { playCampaign(t, seed) })
119- }
120-}
121-
122-func playCampaign(t *testing.T, seed model.Seed) {
123- ts := httptest.NewServer(New(seed, t.TempDir()))
35+func TestHTTPFlow(t *testing.T) {
36+ ts := httptest.NewServer(New(7, t.TempDir()))
12437 defer ts.Close()
12538 c := client{t, ts}
12639 st := c.call("GET", "/api/state", nil, 200)
127- if st.Phase != "explore" || st.Winner != "" {
128- t.Fatalf("bad start: %s", st.Phase)
129- }
130- st = c.collectAll(st)
131- for range 3 {
132- st = c.equipBest(st)
133- }
134- if st.Summary.Loot == 0 {
135- t.Fatal("no loot collected")
136- }
137- if got := len(c.call("GET", "/api/state", nil, 200).Party.Inventory); got == 0 {
138- t.Fatal("inventory empty")
139- }
140- var order []model.MissionStep
141- for _, m := range st.Campaign.SideQuests {
142- order = append(order, m.Steps...)
40+ if st.Phase != "explore" || st.Shop == nil || st.Clock.Day != 1 {
41+ t.Fatalf("bad start: %s shop %v clock %+v", st.Phase, st.Shop, st.Clock)
14342 }
144- main := st.Campaign.Main.Steps
145- order = append(order, main[:len(main)-1]...)
146- g := &game{state: st}
147- sort.SliceStable(order, func(i, j int) bool { return g.poi(order[i].POI).X < g.poi(order[j].POI).X })
148- order = append(order, main[len(main)-1])
149- for _, step := range order {
150- poi := g.poi(step.POI)
151- for tries := 0; tries < 40 && !(&game{state: st}).poi(step.POI).Cleared; tries++ {
152- st = c.call("POST", "/api/move", model.MoveRequest{X: poi.X, Y: poi.Y}, 200)
153- if st.Threat != nil && st.Threat.Band != "" {
154- st = c.call("POST", "/api/interact", model.InteractRequest{ID: st.Threat.Band}, 200)
155- st = c.restIfHurt(c.equipBest(st))
156- continue
157- }
158- if st.Threat == nil || st.Threat.POI != poi.ID {
159- t.Fatalf("no threat before %s", poi.ID)
160- }
161- st = c.call("POST", "/api/interact", model.InteractRequest{ID: poi.ID}, 200)
162- if len(st.Log) == 0 || st.Encounter == nil {
163- t.Fatal("fight without log or encounter")
164- }
165- st = c.equipBest(st)
166- if st.Phase != "victory" {
167- st = c.restIfHurt(st)
168- }
169- }
170- if !(&game{state: st}).poi(step.POI).Cleared {
171- t.Fatalf("could not clear %s step %s", poi.ID, step.ID)
172- }
173- if st.Phase != "victory" {
174- st = c.collectAt(st, poi.X, poi.Y)
175- }
43+ c.call("POST", "/api/rest", nil, 400)
44+ st = c.call("POST", "/api/buy", model.ItemRequest{Item: "potion"}, 200)
45+ if st.Party.Potions != 1 {
46+ t.Fatalf("potions %d", st.Party.Potions)
17647 }
177- for _, m := range append([]model.Mission{st.Campaign.Main}, st.Campaign.SideQuests...) {
178- for _, s := range m.Steps {
179- if !s.Done {
180- t.Fatalf("step %s not done", s.ID)
181- }
182- }
48+ p := (&game{state: st}).poi(st.Campaign.Main.Steps[0].POI)
49+ st = c.call("POST", "/api/move", model.MoveRequest{X: p.X, Y: p.Y}, 200)
50+ if st.Threat == nil || st.Threat.POI != p.ID || st.Clock.Time == 0 || len(st.Trail) == 0 {
51+ t.Fatalf("threat %+v clock %+v", st.Threat, st.Clock)
18352 }
184- if st.Phase != "victory" || st.Winner != "local" {
185- t.Fatalf("phase %s winner %q", st.Phase, st.Winner)
53+ st = c.call("POST", "/api/interact", model.InteractRequest{ID: p.ID}, 200)
54+ if len(st.Log) == 0 || st.Encounter == nil || st.Summary.Battles != 1 {
55+ t.Fatal("fight without log or encounter")
18656 }
187- sum := st.Summary
188- if sum.Kills == 0 || sum.Loot == 0 || sum.Steps < len(st.Campaign.Main.Steps)+len(st.Campaign.SideQuests) || sum.Battles == 0 {
189- t.Fatalf("bad summary %+v", sum)
57+ if st.Phase == "explore" && len(st.Party.Inventory) > 0 {
58+ it := st.Party.Inventory[0]
59+ st = c.call("POST", "/api/equip", model.EquipRequest{Unit: st.Party.Units[0].ID, Item: it.ID}, 200)
19060 }
191- t.Logf("seed %d winner %s summary %+v", st.Seed, st.Winner, sum)
192- c.call("POST", "/api/move", model.MoveRequest{X: 0, Y: 0}, 400)
61+ c.call("POST", "/api/sell", model.ItemRequest{Item: "nope"}, 400)
19362 }
19463
19564 func TestRejections(t *testing.T) {
@@ -213,10 +82,11 @@ func TestNewCampaign(t *testing.T) {
21382 defer ts.Close()
21483 c := client{t, ts}
21584 a := c.call("GET", "/api/state", nil, 200)
216- a = c.collectAll(a)
85+ sp := a.Map.Spawns[1]
86+ c.call("POST", "/api/move", model.MoveRequest{X: sp.X, Y: sp.Y}, 200)
21787 b := c.call("POST", "/api/new", nil, 200)
218- if b.Seed == a.Seed || b.Summary.Loot != 0 || b.Phase != "explore" {
219- t.Fatalf("not fresh: %d vs %d %+v", a.Seed, b.Seed, b.Summary)
88+ if b.Seed == a.Seed || b.Clock.Time != 0 || b.Phase != "explore" {
89+ t.Fatalf("not fresh: %d vs %d %+v", a.Seed, b.Seed, b.Clock)
22090 }
22191 d := c.call("POST", "/api/new", map[string]int{"seed": 99}, 200)
22292 if d.Seed != 99 {
internal/server/shop.go+15-45
@@ -19,24 +19,23 @@ type site struct {
1919 id, name string
2020 x, y int
2121 level int
22- trade bool
2322 }
2423
25-func (g *game) sites() []site {
24+func (g *game) shops() []site {
2625 var out []site
2726 for _, s := range g.state.Map.Spawns {
28- out = append(out, site{s.ID, s.Kind, s.X, s.Y, 1, true})
27+ out = append(out, site{s.ID, s.Kind, s.X, s.Y, 1})
2928 }
3029 for _, p := range g.state.Map.POIs {
31- if p.Cleared {
32- out = append(out, site{p.ID, p.Name, p.X, p.Y, p.Level, p.Kind == "camp" || p.Kind == "village"})
30+ if p.Cleared && (p.Kind == "camp" || p.Kind == "village") {
31+ out = append(out, site{p.ID, p.Name, p.X, p.Y, p.Level})
3332 }
3433 }
3534 return out
3635 }
3736
38-func (g *game) siteAt(x, y int) *site {
39- for _, s := range g.sites() {
37+func (g *game) shopAt(x, y int) *site {
38+ for _, s := range g.shops() {
4039 if s.x == x && s.y == y {
4140 return &s
4241 }
@@ -44,17 +43,6 @@ func (g *game) siteAt(x, y int) *site {
4443 return nil
4544 }
4645
47-func (g *game) camp(x, y int) (int, int) {
48- bx, by := g.spawn.X, g.spawn.Y
49- best := dist(bx, by, x, y)
50- for _, s := range g.sites() {
51- if d := dist(s.x, s.y, x, y); d < best {
52- bx, by, best = s.x, s.y, d
53- }
54- }
55- return bx, by
56-}
57-
5846 func (g *game) stockAt(s *site) []model.Item {
5947 if g.stock == nil {
6048 g.stock = map[string][]model.Item{}
@@ -73,24 +61,21 @@ func (g *game) stockAt(s *site) []model.Item {
7361 return items
7462 }
7563
76-func (g *game) campView() *model.Camp {
77- s := g.siteAt(g.state.Party.X, g.state.Party.Y)
64+func (g *game) shopView() *model.Shop {
65+ s := g.shopAt(g.state.Party.X, g.state.Party.Y)
7866 if s == nil {
7967 return nil
8068 }
81- if !s.trade {
82- return &model.Camp{ID: s.id, Name: s.name}
83- }

Cut short: this commit's diff is over 1000 lines.

internal/sim/combat.go+1-1

Cut short: this commit's diff is over 1000 lines.

internal/sim/xp.go+1-1

Cut short: this commit's diff is over 1000 lines.

internal/world/terrain.go+8-0

Cut short: this commit's diff is over 1000 lines.

scripts/bot.mjs+145-0

Cut short: this commit's diff is over 1000 lines.

scripts/driver.mjs+52-39

Cut short: this commit's diff is over 1000 lines.

scripts/playthrough.mjs+66-63

Cut short: this commit's diff is over 1000 lines.

scripts/verify.mjs+106-71

Cut short: this commit's diff is over 1000 lines.

web/fonts/Alegreya-OFL.txt+93-0

Cut short: this commit's diff is over 1000 lines.

web/fonts/Alegreya.woff2+0-0

Binary file, not shown.

web/fonts/MedievalSharp-OFL.txt+105-0

Cut short: this commit's diff is over 1000 lines.

web/fonts/MedievalSharp.woff2+0-0

Binary file, not shown.

web/js/board.js+57-7

Cut short: this commit's diff is over 1000 lines.

web/js/camp.js+0-69

Cut short: this commit's diff is over 1000 lines.

web/js/chrome.js+1-1

Cut short: this commit's diff is over 1000 lines.

web/js/debug.js+18-3

Cut short: this commit's diff is over 1000 lines.

web/js/frames.js+2-2

Cut short: this commit's diff is over 1000 lines.

web/js/gallery.js+1-2

Cut short: this commit's diff is over 1000 lines.

web/js/hud.js+50-21

Cut short: this commit's diff is over 1000 lines.

web/js/inventory.js+18-18

Cut short: this commit's diff is over 1000 lines.

web/js/journal.js+7-7

Cut short: this commit's diff is over 1000 lines.

web/js/layout.js+4-5

Cut short: this commit's diff is over 1000 lines.

web/js/main.js+38-27

Cut short: this commit's diff is over 1000 lines.

web/js/paint.js+0-2

Cut short: this commit's diff is over 1000 lines.

web/js/screens.js+20-20

Cut short: this commit's diff is over 1000 lines.

web/js/shop.js+57-0

Cut short: this commit's diff is over 1000 lines.

web/js/sky.js+128-0

Cut short: this commit's diff is over 1000 lines.

web/js/text.js+36-18

Cut short: this commit's diff is over 1000 lines.

web/js/threat.js+16-16

Cut short: this commit's diff is over 1000 lines.

web/js/ui.js+8-8

Cut short: this commit's diff is over 1000 lines.

web/js/world.js+16-34

Cut short: this commit's diff is over 1000 lines.