-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathmain.js
3306 lines (3020 loc) · 147 KB
/
main.js
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
All this code is copyright Orteil, 2013.
-with some help, advice and fixes by Debugbro and Opti
Spoilers ahead.
http://orteil.dashnet.org
*/
/*=====================================================================================
MISC HELPER FUNCTIONS
=======================================================================================*/
function l(what) {return document.getElementById(what);}
function choose(arr) {return arr[Math.floor(Math.random()*arr.length)];}
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(needle) {
for(var i = 0; i < this.length; i++) {
if(this[i] === needle) {
return i;
}
}
return -1;
};
}
function shuffle(array)
{
var counter = array.length, temp, index;
// While there are elements in the array
while (counter--)
{
// Pick a random index
index = (Math.random() * counter) | 0;
// And swap the last element with it
temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
function Beautify(what,floats)//turns 9999999 into 9,999,999
{
var str='';
what=Math.round(what*100000)/100000;//get rid of weird rounding errors
if (floats>0)
{
var floater=what-Math.floor(what);
floater=Math.round(floater*100000)/100000;//get rid of weird rounding errors
var floatPresent=floater?1:0;
floater=(floater.toString()+'0000000').slice(2,2+floats);//yes this is hacky (but it works)
str=Beautify(Math.floor(what))+(floatPresent?('.'+floater):'');
}
else
{
what=Math.floor(what);
what=(what+'').split('').reverse();
for (var i in what)
{
if (i%3==0 && i>0) str=','+str;
str=what[i]+str;
}
}
return str;
}
function utf8_to_b64( str ) {
try{
return Base64.encode(unescape(encodeURIComponent( str )));
//return window.btoa(unescape(encodeURIComponent( str )));
}
catch(err)
{
//Popup('There was a problem while encrypting to base64.<br>('+err+')');
return '';
}
}
function b64_to_utf8( str ) {
try{
return decodeURIComponent(escape(Base64.decode( str )));
//return decodeURIComponent(escape(window.atob( str )));
}
catch(err)
{
//Popup('There was a problem while decrypting from base64.<br>('+err+')');
return '';
}
}
function CompressBin(arr)//compress a sequence like [0,1,1,0,1,0]... into a number like 54.
{
var str='';
var arr2=arr.slice(0);
arr2.unshift(1);
arr2.push(1);
arr2.reverse();
for (var i in arr2)
{
str+=arr2[i];
}
str=parseInt(str,2);
return str;
}
function UncompressBin(num)//uncompress a number like 54 to a sequence like [0,1,1,0,1,0].
{
var arr=num.toString(2);
arr=arr.split('');
arr.reverse();
arr.shift();
arr.pop();
return arr;
}
function CompressLargeBin(arr)//we have to compress in smaller chunks to avoid getting into scientific notation
{
var arr2=arr.slice(0);
var thisBit=[];
var bits=[];
for (var i in arr2)
{
thisBit.push(arr2[i]);
if (thisBit.length>=50)
{
bits.push(CompressBin(thisBit));
thisBit=[];
}
}
if (thisBit.length>0) bits.push(CompressBin(thisBit));
arr2=bits.join(';');
return arr2;
}
function UncompressLargeBin(arr)
{
var arr2=arr.split(';');
var bits=[];
for (var i in arr2)
{
bits.push(UncompressBin(parseInt(arr2[i])));
}
arr2=[];
for (var i in bits)
{
for (var ii in bits[i]) arr2.push(bits[i][ii]);
}
return arr2;
}
//seeded random function, courtesy of http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html
(function(a,b,c,d,e,f){function k(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=j&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=j&f+1],c=c*d+h[j&(h[f]=h[g=j&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function l(a,b){var e,c=[],d=(typeof a)[0];if(b&&"o"==d)for(e in a)try{c.push(l(a[e],b-1))}catch(f){}return c.length?c:"s"==d?a:a+"\0"}function m(a,b){for(var d,c=a+"",e=0;c.length>e;)b[j&e]=j&(d^=19*b[j&e])+c.charCodeAt(e++);return o(b)}function n(c){try{return a.crypto.getRandomValues(c=new Uint8Array(d)),o(c)}catch(e){return[+new Date,a,a.navigator.plugins,a.screen,o(b)]}}function o(a){return String.fromCharCode.apply(0,a)}var g=c.pow(d,e),h=c.pow(2,f),i=2*h,j=d-1;c.seedrandom=function(a,f){var j=[],p=m(l(f?[a,o(b)]:0 in arguments?a:n(),3),j),q=new k(j);return m(o(q.S),b),c.random=function(){for(var a=q.g(e),b=g,c=0;h>a;)a=(a+c)*d,b*=d,c=q.g(1);for(;a>=i;)a/=2,b/=2,c>>>=1;return(a+c)/b},p},m(c.random(),b)})(this,[],Math,256,6,52);
/*=====================================================================================
GAME INITIALIZATION
=======================================================================================*/
Game={};
Game.Launch=function()
{
Game.ready=0;
Game.Init=function()
{
Game.ready=1;
l('javascriptError').innerHTML='<div style="padding:64px 128px;"><div class="title">Loading...</div></div>';
/*=====================================================================================
VARIABLES AND PRESETS
=======================================================================================*/
Game.T=0;
Game.fps=30;
Game.version=1.036;
Game.beta=0;
l('versionNumber').innerHTML='v.'+Game.version+(Game.beta?' <span style="color:#ff0;">beta</span>':'');
//l('links').innerHTML=(Game.beta?'<a href="../" target="blank">Live version</a> | ':'<a href="beta" target="blank">Try the beta!</a> | ')+'<a href="http://orteil.dashnet.org/experiments/cookie/" target="blank">Cookie Clicker Classic</a>';
l('links').innerHTML='<a href="http://orteil.dashnet.org/experiments/cookie/" target="blank">Cookie Clicker Classic</a>';
//latency compensator stuff
Game.time=new Date().getTime();
Game.fpsMeasure=new Date().getTime();
Game.accumulatedDelay=0;
Game.catchupLogic=0;
Game.cookiesEarned=0;//all cookies earned during gameplay
Game.cookies=0;//cookies
Game.cookiesd=0;//cookies display
Game.cookiesPs=1;//cookies per second (to recalculate with every new purchase)
Game.cookiesReset=0;//cookies lost to resetting
Game.frenzy=0;//as long as >0, cookie production is multiplied by frenzyPower
Game.frenzyPower=1;
Game.clickFrenzy=0;//as long as >0, mouse clicks get 777x more cookies
Game.cookieClicks=0;//+1 for each click on the cookie
Game.goldenClicks=0;//+1 for each golden cookie clicked
Game.missedGoldenClicks=0;//+1 for each golden cookie missed
Game.handmadeCookies=0;//all the cookies made from clicking the cookie
Game.milkProgress=0;//you can a little bit for each achievement; 0-1 : milk; 1-2 : chocolate milk; 2-3 : raspberry milk
Game.milkH=Game.milkProgress/2;//milk height, between 0 and 1 (although should never go above 0.5)
Game.milkHd=0;//milk height display
Game.milkType=-1;//custom milk : 0=plain, 1=chocolate...
Game.backgroundType=-1;//custom background : 0=blue, 1=red...
Game.prestige=[];//cool stuff that carries over beyond resets
Game.elderWrath=0;
Game.elderWrathD=0;
Game.pledges=0;
Game.pledgeT=0;
Game.researchT=0;
Game.nextResearch=0;
Game.bg='';//background (grandmas and such)
Game.bgFade='';//fading to background
Game.bgR=0;//ratio (0 - not faded, 1 - fully faded)
Game.bgRd=0;//ratio displayed
Game.startDate=parseInt(new Date().getTime());
Game.prefs=[];
Game.DefaultPrefs=function()
{
Game.prefs.particles=1;
Game.prefs.numbers=1;
Game.prefs.autosave=1;
Game.prefs.autoupdate=1;
Game.prefs.milk=1;
Game.prefs.fancy=1;
}
Game.DefaultPrefs();
/*=====================================================================================
UPDATE CHECKER (broken?)
=======================================================================================*/
Game.CheckUpdates=function()
{
ajax('server.php?q=checkupdate',Game.CheckUpdatesResponse);
}
Game.CheckUpdatesResponse=function(response)
{
var r=response.split('|');
if (parseFloat(r[0])>Game.version)
{
var str='<b>New version available : v.'+r[0]+'!</b>';
if (r[1]) str+='<br>Update note : "'+r[1]+'"';
str+='<br><b>Refresh to get it!</b>';
l('alert').innerHTML=str;
l('alert').style.display='block';
}
}
/*=====================================================================================
SAVE
=======================================================================================*/
Game.ExportSave=function()
{
var save=prompt('Copy this text and keep it somewhere safe!',Game.WriteSave(1));
}
Game.ImportSave=function()
{
var save=prompt('Please paste in the text that was given to you on save export.','');
if (save && save!='') Game.LoadSave(save);
Game.WriteSave();
}
Game.WriteSave=function(exporting)//guess what we'e using to save the game?
{
var str='';
str+=Game.version+'|';
str+='|';//just in case we need some more stuff here
str+=//save stats
parseInt(Game.startDate)+
'|';
str+=//prefs
(Game.prefs.particles?'1':'0')+
(Game.prefs.numbers?'1':'0')+
(Game.prefs.autosave?'1':'0')+
(Game.prefs.autoupdate?'1':'0')+
(Game.prefs.milk?'1':'0')+
(Game.prefs.fancy?'1':'0')+
'|';
str+=parseFloat(Math.floor(Game.cookies))+';'+
parseFloat(Math.floor(Game.cookiesEarned))+';'+
parseInt(Math.floor(Game.cookieClicks))+';'+
parseInt(Math.floor(Game.goldenClicks))+';'+
parseFloat(Math.floor(Game.handmadeCookies))+';'+
parseInt(Math.floor(Game.missedGoldenClicks))+';'+
parseInt(Math.floor(Game.backgroundType))+';'+
parseInt(Math.floor(Game.milkType))+';'+
parseFloat(Math.floor(Game.cookiesReset))+';'+
parseInt(Math.floor(Game.elderWrath))+';'+
parseInt(Math.floor(Game.pledges))+';'+
parseInt(Math.floor(Game.pledgeT))+';'+
parseInt(Math.floor(Game.nextResearch))+';'+
parseInt(Math.floor(Game.researchT))+
'|';//cookies
for (var i in Game.Objects)//buildings
{
var me=Game.Objects[i];
str+=me.amount+','+me.bought+','+Math.floor(me.totalCookies)+','+me.specialUnlocked+';';
}
str+='|';
var toCompress=[];
for (var i in Game.Upgrades)//upgrades
{
var me=Game.Upgrades[i];
toCompress.push(Math.min(me.unlocked,1),Math.min(me.bought,1));
}
toCompress=CompressLargeBin(toCompress);
str+=toCompress;
str+='|';
var toCompress=[];
for (var i in Game.Achievements)//achievements
{
var me=Game.Achievements[i];
toCompress.push(Math.min(me.won));
}
toCompress=CompressLargeBin(toCompress);
str+=toCompress;
if (exporting)
{
str=escape(utf8_to_b64(str)+'!END!');
return str;
}
else
{
//that's right
//we're using cookies
//yeah I went there
var now=new Date();//we storin dis for 5 years, people
now.setFullYear(now.getFullYear()+5);//mmh stale cookies
str=utf8_to_b64(str)+'!END!';
str='CookieClickerGame='+escape(str)+'; expires='+now.toUTCString()+';';
document.cookie=str;//aaand save
if (document.cookie.indexOf('CookieClickerGame')<0) Game.Popup('Error while saving.<br>Export your save instead!');
else Game.Popup('Game saved');
}
}
/*=====================================================================================
LOAD
=======================================================================================*/
Game.LoadSave=function(data)
{
var str='';
if (data) str=unescape(data);
else if (document.cookie.indexOf('CookieClickerGame')>=0) str=unescape(document.cookie.split('CookieClickerGame=')[1]);//get cookie here
if (str!='')
{
var version=0;
var oldstr=str.split('|');
if (oldstr[0]<1) {}
else
{
str=str.split('!END!')[0];
str=b64_to_utf8(str);
}
if (str!='')
{
var spl='';
str=str.split('|');
version=parseFloat(str[0]);
if (version>=1 && version>Game.version)
{
alert('Error : you are attempting to load a save from a later version (v.'+version+'; you are using v.'+Game.version+').');
return;
}
else if (version>=1)
{
spl=str[2].split(';');//save stats
Game.startDate=parseInt(spl[0]);
spl=str[3].split('');//prefs
Game.prefs.particles=parseInt(spl[0]);
Game.prefs.numbers=parseInt(spl[1]);
Game.prefs.autosave=parseInt(spl[2]);
Game.prefs.autoupdate=spl[3]?parseInt(spl[3]):1;
Game.prefs.milk=spl[4]?parseInt(spl[4]):1;
Game.prefs.fancy=parseInt(spl[5]);if (Game.prefs.fancy) Game.removeClass('noFancy'); else if (!Game.prefs.fancy) Game.addClass('noFancy');
spl=str[4].split(';');//cookies
Game.cookies=parseFloat(spl[0]);Game.cookiesEarned=parseFloat(spl[1]);
Game.cookieClicks=spl[2]?parseInt(spl[2]):0;
Game.goldenClicks=spl[3]?parseInt(spl[3]):0;
Game.handmadeCookies=spl[4]?parseFloat(spl[4]):0;
Game.missedGoldenClicks=spl[5]?parseInt(spl[5]):0;
Game.backgroundType=spl[6]?parseInt(spl[6]):0;
Game.milkType=spl[7]?parseInt(spl[7]):0;
Game.cookiesReset=spl[8]?parseFloat(spl[8]):0;
Game.elderWrath=spl[9]?parseInt(spl[9]):0;
Game.pledges=spl[10]?parseInt(spl[10]):0;
Game.pledgeT=spl[11]?parseInt(spl[11]):0;
Game.nextResearch=spl[12]?parseInt(spl[12]):0;
Game.researchT=spl[13]?parseInt(spl[13]):0;
spl=str[5].split(';');//buildings
Game.BuildingsOwned=0;
for (var i in Game.ObjectsById)
{
var me=Game.ObjectsById[i];
if (spl[i])
{
var mestr=spl[i].toString().split(',');
me.amount=parseInt(mestr[0]);me.bought=parseInt(mestr[1]);me.totalCookies=parseInt(mestr[2]);me.specialUnlocked=parseInt(mestr[3]);
Game.BuildingsOwned+=me.amount;
}
else
{
me.unlocked=0;me.bought=0;me.totalCookies=0;
}
}
if (version<1.035)//old non-binary algorithm
{
spl=str[6].split(';');//upgrades
Game.UpgradesOwned=0;
for (var i in Game.UpgradesById)
{
var me=Game.UpgradesById[i];
if (spl[i])
{
var mestr=spl[i].split(',');
me.unlocked=parseInt(mestr[0]);me.bought=parseInt(mestr[1]);
if (me.bought) Game.UpgradesOwned++;
}
else
{
me.unlocked=0;me.bought=0;
}
}
if (str[7]) spl=str[7].split(';'); else spl=[];//achievements
Game.AchievementsOwned=0;
for (var i in Game.AchievementsById)
{
var me=Game.AchievementsById[i];
if (spl[i])
{
var mestr=spl[i].split(',');
me.won=parseInt(mestr[0]);
}
else
{
me.won=0;
}
if (me.won && me.hide!=3) Game.AchievementsOwned++;
}
}
else
{
if (str[6]) spl=str[6]; else spl=[];//upgrades
spl=UncompressLargeBin(spl);
Game.UpgradesOwned=0;
for (var i in Game.UpgradesById)
{
var me=Game.UpgradesById[i];
if (spl[i*2])
{
var mestr=[spl[i*2],spl[i*2+1]];
me.unlocked=parseInt(mestr[0]);me.bought=parseInt(mestr[1]);
if (me.bought) Game.UpgradesOwned++;
}
else
{
me.unlocked=0;me.bought=0;
}
}
if (str[7]) spl=str[7]; else spl=[];//achievements
spl=UncompressLargeBin(spl);
Game.AchievementsOwned=0;
for (var i in Game.AchievementsById)
{
var me=Game.AchievementsById[i];
if (spl[i])
{
var mestr=[spl[i]];
me.won=parseInt(mestr[0]);
}
else
{
me.won=0;
}
if (me.won && me.hide!=3) Game.AchievementsOwned++;
}
}
for (var i in Game.ObjectsById)
{
var me=Game.ObjectsById[i];
if (me.buyFunction) me.buyFunction();
me.setSpecial(0);
if (me.special) me.special();
me.refresh();
}
}
else//importing old version save
{
/*
Game.startDate=parseInt(new Date().getTime());
Game.cookies=parseInt(str[1]);
Game.cookiesEarned=parseInt(str[1]);
for (var i in Game.ObjectsById)
{
var me=Game.ObjectsById[i];
me.amount=0;me.bought=0;me.totalCookies=0;
me.refresh();
}
for (var i in Game.UpgradesById)
{
var me=Game.UpgradesById[i];
me.unlocked=0;me.bought=0;
}
var moni=0;
moni+=15*Math.pow(1.1,parseInt(str[2]));
moni+=100*Math.pow(1.1,parseInt(str[4]));
moni+=500*Math.pow(1.1,parseInt(str[6]));
moni+=2000*Math.pow(1.1,parseInt(str[8]));
moni+=7000*Math.pow(1.1,parseInt(str[10]));
moni+=50000*Math.pow(1.1,parseInt(str[12]));
moni+=1000000*Math.pow(1.1,parseInt(str[14]));
if (parseInt(str[16])) moni+=123456789*Math.pow(1.1,parseInt(str[16]));
alert('Imported old save from version '+version+'; recovered '+Beautify(Game.cookies)+' cookies, and converted buildings back to '+Beautify(moni)+' cookies.');
Game.cookies+=moni;
Game.cookiesEarned+=moni;
*/
alert('Sorry, you can\'t import saves from the old version anymore.');
return;
}
Game.goldenCookie.reset();
Game.prestige=[];
Game.Upgrades['Elder Pledge'].basePrice=Math.pow(8,Math.min(Game.pledges+2,13));
Game.RebuildUpgrades();
Game.TickerAge=0;
Game.elderWrathD=0;
Game.frenzy=0;
Game.frenzyPower=1;
Game.clickFrenzy=0;
Game.recalculateGains=1;
Game.storeToRebuild=1;
Game.upgradesToRebuild=1;
Game.Popup('Game loaded');
}
}
}
/*=====================================================================================
RESET
=======================================================================================*/
Game.Reset=function(bypass)
{
if (bypass || confirm('Do you REALLY want to start over?\n(your will lose your progress, but you will keep your achievements and your prestige.)'))
{
if (!bypass)
{
if (Game.cookiesEarned>=1000000) Game.Win('Sacrifice');
if (Game.cookiesEarned>=1000000000) Game.Win('Oblivion');
if (Game.cookiesEarned>=1000000000000) Game.Win('From scratch');
if (Game.cookiesEarned>=1000000000000000) Game.Win('Nihilism');
}
Game.cookiesReset+=Game.cookiesEarned;
Game.cookies=0;
Game.cookiesEarned=0;
Game.cookieClicks=0;
//Game.goldenClicks=0;
//Game.missedGoldenClicks=0;
Game.handmadeCookies=0;
Game.backgroundType=-1;
Game.milkType=-1;
Game.frenzy=0;
Game.frenzyPower=1;
Game.clickFrenzy=0;
Game.pledges=0;
Game.pledgeT=0;
Game.elderWrath=0;
Game.nextResearch=0;
Game.researchT=0;
Game.Upgrades['Elder Pledge'].basePrice=Math.pow(8,Math.min(Game.pledges+2,13));
for (var i in Game.ObjectsById)
{
var me=Game.ObjectsById[i];
me.amount=0;me.bought=0;me.totalCookies=0;me.specialUnlocked=0;
me.setSpecial(0);
me.refresh();
}
for (var i in Game.UpgradesById)
{
var me=Game.UpgradesById[i];
me.unlocked=0;me.bought=0;
}
/*
for (var i in Game.AchievementsById)
{
var me=Game.AchievementsById[i];
me.won=0;
}*/
//Game.DefaultPrefs();
Game.BuildingsOwned=0;
Game.UpgradesOwned=0;
Game.RebuildUpgrades();
Game.TickerAge=0;
Game.recalculateGains=1;
Game.storeToRebuild=1;
Game.upgradesToRebuild=1;
Game.startDate=parseInt(new Date().getTime());
Game.goldenCookie.reset();
Game.Popup('Game reset');
if (!bypass)
{
var prestige=0;
if (Game.prestige.ready) prestige=Game.prestige['Heavenly chips'];
Game.prestige=[];
Game.CalculatePrestige();
prestige=Game.prestige['Heavenly chips']-prestige;
if (prestige!=0) Game.Popup('You earn '+prestige+' heavenly chip'+(prestige==1?'':'s')+'!');
}
}
}
Game.HardReset=function()
{
if (confirm('Do you REALLY want to wipe your save?\n(you will lose your progress, your achievements, and your prestige!)'))
{
if (confirm('Whoah now, are you really, REALLY sure?\n(don\'t say we didn\'t warn you!)'))
{
for (var i in Game.AchievementsById)
{
var me=Game.AchievementsById[i];
me.won=0;
}
Game.AchievementsOwned=0;
Game.goldenClicks=0;
Game.missedGoldenClicks=0;
Game.Reset(1);
Game.cookiesReset=0;
Game.prestige=[];
Game.CalculatePrestige();
}
}
}
/*=====================================================================================
COOKIE ECONOMICS
=======================================================================================*/
Game.Earn=function(howmuch)
{
Game.cookies+=howmuch;
Game.cookiesEarned+=howmuch;
}
Game.Spend=function(howmuch)
{
Game.cookies-=howmuch;
}
Game.mouseCps=function()
{
var add=0;
if (Game.Has('Thousand fingers')) add+=0.1;
if (Game.Has('Million fingers')) add+=0.5;
if (Game.Has('Billion fingers')) add+=2;
if (Game.Has('Trillion fingers')) add+=10;
if (Game.Has('Quadrillion fingers')) add+=20;
if (Game.Has('Quintillion fingers')) add+=100;
var num=0;
for (var i in Game.Objects) {if (Game.Objects[i].name!='Cursor') num+=Game.Objects[i].amount;}
add=add*num;
if (Game.Has('Plastic mouse')) add+=Game.cookiesPs*0.01;
if (Game.Has('Iron mouse')) add+=Game.cookiesPs*0.01;
if (Game.Has('Titanium mouse')) add+=Game.cookiesPs*0.01;
if (Game.Has('Adamantium mouse')) add+=Game.cookiesPs*0.01;
var mult=1;
if (Game.clickFrenzy>0) mult*=777;
return mult*Game.ComputeCps(1,Game.Has('Reinforced index finger'),Game.Has('Carpal tunnel prevention cream')+Game.Has('Ambidextrous'),add);
}
Game.computedMouseCps=1;
Game.globalCpsMult=1;
Game.lastClick=0;
Game.autoclickerDetected=0;
Game.ClickCookie=function()
{
if (new Date().getTime()-Game.lastClick<1000/250)
{
}
else
{
if (new Date().getTime()-Game.lastClick<1000/15)
{
Game.autoclickerDetected+=Game.fps;
if (Game.autoclickerDetected>=Game.fps*5) Game.Win('Uncanny clicker');
}
Game.Earn(Game.computedMouseCps);
Game.handmadeCookies+=Game.computedMouseCps;
if (Game.prefs.particles) Game.cookieParticleAdd();
if (Game.prefs.numbers) Game.cookieNumberAdd('+'+Beautify(Game.computedMouseCps,1));
Game.cookieClicks++;
}
Game.lastClick=new Date().getTime();
}
l('bigCookie').onclick=Game.ClickCookie;
Game.HowMuchPrestige=function(cookies)
{
var prestige=cookies/1000000000000;
//prestige=Math.max(0,Math.floor(Math.pow(prestige,0.5)));//old version
prestige=Math.max(0,Math.floor((-1+Math.pow(1+8*prestige,0.5))/2));//geometric progression
return prestige;
}
Game.CalculatePrestige=function()
{
var prestige=Game.HowMuchPrestige(Game.cookiesReset);
Game.prestige=[];
Game.prestige['Heavenly chips']=prestige;
Game.prestige.ready=1;
}
/*=====================================================================================
CPS RECALCULATOR
=======================================================================================*/
Game.recalculateGains=1;
Game.CalculateGains=function()
{
Game.cookiesPs=0;
var mult=1;
for (var i in Game.Upgrades)
{
var me=Game.Upgrades[i];
if (me.bought>0)
{
if (me.type=='cookie' && Game.Has(me.name)) mult+=me.power*0.01;
}
}
mult+=Game.Has('Specialized chocolate chips')*0.01;
mult+=Game.Has('Designer cocoa beans')*0.02;
mult+=Game.Has('Underworld ovens')*0.03;
mult+=Game.Has('Exotic nuts')*0.04;
mult+=Game.Has('Arcane sugar')*0.05;
if (!Game.prestige.ready) Game.CalculatePrestige();
mult+=parseInt(Game.prestige['Heavenly chips'])*0.02;
for (var i in Game.Objects)
{
var me=Game.Objects[i];
me.storedCps=(typeof(me.cps)=='function'?me.cps():me.cps);
me.storedTotalCps=me.amount*me.storedCps;
Game.cookiesPs+=me.storedTotalCps;
}
if (Game.Has('Kitten helpers')) mult*=(1+Game.milkProgress*0.05);
if (Game.Has('Kitten workers')) mult*=(1+Game.milkProgress*0.1);
if (Game.Has('Kitten engineers')) mult*=(1+Game.milkProgress*0.2);
if (Game.Has('Kitten overseers')) mult*=(1+Game.milkProgress*0.3);
if (Game.frenzy>0) mult*=Game.frenzyPower;
if (Game.Has('Elder Covenant')) mult*=0.95;
Game.globalCpsMult=mult;
Game.cookiesPs*=Game.globalCpsMult;
for (var i=0;i<Game.cpsAchievs.length/2;i++)
{
if (Game.cookiesPs>=Game.cpsAchievs[i*2+1]) Game.Win(Game.cpsAchievs[i*2]);
}
Game.computedMouseCps=Game.mouseCps();
Game.recalculateGains=0;
}
/*=====================================================================================
GOLDEN COOKIE
=======================================================================================*/
Game.goldenCookie={x:0,y:0,life:0,delay:0,dur:13,toDie:1,wrath:0,chain:0,last:''};
Game.goldenCookie.reset=function()
{
Game.goldenCookie.life=0;
Game.goldenCookie.delay=0;
Game.goldenCookie.dur=13;
Game.goldenCookie.toDie=1;
Game.goldenCookie.last='';
Game.goldenCookie.chain=0;
}
Game.goldenCookie.spawn=function()
{
if (Game.goldenCookie.delay!=0 || Game.goldenCookie.life!=0) Game.Win('Cheated cookies taste awful');
var me=l('goldenCookie');
if ((Game.elderWrath==1 && Math.random()<0.33) || (Game.elderWrath==2 && Math.random()<0.66) || (Game.elderWrath==3))
{
Game.goldenCookie.wrath=1;
me.style.background='url(img/wrathCookie.png)';
}
else
{
Game.goldenCookie.wrath=0;
me.style.background='url(img/goldCookie.png)';
}
var r=Math.floor(Math.random()*360);
me.style.transform='rotate('+r+'deg)';
me.style.mozTransform='rotate('+r+'deg)';
me.style.webkitTransform='rotate('+r+'deg)';
me.style.msTransform='rotate('+r+'deg)';
me.style.oTransform='rotate('+r+'deg)';
var screen=l('game').getBoundingClientRect();
Game.goldenCookie.x=Math.floor(Math.random()*(screen.right-screen.left-128)+screen.left+64)-64;
Game.goldenCookie.y=Math.floor(Math.random()*(screen.bottom-screen.top-128)+screen.top+64)-64;
me.style.left=Game.goldenCookie.x+'px';
me.style.top=Game.goldenCookie.y+'px';
me.style.display='block';
var dur=13;
if (Game.Has('Lucky day')) dur*=2;
if (Game.Has('Serendipity')) dur*=2;
if (Game.goldenCookie.chain>0) dur=6;
Game.goldenCookie.dur=dur;
Game.goldenCookie.life=Game.fps*Game.goldenCookie.dur;
me.toDie=0;
}
Game.goldenCookie.update=function()
{
if (Game.goldenCookie.delay==0 && Game.goldenCookie.life==0) Game.goldenCookie.spawn();
if (Game.goldenCookie.life>0)
{
Game.goldenCookie.life--;
l('goldenCookie').style.opacity=1-Math.pow((Game.goldenCookie.life/(Game.fps*Game.goldenCookie.dur))*2-1,4);
if (Game.goldenCookie.life==0 || Game.goldenCookie.toDie==1)
{
if (Game.goldenCookie.life==0) Game.goldenCookie.chain=0;
var m=(5+Math.floor(Math.random()*10));
if (Game.Has('Lucky day')) m/=2;
if (Game.Has('Serendipity')) m/=2;
if (Game.goldenCookie.chain>0) m=0.05;
if (Game.Has('Gold hoard')) m=0.01;
Game.goldenCookie.delay=Math.ceil(Game.fps*60*m);
l('goldenCookie').style.display='none';
if (Game.goldenCookie.toDie==0) Game.missedGoldenClicks++;
Game.goldenCookie.toDie=0;
Game.goldenCookie.life=0;
}
}
if (Game.goldenCookie.delay>0) Game.goldenCookie.delay--;
}
Game.goldenCookie.choose=function()
{
var list=[];
if (Game.goldenCookie.wrath>0) list.push('clot','multiply cookies','ruin cookies');
else list.push('frenzy','multiply cookies');
if (Game.goldenCookie.wrath>0 && Math.random()<0.3) list.push('blood frenzy','chain cookie');
else if (Math.random()<0.01 && Game.cookiesEarned>=100000) list.push('chain cookie');
if (Math.random()<0.05) list.push('click frenzy');
if (Game.goldenCookie.last!='' && Math.random()<0.8 && list.indexOf(Game.goldenCookie.last)!=-1) list.splice(list.indexOf(Game.goldenCookie.last),1);//80% chance to force a different one
var choice=choose(list);
return choice;
}
Game.goldenCookie.click=function()
{
if (Game.goldenCookie.life>0)
{
Game.goldenCookie.toDie=1;
Game.goldenClicks++;
if (Game.goldenClicks>=1) Game.Win('Golden cookie');
if (Game.goldenClicks>=7) Game.Win('Lucky cookie');
if (Game.goldenClicks>=27) Game.Win('A stroke of luck');
if (Game.goldenClicks>=77) Game.Win('Fortune');
if (Game.goldenClicks>=777) Game.Win('Leprechaun');
if (Game.goldenClicks>=7777) Game.Win('Black cat\'s paw');
if (Game.goldenClicks>=7) Game.Unlock('Lucky day');
if (Game.goldenClicks>=27) Game.Unlock('Serendipity');
if (Game.goldenClicks>=77) Game.Unlock('Get lucky');
l('goldenCookie').style.display='none';
var choice=Game.goldenCookie.choose();
if (Game.goldenCookie.chain>0) choice='chain cookie';
Game.goldenCookie.last=choice;
if (choice!='chain cookie') Game.goldenCookie.chain=0;
if (choice=='frenzy')
{
var time=77+77*Game.Has('Get lucky');
Game.frenzy=Game.fps*time;
Game.frenzyPower=7;
Game.recalculateGains=1;
Game.Popup('Frenzy : cookie production x7 for '+time+' seconds!');
}
else if (choice=='multiply cookies')
{
var moni=Math.min(Game.cookies*0.1,Game.cookiesPs*60*20)+13;//add 10% to cookies owned (+13), or 20 minutes of cookie production - whichever is lowest
Game.Earn(moni);
Game.Popup('Lucky! +'+Beautify(moni)+' cookies!');
}
else if (choice=='ruin cookies')
{
var moni=Math.min(Game.cookies*0.05,Game.cookiesPs*60*10)+13;//lose 5% of cookies owned (-13), or 10 minutes of cookie production - whichever is lowest
moni=Math.min(Game.cookies,moni);
Game.Spend(moni);
Game.Popup('Ruin! Lost '+Beautify(moni)+' cookies!');
}
else if (choice=='blood frenzy')
{
var time=6+6*Game.Has('Get lucky');
Game.frenzy=Game.fps*time;//*2;//we shouldn't need *2 but I keep getting reports of it lasting only 3 seconds
Game.frenzyPower=666;
Game.recalculateGains=1;
Game.Popup('Elder frenzy : cookie production x666 for '+time+' seconds!');
}
else if (choice=='clot')
{
var time=66+66*Game.Has('Get lucky');
Game.frenzy=Game.fps*time;
Game.frenzyPower=0.5;
Game.recalculateGains=1;
Game.Popup('Clot : cookie production halved for '+time+' seconds!');
}
else if (choice=='click frenzy')
{
var time=13+13*Game.Has('Get lucky');
Game.clickFrenzy=Game.fps*time;
Game.recalculateGains=1;
Game.Popup('Click frenzy! Clicking power x777 for '+time+' seconds!');
}
else if (choice=='chain cookie')
{
Game.goldenCookie.chain++;
var moni='';
for (var i=0;i<Game.goldenCookie.chain;i++) {moni+='6';}
moni=parseInt(moni);
Game.Popup('Cookie chain : +'+Beautify(moni)+' cookies!');
if ((Math.random()<0.1 || Game.goldenCookie.chain>12 || moni>=Game.cookies*1) && Game.goldenCookie.chain>4) Game.goldenCookie.chain=0;
Game.Earn(moni);
}
}
}
l('goldenCookie').onclick=Game.goldenCookie.click;
/*=====================================================================================
PARTICLES
=======================================================================================*/
//falling cookies
Game.cookieParticles=[];
var str='';
for (var i=0;i<40;i++)
{
Game.cookieParticles[i]={x:0,y:0,life:-1};
str+='<div id="cookieParticle'+i+'" class="cookieParticle"></div>';
}
l('cookieShower').innerHTML=str;
Game.cookieParticlesUpdate=function()
{
for (var i in Game.cookieParticles)
{
var me=Game.cookieParticles[i];
if (me.life!=-1)
{
me.y+=me.life*0.5+Math.random()*0.5;
me.life++;
var el=me.l;
el.style.left=Math.floor(me.x)+'px';
el.style.top=Math.floor(me.y)+'px';
el.style.opacity=1-(me.life/(Game.fps*2));
if (me.life>=Game.fps*2)
{
me.life=-1;
me.l.style.opacity=0;
}
}
}
}
Game.cookieParticleAdd=function()
{
//pick the first free (or the oldest) particle to replace it
if (Game.prefs.particles)
{
var highest=0;
var highestI=0;
for (var i in Game.cookieParticles)
{
if (Game.cookieParticles[i].life==-1) {highestI=i;break;}
if (Game.cookieParticles[i].life>highest)
{
highest=Game.cookieParticles[i].life;
highestI=i;
}
}
var i=highestI;
var rect=l('cookieShower').getBoundingClientRect();
var x=Math.floor(Math.random()*(rect.right-rect.left));
var y=-32;