Added cases for all the commands that will be implemented for now. Updated Server class to contain information about servers, home computer, etc. Added a few fields to Server that will be used when hacking, as well as constructor.

This commit is contained in:
Daniel Xie 2016-10-17 16:23:23 -05:00
parent 7c03b274d7
commit a1fd46232e
4 changed files with 117 additions and 38 deletions

@ -39,9 +39,14 @@ var Player = {
total_money: 0,
lifetime_money: 0,
//Starting (home) computer
homeComputer = new Server();
startingServer.init("19.42.93.219", "home.pc", true, true, true, true, 2);
//Servers
//discoveredServers = [],
//purchasedServers = [],
currentServer = homeComputer, //Server currently being accessed through terminal
discoveredServers = [],
purchasedServers = [],
//Achievements and achievement progress

@ -1,19 +1,54 @@
//Netburner Server class
// Parent class for a Server object. PlayerServer and NPCServer inherit from this
var Server = {
function Server() = {
/* Properties */
//Connection information
ip: "0.0.0.0",
isOnline: false,
this.ip: "0.0.0.0",
this.hostname: "",
this.isOnline: true,
this.isConnectedTo: false, //Whether the player is connected to this server
ownedByPlayer: false,
//Access information
this.hasAdminRights: false, //Whether player has admin rights
this.purchasedByPlayer: false,
//Properties
max_ram: 1, //GB
ram_used: 0,
//RAM and Scripts
maxRam: 1, //GB
ramUsed: 0,
//scripts = [],
scripts = [],
runningScripts = [], //Scripts currently being run
programs = [],
//Manual hack state information
is_hacking: false,
hacking_progress: 0,
};
/* Hacking information (only valid for "foreign" aka non-purchased servers) */
//Skill required to attempt a hack. Whether a hack is successful will be determined
//by a separate formula
requiredHackingSkill = 1,
//Total money available on this server. How much of this you hack will be determined
//by a formula related to hacking skill. The money available on a server will steadily increase
//over time, and it will decrease when you hack it
moneyAvailable = 500,
//Manual hack state information (hacking done without script)
isHacking: false,
hackingProgress: 0,
};
//Initialize the properties of a server
Server.prototype.init = function(ip, hostname, onlineStatus, isConnectedTo, adminRights, purchasedByPlayer, maxRam) {
this.ip = ip;
this.hostname = hostname;
this.isOnline = onlineStatus;
this.isConnectedTo = isConnectedTo;
this.hasAdminRights = adminRights;
this.purchasedByPlayer = purchasedByPlayer;
this.maxRam = maxRam;
}
//Create all "foreign" servers that exist in the game. This does not include
//servers that the player can purchase or the player's starting computer
function initAllServers() {
}

@ -10,9 +10,10 @@ $(document).keyup(function(event) {
var command = $('input[class=terminal-input]').val();
if (command.length > 0) {
post("> " + command);
$('input[class=terminal-input]').val("");
//Execute command function here
//TODO Do i have to switch the order of these two?
executeCommand(command);
$('input[class=terminal-input]').val("");
}
}
});
@ -25,6 +26,60 @@ var executeCommand = function(command) {
}
switch (commandArray[0]) {
case
case "analyze":
//TODO Analyze the system for ports
break;
case "clear":
case "cls":
//TODO
break;
case "connect":
//TODO Disconnect from current server in terminal and connect to new one
break;
case "df":
//TODO
break;
case "hack":
//TODO Hack the current PC (usually for money)
//You can't hack your home pc or servers you purchased
if (Player.currentServer.purchasedByPlayer) {
post("Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers");
} else {
}
break;
case "help":
//TODO
break;
case "hostname":
//Print the hostname of current system
post(Player.currentServer.hostname);
break;
case "ifconfig":
//Print the IP address of the current system
post(Player.currentServer.ip);
break;
case "kill":
//TODO
break;
case "ls":
//TODO
break;
case "ps":
//TODO
break;
case "rm":
//TODO
break;
case "run":
//TODO
break;
case "scan":
//TODO
break;
}
}
}
var runProgram = function(programName) {
}

@ -87,6 +87,7 @@ var Engine = {
loadTerminalContent: function() {
Engine.hideAllContent();
Engine.Display.terminalContent.style.visibility = "visible";
post("Netburner v1.0");
},
loadCharacterContent: function() {
@ -108,7 +109,8 @@ var Engine = {
'Strength: ' + Player.strength + '<br><br>' +
'Defense: ' + Player.defense + '<br><br>' +
'Dexterity: ' + Player.dexterity + '<br><br>' +
'Agility: ' + Player.agility + '<br><br>';
'Agility: ' + Player.agility + '<br><br>' +
'Servers owned: ' + Player.purchasedServers.length + <br><br>';
},
/* Main Event Loop */
@ -139,24 +141,6 @@ var Engine = {
/* Initialization */
init: function() {
//Hacking button
//Engine.Clickables.hackButton = document.getElementById("hackbutton");
//Event Listener for hacking button
//Engine.Clickables.hackButton.addEventListener("click", function() {
// ++Player.hacking_skill;
//Returns false so that once the code runs, the button won't try to do
//anything else
// return false;
//});
//Hacking Skill Display
//Engine.Display.hacking_skill = document.getElementById("hackingskill");
//Status display
//Engine.Display.statusText = document.getElementById("status");
//Load, save, and delete buttons
//Engine.Clickables.saveButton = document.getElementById("save");
//Engine.Clickables.saveButton.addEventListener("click", function() {