feat: conquest in the client: coins at the academy, a village switcher, loyalty in the header and in battle reports
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
72c79240f9
commit
eeaa0f8d6f
|
|
@ -12,6 +12,18 @@ const nextAttack = computed(() => attacks.value[0] ?? null)
|
||||||
const support = computed(() => incoming.value.length - attacks.value.length)
|
const support = computed(() => incoming.value.length - attacks.value.length)
|
||||||
const isActive = (path: string) => route.path === `${base.value}${path}`
|
const isActive = (path: string) => route.path === `${base.value}${path}`
|
||||||
|
|
||||||
|
/** Another of the player's villages, on the same screen where the URL has one. */
|
||||||
|
const others = computed(() => props.village.villages)
|
||||||
|
const position = computed(() => others.value.findIndex((o) => o.id === props.village.id))
|
||||||
|
function switchTo(id: number) {
|
||||||
|
const path = route.path.startsWith(base.value) ? route.path.replace(base.value, `/village/${id}`) : `/village/${id}`
|
||||||
|
navigateTo(path)
|
||||||
|
}
|
||||||
|
function step(by: number) {
|
||||||
|
const list = others.value
|
||||||
|
switchTo(list[(position.value + by + list.length) % list.length]!.id)
|
||||||
|
}
|
||||||
|
|
||||||
const questBook = useQuestBookOpen()
|
const questBook = useQuestBookOpen()
|
||||||
/** Quests to claim plus level rewards to collect. */
|
/** Quests to claim plus level rewards to collect. */
|
||||||
const questsWaiting = computed(() => props.village.quests.claimable + props.village.quests.rewards)
|
const questsWaiting = computed(() => props.village.quests.claimable + props.village.quests.rewards)
|
||||||
|
|
@ -24,7 +36,7 @@ async function rename() {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Above the content, like the header of Die Stämme: the quick bar with the village's
|
Above the content, like the header of Die Stämme: the quick bar with the village's
|
||||||
screens, then one row with the village and its stock. Plain numbers in thin cells;
|
screens, then one row with the village and its stock. Plain numbers in thin cells;
|
||||||
each resource leads to the workforce, where it is made.
|
each resource leads to the workforce, where it is made.
|
||||||
-->
|
-->
|
||||||
|
|
@ -67,7 +79,19 @@ async function rename() {
|
||||||
<button type="button" class="btn btn-ghost" @click="renaming = null">{{ $t('village.rename_cancel') }}</button>
|
<button type="button" class="btn btn-ghost" @click="renaming = null">{{ $t('village.rename_cancel') }}</button>
|
||||||
</form>
|
</form>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NuxtLink :to="base" class="truncate font-bold text-wood-950 hover:text-blood-700">{{ village.name }}</NuxtLink>
|
<span v-if="others.length > 1" class="inline-flex shrink-0 items-center">
|
||||||
|
<button type="button" class="btn btn-ghost px-1" :title="$t('village.switcher.prev')" @click="step(-1)">‹<span class="sr-only">{{ $t('village.switcher.prev') }}</span></button>
|
||||||
|
<select
|
||||||
|
class="input w-auto max-w-48 py-0 font-bold"
|
||||||
|
:value="village.id"
|
||||||
|
:aria-label="$t('village.switcher.label')"
|
||||||
|
@change="switchTo(Number(($event.target as HTMLSelectElement).value))"
|
||||||
|
>
|
||||||
|
<option v-for="o in others" :key="o.id" :value="o.id">{{ o.name }}</option>
|
||||||
|
</select>
|
||||||
|
<button type="button" class="btn btn-ghost px-1" :title="$t('village.switcher.next')" @click="step(1)">›<span class="sr-only">{{ $t('village.switcher.next') }}</span></button>
|
||||||
|
</span>
|
||||||
|
<NuxtLink v-else :to="base" class="truncate font-bold text-wood-950 hover:text-blood-700">{{ village.name }}</NuxtLink>
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
:to="{ path: `/map/${village.world_id}`, query: { x: village.x, y: village.y } }"
|
:to="{ path: `/map/${village.world_id}`, query: { x: village.x, y: village.y } }"
|
||||||
class="shrink-0 font-bold text-wood-950 tabular-nums hover:text-blood-700"
|
class="shrink-0 font-bold text-wood-950 tabular-nums hover:text-blood-700"
|
||||||
|
|
@ -88,6 +112,9 @@ async function rename() {
|
||||||
<NuxtLink v-for="r in (['wood', 'clay', 'iron', 'food'] as const)" :key="r" :to="`${base}/workforce`" class="cell flex hover:bg-parchment-100">
|
<NuxtLink v-for="r in (['wood', 'clay', 'iron', 'food'] as const)" :key="r" :to="`${base}/workforce`" class="cell flex hover:bg-parchment-100">
|
||||||
<GameResource :resource="r" :amount="resources[r]" :cap="village.storage_cap" :rate="village.rates[r]" />
|
<GameResource :resource="r" :amount="resources[r]" :cap="village.storage_cap" :rate="village.rates[r]" />
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
<span v-if="village.loyalty < 100" class="cell flex font-semibold text-blood-700" :title="`${$t('village.loyalty')}: ${$t('village.loyalty_about')}`">
|
||||||
|
{{ $t('village.loyalty') }} <span class="tabular-nums">{{ village.loyalty }}</span>
|
||||||
|
</span>
|
||||||
<span class="cell hidden lg:flex" :title="$t('village.resources.cap')">
|
<span class="cell hidden lg:flex" :title="$t('village.resources.cap')">
|
||||||
<IconBuilding type="storage" class="size-4 text-wood-800" />
|
<IconBuilding type="storage" class="size-4 text-wood-800" />
|
||||||
<span class="tabular-nums">{{ village.storage_cap }}</span>
|
<span class="tabular-nums">{{ village.storage_cap }}</span>
|
||||||
|
|
@ -95,7 +122,7 @@ async function rename() {
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
:to="`${base}/workforce`"
|
:to="`${base}/workforce`"
|
||||||
class="cell flex hover:bg-parchment-100"
|
class="cell flex hover:bg-parchment-100"
|
||||||
:title="`${$t('village.population.villagers')}: ${village.population.villagers} · ${$t('village.population.upkeep')}: ${village.population.upkeep}/${village.population.food_budget}`"
|
:title="`${$t('village.population.villagers')}: ${village.population.villagers} · ${$t('village.population.upkeep')}: ${village.population.upkeep}/${village.population.food_budget}`"
|
||||||
>
|
>
|
||||||
<IconUi name="users" class="size-4 text-wood-800" />
|
<IconUi name="users" class="size-4 text-wood-800" />
|
||||||
<span class="tabular-nums">{{ village.population.villagers }}</span>
|
<span class="tabular-nums">{{ village.population.villagers }}</span>
|
||||||
|
|
|
||||||
|
|
@ -106,5 +106,10 @@ const luckAt = computed(() => Math.max(0, Math.min(100, ((props.report.luck + 25
|
||||||
</span>
|
</span>
|
||||||
<span class="text-ink-500 tabular-nums">{{ $t('reports.battle.haul_of', { loot: looted, capacity: report.capacity }) }}</span>
|
<span class="text-ink-500 tabular-nums">{{ $t('reports.battle.haul_of', { loot: looted, capacity: report.capacity }) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p v-if="report.loyalty" class="font-semibold" :class="report.loyalty.conquered ? 'text-blood-700' : 'text-ink-700'">
|
||||||
|
{{ $t('reports.battle.loyalty', { before: report.loyalty.before, after: report.loyalty.after }) }}
|
||||||
|
<template v-if="report.loyalty.conquered">{{ $t('reports.battle.conquered') }}</template>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { Conquest, Resources } from '~/types/game'
|
||||||
|
|
||||||
|
const props = defineProps<{ conquest: Conquest; resources: Resources; busy: boolean }>()
|
||||||
|
const emit = defineEmits<{ mint: [count: number] }>()
|
||||||
|
|
||||||
|
const count = ref(1)
|
||||||
|
/** How many coins the stock pays for now. */
|
||||||
|
const affordable = computed(() =>
|
||||||
|
Math.floor(Math.min(...(['wood', 'clay', 'iron'] as const).map((r) => (props.conquest.coin_cost[r] ? props.resources[r] / props.conquest.coin_cost[r] : Infinity)))),
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Minting coins at the academy: coins pay for noble slots, the n-th slot n more coins. -->
|
||||||
|
<template>
|
||||||
|
<section class="panel">
|
||||||
|
<div class="panel-head">
|
||||||
|
<span class="panel-title">{{ $t('village.conquest.title') }}</span>
|
||||||
|
<span class="badge badge-plain tabular-nums">{{ $t('village.conquest.slots', { used: conquest.used, slots: conquest.slots }) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body space-y-2 text-[13px]">
|
||||||
|
<p class="text-ink-700">{{ $t('village.conquest.about') }}</p>
|
||||||
|
<table class="grid-table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="whitespace-nowrap">{{ $t('village.conquest.coins') }}</td>
|
||||||
|
<td class="text-right font-semibold tabular-nums">{{ conquest.coins }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="whitespace-nowrap">{{ $t('village.conquest.next_slot') }}</td>
|
||||||
|
<td class="text-right tabular-nums">{{ $t('village.conquest.coins_more', { count: conquest.next_slot_coins }) }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p class="flex flex-wrap items-center justify-between gap-x-2 gap-y-1">
|
||||||
|
<span>{{ $t('village.conquest.coin_cost') }}</span>
|
||||||
|
<UiCost :cost="conquest.coin_cost" :have="resources" />
|
||||||
|
</p>
|
||||||
|
<form class="flex items-center justify-end gap-1.5" @submit.prevent="emit('mint', count)">
|
||||||
|
<input v-model.number="count" type="number" min="1" :max="Math.max(1, affordable)" class="input w-16 text-right" :aria-label="$t('village.conquest.count')" />
|
||||||
|
<span class="text-xs text-ink-500 tabular-nums">({{ affordable }})</span>
|
||||||
|
<button type="submit" class="btn btn-primary" :disabled="busy || count < 1 || count > affordable">{{ $t('village.conquest.mint') }}</button>
|
||||||
|
</form>
|
||||||
|
<p v-if="conquest.max_distance" class="text-xs text-ink-500">{{ $t('village.conquest.range', { fields: conquest.max_distance }) }}</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
@ -126,6 +126,7 @@ export function useVillage(villageId: number) {
|
||||||
sendHome: (homeVillageId: number) => run('rally.sendHome', { home_village_id: homeVillageId }),
|
sendHome: (homeVillageId: number) => run('rally.sendHome', { home_village_id: homeVillageId }),
|
||||||
withdraw: (hostVillageId: number) => run('rally.withdraw', { host_village_id: hostVillageId }),
|
withdraw: (hostVillageId: number) => run('rally.withdraw', { host_village_id: hostVillageId }),
|
||||||
rename: (name: string) => run('village.rename', { name }),
|
rename: (name: string) => run('village.rename', { name }),
|
||||||
|
mint: (count: number) => run('village.mint', { count }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -559,6 +559,11 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
|
||||||
movements: movements(state, v, now),
|
movements: movements(state, v, now),
|
||||||
support: support(state, v),
|
support: support(state, v),
|
||||||
rally: rallyInfo(v),
|
rally: rallyInfo(v),
|
||||||
|
loyalty: 100,
|
||||||
|
conquest: { coins: 0, slots: 0, used: 0, next_slot_coins: 1, coin_cost: { wood: 28000, clay: 30000, iron: 25000 }, max_distance: 100 },
|
||||||
|
villages: state.villages
|
||||||
|
.filter((o) => o.user_id === v.user_id && o.world_id === v.world_id)
|
||||||
|
.map((o) => ({ id: o.id, name: o.name, x: o.x, y: o.y, points: points(o) })),
|
||||||
quests: { claimable: questBook(state, v).lines.filter((l) => l.quest?.complete).length, rewards: 0 },
|
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,
|
unread_reports: (state.reports ?? []).filter((r) => r.user_id === v.user_id && r.world_id === v.world_id && !r.read).length,
|
||||||
builders: BUILDERS,
|
builders: BUILDERS,
|
||||||
|
|
@ -1268,6 +1273,15 @@ const handlers: Record<string, Handler> = {
|
||||||
return view(state, v, now)
|
return view(state, v, now)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The mock takes the payment but keeps no coins; the backend has the real slots.
|
||||||
|
'village.mint': (state, user, data, now) => {
|
||||||
|
const v = ownVillage(state, user, data.village_id, now)
|
||||||
|
if (!v.buildings.some((b) => b.type === 'academy')) fail('requires')
|
||||||
|
const n = Math.max(1, Number(data.count) || 1)
|
||||||
|
pay(v, { wood: 28000 * n, clay: 30000 * n, iron: 25000 * n })
|
||||||
|
return view(state, v, now)
|
||||||
|
},
|
||||||
|
|
||||||
'quest.index': (state, user, data, now): QuestBookState => questBook(state, ownVillage(state, user, data.village_id, now)),
|
'quest.index': (state, user, data, now): QuestBookState => questBook(state, ownVillage(state, user, data.village_id, now)),
|
||||||
|
|
||||||
'quest.claim': (state, user, data, now): QuestClaimed => {
|
'quest.claim': (state, user, data, now): QuestClaimed => {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ const shown = computed(() => village.value.military.find((m) => m.building_id ==
|
||||||
<section v-else class="panel">
|
<section v-else class="panel">
|
||||||
<div class="panel-body py-8 text-center text-sm text-ink-500">{{ $t('village.troops.hint') }}</div>
|
<div class="panel-body py-8 text-center text-sm text-ink-500">{{ $t('village.troops.hint') }}</div>
|
||||||
</section>
|
</section>
|
||||||
|
<div class="space-y-3">
|
||||||
|
<VillageCoinPanel v-if="shown?.type === 'academy'" :conquest="village.conquest" :resources="resources" :busy="v.busy.value" @mint="v.mint" />
|
||||||
<VillageTroopsPanel
|
<VillageTroopsPanel
|
||||||
:troops="village.troops"
|
:troops="village.troops"
|
||||||
:training="village.population.training"
|
:training="village.population.training"
|
||||||
|
|
@ -50,4 +52,5 @@ const shown = computed(() => village.value.military.find((m) => m.building_id ==
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,11 @@ export interface VillageState {
|
||||||
rally: RallyInfo
|
rally: RallyInfo
|
||||||
/** The player's unread reports on this world. */
|
/** The player's unread reports on this world. */
|
||||||
unread_reports: number
|
unread_reports: number
|
||||||
|
/** 0..100; noblemen lower it, at 0 the village changes hands. */
|
||||||
|
loyalty: number
|
||||||
|
conquest: Conquest
|
||||||
|
/** The player's villages in this world, by id: the switcher. */
|
||||||
|
villages: { id: number; name: string; x: number; y: number; points: number }[]
|
||||||
/** Quest book badge: lines with a completed quest to claim, level rewards to collect. */
|
/** Quest book badge: lines with a completed quest to claim, level rewards to collect. */
|
||||||
quests: { claimable: number; rewards: number }
|
quests: { claimable: number; rewards: number }
|
||||||
builders: number
|
builders: number
|
||||||
|
|
@ -194,6 +199,8 @@ export interface BattleReport {
|
||||||
building: { type: BuildingType; before: number; after: number } | null
|
building: { type: BuildingType; before: number; after: number } | null
|
||||||
loot: Cost
|
loot: Cost
|
||||||
capacity: number
|
capacity: number
|
||||||
|
/** Noblemen survived a won attack: loyalty before and after, and whether the village changed hands. */
|
||||||
|
loyalty?: { before: number; after: number; conquered: boolean } | null
|
||||||
/** Only when scouts went along. Resources and buildings only when some got through. */
|
/** Only when scouts went along. Resources and buildings only when some got through. */
|
||||||
scouting?: {
|
scouting?: {
|
||||||
sent: number
|
sent: number
|
||||||
|
|
@ -421,3 +428,15 @@ export interface QuestClaimed {
|
||||||
book: QuestBookState
|
book: QuestBookState
|
||||||
village: VillageState
|
village: VillageState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Coins and noble slots of the player. Every nobleman alive and every village beyond the first takes a slot. */
|
||||||
|
export interface Conquest {
|
||||||
|
coins: number
|
||||||
|
slots: number
|
||||||
|
used: number
|
||||||
|
/** Coins still missing for the next slot. */
|
||||||
|
next_slot_coins: number
|
||||||
|
coin_cost: Cost
|
||||||
|
/** Fields a nobleman marches at most; 0 for no limit. */
|
||||||
|
max_distance: number
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,5 +87,7 @@ export default {
|
||||||
name: 'A village name has 1 to 32 characters.',
|
name: 'A village name has 1 to 32 characters.',
|
||||||
world_full: 'This world is full.',
|
world_full: 'This world is full.',
|
||||||
quest_open: 'This quest is not complete yet.',
|
quest_open: 'This quest is not complete yet.',
|
||||||
|
coins: 'Mint more coins at the academy for another nobleman.',
|
||||||
|
too_far: 'Noblemen don\'t march that far.',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ export default {
|
||||||
scouted_resources: 'Resources',
|
scouted_resources: 'Resources',
|
||||||
scouted_buildings: 'Buildings',
|
scouted_buildings: 'Buildings',
|
||||||
haul_of: '{loot} of {capacity}',
|
haul_of: '{loot} of {capacity}',
|
||||||
|
loyalty: 'Loyalty dropped from {before} to {after}.',
|
||||||
|
conquered: 'The village has been conquered.',
|
||||||
},
|
},
|
||||||
support: {
|
support: {
|
||||||
arrived: 'The support has arrived and now defends {to}.',
|
arrived: 'The support has arrived and now defends {to}.',
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,21 @@ export default {
|
||||||
max_title: 'The most you can recruit now',
|
max_title: 'The most you can recruit now',
|
||||||
submit: 'Recruit',
|
submit: 'Recruit',
|
||||||
},
|
},
|
||||||
|
conquest: {
|
||||||
|
title: 'Coins',
|
||||||
|
about: 'Noblemen need noble slots. Coins minted here pay for them: the first slot takes 1 coin, the second 2 more, the third 3 more. Every nobleman and every village beyond your first takes a slot.',
|
||||||
|
slots: '{used}/{slots} noble slots',
|
||||||
|
coins: 'Coins minted',
|
||||||
|
next_slot: 'Next slot',
|
||||||
|
coins_more: '{count} more coins',
|
||||||
|
coin_cost: 'One coin costs',
|
||||||
|
count: 'Coins to mint',
|
||||||
|
mint: 'Mint',
|
||||||
|
range: 'Noblemen march at most {fields} fields.',
|
||||||
|
},
|
||||||
|
switcher: { label: 'Your villages', prev: 'Previous village', next: 'Next village' },
|
||||||
|
loyalty: 'Loyalty',
|
||||||
|
loyalty_about: 'Noblemen lower it; at 0 the village changes hands. It grows back by itself.',
|
||||||
troops: {
|
troops: {
|
||||||
title: 'Troops',
|
title: 'Troops',
|
||||||
training: '{count} in training',
|
training: '{count} in training',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue