Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TheGameCenter
GitHub Repository: TheGameCenter/TheGameCenter.github.io
Path: blob/main/assets/javascript/cookieclicker/minigameGrimoire.js
15361 views
1
var M={};
2
M.parent=Game.Objects['Wizard tower'];
3
M.parent.minigame=M;
4
M.launch=function()
5
{
6
var M=this;
7
M.name=M.parent.minigameName;
8
M.init=function(div)
9
{
10
//populate div with html and initialize values
11
12
M.spells={
13
'conjure baked goods':{
14
name:'Conjure Baked Goods',
15
desc:'Summon half an hour worth of your CpS, capped at 15% of your cookies owned.',
16
failDesc:'Trigger a 15-minute clot and lose 15 minutes of CpS.',
17
icon:[21,11],
18
costMin:2,
19
costPercent:0.4,
20
win:function()
21
{
22
var val=Math.max(7,Math.min(Game.cookies*0.15,Game.cookiesPs*60*30));
23
Game.Earn(val);
24
Game.Notify('Conjure baked goods!','You magic <b>'+Beautify(val)+' cookie'+(val==1?'':'s')+'</b> out of thin air.',[21,11],6);
25
Game.Popup('<div style="font-size:80%;">+'+Beautify(val)+' cookie'+(val==1?'':'s')+'!</div>',Game.mouseX,Game.mouseY);
26
},
27
fail:function()
28
{
29
var buff=Game.gainBuff('clot',60*15,0.5);
30
var val=Math.min(Game.cookies*0.15,Game.cookiesPs*60*15)+13;
31
val=Math.min(Game.cookies,val);
32
Game.Spend(val);
33
Game.Notify(buff.name,buff.desc,buff.icon,6);
34
Game.Popup('<div style="font-size:80%;">Backfire!<br>Summoning failed! Lost '+Beautify(val)+' cookie'+(val==1?'':'s')+'!</div>',Game.mouseX,Game.mouseY);
35
},
36
},
37
'hand of fate':{
38
name:'Force the Hand of Fate',
39
desc:'Summon a random golden cookie. Each existing golden cookie makes this spell +15% more likely to backfire.',
40
failDesc:'Summon an unlucky wrath cookie.',
41
icon:[22,11],
42
costMin:10,
43
costPercent:0.6,
44
failFunc:function(fail)
45
{
46
return fail+0.15*Game.shimmerTypes['golden'].n;
47
},
48
win:function()
49
{
50
var newShimmer=new Game.shimmer('golden',{noWrath:true});
51
var choices=[];
52
choices.push('frenzy','multiply cookies');
53
if (!Game.hasBuff('Dragonflight')) choices.push('click frenzy');
54
if (Math.random()<0.1) choices.push('chain cookie','cookie storm','blab');
55
if (Game.BuildingsOwned>=10 && Math.random()<0.25) choices.push('building special');
56
//if (Math.random()<0.2) choices.push('clot','cursed finger','ruin cookies');
57
if (Math.random()<0.15) choices=['cookie storm drop'];
58
if (Math.random()<0.0001) choices.push('free sugar lump');
59
newShimmer.force=choose(choices);
60
if (newShimmer.force=='cookie storm drop')
61
{
62
newShimmer.sizeMult=Math.random()*0.75+0.25;
63
}
64
Game.Popup('<div style="font-size:80%;">Promising fate!</div>',Game.mouseX,Game.mouseY);
65
},
66
fail:function()
67
{
68
var newShimmer=new Game.shimmer('golden',{wrath:true});
69
var choices=[];
70
choices.push('clot','ruin cookies');
71
if (Math.random()<0.1) choices.push('cursed finger','blood frenzy');
72
if (Math.random()<0.003) choices.push('free sugar lump');
73
if (Math.random()<0.1) choices=['blab'];
74
newShimmer.force=choose(choices);
75
Game.Popup('<div style="font-size:80%;">Backfire!<br>Sinister fate!</div>',Game.mouseX,Game.mouseY);
76
},
77
},
78
'stretch time':{
79
name:'Stretch Time',
80
desc:'All active buffs gain 10% more time (up to 5 more minutes).',
81
failDesc:'All active buffs are shortened by 20% (up to 10 minutes shorter).',
82
icon:[23,11],
83
costMin:8,
84
costPercent:0.2,
85
win:function()
86
{
87
var changed=0;
88
for (var i in Game.buffs)
89
{
90
var me=Game.buffs[i];
91
var gain=Math.min(Game.fps*60*5,me.maxTime*0.1);
92
me.maxTime+=gain;
93
me.time+=gain;
94
changed++;
95
}
96
if (changed==0){Game.Popup('<div style="font-size:80%;">No buffs to alter!</div>',Game.mouseX,Game.mouseY);return -1;}
97
Game.Popup('<div style="font-size:80%;">Zap! Buffs lengthened.</div>',Game.mouseX,Game.mouseY);
98
},
99
fail:function()
100
{
101
var changed=0;
102
for (var i in Game.buffs)
103
{
104
var me=Game.buffs[i];
105
var loss=Math.min(Game.fps*60*10,me.time*0.2);
106
me.time-=loss;
107
me.time=Math.max(me.time,0);
108
changed++;
109
}
110
if (changed==0){Game.Popup('<div style="font-size:80%;">No buffs to alter!</div>',Game.mouseX,Game.mouseY);return -1;}
111
Game.Popup('<div style="font-size:80%;">Backfire!<br>Fizz! Buffs shortened.</div>',Game.mouseX,Game.mouseY);
112
},
113
},
114
'spontaneous edifice':{
115
name:'Spontaneous Edifice',
116
desc:'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 400, and cannot be your most-built one (unless it is your only one).',
117
failDesc:'Lose a random building.',
118
icon:[24,11],
119
costMin:20,
120
costPercent:0.75,
121
win:function()
122
{
123
var buildings=[];
124
var max=0;
125
var n=0;
126
for (var i in Game.Objects)
127
{
128
if (Game.Objects[i].amount>max) max=Game.Objects[i].amount;
129
if (Game.Objects[i].amount>0) n++;
130
}
131
for (var i in Game.Objects)
132
{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]);}
133
if (buildings.length==0){Game.Popup('<div style="font-size:80%;">No buildings to improve!</div>',Game.mouseX,Game.mouseY);return -1;}
134
var building=choose(buildings);
135
building.buyFree(1);
136
Game.Popup('<div style="font-size:80%;">A new '+building.single+'<br>bursts out of the ground.</div>',Game.mouseX,Game.mouseY);
137
},
138
fail:function()
139
{
140
if (Game.BuildingsOwned==0){Game.Popup('<div style="font-size:80%;">Backfired, but no buildings to destroy!</div>',Game.mouseX,Game.mouseY);return -1;}
141
var buildings=[];
142
for (var i in Game.Objects)
143
{if (Game.Objects[i].amount>0) buildings.push(Game.Objects[i]);}
144
var building=choose(buildings);
145
building.sacrifice(1);
146
Game.Popup('<div style="font-size:80%;">Backfire!<br>One of your '+building.plural+'<br>disappears in a puff of smoke.</div>',Game.mouseX,Game.mouseY);
147
},
148
},
149
'haggler\'s charm':{
150
name:'Haggler\'s Charm',
151
desc:'Upgrades are 2% cheaper for 1 minute.',
152
failDesc:'Upgrades are 2% more expensive for an hour.<q>What\'s that spell? Loadsamoney!</q>',
153
icon:[25,11],
154
costMin:10,
155
costPercent:0.1,
156
win:function()
157
{
158
Game.killBuff('Haggler\'s misery');
159
var buff=Game.gainBuff('haggler luck',60,2);
160
Game.Popup('<div style="font-size:80%;">Upgrades are cheaper!</div>',Game.mouseX,Game.mouseY);
161
},
162
fail:function()
163
{
164
Game.killBuff('Haggler\'s luck');
165
var buff=Game.gainBuff('haggler misery',60*60,2);
166
Game.Popup('<div style="font-size:80%;">Backfire!<br>Upgrades are pricier!</div>',Game.mouseX,Game.mouseY);
167
},
168
},
169
'summon crafty pixies':{
170
name:'Summon Crafty Pixies',
171
desc:'Buildings are 2% cheaper for 1 minute.',
172
failDesc:'Buildings are 2% more expensive for an hour.',
173
icon:[26,11],
174
costMin:10,
175
costPercent:0.2,
176
win:function()
177
{
178
Game.killBuff('Nasty goblins');
179
var buff=Game.gainBuff('pixie luck',60,2);
180
Game.Popup('<div style="font-size:80%;">Crafty pixies!<br>Buildings are cheaper!</div>',Game.mouseX,Game.mouseY);
181
},
182
fail:function()
183
{
184
Game.killBuff('Crafty pixies');
185
var buff=Game.gainBuff('pixie misery',60*60,2);
186
Game.Popup('<div style="font-size:80%;">Backfire!<br>Nasty goblins!<br>Buildings are pricier!</div>',Game.mouseX,Game.mouseY);
187
},
188
},
189
'gambler\'s fever dream':{
190
name:'Gambler\'s Fever Dream',
191
desc:'Cast a random spell at half the magic cost, with twice the chance of backfiring.',
192
icon:[27,11],
193
costMin:3,
194
costPercent:0.05,
195
win:function()
196
{
197
var spells=[];
198
var selfCost=M.getSpellCost(M.spells['gambler\'s fever dream']);
199
for (var i in M.spells)
200
{if (i!='gambler\'s fever dream' && (M.magic-selfCost)>=M.getSpellCost(M.spells[i])*0.5) spells.push(M.spells[i]);}
201
if (spells.length==0){Game.Popup('<div style="font-size:80%;">No eligible spells!</div>',Game.mouseX,Game.mouseY);return -1;}
202
var spell=choose(spells);
203
var cost=M.getSpellCost(spell)*0.5;
204
setTimeout(function(){
205
var out=M.castSpell(spell,{cost:cost,failChanceMax:0.5,passthrough:true});
206
if (!out)
207
{
208
M.magic+=selfCost;
209
setTimeout(function(){
210
Game.Popup('<div style="font-size:80%;">That\'s too bad!<br>Magic refunded.</div>',Game.mouseX,Game.mouseY);
211
},1500);
212
}
213
},1000);
214
Game.Popup('<div style="font-size:80%;">Casting '+spell.name+'<br>for '+Beautify(cost)+' magic...</div>',Game.mouseX,Game.mouseY);
215
},
216
},
217
'resurrect abomination':{
218
name:'Resurrect Abomination',
219
desc:'Instantly summon a wrinkler if conditions are fulfilled.',
220
failDesc:'Pop one of your wrinklers.',
221
icon:[28,11],
222
costMin:20,
223
costPercent:0.1,
224
win:function()
225
{
226
var out=Game.SpawnWrinkler();
227
if (!out){Game.Popup('<div style="font-size:80%;">Unable to spawn a wrinkler!</div>',Game.mouseX,Game.mouseY);return -1;}
228
Game.Popup('<div style="font-size:80%;">Rise, my precious!</div>',Game.mouseX,Game.mouseY);
229
},
230
fail:function()
231
{
232
var out=Game.PopRandomWrinkler();
233
if (!out){Game.Popup('<div style="font-size:80%;">Backfire!<br>But no wrinkler was harmed.</div>',Game.mouseX,Game.mouseY);return -1;}
234
Game.Popup('<div style="font-size:80%;">Backfire!<br>So long, ugly...</div>',Game.mouseX,Game.mouseY);
235
},
236
},
237
'diminish ineptitude':{
238
name:'Diminish Ineptitude',
239
desc:'Spells backfire 10 times less for the next 5 minutes.',
240
failDesc:'Spells backfire 5 times more for the next 10 minutes.',
241
icon:[29,11],
242
costMin:5,
243
costPercent:0.2,
244
win:function()
245
{
246
Game.killBuff('Magic inept');
247
var buff=Game.gainBuff('magic adept',5*60,10);
248
Game.Popup('<div style="font-size:80%;">Ineptitude diminished!</div>',Game.mouseX,Game.mouseY);
249
},
250
fail:function()
251
{
252
Game.killBuff('Magic adept');
253
var buff=Game.gainBuff('magic inept',10*60,5);
254
Game.Popup('<div style="font-size:80%;">Backfire!<br>Ineptitude magnified!</div>',Game.mouseX,Game.mouseY);
255
},
256
},
257
};
258
M.spellsById=[];var n=0;
259
for (var i in M.spells){M.spells[i].id=n;M.spellsById[n]=M.spells[i];n++;}
260
261
262
M.computeMagicM=function()
263
{
264
var towers=Math.max(M.parent.amount,1);
265
var lvl=Math.max(M.parent.level,1);
266
M.magicM=Math.floor(4+Math.pow(towers,0.6)+Math.log((towers+(lvl-1)*10)/15+1)*15);
267
//old formula :
268
/*
269
M.magicM=8+Math.min(M.parent.amount,M.parent.level*5)+Math.ceil(M.parent.amount/10);
270
if (M.magicM>200)
271
{
272
//diminishing returns starting at 200, being 5% as fast by 400
273
var x=M.magicM;
274
var top=x-200;
275
top/=200;
276
var top2=top;
277
top*=(1-top/2);
278
if (top2>=1) top=0.5;
279
top=top*0.95+top2*0.05;
280
top*=200;
281
x=top+200;
282
M.magicM=x;
283
}
284
*/
285
M.magic=Math.min(M.magicM,M.magic);
286
}
287
288
M.getFailChance=function(spell)
289
{
290
var failChance=0.15;
291
if (Game.hasBuff('Magic adept')) failChance*=0.1;
292
if (Game.hasBuff('Magic inept')) failChance*=5;
293
if (spell.failFunc) failChance=spell.failFunc(failChance);
294
return failChance;
295
}
296
297
M.castSpell=function(spell,obj)
298
{
299
var obj=obj||{};
300
var out=0;
301
var cost=0;
302
var fail=false;
303
if (typeof obj.cost!=='undefined') cost=obj.cost; else cost=M.getSpellCost(spell);
304
if (M.magic<cost) return false;
305
var failChance=M.getFailChance(spell);
306
if (typeof obj.failChanceSet!=='undefined') failChance=obj.failChanceSet;
307
if (typeof obj.failChanceAdd!=='undefined') failChance+=obj.failChanceAdd;
308
if (typeof obj.failChanceMult!=='undefined') failChance*=obj.failChanceMult;
309
if (typeof obj.failChanceMax!=='undefined') failChance=Math.max(failChance,obj.failChanceMax);
310
Math.seedrandom(Game.seed+'/'+M.spellsCastTotal);
311
if (!spell.fail || Math.random()<(1-failChance)) {out=spell.win();} else {fail=true;out=spell.fail();}
312
Math.seedrandom();
313
if (out!=-1)
314
{
315
if (!spell.passthrough && !obj.passthrough)
316
{
317
M.spellsCast++;
318
M.spellsCastTotal++;
319
if (M.spellsCastTotal>=9) Game.Win('Bibbidi-bobbidi-boo');
320
if (M.spellsCastTotal>=99) Game.Win('I\'m the wiz');
321
if (M.spellsCastTotal>=999) Game.Win('A wizard is you');
322
}
323
324
M.magic-=cost;
325
M.magic=Math.max(0,M.magic);
326
327
var rect=l('grimoireSpell'+spell.id).getBoundingClientRect();
328
Game.SparkleAt((rect.left+rect.right)/2,(rect.top+rect.bottom)/2-24);
329
330
if (fail) PlaySound('snd/spellFail.mp3',0.75); else PlaySound('snd/spell.mp3',0.75);
331
return true;
332
}
333
PlaySound('snd/spellFail.mp3',0.75);
334
return false;
335
}
336
337
M.getSpellCost=function(spell)
338
{
339
var out=spell.costMin;
340
if (spell.costPercent) out+=M.magicM*spell.costPercent;
341
return Math.floor(out);
342
}
343
M.getSpellCostBreakdown=function(spell)
344
{
345
var str='';
346
if (spell.costPercent) str+=Beautify(spell.costMin)+' magic +'+Beautify(Math.ceil(spell.costPercent*100))+'% of max magic';
347
else str+=Beautify(spell.costMin)+' magic';
348
return str;
349
}
350
351
M.spellTooltip=function(id)
352
{
353
return function(){
354
var me=M.spellsById[id];
355
me.icon=me.icon||[28,12];
356
var cost=Beautify(M.getSpellCost(me));
357
var costBreakdown=M.getSpellCostBreakdown(me);
358
if (cost!=costBreakdown) costBreakdown=' <small>('+costBreakdown+')</small>'; else costBreakdown='';
359
var backfire=M.getFailChance(me);
360
var str='<div style="padding:8px 4px;min-width:350px;">'+
361
'<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>'+
362
'<div class="name">'+me.name+'</div>'+
363
'<div>Magic cost : <b style="color:#'+(cost<=M.magic?'6f6':'f66')+';">'+cost+'</b>'+costBreakdown+'</div>'+
364
(me.fail?('<div><small>Chance to backfire : <b style="color:#f66">'+Math.ceil(100*backfire)+'%</b></small></div>'):'')+
365
'<div class="line"></div><div class="description"><b>Effect :</b> '+me.desc+(me.failDesc?('<div style="height:8px;"></div><b>Backfire :</b> '+me.failDesc):'')+'</div></div>';
366
return str;
367
};
368
}
369
370
var str='';
371
str+='<style>'+
372
'#grimoireBG{background:url(img/shadedBorders.png),url(img/grimoireBG.png);background-size:100% 100%,auto;position:absolute;left:0px;right:0px;top:0px;bottom:16px;}'+
373
'#grimoireContent{position:relative;box-sizing:border-box;padding:4px 24px;}'+
374
'#grimoireBar{max-width:95%;margin:4px auto;height:16px;}'+
375
'#grimoireBarFull{transform:scale(1,2);transform-origin:50% 0;height:50%;}'+
376
'#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;}'+
377
'#grimoireSpells{text-align:center;width:100%;padding:8px;box-sizing:border-box;}'+
378
'.grimoireIcon{pointer-events:none;margin:2px 6px 0px 6px;width:48px;height:48px;opacity:0.8;position:relative;}'+
379
'.grimoirePrice{pointer-events:none;}'+
380
'.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(img/spellBG.png);}'+
381
'.grimoireSpell.ready{color:rgba(255,255,255,0.8);opacity:1;}'+
382
'.grimoireSpell.ready:hover{color:#fff;}'+
383
'.grimoireSpell:hover{box-shadow:6px 6px 6px 2px #000;z-index:1000000001;top:-1px;}'+
384
'.grimoireSpell:active{top:1px;}'+
385
'.grimoireSpell.ready .grimoireIcon{opacity:1;}'+
386
'.grimoireSpell:hover{background-position:0px -74px;} .grimoireSpell:active{background-position:0px 74px;}'+
387
'.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;}'+
388
'.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;}'+
389
'.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;}'+
390
391
'.grimoireSpell:hover .grimoireIcon{top:-1px;}'+
392
'.grimoireSpell.ready:hover .grimoireIcon{animation-name:bounce;animation-iteration-count:infinite;animation-duration:0.8s;}'+
393
394
'#grimoireLumpRefill{cursor:pointer;width:48px;height:48px;position:absolute;left:-40px;top:-17px;transform:scale(0.5);z-index:1000;transition:transform 0.05s;}'+
395
'#grimoireLumpRefill:hover{transform:scale(1);}'+
396
'#grimoireLumpRefill:active{transform:scale(0.4);}'+
397
398
'#grimoireInfo{text-align:center;font-size:11px;margin-top:12px;color:rgba(255,255,255,0.75);text-shadow:-1px 1px 0px #000;}'+
399
'</style>';
400
str+='<div id="grimoireBG"></div>';
401
str+='<div id="grimoireContent">';
402
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/
403
for (var i in M.spells)
404
{
405
var me=M.spells[i];
406
var icon=me.icon||[28,12];
407
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>';
408
}
409
str+='</div>';
410
var icon=[29,14];
411
str+='<div id="grimoireBar" class="smallFramed meterContainer"><div '+Game.getTooltip('<div style="padding:8px;width:300px;font-size:11px;text-align:center;">Click to refill <b>100 units</b> of your magic meter<br>for <span class="price lump">1 sugar lump</span>.</div>')+' id="grimoireLumpRefill" class="usesIcon shadowFilter" style="background-position:'+(-icon[0]*48)+'px '+(-icon[1]*48)+'px;"></div><div id="grimoireBarFull" class="meter filling"></div><div id="grimoireBarText" class="titleFont"></div><div '+Game.getTooltip('<div style="padding:8px;width:300px;font-size:11px;text-align:center;">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>';
412
str+='<div id="grimoireInfo"></div>';
413
str+='</div>';
414
div.innerHTML=str;
415
M.magicBarL=l('grimoireBar');
416
M.magicBarFullL=l('grimoireBarFull');
417
M.magicBarTextL=l('grimoireBarText');
418
M.lumpRefill=l('grimoireLumpRefill');
419
M.infoL=l('grimoireInfo');
420
for (var i in M.spells)
421
{
422
var me=M.spells[i];
423
AddEvent(l('grimoireSpell'+me.id),'click',function(spell){return function(){PlaySound('snd/tick.mp3');M.castSpell(spell);}}(me));
424
}
425
426
AddEvent(M.lumpRefill,'click',function(){
427
if (Game.lumps>=1 && M.magic<M.magicM)
428
{
429
M.magic+=100;
430
M.magic=Math.min(M.magic,M.magicM);
431
Game.lumps-=1;
432
PlaySound('snd/pop'+Math.floor(Math.random()*3+1)+'.mp3',0.75);
433
}
434
});
435
436
M.computeMagicM();
437
M.magic=M.magicM;
438
M.spellsCast=0;
439
M.spellsCastTotal=0;
440
441
//M.parent.switchMinigame(1);
442
}
443
M.save=function()
444
{
445
//output cannot use ",", ";" or "|"
446
var str=''+
447
parseFloat(M.magic)+' '+
448
parseInt(Math.floor(M.spellsCast))+' '+
449
parseInt(Math.floor(M.spellsCastTotal))
450
;
451
return str;
452
}
453
M.load=function(str)
454
{
455
//interpret str; called after .init
456
//note : not actually called in the Game's load; see "minigameSave" in main.js
457
if (!str) return false;
458
var i=0;
459
var spl=str.split(' ');
460
M.computeMagicM();
461
M.magic=parseFloat(spl[i++]||M.magicM);
462
M.spellsCast=parseInt(spl[i++]||0);
463
M.spellsCastTotal=parseInt(spl[i++]||0);
464
}
465
M.reset=function()
466
{
467
M.computeMagicM();
468
M.magic=M.magicM;
469
M.spellsCast=0;
470
}
471
M.logic=function()
472
{
473
//run each frame
474
if (Game.T%5==0) {M.computeMagicM();}
475
M.magicPS=Math.max(0.002,Math.pow(M.magic/Math.max(M.magicM,100),0.5))*0.002;
476
M.magic+=M.magicPS;
477
M.magic=Math.min(M.magic,M.magicM);
478
if (Game.T%5==0)
479
{
480
for (var i in M.spells)
481
{
482
var me=M.spells[i];
483
var cost=M.getSpellCost(me);
484
l('grimoirePrice'+me.id).innerHTML=Beautify(cost);
485
if (M.magic<cost) l('grimoireSpell'+me.id).className='grimoireSpell titleFont';
486
else l('grimoireSpell'+me.id).className='grimoireSpell titleFont ready';
487
}
488
}
489
}
490
M.draw=function()
491
{
492
//run each draw frame
493
M.magicBarTextL.innerHTML=Math.min(Math.floor(M.magicM),Beautify(M.magic))+'/'+Beautify(Math.floor(M.magicM))+(M.magic<M.magicM?(' (+'+Beautify((M.magicPS||0)*Game.fps,2)+'/s)'):'');
494
M.magicBarFullL.style.width=((M.magic/M.magicM)*100)+'%';
495
M.magicBarL.style.width=(M.magicM*3)+'px';
496
M.infoL.innerHTML='Spells cast : '+Beautify(M.spellsCast)+' (total : '+Beautify(M.spellsCastTotal)+')';
497
}
498
M.init(l('rowSpecial'+M.parent.id));
499
}
500
var M=0;
501
502