mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-02 05:47:14 +02:00
NETSCRIPT: add formulas.hacking.growAmount() (#1090)
Also, improve docs.
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import { GetServer, createUniqueRandomIp, ipExists } from "./AllServers";
|
||||
import { Server, IConstructorParams } from "./Server";
|
||||
import { BaseServer } from "./BaseServer";
|
||||
import { calculateServerGrowth, calculateServerGrowthLog } from "./formulas/grow";
|
||||
import { calculateGrowMoney, calculateServerGrowthLog } from "./formulas/grow";
|
||||
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
||||
import { ServerConstants } from "./data/Constants";
|
||||
import { Player } from "@player";
|
||||
import { CompletedProgramName, LiteratureName } from "@enums";
|
||||
import { Person as IPerson } from "@nsdefs";
|
||||
import { isValidNumber } from "../utils/helpers/isValidNumber";
|
||||
import { Server as IServer } from "@nsdefs";
|
||||
import { workerScripts } from "../Netscript/WorkerScripts";
|
||||
import { killWorkerScriptByPid } from "../Netscript/killWorkerScript";
|
||||
@@ -177,25 +176,8 @@ export function numCycleForGrowthCorrected(
|
||||
|
||||
//Applied server growth for a single server. Returns the percentage growth
|
||||
export function processSingleServerGrowth(server: Server, threads: number, cores = 1): number {
|
||||
let serverGrowth = calculateServerGrowth(server, threads, Player, cores);
|
||||
if (serverGrowth < 1) {
|
||||
console.warn("serverGrowth calculated to be less than 1");
|
||||
serverGrowth = 1;
|
||||
}
|
||||
|
||||
const oldMoneyAvailable = server.moneyAvailable;
|
||||
server.moneyAvailable += threads; // It can be grown even if it has no money
|
||||
server.moneyAvailable *= serverGrowth;
|
||||
|
||||
// in case of data corruption
|
||||
if (isValidNumber(server.moneyMax) && isNaN(server.moneyAvailable)) {
|
||||
server.moneyAvailable = server.moneyMax;
|
||||
}
|
||||
|
||||
// cap at max
|
||||
if (isValidNumber(server.moneyMax) && server.moneyAvailable > server.moneyMax) {
|
||||
server.moneyAvailable = server.moneyMax;
|
||||
}
|
||||
server.moneyAvailable = calculateGrowMoney(server, threads, Player, cores);
|
||||
|
||||
// if there was any growth at all, increase security
|
||||
if (oldMoneyAvailable !== server.moneyAvailable) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { currentNodeMults } from "../../BitNode/BitNodeMultipliers";
|
||||
import { Person as IPerson, Server as IServer } from "@nsdefs";
|
||||
import { ServerConstants } from "../data/Constants";
|
||||
import { isValidNumber } from "../../utils/helpers/isValidNumber";
|
||||
|
||||
// Returns the log of the growth rate. When passing 1 for threads, this gives a useful constant.
|
||||
export function calculateServerGrowthLog(server: IServer, threads: number, p: IPerson, cores = 1): number {
|
||||
@@ -30,3 +31,27 @@ export function calculateServerGrowth(server: IServer, threads: number, p: IPers
|
||||
if (!server.serverGrowth) return 0;
|
||||
return Math.exp(calculateServerGrowthLog(server, threads, p, cores));
|
||||
}
|
||||
|
||||
// This differs from calculateServerGrowth in that it includes the additive
|
||||
// factor and all the boundary checks.
|
||||
export function calculateGrowMoney(server: IServer, threads: number, p: IPerson, cores = 1): number {
|
||||
let serverGrowth = calculateServerGrowth(server, threads, p, cores);
|
||||
if (serverGrowth < 1) {
|
||||
console.warn("serverGrowth calculated to be less than 1");
|
||||
serverGrowth = 1;
|
||||
}
|
||||
|
||||
let moneyAvailable = server.moneyAvailable ?? Number.NaN;
|
||||
moneyAvailable += threads; // It can be grown even if it has no money
|
||||
moneyAvailable *= serverGrowth;
|
||||
|
||||
// cap at max (or data corruption)
|
||||
if (
|
||||
server.moneyMax !== undefined &&
|
||||
isValidNumber(server.moneyMax) &&
|
||||
(moneyAvailable > server.moneyMax || isNaN(moneyAvailable))
|
||||
) {
|
||||
moneyAvailable = server.moneyMax;
|
||||
}
|
||||
return moneyAvailable;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user