File size: 23,060 Bytes
8d62d97 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
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 <b>%1</b> out of thin air.",loc("%1 cookie",LBeautify(val))),[21,11],6);
Game.Popup('<div style="font-size:80%;">'+loc("+%1!",loc("%1 cookie",LBeautify(val)))+'</div>',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('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("Summoning failed!")+' '+loc("Lost %1!",loc("%1 cookie",LBeautify(val)))+'</div>',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('<div style="font-size:80%;">'+loc("Promising fate!")+'</div>',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('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("Sinister fate!")+'</div>',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('<div style="font-size:80%;">'+loc("No buffs to alter!")+'</div>',Game.mouseX,Game.mouseY);return -1;}
Game.Popup('<div style="font-size:80%;">'+loc("Zap! Buffs lengthened.")+'</div>',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('<div style="font-size:80%;">'+loc("No buffs to alter!")+'</div>',Game.mouseX,Game.mouseY);return -1;}
Game.Popup('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("Fizz! Buffs shortened.")+'</div>',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<max || n==1) && Game.Objects[i].getPrice()<=Game.cookies*2 && Game.Objects[i].amount<400) buildings.push(Game.Objects[i]);}
if (buildings.length==0){Game.Popup('<div style="font-size:80%;">'+loc("No buildings to improve!")+'</div>',Game.mouseX,Game.mouseY);return -1;}
var building=choose(buildings);
building.buyFree(1);
Game.Popup('<div style="font-size:80%;">'+loc("A new %1<br>bursts out of the ground.",building.single)+'</div>',Game.mouseX,Game.mouseY);
},
fail:function()
{
if (Game.BuildingsOwned==0){Game.Popup('<div style="font-size:80%;">'+loc("Backfired, but no buildings to destroy!")+'</div>',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('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("One of your %1<br>disappears in a puff of smoke.",building.plural)+'</div>',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?'<q>What\'s that spell? Loadsamoney!</q>':''),
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('<div style="font-size:80%;">'+loc("Upgrades are cheaper!")+'</div>',Game.mouseX,Game.mouseY);
},
fail:function()
{
Game.killBuff('Haggler\'s luck');
var buff=Game.gainBuff('haggler misery',60*60,2);
Game.Popup('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("Upgrades are pricier!")+'</div>',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('<div style="font-size:80%;">'+loc("Crafty pixies")+'<br>'+loc("Buildings are cheaper!")+'</div>',Game.mouseX,Game.mouseY);
},
fail:function()
{
Game.killBuff('Crafty pixies');
var buff=Game.gainBuff('pixie misery',60*60,2);
Game.Popup('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("Nasty goblins")+'<br>'+loc("Buildings are pricier!")+'</div>',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('<div style="font-size:80%;">'+loc("No eligible spells!")+'</div>',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('<div style="font-size:80%;">'+loc("That's too bad!<br>Magic refunded.")+'</div>',Game.mouseX,Game.mouseY);
},1500);
}
}}(spell,cost,Game.seed),1000);
Game.Popup('<div style="font-size:80%;">'+loc("Casting %1<br>for %2 magic...",[spell.name,Beautify(cost)])+'</div>',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('<div style="font-size:80%;">'+loc("Unable to spawn a wrinkler!")+'</div>',Game.mouseX,Game.mouseY);return -1;}
Game.Popup('<div style="font-size:80%;">'+loc("Rise, my precious!")+'</div>',Game.mouseX,Game.mouseY);
},
fail:function()
{
var out=Game.PopRandomWrinkler();
if (!out){Game.Popup('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("But no wrinkler was harmed.")+'</div>',Game.mouseX,Game.mouseY);return -1;}
Game.Popup('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("So long, ugly...")+'</div>',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('<div style="font-size:80%;">'+loc("Ineptitude diminished!")+'</div>',Game.mouseX,Game.mouseY);
},
fail:function()
{
Game.killBuff('Magic adept');
var buff=Game.gainBuff('magic inept',10*60,5);
Game.Popup('<div style="font-size:80%;">'+loc("Backfire!")+'<br>'+loc("Ineptitude magnified!")+'</div>',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<cost) return false;
var failChance=M.getFailChance(spell);
if (typeof obj.failChanceSet!=='undefined') failChance=obj.failChanceSet;
if (typeof obj.failChanceAdd!=='undefined') failChance+=obj.failChanceAdd;
if (typeof obj.failChanceMult!=='undefined') failChance*=obj.failChanceMult;
if (typeof obj.failChanceMax!=='undefined') failChance=Math.max(failChance,obj.failChanceMax);
Math.seedrandom(Game.seed+'/'+M.spellsCastTotal);
if (!spell.fail || Math.random()<(1-failChance)) {out=spell.win();} else {fail=true;out=spell.fail();}
Math.seedrandom();
if (out!=-1)
{
if (!spell.passthrough && !obj.passthrough)
{
M.spellsCast++;
M.spellsCastTotal++;
if (M.spellsCastTotal>=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=' <small>('+costBreakdown+')</small>'; else costBreakdown='';
var backfire=M.getFailChance(me);
var str='<div style="padding:8px 4px;min-width:350px;" id="tooltipSpell">'+
'<div class="icon" style="float:left;margin-left:-8px;margin-top:-8px;background-position:'+(-me.icon[0]*48)+'px '+(-me.icon[1]*48)+'px;"></div>'+
'<div class="name">'+me.name+'</div>'+
'<div>'+loc("Magic cost:")+' <b style="color:#'+(cost<=M.magic?'6f6':'f66')+';">'+cost+'</b>'+costBreakdown+'</div>'+
(me.fail?('<div><small>'+loc("Chance to backfire:")+' <b style="color:#f66">'+Math.ceil(100*backfire)+'%</b></small></div>'):'')+
'<div class="line"></div><div class="description"><b>'+loc("Effect:")+'</b> <span class="green">'+(me.descFunc?me.descFunc():me.desc)+'</span>'+(me.failDesc?('<div style="height:8px;"></div><b>'+loc("Backfire:")+'</b> <span class="red">'+me.failDesc+'</span>'):'')+'</div></div>';
return str;
};
}
M.dragonBoostTooltip=function()
{
return '<div style="width:280px;padding:8px;text-align:center;" id="tooltipDragonBoost"><b>'+loc("Supreme Intellect")+'</b><div class="line"></div>'+loc("Grimoire spells are %1% cheaper but fail %1% more.",10*Game.auraMult('Supreme Intellect'))+'</div>';
}
var str='';
str+='<style>'+
'#grimoireBG{background:url('+Game.resPath+'img/shadedBorders.png),url('+Game.resPath+'img/BGgrimoire.jpg);background-size:100% 100%,auto;position:absolute;left:0px;right:0px;top:0px;bottom:16px;}'+
'#grimoireContent{position:relative;box-sizing:border-box;padding:4px 24px;}'+
'#grimoireBar{max-width:95%;margin:4px auto;height:16px;}'+
'#grimoireBarFull{transform:scale(1,2);transform-origin:50% 0;height:50%;}'+
'#grimoireBarText{transform:scale(1,0.8);width:100%;position:absolute;left:0px;top:0px;text-align:center;color:#fff;text-shadow:-1px 1px #000,0px 0px 4px #000,0px 0px 6px #000;margin-top:2px;}'+
'#grimoireSpells{text-align:center;width:100%;padding:8px;box-sizing:border-box;}'+
'.grimoireIcon{pointer-events:none;margin:2px 6px 0px 6px;width:48px;height:48px;opacity:0.8;position:relative;}'+
'.grimoirePrice{pointer-events:none;}'+
'.grimoireSpell{box-shadow:4px 4px 4px #000;cursor:pointer;position:relative;color:#f33;opacity:0.8;text-shadow:0px 0px 4px #000,0px 0px 6px #000;font-weight:bold;font-size:12px;display:inline-block;width:60px;height:74px;background:url('+Game.resPath+'img/spellBG.png);}'+
'.grimoireSpell.ready{color:rgba(255,255,255,0.8);opacity:1;}'+
'.grimoireSpell.ready:hover{color:#fff;}'+
'.grimoireSpell:hover{box-shadow:6px 6px 6px 2px #000;z-index:1000000001;top:-1px;}'+
'.grimoireSpell:active{top:1px;}'+
'.grimoireSpell.ready .grimoireIcon{opacity:1;}'+
'.grimoireSpell:hover{background-position:0px -74px;} .grimoireSpell:active{background-position:0px 74px;}'+
'.grimoireSpell:nth-child(4n+1){background-position:-60px 0px;} .grimoireSpell:nth-child(4n+1):hover{background-position:-60px -74px;} .grimoireSpell:nth-child(4n+1):active{background-position:-60px 74px;}'+
'.grimoireSpell:nth-child(4n+2){background-position:-120px 0px;} .grimoireSpell:nth-child(4n+2):hover{background-position:-120px -74px;} .grimoireSpell:nth-child(4n+2):active{background-position:-120px 74px;}'+
'.grimoireSpell:nth-child(4n+3){background-position:-180px 0px;} .grimoireSpell:nth-child(4n+3):hover{background-position:-180px -74px;} .grimoireSpell:nth-child(4n+3):active{background-position:-180px 74px;}'+
'.grimoireSpell:hover .grimoireIcon{top:-1px;}'+
'.grimoireSpell.ready:hover .grimoireIcon{animation-name:bounce;animation-iteration-count:infinite;animation-duration:0.8s;}'+
'.noFancy .grimoireSpell.ready:hover .grimoireIcon{animation:none;}'+
'#grimoireInfo{text-align:center;font-size:11px;margin-top:12px;color:rgba(255,255,255,0.75);text-shadow:-1px 1px 0px #000;}'+
'</style>';
str+='<div id="grimoireBG"></div>';
str+='<div id="grimoireContent">';
str+='<div id="grimoireSpells">';//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+='<div class="grimoireSpell titleFont" id="grimoireSpell'+me.id+'" '+Game.getDynamicTooltip('Game.ObjectsById['+M.parent.id+'].minigame.spellTooltip('+me.id+')','this')+'><div class="usesIcon shadowFilter grimoireIcon" style="background-position:'+(-icon[0]*48)+'px '+(-icon[1]*48)+'px;"></div><div class="grimoirePrice" id="grimoirePrice'+me.id+'">-</div></div>';
}
str+='</div>';
var icon=[29,14];
str+='<div id="grimoireBar" class="smallFramed meterContainer" style="width:1px;"><div '+Game.getDynamicTooltip('Game.ObjectsById['+M.parent.id+'].minigame.refillTooltip','this')+' id="grimoireLumpRefill" class="usesIcon shadowFilter lumpRefill" style="left:-40px;top:-17px;background-position:'+(-icon[0]*48)+'px '+(-icon[1]*48)+'px;"></div><div id="grimoireBarFull" class="meter filling" style="width:1px;"></div><div id="grimoireBarText" class="titleFont"></div><div '+Game.getTooltip('<div style="padding:8px;width:300px;font-size:11px;text-align:center;">'+loc("This is your magic meter. Each spell costs magic to use.<div class=\"line\"></div>Your maximum amount of magic varies depending on your amount of <b>Wizard towers</b>, and their level.<div class=\"line\"></div>Magic refills over time. The lower your magic meter, the slower it refills.")+'</div>')+' style="position:absolute;left:0px;top:0px;right:0px;bottom:0px;"></div></div>';
str+='<div id="grimoireInfo"></div>';
str+='</div>';
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 '<div style="padding:8px;width:300px;font-size:11px;text-align:center;" id="tooltipRefill">'+loc("Click to refill <b>%1 units</b> of your magic meter for %2.",[100,'<span class="price lump">'+loc("%1 sugar lump",LBeautify(1))+'</span>'])+
(Game.canRefillLump()?'<br><small>('+loc("can be done once every %1",Game.sayTime(Game.getLumpRefillMax(),-1))+')</small>':('<br><small class="red">('+loc("usable again in %1",Game.sayTime(Game.getLumpRefillRemaining()+Game.fps,-1))+')</small>'))+
'</div>';
};
AddEvent(M.lumpRefill,'click',function(){
if (M.magic<M.magicM)
{Game.refillLump(1,function(){
M.magic+=100;
M.magic=Math.min(M.magic,M.magicM);
PlaySound('snd/pop'+Math.floor(Math.random()*3+1)+'.mp3',0.75);
});}
});
M.computeMagicM();
M.magic=M.magicM;
M.spellsCast=0;
M.spellsCastTotal=0;
//M.parent.switchMinigame(1);
}
M.save=function()
{
//output cannot use ",", ";" or "|"
var str=''+
parseFloat(M.magic)+' '+
parseInt(Math.floor(M.spellsCast))+' '+
parseInt(Math.floor(M.spellsCastTotal))+
' '+parseInt(M.parent.onMinigame?'1':'0')
;
return str;
}
M.load=function(str)
{
//interpret str; called after .init
//note : not actually called in the Game's load; see "minigameSave" in main.js
if (!str) return false;
var i=0;
var spl=str.split(' ');
M.computeMagicM();
M.magic=parseFloat(spl[i++]||M.magicM);
M.spellsCast=parseInt(spl[i++]||0);
M.spellsCastTotal=parseInt(spl[i++]||0);
var on=parseInt(spl[i++]||0);if (on && Game.ascensionMode!=1) M.parent.switchMinigame(1);
}
M.reset=function()
{
M.computeMagicM();
M.magic=M.magicM;
M.spellsCast=0;
}
M.logic=function()
{
//run each frame
if (Game.T%5==0) {M.computeMagicM();}
M.magicPS=Math.max(0.002,Math.pow(M.magic/Math.max(M.magicM,100),0.5))*0.002;
M.magic+=M.magicPS;
M.magic=Math.min(M.magic,M.magicM);
if (Game.T%5==0)
{
for (var i in M.spells)
{
var me=M.spells[i];
var cost=M.getSpellCost(me);
l('grimoirePrice'+me.id).innerHTML=Beautify(cost);
if (M.magic<cost) l('grimoireSpell'+me.id).className='grimoireSpell titleFont';
else l('grimoireSpell'+me.id).className='grimoireSpell titleFont ready';
}
}
}
M.draw=function()
{
//run each draw frame
if (Game.drawT%5==0)
{
M.magicBarTextL.innerHTML=Math.min(Math.floor(M.magicM),Beautify(M.magic))+'/'+Beautify(Math.floor(M.magicM))+(M.magic<M.magicM?(' ('+loc("+%1/s",Beautify((M.magicPS||0)*Game.fps,2))+')'):'');
M.magicBarFullL.style.width=((M.magic/M.magicM)*100)+'%';
M.magicBarL.style.width=(M.magicM*3)+'px';
M.infoL.innerHTML=loc("Spells cast: %1 (total: %2)",[Beautify(M.spellsCast),Beautify(M.spellsCastTotal)]);
}
M.magicBarFullL.style.backgroundPosition=(-Game.T*0.5)+'px';
}
M.init(l('rowSpecial'+M.parent.id));
}
var M=0; |