Trying to get hack progress bar to work

This commit is contained in:
Daniel Xie 2016-10-26 22:34:18 -05:00
parent d268ea09f8
commit 0a13496984
3 changed files with 25 additions and 19 deletions

@ -8,7 +8,8 @@ var Player = {
dexterity: 1, dexterity: 1,
agility: 1, agility: 1,
hacking_chance_multiplier: 2, //Increase through ascensions/augmentations hacking_chance_multiplier: 2, //Increase through ascensions/augmentations
hacking_speed_multiplier: 5, //Decrease through ascensions/augmentations //hacking_speed_multiplier: 5, //Decrease through ascensions/augmentations
hacking_speed_multiplier: 1, //Make it faster for debugging
//Note: "Lifetime" refers to current ascension, "total" refers to the entire game history //Note: "Lifetime" refers to current ascension, "total" refers to the entire game history
//Accumulative stats and skills //Accumulative stats and skills
@ -95,10 +96,8 @@ var Player = {
// ------------------------------- * hacking_speed_multiplier // ------------------------------- * hacking_speed_multiplier
// hacking_skill // hacking_skill
calculateHackingTime: function() { calculateHackingTime: function() {
var difficultyMult = Player.currentServer.requiredHackingSkill * Player.currentServer.difficulty; var difficultyMult = Player.currentServer.requiredHackingSkill * Player.currentServer.hackDifficulty;
console.log("difficultyMult: " + difficultyMult);
var skillFactor = difficultyMult / Player.hacking_skill; var skillFactor = difficultyMult / Player.hacking_skill;
console.log("skillFactor: " + skillFactor);
console.log("Player.hacking_speed_multiplier: " + Player.hacking_speed_multiplier); console.log("Player.hacking_speed_multiplier: " + Player.hacking_speed_multiplier);
return skillFactor * Player.hacking_speed_multiplier; return skillFactor * Player.hacking_speed_multiplier;
}, },
@ -112,11 +111,6 @@ var Player = {
//Set the startHack flag so the engine starts the hacking process //Set the startHack flag so the engine starts the hacking process
Player.startHack = true; Player.startHack = true;
while (Player.finishHack == false) {
//Waiting for hack to complete
}
Player.finishHack = false;
//DEBUG //DEBUG
return 5; return 5;
} }

@ -4,6 +4,17 @@ var post = function(input) {
window.scrollTo(0, document.body.scrollHeight); window.scrollTo(0, document.body.scrollHeight);
} }
//Same thing as post but the td cells have ids so they can be animated for the hack progress bar
var hackProgressBarPost = function(input) {
$("#terminal-input").before('<tr class="posted"><td id="hack-progress-bar" style="color: #66ff33;">' + input + '</td></tr>');
window.scrollTo(0, document.body.scrollHeight);
}
var hackProgressPost = function(input) {
$("#terminal-input").before('<tr class="posted"><td id="hack-progress" style="color: #66ff33;">' + input + '</td></tr>');
window.scrollTo(0, document.body.scrollHeight);
}
var postNetburnerText = function() { var postNetburnerText = function() {
post("Netburner v1.0"); post("Netburner v1.0");
} }
@ -77,8 +88,8 @@ var Terminal = {
} else if (Player.currentServer.requiredHackingSkill > Player.hacking_skill) { } else if (Player.currentServer.requiredHackingSkill > Player.hacking_skill) {
post("Your hacking skill is not high enough to attempt hacking this machine. Try analyzing the machine to determine the required hacking skill"); post("Your hacking skill is not high enough to attempt hacking this machine. Try analyzing the machine to determine the required hacking skill");
} else { } else {
post("<p id='hacking-progress'> Time left: </p>"); hackProgressPost("Time left:");
post("<p id='hacking-progress-bar'> | </p>"); hackProgressBarPost("[");
var hackResult = Player.hack(); var hackResult = Player.hack();
} }
break; break;

@ -87,7 +87,6 @@ var Engine = {
loadTerminalContent: function() { loadTerminalContent: function() {
Engine.hideAllContent(); Engine.hideAllContent();
Engine.Display.terminalContent.style.visibility = "visible"; Engine.Display.terminalContent.style.visibility = "visible";
postNetburnerText();
}, },
loadCharacterContent: function() { loadCharacterContent: function() {
@ -132,7 +131,8 @@ var Engine = {
var idleTime = Engine._idleSpeed - timeDifference; var idleTime = Engine._idleSpeed - timeDifference;
//Manual hack //Manual hack
if (Player.startHack = true) { if (Player.startHack == true) {
console.log("Player.startHack flag was set to true");
Engine._totalHackTime = Player.hackingTime; Engine._totalHackTime = Player.hackingTime;
Engine._hackTimeLeft = Player.hackingTime; Engine._hackTimeLeft = Player.hackingTime;
Engine._manualHackInProgress = true; Engine._manualHackInProgress = true;
@ -159,25 +159,26 @@ var Engine = {
_hackProgressBarCount: 0, _hackProgressBarCount: 0,
_manualHackInProgress: false, _manualHackInProgress: false,
updateHackProgress: function() { updateHackProgress: function() {
if (Engine.manualHackInProgress) { if (Engine._manualHackInProgress == true) {
Engine._hackTimeLeft -= (_idleSpeed/ 1000); //Substract idle speed (ms) console.log("Manual Hack in Progress");
Engine._hackTimeLeft -= (Engine._idleSpeed/ 1000); //Substract idle speed (ms)
//Calculate percent filled //Calculate percent filled
var percent = Math.floor((1 - Engine._hackTimeLeft / Engine.totalhackTime) * 100); var percent = Math.floor((1 - Engine._hackTimeLeft / Engine.totalhackTime) * 100);
console.log("Hack progress percent: " + percent);
//Update progress bar //Update progress bar
if (Engine._hackProgressBarCount * 2 < percent) { if (Engine._hackProgressBarCount * 2 < percent) {
Engine._hackProgressStr += '|'; Engine._hackProgressStr += '|';
Engine._ProgressBarCount += 1; Engine._ProgressBarCount += 1;
$('#hacking-progress-bar').html(Engine._hackProgressStr); document.getElementbyId("hack-progress-bar").innerHTML = Engine._hackProgressStr;
} }
//Update hack time remaining //Update hack time remaining
Engine._hackTimeStr = "Time left: " + Engine._hackTimeLeft.asString(); //Engine._hackTimeStr = "Time left: " + Engine._hackTimeLeft.asString();
$('#hacking-progress').html(Engine._hackTimeStr);
//Once percent is 100, the hack is completed //Once percent is 100, the hack is completed
if (percent == 100) { if (percent >= 100) {
Engine.manualHackInProgress = false; Engine.manualHackInProgress = false;
Player.finishHack = true; Player.finishHack = true;
} }