isaacscript-common 1.2.93 → 1.2.96

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.
@@ -6,6 +6,8 @@ local ____exports = {}
6
6
  local hasSubscriptions, postPEffectUpdateReordered, getCurrentHealthValue, v
7
7
  local ____exports = require("features.saveDataManager.exports")
8
8
  local saveDataManager = ____exports.saveDataManager
9
+ local ____bitwise = require("functions.bitwise")
10
+ local countSetBits = ____bitwise.countSetBits
9
11
  local ____player = require("functions.player")
10
12
  local getPlayerIndex = ____player.getPlayerIndex
11
13
  local ____utils = require("functions.utils")
@@ -45,13 +47,18 @@ function getCurrentHealthValue(self, player, healthType)
45
47
  local ____cond11 = ____switch11 == HealthType.RED
46
48
  if ____cond11 then
47
49
  do
48
- return player:GetHearts()
50
+ local rottenHearts = player:GetRottenHearts()
51
+ local hearts = player:GetHearts()
52
+ return hearts - rottenHearts * 2
49
53
  end
50
54
  end
51
55
  ____cond11 = ____cond11 or ____switch11 == HealthType.SOUL
52
56
  if ____cond11 then
53
57
  do
54
- return player:GetSoulHearts()
58
+ local soulHearts = player:GetSoulHearts()
59
+ local blackHeartsBitmask = player:GetBlackHearts()
60
+ local blackHearts = countSetBits(nil, blackHeartsBitmask)
61
+ return soulHearts - blackHearts
55
62
  end
56
63
  end
57
64
  ____cond11 = ____cond11 or ____switch11 == HealthType.ETERNAL
@@ -63,7 +70,8 @@ function getCurrentHealthValue(self, player, healthType)
63
70
  ____cond11 = ____cond11 or ____switch11 == HealthType.BLACK
64
71
  if ____cond11 then
65
72
  do
66
- return player:GetBlackHearts()
73
+ local blackHearts = player:GetBlackHearts()
74
+ return countSetBits(nil, blackHearts)
67
75
  end
68
76
  end
69
77
  ____cond11 = ____cond11 or ____switch11 == HealthType.GOLDEN
@@ -1,3 +1,4 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ export declare function countSetBits(n: int): int;
2
3
  export declare function getKBitOfN(k: int, n: int): int;
3
4
  export declare function getNumBitsOfN(n: int): int;
@@ -1,5 +1,13 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____exports = {}
3
+ function ____exports.countSetBits(self, n)
4
+ local count = 0
5
+ while n > 0 do
6
+ n = n & n - 1
7
+ count = count + 1
8
+ end
9
+ return count
10
+ end
3
11
  function ____exports.getKBitOfN(self, k, n)
4
12
  return n >> k & 1
5
13
  end
@@ -13,7 +13,6 @@ export declare function getAngleDifference(angle1: float, angle2: float): float;
13
13
  * this can be optionally changed by specifying this argument.
14
14
  */
15
15
  export declare function getCircleDiscretizedPoints(centerPos: Vector, radius: float, numPoints: int, xMultiplier?: number, yMultiplier?: number, initialDirection?: Direction): Vector[];
16
- export declare function getSetBits(n: int): int;
17
16
  /**
18
17
  * Helper function to check if a given position is within a given rectangle. This is an inclusive
19
18
  * check, meaning that it will return true if the position is on the border of the rectangle.
@@ -74,14 +74,6 @@ function ____exports.getCircleDiscretizedPoints(self, centerPos, radius, numPoin
74
74
  end
75
75
  return positions
76
76
  end
77
- function ____exports.getSetBits(self, n)
78
- local count = 0
79
- while n > 0 do
80
- n = n & n - 1
81
- count = count + 1
82
- end
83
- return count
84
- end
85
77
  function ____exports.inRectangle(self, position, topLeft, bottomRight)
86
78
  return position.X >= topLeft.X and position.X <= bottomRight.X and position.Y <= topLeft.Y and position.Y >= bottomRight.Y
87
79
  end
@@ -48,6 +48,14 @@ export declare function getAllPlayers(): EntityPlayer[];
48
48
  * The formula for calculating it is: 32 - 2.5 * player.TearHeight
49
49
  */
