// Custom color coding. const cCyan = "\u001b[36m"; const cGreen = "\u001b[32m"; const cRed = "\u001b[31m"; const cReset = "\u001b[0m"; /** @param {NS} ns */ export async function main(ns) { ns.print("This script does nothing on its own, it contains functions for other scripts to use"); } /** @param {NS} ns */ export async function purchaseServers(ns) { const ram = 64; let aServers = listPurchasedServers(ns); let nServers = aServers.length; if (nServers >= ns.getPurchasedServerLimit()) { return nServers; } if (ns.getServerMoneyAvailable("home") > ns.getPurchasedServerCost(ram)) { let sFrontZero = "0"; if (nServers >= 9) { sFrontZero = ""; } let hostname = ns.purchaseServer("pserv-" + sFrontZero + (aServers.length + 1), ram); ns.tprint("Purchased " + cCyan + hostname + cReset); ns.toast("Purchased " + hostname, "info", 10000); } aServers = listPurchasedServers(ns); return aServers.length; } /** @param {NS} ns */ export function listPurchasedServers(ns) { return ns.getPurchasedServers(); } /** @param {NS} ns */ export function getSetting(ns, sSetting) { let oSettings = JSON.parse(ns.read("settings.txt")); let settingEntry = oSettings.setting[sSetting]; //ns.tprint(oSettings.setting[sSetting]) //ns.tprint("settingEntry = "+settingEntry); return settingEntry; } /** @param {NS} ns */ export function getGrowThreads(ns, sTarget, nHackThreads, nCores) { let nHackAmountPercent = ns.hackAnalyze(sTarget) * nHackThreads; let nGrowthThreads = ns.growthAnalyze(sTarget, 1 + nHackAmountPercent, nCores); return nGrowthThreads; }