Make the town hall reduce the construction time of buildings.

This commit is contained in:
Adrian 2024-11-12 16:12:17 +01:00
parent 901d56ffa7
commit 620bfb7581
5 changed files with 20 additions and 2 deletions

View File

@ -47,6 +47,7 @@ export default [
'food': 100, 'food': 100,
} }
}, },
constructionTimeReductionPerLevel: 0.025,
}, },
}, },
{ {

14
src/logic.ts Normal file
View File

@ -0,0 +1,14 @@
import type { BuildingSource } from "./types";
import type { VillageState } from "./village";
export function getTimeToBuild(V: VillageState, building: BuildingSource, level: number): number {
const townhall = V.buildings.find(b => b.type === 'townhall');
if (!townhall) {
throw new Error("Unable to find the Town hall");
}
const reduction = townhall.level * (townhall.behavior.constructionTimeReductionPerLevel || 0);
const baseBuildingTime = building.timeToBuild(level) * 1000;
return baseBuildingTime - (baseBuildingTime * reduction);
}

View File

@ -1,5 +1,6 @@
import { createBuilding, getBuildingSource } from "../create"; import { createBuilding, getBuildingSource } from "../create";
import type { Hex } from "../hexgrid"; import type { Hex } from "../hexgrid";
import { getTimeToBuild } from "../logic";
import { DEFAULT_TILE, type VillageState } from "../village"; import { DEFAULT_TILE, type VillageState } from "../village";
@ -29,7 +30,7 @@ export default function build(V: VillageState, buildingType: string, tile: Hex)
newBuilding.tile = tile; newBuilding.tile = tile;
newBuilding.level = 0; newBuilding.level = 0;
newBuilding.state.upgrade.isUpgrading = true; newBuilding.state.upgrade.isUpgrading = true;
newBuilding.state.upgrade.remainingTime = 1000 * newBuilding.timeToBuild(newBuilding.level + 1); newBuilding.state.upgrade.remainingTime = getTimeToBuild(V, building, 1);
V.buildings.push(newBuilding); V.buildings.push(newBuilding);
V.villageTiles[tile.y][tile.x] = newBuilding.id; V.villageTiles[tile.y][tile.x] = newBuilding.id;

View File

@ -1,3 +1,4 @@
import { getTimeToBuild } from "../logic";
import { canPayBuildingCost, getBuildingUpgradeCost } from "../utils"; import { canPayBuildingCost, getBuildingUpgradeCost } from "../utils";
import type { VillageState } from "../village"; import type { VillageState } from "../village";
@ -28,7 +29,7 @@ export default function upgradeBuilding(V: VillageState, buildingId: number) {
V.resources.food -= cost.food; V.resources.food -= cost.food;
building.state.upgrade.isUpgrading = true; building.state.upgrade.isUpgrading = true;
building.state.upgrade.remainingTime = 1000 * building.timeToBuild(building.level + 1); building.state.upgrade.remainingTime = getTimeToBuild(V, building, building.level + 1);
return true; return true;
} }

View File

@ -34,6 +34,7 @@ export interface BuildingSource {
type: string; type: string;
recruitmentTime: Function; recruitmentTime: Function;
}; };
constructionTimeReductionPerLevel?: number;
}; };
} }