From 75ed86a32345ae0783d4b0dc62ff4b36e4689e89 Mon Sep 17 00:00:00 2001 From: gen BTC Date: Thu, 29 Mar 2018 02:14:18 -0400 Subject: [PATCH] safer number checks --- modules/breedtimer.js | 2 +- modules/jobs.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/breedtimer.js b/modules/breedtimer.js index 25ebb0dc8..740500fdd 100644 --- a/modules/breedtimer.js +++ b/modules/breedtimer.js @@ -136,7 +136,7 @@ function autoBreedTimer() { var numgens = Math.ceil(Math.log10(targetBreed / timeOK) / Math.log10(1.02)); //debug("2a. Time: " + getBreedTime(true) + " / " + getBreedTime(),"breed"); //debug("2b. " + numgens + " Genes.. / " + game.jobs.Geneticist.owned + " -> " + (game.jobs.Geneticist.owned+numgens),"breed"); - if (isNaN(numgens)) numgens = 0; + if (Number.isNaN(numgens)) numgens = 0; safeBuyJob('Geneticist', numgens); //debug("This many Geneticists were FIRED: " + numgens + ". Jobs Now: " + game.jobs.Geneticist.owned, "breed"); //debug("2c. Time: " + getBreedTime(true) + " / " + getBreedTime(),"breed" ); diff --git a/modules/jobs.js b/modules/jobs.js index 46b4c4f57..73cee637a 100644 --- a/modules/jobs.js +++ b/modules/jobs.js @@ -13,8 +13,8 @@ MODULES["jobs"].autoRatio1 = [1,1,1]; MODULES["jobs"].customRatio; //set this like above and it will Auto use it. function safeBuyJob(jobTitle, amount) { - if (!Number.isFinite(amount) || amount === 0 || typeof amount === 'undefined') { - //debug("Exiting out of buyjob early " + jobTitle + " " + amount); + if (!Number.isFinite(amount) || amount === 0 || typeof amount === 'undefined' || Number.isNaN(amount)) { + //debug("Exiting out of buyjob early " + jobTitle + " " + amount,"jobs"); return false; } var old = preBuy2(); @@ -54,7 +54,7 @@ function safeFireJob(job,amount) { var x = 1; if (amount != null) x = amount; - if (!Number.isSafeInteger(oldjob)){ + if (!Number.isFinite(oldjob)){ while (oldjob == test) { test-=x; x*=2; @@ -205,9 +205,10 @@ function buyJobs() { var toBuy = Math.floor((jobratio / totalRatio) * totalDistributableWorkers) - game.jobs[job].owned - subtract; var canBuy = Math.floor(game.resources.trimps.owned - game.resources.trimps.employed); var amount = toBuy <= canBuy ? toBuy : canBuy; - safeBuyJob(job, amount); -/* if (amount > 0) - debug("Jobbing: " + job + " " + amount); */ + if (amount != 0) { + safeBuyJob(job, amount); + //debug("Ratio Buying Job: " + job + " " + amount + " " + jobratio, "jobs"); + } return true; } else