Create Program refactoring, added a notification for it when it comes up

This commit is contained in:
Daniel Xie 2017-05-05 11:52:48 -05:00
parent 66e4fa26a2
commit acc3b8cf89
7 changed files with 127 additions and 25 deletions

@ -104,6 +104,12 @@
overflow-y: scroll;
}
#active-scripts-text {
width: 80%;
margin: 6px;
padding: 4px;
}
.active-scripts-list > li {
margin: 6px;
width: 80%;

@ -115,3 +115,29 @@ tr:focus {
cursor: default;
}
/* Notification icon (for create program right now only) */
.create-program-tab {
position:relative;
}
#create-program-notification {
font-size: 10px;
position: absolute; /* Position the badge within the relatively positioned button */
top: 0;
right: 0;
}
.notification-on {
background-color: #fa3e3e;
color: white;
border-radius: 2px;
padding: 1px 3px;
}
.notification-off {
background-color: #333;
color: #333;
border-radius: 0px;
padding: 0px;
}

@ -9,8 +9,7 @@
<link rel="stylesheet" type="text/css" href="css/workinprogress.css" />
<link rel="stylesheet" type="text/css" href="css/popupboxes.css" />
<!-- We'll add in the jQuery library here - direct from
the Google CDN (Content Delivery Network). -->
<!--jQuery library-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Utils -->
@ -53,6 +52,7 @@
<script src="src/Crimes.js"></script>
<script src="src/Prestige.js"></script>
<script src="src/SaveObject.js"></script>
<script src="src/DarkWeb.js"></script>
<script src="src/engine.js"></script>
@ -88,8 +88,9 @@
<li class="create-program-tab">
<a href="#" id="create-program-menu-link"> Create Program </a>
<span id="create-program-notification" class="notification-off"> </span>
</li>
<li class="factions-tab">
<a href="#" id="factions-menu-link"> Factions </a>
</li>
@ -145,6 +146,8 @@
<!-- Active scripts info page -->
<div id="active-scripts-container">
<p id="active-scripts-text"> This page displays a list of all scripts that are currently running across every machine. It also gives
information about their production </p>
<ul class="active-scripts-list" id="active-scripts-list" style="list-style: none;">
</ul>
</div>

@ -30,53 +30,78 @@ function displayCreateProgramContent() {
//PortHack.exe (in case you delete it lol)
if (Player.getHomeComputer().programs.indexOf(Programs.NukeProgram) == -1) {
portHackALink.style.display = "block";
portHackALink.addEventListener("click", function() {
createProgram(Programs.PortHackProgram, CONSTANTS.MillisecondsPerQuarterHour);
});
}
//BruteSSH
if (Player.getHomeComputer().programs.indexOf(Programs.BruteSSHProgram) == -1 &&
Player.hacking_skill >= 50) {
bruteSshALink.style.display = "block";
bruteSshALink.addEventListener("click", function() {
Player.startCreateProgramWork(Programs.BruteSSHProgram, CONSTANTS.MillisecondsPerQuarterHour);
});
bruteSshALink.style.display = "block";
}
//FTPCrack
if (Player.getHomeComputer().programs.indexOf(Programs.FTPCrackProgram) == -1 &&
Player.hacking_skill >= 100) {
ftpCrackALink.style.display = "block";
ftpCrackALink.addEventListener("click", function() {
Player.startCreateProgramWork(Programs.FTPCrackProgram, CONSTANTS.MillisecondsPerHalfHour);
});
}
//relaySMTP
if (Player.getHomeComputer().programs.indexOf(Programs.RelaySMTPProgram) == -1 &&
Player.hacking_skill >= 250) {
relaySmtpALink.style.display = "block";
relaySmtpAlink.addEventListener("click", function() {
Player.startCreateProgramWork(Programs.RelaySMTPProgram. CONSTANTS.MillisecondsPer2Hours);
});
}
//HTTPWorm
if (Player.getHomeComputer().programs.indexOf(Programs.HTTPWormProgram) == -1 &&
Player.hacking_skill >= 500) {
httpWormALink.style.display = "block";
httpWormALink.addEventListener("click", function() {
Player.startCreateProgramWork(Programs.HTTPWormProgram, CONSTANTS.MillisecondsPer4Hours);
});
}
//SQLInject
if (Player.getHomeComputer().programs.indexOf(Programs.SQLInjectProgram) == -1 &&
Player.hacking_skill >= 750) {
sqlInjectALink.style.display = "block";
sqlInjectALink.addEventListener("click", function() {
Player.startCreateProgramWork(Programs.SQLInjectProgram, CONSTANTS.MillisecondsPer8Hours);
});
}
}
//Returns the number of programs that are currently available to be created
function getNumAvailableCreateProgram() {
var count = 0;
//PortHack.exe (in case you delete it lol)
if (Player.getHomeComputer().programs.indexOf(Programs.NukeProgram) == -1) {
++count;
}
//BruteSSH
if (Player.getHomeComputer().programs.indexOf(Programs.BruteSSHProgram) == -1 &&
Player.hacking_skill >= 50) {
++count;
}
//FTPCrack
if (Player.getHomeComputer().programs.indexOf(Programs.FTPCrackProgram) == -1 &&
Player.hacking_skill >= 100) {
++count;
}
//relaySMTP
if (Player.getHomeComputer().programs.indexOf(Programs.RelaySMTPProgram) == -1 &&
Player.hacking_skill >= 250) {
++count;
}
//HTTPWorm
if (Player.getHomeComputer().programs.indexOf(Programs.HTTPWormProgram) == -1 &&
Player.hacking_skill >= 500) {
++count;
}
//SQLInject
if (Player.getHomeComputer().programs.indexOf(Programs.SQLInjectProgram) == -1 &&
Player.hacking_skill >= 750) {
++count;
}
return count;
}

