mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 06:48:42 +02:00
31 lines
993 B
JavaScript
31 lines
993 B
JavaScript
/* Functions to handle Purchase of Servers */
|
|
purchaseServer = function(ram, cost) {
|
|
//Check if player has enough money
|
|
if (cost > Player.money) {
|
|
dialogBoxCreate("You don't have enough money to purchase this server!");
|
|
return;
|
|
}
|
|
|
|
var newServ = new Server();
|
|
var hostname = document.getElementById("purchase-server-box-input").value;
|
|
if (hostname == "") {
|
|
dialogBoxCreate("You must enter a hostname for your new server!");
|
|
return;
|
|
}
|
|
|
|
|
|
//Create server
|
|
newServ.init(createRandomIp(), hostname, "", true, false, true, true, ram);
|
|
AddToAllServers(newServ);
|
|
|
|
//Add to Player's purchasedServers array
|
|
Player.purchasedServers.push(newServ);
|
|
|
|
//Connect new server to home computer
|
|
var homeComputer = Player.getHomeComputer();
|
|
homeComputer.serversOnNetwork.push(newServ);
|
|
|
|
Player.money -= cost;
|
|
|
|
dialogBoxCreate("Server successfully purchased with hostname " + hostname);
|
|
} |