Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /** @param {NS} ns */
  2. export async function main(ns) {
  3. let target = "n00dles"
  4. //ns.tprint("Money Available: ", ns.getServerMoneyAvailable(target))
  5.  
  6. const IDIF = 25 // Time difference between weaken/hack/grow calls in ms
  7. let numHackThreads = Math.floor(ns.hackAnalyzeThreads(target, 0.45 * ns.getServerMaxMoney(target)))
  8.  
  9. let numGrowThreads = Math.ceil(ns.growthAnalyze(target, 2.1, 1))
  10.  
  11. let actions = [
  12. { name: "w1", wait: ns.getWeakenTime() },
  13. { name: "w2", wait: ns.getWeakenTime() },
  14. { name: "h", wait: ns.getHackTime(target) },
  15. { name: "g", wait: ns.getGrowTime(target) }
  16. ]
  17.  
  18. /**
  19. * Completion order should be:
  20. * w1, h, w2, g
  21. */
  22.  
  23. actions.sort((a, b) => b.wait - a.wait); // We sort actions in descending order to find the call which will take the longest
  24.  
  25. let maxWait = actions[0].wait
  26. let timeElapsed = 0
  27. for (let i = 0; i < 4; i++) {
  28. let action = actions.shift() // We take the longest action
  29. await ns.sleep(maxWait - action.wait - timeElapsed) // Appropriate timing to ensure consistent spacing
  30. timeElapsed += maxWait - action.wait - timeElapsed
  31.  
  32. if (action.name === "w1") {
  33. let threads = Math.ceil(ns.growthAnalyzeSecurity(numGrowThreads) / 0.05) + 1 // Slight Buffer
  34. ns.run("weaken.js", threads, target)
  35. }
  36. else if (action.name === "w2") {
  37. await ns.sleep(IDIF * 2)
  38. timeElapsed += IDIF * 2
  39. let threads = Math.ceil(ns.hackAnalyzeSecurity(numHackThreads) / 0.05) + 1 // Slight Buffer
  40. ns.run("weaken.js", threads, target)
  41. }
  42. else if (action.name === "h") {
  43. await ns.sleep(IDIF)
  44. timeElapsed += IDIF
  45. // If money is too low we do not attempt to hack
  46. if (ns.getServerMaxMoney(target) * 0.5 > ns.getServerMoneyAvailable(target) || numHackThreads < 1) {
  47. continue;
  48. }
  49. ns.run("hack.js", numHackThreads, target)
  50. }
  51. else if (action.name === "g") {
  52. await ns.sleep(IDIF * 3)
  53. timeElapsed += IDIF * 3
  54. ns.run("grow.js", numGrowThreads, target)
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement