isaacscript-common 2.3.2 → 3.1.1

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.
Files changed (337) hide show
  1. package/cachedClasses.d.ts +6 -4
  2. package/cachedClasses.lua +24 -0
  3. package/callbacks/customRevive.lua +2 -0
  4. package/callbacks/itemPickup.lua +2 -0
  5. package/callbacks/postBombInitLate.lua +2 -0
  6. package/callbacks/postBoneSwing.lua +2 -0
  7. package/callbacks/postCollectibleInitFirst.lua +2 -0
  8. package/callbacks/postCursedTeleport.lua +2 -0
  9. package/callbacks/postCustomDoorEnter.lua +44 -0
  10. package/callbacks/postDoorRender.lua +2 -0
  11. package/callbacks/postDoorUpdate.lua +2 -0
  12. package/callbacks/postEffectInitLate.lua +2 -0
  13. package/callbacks/postEffectStateChanged.lua +2 -0
  14. package/callbacks/postEsauJr.lua +2 -0
  15. package/callbacks/postFamiliarInitLate.lua +2 -0
  16. package/callbacks/postFamiliarStateChanged.lua +2 -0
  17. package/callbacks/postFlip.lua +2 -0
  18. package/callbacks/postGreedModeWave.lua +2 -0
  19. package/callbacks/postGridEntity.lua +2 -0
  20. package/callbacks/postGridEntityCollision.lua +2 -0
  21. package/callbacks/postGridEntityRender.lua +2 -0
  22. package/callbacks/postHolyMantleRemoved.lua +2 -0
  23. package/callbacks/postKnifeInitLate.lua +2 -0
  24. package/callbacks/postLaserInitLate.lua +2 -0
  25. package/callbacks/postNPCInitLate.lua +2 -0
  26. package/callbacks/postNPCStateChanged.lua +2 -0
  27. package/callbacks/postNewRoomEarly.lua +2 -0
  28. package/callbacks/postPickupCollect.lua +2 -0
  29. package/callbacks/postPickupInitFirst.d.ts +1 -0
  30. package/callbacks/postPickupInitFirst.lua +55 -0
  31. package/callbacks/postPickupInitLate.lua +2 -0
  32. package/callbacks/postPickupStateChanged.lua +2 -0
  33. package/callbacks/postPitRender.lua +2 -0
  34. package/callbacks/postPitUpdate.lua +2 -0
  35. package/callbacks/postPlayerChangeHealth.lua +2 -0
  36. package/callbacks/postPlayerChangeType.lua +2 -0
  37. package/callbacks/postPlayerFatalDamage.lua +2 -0
  38. package/callbacks/postPlayerInitLate.lua +2 -0
  39. package/callbacks/postPlayerReordered.lua +2 -0
  40. package/callbacks/postPoopRender.lua +2 -0
  41. package/callbacks/postPoopUpdate.lua +2 -0
  42. package/callbacks/postPressurePlateRender.lua +2 -0
  43. package/callbacks/postPressurePlateUpdate.lua +2 -0
  44. package/callbacks/postProjectileInitLate.lua +2 -0
  45. package/callbacks/postPurchase.lua +2 -0
  46. package/callbacks/postRockRender.lua +2 -0
  47. package/callbacks/postRockUpdate.lua +2 -0
  48. package/callbacks/postRoomClearChanged.lua +2 -0
  49. package/callbacks/postSacrifice.lua +2 -0
  50. package/callbacks/postSlotDestroyed.d.ts +1 -0
  51. package/callbacks/postSlotDestroyed.lua +66 -0
  52. package/callbacks/postSlotInitUpdate.lua +2 -0
  53. package/callbacks/postSlotRender.lua +5 -21
  54. package/callbacks/postSpikesRender.lua +2 -0
  55. package/callbacks/postSpikesUpdate.lua +2 -0
  56. package/callbacks/postTNTRender.lua +2 -0
  57. package/callbacks/postTNTUpdate.lua +2 -0
  58. package/callbacks/postTearInitLate.lua +2 -0
  59. package/callbacks/postTearInitVeryLate.lua +2 -0
  60. package/callbacks/postTransformation.lua +2 -0
  61. package/callbacks/postTrinketBreak.lua +2 -0
  62. package/callbacks/preBerserkDeath.lua +2 -0
  63. package/callbacks/preNewLevel.lua +2 -0
  64. package/callbacks/reorderedCallbacks.lua +16 -0
  65. package/callbacks/subscriptions/postBombInitLate.lua +6 -0
  66. package/callbacks/subscriptions/postBoneSwing.lua +6 -0
  67. package/callbacks/subscriptions/postCollectibleInitFirst.lua +6 -0
  68. package/callbacks/subscriptions/postCursedTeleport.lua +6 -0
  69. package/callbacks/subscriptions/postCustomDoorEnter.lua +6 -0
  70. package/callbacks/subscriptions/postCustomRevive.d.ts +1 -0
  71. package/callbacks/subscriptions/postCustomRevive.lua +6 -0
  72. package/callbacks/subscriptions/postDoorRender.d.ts +1 -0
  73. package/callbacks/subscriptions/postDoorRender.lua +6 -0
  74. package/callbacks/subscriptions/postDoorUpdate.d.ts +1 -0
  75. package/callbacks/subscriptions/postDoorUpdate.lua +6 -0
  76. package/callbacks/subscriptions/postEffectInitLate.lua +6 -0
  77. package/callbacks/subscriptions/postEffectStateChanged.lua +6 -0
  78. package/callbacks/subscriptions/postEsauJr.lua +6 -0
  79. package/callbacks/subscriptions/postFamiliarInitLate.lua +6 -0
  80. package/callbacks/subscriptions/postFamiliarStateChanged.lua +6 -0
  81. package/callbacks/subscriptions/postFirstEsauJr.lua +6 -0
  82. package/callbacks/subscriptions/postFirstFlip.lua +6 -0
  83. package/callbacks/subscriptions/postFlip.lua +6 -0
  84. package/callbacks/subscriptions/postGameStartedReordered.lua +6 -0
  85. package/callbacks/subscriptions/postGreedModeWave.lua +6 -0
  86. package/callbacks/subscriptions/postGridEntityBroken.lua +6 -0
  87. package/callbacks/subscriptions/postGridEntityCollision.lua +6 -0
  88. package/callbacks/subscriptions/postGridEntityInit.lua +6 -0
  89. package/callbacks/subscriptions/postGridEntityRemove.lua +6 -0
  90. package/callbacks/subscriptions/postGridEntityRender.lua +6 -0
  91. package/callbacks/subscriptions/postGridEntityStateChanged.lua +6 -0
  92. package/callbacks/subscriptions/postGridEntityUpdate.lua +6 -0
  93. package/callbacks/subscriptions/postHolyMantleRemoved.lua +6 -0
  94. package/callbacks/subscriptions/postItemDischarged.lua +6 -0
  95. package/callbacks/subscriptions/postItemPickup.lua +6 -0
  96. package/callbacks/subscriptions/postKnifeInitLate.lua +6 -0
  97. package/callbacks/subscriptions/postLaserInitLate.lua +6 -0
  98. package/callbacks/subscriptions/postNPCInitLate.lua +6 -0
  99. package/callbacks/subscriptions/postNPCStateChanged.lua +6 -0
  100. package/callbacks/subscriptions/postNewLevelReordered.lua +6 -0
  101. package/callbacks/subscriptions/postNewRoomEarly.lua +6 -0
  102. package/callbacks/subscriptions/postNewRoomReordered.lua +6 -0
  103. package/callbacks/subscriptions/postPEffectUpdateReordered.lua +6 -0
  104. package/callbacks/subscriptions/postPickupCollect.d.ts +1 -0
  105. package/callbacks/subscriptions/postPickupCollect.lua +6 -0
  106. package/callbacks/subscriptions/postPickupInitFirst.d.ts +3 -0
  107. package/callbacks/subscriptions/postPickupInitFirst.lua +29 -0
  108. package/callbacks/subscriptions/postPickupInitLate.lua +6 -0
  109. package/callbacks/subscriptions/postPickupStateChanged.d.ts +1 -0
  110. package/callbacks/subscriptions/postPickupStateChanged.lua +6 -0
  111. package/callbacks/subscriptions/postPitRender.d.ts +1 -0
  112. package/callbacks/subscriptions/postPitRender.lua +6 -0
  113. package/callbacks/subscriptions/postPitUpdate.d.ts +1 -0
  114. package/callbacks/subscriptions/postPitUpdate.lua +6 -0
  115. package/callbacks/subscriptions/postPlayerChangeHealth.lua +6 -0
  116. package/callbacks/subscriptions/postPlayerChangeType.lua +6 -0
  117. package/callbacks/subscriptions/postPlayerFatalDamage.lua +6 -0
  118. package/callbacks/subscriptions/postPlayerInitLate.lua +6 -0
  119. package/callbacks/subscriptions/postPlayerInitReordered.lua +6 -0
  120. package/callbacks/subscriptions/postPlayerRenderReordered.lua +6 -0
  121. package/callbacks/subscriptions/postPlayerUpdateReordered.lua +6 -0
  122. package/callbacks/subscriptions/postPoopRender.d.ts +1 -0
  123. package/callbacks/subscriptions/postPoopRender.lua +6 -0
  124. package/callbacks/subscriptions/postPoopUpdate.d.ts +1 -0
  125. package/callbacks/subscriptions/postPoopUpdate.lua +6 -0
  126. package/callbacks/subscriptions/postPressurePlateRender.d.ts +1 -0
  127. package/callbacks/subscriptions/postPressurePlateRender.lua +6 -0
  128. package/callbacks/subscriptions/postPressurePlateUpdate.d.ts +1 -0
  129. package/callbacks/subscriptions/postPressurePlateUpdate.lua +6 -0
  130. package/callbacks/subscriptions/postProjectileInitLate.lua +6 -0
  131. package/callbacks/subscriptions/postPurchase.lua +6 -0
  132. package/callbacks/subscriptions/postRockRender.d.ts +1 -0
  133. package/callbacks/subscriptions/postRockRender.lua +6 -0
  134. package/callbacks/subscriptions/postRockUpdate.d.ts +1 -0
  135. package/callbacks/subscriptions/postRockUpdate.lua +6 -0
  136. package/callbacks/subscriptions/postRoomClearChanged.lua +6 -0
  137. package/callbacks/subscriptions/postSacrifice.lua +6 -0
  138. package/callbacks/subscriptions/postSlotAnimationChanged.lua +6 -0
  139. package/callbacks/subscriptions/postSlotDestroyed.lua +6 -0
  140. package/callbacks/subscriptions/postSlotInit.lua +6 -0
  141. package/callbacks/subscriptions/postSlotRender.lua +6 -0
  142. package/callbacks/subscriptions/postSlotUpdate.lua +6 -0
  143. package/callbacks/subscriptions/postSpikesRender.d.ts +1 -0
  144. package/callbacks/subscriptions/postSpikesRender.lua +6 -0
  145. package/callbacks/subscriptions/postSpikesUpdate.d.ts +1 -0
  146. package/callbacks/subscriptions/postSpikesUpdate.lua +6 -0
  147. package/callbacks/subscriptions/postTNTRender.d.ts +1 -0
  148. package/callbacks/subscriptions/postTNTRender.lua +6 -0
  149. package/callbacks/subscriptions/postTNTUpdate.d.ts +1 -0
  150. package/callbacks/subscriptions/postTNTUpdate.lua +6 -0
  151. package/callbacks/subscriptions/postTearInitLate.lua +6 -0
  152. package/callbacks/subscriptions/postTearInitVeryLate.lua +6 -0
  153. package/callbacks/subscriptions/postTransformation.lua +6 -0
  154. package/callbacks/subscriptions/postTrinketBreak.lua +6 -0
  155. package/callbacks/subscriptions/preBerserkDeath.lua +6 -0
  156. package/callbacks/subscriptions/preCustomRevive.lua +6 -0
  157. package/callbacks/subscriptions/preItemPickup.lua +6 -0
  158. package/callbacks/subscriptions/preNewLevel.lua +6 -0
  159. package/classes/DefaultMap.d.ts +70 -39
  160. package/classes/DefaultMap.lua +94 -43
  161. package/classes/ModUpgraded.d.ts +3 -3
  162. package/classes/ModUpgraded.lua +5 -0
  163. package/constants.lua +41 -0
  164. package/constantsFirstLast.lua +63 -0
  165. package/enums/HealthType.lua +3 -0
  166. package/enums/ModCallbackCustom.d.ts +62 -40
  167. package/enums/ModCallbackCustom.lua +46 -38
  168. package/enums/private/CopyableIsaacAPIClassType.lua +1 -0
  169. package/enums/private/SerializationBrand.lua +5 -0
  170. package/features/characterHealthConversion.lua +6 -0
  171. package/features/characterStats.lua +17 -0
  172. package/features/debugDisplay/exports.d.ts +17 -0
  173. package/features/debugDisplay/exports.lua +90 -0
  174. package/features/debugDisplay/v.d.ts +17 -0
  175. package/features/deployJSONRoom.d.ts +1 -0
  176. package/features/deployJSONRoom.lua +56 -0
  177. package/features/disableInputs.lua +45 -0
  178. package/features/disableSound.lua +14 -0
  179. package/features/extraConsoleCommands/commandsDisplay.lua +90 -0
  180. package/features/extraConsoleCommands/init.lua +16 -0
  181. package/features/extraConsoleCommands/listCommands.lua +172 -0
  182. package/features/fadeInRemover.lua +10 -0
  183. package/features/fastReset.lua +10 -0
  184. package/features/forgottenSwitch.lua +4 -0
  185. package/features/getCollectibleItemPoolType.lua +5 -0
  186. package/features/playerInventory.lua +18 -0
  187. package/features/ponyDetection.lua +4 -0
  188. package/features/preventCollectibleRotation.lua +9 -0
  189. package/features/runInNFrames.lua +50 -0
  190. package/features/saveDataManager/constants.lua +1 -0
  191. package/features/saveDataManager/exports.lua +115 -0
  192. package/features/saveDataManager/load.lua +12 -8
  193. package/features/saveDataManager/main.lua +16 -3
  194. package/features/saveDataManager/maps.lua +3 -0
  195. package/features/saveDataManager/merge.lua +53 -21
  196. package/features/saveDataManager/save.lua +12 -7
  197. package/features/sirenHelpers.lua +13 -0
  198. package/features/taintedLazarusPlayers.lua +11 -0
  199. package/featuresInitialized.lua +6 -0
  200. package/functions/array.d.ts +2 -0
  201. package/functions/array.lua +85 -0
  202. package/functions/benchmark.lua +6 -0
  203. package/functions/bombs.d.ts +3 -0
  204. package/functions/bombs.lua +12 -0
  205. package/functions/boss.lua +35 -0
  206. package/functions/cacheFlag.lua +4 -0
  207. package/functions/cards.lua +60 -0
  208. package/functions/challenges.lua +1 -0
  209. package/functions/character.lua +23 -0
  210. package/functions/charge.lua +39 -0
  211. package/functions/chargeBar.d.ts +1 -0
  212. package/functions/chargeBar.lua +4 -0
  213. package/functions/collectibleCacheFlag.lua +15 -0
  214. package/functions/collectibleSet.lua +3 -0
  215. package/functions/collectibleTag.lua +9 -0
  216. package/functions/collectibles.d.ts +13 -8
  217. package/functions/collectibles.lua +147 -3
  218. package/functions/color.lua +18 -0
  219. package/functions/debug.lua +18 -0
  220. package/functions/deepCopy.lua +60 -26
  221. package/functions/deepCopyTests.lua +8 -5
  222. package/functions/direction.d.ts +8 -0
  223. package/functions/direction.lua +27 -0
  224. package/functions/doors.d.ts +1 -0
  225. package/functions/doors.lua +58 -0
  226. package/functions/entity.d.ts +4 -4
  227. package/functions/entity.lua +94 -6
  228. package/functions/entitySpecific.d.ts +20 -20
  229. package/functions/entitySpecific.lua +182 -0
  230. package/functions/entityTypes.d.ts +1 -1
  231. package/functions/entityTypes.lua +1 -0
  232. package/functions/enums.d.ts +2 -0
  233. package/functions/enums.lua +62 -0
  234. package/functions/familiars.lua +52 -0
  235. package/functions/flag.lua +77 -0
  236. package/functions/flying.lua +10 -0
  237. package/functions/globals.lua +8 -10
  238. package/functions/gridEntity.lua +105 -0
  239. package/functions/gridEntitySpecific.d.ts +5 -0
  240. package/functions/gridEntitySpecific.lua +8 -0
  241. package/functions/input.lua +11 -0
  242. package/functions/isaacAPIClass.d.ts +4 -4
  243. package/functions/isaacAPIClass.lua +15 -3
  244. package/functions/jsonHelpers.lua +11 -0
  245. package/functions/jsonRoom.d.ts +2 -0
  246. package/functions/jsonRoom.lua +5 -0
  247. package/functions/kColor.lua +9 -0
  248. package/functions/language.lua +5 -0
  249. package/functions/log.lua +31 -3
  250. package/functions/map.lua +18 -0
  251. package/functions/math.lua +26 -0
  252. package/functions/npc.lua +24 -0
  253. package/functions/pickupVariants.d.ts +11 -11
  254. package/functions/pickupVariants.lua +11 -0
  255. package/functions/pickups.d.ts +9 -9
  256. package/functions/pickups.lua +67 -0
  257. package/functions/pills.lua +45 -0
  258. package/functions/player.d.ts +7 -0
  259. package/functions/player.lua +210 -9
  260. package/functions/playerDataStructures.lua +65 -0
  261. package/functions/playerHealth.d.ts +3 -0
  262. package/functions/playerHealth.lua +92 -63
  263. package/functions/playerIndex.d.ts +2 -0
  264. package/functions/playerIndex.lua +47 -0
  265. package/functions/pocketItems.lua +18 -0
  266. package/functions/positionVelocity.d.ts +3 -0
  267. package/functions/positionVelocity.lua +46 -0
  268. package/functions/random.d.ts +2 -0
  269. package/functions/random.lua +32 -0
  270. package/functions/revive.d.ts +2 -0
  271. package/functions/revive.lua +15 -0
  272. package/functions/rng.d.ts +1 -0
  273. package/functions/rng.lua +19 -0
  274. package/functions/roomData.lua +68 -0
  275. package/functions/roomGrid.lua +21 -0
  276. package/functions/roomShape.lua +22 -0
  277. package/functions/rooms.lua +100 -0
  278. package/functions/run.lua +5 -0
  279. package/functions/seeds.lua +4 -0
  280. package/functions/serialization.lua +6 -2
  281. package/functions/set.d.ts +1 -0
  282. package/functions/set.lua +22 -0
  283. package/functions/spawnCollectible.lua +24 -0
  284. package/functions/sprite.d.ts +2 -0
  285. package/functions/sprite.lua +25 -0
  286. package/functions/stage.lua +16 -0
  287. package/functions/string.lua +6 -0
  288. package/functions/table.d.ts +12 -0
  289. package/functions/table.lua +53 -0
  290. package/functions/tears.d.ts +1 -0
  291. package/functions/tears.lua +12 -0
  292. package/functions/transformations.lua +18 -0
  293. package/functions/trinketCacheFlag.lua +3 -0
  294. package/functions/trinketGive.lua +24 -0
  295. package/functions/trinkets.lua +52 -0
  296. package/functions/tstlClass.d.ts +34 -0
  297. package/functions/tstlClass.lua +63 -9
  298. package/functions/ui.d.ts +2 -0
  299. package/functions/ui.lua +16 -0
  300. package/functions/utils.d.ts +16 -0
  301. package/functions/utils.lua +108 -0
  302. package/functions/vector.lua +13 -16
  303. package/index.d.ts +1 -0
  304. package/index.lua +8 -0
  305. package/initCustomCallbacks.lua +6 -0
  306. package/interfaces/AddCallbackParameterCustom.d.ts +2 -0
  307. package/interfaces/ChargeBarSprites.d.ts +1 -0
  308. package/interfaces/private/TSTLClassMetatable.d.ts +2 -0
  309. package/lualib_bundle.lua +21 -34
  310. package/maps/cardMap.lua +1 -0
  311. package/maps/characterMap.lua +1 -0
  312. package/maps/defaultPlayerStatMap.lua +1 -0
  313. package/maps/gridEntityXMLMap.lua +2 -0
  314. package/maps/pillEffectMap.lua +1 -0
  315. package/maps/roomShapeToTopLeftWallGridIndexMap.lua +2 -0
  316. package/maps/roomTypeMap.lua +1 -0
  317. package/objects/LRoomShapeToRectangles.lua +2 -0
  318. package/objects/callbackRegisterFunctions.lua +3 -0
  319. package/objects/colors.lua +4 -0
  320. package/objects/oppositeDoorSlots.d.ts +4 -0
  321. package/objects/oppositeDoorSlots.lua +15 -0
  322. package/objects/roomShapeBounds.lua +2 -0
  323. package/objects/roomShapeLayoutSizes.lua +4 -0
  324. package/objects/roomShapeToBottomRightPosition.lua +2 -0
  325. package/objects/roomShapeToDoorSlotsToGridIndexDelta.lua +2 -0
  326. package/objects/roomShapeToTopLeftPosition.lua +2 -0
  327. package/objects/roomShapeVolumes.lua +3 -0
  328. package/package.json +2 -2
  329. package/patchErrorFunctions.lua +8 -0
  330. package/sets/bossSets.lua +23 -0
  331. package/sets/charactersWithNoRedHeartsSet.lua +2 -0
  332. package/sets/charactersWithNoSoulHeartsSet.lua +2 -0
  333. package/sets/lostStyleCharactersSet.lua +2 -0
  334. package/types/AnyEntity.d.ts +10 -0
  335. package/types/PickingUpItem.lua +7 -0
  336. package/upgradeMod.d.ts +4 -4
  337. package/upgradeMod.lua +18 -0
