Skip to content

Commit bd2b59e

Browse files
committed
Added timer to Grimoire spells (Issue #136) with the help from @hoten pull request (Issue #138) and fixed a very minor tooltip bug
1 parent 04549b5 commit bd2b59e

File tree

3 files changed

+412
-160
lines changed

3 files changed

+412
-160
lines changed

CookieMonster.js

+206-80
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ CM.Disp.FormatTime = function(time, format) {
605605
return str;
606606
}
607607

608-
CM.Disp.GetTimeColor = function(price, bank, cps) {
608+
CM.Disp.GetTimeColor = function(price, bank, cps, time) {
609609
var color;
610610
var text;
611611
if (bank >= price) {
@@ -618,7 +618,12 @@ CM.Disp.GetTimeColor = function(price, bank, cps) {
618618
}
619619
}
620620
else {
621-
var time = (price - bank) / cps;
621+
if (typeof time !== 'undefined') {
622+
var time = time;
623+
}
624+
else {
625+
var time = (price - bank) / cps;
626+
}
622627
text = CM.Disp.FormatTime(time);
623628
if (time > 300) {
624629
color = CM.Disp.colorRed;
@@ -2064,6 +2069,15 @@ CM.Disp.ToggleToolWarnCautPos = function() {
20642069
}
20652070
}
20662071

2072+
CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) {
2073+
var count = 0;
2074+
while (currentMagic < targetMagic) {
2075+
currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002;
2076+
count++;
2077+
}
2078+
return count / Game.fps;
2079+
}
2080+
20672081
CM.Disp.AddTooltipBuild = function() {
20682082
CM.Disp.TooltipBuildBack = [];
20692083
for (var i in Game.Objects) {
@@ -2086,6 +2100,18 @@ CM.Disp.AddTooltipUpgrade = function() {
20862100
}
20872101
}
20882102

2103+
CM.Disp.AddTooltipGrimoire = function() {
2104+
if (Game.Objects['Wizard tower'].minigameLoaded) {
2105+
CM.Disp.TooltipGrimoireBack = [];
2106+
for (var i in Game.Objects['Wizard tower'].minigame.spellsById) {
2107+
if (l('grimoireSpell' + i).onmouseover != null) {
2108+
CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover;
2109+
eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}');
2110+
}
2111+
}
2112+
}
2113+
}
2114+
20892115
CM.Disp.Tooltip = function(type, name) {
20902116
if (type == 'b') {
20912117
l('tooltip').innerHTML = Game.Objects[name].tooltip();
@@ -2120,16 +2146,19 @@ CM.Disp.Tooltip = function(type, name) {
21202146
}
21212147
}
21222148
}
2123-
else { // Upgrades
2149+
else if (type == 'u') {
21242150
if (!Game.UpgradesInStore[name]) return '';
21252151
l('tooltip').innerHTML = Game.crate(Game.UpgradesInStore[name], 'store', undefined, undefined, 1)();
21262152
}
2153+
else { // Grimoire
2154+
l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)();
2155+
}
21272156

21282157
var area = document.createElement('div');
21292158
area.id = 'CMTooltipArea';
21302159
l('tooltip').appendChild(area);
21312160

2132-
if (CM.Config.Tooltip == 1 && (type != 'b' || Game.buyMode == 1)) {
2161+
if (CM.Config.Tooltip == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) {
21332162
l('tooltip').firstChild.style.paddingBottom = '4px';
21342163
var tooltip = document.createElement('div');
21352164
tooltip.style.border = '1px solid';
@@ -2144,6 +2173,7 @@ CM.Disp.Tooltip = function(type, name) {
21442173
div.textContent = text;
21452174
return div;
21462175
}
2176+
21472177
tooltip.appendChild(header('Bonus Income'));
21482178
var income = document.createElement('div');
21492179
income.style.marginBottom = '4px';
@@ -2160,7 +2190,7 @@ CM.Disp.Tooltip = function(type, name) {
21602190
time.id = 'CMTooltipTime';
21612191
tooltip.appendChild(time);
21622192

2163-
l('tooltip').appendChild(tooltip);
2193+
area.appendChild(tooltip);
21642194
}
21652195

21662196
CM.Disp.tooltipType = type;
@@ -2174,92 +2204,141 @@ CM.Disp.Tooltip = function(type, name) {
21742204
CM.Disp.UpdateTooltip = function() {
21752205
if (l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) {
21762206

2177-
// Error checking
2178-
if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) {
2179-
return;
2180-
}
2181-
var price;
2182-
var bonus;
2183-
if (CM.Disp.tooltipType == 'b') {
2184-
var target = '';
2185-
if (Game.buyMode == 1 && Game.buyBulk == 10) {
2186-
target = 'Objects10';
2187-
price = CM.Cache[target][CM.Disp.tooltipName].price;
2188-
}
2189-
else if (Game.buyMode == 1 && Game.buyBulk == 100) {
2190-
target = 'Objects100';
2191-
price = CM.Cache[target][CM.Disp.tooltipName].price;
2207+
if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') {
2208+
// Error checking
2209+
if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) {
2210+
return;
21922211
}
2193-
else {
2194-
target = 'Objects';
2195-
price = Game.Objects[CM.Disp.tooltipName].getPrice();
2196-
}
2197-
bonus = CM.Cache[target][CM.Disp.tooltipName].bonus;
2198-
if (CM.Config.Tooltip == 1 && Game.buyMode == 1) {
2199-
l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
2200-
l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2);
2201-
l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
2202-
}
2203-
}
2204-
else { // Upgrades
2205-
bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus;
2206-
price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice();
2207-
if (CM.Config.Tooltip == 1) {
2208-
l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
2209-
l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2);
2210-
l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
2212+
var price;
2213+
var bonus;
2214+
if (CM.Disp.tooltipType == 'b') {
2215+
var target = '';
2216+
if (Game.buyMode == 1 && Game.buyBulk == 10) {
2217+
target = 'Objects10';
2218+
price = CM.Cache[target][CM.Disp.tooltipName].price;
2219+
}
2220+
else if (Game.buyMode == 1 && Game.buyBulk == 100) {
2221+
target = 'Objects100';
2222+
price = CM.Cache[target][CM.Disp.tooltipName].price;
2223+
}
2224+
else {
2225+
target = 'Objects';
2226+
price = Game.Objects[CM.Disp.tooltipName].getPrice();
2227+
}
2228+
bonus = CM.Cache[target][CM.Disp.tooltipName].bonus;
2229+
if (CM.Config.Tooltip == 1 && Game.buyMode == 1) {
2230+
l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
2231+
l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2);
2232+
l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
2233+
}
22112234
}
2212-
}
2213-
if (CM.Config.Tooltip == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
2214-
l('CMTooltipIncome').textContent = Beautify(bonus, 2);
2215-
2216-
var increase = Math.round(bonus / Game.cookiesPs * 10000);
2217-
if (isFinite(increase) && increase != 0) {
2218-
l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
2235+
else { // Upgrades
2236+
bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus;
2237+
price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice();
2238+
if (CM.Config.Tooltip == 1) {
2239+
l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
2240+
l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2);
2241+
l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
2242+
}
22192243
}
2244+
if (CM.Config.Tooltip == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
2245+
l('CMTooltipIncome').textContent = Beautify(bonus, 2);
2246+
2247+
var increase = Math.round(bonus / Game.cookiesPs * 10000);
2248+
if (isFinite(increase) && increase != 0) {
2249+
l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
2250+
}
22202251

2221-
var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS());
2222-
l('CMTooltipTime').textContent = timeColor.text;
2223-
l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
2224-
}
2225-
2226-
if (CM.Config.ToolWarnCaut == 1) {
2227-
var warn = CM.Cache.Lucky;
2228-
if (CM.Config.ToolWarnCautBon == 1) {
2229-
var bonusNoFren = bonus;
2230-
bonusNoFren /= CM.Sim.getCPSBuffMult();
2231-
warn += ((bonusNoFren * 60 * 15) / 0.15);
2252+
var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS());
2253+
l('CMTooltipTime').textContent = timeColor.text;
2254+
l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
22322255
}
2233-
var caut = warn * 7;
2234-
var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
2235-
if ((amount < warn || amount < caut) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
2236-
if (CM.Config.ToolWarnCautPos == 0) {
2237-
CM.Disp.TooltipWarnCaut.style.right = '0px';
2238-
}
2239-
else {
2240-
CM.Disp.TooltipWarnCaut.style.top = (l('tooltip').offsetHeight) + 'px';
2241-
}
2242-
CM.Disp.TooltipWarnCaut.style.width = (l('tooltip').offsetWidth - 6) + 'px';
2243-
2244-
if (amount < warn) {
2245-
l('CMDispTooltipWarn').style.display = '';
2246-
l('CMDispTooltipWarnText').textContent = Beautify(warn - amount) + ' (' + CM.Disp.FormatTime((warn - amount) / CM.Disp.GetCPS()) + ')';
2247-
l('CMDispTooltipCaut').style.display = '';
2248-
l('CMDispTooltipCautText').textContent = Beautify(caut - amount) + ' (' + CM.Disp.FormatTime((caut - amount) / CM.Disp.GetCPS()) + ')';
2256+
2257+
if (CM.Config.ToolWarnCaut == 1) {
2258+
var warn = CM.Cache.Lucky;
2259+
if (CM.Config.ToolWarnCautBon == 1) {
2260+
var bonusNoFren = bonus;
2261+
bonusNoFren /= CM.Sim.getCPSBuffMult();
2262+
warn += ((bonusNoFren * 60 * 15) / 0.15);
22492263
}
2250-
else if (amount < caut) {
2251-
l('CMDispTooltipCaut').style.display = '';
2252-
l('CMDispTooltipCautText').textContent = Beautify(caut - amount) + ' (' + CM.Disp.FormatTime((caut - amount) / CM.Disp.GetCPS()) + ')';
2253-
l('CMDispTooltipWarn').style.display = 'none';
2264+
var caut = warn * 7;
2265+
var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
2266+
if ((amount < warn || amount < caut) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
2267+
if (CM.Config.ToolWarnCautPos == 0) {
2268+
CM.Disp.TooltipWarnCaut.style.right = '0px';
2269+
}
2270+
else {
2271+
CM.Disp.TooltipWarnCaut.style.top = (l('tooltip').offsetHeight) + 'px';
2272+
}
2273+
CM.Disp.TooltipWarnCaut.style.width = (l('tooltip').offsetWidth - 6) + 'px';
2274+
2275+
if (amount < warn) {
2276+
l('CMDispTooltipWarn').style.display = '';
2277+
l('CMDispTooltipWarnText').textContent = Beautify(warn - amount) + ' (' + CM.Disp.FormatTime((warn - amount) / CM.Disp.GetCPS()) + ')';
2278+
l('CMDispTooltipCaut').style.display = '';
2279+
l('CMDispTooltipCautText').textContent = Beautify(caut - amount) + ' (' + CM.Disp.FormatTime((caut - amount) / CM.Disp.GetCPS()) + ')';
2280+
}
2281+
else if (amount < caut) {
2282+
l('CMDispTooltipCaut').style.display = '';
2283+
l('CMDispTooltipCautText').textContent = Beautify(caut - amount) + ' (' + CM.Disp.FormatTime((caut - amount) / CM.Disp.GetCPS()) + ')';
2284+
l('CMDispTooltipWarn').style.display = 'none';
2285+
}
2286+
else {
2287+
l('CMDispTooltipWarn').style.display = 'none';
2288+
l('CMDispTooltipCaut').style.display = 'none';
2289+
}
22542290
}
22552291
else {
22562292
l('CMDispTooltipWarn').style.display = 'none';
22572293
l('CMDispTooltipCaut').style.display = 'none';
22582294
}
22592295
}
2260-
else {
2261-
l('CMDispTooltipWarn').style.display = 'none';
2262-
l('CMDispTooltipCaut').style.display = 'none';
2296+
}
2297+
else { // Grimoire
2298+
l('CMDispTooltipWarn').style.display = 'none';
2299+
l('CMDispTooltipCaut').style.display = 'none';
2300+
2301+
var minigame = Game.Objects['Wizard tower'].minigame;
2302+
var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]);
2303+
2304+
if (CM.Config.Tooltip == 1 && spellCost <= minigame.magicM) {
2305+
l('CMTooltipArea').innerHTML = '';
2306+
2307+
l('tooltip').firstChild.style.paddingBottom = '4px';
2308+
var tooltip = document.createElement('div');
2309+
tooltip.style.border = '1px solid';
2310+
tooltip.style.padding = '4px';
2311+
tooltip.style.margin = '0px -4px';
2312+
tooltip.id = 'CMTooltipBorder';
2313+
tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray;
2314+
2315+
var header = function(text) {
2316+
var div = document.createElement('div');
2317+
div.style.fontWeight = 'bold';
2318+
div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
2319+
div.textContent = text;
2320+
return div;
2321+
}
2322+
2323+
tooltip.appendChild(header('Time Left'));
2324+
var time = document.createElement('div');
2325+
time.id = 'CMTooltipTime';
2326+
tooltip.appendChild(time);
2327+
var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost));
2328+
time.textContent = timeColor.text;
2329+
time.className = CM.Disp.colorTextPre + timeColor.color;
2330+
2331+
if (spellCost <= minigame.magic) {
2332+
tooltip.appendChild(header('Recover Time'));
2333+
var recover = document.createElement('div');
2334+
recover.id = 'CMTooltipRecover';
2335+
tooltip.appendChild(recover);
2336+
var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic));
2337+
recover.textContent = recoverColor.text;
2338+
recover.className = CM.Disp.colorTextPre + recoverColor.color;
2339+
}
2340+
2341+
l('CMTooltipArea').appendChild(tooltip);
22632342
}
22642343
}
22652344
}
@@ -2460,7 +2539,15 @@ CM.ReplaceNative = function() {
24602539
CM.Backup.UpdateSpecial();
24612540
}
24622541
}
2463-
2542+
2543+
// Probably better to load per minigame
2544+
CM.Backup.scriptLoaded = Game.scriptLoaded;
2545+
Game.scriptLoaded = function(who, script) {
2546+
CM.Backup.scriptLoaded(who, script);
2547+
CM.Disp.AddTooltipGrimoire()
2548+
CM.ReplaceNativeGrimoire();
2549+
}
2550+
24642551
CM.Backup.RebuildUpgrades = Game.RebuildUpgrades;
24652552
Game.RebuildUpgrades = function() {
24662553
CM.Backup.RebuildUpgrades();
@@ -2498,6 +2585,40 @@ CM.ReplaceNative = function() {
24982585
}
24992586
}
25002587

