From ac01ad7b9e251b65b64fa2a143e4c8d5b89df39a Mon Sep 17 00:00:00 2001 From: Zak Timson Date: Fri, 4 Feb 2022 23:56:22 +0000 Subject: [PATCH] Add new file --- scripts/miner.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/miner.js diff --git a/scripts/miner.js b/scripts/miner.js new file mode 100644 index 0000000..dc91dfe --- /dev/null +++ b/scripts/miner.js @@ -0,0 +1,40 @@ +export async function main(ns) { + ns.disableLog('ALL'); + const TARGET = ns.args[0]; + const SECURITY = ns.getServerMinSecurityLevel(TARGET) + 2; + let BALANCE, once = true; + + while(true) { + let s = await ns.getServerSecurityLevel(TARGET); + let b = await ns.getServerMoneyAvailable(TARGET); + if(BALANCE == null) BALANCE = b; + + if(once) { + ns.print('==================================================='); + ns.print(`Bankrupting: ${TARGET}`); + ns.print('==================================================='); + ns.print(`Security: ${Math.round(s * 100) / 100}/${SECURITY}`); + ns.print(`Balance: $${Math.round(BALANCE * 100) / 100}`); + ns.print('==================================================='); + once = false; + } + + if(s > SECURITY) { + ns.print('Attacking Security...'); + const w = await ns.weaken(TARGET); + ns.print(`Security: -${w} (${Math.round((s - w) * 100) / 100}/${SECURITY})`); + } else if(b < BALANCE) { + ns.print('Spoofing Balance...'); + const g = await ns.grow(TARGET); + ns.print(`Balance: +${Math.round(g * 10) / 10}% ($${Math.round(b * g * 100) / 100})`); + } else { + ns.print('Hacking Account...'); + const h = await ns.hack(TARGET); + ns.print(`Balance: -$${h} ($${Math.round((b - h) * 100) / 100})`); + } + } +} + +export function autocomplete(data) { + return [...data.servers]; +}