forked from Xenko/BeachBall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeachBall.js
1296 lines (1170 loc) · 41.3 KB
/
BeachBall.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
//Declare and Initialize Variables
var BeachBall = {};
BeachBall.incoming_ONG = 0;
BeachBall.Time_to_ONG = 1800000;
BeachBall.lootBoxes = ['boosts', 'badges', 'hpt', 'ninj', 'chron', 'cyb', 'bean', 'ceil', 'drac', 'stuff', 'land', 'prize', 'discov', 'monums', 'monumg', 'tagged', 'badgesav'];
BeachBall.resetCaged = 0;
//Version Information
BeachBall.version = '5.2.0.4';
BeachBall.SCBversion = '3.4121'; //Last SandCastle Builder version tested
//BB Audio Alerts Variables
BeachBall.audio_Bell = new Audio("http://xenko.comxa.com/Ship_Bell.mp3");
BeachBall.audio_Bell.volume = 1;
BeachBall.audio_Chime = new Audio("http://xenko.comxa.com/Chime.mp3");
BeachBall.audio_Chime.volume = 1;
BeachBall.RKAlertFrequency = 8;
if (Molpy.Got('Kitnip') == 1){BeachBall.RKAlertFrequency = 10;}
BeachBall.RKPlayAudio = 1;
//RK Variables
BeachBall.RKLevel = '-1';
BeachBall.RKLocation = '123';
BeachBall.RKNew = 1;
BeachBall.RKNewAudio = 1;
BeachBall.RKTimer = Molpy.Redacted.toggle - Molpy.Redacted.countup;
//Caged Logicat Variables
BeachBall.cagedTimeout = false;
BeachBall.cagedTimeoutLength = 5000;
BeachBall.Puzzle = {};
BeachBall.PuzzleConstructor = function(name) {
this.name = name;
BeachBall.Puzzle[name] = {}; // Creates empty object to ensure no conflicts with other versions
BeachBall.Puzzle[name] = this;
this.size = Molpy.PuzzleGens[name].guess.length;
this.puzzleString = Molpy.PuzzleGens[name].StringifyStatements();
this.statement = [];
this.guess = [];
this.error = false;
this.answers = [];
this.known = [];
this.answered = [];
this.unanswered = [];
for (var i = 0; i < this.size; i++) {
this.unanswered.push(i);
}
//Parses a single claim to extract name and value
this.ParseClaim = function (claimText) {
var claim = {};
claim.name = claimText.substring(0,1);
var i = claimText.indexOf("true");
var j = claimText.indexOf("false");
var k = claimText.indexOf("not");
if ((i > 0 && k < 0) || j * k > 0)
claim.value = true;
else
claim.value = false;
claim.result = "unknown";
return claim;
}
//Returns the index of a given statement name
this.FindStatement = function (searchTerm) {
for (var i = 0; i < this.statement.length; i++) {
if (this.statement[i].name == searchTerm)
{
return i;
}
}
}
this.PopulateStatements = function() {
var i = 0;
var j = this.puzzleString.indexOf("]<br>") > 0 ? this.puzzleString.indexOf("]<br>") + 5 : this.puzzleString.indexOf(">")+1;
// console.log(this.puzzleString);
var k = 0;
var l = 0;
var m = 0;
var n = 0;
do {
// Creates a newStatement, and assigns it to the array
var newStatement = {};
this.statement[i] = newStatement;
// Extracts the statement name from the text,
newStatement.name = this.puzzleString.substring(j, j + 1);
// Finds end index of claim(s), and saves that substring
k = this.puzzleString.indexOf("<br>", j);
newStatement.statementText = this.puzzleString.substring(j + 3, k);
// Creates claims array
newStatement.claim = [];
// Parses statement text to extract all claims to claims array
var text = newStatement.statementText;
// Sets claim counter to 0 before entering loop
var p = 0;
// Does loop at least once, and repeats until AND or OR not present.
do {
var claimText = text;
// Determines if more than one statement if AND or OR present
l = text.indexOf("and");
m = text.indexOf("or");
// Sets statement condition (AND/OR) and index of claim end (n)
if (l != -1) {
claimText = text.substring(0, l);
n = l + 4;
newStatement.condition = "and";
}
else if (m != -1) {
claimText = text.substring(0, m);
n = m + 3;
newStatement.condition = "or";
}
// Parses and assigns values to claims array
newStatement.claim[p] = this.ParseClaim(claimText);
// Updates variables and claim text for next loop
text = text.substring(n, text.length);
p++;
} while (l > 0 || m > 0);
// Sets statement value to default of Unknown
newStatement.value = "unknown";
// Updates j to the start of the next statement
j = this.puzzleString.indexOf("</div>", k) + 10;
i++;
} while (i < this.size);
}
this.EvaluateStatementDependence = function() {
// Cycles through every statement to evaluate dependence
for (i in this.statement) {
// Sets dependent default to false
var dependent = false;
// Goes through all claims in all statements except itself
for (j in this.statement) {
if (this.statement[i].name != this.statement[j].name) {
for (k in this.statement[j].claim) {
// If the claim name matches the examined statement's name, then it is a dependent statement.
if (this.statement[i].name == this.statement[j].claim[k].name) {
dependent = true;
break;
}
}
}
}
//Assigns dependency
this.statement[i].dependent = dependent;
if (dependent) this.EvaluateStatementRelevance(i);
}
}
this.EvaluateStatementRelevance = function(index) {
this.statement[index].relevance = false;
for (i in this.statement[index].claim) {
if (this.statement[index].claim[i].name != this.statement[index].name) {
this.statement[index].relevance = true;
break;
}
}
}
this.EvaluateKnownStatements = function() {
for (i in this.statement) {
var me = this.statement[i];
// A: A is false OR claim 2; A must be true.
if (me.condition == "or") {
for (j in me.claim) {
if (me.claim[j].name == me.name && me.claim[j].value == false) {
this.CheckAssignment(i, true);
this.known.push(parseInt(i));
break;
}
}
}
// A: A is true AND A is false; A must be false.
else if (me.condition == "and" && me.claim[0].name == me.name && me.claim[1].name == me.name && me.claim[0].value != me.claim[1].value) {
this.CheckAssignment(i, false);
this.known.push(parseInt(i));
}
// A: A is true OR A is false; A must be true.
else if (me.condition == "and" && me.claim[0].name == me.name && me.claim[1].name == me.name && me.claim[0].value != me.claim[1].value) {
this.CheckAssignment(i, true);
this.known.push(parseInt(i));
}
}
}
this.CheckAssignment = function(index, bool) {
index = parseInt(index);
if (this.statement[index].value == "unknown") {
this.statement[index].value = bool;
var remove = this.unanswered.indexOf(index);
this.unanswered.splice(remove,1);
this.answered.push(index);
}
if (this.statement[index].value != bool) {
this.error = true;
}
}
this.EvaluateClaims = function() {
// Change tracks if something has changed and is a return value
// If a change is made, this function should be re-run to check for more evaluations.
var change = false;
// Go through each answered statement
for (i in this.answered) {
var index = this.answered[i];
// Go through unanswered statements
for (j in this.unanswered) {
var index2 = this.unanswered[j];
var me = this.statement[index2];
for (k in me.claim) {
//If a claim name matches answered statement
if (me.claim[k].name == this.statement[index].name) {
if (typeof me.condition == "undefined"){
if (me.claim[k].value == this.statement[index].value) {
this.CheckAssignment(index2, true);
}
else {
this.CheckAssignment(index2, false);
}
if (!this.error) {
change = true;
}
}
else if (me.claim[k].result == "unknown") {
//Set claim evaluation result
if (me.claim[k].value == this.statement[index].value) {
me.claim[k].result = true;
}
else {
me.claim[k].result = false;
}
// Figure out which claim is k
var m = 0;
if (k == 0) {
m = 1;
}
// If one claim is unknown and the other is self-referential, then evaluate if possible
if (typeof me.claim[k].result == "boolean" && me.claim[m].name == me.name) {
if (me.condition == "or" && me.claim[k].result == true) {
this.CheckAssignment(index2, true);
}
else if (me.condition == "and" && me.claim[k].result == false) {
this.CheckAssignment(index2, false);
}
if (!this.error) {
change = true;
}
}
// Otherwise evaluate AND statements if both results are known
else if (me.claim[m].result != "unknown" && me.condition == "and") {
if (me.claim[0].result && me.claim[1].result) {
this.CheckAssignment(index2, true);
}
else {
this.CheckAssignment(index2, false);
}
if (!this.error) {
change = true;
}
}
// Evaluate OR statements if both results are known
else if (me.claim[m].result != "unknown") {
if (me.claim[0].result || me.claim[1].result) {
this.CheckAssignment(index2, true);
}
else {
this.CheckAssignment(index2, false);
}
if (!this.error) {
change = true;
}
}
}
}
}
}
}
return change;
}
this.GuessClaim = function(number) {
var found = false;
var index;
for (i in this.unanswered) {
index = parseInt(this.unanswered[i]);
var me = this.statement[index];
if (me.dependent && typeof me.condition == "undefined") {
this.guess[number] = index;
found = true;
break;
}
}
if (!found) {
for (i in this.unanswered) {
index = parseInt(this.unanswered[i]);
var me = this.statement[index];
if (me.dependent && me.condition == "and") {
this.guess[number] = index;
found = true;
break;
}
}
}
if (!found) {
for (i in this.unanswered) {
index = parseInt(this.unanswered[i]);
var me = this.statement[index];
if (me.dependent && me.value == "unknown") {
this.guess[number] = index;
found = true;
break;
}
}
}
//Set guess value
if (found) {
this.CheckAssignment(this.guess[number], true);
this.AssignClaim(this.guess[number]);
}
}
this.CheckAnswers = function() {
var error = false;
// Set all claim results
for (var i = 0; i < this.statement.length; i++) {
for (j in this.statement[i].claim) {
var me = this.statement[i].claim[j]
if (typeof me != "undefined") {
var index = this.FindStatement(me.name);
if (me.value == this.statement[index].value) {
me.result = true;
}
else {
me.result = false;
}
}
else {
console.log("Error with " + this.statement[i].name + " i: " + i + " and j: " + j);
}
}
}
// Evaluate all claims in statement (with condition) and checks answer against statement value
for (k in this.statement) {
var me = this.statement[k]
var bool;
if (typeof me.condition == "undefined" && me.claim[0].result != me.value) {
error = true;
}
else if (me.condition == "or") {
bool = me.claim[0].result || me.claim[1].result;
if (bool != me.value) {
error = true;
}
}
else if (me.condition == "and") {
bool = me.claim[0].result && me.claim[1].result;
if (bool != me.value) {
error = true;
}
}
}
if (error) {
this.error = true;
}
}
//Takes in the guess array index of the guess to be changed
this.ChangeGuess = function() {
var bool;
var previousGuesses = [];
for (i in this.guess) {
var num = parseInt(i);
bool = this.statement[this.guess[i]].value;
previousGuesses[i] = bool;
}
// Resets all claim results and statement values to defaults
// Repopulates unanswered array
this.unanswered = [];
for (i in this.statement) {
var me = this.statement[i];
// Reset all claim results to unknown
for (j in me.claim) {
me.claim[j].result = "unknown";
}
//Reset all statement values to unknown
me.value = "unknown";
this.unanswered.push(parseInt(i));
}
this.answered = [];
this.error = false;
number = this.guess.length - 1;
//Re-evaluates known statements
this.EvaluateKnownStatements();
// Checks if it guess needs to roll back 1
while (previousGuesses[number] == false) {
number--;
this.guess.pop();
previousGuesses.pop();
// If number is now less than 0, no solution will be found by the program.
if (number < 0) {
this.error = true;
}
}
// Goes through the remaining Guess Array
for (k = 0; k < this.guess.length; k++) {
var me = this.guess[k];
// If this is the guess to change, change it to false
if (k == number) {
bool = false;
}
// Otherwise set the earlier guesses back to true
else {
var bool = previousGuesses[parseInt(k)];
}
this.CheckAssignment(me, bool);
this.AssignClaim(this.guess[parseInt(k)]);
}
}
// Assigns statement values for claims of guessed statements
this.AssignClaim = function(index) {
var me = this.statement[index];
var i;
var k = 0;
var bool;
// If simple claim
if (typeof me.condition == "undefined") {
// Find statement named in claim
i = this.FindStatement(me.claim[k].name);
// Determine value of statement
bool = me.claim[k].value
if (!me.value) {
bool = !bool;
}
//Assign statement
this.CheckAssignment(i, bool);
}
}
this.PrintAnswers = function() {
for (i in this.statement) {
console.log(this.statement[i].name + " is " + this.statement[i].value);
}
}
this.LoadAnswers = function(puzzleType) {
if (!this.error) {
for (i = 0; i < this.size; i++) {
var choice = 0;
var text = "";
if (this.statement[i].value == true) {
choice = 1;
text = "True";
}
else if (this.statement[i].value == false) {
choice = 2;
text = "False";
}
$('#selectGuess' + i).prop('selectedIndex', choice);
Molpy.PuzzleGens[puzzleType].guess[i] = text;
}
if (BeachBall.Settings['CagedAutoClick'].status == 1 & puzzleType == "caged") {
Molpy.PuzzleGens[puzzleType].Submit();
}
else {
Molpy.PuzzleGens[puzzleType].Submit();
}
}
else {
Molpy.Notify('Program Error, No Solution Found', 0);
}
}
}
//Game Functions
BeachBall.SolveLogic = function(name) {
// Checks if puzzle is active
if (Molpy.PuzzleGens[name].active) {
// Parses the Puzzle
BeachBall.PuzzleConstructor(name);
var me = BeachBall.Puzzle[name];
me.PopulateStatements();
me.EvaluateStatementDependence();
//Searches for Statements that MUST have a given value (no guessing needed)
me.EvaluateKnownStatements();
//Guess a value for an unanswered dependent statement.
me.GuessClaim(0);
var i = 0;
do {
change = me.EvaluateClaims();
i++;
if (!change) {
if (me.error) {
me.ChangeGuess();
change = true;
if (me.error) {
change = false;
}
}
else if (me.answered.length == me.size) {
me.CheckAnswers();
if (me.error) {
me.ChangeGuess();
change = true;
if (me.error) {
change = false;
}
}
}
else if (me.unanswered.length > 0) {
me.GuessClaim(me.guess.length);
change = true;
}
}
} while (i < 50 && change);
me.CheckAnswers();
me.LoadAnswers(name);
}
}
BeachBall.CagedAutoClick = function() {
//Purchases Caged Logicat
//If Caged AutoClick is Enabled, and Caged Logicat isn't Sleeping and Caged Logicat isn't already purchased, and timeout not active
var me = BeachBall.Settings['CagedAutoClick'];
var meLC = BeachBall.Settings['LCSolver'];
if (me.status > 0 && Molpy.Got("LogiPuzzle") > 1 && !Molpy.PuzzleGens["caged"].active && !BeachBall.cagedTimeout) {
//Determines Logicat Cost, and if sufficient blocks available, caged logicat is purchased.
var tens = Math.floor((Molpy.Boosts["LogiPuzzle"].Level - 1) / 10) * 10;
var costSingle = 100 + Molpy.LogiMult(25);
var costMulti = costSingle * tens;
// Buy Single Puzzles
if (me.status == 1 && Molpy.Has('GlassBlocks', costSingle)) {
Molpy.MakeCagedPuzzle(costSingle);
}
// Buy Maximum Puzzles, or Singles if Max is less than 10
else if (me.status == 2) {
if (Molpy.PokeBar() >= 11 && Molpy.Level('LogiPuzzle') >= Molpy.PokeBar() && tens && Molpy.Has('GlassBlocks', costMulti)) {
Molpy.MakeCagedPuzzle(costMulti, tens);
}
else if (Molpy.PokeBar() < 11) {
Molpy.MakeCagedPuzzle(costSingle);
}
}
// Trade Logicats for Bonemeal
else if (me.status == 3 && Molpy.Got('ShadwDrgn') && Molpy.Level('LogiPuzzle') >= 100) {
Molpy.ShadowStrike(1);
}
}
//Caged Logicat Solver is always called, as this ensures both manually purchased and autoclick purchased will be solved
//If a Caged Logicat Problem is Available, and the Logicat Solver is Enabled, and it hasn't been solved, Solve the Logicat
if (Molpy.PuzzleGens["caged"].active && (me.status == 1 || me.status == 2 || meLC.status == 1) && Molpy.PuzzleGens["caged"].guess[0] == "No Guess") {
BeachBall.SolveLogic("caged");
// If there are more puzzles remaining, set the timeout to 5 seconds (prevents Notify spam/lag).
if (Molpy.Got("LogiPuzzle") > 1) {
BeachBall.cagedTimeout = true;
BeachBall.cagedTimer = setTimeout(function(){BeachBall.cagedTimeout = false;}, BeachBall.cagedTimeoutLength);
}
}
}
BeachBall.FindRK = function() {
/* RV of 1 is Sand Tools
RV of 2 is Castle Tools
RV of 3 is Shop
RV of 4 is Boosts Menus, Hill People Tech, etc.
RV of 5 is Badges Earned, Discovery, Monuments and Glass Monuments
RV of 6 is Badges Available */
//Determines RK location
BeachBall.RKLocation = '123';
if (Molpy.Redacted.location == 6) {
BeachBall.RKLocation = 'badgesav';
}
else if (Molpy.Redacted.location > 3) {
BeachBall.RKLocation = Molpy.redactedGr;
}
//Opens RK location
BeachBall.ToggleMenus(BeachBall.RKLocation);
}
BeachBall.MontyHaul = function() {
//If MHP Auto Click is Enabled
if (BeachBall.Settings['MHAutoClick'].status != 0) {
//If Monty Haul Problem is Unlocked
if (Molpy.Boosts['MHP'].unlocked) {
//If unpurchased and can afford, then buy and open Door A
if (!Molpy.Got('MHP')) {
var sp = Math.floor(Molpy.priceFactor * 100 * Math.pow(2, Math.max(1, Molpy.Boosts['MHP'].power - 9)), 1);
var gp = 0;
if (Molpy.IsEnabled('HoM')) {
gp = Math.floor(Molpy.priceFactor * 100 * Math.pow(2, Math.max(1, Molpy.Boosts['MHP'].power - 15)), 1);
}
if (Molpy.Has('GlassBlocks', gp) && Molpy.Has('Sand', sp)) {
Molpy.BoostsById[31].buy();
Molpy.Monty('A');
}
}
//Else If MHP already purchased
else {
//If User Wants a Goat
if (BeachBall.Settings['MHAutoClick'].status == 2) {
//If User Has Beret Guy, then Get Goat
if (Molpy.Got('Beret Guy')) {
Molpy.Monty(Molpy.Boosts['MHP'].goat);
}
//Otherwise open Door A
else {
Molpy.Monty('A');
}
}
//Otherwise switch doors to try for a prize.
else {
//If the Goat is behind C, choose B
if (Molpy.Boosts['MHP'].goat == 'C') {
Molpy.Monty('B');
}
//Otherwise choose C
else if (Molpy.Boosts['MHP'].goat == 'B') {
Molpy.Monty('C');
}
else {
Molpy.Monty('A');
}
}
}
}
}
}
BeachBall.ClickBeach = function(number) {
if (BeachBall.Settings['Enabled'].status == 1) {
if (Molpy.Got('Temporal Rift') == 0 && Molpy.ninjad != 0 && BeachBall.Time_to_ONG >= 5){
Molpy.ClickBeach();
}
}
}
BeachBall.RiftAutoClick = function () {
if (BeachBall.Settings['RiftAutoClick'].status == 0)
return;
switch (parseInt(BeachBall.Settings['RiftAutoClick'].status)) {
case 1 : // farm crystals
// check TL
if (!(Molpy.Boosts['Time Lord'] && Molpy.Boosts['Time Lord'].bought && Molpy.Boosts['Time Lord'].power))
return;
//Vilnor - if Flux Harvest is purchased, and available use it
if (Molpy.Boosts['Flux Harvest'].bought && isFinite(Molpy.Boosts['FluxCrystals'].power)) {
Molpy.FluxHarvest();
}
if ((!Molpy.Got('Temporal Rift')) && (BeachBall.GetBeachState() == 'beachsafe'))
Molpy.RiftJump();
break;
case 2 : // rift to ONG
if (!(Molpy.Boosts['Time Lord'] && Molpy.Boosts['Time Lord'].bought && Molpy.Boosts['Time Lord'].power))
return;
// ninja click has passed, rift occuring, sand in stock
if (Molpy.Got('Temporal Rift') && (BeachBall.GetBeachState() == 'beachsafe')) {
/* Vilnor - Change to spend 1 sand instead of has, to allow Aleph One, and cracks checks to work */
if (Molpy.Boosts['Sand'].Spend(1,1)) {
Molpy.RiftJump();
}
}
break;
}
}
BeachBall.GetBeachState = function () {
var stateClass = 'beachsafe';
if(!Molpy.ninjad) {
if(Molpy.npbONG)
stateClass = 'beachstreakextend';
else
stateClass = 'beachninjawarning';
}
return stateClass;
}
BeachBall.Ninja = function() {
//Molpy.ninjad is 0 when you can't click, and stays 0 until you extend streak, when it turns to 1
//Molpy.npbONG is 0 when you can't click, and 1 when you can click
if (Molpy.ninjad == 0) {
if ((BeachBall.Settings['BeachAutoClick'].status == 3) && (Molpy.Got('Temporal Rift') == 0)) {
Molpy.ClickBeach();
Molpy.Notify('Ninja Ritual Auto Click', 1);
}
if (Molpy.npbONG != 0) {
BeachBall.incoming_ONG = 0;
if (BeachBall.Settings['BeachAutoClick'].status > 0 && Molpy.Got('Temporal Rift') == 0) {
Molpy.ClickBeach();
Molpy.Notify('Ninja Auto Click', 1);
if (BeachBall.resetCaged == 1) {
BeachBall.Settings['CagedAutoClick'].status = 1;
BeachBall.resetCaged = 0;
}
}
/*If the Caged Logicats are essentially infinite in number (thus Temporal Rift is always active)
*the autoclicker needs to be paused to allow temporal rift to end to process the click, then resumed*/
else if (BeachBall.Settings['BeachAutoClick'].status > 0 && Molpy.Got('Temporal Rift') == 1 && BeachBall.Settings['CagedAutoClick'].status == 1) {
//Turn Off Caged AutoClicker, and set variable to reset it after click.
BeachBall.Settings['CagedAutoClick'].status = 0;
BeachBall.resetCaged = 1;
}
}
}
else if (BeachBall.Time_to_ONG <= 15) {
if (BeachBall.incoming_ONG == 0 && BeachBall.Settings['AudioAlerts'].status > 2) {
BeachBall.audio_Chime.play();
BeachBall.incoming_ONG = 1;
}
}
}
BeachBall.PlayRKAlert = function() {
//If proper mNP and hasn't yet played this mNP (can happen if refresh Rate < mNP length)
if (Math.floor(BeachBall.RKTimer % BeachBall.RKAlertFrequency) == 0 && BeachBall.RKPlayAudio == 1) {
BeachBall.audio_Bell.play();
BeachBall.RKPlayAudio = 0;
}
//Otherwise reset played this mNP
else {
BeachBall.RKPlayAudio = 1;
}
}
BeachBall.RedundaKitty = function() {
var meRK = BeachBall.Settings['RKAutoClick'];
var meLC = BeachBall.Settings['LCSolver'];
BeachBall.RKTimer = Molpy.Redacted.toggle - Molpy.Redacted.countup;
//If there is an active RK
if (Molpy.Redacted.location > 0) {
//Update the title, and determine the RK level
document.title = "! kitten !";
BeachBall.RKLevel = Molpy.Redacted.location - 1;
if (BeachBall.Settings['Enabled'].status == 1) {
//If RKAutoClick is Selected
if (meRK.status == 2) {
//If it is a Logicat, Solve and Submit
if (Molpy.PuzzleGens["redacted"].active) {
BeachBall.SolveLogic("redacted");
}
//Otherwise, click the Redundakitty
else {
Molpy.Redacted.onClick(BeachBall.RKLevel);
}
}
//Otherwise if Find RK is selected, find the RK
else if (meRK.status == 1) {
BeachBall.FindRK();
}
else if (meLC.status == 1) {
BeachBall.SolveLogic("redacted");
}
//If the RK is visible, then highlight it
if ($('#redacteditem').length) {
$('#redacteditem').css("border","2px solid red");
}
//If RK Audio Alert Enabled, Play Alert
if (BeachBall.Settings['AudioAlerts'].status == 1 || BeachBall.Settings['AudioAlerts'].status == 4){
BeachBall.PlayRKAlert();
}
// If LC Audio Alert Enabled and LC is available, Play Alert
else if (BeachBall.Settings['AudioAlerts'].status == 2 && Molpy.Redacted.DrawType[Molpy.Redacted.DrawType.length-1] == 'hide2') {
BeachBall.PlayRKAlert();
}
}
}
//If no RK active, update title Timer. Reset audio alert variable.
else {
document.title = BeachBall.RKTimer;
BeachBall.RKPlayAudio = 0;
}
}
BeachBall.ToggleMenus = function(wantOpen) {
//for (var i in BeachBall.lootBoxes) {
//var me = BeachBall.lootBoxes[i];
for (i=0, len = BeachBall.lootBoxes.length; i < len; i++) {
//If the current Box should be open
if (BeachBall.lootBoxes[i] == wantOpen) {
//If it isn't opened, open it.
if (!Molpy.activeLayout.lootVis[BeachBall.lootBoxes[i]]) {
Molpy.ShowhideToggle(BeachBall.lootBoxes[i]);
}
}
//If the current Box should be closed
else {
//If it is open, then close it
if (Molpy.activeLayout.lootVis[BeachBall.lootBoxes[i]]) {
Molpy.ShowhideToggle(BeachBall.lootBoxes[i]);
}
}
}
}
BeachBall.FavsAutoclick = {};
BeachBall.ChooseAutoclick = function () {
var selectedFave = Molpy.selectedFave;
if (selectedFave == 'None')
return;
if (Molpy.activeLayout.faves[selectedFave].boost == 0) {
Molpy.Notify('You need to set a favorite first.', 0);
return;
}
var buttons = $("#sectionFave"+selectedFave+" input[type=Button]");
if (buttons.length == 0) {
Molpy.Notify('This favorite has no button to click !', 0);
return;
}
// cps and click per second handling
var speed = prompt('How shouw it be clicked ?\nType "X cps" or "Xcps" for X click per second.\nType "X s" or "Xs" for 1 click every X second.');
if (speed === null) { // unasign the fav
if (BeachBall.FavsAutoclick[selectedFave] && BeachBall.FavsAutoclick[selectedFave].timer)
BeachBall.ToggleAutoclickFav(selectedFave,false); // we turn it off first
BeachBall.FavsAutoclick[selectedFave] = null;
Molpy.Notify('Favorite asignation for '+Molpy.activeLayout.faves[selectedFave].boost.name+' has been removed', 1);
BeachBall.SaveAutoclickFav();
return;
}
var speed_el = speed.replace(/\s/,"").replace(/,/,".").match(/^(\d+)(\w+)$/i);
// kicking out the bad inputs
if ((!speed_el) || (speed_el.length != 3)) {
Molpy.Notify('No assignation done : time format was not valid', 0);
return;
}
speed_el[1] = parseFloat(speed_el[1]);
if (isNaN(speed_el[1]) || speed_el[1] == 0){
Molpy.Notify('No assignation done : time value was not valid', 0);
return;
}
var period = speed_el[2] == "s" ?
speed_el[1]*1000
: 1000/speed_el[1];
if (buttons.length > 1) {
// preparing the prompt to choose for the right favorite button
var promptText = "There is multiple buttons on this favorite :\n";
for (var index = 0; index < buttons.length; index++) {
promptText += (index+1) + " : " + buttons[index].value + "\n";
}
promptText += "Input the number that is in front of the button you want clicked."
var choice = prompt(promptText);
// kicking out bad inputs
switch (choice) {
case "0" :
case null :
Molpy.Notify('No assignation done : no choice was made', 0);
return;
default : choice = parseInt(choice);
}
if (isNaN(choice) || choice == 0) {
Molpy.Notify('No assignation done : choice was not valid', 0);
return;
}
choice --;
} else {
var choice = 0; // only 1 choice
}
if (BeachBall.FavsAutoclick[selectedFave] && BeachBall.FavsAutoclick[selectedFave].timer)
window.clearInterval(BeachBall.FavsAutoclick[selectedFave].timer);
BeachBall.FavsAutoclick[selectedFave] = {
fave : selectedFave,
choice : choice,
period : period,
speed : speed,
timer : 0
}
BeachBall.ToggleAutoclickFav(selectedFave,false);
Molpy.Notify('AutoclickFav created for '+Molpy.activeLayout.faves[selectedFave].boost.name+' at '+speed, 1);
Molpy.Notify('Click on its timer in the Favorite to disable.', 1);
BeachBall.SaveAutoclickFav();
}
BeachBall.ToggleAutoclickFav = function(fav,shown) {
var me = BeachBall.FavsAutoclick[fav];
if (me.timer) {
window.clearInterval(me.timer);
me.timer = 0;
} else {
me.timer = window.setInterval(BeachBall.getAutoClickFav(fav),me.period)
}
BeachBall.SaveAutoclickFav();
if (shown)
Molpy.Notify('Autoclick Favorite '+Molpy.activeLayout.faves[fav].boost.name+' toggled : '+(me.timer ? 'activated, '+me.speed : 'disabled'), 1);
}
BeachBall.getAutoClickFav = function (fav_to_auto) {
return (function (_fav) {
return function(){
var me = BeachBall.FavsAutoclick[_fav];
if (me.timer) {
var buttons = $("#sectionFave"+me.fave+" input[type=Button]");
if (buttons && buttons[me.choice] && (typeof(buttons[me.choice].click) == 'function'))
buttons[me.choice].click();
}
}
})(fav_to_auto);
}
BeachBall.ImplantAutoclickFavButtons = function () {
for (fav in BeachBall.FavsAutoclick) {
var me = BeachBall.FavsAutoclick[fav];
if (me && me.period && $("#faveHeader"+fav+" h1"))
if ($("#faveHeader"+fav+" h1 .BB_autoclick").length == 0){
if ($("#faveHeader"+fav+" h1").length>0)
$("#faveHeader"+fav+" h1")[0].innerHTML= $("#faveHeader"+fav+" h1")[0].innerHTML +"<a class='BB_autoclick' onclick='BeachBall.ToggleAutoclickFav(\""+fav+"\",true)' "+(me.timer ? "" : "style='text-decoration:line-through' ")+">[ "+me.speed+" ]</a>";
} else {
$("#faveHeader"+fav+" h1 .BB_autoclick").first().css('text-decoration',me.timer ? '' : 'line-through');
}
}
}
BeachBall.LoadAutoclickFav = function() {
BeachBall.FavsAutoclick = localStorage['BB.FavsAutoclick'] ? JSON.parse(localStorage['BB.FavsAutoclick']) : {};
for (fav in BeachBall.FavsAutoclick) {
var me = BeachBall.FavsAutoclick[fav];
if (me && me.timer) {// if there was an active timer when the save occured
me.timer = 0;
BeachBall.ToggleAutoclickFav(fav,false);
}
}
}
BeachBall.SaveAutoclickFav = function() {
localStorage['BB.FavsAutoclick'] = JSON.stringify(BeachBall.FavsAutoclick);
}
//Menus and Settings
BeachBall.CheckToolFactory = function() {
if (Molpy.Boosts['TF'].bought) {
BeachBall.DisplayDescription('ToolFactory');
Molpy.Notify('Tool Factory Option Now Available!', 1);
}
else {
Molpy.Notify('Tool Factory is still unavailable... keep playing!', 1);
}
}
BeachBall.LoadToolFactory = function() {
if (Molpy.Boosts['TF'].bought == 1)
Molpy.LoadToolFactory(BeachBall.Settings['ToolFactory'].setting);
}