From 5935f395f74b6d250de083f35acefa1b7ac84fc0 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Thu, 29 Oct 2026 16:17:00 +0100 Subject: [PATCH] feat: raiders: incoming bands with their gathering countdown, raid reports with bounty, scattered raids Co-Authored-By: Claude Opus 5.5 (1M context) --- app/components/report/Battle.vue | 9 +++- app/components/village/Movements.vue | 4 ++ app/components/village/OverviewSidebar.vue | 2 +- app/mock/server.ts | 55 +++++++++++++++++++++- app/pages/reports/[worldId]/[id].vue | 12 +++-- app/pages/reports/[worldId]/index.vue | 5 +- app/types/game.ts | 17 ++++++- app/utils/military.ts | 9 ++++ i18n/pages/reports.ts | 5 ++ i18n/pages/village.ts | 3 ++ 10 files changed, 108 insertions(+), 13 deletions(-) diff --git a/app/components/report/Battle.vue b/app/components/report/Battle.vue index cdcac0b..9ccf0cf 100644 --- a/app/components/report/Battle.vue +++ b/app/components/report/Battle.vue @@ -42,7 +42,7 @@ const luckAt = computed(() => Math.max(0, Math.min(100, ((props.report.luck + 25
{{ s.label }}
-
{{ s.side.village.player?.name ?? $t('common.barbarian') }}
+
{{ s.side.village.player?.name ?? (s.key === 'attacker' && report.raid ? $t('reports.battle.raiders') : $t('common.barbarian')) }}
{{ s.place }}
{{ villageLabel(s.side.village) }} @@ -107,6 +107,13 @@ const luckAt = computed(() => Math.max(0, Math.min(100, ((props.report.luck + 25 {{ $t('reports.battle.haul_of', { loot: looted, capacity: report.capacity }) }} +
+ {{ $t('reports.battle.bounty') }} + + {{ report.bounty[r] }} + +
+

{{ $t('reports.battle.loyalty', { before: report.loyalty.before, after: report.loyalty.after }) }} diff --git a/app/components/village/Movements.vue b/app/components/village/Movements.vue index 68eabfb..becdcca 100644 --- a/app/components/village/Movements.vue +++ b/app/components/village/Movements.vue @@ -17,6 +17,7 @@ const own = computed(() => props.movements.filter((m) => m.direction !== 'in')) function title(m: Movement) { if (m.direction === 'home') return t('village.movements.return_from', { from: villageLabel(m.from) }) if (m.direction === 'in') { + if (m.raid) return t('village.movements.raid_from', { from: villageLabel(m.from) }) return t(m.type === 'attack' ? 'village.movements.attack_from' : 'village.movements.support_from', { from: villageLabel(m.from) }) } return t(m.type === 'attack' ? 'village.movements.attack_on' : 'village.movements.support_for', { target: villageLabel(m.to) }) @@ -59,6 +60,9 @@ const canCancel = (m: Movement) => !!m.cancel_until && props.secondsUntil(m.canc {{ title(m) }} {{ $t('village.movements.by', { player: m.from.player.name }) }} +

+ {{ $t('village.movements.gathering', { time: formatDuration(secondsUntil(m.marches_at)) }) }} +
{{ count }} diff --git a/app/components/village/OverviewSidebar.vue b/app/components/village/OverviewSidebar.vue index b88d5a1..ac6d934 100644 --- a/app/components/village/OverviewSidebar.vue +++ b/app/components/village/OverviewSidebar.vue @@ -31,7 +31,7 @@ function order(o: BuildOrder) {
  • - {{ villageLabel(m.from) }} + {{ m.raid ? $t('village.side.raiders', { from: `(${m.from.x}|${m.from.y})` }) : villageLabel(m.from) }} {{ formatDuration(secondsUntil(m.arrives_at)) }}
diff --git a/app/mock/server.ts b/app/mock/server.ts index b769648..b3324c7 100644 --- a/app/mock/server.ts +++ b/app/mock/server.ts @@ -103,6 +103,8 @@ interface MockVillage { levy_until?: number | null /** Support standing here, by home village id; it eats here. */ support?: Record + /** When the next mock raid gathers against this village. */ + next_raid_at?: number } interface MockMovement { @@ -121,6 +123,8 @@ interface MockMovement { cargo: Cost | null sent_at: number arrives_at: number + /** Raiders (user_id 0) gather until they march. */ + marches_at?: number } type MockReport = Report & { world_id: number; user_id: number } @@ -818,6 +822,11 @@ function battle(state: MockState, m: MockMovement, d: MockVillage, at: number) { } const wall = d.buildings.find((b) => b.type === 'wall') + // A beaten band of raiders leaves half its attack in resources. + const raided = m.user_id === RAIDERS + const each = raided && !won ? Math.floor(attack / 6) : 0 + const bounty: Cost | null = raided && !won ? { wood: each, clay: each, iron: each } : null + if (bounty) refund(d, bounty) const report: BattleReport = { won, luck: 0, @@ -833,6 +842,8 @@ function battle(state: MockState, m: MockMovement, d: MockVillage, at: number) { building: null, loot, capacity, + raid: raided, + bounty, } // An attacker with no survivors learns nothing about the defence. const seen: BattleReport = hasUnits(survivors) @@ -845,6 +856,42 @@ function battle(state: MockState, m: MockMovement, d: MockVillage, at: number) { if (hasUnits(survivors)) turnBack(state, m, survivors, capacity > 0 ? loot : null, at) } +/** Raiders have no player. */ +const RAIDERS = 0 + +/** + * Every few minutes the nearest made-up barbarian sends a small band at the village; it + * gathers two minutes before it marches. A crude stand-in for app/Engine/Raiders.php. + */ +function planRaid(state: MockState, v: MockVillage, now: number) { + if ((v.next_raid_at ?? 0) > now || (state.movements ?? []).some((m) => m.user_id === RAIDERS && m.target_id === v.id)) return + let camp: { id: number; x: number; y: number } | null = null + for (let r = 1; r <= 8 && !camp; r++) { + for (let dy = -r; dy <= r && !camp; dy++) { + for (let dx = -r; dx <= r && !camp; dx++) { + const b = Math.max(Math.abs(dx), Math.abs(dy)) === r ? barbarianAt(v.x + dx, v.y + dy) : null + if (b) camp = { id: b.id, x: v.x + dx, y: v.y + dy } + } + } + } + if (!camp) return + const marches = now + 120_000 + const m = march(state, { + world_id: v.world_id, + user_id: RAIDERS, + type: 'attack', + mode: DEFAULT_MODE, + origin_id: camp.id, + target_id: v.id, + distance: fieldDistance(camp, v), + units: { spear: 6, sword: 2 }, + cargo: null, + sent_at: marches, + }) + m.marches_at = marches + v.next_raid_at = m.arrives_at + 600_000 +} + /** A movement reaches its target, which was caught up to the arrival first. */ function arrive(state: MockState, m: MockMovement) { const at = m.arrives_at @@ -906,6 +953,8 @@ function movements(state: MockState, v: MockVillage, now: number): Movement[] { sent_at: mine ? iso(m.sent_at) : null, arrives_at: iso(m.arrives_at), cancel_until: mine && direction === 'out' && cancelUntil > now ? iso(cancelUntil) : null, + raid: m.user_id === RAIDERS, + marches_at: m.marches_at && m.marches_at > now ? iso(m.marches_at) : null, } }) } @@ -1054,7 +1103,11 @@ const handlers: Record = { return { village_id: v.id } }, - 'village.show': (state, user, data, now) => view(state, ownVillage(state, user, data.village_id, now), now), + 'village.show': (state, user, data, now) => { + const v = ownVillage(state, user, data.village_id, now) + planRaid(state, v, now) + return view(state, v, now) + }, 'map.view': (state, user, data) => mapView(state, user, data), diff --git a/app/pages/reports/[worldId]/[id].vue b/app/pages/reports/[worldId]/[id].vue index 47f171c..4f4afe3 100644 --- a/app/pages/reports/[worldId]/[id].vue +++ b/app/pages/reports/[worldId]/[id].vue @@ -19,10 +19,11 @@ watch( const subject = computed(() => { const r = report.value - if (!r) return '' - if (r.type === 'support') return t('reports.title_support', { from: villageLabel(r.payload.from), to: villageLabel(r.payload.to) }) - return t('reports.title_attack', { from: villageLabel(r.payload.attacker.village), to: villageLabel(r.payload.defender.village) }) + return r ? reportSubject(r, t) : '' }) +const fight = computed(() => (report.value && report.value.type !== 'support' ? report.value.payload : null)) +const battle = computed(() => (fight.value && !('scattered' in fight.value) ? fight.value : null)) +const scattered = computed(() => (fight.value && 'scattered' in fight.value ? fight.value : null))