isaacscript-common 1.2.36 → 1.2.39

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.
@@ -0,0 +1,18 @@
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 and Box of Friends functions correctly.
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;
@@ -0,0 +1,78 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ local ____lualib = require("lualib_bundle")
3
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
4
+ local ____exports = {}
5
+ local useItemBoxOfFriends, v
6
+ local ____errors = require("errors")
7
+ local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
8
+ local ____familiars = require("functions.familiars")
9
+ local getFamiliars = ____familiars.getFamiliars
10
+ local ____exports = require("features.saveDataManager.exports")
11
+ local saveDataManager = ____exports.saveDataManager
12
+ function useItemBoxOfFriends(self)
13
+ local ____v_room_0, ____numBoxOfFriendsUses_1 = v.room, "numBoxOfFriendsUses"
14
+ ____v_room_0[____numBoxOfFriendsUses_1] = ____v_room_0[____numBoxOfFriendsUses_1] + 1
15
+ end
16
+ local FEATURE_NAME = "check familiar"
17
+ local initialized = false
18
+ v = {room = {numBoxOfFriendsUses = 0}}
19
+ function ____exports.checkFamiliarInit(self, mod)
20
+ initialized = true
21
+ saveDataManager(nil, "checkFamiliar", v)
22
+ mod:AddCallback(ModCallbacks.MC_USE_ITEM, useItemBoxOfFriends, CollectibleType.COLLECTIBLE_BOX_OF_FRIENDS)
23
+ end
24
+ function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
25
+ if not initialized then
26
+ local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
27
+ error(msg)
28
+ end
29
+ local game = Game()
30
+ local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
31
+ local playerPtrHash = GetPtrHash(player)
32
+ local familiars = getFamiliars(nil, familiarVariant, familiarSubTypeToSearchFor)
33
+ local familiarsForThisPlayer = __TS__ArrayFilter(
34
+ familiars,
35
+ function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
36
+ )
37
+ local numCollectibles = player:GetCollectibleNum(collectibleType)
38
+ local numFamiliarsThatShouldExist = numCollectibles * (v.room.numBoxOfFriendsUses + 1)
39
+ if #familiarsForThisPlayer == numFamiliarsThatShouldExist then
40
+ return 0
41
+ end
42
+ if #familiarsForThisPlayer > numFamiliarsThatShouldExist then
43
+ local numFamiliarsToRemove = #familiarsForThisPlayer - numFamiliarsThatShouldExist
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 = numFamiliarsThatShouldExist - #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
+ player,
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
78
+ return ____exports
@@ -2,28 +2,20 @@
2
2
  /**
3
3
  * Helper function to add and remove familiars based on the amount of associated collectibles that a
4
4
  * player has. Use this instead of the `EntityPlayer.CheckFamiliar` method so that the InitSeed of
5
- * the spawned familiar will be set properly.
5
+ * the spawned familiar will be set properly and Box of Friends functions correctly.
6
6
  *
7
7
  * This function is meant to be called in the EvaluateCache callback (when the cache flag is equal
8
8
  * to `CacheFlag.CACHE_FAMILIARS`).
9
9
  *
10
- * Note that if you want your custom familiar to work properly with Box of Friends, you must keep
11
- * track of the number of times that it has been used per room and then pass that as the
12
- * `numTempFamiliars` argument.
13
- *
14
10
  * @param player The player that has the collectibles for this familiar.
15
11
  * @param collectibleType The collectible type of the collectible associated with this familiar.
16
- * @param numTempFamiliars The amount of extra familiars that should exist that are not associated
17
- * with a collectible. Usually, this should be 0. For example, if the player has one familiar and
18
- * has used Box of Friends once in the current room, then 1 should be passed (so that 2 total
19
- * familiars will be spawned).
20
12
  * @param familiarVariant The variant of the familiar to spawn or remove.
21
- * @param familiarSubType The sub-type of the familiar to spawn
13
+ * @param familiarSubType Optional. The sub-type of the familiar to spawn or remove. 0 by default.
22
14
  * @returns The amount of familiars that were added or removed. For example, the player has 0
23
15
  * collectibles and there were 2 familiars, this function would remove the 2 familiars and return
24
16
  * -2.
25
17
  */
26
- export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, numTempFamiliars: int, familiarVariant: int, familiarSubType?: int): int;
18
+ export declare function checkFamiliar(player: EntityPlayer, collectibleType: int, familiarVariant: int, familiarSubType?: int): int;
27
19
  /**
28
20
  * Helper function to get all of the familiars in the room.
29
21
  *
@@ -26,7 +26,7 @@ function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
26
26
  end
27
27
  return familiars
28
28
  end
29
- function ____exports.checkFamiliar(self, player, collectibleType, numTempFamiliars, familiarVariant, familiarSubType)
29
+ function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
30
30
  local game = Game()
31
31
  local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
32
32
  local playerPtrHash = GetPtrHash(player)
@@ -36,7 +36,9 @@ function ____exports.checkFamiliar(self, player, collectibleType, numTempFamilia
36
36
  function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
37
37
  )
38
38
  local numCollectibles = player:GetCollectibleNum(collectibleType)
39
- local numFamiliarsThatShouldExist = numCollectibles + numTempFamiliars
39
+ local effects = player:GetEffects()
40
+ local numBoxOfFriendsUses = effects:GetCollectibleEffectNum(CollectibleType.COLLECTIBLE_BOX_OF_FRIENDS)
41
+ local numFamiliarsThatShouldExist = numCollectibles * (numBoxOfFriendsUses + 1)
40
42
  if #familiarsForThisPlayer == numFamiliarsThatShouldExist then
41
43
  return 0
42
44
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.36",
3
+ "version": "1.2.39",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",