144 lines
No EOL
6.4 KiB
JavaScript
144 lines
No EOL
6.4 KiB
JavaScript
// Holds functions needed to play the game
|
|
const variables = require("./variables.js");
|
|
const death = require("./deathscreens.js");
|
|
const poi = require("./poiscreens.js");
|
|
|
|
module.exports = {
|
|
eatFood,
|
|
calcSickPoints,
|
|
scavenge,
|
|
checkLose,
|
|
calcLocation,
|
|
calcEncounter,
|
|
}
|
|
|
|
function eatFood() {
|
|
if (variables.food == 0) {
|
|
variables.health - 3*variables.travelSpeed
|
|
} else if (variables.isSick == true) {
|
|
variables.food = variables.food-((variables.travelSpeed*variables.foodAmt)+variables.sickSeverity);
|
|
} else {
|
|
variables.food = variables.food-(variables.travelSpeed*variables.foodAmt);
|
|
}
|
|
variables.health = variables.health+(5*variables.foodAmt);
|
|
}
|
|
|
|
function calcSickPoints() {
|
|
if (variables.isSick = true) {
|
|
variables.sickPoints = variables.sickPoints+((variables.sickSeverity-(0.5*variables.foodAmt))+(0.5*(variables.travelSpeed+variables.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!
|
|
if (variables.daysSinceScav < 20 ) {
|
|
console.log("You must wait "+(20-variables.daysSinceScav)+" days until you can scavenge again")
|
|
} else {
|
|
let luck = variables.randomNumber(1,100);
|
|
if (luck <= 20) {
|
|
let group = 0;
|
|
let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]);
|
|
inventory.push(random);
|
|
} else if (luck <= 40) {
|
|
let group = 1;
|
|
let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]);
|
|
inventory.push(random);
|
|
} else if (luck <= 60) {
|
|
let group = 2;
|
|
let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]);
|
|
inventory.push(random);
|
|
} else if (luck <= 80) {
|
|
let group = 3;
|
|
let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]);
|
|
inventory.push(random);
|
|
} else if (luck <= 100) {
|
|
let group = 4;
|
|
let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]);
|
|
inventory.push(random);
|
|
}
|
|
}
|
|
}
|
|
|
|
function checkLose() { // Checks to see if any lose conditions have been met
|
|
if (variables.health <= 0 || variables.sickPoints >= 50) {
|
|
death.deathScreen();
|
|
}
|
|
if (variables.day >= 365) {
|
|
death.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 (variables.travelSpeed == 1) {
|
|
if (variables.isSick == true) {
|
|
variables.location = variables.location+0.75;
|
|
} else {
|
|
variables.location++;
|
|
}
|
|
}
|
|
if (variables.travelSpeed == 2) {
|
|
if (variables.isSick == true) {
|
|
variables.location = variables.location+1.5;
|
|
} else {
|
|
variables.location = variables.location+2;
|
|
}
|
|
}
|
|
if (variables.travelSpeed == 3) {
|
|
if (variables.isSick == true) {
|
|
variables.location = variables.location+2.25;
|
|
} else {
|
|
variables.location = variables.location+3;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Rundown on how I did this:
|
|
/**
|
|
* calcEncounter() checks what faction territory you are in and pipes the respective faction into initilizeEncounter().
|
|
*
|
|
* initEncounter() is pretty much the same however you can use forceFaction (set to true) to bypass the random raider/abomination chance.
|
|
* forceFaction will always be false unless under certian circumstances (eg. Lost Hills, Legion Territory, Malcom Holmes).
|
|
* Turns out the fight/flee variables work exactly how I want so I did not change them.
|
|
*
|
|
* encounterMenuMaker() was changed to account for forceFaction. If forceFaction is set to true, EMM's equivilant forceOpt will take its value.
|
|
* If true it runs the code you had before, no changes. If it is false it will roll a dice to see if you get the normal faction, given by your switch statement,
|
|
* or a radier/abomination. If it is a radier/abomination it will then roll a 50/50. The code for both is the same as the default faction code except that
|
|
* 'faction' will just be 'raider' or 'abomination' instead of the default.
|
|
*
|
|
* I also implemented auto difficulty scaling. Instead of piping in 'encounterDiffOne' you just input the interger of it. This is because you cant
|
|
* use a string as a variable name and or whatever. Just trust me, this is the only way it works. initEncounter() will figure it out on the otherside.
|
|
*/
|
|
|
|
function calcEncounter() {
|
|
if (variables.randomNumber(1,100) <= 20) {
|
|
if (variables.location >= 255) {
|
|
if (variables.locationA > variables.locationB) {
|
|
if ((variables.locationA >= 5 && variables.locationA < 17) || (variables.locationA >= 23 && variables.locationA < 40)) {
|
|
poi.initializeEncounter(NCR,4,true,true,false);
|
|
}
|
|
if (variables.locationB >= 40) {
|
|
poi.initializeEncounter(NCR,5,true,true,false);
|
|
}
|
|
} else if (variables.locationA < variables.locationB) {
|
|
if ((variables.locationB >= 0 && variables.locationB < 30) || (variables.locationB >= 40 && variables.locationB < 80)) {
|
|
poi.initializeEncounter(abomination,3,true,true,false)
|
|
}
|
|
if ((variables.locationB >= 30 && variables.locationB < 40) || (variables.locationB >= 90)) {
|
|
poi.initializeEncounter(NCR,5,true,true,false)
|
|
}
|
|
if (variables.locationB >= 80 && variables.locationB < 90) {
|
|
poi.initializeEncounter(enclave,4,true,true,false)
|
|
}
|
|
} else {
|
|
if (variables.location >= 5 && variables.location < 50) {
|
|
poi.initializeEncounter(abomination,1,true,true,false)
|
|
}
|
|
if (variables.location >= 50 && variables.location < 200) {
|
|
poi.initializeEncounter(MWBOS,2,true,true,false)
|
|
}
|
|
if (variables.location >= 200 && variables.location < 255) {
|
|
poi.initializeEncounter(legion,3,true,true,false)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |