forked from eternaldensity/Sandcastle-Builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcastle.js
3278 lines (3116 loc) · 89.4 KB
/
castle.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
'use strict';
/* In which some Helper functions are defined
+++++++++++++++++++++++++++++++++++++++++++++*/
function ONGsnip(time)
{
if(time.getMinutes()>=30&&Math.abs(Molpy.newpixNumber) <= 240)
{
time.setMinutes(30);
}else
{
time.setMinutes(0);
}
time.setSeconds(0);
time.setMilliseconds(0);
return time;
}
var postfixes=[
{limit:1e210,divisor:1e210,postfix:['Q',' Quita']},
{limit:1e42,divisor:1e42,postfix:['W',' Wololo']},
{limit:1e39,divisor:1e39,postfix:['L',' Lotta']},
{limit:1e36,divisor:1e36,postfix:['F',' Ferro']},
{limit:1e33,divisor:1e33,postfix:['H',' Helo']}, //or Ballard
{limit:1e30,divisor:1e30,postfix:['S',' Squilli']},
{limit:1e27,divisor:1e27,postfix:['U',' Umpty']},
{limit:1e24,divisor:1e24,postfix:['Y',' Yotta']},
{limit:1e21,divisor:1e21,postfix:['Z',' Zeta']},
{limit:1e18,divisor:1e18,postfix:['E',' Exa']},
{limit:1e15,divisor:1e15,postfix:['P',' Peta']},
{limit:1e12,divisor:1e12,postfix:['T',' Tera']},
{limit:1e9,divisor:1e9,postfix:['G',' Giga']},
{limit:1e6,divisor:1e6,postfix:['M',' Mega']},
{limit:9e3,divisor:1e3,postfix:['K',' Kilo']}, //WHAT
];
function Molpify(number, raftcastle, shrinkify)
{
if(isNaN(number))return'Mustard';
if(!isFinite(parseFloat(number)))return'Infinite';
if(number<0)return '-'+Molpify(-number,raftcastle,shrinkify);
var molp='';
if(shrinkify==2)shrinkify=0;
else if(Molpy&&!shrinkify)shrinkify=!Molpy.options.science;
if(shrinkify)
{
for (var i in postfixes)
{
var p = postfixes[i];
if(number>=p.limit)
{
return Molpify(number / p.divisor, raftcastle,1)+p.postfix[Molpy.options.longpostfix];
}
}
}else{
if(number==3)return 'Math.floor(Math.PI)';
if(number==4)return 'Math.ceil(Math.PI)';
}
if(raftcastle>0)
{
var numCopy=number;
//get the right number of decimal places to stick on the end:
var raft=numCopy*Math.pow(10,raftcastle)-Math.floor(numCopy)*Math.pow(10,raftcastle);
var sraft = Math.floor(raft)+'';
if((sraft).length>raftcastle)
{
numCopy++;
sraft=''; //rounded decimal part up to 1
}else if(raft) while(sraft.length<raftcastle)
{
sraft='0'+sraft; //needs leading zeroes because it's a number like 1.01
}
molp=Molpify(numCopy,0,shrinkify)+(raft?('.'+sraft):''); //stick them on the end if there are any
}else
{
number = Math.floor(number);
//drop the decimal bit
var sep = (number+'').indexOf('e') ==-1; //true if not in exponential notation
number=(number+'').split('').reverse(); //convert to string, then array of chars, then backwards
for(var i in number)
{
if(sep&&i%3==0 &&i>0) molp=','+molp;//stick commas in every 3rd spot but not 0th
molp=number[i]+molp;
}
if(!sep)
{
var dot=molp.indexOf('.')+1;
var exp=molp.indexOf('e');
molp=molp.slice(0,dot)+molp.slice(dot,exp).slice(0,6)+molp.slice(exp);//truncate after 6 decimal places
}
}
return molp;
}
/* In which the game initialisation is specified
++++++++++++++++++++++++++++++++++++++++++++++++*/
Molpy.Up=function()
{
Molpy.molpish=0;
Molpy.Wake=function()
{
Molpy.molpish=0;
Molpy.HardcodedData();//split some stuff into separate file
/* In which variables are declared
++++++++++++++++++++++++++++++++++*/
Molpy.Life=0; //number of gameticks that have passed
Molpy.fps = 30 //this is just for paint, not updates
Molpy.time=new Date().getTime();
Molpy.newpixNumber=1; //to track which background to load, and other effects...
Molpy.ONGstart= ONGsnip(new Date()); //contains the time of the previous ONG
Molpy.NPlength=1800; //seconds in current NewPix (or milliseconds in milliNewPix)
Molpy.updateFactor=1; //increase to update more often
Molpy.options=[];
Molpy.lateness=0;
Molpy.ketchupTime=0;
Molpy.baseNinjaTime=12*60*1000; //12 minutes for newpixbot delay
Molpy.ninjaTime=Molpy.baseNinjaTime;
Molpy.ninjad=0; //ninja flag for newpixbots
Molpy.npbONG=0; //activation flag for newpixbots
Molpy.sandDug=0; //total sand dug throughout the game
Molpy.sandManual=0; //total sand dug through user clicks
Molpy.chipsManual=0;
Molpy.sand=0; //current sand balance
Molpy.castlesBuilt=0; //total castles built throughout the game
Molpy.castles=0; //current castle balance
Molpy.castlesDestroyed=0; //total castles destroyed by other structures throughout the game
Molpy.sandPermNP=0; //sand per milliNewPix (recaculated when stuff is bought)
Molpy.glassPermNP=0;
Molpy.prevCastleSand=0; //sand cost of previous castle
Molpy.nextCastleSand=1; //sand cost of next castle
Molpy.castlesSpent=0; //castles spent in shop
Molpy.sandSpent=0; //sand spent on Boosts
Molpy.beachClicks=0; //number of times beach has been clicked for sand
Molpy.ninjaFreeCount=0; //newpix with no clicks in ninja period (but with clicks later)
Molpy.ninjaStealth=0; //streak of uninterrupted ninja-free newpix
Molpy.saveCount=0; //number of times game has been saved
Molpy.loadCount=0; //number of times gave has been loaded
Molpy.autosaveCountup=0;
Molpy.highestNPvisited=1; //keep track of where the player has been
Molpy.timeTravels=0; //number of times timetravel has been used
Molpy.totalCastlesDown=0; //cumulative castles built and then wiped by Molpy Down throughout all games
Molpy.globalCastleMult=1; //for boosting castle gains
Molpy.lGlass=0;
Molpy.totalGlassBuilt=0;
Molpy.totalGlassDestroyed=0;
Molpy.toolsBuilt=0;
Molpy.toolsBuiltTotal=0;
Molpy.blockspmnp = 0;
Molpy.chipspmnp = 0;
Molpy.DefinePersist();
Molpy.DefineGUI();
/* In which the mathematical methods of sandcastles are described
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
var sandEpsilon = 0.0000001; //because floating point errors
var previousSand=0;
Molpy.Dig=function(amount)
{
var oldSand=Molpy.sand;
if(!isFinite(Molpy.sand))amount=0; //because why bother?
Molpy.sandDug+=amount;
Molpy.sand+=amount;
if(isNaN(Molpy.sandDug))Molpy.sandDug=0;
var gap = Math.ceil(Molpy.sand)-Molpy.sand;
if(gap && gap < sandEpsilon)
{
Molpy.sand = Math.ceil(Molpy.sand);
Molpy.sandDug = Math.ceil(Molpy.sandDug);
Molpy.EarnBadge('Clerical Error');
}
Molpy.SandToCastles();
if(isFinite(previousSand)!=isFinite(Molpy.sand)
||isFinite(oldSand)!=isFinite(Molpy.sand))
Molpy.recalculateDig=1;
previousSand=Molpy.sand;
if(Molpy.sand>=50){
Molpy.EarnBadge('Barn');
}
if(Molpy.sand>=200){
Molpy.EarnBadge('Storehouse');
}
if(Molpy.sand>=500){
Molpy.EarnBadge('Bigger Barn');
}
if(Molpy.sandDug>=5000)Molpy.UnlockBoost('Molpies');
if(Molpy.sand>=8000){
Molpy.EarnBadge('Warehouse');
}
if(Molpy.sand>=300000){
Molpy.EarnBadge('Sand Silo');
}
if(Molpy.sand>=7000000){
Molpy.EarnBadge('Silicon Valley');
}
if(Molpy.sand>=80000000){
Molpy.EarnBadge('Glass Factory');
Molpy.UnlockBoost('Glass Furnace');
}
if(Molpy.sand>=420000000){
Molpy.EarnBadge('Seaish Sands');
}
if(Molpy.sand>=123456789){
Molpy.EarnBadge('You can do what you want');
}
if(Molpy.sand>=782222222144){
Molpy.EarnBadge('Store ALL of the sand');
}
}
Molpy.SandToCastles=function()
{
Molpy.buildNotifyFlag=0;
while(Molpy.sand >= Molpy.nextCastleSand && isFinite(Molpy.castles))
{
if(Molpy.Got('Fractal Sandcastles'))
{
var m=1.35;
if(Molpy.Got('Fractal Fractals')) m = 1.5;
Molpy.Build(Math.floor(Math.pow(m,Molpy.Boosts['Fractal Sandcastles'].power)));
Molpy.Boosts['Fractal Sandcastles'].power++;
if(Molpy.Boosts['Fractal Sandcastles'].power>=60)
{
Molpy.EarnBadge('Fractals Forever');
}
}else{
Molpy.Build(1);
}
Molpy.sand -= Molpy.nextCastleSand;
Molpy.currentCastleSand = Molpy.nextCastleSand;
//In which Fibbonacci occurs:
Molpy.nextCastleSand = Molpy.prevCastleSand+Molpy.currentCastleSand;
if(Molpy.nextCastleSand > 80) Molpy.EarnBadge('Getting Expensive');
Molpy.prevCastleSand=Molpy.currentCastleSand
if(!isFinite(Molpy.sand) || Molpy.nextCastleSand<=0)
{
Molpy.nextCastleSand=1;
Molpy.castles=Infinity;
Molpy.castlesBuilt=Infinity;
return;
}
}
Molpy.buildNotifyFlag=1;
Molpy.Build(0);
if(isNaN(Molpy.sand))
{
Molpy.sand=0;
Molpy.EarnBadge('Mustard Cleanup');
}
if(isNaN(Molpy.castles))
{
Molpy.castles=0;
Molpy.EarnBadge('Mustard Cleanup');
}
if(isNaN(Molpy.castlesBuilt))
{
Molpy.castlesBuilt=0;
Molpy.EarnBadge('Mustard Cleanup');
}
}
Molpy.buildNotifyFlag=1;
Molpy.buildNotifyCount=0;
Molpy.Build=function(amount,refund)
{
if(!isFinite(Molpy.castles))
{
amount=0; //no point in adding any more
}
if(!refund&&amount)//don't multiply if amount is 0
{
amount = Math.round(amount*Molpy.globalCastleMult)||0;
}
amount = Math.max(0,amount);
Molpy.castlesBuilt+=amount;
Molpy.castles+=amount;
if(amount&&!isFinite(Molpy.castles))Molpy.recalculateDig=1;
if(Molpy.buildNotifyFlag)
{
if(Molpy.buildNotifyCount)
{
amount+=Molpy.buildNotifyCount;
Molpy.buildNotifyCount=0;
}
if(amount){
if(amount >= Molpy.castles/10000000)
Molpy.Notify(amount==1?'+1 Castle':Molpify(amount,3)+ ' Castles Built',1);
else
Molpy.buildNotifyCount+=amount;
}
}else{
Molpy.buildNotifyCount+=amount;
}
if(Molpy.castlesBuilt>=1){
Molpy.EarnBadge('Rook');
}
if(Molpy.castlesBuilt>=4){
Molpy.EarnBadge('Enough for Chess');
}
if(Molpy.castlesBuilt>=40){
Molpy.EarnBadge('Fortified');
}
if(Molpy.castlesBuilt>=320){
Molpy.EarnBadge('All Along the Watchtower');
}
if(Molpy.castlesBuilt>=1000){
Molpy.EarnBadge('Megopolis');
}
if(Molpy.castlesBuilt>=100000){
Molpy.EarnBadge('Kingdom');
}
if(Molpy.castlesBuilt>=10000000){
Molpy.EarnBadge('Empire');
}
if(Molpy.castlesBuilt>=1000000000){
Molpy.EarnBadge('Reign of Terror');
}
if(Molpy.castlesBuilt>=2000000000000){
Molpy.EarnBadge('Unreachable?');
Molpy.UnlockBoost("Château d'If");
}
if(Molpy.castles>=1000){
Molpy.EarnBadge('We Need a Bigger Beach');
}
if(Molpy.castles>=1000000){
Molpy.EarnBadge('Castle Nation');
}
if(Molpy.castles>=1000000000){
Molpy.EarnBadge('Castle Planet');
}
if(Molpy.castles>=1000000000000){
Molpy.EarnBadge('Castle Star');
}
if(Molpy.castles>=8888000000000000){
Molpy.EarnBadge('Castle Galaxy');
}
if(Molpy.castles>=DeMolpify('1P')){
Molpy.EarnBadge('People Eating Tasty Animals');
}
if(Molpy.castles>=DeMolpify('20P')){
Molpy.UnlockBoost('Free Advice');
}
if(Molpy.castles>=DeMolpify('1Y')){
Molpy.EarnBadge('Y U NO RUN OUT OF SPACE?');
}
if(Molpy.castles>=DeMolpify('1U')){
Molpy.EarnBadge('Dumpty');
}
if(Molpy.castles>=DeMolpify('1S')){
Molpy.EarnBadge('This is a silly number');
}
if(Molpy.castles>=DeMolpify('1H')){
Molpy.EarnBadge('To Da Choppah');
}
if(Molpy.castles>=DeMolpify('1F')){
Molpy.EarnBadge('Toasters');
}
if(Molpy.castles>=DeMolpify('1W')){
Molpy.EarnBadge('Dubya');
}
if(Molpy.castles>=DeMolpify('1WW')){
Molpy.EarnBadge('Rub a Dub Dub');
}
if(Molpy.castles>=DeMolpify('1WWW')){
Molpy.EarnBadge('WWW');
}
if(Molpy.castles>=DeMolpify('1WWWW')){
Molpy.EarnBadge('Age of Empires');
}
if(Molpy.castles>=DeMolpify('1Q')){
Molpy.EarnBadge('Queue');
}
if(Molpy.castles>=DeMolpify('1WQ')){
Molpy.EarnBadge('What Queue');
}
if(!isFinite(Molpy.castles)&&!isFinite(Molpy.sand)){
Molpy.EarnBadge('Everything but the Kitchen Windows');
}
}
Molpy.MakeChips=function(times)
{
var furnaceLevel=(Molpy.Boosts['Sand Refinery'].power)+1;
if (times) furnaceLevel*=times;
Molpy.AddChips(furnaceLevel,1);
}
Molpy.chipAddAmount=0;
Molpy.chipWasteAmount=0;
Molpy.AddChips=function(amount,expand)
{
Molpy.UnlockBoost('GlassChips');
var ch = Molpy.Boosts['GlassChips'];
if(!ch.bought)
{
ch.buy();
}
ch.power+=amount;
var waste = Math.max(0,ch.power-(ch.bought)*10);
if (waste && expand && Molpy.Boosts['Stretchable Chip Storage'].power)
{
ch.power -= amount;
ch.bought += Math.floor(amount/4.5);
}
else
{
if (waste)
{
ch.power-=waste;
amount-=waste;
Molpy.chipWasteAmount+=waste;
if (expand && Molpy.chipWasteAmount > 1000000) Molpy.UnlockBoost('Stretchable Chip Storage');
}
Molpy.chipAddAmount+=amount;
}
Molpy.RefreshGlass();
}
Molpy.blockAddAmount=0;
Molpy.blockWasteAmount=0;
Molpy.MakeBlocks=function(times)
{
var chillerLevel=(Molpy.Boosts['Glass Chiller'].power)+1;
if (times) chillerLevel*=times;
var chipsFor=chillerLevel;
var ch = Molpy.Boosts['GlassChips'];
var rate=Molpy.ChipsPerBlock();
var backoff = 1;
while(ch.power < chipsFor*rate)
{
chipsFor-= backoff;
backoff*=2;
}
if(chipsFor <= 0)
{
Molpy.Notify('Not enough Glass Chips to make any Blocks',1);
return;
}else if (chipsFor<chillerLevel){
Molpy.Notify('Running low on Glass Chips!');
chillerLevel=chipsFor;
}
ch.power-=chipsFor*rate;
Molpy.chipAddAmount-=chipsFor*rate;
Molpy.AddBlocks(chillerLevel,1);
}
Molpy.AddBlocks=function(amount,expand)
{
Molpy.UnlockBoost('GlassBlocks');
var bl = Molpy.Boosts['GlassBlocks'];
if(!bl.bought)
{
bl.buy();
}
bl.power+=amount;
var waste = Math.max(0,bl.power-(bl.bought)*50);
if (waste && expand && Molpy.Boosts['Stretchable Block Storage'].power)
{
bl.power -= amount;
bl.bought += Math.floor(amount/13.5);
}
else
{
if (waste)
{
bl.power-=waste;
amount-=waste;
Molpy.blockWasteAmount+=waste;
if (expand && Molpy.blockWasteAmount > 1000000) Molpy.UnlockBoost('Stretchable Block Storage');
}
if(amount) Molpy.EarnBadge('Glassblower');
Molpy.blockAddAmount+=amount;
}
Molpy.RefreshGlass();
}
Molpy.glassNotifyFactor=1000000000;
Molpy.GlassNotifyFlush=function()
{
Molpy.chipAddAmount=Math.round(Molpy.chipAddAmount);
Molpy.chipWasteAmount=Math.round(Molpy.chipWasteAmount);
Molpy.blockAddAmount=Math.round(Molpy.blockAddAmount);
Molpy.blockWasteAmount=Math.round(Molpy.blockWasteAmount);
if(Molpy.chipAddAmount>0 && !Molpy.Boosts['AA'].power && Molpy.chipAddAmount*Molpy.glassNotifyFactor > Molpy.Boosts['GlassChips'].power)
Molpy.Notify('Gained '+Molpify(Molpy.chipAddAmount,3)+' Glass Chip'+plural(Molpy.chipAddAmount),1);
if(Molpy.chipAddAmount<0 && (-Molpy.chipAddAmount*Molpy.glassNotifyFactor) > Molpy.Boosts['GlassChips'].power)
Molpy.Notify('Consumed '+Molpify(-Molpy.chipAddAmount,3)+' Glass Chip'+plural(-Molpy.chipAddAmount),1);
Molpy.chipAddAmount=0;
if(Molpy.chipWasteAmount>0)
Molpy.Notify('Not enough Chip Storage for '+Molpify(Molpy.chipWasteAmount)+' Glass Chip'+plural(Molpy.chipWasteAmount),1);
Molpy.chipWasteAmount=0;
if(Molpy.blockAddAmount>0 && !Molpy.Boosts['AA'].power && Molpy.blockAddAmount*Molpy.glassNotifyFactor > Molpy.Boosts['GlassBlocks'].power)
Molpy.Notify('Gained '+Molpify(Molpy.blockAddAmount,3)+' Glass Block'+plural(Molpy.blockAddAmount),1);
if(Molpy.blockAddAmount<0 && (-Molpy.blockAddAmount*Molpy.glassNotifyFactor) > Molpy.Boosts['GlassBlocks'].power)
Molpy.Notify('Consumed '+Molpify(-Molpy.blockAddAmount,3)+' Glass Block'+plural(-Molpy.blockAddAmount),1);
Molpy.blockAddAmount=0;
if(Molpy.blockWasteAmount>0)
Molpy.Notify('Not enough Block Storage for '+Molpify(Molpy.blockWasteAmount,3)+' Glass Block'+plural(Molpy.blockWasteAmount),1);
Molpy.blockWasteAmount=0;
}
Molpy.DigGlass=function(amount)
{
Molpy.totalGlassBuilt+=amount;
Molpy.Boosts['Tool Factory'].power+=amount;
}
Molpy.DestroyGlass=function(amount)
{
var tf=Molpy.Boosts['Tool Factory'];
amount=Math.min(tf.power,amount);
tf.power-=amount;
Molpy.totalGlassDestroyed+=amount;
}
Molpy.SpendCastles=function(amount,silent)
{
if(!amount)return;
amount = Math.min(amount,Molpy.castles);
Molpy.castles-=amount;
Molpy.castlesSpent+=amount;
if(isNaN(Molpy.castles))
{
Molpy.castles=0;
Molpy.EarnBadge('Mustard Cleanup');
}
if(!silent&&(isFinite(Molpy.castles)||!isFinite(amount)))
Molpy.Notify('Spent Castles: ' + Molpify(amount,3),1);
}
Molpy.spendSandNotifyFlag=1;
Molpy.spendSandNotifyCount=0;
Molpy.SpendSand=function(amount,silent)
{
if(!amount)return;
Molpy.sand-=amount;
if(Molpy.sand<0)Molpy.sand=0;
Molpy.sandSpent+=amount;
if((isFinite(Molpy.sand)||!isFinite(amount)))
{
if(!silent&&Molpy.spendSandNotifyFlag)
{
if(Molpy.spendSandNotifyCount)
{
amount+=Molpy.spendSandNotifyCount;
Molpy.spendSandNotifyCount=0;
}
if(amount){
if(amount >= Molpy.sand/10000000)
Molpy.Notify('Spent Sand: ' + Molpify(amount,3),1);
else
{
Molpy.spendSandNotifyCount+=amount;
return 1;
}
}
}else{
Molpy.spendSandNotifyCount+=amount;
return 1;
}
}
}
Molpy.destroyNotifyFlag=1;
Molpy.destroyNotifyCount=0;
Molpy.Destroy=function(amount,logsilent)
{
amount = Math.min(amount,Molpy.castles);
Molpy.castles-=amount;
Molpy.castlesDestroyed+=amount;
if(Molpy.destroyNotifyFlag)
{
if(Molpy.destroyNotifyCount)
{
amount+=Molpy.destroyNotifyCount;
Molpy.destroyNotifyCount=0;
}
if(amount){
if(amount >= Molpy.castles/10000000)
Molpy.Notify(amount==1?'-1 Castle':Molpify(amount,3)+ ' Castles Destroyed',!logsilent);
else
{
Molpy.destroyNotifyCount+=amount;
return 1;
}
}
}else{
Molpy.destroyNotifyCount+=amount;
return 1;
}
//destroying is done by trebuchets and stuff: it's different to spending
}
Molpy.sandPerClick=function()
{
var baserate=1 + Molpy.Got('Bigger Buckets')*0.1;
var mult=1;
if(Molpy.Got('Huge Buckets'))mult*=2;
if(Molpy.Got('Buccaneer'))mult*=2;
baserate*=mult;
if(Molpy.Got('Helpful Hands'))
{
var pairs = Math.min(Molpy.SandTools['Bucket'].amount, Molpy.SandTools['Cuegan'].amount);
baserate+=0.5*pairs;
}
if(Molpy.Got('True Colours'))
{
var pairs = Math.min(Molpy.SandTools['Flag'].amount, Molpy.SandTools['Cuegan'].amount);
baserate+=5*pairs;
}
if(Molpy.Got('Raise the Flag'))
{
var pairs = Math.min(Molpy.SandTools['Flag'].amount, Molpy.SandTools['Ladder'].amount);
baserate+=50*pairs;
}
if(Molpy.Got('Hand it Up'))
{
var pairs = Math.min(Molpy.SandTools['Bag'].amount, Molpy.SandTools['Ladder'].amount);
baserate+=500*pairs;
}
if(Molpy.Got('Bucket Brigade'))
{
baserate+=Molpy.sandPermNP*0.01*Math.floor(Molpy.SandTools['Bucket'].amount/50);
}
if(Molpy.Got('Bag Puns'))
{
baserate+= baserate*(4/10)*Math.max(-2,Math.floor((Molpy.SandTools['Bag'].amount-25)/5));
}
return baserate;
}
Molpy.computedSandPerClick=1;
Molpy.globalSpmNPMult=1;
Molpy.globalGpmNPMult=1;
Molpy.lastClick=0;
Molpy.chipsPerClick=0;
Molpy.ClickBeach=function(event, leopard)
{
if(!Molpy.layoutLocked&&!leopard)
{
Molpy.Notify('You cannnot click here while the layout is unlocked but you can use your leopard');
return;
}
var newsand=Molpy.computedSandPerClick;
Molpy.Dig(newsand);
if(newsand&&Molpy.options.numbers) Molpy.AddSandParticle('+'+Molpify(newsand,1));
Molpy.sandManual+=newsand;
if(isNaN(Molpy.sandManual))Molpy.sandManual=0;
if(!isFinite(Molpy.sand)&&Molpy.Got('BG'))
{
Molpy.chipsPerClick=Molpy.BoostsOwned*4
if(Molpy.Got('GM'))
{
Molpy.chipsPerClick+=Molpy.glassPermNP/20;
}
Molpy.Boosts['Tool Factory'].power+=Molpy.chipsPerClick;
Molpy.chipsManual+=Molpy.chipsPerClick;
if(Molpy.chipsPerClick&&Molpy.options.numbers) Molpy.AddSandParticle('+'+Molpify(Molpy.chipsPerClick,1));
}
Molpy.beachClicks+=1;
Molpy.CheckClickAchievements();
if( Molpy.ninjad==0&&Molpy.CastleTools['NewPixBot'].amount)
{
if(Molpy.npbONG==1)
{
Molpy.StealthClick();
}else if(Molpy.npbONG==0){
if(Molpy.NinjaUnstealth())
{
if(Molpy.CastleTools['NewPixBot'].currentActive)
{
Molpy.EarnBadge('Ninja');
}
if(Molpy.CastleTools['NewPixBot'].currentActive>=10)
{
Molpy.EarnBadge('Ninja Strike');
}
}
if(Molpy.CastleTools['NewPixBot'].currentActive>=1000)
{
Molpy.EarnBadge('KiloNinja Strike');
if(Molpy.CastleTools['NewPixBot'].currentActive>=1e6)
{
Molpy.EarnBadge('MegaNinja Strike');
if(Molpy.CastleTools['NewPixBot'].currentActive>=1e9)
{
Molpy.EarnBadge('GigaNinja Strike');
}
}
}
}
}else if(Molpy.Got('VJ'))
{
if(Molpy.beachClicks%100==0)
{
Molpy.Notify(Molpy.Boosts['VJ'].name);
Molpy.Build(Molpy.CalcVJReward(1));
Molpy.Boosts['VJ'].power++;
var sawType='Plain';
if(Molpy.Got('Swedish Chef'))sawType='Swedish Chef';
if(Molpy.Got('Phonesaw'))sawType='PhoneSaw';
if(Molpy.Got('Ninjasaw'))sawType='Ninjasaw';
if(Molpy.Got('Glass Saw'))
{
var p = Molpy.Boosts['Glass Saw'].power;
if(p>0)
{
sawType='Glass Saw';
var maxGlass=Molpy.GlassCeilingCount()*10000000*p;
var absMaxGlass=maxGlass;
var rate = Molpy.ChipsPerBlock();
maxGlass=Math.min(maxGlass,Math.floor(Molpy.Boosts['Tool Factory'].power/rate));
var leave = 0;
var bl = Molpy.Boosts['GlassBlocks'];
if (Molpy.Boosts['AA'].power && Molpy.Boosts['Glass Blower'].power)
{
leave = Molpy.Boosts['Glass Chiller'].power *(1+Molpy.Boosts['AC'].power)/2*10; // 10 mnp space
}
maxGlass=Math.min(maxGlass,bl.bought*50-bl.power - leave);
maxGlass=Math.max(maxGlass,0);
var backoff = 1;
while (bl.power+maxGlass > bl.bought*50 )
{
maxGlass -= backoff;
backoff *= 2;
}
Molpy.AddBlocks(maxGlass);
Molpy.Boosts['Tool Factory'].power-=maxGlass*rate;
Molpy.Boosts['Tool Factory'].power=Math.max(0,Molpy.Boosts['Tool Factory'].power);
if(Molpy.Boosts['Tool Factory'].power > absMaxGlass*rate*2)
Molpy.Boosts['Glass Saw'].power=p*2;
}
}
_gaq.push(['_trackEvent',Molpy.Boosts['VJ'].name,sawType,''+Molpy.Boosts['VJ'].power]);
}
}
if(Molpy.Got('Bag Puns')&&Molpy.Boosts['VJ'].bought!=1)
{
if(Molpy.beachClicks%20==0)
{
Molpy.Notify(GLRschoice(Molpy.bp));
var p = Molpy.Boosts['Bag Puns'].power;
p++;
if(p>100)
{
Molpy.UnlockBoost('VJ');
}
Molpy.Boosts['Bag Puns'].power=p;
}
}
Molpy.ninjad=1;
if(Molpy.oldBeachClass!='beachongwarning')
Molpy.UpdateBeachClass('beachsafe');
Molpy.HandleClickNP();
if(Molpy.Got('Temporal Rift') && Molpy.Boosts['Temporal Rift'].countdown<5 && flandom(2)==1)
{
Molpy.Notify('You accidentally slip through the temporal rift!,1');
Molpy.RiftJump();
}
}
g('beach').onclick=Molpy.ClickBeach;
Molpy.CalcVJReward=function(includeNinja)
{
var p = Molpy.Boosts['VJ'].power;
var mult=1000000;
if(Molpy.Got('Swedish Chef'))
{
mult*=100;
}else{
if(p>20)Molpy.UnlockBoost('Swedish Chef');
}
if(Molpy.Got('Phonesaw')) mult*=mult;
if(includeNinja&&Molpy.Boosts['Ninjasaw'].power)
{
if(Molpy.HasGlassBlocks(50))
{
Molpy.SpendGlassBlocks(50);
mult*=Molpy.CalcStealthBuild(0,1)/10;
}
}
return p*mult;
}
Molpy.StealthClick=function()
{
//clicking first time, after newpixbot
Molpy.EarnBadge('No Ninja');
Molpy.ninjaFreeCount++;
var ninjaInc = 1;
if(Molpy.Got('Active Ninja'))
{
ninjaInc*=3;
}
if(!Molpy.Boosts['Ninja Lockdown'].power)
{
if(Molpy.Got('Ninja League'))
{
ninjaInc*=100;
}
if(Molpy.Got('Ninja Legion'))
{
ninjaInc*=1000;
}
if(Molpy.Got('Ninja Ninja Duck'))
{
ninjaInc*=10;
}
}
Molpy.ninjaStealth+=ninjaInc;
if(Molpy.Got('Ninja Builder'))
{
var stealthBuild=Molpy.CalcStealthBuild(1,1);
Molpy.Build(stealthBuild+1);
var fn='Factory Ninja';
if(Molpy.Got(fn))
{
var runs = Molpy.ActivateFactoryAutomation();
if (runs == 0 && Molpy.sandPermNP == Infinity) Molpy.EarnBadge('Pure Genius');
!Molpy.Boosts[fn].power--
if(!Molpy.Boosts[fn].power)
Molpy.LockBoost(fn);
}
}else{
Molpy.Build(1); //neat!
}
if(Molpy.ninjaStealth>=6)
{
Molpy.EarnBadge('Ninja Stealth');
Molpy.UnlockBoost('Stealthy Bot');
}
if(Molpy.ninjaStealth>=16)
{
Molpy.EarnBadge('Ninja Dedication');
Molpy.UnlockBoost('Ninja Builder');
}
if(Molpy.ninjaStealth>=26)
{
Molpy.EarnBadge('Ninja Madness');
Molpy.UnlockBoost('Ninja Hope');
}
if(Molpy.ninjaStealth>=36)
{
Molpy.EarnBadge('Ninja Omnipresence');
}
if(Molpy.ninjaStealth>4000)
{
Molpy.EarnBadge('Ninja Pact');
}
if(Molpy.ninjaStealth>4000000)
{
Molpy.EarnBadge('Ninja Unity');
}
if(Molpy.Got('Stealth Cam'))Molpy.Shutter();
}
Molpy.CalcStealthBuild=function(vj,spend)
{
var stealthBuild = Molpy.ninjaStealth;
if(Molpy.Got('Ninja Assistants')) stealthBuild*=Molpy.CastleTools['NewPixBot'].amount;
if(Molpy.Got('Skull and Crossbones'))
{
stealthBuild=Math.floor(stealthBuild*Math.pow(1.05,Math.max(-1,Molpy.SandTools['Flag'].amount-40)));
}
if(Molpy.Boosts['Glass Jaw'].power)
{
if(Molpy.HasGlassBlocks(1))
{
if(spend)
Molpy.SpendGlassBlocks(1);
stealthBuild*=100;
}
}
if(Molpy.Got('Ninja Climber'))
{
stealthBuild*=Molpy.SandTools['Ladder'].amount;
if(spend)
{
Molpy.recalculateDig=1;
}
}
if(vj&&Molpy.Boosts['Ninjasaw'].power&&Molpy.Boosts['VJ'].power)
{
if(Molpy.HasGlassBlocks(50))
{
if(spend)
Molpy.SpendGlassBlocks(50);
stealthBuild*=Molpy.CalcVJReward();
}
}
return stealthBuild;
}
var prevKey='';
Molpy.KeyDown=function(e)
{
var key= String.fromCharCode(e.keyCode||e.charCode);
if(key=='5'&&prevKey.toLowerCase()=='f')
{
Molpy.ClickBeach(e,1);
Molpy.EarnBadge('Use Your Leopard');
}
prevKey=key;
}
window.onkeydown=Molpy.KeyDown;
Molpy.NinjaUnstealth=function()
{
if(!Molpy.ninjaStealth)return 0; //Nothing to lose!
if(Molpy.Got('Impervious Ninja'))
{
var payment = Math.floor(Molpy.Boosts['GlassChips'].power*.01);
if(payment>=100)
{
Molpy.SpendGlassChips(payment);
Molpy.Notify('Ninja Forgiven',1);
Molpy.Boosts['Impervious Ninja'].power--;
if(Molpy.Boosts['Impervious Ninja'].power<=0)
{
Molpy.LockBoost('Impervious Ninja');
}
return 0; //Safe
}
}
if(Molpy.Got('Ninja Hope')&&Molpy.Boosts['Ninja Hope'].power)
{
if(Molpy.castles>=10){
Molpy.Destroy(10);
Molpy.Boosts['Ninja Hope'].power--;
Molpy.Notify('Ninja Forgiven',1);
return 0;
}
}
if(Molpy.Got('Ninja Penance')&&Molpy.Boosts['Ninja Penance'].power)
{
if(Molpy.castles>=30){
Molpy.Destroy(30);
Molpy.Boosts['Ninja Penance'].power--;
Molpy.Notify('Ninja Forgiven',1);
return 0;
}
}
Molpy.Boosts['Ninja Hope'].power=1;
Molpy.Boosts['Ninja Penance'].power=2;
if(Molpy.ninjaStealth)
Molpy.Notify('Ninja Unstealthed',1);
if(Molpy.ninjaStealth>=7&&Molpy.Got('Ninja Hope'))
{
Molpy.UnlockBoost('Ninja Penance');
}
if(Molpy.ninjaStealth>=30&&Molpy.ninjaStealth<36)
{
Molpy.EarnBadge('Ninja Shortcomings');
}
Molpy.ninjaStealth=0;
return 1;
}
Molpy.HandleClickNP=function()
{
var NP = Molpy.newpixNumber;
if(NP==404) Molpy.EarnBadge('Badge Not Found');
if(NP==-404) Molpy.EarnBadge('Badge Found');
}
/* In which we calculate how much sand per milliNewPix we dig
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Molpy.CalculateDigSpeed=function()
{
Molpy.recalculateDig=0;
var oldrate = Molpy.sandPermNP;
Molpy.sandPermNP=0;
var multiplier = 1;
for (var i in Molpy.SandTools)
{
var me=Molpy.SandTools[i];
me.storedSpmNP=EvalMaybeFunction(me.spmNP,me);
me.storedTotalSpmNP=me.amount*me.storedSpmNP;
Molpy.sandPermNP+=me.storedTotalSpmNP;
}
var ninjaFactor =1;
if(Molpy.Got('Busy Bot'))ninjaFactor+=0.1;