74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
/** @param {NS} ns */
|
|
export async function main(ns) {
|
|
ns.tail();
|
|
const sTarget = ns.args[0]; // target server
|
|
|
|
// Lowram settings
|
|
const sBatchScript = "lowram/Lowhgw.js";
|
|
const sPrepScript = "lowram/Lowprep.js";
|
|
const sRunScript = "lowram/Lowrun.js";
|
|
const sLowGrowScript = "lowram/Lowgrow.js";
|
|
const sDistScript = "testdistribute.js";
|
|
|
|
const sGrowScript = "RMgrow.js";
|
|
|
|
const nThisScriptRAM = ns.getScriptRam(sLowGrowScript, "home");
|
|
|
|
|
|
let nMoney = ns.getServerMoneyAvailable(sTarget);
|
|
const nMaxMoney = ns.getServerMaxMoney(sTarget);
|
|
|
|
|
|
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");
|
|
//ns.print("nFreeRam = " + nFreeRam);
|
|
//ns.print("needed ram = " + Math.ceil(nFreeRam / ns.getScriptRam(sGrowScript, "home")));
|
|
//ns.print("needed ram? = " + ns.getScriptRam(sGrowScript, "home"));
|
|
|
|
if (nGrowThreadsNeeded >= 1) {
|
|
|
|
const nDelay = ns.getGrowTime(sTarget);
|
|
|
|
ns.run(sDistScript, 1, sGrowScript, Math.ceil(nGrowThreadsNeeded), sTarget, false, 0);
|
|
nMoney = ns.getServerMoneyAvailable(sTarget);
|
|
ns.print("nMoney = " + nMoney);
|
|
await ns.sleep(nDelay+100);
|
|
}
|
|
/*
|
|
if (nFreeRam >= (ns.getScriptRam(sGrowScript, "home") * nGrowThreadsNeeded)) {
|
|
|
|
|
|
let nGrowPID = ns.run(sGrowScript, Math.ceil(nGrowThreadsNeeded), sTarget);
|
|
await ns.nextPortWrite(nGrowPID);
|
|
await ns.sleep(1000);
|
|
nMoney = ns.getServerMoneyAvailable(sTarget);
|
|
}
|
|
else {
|
|
ns.print("Too smol");
|
|
let nGrowPID = ns.run(sGrowScript, Math.ceil((nFreeRam - nThisScriptRAM) / ns.getScriptRam(sGrowScript, "home")), sTarget);
|
|
await ns.nextPortWrite(nGrowPID);
|
|
await ns.sleep(1000);
|
|
nMoney = ns.getServerMoneyAvailable(sTarget);
|
|
|
|
}
|
|
*/
|
|
|
|
await ns.sleep(1);
|
|
//back to Lowrun
|
|
ns.spawn(sRunScript, { threads: 1, spawnDelay: 0 }, sTarget);
|
|
|
|
|
|
} |