Merge pull request #622 from DanielNoord/hotfixes

Hotfixes
This commit is contained in:
Daniël van Noord
2021-02-26 00:13:22 +01:00
committed by GitHub
5 changed files with 59 additions and 20 deletions

File diff suppressed because one or more lines are too long

View File

@@ -684,7 +684,7 @@ CM.Cache.CacheBuildingsPP = function () {
if (typeof CM.Options.PPExcludeTop === 'undefined') CM.Options.PPExcludeTop = 0; // Otherwise breaks during initialization
// Calculate PP and colors when compared to purchase of optimal building in single-purchase mode
if (CM.Options.ColorPPBulkMode === 0) {
if (CM.Options.ColorPPBulkMode === 0 && Game.buyMode > 0) {
for (const i of Object.keys(CM.Cache.Objects1)) {
if (Game.cookiesPs) {
CM.Cache.Objects1[i].pp = (Math.max(Game.Objects[i].getPrice() - (Game.cookies + CM.Disp.GetWrinkConfigBank()), 0) / Game.cookiesPs) + (Game.Objects[i].getPrice() / CM.Cache.Objects1[i].bonus);
@@ -714,7 +714,7 @@ CM.Cache.CacheBuildingsPP = function () {
// Calculate PP of bulk-buy modes
CM.Cache.CacheBuildingsBulkPP('Objects10');
CM.Cache.CacheBuildingsBulkPP('Objects100');
} else {
} else if (Game.buyMode > 0) {
// Calculate PP and colors when compared to purchase of selected bulk mode
const target = `Objects${Game.buyBulk}`;
for (const i of Object.keys(CM.Cache[target])) {

View File

@@ -374,10 +374,15 @@ CM.Disp.CreateBotBar = function () {
* It is called by CM.Disp.Draw()
*/
CM.Disp.UpdateBotBar = function () {
if (CM.Options.BotBar === 1 && CM.Cache.Objects1) {
if (CM.Options.BotBar === 1 && CM.Cache.Objects1 && Game.buyMode === 1) {
let count = 0;
for (const i of Object.keys(CM.Cache.Objects1)) {
const target = `Objects${Game.buyBulk}`;
let target = `Objects${Game.buyBulk}`;
if (Game.buyMode === 1) {
CM.Disp.LastTargetBotBar = target;
} else {
target = CM.Disp.LastTargetBotBar;
}
count++;
CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount;
CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2);
@@ -670,7 +675,12 @@ CM.Disp.UpdateBotTimerBarPosition = function () {
* And by changes in CM.Options.BuildColor, CM.Options.SortBuild & CM.Data.Config.BulkBuildColor
*/
CM.Disp.UpdateBuildings = function () {
const target = `Objects${Game.buyBulk}`;
let target = `Objects${Game.buyBulk}`;
if (Game.buyMode === 1) {
CM.Disp.LastTargetBuildings = target;
} else {
target = CM.Disp.LastTargetBuildings;
}
if (Game.buyMode === 1) {
if (CM.Options.BuildColor === 1) {
for (const i of Object.keys(CM.Cache[target])) {
@@ -1388,7 +1398,12 @@ CM.Disp.UpdateTooltipBuilding = function () {
const tooltipBox = l('CMTooltipBorder');
CM.Disp.TooltipCreateCalculationSection(tooltipBox);
const target = `Objects${Game.buyBulk}`;
let target = `Objects${Game.buyBulk}`;
if (Game.buyMode === 1) {
CM.Disp.LastTargetTooltipBuilding = target;
} else {
target = CM.Disp.LastTargetTooltipBuilding;
}
CM.Disp.TooltipPrice = Game.Objects[CM.Disp.tooltipName].bulkPrice;
CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus;
@@ -1443,7 +1458,7 @@ CM.Disp.UpdateTooltipUpgrade = function () {
l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2);
const increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000);
// Don't display certain parts of tooltip if not applicable
if (l('CMTooltipIncome').textContent === '0') {
if (l('CMTooltipIncome').textContent === '0' && (CM.Disp.tooltipType === 'b' || CM.Disp.tooltipType === 'u')) {
l('Bonus IncomeTitle').style.display = 'none';
l('CMTooltipIncome').style.display = 'none';
l('Payback PeriodTitle').style.display = 'none';
@@ -1540,10 +1555,10 @@ CM.Disp.UpdateTooltipGrimoire = function () {
}
// Extra information on cookies gained when spell is Conjure Baked Goods (Name === 0)
if (CM.Disp.tooltipName === 0) {
if (CM.Disp.tooltipName === '0') {
tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Cookies to be gained/lost'));
const conjure = document.createElement('div');
conjure.id = 'CMTooltipConjure';
conjure.id = 'x';
tooltipBox.appendChild(conjure);
const reward = document.createElement('span');
reward.style.color = '#33FF00';
@@ -2182,7 +2197,7 @@ CM.Disp.AddMenuStats = function (title) {
const popFattestA = document.createElement('a');
popFattestA.textContent = 'Pop Single Fattest';
popFattestA.className = 'option';
popFattestA.onclick = function () { if (CM.Cache.WrinklersFattest[1]) Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; };
popFattestA.onclick = function () { if (CM.Cache.WrinklersFattest[1] !== null) Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; };
popFattestFrag.appendChild(popFattestA);
stats.appendChild(CM.Disp.CreateStatsListing('basic', `Rewards of Popping Single Fattest Non-Shiny Wrinkler (id: ${CM.Cache.WrinklersFattest[1] !== null ? CM.Cache.WrinklersFattest[1] : 'None'})`, popFattestFrag));
}
@@ -2857,7 +2872,7 @@ CM.Disp.CreateWrinklerButtons = function () {
popFattestA.id = 'PopFattestWrinklerButton';
popFattestA.textContent = 'Pop Single Fattest';
popFattestA.className = 'option';
popFattestA.onclick = function () { if (CM.Cache.WrinklersFattest[1]) Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; };
popFattestA.onclick = function () { if (CM.Cache.WrinklersFattest[1] !== null) Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; };
l('sectionLeftExtra').children[0].append(popFattestA);
};
@@ -2954,3 +2969,10 @@ CM.Disp.TooltipWrinkler = -1;
* Used to store the number of cookies to be displayed in the tab-title
*/
CM.Disp.Title = '';
/**
* These are variables used to create various displays when the game is loaded on the "sell all" screen
*/
CM.Disp.LastTargetBotBar = 1;
CM.Disp.LastTargetBuildings = 1;
CM.Disp.LastTargetTooltipBuilding = 1;

View File

@@ -43,6 +43,7 @@ CM.save = function () {
*/
CM.load = function (str) {
const save = JSON.parse(str);
CM.Sim.InitData();
CM.Config.LoadConfig(save.settings);
if (save.version !== `${CM.VersionMajor}.${CM.VersionMinor}`) {
if (Game.prefs.popups) Game.Popup('A new version of Cookie Monster has been loaded, check out the release notes in the info tab!');

View File

@@ -129,10 +129,6 @@ CM.Sim.ReplaceFunction = function (funcToBeReplaced) {
.join('CM.Sim.auraMult')
.split('Game.hasGod')
.join('CM.Sim.hasGod')
.split('M.gods[what]') // Replaces code in the Pantheon minigame
.join('CM.Sim.Objects.Temple.minigame.gods[what]')
.split('M.slot[i]') // Replaces code in the Pantheon minigame
.join('CM.Sim.Objects.Temple.minigame.slot[i]')
.split('Game.effs') // Replaces code in the Pantheon minigame
.join('CM.Sim.effs')
.split('Game.Objects')
@@ -158,7 +154,6 @@ CM.Sim.CreateSimFunctions = function () {
CM.Sim.Has = new Function(`return ${CM.Sim.ReplaceFunction(Game.Has)}`)();
CM.Sim.HasAchiev = new Function(`return ${CM.Sim.ReplaceFunction(Game.HasAchiev)}`)();
CM.Sim.hasAura = new Function(`return ${CM.Sim.ReplaceFunction(Game.hasAura)}`)();
if (Game.hasGod) CM.Sim.hasGod = new Function(`return ${CM.Sim.ReplaceFunction(Game.hasGod)}`)();
CM.Sim.GetHeavenlyMultiplier = new Function(`return ${CM.Sim.ReplaceFunction(Game.GetHeavenlyMultiplier)}`)();
CM.Sim.auraMult = new Function(`return ${CM.Sim.ReplaceFunction(Game.auraMult)}`)();
CM.Sim.eff = new Function(`return ${CM.Sim.ReplaceFunction(Game.eff)}`)();
@@ -180,6 +175,24 @@ CM.Sim.Win = function (what) {
}
};
/**
* This function checks for the current God level in the sim data
* It functions similarly to Game.hasGod()
* It is not created by CM.Sim.CreateSimFunctions() as Game.hasGod() is not always available in each save
* @param {string} what Name of the achievement
*/
CM.Sim.hasGod = function (what) {
if (Game.hasGod) {
const god = CM.Sim.Objects.Temple.minigame.gods[what];
for (let i = 0; i < 3; i++) {
if (CM.Sim.Objects.Temple.minigame.slot[i] === god.id) {
return (i + 1);
}
}
}
return false;
};
/**
* Section: Functions used to create static objects of Buildings, Upgrades and Achievements */
@@ -296,7 +309,10 @@ CM.Sim.CopyData = function () {
you.totalCookies = me.totalCookies;
you.basePrice = me.basePrice;
you.free = me.free;
if (me.minigameLoaded) you.minigameLoaded = me.minigameLoaded; you.minigame = me.minigame;
if (me.minigameLoaded) {
you.minigameLoaded = me.minigameLoaded;
you.minigame = me.minigame;
}
}
// Upgrades
@@ -825,8 +841,8 @@ CM.Sim.CalculateChangeAura = function (aura) {
// Sell highest building but only if aura is different
let price = 0;
if (CM.Sim.dragonAura !== CM.Cache.dragonAura || CM.Sim.dragonAura2 !== CM.Cache.dragonAura2) {
for (let i = Game.ObjectsById.length; i > -1; --i) {
if (Game.ObjectsById[i].amount > 0) {
for (let i = Game.ObjectsById.length - 1; i > -1; --i) {
if (Game.ObjectsById[i - 1].amount > 0) {
const highestBuilding = CM.Sim.Objects[Game.ObjectsById[i].name].name;
CM.Sim.Objects[highestBuilding].amount -= 1;
CM.Sim.buildingsOwned -= 1;