Create-Task/files/variables.js

138 lines
No EOL
3.9 KiB
JavaScript

// Holds the global variables, functions, and math operations such as the day counter and food eaten..
const readline = require('readline-sync');
module.exports = { // Lets variables and functions be used in other files
day,
location,
ammo,
food,
foodAmt,
health,
travelSpeed,
isRadiated,
radSeverity,
isSick,
sickSeverity,
inventory,
name,
prewarmoney,
caps,
eatfood,
calcLocation,
calcSickPoints,
scavenge,
sleep,
checkLose,
userInput,
};
var name = '';
var prewarmoney = 0; // Used in Enclave Stores
var caps = 0; // Used everywhere
var day = 0; // Should we add a definite end? 365 Days?
var location = 0; // Location in the world, 0 is Raven Rock, 200 is CTE.
var ammo = 0; // Used in encounters and hunting, No cap :)
var food = 0; // Max: 200
var foodAmt = 0; // Amt of food eaten per day, 3 levels, starting at 1
var health = 0; // Max: 100
var travelSpeed = 0; // Location points per day, 3 levels, starting at 1
var isRadiated = false;
var radSeverity = 0; // Modifies many things, 3 levels, starting at 1
var isSick = false;
var sickPoints = 0; // If you accumulate 50 sick points you lose
var sickSeverity = 0; // 3 levls, starting at 1
var inventory = []; // Max of 5 items
var lootTables = [[],[],[],[],[]] // Only small things like food and ammo, 5 Loot tables per scavenge score, 3 items in each, first is best
function eatfood() {
if (food == 0) { health - 20 }
if (isSick == true) { food = food-((travelSpeed*foodAmt)+sickSeverity); }
else { food = food-(travelSpeed*foodAmt); }
health = health+(5*foodAmt);
}
function calcSickPoints() {
if (isSick = true) {
sickPoints = sickPoints+((sickSeverity-(0.5*foodAmt))+(0.5*(travelSpeed+radSeverity)));
}
}
function scavenge() { // Rolls a random number between 1 and 100 to see which loot table you get, then picks a random item from it. ADD COOLDOWN!
let luck = Math.random(1,100);
if (luck <= 20) {
let group = 0;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 40) {
let group = 1;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 60) {
let group = 2;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 80) {
let group = 3;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 100) {
let group = 4;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
}
}
function sleep(time) { // Waits the inputed amt of miliseconds before proceeding
setTimeout(() => {}, time);
}
function checkLose() { // Checks to see if any lose conditions have been met
if (health <= 0 || sickPoints >= 50) {
deathScreen();
}
if (day >= 365) {
timeDeath();
}
}
function calcLocation() { // Calculates your location in the world using location points.
// You move your move speed per day, but 3/4 of it if you are sick
if (travelSpeed == 1) {
if (isSick == true) {
location = location+0.75;
} else {
location++;
}
}
if (travelSpeed == 2) {
if (isSick == true) {
location = location+1.5;
} else {
location = location+2;
}
}
if (travelSpeed == 3) {
if (isSick == true) {
location = location+2.25;
} else {
location = location+3;
}
}
}
function userInput(question) { // Basic user input functions, takes in the question to be asked.
let answer = readline.question(question);
return(answer);
}