about summary refs log blame commit diff stats
path: root/js/princess/game.js
blob: 152a69c058a84d707bc8f83823de6cc690b8b5b1 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                                     















                                                                                    
 











                                                                        
 









                                                                              
 

















                                                                                                      
 
                       



                  
                  
                                                                                                                                                                       

                       

 
                                    






                                                 

                                                                           






                                      

                  






                                                         









                                                                                 

                           




                                                                                 

                           

     
let now = new Date();
const MINUTE = 60 * 1000;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;

const futureTime = (now, hours, minutes = 0) => {
    return new Date(now.getTime() + hours * HOUR + minutes * MINUTE);
}

const prettyTime = (time) => {
    return time.toLocaleTimeString('en-US', { hour: 'numeric', minute: 'numeric' });
}

const prettyTimeFromNow = (time) => {
    let diff = time - new Date();
    if (diff === 0) {
        return 'now';
    }
    let hours = Math.floor(diff / HOUR);
    let minutes = Math.floor((diff % HOUR) / MINUTE);
    let hoursText = hours === 1 ? 'hour' : 'hours';
    let minutesText = minutes === 1 ? 'minute' : 'minutes';
    return `${hours} ${hoursText} and ${minutes} ${minutesText}`;
}


const addPartyPerson = (person) => {
    if (princess.party.length < 5 && !princess.party.includes(person)) {
        princess.party.push(person);
    }
}

const removePartyPerson = (person) => {
    if (princess.party.includes(person)) {
        princess.party = princess.party.filter(p => p !== person);
    }
}


const levelUpPrincess = (stat, amount) => {
    princess[stat] += amount;
}

const levelUpPartyMember = (person, stat, amount) => {
    if (princess.party.includes(person) && typeof person[stat] === 'number') {
        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 princess' 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
let people = [
    {
        name: "Hawk",
        description: "Stable boy and goat herd.",
        aspiration: "To be a knight.",
        power: 1,
        speed: 1,
        spider: 2,
        loyalty: 3 // loyalty increases whenever the princess pays a person
    },
    {
        name: "Bella",
        description: "Scullery maid.",
        aspiration: "To be a pirate.",
        power: 2,
        speed: 2,
        spider: 1,
        loyalty: 3
    },
    {
        name: "Silver Teeth in the Moonlight, aka Teeth",
        description: "A rotund goblin doctor.",
        aspiration: "To be the dentist for a king.",
        power: 2,
        speed: 5,
        spider: 1,
        loyalty: 3
    }
]

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,
        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,
        start: null
    }
]