UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

652 lines • 30.6 kB
import type { PillEffect } from "isaac-typescript-definitions"; import { CacheFlag, CardType, CollectibleType, ItemConfigCardType, ItemConfigTag, PlayerForm, TrinketType } from "isaac-typescript-definitions"; import { Feature } from "../../private/Feature"; /** * 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 declare class ModdedElementSets extends Feature { private arraysInitialized; private readonly allCollectibleTypesArray; private readonly allCollectibleTypesSet; private readonly moddedCollectibleTypesArray; private readonly moddedCollectibleTypesSet; private readonly allTrinketTypesArray; private readonly allTrinketTypesSet; private readonly moddedTrinketTypesArray; private readonly moddedTrinketTypesSet; private readonly allCardTypesArray; private readonly allCardTypesSet; private readonly moddedCardTypesArray; private readonly moddedCardTypesSet; private readonly allPillEffectsArray; private readonly allPillEffectsSet; private readonly moddedPillEffectsArray; private readonly moddedPillEffectsSet; private readonly cacheFlagToCollectibleTypesMap; private readonly cacheFlagToTrinketTypesMap; private flyingCollectibleTypes; private permanentFlyingCollectibleTypes; private flyingTrinketTypes; private readonly tagToCollectibleTypesMap; private readonly edenActiveCollectibleTypesSet; private readonly edenPassiveCollectibleTypesSet; private readonly qualityToCollectibleTypesMap; private readonly itemConfigCardTypeToCardTypeMap; /** * The array of card types that are not: * * - ItemConfigCardType.RUNE * - ItemConfigCardType.SPECIAL_OBJECT */ private readonly cardTypeCardArray; private readonly moddedElementDetection; private lazyInit; private lazyInitModdedCollectibleTypes; private lazyInitModdedTrinketTypes; private lazyInitModdedCardTypes; private lazyInitModdedPillEffects; private lazyInitTagToCollectibleTypesMap; private lazyInitCacheFlagToCollectibleTypesMap; private lazyInitCacheFlagToTrinketTypesMap; private lazyInitFlyingCollectibleTypesSet; private lazyInitFlyingTrinketTypesSet; private lazyInitEdenCollectibleTypesSet; private lazyInitQualityToCollectibleTypesMap; private lazyInitCardTypes; /** * 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 */ getCollectibleTypes(): readonly CollectibleType[]; /** * 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 */ getCollectibleTypeSet(): ReadonlySet<CollectibleType>; /** * 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 */ getModdedCollectibleTypes(): readonly CollectibleType[]; /** * 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 */ getModdedCollectibleTypesSet(): ReadonlySet<CollectibleType>; /** * 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 */ getPlayerCollectibleMap(player: EntityPlayer): ReadonlyMap<CollectibleType, int>; /** * 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 */ getTrinketTypes(): readonly TrinketType[]; /** * 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 */ getTrinketTypesSet(): ReadonlySet<TrinketType>; /** * 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 */ getModdedTrinketTypes(): readonly TrinketType[]; /** * 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 */ getModdedTrinketTypesSet(): ReadonlySet<TrinketType>; /** * 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 */ getCardTypes(): readonly CardType[]; /** * 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 */ getCardTypesSet(): ReadonlySet<CardType>; /** * 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 */ getModdedCardTypes(): readonly CardType[]; /** * 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 */ getModdedCardTypesSet(): ReadonlySet<CardType>; /** * 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 */ getPillEffects(): readonly PillEffect[]; /** * 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 */ getPillEffectsSet(): ReadonlySet<PillEffect>; /** * 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 */ getModdedPillEffects(): readonly PillEffect[]; /** * 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 */ getModdedPillEffectsSet(): ReadonlySet<PillEffect>; /** * 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 */ getCollectibleTypesWithCacheFlag(cacheFlag: CacheFlag): readonly CollectibleType[]; /** * 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 */ getTrinketsTypesWithCacheFlag(cacheFlag: CacheFlag): readonly TrinketType[]; /** * 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 */ getPlayerCollectiblesWithCacheFlag(player: EntityPlayer, cacheFlag: CacheFlag): readonly CollectibleType[]; /** * 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 */ getPlayerTrinketsWithCacheFlag(player: EntityPlayer, cacheFlag: CacheFlag): ReadonlyMap<TrinketType, int>; /** * 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. * * Under the hood, this is determined by looking at the collectibles that have `CacheFlag.FLYING` * and excluding the ones that have `CacheFlag.ALL`. (None of the collectibles with * `CacheFlag.ALL` grant flying, including all of the 3 Dollar Bill collectibles and all of the * Birthright effects.) * * 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`. * * @param includeConditionalItems Whether collectibles that only grant flight conditionally should * be included in the set (like Empty Vessel). * @public */ getFlyingCollectibleTypes(includeConditionalItems: boolean): readonly CollectibleType[]; /** * Returns a set of all of the trinkets that grant flight. (All vanilla trinkets that grant flight * do so conditionally, like Bat Wing and Azazel's Stump.) * * Under the hood, this is determined by looking at the trinkets that have `CacheFlag.FLYING` and * excluding the ones that have `CacheFlag.ALL`. (None of the trinket with `CacheFlag.ALL` grant * flying except for Azazel's Stump.) * * 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 */ getFlyingTrinketTypes(): readonly TrinketType[]; /** * Returns a set containing every collectible type with the given tag. * * For example, to get all of the collectible types that count as offensive for the purposes of * Tainted Lost: * * ```ts * const offensiveCollectibleTypes = getCollectibleTypesWithTag(ItemConfigTag.OFFENSIVE); * ``` * * 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 */ getCollectibleTypesWithTag(itemConfigTag: ItemConfigTag): readonly CollectibleType[]; /** * Returns an array of collectible types that a player has with a particular tag. * * 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 */ getPlayerCollectiblesWithTag(player: EntityPlayer, itemConfigTag: ItemConfigTag): readonly CollectibleType[]; /** * Helper function to get all of the collectible types in the game that count towards a particular * transformation. * * For example, to get all of the collectible types that count towards Guppy: * * ```ts * const guppyCollectibleTypes = getCollectiblesForTransformation(PlayerForm.GUPPY); * ``` * * 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 */ getCollectibleTypesForTransformation(playerForm: PlayerForm): readonly CollectibleType[]; /** * Returns an array of collectible types that a player has that count towards a particular * transformation. * * 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 */ getPlayerCollectiblesForTransformation(player: EntityPlayer, playerForm: PlayerForm): readonly CollectibleType[]; /** * Returns a set containing every valid passive item that can be randomly granted to Eden as a * starting item. * * Under the hood, this is determined by looking at the "noeden" tag in "items_metadata.xml". * * 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 */ getEdenActiveCollectibleTypes(): ReadonlySet<CollectibleType>; /** * Returns a set containing every valid passive item that can be randomly granted to Eden as a * starting item. * * Under the hood, this is determined by looking at the "noeden" tag in "items_metadata.xml". * * 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 */ getEdenPassiveCollectibleTypes(): ReadonlySet<CollectibleType>; /** * Returns a random active collectible type that that is a valid starting item for Eden. * * 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). * * If you want to get an unseeded collectible type, you must explicitly pass `undefined` to the * `seedOrRNG` parameter. * * In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`. * * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the * `RNG.Next` method will be called. If `undefined` is provided, it will default * to a random seed. * @param exceptions Optional. An array of runes to not select. * @public */ getRandomEdenActiveCollectibleType(seedOrRNG: Seed | RNG | undefined, exceptions?: readonly CollectibleType[]): CollectibleType; /** * Returns a random passive collectible type that that is a valid starting item for Eden * (including familiars). * * 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). * * If you want to get an unseeded collectible type, you must explicitly pass `undefined` to the * `seedOrRNG` parameter. * * In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`. * * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the * `RNG.Next` method will be called. If `undefined` is provided, it will default * to a random seed. * @param exceptions Optional. An array of runes to not select. * @public */ getRandomEdenPassiveCollectibleType(seedOrRNG: Seed | RNG | undefined, exceptions?: readonly CollectibleType[]): CollectibleType; /** * Returns an array containing every collectible type with the given quality. * * 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 */ getCollectibleTypesOfQuality(quality: Quality): readonly CollectibleType[]; /** * Returns an array of collectible types that a player has that are of a particular quality. * * 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 */ getPlayerCollectiblesOfQuality(player: EntityPlayer, quality: Quality): readonly CollectibleType[]; /** * Helper function to get an array of card types matching the `ItemConfigCardType`. * * This function is variadic, meaning that you can you can specify N card types to get an array * containing cards that match any of the specified types. * * 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 */ getCardTypesOfType(...itemConfigCardTypes: readonly ItemConfigCardType[]): readonly CardType[]; /** * Helper function to get a random card type that matches the provided `ItemConfigCardType`. * * 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). * * If you want to get an unseeded card type, you must explicitly pass `undefined` to the * `seedOrRNG` parameter. * * In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`. * * @param itemConfigCardType The item config card type that represents the pool of cards to select * from. * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the * `RNG.Next` method will be called. If `undefined` is provided, it will default * to a random seed. * @param exceptions Optional. An array of cards to not select. * @public */ getRandomCardTypeOfType(itemConfigCardType: ItemConfigCardType, seedOrRNG: Seed | RNG | undefined, exceptions?: readonly CardType[]): CardType; /** * Has an equal chance of returning any card (e.g. Fool, Reverse Fool, Wild Card, etc.). * * This will not return: * - any runes * - any objects like Dice Shard * * 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). * * If you want to get an unseeded card type, you must explicitly pass `undefined` to the * `seedOrRNG` parameter. * * In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`. * * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the * `RNG.Next` method will be called. If `undefined` is provided, it will default * to a random seed. * @param exceptions Optional. An array of cards to not select. * @public */ getRandomCard(seedOrRNG: Seed | RNG | undefined, exceptions?: readonly CardType[]): CardType; /** * Has an equal chance of returning any rune (e.g. Rune of Hagalaz, Blank Rune, Black Rune, Soul * of Isaac, etc.). This will never return a Rune Shard. * * 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). * * If you want to get an unseeded card type, you must explicitly pass `undefined` to the * `seedOrRNG` parameter. * * In order to use this function, you must upgrade your mod with `ISCFeature.MODDED_ELEMENT_SETS`. * * @param seedOrRNG The `Seed` or `RNG` object to use. If an `RNG` object is provided, the * `RNG.Next` method will be called. If `undefined` is provided, it will default * to a random seed. * @param exceptions Optional. An array of runes to not select. * @public */ getRandomRune(seedOrRNG: Seed | RNG | undefined, exceptions?: readonly CardType[]): CardType; } //# sourceMappingURL=ModdedElementSets.d.ts.map