@ -1,9 +1,9 @@
/* DarkWeb.js */
//Posts a "help" message if connected to DarkWeb
checkIfConnectedToDarkweb() {
checkIfConnectedToDarkweb = function() {
if (SpecialServerIps.hasOwnProperty("Darkweb Server")) {
var darkwebIp = SpecialServerIps["Darkweb Server"];
if (!isValidIPAddress(darkwebIp) {return;}
if (!isValidIPAddress(darkwebIp)) {return;}
if (darkwebIp == Player.getCurrentServer().ip) {
post("You are now connected to the dark web. From the dark web you can purchase illegal items. " +
"Use the 'buy -l' command to display a list of all the items you can buy. Use 'buy [item-name] " +

@ -1496,7 +1496,7 @@ purchaseTorRouter = function() {
dialogBoxCreate("You cannot afford to purchase the Tor router");
return;
}
Player.money -= CONSTANTS.TorRouterCost;
Player.loseMoney(CONSTANTS.TorRouterCost);
var darkweb = new Server();
darkweb.init(createRandomIp(), "darkweb", "", true, false, false, false, 1);

@ -557,6 +557,7 @@ var Engine = {
autoSaveCounter: 300, //Autosave every minute
updateSkillLevelsCounter: 10, //Only update skill levels every 2 seconds. Might improve performance
updateDisplays: 3, //Update displays such as Active Scripts display and character display
createProgramNotifications: 10, //Checks whether any programs can be created and notifies
serverGrowth: 450, //Process server growth every minute and a half
checkFactionInvitations: 1500, //Check whether you qualify for any faction invitations every 5 minutes
passiveFactionGrowth: 600,
@ -595,6 +596,19 @@ var Engine = {
Engine.Counters.updateDisplays = 3;
}
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;
}
if (Engine.Counters.serverGrowth <= 0) {
var numCycles = Math.floor((450 - Engine.Counters.serverGrowth));
processServerGrowth(numCycles);
@ -718,6 +732,7 @@ var Engine = {
//Active scripts list
Engine.ActiveScriptsList = document.getElementById("active-scripts-list");
//Save and Delete buttons
Engine.Clickables.saveMainMenuButton = document.getElementById("save-game-link");
Engine.Clickables.saveMainMenuButton.addEventListener("click", function() {
saveObject.saveGame();
@ -818,6 +833,33 @@ var Engine = {
//Character info
Engine.Display.characterInfo = document.getElementById("character-info");
//Create Program buttons
var portHackALink = document.getElementById("create-program-porthack");
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);
});
//Location lists
Engine.aevumLocationsList = document.getElementById("aevum-locations-list");
Engine.chongqingLocationsList = document.getElementById("chongqing-locations-list");