@@ -1,4 +1,5 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
2
3
  local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
3
4
  local ____exports = {}
4
5
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
@@ -16,6 +17,79 @@ local isCharacter = ____player.isCharacter
16
17
  local ____utils = require("functions.utils")
17
18
  local ensureAllCases = ____utils.ensureAllCases
18
19
  local ____repeat = ____utils["repeat"]
20
+ function ____exports.removeAllPlayerHealth(self, player)
21
+ local goldenHearts = player:GetGoldenHearts()
22
+ local eternalHearts = player:GetEternalHearts()
23
+ local boneHearts = player:GetBoneHearts()
24
+ local brokenHearts = player:GetBrokenHearts()
25
+ player:AddGoldenHearts(goldenHearts * -1)
26
+ player:AddEternalHearts(eternalHearts * -1)
27
+ player:AddBoneHearts(boneHearts * -1)
28
+ player:AddBrokenHearts(brokenHearts * -1)
29
+ player:AddMaxHearts(MAX_PLAYER_HEART_CONTAINERS * -2, true)
30
+ player:AddSoulHearts(MAX_PLAYER_HEART_CONTAINERS * -2)
31
+ if isCharacter(nil, player, PlayerType.THE_SOUL) then
32
+ local forgotten = player:GetSubPlayer()
33
+ if forgotten ~= nil then
34
+ local forgottenBoneHearts = forgotten:GetBoneHearts()
35
+ forgotten:AddBoneHearts(forgottenBoneHearts * -1)
36
+ end
37
+ end
38
+ end
39
+ --- Helper function to set a player's health to a specific state. You can use this in combination
40
+ -- with the `getPlayerHealth` function to restore the player's health back to a certain
41
+ -- configuration at a later time.
42
+ --
43
+ -- Based on the `REVEL.LoadHealth` function in the Revelations mod.
44
+ function ____exports.setPlayerHealth(self, player, playerHealth)
45
+ local character = player:GetPlayerType()
46
+ local subPlayer = player:GetSubPlayer()
47
+ ____exports.removeAllPlayerHealth(nil, player)
48
+ if character == PlayerType.THE_SOUL and subPlayer ~= nil then
49
+ subPlayer:AddMaxHearts(playerHealth.maxHearts, false)
50
+ else
51
+ player:AddMaxHearts(playerHealth.maxHearts, false)
52
+ end
53
+ player:AddEternalHearts(playerHealth.eternalHearts)
54
+ local soulHeartsRemaining = playerHealth.soulHearts
55
+ __TS__ArrayForEach(
56
+ playerHealth.soulHeartTypes,
57
+ function(____, heartType, i)
58
+ local isHalf = playerHealth.soulHearts + playerHealth.boneHearts * 2 < (i + 1) * 2
59
+ local addAmount = 2
60
+ if isHalf or heartType == HeartSubType.BONE or soulHeartsRemaining < 2 then
61
+ addAmount = 1
62
+ end
63
+ if heartType == HeartSubType.SOUL then
64
+ player:AddSoulHearts(addAmount)
65
+ soulHeartsRemaining = soulHeartsRemaining - addAmount
66
+ elseif heartType == HeartSubType.BLACK then
67
+ player:AddBlackHearts(addAmount)
68
+ soulHeartsRemaining = soulHeartsRemaining - addAmount
69
+ elseif heartType == HeartSubType.BONE then
70
+ player:AddBoneHearts(addAmount)
71
+ end
72
+ end
73
+ )
74
+ player:AddRottenHearts(playerHealth.rottenHearts)
75
+ ____repeat(
76
+ nil,
77
+ playerHealth.hearts,
78
+ function()
79
+ player:AddHearts(1)
80
+ if character == PlayerType.MAGDALENE_B then
81
+ player:AddHearts(-1)
82
+ end
83
+ end
84
+ )
85
+ player:AddGoldenHearts(playerHealth.goldenHearts)
86
+ player:AddBrokenHearts(playerHealth.brokenHearts)
87
+ if character == PlayerType.BETHANY then
88
+ player:SetSoulCharge(playerHealth.soulCharges)
89
+ elseif character == PlayerType.BETHANY_B then
90
+ player:SetBloodCharge(playerHealth.bloodCharges)
91
+ end
92
+ end
19
93
  function ____exports.addPlayerHealthType(self, player, healthType, numHearts)
