-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyzePurchasableAugs.ts
More file actions
89 lines (81 loc) · 3.05 KB
/
AnalyzePurchasableAugs.ts
File metadata and controls
89 lines (81 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { BitBurner as NS, AugmentPair } from "Bitburner";
export function main(ns: NS) {
let cinfo = ns.getCharacterInformation();
let freps = {};
let augs = formAugmentationsList(ns, cinfo.factions, freps);
let buy = ns.args.includes("buy");
augs.sort(function (a: AugmentPair, b) { return b.cost - a.cost; });
//ns.tprint(`Total: ${ns.nFormat(calculateTotalCost(ns, augs), "$0.000a")}`);
resolvePrereqs(ns, augs);
augs.forEach(function (aug) {
let color = (freps[aug.faction] > aug.repCost) ? "lime" : "red";
//ns.tprint(`${aug.faction} - ${aug.name}, <font color = "${color}">${aug.repCost} rep.</font> ${ns.nFormat(aug.cost, "$0.000a")}`);
});
if (buy) buyAugs(ns, augs);
else calculateTotalCost(ns, augs);
}
function Augmentation(ns: NS, faction, name, prereqs) {
let costs = ns.getAugmentationCost(name);
return {
faction: faction,
name: name,
repCost: costs[0],
cost: costs[1],
prereqs: prereqs
};
}
function resolvePrereqs(ns: NS, augs) {
for (let i = 0; i < augs.length; i++) {
let aug = augs[i];
if (aug.prereqs.length == 0) continue;
let prereq = aug.prereqs[0];
//ns.tprint(`Found a prereq for ${aug.name} : ${prereq}`);
let pri = augs.findIndex(function (augment) { return augment.name == prereq; });
if (pri != -1) {
//ns.tprint(`Moving ${prereq} to ${i}`);
let prerequisite = augs[pri];
augs.splice(pri, 1);
augs.splice(i, 0, prerequisite);
i--;
aug.prereqs = [];
}
}
}
function formAugmentationsList(ns, factions, freps) {
let augs: any = [];
debugger;
factions.forEach(function (fac) {
freps[fac] = ns.getFactionRep(fac);
let faugs = ns.getAugmentationsFromFaction(fac);
faugs.forEach(function (augment) {
if (!augs.find(function (aug) { return aug.name == augment; }) &&
!ns.getOwnedAugmentations(true).find(function (aug) { return (augment == "NeuroFlux Governor") ? false : (aug == augment); }) &&
ns.getAugmentationCost(augment)[0] <= freps[fac]
) {
augs.push(Augmentation(ns, fac, augment, ns.getAugmentationPrereq(augment)));
}
});
});
return augs;
}
function calculateTotalCost(ns, augs) {
let total = 0;
let multiplier = 1;
augs.forEach(function (aug) {
total += aug.cost * multiplier;
multiplier *= 1.9;
ns.tprint(`${aug.faction} - ${aug.name}, ${aug.repCost} rep. total: ${ns.nFormat(total, "$0.000a")}`);
});
return total;
}
function buyAugs(ns: NS, augs) {
augs.forEach(function (aug) {
if (ns.getServerMoneyAvailable("home") >= aug.cost) {
if (ns.purchaseAugmentation(aug.faction, aug.name))
ns.tprint(`${aug.faction} - ${aug.name} bought!`);
else
ns.tprint(`Can't buy ${aug.faction} - ${aug.name}!`);
} else
ns.tprint(`Can't buy ${aug.faction} - ${aug.name}!`);
});
}