Fix building price displayed in sell mode (source code is incorrect) #359
Fix building price displayed in sell mode
This commit is contained in:
@@ -1424,7 +1424,17 @@ CM.Disp.UpdateBuildings = function() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (var i in CM.Cache.Objects) {
|
for (var i in CM.Cache.Objects) {
|
||||||
l('productPrice' + Game.Objects[i].id).style.color = '';
|
var o = Game.Objects[i];
|
||||||
|
l('productPrice' + o.id).style.color = '';
|
||||||
|
/*
|
||||||
|
* Fix sell price displayed in the object in the store.
|
||||||
|
*
|
||||||
|
* 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('productPrice' + o.id).innerHTML = Beautify(CM.Sim.BuildingSell(o, o.basePrice, o.amount, o.free, Game.buyBulk, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2827,12 +2837,15 @@ CM.Disp.Tooltip = function(type, name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Game.buyMode == -1) {
|
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)));
|
* Fix sell price displayed in the object tooltip.
|
||||||
}
|
*
|
||||||
else {
|
* The buildings sell price displayed by the game itself (without any mod) is incorrect.
|
||||||
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)));
|
* 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') {
|
else if (type == 'u') {
|
||||||
@@ -3639,7 +3652,7 @@ CM.Sim.BuildingGetPrice = function(build, basePrice, start, free, increase) {
|
|||||||
return moni;
|
return moni;
|
||||||
}
|
}
|
||||||
|
|
||||||
CM.Sim.BuildingSell = function(build, basePrice, start, free, amount) {
|
CM.Sim.BuildingSell = function(build, basePrice, start, free, amount, noSim) {
|
||||||
/*var price=0;
|
/*var price=0;
|
||||||
for (var i = Math.max(0, start - amount); i < Math.max(0, start); i++) {
|
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));
|
price += basePrice * Math.pow(Game.priceIncrease, Math.max(0, i - free));
|
||||||
@@ -3658,12 +3671,16 @@ CM.Sim.BuildingSell = function(build, basePrice, start, free, amount) {
|
|||||||
return Math.ceil(price);*/
|
return Math.ceil(price);*/
|
||||||
|
|
||||||
// Calculate money gains from selling buildings
|
// 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;
|
var moni = 0;
|
||||||
|
if (amount == -1) amount = start;
|
||||||
|
if (!amount) amount = Game.buyBulk;
|
||||||
for (var i = 0; i < amount; i++) {
|
for (var i = 0; i < amount; i++) {
|
||||||
var price = basePrice * Math.pow(Game.priceIncrease, Math.max(0, start - free));
|
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);
|
price = Math.ceil(price);
|
||||||
var giveBack = CM.Sim.getSellMultiplier();
|
var giveBack = noSim ? build.getSellMultiplier() : CM.Sim.getSellMultiplier();
|
||||||
price = Math.floor(price * giveBack);
|
price = Math.floor(price * giveBack);
|
||||||
if (start > 0) {
|
if (start > 0) {
|
||||||
moni += price;
|
moni += price;
|
||||||
|
|||||||
27
src/Disp.js
27
src/Disp.js
@@ -676,7 +676,17 @@ CM.Disp.UpdateBuildings = function() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (var i in CM.Cache.Objects) {
|
for (var i in CM.Cache.Objects) {
|
||||||
l('productPrice' + Game.Objects[i].id).style.color = '';
|
var o = Game.Objects[i];
|
||||||
|
l('productPrice' + o.id).style.color = '';
|
||||||
|
/*
|
||||||
|
* Fix sell price displayed in the object in the store.
|
||||||
|
*
|
||||||
|
* 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('productPrice' + o.id).innerHTML = Beautify(CM.Sim.BuildingSell(o, o.basePrice, o.amount, o.free, Game.buyBulk, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2079,12 +2089,15 @@ CM.Disp.Tooltip = function(type, name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Game.buyMode == -1) {
|
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)));
|
* Fix sell price displayed in the object tooltip.
|
||||||
}
|
*
|
||||||
else {
|
* The buildings sell price displayed by the game itself (without any mod) is incorrect.
|
||||||
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)));
|
* 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') {
|
else if (type == 'u') {
|
||||||
|
|||||||
10
src/Sim.js
10
src/Sim.js
@@ -25,7 +25,7 @@ CM.Sim.BuildingGetPrice = function(build, basePrice, start, free, increase) {
|
|||||||
return moni;
|
return moni;
|
||||||
}
|
}
|
||||||
|
|
||||||
CM.Sim.BuildingSell = function(build, basePrice, start, free, amount) {
|
CM.Sim.BuildingSell = function(build, basePrice, start, free, amount, noSim) {
|
||||||
/*var price=0;
|
/*var price=0;
|
||||||
for (var i = Math.max(0, start - amount); i < Math.max(0, start); i++) {
|
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));
|
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);*/
|
return Math.ceil(price);*/
|
||||||
|
|
||||||
// Calculate money gains from selling buildings
|
// 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;
|
var moni = 0;
|
||||||
|
if (amount == -1) amount = start;
|
||||||
|
if (!amount) amount = Game.buyBulk;
|
||||||
for (var i = 0; i < amount; i++) {
|
for (var i = 0; i < amount; i++) {
|
||||||
var price = basePrice * Math.pow(Game.priceIncrease, Math.max(0, start - free));
|
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);
|
price = Math.ceil(price);
|
||||||
var giveBack = CM.Sim.getSellMultiplier();
|
var giveBack = noSim ? build.getSellMultiplier() : CM.Sim.getSellMultiplier();
|
||||||
price = Math.floor(price * giveBack);
|
price = Math.floor(price * giveBack);
|
||||||
if (start > 0) {
|
if (start > 0) {
|
||||||
moni += price;
|
moni += price;
|
||||||
|
|||||||
Reference in New Issue
Block a user