50
50
  export declare function getAzazelBrimstoneDistance(playerOrTearHeight: EntityPlayer | float): number;
51
+ /**
52
+ * Returns the number of black hearts that the player has, excluding any soul hearts. For example,
53
+ * if the player has one full black heart, one full soul heart, and one half black heart, this
54
+ * function returns 3.
55
+ *
56
+ * This is different from the `EntityPlayer.GetBlackHearts` method, since that returns a bitmask.
57
+ */
58
+ export declare function getBlackHearts(player: EntityPlayer): int;
51
59
  /**
52
60
  * Returns the maximum heart containers that the provided character can have. Normally, this is 12,
53
61
  * but with Keeper it is 3, with Tainted Keeper it is 2. Does not account for Birthright or Mother's
@@ -73,6 +81,15 @@ export declare function getEffectsList(player: EntityPlayer): TemporaryEffect[];
73
81
  * method.
74
82
  */
75
83
  export declare function getFinalPlayer(): EntityPlayer;
84
+ /**
85
+ * Returns the number of red hearts that the player has, excluding any rotten hearts. For example,
86
+ * if the player has one full black heart, one full soul heart, and one half black heart, this
87
+ * function returns 3.
88
+ *
89
+ * This is different from the `EntityPlayer.GetHearts` method, since that returns a value that
90
+ * includes rotten hearts.
91
+ */
92
+ export declare function getHearts(player: EntityPlayer): int;
76
93
  /**
77
94
  * Helper function that returns the type of the rightmost heart, not including golden hearts since
78
95
  * they can't be damaged directly.
@@ -176,6 +193,15 @@ export declare function getPlayers(performCharacterExclusions?: boolean): Entity
176
193
  * for. Returns true if any of the characters supplied are present.
177
194
  */
178
195
  export declare function getPlayersOfType(...characters: Array<PlayerType | int>): EntityPlayer[];
