From c984b5b0c5ed3256f1df6cf27b42f37e1df56318 Mon Sep 17 00:00:00 2001 From: Adrian Gaudebert Date: Wed, 13 Nov 2024 15:26:36 +0100 Subject: [PATCH] Allow to repeat indefinitely a mission to an oasis. --- src/board/OasisRegion.svelte | 24 ++++++++++++++++-------- src/board/Worldmap.svelte | 1 + src/missions.ts | 8 +++++++- src/moves/index.ts | 2 ++ src/moves/pillage.ts | 3 ++- src/moves/toggleMissionRepeat.ts | 14 ++++++++++++++ src/types.ts | 1 + 7 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 src/moves/toggleMissionRepeat.ts diff --git a/src/board/OasisRegion.svelte b/src/board/OasisRegion.svelte index f1bf970..a3a40ef 100644 --- a/src/board/OasisRegion.svelte +++ b/src/board/OasisRegion.svelte @@ -8,6 +8,7 @@ let numberOfUnits = 0; + let repeatMission = false; $: maximumUnits = getRemainingUnitCount($village, 'soldier'); $: if (numberOfUnits > maximumUnits) { numberOfUnits = maximumUnits || 0; @@ -20,7 +21,12 @@ function pillage() { - moves.pillage(region.state.index, numberOfUnits); + moves.pillage(region.state.index, numberOfUnits, repeatMission); + } + + + function toggleMissionRepeat() { + moves.toggleMissionRepeat(region.state.index); } @@ -34,6 +40,10 @@

{ region.state.mission.unitCount } soldiers are on a mission here.

Remaining: { Math.ceil(region.state.mission.remainingTime / 1000) }

+
{ :else }
@@ -44,15 +54,13 @@ max={ maximumUnits } bind:value={ numberOfUnits } /> - + { numberOfUnits } +
{ /if } diff --git a/src/board/Worldmap.svelte b/src/board/Worldmap.svelte index ee9caec..60de20a 100644 --- a/src/board/Worldmap.svelte +++ b/src/board/Worldmap.svelte @@ -25,5 +25,6 @@ .region { border: 1px solid white; padding: 1em; + width: 40%; } diff --git a/src/missions.ts b/src/missions.ts index ca7a39d..e688355 100644 --- a/src/missions.ts +++ b/src/missions.ts @@ -18,6 +18,13 @@ export function resolveMission(V: VillageState, region: RegionType) { default: throw new Error(`Unknown mission type: "${ mission.type }"`); } + + if (mission.repeat) { + mission.remainingTime = region.distance * 10 * 1000; + } + else { + delete region.state.mission; + } } @@ -30,5 +37,4 @@ function resolvePillageOasis(V: VillageState, region: OasisType) { const unit = getUnitSource('soldier'); V.resources[region.resource] += mission.unitCount * unit.behavior.caryingCapacity; - delete region.state.mission; } diff --git a/src/moves/index.ts b/src/moves/index.ts index 64ad62f..10fa278 100644 --- a/src/moves/index.ts +++ b/src/moves/index.ts @@ -5,6 +5,7 @@ import build from './build'; import pillage from './pillage'; import recruitUnits from './recruitUnits'; import startQuest from './startQuest'; +import toggleMissionRepeat from './toggleMissionRepeat'; import upgradeBuilding from './upgradeBuilding'; @@ -36,4 +37,5 @@ export default { pillage: makeMove(pillage), recruitUnits: makeMove(recruitUnits), startQuest: makeMove(startQuest), + toggleMissionRepeat: makeMove(toggleMissionRepeat), }; diff --git a/src/moves/pillage.ts b/src/moves/pillage.ts index 4a309ee..a649f0f 100644 --- a/src/moves/pillage.ts +++ b/src/moves/pillage.ts @@ -2,7 +2,7 @@ import { getRemainingUnitCount } from "../utils"; import type { VillageState } from "../village"; -export default function pillage(V: VillageState, regionIndex: number, soldiersCount: number) { +export default function pillage(V: VillageState, regionIndex: number, soldiersCount: number, repeat: boolean) { if (soldiersCount > getRemainingUnitCount(V, 'soldier')) { return false; } @@ -18,6 +18,7 @@ export default function pillage(V: VillageState, regionIndex: number, soldiersCo unitType: 'soldier', unitCount: soldiersCount, remainingTime: region.distance * 10 * 1000, + repeat, }; return true; diff --git a/src/moves/toggleMissionRepeat.ts b/src/moves/toggleMissionRepeat.ts new file mode 100644 index 0000000..2f763ca --- /dev/null +++ b/src/moves/toggleMissionRepeat.ts @@ -0,0 +1,14 @@ +import type { VillageState } from "../village"; + + +export default function toggleMissionRepeat(V: VillageState, regionIndex: number) { + const region = V.worldmap[regionIndex]; + + if (!region.state.mission) { + return false; + } + + region.state.mission.repeat = !region.state.mission.repeat; + + return true; +} diff --git a/src/types.ts b/src/types.ts index 320efb2..a904e0c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -78,6 +78,7 @@ export interface MissionType { unitType: string; unitCount: number; remainingTime: number; + repeat: boolean; } interface BaseRegionType {