Merge pull request #323 from hydroflame/fix-negative-security-growth

cap difficulty and fix negative security growth
This commit is contained in:
danielyxie 2018-06-25 19:59:48 -05:00 committed by GitHub
commit 0343ba863b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -93,18 +93,23 @@ Server.prototype.getScript = function(scriptName) {
return null; return null;
} }
//Strengthens a server's security level (difficulty) by the specified amount Server.prototype.capDifficulty = function() {
Server.prototype.fortify = function(amt) { if (this.hackDifficulty < this.minDifficulty) {this.hackDifficulty = this.minDifficulty;}
this.hackDifficulty += amt; if (this.hackDifficulty < 1) {this.hackDifficulty = 1;}
//Place some arbitrarily limit that realistically should never happen unless someone is //Place some arbitrarily limit that realistically should never happen unless someone is
//screwing around with the game //screwing around with the game
if (this.hackDifficulty > 1000000) {this.hackDifficulty = 1000000;} if (this.hackDifficulty > 1000000) {this.hackDifficulty = 1000000;}
} }
//Strengthens a server's security level (difficulty) by the specified amount
Server.prototype.fortify = function(amt) {
this.hackDifficulty += amt;
this.capDifficulty();
}
Server.prototype.weaken = function(amt) { Server.prototype.weaken = function(amt) {
this.hackDifficulty -= (amt * BitNodeMultipliers.ServerWeakenRate); this.hackDifficulty -= (amt * BitNodeMultipliers.ServerWeakenRate);
if (this.hackDifficulty < this.minDifficulty) {this.hackDifficulty = this.minDifficulty;} this.capDifficulty();
if (this.hackDifficulty < 1) {this.hackDifficulty = 1;}
} }
//Functions for loading and saving a Server //Functions for loading and saving a Server
@ -817,7 +822,8 @@ function processSingleServerGrowth(server, numCycles) {
// if there was any growth at all, increase security // if there was any growth at all, increase security
if(oldMoneyAvailable !== server.moneyAvailable) { if(oldMoneyAvailable !== server.moneyAvailable) {
//Growing increases server security twice as much as hacking //Growing increases server security twice as much as hacking
const usedCycles = numCycleForGrowth(server, server.moneyAvailable / oldMoneyAvailable); let usedCycles = numCycleForGrowth(server, server.moneyAvailable / oldMoneyAvailable);
usedCycles = Math.max(0, usedCycles);
server.fortify(2 * CONSTANTS.ServerFortifyAmount * Math.ceil(usedCycles)); server.fortify(2 * CONSTANTS.ServerFortifyAmount * Math.ceil(usedCycles));
} }
return server.moneyAvailable / oldMoneyAvailable; return server.moneyAvailable / oldMoneyAvailable;