isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
118 lines (117 loc) • 5.82 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaultCollectibleTypesInItemPool = getDefaultCollectibleTypesInItemPool;
exports.getDefaultItemPoolsForCollectibleType = getDefaultItemPoolsForCollectibleType;
exports.getItemPoolName = getItemPoolName;
exports.getRandomItemPool = getRandomItemPool;
exports.isCollectibleTypeInDefaultItemPool = isCollectibleTypeInDefaultItemPool;
exports.removeCollectibleFromPools = removeCollectibleFromPools;
exports.removeTrinketFromPools = removeTrinketFromPools;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedEnumValues_1 = require("../cachedEnumValues");
const cachedClasses_1 = require("../core/cachedClasses");
const itemPoolTypeToItemPoolName_1 = require("../maps/itemPoolTypeToItemPoolName");
const itemPoolTypeToCollectibleTypesSet_1 = require("../objects/itemPoolTypeToCollectibleTypesSet");
const array_1 = require("./array");
const NORMAL_MODE_ONLY_ITEM_POOL_TYPES = [
isaac_typescript_definitions_1.ItemPoolType.TREASURE, // 0
isaac_typescript_definitions_1.ItemPoolType.BOSS, // 2
isaac_typescript_definitions_1.ItemPoolType.SHOP, // 1
isaac_typescript_definitions_1.ItemPoolType.DEVIL, // 3
isaac_typescript_definitions_1.ItemPoolType.ANGEL, // 4
isaac_typescript_definitions_1.ItemPoolType.CURSE, // 12
isaac_typescript_definitions_1.ItemPoolType.SECRET, // 5
];
const GREED_MODE_ONLY_ITEM_POOL_TYPES = [
isaac_typescript_definitions_1.ItemPoolType.GREED_TREASURE, // 16
isaac_typescript_definitions_1.ItemPoolType.GREED_BOSS, // 17
isaac_typescript_definitions_1.ItemPoolType.GREED_SHOP, // 18
isaac_typescript_definitions_1.ItemPoolType.GREED_DEVIL, // 19
isaac_typescript_definitions_1.ItemPoolType.GREED_ANGEL, // 20
isaac_typescript_definitions_1.ItemPoolType.GREED_CURSE, // 21
isaac_typescript_definitions_1.ItemPoolType.GREED_SECRET, // 22
];
const FAKE_ITEM_POOL_TYPES = [isaac_typescript_definitions_1.ItemPoolType.SHELL_GAME];
const NORMAL_MODE_ITEM_POOL_TYPES = (0, array_1.arrayRemove)(cachedEnumValues_1.ITEM_POOL_TYPE_VALUES, ...GREED_MODE_ONLY_ITEM_POOL_TYPES, ...FAKE_ITEM_POOL_TYPES);
const GREED_MODE_ITEM_POOL_TYPES = (0, array_1.arrayRemove)(cachedEnumValues_1.ITEM_POOL_TYPE_VALUES, ...NORMAL_MODE_ONLY_ITEM_POOL_TYPES, ...FAKE_ITEM_POOL_TYPES);
/**
* Helper function to get the collectibles that are in a particular item pool at the beginning of a
* vanilla run.
*/
function getDefaultCollectibleTypesInItemPool(itemPoolType) {
return itemPoolTypeToCollectibleTypesSet_1.ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET[itemPoolType];
}
/**
* Helper function to get the item pools that a particular collectible starts in at the beginning of
* a vanilla run.
*
* This function will automatically account for Greed Mode. In other words, it will not return the
* "normal" item pools when playing in Greed Mode.
*/
function getDefaultItemPoolsForCollectibleType(collectibleType) {
const collectibleItemPoolTypes = [];
const itemPoolTypes = cachedClasses_1.game.IsGreedMode()
? GREED_MODE_ITEM_POOL_TYPES
: NORMAL_MODE_ITEM_POOL_TYPES;
for (const itemPoolType of itemPoolTypes) {
const collectibleTypesSet = itemPoolTypeToCollectibleTypesSet_1.ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET[itemPoolType];
if (collectibleTypesSet.has(collectibleType)) {
collectibleItemPoolTypes.push(itemPoolType);
}
}
return collectibleItemPoolTypes;
}
/**
* Helper function to get the name for an item pool type as it appears in the "itempools.xml" file.
*/
function getItemPoolName(itemPoolType) {
return itemPoolTypeToItemPoolName_1.ITEM_POOL_TYPE_TO_ITEM_POOL_NAME[itemPoolType];
}
/**
* Helper function to get a random item pool. This is not as simple as getting a random value from
* the `ItemPoolType` enum, since `ItemPoolType.SHELL_GAME` (7) is not a real item pool and the
* Greed Mode item pools should be excluded if not playing in Greed Mode.
*
* If you want to get an unseeded item pool, you must explicitly pass `undefined` to the `seedOrRNG`
* parameter.
*
* @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.
*/
function getRandomItemPool(seedOrRNG) {
const itemPoolTypes = cachedClasses_1.game.IsGreedMode()
? GREED_MODE_ITEM_POOL_TYPES
: NORMAL_MODE_ITEM_POOL_TYPES;
return (0, array_1.getRandomArrayElement)(itemPoolTypes, seedOrRNG);
}
/**
* Helper function to check if a particular collectibles is in a particular item pool at the
* beginning of a vanilla run.
*/
function isCollectibleTypeInDefaultItemPool(collectibleType, itemPoolType) {
const collectibleTypesSet = itemPoolTypeToCollectibleTypesSet_1.ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET[itemPoolType];
return collectibleTypesSet.has(collectibleType);
}
/**
* Helper function to remove one or more collectibles from all item pools.
*
* This function is variadic, meaning you can pass as many collectible types as you want to remove.
*/
function removeCollectibleFromPools(...collectibleTypes) {
const itemPool = cachedClasses_1.game.GetItemPool();
for (const collectibleType of collectibleTypes) {
itemPool.RemoveCollectible(collectibleType);
}
}
/**
* Helper function to remove one or more trinkets from all item pools.
*
* This function is variadic, meaning you can pass as many trinket types as you want to remove.
*/
function removeTrinketFromPools(...trinketTypes) {
const itemPool = cachedClasses_1.game.GetItemPool();
for (const trinketType of trinketTypes) {
itemPool.RemoveTrinket(trinketType);
}
}