Advertisement
Arinek

Hacking/Phase_2/Main.js

Mar 19th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. import { getWeakenThreads, getGrowThreads, getHackThreads } from "Utilities/lib.js";
  2.  
  3. /** @param {NS} ns */
  4. export async function main(ns) {
  5. const logActions = ns.args[1] == "-r";
  6. if (logActions) { ns.tail(); ns.disableLog("ALL"); }
  7.  
  8. //Server Variables
  9. const target = ns.args[0];
  10. const minimumCashReservesForHackConst = 0.8; //50%
  11. const mininumSecurityForHackConst = 1 // Lowest value
  12. const minimumCashReserves = minimumCashReservesForHackConst * ns.getServerMaxMoney(target); // Minimum Money Availabe in Server
  13. const minimumSecurity = mininumSecurityForHackConst * ns.getServerMinSecurityLevel(target); // Minimum Security Level of Server
  14.  
  15. //Paths
  16. const weakenPath = "Hacking/Phase_2/weaken.js";
  17. const growPath = "Hacking/Phase_2/grow.js";
  18. const hackPath = "Hacking/Phase_2/hack.js";
  19.  
  20. //Loop
  21. while (true) {
  22. let cashReserves = ns.getServerMoneyAvailable(target);
  23. let securityLevel = ns.getServerSecurityLevel(target);
  24. //Weaken
  25. if (securityLevel > minimumSecurity) {
  26. ns.exec(weakenPath, ns.getHostname(), getWeakenThreads(ns, target, 0), target);
  27. if (logActions) { ns.print(`Started weaken on ${target}`) }
  28. await ns.sleep(ns.getWeakenTime(target) + 500);
  29.  
  30.  
  31. if (logActions) { ns.print(`Weakened ${target} from ${securityLevel} to ${ns.getServerSecurityLevel(target)}`) }
  32. }
  33. //Grow
  34. else if (cashReserves < minimumCashReserves * 1.2) {
  35. ns.exec(growPath, ns.getHostname(), getGrowThreads(ns, target, minimumCashReserves * 1.2), target);
  36. if (logActions) { ns.print(`Started grow on ${target}`) }
  37. await ns.sleep(ns.getGrowTime(target) + 500);
  38.  
  39. if (logActions) { ns.print(`Grew ${target} from ${cashReserves} to ${ns.getServerMoneyAvailable(target)}`) }
  40. }
  41. else {
  42. ns.exec(hackPath, ns.getHostname(), getHackThreads(ns, target, minimumCashReserves * 0.7), target);
  43. if (logActions) { ns.print(`Started hack on ${target}`) }
  44. await ns.sleep(ns.getHackTime(target) + 500);
  45.  
  46. if (logActions) { ns.print(`Hacked ${target} for ${cashReserves - ns.getServerMoneyAvailable(target)}`) }
  47. }
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement