feat: quest book with quest lines, level rewards and a hint to the next click; opens by itself when a quest is done

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-29 10:15:36 +01:00
parent 9950f5423c
commit 87f2dc8bd3
11 changed files with 610 additions and 2 deletions

View File

@ -10,7 +10,7 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars.
- **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 14 px base, square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `app/components/icon/`, colours in `app/utils/palette.ts`. No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo, and nothing copied from Die Stämme.
- **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. Ambient life is welcome and stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns, villagers walking the roads to the zones they work in; all motion stops under `prefers-reduced-motion`. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals.
- **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. Keep components small and typed, with state in composables (`useVillage`, `useWorld`).
- **One game shell, like Die Stämme.** Everything sits in one centred column (1100 px). Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`: a quick bar with the village's screens, and one row with the village, its stock in thin cells and incoming troops), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one.
- **One game shell, like Die Stämme.** Everything sits in one centred column (1100 px). Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`: a quick bar with the village's screens, and one row with the village, its stock in thin cells and incoming troops), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `<dialog>` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=<type>` marking that row.
- All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string.
## Mock server

View File

@ -12,6 +12,10 @@ const nextAttack = computed(() => attacks.value[0] ?? null)
const support = computed(() => incoming.value.length - attacks.value.length)
const isActive = (path: string) => route.path === `${base.value}${path}`
const questBook = useQuestBookOpen()
/** Quests to claim plus level rewards to collect. */
const questsWaiting = computed(() => props.village.quests.claimable + props.village.quests.rewards)
/** The new name while the village is being renamed. */
const renaming = ref<string | null>(null)
async function rename() {
@ -42,6 +46,19 @@ async function rename() {
</nav>
<div class="flex flex-wrap items-stretch border border-wood-700 bg-parchment-200">
<!-- The quest book, with what waits in it. -->
<button
type="button"
class="flex items-center gap-1 border-r border-wood-700 px-2 py-1 font-semibold text-wood-900 hover:bg-parchment-100 hover:text-blood-700"
:class="questsWaiting ? 'bg-gold-400' : ''"
:title="$t('quests.open')"
@click="questBook = true"
>
<IconUi name="book" class="size-4" />
<span class="sr-only sm:not-sr-only">{{ $t('quests.open') }}</span>
<span v-if="questsWaiting" class="font-bold text-blood-700 tabular-nums">({{ questsWaiting }})</span>
</button>
<!-- Which village. -->
<div class="flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1">
<form v-if="renaming !== null" class="flex items-center gap-1" @submit.prevent="rename">

View File

@ -12,6 +12,25 @@ watch(v.village, (state) => {
if (state) enter(state.world_id, state.id)
})
// The quest book opens by itself when a quest is newly complete, like Die Stämme's.
// What the player has already seen is kept per world, so a reload doesn't reopen it.
const questBook = useQuestBookOpen()
watch(
() => v.village.value && { world: v.village.value.world_id, claimable: v.village.value.quests.claimable },
(now) => {
if (!now) return
const key = `vp.quests.${now.world}`
let seen = 0
try {
seen = Number(localStorage.getItem(key) ?? 0)
localStorage.setItem(key, String(now.claimable))
} catch {
return
}
if (now.claimable > seen) questBook.value = true
},
)
// One key per screen of the world, as the menu and quick bar titles show.
useShortcuts(() => {
const base = `/village/${props.villageId}`
@ -48,5 +67,6 @@ useShortcuts(() => {
</div>
</main>
<GameTabBar :village-id="villageId" />
<QuestBook v-if="v.village.value" />
</div>
</template>

View File

@ -17,6 +17,7 @@ export type UiIconName =
| 'eye'
| 'edit'
| 'home'
| 'book'
defineProps<{ name: UiIconName }>()
</script>
@ -78,6 +79,10 @@ defineProps<{ name: UiIconName }>()
<path d="M5 10v10h14V10M10 20v-6h4v6" />
</g>
<path v-else-if="name === 'edit'" d="M4 20l1-4L16 5l3 3L8 19zM14 7l3 3" />
<g v-else-if="name === 'book'">
<path d="M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2z" />
<path d="M4 21V5M8 7h7M8 11h5" />
</g>
<g v-else-if="name === 'eye'">
<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z" />
<circle cx="12" cy="12" r="3" />

View File

@ -0,0 +1,238 @@
<script setup lang="ts">
import type { BuildingType, Cost, Quest, QuestGoal, QuestLine, QuestScreen, Resources } from '~/types/game'
const open = useQuestBookOpen()
const v = useVillageContext()
const q = useQuests()
const { t, te } = useI18n()
const dialog = ref<HTMLDialogElement | null>(null)
const tab = ref<'quests' | 'rewards'>('quests')
const lineKey = ref<QuestLine['line'] | null>(null)
// The native dialog keeps focus inside and closes on Esc; the page behind stays as it is.
async function show() {
await q.load()
// Open on a line with something to claim, else on the one last looked at.
const ready = q.book.value?.lines.find((l) => l.quest?.complete)
if (ready) lineKey.value = ready.line
lineKey.value ??= q.book.value?.lines[0]?.line ?? null
if (open.value && dialog.value && !dialog.value.open) dialog.value.showModal()
}
watch(open, (isOpen) => (isOpen ? show() : dialog.value?.close()))
onMounted(() => {
if (open.value) show()
})
const lines = computed(() => q.book.value?.lines ?? [])
const line = computed(() => lines.value.find((l) => l.line === lineKey.value) ?? null)
const rewards = computed(() => q.book.value?.rewards ?? [])
const village = computed(() => v.village.value!)
const SCREEN_PATHS: Record<Exclude<QuestScreen, 'map' | 'reports'>, string> = {
overview: '',
recruit: '/recruit',
rally: '/rally',
workforce: '/workforce',
}
/** Where a goal's "go there" leads: a building's row on the headquarters screen, or a screen. */
function hintTo(goal: QuestGoal) {
const base = `/village/${village.value.id}`
if (goal.hint === 'map') return `/map/${village.value.world_id}`
if (goal.hint === 'reports') return `/reports/${village.value.world_id}`
if (goal.hint in SCREEN_PATHS) return `${base}${SCREEN_PATHS[goal.hint as keyof typeof SCREEN_PATHS]}`
return { path: `${base}/build`, query: { hint: goal.hint } }
}
function goalText(goal: QuestGoal) {
if (goal.kind === 'building') return t('quests.goal.building', { building: t(`buildings.${goal.subject}`), level: goal.need })
if (goal.kind === 'instances') return t('quests.goal.instances', { building: t(`buildings.${goal.subject}`), count: goal.need })
const key = `quests.counter.${goal.subject.replace('.', '_')}`
return te(key) ? t(key, { count: goal.need }) : goal.subject
}
const title = (key: string) => (te(`quests.q.${key}.title`) ? t(`quests.q.${key}.title`) : key)
const story = (key: string) => (te(`quests.q.${key}.text`) ? t(`quests.q.${key}.text`) : '')
/** The first goal still open, which is where "go there" points. */
const nextGoal = (quest: Quest) => quest.goals.find((g) => !g.met) ?? null
const asCost = (r: Partial<Resources>): Cost => ({ wood: r.wood ?? 0, clay: r.clay ?? 0, iron: r.iron ?? 0 })
/** True when the stock plus these resources would not fit the storage. */
function overflows(r: Partial<Resources>) {
const have = v.resources.value
if (!have) return false
return (['wood', 'clay', 'iron'] as const).some((k) => have[k] + (r[k] ?? 0) > village.value.storage_cap)
}
const rewardTotal = computed(() =>
rewards.value.reduce<Cost>((sum, r) => ({ wood: sum.wood + (r.reward.wood ?? 0), clay: sum.clay + (r.reward.clay ?? 0), iron: sum.iron + (r.reward.iron ?? 0) }), { wood: 0, clay: 0, iron: 0 }),
)
async function go(goal: QuestGoal) {
open.value = false
await navigateTo(hintTo(goal))
}
</script>
<!--
The quest book: quest lines on the left, the current quest of the chosen line on the
right, and a second tab with the level rewards. A plain framed dialog with no veil.
-->
<template>
<dialog
ref="dialog"
class="quest-book m-auto w-[min(46rem,calc(100vw-1rem))] border border-wood-900 bg-parchment-100 p-0 text-ink-900 shadow-[4px_4px_0_0_rgba(43,29,14,1)]"
:aria-label="$t('quests.title')"
@close="open = false"
>
<div class="panel-head">
<span class="panel-title">{{ $t('quests.title') }}</span>
<button type="button" class="btn btn-ghost px-1" :title="$t('quests.close')" @click="open = false">
<IconUi name="close" class="size-4" />
<span class="sr-only">{{ $t('quests.close') }}</span>
</button>
</div>
<div class="space-y-2 p-2.5">
<UiSubTabs
v-model="tab"
:tabs="[
{ key: 'quests', label: $t('quests.tab_quests'), count: village.quests.claimable },
{ key: 'rewards', label: $t('quests.tab_rewards'), count: rewards.length },
]"
/>
<p v-if="q.error.value" class="alert" role="alert">{{ q.error.value }}</p>
<div v-if="tab === 'quests'" class="grid gap-2 sm:grid-cols-[12rem_minmax(0,1fr)]">
<nav class="self-start border border-wood-700 bg-parchment-200 text-[13px]" :aria-label="$t('quests.lines_label')">
<button
v-for="l in lines"
:key="l.line"
type="button"
class="flex w-full items-center justify-between gap-2 border-b border-parchment-300 px-2 py-1 text-left font-semibold last:border-b-0"
:class="l.line === lineKey ? 'bg-wood-800 text-gold-400' : 'text-wood-950 hover:bg-parchment-100 hover:text-blood-700'"
:aria-current="l.line === lineKey ? 'true' : undefined"
@click="lineKey = l.line"
>
<span>{{ $t(`quests.line.${l.line}`) }}</span>
<span class="tabular-nums" :class="l.quest?.complete && l.line !== lineKey ? 'text-blood-700' : ''">
<template v-if="l.quest?.complete">!</template>
{{ l.done }}/{{ l.total }}
</span>
</button>
</nav>
<section v-if="line" class="panel">
<template v-if="line.quest">
<div class="panel-head">
<span class="font-bold text-wood-950">{{ title(line.quest.key) }}</span>
<span class="text-xs text-ink-500 tabular-nums">{{ $t('quests.step', { n: line.done + 1, total: line.total }) }}</span>
</div>
<div class="panel-body space-y-2.5 text-[13px]">
<p v-if="story(line.quest.key)" class="text-ink-700">{{ story(line.quest.key) }}</p>
<table class="grid-table">
<thead>
<tr>
<th>{{ $t('quests.goals') }}</th>
<th class="w-28">{{ $t('quests.progress') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(goal, i) in line.quest.goals" :key="i">
<td :class="goal.met ? 'text-moss-700' : ''">
<span v-if="goal.met" aria-hidden="true">✓ </span>{{ goalText(goal) }}
</td>
<td>
<div class="flex items-center gap-1.5">
<UiBar :value="goal.have / goal.need" :tone="goal.met ? 'emerald' : 'amber'" />
<span class="text-xs tabular-nums">{{ goal.have }}/{{ goal.need }}</span>
</div>
</td>
</tr>
</tbody>
</table>
<div class="flex flex-wrap items-center justify-between gap-2 border-t border-parchment-300 pt-2">
<span class="inline-flex items-center gap-2">
<span class="font-semibold text-ink-700">{{ $t('quests.reward') }}</span>
<UiCost :cost="asCost(line.quest.reward)" />
</span>
<button
v-if="line.quest.complete"
type="button"
class="btn btn-primary"
:disabled="q.busy.value"
@click="q.claim(line.quest.key)"
>
{{ $t('quests.claim') }}
</button>
<button v-else-if="nextGoal(line.quest)" type="button" class="btn btn-outline" @click="go(nextGoal(line.quest)!)">
{{ $t('quests.go') }}
</button>
</div>
<p v-if="line.quest.complete && overflows(line.quest.reward)" class="text-xs text-blood-700">{{ $t('quests.overflow') }}</p>
</div>
</template>
<p v-else class="panel-body text-[13px] text-ink-500">{{ $t('quests.line_done') }}</p>
</section>
</div>
<div v-else class="space-y-2 text-[13px]">
<p class="text-ink-700">{{ $t('quests.rewards_about', { share: Math.round((q.book.value?.share ?? 0) * 100) }) }}</p>
<section class="panel overflow-x-auto">
<table class="grid-table min-w-[28rem]">
<thead>
<tr>
<th>{{ $t('quests.building') }}</th>
<th>{{ $t('quests.reached_in') }}</th>
<th>{{ $t('quests.reward') }}</th>
<th class="text-right" />
</tr>
</thead>
<tbody>
<tr v-for="r in rewards" :key="r.id">
<td class="font-semibold">{{ $t('quests.level_of', { building: $t(`buildings.${r.type}`), level: r.level }) }}</td>
<td class="text-ink-500">{{ r.village.name }}</td>
<td><UiCost :cost="asCost(r.reward)" nowrap /></td>
<td class="text-right">
<button type="button" class="btn btn-outline" :disabled="q.busy.value" @click="q.collect([r.id])">{{ $t('quests.collect') }}</button>
</td>
</tr>
<tr v-if="!rewards.length">
<td colspan="4" class="text-ink-500">{{ $t('quests.no_rewards') }}</td>
</tr>
</tbody>
</table>
</section>
<div v-if="rewards.length" class="flex flex-wrap items-center justify-end gap-2">
<span v-if="overflows(rewardTotal)" class="text-xs text-blood-700">{{ $t('quests.overflow') }}</span>
<UiCost :cost="rewardTotal" nowrap />
<button type="button" class="btn btn-primary" :disabled="q.busy.value" @click="q.collect()">{{ $t('quests.collect_all') }}</button>
</div>
<section v-if="q.book.value?.upcoming.length" class="panel overflow-x-auto">
<div class="panel-head"><span class="font-semibold">{{ $t('quests.upcoming') }}</span></div>
<table class="grid-table min-w-[22rem]">
<tbody>
<tr v-for="u in q.book.value.upcoming" :key="u.type">
<td>{{ $t('quests.level_of', { building: $t(`buildings.${u.type as BuildingType}`), level: u.level }) }}</td>
<td class="text-right"><UiCost :cost="asCost(u.reward)" nowrap /></td>
</tr>
</tbody>
</table>
</section>
</div>
</div>
</dialog>
</template>
<style scoped>
/* No veil behind the book: the page stays visible and untouched. */
.quest-book::backdrop {
background: transparent;
}
</style>

View File

@ -0,0 +1,57 @@
import type { QuestBookState, QuestClaimed } from '~/types/game'
/** Whether the quest book is open; one book for the whole game shell. */
export const useQuestBookOpen = () => useState('quest-book-open', () => false)
/**
* The quest book of the village in the header. Claims answer with the fresh village,
* which goes straight into the shared village state so the stock updates at once.
*/
export function useQuests() {
const v = useVillageContext()
const book = ref<QuestBookState | null>(null)
const error = ref<string | null>(null)
const busy = ref(false)
const errorText = useErrorText()
const villageId = () => v.village.value?.id
async function load() {
const id = villageId()
if (!id) return
error.value = null
try {
book.value = await ws.send<QuestBookState>('quest.index', { village_id: id })
} catch (e) {
error.value = errorText(e)
}
}
async function run(event: string, data: object) {
const id = villageId()
if (!id) return false
busy.value = true
error.value = null
try {
const res = await ws.send<QuestClaimed>(event, { village_id: id, ...data })
book.value = res.book
v.village.value = res.village
return true
} catch (e) {
error.value = errorText(e)
return false
} finally {
busy.value = false
}
}
return {
book,
error,
busy,
load,
claim: (quest: string) => run('quest.claim', { quest }),
/** Collect the given level rewards, or all of them. */
collect: (ids?: number[]) => run('quest.collect', ids ? { ids } : {}),
}
}

View File

@ -6,6 +6,10 @@
import { onUnmounted, ref } from 'vue'
import type {
AuthResult,
QuestBookState,
QuestClaimed,
QuestGoal,
QuestLine,
AuthUser,
BattleReport,
BuildOption,
@ -145,6 +149,8 @@ interface MockState {
/** Missing in states stored before the rally point existed. */
movements?: MockMovement[]
reports?: MockReport[]
/** Claimed quests per `user:world`. */
quests?: Record<string, string[]>
}
const STORAGE_KEY = 'vp.mock.v4'
@ -553,6 +559,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
movements: movements(state, v, now),
support: support(state, v),
rally: rallyInfo(v),
quests: { claimable: questBook(state, v).lines.filter((l) => l.quest?.complete).length, rewards: 0 },
unread_reports: (state.reports ?? []).filter((r) => r.user_id === v.user_id && r.world_id === v.world_id && !r.read).length,
builders: BUILDERS,
buildings: v.buildings.map(
@ -967,6 +974,48 @@ function createVillage(state: MockState, user: AuthUser, worldId: number, now: n
// WS intents.
// A short copy of the quest lines with building goals only; the backend has the real book.
const MOCK_QUESTS: Record<QuestLine['line'], Record<string, { goals: [BuildingType, number][]; reward: Cost }>> = {
construction: {
hq_2: { goals: [['headquarters', 2]], reward: { wood: 120, clay: 120, iron: 100 } },
storage_farm_2: { goals: [['storage', 2], ['farm', 2]], reward: { wood: 150, clay: 150, iron: 150 } },
resource_camps: { goals: [['timber_camp', 1], ['clay_pit', 1], ['iron_mine', 1]], reward: { wood: 200, clay: 200, iron: 150 } },
},
army: {
barracks: { goals: [['barracks', 1]], reward: { wood: 250, clay: 220, iron: 120 } },
rally_point: { goals: [['rally_point', 1]], reward: { wood: 100, clay: 100, iron: 100 } },
},
village: {
hiding_place: { goals: [['hiding_place', 1]], reward: { wood: 120, clay: 120, iron: 120 } },
},
}
function questBook(state: MockState, v: MockVillage): QuestBookState {
const claimed = state.quests?.[`${v.user_id}:${v.world_id}`] ?? []
const levels = new Map<string, number>()
for (const own of state.villages.filter((o) => o.user_id === v.user_id && o.world_id === v.world_id)) {
for (const b of own.buildings) levels.set(b.type, Math.max(levels.get(b.type) ?? 0, b.level))
}
const lines = (Object.keys(MOCK_QUESTS) as QuestLine['line'][]).map((line): QuestLine => {
const quests = MOCK_QUESTS[line]
const key = Object.keys(quests).find((k) => !claimed.includes(k))
const goals = key
? quests[key]!.goals.map(([type, need]): QuestGoal => {
const have = levels.get(type) ?? 0
return { kind: 'building', subject: type, have: Math.min(have, need), need, met: have >= need, hint: type }
})
: []
return {
line,
done: Object.keys(quests).filter((k) => claimed.includes(k)).length,
total: Object.keys(quests).length,
quest: key ? { key, goals, reward: quests[key]!.reward, complete: goals.every((g) => g.met) } : null,
quests: Object.keys(quests).map((k) => ({ key: k, claimed: claimed.includes(k) })),
}
})
return { lines, rewards: [], upcoming: [], share: 0.2 }
}
type Handler = (state: MockState, user: AuthUser, data: any, now: number) => unknown
function ownVillage(state: MockState, user: AuthUser, id: unknown, now: number) {
@ -1219,6 +1268,24 @@ const handlers: Record<string, Handler> = {
return view(state, v, now)
},
'quest.index': (state, user, data, now): QuestBookState => questBook(state, ownVillage(state, user, data.village_id, now)),
'quest.claim': (state, user, data, now): QuestClaimed => {
const v = ownVillage(state, user, data.village_id, now)
const line = questBook(state, v).lines.find((l) => l.quest?.key === data.quest)
if (!line?.quest?.complete) fail('quest_open')
const key = `${v.user_id}:${v.world_id}`
state.quests = { ...state.quests, [key]: [...(state.quests?.[key] ?? []), line.quest.key] }
refund(v, line.quest.reward as Cost)
return { book: questBook(state, v), village: view(state, v, now) }
},
// The mock pays no level rewards.
'quest.collect': (state, user, data, now): QuestClaimed => {
const v = ownVillage(state, user, data.village_id, now)
return { book: questBook(state, v), village: view(state, v, now) }
},
'report.index': (state, user, data): ReportPage => reportPage(state, user, Number(data.world_id), Number(data.page) || 1, data.type || null),
// Opening a report marks it read.

View File

@ -103,6 +103,8 @@ export interface VillageState {
rally: RallyInfo
/** The player's unread reports on this world. */
unread_reports: number
/** Quest book badge: lines with a completed quest to claim, level rewards to collect. */
quests: { claimable: number; rewards: number }
builders: number
buildings: Building[]
queue: BuildOrder[]
@ -362,3 +364,60 @@ export interface GameError {
message: string
code?: string
}
/** A screen a quest goal points at that is not a building's row on the headquarters screen. */
export type QuestScreen = 'overview' | 'recruit' | 'rally' | 'workforce' | 'map' | 'reports'
export interface QuestGoal {
/** building: a type at a level in any village; instances: that many of a type in one village; counter: an action done that often. */
kind: 'building' | 'instances' | 'counter'
/** A building type, or a counter key such as `recruited.spear`. */
subject: string
have: number
need: number
met: boolean
/** Where to go: a building type (its headquarters row) or a screen. */
hint: BuildingType | QuestScreen
}
export interface Quest {
key: string
goals: QuestGoal[]
reward: Partial<Resources>
complete: boolean
}
export interface QuestLine {
line: 'construction' | 'army' | 'village'
done: number
total: number
/** The first unclaimed quest; null once the line is finished. */
quest: Quest | null
quests: { key: string; claimed: boolean }[]
}
/** A building level reached for the first time pays back part of its cost. */
export interface LevelReward {
id: number
type: BuildingType
level: number
reward: Partial<Resources>
/** Where it was reached; it is collected into the current village. */
village: { id: number; name: string | null }
}
/** `quest.index`. */
export interface QuestBookState {
lines: QuestLine[]
rewards: LevelReward[]
/** What the next level of each building type in this village would pay back. */
upcoming: { type: BuildingType; level: number; reward: Partial<Resources> }[]
/** Share of a level's cost paid back, 0..1. */
share: number
}
/** `quest.claim` and `quest.collect`. */
export interface QuestClaimed {
book: QuestBookState
village: VillageState
}

View File

@ -86,5 +86,6 @@ export default {
direction: 'Pick a start direction.',
name: 'A village name has 1 to 32 characters.',
world_full: 'This world is full.',
quest_open: 'This quest is not complete yet.',
},
}

View File

@ -3,12 +3,13 @@ import networking from '@blax-software/networking/i18n'
import en from './locales/en'
import auth from './pages/auth'
import map from './pages/map'
import quests from './pages/quests'
import reports from './pages/reports'
import village from './pages/village'
import worlds from './pages/worlds'
// Explicit imports instead of import.meta.glob: @nuxtjs/i18n also loads this file in the
// Nitro build, where glob imports don't exist. Add new page files here, in path order.
export default mergeMessages({ en }, [auth, map, reports, village, worlds], { packages: [networking] }) as {
export default mergeMessages({ en }, [auth, map, quests, reports, village, worlds], { packages: [networking] }) as {
en: Record<string, any>
}

143
i18n/pages/quests.ts Normal file
View File

@ -0,0 +1,143 @@
import type { TranslationFile } from '@blax-software/i18n'
export default {
en: {
quests: {
title: 'Quest book',
open: 'Quest book',
close: 'Close',
tab_quests: 'Quests',
tab_rewards: 'Rewards',
lines_label: 'Quest lines',
line: { construction: 'Construction', army: 'Army', village: 'Village life' },
step: 'Quest {n} of {total}',
goals: 'Goal',
progress: 'Progress',
reward: 'Reward',
claim: 'Complete quest',
go: 'Show me',
overflow: 'Your storage is too small: whatever does not fit is lost.',
line_done: 'You have finished every quest in this line.',
goal: {
building: '{building} at level {level}',
instances: '{count} × {building} in one village',
},
counter: {
recruited_spear: 'Train {count} spearmen',
attacks_barbarian: 'Attack a barbarian village',
scouts_sent: 'Send scouts to a village',
village_renamed: 'Give your village a name',
priority_set: 'Change the priority of a building',
map_viewed: 'Look at the world map',
reports_read: 'Read a report',
levy_called: 'Call up the levy',
},
rewards_about: 'Every building level you reach for the first time pays back {share}% of what it cost. Collect it into the village you are in.',
building: 'Building',
reached_in: 'Reached in',
level_of: '{building} level {level}',
collect: 'Collect',
collect_all: 'Collect all',
no_rewards: 'Nothing to collect. Finish a building level you have not had before.',
upcoming: 'Next rewards in this village',
q: {
hq_2: {
title: 'A roof over the council',
text: 'The headquarters is a tent for now. Raise it to level 2: your builders work faster and the village gains building space.',
},
storage_farm_2: {
title: 'Stores and fields',
text: 'Everything you make waits in the storage, and the farm feeds the people who make it. Bring both to level 2.',
},
resource_camps: {
title: 'Wood, clay and iron',
text: 'The village only trickles resources on its own. Build a timber camp, a clay pit and an iron mine.',
},
camps_3: {
title: 'Keep the carts rolling',
text: 'More production means faster growth. Raise all three resource sites to level 3.',
},
hq_3: {
title: 'Room to grow',
text: 'Every headquarters level adds building space. Reach level 3 before the village runs out of room.',
},
storage_farm_5: {
title: 'Granaries and barns',
text: 'Bigger buildings cost more than a small storage holds, and soldiers eat. Bring storage and farm to level 5.',
},
hq_5: {
title: 'A proper hall',
text: 'A headquarters at level 5 opens the advanced buildings and gives your builders a real workshop.',
},
camps_8: {
title: 'A busy valley',
text: 'Timber camp and clay pit at level 8, the iron mine at 6: enough to feed a growing army and a growing village.',
},
barracks: {
title: 'Men at arms',
text: 'A village without soldiers is a gift to its neighbours. Build a barracks.',
},
first_spears: {
title: 'Spears for the gate',
text: 'Spearmen are cheap and hold well against horsemen. Train five of them; each one leaves his work for good.',
},
rally_point: {
title: 'A place to gather',
text: 'Troops leave from the rally point. Build one before you send anyone anywhere.',
},
first_raid: {
title: 'Loot from the woods',
text: 'Barbarian villages around you keep resources and few defenders. Send an attack to one of them.',
},
wall_3: {
title: 'Stakes and timber',
text: 'A wall multiplies every defender. Raise it to level 3.',
},
barracks_3: {
title: 'Drill yard',
text: 'A bigger barracks trains faster and opens the archers. Bring it to level 3.',
},
stable: {
title: 'Horses',
text: 'Cavalry is fast and carries more loot. Build a stable.',
},
first_scouts: {
title: 'Eyes on the road',
text: 'Scouts tell you what waits behind a wall before you attack it. Send some to a village.',
},
rename: {
title: 'A name of your own',
text: 'Your village deserves a better name than the one it got. Rename it with the pencil next to its name.',
},
priority: {
title: 'Who works where',
text: 'Villagers staff buildings by priority, and an understaffed building makes far less. Change a building\'s priority on the workforce screen.',
},
look_around: {
title: 'Know your neighbours',
text: 'Open the world map and see who lives around you.',
},
hiding_place: {
title: 'Something put aside',
text: 'Raiders don\'t find what lies in the hiding place. Build one.',
},
second_camp: {
title: 'Two of a kind',
text: 'Here a village can have more than one of a building. Build a second timber camp and see your wood climb.',
},
read_report: {
title: 'News from the field',
text: 'Every battle and every arriving support leaves a report. Read one.',
},
levy: {
title: 'Call the levy',
text: 'When an attack comes, villagers can take up arms as militia. They stop working while they guard the village. Call up the levy once.',
},
second_farm: {
title: 'More mouths, more fields',
text: 'A big army needs food. Build a second farm and decide what this village is for.',
},
},
},
},
} satisfies TranslationFile