UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

63 lines (62 loc) 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anyPlayerHasCollectibleEffect = anyPlayerHasCollectibleEffect; exports.anyPlayerHasNullEffect = anyPlayerHasNullEffect; exports.anyPlayerHasTrinketEffect = anyPlayerHasTrinketEffect; exports.getEffectsList = getEffectsList; exports.shouldWhoreOfBabylonBeActive = shouldWhoreOfBabylonBeActive; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const playerIndex_1 = require("./playerIndex"); const players_1 = require("./players"); /** Helper function to check to see if any player has a temporary collectible effect. */ function anyPlayerHasCollectibleEffect(collectibleType) { const players = (0, playerIndex_1.getAllPlayers)(); return players.some((player) => { const effects = player.GetEffects(); return effects.HasCollectibleEffect(collectibleType); }); } /** Helper function to check to see if any player has a temporary null effect. */ function anyPlayerHasNullEffect(nullItemID) { const players = (0, playerIndex_1.getAllPlayers)(); return players.some((player) => { const effects = player.GetEffects(); return effects.HasNullEffect(nullItemID); }); } /** Helper function to check to see if any player has a temporary trinket effect. */ function anyPlayerHasTrinketEffect(trinketType) { const players = (0, playerIndex_1.getAllPlayers)(); return players.some((player) => { const effects = player.GetEffects(); return effects.HasTrinketEffect(trinketType); }); } /** * Helper function to get an array of temporary effects for a player. This is helpful so that you * don't have to manually create an array from an `EffectsList` object. */ function getEffectsList(player) { const effects = player.GetEffects(); const effectsList = effects.GetEffectsList(); const effectArray = []; for (let i = 0; i < effectsList.Size; i++) { const effect = effectsList.Get(i); if (effect !== undefined) { effectArray.push(effect); } } return effectArray; } /** * Helper function to check if a player should have Whore of Babylon active at their current health * level. * * - For most characters, Whore of Babylon activates when the red hearts are at 1/2 or less. * - For Eve, Whore of Babylon activates when the red hearts are at 1 or less. */ function shouldWhoreOfBabylonBeActive(player) { const redHearts = player.GetHearts(); const threshold = (0, players_1.isCharacter)(player, isaac_typescript_definitions_1.PlayerType.EVE) ? 2 : 1; return redHearts <= threshold; }