diff --git a/src/Player.js b/src/Player.js
index 3eacee7ff..1e5e65240 100644
--- a/src/Player.js
+++ b/src/Player.js
@@ -55,8 +55,8 @@ var Player = {
//Flag to let the engine know the player is starting a hack
- startHack: false,
- hackingTime: 0,
+ startAction: false,
+ actionTime: 0,
init: function() {
@@ -126,15 +126,19 @@ var Player = {
return Math.round(Player.currentServer.hackDifficulty * Player.currentServer.requiredHackingSkill * Player.hacking_exp_mult);
},
- //Hack a server. Return the amount of time the hack will take. This lets the Terminal object know how long to disable itself for
+ //Hack/Analyze a server. Return the amount of time the hack will take. This lets the Terminal object know how long to disable itself for
//This assumes that the server being hacked is not purchased by the player, that the player's hacking skill is greater than the
//required hacking skill and that the player has admin rights.
hack: function() {
- Player.hackingTime = Player.calculateHackingTime();
- console.log("Hacking time: " + Player.hackingTime);
+ Player.actionTime = Player.calculateHackingTime();
+ console.log("Hacking time: " + Player.actionTime);
//Set the startHack flag so the engine starts the hacking process
- Player.startHack = true;
-
- return Player.hackingTime;
- }
+ Player.startAction = true;
+ },
+
+ analyze: function() {
+ //TODO Analyze only takes 5 seconds for now..maybe change this in the future?
+ Player.actionTime = 5;
+ Player.startAction = true;
+ }
};
\ No newline at end of file
diff --git a/src/Terminal.js b/src/Terminal.js
index 918354104..0977fd762 100644
--- a/src/Terminal.js
+++ b/src/Terminal.js
@@ -1,6 +1,6 @@
//Terminal
var post = function(input) {
- $("#terminal-input").before('
' + input.replace( / /g, " " ) + ' |
');
window.scrollTo(0, document.body.scrollHeight);
}
@@ -34,36 +34,92 @@ $(document).keyup(function(event) {
});
var Terminal = {
+ //Flags to determine whether the player is currently running a hack or an analyze
+ hackFlag: false,
+ analyzeFlag: false,
+
+ finishAction: function() {
+ if (Terminal.hackFlag) {
+ Terminal.finishHack();
+ } else if (Terminal.analyzeFlag) {
+ Terminal.finishAnalyze();
+ }
+ },
+
+ //Complete the hack/analyze command
finishHack: function() {
- console.log("Hack done. Determining success/failure of hack. Re-enabling terminal and changing the id of the hack progress bar");
-
- //Calculate whether hack was successful
- var hackChance = Player.calculateHackingChance();
- var rand = Math.random();
- console.log("Hack success chance: " + hackChance + ", rand: " + rand);
- var expGainedOnSuccess = Player.calculateExpGain();
- var expGainedOnFailure = Math.round(expGainedOnSuccess / 4);
- if (rand < hackChance) { //Success!
- var moneyGained = Player.calculatePercentMoneyHacked();
- moneyGained = Math.floor(Player.currentServer.moneyAvailable * moneyGained);
-
- Player.currentServer.moneyAvailable -= moneyGained;
- Player.money += moneyGained;
-
- Player.hacking_exp += expGainedOnSuccess;
-
- post("Hack successful! Gained $" + moneyGained + "and " + expGainedOnSuccess + " hacking EXP");
- } else { //Failure
- //Player only gains 25% exp for failure? TODO Can change this later to balance
- Player.hacking_exp += expGainedOnFailure;
- post("Failed to hack " + Player.currentServer.hostname + ". Gained " + expGainedOnFailure + " hacking EXP");
- }
-
- $("#hack-progress-bar").attr('id', "old-hack-progress-bar");
- $("#hack-progress").attr('id', "old-hack-progress");
- document.getElementById("terminal-input-td").innerHTML = '$