isaacscript-common 1.2.34 → 1.2.37

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
@@ -1,21 +1,4 @@
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
2
  /**
20
3
  * Helper function to get all of the familiars in the room.
21
4
  *
@@ -29,12 +12,6 @@ export declare function checkFamiliar(player: EntityPlayer, collectibleType: int
29
12
  */
30
13
  export declare function getFamiliars(matchingVariant?: FamiliarVariant | int, matchingSubType?: number): EntityFamiliar[];
31
14
  export declare function isFamiliarThatShootsPlayerTears(familiar: EntityFamiliar): boolean;
32
- /**
33
- * Helper function to see if one or more Spin to Win familiars are rotating fast. This is helpful
34
- * because the Spin to Win collectible does not fire the UseItem or PreUseItem callbacks when it is
35
- * used.
36
- */
37
- export declare function isSpinToWinActive(): boolean;
38
15
  /**
39
16
  * Helper function to remove all of the familiars in the room.
40
17
  *
@@ -1,9 +1,7 @@
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
4
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
6
- local __TS__ArraySome = ____lualib.__TS__ArraySome
7
5
  local ____exports = {}
8
6
  local ____constants = require("constants")
9
7
  local FAMILIARS_THAT_SHOOT_PLAYER_TEARS = ____constants.FAMILIARS_THAT_SHOOT_PLAYER_TEARS
@@ -27,66 +25,9 @@ function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
27
25
  end
28
26
  return familiars
29
27
  end
30
- local SPIN_TO_WIN_VELOCITY_ACTIVATION_THRESHOLD = 5
31
- function ____exports.checkFamiliar(self, player, collectibleType, familiarVariant, familiarSubType)
32
- local game = Game()
33
- local familiarSubTypeToSearchFor = familiarSubType == nil and -1 or familiarSubType
34
- local playerPtrHash = GetPtrHash(player)
35
- local familiars = ____exports.getFamiliars(nil, familiarVariant, familiarSubTypeToSearchFor)
36
- local familiarsForThisPlayer = __TS__ArrayFilter(
37
- familiars,
38
- function(____, familiar) return GetPtrHash(familiar.Player) == playerPtrHash end
39
- )
40
- local numCollectibles = player:GetCollectibleNum(collectibleType)
41
- if #familiarsForThisPlayer == numCollectibles then
42
- return 0
43
- end
44
- if #familiarsForThisPlayer > numCollectibles then
45
- local numFamiliarsToRemove = #familiarsForThisPlayer - numCollectibles
46
- do
47
- local i = 0
48
- while i < numFamiliarsToRemove do
49
- local familiar = familiarsForThisPlayer[i + 1]
50
- familiar:Remove()
51
- i = i + 1
52
- end
53
- end
54
- return numFamiliarsToRemove * -1
55
- end
56
- local numFamiliarsToSpawn = numCollectibles - #familiarsForThisPlayer
57
- local collectibleRNG = player:GetCollectibleRNG(collectibleType)
58
- local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
59
- do
60
- local i = 0
61
- while i < numFamiliarsToSpawn do
62
- collectibleRNG:Next()
63
- local familiar = game:Spawn(
64
- EntityType.ENTITY_FAMILIAR,
65
- familiarVariant,
66
- player.Position,
67
- Vector.Zero,
68
- player,
69
- familiarSubTypeToUse,
70
- collectibleRNG:GetSeed()
71
- ):ToFamiliar()
72
- if familiar ~= nil then
73
- familiar.Player = player
74
- end
75
- i = i + 1
76
- end
77
- end
78
- return numFamiliarsToSpawn
79
- end
80
28
  function ____exports.isFamiliarThatShootsPlayerTears(self, familiar)
81
29
  return FAMILIARS_THAT_SHOOT_PLAYER_TEARS:has(familiar.Type)
82
30
  end
83
- function ____exports.isSpinToWinActive(self)
84
- local spinToWins = ____exports.getFamiliars(nil, FamiliarVariant.SPIN_TO_WIN)
85
- return __TS__ArraySome(
86
- spinToWins,
87
- function(____, spinToWin) return spinToWin.Velocity:Length() > SPIN_TO_WIN_VELOCITY_ACTIVATION_THRESHOLD end
88
- )
89
- end
90
31
  function ____exports.removeAllFamiliars(self, variant, subType, cap)
91
32
  local familiars = ____exports.getFamiliars(nil, variant, subType)
92
33
  return removeEntities(nil, familiars, cap)
@@ -69,6 +69,8 @@ local ____preNewLevel = require("callbacks.preNewLevel")
69
69
  local preNewLevelCallbackInit = ____preNewLevel.preNewLevelCallbackInit
70
70
  local ____reorderedCallbacks = require("callbacks.reorderedCallbacks")
71
71
  local reorderedCallbacksInit = ____reorderedCallbacks.reorderedCallbacksInit
72
+ local ____checkFamiliar = require("features.checkFamiliar")
73
+ local checkFamiliarInit = ____checkFamiliar.checkFamiliarInit
72
74
  local ____deployJSONRoom = require("features.deployJSONRoom")
73
75
  local deployJSONRoomInit = ____deployJSONRoom.deployJSONRoomInit
74
76
  local ____disableInputs = require("features.disableInputs")
@@ -127,6 +129,7 @@ function initCustomCallbacks(self, mod)
127
129
  postGridEntityCollisionInit(nil, mod)
128
130
  end
129
131
  function initFeatures(self, mod)
132
+ checkFamiliarInit(nil, mod)
130
133
  deployJSONRoomInit(nil, mod)
131
134
  disableInputsInit(nil, mod)
132
135
  forgottenSwitchInit(nil, mod)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.34",
3
+ "version": "1.2.37",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",