bourgade/src/missions.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

import { WORLDMAP_TYPES, type OasisType, type RegionType } from "./types";
import { assert, getUnitSource } from "./utils";
2024-11-07 14:20:34 +01:00
import type { VillageState } from "./village";
export function resolveMission(V: VillageState, region: RegionType) {
assert(region.type === WORLDMAP_TYPES.OASIS);
2024-11-07 14:20:34 +01:00
const mission = region.state.mission;
if (!mission) {
return;
}
switch (mission.type) {
case 'pillage':
if (region.type === WORLDMAP_TYPES.OASIS) {
2024-11-07 14:20:34 +01:00
resolvePillageOasis(V, region);
}
break;
default:
throw new Error(`Unknown mission type: "${ mission.type }"`);
}
if (mission.repeat) {
mission.remainingTime = 1 * 10 * 1000;
}
else {
delete region.state.mission;
}
2024-11-07 14:20:34 +01:00
}
function resolvePillageOasis(V: VillageState, region: OasisType) {
const mission = region.state.mission;
if (!mission) {
return;
}
2024-11-07 15:14:24 +01:00
const unit = getUnitSource('soldier');
const maxResources = region.distance * region.distance * 100;
2024-11-07 15:14:24 +01:00
V.resources[region.resource] += Math.min(
mission.unitCount * unit.behavior.caryingCapacity,
maxResources
);
2024-11-07 14:20:34 +01:00
}