Advertisement
Guest User

Untitled

a guest
Apr 18th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { time, pre, getPsrvs, getPsrvNames, getServerNames, getValidServers } from "utils.js";
  2.  
  3. /**
  4.  * @param {NS} ns
  5.  */
  6. export async function main(ns) {
  7.     const daddy = ns.getScriptName();
  8.     const serverNames = getServerNames(ns);
  9.     let target = "foodnstuff";
  10.  
  11.     if (ns.args.length > 1) {
  12.         ns.tprint(pre(3) + "bad args -- " + daddy + "target?: String");
  13.         ns.exit();
  14.     } else if (serverNames.includes(ns.args[0])) {
  15.         target = ns.args[0];
  16.     }
  17.  
  18.     ns.disableLog("ALL");
  19.     ns.clearLog();
  20.     ns.tail();
  21.     ns.resizeTail(500, 22 * 18 + 26);
  22.     //ns.moveTail(x, y);
  23.  
  24.     let threshold = 0.05;
  25.     const p = ns.getPlayer();
  26.     //p.skills.hacking *= 1; // uncomment and set value to experiment with augmentation bonuses
  27.     const s = ns.getServer(target);
  28.     s.hackDifficulty = s.minDifficulty; // assume a prepared target
  29.     s.moneyAvailable = s.moneyMax; // assume a prepared target
  30.  
  31.     // hack=1.7gb, grow=1.75 weak=1.75
  32.     const hackThreads = Math.max(1, Math.floor(threshold / ns.formulas.hacking.hackPercent(s, p)));
  33.     const hackTime = ns.formulas.hacking.hackTime(s, p);
  34.     const actualHackPercent = hackThreads * ns.formulas.hacking.hackPercent(s, p);
  35.     const actualHackAmount = actualHackPercent * s.moneyMax;
  36.     //const securityIncreaseByHack = ns.hackAnalyzeSecurity(hackThreads); // see next line - toggle (out)comment to verify
  37.     const securityIncreaseByHack = hackThreads * 0.002; // WTF this is fixed?! 1 hackThread => +0.002 security
  38.     ns.print("threads for " + threshold * 100 + "% hack on " + s.hostname + ": " + hackThreads);
  39.     ns.print("=> RAM[GB]: " + hackThreads * 1.7);
  40.     ns.print("=> time[s]: " + ns.formatNumber(hackTime / 1000, 1));
  41.     ns.print("=> actual hack: " + ns.formatNumber(actualHackPercent * 100, 3) + "%"
  42.         + " = $" + ns.formatNumber(actualHackAmount, 1)
  43.         + "/" + ns.formatNumber(s.moneyMax, 1));
  44.     ns.print("=> security increase: " + s.hackDifficulty + " + " + ns.formatNumber(securityIncreaseByHack));
  45.     s.moneyAvailable -= actualHackAmount;
  46.     s.hackDifficulty += securityIncreaseByHack;
  47.  
  48.     const weakHackThreads = Math.ceil(securityIncreaseByHack / 0.05);
  49.     const weakHackTime = ns.formulas.hacking.weakenTime(s, p);
  50.     const actualWeakHack = weakHackThreads * 0.05;
  51.     ns.print("threads for weakHack: " + weakHackThreads);
  52.     ns.print("=> RAM[GB]: " + weakHackThreads * 1.75);
  53.     ns.print("=> time[s]: " + ns.formatNumber(weakHackTime / 1000, 1));
  54.     ns.print("=> wasted weak: " + ns.formatNumber(actualWeakHack - securityIncreaseByHack, 3));
  55.     s.hackDifficulty = s.minDifficulty;
  56.  
  57.     const growThreads = ns.formulas.hacking.growThreads(s, p, s.moneyMax);
  58.     const growTime = ns.formulas.hacking.growTime(s, p);
  59.     const actualGrowPercent = ns.formulas.hacking.growPercent(s, growThreads, p);
  60.     const actualGrowAmount = actualGrowPercent * s.moneyAvailable - s.moneyMax;
  61.     //const securityIncreaseByGrow = ns.growthAnalyzeSecurity(growThreads); // see next line - toggle (out)comment to verify
  62.     const securityIncreaseByGrow = growThreads * 0.004; // WTF this is fixed?! 1 growThread => +0.004 security
  63.     ns.print("threads to re-grow: " + growThreads);
  64.     ns.print("=> RAM[GB]: " + growThreads * 1.75);
  65.     ns.print("=> time[s]: " + ns.formatNumber(growTime / 1000, 1));
  66.     ns.print("=> wasted grow: $" + ns.formatNumber(actualGrowAmount, 3));
  67.     ns.print("=> security increase: " + s.hackDifficulty + " + " + securityIncreaseByGrow);
  68.     s.moneyAvailable = s.moneyMax;
  69.     s.hackDifficulty += securityIncreaseByGrow;
  70.  
  71.     const weakGrowThreads = Math.ceil(securityIncreaseByGrow / 0.05);
  72.     const weakGrowTime = ns.formulas.hacking.weakenTime(s, p);
  73.     const actualWeakGrow = weakGrowThreads * 0.05;
  74.     ns.print("threads for weakGrow: " + weakGrowThreads);
  75.     ns.print("=> RAM[GB]: " + weakGrowThreads * 1.75);
  76.     ns.print("=> time[s]: " + ns.formatNumber(weakGrowTime / 1000, 1));
  77.     ns.print("=> wasted weak: " + ns.formatNumber(actualWeakGrow - securityIncreaseByGrow, 3));
  78.     s.hackDifficulty = s.minDifficulty;
  79.  
  80.     ns.print("total threads: " + (hackThreads + weakHackThreads + growThreads + weakGrowThreads));
  81.     ns.print("=> RAM[GB]: " + (hackThreads * 1.7 + (weakHackThreads + growThreads + weakGrowThreads) * 1.75));
  82.     ns.print("=> time[s]: " + ns.formatNumber((hackTime + weakHackTime + growTime + weakGrowTime) / 1000, 1));
  83. }
  84.  
  85. export function autocomplete(serverName) {
  86.     return [...serverName.servers];
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement