From f8157c288c6439f040310ce257fee8ea5ecbcdcb Mon Sep 17 00:00:00 2001 From: Adrian Gaudebert Date: Wed, 13 Nov 2024 11:20:12 +0100 Subject: [PATCH] Add Great Warehouse and Great Granary, make buildings be unlocked at some Townhall levels. --- src/data/buildings.ts | 64 ++++++++++++++++++++++++++++++++++ src/hud/BuildingCreator.svelte | 8 +++-- src/quests.ts | 31 ---------------- src/types.ts | 1 + src/update.ts | 2 +- src/utils.ts | 9 +++++ 6 files changed, 80 insertions(+), 35 deletions(-) delete mode 100644 src/quests.ts diff --git a/src/data/buildings.ts b/src/data/buildings.ts index 090b5c8..6184be5 100644 --- a/src/data/buildings.ts +++ b/src/data/buildings.ts @@ -30,6 +30,7 @@ export default [ name: 'Town Hall', autoBuilt: true, maxLevel: 20, + requiredTownhallLevel: 0, cost: (level: number) => { return { wood: getResourceBuildingCost(level, 10), @@ -56,6 +57,7 @@ export default [ name: 'Woodcutter', autoBuilt: true, maxLevel: 20, + requiredTownhallLevel: 0, cost: (level: number) => { return { wood: getResourceBuildingCost(level, 6), @@ -83,6 +85,7 @@ export default [ name: 'Mine', autoBuilt: true, maxLevel: 20, + requiredTownhallLevel: 0, cost: (level: number) => { return { wood: getResourceBuildingCost(level, 10), @@ -110,6 +113,7 @@ export default [ name: 'Pit', autoBuilt: true, maxLevel: 20, + requiredTownhallLevel: 0, cost: (level: number) => { return { wood: getResourceBuildingCost(level, 14), @@ -137,6 +141,7 @@ export default [ name: 'Field', autoBuilt: true, maxLevel: 20, + requiredTownhallLevel: 0, cost: (level: number) => { return { wood: getResourceBuildingCost(level, 14), @@ -159,6 +164,7 @@ export default [ type: 'warehouse', name: 'Warehouse', maxLevel: 20, + requiredTownhallLevel: 0, cost: (level: number) => { return { wood: getStorageBuildingCost(level, 15), @@ -185,6 +191,7 @@ export default [ type: 'granary', name: 'Granary', maxLevel: 20, + requiredTownhallLevel: 0, cost: (level: number) => { return { wood: getStorageBuildingCost(level, 12), @@ -207,10 +214,65 @@ export default [ }, }, }, + { + type: 'great-warehouse', + name: 'Great Warehouse', + maxLevel: 20, + requiredTownhallLevel: 15, + cost: (level: number) => { + return { + wood: getStorageBuildingCost(level, 150), + stone: getStorageBuildingCost(level, 200), + iron: getStorageBuildingCost(level, 100), + food: getStorageBuildingCost(level, 150), + }; + }, + timeToBuild: (level: number) => getStandardTimeToBuild(level) * 2, + behavior: { + storage: (V: VillageState, self: BuildingType) => { + const x = self.level; + const capacity = ( ( ( x + ( x * x ) ) / 2 ) + 3 ) * 250; + return { + 'wood': capacity, + 'stone': capacity, + 'iron': capacity, + 'food': 0, + }; + }, + }, + }, + { + type: 'great-granary', + name: 'Great Granary', + maxLevel: 20, + requiredTownhallLevel: 15, + cost: (level: number) => { + return { + wood: getStorageBuildingCost(level, 120), + stone: getStorageBuildingCost(level, 220), + iron: getStorageBuildingCost(level, 100), + food:getStorageBuildingCost(level, 60), + }; + }, + timeToBuild: (level: number) => getStandardTimeToBuild(level) * 2, + behavior: { + storage: (V: VillageState, self: BuildingType) => { + const x = self.level; + const capacity = ( ( ( x + ( x * x ) ) / 2 ) + 3 ) * 250; + return { + 'wood': 0, + 'stone': 0, + 'iron': 0, + 'food': capacity, + }; + }, + }, + }, { type: 'university', name: 'University', maxLevel: 20, + requiredTownhallLevel: 5, cost: (level: number) => { return { wood: getUnitBuildingCost(level, 75), @@ -237,6 +299,7 @@ export default [ type: 'barracks', name: 'Barracks', maxLevel: 20, + requiredTownhallLevel: 3, cost: (level: number) => { return { wood: getUnitBuildingCost(level, 60), @@ -264,6 +327,7 @@ export default [ name: 'Palace', maxLevel: 20, unique: true, + requiredTownhallLevel: 10, cost: (level: number) => { return { wood: getStorageBuildingCost(level, 200), diff --git a/src/hud/BuildingCreator.svelte b/src/hud/BuildingCreator.svelte index 06490fc..afc805c 100644 --- a/src/hud/BuildingCreator.svelte +++ b/src/hud/BuildingCreator.svelte @@ -3,8 +3,8 @@ import buildings from "../data/buildings"; import moves from "../moves"; import showBuildingCreator from "../stores/showBuildingCreator"; - import { canPayBuildingCost } from "../utils"; - import village, { type VillageState } from "../village"; + import { canPayBuildingCost, getTownhall } from "../utils"; + import village from "../village"; import Cost from "./Cost.svelte"; function close() { @@ -25,11 +25,13 @@ $: constructible = buildings .filter(b => !b.autoBuilt) .filter(b => !(b.unique && $village.buildings.some(b2 => b2.type === b.type))) + .filter(b => !b.requiredTownhallLevel || getTownhall($village).level >= b.requiredTownhallLevel) .map(b =>{ const building = createBuilding(b.type); building.level = 0; return building; - }); + }) + .sort((a, b) => a.requiredTownhallLevel - b.requiredTownhallLevel); { #if $showBuildingCreator !== null } diff --git a/src/quests.ts b/src/quests.ts deleted file mode 100644 index a32f7f1..0000000 --- a/src/quests.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { QuestType, ResourcesType } from "./types"; -import { getEmptyResources, random } from "./utils"; - - -let uid = 0; - - -export function createQuest(level: number): QuestType { - const reward = getEmptyResources(); - const adjustedLevel = level * level + 3; - const duration = random(adjustedLevel - 2, adjustedLevel + 2); - Object.keys(reward).forEach(r => { - const resource = r as keyof ResourcesType; - reward[resource] = random( - Math.round((duration * 5 - level * 10) * (1 + level / 3)), - Math.round((duration * 5 + level * 10) * (1 + level / 3)), - ); - - if (resource === 'culture') { - reward[resource] = Math.round(reward[resource] / 20); - } - }); - - return { - id: uid++, - duration, - reward, - level, - started: false, - }; -} diff --git a/src/types.ts b/src/types.ts index a49432f..320efb2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -26,6 +26,7 @@ export interface BuildingSource { autoBuilt?: boolean; unique?: boolean; maxLevel: number; + requiredTownhallLevel: number; cost: (level: number) => CostType; timeToBuild: (level: number) => number; behavior: { diff --git a/src/update.ts b/src/update.ts index 11298ac..f56ec3e 100644 --- a/src/update.ts +++ b/src/update.ts @@ -1,11 +1,11 @@ import { produce } from 'immer'; import { CULTURE_TO_WIN } from './constants'; +import { createQuest } from './create'; import { resolveMission } from './missions'; import type { ProductionType } from './types'; import { getProduction, getStorage, shuffle } from './utils'; import village, { type VillageState } from "./village"; -import { createQuest } from './quests'; let lastFrame: number; diff --git a/src/utils.ts b/src/utils.ts index 16d97fa..d2f20f2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -161,3 +161,12 @@ export function canPayBuildingCost(V: VillageState, building: BuildingType): boo || cost.food > V.resources.food ); } + + +export function getTownhall(V: VillageState): BuildingType { + const townhall = V.buildings.find(b => b.type === 'townhall'); + if (!townhall) { + throw new Error("Unable to find the Town hall"); + } + return townhall; +}