Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export function buildServerObject(ns, node) {
  2.     var server = {
  3.         instance: ns,
  4.         name: node,
  5.         minSecurity: ns.getServerMinSecurityLevel(node),
  6.         hackingRequired: ns.getServerRequiredHackingLevel(node),
  7.         portsRequired: ns.getServerNumPortsRequired(node),
  8.         maxMoney: ns.getServerMaxMoney(node),
  9.         canCrack: function() { return getPortCrackers(this.instance) >= this.portsRequired && this.hackingRequired <= this.instance.getHackingLevel(); },
  10.         money: function() { return this.instance.getServerMoneyAvailable(this.name); },
  11.         security: function() { return this.instance.getServerSecurityLevel(this.name); },
  12.         serverGrowthPercentage: function() {
  13.             return this.instance.getServerGrowth(this.name) * bitnodeGrowMult * playerHackingGrowMult / 100;
  14.         },
  15.         // if growth rate is optimistic, it is assumed the security is minimum - this is especially not the case when prepping a server
  16.         adjustedGrowthRate: function(isOptimistic) {
  17.             return Math.min(maxGrowthRate, 1 + ((unadjustedGrowthRate - 1) / (isOptimistic ? this.minSecurity : this.security())));
  18.         },
  19.         // actualServerGrowthRate: function(isOptimistic) {
  20.         //     return Math.pow(this.adjustedGrowthRate(isOptimistic), this.serverGrowthPercentage());
  21.         // },
  22.         // this is the target growth coefficient *immediately*
  23.         targetGrowthCoefficient: function() {
  24.             return this.maxMoney / Math.max(this.money(), 1);
  25.         },
  26.         // this is the target growth coefficient per cycle, based on theft
  27.         targetGrowthCoefficientAfterTheft: function() {
  28.             return 1 / (1 - percentageToSteal);
  29.         },
  30.         cyclesNeededForGrowthCoefficient: function() {
  31.             return Math.log(this.targetGrowthCoefficient()) / Math.log(this.adjustedGrowthRate(false));
  32.         },
  33.         cyclesNeededForGrowthCoefficientAfterTheft: function() {
  34.             return Math.log(this.targetGrowthCoefficientAfterTheft()) / Math.log(this.adjustedGrowthRate(true));
  35.         },
  36.         hackEaseCoefficient: function() {
  37.             return (100 - Math.min(100, this.minSecurity)) / 100;
  38.         },
  39.         hackingSkillCoefficient: function() {
  40.             return (this.instance.getHackingLevel() - (this.hackingRequired - 1)) / this.instance.getHackingLevel();
  41.         },
  42.         actualHackCoefficient: function() {
  43.             return this.hackEaseCoefficient() * this.hackingSkillCoefficient() * actualHackMultiplier() / 240;
  44.         },
  45.         percentageStolenPerHackThread: function() {
  46.             return Math.min(1, Math.max(0, this.actualHackCoefficient()));
  47.         },
  48.         hackThreadsNeeded: function() {
  49.             return Math.floor(percentageToSteal / this.percentageStolenPerHackThread());
  50.         },
  51.         growThreadsNeeded: function() {
  52.             return Math.ceil(this.cyclesNeededForGrowthCoefficient() / this.serverGrowthPercentage());
  53.         },
  54.         growThreadsNeededAfterTheft: function() {
  55.             return Math.ceil(this.cyclesNeededForGrowthCoefficientAfterTheft() / this.serverGrowthPercentage());
  56.         },
  57.         weakenThreadsNeededAfterTheft: function() {
  58.             return Math.ceil(this.hackThreadsNeeded() * hackThreadHardening / actualWeakenPotency());
  59.         },
  60.         weakenThreadsNeededAfterGrowth: function() {
  61.             return Math.ceil(this.growThreadsNeededAfterTheft() * growthThreadHardening / actualWeakenPotency());
  62.         },
  63.         weakenThreadTotalPerCycle: function() {
  64.             return (currentTarget.weakenThreadsNeededAfterTheft() + currentTarget.weakenThreadsNeededAfterGrowth());
  65.         },
  66.         hasRoot: function() { return this.instance.hasRootAccess(this.name); },
  67.         shouldHack: function() { return this.maxMoney > 0; },
  68.         isHost: function() { return this.name == daemonHost; },
  69.         getRam: function() { return this.instance.getServerRam(this.name); },
  70.         ramAvailable: function() {
  71.             var ramArray = this.getRam();
  72.             return ramArray[0] - ramArray[1];
  73.         },
  74.         growDelay: function() { return this.timeToWeaken() - this.timeToGrow() + arbitraryExecutionDelay; },
  75.         hackDelay: function() { return this.timeToWeaken() - this.timeToHack(); },
  76.         timeToWeaken: function() { return this.instance.getWeakenTime(this.name); },
  77.         timeToGrow: function() { return this.instance.getGrowTime(this.name); },
  78.         timeToHack: function() { return this.instance.getHackTime(this.name); },
  79.         weakenThreadsNeeded: function() { return Math.ceil((this.security() - this.minSecurity) / actualWeakenPotency()); }
  80.     };
  81.     return server;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement