isaacscript-common 1.0.601 → 1.0.602
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.
- package/dist/functions/jsonRoom.lua +36 -26
- package/dist/functions/npc.lua +17 -23
- package/dist/functions/player.d.ts +3 -1
- package/dist/functions/player.lua +44 -42
- package/package.json +1 -1
|
@@ -2,56 +2,66 @@
|
|
|
2
2
|
require("lualib_bundle");
|
|
3
3
|
local ____exports = {}
|
|
4
4
|
local getTotalWeightOfJSONRooms, getJSONRoomWithChosenWeight
|
|
5
|
+
local ____array = require("functions.array")
|
|
6
|
+
local arraySum = ____array.arraySum
|
|
5
7
|
local ____log = require("functions.log")
|
|
6
8
|
local log = ____log.log
|
|
7
9
|
local ____random = require("functions.random")
|
|
8
10
|
local getRandomFloat = ____random.getRandomFloat
|
|
9
11
|
function getTotalWeightOfJSONRooms(self, jsonRooms)
|
|
10
|
-
local
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
local weights = __TS__ArrayMap(
|
|
13
|
+
jsonRooms,
|
|
14
|
+
function(____, jsonRoom)
|
|
15
|
+
local roomWeightString = jsonRoom["$"].weight
|
|
16
|
+
local roomWeight = tonumber(roomWeightString)
|
|
17
|
+
if roomWeight == nil then
|
|
18
|
+
error(("Failed to parse the weight of a JSON room: " .. roomWeightString) .. ".")
|
|
19
|
+
end
|
|
20
|
+
return roomWeight
|
|
16
21
|
end
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return totalWeight
|
|
22
|
+
)
|
|
23
|
+
return arraySum(nil, weights)
|
|
20
24
|
end
|
|
21
25
|
function getJSONRoomWithChosenWeight(self, jsonRooms, chosenWeight)
|
|
22
26
|
for ____, jsonRoom in ipairs(jsonRooms) do
|
|
23
27
|
local roomWeightString = jsonRoom["$"].weight
|
|
24
28
|
local roomWeight = tonumber(roomWeightString)
|
|
25
29
|
if roomWeight == nil then
|
|
26
|
-
error("Failed to parse the weight of a room: " .. roomWeightString)
|
|
30
|
+
error("Failed to parse the weight of a JSON room: " .. roomWeightString)
|
|
27
31
|
end
|
|
28
32
|
if chosenWeight < roomWeight then
|
|
29
33
|
return jsonRoom
|
|
30
34
|
end
|
|
31
35
|
chosenWeight = chosenWeight - roomWeight
|
|
32
36
|
end
|
|
33
|
-
return error("Failed to get a room with chosen weight: " .. tostring(chosenWeight))
|
|
37
|
+
return error("Failed to get a JSON room with chosen weight: " .. tostring(chosenWeight))
|
|
34
38
|
end
|
|
35
39
|
function ____exports.getJSONRoomOfVariant(self, jsonRooms, variant)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
local jsonRoomsOfVariant = __TS__ArrayFilter(
|
|
41
|
+
jsonRooms,
|
|
42
|
+
function(____, jsonRoom)
|
|
43
|
+
local roomVariantString = jsonRoom["$"].variant
|
|
44
|
+
local roomVariant = tonumber(roomVariantString)
|
|
45
|
+
return roomVariant == variant
|
|
41
46
|
end
|
|
47
|
+
)
|
|
48
|
+
if #jsonRoomsOfVariant == 0 then
|
|
49
|
+
return nil
|
|
50
|
+
end
|
|
51
|
+
if #jsonRoomsOfVariant == 1 then
|
|
52
|
+
return jsonRoomsOfVariant[1]
|
|
42
53
|
end
|
|
43
|
-
return
|
|
54
|
+
return error(((("Found " .. tostring(#jsonRoomsOfVariant)) .. " JSON rooms with a variant of ") .. tostring(variant)) .. ", when there should only be 1.")
|
|
44
55
|
end
|
|
45
56
|
function ____exports.getJSONRoomsOfSubType(self, jsonRooms, subType)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
return __TS__ArrayFilter(
|
|
58
|
+
jsonRooms,
|
|
59
|
+
function(____, jsonRoom)
|
|
60
|
+
local roomSubTypeString = jsonRoom["$"].subtype
|
|
61
|
+
local roomSubType = tonumber(roomSubTypeString)
|
|
62
|
+
return roomSubType == subType
|
|
52
63
|
end
|
|
53
|
-
|
|
54
|
-
return jsonRoomsOfSubType
|
|
64
|
+
)
|
|
55
65
|
end
|
|
56
66
|
function ____exports.getRandomJSONRoom(self, jsonRooms, seed, verbose)
|
|
57
67
|
if seed == nil then
|
|
@@ -66,7 +76,7 @@ function ____exports.getRandomJSONRoom(self, jsonRooms, seed, verbose)
|
|
|
66
76
|
end
|
|
67
77
|
local chosenWeight = getRandomFloat(nil, 0, totalWeight, seed)
|
|
68
78
|
if verbose then
|
|
69
|
-
log("Randomly chose weight: " .. tostring(chosenWeight))
|
|
79
|
+
log("Randomly chose weight for JSON room: " .. tostring(chosenWeight))
|
|
70
80
|
end
|
|
71
81
|
return getJSONRoomWithChosenWeight(nil, jsonRooms, chosenWeight)
|
|
72
82
|
end
|
package/dist/functions/npc.lua
CHANGED
|
@@ -9,14 +9,12 @@ local getEntities = ____entity.getEntities
|
|
|
9
9
|
local getFilteredNewEntities = ____entity.getFilteredNewEntities
|
|
10
10
|
local getProjectiles = ____entity.getProjectiles
|
|
11
11
|
local removeEntities = ____entity.removeEntities
|
|
12
|
-
function ____exports.
|
|
13
|
-
local
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
return bosses
|
|
12
|
+
function ____exports.getAliveNPCs(self)
|
|
13
|
+
local npcs = ____exports.getNPCs(nil)
|
|
14
|
+
return __TS__ArrayFilter(
|
|
15
|
+
npcs,
|
|
16
|
+
function(____, npc) return not npc:IsDead() and not ____exports.isAliveExceptionNPC(nil, npc) end
|
|
17
|
+
)
|
|
20
18
|
end
|
|
21
19
|
function ____exports.getNPCs(self, matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
|
|
22
20
|
if ignoreFriendly == nil then
|
|
@@ -92,22 +90,18 @@ function ____exports.fireProjectiles(self, npc, position, velocity, projectilesM
|
|
|
92
90
|
return getFilteredNewEntities(nil, oldProjectiles, newProjectiles)
|
|
93
91
|
end
|
|
94
92
|
function ____exports.getAliveBosses(self)
|
|
95
|
-
local
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
end
|
|
101
|
-
return aliveBosses
|
|
93
|
+
local aliveNPCs = ____exports.getAliveNPCs(nil)
|
|
94
|
+
return __TS__ArrayFilter(
|
|
95
|
+
aliveNPCs,
|
|
96
|
+
function(____, aliveNPC) return aliveNPC:IsBoss() end
|
|
97
|
+
)
|
|
102
98
|
end
|
|
103
|
-
function ____exports.
|
|
104
|
-
local
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
return aliveNPCs
|
|
99
|
+
function ____exports.getBosses(self)
|
|
100
|
+
local npcs = ____exports.getNPCs(nil)
|
|
101
|
+
return __TS__ArrayFilter(
|
|
102
|
+
npcs,
|
|
103
|
+
function(____, npc) return npc:IsBoss() end
|
|
104
|
+
)
|
|
111
105
|
end
|
|
112
106
|
function ____exports.removeAllNPCs(self, cap)
|
|
113
107
|
local npcs = ____exports.getNPCs(nil)
|
|
@@ -25,7 +25,7 @@ export declare function anyPlayerHasTrinket(trinketType: TrinketType | int): boo
|
|
|
25
25
|
* This function is variadic, meaning that you can supply as many characters as you want to check
|
|
26
26
|
* for. Returns true if any of the characters supplied are present.
|
|
27
27
|
*/
|
|
28
|
-
export declare function anyPlayerIs(...
|
|
28
|
+
export declare function anyPlayerIs(...matchingCharacters: PlayerType[]): boolean;
|
|
29
29
|
/**
|
|
30
30
|
* Helper function to determine if the provided character can have red heart containers. Returns
|
|
31
31
|
* true for characters like Isaac, Magdalene, or Cain. Returns true for Keeper and Tainted Keeper,
|
|
@@ -83,6 +83,8 @@ export declare function getPlayerAvailableHeartSlots(player: EntityPlayer): int;
|
|
|
83
83
|
* Kiss; use the `getPlayerMaxHeartContainers()` function for that.
|
|
84
84
|
*/
|
|
85
85
|
export declare function getCharacterMaxHeartContainers(character: PlayerType): int;
|
|
86
|
+
/** Helper function to get an array containing the characters of all of the current players. */
|
|
87
|
+
export declare function getCharacters(): number[];
|
|
86
88
|
/**
|
|
87
89
|
* Iterates over all players and checks if any are close enough to the specified position.
|
|
88
90
|
*
|
|
@@ -29,6 +29,13 @@ function ____exports.getCharacterMaxHeartContainers(self, character)
|
|
|
29
29
|
end
|
|
30
30
|
return 12
|
|
31
31
|
end
|
|
32
|
+
function ____exports.getCharacters(self)
|
|
33
|
+
local players = ____exports.getPlayers(nil)
|
|
34
|
+
return __TS__ArrayMap(
|
|
35
|
+
players,
|
|
36
|
+
function(____, player) return player:GetPlayerType() end
|
|
37
|
+
)
|
|
38
|
+
end
|
|
32
39
|
function ____exports.getPlayerIndex(self, player)
|
|
33
40
|
local character = player:GetPlayerType()
|
|
34
41
|
local collectibleToUse = character == PlayerType.PLAYER_LAZARUS2_B and CollectibleType.COLLECTIBLE_INNER_EYE or CollectibleType.COLLECTIBLE_SAD_ONION
|
|
@@ -61,18 +68,18 @@ function ____exports.getPlayers(self, performExclusions)
|
|
|
61
68
|
do
|
|
62
69
|
local player = Isaac.GetPlayer(i)
|
|
63
70
|
if player == nil then
|
|
64
|
-
goto
|
|
71
|
+
goto __continue70
|
|
65
72
|
end
|
|
66
73
|
if ____exports.isChildPlayer(nil, player) then
|
|
67
|
-
goto
|
|
74
|
+
goto __continue70
|
|
68
75
|
end
|
|
69
76
|
local character = player:GetPlayerType()
|
|
70
77
|
if performExclusions and EXCLUDED_CHARACTERS:has(character) then
|
|
71
|
-
goto
|
|
78
|
+
goto __continue70
|
|
72
79
|
end
|
|
73
80
|
__TS__ArrayPush(players, player)
|
|
74
81
|
end
|
|
75
|
-
::
|
|
82
|
+
::__continue70::
|
|
76
83
|
i = i + 1
|
|
77
84
|
end
|
|
78
85
|
end
|
|
@@ -99,39 +106,34 @@ function ____exports.addTrinketCostume(self, player, trinketType)
|
|
|
99
106
|
player:AddCostume(itemConfigTrinket, false)
|
|
100
107
|
end
|
|
101
108
|
function ____exports.anyPlayerCloserThan(self, position, distance)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
return false
|
|
109
|
+
local players = ____exports.getPlayers(nil)
|
|
110
|
+
return __TS__ArraySome(
|
|
111
|
+
players,
|
|
112
|
+
function(____, player) return player.Position:Distance(position) <= distance end
|
|
113
|
+
)
|
|
108
114
|
end
|
|
109
115
|
function ____exports.anyPlayerHasCollectible(self, collectibleType)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
return false
|
|
116
|
+
local players = ____exports.getPlayers(nil)
|
|
117
|
+
return __TS__ArraySome(
|
|
118
|
+
players,
|
|
119
|
+
function(____, player) return player:HasCollectible(collectibleType) end
|
|
120
|
+
)
|
|
116
121
|
end
|
|
117
122
|
function ____exports.anyPlayerHasTrinket(self, trinketType)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
return false
|
|
123
|
+
local players = ____exports.getPlayers(nil)
|
|
124
|
+
return __TS__ArraySome(
|
|
125
|
+
players,
|
|
126
|
+
function(____, player) return player:HasTrinket(trinketType) end
|
|
127
|
+
)
|
|
124
128
|
end
|
|
125
129
|
function ____exports.anyPlayerIs(self, ...)
|
|
126
|
-
local
|
|
127
|
-
local
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
end
|
|
134
|
-
return false
|
|
130
|
+
local matchingCharacters = {...}
|
|
131
|
+
local matchingCharacterSet = __TS__New(Set, matchingCharacters)
|
|
132
|
+
local characters = ____exports.getCharacters(nil)
|
|
133
|
+
return __TS__ArraySome(
|
|
134
|
+
characters,
|
|
135
|
+
function(____, character) return matchingCharacterSet:has(character) end
|
|
136
|
+
)
|
|
135
137
|
end
|
|
136
138
|
function ____exports.characterCanHaveRedHearts(self, character)
|
|
137
139
|
return not CHARACTERS_WITH_NO_RED_HEARTS:has(character)
|
|
@@ -282,14 +284,14 @@ function ____exports.getPlayerIndexVanilla(self, playerToFind)
|
|
|
282
284
|
do
|
|
283
285
|
local player = Isaac.GetPlayer(i)
|
|
284
286
|
if player == nil then
|
|
285
|
-
goto
|
|
287
|
+
goto __continue62
|
|
286
288
|
end
|
|
287
289
|
local playerHash = GetPtrHash(player)
|
|
288
290
|
if playerHash == playerToFindHash then
|
|
289
291
|
return i
|
|
290
292
|
end
|
|
291
293
|
end
|
|
292
|
-
::
|
|
294
|
+
::__continue62::
|
|
293
295
|
i = i + 1
|
|
294
296
|
end
|
|
295
297
|
end
|
|
@@ -450,9 +452,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
|
|
|
450
452
|
itemPool:RemoveCollectible(collectibleType)
|
|
451
453
|
end
|
|
452
454
|
repeat
|
|
453
|
-
local
|
|
454
|
-
local
|
|
455
|
-
if
|
|
455
|
+
local ____switch112 = activeSlot
|
|
456
|
+
local ____cond112 = ____switch112 == ActiveSlot.SLOT_PRIMARY
|
|
457
|
+
if ____cond112 then
|
|
456
458
|
do
|
|
457
459
|
if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
|
|
458
460
|
player:RemoveCollectible(primaryCollectibleType)
|
|
@@ -461,8 +463,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
|
|
|
461
463
|
break
|
|
462
464
|
end
|
|
463
465
|
end
|
|
464
|
-
|
|
465
|
-
if
|
|
466
|
+
____cond112 = ____cond112 or ____switch112 == ActiveSlot.SLOT_SECONDARY
|
|
467
|
+
if ____cond112 then
|
|
466
468
|
do
|
|
467
469
|
if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
|
|
468
470
|
player:RemoveCollectible(primaryCollectibleType)
|
|
@@ -477,16 +479,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
|
|
|
477
479
|
break
|
|
478
480
|
end
|
|
479
481
|
end
|
|
480
|
-
|
|
481
|
-
if
|
|
482
|
+
____cond112 = ____cond112 or ____switch112 == ActiveSlot.SLOT_POCKET
|
|
483
|
+
if ____cond112 then
|
|
482
484
|
do
|
|
483
485
|
player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
|
|
484
486
|
player:SetActiveCharge(charge, activeSlot)
|
|
485
487
|
break
|
|
486
488
|
end
|
|
487
489
|
end
|
|
488
|
-
|
|
489
|
-
if
|
|
490
|
+
____cond112 = ____cond112 or ____switch112 == ActiveSlot.SLOT_POCKET2
|
|
491
|
+
if ____cond112 then
|
|
490
492
|
do
|
|
491
493
|
player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
|
|
492
494
|
break
|