isaacscript-common 1.2.31 → 1.2.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,8 @@ local ____exports = require("features.saveDataManager.exports")
5
5
  local saveDataManager = ____exports.saveDataManager
6
6
  local ____collectibles = require("functions.collectibles")
7
7
  local removeCollectibleFromItemTracker = ____collectibles.removeCollectibleFromItemTracker
8
- local ____entity = require("functions.entity")
9
- local removeAllFamiliars = ____entity.removeAllFamiliars
8
+ local ____familiars = require("functions.familiars")
9
+ local removeAllFamiliars = ____familiars.removeAllFamiliars
10
10
  local ____player = require("functions.player")
11
11
  local getPlayerIndex = ____player.getPlayerIndex
12
12
  local ____ModCallbacksCustom = require("types.ModCallbacksCustom")
@@ -85,18 +85,6 @@ export declare function getEntityPositions(entities?: Entity[]): Map<PtrHash, Ve
85
85
  * times.
86
86
  */
87
87
  export declare function getEntityVelocities(entities?: Entity[]): Map<PtrHash, Vector>;
88
- /**
89
- * Helper function to get all of the familiars in the room.
90
- *
91
- * Example:
92
- * ```
93
- * // Make all of the familiars in the room invisible
94
- * for (const familiar of getFamiliars()) {
95
- * familiar.Visible = false;
96
- * }
97
- * ```
98
- */
99
- export declare function getFamiliars(matchingVariant?: FamiliarVariant | int, matchingSubType?: number): EntityFamiliar[];
100
88
  /**
101
89
  * Helper function to get all of the knives in the room.
102
90
  *
@@ -197,15 +185,6 @@ export declare function removeAllBombs(variant?: BombVariant | int, subType?: in
197
185
  * @returns True if one or more effects was removed, false otherwise.
198
186
  */
199
187
  export declare function removeAllEffects(variant?: EffectVariant | int, subType?: int, cap?: int): boolean;
200
- /**
201
- * Helper function to remove all of the familiars in the room.
202
- *
203
- * @param variant Optional. If specified, will only remove familiars that match this variant.
204
- * @param subType Optional. If specified, will only remove familiars that match this sub-type.
205
- * @param cap Optional. If specified, will only remove the given amount of familiars.
206
- * @returns True if one or more familiars was removed, false otherwise.
207
- */
208
- export declare function removeAllFamiliars(variant?: FamiliarVariant | int, subType?: int, cap?: int): boolean;
209
188
  /**
210
189
  * Helper function to remove all of the knives in the room.
211
190
  *
@@ -118,23 +118,6 @@ function ____exports.getEntityVelocities(self, entities)
118
118
  end
119
119
  return entityVelocities
120
120
  end
121
- function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
122
- if matchingVariant == nil then
123
- matchingVariant = -1
124
- end
125
- if matchingSubType == nil then
126
- matchingSubType = -1
127
- end
128
- local entities = ____exports.getEntities(nil, EntityType.ENTITY_FAMILIAR, matchingVariant, matchingSubType)
129
- local familiars = {}
130
- for ____, entity in ipairs(entities) do
131
- local familiar = entity:ToFamiliar()
132
- if familiar ~= nil then
133
- __TS__ArrayPush(familiars, familiar)
134
- end
135
- end
136
- return familiars
137
- end
138
121
  function ____exports.getKnives(self, matchingVariant, matchingSubType)
139
122
  if matchingVariant == nil then
140
123
  matchingVariant = -1
@@ -266,10 +249,6 @@ function ____exports.removeAllEffects(self, variant, subType, cap)
266
249
  local effects = ____exports.getEffects(nil, variant, subType)
267
250
  return ____exports.removeEntities(nil, effects, cap)
268
251
  end
269
- function ____exports.removeAllFamiliars(self, variant, subType, cap)
270
- local familiars = ____exports.getFamiliars(nil, variant, subType)
271
- return ____exports.removeEntities(nil, familiars, cap)
272
- end
273
252
  function ____exports.removeAllKnives(self, variant, subType, cap)
274
253
  local knives = ____exports.getKnives(nil, variant, subType)
275
254
  return ____exports.removeEntities(nil, knives, cap)
@@ -1,2 +1,40 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Helper function to add and remove familiars based on the amount of associated collectibles that a
4
+ * player has. Use this instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of
5
+ * the spawned familiar will be set properly.
6
+ *
7
+ * This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
8
+ * to `CacheFlag.CACHE_FAMILIARS`).
9
+ *
10
+ * @param player The player that has the collectibles for this familiar.
11
+ * @param collectibleType The collectible type of the collectible associated with this familiar.
12
+ * @param familiarVariant The variant of the familiar to spawn or remove.
13
+ * @param familiarSubType The sub-type of the familiar to spawn
14
+ * @returns The amount of familiars that were added or removed. For example, the player has 0
15
+ * collectibles and there were 2 familiars, this function would remove the 2 familiars and return
16
+ * -2.
17
+ */
18
+ export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): int;
19
+ /**
20
+ * Helper function to get all of the familiars in the room.
21
+ *
22
+ * Example:
23
+ * ```
24
+ * // Make all of the familiars in the room invisible
25
+ * for (const familiar of getFamiliars()) {
26
+ * familiar.Visible = false;
27
+ * }
28
+ * ```
29
+ */
30
+ export declare function getFamiliars(matchingVariant?: FamiliarVariant | int, matchingSubType?: number): EntityFamiliar[];
2
31
  export declare function isFamiliarThatShootsPlayerTears(familiar: EntityFamiliar): boolean;
