Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function buildServerObject(ns, node) {
- var server = {
- instance: ns,
- name: node,
- minSecurity: ns.getServerMinSecurityLevel(node),
- hackingRequired: ns.getServerRequiredHackingLevel(node),
- portsRequired: ns.getServerNumPortsRequired(node),
- maxMoney: ns.getServerMaxMoney(node),
- canCrack: function() { return getPortCrackers(this.instance) >= this.portsRequired && this.hackingRequired <= this.instance.getHackingLevel(); },
- money: function() { return this.instance.getServerMoneyAvailable(this.name); },
- security: function() { return this.instance.getServerSecurityLevel(this.name); },
- serverGrowthPercentage: function() {
- return this.instance.getServerGrowth(this.name) * bitnodeGrowMult * playerHackingGrowMult / 100;
- },
- // if growth rate is optimistic, it is assumed the security is minimum - this is especially not the case when prepping a server
- adjustedGrowthRate: function(isOptimistic) {
- return Math.min(maxGrowthRate, 1 + ((unadjustedGrowthRate - 1) / (isOptimistic ? this.minSecurity : this.security())));
- },
- // actualServerGrowthRate: function(isOptimistic) {
- // return Math.pow(this.adjustedGrowthRate(isOptimistic), this.serverGrowthPercentage());
- // },
- // this is the target growth coefficient *immediately*
- targetGrowthCoefficient: function() {
- return this.maxMoney / Math.max(this.money(), 1);
- },
- // this is the target growth coefficient per cycle, based on theft
- targetGrowthCoefficientAfterTheft: function() {
- return 1 / (1 - percentageToSteal);
- },
- cyclesNeededForGrowthCoefficient: function() {
- return Math.log(this.targetGrowthCoefficient()) / Math.log(this.adjustedGrowthRate(false));
- },
- cyclesNeededForGrowthCoefficientAfterTheft: function() {
- return Math.log(this.targetGrowthCoefficientAfterTheft()) / Math.log(this.adjustedGrowthRate(true));
- },
- hackEaseCoefficient: function() {
- return (100 - Math.min(100, this.minSecurity)) / 100;
- },
- hackingSkillCoefficient: function() {
- return (this.instance.getHackingLevel() - (this.hackingRequired - 1)) / this.instance.getHackingLevel();
- },
- actualHackCoefficient: function() {
- return this.hackEaseCoefficient() * this.hackingSkillCoefficient() * actualHackMultiplier() / 240;
- },
- percentageStolenPerHackThread: function() {
- return Math.min(1, Math.max(0, this.actualHackCoefficient()));
- },
- hackThreadsNeeded: function() {
- return Math.floor(percentageToSteal / this.percentageStolenPerHackThread());
- },
- growThreadsNeeded: function() {
- return Math.ceil(this.cyclesNeededForGrowthCoefficient() / this.serverGrowthPercentage());
- },
- growThreadsNeededAfterTheft: function() {
- return Math.ceil(this.cyclesNeededForGrowthCoefficientAfterTheft() / this.serverGrowthPercentage());
- },
- weakenThreadsNeededAfterTheft: function() {
- return Math.ceil(this.hackThreadsNeeded() * hackThreadHardening / actualWeakenPotency());
- },
- weakenThreadsNeededAfterGrowth: function() {
- return Math.ceil(this.growThreadsNeededAfterTheft() * growthThreadHardening / actualWeakenPotency());
- },
- weakenThreadTotalPerCycle: function() {
- return (currentTarget.weakenThreadsNeededAfterTheft() + currentTarget.weakenThreadsNeededAfterGrowth());
- },
- hasRoot: function() { return this.instance.hasRootAccess(this.name); },
- shouldHack: function() { return this.maxMoney > 0; },
- isHost: function() { return this.name == daemonHost; },
- getRam: function() { return this.instance.getServerRam(this.name); },
- ramAvailable: function() {
- var ramArray = this.getRam();
- return ramArray[0] - ramArray[1];
- },
- growDelay: function() { return this.timeToWeaken() - this.timeToGrow() + arbitraryExecutionDelay; },
- hackDelay: function() { return this.timeToWeaken() - this.timeToHack(); },
- timeToWeaken: function() { return this.instance.getWeakenTime(this.name); },
- timeToGrow: function() { return this.instance.getGrowTime(this.name); },
- timeToHack: function() { return this.instance.getHackTime(this.name); },
- weakenThreadsNeeded: function() { return Math.ceil((this.security() - this.minSecurity) / actualWeakenPotency()); }
- };
- return server;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement