Add option to allow the hacknet server to auto-increase it's limit
This commit is contained in:
parent
efd3d28bce
commit
130bafc050
@ -190,6 +190,7 @@ Usage: run hacknet-manager.js [OPTIONS] [LIMIT]
|
|||||||
LIMIT Limit the number of nodes the manager will buy, defaults to 8
|
LIMIT Limit the number of nodes the manager will buy, defaults to 8
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
-a --auto-limit Automatically increase the node limit when there is nothing to do
|
||||||
-b --balance Prevent spending bellow point
|
-b --balance Prevent spending bellow point
|
||||||
-s --sleep Amount of time to wait between purchases, defaults to 1 (second)
|
-s --sleep Amount of time to wait between purchases, defaults to 1 (second)
|
||||||
-h --help Display this help message
|
-h --help Display this help message
|
||||||
|
@ -10,6 +10,7 @@ export async function main(ns) {
|
|||||||
ns.disableLog('ALL');
|
ns.disableLog('ALL');
|
||||||
const argParser = new ArgParser('hacknet-manager.js', 'Buy, upgrade & manage Hacknet nodes automatically. Tail for live updates.', null, [
|
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: '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: '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'}
|
{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}`);
|
logger.log(`Buying Node ${nodeCount}`);
|
||||||
} else {
|
} else {
|
||||||
// Create an ordered list of nodes by their cheapest upgrade
|
// 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
|
.map((ignore, i) => ({ // Gather information
|
||||||
index: i,
|
index: i,
|
||||||
cacheCost: ns.hacknet.getCacheUpgradeCost(i),
|
cacheCost: ns.hacknet.getCacheUpgradeCost(i),
|
||||||
@ -71,10 +72,15 @@ export async function main(ns) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Apply the cheapest upgrade
|
// Apply the cheapest upgrade
|
||||||
if(nodes.length && balance - nodes[0].bestUpgrade.cost >= args['balance']) {
|
if(upgrades.length) {
|
||||||
const cost = Math.round(nodes[0].bestUpgrade.cost * 100) / 100;
|
if(args['autoLimit'] && nodeCount >= args['limit'] && upgrades[0].bestUpgrade.cost == Infinity) {
|
||||||
logger.log(`Node ${nodes[0].index} - ${nodes[0].bestUpgrade.name} ${nodes[0][nodes[0].bestUpgrade.name] + 1} - $${cost}`);
|
args['limit'] += 1;
|
||||||
nodes[0].bestUpgrade.purchase();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user