var M={}; M.parent=Game.Objects['Wizard tower']; M.parent.minigame=M; M.launch=function() { var M=this; M.name=M.parent.minigameName; M.init=function(div) { //populate div with html and initialize values M.spells={ 'conjure baked goods':{ name:loc("Conjure Baked Goods"), desc:loc("Summon half an hour worth of your CpS, capped at %1% of your cookies owned.",15), failDesc:loc("Trigger a %1-minute clot and lose %1 minutes of CpS.",15), icon:[21,11], costMin:2, costPercent:0.4, win:function() { var val=Math.max(7,Math.min(Game.cookies*0.15,Game.cookiesPs*60*30)); Game.Earn(val); Game.Notify(loc("Conjure Baked Goods")+(EN?'!':''),loc("You magic %1 out of thin air.",loc("%1 cookie",LBeautify(val))),[21,11],6); Game.Popup('
'+loc("+%1!",loc("%1 cookie",LBeautify(val)))+'
',Game.mouseX,Game.mouseY); }, fail:function() { var buff=Game.gainBuff('clot',60*15,0.5); var val=Math.min(Game.cookies*0.15,Game.cookiesPs*60*15)+13; val=Math.min(Game.cookies,val); Game.Spend(val); Game.Notify(buff.name,buff.desc,buff.icon,6); Game.Popup('
'+loc("Backfire!")+'
'+loc("Summoning failed!")+' '+loc("Lost %1!",loc("%1 cookie",LBeautify(val)))+'
',Game.mouseX,Game.mouseY); }, }, 'hand of fate':{ name:loc("Force the Hand of Fate"), desc:loc("Summon a random golden cookie. Each existing golden cookie makes this spell +%1% more likely to backfire.",15), failDesc:loc("Summon an unlucky wrath cookie."), icon:[22,11], costMin:10, costPercent:0.6, failFunc:function(fail) { return fail+0.15*Game.shimmerTypes['golden'].n; }, win:function() { var newShimmer=new Game.shimmer('golden',{noWrath:true}); var choices=[]; choices.push('frenzy','multiply cookies'); if (!Game.hasBuff('Dragonflight')) choices.push('click frenzy'); if (Math.random()<0.1) choices.push('cookie storm','cookie storm','blab'); if (Game.BuildingsOwned>=10 && Math.random()<0.25) choices.push('building special'); //if (Math.random()<0.2) choices.push('clot','cursed finger','ruin cookies'); if (Math.random()<0.15) choices=['cookie storm drop']; if (Math.random()<0.0001) choices.push('free sugar lump'); newShimmer.force=choose(choices); if (newShimmer.force=='cookie storm drop') { newShimmer.sizeMult=Math.random()*0.75+0.25; } Game.Popup('
'+loc("Promising fate!")+'
',Game.mouseX,Game.mouseY); }, fail:function() { var newShimmer=new Game.shimmer('golden',{wrath:true}); var choices=[]; choices.push('clot','ruin cookies'); if (Math.random()<0.1) choices.push('cursed finger','blood frenzy'); if (Math.random()<0.003) choices.push('free sugar lump'); if (Math.random()<0.1) choices=['blab']; newShimmer.force=choose(choices); Game.Popup('
'+loc("Backfire!")+'
'+loc("Sinister fate!")+'
',Game.mouseX,Game.mouseY); }, }, 'stretch time':{ name:loc("Stretch Time"), desc:loc("All active buffs gain %1% more time (up to %2 more minutes).",[10,5]), failDesc:loc("All active buffs are shortened by %1% (up to %2 minutes shorter).",[20,10]), icon:[23,11], costMin:8, costPercent:0.2, win:function() { var changed=0; for (var i in Game.buffs) { var me=Game.buffs[i]; var gain=Math.min(Game.fps*60*5,me.maxTime*0.1); me.maxTime+=gain; me.time+=gain; changed++; } if (changed==0){Game.Popup('
'+loc("No buffs to alter!")+'
',Game.mouseX,Game.mouseY);return -1;} Game.Popup('
'+loc("Zap! Buffs lengthened.")+'
',Game.mouseX,Game.mouseY); }, fail:function() { var changed=0; for (var i in Game.buffs) { var me=Game.buffs[i]; var loss=Math.min(Game.fps*60*10,me.time*0.2); me.time-=loss; me.time=Math.max(me.time,0); changed++; } if (changed==0){Game.Popup('
'+loc("No buffs to alter!")+'
',Game.mouseX,Game.mouseY);return -1;} Game.Popup('
'+loc("Backfire!")+'
'+loc("Fizz! Buffs shortened.")+'
',Game.mouseX,Game.mouseY); }, }, 'spontaneous edifice':{ name:loc("Spontaneous Edifice"), desc:loc("The spell picks a random building you could afford if you had twice your current cookies, and gives it to you for free. The building selected must be under %1, and cannot be your most-built one (unless it is your only one).",400), failDesc:loc("Lose a random building."), icon:[24,11], costMin:20, costPercent:0.75, win:function() { var buildings=[]; var max=0; var n=0; for (var i in Game.Objects) { if (Game.Objects[i].amount>max) max=Game.Objects[i].amount; if (Game.Objects[i].amount>0) n++; } for (var i in Game.Objects) {if ((Game.Objects[i].amount'+loc("No buildings to improve!")+'',Game.mouseX,Game.mouseY);return -1;} var building=choose(buildings); building.buyFree(1); Game.Popup('
'+loc("A new %1
bursts out of the ground.",building.single)+'
',Game.mouseX,Game.mouseY); }, fail:function() { if (Game.BuildingsOwned==0){Game.Popup('
'+loc("Backfired, but no buildings to destroy!")+'
',Game.mouseX,Game.mouseY);return -1;} var buildings=[]; for (var i in Game.Objects) {if (Game.Objects[i].amount>0) buildings.push(Game.Objects[i]);} var building=choose(buildings); building.sacrifice(1); Game.Popup('
'+loc("Backfire!")+'
'+loc("One of your %1
disappears in a puff of smoke.",building.plural)+'
',Game.mouseX,Game.mouseY); }, }, 'haggler\'s charm':{ name:loc("Haggler's Charm"), desc:loc("Upgrades are %1% cheaper for 1 minute.",2), failDesc:loc("Upgrades are %1% more expensive for an hour.",2)+(EN?'What\'s that spell? Loadsamoney!':''), icon:[25,11], costMin:10, costPercent:0.1, win:function() { Game.killBuff('Haggler\'s misery'); var buff=Game.gainBuff('haggler luck',60,2); Game.Popup('
'+loc("Upgrades are cheaper!")+'
',Game.mouseX,Game.mouseY); }, fail:function() { Game.killBuff('Haggler\'s luck'); var buff=Game.gainBuff('haggler misery',60*60,2); Game.Popup('
'+loc("Backfire!")+'
'+loc("Upgrades are pricier!")+'
',Game.mouseX,Game.mouseY); }, }, 'summon crafty pixies':{ name:loc("Summon Crafty Pixies"), desc:loc("Buildings are %1% cheaper for 1 minute.",2), failDesc:loc("Buildings are %1% more expensive for an hour.",2), icon:[26,11], costMin:10, costPercent:0.2, win:function() { Game.killBuff('Nasty goblins'); var buff=Game.gainBuff('pixie luck',60,2); Game.Popup('
'+loc("Crafty pixies")+'
'+loc("Buildings are cheaper!")+'
',Game.mouseX,Game.mouseY); }, fail:function() { Game.killBuff('Crafty pixies'); var buff=Game.gainBuff('pixie misery',60*60,2); Game.Popup('
'+loc("Backfire!")+'
'+loc("Nasty goblins")+'
'+loc("Buildings are pricier!")+'
',Game.mouseX,Game.mouseY); }, }, 'gambler\'s fever dream':{ name:loc("Gambler's Fever Dream"), desc:loc("Cast a random spell at half the magic cost, with twice the chance of backfiring."), icon:[27,11], costMin:3, costPercent:0.05, win:function() { var spells=[]; var selfCost=M.getSpellCost(M.spells['gambler\'s fever dream']); for (var i in M.spells) {if (i!='gambler\'s fever dream' && (M.magic-selfCost)>=M.getSpellCost(M.spells[i])*0.5) spells.push(M.spells[i]);} if (spells.length==0){Game.Popup('
'+loc("No eligible spells!")+'
',Game.mouseX,Game.mouseY);return -1;} var spell=choose(spells); var cost=M.getSpellCost(spell)*0.5; setTimeout(function(spell,cost,seed){return function(){ if (Game.seed!=seed) return false; var out=M.castSpell(spell,{cost:cost,failChanceMax:0.5,passthrough:true}); if (!out) { M.magic+=selfCost; setTimeout(function(){ Game.Popup('
'+loc("That's too bad!
Magic refunded.")+'
',Game.mouseX,Game.mouseY); },1500); } }}(spell,cost,Game.seed),1000); Game.Popup('
'+loc("Casting %1
for %2 magic...",[spell.name,Beautify(cost)])+'
',Game.mouseX,Game.mouseY); }, }, 'resurrect abomination':{ name:loc("Resurrect Abomination"), desc:loc("Instantly summon a wrinkler if conditions are fulfilled."), failDesc:loc("Pop one of your wrinklers."), icon:[28,11], costMin:20, costPercent:0.1, win:function() { var out=Game.SpawnWrinkler(); if (!out){Game.Popup('
'+loc("Unable to spawn a wrinkler!")+'
',Game.mouseX,Game.mouseY);return -1;} Game.Popup('
'+loc("Rise, my precious!")+'
',Game.mouseX,Game.mouseY); }, fail:function() { var out=Game.PopRandomWrinkler(); if (!out){Game.Popup('
'+loc("Backfire!")+'
'+loc("But no wrinkler was harmed.")+'
',Game.mouseX,Game.mouseY);return -1;} Game.Popup('
'+loc("Backfire!")+'
'+loc("So long, ugly...")+'
',Game.mouseX,Game.mouseY); }, }, 'diminish ineptitude':{ name:loc("Diminish Ineptitude"), desc:loc("Spells backfire %1 times less for the next %2 minutes.",[10,5]), failDesc:loc("Spells backfire %1 times more for the next %2 minutes.",[5,10]), icon:[29,11], costMin:5, costPercent:0.2, win:function() { Game.killBuff('Magic inept'); var buff=Game.gainBuff('magic adept',5*60,10); Game.Popup('
'+loc("Ineptitude diminished!")+'
',Game.mouseX,Game.mouseY); }, fail:function() { Game.killBuff('Magic adept'); var buff=Game.gainBuff('magic inept',10*60,5); Game.Popup('
'+loc("Backfire!")+'
'+loc("Ineptitude magnified!")+'
',Game.mouseX,Game.mouseY); }, }, }; M.spellsById=[];var n=0; for (var i in M.spells){M.spells[i].id=n;M.spellsById[n]=M.spells[i];n++;} M.computeMagicM=function() { var towers=Math.max(M.parent.amount,1); var lvl=Math.max(M.parent.level,1); M.magicM=Math.floor(4+Math.pow(towers,0.6)+Math.log((towers+(lvl-1)*10)/15+1)*15); //old formula : /* M.magicM=8+Math.min(M.parent.amount,M.parent.level*5)+Math.ceil(M.parent.amount/10); if (M.magicM>200) { //diminishing returns starting at 200, being 5% as fast by 400 var x=M.magicM; var top=x-200; top/=200; var top2=top; top*=(1-top/2); if (top2>=1) top=0.5; top=top*0.95+top2*0.05; top*=200; x=top+200; M.magicM=x; } */ M.magic=Math.min(M.magicM,M.magic); } M.getFailChance=function(spell) { var failChance=0.15; if (Game.hasBuff('Magic adept')) failChance*=0.1; if (Game.hasBuff('Magic inept')) failChance*=5; failChance*=1+0.1*Game.auraMult('Supreme Intellect'); if (spell.failFunc) failChance=spell.failFunc(failChance); return failChance; } M.castSpell=function(spell,obj) { var obj=obj||{}; var out=0; var cost=0; var fail=false; if (typeof obj.cost!=='undefined') cost=obj.cost; else cost=M.getSpellCost(spell); if (M.magic=9) Game.Win('Bibbidi-bobbidi-boo'); if (M.spellsCastTotal>=99) Game.Win('I\'m the wiz'); if (M.spellsCastTotal>=999) Game.Win('A wizard is you'); } M.magic-=cost; M.magic=Math.max(0,M.magic); var rect=l('grimoireSpell'+spell.id).getBounds(); Game.SparkleAt((rect.left+rect.right)/2,(rect.top+rect.bottom)/2-24); if (fail) PlaySound('snd/spellFail.mp3',0.75); else PlaySound('snd/spell.mp3',0.75); return true; } PlaySound('snd/spellFail.mp3',0.75); return false; } M.getSpellCost=function(spell) { var out=spell.costMin; if (spell.costPercent) out+=M.magicM*spell.costPercent; out*=1-0.1*Game.auraMult('Supreme Intellect'); return Math.floor(out); } M.getSpellCostBreakdown=function(spell) { var str=''; if (spell.costPercent) str+=loc("%1 magic",Beautify(spell.costMin))+' '+loc("+%1% of max magic",Beautify(Math.ceil(spell.costPercent*100))); else str+=loc("%1 magic",Beautify(spell.costMin)); return str; } M.spellTooltip=function(id) { return function(){ var me=M.spellsById[id]; me.icon=me.icon||[28,12]; var cost=Beautify(M.getSpellCost(me)); var costBreakdown=M.getSpellCostBreakdown(me); if (cost!=costBreakdown) costBreakdown=' ('+costBreakdown+')'; else costBreakdown=''; var backfire=M.getFailChance(me); var str='
'+ '
'+ '
'+me.name+'
'+ '
'+loc("Magic cost:")+' '+cost+''+costBreakdown+'
'+ (me.fail?('
'+loc("Chance to backfire:")+' '+Math.ceil(100*backfire)+'%
'):'')+ '
'+loc("Effect:")+' '+(me.descFunc?me.descFunc():me.desc)+''+(me.failDesc?('
'+loc("Backfire:")+' '+me.failDesc+''):'')+'
'; return str; }; } M.dragonBoostTooltip=function() { return '
'+loc("Supreme Intellect")+'
'+loc("Grimoire spells are %1% cheaper but fail %1% more.",10*Game.auraMult('Supreme Intellect'))+'
'; } var str=''; str+=''; str+='
'; str+='
'; str+='
';//did you know adding class="shadowFilter" to this cancels the "z-index:1000000001" that displays the selected spell above the tooltip? stacking orders are silly https://philipwalton.com/articles/what-no-one-told-you-about-z-index/ for (var i in M.spells) { var me=M.spells[i]; var icon=me.icon||[28,12]; str+='
-
'; } str+='
'; var icon=[29,14]; str+='
'+loc("This is your magic meter. Each spell costs magic to use.
Your maximum amount of magic varies depending on your amount of Wizard towers, and their level.
Magic refills over time. The lower your magic meter, the slower it refills.")+'
')+' style="position:absolute;left:0px;top:0px;right:0px;bottom:0px;">
'; str+='
'; str+=''; div.innerHTML=str; M.magicBarL=l('grimoireBar'); M.magicBarFullL=l('grimoireBarFull'); M.magicBarTextL=l('grimoireBarText'); M.lumpRefill=l('grimoireLumpRefill'); M.infoL=l('grimoireInfo'); for (var i in M.spells) { var me=M.spells[i]; AddEvent(l('grimoireSpell'+me.id),'click',function(spell){return function(){PlaySound('snd/tick.mp3');M.castSpell(spell);}}(me)); } M.refillTooltip=function(){ return '
'+loc("Click to refill %1 units of your magic meter for %2.",[100,''+loc("%1 sugar lump",LBeautify(1))+''])+ (Game.canRefillLump()?'
('+loc("can be done once every %1",Game.sayTime(Game.getLumpRefillMax(),-1))+')':('
('+loc("usable again in %1",Game.sayTime(Game.getLumpRefillRemaining()+Game.fps,-1))+')'))+ '
'; }; AddEvent(M.lumpRefill,'click',function(){ if (M.magic