Fixed bug where hacking special servers w/ no money would result in NaN because of a '0 / 0' in fortify() calculation

This commit is contained in:
danielyxie 2018-07-25 15:58:36 -05:00
parent a27ecca7bf
commit 47134a9640
3 changed files with 9 additions and 2 deletions

File diff suppressed because one or more lines are too long

@ -498,6 +498,7 @@ let CONSTANTS = {
"* Added getCurrentAction() to Bladeburner API<br>" + "* Added getCurrentAction() to Bladeburner API<br>" +
"* Added a variety of functions to Bladeburner API that deal with action levels (change by hydroflame)<br>" + "* Added a variety of functions to Bladeburner API that deal with action levels (change by hydroflame)<br>" +
"* Added getPurchasedServerLimit() and getPurchasedServerMaxRam() functions to Netscript (change by hydroflame & kopelli)<br>" + "* Added getPurchasedServerLimit() and getPurchasedServerMaxRam() functions to Netscript (change by hydroflame & kopelli)<br>" +
"* Added getOwnedSourceFiles() Singularity function (by hydroflame)<br>" +
"* Completely re-designed the Hacknet Node API<br>" + "* Completely re-designed the Hacknet Node API<br>" +
"* getSkillLevel() in Bladeburner API now returns an error if no argument is passed in (as opposed to an object with all skill levels). This may break scripts<br>" + "* getSkillLevel() in Bladeburner API now returns an error if no argument is passed in (as opposed to an object with all skill levels). This may break scripts<br>" +
"* Minimum Netscript execution time reduced from 15ms to 10ms (configurable in Options)<br>" + "* Minimum Netscript execution time reduced from 15ms to 10ms (configurable in Options)<br>" +
@ -505,6 +506,8 @@ let CONSTANTS = {
"* Source-File 6 now increases both the level and experience gain of all combat stats (it was only experience gain previously)<br>" + "* Source-File 6 now increases both the level and experience gain of all combat stats (it was only experience gain previously)<br>" +
"* Reverted a previous change for Source-File 12. It's benefits are now multiplicative rather than additive<br>" + "* Reverted a previous change for Source-File 12. It's benefits are now multiplicative rather than additive<br>" +
"* Starting Infiltration security level for almost every location decreased by ~10%<br>" + "* Starting Infiltration security level for almost every location decreased by ~10%<br>" +
"* Changed 'fl1ght.exe' message when its listed conditions are fulfilled (by hydroflame)<br>" +
"* The 'Save Game' button in the top-right overview panel now flashes red if autosave is disabled<br>" +
"* Bug Fix: Infiltration buttons can no longer be clicked through NetscriptJS<br>" + "* Bug Fix: Infiltration buttons can no longer be clicked through NetscriptJS<br>" +
"* Bug Fix: Bladeburner 'Overclock' skill can no longer be leveled above max level through the API (by hydroflame)" "* Bug Fix: Bladeburner 'Overclock' skill can no longer be leveled above max level through the API (by hydroflame)"
} }

@ -298,7 +298,11 @@ function NetscriptFunctions(workerScript) {
var expGainedOnFailure = (expGainedOnSuccess / 4); var expGainedOnFailure = (expGainedOnSuccess / 4);
if (rand < hackChance) { //Success! if (rand < hackChance) { //Success!
const percentHacked = scriptCalculatePercentMoneyHacked(server); const percentHacked = scriptCalculatePercentMoneyHacked(server);
const maxThreadNeeded = Math.ceil(1/percentHacked*(server.moneyAvailable/server.moneyMax)) let maxThreadNeeded = Math.ceil(1/percentHacked*(server.moneyAvailable/server.moneyMax));
if (isNaN(maxThreadNeeded)) {
maxThreadNeeded = 1e6; //Server has a 'max money' of 0 (probably)
}
let moneyGained = Math.floor(server.moneyAvailable * percentHacked) * threads; let moneyGained = Math.floor(server.moneyAvailable * percentHacked) * threads;
//Over-the-top safety checks //Over-the-top safety checks