From 62dae6560637f9b6644f4b2bbaa4e8d44521acd6 Mon Sep 17 00:00:00 2001 From: Aktanusa Date: Sat, 21 Jul 2018 08:30:52 -0400 Subject: [PATCH] Fix calculation error due to timing being off by a little bit (happens more often on slower computers) (Issue #200) --- CookieMonster.js | 12 ++++++------ src/Main.js | 4 ++-- src/Sim.js | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 59cd761..e4d7d43 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2565,10 +2565,10 @@ CM.ReplaceNative = function() { Beautify = CM.Disp.Beautify; CM.Backup.CalculateGains = Game.CalculateGains; + eval('CM.Backup.CalculateGainsMod = ' + Game.CalculateGains.toString().split('ages\');').join('ages\');CM.Sim.DateAges = Date.now();').split('var day').join('CM.Sim.DateCentury = Date.now();var day')); Game.CalculateGains = function() { - CM.Backup.CalculateGains(); + CM.Backup.CalculateGainsMod(); CM.Sim.DoSims = 1; - CM.Sim.Date = Date.now(); } CM.Backup.tooltip = {}; @@ -3008,9 +3008,9 @@ CM.Sim.CalculateGains = function() { else if (godLvl == 3) mult *= 1.05; var godLvl = Game.hasGod('ages'); - if (godLvl == 1) mult *= 1 + 0.15 * Math.sin((CM.Sim.Date / 1000 / (60 * 60 * 3)) * Math.PI * 2); - else if (godLvl == 2) mult *= 1 + 0.15 * Math.sin((CM.Sim.Date / 1000 / (60 * 60 * 12)) * Math.PI*2); - else if (godLvl == 3) mult *= 1 + 0.15 * Math.sin((CM.Sim.Date / 1000 / (60 * 60 * 24)) * Math.PI*2); + if (godLvl == 1) mult *= 1 + 0.15 * Math.sin((CM.Sim.DateAges / 1000 / (60 * 60 * 3)) * Math.PI * 2); + else if (godLvl == 2) mult *= 1 + 0.15 * Math.sin((CM.Sim.DateAges / 1000 / (60 * 60 * 12)) * Math.PI*2); + else if (godLvl == 3) mult *= 1 + 0.15 * Math.sin((CM.Sim.DateAges / 1000 / (60 * 60 * 24)) * Math.PI*2); var godLvl = Game.hasGod('decadence'); if (godLvl == 1) buildMult *= 0.93; @@ -3079,7 +3079,7 @@ CM.Sim.CalculateGains = function() { if (CM.Sim.Has('Ant larva')) eggMult *= 1.01; if (CM.Sim.Has('Century egg')) { // The boost increases a little every day, with diminishing returns up to +10% on the 100th day - var day = Math.floor((CM.Sim.Date - Game.startDate) / 1000 / 10) * 10 / 60 / 60 / 24; + var day = Math.floor((CM.Sim.DateCentury - Game.startDate) / 1000 / 10) * 10 / 60 / 60 / 24; day = Math.min(day, 100); CM.Cache.CentEgg = 1 + (1 - Math.pow(1 - day / 100, 3)) * 0.1; eggMult *= CM.Cache.CentEgg; diff --git a/src/Main.js b/src/Main.js index fb6793c..341f3a1 100644 --- a/src/Main.js +++ b/src/Main.js @@ -7,10 +7,10 @@ CM.ReplaceNative = function() { Beautify = CM.Disp.Beautify; CM.Backup.CalculateGains = Game.CalculateGains; + eval('CM.Backup.CalculateGainsMod = ' + Game.CalculateGains.toString().split('ages\');').join('ages\');CM.Sim.DateAges = Date.now();').split('var day').join('CM.Sim.DateCentury = Date.now();var day')); Game.CalculateGains = function() { - CM.Backup.CalculateGains(); + CM.Backup.CalculateGainsMod(); CM.Sim.DoSims = 1; - CM.Sim.Date = Date.now(); } CM.Backup.tooltip = {}; diff --git a/src/Sim.js b/src/Sim.js index 0da872e..4655f32 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -195,9 +195,9 @@ CM.Sim.CalculateGains = function() { else if (godLvl == 3) mult *= 1.05; var godLvl = Game.hasGod('ages'); - if (godLvl == 1) mult *= 1 + 0.15 * Math.sin((CM.Sim.Date / 1000 / (60 * 60 * 3)) * Math.PI * 2); - else if (godLvl == 2) mult *= 1 + 0.15 * Math.sin((CM.Sim.Date / 1000 / (60 * 60 * 12)) * Math.PI*2); - else if (godLvl == 3) mult *= 1 + 0.15 * Math.sin((CM.Sim.Date / 1000 / (60 * 60 * 24)) * Math.PI*2); + if (godLvl == 1) mult *= 1 + 0.15 * Math.sin((CM.Sim.DateAges / 1000 / (60 * 60 * 3)) * Math.PI * 2); + else if (godLvl == 2) mult *= 1 + 0.15 * Math.sin((CM.Sim.DateAges / 1000 / (60 * 60 * 12)) * Math.PI*2); + else if (godLvl == 3) mult *= 1 + 0.15 * Math.sin((CM.Sim.DateAges / 1000 / (60 * 60 * 24)) * Math.PI*2); var godLvl = Game.hasGod('decadence'); if (godLvl == 1) buildMult *= 0.93; @@ -266,7 +266,7 @@ CM.Sim.CalculateGains = function() { if (CM.Sim.Has('Ant larva')) eggMult *= 1.01; if (CM.Sim.Has('Century egg')) { // The boost increases a little every day, with diminishing returns up to +10% on the 100th day - var day = Math.floor((CM.Sim.Date - Game.startDate) / 1000 / 10) * 10 / 60 / 60 / 24; + var day = Math.floor((CM.Sim.DateCentury - Game.startDate) / 1000 / 10) * 10 / 60 / 60 / 24; day = Math.min(day, 100); CM.Cache.CentEgg = 1 + (1 - Math.pow(1 - day / 100, 3)) * 0.1; eggMult *= CM.Cache.CentEgg;