VHWFHMNWZS4GA5ZW6QSOTDXS4WONZLGEZS5P2RFM7DK7VWDYSHHAC const integer_get_threads_required_for_min_security_weaken = function(ns, string_server_target, float_server_target_security) {void_debug(integer_get_threads_required_for_min_security_weaken, Array.from(arguments));
const integer_get_threads_required_for_weaken_minimum_security = function(ns, string_server_target, float_server_target_security) {void_debug(integer_get_threads_required_for_weaken_minimum_security, Array.from(arguments));
const integer_threads_required = integer_get_threads_required_for_min_security_weaken(ns, string_server_target, float_server_target_security);
const integer_threads_required = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security);
};// returns the security decrease from the weaken threads used. Adapted from `weaken` in NetscriptFunctions.js and `weaken` in Server.tsconst float_get_security_decrease_from_weaken = function(ns, integer_threads_weaken) {void_debug(float_get_security_decrease_from_weaken, Array.from(arguments));return integer_threads_weaken * object_get_constants(ns).ServerWeakenAmount;
const integer_get_threads_required_for_max_cash_grow = function(ns, string_server_target, float_server_target_security, float_server_target_cash) {void_debug(integer_get_threads_required_for_max_cash_grow, Array.from(arguments));
const integer_get_threads_required_for_grow_maximum_cash = function(ns, string_server_target, float_server_target_security, float_server_target_cash) {void_debug(integer_get_threads_required_for_grow_maximum_cash, Array.from(arguments));
const integer_threads_required = integer_get_threads_required_for_max_cash_grow(ns, string_server_target, float_server_target_security, float_server_target_cash);
const integer_threads_required = integer_get_threads_required_for_grow_maximum_cash(ns, string_server_target, float_server_target_security, float_server_target_cash);
const float_get_threads_required_to_hack_percentage = function(ns, string_server_target, float_server_target_security, float_percentage_to_steal) {void_debug(float_get_threads_required_to_hack_percentage, Array.from(arguments));
const integer_get_threads_required_to_hack_percentage = function(ns, string_server_target, float_server_target_security, float_percentage_to_steal) {void_debug(integer_get_threads_required_to_hack_percentage, Array.from(arguments));
const integer_threads_required = float_get_threads_required_to_hack_percentage(ns, string_server_target, float_server_target_security, float_percentage_to_steal);
const integer_threads_required = integer_get_threads_required_to_hack_percentage(ns, string_server_target, float_server_target_security, float_percentage_to_steal);
// 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) {
// should return 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 back to maximum after stealing float_percentage_to_steal of the cash, 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, float_server_target_security, float_percentage_to_steal) {
const integer_threads_available = Math.trunc(float_server_used_ram_free * Math.pow (object_get_constants(ns).object_scripts.grow.ram, -1));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)));if (integer_threads_required < integer_threads_available) {return false;
const float_server_target_security_after_hack = float_server_target_security + float_get_security_increase_from_hack(ns, string_server_target, float_server_target_security, float_server_target_cash, integer_get_threads_hack(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_percentage_to_steal));const integer_threads_required_for_weaken_minimum_security_after_hack = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security_after_hack);const float_server_target_security_after_weaken = float_server_target_security_after_hack - float_get_security_decrease_from_weaken(ns, integer_threads_required_for_weaken_minimum_security_after_hack);const integer_threads_required_for_cash_grow_after_percentage_stolen = integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security_after_weaken, float_percentage_to_steal);const float_server_target_security_after_grow = float_server_target_security_after_weaken + float_get_security_increase_from_grow(ns,integer_threads_required_for_cash_grow_after_percentage_stolen);const integer_threads_required_for_weaken_minimum_security_after_grow = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security_after_grow);const float_ram_required = (integer_threads_required_for_weaken_minimum_security_after_hack * object_scripts.grow.weaken) + (integer_threads_required_for_cash_grow_after_percentage_stolen * object_scripts.grow.ram) + (integer_threads_required_for_weaken_minimum_security_after_grow * object_scripts.grow.weaken);if (float_ram_required < float_server_used_ram_free) {return true;
// 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) {
// this should return optimum percentage to steal such that cash stolen at most is as high as float_steal_cap and string_server_target's security is able to be weakened to minimum with one weaken after the hack, its cash grown to 100% after one grow after the weaken, then its security weakened again to minimum with one weaken, all with the ram it has remaining after the hack 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, float_server_target_security, float_precision, float_steal_cap) {
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 (bool_is_ram_enough_after_hack_percentage(ns, float_server_used_ram_free, string_server_target, float_server_target_cash, float_server_target_security, float_percentage_to_steal)) {
const 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 - float_get_security_decrease_from_weaken(ns, integer_threads_weaken);
// 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));
// // 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));