Add option to allow the hacknet server to auto-increase it's limit

This commit is contained in:
Zakary Timson 2022-04-02 12:59:17 -04:00
parent efd3d28bce
commit 130bafc050
2 changed files with 12 additions and 5 deletions

View File

@ -190,6 +190,7 @@ Usage: run hacknet-manager.js [OPTIONS] [LIMIT]
LIMIT Limit the number of nodes the manager will buy, defaults to 8
Options:
-a --auto-limit Automatically increase the node limit when there is nothing to do
-b --balance Prevent spending bellow point
-s --sleep Amount of time to wait between purchases, defaults to 1 (second)
-h --help Display this help message

View File

@ -10,6 +10,7 @@ export async function main(ns) {
ns.disableLog('ALL');
const argParser = new ArgParser('hacknet-manager.js', 'Buy, upgrade & manage Hacknet nodes automatically. Tail for live updates.', null, [
{name: 'limit', desc: 'Limit the number of nodes the manager will buy, defaults to 8', optional: true, default: 8, type: 'num'},
{name: 'autoLimit', desc: 'Automatically increase the node limit when there is nothing to do', flags: ['-a', '--auto-limit'], type: 'bool'},
{name: 'balance', desc: 'Prevent spending bellow point', flags: ['-b', '--balance'], type: 'num'},
{name: 'sleep', desc: 'Amount of time to wait between purchases, defaults to 1 (second)', flags: ['-s', '--sleep'], default: 1, type: 'num'}
]);
@ -29,7 +30,7 @@ export async function main(ns) {
logger.log(`Buying Node ${nodeCount}`);
} else {
// Create an ordered list of nodes by their cheapest upgrade
const nodes = Array(nodeCount).fill(null)
const upgrades = Array(nodeCount).fill(null)
.map((ignore, i) => ({ // Gather information
index: i,
cacheCost: ns.hacknet.getCacheUpgradeCost(i),
@ -71,10 +72,15 @@ export async function main(ns) {
});
// Apply the cheapest upgrade
if(nodes.length && balance - nodes[0].bestUpgrade.cost >= args['balance']) {
const cost = Math.round(nodes[0].bestUpgrade.cost * 100) / 100;
logger.log(`Node ${nodes[0].index} - ${nodes[0].bestUpgrade.name} ${nodes[0][nodes[0].bestUpgrade.name] + 1} - $${cost}`);
nodes[0].bestUpgrade.purchase();
if(upgrades.length) {
if(args['autoLimit'] && nodeCount >= args['limit'] && upgrades[0].bestUpgrade.cost == Infinity) {
args['limit'] += 1;
logger.log(`Increasing node limit to ${args['limit']}`);
} else if(balance - upgrades[0].bestUpgrade.cost >= args['balance']) {
const cost = Math.round(upgrades[0].bestUpgrade.cost * 100) / 100;
logger.log(`Node ${upgrades[0].index} - ${upgrades[0].bestUpgrade.name} ${upgrades[0][upgrades[0].bestUpgrade.name] + 1} - $${cost}`);
upgrades[0].bestUpgrade.purchase();
}
}
}