initial commit

This commit is contained in:
Vomitblood 2026-04-29 08:56:38 +08:00
parent 9c24345bdd
commit cf68ee6ba6
6 changed files with 10468 additions and 5 deletions

10399
NetscriptDefinitions.d.ts vendored Normal file

File diff suppressed because it is too large Load diff

2
mise.toml Normal file
View file

@ -0,0 +1,2 @@
[tools]
node = "latest"

27
src/super.ts Normal file
View file

@ -0,0 +1,27 @@
import { NS } from '@ns';
export const main = async (ns: NS) => {
const target = ns.args[0].toString();
ns.tprint('Target selected: ' + target);
const maxMoneyThresh = ns.getServerMaxMoney(target);
const minSecurityThresh = ns.getServerMinSecurityLevel(target);
// get root access
ns.nuke(target);
// main loop that continously hacks/grows/weakens the target server
while (true) {
if (ns.getServerSecurityLevel(target) > minSecurityThresh) {
// If the server's security level is above our threshold, weaken it
await ns.weaken(target);
} else if (ns.getServerMoneyAvailable(target) < maxMoneyThresh) {
// If the server's money is less than our threshold, grow it
await ns.grow(target);
} else {
// Otherwise, hack it
await ns.hack(target);
}
}
};

View file

@ -1,5 +0,0 @@
import { NS } from '@ns';
export async function main(ns: NS) {
ns.tprint('Hello World!');
}

7
src/test.ts Normal file
View file

@ -0,0 +1,7 @@
import { NS } from '@ns';
import { scan } from './utils/scan';
export const main = (ns: NS) => {
const hosts = scan(ns, undefined, 50);
ns.tprint(hosts);
};

33
src/utils/scan.ts Normal file
View file

@ -0,0 +1,33 @@
import { NS } from '@ns';
export const scan = (
ns: NS,
rootAccess?: boolean,
requiredHackingSkill?: number,
portsForNuke?: number,
ram?: number,
): string[] => {
// initialize a new set to store a list of all hosts
const allHosts = new Set<string>(['home']);
// for each host in the set, scan it and add all of its neighbors to the set
allHosts.forEach((h) => {
ns.scan(h).forEach((n) => allHosts.add(n));
});
// remove home from the set
allHosts.delete('home');
// now we start the filtering into another new list
const filteredHosts = Array.from(allHosts).filter((host: string) => {
if (rootAccess && ns.hasRootAccess(host) !== rootAccess) return false;
if (requiredHackingSkill && ns.getServerRequiredHackingLevel(host) > requiredHackingSkill) return false;
if (portsForNuke && ns.getServerNumPortsRequired(host) > portsForNuke) return false;
if (ram && ns.getServerMaxRam(host) < ram) return false;
return true;
});
// convert the set to an array and return it
return Array.from(filteredHosts);
};