isaacscript-common 1.2.36 → 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,29 +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
|
-
* 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
|
-
* @param player The player that has the collectibles for this familiar.
|
|
15
|
-
* @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
|
-
* @param familiarVariant The variant of the familiar to spawn or remove.
|
|
21
|
-
* @param familiarSubType The sub-type of the familiar to spawn
|
|
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, numTempFamiliars: int, familiarVariant: int, familiarSubType?: int): int;
|
|
27
2
|
/**
|
|
28
3
|
* Helper function to get all of the familiars in the room.
|
|
29
4
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
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
5
|
local ____exports = {}
|
|
7
6
|
local ____constants = require("constants")
|
|
@@ -26,56 +25,6 @@ function ____exports.getFamiliars(self, matchingVariant, matchingSubType)
|
|
|
26
25
|
end
|
|
27
26
|
return familiars
|
|
28
27
|
end
|
|
29
|
-
function ____exports.checkFamiliar(self, player, collectibleType, numTempFamiliars, 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
|
-
local numFamiliarsThatShouldExist = numCollectibles + numTempFamiliars
|
|
40
|
-
if #familiarsForThisPlayer == numFamiliarsThatShouldExist then
|
|
41
|
-
return 0
|
|
42
|
-
end
|
|
43
|
-
if #familiarsForThisPlayer > numFamiliarsThatShouldExist then
|
|
44
|
-
local numFamiliarsToRemove = #familiarsForThisPlayer - numFamiliarsThatShouldExist
|
|
45
|
-
do
|
|
46
|
-
local i = 0
|
|
47
|
-
while i < numFamiliarsToRemove do
|
|
48
|
-
local familiar = familiarsForThisPlayer[i + 1]
|
|
49
|
-
familiar:Remove()
|
|
50
|
-
i = i + 1
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
return numFamiliarsToRemove * -1
|
|
54
|
-
end
|
|
55
|
-
local numFamiliarsToSpawn = numFamiliarsThatShouldExist - #familiarsForThisPlayer
|
|
56
|
-
local collectibleRNG = player:GetCollectibleRNG(collectibleType)
|
|
57
|
-
local familiarSubTypeToUse = familiarSubType == nil and 0 or familiarSubType
|
|
58
|
-
do
|
|
59
|
-
local i = 0
|
|
60
|
-
while i < numFamiliarsToSpawn do
|
|
61
|
-
collectibleRNG:Next()
|
|
62
|
-
local familiar = game:Spawn(
|
|
63
|
-
EntityType.ENTITY_FAMILIAR,
|
|
64
|
-
familiarVariant,
|
|
65
|
-
player.Position,
|
|
66
|
-
Vector.Zero,
|
|
67
|
-
player,
|
|
68
|
-
familiarSubTypeToUse,
|
|
69
|
-
collectibleRNG:GetSeed()
|
|
70
|
-
):ToFamiliar()
|
|
71
|
-
if familiar ~= nil then
|
|
72
|
-
familiar.Player = player
|
|
73
|
-
end
|
|
74
|
-
i = i + 1
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
return numFamiliarsToSpawn
|
|
78
|
-
end
|
|
79
28
|
function ____exports.isFamiliarThatShootsPlayerTears(self, familiar)
|
|
80
29
|
return FAMILIARS_THAT_SHOOT_PLAYER_TEARS:has(familiar.Type)
|
|
81
30
|
end
|
package/dist/upgradeMod.lua
CHANGED
|
@@ -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)
|