mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 05:33:54 +01:00
Continue statement, began work on missions
This commit is contained in:
parent
796614bc41
commit
c93a398fbf
90
css/missions.css
Normal file
90
css/missions.css
Normal file
@ -0,0 +1,90 @@
|
||||
/* css for Missions */
|
||||
|
||||
/* Hacking missions */
|
||||
|
||||
.hack-mission-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 7% 7% 7% 7% 7% 7% 7% 7%;
|
||||
grid-template-rows: 7% 7% 7% 7% 7% 7% 7% 7%;
|
||||
grid-gap: 3%;
|
||||
height: 100%;
|
||||
position:fixed;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.hack-mission-node {
|
||||
color:gray;
|
||||
z-index:5;
|
||||
background-color:gray;
|
||||
align-self: center;
|
||||
justify-self: center;
|
||||
}
|
||||
|
||||
.hack-mission-node p {
|
||||
color:white;
|
||||
font-size:12px;
|
||||
margin-top: 8px;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.hack-mission-player-node {
|
||||
color:blue;
|
||||
background-color:blue;
|
||||
}
|
||||
|
||||
.hack-mission-player-node:hover,
|
||||
.hack-mission-player-node-active {
|
||||
border: 2px solid white;
|
||||
color: #6666ff;
|
||||
background-color: #6666ff;
|
||||
}
|
||||
|
||||
.hack-mission-enemy-node {
|
||||
color:red;
|
||||
background-color:red;
|
||||
}
|
||||
|
||||
.hack-mission-cpu-node {
|
||||
width:100%;
|
||||
height:100%;
|
||||
-moz-border-radius: 50%;
|
||||
-webkit-border-radius: 50%;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.hack-mission-firewall-node {
|
||||
width:100%;
|
||||
height:75%;
|
||||
}
|
||||
|
||||
.hack-mission-database-node {
|
||||
width: 100%;
|
||||
height: 75%;
|
||||
-webkit-transform: skew(20deg);
|
||||
-moz-transform: skew(20deg);
|
||||
-o-transform: skew(20deg);
|
||||
}
|
||||
|
||||
.hack-mission-database-node p {
|
||||
-webkit-transform: skew(-20deg);
|
||||
-moz-transform: skew(-20deg);
|
||||
-o-transform: skew(-20deg);
|
||||
}
|
||||
|
||||
.hack-mission-spam-node,
|
||||
.hack-mission-transfer-node,
|
||||
.hack-mission-shield-node {
|
||||
height:100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Non-map related DOM elements */
|
||||
|
||||
/* Element at the top of the Hacking Mission page (intro page, start button, guide buttons, etc.) */
|
||||
.hack-mission-header-element {
|
||||
margin: 6px;
|
||||
}
|
||||
|
||||
.hack-mission-action-buttons-container {
|
||||
border: 2px solid white;
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
/* Both Work in progress and BitNode stuff */
|
||||
#generic-fullscreen-container {
|
||||
.generic-fullscreen-container {
|
||||
color: var(--my-font-color);
|
||||
padding-top: 10px;
|
||||
padding-left: 10px;
|
||||
margin: 10px;
|
||||
height: 100%;
|
||||
width: 99%;
|
||||
}
|
||||
|
||||
|
15974
dist/bundle.js
vendored
15974
dist/bundle.js
vendored
File diff suppressed because it is too large
Load Diff
12
index.html
12
index.html
@ -10,6 +10,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="css/popupboxes.css" />
|
||||
<link rel="stylesheet" type="text/css" href="css/interactivetutorial.css" />
|
||||
<link rel="stylesheet" type="text/css" href="css/loader.css" />
|
||||
<link rel="stylesheet" type="text/css" href="css/missions.css" />
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
@ -509,6 +510,17 @@
|
||||
use your terminal or create scripts when you are performing a task! <br><br><br><br>
|
||||
</p>
|
||||
|
||||
<div id="faction-hack-mission-div" class="faction-work-div">
|
||||
<div id="faction-hack-mission-div-wrapper" class="faction-work-div-wrapper">
|
||||
<a id="faction-hack-mission-button" class="a-link-button">Hacking Mission</a>
|
||||
<p id="faction-hack-mission-text">
|
||||
Attempt a hacking mission for your faction.
|
||||
A mission is a mini game that, if won, earns you significant reputation with this faction.
|
||||
</p>
|
||||
</div>
|
||||
<div class="faction-clear"></div>
|
||||
</div>
|
||||
|
||||
<div id="faction-hack-div" class="faction-work-div">
|
||||
<div id="faction-hack-div-wrapper" class="faction-work-div-wrapper">
|
||||
<a id="faction-hack-button" class="a-link-button">Hacking Contracts</a>
|
||||
|
@ -200,45 +200,26 @@ function updateActiveScriptsItemContent(workerscript) {
|
||||
var itemName = itemNameArray.join("-");
|
||||
var itemContent = document.getElementById(itemName + "-content")
|
||||
|
||||
//Clear the item
|
||||
while (itemContent.firstChild) {
|
||||
itemContent.removeChild(itemContent.firstChild);
|
||||
}
|
||||
|
||||
//Add the updated text back. Returns the total online production rate
|
||||
return createActiveScriptsText(workerscript, itemContent);
|
||||
return updateActiveScriptsText(workerscript, itemContent);
|
||||
}
|
||||
|
||||
function createActiveScriptsText(workerscript, item) {
|
||||
var itemText = document.createElement("p");
|
||||
var itemTextHeader = document.createElement("p");
|
||||
var itemTextStats = document.createElement("p");
|
||||
var itemId = item.id;
|
||||
itemTextStats.setAttribute("id", itemId + "-stats");
|
||||
|
||||
//Server ip/hostname
|
||||
var threads = "Threads: " + workerscript.scriptRef.threads;
|
||||
var args = "Args: " + printArray(workerscript.args);
|
||||
|
||||
//Online
|
||||
var onlineTotalMoneyMade = "Total online production: $" + formatNumber(workerscript.scriptRef.onlineMoneyMade, 2);
|
||||
var onlineTotalExpEarned = (Array(26).join(" ") + formatNumber(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
itemTextHeader.innerHTML = threads + "<br>" + args + "<br>";
|
||||
|
||||
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineMpsText = "Online production rate: $" + formatNumber(onlineMps, 2) + "/second";
|
||||
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineEpsText = (Array(25).join(" ") + formatNumber(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
item.appendChild(itemTextHeader);
|
||||
item.appendChild(itemTextStats);
|
||||
|
||||
//Offline
|
||||
var offlineTotalMoneyMade = "Total offline production: $" + formatNumber(workerscript.scriptRef.offlineMoneyMade, 2);
|
||||
var offlineTotalExpEarned = (Array(27).join(" ") + formatNumber(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineMpsText = "Offline production rate: $" + formatNumber(offlineMps, 2) + "/second";
|
||||
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineEpsText = (Array(26).join(" ") + formatNumber(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
itemText.innerHTML = threads + "<br>" + args + "<br>" + onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
||||
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
||||
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
||||
|
||||
item.appendChild(itemText);
|
||||
var onlineMps = updateActiveScriptsText(workerscript, item, itemTextStats);
|
||||
|
||||
var logButton = document.createElement("span");
|
||||
logButton.innerHTML = "Log";
|
||||
@ -262,4 +243,36 @@ function createActiveScriptsText(workerscript, item) {
|
||||
return onlineMps;
|
||||
}
|
||||
|
||||
function updateActiveScriptsText(workerscript, item, statsEl=null) {
|
||||
var itemId = item.id
|
||||
var itemTextStats = document.getElementById(itemId + "-stats");
|
||||
if (itemTextStats === null || itemTextStats === undefined) {
|
||||
itemTextStats = statsEl;
|
||||
}
|
||||
|
||||
//Updates statistics only
|
||||
//Online
|
||||
var onlineTotalMoneyMade = "Total online production: $" + formatNumber(workerscript.scriptRef.onlineMoneyMade, 2);
|
||||
var onlineTotalExpEarned = (Array(26).join(" ") + formatNumber(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineMpsText = "Online production rate: $" + formatNumber(onlineMps, 2) + "/second";
|
||||
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineEpsText = (Array(25).join(" ") + formatNumber(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
//Offline
|
||||
var offlineTotalMoneyMade = "Total offline production: $" + formatNumber(workerscript.scriptRef.offlineMoneyMade, 2);
|
||||
var offlineTotalExpEarned = (Array(27).join(" ") + formatNumber(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineMpsText = "Offline production rate: $" + formatNumber(offlineMps, 2) + "/second";
|
||||
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineEpsText = (Array(26).join(" ") + formatNumber(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
itemTextStats.innerHTML = onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
||||
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
||||
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
||||
return onlineMps;
|
||||
}
|
||||
|
||||
export {setActiveScriptsClickHandlers, addActiveScriptsItem, deleteActiveScriptsItem, updateActiveScriptsItems};
|
||||
|
@ -124,6 +124,7 @@ let CONSTANTS = {
|
||||
//Hacking Missions
|
||||
HackingMissionRepToDiffConversion: 5000, //Faction rep is divided by this to get mission difficulty
|
||||
HackingMissionRepToRewardConversion: 20, //Faction rep divided byt his to get mission rep reward
|
||||
HackingMissionHowToPlay: "Hacking missions are a minigame that, if won, will reward you with factin reputation",
|
||||
|
||||
//Gang constants
|
||||
GangRespectToReputationRatio: 2, //Respect is divided by this to get rep gain
|
||||
@ -552,8 +553,8 @@ let CONSTANTS = {
|
||||
"<i>serverExists(hostname/ip)</i><br>Returns a boolean denoting whether or not the specified server exists. The argument " +
|
||||
"must be a string with the hostname or IP of the target server.<br><br>" +
|
||||
"<i>fileExists(filename, [hostname/ip])</i><br> Returns a boolean (true or false) indicating whether the specified file exists on a server. " +
|
||||
"The first argument must be a string with the name of the file. A file can either be a script or a program. A script name is case-sensitive, but a " +
|
||||
"program is not. For example, fileExists('brutessh.exe') will work fine, even though the actual program is named BruteSSH.exe. <br><br> " +
|
||||
"The first argument must be a string with the name of the file. A file can either be a script, program, or literature file. A script name is case-sensitive, but a " +
|
||||
"program/literature file is not. For example, fileExists('brutessh.exe') will work fine, even though the actual program is named BruteSSH.exe. <br><br> " +
|
||||
"The second argument is a string with the hostname or IP of the server on which to search for the program. This second argument is optional. " +
|
||||
"If it is omitted, then the function will search through the current server (the server running the script that calls this function) for the file. <br> " +
|
||||
"Example: fileExists('foo.script', 'foodnstuff');<br>" +
|
||||
@ -957,6 +958,9 @@ let CONSTANTS = {
|
||||
"World Stock Exchange account and TIX API Access<br>",
|
||||
|
||||
LatestUpdate:
|
||||
"v0.29.1<br>" +
|
||||
"-Added continue statement for for/while loops<br>" +
|
||||
"-fileExists() function now works on literature files<br><br>" +
|
||||
"v0.29.0<br>" +
|
||||
"-Added BitNode-5: Artificial Intelligence<br>" +
|
||||
"-Added getIp(), getIntelligence(), getHackingMultipliers(), and getBitNodeMultipliers() Netscript functions (requires Source-File 5)<br>" +
|
||||
|
@ -5,6 +5,7 @@ import {CONSTANTS} from "./Constants.js";
|
||||
import {Engine} from "./engine.js";
|
||||
import {FactionInfo} from "./FactionInfo.js";
|
||||
import {Locations} from "./Location.js";
|
||||
import {HackingMission, setInMission} from "./Missions.js";
|
||||
import {Player} from "./Player.js";
|
||||
import {Settings} from "./Settings.js";
|
||||
|
||||
@ -455,16 +456,26 @@ function displayFactionContent(factionName) {
|
||||
"is gained whenever you reset after installing an Augmentation. The amount of " +
|
||||
"favor you gain depends on how much reputation you have with the faction</span>";
|
||||
|
||||
var hackMissionDiv = document.getElementById("faction-hack-mission-div");
|
||||
var hackDiv = document.getElementById("faction-hack-div");
|
||||
var fieldWorkDiv = document.getElementById("faction-fieldwork-div");
|
||||
var securityWorkDiv = document.getElementById("faction-securitywork-div");
|
||||
var donateDiv = document.getElementById("faction-donate-div");
|
||||
var gangDiv = document.getElementById("faction-gang-div");
|
||||
|
||||
var newHackMissionButton = clearEventListeners("faction-hack-mission-button");
|
||||
var newHackButton = clearEventListeners("faction-hack-button");
|
||||
var newFieldWorkButton = clearEventListeners("faction-fieldwork-button");
|
||||
var newSecurityWorkButton = clearEventListeners("faction-securitywork-button");
|
||||
var newDonateWorkButton = clearEventListeners("faction-donate-button");
|
||||
newHackMissionButton.addEventListener("click", function() {
|
||||
Engine.loadMissionContent();
|
||||
var mission = new HackingMission(faction.playerReputation, faction);
|
||||
setInMission(true); //Sets inMission flag to true
|
||||
mission.init();
|
||||
return false;
|
||||
});
|
||||
|
||||
newHackButton.addEventListener("click", function() {
|
||||
Player.startFactionHackWork(faction);
|
||||
return false;
|
||||
@ -602,156 +613,187 @@ function displayFactionContent(factionName) {
|
||||
|
||||
switch(faction.name) {
|
||||
case "Illuminati":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "Daedalus":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "The Covenant":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "ECorp":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "MegaCorp":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Bachman & Associates":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Blade Industries":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "NWO":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Clarke Incorporated":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "OmniTek Incorporated":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Four Sigma":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "KuaiGong International":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Fulcrum Secret Technologies":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "none";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "BitRunners":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "none";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "The Black Hand":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "NiteSec":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "none";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "Chongqing":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Sector-12":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "New Tokyo":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Aevum":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Ishima":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Volhaven":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Speakers for the Dead":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "The Dark Army":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "The Syndicate":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Silhouette":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "Tetrads":
|
||||
hackMissionDiv.style.display = "none";
|
||||
hackDiv.style.display = "none";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Slum Snakes":
|
||||
hackMissionDiv.style.display = "none";
|
||||
hackDiv.style.display = "none";
|
||||
fieldWorkDiv.style.display = "inline";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "Netburners":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "none";
|
||||
securityWorkDiv.style.display = "none";
|
||||
break;
|
||||
case "Tian Di Hui":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "none";
|
||||
securityWorkDiv.style.display = "inline";
|
||||
break;
|
||||
case "CyberSec":
|
||||
hackMissionDiv.style.display = "inline";
|
||||
hackDiv.style.display = "inline";
|
||||
fieldWorkDiv.style.display = "none";
|
||||
securityWorkDiv.style.display = "none";
|
||||
|
611
src/Missions.js
Normal file
611
src/Missions.js
Normal file
@ -0,0 +1,611 @@
|
||||
import {Player} from "./Player.js";
|
||||
import {CONSTANTS} from "./Constants.js";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox.js";
|
||||
import {addOffset, getRandomInt,
|
||||
clearEventListenersEl} from "../utils/HelperFunctions.js";
|
||||
import {formatNumber} from "../utils/StringHelperFunctions.js";
|
||||
import jsplumb from 'jsplumb'
|
||||
|
||||
let inMission = false; //Flag to denote whether a mission is running
|
||||
function setInMission(bool) {
|
||||
inMission = bool;
|
||||
}
|
||||
/* Hacking Missions */
|
||||
|
||||
/*You start with N CPU nodes dependent on home computer cores
|
||||
|
||||
Three main stats:
|
||||
Attack - Specific to a node. Affected by hacking skill, RAM (for home comp)
|
||||
Defense - Universal defense - summed from all nodes
|
||||
HP - Specific to a node. Affected by hacking skill, RAM (for home comp)
|
||||
|
||||
Enemy has the following nodes:
|
||||
Firewall Nodes - Essentially shields. Weak attack but large def
|
||||
CPU Nodes - Defeating and capturing these will give you new nodes to use
|
||||
Database Node - Main Target
|
||||
|
||||
Misc Nodes (initially not owned by player or enemy):
|
||||
Spam nodes - Increases time limit
|
||||
Transfer Nodes - Slightly increases attack for all of your CPUs
|
||||
Shield Node - Increases your defense
|
||||
|
||||
Shapes for nodes:
|
||||
Firewall - Rectangle
|
||||
CPU - Circle
|
||||
Database - Parralelogram
|
||||
Spam - Diamond
|
||||
Transfer - Cone
|
||||
Shield - Shield shape
|
||||
|
||||
*/
|
||||
let NodeTypes = {
|
||||
Core: "CPU Core Node", //All actions available
|
||||
Firewall: "Firewall Node", //No actions available
|
||||
Database: "Database Node", //No actions available
|
||||
Spam: "Spam Node", //No actions Available
|
||||
Transfer: "Transfer Node", //Can Soften, Scan, and Overflow
|
||||
Shield: "Shield Node" //Can Fortify
|
||||
}
|
||||
|
||||
let NodeActions = {
|
||||
Attack: "Attack", //Damaged based on attack stat + hacking level + opp def
|
||||
Scan: "Scan", //-Def for target, affected by hacking level
|
||||
Soften: "Soften", //-Attack for target, affected by hacking level
|
||||
Fortify: "Fortify", //+Defense for Node, affected by hacking level
|
||||
Overflow: "Overflow", //+Attack but -Defense for Node, affected by hacking level
|
||||
}
|
||||
|
||||
function Node(type, stats) {
|
||||
this.type = type;
|
||||
this.atk = stats.atk ? stats.atk : 0;
|
||||
this.def = stats.def ? stats.def : 0;
|
||||
this.hp = stats.hp ? stats.hp : 0;
|
||||
this.maxhp = this.hp;
|
||||
this.plyrCtrl = false;
|
||||
this.enmyCtrl = false;
|
||||
this.pos = [0, 0]; //x, y
|
||||
this.el = null; //Holds the Node's DOM element
|
||||
this.action = null;
|
||||
}
|
||||
|
||||
Node.prototype.setPosition = function(x, y) {
|
||||
this.pos = [x, y];
|
||||
}
|
||||
|
||||
Node.prototype.setControlledByPlayer = function() {
|
||||
this.plyrCtrl = true;
|
||||
this.enmyCtrl = false;
|
||||
if (this.el) {
|
||||
this.classList.remove("hack-mission-enemy-node");
|
||||
this.classList.add("hack-mission-player-node");
|
||||
}
|
||||
}
|
||||
|
||||
Node.prototype.setControlledByEnemy = function() {
|
||||
this.plyrCtrl = false;
|
||||
this.enmyCtrl = true;
|
||||
if (this.el) {
|
||||
this.classList.remove("hack-mission-player-node");
|
||||
this.classList.add("hack-mission-enemy-node");
|
||||
}
|
||||
}
|
||||
|
||||
//Sets this node to be the active node
|
||||
Node.prototype.select = function(actionButtons) {
|
||||
if (this.enmyCtrl) {return;}
|
||||
this.el.classList.add("hack-mission-player-node-active");
|
||||
|
||||
//Make all buttons inactive
|
||||
for (var i = 0; i < actionButtons.length; ++i) {
|
||||
actionButtons[i].classList.remove("a-link-button");
|
||||
actionButtons[i].classList.add("a-link-button-inactive");
|
||||
}
|
||||
|
||||
switch(this.type) {
|
||||
case NodeTypes.Core:
|
||||
//All buttons active
|
||||
for (var i = 0; i < actionButtons.length; ++i) {
|
||||
actionButtons[i].classList.remove("a-link-button-inactive");
|
||||
actionButtons[i].classList.add("a-link-button");
|
||||
}
|
||||
break;
|
||||
case NodeTypes.Transfer:
|
||||
actionButtons[1].classList.remove("a-link-button-inactive");
|
||||
actionButtons[1].classList.add("a-link-button");
|
||||
actionButtons[2].classList.remove("a-link-button-inactive");
|
||||
actionButtons[2].classList.add("a-link-button");
|
||||
actionButtons[4].classList.remove("a-link-button-inactive");
|
||||
actionButtons[4].classList.add("a-link-button");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Node.prototype.deselect = function(actionButtons) {
|
||||
this.el.classList.remove("active");
|
||||
for (var i = 0; i < actionButtons.length; ++i) {
|
||||
actionButtons[i].classList.remove("a-link-button");
|
||||
actionButtons[i].classList.add("a-link-button-inactive");
|
||||
}
|
||||
}
|
||||
|
||||
//Hacking mission instance
|
||||
//Takes in the reputation of the Faction for which the mission is
|
||||
//being conducted
|
||||
function HackingMission(rep, fac) {
|
||||
this.faction = fac;
|
||||
|
||||
this.playerCores = [];
|
||||
this.playerNodes = []; //Non-core nodes
|
||||
this.playerDef = 0;
|
||||
|
||||
this.enemyCores = [];
|
||||
this.enemyDatabases = [];
|
||||
this.enemyNodes = []; //Non-core nodes
|
||||
this.enemyDef = 0;
|
||||
|
||||
this.miscNodes = [];
|
||||
|
||||
this.selectedNode = null; //Which of the player's nodes is currently selected
|
||||
|
||||
this.actionButtons = []; //DOM buttons for actions
|
||||
|
||||
this.availablePositions = [];
|
||||
for (var r = 0; r < 8; ++r) {
|
||||
for (var c = 0; c < 8; ++c) {
|
||||
this.availablePositions.push([r, c]);
|
||||
}
|
||||
}
|
||||
|
||||
//this.map = Array(8).fill(Array(8).fill(null)); //8x8 2d array of references to Nodes
|
||||
this.map = [];
|
||||
for (var i = 0; i < 8; ++i) {
|
||||
this.map.push([null, null, null, null, null, null, null, null]);
|
||||
}
|
||||
|
||||
//difficulty capped at 16
|
||||
this.difficulty = Math.min(16, Math.round(rep / CONSTANTS.HackingMissionRepToDiffConversion) + 1);
|
||||
console.log("difficulty: " + this.difficulty);
|
||||
this.reward = 200 + (rep / CONSTANTS.HackingMissionRepToRewardConversion);
|
||||
}
|
||||
|
||||
HackingMission.prototype.init = function() {
|
||||
//Create Header DOM
|
||||
this.createPageDom();
|
||||
|
||||
//Create player starting nodes
|
||||
var home = Player.getHomeComputer()
|
||||
for (var i = 0; i < home.cpuCores; ++i) {
|
||||
var stats = {
|
||||
atk: (Player.hacking_skill / 10) * (home.maxRam / 8),
|
||||
def: (Player.hacking_skill / 20) * (home.maxRam / 2),
|
||||
hp: (Player.hacking_skill / 5) * (home.maxRam / 4),
|
||||
};
|
||||
this.playerCores.push(new Node(NodeTypes.Core, stats));
|
||||
this.playerCores[i].setControlledByPlayer();
|
||||
this.setNodePosition(this.playerCores[i], 0, i);
|
||||
this.removeAvailablePosition(0, i);
|
||||
}
|
||||
|
||||
//Randomly generate enemy nodes (CPU and Firewall) based on difficulty
|
||||
var numNodes = getRandomInt(this.difficulty, this.difficulty + 2);
|
||||
var numFirewalls = getRandomInt(this.difficulty, this.difficulty + 5);
|
||||
var numDatabases = getRandomInt(this.difficulty, this.difficulty + 1);
|
||||
var totalNodes = numNodes + numFirewalls + numDatabases;
|
||||
var xlimit = 7 - Math.floor(totalNodes / 8);
|
||||
console.log("numNodes: " + numNodes);
|
||||
console.log("numFirewalls: " + numFirewalls);
|
||||
console.log("numDatabases: " + numDatabases);
|
||||
console.log("totalNodes: " + totalNodes);
|
||||
console.log("xlimit: " + xlimit);
|
||||
var randMult = addOffset(this.difficulty, 20);
|
||||
for (var i = 0; i < numNodes; ++i) {
|
||||
var stats = {
|
||||
atk: randMult * getRandomInt(400, 750),
|
||||
def: randMult * getRandomInt(400, 750),
|
||||
hp: randMult * getRandomInt(800, 1200)
|
||||
}
|
||||
this.enemyCores.push(new Node(NodeTypes.Core, stats));
|
||||
this.enemyCores[i].setControlledByEnemy();
|
||||
this.setNodeRandomPosition(this.enemyCores[i], xlimit);
|
||||
}
|
||||
for (var i = 0; i < numFirewalls; ++i) {
|
||||
var stats = {
|
||||
atk: randMult * getRandomInt(100, 400),
|
||||
def: randMult * getRandomInt(1000, 2500),
|
||||
hp: randMult * getRandomInt(500, 2000)
|
||||
}
|
||||
this.enemyNodes.push(new Node(NodeTypes.Firewall, stats));
|
||||
this.enemyNodes[i].setControlledByEnemy();
|
||||
this.setNodeRandomPosition(this.enemyNodes[i], xlimit);
|
||||
}
|
||||
for (var i = 0; i < numDatabases; ++i) {
|
||||
var stats = {
|
||||
atk: randMult * getRandomInt(100, 200),
|
||||
def: randMult * getRandomInt(1000, 1500),
|
||||
hp: randMult * getRandomInt(1000, 2000)
|
||||
}
|
||||
var node = new Node(NodeTypes.Database, stats);
|
||||
node.setControlledByEnemy();
|
||||
this.setNodeRandomPosition(node, xlimit);
|
||||
this.enemyDatabases.push(node);
|
||||
}
|
||||
this.calculateDefenses();
|
||||
this.createMap();
|
||||
}
|
||||
|
||||
HackingMission.prototype.createPageDom = function() {
|
||||
var container = document.getElementById("mission-container");
|
||||
|
||||
var headerText = document.createElement("p");
|
||||
headerText.innerHTML = "You are about to start a hacking mission! For more information " +
|
||||
"about how hacking missions work, click one of the guide links " +
|
||||
"below (one opens up an in-game guide and the other opens up " +
|
||||
"the guide from the wiki). Click the 'Start' button to begin.";
|
||||
headerText.style.display = "block";
|
||||
headerText.classList.add("hack-mission-header-element");
|
||||
headerText.style.width = "80%";
|
||||
|
||||
var inGameGuideBtn = document.createElement("a");
|
||||
inGameGuideBtn.innerText = "How to Play";
|
||||
inGameGuideBtn.classList.add("a-link-button");
|
||||
inGameGuideBtn.style.display = "inline-block";
|
||||
inGameGuideBtn.classList.add("hack-mission-header-element");
|
||||
inGameGuideBtn.addEventListener("click", function() {
|
||||
dialogBoxCreate(CONSTANTS.HackingMissionHowToPlay);
|
||||
return false;
|
||||
});
|
||||
|
||||
var wikiGuideBtn = document.createElement("a");
|
||||
wikiGuideBtn.innerText = "Wiki Guide";
|
||||
wikiGuideBtn.classList.add("a-link-button");
|
||||
wikiGuideBtn.style.display = "inline-block";
|
||||
wikiGuideBtn.classList.add("hack-mission-header-element");
|
||||
wikiGuideBtn.target = "_blank";
|
||||
//TODO Add link to wiki page wikiGuideBtn.href =
|
||||
|
||||
|
||||
//Start button will get replaced with forfeit when game is started
|
||||
var startBtn = document.createElement("a");
|
||||
startBtn.classList.add("hack-mission-header-element");
|
||||
startBtn.style.display = "block";
|
||||
|
||||
//Create Action Buttons (Attack/Scan/Soften/ etc...)
|
||||
var actionsContainer = document.createElement("span");
|
||||
actionsContainer.classList.add("hack-mission-action-buttons-container");
|
||||
for (var i = 0; i < 5; ++i) {
|
||||
this.actionButtons.push(document.createElement("a"));
|
||||
this.actionButtons[i].style.display = "inline-block";
|
||||
this.actionButtons[i].classList.add("a-link-button-inactive"); //Disabled at start
|
||||
this.actionButtons[i].classList.add("tooltip"); //Disabled at start
|
||||
this.actionButtons[i].classList.add("hack-mission-header-element");
|
||||
actionsContainer.appendChild(this.actionButtons[i]);
|
||||
}
|
||||
this.actionButtons[0].innerText = "Attack(1)";
|
||||
var atkTooltip = document.createElement("span");
|
||||
atkTooltip.classList.add("tooltiptext");
|
||||
atkTooltip.innerText = "Lowers the targeted node's HP. The effectiveness of this depends on " +
|
||||
"this node's Attack level, your hacking level, and the opponents defense level.";
|
||||
this.actionButtons[0].appendChild(atkTooltip);
|
||||
this.actionButtons[1].innerText = "Scan(2)";
|
||||
var scanTooltip = document.createElement("span");
|
||||
scanTooltip.classList.add("tooltiptext");
|
||||
scanTooltip.innerText = "Lowers the targeted node's defense. The effectiveness of this depends on " +
|
||||
"this node's Attack level and your hacking level";
|
||||
this.actionButtons[1].appendChild(scanTooltip);
|
||||
this.actionButtons[2].innerText = "Soften(3)";
|
||||
var softenTooltip = document.createElement("span");
|
||||
softenTooltip.classList.add("tooltiptext");
|
||||
softenTooltip.innerText = "Lowers the targeted node's attack. The effectiveness of this depends on " +
|
||||
"this node's Attack level and your hacking level";
|
||||
this.actionButtons[2].appendChild(softenTooltip);
|
||||
this.actionButtons[3].innerText = "Fortify(4)";
|
||||
var fortifyTooltip = document.createElement("span");
|
||||
fortifyTooltip.classList.add("tooltiptext");
|
||||
fortifyTooltip.innerText = "Raises this node's Defense level. The effectiveness of this depends on " +
|
||||
"your hacking level";
|
||||
this.actionButtons[3].appendChild(fortifyTooltip);
|
||||
this.actionButtons[4].innerText = "Overflow(5)";
|
||||
var overflowTooltip = document.createElement("span");
|
||||
overflowTooltip.classList.add("tooltiptext");
|
||||
overflowTooltip.innerText = "Raises this node's Attack level but lowers its Defense level. The effectiveness " +
|
||||
"of this depends on your hacking level.";
|
||||
this.actionButtons[4].appendChild(overflowTooltip);
|
||||
|
||||
var timeDisplay = document.createElement("p");
|
||||
|
||||
container.appendChild(headerText);
|
||||
container.appendChild(inGameGuideBtn);
|
||||
container.appendChild(wikiGuideBtn);
|
||||
container.appendChild(startBtn);
|
||||
container.appendChild(actionsContainer);
|
||||
container.appendChild(timeDisplay);
|
||||
}
|
||||
|
||||
//Should only be used at the start
|
||||
HackingMission.prototype.calculateDefenses = function() {
|
||||
var total = 0;
|
||||
for (var i = 0; i < this.playerCores.length; ++i) {
|
||||
total += this.playerCores[i].def;
|
||||
}
|
||||
for (var i = 0; i < this.playerNodes.length; ++i) {
|
||||
total += this.playerNodes[i].def;
|
||||
}
|
||||
console.log("player defenses calculated to be: " + total);
|
||||
this.playerDef = total;
|
||||
total = 0;
|
||||
for (var i = 0; i < this.enemyCores.length; ++i) {
|
||||
total += this.enemyCores[i].def;
|
||||
}
|
||||
for (var i = 0; i < this.enemyDatabases.length; ++i) {
|
||||
total += this.enemyDatabases[i].def;
|
||||
}
|
||||
for (var i = 0; i < this.enemyNodes.length; ++i) {
|
||||
total += this.enemyNodes[i].def;
|
||||
}
|
||||
console.log("enemy defenses calculated to be: " + total);
|
||||
this.enemyDef = total;
|
||||
}
|
||||
|
||||
HackingMission.prototype.removeAvailablePosition = function(x, y) {
|
||||
for (var i = 0; i < this.availablePositions.length; ++i) {
|
||||
if (this.availablePositions[i][0] === x &&
|
||||
this.availablePositions[i][1] === y) {
|
||||
this.availablePositions.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.log("WARNING: removeAvailablePosition() did not remove " + x + ", " + y);
|
||||
}
|
||||
|
||||
HackingMission.prototype.setNodePosition = function(nodeObj, x, y) {
|
||||
if (!(nodeObj instanceof Node)) {
|
||||
console.log("WARNING: Non-Node object passed into setNodePOsition");
|
||||
return;
|
||||
}
|
||||
if (isNaN(x) || isNaN(y)) {
|
||||
console.log("ERR: Invalid values passed as x and y for setNodePosition");
|
||||
console.log(x);
|
||||
console.log(y);
|
||||
return;
|
||||
}
|
||||
nodeObj.pos = [x, y];
|
||||
this.map[x][y] = nodeObj;
|
||||
}
|
||||
|
||||
HackingMission.prototype.setNodeRandomPosition = function(nodeObj, xlimit=0) {
|
||||
var i = getRandomInt(0, this.availablePositions.length - 1);
|
||||
var pos = this.availablePositions.splice(i, 1);
|
||||
pos = pos[0];
|
||||
this.setNodePosition(nodeObj, pos[0], pos[1]);
|
||||
}
|
||||
|
||||
HackingMission.prototype.createMap = function() {
|
||||
//Use a grid
|
||||
var map = document.createElement("div");
|
||||
map.classList.add("hack-mission-grid");
|
||||
map.setAttribute("id", "hacking-mission-map");
|
||||
document.getElementById("mission-container").appendChild(map);
|
||||
|
||||
//Create random Nodes for every space in the map that
|
||||
//hasn't been filled yet
|
||||
for (var x = 0; x < 8; ++x) {
|
||||
for (var y = 0; y < 8; ++y) {
|
||||
if (!(this.map[x][y] instanceof Node)) {
|
||||
var node, type = getRandomInt(0, 2);
|
||||
var randMult = addOffset(this.difficulty, 20);
|
||||
switch (type) {
|
||||
case 0: //Spam
|
||||
var stats = {
|
||||
atk: 0,
|
||||
def: randMult * getRandomInt(400, 800),
|
||||
hp: randMult * getRandomInt(500, 1000)
|
||||
}
|
||||
node = new Node(NodeTypes.Spam, stats);
|
||||
break;
|
||||
case 1: //Transfer
|
||||
var stats = {
|
||||
atk: 0,
|
||||
def: randMult * getRandomInt(500, 1000),
|
||||
hp: randMult * getRandomInt(600, 1100)
|
||||
}
|
||||
node = new Node(NodeTypes.Transfer, stats);
|
||||
break;
|
||||
case 2: //Shield
|
||||
default:
|
||||
var stats = {
|
||||
atk: 0,
|
||||
def: randMult * getRandomInt(750, 1000),
|
||||
hp: randMult * getRandomInt(700, 1000)
|
||||
}
|
||||
node = new Node(NodeTypes.Shield, stats);
|
||||
break;
|
||||
}
|
||||
this.setNodePosition(node, x, y);
|
||||
this.removeAvailablePosition(x, y);
|
||||
this.miscNodes.push(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Create DOM elements in order
|
||||
for (var r = 0; r < 8; ++r) {
|
||||
for (var c = 0; c < 8; ++c) {
|
||||
this.createNodeDomElement(this.map[r][c]);
|
||||
}
|
||||
}
|
||||
|
||||
//Configure all Player CPUS
|
||||
for (var i = 0; i < this.playerCores.length; ++i) {
|
||||
console.log("Configuring Player Node: " + this.playerCores[i].el.id);
|
||||
this.configurePlayerNodeElement(this.playerCores[i].el);
|
||||
}
|
||||
|
||||
console.log(this.map);
|
||||
this.initJsPlumb();
|
||||
}
|
||||
|
||||
HackingMission.prototype.createNodeDomElement = function(nodeObj) {
|
||||
var nodeDiv = document.createElement("a");
|
||||
nodeObj.el = nodeDiv;
|
||||
document.getElementById("hacking-mission-map").appendChild(nodeDiv);
|
||||
|
||||
//Set the node element's id based on its coordinates
|
||||
nodeDiv.setAttribute("id", "hacking-mission-node-" +
|
||||
nodeObj.pos[0] + "-" +
|
||||
nodeObj.pos[1]);
|
||||
|
||||
//Set node classes for owner
|
||||
nodeDiv.classList.add("hack-mission-node");
|
||||
if (nodeObj.plyrCtrl) {
|
||||
nodeDiv.classList.add("hack-mission-player-node");
|
||||
} else if (nodeObj.enmyCtrl) {
|
||||
nodeDiv.classList.add("hack-mission-enemy-node");
|
||||
}
|
||||
|
||||
//Set node classes based on type
|
||||
switch (nodeObj.type) {
|
||||
case NodeTypes.Core:
|
||||
nodeDiv.innerHTML = "<p>CPU Core<br>" + "HP: " +
|
||||
formatNumber(nodeObj.hp, 1) + "</p>";
|
||||
nodeDiv.classList.add("hack-mission-cpu-node");
|
||||
break;
|
||||
case NodeTypes.Firewall:
|
||||
nodeDiv.innerHTML = "<p>Firewall<br>" + "HP: " +
|
||||
formatNumber(nodeObj.hp, 1) + "</p>";
|
||||
nodeDiv.classList.add("hack-mission-firewall-node");
|
||||
break;
|
||||
case NodeTypes.Database:
|
||||
nodeDiv.innerHTML = "<p>Database<br>" + "HP: " +
|
||||
formatNumber(nodeObj.hp, 1) + "</p>";
|
||||
nodeDiv.classList.add("hack-mission-database-node");
|
||||
break;
|
||||
case NodeTypes.Spam:
|
||||
nodeDiv.innerHTML = "<p>Spam<br>" + "HP: " +
|
||||
formatNumber(nodeObj.hp, 1) + "</p>";
|
||||
nodeDiv.classList.add("hack-mission-spam-node");
|
||||
break;
|
||||
case NodeTypes.Transfer:
|
||||
nodeDiv.innerHTML = "<p>Transfer<br>" + "HP: " +
|
||||
formatNumber(nodeObj.hp, 1) + "</p>";
|
||||
nodeDiv.classList.add("hack-mission-transfer-node");
|
||||
break;
|
||||
case NodeTypes.Shield:
|
||||
default:
|
||||
nodeDiv.innerHTML = "<p>Shield<br>" + "HP: " +
|
||||
formatNumber(nodeObj.hp, 1) + "</p>";
|
||||
nodeDiv.classList.add("hack-mission-shield-node");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets a Node DOM element's corresponding Node object using its
|
||||
//element id
|
||||
HackingMission.prototype.getNodeFromElement = function(el) {
|
||||
var id = el.id;
|
||||
id = id.replace("hacking-mission-node-", "");
|
||||
var res = id.split('-');
|
||||
if (res.length != 2) {
|
||||
console.log("ERROR Parsing Hacking Mission Node Id. Could not find coordinates");
|
||||
return null;
|
||||
}
|
||||
var x = res[0], y = res[1];
|
||||
if (isNaN(x) || isNaN(y) || x >= 8 || y >= 8 || x < 0 || y < 0) {
|
||||
console.log("ERROR: Unexpected values for x and y: " + x + ", " + y);
|
||||
return null;
|
||||
}
|
||||
return this.map[x][y];
|
||||
}
|
||||
|
||||
//Configures a DOM element representing a player-owned node to
|
||||
//be selectable and actionable
|
||||
//Note: Does NOT change its css class. This is handled by Node.setControlledBy...
|
||||
HackingMission.prototype.configurePlayerNodeElement = function(el) {
|
||||
var nodeObj = this.getNodeFromElement(el);
|
||||
if (nodeObj === null) {console.log("Error getting Node object");}
|
||||
|
||||
//Add event listener
|
||||
el.addEventListener("click", ()=>{
|
||||
if (this.selectedNode instanceof Node) {
|
||||
this.selectedNode.deselect(this.actionButtons);
|
||||
this.selectedNode = null;
|
||||
}
|
||||
console.log("Selecting node :" + el.id);
|
||||
nodeObj.select(this.actionButtons);
|
||||
this.selectedNode = nodeObj;
|
||||
});
|
||||
}
|
||||
|
||||
//Configures a DOM element representing an enemy-node by removing
|
||||
//any event listeners
|
||||
HackingMission.prototype.configureEnemyNodeElement = function(el) {
|
||||
//Deselect node if it was the selected node
|
||||
var nodeObj = this.getNodeFromElement(el);
|
||||
if (this.selectedNode == nodeObj) {
|
||||
nodeObj.deselect(this.actionButtons);
|
||||
}
|
||||
}
|
||||
|
||||
HackingMission.prototype.initJsPlumb = function() {
|
||||
var instance = jsPlumb.getInstance({
|
||||
DragOptions:{cursor:"pointer", zIndex:2000},
|
||||
PaintStyle: {
|
||||
gradient: { stops: [
|
||||
[ 0, "#FFFFFF" ],
|
||||
[ 1, "#FFFFFF" ]
|
||||
] },
|
||||
stroke: "#FFFFFF",
|
||||
strokeWidth: 10
|
||||
},
|
||||
});
|
||||
|
||||
//All player cores are sources
|
||||
for (var i = 0; i < this.playerCores.length; ++i) {
|
||||
instance.makeSource(this.playerCores[i].el, {
|
||||
deleteEndpointsOnEmpty:true,
|
||||
maxConnections:1,
|
||||
anchor:"Center",
|
||||
connector:"Straight"
|
||||
});
|
||||
}
|
||||
|
||||
//Everything else is a target
|
||||
for (var i = 0; i < this.enemyCores.length; ++i) {
|
||||
instance.makeTarget(this.enemyCores[i].el, {
|
||||
maxConnections:-1,
|
||||
anchor:"Center",
|
||||
connector:"Straight"
|
||||
});
|
||||
}
|
||||
for (var i = 0; i < this.enemyDatabases.length; ++i) {
|
||||
instance.makeTarget(this.enemyDatabases[i].el, {
|
||||
maxConnections:-1,
|
||||
anchor:"Center",
|
||||
connector:["Straight"]
|
||||
});
|
||||
}
|
||||
for (var i = 0; i < this.enemyNodes.length; ++i) {
|
||||
instance.makeTarget(this.enemyNodes[i].el, {
|
||||
maxConnections:-1,
|
||||
anchor:"Center",
|
||||
connector:"Straight"
|
||||
});
|
||||
}
|
||||
for (var i = 0; i < this.miscNodes.length; ++i) {
|
||||
instance.makeTarget(this.miscNodes[i].el, {
|
||||
maxConnections:-1,
|
||||
anchor:"Center",
|
||||
connector:"Straight"
|
||||
});
|
||||
}
|
||||
|
||||
//Clicking a connection drops it
|
||||
instance.bind("click", function(conn, originalEvent) {
|
||||
console.log("test");
|
||||
var endpoints = conn.endpoints;
|
||||
endpoints[0].detachFrom(endpoints[1]);
|
||||
});
|
||||
}
|
||||
|
||||
export {HackingMission, inMission, setInMission};
|
@ -201,6 +201,9 @@ function evaluate(exp, workerScript) {
|
||||
case "BreakStatement":
|
||||
reject("BREAKSTATEMENT");
|
||||
break;
|
||||
case "ContinueStatement":
|
||||
reject("CONTINUESTATEMENT");
|
||||
break;
|
||||
case "IfStatement":
|
||||
evaluateIf(exp, workerScript).then(function(forLoopRes) {
|
||||
resolve("forLoopDone");
|
||||
@ -524,7 +527,23 @@ function evaluateFor(exp, workerScript) {
|
||||
reject(e);
|
||||
});
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
if (e == "CONTINUESTATEMENT" ||
|
||||
(e instanceof WorkerScript && e.errorMessage == "CONTINUESTATEMENT")) {
|
||||
//Continue statement, recurse to next iteration
|
||||
var pUpdate = evaluate(exp.update, workerScript);
|
||||
pUpdate.then(function(resPostloop) {
|
||||
var recursiveCall = evaluateFor(exp, workerScript);
|
||||
recursiveCall.then(function(foo) {
|
||||
resolve("endForLoop");
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
} else {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resolve("endForLoop"); //Doesn't need to resolve to any particular value
|
||||
@ -561,7 +580,18 @@ function evaluateWhile(exp, workerScript) {
|
||||
evaluatePromise.then(function(resCode) {
|
||||
resolve(resCode);
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
if (e == "CONTINUESTATEMENT" ||
|
||||
(e instanceof WorkerScript && e.errorMessage == "CONTINUESTATEMENT")) {
|
||||
//Continue statement, recurse
|
||||
var recursiveCall = evaluateWhile(exp, workerScript);
|
||||
recursiveCall.then(function(foo) {
|
||||
resolve("endWhileLoop");
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
} else {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
});
|
||||
|
@ -770,6 +770,12 @@ function NetscriptFunctions(workerScript) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < server.messages.length; ++i) {
|
||||
if (!(server.messages[i] instanceof Message) &&
|
||||
filename.toLowerCase() === server.messages[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isRunning : function(filename,ip){
|
||||
|
@ -12,8 +12,6 @@ require('brace/theme/xcode');
|
||||
require("brace/keybinding/vim");
|
||||
require("brace/keybinding/emacs");
|
||||
|
||||
|
||||
|
||||
import {CONSTANTS} from "./Constants.js";
|
||||
import {Engine} from "./engine.js";
|
||||
import {iTutorialSteps, iTutorialNextStep,
|
||||
|
@ -178,6 +178,7 @@ let Engine = {
|
||||
locationContent: null,
|
||||
workInProgressContent: null,
|
||||
redPillContent: null,
|
||||
missionContent: null,
|
||||
|
||||
//Character info
|
||||
characterInfo: null,
|
||||
@ -202,6 +203,7 @@ let Engine = {
|
||||
Infiltration: "Infiltration",
|
||||
StockMarket: "StockMarket",
|
||||
Gang: "Gang",
|
||||
Mission: "Mission",
|
||||
},
|
||||
currentPage: null,
|
||||
|
||||
@ -385,7 +387,13 @@ let Engine = {
|
||||
Engine.loadTerminalContent();
|
||||
Engine.currentPage = Engine.Page.Terminal;
|
||||
}
|
||||
},
|
||||
|
||||
loadMissionContent: function() {
|
||||
Engine.hideAllContent();
|
||||
document.getElementById("mainmenu-container").style.visibility = "hidden";
|
||||
document.getElementById("character-overview-wrapper").style.visibility = "hidden";
|
||||
Engine.Display.missionContent.style.visibility = "visible";
|
||||
},
|
||||
|
||||
//Helper function that hides all content
|
||||
@ -407,6 +415,7 @@ let Engine = {
|
||||
Engine.Display.redPillContent.style.visibility = "hidden";
|
||||
Engine.Display.infiltrationContent.style.visibility = "hidden";
|
||||
Engine.Display.stockMarketContent.style.visibility = "hidden";
|
||||
Engine.Display.missionContent.style.visibility = "hidden";
|
||||
if (document.getElementById("gang-container")) {
|
||||
document.getElementById("gang-container").style.visibility = "hidden";
|
||||
}
|
||||
@ -1278,6 +1287,8 @@ let Engine = {
|
||||
Engine.Display.stockMarketContent = document.getElementById("stock-market-container");
|
||||
Engine.Display.stockMarketContent.style.visibility = "hidden";
|
||||
|
||||
Engine.Display.missionContent = document.getElementById("mission-container");
|
||||
Engine.Display.missionContent.style.visibility = "hidden";
|
||||
|
||||
//Character info
|
||||
Engine.Display.characterInfo = document.getElementById("character-info");
|
||||
|
@ -30,6 +30,14 @@ function clearEventListeners(elemId) {
|
||||
return newElem;
|
||||
}
|
||||
|
||||
//Same as clearEventListeners except it takes a DOM element object rather than an ID
|
||||
function clearEventListenersEl(el) {
|
||||
if (el == null) {console.log("ERR: element passed into clearEventListenersEl is null"); return null;}
|
||||
var newElem = el.cloneNode(true);
|
||||
el.parentNode.replaceChild(newElem, el);
|
||||
return newElem;
|
||||
}
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
if (min > max) {return getRandomInt(max, min);}
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
@ -59,4 +67,4 @@ function powerOfTwo(n) {
|
||||
}
|
||||
|
||||
export {sizeOfObject, addOffset, clearEventListeners, getRandomInt,
|
||||
compareArrays, printArray, powerOfTwo};
|
||||
compareArrays, printArray, powerOfTwo, clearEventListenersEl};
|
||||
|
Loading…
Reference in New Issue
Block a user