@@ -23,15 +30,19 @@
out:fly={{ duration: 200, x: 500 }}
animate:flip={{ duration: 100 }}
>
-
-
+
+
+
+ { #if quest.started }
+ { getPrettyTime(quest.remainingTime || 0) }
+ { :else }
+ { quest.duration }
+ { /if }
+
+
+ { #if !quest.started }
-
- { #if quest.started }
- { getPrettyTime(quest.remainingTime || 0) }
- { :else }
- { quest.duration }
{ #each availableHeroes as hero }
+ { /if }
{ /each }
diff --git a/src/moves/startQuest.ts b/src/moves/startQuest.ts
index ef9eb60..1bbd475 100644
--- a/src/moves/startQuest.ts
+++ b/src/moves/startQuest.ts
@@ -1,5 +1,6 @@
import type { VillageState } from "../village";
+
export default function startQuest(V: VillageState, questId: number, heroId: number) {
const quest = V.quests.find(q => q.id === questId);
if (!quest) {
diff --git a/src/types.ts b/src/types.ts
index dfae412..301e87a 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -26,6 +26,9 @@ export interface ResourcesType extends CostType {
}
+export type Resource = keyof ResourcesType;
+
+
export interface BuildingSource {
name: string;
type: string;
@@ -139,7 +142,8 @@ export interface HeroType {
export interface QuestType {
id: number;
duration: number;
- reward: ResourcesType;
+ resource: keyof ResourcesType
+ reward: number;
level: number;
started: boolean;
hero?: number;
diff --git a/src/update.ts b/src/update.ts
index 5f9eb4c..6691677 100644
--- a/src/update.ts
+++ b/src/update.ts
@@ -56,15 +56,11 @@ export default function update(timestamp: number) {
quest.remainingTime -= delta;
if (quest.remainingTime <= 0) {
- V.resources.wood += quest.reward.wood;
- V.resources.stone += quest.reward.stone;
- V.resources.iron += quest.reward.iron;
- V.resources.food += quest.reward.food;
- V.resources.culture += quest.reward.culture;
+ V.resources[quest.resource] += quest.reward;
// Replace the finished quest with a new one.
- V.quests = V.quests.filter(q => q.id !== quest.id);
- V.quests.push(createQuest(quest.level + 1));
+ const index = V.quests.findIndex(q => q.id === quest.id);
+ V.quests[index] = createQuest(quest.resource, quest.level + 1);
}
});
diff --git a/src/village.ts b/src/village.ts
index fa23ef7..2137a2f 100644
--- a/src/village.ts
+++ b/src/village.ts
@@ -1,11 +1,11 @@
import { writable } from "svelte/store";
+import { RESOURCE_BUILDINGS_START_LEVEL, RESOURCES, TOWN_HALL_START_LEVEL, WORLD_MAP_HEIGHT, WORLD_MAP_WIDTH } from "./constants";
import { createBuilding, createHero, createQuest } from "./create";
import worldmap from "./data/worldmap";
import { getTilesAtDistance, Hex } from "./hexgrid";
import { WORLDMAP_TYPES, type BuildingType, type CostType, type HeroType, type QuestType, type RegionType, type ResourcesType } from "./types";
-import { distanceBetweenCells, getAdjacentWorldmapCells, getKeysAsNumbers, indexToPoint, shuffle } from "./utils";
-import { RESOURCE_BUILDINGS_START_LEVEL, TOWN_HALL_START_LEVEL, WORLD_MAP_HEIGHT, WORLD_MAP_WIDTH } from "./constants";
+import { distanceBetweenCells, getKeysAsNumbers, indexToPoint, shuffle } from "./utils";
type Board = {
@@ -106,11 +106,9 @@ function getInitialWorldmap(): RegionType[] {
function getInitialQuests(): QuestType[] {
- return [
- createQuest(1),
- createQuest(1),
- createQuest(1),
- ];
+ return RESOURCES.map(r => {
+ return createQuest(r, 1);
+ });
}