Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mamayaya1
GitHub Repository: mamayaya1/game
Path: blob/main/projects/cookie-clicker/minigameGrimoire.js
4626 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('cookie storm','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(spell,cost,seed){return function(){
205
if (Game.seed!=seed) return false;
206
var out=M.castSpell(spell,{cost:cost,failChanceMax:0.5,passthrough:true});
207
if (!out)
208
{
209
M.magic+=selfCost;
210
setTimeout(function(){
211
Game.Popup('<div style="font-size:80%;">That\'s too bad!<br>Magic refunded.</div>',Game.mouseX,Game.mouseY);
212
},1500);
213
}
214
}}(spell,cost,Game.seed),1000);
215
Game.Popup('<div style="font-size:80%;">Casting '+spell.name+'<br>for '+Beautify(cost)+' magic...</div>',Game.mouseX,Game.mouseY);
216
},
217
},
218
'resurrect abomination':{
219
name:'Resurrect Abomination',
220
desc:'Instantly summon a wrinkler if conditions are fulfilled.',
221
failDesc:'Pop one of your wrinklers.',
222
icon:[28,11],
223
costMin:20,
224
costPercent:0.1,
225
win:function()
226
{
227
var out=Game.SpawnWrinkler();
228
if (!out){Game.Popup('<div style="font-size:80%;">Unable to spawn a wrinkler!</div>',Game.mouseX,Game.mouseY);return -1;}
229
Game.Popup('<div style="font-size:80%;">Rise, my precious!</div>',Game.mouseX,Game.mouseY);
230
},
231
fail:function()
232
{
233
var out=Game.PopRandomWrinkler();
234
if (!out){Game.Popup('<div style="font-size:80%;">Backfire!<br>But no wrinkler was harmed.</div>',Game.mouseX,Game.mouseY);return -1;}
235
Game.Popup('<div style="font-size:80%;">Backfire!<br>So long, ugly...</div>',Game.mouseX,Game.mouseY);
236
},
237
},
238
'diminish ineptitude':{
239
name:'Diminish Ineptitude',
240
desc:'Spells backfire 10 times less for the next 5 minutes.',
241
failDesc:'Spells backfire 5 times more for the next 10 minutes.',
242
icon:[29,11],
243
costMin:5,
244
costPercent:0.2,
245
win:function()
246
{
247
Game.killBuff('Magic inept');
248
var buff=Game.gainBuff('magic adept',5*60,10);
249
Game.Popup('<div style="font-size:80%;">Ineptitude diminished!</div>',Game.mouseX,Game.mouseY);
250
},
251
fail:function()
252
{
253
Game.killBuff('Magic adept');
254
var buff=Game.gainBuff('magic inept',10*60,5);
255
Game.Popup('<div style="font-size:80%;">Backfire!<br>Ineptitude magnified!</div>',Game.mouseX,Game.mouseY);
256
},
257
},
258
};
259
M.spellsById=[];var n=0;
260
for (var i in M.spells){M.spells[i].id=n;M.spellsById[n]=M.spells[i];n++;}
261
262
263
M.computeMagicM=function()
264
{
265
var towers=Math.max(M.parent.amount,1);
266
var lvl=Math.max(M.parent.level,1);
267
M.magicM=Math.floor(4+Math.pow(towers,0.6)+Math.log((towers+(lvl-1)*10)/15+1)*15);
268
//old formula :
269
/*
270
M.magicM=8+Math.min(M.parent.amount,M.parent.level*5)+Math.ceil(M.parent.amount/10);
271
if (M.magicM>200)
272
{
273
//diminishing returns starting at 200, being 5% as fast by 400
274
var x=M.magicM;
275
var top=x-200;
276
top/=200;
277
var top2=top;
278
top*=(1-top/2);
279
if (top2>=1) top=0.5;
280
top=top*0.95+top2*0.05;
281
top*=200;
282
x=top+200;
283
M.magicM=x;
284
}
285
*/
286
M.magic=Math.min(M.magicM,M.magic);
287
}
288
289
M.getFailChance=function(spell)
290
{
291
var failChance=0.15;
292
if (Game.hasBuff('Magic adept')) failChance*=0.1;
293
if (Game.hasBuff('Magic inept')) failChance*=5;
294
if (spell.failFunc) failChance=spell.failFunc(failChance);
295
return failChance;
296
}
297
298
M.castSpell=function(spell,obj)
299
{
300
var obj=obj||{};
301
var out=0;
302
var cost=0;
303
var fail=false;
304
if (typeof obj.cost!=='undefined') cost=obj.cost; else cost=M.getSpellCost(spell);
305
if (M.magic<cost) return false;
306
var failChance=M.getFailChance(spell);
307
if (typeof obj.failChanceSet!=='undefined') failChance=obj.failChanceSet;
308
if (typeof obj.failChanceAdd!=='undefined') failChance+=obj.failChanceAdd;
309
if (typeof obj.failChanceMult!=='undefined') failChance*=obj.failChanceMult;
310
if (typeof obj.failChanceMax!=='undefined') failChance=Math.max(failChance,obj.failChanceMax);
311
Math.seedrandom(Game.seed+'/'+M.spellsCastTotal);
312
if (!spell.fail || Math.random()<(1-failChance)) {out=spell.win();} else {fail=true;out=spell.fail();}
313
Math.seedrandom();
314
if (out!=-1)
315
{
316
if (!spell.passthrough && !obj.passthrough)
317
{
318
M.spellsCast++;
319
M.spellsCastTotal++;
320
if (M.spellsCastTotal>=9) Game.Win('Bibbidi-bobbidi-boo');
321
if (M.spellsCastTotal>=99) Game.Win('I\'m the wiz');
322
if (M.spellsCastTotal>=999) Game.Win('A wizard is you');
323
}
324
325
M.magic-=cost;
326
M.magic=Math.max(0,M.magic);
327
328
var rect=l('grimoireSpell'+spell.id).getBoundingClientRect();
329
Game.SparkleAt((rect.left+rect.right)/2,(rect.top+rect.bottom)/2-24);
330
331
if (fail) PlaySound('snd/spellFail.mp3',0.75); else PlaySound('snd/spell.mp3',0.75);
332
return true;
333
}
334
PlaySound('snd/spellFail.mp3',0.75);
335
return false;
336
}
337
338
M.getSpellCost=function(spell)
339
{
340
var out=spell.costMin;
341
if (spell.costPercent) out+=M.magicM*spell.costPercent;
342
return Math.floor(out);
343
}
344
M.getSpellCostBreakdown=function(spell)
345
{
346
var str='';
347
if (spell.costPercent) str+=Beautify(spell.costMin)+' magic +'+Beautify(Math.ceil(spell.costPercent*100))+'% of max magic';
348
else str+=Beautify(spell.costMin)+' magic';
349
return str;
350
}
351
352
M.spellTooltip=function(id)
353
{
354
return function(){
355
var me=M.spellsById[id];
356
me.icon=me.icon||[28,12];
357
var cost=Beautify(M.getSpellCost(me));
358
var costBreakdown=M.getSpellCostBreakdown(me);
359
if (cost!=costBreakdown) costBreakdown=' <small>('+costBreakdown+')</small>'; else costBreakdown='';
360
var backfire=M.getFailChance(me);
361
var str='<div style="padding:8px 4px;min-width:350px;">'+
362
'<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>'+
363
'<div class="name">'+me.name+'</div>'+
364
'<div>Magic cost : <b style="color:#'+(cost<=M.magic?'6f6':'f66')+';">'+cost+'</b>'+costBreakdown+'</div>'+
365
(me.fail?('<div><small>Chance to backfire : <b style="color:#f66">'+Math.ceil(100*backfire)+'%</b></small></div>'):'')+
366
'<div class="line"></div><div class="description"><b>Effect :</b> <span class="green">'+(me.descFunc?me.descFunc():me.desc)+'</span>'+(me.failDesc?('<div style="height:8px;"></div><b>Backfire :</b> <span class="red">'+me.failDesc+'</span>'):'')+'</div></div>';
367
return str;
368
};
369
}
370
371
var str='';
372
str+='<style>'+
373
'#grimoireBG{background:url(img/shadedBorders.png),url(img/BGgrimoire.jpg);background-size:100% 100%,auto;position:absolute;left:0px;right:0px;top:0px;bottom:16px;}'+
374
'#grimoireContent{position:relative;box-sizing:border-box;padding:4px 24px;}'+
375
'#grimoireBar{max-width:95%;margin:4px auto;height:16px;}'+
376
'#grimoireBarFull{transform:scale(1,2);transform-origin:50% 0;height:50%;}'+
377
'#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;}'+
378
'#grimoireSpells{text-align:center;width:100%;padding:8px;box-sizing:border-box;}'+
379
'.grimoireIcon{pointer-events:none;margin:2px 6px 0px 6px;width:48px;height:48px;opacity:0.8;position:relative;}'+
380
'.grimoirePrice{pointer-events:none;}'+
381
'.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);}'+
382
'.grimoireSpell.ready{color:rgba(255,255,255,0.8);opacity:1;}'+
383
'.grimoireSpell.ready:hover{color:#fff;}'+
384
'.grimoireSpell:hover{box-shadow:6px 6px 6px 2px #000;z-index:1000000001;top:-1px;}'+
385
'.grimoireSpell:active{top:1px;}'+
386
'.grimoireSpell.ready .grimoireIcon{opacity:1;}'+
387
'.grimoireSpell:hover{background-position:0px -74px;} .grimoireSpell:active{background-position:0px 74px;}'+
388
'.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;}'+
389
'.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;}'+
390
'.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;}'+
391
392
'.grimoireSpell:hover .grimoireIcon{top:-1px;}'+
393
'.grimoireSpell.ready:hover .grimoireIcon{animation-name:bounce;animation-iteration-count:infinite;animation-duration:0.8s;}'+
394
'.noFancy .grimoireSpell.ready:hover .grimoireIcon{animation:none;}'+
395
396
'#grimoireInfo{text-align:center;font-size:11px;margin-top:12px;color:rgba(255,255,255,0.75);text-shadow:-1px 1px 0px #000;}'+
397
'</style>';
398
str+='<div id="grimoireBG"></div>';
399
str+='<div id="grimoireContent">';
400
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/
401
for (var i in M.spells)
402
{
403
var me=M.spells[i];
404
var icon=me.icon||[28,12];
405
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>';
406
}
407
str+='</div>';
408
var icon=[29,14];
409
str+='<div id="grimoireBar" class="smallFramed meterContainer"><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"></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>';
410
str+='<div id="grimoireInfo"></div>';
411
str+='</div>';
412
div.innerHTML=str;
413
M.magicBarL=l('grimoireBar');
414
M.magicBarFullL=l('grimoireBarFull');
415
M.magicBarTextL=l('grimoireBarText');
416
M.lumpRefill=l('grimoireLumpRefill');
417
M.infoL=l('grimoireInfo');
418
for (var i in M.spells)
419
{
420
var me=M.spells[i];
421
AddEvent(l('grimoireSpell'+me.id),'click',function(spell){return function(){PlaySound('snd/tick.mp3');M.castSpell(spell);}}(me));
422
}
423
424
M.refillTooltip=function(){
425
return '<div style="padding:8px;width:300px;font-size:11px;text-align:center;">Click to refill <b>100 units</b> of your magic meter for <span class="price lump">1 sugar lump</span>.'+
426
(Game.canRefillLump()?'<br><small>(can be done once every '+Game.sayTime(Game.getLumpRefillMax(),-1)+')</small>':('<br><small class="red">(usable again in '+Game.sayTime(Game.getLumpRefillRemaining()+Game.fps,-1)+')</small>'))+
427
'</div>';
428
};
429
AddEvent(M.lumpRefill,'click',function(){
430
if (M.magic<M.magicM)
431
{Game.refillLump(1,function(){
432
M.magic+=100;
433
M.magic=Math.min(M.magic,M.magicM);
434
PlaySound('snd/pop'+Math.floor(Math.random()*3+1)+'.mp3',0.75);
435
});}
436
});
437
438
M.computeMagicM();
439
M.magic=M.magicM;
440
M.spellsCast=0;
441
M.spellsCastTotal=0;
442
443
//M.parent.switchMinigame(1);
444
}
445
M.save=function()
446
{
447
//output cannot use ",", ";" or "|"
448
var str=''+
449
parseFloat(M.magic)+' '+
450
parseInt(Math.floor(M.spellsCast))+' '+
451
parseInt(Math.floor(M.spellsCastTotal))+
452
' '+parseInt(M.parent.onMinigame?'1':'0')
453
;
454
return str;
455
}
456
M.load=function(str)
457
{
458
//interpret str; called after .init
459
//note : not actually called in the Game's load; see "minigameSave" in main.js
460
if (!str) return false;
461
var i=0;
462
var spl=str.split(' ');
463
M.computeMagicM();
464
M.magic=parseFloat(spl[i++]||M.magicM);
465
M.spellsCast=parseInt(spl[i++]||0);
466
M.spellsCastTotal=parseInt(spl[i++]||0);
467
var on=parseInt(spl[i++]||0);if (on && Game.ascensionMode!=1) M.parent.switchMinigame(1);
468
}
469
M.reset=function()
470
{
471
M.computeMagicM();
472
M.magic=M.magicM;
473
M.spellsCast=0;
474
}
475
M.logic=function()
476
{
477
//run each frame
478
if (Game.T%5==0) {M.computeMagicM();}
479
M.magicPS=Math.max(0.002,Math.pow(M.magic/Math.max(M.magicM,100),0.5))*0.002;
480
M.magic+=M.magicPS;
481
M.magic=Math.min(M.magic,M.magicM);
482
if (Game.T%5==0)
483
{
484
for (var i in M.spells)
485
{
486
var me=M.spells[i];
487
var cost=M.getSpellCost(me);
488
l('grimoirePrice'+me.id).innerHTML=Beautify(cost);
489
if (M.magic<cost) l('grimoireSpell'+me.id).className='grimoireSpell titleFont';
490
else l('grimoireSpell'+me.id).className='grimoireSpell titleFont ready';
491
}
492
}
493
}
494
M.draw=function()
495
{
496
//run each draw frame
497
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)'):'');
498
M.magicBarFullL.style.width=((M.magic/M.magicM)*100)+'%';
499
M.magicBarL.style.width=(M.magicM*3)+'px';
500
M.infoL.innerHTML='Spells cast : '+Beautify(M.spellsCast)+' (total : '+Beautify(M.spellsCastTotal)+')';
501
}
502
M.init(l('rowSpecial'+M.parent.id));
503
}
504
var M=0;
505