-
Notifications
You must be signed in to change notification settings - Fork 73
/
QuestManager.java
2697 lines (2506 loc) · 117 KB
/
QuestManager.java
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
package net.sourceforge.kolmafia.session;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import net.sourceforge.kolmafia.AdventureResult;
import net.sourceforge.kolmafia.KoLAdventure;
import net.sourceforge.kolmafia.KoLCharacter;
import net.sourceforge.kolmafia.KoLConstants;
import net.sourceforge.kolmafia.KoLConstants.MafiaState;
import net.sourceforge.kolmafia.KoLmafia;
import net.sourceforge.kolmafia.Modifiers;
import net.sourceforge.kolmafia.RequestLogger;
import net.sourceforge.kolmafia.RequestThread;
import net.sourceforge.kolmafia.SpecialOutfit.Checkpoint;
import net.sourceforge.kolmafia.objectpool.AdventurePool;
import net.sourceforge.kolmafia.objectpool.EffectPool;
import net.sourceforge.kolmafia.objectpool.FamiliarPool;
import net.sourceforge.kolmafia.objectpool.ItemPool;
import net.sourceforge.kolmafia.objectpool.OutfitPool;
import net.sourceforge.kolmafia.persistence.*;
import net.sourceforge.kolmafia.persistence.QuestDatabase.Quest;
import net.sourceforge.kolmafia.preferences.Preferences;
import net.sourceforge.kolmafia.request.AWOLQuartermasterRequest;
import net.sourceforge.kolmafia.request.AdventureRequest;
import net.sourceforge.kolmafia.request.BURTRequest;
import net.sourceforge.kolmafia.request.CampgroundRequest;
import net.sourceforge.kolmafia.request.EquipmentRequest;
import net.sourceforge.kolmafia.request.GenericRequest;
import net.sourceforge.kolmafia.request.OrcChasmRequest;
import net.sourceforge.kolmafia.request.QuestLogRequest;
import net.sourceforge.kolmafia.request.TavernRequest;
import net.sourceforge.kolmafia.request.UpdateSuppressedRequest;
import net.sourceforge.kolmafia.request.UseSkillRequest;
import net.sourceforge.kolmafia.utilities.StringUtilities;
public class QuestManager {
private static final Pattern ORE_PATTERN =
Pattern.compile("(asbestos|linoleum|chrome) ore[\\. ]");
private static final Pattern BATHOLE_PATTERN = Pattern.compile("bathole_(\\d)\\.gif");
private static final Pattern DRAWER_PATTERN =
Pattern.compile("search through <b>(\\d+)</b> drawers");
private static final Pattern LIGHTER_PATTERN =
Pattern.compile("group of (\\d+) nearby protesters do the same");
private static final Pattern TACO_FISH_PATTERN = Pattern.compile("gain (\\d+) taco fish meat");
private static final Pattern LOWER_CHAMBER_PATTERN =
Pattern.compile("action=pyramid_state(\\d+)");
private static final Pattern GORE_PATTERN = Pattern.compile("(\\d+) pounds of (?:the gore|gore)");
private static final Pattern TOURIST_PATTERN =
Pattern.compile("and the (\\d+) tourists in front");
private static final Pattern WALFORD_PATTERN =
Pattern.compile("\\(Walford's bucket filled by (?:an additional |)(\\d+)%\\)");
private static final Pattern SNOWMAN_PATTERN = Pattern.compile("otherimages/combatsnowman/");
private static final Pattern PARANORMAL_PATTERN =
Pattern.compile(""Paranormal disturbance reported (.*?)."");
private static final Pattern DJ_MEAT_PATTERN = Pattern.compile("collect (.*?) Meat for the DJ");
private static final Pattern TRASH_PATTERN = Pattern.compile("you clean up (\\d+) ");
private static Set<String> friarElbowNCs =
Set.of(
"Deep Imp Act",
"Imp Art, Some Wisdom",
"A Secret, But Not the Secret You're Looking For",
"Butter Knife? I'll Take the Knife");
private static Set<String> friarNeckNCs =
Set.of(
"How Do We Do It? Quaint and Curious Volume!",
"Strike One!",
"Olive My Love To You, Oh.",
"Dodecahedrariffic!");
private static Set<String> friarHeartNCs =
Set.of(
"Moon Over the Dark Heart",
"Running the Lode",
"I, Martin",
"Imp Be Nimble, Imp Be Quick");
private QuestManager() {}
public static final void handleQuestChange(GenericRequest request) {
// Certain location-specific quest changes are noticed by
// simply adventuring in a location. Get the location.
String location = request.getURLString();
String field = request.getFormField("snarfblat");
int locationId = StringUtilities.isNumeric(field) ? StringUtilities.parseInt(field) : 0;
// If we redirected to a choice or fight, there is no response
// text here. Look for the above-mentioned quest changes which
// don't depend on a responseText.
String redirectLocation = request.redirectLocation;
if (redirectLocation != null) {
if (location.startsWith("adventure")) {
switch (locationId) {
case AdventurePool.PALINDOME:
QuestDatabase.setQuestIfBetter(Quest.PALINDOME, QuestDatabase.STARTED);
break;
case AdventurePool.EL_VIBRATO_ISLAND:
handleElVibratoChange(location, "");
break;
}
}
return;
}
// If there was no redirect but we didn't get a response for
// some reason, that is puzzling, but nothing to do.
String responseText = request.responseText;
if (responseText == null || responseText.equals("")) {
// Similarly, don't process an empty response
return;
}
if (location.startsWith("adventure")) {
switch (locationId) {
case AdventurePool.ROAD_TO_WHITE_CITADEL:
handleWhiteCitadelChange(responseText);
break;
case AdventurePool.WHITEYS_GROVE:
handleWhiteysGroveChange(responseText);
break;
case AdventurePool.TOWER_RUINS:
handleTowerRuinsChange(responseText);
break;
case AdventurePool.BARROOM_BRAWL:
handleBarroomBrawlChange(responseText);
break;
case AdventurePool.KNOB_SHAFT:
handleKnobShaftChange(responseText);
break;
case AdventurePool.ARRRBORETUM:
handleArrrboretumChange(responseText);
break;
case AdventurePool.EXTREME_SLOPE:
handleExtremityChange(responseText);
break;
case AdventurePool.ICY_PEAK:
handleIcyPeakChange(responseText);
break;
case AdventurePool.AIRSHIP:
case AdventurePool.CASTLE_BASEMENT:
case AdventurePool.CASTLE_GROUND:
case AdventurePool.CASTLE_TOP:
handleBeanstalkChange(location, responseText);
break;
case AdventurePool.ZEPPELIN_PROTESTORS:
handleZeppelinMobChange(responseText);
break;
case AdventurePool.RED_ZEPPELIN:
handleZeppelinChange(responseText);
break;
case AdventurePool.PALINDOME:
{
// Non-fight, non-choice. Could be a regular
// non-combat, or it could be an error message.
//
// You get the following if you haven't made a
// Talisman o' Namsilat.
if (!responseText.contains("That place isn't accessible to you right now.")
&& !responseText.contains("You find yourself unable to get near the Palindome.")) {
QuestDatabase.setQuestIfBetter(Quest.PALINDOME, QuestDatabase.STARTED);
}
break;
}
case AdventurePool.EL_VIBRATO_ISLAND:
handleElVibratoChange(location, responseText);
break;
case AdventurePool.ABOO_PEAK:
handleABooPeakChange(responseText);
break;
case AdventurePool.OIL_PEAK:
handleOilPeakChange(responseText);
break;
case AdventurePool.POOP_DECK:
handlePoopDeckChange(responseText);
break;
case AdventurePool.HAUNTED_BILLIARDS_ROOM:
handleBilliardsRoomChange(responseText);
break;
case AdventurePool.HAUNTED_BALLROOM:
handleManorSecondFloorChange(location, responseText);
break;
case AdventurePool.UPPER_CHAMBER:
case AdventurePool.MIDDLE_CHAMBER:
handlePyramidChange(location, responseText);
break;
case AdventurePool.SLOPPY_SECONDS_DINER:
case AdventurePool.FUN_GUY_MANSION:
case AdventurePool.YACHT:
case AdventurePool.DR_WEIRDEAUX:
case AdventurePool.SECRET_GOVERNMENT_LAB:
case AdventurePool.DEEP_DARK_JUNGLE:
case AdventurePool.BARF_MOUNTAIN:
case AdventurePool.GARBAGE_BARGES:
case AdventurePool.TOXIC_TEACUPS:
case AdventurePool.LIQUID_WASTE_SLUICE:
case AdventurePool.SMOOCH_ARMY_HQ:
case AdventurePool.VELVET_GOLD_MINE:
case AdventurePool.LAVACO_LAMP_FACTORY:
case AdventurePool.BUBBLIN_CALDERA:
case AdventurePool.ICE_HOTEL:
case AdventurePool.VYKEA:
case AdventurePool.ICE_HOLE:
handleAirportChange(location, responseText);
break;
case AdventurePool.MERKIN_OUTPOST:
case AdventurePool.CALIGINOUS_ABYSS:
handleSeaChange(location, responseText);
break;
case AdventurePool.GINGERBREAD_CIVIC_CENTER:
case AdventurePool.GINGERBREAD_TRAIN_STATION:
case AdventurePool.GINGERBREAD_INDUSTRIAL_ZONE:
case AdventurePool.GINGERBREAD_RETAIL_DISTRICT:
case AdventurePool.GINGERBREAD_SEWERS:
handleGingerbreadCityChange(location, responseText);
break;
case AdventurePool.SPACEGATE:
handleSpacegateChange(location, responseText);
break;
case AdventurePool.THE_POND:
case AdventurePool.THE_BACK_40:
case AdventurePool.THE_OTHER_BACK_40:
case AdventurePool.THE_GRANARY:
case AdventurePool.THE_BOG:
case AdventurePool.THE_FAMILY_PLOT:
case AdventurePool.THE_SHADY_THICKET:
handleFarmChange(location, responseText);
break;
case AdventurePool.DARK_ELBOW_OF_THE_WOODS:
case AdventurePool.DARK_HEART_OF_THE_WOODS:
case AdventurePool.DARK_NECK_OF_THE_WOODS:
handleFriarsCopseChange(locationId, responseText);
break;
default:
if (KoLCharacter.getInebriety() > 25) {
handleSneakyPeteChange(responseText);
}
}
} else if (location.startsWith("choice.php") && location.contains("forceoption=0")) {
// This can have no active choice options and therefore
// won't be interpreted by ChoiceManager
parseSpacegateTerminal(responseText, false);
} else if (location.startsWith("cobbsknob.php")) {
if (location.contains("action=cell37")) {
handleCell37(responseText);
}
} else if (location.startsWith("council")) {
handleCouncilChange(responseText);
} else if (location.startsWith("da")) {
handleDungeonsChange(responseText);
} else if (location.startsWith("fernruin")) {
QuestDatabase.setQuestIfBetter(Quest.EGO, "step3");
} else if (location.startsWith("friars")) {
handleFriarsChange(responseText);
} else if (location.contains("whichplace=highlands")) {
handleHighlandsChange(location, responseText);
} else if (location.startsWith("inv_use")) {
if (location.contains("whichitem=" + ItemPool.AWOL_COMMENDATION)) {
AWOLQuartermasterRequest.parseResponse(responseText);
} else if (location.contains("whichitem=" + ItemPool.BURT)) {
BURTRequest.parseResponse(responseText);
}
} else if (location.startsWith("main")) {
if (Preferences.getInteger("lastIslandUnlock") != KoLCharacter.getAscensions()
&& responseText.contains("island.php")) {
Preferences.setInteger("lastIslandUnlock", KoLCharacter.getAscensions());
}
} else if (location.startsWith("manor")) {
handleManorFirstFloorChange(location, responseText);
} else if (location.startsWith("monkeycastle")) {
handleSeaChange(location, responseText);
} else if (location.startsWith("pandamonium")) {
// Quest starts the very instant you click on pandamonium.php
QuestDatabase.setQuestIfBetter(Quest.AZAZEL, QuestDatabase.STARTED);
} else if (location.startsWith("place.php")) {
String place = GenericRequest.getPlace(location);
if (place != null) {
String action = GenericRequest.getAction(location);
if (place.startsWith("airport")) {
handleAirportChange(location, responseText);
}
switch (place) {
case "bathole" -> handleBatholeChange(responseText);
case "beanstalk" -> {
if (responseText.contains("otherimages/stalktop/beanstalk.gif")) {
QuestDatabase.setQuestIfBetter(Quest.GARBAGE, "step1");
}
}
case "canadia" -> handleCanadiaChange(location, responseText);
case "desertbeach" -> {
if (action != null && action.equals("db_pyramid1")) {
handlePyramidChange(location, responseText);
} else {
handleBeachChange(responseText);
}
}
case "exploathing_beach" -> {
if (action != null && action.equals("expl_pyramidpre")) {
handlePyramidChange(location, responseText);
} else {
handleBeachChange(responseText);
}
}
case "exploathing" -> {
if (action != null && action.equals("expl_council")) {
handleCouncilChange(responseText);
}
}
case "gingerbreadcity" -> handleGingerbreadCityChange(location, responseText);
case "hiddencity" -> handleHiddenCityChange(location, responseText);
case "manor1" -> handleManorFirstFloorChange(location, responseText);
case "manor2" -> handleManorSecondFloorChange(location, responseText);
case "manor3" -> {
if (responseText.contains("Spookyraven Manor Third Floor")) {
// If here at all, Necklace and Dance quests are complete and second floor open
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_NECKLACE, QuestDatabase.FINISHED);
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_DANCE, QuestDatabase.FINISHED);
// Legacy code support
Preferences.setInteger("lastSecondFloorUnlock", KoLCharacter.getAscensions());
}
}
case "manor4" -> {
if (responseText.contains("Spookyraven Manor Cellar")) {
// If here at all, Necklace and Dance quests are complete and second floor and
// basement
// open
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_NECKLACE, QuestDatabase.FINISHED);
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_DANCE, QuestDatabase.FINISHED);
}
if (responseText.contains("sr_brickhole.gif")) {
QuestDatabase.setQuestIfBetter(Quest.MANOR, "step3");
} else {
// sr_masonry.gif
QuestDatabase.setQuestIfBetter(Quest.MANOR, "step1");
}
// Legacy code support
Preferences.setInteger("lastSecondFloorUnlock", KoLCharacter.getAscensions());
if (responseText.contains("Cold as ice and twice as smooth")) {
QuestDatabase.setQuestProgress(Quest.MANOR, QuestDatabase.FINISHED);
ResultProcessor.removeItem(ItemPool.ED_EYE);
if (InventoryManager.getCount(ItemPool.ED_FATS_STAFF) == 0
&& InventoryManager.getCount(ItemPool.ED_AMULET) == 0) {
QuestDatabase.setQuestProgress(Quest.MACGUFFIN, QuestDatabase.FINISHED);
}
}
}
case "marais" -> handleMaraisChange(responseText);
case "mclargehuge" -> {
if (action != null) {
switch (action) {
case "trappercabin" -> handleTrapperChange(responseText);
case "cloudypeak" -> handleMcLargehugeChange(responseText);
}
}
}
case "monorail" -> handleMonorailChange(location, responseText);
case "orc_chasm" -> handleChasmChange(responseText);
case "palindome" -> handlePalindomeChange(location, responseText);
case "plains" -> handlePlainsChange(responseText);
case "pyramid" -> handlePyramidChange(location, responseText);
case "realm_fantasy" -> handleFantasyRealmChange(location, responseText);
case "realm_pirate" -> handlePirateRealmChange(location, responseText);
case "sea_oldman" -> handleSeaChange(location, responseText);
case "spacegate" -> handleSpacegateChange(location, responseText);
case "speakeasy" -> handleSpeakeasyChange(responseText);
// don't catch town_wrong, town_right, or town_market
case "town" -> handleTownChange(location, responseText);
case "town_right" -> handleTownRightChange(location, responseText);
case "town_wrong" -> handleTownWrongChange(location, responseText);
case "town_market" -> handleTownMarketChange(location, responseText);
case "woods" -> handleWoodsChange(location, responseText);
case "zeppelin" -> {
if (responseText.contains("zep_mob1.gif")) {
QuestDatabase.setQuestIfBetter(Quest.RON, "step2");
}
}
}
}
} else if (location.startsWith("questlog")) {
QuestLogRequest.registerQuests(false, location, responseText);
} else if (location.startsWith("sea_merkin")) {
handleSeaChange(location, responseText);
} else if (location.startsWith("seafloor")) {
handleSeaChange(location, responseText);
} else if (location.startsWith("tavern")) {
TavernManager.handleTavernChange(responseText);
} else if (location.startsWith("trickortreat")) {
handleTrickOrTreatingChange(responseText);
} else if (location.startsWith("wham")) {
if (responseText.contains("Congratulations! You solved the case")) {
Preferences.increment("_detectiveCasesCompleted");
}
}
// Obsolete. Sigh.
else if (location.startsWith("generate15")) {
// You slide the last tile into place ...
if (AdventureRequest.registerDemonName("Strange Cube", responseText)
|| responseText.contains("slide the last tile")) {
ResultProcessor.processItem(ItemPool.STRANGE_CUBE, -1);
}
}
}
private static void handleArrrboretumChange(String responseText) {
if (!responseText.contains("Plant a Tree, Plant a Tree!")
&& !responseText.contains("Stumped")
&& !responseText.contains("Timbarrrr!")) {
Preferences.increment("_saplingsPlanted");
}
}
private static void handleMcLargehugeChange(String responseText) {
if (responseText.contains("you spy a crude stone staircase")
|| responseText.contains("notice a set of crude carved stairs")) {
QuestDatabase.setQuestIfBetter(Quest.TRAPPER, "step3");
Preferences.setInteger("currentExtremity", 0);
}
}
private static void handleBarroomBrawlChange(String responseText) {
if (responseText.contains("Jackin' the Jukebox")) {
QuestDatabase.setQuestProgress(Quest.CLANCY, "step1");
}
}
private static void handleKnobShaftChange(String responseText) {
if (responseText.contains("A Miner Variation")) {
QuestDatabase.setQuestProgress(Quest.CLANCY, "step3");
}
}
private static void handleIcyPeakChange(String responseText) {
if (responseText.contains("Mercury Rising")) {
QuestDatabase.setQuestProgress(Quest.CLANCY, "step7");
}
}
private static void handleTownChange(final String location, String responseText) {
QuestManager.handleTimeTower(responseText.contains("town_tower"));
QuestManager.handleEldritchFissure(responseText.contains("town_eincursion"));
QuestManager.handleEldritchHorror(responseText.contains("town_eicfight2"));
}
private static void handleTownRightChange(final String location, String responseText) {
if (!location.contains("action") && !KoLCharacter.inBadMoon()) {
if (responseText.contains("Voting Booth") && !Preferences.getBoolean("voteAlways")) {
Preferences.setBoolean("_voteToday", true);
}
}
if (responseText.contains("Horsery")) {
Preferences.setBoolean("horseryAvailable", true);
}
if (responseText.contains("Telegraph Office")
&& !Preferences.getBoolean("telegraphOfficeAvailable")) {
Preferences.setBoolean("_telegraphOfficeToday", true);
}
if (responseText.contains("Madness Bakery")) {
Preferences.setBoolean("madnessBakeryAvailable", true);
}
}
private static void handleTownWrongChange(final String location, String responseText) {
if (!location.contains("action") && !KoLCharacter.inBadMoon()) {
Preferences.setBoolean("hasDetectiveSchool", responseText.contains("Precinct"));
if (responseText.contains("The Neverending Party")
&& !Preferences.getBoolean("neverendingPartyAlways")) {
Preferences.setBoolean("_neverendingPartyToday", true);
}
if (Preferences.getInteger("_neverendingPartyFreeTurns") < 10
&& responseText.contains("The Neverending Party (1)")) {
Preferences.setInteger("_neverendingPartyFreeTurns", 10);
}
if (responseText.contains("Boxing Daycare") && !Preferences.getBoolean("daycareOpen")) {
Preferences.setBoolean("_daycareToday", true);
}
if (responseText.contains("Tunnel of L.O.V.E.")
&& !Preferences.getBoolean("loveTunnelAvailable")) {
Preferences.setBoolean("_loveTunnelToday", true);
}
if (responseText.contains("Speakeasy")) {
handleSpeakeasyName(responseText);
Preferences.setBoolean("ownsSpeakeasy", true);
}
if (responseText.contains("Overgrown Lot")) {
Preferences.setBoolean("overgrownLotAvailable", true);
}
}
}
private static Pattern SPEAKEASY_NAME = Pattern.compile("whichplace=speakeasy.*?title=\"(.*?)\"");
private static void handleSpeakeasyName(final String text) {
var matcher = SPEAKEASY_NAME.matcher(text);
if (!matcher.find()) return;
Preferences.setString("speakeasyName", matcher.group(1));
}
private static void handleSpeakeasyChange(final String text) {
if (!text.contains("olivers_nocost")) {
Preferences.setInteger("_speakeasyFreeFights", 3);
}
}
private static void handleTownMarketChange(final String location, String responseText) {
if (!location.contains("action") && !KoLCharacter.inBadMoon()) {
if (responseText.contains("The Skeleton Store")) {
Preferences.setBoolean("skeletonStoreAvailable", true);
}
}
}
private static void handleMonorailChange(final String location, String responseText) {
if (responseText.contains("FantasyRealm") && !Preferences.getBoolean("frAlways")) {
Preferences.setBoolean("_frToday", true);
}
if (responseText.contains("PirateRealm") && !Preferences.getBoolean("prAlways")) {
Preferences.setBoolean("_prToday", true);
}
}
public static void handleTimeTower(final boolean available) {
if (Preferences.getBoolean("timeTowerAvailable") == available) {
return;
}
Preferences.setBoolean("timeTowerAvailable", available);
// time-twitching toolbelt is a free pull if the time tower is
// available. Place it in correct storage list.
Modifiers.getModifiers("Item", "time-twitching toolbelt");
AdventureResult toolbelt = ItemPool.get(ItemPool.TIME_TWITCHING_TOOLBELT, 1);
List<AdventureResult> source = available ? KoLConstants.storage : KoLConstants.freepulls;
List<AdventureResult> dest = available ? KoLConstants.freepulls : KoLConstants.storage;
int index = source.indexOf(toolbelt);
if (index > -1) {
AdventureResult item = source.get(index);
source.remove(item);
dest.add(item);
}
ConcoctionDatabase.setRefreshNeeded(false);
}
public static void handleEldritchFissure(final boolean available) {
if (Preferences.getBoolean("eldritchFissureAvailable") == available) {
return;
}
Preferences.setBoolean("eldritchFissureAvailable", available);
}
public static void handleEldritchHorror(final boolean available) {
if (Preferences.getBoolean("eldritchHorrorAvailable") == available) {
return;
}
Preferences.setBoolean("eldritchHorrorAvailable", available);
}
private static void handlePoopDeckChange(final String responseText) {
if (responseText.contains("unlocks a padlock on a trap door")) {
QuestDatabase.setQuestProgress(Quest.PIRATE, QuestDatabase.FINISHED);
}
}
private static void handleWhiteysGroveChange(final String responseText) {
if (responseText.contains("It's A Sign!")) {
QuestDatabase.setQuestIfBetter(Quest.CITADEL, "step1");
}
}
private static void handleTowerRuinsChange(final String responseText) {
if (QuestDatabase.getQuest(Quest.EGO).equals(QuestDatabase.FINISHED)) {
return;
}
if (responseText.contains("Take a Dusty Look!")) {
QuestDatabase.setQuestIfBetter(Quest.EGO, "step6");
} else if (responseText.contains("Into the Maw of Deepness")) {
QuestDatabase.setQuestIfBetter(Quest.EGO, "step5");
} else if (responseText.contains("Staring into Nothing")) {
QuestDatabase.setQuestIfBetter(Quest.EGO, "step4");
} else {
QuestDatabase.setQuestIfBetter(Quest.EGO, "step3");
}
}
private static void handleWhiteCitadelChange(final String responseText) {
if (responseText.contains("I Guess They Were the Existential Blues Brothers")) {
QuestDatabase.setQuestProgress(Quest.CITADEL, "step3");
} else {
QuestDatabase.setQuestIfBetter(Quest.CITADEL, "step2");
}
}
private static void handleGingerbreadCityChange(
final String location, final String responseText) {
if (!Preferences.getBoolean("gingerbreadCityAvailable")
&& !responseText.contains("That's not a real place.")) {
Preferences.setBoolean("_gingerbreadCityToday", true);
}
if (responseText.contains("snarfblat=480")) {
Preferences.setBoolean("gingerRetailUnlocked", true);
}
if (responseText.contains("snarfblat=481")) {
Preferences.setBoolean("gingerSewersUnlocked", true);
}
if (responseText.contains("digitalclock.gif")) {
Preferences.setBoolean("gingerAdvanceClockUnlocked", true);
}
if (responseText.contains("Infrastructure Failure")) {
Preferences.increment("_gingerbreadCityTurns");
}
}
private static void handleHiddenCityChange(final String location, final String responseText) {
if (responseText.contains("snarfblat=341")) {
if (Preferences.getInteger("hiddenApartmentProgress") == 0) {
Preferences.setInteger("hiddenApartmentProgress", 1);
}
}
if (responseText.contains("snarfblat=342")) {
if (Preferences.getInteger("hiddenHospitalProgress") == 0) {
Preferences.setInteger("hiddenHospitalProgress", 1);
}
}
if (responseText.contains("snarfblat=343")) {
if (Preferences.getInteger("hiddenOfficeProgress") == 0) {
Preferences.setInteger("hiddenOfficeProgress", 1);
}
}
if (responseText.contains("snarfblat=344")) {
if (Preferences.getInteger("hiddenBowlingAlleyProgress") == 0) {
Preferences.setInteger("hiddenBowlingAlleyProgress", 1);
}
}
if (responseText.contains("whichshop=hiddentavern")) {
Preferences.setInteger("hiddenTavernUnlock", KoLCharacter.getAscensions());
}
}
private static void handleSpacegateChange(final String location, final String responseText) {
if (!Preferences.getBoolean("spacegateAlways")) {
Preferences.setBoolean("_spacegateToday", true);
}
if (location.contains("action=sg_Terminal")) {
parseSpacegateTerminal(responseText, false);
}
if (location.startsWith("adventure.php")) {
parseSpacegateAdventure(responseText);
}
}
private static void handleFarmChange(final String location, final String responseText) {
if (responseText.contains("There are no more ducks here")) {
KoLAdventure adventure = KoLAdventure.lastVisitedLocation;
if (adventure != null) {
StringBuilder buffer = new StringBuilder(Preferences.getString("duckAreasCleared"));
if (buffer.length() != 0) {
buffer.append(",");
}
buffer.append(adventure.getAdventureId());
Preferences.setString("duckAreasCleared", buffer.toString());
}
}
}
private static void handleFriarsCopseChange(final int locationId, final String responseText) {
String encounterName = AdventureRequest.parseEncounter(responseText);
String location = AdventureDatabase.getAdventure(locationId).getAdventureName();
switch (location) {
case "The Dark Elbow of the Woods":
if (friarElbowNCs.contains(encounterName)) {
Preferences.setInteger("lastFriarsElbowNC", AdventureSpentDatabase.getTurns(location));
}
break;
case "The Dark Heart of the Woods":
if (friarHeartNCs.contains(encounterName)) {
Preferences.setInteger("lastFriarsHeartNC", AdventureSpentDatabase.getTurns(location));
}
break;
case "The Dark Neck of the Woods":
if (friarNeckNCs.contains(encounterName)) {
Preferences.setInteger("lastFriarsNeckNC", AdventureSpentDatabase.getTurns(location));
}
break;
}
}
private static void handleFantasyRealmChange(final String location, final String responseText) {
if (!Preferences.getBoolean("frAlways")) {
Preferences.setBoolean("_frToday", true);
}
// If Welcome Center is present, then any area available is permanently unlocked
if (responseText.contains("action=fr_initcenter")) {
Preferences.setBoolean("frMountainsUnlocked", responseText.contains("snarfblat=503"));
Preferences.setBoolean("frWoodUnlocked", responseText.contains("snarfblat=504"));
Preferences.setBoolean("frSwampUnlocked", responseText.contains("snarfblat=505"));
Preferences.setBoolean("frVillageUnlocked", responseText.contains("snarfblat=506"));
Preferences.setBoolean("frCemetaryUnlocked", responseText.contains("snarfblat=507"));
}
// Otherwise we can see everything that is unlocked at present and correct
else {
StringBuilder unlocks = new StringBuilder();
if (responseText.contains("snarfblat=502")) unlocks.append("The Bandit Crossroads,");
if (responseText.contains("snarfblat=503")) unlocks.append("The Towering Mountains,");
if (responseText.contains("snarfblat=504")) unlocks.append("The Mystic Wood,");
if (responseText.contains("snarfblat=505")) unlocks.append("The Putrid Swamp,");
if (responseText.contains("snarfblat=506")) unlocks.append("The Cursed Village,");
if (responseText.contains("snarfblat=507")) unlocks.append("The Sprawling Cemetery,");
if (responseText.contains("snarfblat=509")) unlocks.append("The Old Rubee Mine,");
if (responseText.contains("snarfblat=510")) unlocks.append("The Foreboding Cave,");
if (responseText.contains("snarfblat=511")) unlocks.append("The Faerie Cyrkle,");
if (responseText.contains("snarfblat=512")) unlocks.append("The Druidic Campsite,");
if (responseText.contains("snarfblat=513")) unlocks.append("Near the Witch's House,");
if (responseText.contains("snarfblat=514")) unlocks.append("The Evil Cathedral,");
if (responseText.contains("snarfblat=515")) unlocks.append("The Barrow Mounds,");
if (responseText.contains("snarfblat=516"))
unlocks.append("The Cursed Village Thieves' Guild,");
if (responseText.contains("snarfblat=517")) unlocks.append("The Troll Fortress,");
if (responseText.contains("snarfblat=518")) unlocks.append("The Labyrinthine Crypt,");
if (responseText.contains("snarfblat=519")) unlocks.append("The Lair of the Phoenix,");
if (responseText.contains("snarfblat=520")) unlocks.append("The Dragon's Moor,");
if (responseText.contains("snarfblat=521")) unlocks.append("Duke Vampire's Chateau,");
if (responseText.contains("snarfblat=522")) unlocks.append("The Master Thief's Chalet,");
if (responseText.contains("snarfblat=523")) unlocks.append("The Spider Queen's Lair,");
if (responseText.contains("snarfblat=524")) unlocks.append("The Archwizard's Tower,");
if (responseText.contains("snarfblat=525")) unlocks.append("The Ley Nexus,");
if (responseText.contains("snarfblat=526")) unlocks.append("The Ghoul King's Catacomb,");
if (responseText.contains("snarfblat=527")) unlocks.append("The Ogre Chieftain's Keep,");
Preferences.setString("_frAreasUnlocked", unlocks.toString());
}
}
private static void addFantasyRealmKill(String monster) {
if (monster == null) {
return;
}
StringBuffer kills = new StringBuffer(Preferences.getString("_frMonstersKilled"));
String monsterPattern = monster;
if (monster.contains("barrow wraith")) {
monsterPattern = "barrow wraith\\?";
} else if (monster.contains("Phoenix")) {
monsterPattern = "\\\"Phoenix\\\"";
}
Pattern FR_MONSTER_PATTERN = Pattern.compile(monsterPattern + ":(\\d+),");
Matcher MonsterMatcher = FR_MONSTER_PATTERN.matcher(kills.toString());
if (MonsterMatcher.find()) {
String newMonster =
monster + ":" + (StringUtilities.parseInt(MonsterMatcher.group(1)) + 1) + ",";
StringUtilities.singleStringReplace(kills, MonsterMatcher.group(0), newMonster);
} else {
kills.append(monster);
kills.append(":1,");
}
Preferences.setString("_frMonstersKilled", kills.toString());
}
private static void handlePirateRealmChange(final String location, final String responseText) {
if (!Preferences.getBoolean("prAlways")) {
Preferences.setBoolean("_prToday", true);
}
}
private static void handleBilliardsRoomChange(final String responseText) {
if (responseText.contains("That's Your Cue")) {
QuestDatabase.setQuestProgress(Quest.SPOOKYRAVEN_NECKLACE, "step2");
}
}
private static void handleManorFirstFloorChange(
final String location, final String responseText) {
if (location.contains("action=manor1_ladys")) {
if (responseText.contains("ghostly copy of the necklace")) {
QuestDatabase.setQuestProgress(Quest.SPOOKYRAVEN_NECKLACE, QuestDatabase.FINISHED);
}
}
// Derive quest status from available rooms
if (responseText.contains("snarfblat=" + AdventurePool.HAUNTED_KITCHEN)) {
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_NECKLACE, QuestDatabase.STARTED);
}
if (responseText.contains("whichplace=manor2")) {
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_NECKLACE, QuestDatabase.FINISHED);
// Legacy code support
Preferences.setInteger("lastSecondFloorUnlock", KoLCharacter.getAscensions());
}
if (responseText.contains("whichplace=manor4")) {
QuestDatabase.setQuestIfBetter(Quest.MANOR, "step1");
}
}
private static void handleManorSecondFloorChange(
final String location, final String responseText) {
if (!responseText.contains("Spookyraven Manor Second Floor")) {
return;
}
int area = AdventureRequest.parseArea(location);
if (location.contains("action=manor2_ladys")) {
if (responseText.contains("just want to dance")) {
QuestDatabase.setQuestProgress(Quest.SPOOKYRAVEN_DANCE, "step1");
}
if (responseText.contains("Meet me in the ballroom")) {
QuestDatabase.setQuestProgress(Quest.SPOOKYRAVEN_DANCE, "step3");
ResultProcessor.removeItem(ItemPool.POWDER_PUFF);
ResultProcessor.removeItem(ItemPool.FINEST_GOWN);
ResultProcessor.removeItem(ItemPool.DANCING_SHOES);
}
}
if (area == AdventurePool.HAUNTED_BALLROOM) {
if (responseText.contains("Having a Ball in the Ballroom")) {
QuestDatabase.setQuestProgress(Quest.SPOOKYRAVEN_DANCE, QuestDatabase.FINISHED);
// You cannot visit the third floor unless you have visited the second floor
new UpdateSuppressedRequest("place.php?whichplace=manor2").run();
}
}
// Derive quest status from available rooms
if (responseText.contains("snarfblat=" + AdventurePool.HAUNTED_BATHROOM)) {
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_DANCE, "step1");
}
if (responseText.contains("snarfblat=" + AdventurePool.HAUNTED_BALLROOM)) {
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_DANCE, "step3");
}
if (responseText.contains("whichplace=manor3")) {
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_DANCE, QuestDatabase.FINISHED);
}
// If here at all, Necklace quest is complete
QuestDatabase.setQuestIfBetter(Quest.SPOOKYRAVEN_NECKLACE, QuestDatabase.FINISHED);
// Legacy code support
Preferences.setInteger("lastSecondFloorUnlock", KoLCharacter.getAscensions());
}
public static final void handlePyramidChange(final String location, final String responseText) {
int area = AdventureRequest.parseArea(location);
if (location.contains("action=db_pyramid1") || location.contains("action=expl_pyramidpre")) {
// Unlock Pyramid
if (responseText.contains("the model bursts into flames and is quickly consumed")) {
QuestDatabase.setQuestProgress(Quest.PYRAMID, QuestDatabase.STARTED);
}
} else if (area == AdventurePool.UPPER_CHAMBER) {
if (responseText.contains("Down Dooby-Doo Down Down")) {
// Open Middle Chamber
Preferences.setBoolean("middleChamberUnlock", true);
QuestDatabase.setQuestProgress(Quest.PYRAMID, "step1");
}
} else if (area == AdventurePool.MIDDLE_CHAMBER) {
if (responseText.contains("Further Down Dooby-Doo Down Down")) {
// Open Lower Chamber
Preferences.setBoolean("lowerChamberUnlock", true);
QuestDatabase.setQuestProgress(Quest.PYRAMID, "step2");
} else if (responseText.contains("Under Control")) {
// Open Control Room
Preferences.setBoolean("controlRoomUnlock", true);
Preferences.setInteger("pyramidPosition", 1);
QuestDatabase.setQuestProgress(Quest.PYRAMID, "step3");
} else if (responseText.contains("Don't You Know Who I Am?")) {
QuestDatabase.setQuestProgress(Quest.CLANCY, QuestDatabase.FINISHED);
}
// If here, must have unlocked middle chamber
Preferences.setBoolean("middleChamberUnlock", true);
QuestDatabase.setQuestIfBetter(Quest.PYRAMID, "step1");
} else if (location.contains("whichplace=pyramid")) {
// Verify settings based on images displayed, in case above steps were missed
QuestDatabase.setQuestIfBetter(Quest.PYRAMID, QuestDatabase.STARTED);
if (responseText.contains("pyramid_middle.gif")) {
Preferences.setBoolean("middleChamberUnlock", true);
QuestDatabase.setQuestIfBetter(Quest.PYRAMID, "step1");
}
if (responseText.contains("pyramid_bottom")) {
Preferences.setBoolean("lowerChamberUnlock", true);
QuestDatabase.setQuestIfBetter(Quest.PYRAMID, "step2");
}
if (responseText.contains("pyramid_controlroom.gif")) {
Preferences.setBoolean("controlRoomUnlock", true);
QuestDatabase.setQuestIfBetter(Quest.PYRAMID, "step3");
}
Matcher LowerChamberMatcher = QuestManager.LOWER_CHAMBER_PATTERN.matcher(responseText);
if (LowerChamberMatcher.find()) {
Preferences.setInteger(
"pyramidPosition", StringUtilities.parseInt(LowerChamberMatcher.group(1)));
}
if (responseText.contains("action=pyramid_state1a")) {
Preferences.setBoolean("pyramidBombUsed", true);
}
// Lower chamber parsing
if (location.contains("action=pyramid_state")) {
if (responseText.contains("the rubble is gone")) {
Preferences.setBoolean("pyramidBombUsed", true);
ResultProcessor.processItem(ItemPool.ANCIENT_BOMB, -1);
}
}
}
return;
}
public static final void handleAirportChange(final String location, final String responseText) {
int area = AdventureRequest.parseArea(location);
// Check Cold settings
if (!Preferences.getBoolean("coldAirportAlways")) {
// Detect if Airport is open today
if (area == AdventurePool.ICE_HOTEL
|| area == AdventurePool.VYKEA
|| area == AdventurePool.ICE_HOLE
|| location.contains("whichplace=airport_cold")) {
if (!responseText.contains("You don't know where that is.")
&& !responseText.contains("That isn't a place you can go.")) {
Preferences.setBoolean("_coldAirportToday", true);
}
} else if (location.contains("whichplace=airport")) {
if (responseText.contains("whichplace=airport_cold")) {
Preferences.setBoolean("_coldAirportToday", true);
}
}
}
// Check Hot settings
if (!Preferences.getBoolean("hotAirportAlways")) {
// Detect if Airport is open today
if (area == AdventurePool.SMOOCH_ARMY_HQ
|| area == AdventurePool.VELVET_GOLD_MINE
|| area == AdventurePool.LAVACO_LAMP_FACTORY
|| area == AdventurePool.BUBBLIN_CALDERA
|| location.contains("whichplace=airport_hot")) {
if (!responseText.contains("You don't know where that is.")
&& !responseText.contains("That isn't a place you can go.")) {
Preferences.setBoolean("_hotAirportToday", true);
}
} else if (location.contains("whichplace=airport")) {
if (responseText.contains("whichplace=airport_hot")) {
Preferences.setBoolean("_hotAirportToday", true);
}
}
}
// Check Sleaze settings
if (!Preferences.getBoolean("sleazeAirportAlways")) {
// Detect if Airport is open today
if (area == AdventurePool.FUN_GUY_MANSION
|| area == AdventurePool.SLOPPY_SECONDS_DINER
|| area == AdventurePool.YACHT
|| location.contains("whichplace=airport_sleaze")) {
if (!responseText.contains("You don't know where that is.")
&& !responseText.contains("That isn't a place you can go.")) {
Preferences.setBoolean("_sleazeAirportToday", true);
}
} else if (location.contains("whichplace=airport")) {
if (responseText.contains("whichplace=airport_sleaze")) {
Preferences.setBoolean("_sleazeAirportToday", true);
}
}
}
// Check Spooky settings
if (!Preferences.getBoolean("spookyAirportAlways")) {
// Detect if Airport is open today
if (area == AdventurePool.DR_WEIRDEAUX
|| area == AdventurePool.SECRET_GOVERNMENT_LAB
|| area == AdventurePool.DEEP_DARK_JUNGLE
|| location.contains("whichplace=airport_spooky")) {
if (!responseText.contains("You don't know where that is.")
&& !responseText.contains("That isn't a place you can go.")) {
Preferences.setBoolean("_spookyAirportToday", true);
}
} else if (location.contains("whichplace=airport")) {
if (responseText.contains("whichplace=airport_spooky")) {
Preferences.setBoolean("_spookyAirportToday", true);
}
}
}
// Check Stench settings
if (!Preferences.getBoolean("stenchAirportAlways")) {
// Detect if Airport is open today
if (area == AdventurePool.BARF_MOUNTAIN
|| area == AdventurePool.GARBAGE_BARGES
|| area == AdventurePool.TOXIC_TEACUPS
|| area == AdventurePool.LIQUID_WASTE_SLUICE
|| location.contains("whichplace=airport_stench")) {
if (!responseText.contains("You don't know where that is.")
&& !responseText.contains("That isn't a place you can go.")) {
Preferences.setBoolean("_stenchAirportToday", true);
}
} else if (location.contains("whichplace=airport")) {
if (responseText.contains("whichplace=airport_stench")) {
Preferences.setBoolean("_stenchAirportToday", true);
}
}
}
// Detect Bunker state
if (location.contains("whichplace=airport_spooky_bunker")) {