Skip to content

Instantly share code, notes, and snippets.

@KrunoSaho
Created July 5, 2023 13:23
Show Gist options
  • Save KrunoSaho/a536623f0bfed84eed19718280820f48 to your computer and use it in GitHub Desktop.
Save KrunoSaho/a536623f0bfed84eed19718280820f48 to your computer and use it in GitHub Desktop.
bug report
import { NS } from "@ns";
import { buyAllTorStuff, buyServers, getServers, spendHashes } from "./Util";
import { getMostProfitableCrime } from "./util/Crime";
function upgradeHome(ns: NS) {
ns.singularity.upgradeHomeRam();
ns.singularity.upgradeHomeCores();
}
async function* serialBehaviour(ns: NS) {
yield "Training Dexterity & Agility to 5";
while (ns.getPlayer().skills.agility < 5) {
ns.singularity.gymWorkout("Powerhouse Gym", "agility", true);
await ns.sleep(20);
}
while (ns.getPlayer().skills.dexterity < 5) {
ns.singularity.gymWorkout("Powerhouse Gym", "dexterity", true);
await ns.sleep(20);
}
ns.singularity.stopAction();
yield "Polling...";
let crime = getMostProfitableCrime(ns);
if (ns.exec("util/Share.js", "home", 1) < 1) {
throw new Error("Failed to start Share.js");
}
let progressStoryTimer = 0;
const { targetServers } = getServers(ns);
while (true) {
// crimes
crime = getMostProfitableCrime(ns);
if (!ns.singularity.isBusy()) ns.exec("scripts/RunCrime.js", "home", 1, crime.name as any, false);
// Busy waiting stuff
ns.singularity.checkFactionInvitations().forEach(ns.singularity.joinFaction);
// boost server
const serverToBoost = targetServers[0];
spendHashes(ns, "Increase Maximum Money", serverToBoost.hostname as string);
// misc
upgradeHome(ns);
buyServers(ns);
buyAllTorStuff(ns);
progressStoryTimer++;
if (progressStoryTimer > 60 * 15) {
try {
ns.exec("ProgressStory.js", "home", 1);
} catch (e: any) {}
progressStoryTimer = 0;
}
await ns.sleep(1000);
}
return false;
}
async function runScript(ns: NS) {
const tasks = serialBehaviour(ns);
let task = (await tasks.next()).value;
while (task) {
ns.print(task);
task = (await tasks.next()).value;
await ns.sleep(200);
}
}
export async function main(ns: NS) {
ns.disableLog("ALL");
ns.clearLog();
ns.tail();
ns.resizeTail(500, 200);
ns.moveTail(1800, 10);
const batcher = ns.exec("HGWScheduler.js", "home", 1);
if (ns.exec("Hacknet.js", "home", 1) === 0) {
throw new Error("Failed to start HGWScheduler.js");
}
ns.exec("Gang.js", "home", 1);
ns.atExit(() => {
ns.closeTail(batcher);
ns.killall();
});
// new reset
await runScript(ns);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment