This commit is contained in:
2022-09-12 14:24:18 +02:00
parent 2963efd97b
commit 34254586b5
12 changed files with 132 additions and 65 deletions
+92 -26
View File
@@ -3,42 +3,101 @@
export async function main(ns) {
ns.disableLog('ALL');
let nodeCostThreshold = ns.args.length > 0 ? ns.args[0] : 0.1;
let upgradeCostThreshold = ns.args.length > 1 ? ns.args[1] : 0.05;
let upgradeCount = ns.args.length > 2 ? ns.args[2] : 1;
let levelCap = 150;
let ramCap = 64;
let coreCap = 4;
let nodeCap = 18;
const nodeCostThreshold = ns.args.length > 0 ? ns.args[0] : 0.8;
const upgradeCostThreshold = ns.args.length > 1 ? ns.args[1] : 0.1;
const upgradeCount = ns.args.length > 2 ? ns.args[2] : 1;
const nodeCap = 18;
const levelCap = 200;
const ramCap = 64;
const coreCap = 16;
// const levelCap = 150;
// const ramCap = 64;
// const coreCap = 4;
ns.tprint(`Bot started {nodeCostThreshold: ${nodeCostThreshold}, upgradeCostThreshold: ${upgradeCostThreshold}, upgradeCount: ${upgradeCount}}`);
// const terminalInput = document.getElementById("terminal-input");
// const handler = Object.keys(terminalInput)[1];
const darkWebPrograms = [
{ name: 'BruteSSH.exe', cost: 0 },
{ name: 'FTPCrack.exe', cost: 1500000 },
{ name: 'relaySMTP.exe', cost: 5000000 },
{ name: 'HTTPWorm.exe', cost: 30000000 },
{ name: 'SQLInject.exe', cost: 250000000 },
{ name: 'ServerProfiler.exe', cost: 500000 },
{ name: 'DeepscanV1.exe', cost: 500000 },
{ name: 'DeepscanV2.exe', cost: 25000000 },
{ name: 'AutoLink.exe', cost: 1000000 },
{ name: 'Formulas.exe', cost: 5000000000 }
];
const HACKNET_UPGRADE_PATTERN = {
currentLevel: 0,
upgradeLevels: [
{
nodeCount: 6,
nodeLevel: 30,
ram: 4,
cores: 1
},
{
nodeCount: 9,
nodeLevel: 60,
ram: 8,
cores: 2
},
{
nodeCount: 12,
nodeLevel: 60,
ram: 8,
cores: 2
},
{
nodeCount: 15,
nodeLevel: 150,
ram: 16,
cores: 6
},
{
nodeCount: 18,
nodeLevel: 200,
ram: 64,
cores: 16
}
],
complete: false
};
while (true) {
let currentMoney = ns.getServerMoneyAvailable("home");
let nodePurchaseCost = ns.hacknet.getPurchaseNodeCost();
let nodeCount = ns.hacknet.numNodes();
if (nodeCount < nodeCap && nodePurchaseCost / Math.abs(currentMoney) < nodeCostThreshold) {
ns.hacknet.purchaseNode();
currentMoney = ns.getServerMoneyAvailable("home");
++nodeCount;
}
if (!HACKNET_UPGRADE_PATTERN.complete) {
let nodePurchaseCost = ns.hacknet.getPurchaseNodeCost();
let nodeCount = ns.hacknet.numNodes();
for (let index = 0; index < nodeCount; ++index) {
let nodeStats = ns.hacknet.getNodeStats(index);
if (nodeStats.level < levelCap && ns.hacknet.getLevelUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < upgradeCostThreshold) {
ns.hacknet.upgradeLevel(index, upgradeCount);
if (nodeCount < nodeCap && nodePurchaseCost / Math.abs(currentMoney) < nodeCostThreshold) {
ns.hacknet.purchaseNode();
currentMoney = ns.getServerMoneyAvailable("home");
++nodeCount;
}
if (nodeStats.ram < ramCap && ns.hacknet.getRamUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < upgradeCostThreshold) {
ns.hacknet.upgradeRam(index, upgradeCount);
currentMoney = ns.getServerMoneyAvailable("home");
}
for (let index = 0; index < nodeCount; ++index) {
let nodeStats = ns.hacknet.getNodeStats(index);
if (nodeStats.cores < coreCap && ns.hacknet.getCoreUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < upgradeCostThreshold) {
ns.hacknet.upgradeCore(index, upgradeCount);
currentMoney = ns.getServerMoneyAvailable("home");
if (nodeStats.level < levelCap && ns.hacknet.getLevelUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < upgradeCostThreshold) {
ns.hacknet.upgradeLevel(index, upgradeCount);
currentMoney = ns.getServerMoneyAvailable("home");
}
if (nodeStats.ram < ramCap && ns.hacknet.getRamUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < upgradeCostThreshold) {
ns.hacknet.upgradeRam(index, upgradeCount);
currentMoney = ns.getServerMoneyAvailable("home");
}
if (nodeStats.cores < coreCap && ns.hacknet.getCoreUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < upgradeCostThreshold) {
ns.hacknet.upgradeCore(index, upgradeCount);
currentMoney = ns.getServerMoneyAvailable("home");
}
}
}
@@ -49,11 +108,18 @@ export async function main(ns) {
if (newServer != '') {
ns.tprint(`Bought a server`);
ns.scp('grow-helper.js', newServer);
ns.scp('constants.js', newServer);
let execExitCode = ns.exec('grow-helper.js', newServer, 5, 20);
ns.tprint(`Exec 'grow-helper.js' exit code: ${execExitCode}`);
}
}
// terminalInput.value = backdoorCommand;
// terminalInput[handler].onChange({ target: terminalInput });
// terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
let logFiles = ['hack-log.js', 'nuke-log.js'];
for (let index = 0; index < logFiles.length; index++) {