Added port properties to server. Wrote code for hacking() and PortHacking, currently untested

This commit is contained in:
Daniel Xie
2016-10-24 16:16:51 -05:00
parent 1446a8d96e
commit 0307b3334d
4 changed files with 240 additions and 45 deletions
+44
View File
@@ -131,6 +131,18 @@ var Engine = {
var idleTime = Engine._idleSpeed - timeDifference;
//Manual hack
if (Player.startHack = true) {
Engine._totalHackTime = Player.hackingTime;
Engine._hackTimeLeft = Player.hackingTime;
Engine._manualHackInProgress = true;
Engine._hackProgressBarCount = 0;
Engine._hackProgressStr = "[";
Engine._hackTimeStr = "Time left: ";
Player.startHack = false;
}
Engine.updateHackProgress();
// Once that entire "while loop" has run, we call the IdleTimer
// function again, but this time with a timeout (delay) of
@@ -139,6 +151,38 @@ var Engine = {
},
/* Calculates the hack progress for a manual (non-scripted) hack and updates the progress bar/time accordingly */
_totalHackTime: 0,
_hackTimeLeft: 0,
_hackTimeStr: "Time left: ",
_hackProgressStr: "[",
_hackProgressBarCount: 0,
_manualHackInProgress: false,
updateHackProgress: function() {
if (Engine.manualHackInProgress) {
Engine._hackTimeLeft -= (_idleSpeed/ 1000); //Substract idle speed (ms)
//Calculate percent filled
var percent = Math.floor((1 - Engine._hackTimeLeft / Engine.totalhackTime) * 100);
//Update progress bar
if (Engine._hackProgressBarCount * 2 < percent) {
Engine._hackProgressStr += '|';
$('#hacking-progress-bar').html(Engine._hackProgressStr);
}
//Update hack time remaining
Engine._hackTimeStr = "Time left: " + Engine._hackTimeLeft.asString();
$('#hacking-progress').html(Engine._hackTimeStr);
//Once percent is 100, the hack is completed
if (percent == 100) {
Engine.manualHackInProgress = false;
Player.finishHack = true;
}
}
},
/* Initialization */
init: function() {
//Initialize Player objects