forked from kolmafia/kolmafia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AreaCombatData.java
1681 lines (1489 loc) 路 62.1 KB
/
AreaCombatData.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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import net.sourceforge.kolmafia.KoLConstants.Stat;
import net.sourceforge.kolmafia.objectpool.EffectPool;
import net.sourceforge.kolmafia.objectpool.FamiliarPool;
import net.sourceforge.kolmafia.objectpool.IntegerPool;
import net.sourceforge.kolmafia.persistence.AdventureDatabase;
import net.sourceforge.kolmafia.persistence.AdventureQueueDatabase;
import net.sourceforge.kolmafia.persistence.AdventureSpentDatabase;
import net.sourceforge.kolmafia.persistence.BountyDatabase;
import net.sourceforge.kolmafia.persistence.ItemDatabase;
import net.sourceforge.kolmafia.persistence.MonsterDatabase;
import net.sourceforge.kolmafia.persistence.MonsterDatabase.Element;
import net.sourceforge.kolmafia.persistence.MonsterDatabase.Phylum;
import net.sourceforge.kolmafia.persistence.QuestDatabase;
import net.sourceforge.kolmafia.persistence.QuestDatabase.Quest;
import net.sourceforge.kolmafia.preferences.Preferences;
import net.sourceforge.kolmafia.request.FightRequest;
import net.sourceforge.kolmafia.session.BanishManager;
import net.sourceforge.kolmafia.session.CrystalBallManager;
import net.sourceforge.kolmafia.session.EncounterManager;
import net.sourceforge.kolmafia.session.EncounterManager.EncounterType;
import net.sourceforge.kolmafia.session.EquipmentManager;
import net.sourceforge.kolmafia.session.TurnCounter;
import net.sourceforge.kolmafia.utilities.StringUtilities;
public class AreaCombatData {
private static double lastDropModifier = 0.0;
private static double lastDropMultiplier = 0.0;
private int minHit;
private int maxHit;
private int minEvade;
private int maxEvade;
private int poison;
private int jumpChance;
private final int combats;
private double weights;
// Parallel lists: monsters and encounter weighting
private final List<MonsterData> monsters;
private final List<MonsterData> superlikelyMonsters;
private final Map<MonsterData, Integer> baseWeightings;
private final Map<MonsterData, Integer> currentWeightings;
private final Map<MonsterData, Integer> rejection;
private final String zone;
// Flags in low-order bits of weightings
private static final int ASCENSION_ODD = 0x01;
private static final int ASCENSION_EVEN = 0x02;
private static final int WEIGHT_SHIFT = 2;
// Combat-data-relevant effects
private static final AdventureResult EW_THE_HUMANITY = EffectPool.get(EffectPool.EW_THE_HUMANITY);
private static final AdventureResult A_BEASTLY_ODOR = EffectPool.get(EffectPool.A_BEASTLY_ODOR);
public AreaCombatData(String zone, final int combats) {
this.zone = zone;
this.monsters = new ArrayList<>();
this.superlikelyMonsters = new ArrayList<>();
this.baseWeightings = new HashMap<>();
this.currentWeightings = new HashMap<>();
this.rejection = new HashMap<>();
this.combats = combats;
this.weights = 0.0;
this.minHit = Integer.MAX_VALUE;
this.maxHit = 0;
this.minEvade = Integer.MAX_VALUE;
this.maxEvade = 0;
this.poison = Integer.MAX_VALUE;
this.jumpChance = Integer.MAX_VALUE;
}
public void recalculate() {
this.minHit = Integer.MAX_VALUE;
this.maxHit = 0;
this.minEvade = Integer.MAX_VALUE;
this.maxEvade = 0;
this.jumpChance = 100;
double weights = 0.0;
Map<MonsterData, Integer> currentWeightings = new HashMap<>();
for (MonsterData monster : monsters) {
// Weighting has two low bits which represent odd or even ascension restriction
// Strip them out now and restore them at the end
int baseWeighting = this.baseWeightings.get(monster);
int flags = baseWeighting & 3;
baseWeighting = baseWeighting >> WEIGHT_SHIFT;
String monsterName = monster.getName();
Phylum monsterPhylum = monster.getPhylum();
baseWeighting = AreaCombatData.adjustConditionalWeighting(zone, monsterName, baseWeighting);
int currentWeighting = baseWeighting;
// If olfacted, add three to encounter pool
if (Preferences.getString("olfactedMonster").equals(monsterName)
&& KoLConstants.activeEffects.contains(FightRequest.ONTHETRAIL)) {
currentWeighting += 3 * baseWeighting;
}
// If Nosy Nose sniffed, and is current familiar, add one to encounter pool
if (Preferences.getString("nosyNoseMonster").equals(monsterName)
&& KoLCharacter.getFamiliar().getId() == FamiliarPool.NOSY_NOSE) {
currentWeighting += baseWeighting;
}
// If Red Snapper tracks its phylum, and is current familiar, add two to encounter pool
if (Preferences.getString("redSnapperPhylum").equals(monsterPhylum.toString())
&& KoLCharacter.getFamiliar().getId() == FamiliarPool.RED_SNAPPER) {
currentWeighting += 2 * baseWeighting;
}
// If any relevant Daily Candle familiar-tracking potions are active, add two(?) to the
// encounter pool
if ((monsterPhylum.equals(Phylum.HUMANOID)
&& KoLConstants.activeEffects.contains(EW_THE_HUMANITY))
|| (monsterPhylum.equals(Phylum.BEAST)
&& KoLConstants.activeEffects.contains(A_BEASTLY_ODOR))) {
currentWeighting += 2 * baseWeighting;
}
// If Gallapagosian Mating Call used, add one to encounter pool
if (Preferences.getString("_gallapagosMonster").equals(monsterName)) {
currentWeighting += baseWeighting;
}
// If Offer Latte to Opponent used, add two to encounter pool
if (Preferences.getString("_latteMonster").equals(monsterName)
&& TurnCounter.isCounting("Latte Monster")) {
currentWeighting += 2 * baseWeighting;
}
// If Superficially Interested used, add three to encounter pool
if (Preferences.getString("superficiallyInterestedMonster").equals(monsterName)
&& TurnCounter.isCounting("Superficially Interested Monster")) {
currentWeighting += 3 * baseWeighting;
}
// If Staff of the Cream of the Cream jiggle, add two to encounter pool
if (Preferences.getString("_jiggleCreamedMonster").equals(monsterName)) {
currentWeighting += 2 * baseWeighting;
}
// If Make Friends used, add three to encounter pool
if (Preferences.getString("makeFriendsMonster").equals(monsterName)) {
currentWeighting += 3 * baseWeighting;
}
// If Curse of Stench used, add three to encounter pool
if (Preferences.getString("stenchCursedMonster").equals(monsterName)) {
currentWeighting += 3 * baseWeighting;
}
// If Long Con used, add three to encounter pool
if (Preferences.getString("longConMonster").equals(monsterName)) {
currentWeighting += 3 * baseWeighting;
}
if (BanishManager.isBanished(monsterName)) {
// Banishing reduces number of copies
currentWeighting -= baseWeighting;
// If this takes it to zero chance, it's properly banished
if (currentWeighting == 0) {
currentWeighting = -3;
}
}
// Not available in current
if ((flags == ASCENSION_ODD && KoLCharacter.getAscensions() % 2 == 1)
|| (flags == ASCENSION_EVEN && KoLCharacter.getAscensions() % 2 == 0)) {
currentWeighting = -2; // impossible this ascension
}
// Temporarily set to 0% chance
if (baseWeighting == -4) {
currentWeighting = -4;
}
currentWeightings.put(monster, (currentWeighting << WEIGHT_SHIFT) | flags);
// Omit currently 0% chance, banished (-3), impossible (-2) and ultra-rare (-1) monsters
if (currentWeighting < 0) {
continue;
}
weights += currentWeighting * (1 - (double) this.getRejection(monster) / 100);
this.addMonsterStats(monster);
}
this.weights = weights;
this.currentWeightings.putAll(currentWeightings);
// Take into account superlikely monsters if they have a non zero chance to appear
for (MonsterData monster : superlikelyMonsters) {
if (AreaCombatData.superlikelyChance(monster) > 0) {
this.addMonsterStats(monster);
}
}
}
private void addMonsterStats(MonsterData monster) {
// These include current monster level and Beeosity
int attack = monster.getAttack();
if (attack < this.minEvade) {
this.minEvade = attack;
}
if (attack > this.maxEvade) {
this.maxEvade = attack;
}
int defense = monster.getDefense();
if (defense < this.minHit) {
this.minHit = defense;
}
if (defense > this.maxHit) {
this.maxHit = defense;
}
int jumpChance = monster.getJumpChance();
if (jumpChance < this.jumpChance) {
this.jumpChance = jumpChance;
}
}
public boolean addMonster(String name) {
int weighting = 1;
int flags = ASCENSION_EVEN | ASCENSION_ODD;
int rejection = 0;
int colon = name.indexOf(":");
if (colon > 0) {
String weight = name.substring(colon + 1).trim();
name = name.substring(0, colon);
String flag = null;
if (weight.length() == 0) {
KoLmafia.updateDisplay("Missing entry after colon for " + name + " in combats.txt.");
return false;
}
for (int i = 0; i < weight.length(); i++) {
char ch = weight.charAt(i);
if (i == 0 && ch == '-') {
continue;
}
if (!Character.isDigit(ch)) {
flag = weight.substring(i);
weight = weight.substring(0, i);
break;
}
}
if (!StringUtilities.isNumeric(weight)) {
KoLmafia.updateDisplay(
"First entry after colon for " + name + " in combats.txt is not numeric.");
return false;
}
weighting = Integer.parseInt(weight);
// Only one flag per monster is is supported
if (flag != null) {
switch (flag.charAt(0)) {
case 'e':
flags = ASCENSION_EVEN;
break;
case 'o':
flags = ASCENSION_ODD;
break;
case 'r':
if (flag.length() > 1) {
if (!StringUtilities.isNumeric(flag.substring(1))) {
KoLmafia.updateDisplay(
"Rejection percentage specified for "
+ name
+ " in combats.txt is not numeric.");
return false;
}
rejection = StringUtilities.parseInt(flag.substring(1));
} else {
KoLmafia.updateDisplay(
"No rejection percentage specified for " + name + " in combats.txt.");
return false;
}
break;
default:
KoLmafia.updateDisplay(
"Unknown flag " + flag.charAt(0) + " specified for " + name + " in combats.txt.");
return false;
}
}
}
MonsterData monster = MonsterDatabase.findMonster(name);
if (monster == null) {
KoLmafia.updateDisplay(
"Monster name '" + name + "' in combats.txt does not exactly match a known monster,");
return false;
}
if (EncounterManager.isSuperlikelyMonster(monster.getName())) {
this.superlikelyMonsters.add(monster);
} else {
this.monsters.add(monster);
this.baseWeightings.put(monster, IntegerPool.get((weighting << WEIGHT_SHIFT) | flags));
this.currentWeightings.put(monster, IntegerPool.get((weighting << WEIGHT_SHIFT) | flags));
this.rejection.put(monster, IntegerPool.get(rejection));
}
this.poison = Math.min(this.poison, monster.getPoison());
// Don't let ultra-rare monsters skew hit and evade numbers -
// or anything else.
if (weighting < 0) {
return true;
}
// Don't let special monsters skew combat percentage numbers
// or things derived from them, like area-wide item and meat
// drops. Do include them in hit and evade ("safety") numbers.
// Assume that the number and total weights of even- and
// odd-ascension-only monsters are equal.
if (weighting > 0 && flags != ASCENSION_ODD) {
this.weights += weighting * (1 - (double) rejection / 100);
}
this.addMonsterStats(monster);
return true;
}
/**
* Counts the number of monsters in this area that drop the item with the given ID.
*
* @param itemId the itemID of the the item to count
* @return the number of monsters in this area dropping the item
*/
public int countMonstersDroppingItem(final int itemId) {
int total = 0;
for (MonsterData monster : this.monsters) {
for (AdventureResult item : monster.getItems()) {
if (item.getItemId() == itemId) {
total++;
break;
}
}
}
for (MonsterData monster : this.superlikelyMonsters) {
for (AdventureResult item : monster.getItems()) {
if (item.getItemId() == itemId) {
total++;
break;
}
}
}
return total;
}
public List<MonsterData> getMonsters() {
return this.monsters;
}
public int getMonsterCount() {
return this.monsters.size();
}
public List<MonsterData> getSuperlikelyMonsters() {
return this.superlikelyMonsters;
}
public int getSuperlikelyMonsterCount() {
return this.superlikelyMonsters.size();
}
public int getAvailableMonsterCount() {
return (int)
Stream.concat(
monsters.stream().map(m -> getWeighting(m) > 0),
superlikelyMonsters.stream().map(m -> superlikelyChance(m) > 0))
.filter(p -> p)
.count();
}
public MonsterData getMonster(final int i) {
return this.monsters.get(i);
}
public MonsterData getSuperlikelyMonster(final int i) {
return this.superlikelyMonsters.get(i);
}
public boolean hasMonster(final MonsterData m) {
if (m == null) {
return false;
}
return this.monsters.contains(m) || this.superlikelyMonsters.contains(m);
}
public int getMonsterIndex(MonsterData monster) {
return this.monsters.indexOf(monster);
}
public int getSuperlikelyMonsterIndex(MonsterData monster) {
return this.superlikelyMonsters.indexOf(monster);
}
public int getWeighting(final MonsterData monster) {
int raw = (this.currentWeightings.getOrDefault(monster, 0)).intValue();
if (((raw >> (KoLCharacter.getAscensions() & 1)) & 1) == 0) {
return -2; // impossible this ascension
}
return raw >> WEIGHT_SHIFT;
}
public int getRejection(final MonsterData monster) {
return this.rejection.get(monster);
}
public double totalWeighting() {
return this.weights;
}
public int combats() {
return this.combats;
}
public int minHit() {
return this.minHit == Integer.MAX_VALUE ? 0 : this.minHit;
}
public int maxHit() {
return this.maxHit;
}
public int minEvade() {
return this.minEvade == Integer.MAX_VALUE ? 0 : this.minEvade;
}
public int maxEvade() {
return this.maxEvade;
}
public int poison() {
return this.poison;
}
public boolean willHitSomething() {
int hitStat = EquipmentManager.getAdjustedHitStat();
return AreaCombatData.hitPercent(hitStat, this.minHit()) > 0.0;
}
public int getJumpChance() {
return getJumpChance(m -> m.getJumpChance());
}
public int getJumpChance(int initiative, int ml) {
return getJumpChance(m -> m.getJumpChance(initiative, ml));
}
public int getJumpChance(int initiative) {
return getJumpChance(m -> m.getJumpChance(initiative));
}
public int getJumpChance(Function<MonsterData, Integer> fn) {
return getMonsterData(true).entrySet().stream()
.filter(e -> e.getValue() > 0)
.mapToInt(e -> fn.apply(e.getKey()))
.min()
.orElse(0);
}
public double getAverageML() {
double averageML =
monsters.stream()
.filter(m -> getWeighting(m) > 0)
.map(
m ->
(double) getWeighting(m)
* (1 - (double) this.getRejection(m) / 100)
/ this.totalWeighting())
.reduce(0.0, Double::sum);
double averageSuperlikelyML = 0.0;
double superlikelyChance = 0.0;
for (MonsterData monster : this.superlikelyMonsters) {
double chance = AreaCombatData.superlikelyChance(monster);
if (chance > 0) {
averageSuperlikelyML += chance * monster.getAttack();
superlikelyChance += chance;
}
}
return averageML * (1 - superlikelyChance / 100) + averageSuperlikelyML;
}
@Override
public String toString() {
return this.toString(false);
}
public String toString(final boolean fullString) {
StringBuffer buffer = new StringBuffer();
buffer.append("<html><head>");
buffer.append("<style>");
buffer.append("body { font-family: sans-serif; font-size: ");
buffer.append(Preferences.getString("chatFontSize"));
buffer.append("; }");
buffer.append("</style>");
buffer.append("</head><body>");
this.getSummary(buffer, fullString);
this.getEncounterData(buffer);
this.appendMonsterData(buffer, fullString);
buffer.append("</body></html>");
return buffer.toString();
}
public void getSummary(final StringBuffer buffer, final boolean fullString) {
// Get up-to-date monster stats in area summary
this.recalculate();
int moxie = KoLCharacter.getAdjustedMoxie();
String statName = EquipmentManager.getHitStatType() == Stat.MOXIE ? "Mox" : "Mus";
int hitstat = EquipmentManager.getAdjustedHitStat();
double minHitPercent = AreaCombatData.hitPercent(hitstat, this.minHit());
double maxHitPercent = AreaCombatData.hitPercent(hitstat, this.maxHit);
int minPerfectHit = AreaCombatData.perfectHit(hitstat, this.minHit());
int maxPerfectHit = AreaCombatData.perfectHit(hitstat, this.maxHit);
double minEvadePercent = AreaCombatData.hitPercent(moxie, this.minEvade());
double maxEvadePercent = AreaCombatData.hitPercent(moxie, this.maxEvade);
int minPerfectEvade = AreaCombatData.perfectHit(moxie, this.minEvade());
int maxPerfectEvade = AreaCombatData.perfectHit(moxie, this.maxEvade);
int jumpChance = this.jumpChance;
// statGain constants
double experienceAdjustment = KoLCharacter.getExperienceAdjustment();
// Area Combat percentage
double combatFactor = this.areaCombatPercent() / 100.0;
// Iterate once through monsters to calculate average statGain
double averageExperience = 0.0;
for (MonsterData monster : monsters) {
int weighting = this.getWeighting(monster);
// Omit impossible (-2), ultra-rare (-1) and special/banished (0) monsters
if (weighting < 1) {
continue;
}
double weight =
(double) weighting
* (1 - (double) this.getRejection(monster) / 100)
/ this.totalWeighting();
int ml = monster.ML();
averageExperience +=
weight * (monster.getExperience() + experienceAdjustment - ml / (ml > 0 ? 6.0 : 8.0));
}
double averageSuperlikelyExperience = 0.0;
double superlikelyChance = 0.0;
for (MonsterData monster : this.superlikelyMonsters) {
String monsterName = monster.getName();
double chance = AreaCombatData.superlikelyChance(monsterName);
if (chance > 0) {
averageSuperlikelyExperience +=
chance / 100 * (monster.getExperience() + experienceAdjustment);
superlikelyChance += chance;
}
}
buffer.append("<b>Hit</b>: ");
buffer.append(
this.getRateString(
minHitPercent, minPerfectHit, maxHitPercent, maxPerfectHit, statName, fullString));
buffer.append("<br><b>Evade</b>: ");
buffer.append(
this.getRateString(
minEvadePercent, minPerfectEvade, maxEvadePercent, maxPerfectEvade, "Mox", fullString));
buffer.append("<br><b>Jump Chance</b>: ");
buffer.append(jumpChance + "%");
buffer.append("<br><b>Combat Rate</b>: ");
double combatXP =
averageSuperlikelyExperience
+ averageExperience * (1 - superlikelyChance / 100) * combatFactor;
if (this.combats > 0) {
buffer.append(
this.format(superlikelyChance + (1 - superlikelyChance / 100) * combatFactor * 100.0)
+ "%");
buffer.append("<br><b>Combat XP</b>: " + KoLConstants.FLOAT_FORMAT.format(combatXP));
} else if (this.combats == 0) {
buffer.append("0%");
} else {
buffer.append("No data");
}
}
public Map<MonsterData, Double> getMonsterData() {
return getMonsterData(false);
}
public Map<MonsterData, Double> getMonsterData(boolean stateful) {
Map monsterData = new HashMap<>();
if (stateful) {
recalculate();
}
double totalSuperlikelyChance = 0.0;
for (MonsterData monster : superlikelyMonsters) {
double chance = superlikelyChance(monster);
monsterData.put(monster, chance);
totalSuperlikelyChance += chance;
}
double combatFactor = this.areaCombatPercent(stateful) / 100.0;
for (MonsterData monster : monsters) {
int weighting = getWeighting(monster);
if (weighting == -2) {
continue;
}
// Negative weight will set this to zero (which is good!)
double chance =
Math.max(
0,
100.0
* combatFactor
* (1 - totalSuperlikelyChance / 100)
* weighting
* (1 - (double) getRejection(monster) / 100));
if (stateful) {
chance = AdventureQueueDatabase.applyQueueEffects(chance, monster, this);
} else {
chance = chance / totalWeighting();
}
monsterData.put(monster, chance);
}
return monsterData;
}
public void appendMonsterData(final StringBuffer buffer, final boolean fullString) {
int moxie = KoLCharacter.getAdjustedMoxie();
int hitstat = EquipmentManager.getAdjustedHitStat();
for (Map.Entry<MonsterData, Double> entry : getMonsterData(true).entrySet()) {
MonsterData monster = entry.getKey();
double chance = entry.getValue();
buffer
.append("<br><br>")
.append(
this.getMonsterString(
monster, moxie, hitstat, getWeighting(monster), chance, fullString));
}
}
public void getEncounterData(final StringBuffer buffer) {
String environment = AdventureDatabase.getEnvironment(this.zone);
if (environment == null) {
buffer.append("<br>");
buffer.append("<b>Environment:</b> unknown");
} else {
buffer.append("<br>");
buffer.append("<b>Environment:</b> ");
buffer.append(environment);
}
int recommendedStat = AdventureDatabase.getRecommendedStat(this.zone);
if (recommendedStat == -1) {
buffer.append("<br>");
buffer.append("<b>Recommended Mainstat:</b> unknown");
} else {
buffer.append("<br>");
buffer.append("<b>Recommended Mainstat:</b> ");
buffer.append(recommendedStat);
}
if (KoLCharacter.inRaincore()) {
int waterLevel = KoLCharacter.getWaterLevel();
Boolean fixed = AdventureDatabase.getWaterLevel(this.zone) != -1;
if (environment == null) {
buffer.append("<br>");
buffer.append("<b>Water Level:</b> unknown");
} else if (recommendedStat == -1 && !fixed) {
buffer.append("<br>");
buffer.append("<b>Water Level:</b> ");
buffer.append(waterLevel);
buffer.append(" (at least)");
} else {
buffer.append("<br>");
buffer.append("<b>Water Level:</b> ");
buffer.append(waterLevel);
}
}
String encounter = EncounterManager.findEncounterForLocation(this.zone, EncounterType.SEMIRARE);
if (null != encounter) {
buffer.append("<br>");
buffer.append("<b>Semi-Rare:</b> ");
buffer.append(encounter);
}
encounter = EncounterManager.findEncounterForLocation(this.zone, EncounterType.CLOVER);
if (null != encounter) {
buffer.append("<br>");
buffer.append("<b>Clover:</b> ");
buffer.append(encounter);
}
encounter = EncounterManager.findEncounterForLocation(this.zone, EncounterType.GLYPH);
if (null != encounter) {
buffer.append("<br>");
buffer.append("<b>Hobo Glyph:</b> ");
buffer.append(encounter);
}
if (KoLCharacter.inAxecore()) {
encounter = EncounterManager.findEncounterForLocation(this.zone, EncounterType.BORIS);
if (null != encounter) {
buffer.append("<br>");
buffer.append("<b>Clancy:</b> ");
buffer.append(encounter);
}
}
if (KoLCharacter.inBadMoon()) {
encounter = EncounterManager.findEncounterForLocation(this.zone, EncounterType.BADMOON);
if (null != encounter) {
buffer.append("<br>");
buffer.append("<b>Badmoon:</b> ");
buffer.append(encounter);
}
}
}
private String format(final double percentage) {
return String.valueOf((int) percentage);
}
public double areaCombatPercent() {
return areaCombatPercent(true);
}
public double areaCombatPercent(boolean stateful) {
if (stateful) {
// Some situations can force combats
if (EncounterManager.isSaberForceZone(this.getZone())) {
return 100;
}
// Some areas have fixed non-combats, if we're tracking this, handle them here.
switch (zone) {
case "The Defiled Alcove":
if (Preferences.getInteger("cyrptAlcoveEvilness") <= 25) {
return 100;
}
break;
case "The Defiled Cranny":
if (Preferences.getInteger("cyrptCrannyEvilness") <= 25) {
return 100;
}
break;
case "The Defiled Niche":
if (Preferences.getInteger("cyrptNicheEvilness") <= 25) {
return 100;
}
break;
case "The Defiled Nook":
if (Preferences.getInteger("cyrptNookEvilness") <= 25) {
return 100;
}
break;
case "The Smut Orc Logging Camp":
return Preferences.getInteger("smutOrcNoncombatProgress") < 15 ? 100 : 0;
case "Barf Mountain":
return Preferences.getBoolean("dinseyRollercoasterNext") ? 0 : 100;
case "Investigating a Plaintive Telegram":
return Preferences.getInteger("lttQuestStageCount") == 9
|| QuestDatabase.isQuestStep(Quest.TELEGRAM, QuestDatabase.STARTED)
? 0
: 100;
case "The Dripping Trees":
// Non-Combat on turn 16, 31, 46, ...
int advs = Preferences.getInteger("drippingTreesAdventuresSinceAscension");
return (advs > 0 && (advs % 15) == 0) ? 0 : 100;
}
}
// If we don't have the data, pretend it's all combat
if (this.combats < 0) {
return 100.0;
}
// Some areas are inherently all combat or no combat
if (this.combats == 0 || this.combats == 100) {
return this.combats;
}
double pct = this.combats;
if (stateful) {
pct += KoLCharacter.getCombatRateAdjustment();
}
return Math.max(0.0, Math.min(100.0, pct));
}
private String getRateString(
final double minPercent,
final int minMargin,
final double maxPercent,
final int maxMargin,
final String statName,
boolean fullString) {
StringBuilder buffer = new StringBuilder();
buffer.append(this.format(minPercent));
buffer.append("%/");
buffer.append(this.format(maxPercent));
buffer.append("%");
if (!fullString) {
return buffer.toString();
}
buffer.append(" (");
buffer.append(statName);
if (minMargin < Integer.MAX_VALUE / 2) {
if (minMargin >= 0) {
buffer.append("+");
}
buffer.append(minMargin);
buffer.append("/");
} else {
buffer.append(" always hit");
}
if (minMargin < Integer.MAX_VALUE / 2) {
if (maxMargin >= 0) {
buffer.append("+");
}
buffer.append(maxMargin);
}
buffer.append(")");
return buffer.toString();
}
private String getMonsterString(
final MonsterData monster,
final int moxie,
final int hitstat,
final int weighting,
final double chance,
final boolean fullString) {
// moxie and hitstat NOT adjusted for monster level, since monster stats now are
int defense = monster.getDefense();
double hitPercent = AreaCombatData.hitPercent(hitstat, defense);
int attack = monster.getAttack();
double evadePercent = AreaCombatData.hitPercent(moxie, attack);
int health = monster.getHP();
double statGain = monster.getExperience();
StringBuffer buffer = new StringBuffer();
Element ed = monster.getDefenseElement();
Element ea = monster.getAttackElement();
Element element = ed == Element.NONE ? ea : ed;
Phylum phylum = monster.getPhylum();
int init = monster.getInitiative();
int jumpChance = monster.getJumpChance();
// Color the monster name according to its element
buffer.append(" <font color=" + AreaCombatData.elementColor(element) + "><b>");
if (monster.getPoison() < Integer.MAX_VALUE) {
buffer.append("\u2620 ");
}
String name = monster.getName();
buffer.append(name);
buffer.append("</b></font> (");
if (EncounterManager.isSaberForceMonster(name, this.getZone())) {
buffer.append("forced by the saber");
} else if (CrystalBallManager.isCrystalBallMonster(name, this.getZone())) {
buffer.append("predicted by crystal ball");
} else if (weighting == -1) {
buffer.append("ultra-rare");
} else if (weighting == -3) {
buffer.append("banished");
} else if (weighting == -4) {
buffer.append("0%");
} else if (weighting == 0) {
buffer.append("special");
} else {
buffer.append(this.format(chance) + "%");
}
buffer.append(")<br>Hit: <font color=" + AreaCombatData.elementColor(ed) + ">");
buffer.append(this.format(hitPercent));
buffer.append("%</font>, Evade: <font color=" + AreaCombatData.elementColor(ea) + ">");
buffer.append(this.format(evadePercent));
buffer.append("%</font>, Jump Chance: <font color=" + AreaCombatData.elementColor(ea) + ">");
buffer.append(this.format(jumpChance));
buffer.append("%</font><br>Atk: " + attack + ", Def: " + defense);
buffer.append(", HP: " + health + ", XP: " + KoLConstants.FLOAT_FORMAT.format(statGain));
buffer.append("<br>Phylum: " + phylum);
if (init == -10000) {
buffer.append(", Never wins initiative");
} else if (init == 10000) {
buffer.append(", Always wins initiative");
} else {
buffer.append(", Init: " + init);
}
if (fullString) {
this.appendMeatDrop(buffer, monster);
this.appendSprinkleDrop(buffer, monster);
}
this.appendItemList(buffer, monster.getItems(), monster.getPocketRates(), fullString);
String bounty = BountyDatabase.getNameByMonster(monster.getName());
if (bounty != null) {
buffer.append("<br>" + bounty + " (bounty)");
}
return buffer.toString();
}
private void appendMeatDrop(final StringBuffer buffer, final MonsterData monster) {
int minMeat = monster.getMinMeat();
int maxMeat = monster.getMaxMeat();
if (maxMeat == 0) {
return;
}
int avgMeat = monster.getBaseMeat();
double modifier = Math.max(0.0, (KoLCharacter.getMeatDropPercentAdjustment() + 100.0) / 100.0);
buffer.append("<br>Meat: ");
buffer.append(this.format((int) Math.floor(minMeat * modifier)));
buffer.append("-");
buffer.append(this.format((int) Math.floor(maxMeat * modifier)));
buffer.append(" (");
buffer.append(this.format((int) Math.floor(avgMeat * modifier)));
buffer.append(" average)");
}
private void appendSprinkleDrop(final StringBuffer buffer, final MonsterData monster) {
int minSprinkles = monster.getMinSprinkles();
int maxSprinkles = monster.getMaxSprinkles();
if (maxSprinkles == 0) {
return;
}
double modifier =
Math.max(0.0, (KoLCharacter.getSprinkleDropPercentAdjustment() + 100.0) / 100.0);
buffer.append("<br>Sprinkles: ");
buffer.append(this.format((int) Math.floor(minSprinkles * modifier)));
if (maxSprinkles != minSprinkles) {
buffer.append("-");