2021-10-07 22:56:01 +02:00
|
|
|
import { GetServer, createUniqueRandomIp, ipExists } from "./AllServers";
|
2019-05-05 06:03:40 +02:00
|
|
|
import { Server, IConstructorParams } from "./Server";
|
2021-09-16 01:50:44 +02:00
|
|
|
import { BaseServer } from "./BaseServer";
|
2024-03-26 11:26:50 +01:00
|
|
|
import { calculateGrowMoney, calculateServerGrowthLog } from "./formulas/grow";
|
2024-02-17 02:18:16 +01:00
|
|
|
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
2024-02-10 10:13:42 +01:00
|
|
|
import { ServerConstants } from "./data/Constants";
|
2022-10-10 00:42:14 +02:00
|
|
|
import { Player } from "@player";
|
2023-06-12 06:34:20 +02:00
|
|
|
import { CompletedProgramName, LiteratureName } from "@enums";
|
2023-02-14 23:38:51 +01:00
|
|
|
import { Person as IPerson } from "@nsdefs";
|
2023-04-11 21:12:55 +02:00
|
|
|
import { Server as IServer } from "@nsdefs";
|
2023-05-26 20:59:31 +02:00
|
|
|
import { workerScripts } from "../Netscript/WorkerScripts";
|
|
|
|
import { killWorkerScriptByPid } from "../Netscript/killWorkerScript";
|
2024-04-29 03:35:56 +02:00
|
|
|
import { serverMetadata } from "./data/servers";
|
2019-05-05 06:03:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new server, while also ensuring that the new server
|
|
|
|
* does not have a duplicate hostname/ip.
|
|
|
|
*/
|
2022-10-09 07:25:31 +02:00
|
|
|
export function safelyCreateUniqueServer(params: IConstructorParams): Server {
|
2021-12-19 05:03:14 +01:00
|
|
|
let hostname: string = params.hostname.replace(/ /g, `-`);
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (params.ip != null && ipExists(params.ip)) {
|
|
|
|
params.ip = createUniqueRandomIp();
|
|
|
|
}
|
|
|
|
|
2021-12-19 05:03:14 +01:00
|
|
|
if (GetServer(hostname) != null) {
|
2022-09-23 18:04:21 +02:00
|
|
|
if (hostname.slice(-2) != `-0`) {
|
|
|
|
hostname = `${hostname}-0`;
|
|
|
|
}
|
2021-12-19 05:03:14 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Use a for loop to ensure that we don't get suck in an infinite loop somehow
|
|
|
|
for (let i = 0; i < 200; ++i) {
|
2021-12-19 05:03:14 +01:00
|
|
|
hostname = hostname.replace(/-[0-9]+$/, `-${i}`);
|
2021-10-07 22:56:01 +02:00
|
|
|
if (GetServer(hostname) == null) {
|
2021-09-05 01:09:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2021-12-19 05:03:14 +01:00
|
|
|
params.hostname = hostname;
|
2021-09-05 01:09:30 +02:00
|
|
|
return new Server(params);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
2019-03-03 04:15:10 +01:00
|
|
|
|
2019-07-14 05:55:58 +02:00
|
|
|
/**
|
2023-02-14 23:38:51 +01:00
|
|
|
* Returns the number of "growth cycles" needed to grow the specified server by the specified amount, taking into
|
|
|
|
* account only the multiplicative factor. Does not account for the additive $1/thread. Only used for growthAnalyze.
|
2019-07-14 05:55:58 +02:00
|
|
|
* @param server - Server being grown
|
|
|
|
* @param growth - How much the server is being grown by, in DECIMAL form (e.g. 1.5 rather than 50)
|
|
|
|
* @param p - Reference to Player object
|
|
|
|
* @returns Number of "growth cycles" needed
|
|
|
|
*/
|
2023-04-11 21:12:55 +02:00
|
|
|
export function numCycleForGrowth(server: IServer, growth: number, cores = 1): number {
|
|
|
|
if (!server.serverGrowth) return Infinity;
|
2024-02-01 01:27:31 +01:00
|
|
|
return Math.log(growth) / calculateServerGrowthLog(server, 1, Player, cores);
|
2019-03-03 04:15:10 +01:00
|
|
|
}
|
|
|
|
|
2022-01-28 22:36:28 +01:00
|
|
|
/**
|
2022-02-01 05:04:39 +01:00
|
|
|
* This function calculates the number of threads needed to grow a server from one $amount to a higher $amount
|
2023-02-14 23:38:51 +01:00
|
|
|
* (ie, how many threads to grow this server from $200 to $600 for example).
|
2022-02-01 04:54:38 +01:00
|
|
|
* It protects the inputs (so putting in INFINITY for targetMoney will use moneyMax, putting in a negative for start will use 0, etc.)
|
2022-01-28 22:36:28 +01:00
|
|
|
* @param server - Server being grown
|
|
|
|
* @param targetMoney - How much you want the server grown TO (not by), for instance, to grow from 200 to 600, input 600
|
|
|
|
* @param startMoney - How much you are growing the server from, for instance, to grow from 200 to 600, input 200
|
2022-09-18 03:09:15 +02:00
|
|
|
* @param cores - Number of cores on the host performing grow
|
2023-02-14 23:38:51 +01:00
|
|
|
* @returns Integer threads needed by a single ns.grow call to reach targetMoney from startMoney.
|
2022-01-28 22:45:12 +01:00
|
|
|
*/
|
2023-02-14 23:38:51 +01:00
|
|
|
export function numCycleForGrowthCorrected(
|
2023-04-11 21:12:55 +02:00
|
|
|
server: IServer,
|
2023-02-14 23:38:51 +01:00
|
|
|
targetMoney: number,
|
|
|
|
startMoney: number,
|
|
|
|
cores = 1,
|
|
|
|
person: IPerson = Player,
|
|
|
|
): number {
|
2023-04-11 21:12:55 +02:00
|
|
|
if (!server.serverGrowth) return Infinity;
|
|
|
|
const moneyMax = server.moneyMax ?? 1;
|
|
|
|
|
2023-02-14 23:38:51 +01:00
|
|
|
if (startMoney < 0) startMoney = 0; // servers "can't" have less than 0 dollars on them
|
2023-04-11 21:12:55 +02:00
|
|
|
if (targetMoney > moneyMax) targetMoney = moneyMax; // can't grow a server to more than its moneyMax
|
2023-02-14 23:38:51 +01:00
|
|
|
if (targetMoney <= startMoney) return 0; // no growth --> no threads
|
2022-01-29 00:21:05 +01:00
|
|
|
|
2024-02-01 01:27:31 +01:00
|
|
|
const k = calculateServerGrowthLog(server, 1, person, cores);
|
2022-04-07 01:30:08 +02:00
|
|
|
/* To understand what is done below we need to do some math. I hope the explanation is clear enough.
|
|
|
|
* First of, the names will be shortened for ease of manipulation:
|
2024-02-01 01:27:31 +01:00
|
|
|
* n:= targetMoney (n for new), o:= startMoney (o for old), k:= calculateServerGrowthLog, x:= threads
|
|
|
|
* x is what we are trying to compute.
|
2022-04-07 01:30:08 +02:00
|
|
|
*
|
2024-02-01 01:27:31 +01:00
|
|
|
* After growing, the money on a server is n = (o + x) * exp(k*x)
|
|
|
|
* x appears in an exponent and outside it, this is usually solved using the productLog/lambert's W special function,
|
|
|
|
* but it turns out that due to floating-point range issues this approach is *useless* to us, so it will be ignored.
|
2022-04-07 01:30:08 +02:00
|
|
|
*
|
2024-02-01 01:27:31 +01:00
|
|
|
* Instead, we proceed directly to Newton-Raphson iteration. We first rewrite the equation in
|
|
|
|
* log-form, since iterating it this way has faster convergence: log(n) = log(o+x) + k*x.
|
|
|
|
* Now our goal is to find the zero of f(x) = log((o+x)/n) + k*x.
|
|
|
|
* (Due to the shape of the function, there will be a single zero.)
|
2022-04-07 01:30:08 +02:00
|
|
|
*
|
|
|
|
* The idea of this method is to take the horizontal position at which the horizontal axis
|
|
|
|
* intersects with of the tangent of the function's curve as the next approximation.
|
|
|
|
* It is equivalent to treating the curve as a line (it is called a first order approximation)
|
2024-02-01 01:27:31 +01:00
|
|
|
* If the current approximation is x then the new approximated value is x - f(x)/f'(x)
|
2022-04-07 01:30:08 +02:00
|
|
|
* (where f' is the derivative of f).
|
|
|
|
*
|
2024-02-01 01:27:31 +01:00
|
|
|
* In our case f(x) = log((o+x)/n) + k*x, f'(x) = d(log((o+x)/n) + k*x)/dx
|
|
|
|
* = 1/(o + x) + k
|
|
|
|
* And the update step is x[new] = x - (log((o+x)/n) + k*x)/(1/(o+x) + k)
|
|
|
|
* We can simplify this by bringing the first term up into the fraction:
|
|
|
|
* = (x * (1/(o+x) + k) - log((o+x)/n) - k*x) / (1/(o+x) + k)
|
|
|
|
* = (x/(o+x) - log((o+x)/n)) / (1/(o+x) + k) [multiplying top and bottom by (o+x)]
|
|
|
|
* = (x - (o+x)*log((o+x)/n)) / (1 + (o+x)*k)
|
2022-04-07 01:30:08 +02:00
|
|
|
*
|
2024-02-01 01:27:31 +01:00
|
|
|
* The main question to ask when using this method is "does it converge?"
|
2022-04-07 01:30:08 +02:00
|
|
|
* (are the approximations getting better?), if it does then it does quickly.
|
2024-02-01 01:27:31 +01:00
|
|
|
* Since the derivative is always positive but also strictly decreasing, convergence is guaranteed.
|
|
|
|
* This also provides the useful knowledge that any x which starts *greater* than the solution will
|
|
|
|
* undershoot across to the left, while values *smaller* than the zero will continue to find
|
|
|
|
* closer approximations that are still smaller than the final value.
|
|
|
|
*
|
|
|
|
* Of great importance for reducing the number of iterations is starting with a good initial
|
|
|
|
* guess. We use a very simple starting condition: x_0 = n - o. We *know* this will always overshot
|
|
|
|
* the target, usually by a vast amount. But we can run it manually through one Newton iteration
|
|
|
|
* to get a better start with nice properties:
|
|
|
|
* x_1 = ((n - o) - (n - o + o)*log((n-o+o)/n)) / (1 + (n-o+o)*k)
|
|
|
|
* = ((n - o) - n * log(n/n)) / (1 + n*k)
|
|
|
|
* = ((n - o) - n * 0) / (1 + n*k)
|
|
|
|
* = (n - o) / (1 + n*k)
|
|
|
|
* We can do the same procedure with the exponential form of Newton's method, starting from x_0 = 0.
|
|
|
|
* This gives x_1 = (n - o) / (1 + o*k), (full derivation omitted) which will be an overestimate.
|
|
|
|
* We use a weighted average of the denominators to get the final guess:
|
|
|
|
* x = (n - o) / (1 + (1/16*n + 15/16*o)*k)
|
|
|
|
* The reason for this particular weighting is subtle; it is exactly representable and holds up
|
|
|
|
* well under a wide variety of conditions, making it likely that the we start within 1 thread of
|
|
|
|
* correct. It particularly bounds the worst-case to 3 iterations, and gives a very wide swatch
|
|
|
|
* where 2 iterations is good enough.
|
|
|
|
*
|
|
|
|
* The accuracy of the initial guess is good for many inputs - often one iteration
|
|
|
|
* is sufficient. This means the overall cost is two logs (counting the one in calculateServerGrowthLog),
|
|
|
|
* possibly one exp, 5 divisions, and a handful of basic arithmetic.
|
2022-04-07 01:30:08 +02:00
|
|
|
*/
|
2024-02-01 01:27:31 +01:00
|
|
|
const guess = (targetMoney - startMoney) / (1 + (targetMoney * (1 / 16) + startMoney * (15 / 16)) * k);
|
|
|
|
let x = guess;
|
|
|
|
let diff;
|
2022-04-07 01:30:08 +02:00
|
|
|
do {
|
2024-02-01 01:27:31 +01:00
|
|
|
const ox = startMoney + x;
|
|
|
|
// Have to use division instead of multiplication by inverse, because
|
|
|
|
// if targetMoney is MIN_VALUE then inverting gives Infinity
|
|
|
|
const newx = (x - ox * Math.log(ox / targetMoney)) / (1 + ox * k);
|
|
|
|
diff = newx - x;
|
|
|
|
x = newx;
|
|
|
|
} while (diff < -1 || diff > 1);
|
|
|
|
/* If we see a diff of 1 or less we know all future diffs will be smaller, and the rate of
|
|
|
|
* convergence means the *sum* of the diffs will be less than 1.
|
|
|
|
|
|
|
|
* In most cases, our result here will be ceil(x).
|
2022-04-07 01:30:08 +02:00
|
|
|
*/
|
2024-02-01 01:27:31 +01:00
|
|
|
const ccycle = Math.ceil(x);
|
|
|
|
if (ccycle - x > 0.999999) {
|
|
|
|
// Rounding-error path: It's possible that we slightly overshot the integer value due to
|
|
|
|
// rounding error, and more specifically precision issues with log and the size difference of
|
|
|
|
// startMoney vs. x. See if a smaller integer works. Most of the time, x was not close enough
|
|
|
|
// that we need to try.
|
|
|
|
const fcycle = ccycle - 1;
|
|
|
|
if (targetMoney <= (startMoney + fcycle) * Math.exp(k * fcycle)) {
|
|
|
|
return fcycle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ccycle >= x + ((diff <= 0 ? -diff : diff) + 0.000001)) {
|
|
|
|
// Fast-path: We know the true value is somewhere in the range [x, x + |diff|] but the next
|
|
|
|
// greatest integer is past this. Since we have to round up grows anyway, we can return this
|
|
|
|
// with no more calculation. We need some slop due to rounding errors - we can't fast-path
|
|
|
|
// a value that is too small.
|
|
|
|
return ccycle;
|
2022-04-07 01:30:08 +02:00
|
|
|
}
|
2024-02-01 01:27:31 +01:00
|
|
|
if (targetMoney <= (startMoney + ccycle) * Math.exp(k * ccycle)) {
|
|
|
|
return ccycle;
|
2022-04-07 01:30:08 +02:00
|
|
|
}
|
2024-02-01 01:27:31 +01:00
|
|
|
return ccycle + 1;
|
2022-01-29 00:21:05 +01:00
|
|
|
}
|
|
|
|
|
2019-03-03 04:15:10 +01:00
|
|
|
//Applied server growth for a single server. Returns the percentage growth
|
2022-09-18 03:09:15 +02:00
|
|
|
export function processSingleServerGrowth(server: Server, threads: number, cores = 1): number {
|
2021-09-05 01:09:30 +02:00
|
|
|
const oldMoneyAvailable = server.moneyAvailable;
|
2024-03-26 11:26:50 +01:00
|
|
|
server.moneyAvailable = calculateGrowMoney(server, threads, Player, cores);
|
2021-09-05 01:09:30 +02:00
|
|
|
|
|
|
|
// if there was any growth at all, increase security
|
|
|
|
if (oldMoneyAvailable !== server.moneyAvailable) {
|
2022-09-18 03:09:15 +02:00
|
|
|
let usedCycles = numCycleForGrowthCorrected(server, server.moneyAvailable, oldMoneyAvailable, cores);
|
2022-01-30 12:34:05 +01:00
|
|
|
// Growing increases server security twice as much as hacking
|
2021-10-28 21:24:33 +02:00
|
|
|
usedCycles = Math.min(Math.max(0, Math.ceil(usedCycles)), threads);
|
2024-02-10 10:13:42 +01:00
|
|
|
server.fortify(2 * ServerConstants.ServerFortifyAmount * usedCycles);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
return server.moneyAvailable / oldMoneyAvailable;
|
2019-03-03 04:15:10 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 03:09:15 +02:00
|
|
|
export function prestigeHomeComputer(homeComp: Server): void {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
const hasBitflume = homeComp.programs.includes(CompletedProgramName.bitFlume);
|
2021-09-05 01:09:30 +02:00
|
|
|
|
|
|
|
homeComp.programs.length = 0; //Remove programs
|
|
|
|
homeComp.serversOnNetwork = [];
|
|
|
|
homeComp.isConnectedTo = true;
|
|
|
|
homeComp.ramUsed = 0;
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
homeComp.programs.push(CompletedProgramName.nuke);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (hasBitflume) {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
homeComp.programs.push(CompletedProgramName.bitFlume);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
homeComp.messages.length = 0; //Remove .lit and .msg files
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
homeComp.messages.push(LiteratureName.HackersStartingHandbook);
|
2023-04-28 00:21:06 +02:00
|
|
|
if (homeComp.runningScriptMap.size !== 0) {
|
2023-05-26 20:59:31 +02:00
|
|
|
// Temporary verbose logging section to gather data on a bug
|
|
|
|
console.error("Some runningScripts were still present on home during prestige");
|
|
|
|
for (const [scriptKey, byPidMap] of homeComp.runningScriptMap) {
|
|
|
|
console.error(`script key: ${scriptKey}: ${byPidMap.size} scripts`);
|
|
|
|
for (const pid of byPidMap.keys()) {
|
|
|
|
if (workerScripts.has(pid)) killWorkerScriptByPid(pid);
|
|
|
|
}
|
|
|
|
byPidMap.clear();
|
|
|
|
}
|
|
|
|
homeComp.runningScriptMap.clear();
|
2023-04-28 00:21:06 +02:00
|
|
|
}
|
2019-03-03 04:15:10 +01:00
|
|
|
}
|
|
|
|
|
2019-03-05 02:40:28 +01:00
|
|
|
// Returns the i-th server on the specified server's network
|
|
|
|
// A Server's serverOnNetwork property holds only the IPs. This function returns
|
|
|
|
// the actual Server object
|
2021-10-07 22:04:04 +02:00
|
|
|
export function getServerOnNetwork(server: BaseServer, i: number): BaseServer | null {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (i > server.serversOnNetwork.length) {
|
|
|
|
console.error("Tried to get server on network that was out of range");
|
|
|
|
return null;
|
|
|
|
}
|
2019-03-05 02:40:28 +01:00
|
|
|
|
2021-10-07 22:56:01 +02:00
|
|
|
return GetServer(server.serversOnNetwork[i]);
|
2019-03-05 02:40:28 +01:00
|
|
|
}
|
2021-04-29 02:07:26 +02:00
|
|
|
|
2021-10-07 22:04:04 +02:00
|
|
|
export function isBackdoorInstalled(server: BaseServer): boolean {
|
|
|
|
if (server instanceof Server) {
|
2021-09-05 01:09:30 +02:00
|
|
|
return server.backdoorInstalled;
|
|
|
|
}
|
|
|
|
return false;
|
2021-04-29 02:07:26 +02:00
|
|
|
}
|
2023-12-08 02:10:21 +01:00
|
|
|
|
2024-04-29 03:35:56 +02:00
|
|
|
export function isBackdoorInstalledInCompanyServer(companyName: string): boolean {
|
|
|
|
const serverMeta = serverMetadata.find((s) => s.specialName === companyName);
|
|
|
|
const server = GetServer(serverMeta ? serverMeta.hostname : "");
|
|
|
|
if (!server) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isBackdoorInstalled(server);
|
|
|
|
}
|
|
|
|
|
2023-12-08 02:10:21 +01:00
|
|
|
export function getCoreBonus(cores = 1): number {
|
|
|
|
const coreBonus = 1 + (cores - 1) / 16;
|
|
|
|
return coreBonus;
|
|
|
|
}
|
2024-02-17 02:18:16 +01:00
|
|
|
|
|
|
|
export function getWeakenEffect(threads: number, cores: number): number {
|
|
|
|
const coreBonus = getCoreBonus(cores);
|
|
|
|
return ServerConstants.ServerWeakenAmount * threads * coreBonus * currentNodeMults.ServerWeakenRate;
|
|
|
|
}
|