2016-10-17 10:24:39 +02:00
|
|
|
var Engine = {
|
2017-01-31 04:41:42 +01:00
|
|
|
Debug: true,
|
2017-05-05 03:08:44 +02:00
|
|
|
|
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,
|
2017-04-27 22:02:58 +02:00
|
|
|
hacknetNodesMainMenuButton: null,
|
2017-01-31 04:41:42 +01:00
|
|
|
worldMainMenuButton: null,
|
|
|
|
createProgramMainMenuButton: null,
|
|
|
|
factionsMainMenuButton: null,
|
|
|
|
augmentationsMainMenuButton: null,
|
|
|
|
tutorialMainMenuButton: null,
|
|
|
|
saveMainMenuButton: null,
|
|
|
|
deleteMainMenuButton: null,
|
2017-03-31 23:47:06 +02:00
|
|
|
|
|
|
|
//Tutorial buttons
|
|
|
|
tutorialGettingStartedButton: null,
|
|
|
|
tutorialNetworkingButton: null,
|
|
|
|
tutorialHackingButton: null,
|
|
|
|
tutorialScriptsButton: null,
|
2017-05-07 00:19:18 +02:00
|
|
|
tutorialNetscriptButton: null,
|
2017-03-31 23:47:06 +02:00
|
|
|
tutorialTravelingButton: null,
|
|
|
|
tutorialJobsButton: null,
|
|
|
|
tutorialFactionsButton: null,
|
|
|
|
tutorialAugmentationsButton: null,
|
|
|
|
tutorialBackButton: 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-02-28 18:10:35 +01:00
|
|
|
terminalContent: null,
|
|
|
|
characterContent: null,
|
|
|
|
scriptEditorContent: null,
|
|
|
|
activeScriptsContent: null,
|
2017-04-27 22:02:58 +02:00
|
|
|
hacknetNodesContent: null,
|
2017-02-28 18:10:35 +01:00
|
|
|
worldContent: null,
|
|
|
|
createProgramContent: null,
|
|
|
|
factionsContent: null,
|
|
|
|
factionContent: null,
|
|
|
|
factionAugmentationsContent: null,
|
|
|
|
augmentationsContent: null,
|
|
|
|
tutorialContent: null,
|
|
|
|
locationContent: null,
|
|
|
|
workInProgressContent: null,
|
2016-10-17 10:24:39 +02:00
|
|
|
|
|
|
|
//Character info
|
2017-02-28 18:10:35 +01:00
|
|
|
characterInfo: null,
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
//Script editor text
|
2017-02-28 18:10:35 +01:00
|
|
|
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",
|
2017-04-27 22:02:58 +02:00
|
|
|
HacknetNodes: "HacknetNodes",
|
2017-01-31 04:41:42 +01:00
|
|
|
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",
|
2017-02-16 19:52:11 +01:00
|
|
|
workInProgress: "WorkInProgress",
|
2017-01-31 04:41:42 +01:00
|
|
|
},
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
2017-05-15 03:43:10 +02:00
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.currentPage = Engine.Page.ScriptEditor;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadActiveScriptsContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.activeScriptsContent.style.visibility = "visible";
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.ActiveScripts;
|
|
|
|
},
|
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
loadHacknetNodesContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.hacknetNodesContent.style.visibility = "visible";
|
|
|
|
displayHacknetNodesContent();
|
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.HacknetNodes;
|
|
|
|
},
|
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
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";
|
2017-02-28 22:20:37 +01:00
|
|
|
displayCreateProgramContent();
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.CreateProgram;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadFactionsContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.factionsContent.style.visibility = "visible";
|
2017-02-20 23:45:36 +01:00
|
|
|
Engine.displayFactionsInfo();
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
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";
|
2017-02-20 23:45:36 +01:00
|
|
|
Engine.displayAugmentationsContent();
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Augmentations;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadTutorialContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.tutorialContent.style.visibility = "visible";
|
2017-03-31 23:47:06 +02:00
|
|
|
Engine.displayTutorialContent();
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Tutorial;
|
|
|
|
},
|
|
|
|
|
|
|
|
loadLocationContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
Engine.Display.locationContent.style.visibility = "visible";
|
2017-01-31 05:43:33 +01:00
|
|
|
displayLocationContent();
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
Engine.currentPage = Engine.Page.Location;
|
|
|
|
},
|
2016-10-17 10:24:39 +02:00
|
|
|
|
2017-02-08 01:27:11 +01:00
|
|
|
loadWorkInProgressContent: function() {
|
|
|
|
Engine.hideAllContent();
|
|
|
|
|
|
|
|
var mainMenu = document.getElementById("mainmenu-container");
|
|
|
|
mainMenu.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.workInProgressContent.style.visibility = "visible";
|
|
|
|
|
2017-02-16 19:52:11 +01:00
|
|
|
Engine.currentPage = Engine.Page.WorkInProgress;
|
2017-02-08 01:27:11 +01:00
|
|
|
},
|
|
|
|
|
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";
|
2017-04-27 22:02:58 +02:00
|
|
|
Engine.Display.hacknetNodesContent.style.visibility = "hidden";
|
2017-01-31 04:41:42 +01:00
|
|
|
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-02-28 18:10:35 +01:00
|
|
|
Engine.Display.factionAugmentationsContent.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-02-08 01:27:11 +01:00
|
|
|
Engine.Display.workInProgressContent.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() {
|
2017-02-03 23:05:59 +01:00
|
|
|
var companyPosition = "";
|
|
|
|
if (Player.companyPosition != "") {
|
|
|
|
companyPosition = Player.companyPosition.positionName;
|
|
|
|
}
|
2017-05-04 22:50:17 +02:00
|
|
|
Engine.Display.characterInfo.innerHTML =
|
2017-05-05 03:08:44 +02:00
|
|
|
('<b>General</b><br><br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Current City: ' + Player.city + '<br><br>' +
|
|
|
|
'Employer: ' + Player.companyName + '<br>' +
|
|
|
|
'Job Title: ' + companyPosition + '<br><br>' +
|
|
|
|
'Money: $' + formatNumber(Player.money, 2)+ '<br><br><br>' +
|
|
|
|
'<b>Stats</b><br><br>' +
|
|
|
|
'Hacking Level: ' + (Player.hacking_skill).toLocaleString() +
|
|
|
|
" (" + formatNumber(Player.hacking_exp, 4) + ' experience)<br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Strength: ' + (Player.strength).toLocaleString() +
|
2017-05-04 22:50:17 +02:00
|
|
|
" (" + formatNumber(Player.strength_exp, 4) + ' experience)<br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Defense: ' + (Player.defense).toLocaleString() +
|
2017-05-04 22:50:17 +02:00
|
|
|
" (" + formatNumber(Player.defense_exp, 4) + ' experience)<br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Dexterity: ' + (Player.dexterity).toLocaleString() +
|
2017-05-04 22:50:17 +02:00
|
|
|
" (" + formatNumber(Player.dexterity_exp, 4) + ' experience)<br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Agility: ' + (Player.agility).toLocaleString() +
|
2017-05-04 22:50:17 +02:00
|
|
|
" (" + formatNumber(Player.agility_exp, 4) + ' experience)<br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Charisma: ' + (Player.charisma).toLocaleString() +
|
2017-05-04 22:50:17 +02:00
|
|
|
" (" + formatNumber(Player.charisma_exp, 4) + ' experience)<br><br><br>' +
|
|
|
|
'<b>Multipliers</b><br><br>' +
|
|
|
|
'Hacking Chance multiplier: ' + formatNumber(Player.hacking_chance_mult * 100, 2) + '%<br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Hacking Speed multiplier: ' + formatNumber(Player.hacking_speed_mult * 100, 2) + '%<br>' +
|
|
|
|
'Hacking money multiplier: ' + formatNumber(Player.hacking_money_mult * 100, 2) + '%<br><br>' +
|
|
|
|
'Hacking Level multiplier: ' + formatNumber(Player.hacking_mult * 100, 2) + '%<br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Hacking Experience multiplier: ' + formatNumber(Player.hacking_exp_mult * 100, 2) + '%<br><br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Strength Level multiplier: ' + formatNumber(Player.strength_mult * 100, 2) + '%<br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Strength Experience multiplier: ' + formatNumber(Player.strength_exp_mult * 100, 2) + '%<br><br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Defense Level multiplier: ' + formatNumber(Player.defense_mult * 100, 2) + '%<br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Defense Experience multiplier: ' + formatNumber(Player.defense_exp_mult * 100, 2) + '%<br><br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Dexterity Level multiplier: ' + formatNumber(Player.dexterity_mult * 100, 2) + '%<br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Dexterity Experience multiplier: ' + formatNumber(Player.dexterity_exp_mult * 100, 2) + '%<br><br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Agility Level multiplier: ' + formatNumber(Player.agility_mult * 100, 2) + '%<br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Agility Experience multiplier: ' + formatNumber(Player.agility_exp_mult * 100, 2) + '%<br><br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Charisma Level multiplier: ' + formatNumber(Player.charisma_mult * 100, 2) + '%<br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Charisma Experience multiplier: ' + formatNumber(Player.charisma_exp_mult * 100, 2) + '%<br><br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Hacknet Node production multiplier: ' + formatNumber(Player.hacknet_node_money_mult * 100, 2) + '%<br>' +
|
|
|
|
'Hacknet Node purchase cost multiplier: ' + formatNumber(Player.hacknet_node_purchase_cost_mult * 100, 2) + '%<br>' +
|
|
|
|
'Hacknet Node RAM upgrade cost multiplier: ' + formatNumber(Player.hacknet_node_ram_cost_mult * 100, 2) + '%<br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'Hacknet Node Core purchase cost multiplier: ' + formatNumber(Player.hacknet_node_core_cost_mult * 100, 2) + '%<br>' +
|
|
|
|
'Hacknet Node level upgrade cost multiplier: ' + formatNumber(Player.hacknet_node_level_cost_mult * 100, 2) + '%<br><br>' +
|
|
|
|
'Company reputation gain multiplier: ' + formatNumber(Player.company_rep_mult * 100, 2) + '%<br>' +
|
|
|
|
'Faction reputation gain multiplier: ' + formatNumber(Player.faction_rep_mult * 100, 2) + '%<br>' +
|
2017-05-12 20:12:32 +02:00
|
|
|
'Salary multiplier: ' + formatNumber(Player.work_money_mult * 100, 2) + '%<br>' +
|
|
|
|
'Crime money multiplier: ' + formatNumber(Player.crime_money_mult * 100, 2) + '%<br><br><br>' +
|
2017-05-04 22:50:17 +02:00
|
|
|
'<b>Misc</b><br><br>' +
|
2017-05-05 03:08:44 +02:00
|
|
|
'Servers owned: ' + Player.purchasedServers.length + '<br>' +
|
2017-05-15 16:15:59 +02:00
|
|
|
'Hacknet Nodes owned: ' + Player.hacknetNodes.length + '<br>' +
|
|
|
|
'Time played: ' + convertTimeMsToTimeElapsedString(Player.totalPlaytime) + '<br><br><br>').replace( / /g, " " );
|
2017-05-04 22:50:17 +02:00
|
|
|
|
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";
|
|
|
|
|
2017-05-06 21:12:45 +02:00
|
|
|
document.getElementById("world-city-name").innerHTML = Player.city;
|
|
|
|
var cityDesc = document.getElementById("world-city-desc"); //TODO
|
2017-01-31 04:41:42 +01:00
|
|
|
switch(Player.city) {
|
2017-05-06 21:12:45 +02:00
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
case Locations.Aevum:
|
|
|
|
Engine.aevumLocationsList.style.display = "inline";
|
|
|
|
break;
|
|
|
|
case Locations.Chongqing:
|
|
|
|
Engine.chongqingLocationsList.style.display = "inline";
|
|
|
|
break;
|
|
|
|
case Locations.Sector12:
|
|
|
|
Engine.sector12LocationsList.style.display = "inline";
|
|
|
|
break;
|
|
|
|
case Locations.NewTokyo:
|
|
|
|
Engine.newTokyoLocationsList.style.display = "inline";
|
|
|
|
break;
|
|
|
|
case Locations.Ishima:
|
|
|
|
Engine.ishimaLocationsList.style.display = "inline";
|
|
|
|
break;
|
|
|
|
case Locations.Volhaven:
|
|
|
|
Engine.volhavenLocationsList.style.display = "inline";
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
2017-02-20 23:45:36 +01:00
|
|
|
createActiveScriptsText: function(workerscript, item) {
|
2017-01-31 04:41:42 +01:00
|
|
|
//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
|
2017-05-04 22:50:17 +02:00
|
|
|
var onlineTotalMoneyMade = "Total online production: $" + formatNumber(workerscript.scriptRef.onlineMoneyMade, 2);
|
|
|
|
var onlineTotalExpEarned = (Array(26).join(" ") + formatNumber(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
2017-03-31 23:47:06 +02:00
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
2017-05-04 22:50:17 +02:00
|
|
|
var onlineMpsText = "Online production rate: $" + formatNumber(onlineMps, 2) + "/second";
|
2017-01-31 04:41:42 +01:00
|
|
|
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
2017-05-04 22:50:17 +02:00
|
|
|
var onlineEpsText = (Array(25).join(" ") + formatNumber(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
//Offline
|
2017-05-04 22:50:17 +02:00
|
|
|
var offlineTotalMoneyMade = "Total offline production: $" + formatNumber(workerscript.scriptRef.offlineMoneyMade, 2);
|
|
|
|
var offlineTotalExpEarned = (Array(27).join(" ") + formatNumber(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
2017-03-31 23:47:06 +02:00
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
2017-05-04 22:50:17 +02:00
|
|
|
var offlineMpsText = "Offline production rate: $" + formatNumber(offlineMps, 2) + "/second";
|
2017-01-31 04:41:42 +01:00
|
|
|
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
2017-05-04 22:50:17 +02:00
|
|
|
var offlineEpsText = (Array(26).join(" ") + formatNumber(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
2017-01-31 04:41:42 +01:00
|
|
|
|
2017-03-31 23:47:06 +02:00
|
|
|
itemText.innerHTML = serverIpHostname + "<br>" + onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
|
|
|
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
|
|
|
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
item.appendChild(itemText);
|
|
|
|
},
|
|
|
|
|
2017-02-20 23:45:36 +01:00
|
|
|
displayFactionsInfo: function() {
|
|
|
|
var factionsList = document.getElementById("factions-list");
|
|
|
|
|
2017-04-19 07:02:40 +02:00
|
|
|
//Clear the list
|
|
|
|
while (factionsList.firstChild) {
|
|
|
|
factionsList.removeChild(factionsList.firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Re-add a link for each faction you are a member of
|
2017-02-20 23:45:36 +01:00
|
|
|
for (var i = 0; i < Player.factions.length; ++i) {
|
2017-05-04 21:29:50 +02:00
|
|
|
(function () {
|
|
|
|
var factionName = Player.factions[i];
|
|
|
|
|
|
|
|
//Add the faction to the Factions page content
|
|
|
|
var item = document.createElement("li");
|
|
|
|
var aElem = document.createElement("a");
|
|
|
|
aElem.setAttribute("href", "#");
|
|
|
|
aElem.setAttribute("class", "a-link-button");
|
|
|
|
aElem.innerHTML = factionName;
|
|
|
|
aElem.addEventListener("click", function() {
|
|
|
|
console.log("factionName:" + factionName)
|
|
|
|
Engine.loadFactionContent();
|
|
|
|
displayFactionContent(factionName);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
item.appendChild(aElem);
|
|
|
|
|
|
|
|
factionsList.appendChild(item);
|
|
|
|
}()); //Immediate invocation
|
2017-02-20 23:45:36 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
displayAugmentationsContent: function() {
|
|
|
|
var augmentationsList = document.getElementById("augmentations-list");
|
|
|
|
|
2017-05-05 20:13:31 +02:00
|
|
|
while (augmentationsList.firstChild) {
|
|
|
|
augmentationsList.removeChild(augmentationsList.firstChild);
|
|
|
|
}
|
|
|
|
|
2017-02-20 23:45:36 +01:00
|
|
|
for (var i = 0; i < Player.augmentations.length; ++i) {
|
|
|
|
var augName = Player.augmentations[i];
|
|
|
|
var aug = Augmentations[augName];
|
|
|
|
|
|
|
|
|
|
|
|
var item = document.createElement("li");
|
|
|
|
var hElem = document.createElement("h2");
|
|
|
|
var pElem = document.createElement("p");
|
|
|
|
|
|
|
|
item.setAttribute("class", "installed-augmentation");
|
|
|
|
hElem.innerHTML = augName;
|
2017-05-07 12:04:54 +02:00
|
|
|
if (augName == AugmentationNames.NeuroFluxGovernor) {
|
2017-05-08 18:00:34 +02:00
|
|
|
hElem.innerHTML += " - Level " + (aug.level);
|
2017-05-07 12:04:54 +02:00
|
|
|
}
|
2017-02-20 23:45:36 +01:00
|
|
|
pElem.innerHTML = aug.info;
|
|
|
|
|
|
|
|
item.appendChild(hElem);
|
|
|
|
item.appendChild(pElem);
|
|
|
|
|
|
|
|
augmentationsList.appendChild(item);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-31 23:47:06 +02:00
|
|
|
displayTutorialContent: function() {
|
|
|
|
Engine.Clickables.tutorialGettingStartedButton.style.display = "block";
|
|
|
|
Engine.Clickables.tutorialNetworkingButton.style.display = "block";
|
|
|
|
Engine.Clickables.tutorialHackingButton.style.display = "block";
|
|
|
|
Engine.Clickables.tutorialScriptsButton.style.display = "block";
|
2017-05-07 00:19:18 +02:00
|
|
|
Engine.Clickables.tutorialNetscriptButton.style.display = "block";
|
2017-03-31 23:47:06 +02:00
|
|
|
Engine.Clickables.tutorialTravelingButton.style.display = "block";
|
|
|
|
Engine.Clickables.tutorialJobsButton.style.display = "block";
|
|
|
|
Engine.Clickables.tutorialFactionsButton.style.display = "block";
|
|
|
|
Engine.Clickables.tutorialAugmentationsButton.style.display = "block";
|
|
|
|
|
2017-04-13 19:33:34 +02:00
|
|
|
Engine.Clickables.tutorialBackButton.style.display = "none";
|
2017-03-31 23:47:06 +02:00
|
|
|
document.getElementById("tutorial-text").style.display = "none";
|
|
|
|
},
|
|
|
|
|
|
|
|
//Displays the text when a section of the Tutorial is opened
|
|
|
|
displayTutorialPage: function(text) {
|
|
|
|
Engine.Clickables.tutorialGettingStartedButton.style.display = "none";
|
|
|
|
Engine.Clickables.tutorialNetworkingButton.style.display = "none";
|
|
|
|
Engine.Clickables.tutorialHackingButton.style.display = "none";
|
|
|
|
Engine.Clickables.tutorialScriptsButton.style.display = "none";
|
2017-05-07 00:19:18 +02:00
|
|
|
Engine.Clickables.tutorialNetscriptButton.style.display = "none";
|
2017-03-31 23:47:06 +02:00
|
|
|
Engine.Clickables.tutorialTravelingButton.style.display = "none";
|
|
|
|
Engine.Clickables.tutorialJobsButton.style.display = "none";
|
|
|
|
Engine.Clickables.tutorialFactionsButton.style.display = "none";
|
|
|
|
Engine.Clickables.tutorialAugmentationsButton.style.display = "none";
|
|
|
|
|
2017-04-13 19:33:34 +02:00
|
|
|
Engine.Clickables.tutorialBackButton.style.display = "inline-block";
|
2017-03-31 23:47:06 +02:00
|
|
|
document.getElementById("tutorial-text").style.display = "block";
|
|
|
|
document.getElementById("tutorial-text").innerHTML = text;
|
|
|
|
},
|
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
/* 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) {
|
2017-05-15 16:15:59 +02:00
|
|
|
//Update total playtime
|
|
|
|
var time = numCycles * Engine._idleSpeed;
|
|
|
|
if (Player.totalPlaytime == null) {Player.totalPlaytime = 0;}
|
|
|
|
Player.totalPlaytime += time;
|
|
|
|
|
2017-02-08 05:48:50 +01:00
|
|
|
//Start 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;
|
|
|
|
}
|
|
|
|
|
2017-04-24 21:10:35 +02:00
|
|
|
//Working
|
2017-02-06 06:01:01 +01:00
|
|
|
if (Player.isWorking) {
|
2017-04-24 21:10:35 +02:00
|
|
|
if (Player.workType == CONSTANTS.WorkTypeFaction) {
|
2017-04-13 22:21:03 +02:00
|
|
|
Player.workForFaction(numCycles);
|
2017-04-24 21:10:35 +02:00
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
|
2017-04-13 22:21:03 +02:00
|
|
|
Player.createProgramWork(numCycles);
|
2017-04-24 21:10:35 +02:00
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeStudyClass) {
|
2017-05-04 07:27:22 +02:00
|
|
|
Player.takeClass(numCycles);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCrime) {
|
|
|
|
Player.commitCrime(numCycles);
|
2017-05-10 22:21:15 +02:00
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) {
|
|
|
|
Player.workPartTime(numCycles);
|
2017-04-13 22:21:03 +02:00
|
|
|
} else {
|
|
|
|
Player.work(numCycles);
|
|
|
|
}
|
2017-02-06 06:01:01 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
//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);
|
2017-04-27 22:02:58 +02:00
|
|
|
|
|
|
|
//Hacknet Nodes
|
|
|
|
processAllHacknetNodeEarnings(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
|
2017-02-16 19:52:11 +01:00
|
|
|
updateSkillLevelsCounter: 10, //Only update skill levels every 2 seconds. Might improve performance
|
2017-05-04 07:27:22 +02:00
|
|
|
updateDisplays: 3, //Update displays such as Active Scripts display and character display
|
2017-05-05 18:52:48 +02:00
|
|
|
createProgramNotifications: 10, //Checks whether any programs can be created and notifies
|
2017-02-16 19:52:11 +01:00
|
|
|
serverGrowth: 450, //Process server growth every minute and a half
|
2017-04-19 21:19:33 +02:00
|
|
|
checkFactionInvitations: 1500, //Check whether you qualify for any faction invitations every 5 minutes
|
2017-05-04 07:05:48 +02:00
|
|
|
passiveFactionGrowth: 600,
|
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) {
|
2017-05-05 03:08:44 +02:00
|
|
|
saveObject.saveGame();
|
2016-12-02 22:57:20 +01:00
|
|
|
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();
|
2017-04-27 22:02:58 +02:00
|
|
|
} else if (Engine.currentPage == Engine.Page.HacknetNodes) {
|
|
|
|
updateHacknetNodesContent();
|
2017-05-12 20:12:32 +02:00
|
|
|
} else if (Engine.currentPage == Engine.Page.CreateProgram) {
|
|
|
|
displayCreateProgramContent();
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
2017-01-31 04:41:42 +01:00
|
|
|
|
2017-05-04 07:27:22 +02:00
|
|
|
Engine.Counters.updateDisplays = 3;
|
2017-01-31 04:41:42 +01:00
|
|
|
}
|
|
|
|
|
2017-05-05 18:52:48 +02:00
|
|
|
if (Engine.Counters.createProgramNotifications <= 0) {
|
|
|
|
var num = getNumAvailableCreateProgram();
|
|
|
|
var elem = document.getElementById("create-program-notification");
|
|
|
|
if (num > 0) {
|
|
|
|
elem.innerHTML = num;
|
|
|
|
elem.setAttribute("class", "notification-on");
|
|
|
|
} else {
|
|
|
|
elem.innerHTML = "";
|
|
|
|
elem.setAttribute("class", "notification-off");
|
|
|
|
}
|
|
|
|
Engine.Counters.createProgramNotifications = 10;
|
|
|
|
}
|
|
|
|
|
2017-01-31 04:41:42 +01:00
|
|
|
if (Engine.Counters.serverGrowth <= 0) {
|
|
|
|
var numCycles = Math.floor((450 - Engine.Counters.serverGrowth));
|
|
|
|
processServerGrowth(numCycles);
|
|
|
|
Engine.Counters.serverGrowth = 450;
|
|
|
|
}
|
2017-02-16 19:52:11 +01:00
|
|
|
|
|
|
|
if (Engine.Counters.checkFactionInvitations <= 0) {
|
|
|
|
var invitedFactions = Player.checkForFactionInvitations();
|
|
|
|
if (invitedFactions.length > 0) {
|
|
|
|
var randFaction = invitedFactions[Math.floor(Math.random() * invitedFactions.length)];
|
|
|
|
inviteToFaction(randFaction);
|
|
|
|
}
|
|
|
|
Engine.Counters.checkFactionInvitations = 1500;
|
|
|
|
}
|
2017-05-04 07:05:48 +02:00
|
|
|
|
|
|
|
if (Engine.Counters.passiveFactionGrowth <= 0) {
|
|
|
|
var adjustedCycles = Math.floor((600 - Engine.Counters.passiveFactionGrowth));
|
|
|
|
processPassiveFactionRepGain(adjustedCycles);
|
|
|
|
Engine.Counters.passiveFactionGrowth = 600;
|
|
|
|
}
|
2017-01-31 04:41:42 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/* 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)
|
2017-04-18 06:32:17 +02:00
|
|
|
Engine._actionTimeLeft = Math.max(Engine._actionTimeLeft, 0);
|
2017-01-31 04:41:42 +01:00
|
|
|
|
|
|
|
//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
|
|
|
|
2017-05-05 23:27:35 +02:00
|
|
|
load: function() {
|
|
|
|
//Load game from save or create new game
|
|
|
|
if (loadGame(saveObject)) {
|
|
|
|
console.log("Loaded game from save");
|
|
|
|
Engine.setDisplayElements(); //Sets variables for important DOM elements
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.init(); //Initialize buttons, work, etc.
|
|
|
|
Engine.start(); //Run main game loop and Scripts loop
|
2017-05-05 23:27:35 +02:00
|
|
|
CompanyPositions.init();
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
|
|
/* Process offline progress */
|
|
|
|
processServerGrowth(numCyclesOffline); //Should be done before offline production for scripts
|
|
|
|
loadAllRunningScripts(); //This also takes care of offline production for those scripts
|
|
|
|
if (Player.isWorking) {
|
|
|
|
if (Player.workType == CONSTANTS.WorkTypeFaction) {
|
|
|
|
Player.workForFaction(numCyclesOffline);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
|
|
|
|
Player.createProgramWork(numCyclesOffline);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeStudyClass) {
|
|
|
|
Player.takeClass(numCyclesOffline);
|
2017-05-10 22:21:15 +02:00
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCrime) {
|
|
|
|
Player.commitCrime(numCyclesOffline);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) {
|
2017-05-12 20:52:02 +02:00
|
|
|
Player.workPartTime(numCyclesOffline);
|
2017-05-05 23:27:35 +02:00
|
|
|
} else {
|
|
|
|
Player.work(numCyclesOffline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Hacknet Nodes offline progress
|
|
|
|
processAllHacknetNodeEarnings(numCyclesOffline);
|
|
|
|
|
|
|
|
//Passive faction rep gain offline
|
|
|
|
processPassiveFactionRepGain(numCyclesOffline);
|
|
|
|
} else {
|
|
|
|
//No save found, start new game
|
|
|
|
console.log("Initializing new game");
|
2017-05-07 12:04:54 +02:00
|
|
|
SpecialServerIps = new SpecialServerIpsMap();
|
2017-05-05 23:27:35 +02:00
|
|
|
Engine.setDisplayElements(); //Sets variables for important DOM elements
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.start(); //Run main game loop and Scripts loop
|
2017-05-05 23:27:35 +02:00
|
|
|
Player.init();
|
|
|
|
initForeignServers();
|
|
|
|
initCompanies();
|
|
|
|
initFactions();
|
|
|
|
CompanyPositions.init();
|
|
|
|
initAugmentations();
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Start interactive tutorial
|
|
|
|
iTutorialStart();
|
2017-05-05 23:27:35 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setDisplayElements: function() {
|
|
|
|
//Content elements
|
|
|
|
Engine.Display.terminalContent = document.getElementById("terminal-container");
|
|
|
|
Engine.currentPage = Engine.Page.Terminal;
|
|
|
|
|
|
|
|
Engine.Display.characterContent = document.getElementById("character-container");
|
|
|
|
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.hacknetNodesContent = document.getElementById("hacknet-nodes-container");
|
|
|
|
Engine.Display.hacknetNodesContent.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";
|
|
|
|
|
|
|
|
|
|
|
|
Engine.Display.factionContent = document.getElementById("faction-container");
|
|
|
|
Engine.Display.factionContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
Engine.Display.factionAugmentationsContent = document.getElementById("faction-augmentations-container");
|
|
|
|
Engine.Display.factionAugmentationsContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
//Character info
|
|
|
|
Engine.Display.characterInfo = document.getElementById("character-info");
|
|
|
|
|
|
|
|
//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";
|
|
|
|
|
|
|
|
//Work In Progress
|
|
|
|
Engine.Display.workInProgressContent = document.getElementById("work-in-progress-container");
|
|
|
|
Engine.Display.workInProgressContent.style.visibility = "hidden";
|
|
|
|
|
|
|
|
//Init Location buttons
|
|
|
|
initLocationButtons();
|
|
|
|
|
|
|
|
//Script editor
|
|
|
|
Engine.Display.scriptEditorText = document.getElementById("script-editor-text");
|
2017-05-06 08:24:01 +02:00
|
|
|
|
|
|
|
//Tutorial buttons
|
|
|
|
Engine.Clickables.tutorialGettingStartedButton = document.getElementById("tutorial-getting-started-link");
|
|
|
|
Engine.Clickables.tutorialGettingStartedButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialGettingStartedText);
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialNetworkingButton = document.getElementById("tutorial-networking-link");
|
|
|
|
Engine.Clickables.tutorialNetworkingButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialNetworkingText);
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialHackingButton = document.getElementById("tutorial-hacking-link");
|
|
|
|
Engine.Clickables.tutorialHackingButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialHackingText);
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialScriptsButton = document.getElementById("tutorial-scripts-link");
|
|
|
|
Engine.Clickables.tutorialScriptsButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialScriptsText);
|
|
|
|
});
|
|
|
|
|
2017-05-07 00:19:18 +02:00
|
|
|
Engine.Clickables.tutorialNetscriptButton = document.getElementById("tutorial-netscript-link");
|
|
|
|
Engine.Clickables.tutorialNetscriptButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialNetscriptText);
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.tutorialTravelingButton = document.getElementById("tutorial-traveling-link");
|
|
|
|
Engine.Clickables.tutorialTravelingButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialTravelingText);
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialJobsButton = document.getElementById("tutorial-jobs-link");
|
|
|
|
Engine.Clickables.tutorialJobsButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialJobsText);
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialFactionsButton = document.getElementById("tutorial-factions-link");
|
|
|
|
Engine.Clickables.tutorialFactionsButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialFactionsText);
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialAugmentationsButton = document.getElementById("tutorial-augmentations-link");
|
|
|
|
Engine.Clickables.tutorialAugmentationsButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialAugmentationsText);
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.tutorialBackButton = document.getElementById("tutorial-back-button");
|
|
|
|
Engine.Clickables.tutorialBackButton.addEventListener("click", function() {
|
|
|
|
Engine.displayTutorialContent();
|
|
|
|
});
|
2017-05-06 21:12:45 +02:00
|
|
|
|
|
|
|
//If DarkWeb already purchased, disable the button
|
|
|
|
if (SpecialServerIps.hasOwnProperty("Darkweb Server")) {
|
|
|
|
document.getElementById("location-purchase-tor").setAttribute("class", "a-link-button-inactive");
|
|
|
|
}
|
2017-05-06 08:24:01 +02:00
|
|
|
},
|
2017-05-05 23:27:35 +02:00
|
|
|
|
2016-10-17 10:24:39 +02:00
|
|
|
/* Initialization */
|
2017-01-31 04:41:42 +01:00
|
|
|
init: function() {
|
2016-10-17 10:24:39 +02:00
|
|
|
//Main menu buttons and content
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.terminalMainMenuButton = clearEventListeners("terminal-menu-link");
|
2016-10-17 10:24:39 +02:00
|
|
|
Engine.Clickables.terminalMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadTerminalContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.characterMainMenuButton = clearEventListeners("character-menu-link");
|
2016-10-17 10:24:39 +02:00
|
|
|
Engine.Clickables.characterMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadCharacterContent();
|
|
|
|
return false;
|
|
|
|
});
|
2017-01-31 04:41:42 +01:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.scriptEditorMainMenuButton = clearEventListeners("create-script-menu-link");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Clickables.scriptEditorMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadScriptEditorContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.activeScriptsMainMenuButton = clearEventListeners("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;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.hacknetNodesMainMenuButton = clearEventListeners("hacknet-nodes-menu-link");
|
2017-04-27 22:02:58 +02:00
|
|
|
Engine.Clickables.hacknetNodesMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadHacknetNodesContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.worldMainMenuButton = clearEventListeners("world-menu-link");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Clickables.worldMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadWorldContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.createProgramMainMenuButton = clearEventListeners("create-program-menu-link");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Clickables.createProgramMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadCreateProgramContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.factionsMainMenuButton = clearEventListeners("factions-menu-link");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Clickables.factionsMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadFactionsContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.augmentationsMainMenuButton = clearEventListeners("augmentations-menu-link");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Clickables.augmentationsMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadAugmentationsContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
Engine.Clickables.tutorialMainMenuButton = clearEventListeners("tutorial-menu-link");
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.Clickables.tutorialMainMenuButton.addEventListener("click", function() {
|
|
|
|
Engine.loadTutorialContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
//Active scripts list
|
|
|
|
Engine.ActiveScriptsList = document.getElementById("active-scripts-list");
|
|
|
|
|
2017-05-05 18:52:48 +02:00
|
|
|
//Save and Delete buttons
|
2016-12-01 23:18:18 +01:00
|
|
|
Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link");
|
|
|
|
Engine.Clickables.saveMainMenuButton.addEventListener("click", function() {
|
2017-05-05 03:08:44 +02:00
|
|
|
saveObject.saveGame();
|
2016-12-01 23:18:18 +01:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Engine.Clickables.deleteMainMenuButton = document.getElementById("delete-game-link");
|
|
|
|
Engine.Clickables.deleteMainMenuButton.addEventListener("click", function() {
|
2017-05-05 03:08:44 +02:00
|
|
|
saveObject.deleteGame();
|
2016-12-01 23:18:18 +01:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-15 04:21:22 +02:00
|
|
|
|
|
|
|
//Script Editor Netscript documentation button
|
|
|
|
var netscriptDocButton = document.getElementById("script-editor-netscript-doc-button");
|
|
|
|
netscriptDocButton.addEventListener("click", function() {
|
|
|
|
Engine.loadTutorialContent();
|
|
|
|
Engine.displayTutorialContent();
|
|
|
|
Engine.displayTutorialPage(CONSTANTS.TutorialNetscriptText);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-05-05 18:52:48 +02:00
|
|
|
//Create Program buttons
|
2017-05-08 16:33:26 +02:00
|
|
|
var portHackALink = document.getElementById("create-program-nuke");
|
2017-05-05 18:52:48 +02:00
|
|
|
var bruteSshALink = document.getElementById("create-program-brutessh");
|
|
|
|
var ftpCrackALink = document.getElementById("create-program-ftpcrack");
|
|
|
|
var relaySmtpALink = document.getElementById("create-program-relaysmtp");
|
|
|
|
var httpWormALink = document.getElementById("create-program-httpworm");
|
|
|
|
var sqlInjectALink = document.getElementById("create-program-sqlinject");
|
|
|
|
portHackALink.addEventListener("click", function() {
|
|
|
|
createProgram(Programs.PortHackProgram, CONSTANTS.MillisecondsPerQuarterHour);
|
|
|
|
});
|
|
|
|
bruteSshALink.addEventListener("click", function() {
|
|
|
|
Player.startCreateProgramWork(Programs.BruteSSHProgram, CONSTANTS.MillisecondsPerQuarterHour);
|
|
|
|
});
|
|
|
|
ftpCrackALink.addEventListener("click", function() {
|
|
|
|
Player.startCreateProgramWork(Programs.FTPCrackProgram, CONSTANTS.MillisecondsPerHalfHour);
|
|
|
|
});
|
|
|
|
relaySmtpALink.addEventListener("click", function() {
|
|
|
|
Player.startCreateProgramWork(Programs.RelaySMTPProgram. CONSTANTS.MillisecondsPer2Hours);
|
|
|
|
});
|
|
|
|
httpWormALink.addEventListener("click", function() {
|
|
|
|
Player.startCreateProgramWork(Programs.HTTPWormProgram, CONSTANTS.MillisecondsPer4Hours);
|
|
|
|
});
|
|
|
|
sqlInjectALink.addEventListener("click", function() {
|
|
|
|
Player.startCreateProgramWork(Programs.SQLInjectProgram, CONSTANTS.MillisecondsPer8Hours);
|
|
|
|
});
|
2017-02-16 19:52:11 +01:00
|
|
|
|
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
|
|
|
|
2017-05-10 22:21:15 +02:00
|
|
|
//Player was working cancel button
|
2017-02-16 19:52:11 +01:00
|
|
|
if (Player.isWorking) {
|
|
|
|
var cancelButton = document.getElementById("work-in-progress-cancel-button");
|
|
|
|
cancelButton.addEventListener("click", function() {
|
2017-04-24 21:10:35 +02:00
|
|
|
if (Player.workType == CONSTANTS.WorkTypeFaction) {
|
2017-04-24 03:43:41 +02:00
|
|
|
var fac = Factions[Player.currentWorkFactionName];
|
|
|
|
Player.finishFactionWork(true, fac);
|
2017-05-15 17:28:59 +02:00
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
|
2017-04-24 03:43:41 +02:00
|
|
|
Player.finishCreateProgramWork(true, Player.createProgramName);
|
2017-04-24 21:10:35 +02:00
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeStudyClass) {
|
|
|
|
Player.finishClass();
|
2017-05-10 22:21:15 +02:00
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCrime) {
|
|
|
|
Player.finishCrime(true);
|
|
|
|
} else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) {
|
|
|
|
Player.finishWorkPartTime();
|
2017-04-24 03:43:41 +02:00
|
|
|
} else {
|
|
|
|
Player.finishWork(true);
|
|
|
|
}
|
2017-02-16 19:52:11 +01:00
|
|
|
});
|
|
|
|
Engine.loadWorkInProgressContent();
|
|
|
|
}
|
2017-05-15 16:15:59 +02:00
|
|
|
|
|
|
|
//DEBUG
|
|
|
|
document.getElementById("debug-delete-scripts-link").addEventListener("click", function() {
|
|
|
|
Player.getHomeComputer().runningScripts = [];
|
|
|
|
return false;
|
|
|
|
});
|
2017-05-06 08:24:01 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
start: function() {
|
2016-10-17 10:24:39 +02:00
|
|
|
//Run main loop
|
2017-01-31 04:41:42 +01:00
|
|
|
Engine.idleTimer();
|
|
|
|
|
2017-02-16 19:52:11 +01:00
|
|
|
//Scripts
|
2017-01-31 04:41:42 +01:00
|
|
|
runScriptsLoop();
|
|
|
|
}
|
2016-10-17 10:24:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
window.onload = function() {
|
2017-05-05 23:27:35 +02:00
|
|
|
Engine.load();
|
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
|
|
|
|