32
+ /**
33
+ * Helper function to remove all of the familiars in the room.
34
+ *
35
+ * @param variant Optional. If specified, will only remove familiars that match this variant.
36
+ * @param subType Optional. If specified, will only remove familiars that match this sub-type.
37
+ * @param cap Optional. If specified, will only remove the given amount of familiars.
38
+ * @returns True if one or more familiars was removed, false otherwise.
39
+ */
40
+ export declare function removeAllFamiliars(variant?: FamiliarVariant | int, subType?: int, cap?: int): boolean;
@@ -1,10 +1,85 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
5
+ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
4
6
  local ____exports = {}
5
7
  local ____constants = require("constants")
6
8
  local FAMILIARS_THAT_SHOOT_PLAYER_TEARS = ____constants.FAMILIARS_THAT_SHOOT_PLAYER_TEARS
9
+ local ____entity = require("functions.entity")
10
+ local getEntities = ____entity.getEntities
11
+ local removeEntities = ____entity.removeEntities
12
+ function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
13
+ if matchingVariant == nil then
14
+ matchingVariant = -1
15
+ end
16
+ if matchingSubType == nil then
17
+ matchingSubType = -1
18
+ end
19
+ local entities = getEntities(nil, EntityType.ENTITY_FAMILIAR, matchingVariant, matchingSubType)
20
+ local familiars = {}
21
+ for ____, entity in ipairs(entities) do
22
+ local familiar = entity:ToFamiliar()
23
+ if familiar ~= nil then
24
+ __TS__ArrayPush(familiars, familiar)
25
+ end
26
+ end
27
+ return familiars
28
+ end
29
+ function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
30
+ local game = Game()
31
+ local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
32
+ local playerPtrHash = GetPtrHash(player)
33
+ local familiars = ____exports.getFamiliars(nil, familiarVariant, familiarSubTypeToSearchFor)
34
+ local familiarsForThisPlayer = __TS__ArrayFilter(
35
+ familiars,
36
+ function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
37
+ )
38
+ local numCollectibles = player:GetCollectibleNum(collectibleType)
39
+ if #familiarsForThisPlayer == numCollectibles then
40
+ return 0
41
+ end
42
+ if #familiarsForThisPlayer > numCollectibles then
43
+ local numFamiliarsToRemove = #familiarsForThisPlayer - numCollectibles
44
+ do
45
+ local i = 0
46
+ while i < numFamiliarsToRemove do
47
+ local familiar = familiarsForThisPlayer[i + 1]
48
+ familiar:Remove()
49
+ i = i + 1
50
+ end
51
+ end
52
+ return numFamiliarsToRemove * -1
53
+ end
54
+ local numFamiliarsToSpawn = numCollectibles - #familiarsForThisPlayer
55
+ local collectibleRNG = player:GetCollectibleRNG(collectibleType)
56
+ local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
57
+ do
58
+ local i = 0
59
+ while i < numFamiliarsToSpawn do
60
+ collectibleRNG:Next()
61
+ local familiar = game:Spawn(
62
+ EntityType.ENTITY_FAMILIAR,
63
+ familiarVariant,
64
+ player.Position,
65
+ Vector.Zero,
66
+ nil,
67
+ familiarSubTypeToUse,
68
+ collectibleRNG:GetSeed()
69
+ ):ToFamiliar()
70
+ if familiar ~= nil then
71
+ familiar.Player = player
72
+ end
73
+ i = i + 1
74
+ end
75
+ end
76
+ return numFamiliarsToSpawn
77
+ end
7
78
  function ____exports.isFamiliarThatShootsPlayerTears(self, familiar)
8
79
  return FAMILIARS_THAT_SHOOT_PLAYER_TEARS:has(familiar.Type)
9
80
  end
81
+ function ____exports.removeAllFamiliars(self, variant, subType, cap)
82
+ local familiars = ____exports.getFamiliars(nil, variant, subType)
83
+ return removeEntities(nil, familiars, cap)
84
+ end
10
85
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.31",
3
+ "version": "1.2.32",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.0",
29
- "isaac-typescript-definitions": "^1.0.343",
29
+ "isaac-typescript-definitions": "^1.0.347",
30
30
  "isaacscript-lint": "^1.0.79",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
32
  "typedoc": "^0.22.12",