more work on the lowram scripts

This commit is contained in:
2024-10-10 17:19:40 +02:00
parent 81b1675356
commit a63a9ca66f
15 changed files with 115 additions and 51 deletions

View File

@@ -83,14 +83,14 @@ export function findBestTarget(ns, maxSec, maxPorts, currentHackLevel, manualTar
if (!ns.fileExists("serverList.txt", "home")) scanServerList();
let serverList = JSON.parse(ns.read("serverList.txt"));
let bestEntry = "";
if (manualTargetOverride.length > 0) {
if (manualTargetOverride && manualTargetOverride.length > 0) {
bestEntry = manualTargetOverride;
} else {
bestEntry = null;
let nMaxMoneyPerChance = 0;
let nBestMoneyPerChance = 0;
for (const [name, entry] of Object.entries(serverList)) {
if (entry.minSec <= maxSec && entry.minPorts <= maxPorts && entry.minHackLvl < currentHackLevel) {
if (entry.minSec <= maxSec && entry.minPorts <= maxPorts && entry.minHackLvl <= currentHackLevel) {
nMaxMoneyPerChance = (entry.maxMoney * ns.hackAnalyzeChance(name)) / entry.minSec;
if (nMaxMoneyPerChance > nBestMoneyPerChance) {
nBestMoneyPerChance = nMaxMoneyPerChance;
@@ -241,3 +241,15 @@ export function getGrowThreads(ns, sTarget, nHackThreads, nCores) {
let nGrowthThreads = ns.growthAnalyze(sTarget, 1 + nHackAmountPercent, nCores);
return nGrowthThreads;
}
/** @param {NS} ns */
export async function ExecuteAndWait(ns, sScript, ...args) {
if (!ns.isRunning(sScript, ...args)) { ns.exec(sScript, ...args); }
while (ns.isRunning(sScript, ...args)) { await ns.sleep(100); }
}
/** @param {NS} ns */
export async function RunAndWait(ns, sScript, ...args) {
if (!ns.isRunning(sScript, ...args)) { ns.run(sScript, ...args); }
while (ns.isRunning(sScript, ...args)) { await ns.sleep(100); }
}