-
Notifications
You must be signed in to change notification settings - Fork 21
/
ModdedElementSets.ts
1472 lines (1327 loc) · 51.1 KB
/
ModdedElementSets.ts
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
import type { PillEffect } from "isaac-typescript-definitions";
import {
CacheFlag,
CardType,
CollectibleType,
ItemConfigCardType,
ItemConfigTag,
PlayerForm,
TrinketType,
} from "isaac-typescript-definitions";
import {
CACHE_FLAG_VALUES,
ITEM_CONFIG_CARD_TYPE_VALUES,
ITEM_CONFIG_TAG_VALUES,
} from "../../../cachedEnumValues";
import { itemConfig } from "../../../core/cachedClasses";
import {
FIRST_GLITCHED_COLLECTIBLE_TYPE,
QUALITIES,
} from "../../../core/constants";
import {
VANILLA_CARD_TYPES,
VANILLA_COLLECTIBLE_TYPES,
VANILLA_PILL_EFFECTS,
VANILLA_TRINKET_TYPES,
} from "../../../core/constantsVanilla";
import { Exported } from "../../../decorators";
import { ISCFeature } from "../../../enums/ISCFeature";
import { arrayRemove, getRandomArrayElement } from "../../../functions/array";
import { getItemConfigCardType } from "../../../functions/cards";
import { collectibleHasTag } from "../../../functions/collectibleTag";
import {
collectibleHasCacheFlag,
getCollectibleQuality,
isActiveCollectible,
isHiddenCollectible,
isPassiveOrFamiliarCollectible,
} from "../../../functions/collectibles";
import { getFlagName } from "../../../functions/flag";
import { getRandomSetElement } from "../../../functions/set";
import { trinketHasCacheFlag } from "../../../functions/trinkets";
import {
asCardType,
asCollectibleType,
asPillEffect,
asTrinketType,
} from "../../../functions/types";
import { assertDefined, iRange, repeat } from "../../../functions/utils";
import { ITEM_CONFIG_CARD_TYPES_FOR_CARDS } from "../../../sets/itemConfigCardTypesForCards";
import { ReadonlyMap } from "../../../types/ReadonlyMap";
import type { ReadonlySet } from "../../../types/ReadonlySet";
import { Feature } from "../../private/Feature";
import type { ModdedElementDetection } from "./ModdedElementDetection";
const CONDITIONAL_FLYING_COLLECTIBLE_TYPES = [
CollectibleType.BIBLE,
CollectibleType.EMPTY_VESSEL,
CollectibleType.ASTRAL_PROJECTION,
CollectibleType.RECALL,
] as const;
const TRANSFORMATION_TO_TAG_MAP = new ReadonlyMap<PlayerForm, ItemConfigTag>([
[PlayerForm.GUPPY, ItemConfigTag.GUPPY], // 0
[PlayerForm.BEELZEBUB, ItemConfigTag.FLY], // 1
[PlayerForm.FUN_GUY, ItemConfigTag.MUSHROOM], // 2
[PlayerForm.SERAPHIM, ItemConfigTag.ANGEL], // 3
[PlayerForm.BOB, ItemConfigTag.BOB], // 4
[PlayerForm.SPUN, ItemConfigTag.SYRINGE], // 5
[PlayerForm.YES_MOTHER, ItemConfigTag.MOM], // 6
[PlayerForm.CONJOINED, ItemConfigTag.BABY], // 7
[PlayerForm.LEVIATHAN, ItemConfigTag.DEVIL], // 8
[PlayerForm.OH_CRAP, ItemConfigTag.POOP], // 9
[PlayerForm.BOOKWORM, ItemConfigTag.BOOK], // 10
// PlayerForm.ADULTHOOD (11) is based on pill usage.
[PlayerForm.SPIDER_BABY, ItemConfigTag.SPIDER], // 12
// PlayerForm.STOMPY (13) is based on size.
]);
/**
* A feature that lazy-inits and caches various arrays and sets that include both vanilla and modded
* elements. This is useful for performance purposes (so that we do not have to reconstruct the
* arrays/sets multiple times).
*
* The modded arrays/sets are created using the functions from
* `ISCFeature.MODDED_ELEMENT_DETECTION`.
*/
export class ModdedElementSets extends Feature {
private arraysInitialized = false;
// ----------------
// Main collections
// ----------------
private readonly allCollectibleTypesArray: CollectibleType[] = [];
private readonly allCollectibleTypesSet = new Set<CollectibleType>();
private readonly moddedCollectibleTypesArray: CollectibleType[] = [];
private readonly moddedCollectibleTypesSet = new Set<CollectibleType>();
private readonly allTrinketTypesArray: TrinketType[] = [];
private readonly allTrinketTypesSet = new Set<TrinketType>();
private readonly moddedTrinketTypesArray: TrinketType[] = [];
private readonly moddedTrinketTypesSet = new Set<TrinketType>();
private readonly allCardTypesArray: CardType[] = [];
private readonly allCardTypesSet = new Set<CardType>();
private readonly moddedCardTypesArray: CardType[] = [];
private readonly moddedCardTypesSet = new Set<CardType>();
private readonly allPillEffectsArray: PillEffect[] = [];
private readonly allPillEffectsSet = new Set<PillEffect>();
private readonly moddedPillEffectsArray: PillEffect[] = [];
private readonly moddedPillEffectsSet = new Set<PillEffect>();
// -----------------
// Other collections
// -----------------
private readonly cacheFlagToCollectibleTypesMap = new Map<
CacheFlag,
readonly CollectibleType[]
>();
private readonly cacheFlagToTrinketTypesMap = new Map<
CacheFlag,
readonly TrinketType[]
>();
private flyingCollectibleTypes: CollectibleType[] = [];
private permanentFlyingCollectibleTypes: CollectibleType[] = [];
private flyingTrinketTypes: TrinketType[] = [];
private readonly tagToCollectibleTypesMap = new Map<
ItemConfigTag,
CollectibleType[]
>();
private readonly edenActiveCollectibleTypesSet = new Set<CollectibleType>();
private readonly edenPassiveCollectibleTypesSet = new Set<CollectibleType>();
private readonly qualityToCollectibleTypesMap = new Map<
Quality,
readonly CollectibleType[]
>();
private readonly itemConfigCardTypeToCardTypeMap = new Map<
ItemConfigCardType,
CardType[]
>();
/**
* The array of card types that are not:
*
* - ItemConfigCardType.RUNE
* - ItemConfigCardType.SPECIAL_OBJECT
*/
private readonly cardTypeCardArray: CardType[] = [];
private readonly moddedElementDetection: ModdedElementDetection;
/** @internal */
constructor(moddedElementDetection: ModdedElementDetection) {
super();
this.featuresUsed = [ISCFeature.MODDED_ELEMENT_DETECTION];
this.moddedElementDetection = moddedElementDetection;
}
private lazyInit() {
if (this.arraysInitialized) {
return;
}
this.arraysInitialized = true;
this.lazyInitModdedCollectibleTypes();
this.lazyInitModdedTrinketTypes();
this.lazyInitModdedCardTypes();
this.lazyInitModdedPillEffects();
this.lazyInitTagToCollectibleTypesMap();
this.lazyInitCacheFlagToCollectibleTypesMap();
this.lazyInitCacheFlagToTrinketTypesMap();
this.lazyInitFlyingCollectibleTypesSet();
this.lazyInitFlyingTrinketTypesSet();
this.lazyInitEdenCollectibleTypesSet();
this.lazyInitQualityToCollectibleTypesMap();
this.lazyInitCardTypes();
}
private lazyInitModdedCollectibleTypes() {
for (const collectibleType of VANILLA_COLLECTIBLE_TYPES) {
this.allCollectibleTypesArray.push(collectibleType);
this.allCollectibleTypesSet.add(collectibleType);
}
const firstModdedCollectibleType =
this.moddedElementDetection.getFirstModdedCollectibleType();
if (firstModdedCollectibleType === undefined) {
return;
}
const lastCollectibleType =
this.moddedElementDetection.getLastCollectibleType();
const moddedCollectibleTypes = iRange(
firstModdedCollectibleType,
lastCollectibleType,
);
for (const collectibleTypeInt of moddedCollectibleTypes) {
// Modded collectible types are contiguous, but we check every value just in case.
const collectibleType = asCollectibleType(collectibleTypeInt);
const itemConfigItem = itemConfig.GetCollectible(collectibleType);
if (itemConfigItem !== undefined) {
this.moddedCollectibleTypesArray.push(collectibleType);
this.moddedCollectibleTypesSet.add(collectibleType);
this.allCollectibleTypesArray.push(collectibleType);
this.allCollectibleTypesSet.add(collectibleType);
}
}
}
private lazyInitModdedTrinketTypes() {
for (const trinketType of VANILLA_TRINKET_TYPES) {
this.allTrinketTypesArray.push(trinketType);
this.allTrinketTypesSet.add(trinketType);
}
const firstModdedTrinketType =
this.moddedElementDetection.getFirstModdedTrinketType();
if (firstModdedTrinketType === undefined) {
return;
}
const lastTrinketType = this.moddedElementDetection.getLastTrinketType();
const moddedTrinketTypes = iRange(firstModdedTrinketType, lastTrinketType);
for (const trinketTypeInt of moddedTrinketTypes) {
// Modded trinket types are contiguous, but we check every value just in case.
const trinketType = asTrinketType(trinketTypeInt);
const itemConfigItem = itemConfig.GetTrinket(trinketType);
if (itemConfigItem !== undefined) {
this.moddedTrinketTypesArray.push(trinketType);
this.moddedTrinketTypesSet.add(trinketType);
this.allTrinketTypesArray.push(trinketType);
this.allTrinketTypesSet.add(trinketType);
}
}
}
private lazyInitModdedCardTypes() {
for (const cardType of VANILLA_CARD_TYPES) {
this.allCardTypesArray.push(cardType);
this.allCardTypesSet.add(cardType);
}
const firstModdedCardType =
this.moddedElementDetection.getFirstModdedCardType();
if (firstModdedCardType === undefined) {
return;
}
const lastCardType = this.moddedElementDetection.getLastCardType();
const moddedCardTypes = iRange(firstModdedCardType, lastCardType);
for (const cardTypeInt of moddedCardTypes) {
// Modded card types are contiguous, but we check every value just in case.
const cardType = asCardType(cardTypeInt);
const itemConfigCard = itemConfig.GetCard(cardType);
if (itemConfigCard !== undefined) {
this.moddedCardTypesArray.push(cardType);
this.moddedCardTypesSet.add(cardType);
this.allCardTypesArray.push(cardType);
this.allCardTypesSet.add(cardType);
}
}
}
private lazyInitModdedPillEffects() {
for (const pillEffect of VANILLA_PILL_EFFECTS) {
this.allPillEffectsArray.push(pillEffect);
this.allPillEffectsSet.add(pillEffect);
}
const firstModdedPillEffect =
this.moddedElementDetection.getFirstModdedPillEffect();
if (firstModdedPillEffect === undefined) {
return;
}
const lastPillEffect = this.moddedElementDetection.getLastPillEffect();
const moddedPillEffects = iRange(firstModdedPillEffect, lastPillEffect);
for (const pillEffectInt of moddedPillEffects) {
// Modded pill effects are contiguous, but we check every value just in case.
const pillEffect = asPillEffect(pillEffectInt);
const itemConfigPillEffect = itemConfig.GetPillEffect(pillEffect);
if (itemConfigPillEffect !== undefined) {
this.moddedPillEffectsArray.push(pillEffect);
this.moddedPillEffectsSet.add(pillEffect);
this.allPillEffectsArray.push(pillEffect);
this.allPillEffectsSet.add(pillEffect);
}
}
}
private lazyInitTagToCollectibleTypesMap() {
// The tag to collectible types map should be valid for every tag, so we initialize it with
// empty arrays.
for (const itemConfigTag of ITEM_CONFIG_TAG_VALUES) {
this.tagToCollectibleTypesMap.set(itemConfigTag, [] as CollectibleType[]);
}
for (const collectibleType of this.getCollectibleTypes()) {
for (const itemConfigTag of ITEM_CONFIG_TAG_VALUES) {
if (!collectibleHasTag(collectibleType, itemConfigTag)) {
continue;
}
const collectibleTypes =
this.tagToCollectibleTypesMap.get(itemConfigTag);
if (collectibleTypes === undefined) {
const flagName = getFlagName(itemConfigTag, ItemConfigTag);
error(
`Failed to get the collectible types for item tag: ${flagName}`,
);
}
collectibleTypes.push(collectibleType);
}
}
}
private lazyInitCacheFlagToCollectibleTypesMap() {
for (const cacheFlag of CACHE_FLAG_VALUES) {
const collectibleTypes: CollectibleType[] = [];
for (const collectibleType of this.getCollectibleTypes()) {
if (collectibleHasCacheFlag(collectibleType, cacheFlag)) {
collectibleTypes.push(collectibleType);
}
}
this.cacheFlagToCollectibleTypesMap.set(cacheFlag, collectibleTypes);
}
}
private lazyInitCacheFlagToTrinketTypesMap() {
for (const cacheFlag of CACHE_FLAG_VALUES) {
const trinketTypes: TrinketType[] = [];
for (const trinketType of this.getTrinketTypes()) {
if (trinketHasCacheFlag(trinketType, cacheFlag)) {
trinketTypes.push(trinketType);
}
}
this.cacheFlagToTrinketTypesMap.set(cacheFlag, trinketTypes);
}
}
private lazyInitFlyingCollectibleTypesSet() {
// Instead of manually compiling a list of collectibles that grant flying, we can instead
// dynamically look for collectibles that have `CacheFlag.FLYING`. But none of the collectibles
// with a cache of "all" grant flying (including all of the 3 Dollar Bill collectibles and all
// of the Birthright effects), so we can safely remove them from the list.
const collectibleTypesWithFlyingCacheFlag =
this.getCollectibleTypesWithCacheFlag(CacheFlag.FLYING);
const collectibleTypesWithAllCacheFlag =
this.getCollectibleTypesWithCacheFlag(CacheFlag.ALL);
this.flyingCollectibleTypes = arrayRemove(
collectibleTypesWithFlyingCacheFlag,
...collectibleTypesWithAllCacheFlag,
);
// Additionally, create a second set that represents the collectible types that grant flying
// non-conditionally.
this.permanentFlyingCollectibleTypes = arrayRemove(
this.flyingCollectibleTypes,
...CONDITIONAL_FLYING_COLLECTIBLE_TYPES,
);
}
private lazyInitFlyingTrinketTypesSet() {
// Instead of manually compiling a list of trinkets that grant flying, we can instead
// dynamically look for collectibles that have `CacheFlag.FLYING`. But none of the trinkets with
// `CacheFlag.ALL` grant flying except for Azazel's Stump, so we can safely remove them from the
// list.
const trinketTypesWithFlyingCacheFlag = this.getTrinketsTypesWithCacheFlag(
CacheFlag.FLYING,
);
const trinketTypesWithAllCacheFlag = this.getTrinketsTypesWithCacheFlag(
CacheFlag.ALL,
);
const trinketTypesWithAllCacheFlagThatDontGrantFlying = arrayRemove(
trinketTypesWithAllCacheFlag,
TrinketType.AZAZELS_STUMP,
);
this.flyingTrinketTypes = arrayRemove(
trinketTypesWithFlyingCacheFlag,
...trinketTypesWithAllCacheFlagThatDontGrantFlying,
);
}
private lazyInitEdenCollectibleTypesSet() {
for (const collectibleType of this.getCollectibleTypes()) {
if (
isHiddenCollectible(collectibleType) ||
collectibleHasTag(collectibleType, ItemConfigTag.NO_EDEN)
) {
continue;
}
if (isActiveCollectible(collectibleType)) {
this.edenActiveCollectibleTypesSet.add(collectibleType);
}
if (isPassiveOrFamiliarCollectible(collectibleType)) {
this.edenPassiveCollectibleTypesSet.add(collectibleType);
}
}
}
private lazyInitQualityToCollectibleTypesMap() {
for (const quality of QUALITIES) {
const collectibleTypes: CollectibleType[] = [];
for (const collectibleType of this.getCollectibleTypes()) {
const collectibleTypeQuality = getCollectibleQuality(collectibleType);
if (collectibleTypeQuality === quality) {
collectibleTypes.push(collectibleType);
}
}
this.qualityToCollectibleTypesMap.set(quality, collectibleTypes);
}
}
private lazyInitCardTypes() {
// The card type to cards map should be valid for every card type, so we initialize it with
// empty arrays.
for (const itemConfigCardType of ITEM_CONFIG_CARD_TYPE_VALUES) {
this.itemConfigCardTypeToCardTypeMap.set(
itemConfigCardType,
[] as CardType[],
);
}
for (const cardType of this.getCardTypes()) {
const itemConfigCardType = getItemConfigCardType(cardType);
if (itemConfigCardType !== undefined) {
const cardTypes =
this.itemConfigCardTypeToCardTypeMap.get(itemConfigCardType);
assertDefined(
cardTypes,
`Failed to get the card types for item config card type: ${itemConfigCardType}`,
);
cardTypes.push(cardType);
if (ITEM_CONFIG_CARD_TYPES_FOR_CARDS.has(itemConfigCardType)) {
this.cardTypeCardArray.push(cardType);
}
}
}
}
// ------------
// Collectibles
// ------------
/**
* Returns an array containing every valid collectible type in the game, including modded
* collectibles.
*
* Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
* then use the `getCollectibleTypesSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all collectible types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getCollectibleTypes(): readonly CollectibleType[] {
this.lazyInit();
return this.allCollectibleTypesArray;
}
/**
* Returns a set containing every valid collectible type in the game, including modded
* collectibles.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
* then use the `getCollectibleTypes` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all collectible types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getCollectibleTypeSet(): ReadonlySet<CollectibleType> {
this.lazyInit();
return this.allCollectibleTypesSet;
}
/**
* Returns an array containing every modded collectible type in the game.
*
* Use this if you need to iterate over the collectibles in order. If you need to do O(1) lookups,
* then use the `getModdedCollectibleTypesSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all collectible types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedCollectibleTypes(): readonly CollectibleType[] {
this.lazyInit();
return this.moddedCollectibleTypesArray;
}
/**
* Returns a set containing every modded collectible type in the game.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the collectibles in order,
* then use the `getModdedCollectibleTypes` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all collectible types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedCollectibleTypesSet(): ReadonlySet<CollectibleType> {
this.lazyInit();
return this.moddedCollectibleTypesSet;
}
/**
* Iterates over every collectible in the game and returns a map containing the number of each
* item that the player has.
*
* Note that this will filter out non-real collectibles like Lilith's Incubus.
*
* This function can only be called if at least one callback has been executed. This is because
* not all collectible types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getPlayerCollectibleMap(
player: EntityPlayer,
): Map<CollectibleType, int> {
const collectibleArray = this.getCollectibleTypes();
const collectibleMap = new Map<CollectibleType, int>();
for (const collectibleType of collectibleArray) {
// We specify "true" as the second argument to filter out things like Lilith's Incubus.
const numCollectibles = player.GetCollectibleNum(collectibleType, true);
if (numCollectibles > 0) {
collectibleMap.set(collectibleType, numCollectibles);
}
}
// If the player has TMTRAINER, they might also have glitched items.
if (player.HasCollectible(CollectibleType.TMTRAINER)) {
let collectibleType = FIRST_GLITCHED_COLLECTIBLE_TYPE;
let itemConfigItem: Readonly<ItemConfigItem> | undefined;
do {
itemConfigItem = itemConfig.GetCollectible(collectibleType);
if (itemConfigItem !== undefined) {
// The `EntityPlayer.GetCollectibleNum` method is bugged with TMTrainer items and will
// always return 0. To work around this, we simply assume that if the player has the
// collectible, then they have one copy of the item.
const hasCollectibles = player.HasCollectible(collectibleType, true);
if (hasCollectibles) {
collectibleMap.set(collectibleType, 1);
}
}
collectibleType--; // eslint-disable-line isaacscript/strict-enums
} while (itemConfigItem !== undefined);
}
return collectibleMap;
}
// --------
// Trinkets
// --------
/**
* Returns an array containing every modded trinket type in the game.
*
* Use this if you need to iterate over the trinkets in order. If you need to do O(1) lookups,
* then use the `getModdedTrinketTypesSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all trinket types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getTrinketTypes(): readonly TrinketType[] {
this.lazyInit();
return this.allTrinketTypesArray;
}
/**
* Returns a set containing every modded trinket type in the game.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the trinkets in order,
* then use the `getModdedTrinketTypes` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all trinket types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getTrinketTypesSet(): ReadonlySet<TrinketType> {
this.lazyInit();
return this.allTrinketTypesSet;
}
/**
* Returns an array containing every modded trinket type in the game.
*
* Use this if you need to iterate over the trinkets in order. If you need to do O(1) lookups,
* then use the `getModdedTrinketTypesSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all trinket types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedTrinketTypes(): readonly TrinketType[] {
this.lazyInit();
return this.moddedTrinketTypesArray;
}
/**
* Returns a set containing every modded trinket type in the game.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the trinkets in order,
* then use the `getModdedTrinketTypes` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all trinket types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedTrinketTypesSet(): ReadonlySet<TrinketType> {
this.lazyInit();
return this.moddedTrinketTypesSet;
}
// -----
// Cards
// -----
/**
* Returns an array containing every valid card type in the game, including modded cards.
*
* Use this if you need to iterate over the cards in order. If you need to do O(1) lookups, then
* use the `getCardTypesSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all card types will necessarily be present when a mod first loads (due to mod load order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getCardTypes(): readonly CardType[] {
this.lazyInit();
return this.allCardTypesArray;
}
/**
* Returns a set containing every valid card type in the game, including modded cards.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the cards in order, then
* use the `getCardTypes` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all card types will necessarily be present when a mod first loads (due to mod load order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getCardTypesSet(): ReadonlySet<CardType> {
this.lazyInit();
return this.allCardTypesSet;
}
/**
* Returns an array containing every modded card type in the game.
*
* Use this if you need to iterate over the cards in order. If you need to do O(1) lookups, then
* use the `getModdedCardTypesSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all card types will necessarily be present when a mod first loads (due to mod load order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedCardTypes(): readonly CardType[] {
this.lazyInit();
return this.moddedCardTypesArray;
}
/**
* Returns a set containing every modded card type in the game.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the cards in order, then
* use the `getModdedCardTypes` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all card types will necessarily be present when a mod first loads (due to mod load order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedCardTypesSet(): ReadonlySet<CardType> {
this.lazyInit();
return this.moddedCardTypesSet;
}
// ------------
// Pill Effects
// ------------
/**
* Returns an array containing every valid pill effect in the game, including modded pill effects.
*
* Use this if you need to iterate over the pill effects in order. If you need to do O(1) lookups,
* then use the `getPillEffectSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all pill effects will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getPillEffects(): readonly PillEffect[] {
this.lazyInit();
return this.allPillEffectsArray;
}
/**
* Returns a set containing every valid pill effect in the game, including modded pill effects.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the pill effects in order,
* then use the `getPillEffects` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all pill effects will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getPillEffectsSet(): ReadonlySet<PillEffect> {
this.lazyInit();
return this.allPillEffectsSet;
}
/**
* Returns an array containing every modded pill effect in the game.
*
* Use this if you need to iterate over the pill effects in order. If you need to do O(1) lookups,
* then use the `getModdedPillEffectsSet` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all pill effects will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedPillEffects(): readonly PillEffect[] {
this.lazyInit();
return this.moddedPillEffectsArray;
}
/**
* Returns a set containing every modded pill effect in the game.
*
* Use this if you need to do O(1) lookups. If you need to iterate over the pill effects in order,
* then use the `getModdedPillEffects` helper function instead.
*
* This function can only be called if at least one callback has been executed. This is because
* not all pill effects will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getModdedPillEffectsSet(): ReadonlySet<PillEffect> {
this.lazyInit();
return this.moddedPillEffectsSet;
}
// -----------
// Cache Flags
// -----------
/**
* Returns a set containing every collectible type with the given cache flag, including modded
* collectibles.
*
* This function can only be called if at least one callback has been executed. This is because
* not all collectible types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getCollectibleTypesWithCacheFlag(
cacheFlag: CacheFlag,
): readonly CollectibleType[] {
this.lazyInit();
const collectiblesSet = this.cacheFlagToCollectibleTypesMap.get(cacheFlag);
if (collectiblesSet === undefined) {
return [];
}
return collectiblesSet;
}
/**
* Returns a set containing every trinket type with the given cache flag, including modded
* trinkets.
*
* This function can only be called if at least one callback has been executed. This is because
* not all trinket types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getTrinketsTypesWithCacheFlag(
cacheFlag: CacheFlag,
): readonly TrinketType[] {
this.lazyInit();
const trinketTypes = this.cacheFlagToTrinketTypesMap.get(cacheFlag);
if (trinketTypes === undefined) {
return [];
}
return trinketTypes;
}
/**
* Returns an array containing every collectible type that the player has that matches the
* provided `CacheFlag`.
*
* For example, if the cache flag is `CacheFlag.FLYING`, and the player has one Lord of the Pit
* and two Dead Doves, then this function would return:
*
* ```ts
* [
* CollectibleType.LORD_OF_THE_PIT,
* CollectibleType.DEAD_DOVE,
* CollectibleType.DEAD_DOVE,
* ]
* ```
*
* Note that this array will not include collectibles that the player does not really have, like
* Lilith's Incubus.
*
* This function can only be called if at least one callback has been executed. This is because
* not all collectible types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getPlayerCollectiblesWithCacheFlag(
player: EntityPlayer,
cacheFlag: CacheFlag,
): readonly CollectibleType[] {
const collectiblesWithCacheFlag =
this.getCollectibleTypesWithCacheFlag(cacheFlag);
const playerCollectibles: CollectibleType[] = [];
for (const collectibleType of collectiblesWithCacheFlag) {
// We specify "true" as the second argument to filter out things like Lilith's Incubus.
const numCollectibles = player.GetCollectibleNum(collectibleType, true);
repeat(numCollectibles, () => {
playerCollectibles.push(collectibleType);
});
}
return playerCollectibles;
}
/**
* Returns a map containing every trinket type that the player has that matches the provided
* `CacheFlag`. The values of the map correspond to the multiplier for that trinket.
*
* This function can only be called if at least one callback has been executed. This is because
* not all trinket types will necessarily be present when a mod first loads (due to mod load
* order).
*
* In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`.
*
* @public
*/
@Exported
public getPlayerTrinketsWithCacheFlag(
player: EntityPlayer,
cacheFlag: CacheFlag,
): Map<TrinketType, int> {
const trinketTypesWithCacheFlag =
this.getTrinketsTypesWithCacheFlag(cacheFlag);
const playerTrinkets = new Map<TrinketType, int>();
for (const trinketType of trinketTypesWithCacheFlag) {
const trinketMultiplier = player.GetTrinketMultiplier(trinketType);
if (trinketMultiplier > 0) {
playerTrinkets.set(trinketType, trinketMultiplier);
}
}
return playerTrinkets;
}
/**
* Returns a set of all of the collectibles that grant flight. This is derived from collectibles
* that have `CacheFlag.FLYING` set in the "items.xml" file.
*
* Vanilla collectibles that only grant flight conditionally are manually pruned. Collectibles
* such as Empty Vessel should be checked for via the `hasFlyingTemporaryEffect` function.
*