20
94
  repeat
21
95
  local ____switch3 = healthType
@@ -89,6 +163,11 @@ function ____exports.addPlayerHealthType(self, player, healthType, numHearts)
89
163
  end
90
164
  until true
91
165
  end
166
+ --- Helper function to get an object representing the player's health. You can use this in
167
+ -- combination with the `setPlayerHealth` function to restore the player's health back to a certain
168
+ -- configuration at a later time.
169
+ --
170
+ -- This is based on the `REVEL.StoreHealth` function in the Revelations mod.
92
171
  function ____exports.getPlayerHealth(self, player)
93
172
  local character = player:GetPlayerType()
94
173
  local soulHeartTypes = {}
@@ -215,72 +294,22 @@ function ____exports.getPlayerHealthType(self, player, healthType)
215
294
  end
216
295
  until true
217
296
  end
218
- function ____exports.removeAllPlayerHealth(self, player)
219
- local goldenHearts = player:GetGoldenHearts()
220
- local eternalHearts = player:GetEternalHearts()
221
- local boneHearts = player:GetBoneHearts()
222
- local brokenHearts = player:GetBrokenHearts()
223
- player:AddGoldenHearts(goldenHearts * -1)
224
- player:AddEternalHearts(eternalHearts * -1)
225
- player:AddBoneHearts(boneHearts * -1)
226
- player:AddBrokenHearts(brokenHearts * -1)
227
- player:AddMaxHearts(MAX_PLAYER_HEART_CONTAINERS * -2, true)
228
- player:AddSoulHearts(MAX_PLAYER_HEART_CONTAINERS * -2)
229
- if isCharacter(nil, player, PlayerType.THE_SOUL) then
230
- local forgotten = player:GetSubPlayer()
231
- if forgotten ~= nil then
232
- local forgottenBoneHearts = forgotten:GetBoneHearts()
233
- forgotten:AddBoneHearts(forgottenBoneHearts * -1)
234
- end
235
- end
236
- end
237
- function ____exports.setPlayerHealth(self, player, playerHealth)
238
- local character = player:GetPlayerType()
239
- local subPlayer = player:GetSubPlayer()
297
+ function ____exports.playerConvertBlackHeartsToSoulHearts(self, player)
298
+ local playerHealth = ____exports.getPlayerHealth(nil, player)
240
299
  ____exports.removeAllPlayerHealth(nil, player)