196
+ /**
197
+ * Returns the number of soul hearts that the player has, excluding any black hearts. For example,
198
+ * if the player has one full black heart, one full soul heart, and one half black heart, this
199
+ * function returns 2.
200
+ *
201
+ * This is different from the `EntityPlayer.GetSoulHearts` method, since that returns the combined
202
+ * number of soul hearts and black hearts.
203
+ */
204
+ export declare function getSoulHearts(player: EntityPlayer): int;
179
205
  /**
180
206
  * Helper function to get a parent `EntityPlayer` object for a given `EntitySubPlayer` object. This
181
207
  * is useful because calling the `EntityPlayer.GetSubPlayer` method on a sub-player object will
@@ -25,6 +25,7 @@ local ____array = require("functions.array")
25
25
  local getLastElement = ____array.getLastElement
26
26
  local sumArray = ____array.sumArray
27
27
  local ____bitwise = require("functions.bitwise")
28
+ local countSetBits = ____bitwise.countSetBits
28
29
  local getKBitOfN = ____bitwise.getKBitOfN
29
30
  local getNumBitsOfN = ____bitwise.getNumBitsOfN
30
31
  local ____collectibles = require("functions.collectibles")
@@ -90,15 +91,15 @@ end
90
91
  function getPlayerIndexCollectibleType(self, player, differentiateForgottenAndSoul)
91
92
  local character = player:GetPlayerType()
92
93
  repeat
93
- local ____switch64 = character
94
- local ____cond64 = ____switch64 == PlayerType.PLAYER_THESOUL
95
- if ____cond64 then
94
+ local ____switch66 = character
95
+ local ____cond66 = ____switch66 == PlayerType.PLAYER_THESOUL
96
+ if ____cond66 then
96
97
  do
97
98
  return differentiateForgottenAndSoul and CollectibleType.COLLECTIBLE_SPOON_BENDER or DEFAULT_COLLECTIBLE_TYPE
98
99
  end
99
100
  end
100
- ____cond64 = ____cond64 or ____switch64 == PlayerType.PLAYER_LAZARUS2_B
101
- if ____cond64 then
101
+ ____cond66 = ____cond66 or ____switch66 == PlayerType.PLAYER_LAZARUS2_B
102
+ if ____cond66 then
102
103
  do
103
104
  return CollectibleType.COLLECTIBLE_INNER_EYE
104
105
  end
@@ -126,39 +127,39 @@ end
126
127
  function getAdjustedPlayerName(self, player)
127
128
  local character = player:GetPlayerType()
128
129
  repeat
129
- local ____switch77 = character
130
- local ____cond77 = ____switch77 == PlayerType.PLAYER_BLUEBABY or ____switch77 == PlayerType.PLAYER_BLUEBABY_B
131
- if ____cond77 then
130
+ local ____switch79 = character
131
+ local ____cond79 = ____switch79 == PlayerType.PLAYER_BLUEBABY or ____switch79 == PlayerType.PLAYER_BLUEBABY_B
132
+ if ____cond79 then
132
133
  do
133
134
  return "Blue Baby"
134
135
  end
135
136
  end
136
- ____cond77 = ____cond77 or ____switch77 == PlayerType.PLAYER_LAZARUS2
137
- if ____cond77 then
137
+ ____cond79 = ____cond79 or ____switch79 == PlayerType.PLAYER_LAZARUS2
138
+ if ____cond79 then
138
139
  do
139
140
  return "Lazarus II"
140
141
  end
141
142
  end
142
- ____cond77 = ____cond77 or ____switch77 == PlayerType.PLAYER_BLACKJUDAS
143
- if ____cond77 then
143
+ ____cond79 = ____cond79 or ____switch79 == PlayerType.PLAYER_BLACKJUDAS
144
+ if ____cond79 then
144
145
  do
145
146
  return "Dark Judas"
146
147
  end
147
148
  end
148
- ____cond77 = ____cond77 or ____switch77 == PlayerType.PLAYER_JACOB
149
- if ____cond77 then
149
+ ____cond79 = ____cond79 or ____switch79 == PlayerType.PLAYER_JACOB
150
+ if ____cond79 then
150
151
  do
151
152
  return "Jacob & Esau"
152
153
  end
153
154
  end
154
- ____cond77 = ____cond77 or ____switch77 == PlayerType.PLAYER_LAZARUS2_B
155
- if ____cond77 then
155
+ ____cond79 = ____cond79 or ____switch79 == PlayerType.PLAYER_LAZARUS2_B
156
+ if ____cond79 then
156
157
  do
157
158
  return "Dead Tainted Lazarus"
158
159
  end
159
160
  end
160
- ____cond77 = ____cond77 or ____switch77 == PlayerType.PLAYER_JACOB2_B
161
- if ____cond77 then
161
+ ____cond79 = ____cond79 or ____switch79 == PlayerType.PLAYER_JACOB2_B
162
+ if ____cond79 then
162
163
  do
163
164
  return "Dead Tainted Jacob"
164
165
  end
@@ -294,6 +295,10 @@ function ____exports.getAzazelBrimstoneDistance(self, playerOrTearHeight)
294
295
  end
295
296
  return 32 - 2.5 * tearHeight
296
297
  end
298
+ function ____exports.getBlackHearts(self, player)
299
+ local blackHearts = player:GetBlackHearts()
300
+ return countSetBits(nil, blackHearts)
301
+ end
297
302
  function ____exports.getClosestPlayer(self, position)
298
303
  local closestPlayer = nil
299
304
  local closestDistance = math.huge
@@ -339,6 +344,11 @@ function ____exports.getFinalPlayer(self)
339
344
  local players = ____exports.getPlayers(nil)
340
345
  return getLastElement(nil, players)
341
346
  end
347
+ function ____exports.getHearts(self, player)
348
+ local rottenHearts = player:GetRottenHearts()
349
+ local hearts = player:GetHearts()
350
+ return hearts - rottenHearts * 2
351
+ end
342
352
  function ____exports.getLastHeart(self, player)
343
353
  local hearts = player:GetHearts()
344
354
  local effectiveMaxHearts = player:GetEffectiveMaxHearts()
@@ -475,6 +485,11 @@ function ____exports.getPlayersOfType(self, ...)
475
485
  end
476
486
  )
477
487
  end
488
+ function ____exports.getSoulHearts(self, player)
489
+ local soulHearts = player:GetSoulHearts()
490
+ local blackHearts = ____exports.getBlackHearts(nil, player)
491
+ return soulHearts - blackHearts
492
+ end
478
493
  function ____exports.getTotalCharge(self, player, activeSlot)
479
494
  local activeCharge = player:GetActiveCharge(activeSlot)
480
495
  local batteryCharge = player:GetBatteryCharge(activeSlot)
@@ -573,9 +588,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
573
588
  itemPool:RemoveCollectible(collectibleType)
574
589
  end
575
590
  repeat
576
- local ____switch122 = activeSlot
577
- local ____cond122 = ____switch122 == ActiveSlot.SLOT_PRIMARY
578
- if ____cond122 then
591
+ local ____switch125 = activeSlot
592
+ local ____cond125 = ____switch125 == ActiveSlot.SLOT_PRIMARY
593
+ if ____cond125 then
579
594
  do
580
595
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
581
596
  player:RemoveCollectible(primaryCollectibleType)
@@ -584,8 +599,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
584
599
  break
585
600
  end
586
601
  end
587
- ____cond122 = ____cond122 or ____switch122 == ActiveSlot.SLOT_SECONDARY
588
- if ____cond122 then
602
+ ____cond125 = ____cond125 or ____switch125 == ActiveSlot.SLOT_SECONDARY
603
+ if ____cond125 then
589
604
  do
590
605
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
591
606
  player:RemoveCollectible(primaryCollectibleType)
@@ -600,16 +615,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
600
615
  break
601
616
  end
602
617
  end
603
- ____cond122 = ____cond122 or ____switch122 == ActiveSlot.SLOT_POCKET
604
- if ____cond122 then
618
+ ____cond125 = ____cond125 or ____switch125 == ActiveSlot.SLOT_POCKET
619
+ if ____cond125 then
605
620
  do
606
621
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
607
622
  player:SetActiveCharge(charge, activeSlot)
608
623
  break
609
624
  end
610
625
  end
611
- ____cond122 = ____cond122 or ____switch122 == ActiveSlot.SLOT_POCKET2
612
- if ____cond122 then
626
+ ____cond125 = ____cond125 or ____switch125 == ActiveSlot.SLOT_POCKET2
627
+ if ____cond125 then
613
628
  do
614
629
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
615
630
  break
@@ -92,7 +92,7 @@ end
92
92
  function ____exports.inDeathCertificateArea(self)
93
93
  local roomStageID = ____exports.getRoomStageID(nil)
94
94
  local roomSubType = ____exports.getRoomSubType(nil)
95
- return roomStageID == 35 and (roomSubType == 33 or roomSubType == 34)
95
+ return roomStageID == 35 and (roomSubType == 33 or roomSubType == 33)
96
96
  end
97
97
  function ____exports.changeRoom(self, roomGridIndex)
98
98
  local game = Game()
@@ -214,7 +214,7 @@ function ____exports.inCrawlspace(self)
214
214
  local room = game:GetRoom()
215
215
  local roomType = room:GetType()
216
216
  local roomSubType = ____exports.getRoomSubType(nil)
217
- return roomType == RoomType.ROOM_DUNGEON and roomSubType ~= 4
217
+ return roomType == RoomType.ROOM_DUNGEON and roomSubType == 0
218
218
  end
219
219
  function ____exports.inDevilsCrownTreasureRoom(self)
220
220
  local roomDescriptor = ____exports.getCurrentRoomDescriptorReadOnly(nil)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.93",
3
+ "version": "1.2.96",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,10 +25,10 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "@zamiell/typescript-to-lua": "^1.4.0",
29
- "isaac-typescript-definitions": "^1.0.355",
30
- "isaacscript-lint": "^1.0.83",
31
- "isaacscript-tsconfig": "^1.1.8",
28
+ "@zamiell/typescript-to-lua": "1.4.0",
29
+ "isaac-typescript-definitions": "1.0.354",
30
+ "isaacscript-lint": "1.0.81",
31
+ "isaacscript-tsconfig": "1.1.8",
32
32
  "typedoc": "^0.22.12",
33
33
  "typescript": "4.5.5"
34
34
  }