VMXI7PS4GFDOWPFLHQ7TYKJ5K3K7FXNPJCBEVYHTTRN7YB5ZHEQAC // ram is at least equal to the ram of "home", probably a bad idea to hardcode this since the string_name of "home" might change in the future. tags: warning, potential, problem(integer_server_ram_biggest_afforded >= integer_get_server_ram_total(ns, object_constants.string_host)) &&// you have no bought servers yet(ns.getPurchasedServers().length === 0)
// ram is at least equal to the ram of "home" (probably a bad idea to hardcode this since the string_name of "home" might change in the future) or max ram.(integer_server_ram_biggest_afforded >= integer_get_server_ram_total(ns, "home") ||integer_server_ram_biggest_afforded >= object_constants.PurchasedServerMaxRam)
(float_ram_server_bought_biggest != integer_servers_bought_limit) &&(integer_get_server_ram_biggest_afforded(ns) > float_ram_server_bought_biggest)
(float_ram_server_bought_biggest != object_constants.PurchasedServerMaxRam) &&(float_ram_server_bought_biggest < integer_get_server_ram_biggest_afforded(ns))
// returns the score of a server which is calculated by taking into account its max cash, growth, minimum security level and server difficulty
// returns the score of a server which is calculated by taking into account its max cash, growth, and required hacking level. adapted from `calculatePercentMoneyHacked` in Hacking.js
return ns.getServerMaxMoney(string_server_target) * ns.getServerGrowth(string_server_target) * Math.pow(ns.getServerMinSecurityLevel(string_server_target), -1) * Math.pow(ns.getServerRequiredHackingLevel(string_server_target), -1);
const float_player_hacking_level = ns.getHackingLevel();return ns.getServerMaxMoney(string_server_target) * ns.getServerGrowth(string_server_target) * ((float_player_hacking_level - (ns.getServerRequiredHackingLevel(string_server_target) - 1)) * Math.pow(float_player_hacking_level, -1));
};// returns the security increase from the growth threads used. Adapted from `processSingleServerGrowth` in ServerHelpers.ts and `fortify` in Server.tsconst float_get_security_increase_from_grow = function(ns, integer_threads_grow) {void_debug(float_get_security_increase_from_grow, Array.from(arguments));return 2 * object_get_constants(ns).ServerFortifyAmount * integer_threads_grow;
const skillMult = (object_constants.object_stats.hacking - (ns.getServerRequiredHackingLevel(string_server_target) - 1)) / object_constants.object_stats.hacking;let percentMoneyHacked = difficultyMult * skillMult * object_constants.object_hacking_multipliers.money / balanceFactor;if (percentMoneyHacked < 0) {return 0;}if (percentMoneyHacked > 1) {return 1;}
const skillMult = (ns.getHackingLevel() - (ns.getServerRequiredHackingLevel(string_server_target) - 1)) / ns.getHackingLevel();const percentMoneyHacked = difficultyMult * skillMult * object_constants.object_hacking_multipliers.money / balanceFactor;if (percentMoneyHacked < 0) { return 0; }if (percentMoneyHacked > 1) { return 1; }
return float_percentage_to_steal / float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security);
return Math.ceil(float_percentage_to_steal / float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security));
};// returns the security increase from the hack threads. adapted from `hack` in NetscriptFunctions.js and `fortify` in Server.tsconst float_get_security_increase_from_hack = function(ns, string_server_target, float_server_target_security, float_server_target_cash, integer_threads_hack) {void_debug(float_get_security_increase_from_hack, Array.from(arguments));let maxThreadNeeded = Math.ceil(1/float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security)*(float_server_target_cash/ns.getServerMaxMoney(string_server_target)));if (isNaN(maxThreadNeeded)) {// Server has a 'max money' of 0 (probably). We'll set this to an arbitrarily large valuemaxThreadNeeded = 1e6;}return object_get_constants(ns).ServerFortifyAmount * Math.min(integer_threads_hack, maxThreadNeeded);
// returns true if there is enough ram to provide the threads required by grow to grow string_server_target's cash by float_percentage_to_steal if possible, otherwise, returns false. assumes security is at float_server_target_securityconst bool_is_ram_enough_for_growth_percentage = function(ns, float_server_used_ram_free, string_server_target, float_percentage_to_steal, float_server_target_security) {void_debug(bool_is_ram_enough_for_growth_percentage, Array.from(arguments));
// returns true if there is enough ram to provide the threads required by weaken to weaken to minimum security, then by grow to grow string_server_target's cash by float_percentage_to_steal, then by weaken to weaken to minimum security again if possible, otherwise, returns false. assumes security is at float_server_target_securityconst bool_is_ram_enough_after_hack_percentage = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash_before, float_server_target_security, float_percentage_to_steal) {void_debug(bool_is_ram_enough_after_hack_percentage, Array.from(arguments));
const integer_threads_required = integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security, float_percentage_to_steal);
const integer_threads_required = integer_get_threads_required_for_min_security_weaken(ns, string_server_target, float_get_security_increase_from_hack(ns, string_server_target, float_server_target_security, float_server_target_cash_before, integer_get_threads_hack(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_percentage_to_steal))) + integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security, float_percentage_to_steal) + integer_get_threads_required_for_min_security_weaken(ns, string_server_target, float_get_security_increase_from_grow(ns, integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security, float_percentage_to_steal)));
// this should return optimum percentage to steal such that cash stolen is as high as float_cap and string_server_target's cash still able to be grown to 100% after one grow with the ram it has remaining by using a binary search algorithmconst float_get_percentage_to_steal = function(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_precision, float_cap) {
// this should return optimum percentage to steal such that cash stolen is as high as float_steal_cap and string_server_target's cash still able to be grown to 100% after one grow with the ram it has remaining by using a binary search algorithmconst float_get_percentage_to_steal = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash_before, float_server_target_security, float_precision, float_steal_cap) {
if (bool_is_ram_enough_for_growth_percentage(ns, float_server_used_ram_free_halved, string_server_target, float_percentage_to_steal, float_server_target_security)) {
if (bool_is_ram_enough_after_hack_percentage(ns, float_server_used_ram_free, string_server_target, float_server_target_cash_before, float_server_target_security, float_percentage_to_steal)) {
if (hack == null) {hack = object_constants.object_stats.hacking;}if (int == null) {int = object_constants.object_stats.intelligence;}
const hack = object_constants.object_stats.hacking;const int = object_constants.object_stats.intelligence;
for (let integer_indices_0 = 0; integer_indices_0 < array_servers_rooted_sorted_by_ram.length; ++integer_indices_0) {
// iterate through servers in reverse to use servers with the biggest rams firstfor (let integer_indices_0 = array_servers_rooted_sorted_by_ram.length - 1; integer_indices_0 >= 0; --integer_indices_0) {if (integer_array_schedule_length >= integer_action_cap) {break;}
let float_server_target_security_uncorrected = float_server_target_security_current - (integer_threads_weaken * object_constants.ServerWeakenAmount);
const float_server_target_security_uncorrected = float_server_target_security_current - (integer_threads_weaken * object_constants.ServerWeakenAmount);
let float_server_target_cash_current_uncorrected = float_server_target_cash_current * float_get_growth_from_threads(ns, string_server_target, float_server_target_security_current, integer_threads_grow);
const float_server_target_cash_current_uncorrected = float_server_target_cash_current * float_get_growth_from_threads(ns, string_server_target, float_server_target_security_current, integer_threads_grow);
const integer_threads_hack = integer_get_threads_hack(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_get_percentage_to_steal (ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_precision, float_cap));
// this is supposed to be the section that uses the `float_get_percentage_to_steal` function to calculate and hack the optimum amount of cash, but it doesn't seem to work properly and I still haven't figured why or how to fix it, so for now I think it just hacks whatever `float_steal_cap` percent of cash the server has.//const integer_threads_hack = integer_get_threads_hack(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_get_percentage_to_steal(ns, float_server_used_ram_free_current, string_server_target, float_server_target_cash_current, float_server_target_security_current, float_precision, float_steal_cap));
float_server_used_ram_free_current -= integer_threads_hack * object_scripts.hack.ram;
const integer_threads_hack = integer_get_threads_hack(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_steal_cap);
float_server_target_cash_current -= float_server_target_cash_current * float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security_current);
float_server_used_ram_free_current -= integer_threads_hack * object_scripts.hack.ram;
let maxThreadNeeded = Math.ceil(1/float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security_current)*(float_server_target_cash_current/float_server_target_cash_maximum));if (isNaN(maxThreadNeeded)) {// Server has a 'max money' of 0 (probably). We'll set this to an arbitrarily large valuemaxThreadNeeded = 1e6;
const float_server_target_cash_before = float_server_target_cash_current;const float_server_target_cash_current_uncorrected = float_server_target_cash_current - Math.floor(float_server_target_cash_current * float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security_current)) * integer_threads_hack;if (float_server_target_cash_current_uncorrected < 0) {float_server_target_cash_current = 0;
float_server_target_security_current += object_constants.ServerFortifyAmount * Math.min(integer_threads_hack, maxThreadNeeded);
else {float_server_target_cash_current = float_server_target_cash_current_uncorrected;}float_server_target_security_current += float_get_security_increase_from_hack(ns, string_server_target, float_server_target_security_current, float_server_target_cash_before, integer_threads_hack);
export const void_schedule_runner = async function(ns, string_servers_bought_name, float_precision, float_cap, float_padding_seconds) {
export const void_schedule_runner = async function(ns, string_servers_bought_name, integer_action_cap, float_precision, float_steal_cap, float_padding_seconds) {
const array_schedule = array_make_schedule(ns, float_precision, float_cap, float_padding_seconds);
const array_schedule = array_make_schedule(ns, integer_action_cap, float_precision, float_steal_cap, float_padding_seconds);
// the maximum percentage of cash that should be stolen from a serverconst float_cap = 0.98;// time period used for checking the time in seconds
// the maximum percentage of cash that should be stolen from a serverconst float_steal_cap = 0.98;// time period used for checking the time in seconds
integer_time_finishes = await void_schedule_runner(ns, string_servers_bought_name, float_precision, float_cap, float_padding_seconds) + Date.now();
integer_time_finishes = await void_schedule_runner(ns, string_servers_bought_name, integer_action_cap, float_precision, float_steal_cap, float_padding_seconds) + Date.now();
const void_print_information = function (ns, string_server) {const float_cash_max = ns.getServerMaxMoney(string_server);const float_cash_current = ns.getServerMoneyAvailable(string_server);const float_security_minimum = ns.getServerMinSecurityLevel(string_server);const float_security_current = Math.round(ns.getServerSecurityLevel(string_server));const array_ram = ns.getServerRam(string_server);const float_ram_total = array_ram[0];const float_ram_used = array_ram[1];const float_ram_free = array_ram[0] - array_ram[1];const string_server_information =// comment out unneeded info`Time: ${new Date().toISOString()}Name: ${string_server}Root access: ${ns.hasRootAccess(string_server)}Maximum cash ($): ${float_cash_max}Current cash ($): ${float_cash_current.toFixed(2)}Current cash (%): ${(float_cash_current * 100 / float_cash_max).toFixed(2)}Minimum security: ${float_security_minimum}Current security: ${float_security_current}Current security (x): ${(float_security_current / float_security_minimum).toFixed(2)}Growth rate: ${ns.getServerGrowth(string_server)}Hacking level needed: ${ns.getServerRequiredHackingLevel(string_server)}Ports needed for root: ${ns.getServerNumPortsRequired(string_server)}RAM total (GB): ${float_ram_total}RAM used (GB): ${float_ram_used.toFixed(2)}RAM used (%): ${(float_ram_used * 100 / float_ram_total).toFixed(2)}RAM free (GB): ${float_ram_free.toFixed(2)}RAM free (%): ${(float_ram_free * 100 / float_ram_total).toFixed(2)}`;ns.tprint(string_server_information);};
for (let indices_0 = 0; indices_0 < ns.args.length; ++indices_0) {const float_cash_max = ns.getServerMaxMoney(ns.args[indices_0]);const float_cash_current = ns.getServerMoneyAvailable(ns.args[indices_0]);const float_security_minimum = ns.getServerMinSecurityLevel(ns.args[indices_0]);const float_security_current = Math.round(ns.getServerSecurityLevel(ns.args[indices_0]));const array_ram = ns.getServerRam(ns.args[indices_0]);const float_ram_total = array_ram[0];const float_ram_used = array_ram[1];const float_ram_free = array_ram[0] - array_ram[1];const data = [// comment out unneeded info"Name:\t\t\t" + ns.args[indices_0],"Root access:\t\t" + ns.hasRootAccess(ns.args[indices_0]),"Maximum cash ($):\t" + float_cash_max,"Current cash ($):\t" + float_cash_current.toFixed(2),"Current cash (%):\t" + (float_cash_current * 100 / float_cash_max).toFixed(2),"Growth:\t\t" + ns.getServerGrowth(ns.args[indices_0]),"Minimum security:\t" + float_security_minimum,"Current security:\t" + float_security_current,"Current security (x):\t" + (float_security_current / float_security_minimum).toFixed(2),"Hacking level needed:\t" + ns.getServerRequiredHackingLevel(ns.args[indices_0]),"Ports needed for root:\t" + ns.getServerNumPortsRequired(ns.args[indices_0]),"RAM total (Gb):\t" + float_ram_total,"RAM used (Gb):\t\t" + float_ram_used.toFixed(2),"RAM used (%):\t\t" + (float_ram_used * 100 / float_ram_total).toFixed(2),"RAM free (Gb):\t\t" + float_ram_free.toFixed(2),"RAM free (%):\t\t" + (float_ram_free * 100 / float_ram_total).toFixed(2),"\n"];for (let indices_0 = 0; indices_0 < data.length; ++indices_0) {ns.tprint(data[indices_0]);}
let array_arguments = ns.args;let float_sleep_duration = 0;while (true) {for (let integer_indices_0 = 0; integer_indices_0 < array_arguments.length; ++integer_indices_0) {const string_argument = array_arguments[integer_indices_0];if ((string_argument === "--sleep") ||(string_argument === "-s")) {float_sleep_duration = array_arguments[integer_indices_0 + 1];array_arguments.splice(integer_indices_0, 2);}try {void_print_information(ns, string_argument);}catch (error) {ns.tprint(JSON.stringify(error));}}if (float_sleep_duration < 1) {break;}else {await ns.sleep(float_sleep_duration);}