sync corp
This commit is contained in:
62
Ramses/home/lowram/Lowgrow.js
Normal file
62
Ramses/home/lowram/Lowgrow.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/** @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 (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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//back to Lowrun
|
||||
ns.spawn(sRunScript, { threads: 1, spawnDelay: 0 }, sTarget);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user