Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @param {NS} ns */
- export function getOptimalThreads(ns, target) {
- //Script paths
- const growPath = "Scelus_Saeclum/Peritus_Infiltra/Cresco.js";
- const weakenPath = "Scelus_Saeclum/Peritus_Infiltra/Imminuo.js";
- const hackPath = "Scelus_Saeclum/Peritus_Infiltra/Fur.js";
- //Server Information
- const targetMaxMoney = ns.getServerMaxMoney(target);
- const targetAvailableMoney = ns.getServerMoneyAvailable(target) || 1;
- const hostCpuCores = ns.getServer(ns.getHostname())["cpuCores"];
- const hostRemainingRam = getServerRemainingRam(ns, ns.getHostname());
- //ns.tprintf(targetAvailableMoney);
- //ns.tprintf(targetMaxMoney);
- //Calculating Growth Threads
- const necessaryGrowthFactor = Math.max(1, targetMaxMoney / targetAvailableMoney);
- const necessaryGrowthThreads = ns.growthAnalyze(target, necessaryGrowthFactor, hostCpuCores);
- const possibleGrowthThreads = hostRemainingRam / ns.getScriptRam(growPath);
- //Calculating Weaken Threads
- const necessarySecurityToWeaken = ns.getServerSecurityLevel(target); - ns.getServerMinSecurityLevel(target);
- const necessaryWeakenThreads = necessarySecurityToWeaken / ns.weakenAnalyze(1, 1);
- const possibleWeakenThreads = hostRemainingRam / ns.getScriptRam(weakenPath);
- //Calculating Hack Threads
- const moneyToBeStolen = Math.min(targetMaxMoney, targetMaxMoney * possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores) / (1 + possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores)));
- const necessaryHackingThreads = moneyToBeStolen / ns.hackAnalyze(target) / targetMaxMoney;
- const possibleHackingThreads = hostRemainingRam / ns.getScriptRam(hackPath);
- //Conclusion
- const growthThreads = Math.floor(Math.min(necessaryGrowthThreads + 1, possibleGrowthThreads)) || 1;
- const weakenThreads = Math.floor(Math.min(necessaryWeakenThreads + 1, possibleWeakenThreads)) || 1;
- const hackingThreads = Math.floor(Math.min(necessaryHackingThreads + 1, possibleHackingThreads)) || 1;
- return [growthThreads, weakenThreads, hackingThreads];
- /*
- Explanation for moneyToBeStolen:
- X is the amount of money stolen
- (targetMaxMoney - (targetMaxMoney-X))/(targetMaxMoney-X) * 100 = (new-old)/old = percentual change
- (targetMaxMoney - (targetMaxMoney-X))/(targetMaxMoney-X) * 100 * ns.growthAnalyze(target, 1.01, hostCpuCores) = possibleGrowthThreads
- (targetMaxMoney - (targetMaxMoney-X))/(targetMaxMoney-X) = possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores)
- X / (targetMaxMoney-X) = possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores)
- X = (possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores)) * (targetMaxMoney-X)
- X = targetMaxMoney * (possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores)) - X * (possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores))
- X + X * (possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores)) = targetMaxMoney * (possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores))
- X * (1 + (possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores))) = targetMaxMoney * (possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores))
- X = targetMaxMoney * possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores) / (1 + possibleGrowthThreads / 100 / ns.growthAnalyze(target, 1.01, hostCpuCores))
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement