From befcf49e74016d5719d717cd3ccd7fb587d46db9 Mon Sep 17 00:00:00 2001 From: elioat Date: Mon, 13 May 2024 10:16:41 -0400 Subject: * --- js/princess/game.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'js/princess') diff --git a/js/princess/game.js b/js/princess/game.js index aab427c..17d70e2 100644 --- a/js/princess/game.js +++ b/js/princess/game.js @@ -47,13 +47,33 @@ const levelUpPartyMember = (person, stat, amount) => { } }; +const addQuest = (quest) => { + if (!princess.activeQuests.includes(quest)) { + quest.start = new Date(); // Update the quest's start time to the current time + princess.activeQuests.push(quest); + } +} + +const checkQuests = () => { + princess.activeQuests.forEach(quest => { + let currentTime = new Date(); + let elapsedTime = currentTime - quest.start; + if (elapsedTime >= quest.duration) { // TODO: shooting from the hip, this'll need to be tested + princess.completedQuests.push(quest); + princess.activeQuests = princess.activeQuests.filter(q => q !== quest); + } + }); +} + // the player character let princess = { finery: 10, knowledge: 10, spider: 100, treasure: 100, - party: [] // the princesses party of people (an array may not make sense for this, since I'd like to limit it's max size, but maybe I can have a bounding function) + party: [], // the princesses party of people (an array may not make sense for this, since I'd like to limit it's max size, but maybe I can have a bounding function) + activeQuests: [], + completedQuests: [] } // the people the player can recruit @@ -92,12 +112,14 @@ let quests = [ name: "The Spider of the Silver Forest", description: "The princess must defeat the spider of the silver forest.", reward: "The treasure of the silver forest.", - duration: 2 * HOUR + duration: 2 * HOUR, + start: null }, { name: "The Treasure of the Silver Forest", description: "The princess must find the treasure of the silver forest.", reward: "The spider of the silver forest.", - duration: 2 * HOUR + duration: 2 * HOUR, + start: null } ] \ No newline at end of file -- cgit 1.4.1-2-gfad0