241
- if character == PlayerType.THE_SOUL and subPlayer ~= nil then
242
- subPlayer:AddMaxHearts(playerHealth.maxHearts, false)
243
- else
244
- player:AddMaxHearts(playerHealth.maxHearts, false)
245
- end
246
- player:AddEternalHearts(playerHealth.eternalHearts)
247
- local soulHeartsRemaining = playerHealth.soulHearts
248
- __TS__ArrayForEach(
300
+ playerHealth.soulHeartTypes = __TS__ArrayMap(
249
301
  playerHealth.soulHeartTypes,
250
- function(____, heartType, i)
251
- local isHalf = playerHealth.soulHearts + playerHealth.boneHearts * 2 < (i + 1) * 2
252
- local addAmount = 2
253
- if isHalf or heartType == HeartSubType.BONE or soulHeartsRemaining < 2 then
254
- addAmount = 1
255
- end
256
- if heartType == HeartSubType.SOUL then
257
- player:AddSoulHearts(addAmount)
258
- soulHeartsRemaining = soulHeartsRemaining - addAmount
259
- elseif heartType == HeartSubType.BLACK then
260
- player:AddBlackHearts(addAmount)
261
- soulHeartsRemaining = soulHeartsRemaining - addAmount
262
- elseif heartType == HeartSubType.BONE then
263
- player:AddBoneHearts(addAmount)
264
- end
265
- end
302
+ function(____, soulHeartType) return soulHeartType == HeartSubType.BLACK and HeartSubType.SOUL or soulHeartType end
266
303
  )
267
- player:AddRottenHearts(playerHealth.rottenHearts)
268
- ____repeat(
269
- nil,
270
- playerHealth.hearts,
271
- function()
272
- player:AddHearts(1)
273
- if character == PlayerType.MAGDALENE_B then
274
- player:AddHearts(-1)
275
- end
276
- end
304
+ ____exports.setPlayerHealth(nil, player, playerHealth)
305
+ end
306
+ function ____exports.playerConvertSoulHeartsToBlackHearts(self, player)
307
+ local playerHealth = ____exports.getPlayerHealth(nil, player)
308
+ ____exports.removeAllPlayerHealth(nil, player)
309
+ playerHealth.soulHeartTypes = __TS__ArrayMap(
310
+ playerHealth.soulHeartTypes,
311
+ function(____, soulHeartType) return soulHeartType == HeartSubType.SOUL and HeartSubType.BLACK or soulHeartType end
277
312
  )
278
- player:AddGoldenHearts(playerHealth.goldenHearts)
279
- player:AddBrokenHearts(playerHealth.brokenHearts)
280
- if character == PlayerType.BETHANY then
281
- player:SetSoulCharge(playerHealth.soulCharges)
282
- elseif character == PlayerType.BETHANY_B then
283
- player:SetBloodCharge(playerHealth.bloodCharges)
284
- end
313
+ ____exports.setPlayerHealth(nil, player, playerHealth)
285
314
  end
286
315
  return ____exports
@@ -1,4 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
3
+ /// <reference types="isaac-typescript-definitions" />
2
4
  import { PlayerIndex } from "../types/PlayerIndex";
3
5
  /**
4
6
  * Helper function to get every player with no restrictions, by using `Game.GetNumPlayers` and
@@ -10,6 +10,11 @@ local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
10
10
  local PlayerType = ____isaac_2Dtypescript_2Ddefinitions.PlayerType
11
11
  local ____cachedClasses = require("cachedClasses")
12
12
  local game = ____cachedClasses.game
13
+ --- Helper function to get every player with no restrictions, by using `Game.GetNumPlayers` and
14
+ -- `Isaac.GetPlayer`.
15
+ --
16
+ -- This function is almost never what you want to use. For most purposes, use the `getPlayers`
17
+ -- helper function instead to get a filtered list of players.
13
18
  function ____exports.getAllPlayers(self)
14
19
  local numPlayers = game:GetNumPlayers()
15
20
  local players = {}
@@ -23,6 +28,33 @@ function ____exports.getAllPlayers(self)
23
28
  end
24
29
  return players
25
30
  end
31
+ --- Mods often have to track variables relating to the player. In naive mods, information will only
32
+ -- be stored about the first player. However, in order to be robust, mods must handle up to 4
33
+ -- players playing at the same time. This means that information must be stored on a map data
34
+ -- structure. Finding a good index for these types of map data structures is difficult:
35
+ --
36
+ -- - We cannot use the index from `Isaac.GetPlayer(i)` since this fails in the case where there are
37
+ -- two players and the first player leaves the run.
38
+ -- - We cannot use `EntityPlayer.ControllerIndex` as an index because it fails in the case of Jacob
39
+ -- & Esau or Tainted Forgotten. It also fails in the case of a player changing their controls
40
+ -- mid-run.
41
+ -- - We cannot use `EntityPlayer.GetData().index` because it does not persist across saving and
42
+ -- continuing.
43
+ -- - We cannot use `GetPtrHash()` as an index because it does not persist across exiting and
44
+ -- relaunching the game.
45
+ -- - We cannot use `EntityPlayer.InitSeed` because it is not consistent with additional players
46
+ -- beyond the first.
47
+ --
48
+ -- Instead, we use the `EntityPlayer.GetCollectibleRNG` method with an arbitrary value of Sad Onion
49
+ -- (1). This works even if the player does not have any Sad Onions.
50
+ --
51
+ -- Since the RNG value is the same for both Tainted Lazarus and Dead Tainted Lazarus, we revert to
52
+ -- using the RNG of The Inner Eye (2) for Dead Tainted Lazarus.
53
+ --
54
+ -- Note that by default, this returns the same index for both The Forgotten and The Soul. (Even
55
+ -- though they are technically different characters, they share the same inventory and InitSeed.) If
56
+ -- this is not desired, pass true for the `differentiateForgottenAndSoul` argument, and the RNG of
57
+ -- Spoon Bender (3) will be used for The Soul.
26
58
  function ____exports.getPlayerIndex(self, player, differentiateForgottenAndSoul)
27
59
  if differentiateForgottenAndSoul == nil then
28
60
  differentiateForgottenAndSoul = false
@@ -63,6 +95,14 @@ function getPlayerIndexCollectibleType(self, player, differentiateForgottenAndSo
63
95
  end
64
96
  until true
65
97
  end
98
+ --- This function always excludes players with a non-undefined parent, since they are not real
99
+ -- players (e.g. the Strawman Keeper).
100
+ --
101
+ -- If this is not desired, use the `getAllPlayers` helper function instead.
102
+ --
103
+ -- @param performCharacterExclusions Whether or not to exclude characters that are not directly
104
+ -- controlled by the player (i.e. Esau & Tainted Soul). Default is
105
+ -- false.
66
106
  function ____exports.getPlayers(self, performCharacterExclusions)
67
107
  if performCharacterExclusions == nil then
68
108
  performCharacterExclusions = false
@@ -81,6 +121,9 @@ function ____exports.getPlayers(self, performCharacterExclusions)
81
121
  )
82
122
  return performCharacterExclusions and nonChildPlayersFiltered or nonChildPlayers
83
123
  end
124
+ --- Helper function to get a parent `EntityPlayer` object for a given `EntitySubPlayer` object. This
125
+ -- is useful because calling the `EntityPlayer.GetSubPlayer` method on a sub-player object will
126
+ -- return undefined.
84
127
  function ____exports.getSubPlayerParent(self, subPlayer)
85
128
  local subPlayerPtrHash = GetPtrHash(subPlayer)
86
129
  local players = ____exports.getPlayers(nil)
@@ -96,6 +139,8 @@ function ____exports.getSubPlayerParent(self, subPlayer)
96
139
  end
97
140
  )
98
141
  end
142
+ --- Some players are "child" players, meaning that they have a non-undefined Parent property. (For
143
+ -- example, the Strawman Keeper.)
99
144
  function ____exports.isChildPlayer(self, player)
100
145
  return player.Parent ~= nil
101
146
  end
@@ -108,6 +153,8 @@ function ____exports.getPlayerFromIndex(self, playerIndex)
108
153
  function(____, player) return ____exports.getPlayerIndex(nil, player) == playerIndex end
109
154
  )
110
155
  end
156
+ --- Helper function to return the index of this player with respect to the output of the
157
+ -- `Isaac.GetPlayer` method.
111
158
  function ____exports.getPlayerIndexVanilla(self, playerToFind)
112
159
  local numPlayers = game:GetNumPlayers()
113
160
  local playerToFindHash = GetPtrHash(playerToFind)
@@ -15,6 +15,14 @@ local ____enums = require("functions.enums")
15
15
  local getEnumValues = ____enums.getEnumValues
16
16
  local ____player = require("functions.player")
17
17
  local isCharacter = ____player.isCharacter
18
+ --- Use this helper function as a workaround for the `EntityPlayer.GetPocketItem` method not working
19
+ -- correctly.
20
+ --
21
+ -- Note that due to API limitations, there is no way to determine the location of a Dice Bag trinket
22
+ -- dice. Furthermore, when the player has a Dice Bag trinket dice and a pocket active at the same
23
+ -- time, there is no way to determine the location of the pocket active item. If this function
24
+ -- cannot determine the identity of a particular slot, it will mark the type of the slot as
25
+ -- `PocketItemType.UNDETERMINABLE`.
18
26
  function ____exports.getPocketItems(self, player)
19
27
  local pocketItem = player:GetActiveItem(ActiveSlot.POCKET)
20
28
  local hasPocketItem = pocketItem ~= CollectibleType.NULL
@@ -49,6 +57,8 @@ function ____exports.getPocketItems(self, player)
49
57
  end
50
58
  return pocketItems
51
59
  end
60
+ --- Helper function to get the `PocketItemSlot` that the player's pocket active collectible item is
61
+ -- in, if any. Returns undefined if the player does not have a pocket active item.
52
62
  function ____exports.getActivePocketItemSlot(self, player)
53
63
  local pocketItems = ____exports.getPocketItems(nil, player)
54
64
  for ____, pocketItem in ipairs(pocketItems) do
@@ -65,6 +75,12 @@ function ____exports.getFirstCardOrPill(self, player)
65
75
  function(____, pocketItem) return pocketItem.type == PocketItemType.CARD or pocketItem.type == PocketItemType.PILL end
66
76
  )
67
77
  end
78
+ --- Returns whether or not the player can hold an additional pocket item, beyond what they are
79
+ -- currently carrying. This takes into account items that modify the max number of pocket items,
80
+ -- like Starter Deck.
81
+ --
82
+ -- If the player is the Tainted Soul, this always returns false, since that character cannot pick up
83
+ -- items. (Only Tainted Forgotten can pick up items.)
68
84
  function ____exports.hasOpenPocketItemSlot(self, player)
69
85
  if isCharacter(nil, player, PlayerType.THE_SOUL_B) then
70
86
  return false
@@ -75,6 +91,8 @@ function ____exports.hasOpenPocketItemSlot(self, player)
75
91
  function(____, pocketItem) return pocketItem.type == PocketItemType.EMPTY end
76
92
  )
77
93
  end
94
+ --- Helper function to determine whether or not the player's "active" pocket item slot is set to
95
+ -- their pocket active item.
78
96
  function ____exports.isFirstSlotPocketActiveItem(self, player)
79
97
  local pocketItems = ____exports.getPocketItems(nil, player)
80
98
  local firstPocketItem = pocketItems[1]
@@ -1,4 +1,7 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
3
+ /// <reference types="isaac-typescript-definitions" />
4
+ /// <reference types="isaac-typescript-definitions" />
2
5
  export declare function anyEntityCloserThan(entities: Entity[], position: Vector, distance: int): boolean;
3
6
  /** Iterates over all players and checks if any player is close enough to the specified position. */
4
7
  export declare function anyPlayerCloserThan(position: Vector, distance: float): boolean;
@@ -25,6 +25,7 @@ function ____exports.anyEntityCloserThan(self, entities, position, distance)
25
25
  function(____, entity) return position:Distance(entity.Position) <= distance end
26
26
  )
27
27
  end
28
+ --- Iterates over all players and checks if any player is close enough to the specified position.
28
29
  function ____exports.anyPlayerCloserThan(self, position, distance)
29
30
  local players = getPlayers(nil)
30
31
  return __TS__ArraySome(
@@ -32,6 +33,15 @@ function ____exports.anyPlayerCloserThan(self, position, distance)
32
33
  function(____, player) return player.Position:Distance(position) <= distance end
33
34
  )
34
35
  end
36
+ --- Helper function to get a room position that is not overlapping with a grid entity, a heaven door,
37
+ -- or a player. The `Room.FindFreePickupSpawnPosition` method will return locations that overlap
38
+ -- with heaven doors and partially overlap with players, if the thing being spawned is bigger than a
39
+ -- tile (like a Blood Donation Machine). Use this function instead if you want to account for those
40
+ -- specific situations.
41
+ --
42
+ -- @param startingPosition The position to start searching from. If this position is not overlapping
43
+ -- with anything, then it will be returned.
44
+ -- @param avoidActiveEntities Optional. Default is false.
35
45
  function ____exports.findFreePosition(self, startingPosition, avoidActiveEntities)
36
46
  if avoidActiveEntities == nil then
37
47
  avoidActiveEntities = false
@@ -59,6 +69,13 @@ function ____exports.findFreePosition(self, startingPosition, avoidActiveEntitie
59
69
  end
60
70
  return room:FindFreePickupSpawnPosition(startingPosition)
61
71
  end
72
+ --- Helper function to get a map containing the positions of every entity in the current room.
73
+ --
74
+ -- This is useful for rewinding entity positions at a later time. Also see `setEntityPositions`.
75
+ --
76
+ -- @param entities Optional. If provided, will only get the positions of the provided entities. Use
77
+ -- this with cached entities to avoid invoking the `Isaac.GetRoomEntities` method
78
+ -- multiple times.
62
79
  function ____exports.getEntityPositions(self, entities)
63
80
  if entities == nil then
64
81
  entities = getEntities(nil)
@@ -70,6 +87,13 @@ function ____exports.getEntityPositions(self, entities)
70
87
  end
71
88
  return entityPositions
72
89
  end
90
+ --- Helper function to get a map containing the velocities of every entity in the current room.
91
+ --
92
+ -- This is useful for rewinding entity velocities at a later time. Also see `setEntityVelocities`.
93
+ --
94
+ -- @param entities Optional. If provided, will only get the velocities of the provided entities. Use
95
+ -- this with cached entities to avoid invoking the `Isaac.GetRoomEntities` method
96
+ -- multiple times.
73
97
  function ____exports.getEntityVelocities(self, entities)
74
98
  if entities == nil then
75
99
  entities = getEntities(nil)
@@ -81,6 +105,17 @@ function ____exports.getEntityVelocities(self, entities)
81
105
  end
82
106
  return entityVelocities
83
107
  end
108
+ --- Helper function to set the position of every entity in the room based on a map of positions. If
109
+ -- an entity is found that does not have matching element in the provided map, then that entity will
110
+ -- be skipped.
111
+ --
112
+ -- This function is useful for rewinding entity positions at a later time. Also see
113
+ -- `getEntityPositions`.
114
+ --
115
+ -- @param entityPositions The map providing the positions for every entity.
116
+ -- @param entities Optional. If provided, will only set the positions of the provided entities. Use
117
+ -- this with cached entities to avoid invoking the `Isaac.GetRoomEntities` method
118
+ -- multiple times.
84
119
  function ____exports.setEntityPositions(self, entityPositions, entities)
85
120
  if entities == nil then
86
121
  entities = getEntities(nil)
@@ -93,6 +128,17 @@ function ____exports.setEntityPositions(self, entityPositions, entities)
93
128
  end
94
129
  end
95
130
  end
131
+ --- Helper function to set the velocity of every entity in the room based on a map of velocities. If
132
+ -- an entity is found that does not have matching element in the provided map, then that entity will
133
+ -- be skipped.
134
+ --
135
+ -- This function is useful for rewinding entity velocities at a later time. Also see
136
+ -- `getEntityVelocities`.
137
+ --
138
+ -- @param entityVelocities The map providing the velocities for every entity.
139
+ -- @param entities Optional. If provided, will only set the velocities of the provided entities. Use
140
+ -- this with cached entities to avoid invoking the `Isaac.GetRoomEntities` method
141
+ -- multiple times.
96
142
  function ____exports.setEntityVelocities(self, entityVelocities, entities)
97
143
  if entities == nil then
98
144
  entities = getEntities(nil)
@@ -1,4 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
3
+ /// <reference types="isaac-typescript-definitions" />
2
4
  /**
3
5
  * This returns a random float between 0 and 1. It is inclusive on the low end, but exclusive on the
4
6
  * high end. (This is because the `RNG.RandomFloat` method will never return a value of exactly 1.)
@@ -3,6 +3,11 @@ local ____rng = require("functions.rng")
3
3
  local getRandomSeed = ____rng.getRandomSeed
4
4
  local isRNG = ____rng.isRNG
5
5
  local newRNG = ____rng.newRNG
6
+ --- This returns a random float between 0 and 1. It is inclusive on the low end, but exclusive on the
7
+ -- high end. (This is because the `RNG.RandomFloat` method will never return a value of exactly 1.)
8
+ --
9
+ -- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
10
+ -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
6
11
  function ____exports.getRandom(self, seedOrRNG)
7
12
  if seedOrRNG == nil then
8
13
  seedOrRNG = getRandomSeed(nil)
@@ -10,6 +15,18 @@ function ____exports.getRandom(self, seedOrRNG)
10
15
  local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
11
16
  return rng:RandomFloat()
12
17
  end
18
+ --- This returns a random float between min and max.
19
+ --
20
+ -- For example:
21
+ --
22
+ -- ```ts
23
+ -- const realNumberBetweenOneAndThree = getRandomFloat(1, 3);
24
+ -- ```
25
+ --
26
+ -- @param min The lower bound for the random number (inclusive).
27
+ -- @param max The upper bound for the random number (exclusive).
28
+ -- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
29
+ -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
13
30
  function ____exports.getRandomFloat(self, min, max, seedOrRNG)
14
31
  if seedOrRNG == nil then
15
32
  seedOrRNG = getRandomSeed(nil)
@@ -22,6 +39,21 @@ function ____exports.getRandomFloat(self, min, max, seedOrRNG)
22
39
  end
23
40
  return min + ____exports.getRandom(nil, seedOrRNG) * (max - min)
24
41
  end
42
+ --- This returns a random integer between min and max. It is inclusive on both ends.
43
+ --
44
+ -- Note that this function will invoke the `Next` method on the `RNG` object before returning the
45
+ -- random number.
46
+ --
47
+ -- For example:
48
+ --
49
+ -- ```ts
50
+ -- const oneTwoOrThree = getRandomInt(1, 3);
51
+ -- ```
52
+ --
53
+ -- @param min The lower bound for the random number (inclusive).
54
+ -- @param max The upper bound for the random number (inclusive).
55
+ -- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
56
+ -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
25
57
  function ____exports.getRandomInt(self, min, max, seedOrRNG)
26
58
  if seedOrRNG == nil then
27
59
  seedOrRNG = getRandomSeed(nil)
@@ -1,4 +1,6 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
3
+ /// <reference types="isaac-typescript-definitions" />
2
4
  /**
3
5
  * Uses the player's current health and other miscellaneous things to determine if incoming damage
4
6
  * will be fatal.
@@ -22,6 +22,9 @@ local getLastFrameOfAnimation = ____sprite.getLastFrameOfAnimation
22
22
  local ____trinketGive = require("functions.trinketGive")
23
23
  local giveTrinketsBack = ____trinketGive.giveTrinketsBack
24
24
  local temporarilyRemoveTrinket = ____trinketGive.temporarilyRemoveTrinket
25
+ --- Helper function to determine if the player will be revived by the Heartbreak collectible if they
26
+ -- take fatal damage. This is contingent on the character that they are playing as and the amount of
27
+ -- broken hearts that they already have.
25
28
  function ____exports.willReviveFromHeartbreak(self, player)
26
29
  if not player:HasCollectible(CollectibleType.HEARTBREAK) then
27
30
  return false
@@ -32,6 +35,8 @@ function ____exports.willReviveFromHeartbreak(self, player)
32
35
  local numBrokenHeartsAfterRevival = numBrokenHeartsThatWillBeAdded + brokenHearts
33
36
  return maxHeartContainers > numBrokenHeartsAfterRevival
34
37
  end
38
+ --- Helper function to determine if the Spirit Shackles item is in an enabled state. (It can be
39
+ -- either enabled or disabled.)
35
40
  function ____exports.willReviveFromSpiritShackles(self, player)
36
41
  if not player:HasCollectible(CollectibleType.SPIRIT_SHACKLES) then
37
42
  return false
@@ -41,6 +46,8 @@ function ____exports.willReviveFromSpiritShackles(self, player)
41
46
  local playerInSoulForm = effects:HasNullEffect(NullItemID.SPIRIT_SHACKLES_SOUL)
42
47
  return spiritShacklesEnabled and not playerInSoulForm
43
48
  end
49
+ --- Uses the player's current health and other miscellaneous things to determine if incoming damage
50
+ -- will be fatal.
44
51
  function ____exports.isDamageToPlayerFatal(self, player, damageAmount, damageSource, lastDamageGameFrame)
45
52
  local gameFrameCount = game:GetFrameCount()
46
53
  local character = player:GetPlayerType()
@@ -84,6 +91,12 @@ function ____exports.isDamageToPlayerFatal(self, player, damageAmount, damageSou
84
91
  end
85
92
  return true
86
93
  end
94
+ --- Assuming that we are on the frame of fatal damage, this function returns whether or not
95
+ -- Mysterious Paper would rotate to Missing Poster on the frame that the "Game Over" screen would
96
+ -- appear (which would subsequently save the player from fatal damage).
97
+ --
98
+ -- Mysterious Paper rotates between the 4 items on every frame, in order. The formula for whether
99
+ -- Mysterious Paper be Missing Power is: `gameFrameCount % 4 === 3`
87
100
  function ____exports.willMysteriousPaperRevive(self, player)
88
101
  local gameFrameCount = game:GetFrameCount()
89
102
  local sprite = player:GetSprite()
@@ -93,6 +106,8 @@ function ____exports.willMysteriousPaperRevive(self, player)
93
106
  local frameOfDeath = gameFrameCount + deathAnimationFrames + 1
94
107
  return frameOfDeath % 4 == 3
95
108
  end
109
+ --- The `EntityPlayer.WillPlayerRevive` method does not properly account for Mysterious Paper, so use
110
+ -- this helper function instead for more robust revival detection.
96
111
  function ____exports.willPlayerRevive(self, player)
97
112
  local trinketSituation = temporarilyRemoveTrinket(nil, player, TrinketType.MYSTERIOUS_PAPER)
98
113
  local willRevive = player:WillPlayerRevive() or trinketSituation ~= nil and ____exports.willMysteriousPaperRevive(nil, player)
@@ -1,4 +1,5 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
2
3
  /// <reference types="typescript-to-lua/language-extensions" />
3
4
  import { SerializationType } from "../enums/SerializationType";
4
5
  declare type SerializedRNG = LuaTable<string, unknown> & {
package/functions/rng.lua CHANGED
@@ -16,14 +16,21 @@ local getNumbersFromTable = ____table.getNumbersFromTable
16
16
  local tableHasKeys = ____table.tableHasKeys
17
17
  local ____utils = require("functions.utils")
18
18
  local ensureAllCases = ____utils.ensureAllCases
19
+ --- Helper function to get a random `Seed` value to be used in spawning entities and so on. Use this
20
+ -- instead of calling the `Random` function directly since that can return a value of 0 and crash
21
+ -- the game.
19
22
  function ____exports.getRandomSeed(self)
20
23
  local randomNumber = Random()
21
24
  local safeRandomNumber = randomNumber == 0 and 1 or randomNumber
22
25
  return safeRandomNumber
23
26
  end
27
+ --- Helper function to check if something is an instantiated RNG object.
24
28
  function ____exports.isRNG(self, object)
25
29
  return isIsaacAPIClassOfType(nil, object, OBJECT_NAME)
26
30
  end
31
+ --- Helper function to initialize an RNG object using Blade's recommended shift index.
32
+ --
33
+ -- @param seed The seed to initialize it with. Default is `getRandomSeed()`.
27
34
  function ____exports.newRNG(self, seed)
28
35
  if seed == nil then
29
36
  seed = ____exports.getRandomSeed(nil)
@@ -32,6 +39,7 @@ function ____exports.newRNG(self, seed)
32
39
  ____exports.setSeed(nil, rng, seed)
33
40
  return rng
34
41
  end
42
+ --- Helper function to set a seed to an RNG object using Blade's recommended shift index.
35
43
  function ____exports.setSeed(self, rng, seed)
36
44
  if seed == 0 then
37
45
  error("You cannot set an RNG object to a seed of 0, or the game will crash.")
@@ -41,6 +49,11 @@ end
41
49
  RECOMMENDED_SHIFT_IDX = 35
42
50
  local KEYS = {"seed"}
43
51
  OBJECT_NAME = "RNG"
52
+ --- Helper function to copy an `RNG` object.
53
+ --
54
+ -- @param rng The RNG object to copy. In the case of deserialization, this will actually be a Lua
55
+ -- table instead of an instantiated RNG class.
56
+ -- @param serializationType Default is `SerializationType.NONE`.
44
57
  function ____exports.copyRNG(self, rng, serializationType)
45
58
  if serializationType == nil then
46
59
  serializationType = SerializationType.NONE
@@ -94,6 +107,8 @@ function ____exports.copyRNG(self, rng, serializationType)
94
107
  end
95
108
  until true
96
109
  end
110
+ --- Used to determine is the given table is a serialized `RNG` object created by the save data
111
+ -- manager and/or the `deepCopy` function.
97
112
  function ____exports.isSerializedRNG(self, object)
98
113
  local objectType = type(object)
99
114
  if objectType ~= "table" then
@@ -109,6 +124,8 @@ end
109
124
  function ____exports.rngEquals(self, rng1, rng2)
110
125
  return isaacAPIClassEquals(nil, rng1, rng2, KEYS)
111
126
  end
127
+ --- Helper function to iterate over the provided object and set the seed for all of the values that
128
+ -- are RNG objects equal to a particular seed.
112
129
  function ____exports.setAllRNGToSeed(self, object, seed)
113
130
  local objectType = type(object)
114
131
  if objectType ~= "table" then
@@ -121,6 +138,8 @@ function ____exports.setAllRNGToSeed(self, object, seed)
121
138
  end
122
139
  end
123
140
  end
141
+ --- Helper function to iterate over the provided object and set the seed for all of the values that
142
+ -- are RNG objects equal to the start seed for the current run.
124
143
  function ____exports.setAllRNGToStartSeed(self, object)
125
144
  local seeds = game:GetSeeds()
126
145
  local startSeed = seeds:GetStartSeed()