New Folder Structure test
This commit is contained in:
30
Mizzajl/home/gang/argFunctions.js
Normal file
30
Mizzajl/home/gang/argFunctions.js
Normal file
@@ -0,0 +1,30 @@
|
||||
export function GetFlag(ns, flag)
|
||||
{
|
||||
return ns.args.includes(flag);
|
||||
}
|
||||
|
||||
export function GetArg(ns, arg, def = null)
|
||||
{
|
||||
for(var i = 0; i < ns.args.length - 1; i++)
|
||||
{
|
||||
if(ns.args[i] == arg)
|
||||
{
|
||||
return ns.args[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
export function GetIndex(ns, arg)
|
||||
{
|
||||
for(var i = 0; i < ns.args.length; i++)
|
||||
{
|
||||
if(ns.args[i] == arg)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
114
Mizzajl/home/gang/auto-gang.js
Normal file
114
Mizzajl/home/gang/auto-gang.js
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
|
||||
A 'cycle' lasts 5 minutes and the current task for any given member on a cycle
|
||||
is set by taking the cycle and their member index and modding by the number
|
||||
of tasks in your list, so it should spread out tasks evenly among your members,
|
||||
and each one should progress through the list of tasks, although when you start
|
||||
only the first member will start on task 0.
|
||||
|
||||
Set 'upgradeEquipmentNames' to a list of the gear you want to purchase,
|
||||
currently it gets a list of all equipment by type and includes all types.
|
||||
|
||||
|
||||
|
||||
Jobs are:
|
||||
[
|
||||
"Unassigned",
|
||||
"Mug People",
|
||||
"Deal Drugs",
|
||||
"Strongarm Civilians",
|
||||
"Run a Con",
|
||||
"Armed Robbery",
|
||||
"Traffick Illegal Arms",
|
||||
"Threaten & Blackmail",
|
||||
"Human Trafficking",
|
||||
"Terrorism",
|
||||
"Vigilante Justice",
|
||||
"Train Combat",
|
||||
"Train Hacking",
|
||||
"Train Charisma",
|
||||
"Territory Warfare"
|
||||
]
|
||||
|
||||
*/
|
||||
|
||||
const DURATION = 5 * 60 * 1000 // 5 minutes
|
||||
|
||||
const newMemberNames = ('General Kenobi,General Zod,Admiral Akbar,Admiral Thrawn' +
|
||||
',Colonel Duke,Colonel Nick Fury,Major Tom,Major Paine' +
|
||||
',Corporal Klinger,Corporal Barnes,Sergeant Slaughter,Sergeant Smith').split(',')
|
||||
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
// // show list of job names
|
||||
// ns.tprint(JSON.stringify(ns.gang.getTaskNames(), null, 2))
|
||||
// return
|
||||
|
||||
ns.disableLog('ALL')
|
||||
|
||||
// what gear will we buy after ascension?
|
||||
let equipmentNames = ns.gang.getEquipmentNames()
|
||||
let upgradeEquipmentNames = equipmentNames.filter(x => ['Weapon', 'Armor', 'Vehicle', 'Rootkit', 'Augmentation'].find(y => ns.gang.getEquipmentType(x) === y))
|
||||
|
||||
let cycle = 0
|
||||
|
||||
// with 6 jobs and 12 members, we should have two members on each
|
||||
let cycleTasks = ['Train Combat', 'Train Combat',
|
||||
'Vigilante Justice', 'Terrorism',
|
||||
'Human Trafficking', 'Territory Warfare']
|
||||
|
||||
while (true) {
|
||||
let memberNames = ns.gang.getMemberNames()
|
||||
ns.print(`Cycle ${cycle} activating for ${memberNames.length} gang members`)
|
||||
memberNames.forEach((name, index) => {
|
||||
let taskIndex = (cycle + index) % cycleTasks.length
|
||||
if (taskIndex === 0) {
|
||||
let result = ns.gang.ascendMember(name)
|
||||
if (result) ns.print(`INFO: Ascended gang member ${name}:\n Hack:${sf(result.hack)}, Str:${sf(result.str)}, Def:${sf(result.def)}, Dex:${sf(result.dex)}, Agi:${sf(result.agi)}`)
|
||||
// if (result) ns.print(`INFO: Ascended gang member ${name}:\n ${JSON.stringify(result)}`)
|
||||
purchaseEquipment(name)
|
||||
}
|
||||
ns.gang.setMemberTask(name, cycleTasks[taskIndex])
|
||||
})
|
||||
|
||||
// hire new members if possible and set them to first job for this cycle,
|
||||
// should be training probably
|
||||
if (ns.gang.canRecruitMember()) {
|
||||
newMemberNames.forEach(name => {
|
||||
if (ns.gang.recruitMember(name)) {
|
||||
ns.print(`INFO: Recruited new gang member '${name}`)
|
||||
ns.gang.setMemberTask(name, cycleTasks[0])
|
||||
purchaseEquipment()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let cycleEnd = new Date(new Date().valueOf() + DURATION).toLocaleTimeString()
|
||||
ns.print(`Next cycle at ${cycleEnd}`)
|
||||
await ns.sleep(DURATION) // wait 5 minutes
|
||||
cycle++
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchase equipment for a gang member if we have the money
|
||||
*
|
||||
* @param {string} memberName Name of the gang member to purchase equipment for
|
||||
*/
|
||||
function purchaseEquipment(memberName) {
|
||||
let { money } = ns.getPlayer()
|
||||
upgradeEquipmentNames.forEach(equipName => {
|
||||
let cost = ns.gang.getEquipmentCost(equipName)
|
||||
if (money >= cost && ns.gang.purchaseEquipment(memberName, equipName)) money -= cost
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple format for stats
|
||||
*
|
||||
* @param {number} value
|
||||
*/
|
||||
function sf(value) {
|
||||
if (typeof(value) !== 'number') return '???'
|
||||
return Math.trunc(value * 1000) / 1000
|
||||
}
|
||||
}
|
||||
144
Mizzajl/home/gang/auto-gang2.js
Normal file
144
Mizzajl/home/gang/auto-gang2.js
Normal file
@@ -0,0 +1,144 @@
|
||||
const TASK_TRAIN = "Train Combat";
|
||||
const TASK_VIGI = "Vigilante Justice";
|
||||
const TASK_NOOB = String.fromCharCode(77) + "ug People";
|
||||
const TASK_RESPECT = String.fromCharCode(84) + "errorism";
|
||||
const TASK_MONEY = "Human " + String.fromCharCode(84) + "rafficking";
|
||||
const TASK_WARFARE = "Territory Warfare";
|
||||
const TASK_NULL = "Unassigned";
|
||||
const TASK_MANUAL = "Manual/NotReallyTaskName";
|
||||
|
||||
const ASCEND_ON_MPL = 10;
|
||||
const EQUIP_AFFORD_COEFF = 100;
|
||||
|
||||
const STATS_TRESHOLD = 0.7;
|
||||
const STATS_MIN = 4000;
|
||||
const STATS_HARD_MIN = 200;
|
||||
const TRAIN_CHANCE = 0.2;
|
||||
const RESPECT_MIN = 2e+7;
|
||||
|
||||
const WANTED_PENALTY_TRESHOLD = 0.99;
|
||||
const WARFARE_TRESHOLD = 2;
|
||||
|
||||
const MEMBERS_MIN = 6;
|
||||
const MEMBERS_MAX = 12;
|
||||
|
||||
const SLEEP_TIME = 10000;
|
||||
|
||||
/** @param {NS} ns **/
|
||||
export async function main(ns) {
|
||||
ns.tail();
|
||||
const gang = ns.gang;
|
||||
// Get weighted stats sum (at this moment, sum of combat stats in eq proportions)
|
||||
function getStatsSum(member) {
|
||||
const info = gang.getMemberInformation(member);
|
||||
return info.str + info.def + info.dex + info.agi;
|
||||
}
|
||||
// Find the best gang power except our gang
|
||||
function maxEnemyPower(myGang) {
|
||||
const others = ns.gang.getOtherGangInformation();
|
||||
let maxPower = 0;
|
||||
for (let name in others) {
|
||||
if (name === myGang.faction) continue;
|
||||
maxPower = Math.max(maxPower, others[name].power);
|
||||
}
|
||||
return maxPower;
|
||||
}
|
||||
// Set a task or not to set (if manually overridden)
|
||||
const autoTasks = {}
|
||||
function setAutoTask(member, task) {
|
||||
const info = gang.getMemberInformation(member);
|
||||
const lastTask = info.task;
|
||||
// Manual task: stored task mismatches real task and not unassigned
|
||||
if (lastTask !== TASK_NULL && autoTasks.hasOwnProperty(member) && autoTasks[member] !== lastTask) {
|
||||
autoTasks[member] = TASK_MANUAL;
|
||||
return;
|
||||
}
|
||||
// Automatic task: set it if differs from real one
|
||||
autoTasks[member] = task;
|
||||
if (lastTask !== task) {
|
||||
gang.setMemberTask(member, task);
|
||||
}
|
||||
}
|
||||
// The script accepts argument for default task override (optional)
|
||||
let defaultTask = null;
|
||||
if (ns.args[0] && gang.getTaskNames().includes(ns.args[0])) {
|
||||
defaultTask = ns.args[0];
|
||||
}
|
||||
// Main loop
|
||||
for (; ;) {
|
||||
// Recruit any member possible
|
||||
while (gang.canRecruitMember()) {
|
||||
gang.recruitMember('member' + Math.random().toString().substr(2, 3));
|
||||
}
|
||||
let bestStats = STATS_MIN / STATS_TRESHOLD; // minimum
|
||||
const members = gang.getMemberNames();
|
||||
const info = gang.getGangInformation();
|
||||
// Ascend if good enough
|
||||
for (let member of members) {
|
||||
const r = gang.getAscensionResult(member);
|
||||
if (!r) continue;
|
||||
const mpl = r.agi * r.def * r.dex * r.str;
|
||||
if (mpl > ASCEND_ON_MPL) {
|
||||
gang.ascendMember(member);
|
||||
ns.tprint(`Member ${member} ascended!`);
|
||||
}
|
||||
}
|
||||
// Purchase equipment
|
||||
const allEquip = gang.getEquipmentNames();
|
||||
let money = ns.getServerMoneyAvailable('home');
|
||||
for (let equip of allEquip) {
|
||||
const cost = gang.getEquipmentCost(equip);
|
||||
const amount = money / cost;
|
||||
if (amount < EQUIP_AFFORD_COEFF) continue;
|
||||
for (let member of members) {
|
||||
const info = gang.getMemberInformation(member);
|
||||
if (info.upgrades.includes(equip) || info.augmentations.includes(equip)) continue;
|
||||
if (gang.purchaseEquipment(member, equip)) {
|
||||
money -= cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Find best stats
|
||||
for (let member of members) {
|
||||
let sum = getStatsSum(member);
|
||||
if (sum > bestStats) bestStats = sum;
|
||||
}
|
||||
// Check if we are powerful enough
|
||||
let powerfulEnough = info.power >= maxEnemyPower(info) * WARFARE_TRESHOLD;
|
||||
gang.setTerritoryWarfare(powerfulEnough);
|
||||
// Choose the default task for members
|
||||
let task = defaultTask;
|
||||
if (!defaultTask) {
|
||||
// If gang isn't full - gain respect
|
||||
if (members.length < MEMBERS_MAX) {
|
||||
task = (members.length < MEMBERS_MIN) ? TASK_NOOB : TASK_RESPECT;
|
||||
} else {
|
||||
// if respect too low - gain it first, power second, money last
|
||||
if (info.respect < RESPECT_MIN) {
|
||||
task = TASK_RESPECT;
|
||||
} else if (!powerfulEnough) {
|
||||
task = TASK_WARFARE;
|
||||
} else {
|
||||
task = TASK_MONEY;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Assign tasks
|
||||
for (let member of members) {
|
||||
let sum = getStatsSum(member);
|
||||
// Train members, not acceptable in 'noob mode'
|
||||
if (sum < STATS_HARD_MIN || (members.length >= MEMBERS_MIN && sum < bestStats * STATS_TRESHOLD)) {
|
||||
setAutoTask(member, TASK_TRAIN);
|
||||
continue;
|
||||
}
|
||||
// Vigi if wanted penalty too large
|
||||
if (info.wantedLevel > 2 && info.wantedPenalty < WANTED_PENALTY_TRESHOLD) {
|
||||
setAutoTask(member, TASK_VIGI);
|
||||
continue;
|
||||
}
|
||||
// Do the default task (autoselected or called with args[0])
|
||||
setAutoTask(member, Math.random() < TRAIN_CHANCE ? TASK_TRAIN : task);
|
||||
}
|
||||
await ns.sleep(SLEEP_TIME);
|
||||
}
|
||||
}
|
||||
219
Mizzajl/home/gang/gangManager.js
Normal file
219
Mizzajl/home/gang/gangManager.js
Normal file
@@ -0,0 +1,219 @@
|
||||
import { GetFlag, GetArg } from "gang/argFunctions.js";
|
||||
|
||||
function getRandomInt(max) {
|
||||
return Math.floor(Math.random() * Math.floor(max));
|
||||
}
|
||||
|
||||
// 30 possible gang members
|
||||
// create list of names
|
||||
let memberNamePool = [
|
||||
"Thor", // 1
|
||||
"Iron Man", // 2
|
||||
"Starlord", // 3
|
||||
"Thanos", // 4
|
||||
"Groot", // 5
|
||||
"Ant-Man", // 6
|
||||
"Wasp", // 7
|
||||
"Spiderman", // 8
|
||||
"Loki", // 9
|
||||
"Gamora", // 10
|
||||
"Rocket Raccoon", // 11
|
||||
"T'Challa", // 12
|
||||
"Vision", // 13
|
||||
"Scarlet Witch", // 14
|
||||
"Winter Soldier", // 15
|
||||
"Black Widow", // 16
|
||||
"Hulk", // 17
|
||||
"Bruce Banner", // 18
|
||||
"Hawkeye", // 19
|
||||
"Captain Marvel", // 20
|
||||
"War Machine", // 21
|
||||
"Nick Fury", // 22
|
||||
"Nebula", // 23
|
||||
"Drax", // 24
|
||||
"Deadpool", // 25
|
||||
"Cable", // 26
|
||||
"Quicksilver", // 27
|
||||
"Wolverine", // 28
|
||||
"Adam Warlock", // 29
|
||||
"Yondu", // 30
|
||||
];
|
||||
|
||||
export async function main(ns) {
|
||||
var buyAll = GetFlag(ns, "--buyAll");
|
||||
|
||||
var buyEquip = buyAll || GetFlag(ns, "--buyEquip");
|
||||
|
||||
var buyWeapon = buyAll || buyEquip || GetFlag(ns, "--buyWeapon");
|
||||
var buyArmor = buyAll || buyEquip || GetFlag(ns, "--buyArmor");
|
||||
var buyVehicle = buyAll || buyEquip || GetFlag(ns, "--buyVehicle");
|
||||
var buyRoot = buyAll || buyEquip || GetFlag(ns, "--buyRoot");
|
||||
|
||||
var buyAug = buyAll || GetFlag(ns, "--buyAug");
|
||||
|
||||
var myGang = ns.gang.getGangInformation();
|
||||
var possibleTasks = ns.gang.getTaskNames();
|
||||
var unassignedTask = possibleTasks.shift();
|
||||
|
||||
var territoryTask = possibleTasks.pop();
|
||||
var trainingTasks = possibleTasks.splice(possibleTasks.length - 3, 3);
|
||||
var wantedLevelLowerTask = possibleTasks.pop();
|
||||
|
||||
var desirableAugs = [];
|
||||
|
||||
if (myGang.isHacking) {
|
||||
wantedLevelLowerTask = possibleTasks.pop();
|
||||
|
||||
// replace combat with hacking
|
||||
trainingTasks.splice(0, 1, trainingTasks[1]);
|
||||
|
||||
desirableAugs.push("BitWire");
|
||||
desirableAugs.push("Neuralstimulator");
|
||||
desirableAugs.push("DataJack");
|
||||
}
|
||||
else {
|
||||
// replace hacking with combat
|
||||
trainingTasks.splice(1, 1, trainingTasks[0]);
|
||||
|
||||
desirableAugs.push("Bionic Arms");
|
||||
desirableAugs.push("Bionic Legs");
|
||||
desirableAugs.push("Bionic Spine");
|
||||
desirableAugs.push("BrachiBlades");
|
||||
desirableAugs.push("Nanofiber Weave");
|
||||
desirableAugs.push("Synthetic Heart");
|
||||
desirableAugs.push("Synfibril Muscle");
|
||||
desirableAugs.push("Graphene Bone Lacings");
|
||||
}
|
||||
|
||||
var ascensionCycles = GetArg(ns, "--asc", 600000);
|
||||
var nextAscensionAttempt = 0;
|
||||
var cycleMs = 1100;
|
||||
var ascensionMultLimit = GetArg(ns, "--alim", 2);
|
||||
|
||||
while (true) {
|
||||
myGang = ns.gang.getGangInformation();
|
||||
var otherGangs = ns.gang.getOtherGangInformation();
|
||||
var buyableEquipment = ns.gang.getEquipmentNames().filter(e => {
|
||||
return ns.gang.getEquipmentType(e) != "Augmentation" || desirableAugs.includes(e);
|
||||
});
|
||||
|
||||
var members = ns.gang.getMemberNames();
|
||||
|
||||
while (ns.gang.canRecruitMember()) {
|
||||
var possibleNames = memberNamePool.filter(name => !members.includes(name));
|
||||
var toRecruit = possibleNames[getRandomInt(possibleNames.length)];
|
||||
|
||||
ns.gang.recruitMember(toRecruit);
|
||||
await ns.sleep(1);
|
||||
}
|
||||
|
||||
members = ns.gang.getMemberNames();
|
||||
var memInfo = null;
|
||||
|
||||
members.sort((a, b) => { return Math.random() * 2 - 1; });
|
||||
members.forEach((m) => {
|
||||
var didBuy = false;
|
||||
var hadAll = true;
|
||||
|
||||
memInfo = ns.gang.getMemberInformation(m);
|
||||
|
||||
ns.gang.setMemberTask(m, unassignedTask);
|
||||
|
||||
buyableEquipment.forEach((e) => {
|
||||
if (memInfo.equipment.includes(e)) return;
|
||||
if (memInfo.augmentations.includes(e)) return;
|
||||
|
||||
hadAll = false;
|
||||
|
||||
var type = ns.gang.getEquipmentType(e);
|
||||
switch (type) {
|
||||
case "Weapon":
|
||||
if (buyWeapon) {
|
||||
didBuy |= ns.gang.purchaseEquipment(m, e);
|
||||
}
|
||||
break;
|
||||
case "Armor":
|
||||
if (buyArmor) {
|
||||
didBuy |= ns.gang.purchaseEquipment(m, e);
|
||||
}
|
||||
break;
|
||||
case "Vehicle":
|
||||
if (buyVehicle) {
|
||||
didBuy |= ns.gang.purchaseEquipment(m, e);
|
||||
}
|
||||
break;
|
||||
case "Rootkit":
|
||||
if (buyRoot) {
|
||||
didBuy |= ns.gang.purchaseEquipment(m, e);
|
||||
}
|
||||
break;
|
||||
case "Augmentation":
|
||||
if (buyAug) {
|
||||
didBuy |= ns.gang.purchaseEquipment(m, e);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
var wantsToAscend = hadAll;
|
||||
|
||||
if (myGang.isHacking) {
|
||||
wantsToAscend &= memInfo.hackingAscensionMult < ascensionMultLimit;
|
||||
}
|
||||
else {
|
||||
wantsToAscend &= memInfo.hackingAscensionMult < ascensionMultLimit;
|
||||
wantsToAscend &= memInfo.strengthAscensionMult < ascensionMultLimit;
|
||||
wantsToAscend &= memInfo.agilityAscensionMult < ascensionMultLimit;
|
||||
wantsToAscend &= memInfo.dexterityAscensionMult < ascensionMultLimit;
|
||||
}
|
||||
|
||||
if (wantsToAscend && nextAscensionAttempt <= 0) {
|
||||
ns.gang.ascendMember(m);
|
||||
}
|
||||
});
|
||||
|
||||
if (nextAscensionAttempt <= 0) {
|
||||
nextAscensionAttempt = ascensionCycles;
|
||||
}
|
||||
|
||||
var member = "";
|
||||
if (!myGang.isHacking) {
|
||||
var memCount = members.length;
|
||||
|
||||
while (members.length > (memCount / 2)) {
|
||||
member = members.pop();
|
||||
ns.gang.setMemberTask(member, territoryTask);
|
||||
}
|
||||
}
|
||||
|
||||
while (members.length > 0) {
|
||||
var task = "";
|
||||
member = members.pop();
|
||||
memInfo = ns.gang.getMemberInformation(member);
|
||||
|
||||
var statsTarget = 50;
|
||||
|
||||
if ((myGang.isHacking && memInfo.hacking < statsTarget) ||
|
||||
(!myGang.isHacking && memInfo.strength < statsTarget && memInfo.agility < statsTarget && memInfo.charisma < statsTarget && memInfo.defense < statsTarget)) {
|
||||
task = trainingTasks[getRandomInt(trainingTasks.length)];
|
||||
}
|
||||
else if (myGang.wantedLevel > 1) {
|
||||
task = wantedLevelLowerTask;
|
||||
}
|
||||
else {
|
||||
if (Math.random() > 0.25) {
|
||||
task = possibleTasks[possibleTasks.length - getRandomInt(2) - 1];
|
||||
}
|
||||
else {
|
||||
task = trainingTasks[getRandomInt(trainingTasks.length)];
|
||||
}
|
||||
}
|
||||
|
||||
ns.gang.setMemberTask(member, task);
|
||||
}
|
||||
|
||||
await ns.sleep(cycleMs);
|
||||
nextAscensionAttempt -= cycleMs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user