Advertisement
r00key

sustained.js

Aug 15th, 2022 (edited)
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Bitburner script: sustained_hack.js
  2. /** @param {NS} ns */
  3. //NS-Arguments (in Order)
  4. let target;
  5. //Tweakable Constants
  6. const minMoney = 0.80
  7. const maxSecurity = 0.1
  8. //Server Specs
  9. let maxMoney;
  10. let minSecurity;
  11. //global vars
  12. let stop = false;
  13.  
  14. export async function main(ns) {
  15.     target = ns.args[0];
  16.  
  17.     await initServerSpecs(ns);
  18.     await hackServer(ns);
  19. }
  20.  
  21. async function initServerSpecs(ns) {
  22.     maxMoney = ns.getServerMaxMoney(target);
  23.     minSecurity = ns.getServerMinSecurityLevel(target);
  24. }
  25.  
  26. async function hackServer(ns) {
  27.     while (!ns.isRunning("kill.js", "home", "sustained_hack.js") && !ns.isRunning("kill.js", "home")) {
  28.         if (await keepUp(ns)) {
  29.             await ns.hack(target);
  30.         }
  31.     }
  32. }
  33.  
  34. async function keepUp(ns) {
  35.     let unsecure = ns.getServerSecurityLevel(target) <= minSecurity + maxSecurity;
  36.     let rich = ns.getServerMoneyAvailable(target) >= maxMoney * minMoney;
  37.     if (unsecure && rich) {
  38.         return true;
  39.     } else if (unsecure) {
  40.         await ns.grow(target);
  41.     } else {
  42.         await ns.weaken(target);
  43.     }
  44.     return false;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement