summary refs log tree commit diff stats
path: root/compiler/vmconv.nim
Commit message (Expand)AuthorAgeFilesLines
* make system random work in VM (#17059)flywind2021-02-171-0/+4
* add `--experimental:vmopsDanger`; add generic conversion for vmops (#13813)Timothee Cour2020-04-201-0/+41
href='#n40'>40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
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
    }
]