-
Notifications
You must be signed in to change notification settings - Fork 73
/
ConcoctionDatabase.java
3349 lines (2889 loc) · 132 KB
/
ConcoctionDatabase.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.persistence;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.stream.Collectors;
import net.java.dev.spellcast.utilities.LockableListModel;
import net.java.dev.spellcast.utilities.SortedListModel;
import net.sourceforge.kolmafia.AdventureResult;
import net.sourceforge.kolmafia.CoinmasterData;
import net.sourceforge.kolmafia.CoinmasterRegistry;
import net.sourceforge.kolmafia.KoLCharacter;
import net.sourceforge.kolmafia.KoLCharacter.Gender;
import net.sourceforge.kolmafia.KoLConstants;
import net.sourceforge.kolmafia.KoLConstants.ConsumptionType;
import net.sourceforge.kolmafia.KoLConstants.CraftingMisc;
import net.sourceforge.kolmafia.KoLConstants.CraftingRequirements;
import net.sourceforge.kolmafia.KoLConstants.CraftingType;
import net.sourceforge.kolmafia.KoLmafia;
import net.sourceforge.kolmafia.RequestLogger;
import net.sourceforge.kolmafia.RequestThread;
import net.sourceforge.kolmafia.RestrictedItemType;
import net.sourceforge.kolmafia.SpecialOutfit.Checkpoint;
import net.sourceforge.kolmafia.StaticEntity;
import net.sourceforge.kolmafia.VYKEACompanionData;
import net.sourceforge.kolmafia.listener.NamedListenerRegistry;
import net.sourceforge.kolmafia.objectpool.Concoction;
import net.sourceforge.kolmafia.objectpool.ConcoctionPool;
import net.sourceforge.kolmafia.objectpool.ConcoctionType;
import net.sourceforge.kolmafia.objectpool.EffectPool;
import net.sourceforge.kolmafia.objectpool.FamiliarPool;
import net.sourceforge.kolmafia.objectpool.ItemPool;
import net.sourceforge.kolmafia.objectpool.SkillPool;
import net.sourceforge.kolmafia.persistence.QuestDatabase.Quest;
import net.sourceforge.kolmafia.preferences.Preferences;
import net.sourceforge.kolmafia.request.CampgroundRequest;
import net.sourceforge.kolmafia.request.ChezSnooteeRequest;
import net.sourceforge.kolmafia.request.ClanLoungeRequest;
import net.sourceforge.kolmafia.request.CreateItemRequest;
import net.sourceforge.kolmafia.request.CrimboCafeRequest;
import net.sourceforge.kolmafia.request.DrinkItemRequest;
import net.sourceforge.kolmafia.request.EatItemRequest;
import net.sourceforge.kolmafia.request.FightRequest;
import net.sourceforge.kolmafia.request.GenericRequest;
import net.sourceforge.kolmafia.request.HellKitchenRequest;
import net.sourceforge.kolmafia.request.MicroBreweryRequest;
import net.sourceforge.kolmafia.request.PurchaseRequest;
import net.sourceforge.kolmafia.request.StandardRequest;
import net.sourceforge.kolmafia.request.StillSuitRequest;
import net.sourceforge.kolmafia.request.UseItemRequest;
import net.sourceforge.kolmafia.session.ChoiceManager;
import net.sourceforge.kolmafia.session.ClanManager;
import net.sourceforge.kolmafia.session.EquipmentManager;
import net.sourceforge.kolmafia.session.InventoryManager;
import net.sourceforge.kolmafia.swingui.ItemManageFrame;
import net.sourceforge.kolmafia.utilities.FileUtilities;
import net.sourceforge.kolmafia.utilities.StringUtilities;
public class ConcoctionDatabase {
private static final Set<AdventureResult> EMPTY_SET = new HashSet<>();
private static final LockableListModel<CreateItemRequest> creatableList =
new LockableListModel<>();
private static final UsableConcoctions usableList = new UsableConcoctions();
public static String excuse; // reason why creation is impossible
private static boolean refreshNeeded = true;
private static boolean recalculateAdventureRange = false;
public static int refreshLevel = 0;
public static int queuedAdventuresUsed = 0;
public static int queuedFreeCraftingTurns = 0;
public static int queuedStillsUsed = 0;
public static int queuedTomesUsed = 0;
public static int queuedExtrudesUsed = 0;
public static int queuedPullsUsed = 0;
public static int queuedMeatSpent = 0;
public static boolean queuedFancyDog = false;
public static int queuedSpeakeasyDrink = 0;
public static int queuedSmores = 0;
public static int queuedAffirmationCookies = 0;
public static int queuedSpaghettiBreakfast = 0;
public static int queuedEverfullGlass = 0;
public static int queuedPirateFork = 0;
public static boolean queuedMimeShotglass = false;
public static int lastQueuedMayo = 0;
private static int queuedFullness = 0;
public static final LockableListModel<QueuedConcoction> queuedFood = new LockableListModel<>();
private static final SortedListModel<AdventureResult> queuedFoodIngredients =
new SortedListModel<>();
private static int queuedInebriety = 0;
public static final LockableListModel<QueuedConcoction> queuedBooze = new LockableListModel<>();
private static final SortedListModel<AdventureResult> queuedBoozeIngredients =
new SortedListModel<>();
private static int queuedSpleenHit = 0;
public static final LockableListModel<QueuedConcoction> queuedSpleen = new LockableListModel<>();
private static final SortedListModel<AdventureResult> queuedSpleenIngredients =
new SortedListModel<>();
public static final LockableListModel<QueuedConcoction> queuedPotions = new LockableListModel<>();
private static final SortedListModel<AdventureResult> queuedPotionIngredients =
new SortedListModel<>();
public static final Concoction stillsLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Concoction clipArtLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Concoction extrudeLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Concoction adventureLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Concoction adventureSmithingLimit =
new Concoction(null, CraftingType.NOCREATE);
public static final Concoction cookingLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Concoction turnFreeLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Concoction turnFreeCookingLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Concoction turnFreeSmithingLimit =
new Concoction(null, CraftingType.NOCREATE);
public static final Concoction meatLimit = new Concoction(null, CraftingType.NOCREATE);
public static final Map<Integer, Set<AdventureResult>> knownUses = new HashMap<>();
public static final EnumSet<CraftingType> PERMIT_METHOD = EnumSet.noneOf(CraftingType.class);
public static final Map<CraftingType, Integer> ADVENTURE_USAGE =
new EnumMap<>(CraftingType.class);
public static final Map<CraftingType, Integer> CREATION_COST = new EnumMap<>(CraftingType.class);
public static final Map<CraftingType, String> EXCUSE = new EnumMap<>(CraftingType.class);
public static final EnumSet<CraftingRequirements> REQUIREMENT_MET =
EnumSet.noneOf(CraftingRequirements.class);
private static final AdventureResult[] NO_INGREDIENTS = new AdventureResult[0];
public static final AdventureResult INIGO = EffectPool.get(EffectPool.INIGOS, 0);
public static final AdventureResult CRAFT_TEA = EffectPool.get(EffectPool.CRAFT_TEA, 0);
private static final HashMap<Integer, Concoction> chefStaff = new HashMap<>();
private static final HashMap<Integer, Concoction> singleUse = new HashMap<>();
private static final HashMap<Integer, Concoction> multiUse = new HashMap<>();
private static final HashMap<Integer, Concoction> noodles = new HashMap<>();
private static final HashMap<Integer, Concoction> meatStack = new HashMap<>();
private static CraftingType mixingMethod = null;
private static final EnumSet<CraftingRequirements> requirements =
EnumSet.noneOf(CraftingRequirements.class);
private static final EnumSet<CraftingMisc> info = EnumSet.noneOf(CraftingMisc.class);
private static int row = 0;
private ConcoctionDatabase() {}
public static final void resetQueue() {
LockableListModel<QueuedConcoction> queue = ConcoctionDatabase.queuedFood;
while (queue.size() > 0) {
ConcoctionDatabase.pop(ConcoctionType.FOOD);
}
queue = ConcoctionDatabase.queuedBooze;
while (queue.size() > 0) {
ConcoctionDatabase.pop(ConcoctionType.BOOZE);
}
queue = ConcoctionDatabase.queuedSpleen;
while (queue.size() > 0) {
ConcoctionDatabase.pop(ConcoctionType.SPLEEN);
}
queue = ConcoctionDatabase.queuedPotions;
while (queue.size() > 0) {
ConcoctionDatabase.pop(ConcoctionType.POTION);
}
}
public static void resetUsableList() {
// Construct the usable list from all known concoctions.
// This includes all items
ConcoctionDatabase.usableList.fill();
ConcoctionDatabase.usableList.sort(true);
}
static {
// This begins by opening up the data file and preparing
// a buffered reader; once this is done, every line is
// examined and float-referenced: once in the name-lookup,
// and again in the Id lookup.
try (BufferedReader reader =
FileUtilities.getVersionedReader("concoctions.txt", KoLConstants.CONCOCTIONS_VERSION)) {
String[] data;
while ((data = FileUtilities.readData(reader)) != null) {
ConcoctionDatabase.addConcoction(data);
}
} catch (IOException e) {
StaticEntity.printStackTrace(e);
}
}
private static void addConcoction(final String[] data) {
// Need at least concoction name and mixing method
if (data.length < 2) {
return;
}
boolean bogus = false;
ConcoctionDatabase.mixingMethod = null;
ConcoctionDatabase.requirements.clear();
ConcoctionDatabase.info.clear();
ConcoctionDatabase.row = 0;
String name = data[0];
String[] mixes = data[1].split("\\s*,\\s*");
for (String mix : mixes) {
ConcoctionDatabase.addCraftingData(mix, name);
}
if (ConcoctionDatabase.mixingMethod == null) {
RequestLogger.printLine("No mixing method specified for concoction: " + name);
bogus = true;
}
AdventureResult item = AdventureResult.parseItem(name, true);
int itemId = item.getItemId();
if (itemId < 0 && !ConcoctionDatabase.pseudoItemMixingMethod(ConcoctionDatabase.mixingMethod)) {
RequestLogger.printLine("Unknown concoction: " + name);
bogus = true;
}
AdventureResult[] ingredients = new AdventureResult[data.length - 2];
int param = 0;
if (data.length >= 2) {
for (int i = 2; i < data.length; ++i) {
if (StringUtilities.isNumeric(
data[i])) { // Treat all-numeric element as parameter instead of item.
// Up to 4 such parameters can be given if each fits in a byte.
// Currently only used for Clip Art
param = (param << 8) | StringUtilities.parseInt(data[i]);
continue;
}
AdventureResult ingredient = AdventureResult.parseItem(data[i], true);
if (ingredient == null || ingredient.getItemId() == -1 || ingredient.getName() == null) {
RequestLogger.printLine("Unknown ingredient (" + data[i] + ") for concoction: " + name);
bogus = true;
continue;
}
ingredients[i - 2] = ingredient;
}
}
if (!bogus) {
Concoction concoction =
new Concoction(
item,
ConcoctionDatabase.mixingMethod,
ConcoctionDatabase.requirements.clone(),
ConcoctionDatabase.info.clone(),
ConcoctionDatabase.row);
concoction.setParam(param);
Concoction existing = ConcoctionPool.get(item);
if (concoction.getMisc().contains(CraftingMisc.MANUAL)
|| (existing != null
&& existing.getMixingMethod()
!= CraftingType.NOCREATE)) { // Until multiple recipes are supported...
return;
}
if (ingredients.length > 0) {
for (AdventureResult ingredient : ingredients) {
if (ingredient == null) { // Was a parameter, not an ingredient.
continue;
}
concoction.addIngredient(ingredient);
if (ingredient.getItemId() == ItemPool.MEAT_STACK) {
ConcoctionDatabase.meatStack.put(itemId, concoction);
}
}
}
ConcoctionPool.set(concoction);
switch (ConcoctionDatabase.mixingMethod) {
case STAFF -> ConcoctionDatabase.chefStaff.put(ingredients[0].getItemId(), concoction);
case SINGLE_USE -> ConcoctionDatabase.singleUse.put(ingredients[0].getItemId(), concoction);
case MULTI_USE -> ConcoctionDatabase.multiUse.put(ingredients[0].getItemId(), concoction);
}
if (ConcoctionDatabase.requirements.contains(CraftingRequirements.PASTA)) {
ConcoctionDatabase.noodles.put(concoction.getItemId(), concoction);
}
}
}
public static Concoction chefStaffCreation(final int itemId) {
return ConcoctionDatabase.chefStaff.get(itemId);
}
public static Concoction singleUseCreation(final int itemId) {
return ConcoctionDatabase.singleUse.get(itemId);
}
public static Concoction multiUseCreation(final int itemId) {
return ConcoctionDatabase.multiUse.get(itemId);
}
public static Concoction noodleCreation(final int itemId) {
return ConcoctionDatabase.noodles.get(itemId);
}
public static Concoction meatStackCreation(final int itemId) {
return ConcoctionDatabase.meatStack.get(itemId);
}
private static boolean pseudoItemMixingMethod(final CraftingType mixingMethod) {
return mixingMethod == CraftingType.SUSHI
|| mixingMethod == CraftingType.VYKEA
|| mixingMethod == CraftingType.STILLSUIT;
}
public static final Set<AdventureResult> getKnownUses(final int itemId) {
Set<AdventureResult> uses = ConcoctionDatabase.knownUses.get(itemId);
return uses == null ? ConcoctionDatabase.EMPTY_SET : uses;
}
public static final Set<AdventureResult> getKnownUses(final AdventureResult item) {
return ConcoctionDatabase.getKnownUses(item.getItemId());
}
public static final boolean isPermittedMethod(
final CraftingType method, final EnumSet<CraftingRequirements> requirements) {
// If we can't make anything via this method, punt
if (!ConcoctionDatabase.PERMIT_METHOD.contains(method)) {
return false;
}
// If we don't meet special creation requirements for this item, punt
for (CraftingRequirements requirement : requirements) {
if (!ConcoctionDatabase.REQUIREMENT_MET.contains(requirement)) {
return false;
}
}
// Otherwise, go for it!
return true;
}
public static final boolean isPermittedMethod(AdventureResult item) {
return ConcoctionDatabase.checkPermittedMethod(ConcoctionPool.get(item));
}
public static final boolean isPermittedMethod(Concoction conc) {
// Also checks for Coinmaster accessibilty, since we know the item.
if (conc == null) {
return false;
}
// If this is a Coinmaster creation, the Coinmaster must be accessible
CraftingType method = conc.getMixingMethod();
if (method == CraftingType.COINMASTER) {
String message = conc.getPurchaseRequest().accessible();
if (message != null) {
return false;
}
}
EnumSet<CraftingRequirements> requirements = conc.getRequirements();
return ConcoctionDatabase.isPermittedMethod(method, requirements);
}
public static final boolean checkPermittedMethod(Concoction conc) {
// Same as isPermittedMethod(), but sets excuse.
// Also checks for Coinmaster accessibilty, since we know the item.
ConcoctionDatabase.excuse = null;
if (conc == null) {
return false;
}
CraftingType method = conc.getMixingMethod();
if (!ConcoctionDatabase.PERMIT_METHOD.contains(method)) {
ConcoctionDatabase.excuse = ConcoctionDatabase.EXCUSE.get(method);
return false;
}
// If this is a Coinmaster creation, the Coinmaster must be accessible
if (method == CraftingType.COINMASTER) {
String message = conc.getPurchaseRequest().accessible();
if (message != null) {
ConcoctionDatabase.excuse = message;
return false;
}
}
EnumSet<CraftingRequirements> requirements = conc.getRequirements();
for (CraftingRequirements next : requirements) {
if (!ConcoctionDatabase.REQUIREMENT_MET.contains(next)) {
ConcoctionDatabase.excuse =
"You lack a skill or other prerequisite for creating that item ("
+ ConcoctionDatabase.mixingMethodDescription(method, requirements)
+ ").";
return false;
}
}
return true;
}
public static final LockableListModel<AdventureResult> getQueuedIngredients(ConcoctionType type) {
return switch (type) {
case FOOD -> ConcoctionDatabase.queuedFoodIngredients;
case BOOZE -> ConcoctionDatabase.queuedBoozeIngredients;
case SPLEEN -> ConcoctionDatabase.queuedSpleenIngredients;
case POTION -> ConcoctionDatabase.queuedPotionIngredients;
default -> null;
};
}
public static final boolean canQueueFood(final int id) {
switch (id) {
case ItemPool.QUANTUM_TACO:
case ItemPool.MUNCHIES_PILL:
case ItemPool.WHETSTONE:
case ItemPool.MAGICAL_SAUSAGE:
return true;
}
if (ConcoctionDatabase.isMayo(id)
&& ConcoctionDatabase.lastQueuedMayo == 0
&& (!ConcoctionDatabase.queuedFood.isEmpty()
|| Preferences.getString("mayoInMouth").equals(""))) {
AdventureResult workshedItem = CampgroundRequest.getCurrentWorkshedItem();
if (workshedItem == null || workshedItem.getItemId() != ItemPool.MAYO_CLINIC) {
return false;
}
return true;
}
return false;
}
public static final boolean isMayo(final int id) {
return switch (id) {
case ItemPool.MAYONEX,
ItemPool.MAYODIOL,
ItemPool.MAYOSTAT,
ItemPool.MAYOZAPINE,
ItemPool.MAYOFLEX -> true;
default -> false;
};
}
public static final boolean canQueueBooze(final int id) {
return switch (id) {
case ItemPool.SCHRODINGERS_THERMOS -> true;
default -> false;
};
}
public static final void push(final Concoction c, final int quantity) {
LockableListModel<QueuedConcoction> queue;
LockableListModel<AdventureResult> queuedIngredients;
int id = c.getItemId();
ConsumptionType consumpt = ItemDatabase.getConsumptionType(id);
if (c.getFullness() > 0
|| consumpt == ConsumptionType.FOOD_HELPER
|| ConcoctionDatabase.canQueueFood(id)) {
queue = ConcoctionDatabase.queuedFood;
queuedIngredients = ConcoctionDatabase.queuedFoodIngredients;
if (ConcoctionDatabase.lastQueuedMayo == ItemPool.MAYODIOL) {
ConcoctionDatabase.queuedFullness--;
ConcoctionDatabase.queuedInebriety++;
}
} else if (c.getInebriety() > 0
|| consumpt == ConsumptionType.DRINK_HELPER
|| ConcoctionDatabase.canQueueBooze(id)) {
queue = ConcoctionDatabase.queuedBooze;
queuedIngredients = ConcoctionDatabase.queuedBoozeIngredients;
} else if (c.getSpleenHit() > 0) {
queue = ConcoctionDatabase.queuedSpleen;
queuedIngredients = ConcoctionDatabase.queuedSpleenIngredients;
} else {
queue = ConcoctionDatabase.queuedPotions;
queuedIngredients = ConcoctionDatabase.queuedPotionIngredients;
}
// Handle items that affect more than one organ
ConcoctionDatabase.queuedFullness += c.getFullness() * quantity;
ConcoctionDatabase.queuedInebriety += c.getInebriety() * quantity;
ConcoctionDatabase.queuedSpleenHit += c.getSpleenHit() * quantity;
// Get current values of things that a concoction can consume
int meat = ConcoctionDatabase.queuedMeatSpent;
int pulls = ConcoctionDatabase.queuedPullsUsed;
int tome = ConcoctionDatabase.queuedTomesUsed;
int stills = ConcoctionDatabase.queuedStillsUsed;
int extrudes = ConcoctionDatabase.queuedExtrudesUsed;
int free = ConcoctionDatabase.queuedFreeCraftingTurns;
int advs = ConcoctionDatabase.queuedAdventuresUsed;
// Queue the ingredients used by this concoction
ArrayList<AdventureResult> ingredients = new ArrayList<>();
c.queue(queuedIngredients, ingredients, quantity);
// Adjust lists to account for what just changed
meat = ConcoctionDatabase.queuedMeatSpent - meat;
if (meat != 0) {
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.MEAT_SPENT, meat));
}
pulls = ConcoctionDatabase.queuedPullsUsed - pulls;
if (pulls != 0) {
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.PULL, pulls));
}
tome = ConcoctionDatabase.queuedTomesUsed - tome;
if (tome != 0) {
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.TOME, tome));
}
extrudes = ConcoctionDatabase.queuedExtrudesUsed - extrudes;
if (extrudes != 0) {
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.EXTRUDE, extrudes));
}
stills = ConcoctionDatabase.queuedStillsUsed - stills;
if (stills != 0) {
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.STILL, stills));
}
advs = ConcoctionDatabase.queuedAdventuresUsed - advs;
if (advs != 0) {
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.ADV, advs));
}
free = ConcoctionDatabase.queuedFreeCraftingTurns - free;
if (free != 0) {
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.FREE_CRAFT, free));
}
if (c.fancydog) {
ConcoctionDatabase.queuedFancyDog = true;
}
if (c.speakeasy != null) {
ConcoctionDatabase.queuedSpeakeasyDrink += quantity;
}
if (ConcoctionDatabase.isMayo(id)) {
ConcoctionDatabase.lastQueuedMayo = id;
} else {
ConcoctionDatabase.lastQueuedMayo = 0;
}
if (c.getInebriety() == 1
&& !ConcoctionDatabase.queuedMimeShotglass
&& InventoryManager.getCount(ItemPool.MIME_SHOTGLASS) > 0
&& !Preferences.getBoolean("_mimeArmyShotglassUsed")) {
ConcoctionDatabase.queuedInebriety--;
ConcoctionDatabase.queuedMimeShotglass = true;
}
queue.add(
new QueuedConcoction(
c, quantity, ingredients, meat, pulls, tome, stills, extrudes, advs, free));
if (c.getItemId() == ItemPool.SMORE) {
ConcoctionDatabase.queuedSmores++;
ConsumablesDatabase.setSmoresData();
}
if (c.getItemId() == ItemPool.AFFIRMATION_COOKIE) {
ConcoctionDatabase.queuedAffirmationCookies++;
}
if (c.getItemId() == ItemPool.SPAGHETTI_BREAKFAST) {
ConcoctionDatabase.queuedSpaghettiBreakfast++;
}
if (c.getItemId() == ItemPool.EVERFULL_GLASS) {
ConcoctionDatabase.queuedEverfullGlass++;
}
if (c.getItemId() == ItemPool.PIRATE_FORK) {
ConcoctionDatabase.queuedPirateFork++;
}
}
public static final QueuedConcoction pop(ConcoctionType type) {
LockableListModel<QueuedConcoction> queue;
LockableListModel<AdventureResult> queuedIngredients;
switch (type) {
case FOOD:
queue = ConcoctionDatabase.queuedFood;
queuedIngredients = ConcoctionDatabase.queuedFoodIngredients;
break;
case BOOZE:
queue = ConcoctionDatabase.queuedBooze;
queuedIngredients = ConcoctionDatabase.queuedBoozeIngredients;
break;
case SPLEEN:
queue = ConcoctionDatabase.queuedSpleen;
queuedIngredients = ConcoctionDatabase.queuedSpleenIngredients;
break;
case POTION:
queue = ConcoctionDatabase.queuedPotions;
queuedIngredients = ConcoctionDatabase.queuedPotionIngredients;
break;
// Unreachable
default:
return null;
}
if (queue.isEmpty()) {
return null;
}
QueuedConcoction qc = queue.remove(queue.size() - 1);
Concoction c = qc.getConcoction();
int quantity = qc.getCount();
c.queued -= quantity;
ConcoctionDatabase.queuedFullness -= c.getFullness() * quantity;
ConcoctionDatabase.queuedInebriety -= c.getInebriety() * quantity;
ConcoctionDatabase.queuedSpleenHit -= c.getSpleenHit() * quantity;
for (AdventureResult ingredient : qc.getIngredients()) {
AdventureResult.addOrRemoveResultToList(queuedIngredients, ingredient.getNegation());
}
int meat = qc.getMeat();
if (meat != 0) {
ConcoctionDatabase.queuedMeatSpent -= meat;
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.MEAT_SPENT, -meat));
}
int pulls = qc.getPulls();
if (pulls != 0) {
c.queuedPulls -= pulls;
ConcoctionDatabase.queuedPullsUsed -= pulls;
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.PULL, -pulls));
}
int tome = qc.getTomes();
if (tome != 0) {
ConcoctionDatabase.queuedTomesUsed -= tome;
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.TOME, -tome));
}
int stills = qc.getStills();
if (stills != 0) {
ConcoctionDatabase.queuedStillsUsed -= stills;
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.STILL, -stills));
}
int extrudes = qc.getExtrudes();
if (extrudes != 0) {
ConcoctionDatabase.queuedExtrudesUsed -= extrudes;
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.EXTRUDE, -extrudes));
}
int advs = qc.getAdventures();
if (advs != 0) {
ConcoctionDatabase.queuedAdventuresUsed -= advs;
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.ADV, -advs));
}
int free = qc.getFreeCrafts();
if (free != 0) {
ConcoctionDatabase.queuedFreeCraftingTurns -= free;
AdventureResult.addOrRemoveResultToList(
queuedIngredients, new AdventureResult(AdventureResult.FREE_CRAFT, -free));
}
if (qc.getConcoction().fancydog) {
ConcoctionDatabase.queuedFancyDog = false;
}
if (qc.getConcoction().speakeasy != null) {
ConcoctionDatabase.queuedSpeakeasyDrink -= quantity;
}
if (ConcoctionDatabase.isMayo(c.getItemId())) {
ConcoctionDatabase.lastQueuedMayo = 0;
}
// Is the new last item Mayo ?
if (!queue.isEmpty()) {
QueuedConcoction lqc = queue.get(queue.size() - 1);
Concoction lc = lqc.getConcoction();
int id = lc.getItemId();
if (ConcoctionDatabase.isMayo(id)) {
ConcoctionDatabase.lastQueuedMayo = id;
if (id == ItemPool.MAYODIOL) {
ConcoctionDatabase.queuedFullness++;
ConcoctionDatabase.queuedInebriety--;
}
}
}
if (ConcoctionDatabase.queuedMimeShotglass && type == ConcoctionType.BOOZE) {
// Did we remove last 1 fullness drink ?
boolean shotglassUsed = true;
for (QueuedConcoction drink : queue) {
Concoction drinkConc = drink.getConcoction();
if (drinkConc.getInebriety() == 1) {
shotglassUsed = false;
}
}
if (shotglassUsed) {
ConcoctionDatabase.queuedInebriety++;
ConcoctionDatabase.queuedMimeShotglass = false;
}
}
if (c.getItemId() == ItemPool.SMORE) {
ConcoctionDatabase.queuedSmores--;
ConsumablesDatabase.setSmoresData();
// The last s'more was smaller than the next one, so adjust queued fullness
ConcoctionDatabase.queuedFullness++;
}
if (c.getItemId() == ItemPool.AFFIRMATION_COOKIE) {
ConcoctionDatabase.queuedAffirmationCookies--;
}
if (c.getItemId() == ItemPool.SPAGHETTI_BREAKFAST) {
ConcoctionDatabase.queuedSpaghettiBreakfast--;
}
if (c.getItemId() == ItemPool.EVERFULL_GLASS) {
ConcoctionDatabase.queuedEverfullGlass--;
}
if (c.getItemId() == ItemPool.PIRATE_FORK) {
ConcoctionDatabase.queuedPirateFork--;
}
return qc;
}
public static final void addUsableConcoction(final Concoction c) {
ConcoctionDatabase.usableList.add(c);
ConcoctionDatabase.usableList.sort();
}
public static final UsableConcoctions getUsables() {
return ConcoctionDatabase.usableList;
}
public static final LockableListModel<CreateItemRequest> getCreatables() {
return ConcoctionDatabase.creatableList;
}
public static final LockableListModel<QueuedConcoction> getQueue(ConcoctionType type) {
return switch (type) {
case FOOD -> ConcoctionDatabase.queuedFood;
case BOOZE -> ConcoctionDatabase.queuedBooze;
case SPLEEN -> ConcoctionDatabase.queuedSpleen;
case POTION -> ConcoctionDatabase.queuedPotions;
default -> null;
};
// Unreachable
}
private static AdventureResult currentConsumptionHelper(ConcoctionType type) {
return switch (type) {
case FOOD -> EatItemRequest.currentFoodHelper();
case BOOZE -> DrinkItemRequest.currentDrinkHelper();
default -> null;
};
}
private static void clearConsumptionHelper(ConcoctionType type) {
switch (type) {
case FOOD -> EatItemRequest.clearFoodHelper();
case BOOZE -> DrinkItemRequest.clearBoozeHelper();
}
}
private static int lastUnconsumed(int quantity, ConcoctionType type) {
return quantity
- (type == ConcoctionType.FOOD
? EatItemRequest.foodConsumed
: type == ConcoctionType.BOOZE ? DrinkItemRequest.boozeConsumed : 0);
}
public static final void handleQueue(ConcoctionType type, ConsumptionType consumptionType) {
// consumptionType can be:
//
// ConsumptionType.NONE - create or retrieve items
// ConsumptionType.EAT - eat food items
// ConsumptionType.DRINK - drink booze items
// ConsumptionType.SPLEEN - use spleen items
// ConsumptionType.GLUTTONOUS_GHOST - binge ghost with food
// ConsumptionType.SPIRIT_HOBO - binge hobo with booze
// ConsumptionType.USE - use potions
// ConsumptionType.USE_MULTIPLE - use potions
// ConsumptionType.AVATAR_POTION - use potions
QueuedConcoction currentItem;
Stack<QueuedConcoction> toProcess = new Stack<>();
// Remove items in inverse order from the queue and push them on a stack.
while ((currentItem = ConcoctionDatabase.pop(type)) != null) {
toProcess.push(currentItem);
}
// If we refreshed concoctions while there were items queued,
// the creatable amounts assume that queued ingredients are
// already spoken for. Refresh again now that the queue is
// empty.
ConcoctionDatabase.refreshConcoctionsNow();
try (Checkpoint checkpoint = new Checkpoint()) {
ConcoctionDatabase.handleQueue(toProcess, type, consumptionType);
}
// Refresh again now that ingredients have been deducted
ConcoctionDatabase.refreshConcoctions();
}
private static void handleQueue(
Stack<QueuedConcoction> toProcess, ConcoctionType type, ConsumptionType consumptionType) {
// Keep track of current consumption helper. These can be
// "queued" by simply "using" them. Account for that.
AdventureResult helper = ConcoctionDatabase.currentConsumptionHelper(type);
// Since items were pushed in inverse order from the queue,
// popping the stack will get items in actual queued order.
while (!toProcess.isEmpty()) {
QueuedConcoction currentItem = toProcess.pop();
Concoction c = currentItem.getConcoction();
int quantity = currentItem.getCount();
if (consumptionType != ConsumptionType.EAT
&& consumptionType != ConsumptionType.DRINK
&& consumptionType != ConsumptionType.SPLEEN) {
// Binge familiar or create only
// If it's not an actual item, it's a purchase from a cafe.
// Those are invalid for anything except "use"
if (c.getItem() == null) {
continue;
}
ConsumptionType consumpt = ItemDatabase.getConsumptionType(c.getItemId());
// Skip consumption helpers; we cannot binge a
// familiar with them and we don't "create" them
if (consumpt == ConsumptionType.FOOD_HELPER || consumpt == ConsumptionType.DRINK_HELPER) {
continue;
}
// Certain items are virtual consumption
// helpers, but are "used" first. Skip if
// bingeing familiar.
if ((consumptionType == ConsumptionType.GLUTTONOUS_GHOST && consumpt != ConsumptionType.EAT)
|| (consumptionType == ConsumptionType.SPIRIT_HOBO
&& consumpt != ConsumptionType.DRINK)) {
continue;
}
// Retrieve the desired items, creating if necessary
AdventureResult toConsume = c.getItem().getInstance(quantity);
InventoryManager.retrieveItem(toConsume);
if (consumptionType == ConsumptionType.GLUTTONOUS_GHOST
| consumptionType == ConsumptionType.SPIRIT_HOBO) {
// Binge the familiar!
RequestThread.postRequest(UseItemRequest.getInstance(consumptionType, toConsume));
continue;
}
if (consumptionType == ConsumptionType.NONE) {
// Create only
continue;
}
// CONSUME_USE, CONSUME_MULTIPLE, CONSUME_AVATAR - potions
// Consume it.
}
// "using" the item will either queue a consumption
// helper or actually consume the item.
ConcoctionDatabase.consumeItem(c, quantity, consumptionType);
if (!KoLmafia.permitsContinue()) {
// Consumption failed.
// Get current state of appropriate consumption helper
helper = ConcoctionDatabase.currentConsumptionHelper(type);
// If there was a consumption helper queued, clear it
if (helper != null) {
ConcoctionDatabase.clearConsumptionHelper(type);
}
// If the "consumption queue" is not visible to
// the user, just quit now.
if (!Preferences.getBoolean("addCreationQueue")) {
break;
}
// Otherwise, put the item and remaining
// unprocessed items back on queue
// If there is a consumption helper queued, push that first.
if (helper != null) {
ConcoctionDatabase.push(ConcoctionPool.get(helper), helper.getCount());
}
// Push current item back on consumption queue
ConcoctionDatabase.push(c, ConcoctionDatabase.lastUnconsumed(quantity, type));
// Move items from unprocessed queue back to
// consumption queue
while (!toProcess.isEmpty()) {
// Pop unprocessed items and push back
// on appropriate consumption queue
currentItem = toProcess.pop();
c = currentItem.getConcoction();
quantity = currentItem.getCount();
ConcoctionDatabase.push(c, quantity);
}
// Done queuing items
KoLmafia.forceContinue();
ConcoctionDatabase.refreshConcoctions();
ConcoctionDatabase.getUsables().sort();
break;
}
// Get current state of appropriate consumption helper
helper = ConcoctionDatabase.currentConsumptionHelper(type);
}
}
private static void consumeItem(Concoction c, int quantity, ConsumptionType consumptionType) {
AdventureResult item = c.getItem();
// If it's food we're consuming, we have a MayoMinder set, and we are autostocking it, do so
// Don't get Mayostat if it's a 1 fullness food, or it'd be wasted
// Don't get Mayodiol if it'd cause you to overdrink
String minderSetting = Preferences.getString("mayoMinderSetting");
AdventureResult workshedItem = CampgroundRequest.getCurrentWorkshedItem();
if (item != null
&& consumptionType == ConsumptionType.EAT
&& !ConcoctionDatabase.isMayo(item.getItemId())
&& !minderSetting.equals("")
&& Preferences.getBoolean("autoFillMayoMinder")
&& !(minderSetting.equals("Mayostat") && c.getFullness() == 1)
&& !(minderSetting.equals("Mayodiol")
&& KoLCharacter.getInebrietyLimit() == KoLCharacter.getInebriety())
&& workshedItem != null
&& workshedItem.getItemId() == ItemPool.MAYO_CLINIC) {
int mayoCount = Preferences.getString("mayoInMouth").equals("") ? 0 : 1;
if (quantity > mayoCount && c.getFullness() != 0) {
InventoryManager.retrieveItem(minderSetting, quantity - mayoCount);
}
}
// If there's an actual item, it's not from a store
if (item != null && c.speakeasy == null) {
// If concoction is a normal item, use normal item acquisition methods.
if (item.getItemId() > 0) {
UseItemRequest request;
// First, consume any items which appear in the inventory.
int initial = Math.min(quantity, InventoryManager.getCount(item.getItemId()));
if (initial > 0) {
request = UseItemRequest.getInstance(consumptionType, item.getInstance(initial));
RequestThread.postRequest(request);
quantity -= initial;
}
// Second, let UseItemRequest acquire remaining items.