New Setup?

This commit is contained in:
Philipp
2024-10-06 10:23:13 +02:00
parent 4ac218bba3
commit 0824fbb6f1
115 changed files with 9187 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
/** @param {NS} ns */
export async function main(ns) {
//args
const sTarget = ns.args[0]; // target server
// declare objects
const oHome = ns.getServer("home");
//const oTarget = ns.getServer(sTarget);
//declare variables
const sWeakenScript = "RMweaken.js";
const sGrowScript = "RMgrow.js";
const sBatch = "RMcontroller.js";
const nCores = oHome.cpuCores;
let nSecurity = ns.getServerSecurityLevel(sTarget);
const nMinSecurity = ns.getServerMinSecurityLevel(sTarget);
let nMoney = ns.getServerMoneyAvailable(sTarget);
const nMaxMoney = ns.getServerMaxMoney(sTarget);
const nWeakenSTR = ns.weakenAnalyze(1, nCores);
let nWeakenThreads = Math.ceil((nSecurity - nMinSecurity) / nWeakenSTR);
let nFreeRam = ns.getServerMaxRam("home") - ns.getServerUsedRam("home");
ns.tail(ns.pid, oHome.hostname, sTarget);
//ns.resizeTail(815, 395);
//ns.moveTail(1925, 0);
// crack target
//ns.run(sCrack, 1, sTarget);
const nDelay = ns.getWeakenTime(sTarget);
if (nWeakenThreads > 0 && nSecurity > nMinSecurity) {
ns.tprint("current security is: " + nSecurity);
ns.tprint("minimum security is: " + nMinSecurity);
ns.tprint("threads needed for weaken: " + nWeakenThreads);
ns.tprint(nWeakenThreads + " will reduce Security by " + ns.weakenAnalyze(nWeakenThreads, nCores));
let nScriptRAM = ns.getScriptRam(sWeakenScript, "home");
let nRequiredRAM = nScriptRAM * nWeakenThreads;
ns.tprint(nWeakenThreads + " of " + sWeakenScript + " requires " + nRequiredRAM + " GB of RAM");
ns.tprint("weakening will take " + (nDelay / 1000 / 60) + " minutes");
if (nFreeRam > nRequiredRAM) {
ns.run(sWeakenScript, nWeakenThreads, sTarget);
//await ns.sleep(Math.ceil(nDelay));
nSecurity = ns.getServerSecurityLevel(sTarget);
ns.tprint("Breach complete, security level is now at: " + nSecurity);
}
else {
ns.print("not enough RAM to run all threads at once, splitting into smaller chunks...");
while (nSecurity > nMinSecurity) {
//nWeakenThreads /= (1+(nRequiredRAM / nFreeRam));
nMaxThreads = Math.min( );
ns.print(Math.ceil(nRequiredRAM / nFreeRam));
ns.print(nWeakenThreads);
ns.print(nWeakenThreads * nScriptRAM);
ns.run(sWeakenScript, Math.ceil(nWeakenThreads), sTarget);
await ns.sleep(Math.ceil(nDelay));
nSecurity = ns.getServerSecurityLevel(sTarget);
}
}
}
/*
let nGrowMulti = 1;
ns.print("nGrowMulti = " + nGrowMulti);
let nGrowth = ns.growthAnalyze(sTarget, nGrowMulti, nCores);
ns.print("nGrowth = " + nGrowth);
*/
//ns.growthAnalyzeSecurity();
const startValue = nMoney; // First argument: starting value
const target = nMaxMoney; // Second argument: target value
let result = startValue; // Initialize result with the starting value
let n = 1;
// For loop that continues until the result exceeds or matches the target
for (; result < target; n++) {
result += 1; // Add 1 before multiplication
result *= n; // Multiply by the current step value
}
let nGrowThreadsNeeded = n * ns.growthAnalyze(sTarget, n, 1);
ns.print("nGrowThreadsNeeded = " + nGrowThreadsNeeded);
while (nMoney < nMaxMoney) {
let nFreeRam = ns.getServerMaxRam("home") - ns.getServerUsedRam("home");
let nGrowPID = ns.run(sGrowScript, Math.min([Math.ceil(nGrowThreadsNeeded)], [Math.ceil(nFreeRam / ns.getScriptRam(sGrowScript, "home"))]), sTarget);
await ns.nextPortWrite(nGrowPID);
await ns.sleep(1000);
nMoney = ns.getServerMoneyAvailable(sTarget);
}
await ns.sleep(Math.ceil(nDelay));
//run batch
const nBatchPID = ns.run(sBatch, 1, sTarget);
ns.tail(nBatchPID, "home", sBatch, 1, sTarget);
ns.resizeTail(815, 395, nBatchPID);
ns.moveTail(1925, 0, nBatchPID);
}