2016-10-17 10:24:39 +02:00
|
|
|
var Engine = {
|
2017-01-31 04:41:42 +01:00
|
|
|
Debug: true,
|
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
//Clickable objects
|
2017-01-09 23:14:18 +01:00
|
|
|
Clickables: {
|
2016-10-17 10:24:39 +02:00
|
|
|
//Main menu buttons
|
2017-01-31 04:41:42 +01:00
|
|
|
terminalMainMenuButton: null,
|
|
|
|
characterMainMenuButton: null,
|
|
|
|
scriptEditorMainMenuButton: null,
|
|
|
|
activeScriptsMainMenuButton: null,
|
|
|
|
worldMainMenuButton: null,
|
|
|
|
createProgramMainMenuButton: null,
|
|
|
|
factionsMainMenuButton: null,
|
|
|
|
augmentationsMainMenuButton: null,
|
|
|
|
tutorialMainMenuButton: null,
|
|
|
|
saveMainMenuButton: null,
|
|
|
|
deleteMainMenuButton: null,
|
2016-10-17 10:24:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
//Display objects
|
|
|
|
Display: {
|
|
|
|
//Progress bar
|
2017-01-31 04:41:42 +01:00
|
|
|
progress: null,
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Display for status text (such as "Saved" or "Loaded")
|
2017-01-31 04:41:42 +01:00
|
|
|
statusText: null,
|
|
|
|
|
|
|
|
hacking_skill: null,
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Main menu content
|
2017-01-31 04:41:42 +01:00
|
|
|
terminalContent: null,
|
|
|
|
characterContent: null,
|
|
|
|
scriptEditorContent: null,
|
|
|
|
activeScriptsContent: null,
|
|
|
|
worldContent: null,
|
|
|
|
createProgramContent: null,
|
|
|
|
factionsContent: null,
|
2017-01-28 04:10:16 +01:00
|
|
|
factionContent: null,
|
2017-01-31 04:41:42 +01:00
|
|
|
augmentationsContent: null,
|
|
|
|
tutorialContent: null,
|
|
|
|
locationContent: null,
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Character info
|
2017-01-31 04:41:42 +01:00
|
|
|
characterInfo: null,
|
|
|
|
|
|
|
|
//Script editor text
|
|
|
|
scriptEditorText: null,
|
2016-10-17 10:24:39 +02:00
|
|
|
},
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
//Current page status
|
|
|
|
Page: {
|
|
|
|
Terminal: "Terminal",
|
|
|
|
CharacterInfo: "CharacterInfo",
|
|
|
|
ScriptEditor: "ScriptEditor",
|
|
|
|
ActiveScripts: "ActiveScripts",
|
|
|
|
World: "World",
|
|
|
|
CreateProgram: "CreateProgram",
|
|
|
|
Factions: "Factions",
|
2017-01-28 04:10:16 +01:00
|
|
|
Faction: "Faction",
|
2017-01-31 04:41:42 +01:00
|
|
|
Augmentations: "Augmentations",
|
|
|
|
Tutorial: "Tutorial",
|
|
|
|
Location: "Location",
|
|
|
|
},
|
|
|
|
currentPage: null,
|
2016-11-24 23:30:33 +01:00
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
//Time variables (milliseconds unix epoch time)
|
|
|
|
_lastUpdate: new Date().getTime(),
|
|
|
|
_idleSpeed: 200, //Speed (in ms) at which the main loop is updated
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Save function
|
2016-11-24 23:30:33 +01:00
|
|
|
saveGame: function() {
|
2017-01-31 04:41:42 +01:00
|
|
|
var PlayerSave = JSON.stringify(Player);
|
|
|
|
var AllServersSave = JSON.stringify(AllServers);
|
|
|
|
var CompaniesSave = JSON.stringify(Companies);
|
|
|
|
var FactionsSave = JSON.stringify(Factions);
|
|
|
|
//TODO Add factions + companies here when they're done
|
2016-10-17 10:24:39 +02:00
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
window.localStorage.setItem("netburnerPlayerSave", PlayerSave);
|
2016-12-01 23:18:18 +01:00
|
|
|
window.localStorage.setItem("netburnerAllServersSave", AllServersSave);
|
2017-01-31 04:41:42 +01:00
|
|
|
window.localStorage.setItem("netburnerCompaniesSave", CompaniesSave);
|
|
|
|
window.localStorage.setItem("netburnerFactionsSave", FactionsSave);
|
|
|
|
console.log("Game saved to local storage");
|
2016-10-17 10:24:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
//Load saved game function
|
|
|
|
loadSave: function() {
|
|
|
|
//Check to see if file exists
|
2016-11-24 23:30:33 +01:00
|
|
|
if (!window.localStorage.getItem("netburnerPlayerSave")) {
|
2017-01-31 04:41:42 +01:00
|
|
|
console.log("No Player save to load");
|
|
|
|
return false;
|
2016-12-01 23:18:18 +01:00
|
|
|
} else if (!window.localStorage.getItem("netburnerAllServersSave")) {
|
|
|
|
console.log("No AllServers save to load");
|
|
|
|
return false;
|
2017-01-31 04:41:42 +01:00
|
|
|
} else if (!window.localStorage.getItem("netburnerCompaniesSave")) {
|
|
|
|
console.log("No Companies save to load");
|
|
|
|
return false;
|
|
|
|
} else if (!window.localStorage.getItem("netburnerFactionsSave")) {
|
|
|
|
console.log("No Factions save to load");
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
var PlayerSave = window.localStorage.getItem("netburnerPlayerSave");
|
|
|
|
var AllServersSave = window.localStorage.getItem("netburnerAllServersSave");
|
|
|
|
var CompaniesSave = window.localStorage.getItem("netburnerCompaniesSave");
|
|
|
|
var FactionsSave = window.localStorage.getItem("netburnerFactionsSave");
|
|
|
|
Player = JSON.parse(PlayerSave, Reviver);
|
|
|
|
AllServers = JSON.parse(AllServersSave, Reviver);
|
|
|
|
Companies = JSON.parse(CompaniesSave, Reviver);
|
|
|
|
Factions = JSON.parse(FactionsSave, Reviver);
|
|
|
|
return true;
|
2016-10-17 10:24:39 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//Delete saved game function
|
|
|
|
deleteSave: function() {
|
2017-01-31 04:41:42 +01:00
|
|
|
//TODO if a save doesn't exist..maybe I shouldn't return? I just keep going
|
|
|
|
//or else nothing gets deleted. TODO Fix this
|
2016-11-24 23:44:48 +01:00
|
|
|
if (!window.localStorage.getItem("netburnerPlayerSave")) {
|
|
|
|
console.log("No Player Save to delete");
|
2017-01-31 04:41:42 +01:00
|
|
|
return false;
|
2016-12-01 23:18:18 +01:00
|
|
|
} else if (!window.localStorage.getItem("netburnerAllServersSave")) {
|
|
|
|
console.log("No AllServers Save to delete");
|
2017-01-31 04:41:42 +01:00
|
|
|
return false;
|
|
|
|
} else if (!window.localStorage.getItem("netburnerCompaniesSave")) {
|
|
|
|
console.log("No Companies Save to delete");
|
|
|
|
return false;
|
|
|
|
} else if (!window.localStorage.getItem("netburnerFactionsSave")) {
|
|
|
|
console.log("No Factions Save to delete");
|
|
|
|
return false;
|
2016-10-17 10:24:39 +02:00
|
|
|
} else {
|
2016-11-24 23:44:48 +01:00
|
|
|
window.localStorage.removeItem("netburnerPlayerSave");
|
2016-12-01 23:18:18 +01:00
|
|
|
window.localStorage.removeItem("netburnerAllServersSave");
|
2017-01-31 04:41:42 +01:00
|
|
|
window.localStorage.removeItem("netburnerCompaniesSave");
|
|
|
|
window.localStorage.removeItem("netburnerFactionsSave");
|
|
|
|
console.log("Deleted saves")
|
2016-11-24 23:44:48 +01:00
|
|
|
return true;
|
2016-10-17 10:24:39 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Load content when a main menu button is clicked */
|
|
|
|
loadTerminalContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.terminalContent.style.visibility = "visible";
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.currentPage = Engine.Page.Terminal;
|
2016-10-17 10:24:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
loadCharacterContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.characterContent.style.visibility = "visible";
|
|
|
|
Engine.displayCharacterInfo();
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.currentPage = Engine.Page.CharacterInfo;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadScriptEditorContent: function(filename = "", code = "") {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.scriptEditorContent.style.visibility = "visible";
|
|
|
|
if (filename == "") {
|
|
|
|
document.getElementById("script-editor-filename").value = "untitled";
|
|
|
|
} else {
|
|
|
|
document.getElementById("script-editor-filename").value = filename;
|
|
|
|
}
|
|
|
|
document.getElementById("script-editor-text").value = code;
|
|
|
|
Engine.currentPage = Engine.Page.ScriptEditor;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadActiveScriptsContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.activeScriptsContent.style.visibility = "visible";
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.ActiveScripts;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadWorldContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.worldContent.style.visibility = "visible";
|
|
|
|
Engine.displayWorldInfo();
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.World;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadCreateProgramContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.createProgramContent.style.visibility = "visible";
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.CreateProgram;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadFactionsContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.factionsContent.style.visibility = "visible";
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Factions;
|
2016-10-17 10:24:39 +02:00
|
|
|
},
|
2017-01-28 04:10:16 +01:00
|
|
|
|
|
|
|
loadFactionContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.factionContent.style.visibility = "visible";
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Faction;
|
|
|
|
},
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
loadAugmentationsContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.augmentationsContent.style.visibility = "visible";
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Augmentations;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadTutorialContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.tutorialContent.style.visibility = "visible";
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Tutorial;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadLocationContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.locationContent.style.visibility = "visible";
|
|
|
|
displayLocationContent(Player.location);
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Location;
|
|
|
|
},
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Helper function that hides all content
|
|
|
|
hideAllContent: function() {
|
|
|
|
Engine.Display.terminalContent.style.visibility = "hidden";
|
|
|
|
Engine.Display.characterContent.style.visibility = "hidden";
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Display.scriptEditorContent.style.visibility = "hidden";
|
|
|
|
Engine.Display.activeScriptsContent.style.visibility = "hidden";
|
|
|
|
Engine.Display.worldContent.style.visibility = "hidden";
|
|
|
|
Engine.Display.createProgramContent.style.visibility = "hidden";
|
|
|
|
Engine.Display.factionsContent.style.visibility = "hidden";
|
2017-01-28 04:10:16 +01:00
|
|
|
Engine.Display.factionContent.style.visibility = "hidden";
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Display.augmentationsContent.style.visibility = "hidden";
|
|
|
|
Engine.Display.tutorialContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.locationContent.style.visibility = "hidden";
|
2017-01-28 04:10:16 +01:00
|
|
|
|
|
|
|
//Location lists
|
|
|
|
Engine.aevumLocationsList.style.display = "none";
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.chongqingLocationsList.style.display = "none";
|
|
|
|
Engine.sector12LocationsList.style.display = "none";
|
|
|
|
Engine.newTokyoLocationsList.style.display = "none";
|
|
|
|
Engine.ishimaLocationsList.style.display = "none";
|
|
|
|
Engine.volhavenLocationsList.style.display = "none";
|
2016-10-17 10:24:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Display character info */
|
|
|
|
displayCharacterInfo: function() {
|
2016-12-19 21:59:13 +01:00
|
|
|
Engine.Display.characterInfo.innerHTML = 'Money: $' + Player.money.toFixed(2) + '<br><br>' +
|
2016-10-17 10:24:39 +02:00
|
|
|
'Hacking Level: ' + Player.hacking_skill + '<br><br>' +
|
|
|
|
'Strength: ' + Player.strength + '<br><br>' +
|
|
|
|
'Defense: ' + Player.defense + '<br><br>' +
|
|
|
|
'Dexterity: ' + Player.dexterity + '<br><br>' +
|
2016-10-17 23:23:23 +02:00
|
|
|
'Agility: ' + Player.agility + '<br><br>' +
|
2017-01-31 04:41:42 +01:00
|
|
|
'Charisma: ' + Player.charisma + '<br><br>' +
|
|
|
|
'Servers owned: ' + Player.purchasedServers.length + '<br><br>' +
|
2016-12-19 21:59:13 +01:00
|
|
|
'Hacking Experience: ' + Player.hacking_exp.toFixed(4) + '<br><br>';
|
2016-10-17 10:24:39 +02:00
|
|
|
},
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
/* Display locations in the world*/
|
|
|
|
aevumLocationsList: null,
|
|
|
|
chongqingLocationsList: null,
|
|
|
|
sector12LocationsList: null,
|
|
|
|
newTokyoLocationsList: null,
|
|
|
|
ishimaLocationsList: null,
|
|
|
|
volhavenLocationsList: null,
|
|
|
|
|
|
|
|
displayWorldInfo: function() {
|
|
|
|
Engine.aevumLocationsList.style.display = "none";
|
|
|
|
Engine.chongqingLocationsList.style.display = "none";
|
|
|
|
Engine.sector12LocationsList.style.display = "none";
|
|
|
|
Engine.newTokyoLocationsList.style.display = "none";
|
|
|
|
Engine.ishimaLocationsList.style.display = "none";
|
|
|
|
Engine.volhavenLocationsList.style.display = "none";
|
|
|
|
|
|
|
|
switch(Player.city) {
|
|
|
|
case Locations.Aevum:
|
|
|
|
Engine.aevumLocationsList.style.display = "inline";
|
2017-01-28 04:10:16 +01:00
|
|
|
Engine.aevumLocationsList.style.visibility = "visible";
|
2017-01-31 04:41:42 +01:00
|
|
|
break;
|
|
|
|
case Locations.Chongqing:
|
|
|
|
Engine.chongqingLocationsList.style.display = "inline";
|
2017-01-28 04:10:16 +01:00
|
|
|
Engine.chongqingLocationsList.style.visibility = "visible";
|
2017-01-31 04:41:42 +01:00
|
|
|
break;
|
|
|
|
case Locations.Sector12:
|
|
|
|
Engine.sector12LocationsList.style.display = "inline";
|
2017-01-28 04:10:16 +01:00
|
|
|
Engine.sector12LocationsList.style.visibility = "visible";
|
2017-01-31 04:41:42 +01:00
|
|
|
break;
|
|
|
|
case Locations.NewTokyo:
|
|
|
|
Engine.newTokyoLocationsList.style.display = "inline";
|
2017-01-28 04:10:16 +01:00
|
|
|
Engine.newTokyoLocationsList.style.visibility = "visible";
|
2017-01-31 04:41:42 +01:00
|
|
|
break;
|
|
|
|
case Locations.Ishima:
|
|
|
|
Engine.ishimaLocationsList.style.display = "inline";
|
2017-01-28 04:10:16 +01:00
|
|
|
Engine.ishimaLocationsList.style.visibility = "visible";
|
2017-01-31 04:41:42 +01:00
|
|
|
break;
|
|
|
|
case Locations.Volhaven:
|
|
|
|
Engine.volhavenLocationsList.style.display = "inline";
|
2017-01-28 04:10:16 +01:00
|
|
|
Engine.volhavenLocationsList.style.visibility = "visible";
|
2017-01-31 04:41:42 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("Invalid city value in Player object!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Functions used to update information on the Active Scripts page */
|
|
|
|
ActiveScriptsList: null,
|
|
|
|
|
|
|
|
//Creates and adds the <li> object for a given workerScript
|
|
|
|
addActiveScriptsItem: function(workerscript) {
|
|
|
|
var item = document.createElement("li");
|
|
|
|
|
|
|
|
Engine.createActiveScriptsText(workerscript, item);
|
|
|
|
|
|
|
|
//Add the li element onto the list
|
|
|
|
if (Engine.ActiveScriptsList == null) {
|
|
|
|
Engine.ActiveScriptsList = document.getElementById("active-scripts-list");
|
|
|
|
}
|
|
|
|
Engine.ActiveScriptsList.appendChild(item);
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteActiveScriptsItem: function(i) {
|
|
|
|
var list = Engine.ActiveScriptsList.querySelectorAll('#active-scripts-list li');
|
|
|
|
if (i >= list.length) {
|
|
|
|
throw new Error("Trying to delete an out-of-range Active Scripts item");
|
|
|
|
}
|
|
|
|
|
|
|
|
var li = list[i];
|
|
|
|
li.parentNode.removeChild(li);
|
|
|
|
},
|
|
|
|
|
|
|
|
//Update the ActiveScriptsItems array
|
|
|
|
updateActiveScriptsItems: function() {
|
|
|
|
for (var i = 0; i < workerScripts.length; ++i) {
|
|
|
|
Engine.updateActiveScriptsItemContent(i, workerScripts[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//Updates the content of the given item in the Active Scripts list
|
|
|
|
updateActiveScriptsItemContent: function(i, workerscript) {
|
|
|
|
var list = Engine.ActiveScriptsList.getElementsByTagName("li");
|
|
|
|
if (i >= list.length) {
|
|
|
|
throw new Error("Trying to update an out-of-range Active Scripts Item");
|
|
|
|
}
|
|
|
|
|
|
|
|
var item = list[i];
|
|
|
|
|
|
|
|
//Clear the item
|
|
|
|
while (item.firstChild) {
|
|
|
|
item.removeChild(item.firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add the updated text back
|
|
|
|
Engine.createActiveScriptsText(workerscript, item);
|
|
|
|
},
|
|
|
|
|
|
|
|
createActiveScriptsText(workerscript, item) {
|
|
|
|
//Script name
|
|
|
|
var scriptName = document.createElement("h2");
|
|
|
|
scriptName.appendChild(document.createTextNode(workerscript.name));
|
|
|
|
item.appendChild(scriptName);
|
|
|
|
|
|
|
|
var itemText = document.createElement("p");
|
|
|
|
|
|
|
|
//Server ip/hostname
|
|
|
|
var hostname = workerscript.getServer().hostname;
|
|
|
|
var serverIpHostname = "Server: " + hostname + "(" + workerscript.serverIp + ")";
|
|
|
|
|
|
|
|
//Online
|
|
|
|
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
|
|
|
var onlineMpsText = "Online production: $" + onlineMps.toFixed(2) + "/second";
|
|
|
|
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
|
|
|
var onlineEpsText = (Array(20).join(" ") + onlineEps.toFixed(4) + " exp/second").replace( / /g, " ");
|
|
|
|
|
|
|
|
//Offline
|
|
|
|
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
|
|
|
var offlineMpsText = "Offline production: $" + offlineMps.toFixed(2) + "/second";
|
|
|
|
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
|
|
|
var offlineEpsText = (Array(21).join(" ") + offlineEps.toFixed(4) + " exp/second").replace( / /g, " ");
|
|
|
|
|
|
|
|
itemText.innerHTML = serverIpHostname + "<br>" + onlineMpsText + "<br>" + onlineEpsText + "<br>" +
|
|
|
|
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
|
|
|
|
|
|
|
item.appendChild(itemText);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Main Event Loop */
|
|
|
|
idleTimer: function() {
|
|
|
|
//Get time difference
|
|
|
|
var _thisUpdate = new Date().getTime();
|
|
|
|
var diff = _thisUpdate - Engine._lastUpdate;
|
2016-12-02 22:57:20 +01:00
|
|
|
var offset = diff % Engine._idleSpeed;
|
2017-01-31 04:41:42 +01:00
|
|
|
|
2016-11-21 07:11:14 +01:00
|
|
|
//Divide this by cycle time to determine how many cycles have elapsed since last update
|
2016-12-01 23:39:13 +01:00
|
|
|
diff = Math.floor(diff / Engine._idleSpeed);
|
2017-01-31 04:41:42 +01:00
|
|
|
|
2016-11-21 07:11:14 +01:00
|
|
|
if (diff > 0) {
|
|
|
|
//Update the game engine by the calculated number of cycles
|
|
|
|
Engine.updateGame(diff);
|
2016-12-02 22:57:20 +01:00
|
|
|
Engine._lastUpdate = _thisUpdate - offset;
|
2017-01-31 04:41:42 +01:00
|
|
|
Player.lastUpdate = _thisUpdate - offset;
|
2016-11-21 07:11:14 +01:00
|
|
|
}
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
window.requestAnimationFrame(Engine.idleTimer);
|
|
|
|
},
|
2016-11-21 07:11:14 +01:00
|
|
|
|
2016-12-15 23:22:42 +01:00
|
|
|
updateGame: function(numCycles = 1) {
|
|
|
|
//Manual hack
|
2017-01-31 04:41:42 +01:00
|
|
|
if (Player.startAction == true) {
|
|
|
|
Engine._totalActionTime = Player.actionTime;
|
|
|
|
Engine._actionTimeLeft = Player.actionTime;
|
|
|
|
Engine._actionInProgress = true;
|
|
|
|
Engine._actionProgressBarCount = 1;
|
|
|
|
Engine._actionProgressStr = "[ ]";
|
|
|
|
Engine._actionTimeStr = "Time left: ";
|
|
|
|
Player.startAction = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Counters
|
|
|
|
Engine.decrementAllCounters(numCycles);
|
|
|
|
Engine.checkCounters();
|
|
|
|
|
|
|
|
//Manual hacks
|
|
|
|
if (Engine._actionInProgress == true) {
|
|
|
|
Engine.updateHackProgress(numCycles);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update the running time of all active scripts
|
|
|
|
updateOnlineScriptTimes(numCycles);
|
2016-12-15 23:22:42 +01:00
|
|
|
},
|
2017-01-31 04:41:42 +01:00
|
|
|
|
2016-12-02 22:57:20 +01:00
|
|
|
//Counters for the main event loop. Represent the number of game cycles are required
|
|
|
|
//for something to happen.
|
|
|
|
Counters: {
|
2017-01-31 04:41:42 +01:00
|
|
|
autoSaveCounter: 300, //Autosave every minute
|
|
|
|
updateSkillLevelsCounter: 10, //Only update skill levels every 2 seconds. Might improve performance
|
|
|
|
updateDisplays: 10, //Update displays such as Active Scripts display and character display
|
|
|
|
serverGrowth: 450, //Process server growth every minute and a half
|
2016-12-02 22:57:20 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
decrementAllCounters: function(numCycles = 1) {
|
|
|
|
for (var counter in Engine.Counters) {
|
|
|
|
if (Engine.Counters.hasOwnProperty(counter)) {
|
|
|
|
Engine.Counters[counter] = Engine.Counters[counter] - numCycles;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//Checks if any counters are 0 and if they are, executes whatever
|
|
|
|
//is necessary and then resets the counter
|
|
|
|
checkCounters: function() {
|
|
|
|
if (Engine.Counters.autoSaveCounter <= 0) {
|
|
|
|
Engine.saveGame();
|
|
|
|
Engine.Counters.autoSaveCounter = 300;
|
|
|
|
}
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
if (Engine.Counters.updateSkillLevelsCounter <= 0) {
|
|
|
|
Player.updateSkillLevels();
|
|
|
|
Engine.Counters.updateSkillLevelsCounter = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Engine.Counters.updateDisplays <= 0) {
|
|
|
|
if (Engine.currentPage == Engine.Page.ActiveScripts) {
|
|
|
|
Engine.updateActiveScriptsItems();
|
|
|
|
} else if (Engine.currentPage == Engine.Page.CharacterInfo) {
|
|
|
|
Engine.displayCharacterInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
Engine.Counters.updateDisplays = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Engine.Counters.serverGrowth <= 0) {
|
|
|
|
var numCycles = Math.floor((450 - Engine.Counters.serverGrowth));
|
|
|
|
processServerGrowth(numCycles);
|
|
|
|
Engine.Counters.serverGrowth = 450;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Calculates the hack progress for a manual (non-scripted) hack and updates the progress bar/time accordingly */
|
|
|
|
_totalActionTime: 0,
|
|
|
|
_actionTimeLeft: 0,
|
|
|
|
_actionTimeStr: "Time left: ",
|
|
|
|
_actionProgressStr: "[ ]",
|
|
|
|
_actionProgressBarCount: 1,
|
|
|
|
_actionInProgress: false,
|
|
|
|
updateHackProgress: function(numCycles = 1) {
|
|
|
|
var timeElapsedMilli = numCycles * Engine._idleSpeed;
|
|
|
|
Engine._actionTimeLeft -= (timeElapsedMilli/ 1000); //Substract idle speed (ms)
|
|
|
|
|
|
|
|
//Calculate percent filled
|
|
|
|
var percent = Math.round((1 - Engine._actionTimeLeft / Engine._totalActionTime) * 100);
|
|
|
|
|
|
|
|
//Update progress bar
|
|
|
|
while (Engine._actionProgressBarCount * 2 <= percent) {
|
|
|
|
Engine._actionProgressStr = Engine._actionProgressStr.replaceAt(Engine._actionProgressBarCount, "|");
|
|
|
|
Engine._actionProgressBarCount += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update hack time remaining
|
|
|
|
Engine._actionTimeStr = "Time left: " + Math.max(0, Math.round(Engine._actionTimeLeft)).toString() + "s";
|
|
|
|
document.getElementById("hack-progress").innerHTML = Engine._actionTimeStr;
|
|
|
|
|
|
|
|
//Dynamically update progress bar
|
|
|
|
document.getElementById("hack-progress-bar").innerHTML = Engine._actionProgressStr.replace( / /g, " " );
|
|
|
|
|
|
|
|
//Once percent is 100, the hack is completed
|
|
|
|
if (percent >= 100) {
|
|
|
|
Engine._actionInProgress = false;
|
|
|
|
Terminal.finishAction();
|
|
|
|
}
|
2016-11-21 07:11:14 +01:00
|
|
|
},
|
2016-12-15 23:22:42 +01:00
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
/* Initialization */
|
2017-01-31 04:41:42 +01:00
|
|
|
init: function() {
|
|
|
|
//Initialization functions
|
|
|
|
if (Engine.loadSave()) {
|
|
|
|
console.log("Loaded game from save");
|
|
|
|
CompanyPositions.init();
|
2017-01-28 04:10:16 +01:00
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
//Calculate the number of cycles have elapsed while offline
|
|
|
|
var thisUpdate = new Date().getTime();
|
|
|
|
var lastUpdate = Player.lastUpdate;
|
|
|
|
var numCyclesOffline = Math.floor((thisUpdate - lastUpdate) / Engine._idleSpeed);
|
|
|
|
|
|
|
|
processServerGrowth(numCyclesOffline); //Should be done before offline production for scripts
|
|
|
|
loadAllRunningScripts(); //This also takes care of offline production for those scripts
|
|
|
|
} else {
|
|
|
|
//No save found, start new game
|
|
|
|
console.log("Initializing new game");
|
|
|
|
Player.init();
|
|
|
|
initForeignServers();
|
|
|
|
initCompanies();
|
|
|
|
initFactions();
|
2017-01-28 04:10:16 +01:00
|
|
|
CompanyPositions.init();
|
2017-01-31 04:41:42 +01:00
|
|
|
}
|
2016-12-14 00:52:32 +01:00
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
//Main menu buttons and content
|
|
|
|
Engine.Clickables.terminalMainMenuButton = document.getElementById("terminal-menu-link");
|
|
|
|
Engine.Clickables.terminalMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadTerminalContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.characterMainMenuButton = document.getElementById("character-menu-link");
|
|
|
|
Engine.Clickables.characterMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadCharacterContent();
|
|
|
|
return false;
|
|
|
|
});
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
Engine.Clickables.scriptEditorMainMenuButton = document.getElementById("create-script-menu-link");
|
|
|
|
Engine.Clickables.scriptEditorMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadScriptEditorContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.activeScriptsMainMenuButton = document.getElementById("active-scripts-menu-link");
|
2016-12-19 19:20:19 +01:00
|
|
|
Engine.Clickables.activeScriptsMainMenuButton.addEventListener("click", function() {
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.loadActiveScriptsContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.worldMainMenuButton = document.getElementById("world-menu-link");
|
|
|
|
Engine.Clickables.worldMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadWorldContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.createProgramMainMenuButton = document.getElementById("create-program-menu-link");
|
|
|
|
Engine.Clickables.createProgramMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadCreateProgramContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.factionsMainMenuButton = document.getElementById("factions-menu-link");
|
|
|
|
Engine.Clickables.factionsMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadFactionsContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.augmentationsMainMenuButton = document.getElementById("augmentations-menu-link");
|
|
|
|
Engine.Clickables.augmentationsMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadAugmentationsContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialMainMenuButton = document.getElementById("tutorial-menu-link");
|
|
|
|
Engine.Clickables.tutorialMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadTutorialContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
//Active scripts list
|
|
|
|
Engine.ActiveScriptsList = document.getElementById("active-scripts-list");
|
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link");
|
|
|
|
Engine.Clickables.saveMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.saveGame();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.deleteMainMenuButton = document.getElementById("delete-game-link");
|
|
|
|
Engine.Clickables.deleteMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.deleteSave();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
Engine.Display.terminalContent = document.getElementById("terminal-container");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.currentPage = Engine.Page.Terminal;
|
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
Engine.Display.characterContent = document.getElementById("character-container");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Display.characterContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.scriptEditorContent = document.getElementById("script-editor-container");
|
|
|
|
Engine.Display.scriptEditorContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.activeScriptsContent = document.getElementById("active-scripts-container");
|
|
|
|
Engine.Display.activeScriptsContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.worldContent = document.getElementById("world-container");
|
|
|
|
Engine.Display.worldContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.createProgramContent = document.getElementById("create-program-container");
|
|
|
|
Engine.Display.createProgramContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.factionsContent = document.getElementById("factions-container");
|
|
|
|
Engine.Display.factionsContent.style.visibility = "hidden";
|
2017-01-28 04:10:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
Engine.Display.factionContent = document.getElementById("faction-container");
|
|
|
|
Engine.Display.factionContent.style.visibility = "hidden";
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
Engine.Display.augmentationsContent = document.getElementById("augmentations-container");
|
|
|
|
Engine.Display.augmentationsContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.tutorialContent = document.getElementById("tutorial-container");
|
|
|
|
Engine.Display.tutorialContent.style.visibility = "hidden";
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Character info
|
|
|
|
Engine.Display.characterInfo = document.getElementById("character-info");
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
//Location lists
|
|
|
|
Engine.aevumLocationsList = document.getElementById("aevum-locations-list");
|
|
|
|
Engine.chongqingLocationsList = document.getElementById("chongqing-locations-list");
|
|
|
|
Engine.sector12LocationsList = document.getElementById("sector12-locations-list");
|
|
|
|
Engine.newTokyoLocationsList = document.getElementById("newtokyo-locations-list");
|
|
|
|
Engine.ishimaLocationsList = document.getElementById("ishima-locations-list");
|
|
|
|
Engine.volhavenLocationsList = document.getElementById("volhaven-locations-list");
|
|
|
|
|
|
|
|
//Location page (page that shows up when you visit a specific location in World)
|
|
|
|
Engine.Display.locationContent = document.getElementById("location-container");
|
|
|
|
Engine.Display.locationContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
//Script editor
|
|
|
|
Engine.Display.scriptEditorText = document.getElementById("script-editor-text");
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Message at the top of terminal
|
2017-01-31 04:41:42 +01:00
|
|
|
postNetburnerText();
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Run main loop
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.idleTimer();
|
|
|
|
|
|
|
|
runScriptsLoop();
|
|
|
|
}
|
2016-10-17 10:24:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
window.onload = function() {
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.init();
|
2016-10-17 10:24:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
|