Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @param {NS} ns */
- export async function main(ns) {
- let target = "n00dles"
- //ns.tprint("Money Available: ", ns.getServerMoneyAvailable(target))
- const IDIF = 25 // Time difference between weaken/hack/grow calls in ms
- let numHackThreads = Math.floor(ns.hackAnalyzeThreads(target, 0.45 * ns.getServerMaxMoney(target)))
- let numGrowThreads = Math.ceil(ns.growthAnalyze(target, 2.1, 1))
- let actions = [
- { name: "w1", wait: ns.getWeakenTime() },
- { name: "w2", wait: ns.getWeakenTime() },
- { name: "h", wait: ns.getHackTime(target) },
- { name: "g", wait: ns.getGrowTime(target) }
- ]
- /**
- * Completion order should be:
- * w1, h, w2, g
- */
- actions.sort((a, b) => b.wait - a.wait); // We sort actions in descending order to find the call which will take the longest
- let maxWait = actions[0].wait
- let timeElapsed = 0
- for (let i = 0; i < 4; i++) {
- let action = actions.shift() // We take the longest action
- await ns.sleep(maxWait - action.wait - timeElapsed) // Appropriate timing to ensure consistent spacing
- timeElapsed += maxWait - action.wait - timeElapsed
- if (action.name === "w1") {
- let threads = Math.ceil(ns.growthAnalyzeSecurity(numGrowThreads) / 0.05) + 1 // Slight Buffer
- ns.run("weaken.js", threads, target)
- }
- else if (action.name === "w2") {
- await ns.sleep(IDIF * 2)
- timeElapsed += IDIF * 2
- let threads = Math.ceil(ns.hackAnalyzeSecurity(numHackThreads) / 0.05) + 1 // Slight Buffer
- ns.run("weaken.js", threads, target)
- }
- else if (action.name === "h") {
- await ns.sleep(IDIF)
- timeElapsed += IDIF
- // If money is too low we do not attempt to hack
- if (ns.getServerMaxMoney(target) * 0.5 > ns.getServerMoneyAvailable(target) || numHackThreads < 1) {
- continue;
- }
- ns.run("hack.js", numHackThreads, target)
- }
- else if (action.name === "g") {
- await ns.sleep(IDIF * 3)
- timeElapsed += IDIF * 3
- ns.run("grow.js", numGrowThreads, target)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement