mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 17:43:48 +01:00
Merge pull request #299 from hydroflame/fix-grow-security
fix growth not increasing security if server reaches max money
This commit is contained in:
commit
b4cec584f6
@ -768,19 +768,31 @@ function initForeignServers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function numCycleForGrowth(server, growth) {
|
||||||
|
let ajdGrowthRate = 1 + (CONSTANTS.ServerBaseGrowthRate - 1) / server.hackDifficulty;
|
||||||
|
if(ajdGrowthRate > CONSTANTS.ServerMaxGrowthRate) {
|
||||||
|
ajdGrowthRate = CONSTANTS.ServerMaxGrowthRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
const serverGrowthPercentage = server.serverGrowth / 100;
|
||||||
|
|
||||||
|
const cycles = Math.log(growth)/(Math.log(ajdGrowthRate)*Player.hacking_grow_mult*serverGrowthPercentage);
|
||||||
|
return cycles;
|
||||||
|
}
|
||||||
|
|
||||||
//Applied server growth for a single server. Returns the percentage growth
|
//Applied server growth for a single server. Returns the percentage growth
|
||||||
function processSingleServerGrowth(server, numCycles) {
|
function processSingleServerGrowth(server, numCycles) {
|
||||||
//Server growth processed once every 450 game cycles
|
//Server growth processed once every 450 game cycles
|
||||||
var numServerGrowthCycles = Math.max(Math.floor(numCycles / 450), 0);
|
const numServerGrowthCycles = Math.max(Math.floor(numCycles / 450), 0);
|
||||||
|
|
||||||
//Get adjusted growth rate, which accounts for server security
|
//Get adjusted growth rate, which accounts for server security
|
||||||
var growthRate = CONSTANTS.ServerBaseGrowthRate;
|
const growthRate = CONSTANTS.ServerBaseGrowthRate;
|
||||||
var adjGrowthRate = 1 + (growthRate - 1) / server.hackDifficulty;
|
var adjGrowthRate = 1 + (growthRate - 1) / server.hackDifficulty;
|
||||||
if (adjGrowthRate > CONSTANTS.ServerMaxGrowthRate) {adjGrowthRate = CONSTANTS.ServerMaxGrowthRate;}
|
if (adjGrowthRate > CONSTANTS.ServerMaxGrowthRate) {adjGrowthRate = CONSTANTS.ServerMaxGrowthRate;}
|
||||||
|
|
||||||
//Calculate adjusted server growth rate based on parameters
|
//Calculate adjusted server growth rate based on parameters
|
||||||
var serverGrowthPercentage = server.serverGrowth / 100;
|
const serverGrowthPercentage = server.serverGrowth / 100;
|
||||||
var numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage * BitNodeMultipliers.ServerGrowthRate;
|
const numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage * BitNodeMultipliers.ServerGrowthRate;
|
||||||
|
|
||||||
//Apply serverGrowth for the calculated number of growth cycles
|
//Apply serverGrowth for the calculated number of growth cycles
|
||||||
var serverGrowth = Math.pow(adjGrowthRate, numServerGrowthCyclesAdjusted * Player.hacking_grow_mult);
|
var serverGrowth = Math.pow(adjGrowthRate, numServerGrowthCyclesAdjusted * Player.hacking_grow_mult);
|
||||||
@ -789,19 +801,26 @@ function processSingleServerGrowth(server, numCycles) {
|
|||||||
serverGrowth = 1;
|
serverGrowth = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldMoneyAvailable = server.moneyAvailable;
|
const oldMoneyAvailable = server.moneyAvailable;
|
||||||
server.moneyAvailable *= serverGrowth;
|
server.moneyAvailable *= serverGrowth;
|
||||||
|
|
||||||
|
// in case of data corruption
|
||||||
if (server.moneyMax && isNaN(server.moneyAvailable)) {
|
if (server.moneyMax && isNaN(server.moneyAvailable)) {
|
||||||
server.moneyAvailable = server.moneyMax;
|
server.moneyAvailable = server.moneyMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cap at max
|
||||||
if (server.moneyMax && server.moneyAvailable > server.moneyMax) {
|
if (server.moneyMax && server.moneyAvailable > server.moneyMax) {
|
||||||
server.moneyAvailable = server.moneyMax;
|
server.moneyAvailable = server.moneyMax;
|
||||||
return server.moneyAvailable / oldMoneyAvailable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Growing increases server security twice as much as hacking
|
// if there was any growth at all, increase security
|
||||||
server.fortify(2 * CONSTANTS.ServerFortifyAmount * numServerGrowthCycles);
|
if(oldMoneyAvailable !== server.moneyAvailable) {
|
||||||
return serverGrowth;
|
//Growing increases server security twice as much as hacking
|
||||||
|
const usedCycles = numCycleForGrowth(server, server.moneyAvailable / oldMoneyAvailable);
|
||||||
|
server.fortify(2 * CONSTANTS.ServerFortifyAmount * Math.ceil(usedCycles));
|
||||||
|
}
|
||||||
|
return server.moneyAvailable / oldMoneyAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prestigeHomeComputer(homeComp) {
|
function prestigeHomeComputer(homeComp) {
|
||||||
|
Loading…
Reference in New Issue
Block a user