Added BitNode multipliers for purchased servers. Fixed bugs in new Script Editor implementation. Added documentation for script editors

This commit is contained in:
danielyxie
2019-01-29 22:02:27 -08:00
parent d54f0906f0
commit a09ea46a38
31 changed files with 3355 additions and 2558 deletions
+46 -18
View File
@@ -1,16 +1,46 @@
import {CONSTANTS} from "./Constants";
import {Player} from "./Player";
import {Server, AllServers, AddToAllServers} from "./Server";
import {dialogBoxCreate} from "../utils/DialogBox";
import {createRandomIp} from "../utils/IPAddress";
import {yesNoTxtInpBoxGetInput} from "../utils/YesNoBox";
/* Functions to handle any server-related purchasing:
* Purchasing new servers
* Purchasing more RAM for home computer
/**
* Implements functions for purchasing servers or purchasing more RAM for
* the home computer
*/
function purchaseServer(ram, cost) {
import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
import { CONSTANTS } from "./Constants";
import { Player } from "./Player";
import { Server,
AllServers,
AddToAllServers} from "./Server";
import { dialogBoxCreate } from "../utils/DialogBox";
import { createRandomIp } from "../utils/IPAddress";
import { yesNoTxtInpBoxGetInput } from "../utils/YesNoBox";
import { isPowerOfTwo } from "../utils/helpers/isPowerOfTwo";
// Returns the cost of purchasing a server with the given RAM
// Returns Infinity for invalid 'ram' arguments
export function getPurchaseServerCost(ram) {
const sanitizedRam = Math.round(ram);
if (isNaN(sanitizedRam) || !isPowerOfTwo(sanitizedRam)) {
return Infinity;
}
if (sanitizedRam > getPurchaseServerMaxRam()) {
return Infinity;
}
return sanitizedRam * CONSTANTS.BaseCostFor1GBOfRamServer * BitNodeMultipliers.PurchasedServerCost;
}
export function getPurchaseServerLimit() {
return Math.round(CONSTANTS.PurchasedServerLimit * BitNodeMultipliers.PurchasedServerLimit);
}
export function getPurchaseServerMaxRam() {
// TODO ensure this is a power of 2?
return Math.round(CONSTANTS.PurchasedServerMaxRam * BitNodeMultipliers.PurchasedServerMaxRam);
}
// Manually purchase a server (NOT through Netscript)
export function purchaseServer(ram) {
const cost = getPurchaseServerCost(ram);
//Check if player has enough money
if (Player.money.lt(cost)) {
dialogBoxCreate("You don't have enough money to purchase this server!");
@@ -18,8 +48,8 @@ function purchaseServer(ram, cost) {
}
//Maximum server limit
if (Player.purchasedServers.length >= CONSTANTS.PurchasedServerLimit) {
dialogBoxCreate("You have reached the maximum limit of " + CONSTANTS.PurchasedServerLimit + " servers. " +
if (Player.purchasedServers.length >= getPurchaseServerLimit()) {
dialogBoxCreate("You have reached the maximum limit of " + getPurchaseServerLimit() + " servers. " +
"You cannot purchase any more. You can " +
"delete some of your purchased servers using the deleteServer() Netscript function in a script");
return;
@@ -51,8 +81,8 @@ function purchaseServer(ram, cost) {
dialogBoxCreate("Server successfully purchased with hostname " + hostname);
}
function purchaseRamForHomeComputer(cost) {
// Manually upgrade RAM on home computer (NOT through Netscript)
export function purchaseRamForHomeComputer(cost) {
if (Player.money.lt(cost)) {
dialogBoxCreate("You do not have enough money to purchase additional RAM for your home computer");
return;
@@ -70,5 +100,3 @@ function purchaseRamForHomeComputer(cost) {
dialogBoxCreate("Purchased additional RAM for home computer! It now has " + homeComputer.maxRam + "GB of RAM.");
}
export {purchaseServer, purchaseRamForHomeComputer};