tiny-adventure / commits / ff5e52a
Tune difficulty, show gear in stats, fix end and new game screens, add README
Co-Authored-By: Claude Sonnet 5.5
@@ -1 +1,48 @@
11 # Tiny Adventure
2+
3+A procedurally generated, tiny Dungeons and Dragons style campaign in the browser. A Go server generates the world from a seed. A Three.js client renders it. Combat plays out automatically from unit stats, abilities and gear.
4+
5+## Run
6+
7+```
8+go run ./cmd/server
9+```
10+
11+Open http://localhost:8080. Flags:
12+
13+- `--seed N` fixes the campaign seed. Without it, a random seed is picked at boot.
14+- `--addr :8080` sets the listen address.
15+- `--web web` sets the static files directory.
16+
17+The New Game button on the end screen asks the server for a fresh random seed.
18+
19+## Assets
20+
21+Generated textures and icons are committed in `web/assets`. To regenerate them, put `OPENROUTER_API_KEY=...` in `.env` (never committed) and run:
22+
23+```
24+scripts/gen-assets.sh
25+```
26+
27+## How a campaign is built
28+
29+The seed decides every system and its details:
30+
31+- Enabled systems: factions, hazards, key items, side quests, and which POI kinds exist (village, ruins, mine, tower, beach, camp, crypt).
32+- Factions: names, themes and power, which set the enemy types and strength.
33+- Main mission: a template of typed steps (reach, defeat, retrieve, boss) whose slots (POI kind, faction, item) are filled from the seed. Swapping a mine and vampires for a beach and lizardfolk only changes slot values.
34+- Side quests: a few smaller missions that reuse the same step types.
35+- Spawn: the party starts at structures whose hints point to the first main step.
36+- Party: classes, stats, abilities and starting gear are rolled per seed.
37+- 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.
38+
39+Beating the boss ends the campaign with a stats screen.
40+
41+## Check
42+
43+```
44+go vet ./...
45+go test ./...
46+```
47+
48+API reference: `docs/api.md`.
@@ -16,11 +16,11 @@ func bossName(r *rand.Rand, f model.Faction) string {
1616 }
1717
1818 func enemy(r *rand.Rand, id, name string, f model.Faction, level int, mult float64) model.Unit {
19- hp := int(float64(18+level*8+r.Intn(5)) * mult)
19+ hp := int(float64(14+level*6+r.Intn(5)) * mult)
2020 return model.Unit{
2121 ID: id, Name: name, Class: "monster", Faction: f.ID, Level: level,
2222 Stats: model.Stats{
23- HP: hp, MaxHP: hp, Attack: int(float64(3+level*2) * mult), Defense: 1 + level/2,
23+ HP: hp, MaxHP: hp, Attack: int(float64(3+level*3/2) * mult), Defense: 1 + level/2,
2424 Magic: level, Speed: between(r, 3, 7), Crit: 5,
2525 },
2626 Abilities: []model.Ability{{ID: "strike", Name: "Strike", Kind: "damage", Power: 1.0, Cooldown: 0, Target: "enemy"}},
@@ -32,7 +32,7 @@ func buildEncounter(r *rand.Rand, poi model.POI, f model.Faction, level int, bos
3232 e := model.Encounter{ID: "enc-" + poi.ID, POI: poi.ID}
3333 if boss != "" {
3434 e.Boss = true
35- e.Enemies = append(e.Enemies, enemy(r, e.ID+"-boss", boss, f, level+1, 2.5))
35+ e.Enemies = append(e.Enemies, enemy(r, e.ID+"-boss", boss, f, level+1, 1.7))
3636 }
3737 count := between(r, 2, 2+min(2, level/3))
3838 for i := 0; i < count; i++ {
@@ -91,5 +91,5 @@ func uniqueName(r *rand.Rand, pois []model.POI, kind string) string {
9191 }
9292
9393 func levelAt(origin model.SpawnPoint, maxDist, x, y int) int {
94- return 1 + (abs(x-origin.X)+abs(y-origin.Y))*9/max(1, maxDist)
94+ return 1 + (abs(x-origin.X)+abs(y-origin.Y))*6/max(1, maxDist)
9595 }
@@ -157,6 +157,7 @@ async function collectHere() {
157157 async function restart() {
158158 const s = await api.newGame();
159159 load(s);
160+ ui.show(false);
160161 showTitle(s, { onStart: begin, onNew: restart });
161162 }
162163
@@ -188,6 +189,7 @@ async function boot() {
188189 tex = await loadTextures();
189190 load(await api.getState());
190191 frame();
192+ if (state.winner || state.phase === 'victory') return showEnd(state, restart);
191193 showTitle(state, { onStart: begin, onNew: restart });
192194 }
193195
@@ -9,6 +9,7 @@ const STATS = ['maxHp', 'attack', 'defense', 'magic', 'speed', 'crit'];
99
1010 const icon = (sheet, i) => `<i class="icon" style="background-image:url(/assets/${sheet}.png);background-position:${(i % 4) * 33.33}% ${Math.floor(i / 4) * 33.33}%"></i>`;
1111 const itemIcon = (it) => icon('icons_items', it.key ? 12 : SLOT_ICON[it.slot] ?? 14);
12+const total = (u, k) => u.stats[k] + Object.values(u.gear || {}).reduce((n, it) => n + (it.bonus?.[k] || 0), 0);
1213 const bonusText = (b) => Object.entries(b || {}).filter(([, v]) => v).map(([k, v]) => `${v > 0 ? '+' : ''}${v} ${k}`).join(', ');
1314 const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
1415
@@ -65,7 +66,7 @@ export function createUI(h) {
6566 const it = u.gear?.[s];
6667 return `<div class="slot ${it ? 'filled' : ''}" data-slot="${s}" title="${it ? esc(it.name) + ' ' + bonusText(it.bonus) + ' (click to unequip)' : s}">${it ? itemIcon(it) : icon('icons_items', SLOT_ICON[s]).replace('class="icon"', 'class="icon ghost"')}<span style="color:${it ? rarityColor(it.rarity) : '#8a7a5a'}">${it ? esc(it.name) : s}</span></div>`;
6768 }).join('')}</div>
68- <div class="stats">${STATS.map((k) => `<span>${k}<b>${u.stats[k]}</b></span>`).join('')}</div>
69+ <div class="stats">${STATS.map((k) => `<span>${k}<b>${total(u, k)}</b></span>`).join('')}</div>
6970 <div class="hero">Pack (${state.party.inventory.length})</div>
7071 <div class="grid">${state.party.inventory.map((it) => `<div class="cell" data-item="${it.id}" title="${esc(it.name)} [${it.rarity}] ${bonusText(it.bonus)}">${itemIcon(it)}<span style="color:${rarityColor(it.rarity)}">${esc(it.name)}</span></div>`).join('') || '<p class="empty">Nothing yet. Explore for loot.</p>'}</div>`;
7172 $('inv-body').querySelectorAll('[data-u]').forEach((b) => (b.onclick = () => { selected = b.dataset.u; renderParty(state); renderPanels(); }));