isaacscript-common 1.2.40 → 1.2.41

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.
@@ -1,4 +1,29 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Helper function to add and remove familiars based on a target amount that you specify. Use this
4
+ * instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of the spawned familiar
5
+ * will be set properly. Note that when using this function, you need to automatically account for
6
+ * Box of Friends.
7
+ *
8
+ * This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
9
+ * to `CacheFlag.CACHE_FAMILIARS`).
10
+ *
11
+ * Note that this function is only meant to be used in special circumstances. For general purpose
12
+ * usage, please use the `checkFamiliarFromCollectibles` helper function instead.
13
+ *
14
+ * @param player The player that owns the familiars.
15
+ * @param collectibleType The collectible type of the collectible associated with this familiar.
16
+ * @param numTargetFamiliars The number of familiars that should exist. This function will add or
17
+ * remove familiars until it matches the target count.
18
+ * @param familiarVariant The variant of the familiar to spawn or remove.
19
+ * @param familiarSubType Optional. The sub-type of the familiar to spawn or remove. If not
20
+ * specified, it will search for existing familiars of all sub-types, and spawn new familiars with a
21
+ * sub-type of 0.
22
+ * @returns The amount of familiars that were added or removed. For example, the player has 0
23
+ * collectibles and there were 2 familiars, this function would remove the 2 familiars and return
24
+ * -2.
25
+ */
26
+ export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, numTargetFamiliars: int, familiarVariant: int, familiarSubType?: int): int;
2
27
  /**
3
28
  * Helper function to add and remove familiars based on the amount of associated collectibles that a
4
29
  * player has. Use this instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of
@@ -7,15 +32,21 @@
7
32
  * This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
8
33
  * to `CacheFlag.CACHE_FAMILIARS`).
9
34
  *
10
- * @param player The player that has the collectibles for this familiar.
35
+ * Use this function when the amount of familiars should be equal to the amount of associated
36
+ * collectibles that the player has (plus any extras from having used Box of Friends). If you
37
+ * instead need to have a custom amount of familiars, use the `checkFamiliars` function instead.
38
+ *
39
+ * @param player The player that owns the familiars and collectibles.
11
40
  * @param collectibleType The collectible type of the collectible associated with this familiar.
12
41
  * @param familiarVariant The variant of the familiar to spawn or remove.
13
- * @param familiarSubType Optional. The sub-type of the familiar to spawn or remove. 0 by default.
42
+ * @param familiarSubType Optional. The sub-type of the familiar to spawn or remove. If not
43
+ * specified, it will search for existing familiars of all sub-types, and spawn new familiars with a
44
+ * sub-type of 0.
14
45
  * @returns The amount of familiars that were added or removed. For example, the player has 0
15
46
  * collectibles and there were 2 familiars, this function would remove the 2 familiars and return
16
47
  * -2.
17
48
  */
18
- export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): int;
49
+ export declare function checkFamiliarFromCollectibles(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): int;
19
50
  /**
20
51
  * Helper function to get all of the familiars in the room.
21
52
  *
@@ -25,7 +25,7 @@ function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
25
25
  end
26
26
  return familiars
27
27
  end
28
- function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
28
+ function ____exports.checkFamiliar(self, player, collectibleType, numTargetFamiliars, familiarVariant, familiarSubType)
29
29
  local game = Game()
30
30
  local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
31
31
  local playerPtrHash = GetPtrHash(player)
@@ -34,15 +34,11 @@ function ____exports.checkFamiliar(self, player, collectibleType, familiarVarian
34
34
  familiars,
35
35
  function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
36
36
  )
37
- local numCollectibles = player:GetCollectibleNum(collectibleType)
38
- local effects = player:GetEffects()
39
- local numBoxOfFriendsUses = effects:GetCollectibleEffectNum(CollectibleType.COLLECTIBLE_BOX_OF_FRIENDS)
40
- local numFamiliarsThatShouldExist = numCollectibles * (numBoxOfFriendsUses + 1)
41
- if #familiarsForThisPlayer == numFamiliarsThatShouldExist then
37
+ if #familiarsForThisPlayer == numTargetFamiliars then
42
38
  return 0
43
39
  end
44
- if #familiarsForThisPlayer > numFamiliarsThatShouldExist then
45
- local numFamiliarsToRemove = #familiarsForThisPlayer - numFamiliarsThatShouldExist
40
+ if #familiarsForThisPlayer > numTargetFamiliars then
41
+ local numFamiliarsToRemove = #familiarsForThisPlayer - numTargetFamiliars
46
42
  do
47
43
  local i = 0
48
44
  while i < numFamiliarsToRemove do
@@ -53,7 +49,7 @@ function ____exports.checkFamiliar(self, player, collectibleType, familiarVarian
53
49
  end
54
50
  return numFamiliarsToRemove * -1
55
51
  end
56
- local numFamiliarsToSpawn = numFamiliarsThatShouldExist - #familiarsForThisPlayer
52
+ local numFamiliarsToSpawn = numTargetFamiliars - #familiarsForThisPlayer
57
53
  local collectibleRNG = player:GetCollectibleRNG(collectibleType)
58
54
  local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
59
55
  do
@@ -77,6 +73,20 @@ function ____exports.checkFamiliar(self, player, collectibleType, familiarVarian
77
73
  end
78
74
  return numFamiliarsToSpawn
79
75
  end
76
+ function ____exports.checkFamiliarFromCollectibles(self, player, collectibleType, familiarVariant, familiarSubType)
77
+ local numCollectibles = player:GetCollectibleNum(collectibleType)
78
+ local effects = player:GetEffects()
79
+ local numBoxOfFriendsUses = effects:GetCollectibleEffectNum(CollectibleType.COLLECTIBLE_BOX_OF_FRIENDS)
80
+ local numTargetFamiliars = numCollectibles * (numBoxOfFriendsUses + 1)
81
+ return ____exports.checkFamiliar(
82
+ nil,
83
+ player,
84
+ collectibleType,
85
+ numTargetFamiliars,
86
+ familiarVariant,
87
+ familiarSubType
88
+ )
89
+ end
80
90
  function ____exports.isFamiliarThatShootsPlayerTears(self, familiar)
81
91
  return FAMILIARS_THAT_SHOOT_PLAYER_TEARS:has(familiar.Type)
82
92
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.40",
3
+ "version": "1.2.41",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",