2588+
CM.ReplaceNativeGrimoire = function() {
2589+
CM.ReplaceNativeGrimoireLaunch();
2590+
CM.ReplaceNativeGrimoireDraw();
2591+
}
2592+
2593+
CM.ReplaceNativeGrimoireLaunch = function() {
2594+
if (!CM.HasReplaceNativeGrimoireLaunch && Game.Objects['Wizard tower'].minigameLoaded) {
2595+
var minigame = Game.Objects['Wizard tower'].minigame;
2596+
CM.Backup.GrimoireLaunch = minigame.launch;
2597+
eval('CM.Backup.GrimoireLaunchMod = ' + minigame.launch.toString().split('=this').join('= Game.Objects[\'Wizard tower\'].minigame'));
2598+
Game.Objects['Wizard tower'].minigame.launch = function() {
2599+
CM.Backup.GrimoireLaunchMod();
2600+
CM.Disp.AddTooltipGrimoire();
2601+
CM.HasReplaceNativeGrimoireDraw = false;
2602+
CM.ReplaceNativeGrimoireDraw();
2603+
}
2604+
CM.HasReplaceNativeGrimoireLaunch = true;
2605+
}
2606+
}
2607+
2608+
CM.ReplaceNativeGrimoireDraw = function() {
2609+
if (!CM.HasReplaceNativeGrimoireDraw && Game.Objects['Wizard tower'].minigameLoaded) {
2610+
var minigame = Game.Objects['Wizard tower'].minigame;
2611+
CM.Backup.GrimoireDraw = minigame.draw;
2612+
Game.Objects['Wizard tower'].minigame.draw = function() {
2613+
CM.Backup.GrimoireDraw();
2614+
if (minigame.magic < minigame.magicM) {
2615+
minigame.magicBarTextL.innerHTML += ' (' + CM.Disp.FormatTime(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, minigame.magicM)) + ')';
2616+
}
2617+
}
2618+
CM.HasReplaceNativeGrimoireDraw = true;
2619+
}
2620+
}
2621+
25012622
CM.Loop = function() {
25022623
if (CM.Disp.lastAscendState != Game.OnAscend) {
25032624
CM.Disp.lastAscendState = Game.OnAscend;
@@ -2604,9 +2725,11 @@ CM.DelayInit = function() {
26042725
CM.Disp.CreateTooltip('ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamind slot, selling all buildings with Earth Shatterer aura, and then buying Chocolate egg', '360px');
26052726
CM.Disp.CreateTooltipWarnCaut();
26062727
CM.Disp.AddTooltipBuild();
2728+
CM.Disp.AddTooltipGrimoire();
26072729
CM.Disp.AddWrinklerAreaDetect();
26082730
CM.Cache.InitCookiesDiff();
26092731
CM.ReplaceNative();
2732+
CM.ReplaceNativeGrimoire();
26102733
Game.CalculateGains();
26112734
CM.LoadConfig(); // Must be after all things are created!
26122735
CM.Disp.lastAscendState = Game.OnAscend;
@@ -2619,6 +2742,9 @@ CM.DelayInit = function() {
26192742
Game.Win('Third-party');
26202743
}
26212744

2745+
CM.HasReplaceNativeGrimoireLaunch = false;
2746+
CM.HasReplaceNativeGrimoireDraw = false;
2747+
26222748
CM.ConfigDefault = {BotBar: 1, TimerBar: 1, TimerBarPos: 0, BuildColor: 1, BulkBuildColor: 0, UpBarColor: 1, CalcWrink: 0, CPSMode: 1, AvgCPSHist: 0, AvgClicksHist: 0, ToolWarnCautBon: 0, Flash: 1, Sound: 1, Volume: 100, GCSoundURL: 'http://freesound.org/data/previews/66/66717_931655-lq.mp3', SeaSoundURL: 'http://www.freesound.org/data/previews/121/121099_2193266-lq.mp3', GCTimer: 1, Title: 1, Favicon: 1, Tooltip: 1, TooltipAmor: 0, ToolWarnCaut: 1, ToolWarnCautPos: 1, ToolWrink: 1, Stats: 1, UpStats: 1, TimeFormat: 0, SayTime: 1, Scale: 2, StatsPref: {Lucky: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}};
26232749
CM.ConfigPrefix = 'CMConfig';
26242750

0 commit comments

Comments
 (0)