From d257830de81b06d856da8914745bdc7a55ef016e Mon Sep 17 00:00:00 2001 From: Chorizorro Date: Sun, 29 Nov 2020 11:54:20 +0100 Subject: [PATCH] Fix building tooltip in sell mode (#359) --- CookieMonster.js | 25 ++++++++++++++++--------- src/Disp.js | 15 +++++++++------ src/Sim.js | 10 +++++++--- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 3cfb74e..c945cf9 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2827,12 +2827,15 @@ CM.Disp.Tooltip = function(type, name) { } } else if (Game.buyMode == -1) { - if (Game.buyBulk == -1) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join('-' + Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.Objects[name].amount))); - } - else { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join('-' + Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk))); - } + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); } } else if (type == 'u') { @@ -3639,7 +3642,7 @@ CM.Sim.BuildingGetPrice = function(build, basePrice, start, free, increase) { return moni; } -CM.Sim.BuildingSell = function(build, basePrice, start, free, amount) { +CM.Sim.BuildingSell = function(build, basePrice, start, free, amount, noSim) { /*var price=0; for (var i = Math.max(0, start - amount); i < Math.max(0, start); i++) { price += basePrice * Math.pow(Game.priceIncrease, Math.max(0, i - free)); @@ -3658,12 +3661,16 @@ CM.Sim.BuildingSell = function(build, basePrice, start, free, amount) { return Math.ceil(price);*/ // Calculate money gains from selling buildings + // If noSim is set, use Game methods to compute price instead of Sim ones. + noSim = typeof noSim === "undefined" ? 0 : noSim; var moni = 0; + if (amount == -1) amount = start; + if (!amount) amount = Game.buyBulk; for (var i = 0; i < amount; i++) { var price = basePrice * Math.pow(Game.priceIncrease, Math.max(0, start - free)); - price = CM.Sim.modifyBuildingPrice(build, price); + price = noSim ? Game.modifyBuildingPrice(build, price) : CM.Sim.modifyBuildingPrice(build, price); price = Math.ceil(price); - var giveBack = CM.Sim.getSellMultiplier(); + var giveBack = noSim ? build.getSellMultiplier() : CM.Sim.getSellMultiplier(); price = Math.floor(price * giveBack); if (start > 0) { moni += price; diff --git a/src/Disp.js b/src/Disp.js index 6da56c6..be7b31b 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2079,12 +2079,15 @@ CM.Disp.Tooltip = function(type, name) { } } else if (Game.buyMode == -1) { - if (Game.buyBulk == -1) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join('-' + Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.Objects[name].amount))); - } - else { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join('-' + Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk))); - } + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); } } else if (type == 'u') { diff --git a/src/Sim.js b/src/Sim.js index 9ea54db..a8fba6f 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -25,7 +25,7 @@ CM.Sim.BuildingGetPrice = function(build, basePrice, start, free, increase) { return moni; } -CM.Sim.BuildingSell = function(build, basePrice, start, free, amount) { +CM.Sim.BuildingSell = function(build, basePrice, start, free, amount, noSim) { /*var price=0; for (var i = Math.max(0, start - amount); i < Math.max(0, start); i++) { price += basePrice * Math.pow(Game.priceIncrease, Math.max(0, i - free)); @@ -44,12 +44,16 @@ CM.Sim.BuildingSell = function(build, basePrice, start, free, amount) { return Math.ceil(price);*/ // Calculate money gains from selling buildings + // If noSim is set, use Game methods to compute price instead of Sim ones. + noSim = typeof noSim === "undefined" ? 0 : noSim; var moni = 0; + if (amount == -1) amount = start; + if (!amount) amount = Game.buyBulk; for (var i = 0; i < amount; i++) { var price = basePrice * Math.pow(Game.priceIncrease, Math.max(0, start - free)); - price = CM.Sim.modifyBuildingPrice(build, price); + price = noSim ? Game.modifyBuildingPrice(build, price) : CM.Sim.modifyBuildingPrice(build, price); price = Math.ceil(price); - var giveBack = CM.Sim.getSellMultiplier(); + var giveBack = noSim ? build.getSellMultiplier() : CM.Sim.getSellMultiplier(); price = Math.floor(price * giveBack); if (start > 0) { moni += price;