diff --git a/app/components/game/VillageBar.vue b/app/components/game/VillageBar.vue index 4b87d52..e6e8bc5 100644 --- a/app/components/game/VillageBar.vue +++ b/app/components/game/VillageBar.vue @@ -12,6 +12,18 @@ 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}` +/** 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() /** Quests to claim plus level rewards to collect. */ const questsWaiting = computed(() => props.village.quests.claimable + props.village.quests.rewards) @@ -24,7 +36,7 @@ async function rename() { @@ -67,7 +79,19 @@ async function rename() { diff --git a/app/components/village/CoinPanel.vue b/app/components/village/CoinPanel.vue new file mode 100644 index 0000000..48afe83 --- /dev/null +++ b/app/components/village/CoinPanel.vue @@ -0,0 +1,47 @@ + + + + diff --git a/app/composables/useVillage.ts b/app/composables/useVillage.ts index 83198d7..38a1088 100644 --- a/app/composables/useVillage.ts +++ b/app/composables/useVillage.ts @@ -126,6 +126,7 @@ export function useVillage(villageId: number) { sendHome: (homeVillageId: number) => run('rally.sendHome', { home_village_id: homeVillageId }), withdraw: (hostVillageId: number) => run('rally.withdraw', { host_village_id: hostVillageId }), rename: (name: string) => run('village.rename', { name }), + mint: (count: number) => run('village.mint', { count }), } } diff --git a/app/mock/server.ts b/app/mock/server.ts index 16e8270..3be6c9e 100644 --- a/app/mock/server.ts +++ b/app/mock/server.ts @@ -559,6 +559,11 @@ function view(state: MockState, v: MockVillage, now: number): VillageState { movements: movements(state, v, now), support: support(state, 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 }, unread_reports: (state.reports ?? []).filter((r) => r.user_id === v.user_id && r.world_id === v.world_id && !r.read).length, builders: BUILDERS, @@ -1268,6 +1273,15 @@ const handlers: Record = { 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.claim': (state, user, data, now): QuestClaimed => { diff --git a/app/pages/village/[id]/recruit.vue b/app/pages/village/[id]/recruit.vue index 141ea41..02ec2bd 100644 --- a/app/pages/village/[id]/recruit.vue +++ b/app/pages/village/[id]/recruit.vue @@ -38,16 +38,19 @@ const shown = computed(() => village.value.military.find((m) => m.building_id ==
{{ $t('village.troops.hint') }}
- +
+ + +
diff --git a/app/types/game.ts b/app/types/game.ts index 3d58896..ab24388 100644 --- a/app/types/game.ts +++ b/app/types/game.ts @@ -103,6 +103,11 @@ export interface VillageState { rally: RallyInfo /** The player's unread reports on this world. */ 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. */ quests: { claimable: number; rewards: number } builders: number @@ -194,6 +199,8 @@ export interface BattleReport { building: { type: BuildingType; before: number; after: number } | null loot: Cost 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. */ scouting?: { sent: number @@ -421,3 +428,15 @@ export interface QuestClaimed { book: QuestBookState 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 +} diff --git a/i18n/locales/en.ts b/i18n/locales/en.ts index f250400..26815bf 100644 --- a/i18n/locales/en.ts +++ b/i18n/locales/en.ts @@ -87,5 +87,7 @@ export default { name: 'A village name has 1 to 32 characters.', world_full: 'This world is full.', 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.', }, } diff --git a/i18n/pages/reports.ts b/i18n/pages/reports.ts index 35246a7..4c5c623 100644 --- a/i18n/pages/reports.ts +++ b/i18n/pages/reports.ts @@ -46,6 +46,8 @@ export default { scouted_resources: 'Resources', scouted_buildings: 'Buildings', haul_of: '{loot} of {capacity}', + loyalty: 'Loyalty dropped from {before} to {after}.', + conquered: 'The village has been conquered.', }, support: { arrived: 'The support has arrived and now defends {to}.', diff --git a/i18n/pages/village.ts b/i18n/pages/village.ts index eca50ce..846fff8 100644 --- a/i18n/pages/village.ts +++ b/i18n/pages/village.ts @@ -95,6 +95,21 @@ export default { max_title: 'The most you can recruit now', 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: { title: 'Troops', training: '{count} in training',