-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.js
4946 lines (4494 loc) · 228 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
-also includes a bunch of snippets found on stackoverflow.com
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)];}
//disable sounds coming from soundjay.com (sorry,
realAudio=Audio;//backup real audio
Audio=function(src){
if (src.indexOf('soundjay')>-1) {Game.Popup('Sorry, no sounds hotlinked from soundjay.com.');this.play=function(){};}
else return new realAudio(src);
};
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 randomFloor(x) {if ((x%1)<Math.random()) return Math.floor(x); else return Math.ceil(x);}
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='';
if (!isFinite(what)) return 'Infinity';
if (what.toString().indexOf('e')!=-1) return what.toString();
what=Math.round(what*10000000)/10000000;//get rid of weird rounding errors
if (floats>0)
{
var floater=what-Math.floor(what);
floater=Math.round(floater*10000000)/10000000;//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)
if (parseInt(floater)===0) floatPresent=0;
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)
{
//Game.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)
{
//Game.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);
function bind(scope, fn)
{
//use : bind(this,function(){this.x++;}) - returns a function where "this" refers to the scoped this
return function()
{
fn.apply(scope,arguments);
};
}
CanvasRenderingContext2D.prototype.fillPattern=function(img,X,Y,W,H,iW,iH)
{
//for when built-in patterns aren't enough
for (var y=0;y<H;y+=iH)
{
for (var x=0;x<W;x+=iW)
{
this.drawImage(img,X+x,Y+y,iW,iH);
}
}
}
function AddEvent(html_element, event_name, event_function)
{
if(html_element.attachEvent) //Internet Explorer
html_element.attachEvent("on" + event_name, function() {event_function.call(html_element);});
else if(html_element.addEventListener) //Firefox & company
html_element.addEventListener(event_name, event_function, false); //don't need the 'call' trick because in FF everything already works in the right way
}
Loader=function()//asset-loading system
{
this.loadingN=0;
this.assets=[];
this.domain='';
this.loaded=0;//callback
this.doneLoading=0;
this.Load=function(assets)
{
var assetsLoaded=[];
for (var i in assets)
{
this.loadingN++;
if (!assetsLoaded[assets[i]])
{
var img=new Image();
img.src=this.domain+assets[i];
img.onload=bind(this,this.onLoad);
this.assets[assets[i]]=img;
assetsLoaded[assets[i]]=1;
}
}
}
this.onLoad=function()
{
this.loadingN--;
if (this.doneLoading==0 && this.loadingN<=0 && this.loaded!=0)
{
this.doneLoading=1;
this.loaded();
}
}
this.getProgress=function()
{
return (1-this.loadingN/this.assets.length);
}
}
var debugStr='';
Debug=function(what)
{
if (!debugStr) debugStr=what;
else debugStr+='; '+what;
}
/*=====================================================================================
GAME INITIALIZATION
=======================================================================================*/
Game={};
Game.Launch=function()
{
Game.version=1.0411;
Game.beta=0;
Game.mobile=0;
Game.updateLog=
'<div class="section">Updates</div>'+
'<div class="subsection">'+
'<div class="title">Now working on :</div>'+
'<div class="listing">-founding a game studio</div>'+
'<div class="listing">-getting back to the mobile version</div>'+
'<div class="listing">-technical optimization <small>(game gets too slow with too many buildings on screen)</small></div>'+
'<div class="listing">-prettifying it up</div>'+
'<div class="listing">-more customization options</div>'+
'</div><div class="subsection">'+
'<div class="title">What\'s next :</div>'+
'<div class="listing">-more dungeon stuff!</div>'+
'<div class="listing">-more buildings and upgrades!</div>'+
'<div class="listing">-revamping the prestige system!</div>'+
'<div class="listing">-mobile app!</div>'+
'<div class="listing"><span class="warning">Note : this game is updated fairly frequently, which often involves rebalancing. Expect to see prices and cookies/second vary wildly from one update to another!</span></div>'+
'</div><div class="subsection update small">'+
'<div class="title">14/02/2014 - lovely rainbowcalypse</div>'+
'<div class="listing">-new building (it\'s been a while). More to come!</div>'+
'<div class="listing">-you can now trigger seasonal events to your heart\'s content (upgrade unlocks at 5000 heavenly chips)</div>'+
'<div class="listing">-new ultra-expensive batch of seasonal cookie upgrades you\'ll love to hate</div>'+
'<div class="listing">-new timer bars for golden cookie buffs</div>'+
'<div class="listing">-buildings are now hidden when you start out and appear as they become available</div>'+
'<div class="listing">-technical stuff : the game is now saved through localstorage instead of browser cookies, therefore ruining a perfectly good pun</div>'+
'</div><div class="subsection update small">'+
'<div class="title">22/12/2013 - merry fixmas</div>'+
'<div class="listing">-some issues with the christmas upgrades have been fixed</div>'+
'<div class="listing">-reindeer cookie drops are now more common</div>'+
'<div class="listing">-reindeers are now reindeer</div>'+
'</div><div class="subsection update">'+
'<div class="title">20/12/2013 - Christmas is here</div>'+
'<div class="listing">-there is now a festive new evolving upgrade in store</div>'+
'<div class="listing">-reindeer are running amok (catch them if you can!)</div>'+
'<div class="listing">-added a new option to warn you when you close the window, so you don\'t lose your un-popped wrinklers</div>'+
'<div class="listing">-also added a separate option for displaying cursors</div>'+
'<div class="listing">-all the Halloween features are still there (and having the Spooky cookies achievements makes the Halloween cookies drop much more often)</div>'+
'<div class="listing">-oh yeah, we now have <a href="http://www.redbubble.com/people/dashnet" target="_blank">Cookie Clicker shirts, stickers and hoodies</a>! (they\'re really rad)</div>'+
'</div><div class="subsection update small">'+
'<div class="title">29/10/2013 - spooky update</div>'+
'<div class="listing">-the Grandmapocalypse now spawns wrinklers, hideous elderly creatures that damage your CpS when they reach your big cookie. Thankfully, you can click on them to make them explode (you\'ll even gain back the cookies they\'ve swallowed - with interest!).</div>'+
'<div class="listing">-wrath cookie now 27% spookier</div>'+
'<div class="listing">-some other stuff</div>'+
'<div class="listing">-you should totally go check out <a href="http://candybox2.net/" target="_blank">Candy Box 2</a>, the sequel to the game that inspired Cookie Clicker</div>'+
'</div><div class="subsection update small">'+
'<div class="title">15/10/2013 - it\'s a secret</div>'+
'<div class="listing">-added a new heavenly upgrade that gives you 5% of your heavenly chips power for 11 cookies (if you purchased the Heavenly key, you might need to buy it again, sorry)</div>'+
'<div class="listing">-golden cookie chains should now work properly</div>'+
'</div><div class="subsection update small">'+
'<div class="title">15/10/2013 - player-friendly</div>'+
'<div class="listing">-heavenly upgrades are now way, way cheaper</div>'+
'<div class="listing">-tier 5 building upgrades are 5 times cheaper</div>'+
'<div class="listing">-cursors now just plain disappear with Fancy Graphics off, I might add a proper option to toggle only the cursors later</div>'+
'<div class="listing">-warning : the Cookie Monster add-on seems to be buggy with this update, you might want to wait until its programmer updates it</div>'+
'</div><div class="subsection update small">'+
'<div class="title">15/10/2013 - a couple fixes</div>'+
'<div class="listing">-golden cookies should no longer spawn embarrassingly often</div>'+
'<div class="listing">-cursors now stop moving if Fancy Graphics is turned off</div>'+
'</div><div class="subsection update small">'+
'<div class="title">14/10/2013 - going for the gold</div>'+
'<div class="listing">-golden cookie chains work a bit differently</div>'+
'<div class="listing">-golden cookie spawns are more random</div>'+
'<div class="listing">-CpS achievements are no longer affected by golden cookie frenzies</div>'+
'<div class="listing">-revised cookie-baking achievement requirements</div>'+
'<div class="listing">-heavenly chips now require upgrades to function at full capacity</div>'+
'<div class="listing">-added 4 more cookie upgrades, unlocked after reaching certain amounts of Heavenly Chips</div>'+
'<div class="listing">-speed baking achievements now require you to have no heavenly upgrades; as such, they have been reset for everyone (along with the Hardcore achievement) to better match their initially intended difficulty</div>'+
'<div class="listing">-made good progress on the mobile port</div>'+
'</div><div class="subsection update small">'+
'<div class="title">01/10/2013 - smoothing it out</div>'+
'<div class="listing">-some visual effects have been completely rewritten and should now run more smoothly (and be less CPU-intensive)</div>'+
'<div class="listing">-new upgrade tier</div>'+
'<div class="listing">-new milk tier</div>'+
'<div class="listing">-cookie chains have different capping mechanics</div>'+
'<div class="listing">-antimatter condensers are back to their previous price</div>'+
'<div class="listing">-heavenly chips now give +2% CpS again (they will be extensively reworked in the future)</div>'+
'<div class="listing">-farms have been buffed a bit (to popular demand)</div>'+
'<div class="listing">-dungeons still need a bit more work and will be released soon - we want them to be just right! (you can test an unfinished version in <a href="beta" target="_blank">the beta</a>)</div>'+
'</div><div class="subsection update">'+
'<div class="title">28/09/2013 - dungeon beta</div>'+
'<div class="listing">-from now on, big updates will come through a beta stage first (you can <a href="beta" target="_blank">try it here</a>)</div>'+
'<div class="listing">-first dungeons! (you need 50 factories to unlock them!)</div>'+
'<div class="listing">-cookie chains can be longer</div>'+
'<div class="listing">-antimatter condensers are a bit more expensive</div>'+
'<div class="listing">-heavenly chips now only give +1% cps each (to account for all the cookies made from condensers)</div>'+
'<div class="listing">-added flavor text on all upgrades</div>'+
'</div><div class="subsection update small">'+
'<div class="title">15/09/2013 - anticookies</div>'+
'<div class="listing">-ran out of regular matter to make your cookies? Try our new antimatter condensers!</div>'+
'<div class="listing">-renamed Hard-reset to "Wipe save" to avoid confusion</div>'+
'<div class="listing">-reset achievements are now regular achievements and require cookies baked all time, not cookies in bank</div>'+
'<div class="listing">-heavenly chips have been nerfed a bit (and are now awarded following a geometric progression : 1 trillion for the first, 2 for the second, etc); the prestige system will be extensively reworked in a future update (after dungeons)</div>'+
'<div class="listing">-golden cookie clicks are no longer reset by soft-resets</div>'+
'<div class="listing">-you can now see how long you\'ve been playing in the stats</div>'+
'</div><div class="subsection update small">'+
'<div class="title">08/09/2013 - everlasting cookies</div>'+
'<div class="listing">-added a prestige system - resetting gives you permanent CpS boosts (the more cookies made before resetting, the bigger the boost!)</div>'+
'<div class="listing">-save format has been slightly modified to take less space</div>'+
'<div class="listing">-Leprechaun has been bumped to 777 golden cookies clicked and is now shadow; Fortune is the new 77 golden cookies achievement</div>'+
'<div class="listing">-clicking frenzy is now x777</div>'+
'</div><div class="subsection update small">'+
'<div class="title">04/09/2013 - smarter cookie</div>'+
'<div class="listing">-golden cookies only have 20% chance of giving the same outcome twice in a row now</div>'+
'<div class="listing">-added a golden cookie upgrade</div>'+
'<div class="listing">-added an upgrade that makes pledges last twice as long (requires having pledged 10 times)</div>'+
'<div class="listing">-Quintillion fingers is now twice as efficient</div>'+
'<div class="listing">-Uncanny clicker was really too unpredictable; it is now a regular achievement and no longer requires a world record, just *pretty fast* clicking</div>'+
'</div><div class="subsection update small">'+
'<div class="title">02/09/2013 - a better way out</div>'+
'<div class="listing">-Elder Covenant is even cheaper, and revoking it is cheaper still (also added a new achievement for getting it)</div>'+
'<div class="listing">-each grandma upgrade now requires 15 of the matching building</div>'+
'<div class="listing">-the dreaded bottom cursor has been fixed with a new cursor display style</div>'+
'<div class="listing">-added an option for faster, cheaper graphics</div>'+
'<div class="listing">-base64 encoding has been redone; this might make saving possible again on some older browsers</div>'+
'<div class="listing">-shadow achievements now have their own section</div>'+
'<div class="listing">-raspberry juice is now named raspberry milk, despite raspberry juice being delicious and going unquestionably well with cookies</div>'+
'<div class="listing">-HOTFIX : cursors now click; fancy graphics button renamed; cookies amount now more visible against cursors</div>'+
'</div><div class="subsection update small">'+
'<div class="title">01/09/2013 - sorting things out</div>'+
'<div class="listing">-upgrades and achievements are properly sorted in the stats screen</div>'+
'<div class="listing">-made Elder Covenant much cheaper and less harmful</div>'+
'<div class="listing">-importing from the first version has been disabled, as promised</div>'+
'<div class="listing">-"One mind" now actually asks you to confirm the upgrade</div>'+
'</div><div class="subsection update small">'+
'<div class="title">31/08/2013 - hotfixes</div>'+
'<div class="listing">-added a way to permanently stop the grandmapocalypse</div>'+
'<div class="listing">-Elder Pledge price is now capped</div>'+
'<div class="listing">-One Mind and other grandma research upgrades are now a little more powerful, if not 100% accurate</div>'+
'<div class="listing">-"golden" cookie now appears again during grandmapocalypse; Elder Pledge-related achievements are now unlockable</div>'+
'</div><div class="subsection update">'+
'<div class="title">31/08/2013 - too many grandmas</div>'+
'<div class="listing">-the grandmapocalypse is back, along with more grandma types</div>'+
'<div class="listing">-added some upgrades that boost your clicking power and make it scale with your cps</div>'+
'<div class="listing">-clicking achievements made harder; Neverclick is now a shadow achievement; Uncanny clicker should now truly be a world record</div>'+
'</div><div class="subsection update small">'+
'<div class="title">28/08/2013 - over-achiever</div>'+
'<div class="listing">-added a few more achievements</div>'+
'<div class="listing">-reworked the "Bake X cookies" achievements so they take longer to achieve</div>'+
'</div><div class="subsection update small">'+
'<div class="title">27/08/2013 - a bad idea</div>'+
'<div class="listing">-due to popular demand, retired 5 achievements (the "reset your game" and "cheat" ones); they can still be unlocked, but do not count toward your total anymore. Don\'t worry, there will be many more achievements soon!</div>'+
'<div class="listing">-made some achievements hidden for added mystery</div>'+
'</div><div class="subsection update">'+
'<div class="title">27/08/2013 - a sense of achievement</div>'+
'<div class="listing">-added achievements (and milk)</div>'+
'<div class="listing"><i>(this is a big update, please don\'t get too mad if you lose some data!)</i></div>'+
'</div><div class="subsection update small">'+
'<div class="title">26/08/2013 - new upgrade tier</div>'+
'<div class="listing">-added some more upgrades (including a couple golden cookie-related ones)</div>'+
'<div class="listing">-added clicking stats</div>'+
'</div><div class="subsection update small">'+
'<div class="title">26/08/2013 - more tweaks</div>'+
'<div class="listing">-tweaked a couple cursor upgrades</div>'+
'<div class="listing">-made time machines less powerful</div>'+
'<div class="listing">-added offline mode option</div>'+
'</div><div class="subsection update small">'+
'<div class="title">25/08/2013 - tweaks</div>'+
'<div class="listing">-rebalanced progression curve (mid- and end-game objects cost more and give more)</div>'+
'<div class="listing">-added some more cookie upgrades</div>'+
'<div class="listing">-added CpS for cursors</div>'+
'<div class="listing">-added sell button</div>'+
'<div class="listing">-made golden cookie more useful</div>'+
'</div><div class="subsection update small">'+
'<div class="title">24/08/2013 - hotfixes</div>'+
'<div class="listing">-added import/export feature, which also allows you to retrieve a save game from the old version (will be disabled in a week to prevent too much cheating)</div>'+
'<div class="listing">-upgrade store now has unlimited slots (just hover over it), due to popular demand</div>'+
'<div class="listing">-added update log</div>'+
'</div><div class="subsection update">'+
'<div class="title">24/08/2013 - big update!</div>'+
'<div class="listing">-revamped the whole game (new graphics, new game mechanics)</div>'+
'<div class="listing">-added upgrades</div>'+
'<div class="listing">-much safer saving</div>'+
'</div><div class="subsection update">'+
'<div class="title">08/08/2013 - game launch</div>'+
'<div class="listing">-made the game in a couple hours, for laughs</div>'+
'<div class="listing">-kinda starting to regret it</div>'+
'<div class="listing">-ah well</div>'+
'</div>'
;
Game.ready=0;
/*
What we should load in here :
-heavy images
-images that are displayed on and off (flashing backgrounds etc)
-images used in <canvas> stuff
*/
Game.toLoad=[
'perfectCookie.png',
'goldCookie.png',
'wrathCookie.png',
'spookyCookie.png',
'icons.png',
'cookieShower1.png',
'cookieShower2.png',
'cookieShower3.png',
'milkWave.png',
'chocolateMilkWave.png',
'raspberryWave.png',
'orangeWave.png',
'caramelWave.png',
'grandmas1.jpg',
'grandmas2.jpg',
'grandmas3.jpg',
'bgBlue.jpg',
'blackGradient.png',
'shine.png',
'shadedBorders.png',
'shadedBordersRed.png',
'shadedBordersGold.png',
'smallCookies.png',
'cursor.png',
'wrinkler.png',
'winterWrinkler.png',
'wrinklerBits.png',
'grandmaIcon.png',
'grandmaIconB.png',
'grandmaIconC.png',
'grandmaIconD.png',
'santa.png',
'frostedReindeer.png',
'snow2.jpg',
'winterFrame.png',
'hearts.png',
'heartStorm.png'
];
Game.Load=function()
{
l('javascriptError').innerHTML='<div style="padding:64px 128px;"><div class="title">Loading...</div></div>';
Game.Loader=new Loader();
Game.Loader.domain='img/';
Game.Loader.loaded=Game.Init;
Game.Loader.Load(Game.toLoad);
Game.Assets=Game.Loader.assets;
}
Game.Init=function()
{
Game.ready=1;
/*=====================================================================================
VARIABLES AND PRESETS
=======================================================================================*/
Game.T=0;
Game.drawT=0;
Game.fps=30;
Game.baseSeason='valentines';//halloween, christmas, valentines
Game.season=Game.baseSeason;
if (Game.mobile==1)
{
l('wrapper').className='mobile';
}
Game.SaveTo='CookieClickerGame';
if (Game.beta) Game.SaveTo='CookieClickerGameBeta';
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.frenzyMax=0;//how high was our initial burst
Game.frenzyPower=1;
Game.clickFrenzy=0;//as long as >0, mouse clicks get 777x more cookies
Game.clickFrenzyMax=0;//how high was our initial burst
Game.cookieClicks=0;//+1 for each click on the cookie
Game.goldenClicks=0;//+1 for each golden cookie clicked (all time)
Game.goldenClicksLocal=0;//+1 for each golden cookie clicked (this game only)
Game.missedGoldenClicks=0;//+1 for each golden cookie missed
Game.handmadeCookies=0;//all the cookies made from clicking the cookie
Game.milkProgress=0;//you gain a little bit for each achievement. Each increment of 1 is a different milk displayed.
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.resets=0;//reset counter
Game.elderWrath=0;
Game.elderWrathD=0;
Game.pledges=0;
Game.pledgeT=0;
Game.researchT=0;
Game.nextResearch=0;
Game.cookiesSucked=0;//cookies sucked by wrinklers
Game.cpsSucked=0;//percent of CpS being sucked by wrinklers
Game.wrinklersPopped=0;
Game.santaLevel=0;
Game.reindeerClicked=0;
Game.seasonT=0;
Game.seasonUses=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());//when we started playing
Game.fullDate=parseInt(new Date().getTime());//when we started playing (carries over with resets)
Game.lastDate=parseInt(new Date().getTime());//when we last saved the game (used to compute "cookies made since we closed the game" etc)
var timers=['frenzy','elderFrenzy','clot','clickFrenzy'];
var str='';
for (var i in timers)
{
str+='<div id="timer-'+timers[i]+'"></div>';
}
l('timers').innerHTML=str;
Game.timersEl=[];
for (var i in timers)
{
Game.timersEl[timers[i]]=l('timer-'+timers[i]);
}
Game.prefs=[];
Game.DefaultPrefs=function()
{
Game.prefs.particles=1;//particle effects : falling cookies etc
Game.prefs.numbers=1;//numbers that pop up when clicking the cookie
Game.prefs.autosave=1;//save the game every minute or so
Game.prefs.autoupdate=1;//send an AJAX request to the server every 30 minutes (crashes the game when playing offline)
Game.prefs.milk=1;//display milk
Game.prefs.fancy=1;//CSS shadow effects (might be heavy on some browsers)
Game.prefs.warn=0;//warn before closing the window
Game.prefs.cursors=1;//display cursors
}
Game.DefaultPrefs();
window.onbeforeunload=function(event)
{
if (Game.prefs.warn)
{
if (typeof event=='undefined') event=window.event;
if (event) event.returnValue='Are you sure you want to close Cookie Clicker?\n(you might have some un-popped wrinklers!)';
}
}
Game.Mobile=function()
{
if (!Game.mobile)
{
l('wrapper').className='mobile';
Game.mobile=1;
}
else
{
l('wrapper').className='';
Game.mobile=0;
}
}
/*=====================================================================================
UPDATE CHECKER
=======================================================================================*/
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';
}
}
Game.useLocalStorage=1;
//window.localStorage.clear();//won't switch back to cookie-based if there is localStorage info
/*=====================================================================================
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?
{
Game.lastDate=parseInt(new Date().getTime());
var str='';
str+=Game.version+'|';
str+='|';//just in case we need some more stuff here
str+=//save stats
parseInt(Game.startDate)+';'+
parseInt(Game.fullDate)+';'+
parseInt(Game.lastDate)+
'|';
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')+
(Game.prefs.warn?'1':'0')+
(Game.prefs.cursors?'1':'0')+
'|';
str+=parseFloat(Game.cookies).toString()+';'+
parseFloat(Game.cookiesEarned).toString()+';'+
parseInt(Math.floor(Game.cookieClicks))+';'+
parseInt(Math.floor(Game.goldenClicks))+';'+
parseFloat(Game.handmadeCookies).toString()+';'+
parseInt(Math.floor(Game.missedGoldenClicks))+';'+
parseInt(Math.floor(Game.backgroundType))+';'+
parseInt(Math.floor(Game.milkType))+';'+
parseFloat(Game.cookiesReset).toString()+';'+
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))+';'+
parseInt(Math.floor(Game.resets))+';'+
parseInt(Math.floor(Game.goldenClicksLocal))+';'+
parseFloat(Game.cookiesSucked).toString()+';'+
parseInt(Math.floor(Game.wrinklersPopped))+';'+
parseInt(Math.floor(Game.santaLevel))+';'+
parseInt(Math.floor(Game.reindeerClicked))+';'+
parseInt(Math.floor(Game.seasonT))+';'+
parseInt(Math.floor(Game.seasonUses))+';'+
(Game.season)+';'+
'|';//cookies
for (var i in Game.Objects)//buildings
{
var me=Game.Objects[i];
str+=me.amount+','+me.bought+','+Math.floor(me.totalCookies)+','+(me.specialUnlocked?1:0)+';';
}
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
{
if (Game.useLocalStorage)
{
//so we used to save the game using browser cookies, which was just really neat considering the game's name
//we're using localstorage now, which is more efficient but not as cool
//a moment of silence for our fallen puns
str=utf8_to_b64(str)+'!END!';
str=escape(str);
window.localStorage.setItem(Game.SaveTo,str);//aaand save
if (!window.localStorage.getItem(Game.SaveTo)) Game.Popup('Error while saving.<br>Export your save instead!');
else Game.Popup('Game saved');
}
else//legacy system
{
//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!';
Game.saveData=escape(str);
str=Game.SaveTo+'='+escape(str)+'; expires='+now.toUTCString()+';';
document.cookie=str;//aaand save
if (document.cookie.indexOf(Game.SaveTo)<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 (Game.useLocalStorage)
{
var localStorage=window.localStorage.getItem(Game.SaveTo);
if (!localStorage)//no localstorage save found ? let's get the cookie one last time
{
if (document.cookie.indexOf(Game.SaveTo)>=0) str=unescape(document.cookie.split(Game.SaveTo+'=')[1]);
}
else
{
str=unescape(localStorage);
}
}
else//legacy system
{
if (document.cookie.indexOf(Game.SaveTo)>=0) str=unescape(document.cookie.split(Game.SaveTo+'=')[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 (isNaN(version) || str.length<5) {Game.Popup('Oops, looks like the import string is all wrong!');return 0;}
if (version>=1 && version>Game.version)
{
alert('Error : you are attempting to load a save from a future version (v.'+version+'; you are using v.'+Game.version+').');
return 0;
}
else if (version>=1)
{
spl=str[2].split(';');//save stats
Game.startDate=parseInt(spl[0]);
Game.fullDate=parseInt(spl[1]);
Game.lastDate=parseInt(spl[2]);
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');
Game.prefs.warn=spl[6]?parseInt(spl[6]):0;
Game.prefs.cursors=spl[7]?parseInt(spl[7]):0;
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;
Game.resets=spl[14]?parseInt(spl[14]):0;
Game.goldenClicksLocal=spl[15]?parseInt(spl[15]):0;
Game.cookiesSucked=spl[16]?parseFloat(spl[16]):0;
Game.wrinklersPopped=spl[17]?parseInt(spl[17]):0;
Game.santaLevel=spl[18]?parseInt(spl[18]):0;
Game.reindeerClicked=spl[19]?parseInt(spl[19]):0;
Game.seasonT=spl[20]?parseInt(spl[20]):0;
Game.seasonUses=spl[21]?parseInt(spl[21]):0;
Game.season=spl[22]?spl[22]:Game.baseSeason;
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.amount=0;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 && me.hide!=3) 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 && me.hide!=3) 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++;
}
}
if (version<1.038)
{
Game.Achievements['Hardcore'].won=0;
Game.Achievements['Speed baking I'].won=0;
Game.Achievements['Speed baking II'].won=0;
Game.Achievements['Speed baking III'].won=0;
}
for (var i in Game.ObjectsById)
{
var me=Game.ObjectsById[i];
if (me.buyFunction) me.buyFunction();
me.setSpecial(0);
if (me.special && me.specialUnlocked==1) me.special();
me.refresh();
}
Game.ResetWrinklers();
/*//why was this here ?
Game.cookiesSucked=0;
Game.wrinklersPopped=0;
Game.santaLevel=0;
Game.reindeerClicked=0;
*/
//recompute season trigger prices
Game.computeSeasonPrices();
Game.CalculateGains();
//compute cookies earned while the game was closed
if (Game.mobile || Game.Has('Perfect idling'))
{
var amount=((new Date().getTime()-Game.lastDate)/1000)*Game.cookiesPs;
if (amount>0)
{
Game.Popup('Earned '+Beautify(amount)+' cookie'+(Math.floor(amount)==1?'':'s')+' while you were away');
Game.Earn(amount);
}