mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
Added full hack functionality with animated progress bar and everthing. All thats left is balancing exp/money gains and also taking care of porthack stuff. Also fixed the terminal not being scrollable
This commit is contained in:
parent
0a13496984
commit
f6aaef455d
@ -1,7 +1,10 @@
|
|||||||
#terminal-container {
|
#terminal-container {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
margin-left: 10%;
|
margin-left: 10%;
|
||||||
|
height: 100%;
|
||||||
width: 99%;
|
width: 99%;
|
||||||
|
overflow: auto;
|
||||||
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
#terminal {
|
#terminal {
|
||||||
@ -10,6 +13,8 @@
|
|||||||
height: auto;
|
height: auto;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
overflow: auto;
|
||||||
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
#terminal-input {
|
#terminal-input {
|
||||||
|
18
index.html
18
index.html
@ -19,8 +19,20 @@
|
|||||||
<a href="#" id="character-menu-link"> Character </a>
|
<a href="#" id="character-menu-link"> Character </a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="gym-tab">
|
<li class="create-script-tab" style="display:none">
|
||||||
<a href=#Gym> Gym </a>
|
<a href="#" id="create-script-menu-link"> Create Script </a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="gym-tab" style="display:none">
|
||||||
|
<a href="#" id="gym-menu-link"> Gym </a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="world-tab" style="display:none">
|
||||||
|
<a href="#" id="world-menu-link"> World </a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="develop-gui-tab" style="display:none">
|
||||||
|
<a href="#" id="develop-gui-menu-link"> Develop GUI </a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -29,7 +41,7 @@
|
|||||||
<!-- Terminal -->
|
<!-- Terminal -->
|
||||||
<table id="terminal">
|
<table id="terminal">
|
||||||
<tr id="terminal-input">
|
<tr id="terminal-input">
|
||||||
<td>$ <input type="text" class="terminal-input"/></td>
|
<td id="terminal-input-td">$ <input type="text" class="terminal-input"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table> <!-- End terminal -->
|
</table> <!-- End terminal -->
|
||||||
|
@ -10,6 +10,7 @@ var Player = {
|
|||||||
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
|
hacking_speed_multiplier: 1, //Make it faster for debugging
|
||||||
|
hacking_money_multiplier: .01, //Increase through ascensions/augmentations. Can't go above 1
|
||||||
|
|
||||||
//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
|
||||||
@ -55,7 +56,6 @@ var Player = {
|
|||||||
|
|
||||||
//Flag to let the engine know the player is starting a hack
|
//Flag to let the engine know the player is starting a hack
|
||||||
startHack: false,
|
startHack: false,
|
||||||
finishHack : false,
|
|
||||||
hackingTime: 0,
|
hackingTime: 0,
|
||||||
|
|
||||||
|
|
||||||
@ -64,6 +64,9 @@ var Player = {
|
|||||||
Player.homeComputer.init("19.42.93.219", "home", "Home PC", true, true, true, true, 1);
|
Player.homeComputer.init("19.42.93.219", "home", "Home PC", true, true, true, true, 1);
|
||||||
Player.currentServer = Player.homeComputer;
|
Player.currentServer = Player.homeComputer;
|
||||||
|
|
||||||
|
//FOR TESTING ONLY
|
||||||
|
Player.homeComputer.programs.push("PortHack.exe");
|
||||||
|
|
||||||
var NetworkGroup1 = [ForeignServers.IronGym, ForeignServers.FoodNStuff, ForeignServers.SigmaCosmetics, ForeignServers.JoesGuns, ForeignServers.HongFangTeaHouse, ForeignServers.HaraKiriSushiBar];
|
var NetworkGroup1 = [ForeignServers.IronGym, ForeignServers.FoodNStuff, ForeignServers.SigmaCosmetics, ForeignServers.JoesGuns, ForeignServers.HongFangTeaHouse, ForeignServers.HaraKiriSushiBar];
|
||||||
for (var i = 0; i < NetworkGroup1.length; i++) {
|
for (var i = 0; i < NetworkGroup1.length; i++) {
|
||||||
Player.homeComputer.serversOnNetwork.push(NetworkGroup1[i]);
|
Player.homeComputer.serversOnNetwork.push(NetworkGroup1[i]);
|
||||||
@ -82,7 +85,7 @@ var Player = {
|
|||||||
//The formula is:
|
//The formula is:
|
||||||
// (hacking_chance_multiplier * hacking_skill - requiredLevel) 100 - difficulty
|
// (hacking_chance_multiplier * hacking_skill - requiredLevel) 100 - difficulty
|
||||||
// ----------------------------------------------------------- * -----------------
|
// ----------------------------------------------------------- * -----------------
|
||||||
// hacking_chance_multiplier * hacking_skill) 100
|
// (hacking_chance_multiplier * hacking_skill) 100
|
||||||
calculateHackingChance: function() {
|
calculateHackingChance: function() {
|
||||||
var difficultyMult = (100 - Player.currentServer.hackDifficulty) / 100;
|
var difficultyMult = (100 - Player.currentServer.hackDifficulty) / 100;
|
||||||
var skillMult = (Player.hacking_chance_multiplier * Player.hacking_skill);
|
var skillMult = (Player.hacking_chance_multiplier * Player.hacking_skill);
|
||||||
@ -98,22 +101,40 @@ var Player = {
|
|||||||
calculateHackingTime: function() {
|
calculateHackingTime: function() {
|
||||||
var difficultyMult = Player.currentServer.requiredHackingSkill * Player.currentServer.hackDifficulty;
|
var difficultyMult = Player.currentServer.requiredHackingSkill * Player.currentServer.hackDifficulty;
|
||||||
var skillFactor = difficultyMult / Player.hacking_skill;
|
var skillFactor = difficultyMult / Player.hacking_skill;
|
||||||
console.log("Player.hacking_speed_multiplier: " + Player.hacking_speed_multiplier);
|
|
||||||
return skillFactor * Player.hacking_speed_multiplier;
|
return skillFactor * Player.hacking_speed_multiplier;
|
||||||
},
|
},
|
||||||
|
|
||||||
//Hack a server. Return the amount of money hacked.
|
//Calculates the PERCENTAGE of a server's money that the player will hack from the server if successful
|
||||||
//This assumes that the server being hacked is not purchased by the palyer, that the player's hacking skill is greater than the
|
//The formula is:
|
||||||
|
// (hacking_skill - (requiredLevel-1)) 100 - difficulty
|
||||||
|
// --------------------------------------* ----------------------- * hacking_money_multiplier
|
||||||
|
// hacking_skill 100
|
||||||
|
calculatePercentMoneyHacked: function() {
|
||||||
|
var difficultyMult = (100 - Player.currentServer.hackDifficulty) / 100;
|
||||||
|
var skillMult = (Player.hacking_skill - (Player.currentServer.requiredHackingSkill - 1)) / Player.hacking_skill;
|
||||||
|
var percentMoneyHacked = difficultyMult * skillMult * Player.hacking_money_multiplier;
|
||||||
|
console.log("Percent money hacked calculated to be: " + percentMoneyHacked);
|
||||||
|
return percentMoneyHacked;
|
||||||
|
},
|
||||||
|
|
||||||
|
//Returns how much EXP the player gains on a successful hack
|
||||||
|
//The formula is:
|
||||||
|
// difficulty * requiredLevel * hacking_multiplier
|
||||||
|
//
|
||||||
|
// Note: Keep it at an integer for now,
|
||||||
|
calculateExpGain: function() {
|
||||||
|
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
|
||||||
|
//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.
|
//required hacking skill and that the player has admin rights.
|
||||||
hack: function(hackingSkill) {
|
hack: function() {
|
||||||
Player.hackingTime = Player.calculateHackingTime();
|
Player.hackingTime = Player.calculateHackingTime();
|
||||||
console.log("Hacking time: " + Player.hackingTime);
|
console.log("Hacking time: " + Player.hackingTime);
|
||||||
//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;
|
||||||
|
|
||||||
//DEBUG
|
return Player.hackingTime;
|
||||||
return 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
@ -423,8 +423,6 @@ ForeignServers = {
|
|||||||
|
|
||||||
/* Create a randomized network of all foreign servers */
|
/* Create a randomized network of all foreign servers */
|
||||||
createNetwork: function() {
|
createNetwork: function() {
|
||||||
console.log("createNetwork() called");
|
|
||||||
|
|
||||||
//Groupings for creating a randomized network
|
//Groupings for creating a randomized network
|
||||||
var NetworkGroup1 = [ForeignServers.IronGym, ForeignServers.FoodNStuff, ForeignServers.SigmaCosmetics, ForeignServers.JoesGuns, ForeignServers.HongFangTeaHouse, ForeignServers.HaraKiriSushiBar];
|
var NetworkGroup1 = [ForeignServers.IronGym, ForeignServers.FoodNStuff, ForeignServers.SigmaCosmetics, ForeignServers.JoesGuns, ForeignServers.HongFangTeaHouse, ForeignServers.HaraKiriSushiBar];
|
||||||
var NetworkGroup2 = [ForeignServers.MaxHardware, ForeignServers.NectarNightclub, ForeignServers.Zer0Nightclub];
|
var NetworkGroup2 = [ForeignServers.MaxHardware, ForeignServers.NectarNightclub, ForeignServers.Zer0Nightclub];
|
||||||
|
@ -34,6 +34,37 @@ $(document).keyup(function(event) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var Terminal = {
|
var Terminal = {
|
||||||
|
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 = '$ <input type="text" class="terminal-input"/>';
|
||||||
|
$('input[class=terminal-input]').prop('disabled', false);
|
||||||
|
},
|
||||||
|
|
||||||
executeCommand: function(command) {
|
executeCommand: function(command) {
|
||||||
var commandArray = command.split(" ");
|
var commandArray = command.split(" ");
|
||||||
|
|
||||||
@ -53,7 +84,7 @@ var Terminal = {
|
|||||||
break;
|
break;
|
||||||
case "connect":
|
case "connect":
|
||||||
case "telnet":
|
case "telnet":
|
||||||
//Disconnect from current server in terminal and connect to new one..maybe rename this to telnet?
|
//Disconnect from current server in terminal and connect to new one
|
||||||
if (commandArray.length != 2) {
|
if (commandArray.length != 2) {
|
||||||
post("Incorrect usage of connect/telnet command. Usage: connect/telnet [ip/hostname]");
|
post("Incorrect usage of connect/telnet command. Usage: connect/telnet [ip/hostname]");
|
||||||
return;
|
return;
|
||||||
@ -79,7 +110,7 @@ var Terminal = {
|
|||||||
post("Available: " + (Player.currentServer.maxRam - Player.currentServer.ramUsed).toString() + " GB");
|
post("Available: " + (Player.currentServer.maxRam - Player.currentServer.ramUsed).toString() + " GB");
|
||||||
break;
|
break;
|
||||||
case "hack":
|
case "hack":
|
||||||
//TODO Hack the current PC (usually for money)
|
//Hack the current PC (usually for money)
|
||||||
//You can't hack your home pc or servers you purchased
|
//You can't hack your home pc or servers you purchased
|
||||||
if (Player.currentServer.purchasedByPlayer) {
|
if (Player.currentServer.purchasedByPlayer) {
|
||||||
post("Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers");
|
post("Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers");
|
||||||
@ -90,7 +121,12 @@ var Terminal = {
|
|||||||
} else {
|
} else {
|
||||||
hackProgressPost("Time left:");
|
hackProgressPost("Time left:");
|
||||||
hackProgressBarPost("[");
|
hackProgressBarPost("[");
|
||||||
var hackResult = Player.hack();
|
var timeToHack = Player.hack();
|
||||||
|
|
||||||
|
//Disable terminal
|
||||||
|
console.log("Disabling terminal");
|
||||||
|
document.getElementById("terminal-input-td").innerHTML = '<input type="text" class="terminal-input"/>';
|
||||||
|
$('input[class=terminal-input]').prop('disabled', true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "help":
|
case "help":
|
||||||
@ -108,7 +144,23 @@ var Terminal = {
|
|||||||
//TODO
|
//TODO
|
||||||
break;
|
break;
|
||||||
case "ls":
|
case "ls":
|
||||||
//TODO
|
//Display all programs and scripts
|
||||||
|
var allFiles = [];
|
||||||
|
|
||||||
|
//Get all of the programs and scripts on the machine into one temporary array
|
||||||
|
for (var i = 0; i < Player.currentServer.programs.length; i++) {
|
||||||
|
allFiles.push(Player.currentServer.programs[i]);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < Player.currentServer.scripts.length; i++) {
|
||||||
|
allFiles.push(Player.currentServer.scripts[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Sort the files alphabetically then print each
|
||||||
|
allFiles.sort();
|
||||||
|
|
||||||
|
for (var i = 0; i < allFiles.length; i++) {
|
||||||
|
post(allFiles[i]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "netstat":
|
case "netstat":
|
||||||
case "scan":
|
case "scan":
|
||||||
@ -154,9 +206,27 @@ var Terminal = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//First called when the "run [program]" command is called. Checks to see if you
|
||||||
|
//have the executable and, if you do, calls the executeProgram() function
|
||||||
runProgram: function(programName) {
|
runProgram: function(programName) {
|
||||||
|
//Check if you have the program on your computer. If you do, execute it, otherwise
|
||||||
|
//display an error message
|
||||||
|
for (var i = 0; i < Player.homeComputer.programs.length; i++) {
|
||||||
|
if (Player.homeComputer.programs[i] == programName) {
|
||||||
|
Terminal.executeProgram(programName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post("ERROR: No such executable");
|
||||||
|
},
|
||||||
|
|
||||||
|
//Contains the implementations of all possible programs
|
||||||
|
executeProgram: function(programName) {
|
||||||
switch (programName) {
|
switch (programName) {
|
||||||
case "PortHack":
|
case "PortHack.exe":
|
||||||
|
if (Player.currentServer.hasAdminRights) {
|
||||||
|
post("You already have root access to this computer. There is no reason to run PortHack.exe");
|
||||||
|
} else {
|
||||||
console.log("Running PortHack executable");
|
console.log("Running PortHack executable");
|
||||||
if (Player.currentServer.openPortCount >= Player.currentServer.numOpenPortsRequired) {
|
if (Player.currentServer.openPortCount >= Player.currentServer.numOpenPortsRequired) {
|
||||||
Player.currentServer.hasAdminRights = true;
|
Player.currentServer.hasAdminRights = true;
|
||||||
@ -165,6 +235,7 @@ var Terminal = {
|
|||||||
} else {
|
} else {
|
||||||
post("PortHack unsuccessful. Not enough ports have been opened");
|
post("PortHack unsuccessful. Not enough ports have been opened");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
post("Executable not found");
|
post("Executable not found");
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
//Replaces the character at an index with a new character
|
||||||
|
String.prototype.replaceAt=function(index, character) {
|
||||||
|
return this.substr(0, index) + character + this.substr(index+character.length);
|
||||||
|
}
|
||||||
|
|
||||||
var Engine = {
|
var Engine = {
|
||||||
|
|
||||||
@ -132,14 +136,15 @@ var Engine = {
|
|||||||
|
|
||||||
//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;
|
||||||
Engine._hackProgressBarCount = 0;
|
Engine._hackProgressBarCount = 1;
|
||||||
Engine._hackProgressStr = "[";
|
Engine._hackProgressStr = "[ ]";
|
||||||
Engine._hackTimeStr = "Time left: ";
|
Engine._hackTimeStr = "Time left: ";
|
||||||
Player.startHack = false;
|
Player.startHack = false;
|
||||||
|
|
||||||
|
document.getElementById("hack-progress-bar").style.whiteSpace = "pre";
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine.updateHackProgress();
|
Engine.updateHackProgress();
|
||||||
@ -155,33 +160,35 @@ var Engine = {
|
|||||||
_totalHackTime: 0,
|
_totalHackTime: 0,
|
||||||
_hackTimeLeft: 0,
|
_hackTimeLeft: 0,
|
||||||
_hackTimeStr: "Time left: ",
|
_hackTimeStr: "Time left: ",
|
||||||
_hackProgressStr: "[",
|
_hackProgressStr: "[ ]",
|
||||||
_hackProgressBarCount: 0,
|
_hackProgressBarCount: 1,
|
||||||
_manualHackInProgress: false,
|
_manualHackInProgress: false,
|
||||||
updateHackProgress: function() {
|
updateHackProgress: function() {
|
||||||
if (Engine._manualHackInProgress == true) {
|
if (Engine._manualHackInProgress == true) {
|
||||||
console.log("Manual Hack in Progress");
|
|
||||||
Engine._hackTimeLeft -= (Engine._idleSpeed/ 1000); //Substract idle speed (ms)
|
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.round((1 - Engine._hackTimeLeft / Engine._totalHackTime) * 100);
|
||||||
console.log("Hack progress percent: " + percent);
|
|
||||||
|
|
||||||
//Update progress bar
|
//Update progress bar
|
||||||
if (Engine._hackProgressBarCount * 2 < percent) {
|
while (Engine._hackProgressBarCount * 2 <= percent) {
|
||||||
Engine._hackProgressStr += '|';
|
Engine._hackProgressStr = Engine._hackProgressStr.replaceAt(Engine._hackProgressBarCount, "|");
|
||||||
Engine._ProgressBarCount += 1;
|
Engine._hackProgressBarCount += 1;
|
||||||
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: " + Math.max(0, Math.round(Engine._hackTimeLeft)).toString() + "s";
|
||||||
|
document.getElementById("hack-progress").innerHTML = Engine._hackTimeStr;
|
||||||
|
|
||||||
|
//Dynamically update progress bar
|
||||||
|
document.getElementById("hack-progress-bar").innerHTML = Engine._hackProgressStr.replace( / /g, " " );
|
||||||
|
|
||||||
//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;
|
Terminal.finishHack();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user