isaacscript-common 2.3.1 → 3.1.0

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 (327) 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/postPickupInitLate.lua +2 -0
  30. package/callbacks/postPickupStateChanged.lua +2 -0
  31. package/callbacks/postPitRender.lua +2 -0
  32. package/callbacks/postPitUpdate.lua +2 -0
  33. package/callbacks/postPlayerChangeHealth.lua +2 -0
  34. package/callbacks/postPlayerChangeType.lua +2 -0
  35. package/callbacks/postPlayerFatalDamage.lua +2 -0
  36. package/callbacks/postPlayerInitLate.lua +2 -0
  37. package/callbacks/postPlayerReordered.lua +2 -0
  38. package/callbacks/postPoopRender.lua +2 -0
  39. package/callbacks/postPoopUpdate.lua +2 -0
  40. package/callbacks/postPressurePlateRender.lua +2 -0
  41. package/callbacks/postPressurePlateUpdate.lua +2 -0
  42. package/callbacks/postProjectileInitLate.lua +2 -0
  43. package/callbacks/postPurchase.lua +2 -0
  44. package/callbacks/postRockRender.lua +2 -0
  45. package/callbacks/postRockUpdate.lua +2 -0
  46. package/callbacks/postRoomClearChanged.lua +2 -0
  47. package/callbacks/postSacrifice.lua +2 -0
  48. package/callbacks/postSlotDestroyed.d.ts +1 -0
  49. package/callbacks/postSlotDestroyed.lua +66 -0
  50. package/callbacks/postSlotInitUpdate.lua +2 -0
  51. package/callbacks/postSlotRender.lua +5 -21
  52. package/callbacks/postSpikesRender.lua +2 -0
  53. package/callbacks/postSpikesUpdate.lua +2 -0
  54. package/callbacks/postTNTRender.lua +2 -0
  55. package/callbacks/postTNTUpdate.lua +2 -0
  56. package/callbacks/postTearInitLate.lua +2 -0
  57. package/callbacks/postTearInitVeryLate.lua +2 -0
  58. package/callbacks/postTransformation.lua +2 -0
  59. package/callbacks/postTrinketBreak.lua +2 -0
  60. package/callbacks/preBerserkDeath.lua +2 -0
  61. package/callbacks/preNewLevel.lua +2 -0
  62. package/callbacks/reorderedCallbacks.lua +16 -0
  63. package/callbacks/subscriptions/postBombInitLate.lua +6 -0
  64. package/callbacks/subscriptions/postBoneSwing.lua +6 -0
  65. package/callbacks/subscriptions/postCollectibleInitFirst.lua +6 -0
  66. package/callbacks/subscriptions/postCursedTeleport.lua +6 -0
  67. package/callbacks/subscriptions/postCustomDoorEnter.lua +6 -0
  68. package/callbacks/subscriptions/postCustomRevive.d.ts +1 -0
  69. package/callbacks/subscriptions/postCustomRevive.lua +6 -0
  70. package/callbacks/subscriptions/postDoorRender.d.ts +1 -0
  71. package/callbacks/subscriptions/postDoorRender.lua +6 -0
  72. package/callbacks/subscriptions/postDoorUpdate.d.ts +1 -0
  73. package/callbacks/subscriptions/postDoorUpdate.lua +6 -0
  74. package/callbacks/subscriptions/postEffectInitLate.lua +6 -0
  75. package/callbacks/subscriptions/postEffectStateChanged.lua +6 -0
  76. package/callbacks/subscriptions/postEsauJr.lua +6 -0
  77. package/callbacks/subscriptions/postFamiliarInitLate.lua +6 -0
  78. package/callbacks/subscriptions/postFamiliarStateChanged.lua +6 -0
  79. package/callbacks/subscriptions/postFirstEsauJr.lua +6 -0
  80. package/callbacks/subscriptions/postFirstFlip.lua +6 -0
  81. package/callbacks/subscriptions/postFlip.lua +6 -0
  82. package/callbacks/subscriptions/postGameStartedReordered.lua +6 -0
  83. package/callbacks/subscriptions/postGreedModeWave.lua +6 -0
  84. package/callbacks/subscriptions/postGridEntityBroken.lua +6 -0
  85. package/callbacks/subscriptions/postGridEntityCollision.lua +6 -0
  86. package/callbacks/subscriptions/postGridEntityInit.lua +6 -0
  87. package/callbacks/subscriptions/postGridEntityRemove.lua +6 -0
  88. package/callbacks/subscriptions/postGridEntityRender.lua +6 -0
  89. package/callbacks/subscriptions/postGridEntityStateChanged.lua +6 -0
  90. package/callbacks/subscriptions/postGridEntityUpdate.lua +6 -0
  91. package/callbacks/subscriptions/postHolyMantleRemoved.lua +6 -0
  92. package/callbacks/subscriptions/postItemDischarged.lua +6 -0
  93. package/callbacks/subscriptions/postItemPickup.lua +6 -0
  94. package/callbacks/subscriptions/postKnifeInitLate.lua +6 -0
  95. package/callbacks/subscriptions/postLaserInitLate.lua +6 -0
  96. package/callbacks/subscriptions/postNPCInitLate.lua +6 -0
  97. package/callbacks/subscriptions/postNPCStateChanged.lua +6 -0
  98. package/callbacks/subscriptions/postNewLevelReordered.lua +6 -0
  99. package/callbacks/subscriptions/postNewRoomEarly.lua +6 -0
  100. package/callbacks/subscriptions/postNewRoomReordered.lua +6 -0
  101. package/callbacks/subscriptions/postPEffectUpdateReordered.lua +6 -0
  102. package/callbacks/subscriptions/postPickupCollect.d.ts +1 -0
  103. package/callbacks/subscriptions/postPickupCollect.lua +6 -0
  104. package/callbacks/subscriptions/postPickupInitLate.lua +6 -0
  105. package/callbacks/subscriptions/postPickupStateChanged.d.ts +1 -0
  106. package/callbacks/subscriptions/postPickupStateChanged.lua +6 -0
  107. package/callbacks/subscriptions/postPitRender.d.ts +1 -0
  108. package/callbacks/subscriptions/postPitRender.lua +6 -0
  109. package/callbacks/subscriptions/postPitUpdate.d.ts +1 -0
  110. package/callbacks/subscriptions/postPitUpdate.lua +6 -0
  111. package/callbacks/subscriptions/postPlayerChangeHealth.lua +6 -0
  112. package/callbacks/subscriptions/postPlayerChangeType.lua +6 -0
  113. package/callbacks/subscriptions/postPlayerFatalDamage.lua +6 -0
  114. package/callbacks/subscriptions/postPlayerInitLate.lua +6 -0
  115. package/callbacks/subscriptions/postPlayerInitReordered.lua +6 -0
  116. package/callbacks/subscriptions/postPlayerRenderReordered.lua +6 -0
  117. package/callbacks/subscriptions/postPlayerUpdateReordered.lua +6 -0
  118. package/callbacks/subscriptions/postPoopRender.d.ts +1 -0
  119. package/callbacks/subscriptions/postPoopRender.lua +6 -0
  120. package/callbacks/subscriptions/postPoopUpdate.d.ts +1 -0
  121. package/callbacks/subscriptions/postPoopUpdate.lua +6 -0
  122. package/callbacks/subscriptions/postPressurePlateRender.d.ts +1 -0
  123. package/callbacks/subscriptions/postPressurePlateRender.lua +6 -0
  124. package/callbacks/subscriptions/postPressurePlateUpdate.d.ts +1 -0
  125. package/callbacks/subscriptions/postPressurePlateUpdate.lua +6 -0
  126. package/callbacks/subscriptions/postProjectileInitLate.lua +6 -0
  127. package/callbacks/subscriptions/postPurchase.lua +6 -0
  128. package/callbacks/subscriptions/postRockRender.d.ts +1 -0
  129. package/callbacks/subscriptions/postRockRender.lua +6 -0
  130. package/callbacks/subscriptions/postRockUpdate.d.ts +1 -0
  131. package/callbacks/subscriptions/postRockUpdate.lua +6 -0
  132. package/callbacks/subscriptions/postRoomClearChanged.lua +6 -0
  133. package/callbacks/subscriptions/postSacrifice.lua +6 -0
  134. package/callbacks/subscriptions/postSlotAnimationChanged.lua +6 -0
  135. package/callbacks/subscriptions/postSlotDestroyed.lua +6 -0
  136. package/callbacks/subscriptions/postSlotInit.lua +6 -0
  137. package/callbacks/subscriptions/postSlotRender.lua +6 -0
  138. package/callbacks/subscriptions/postSlotUpdate.lua +6 -0
  139. package/callbacks/subscriptions/postSpikesRender.d.ts +1 -0
  140. package/callbacks/subscriptions/postSpikesRender.lua +6 -0
  141. package/callbacks/subscriptions/postSpikesUpdate.d.ts +1 -0
  142. package/callbacks/subscriptions/postSpikesUpdate.lua +6 -0
  143. package/callbacks/subscriptions/postTNTRender.d.ts +1 -0
  144. package/callbacks/subscriptions/postTNTRender.lua +6 -0
  145. package/callbacks/subscriptions/postTNTUpdate.d.ts +1 -0
  146. package/callbacks/subscriptions/postTNTUpdate.lua +6 -0
  147. package/callbacks/subscriptions/postTearInitLate.lua +6 -0
  148. package/callbacks/subscriptions/postTearInitVeryLate.lua +6 -0
  149. package/callbacks/subscriptions/postTransformation.lua +6 -0
  150. package/callbacks/subscriptions/postTrinketBreak.lua +6 -0
  151. package/callbacks/subscriptions/preBerserkDeath.lua +6 -0
  152. package/callbacks/subscriptions/preCustomRevive.lua +6 -0
  153. package/callbacks/subscriptions/preItemPickup.lua +6 -0
  154. package/callbacks/subscriptions/preNewLevel.lua +6 -0
  155. package/classes/DefaultMap.d.ts +70 -39
  156. package/classes/DefaultMap.lua +94 -43
  157. package/classes/ModUpgraded.d.ts +3 -3
  158. package/classes/ModUpgraded.lua +5 -0
  159. package/constants.lua +41 -0
  160. package/constantsFirstLast.lua +63 -0
  161. package/enums/HealthType.lua +3 -0
  162. package/enums/ModCallbackCustom.d.ts +1 -1
  163. package/enums/ModCallbackCustom.lua +6 -0
  164. package/enums/private/CopyableIsaacAPIClassType.lua +1 -0
  165. package/enums/private/SerializationBrand.lua +5 -0
  166. package/features/characterHealthConversion.lua +6 -0
  167. package/features/characterStats.lua +17 -0
  168. package/features/debugDisplay/exports.d.ts +17 -0
  169. package/features/debugDisplay/exports.lua +90 -0
  170. package/features/debugDisplay/v.d.ts +17 -0
  171. package/features/deployJSONRoom.d.ts +1 -0
  172. package/features/deployJSONRoom.lua +56 -0
  173. package/features/disableInputs.lua +45 -0
  174. package/features/disableSound.lua +14 -0
  175. package/features/extraConsoleCommands/commandsDisplay.lua +90 -0
  176. package/features/extraConsoleCommands/init.lua +16 -0
  177. package/features/extraConsoleCommands/listCommands.lua +172 -0
  178. package/features/fadeInRemover.lua +10 -0
  179. package/features/fastReset.lua +10 -0
  180. package/features/forgottenSwitch.lua +4 -0
  181. package/features/getCollectibleItemPoolType.lua +5 -0
  182. package/features/playerInventory.lua +18 -0
  183. package/features/ponyDetection.lua +4 -0
  184. package/features/preventCollectibleRotation.lua +9 -0
  185. package/features/runInNFrames.lua +50 -0
  186. package/features/saveDataManager/constants.lua +1 -0
  187. package/features/saveDataManager/exports.lua +115 -0
  188. package/features/saveDataManager/load.lua +12 -8
  189. package/features/saveDataManager/main.lua +16 -3
  190. package/features/saveDataManager/maps.lua +3 -0
  191. package/features/saveDataManager/merge.lua +53 -21
  192. package/features/saveDataManager/save.lua +12 -7
  193. package/features/sirenHelpers.lua +13 -0
  194. package/features/taintedLazarusPlayers.lua +11 -0
  195. package/featuresInitialized.lua +6 -0
  196. package/functions/array.d.ts +2 -0
  197. package/functions/array.lua +85 -0
  198. package/functions/benchmark.lua +6 -0
  199. package/functions/boss.lua +35 -0
  200. package/functions/cacheFlag.lua +4 -0
  201. package/functions/cards.lua +60 -0
  202. package/functions/challenges.lua +1 -0
  203. package/functions/character.lua +23 -0
  204. package/functions/charge.lua +39 -0
  205. package/functions/chargeBar.d.ts +1 -0
  206. package/functions/chargeBar.lua +4 -0
  207. package/functions/collectibleCacheFlag.lua +15 -0
  208. package/functions/collectibleSet.lua +3 -0
  209. package/functions/collectibleTag.lua +9 -0
  210. package/functions/collectibles.d.ts +6 -1
  211. package/functions/collectibles.lua +146 -2
  212. package/functions/color.lua +18 -0
  213. package/functions/debug.lua +18 -0
  214. package/functions/deepCopy.lua +60 -26
  215. package/functions/deepCopyTests.lua +8 -5
  216. package/functions/direction.d.ts +1 -0
  217. package/functions/direction.lua +22 -0
  218. package/functions/doors.d.ts +1 -0
  219. package/functions/doors.lua +58 -0
  220. package/functions/entity.d.ts +4 -4
  221. package/functions/entity.lua +94 -6
  222. package/functions/entitySpecific.d.ts +20 -20
  223. package/functions/entitySpecific.lua +182 -0
  224. package/functions/entityTypes.d.ts +1 -1
  225. package/functions/entityTypes.lua +1 -0
  226. package/functions/enums.d.ts +2 -0
  227. package/functions/enums.lua +62 -0
  228. package/functions/familiars.lua +52 -0
  229. package/functions/flag.lua +77 -0
  230. package/functions/flying.lua +10 -0
  231. package/functions/globals.lua +8 -10
  232. package/functions/gridEntity.lua +105 -0
  233. package/functions/gridEntitySpecific.d.ts +5 -0
  234. package/functions/gridEntitySpecific.lua +8 -0
  235. package/functions/input.lua +11 -0
  236. package/functions/isaacAPIClass.d.ts +4 -4
  237. package/functions/isaacAPIClass.lua +15 -3
  238. package/functions/jsonHelpers.lua +11 -0
  239. package/functions/jsonRoom.d.ts +2 -0
  240. package/functions/jsonRoom.lua +5 -0
  241. package/functions/kColor.lua +9 -0
  242. package/functions/language.lua +5 -0
  243. package/functions/log.lua +31 -3
  244. package/functions/map.lua +18 -0
  245. package/functions/math.lua +26 -0
  246. package/functions/npc.lua +24 -0
  247. package/functions/pickupVariants.d.ts +11 -11
  248. package/functions/pickupVariants.lua +11 -0
  249. package/functions/pickups.d.ts +9 -9
  250. package/functions/pickups.lua +67 -0
  251. package/functions/pills.lua +45 -0
  252. package/functions/player.lua +166 -0
  253. package/functions/playerDataStructures.lua +65 -0
  254. package/functions/playerHealth.d.ts +1 -0
  255. package/functions/playerHealth.lua +10 -0
  256. package/functions/playerIndex.d.ts +2 -0
  257. package/functions/playerIndex.lua +47 -0
  258. package/functions/pocketItems.lua +18 -0
  259. package/functions/positionVelocity.d.ts +3 -0
  260. package/functions/positionVelocity.lua +46 -0
  261. package/functions/random.d.ts +2 -0
  262. package/functions/random.lua +32 -0
  263. package/functions/revive.d.ts +2 -0
  264. package/functions/revive.lua +15 -0
  265. package/functions/rng.d.ts +1 -0
  266. package/functions/rng.lua +19 -0
  267. package/functions/roomData.lua +68 -0
  268. package/functions/roomGrid.lua +21 -0
  269. package/functions/roomShape.lua +22 -0
  270. package/functions/rooms.lua +100 -0
  271. package/functions/run.lua +5 -0
  272. package/functions/seeds.lua +4 -0
  273. package/functions/serialization.lua +6 -2
  274. package/functions/set.d.ts +1 -0
  275. package/functions/set.lua +22 -0
  276. package/functions/spawnCollectible.lua +24 -0
  277. package/functions/sprite.d.ts +2 -0
  278. package/functions/sprite.lua +25 -0
  279. package/functions/stage.lua +16 -0
  280. package/functions/string.lua +6 -0
  281. package/functions/table.d.ts +12 -0
  282. package/functions/table.lua +53 -0
  283. package/functions/tears.d.ts +1 -0
  284. package/functions/tears.lua +12 -0
  285. package/functions/transformations.lua +18 -0
  286. package/functions/trinketCacheFlag.lua +3 -0
  287. package/functions/trinketGive.lua +24 -0
  288. package/functions/trinkets.lua +52 -0
  289. package/functions/tstlClass.d.ts +34 -0
  290. package/functions/tstlClass.lua +63 -9
  291. package/functions/ui.d.ts +2 -0
  292. package/functions/ui.lua +16 -0
  293. package/functions/utils.d.ts +16 -0
  294. package/functions/utils.lua +108 -0
  295. package/functions/vector.lua +13 -16
  296. package/index.d.ts +1 -0
  297. package/initCustomCallbacks.lua +3 -0
  298. package/interfaces/ChargeBarSprites.d.ts +1 -0
  299. package/interfaces/private/TSTLClassMetatable.d.ts +2 -0
  300. package/lualib_bundle.lua +21 -34
  301. package/maps/cardMap.lua +1 -0
  302. package/maps/characterMap.lua +1 -0
  303. package/maps/defaultPlayerStatMap.lua +1 -0
  304. package/maps/gridEntityXMLMap.lua +2 -0
  305. package/maps/pillEffectMap.lua +1 -0
  306. package/maps/roomShapeToTopLeftWallGridIndexMap.lua +2 -0
  307. package/maps/roomTypeMap.lua +1 -0
  308. package/objects/LRoomShapeToRectangles.lua +2 -0
  309. package/objects/colors.lua +4 -0
  310. package/objects/oppositeDoorSlots.d.ts +4 -0
  311. package/objects/oppositeDoorSlots.lua +15 -0
  312. package/objects/roomShapeBounds.lua +2 -0
  313. package/objects/roomShapeLayoutSizes.lua +4 -0
  314. package/objects/roomShapeToBottomRightPosition.lua +2 -0
  315. package/objects/roomShapeToDoorSlotsToGridIndexDelta.lua +2 -0
  316. package/objects/roomShapeToTopLeftPosition.lua +2 -0
  317. package/objects/roomShapeVolumes.lua +3 -0
  318. package/package.json +2 -2
  319. package/patchErrorFunctions.lua +8 -0
  320. package/sets/bossSets.lua +23 -0
  321. package/sets/charactersWithNoRedHeartsSet.lua +2 -0
  322. package/sets/charactersWithNoSoulHeartsSet.lua +2 -0
  323. package/sets/lostStyleCharactersSet.lua +2 -0
  324. package/types/AnyEntity.d.ts +10 -0
  325. package/types/PickingUpItem.lua +7 -0
  326. package/upgradeMod.d.ts +4 -4
  327. package/upgradeMod.lua +18 -0
@@ -49,6 +49,7 @@ local addTearsStat = ____tears.addTearsStat
49
49
  local ____utils = require("functions.utils")
50
50
  local ensureAllCases = ____utils.ensureAllCases
51
51
  local ____repeat = ____utils["repeat"]
52
+ --- Helper function to get an array containing the characters of all of the current players.
52
53
  function ____exports.getCharacters(self)
53
54
  local players = getPlayers(nil)
54
55
  return __TS__ArrayMap(
@@ -56,6 +57,10 @@ function ____exports.getCharacters(self)
56
57
  function(____, player) return player:GetPlayerType() end
57
58
  )
58
59
  end
60
+ --- Returns the maximum heart containers that the provided player can have. Normally, this is 12, but
61
+ -- it can change depending on the character (e.g. Keeper) and other things (e.g. Mother's Kiss).
62
+ -- This function does not account for Broken Hearts; use the `getPlayerAvailableHeartSlots` helper
63
+ -- function for that.
59
64
  function ____exports.getPlayerMaxHeartContainers(self, player)
60
65
  local character = player:GetPlayerType()
61
66
  local characterMaxHeartContainers = getCharacterMaxHeartContainers(nil, character)
@@ -72,12 +77,18 @@ function ____exports.getPlayerMaxHeartContainers(self, player)
72
77
  end
73
78
  return characterMaxHeartContainers
74
79
  end
80
+ --- Helper function to check if a player is a specific character (i.e. `PlayerType`).
81
+ --
82
+ -- This function is variadic, meaning that you can supply as many characters as you want to check
83
+ -- for. Returns true if the player is any of the supplied characters.
75
84
  function ____exports.isCharacter(self, player, ...)
76
85
  local characters = {...}
77
86
  local characterSet = __TS__New(Set, characters)
78
87
  local character = player:GetPlayerType()
79
88
  return characterSet:has(character)
80
89
  end
90
+ --- Helper function for detecting when a player is Keeper or Tainted Keeper. Useful for situations
91
+ -- where you want to know if the health is coin hearts, for example.
81
92
  function ____exports.isKeeper(self, player)
82
93
  local character = player:GetPlayerType()
83
94
  return character == PlayerType.KEEPER or character == PlayerType.KEEPER_B
@@ -110,6 +121,19 @@ function ____exports.addCollectibleCostume(self, player, collectibleType)
110
121
  end
111
122
  player:AddCostume(itemConfigItem, false)
112
123
  end
124
+ --- Helper function to add a stat to a player based on the `CacheFlag` provided. Call this function
125
+ -- from the EvaluateCache callback.
126
+ --
127
+ -- Note that for `CacheFlag.FIRE_DELAY`, the "amount" argument will be interpreted as the tear stat
128
+ -- to add (and not the amount to mutate `EntityPlayer.MaxFireDelay` by).
129
+ --
130
+ -- This function supports the following cache flags:
131
+ -- - CacheFlag.DAMAGE (1 << 0)
132
+ -- - CacheFlag.FIRE_DELAY (1 << 1)
133
+ -- - CacheFlag.SHOT_SPEED (1 << 2)
134
+ -- - CacheFlag.RANGE (1 << 3)
135
+ -- - CacheFlag.SPEED (1 << 4)
136
+ -- - CacheFlag.LUCK (1 << 10)
113
137
  function ____exports.addStat(self, player, cacheFlag, amount)
114
138
  if not STAT_CACHE_FLAGS_SET:has(cacheFlag) then
115
139
  error("You cannot add a stat to a player with the cache flag of: " .. tostring(cacheFlag))
@@ -186,6 +210,10 @@ function ____exports.anyPlayerHasTrinket(self, trinketType)
186
210
  function(____, player) return player:HasTrinket(trinketType) end
187
211
  )
188
212
  end
213
+ --- Helper function to determine if the given character is present.
214
+ --
215
+ -- This function is variadic, meaning that you can supply as many characters as you want to check
216
+ -- for. Returns true if any of the characters supplied are present.
189
217
  function ____exports.anyPlayerIs(self, ...)
190
218
  local matchingCharacters = {...}
191
219
  local matchingCharacterSet = __TS__New(Set, matchingCharacters)
@@ -195,10 +223,19 @@ function ____exports.anyPlayerIs(self, ...)
195
223
  function(____, character) return matchingCharacterSet:has(character) end
196
224
  )
197
225
  end
226
+ --- Helper function to determine if a player will destroy a rock/pot/skull if they walk over it.
227
+ --
228
+ -- The following situations allow for this to be true:
229
+ -- - the player has Leo (collectible 302)
230
+ -- - the player has Thunder Thighs (collectible 314)
231
+ -- - the player is under the effects of Mega Mush (collectible 625)
232
+ -- - the player has Stompy (transformation 13)
198
233
  function ____exports.canPlayerCrushRocks(self, player)
199
234
  local effects = player:GetEffects()
200
235
  return player:HasCollectible(CollectibleType.LEO) or player:HasCollectible(CollectibleType.THUNDER_THIGHS) or effects:HasCollectibleEffect(CollectibleType.MEGA_MUSH) or player:HasPlayerForm(PlayerForm.STOMPY)
201
236
  end
237
+ --- Helper function to find the active slot that the player has the corresponding collectible type
238
+ -- in. Returns undefined if the player does not have the collectible in any active slot.
202
239
  function ____exports.getActiveItemSlot(self, player, collectibleType)
203
240
  local activeSlots = getEnumValues(nil, ActiveSlot)
204
241
  return __TS__ArrayFind(
@@ -209,6 +246,10 @@ function ____exports.getActiveItemSlot(self, player, collectibleType)
209
246
  end
210
247
  )
211
248
  end
249
+ --- Helper function to get how long Azazel's Brimstone laser should be. You can pass either an
250
+ -- `EntityPlayer` object or a tear height stat.
251
+ --
252
+ -- The formula for calculating it is: 32 - 2.5 * player.TearHeight
212
253
  function ____exports.getAzazelBrimstoneDistance(self, playerOrTearHeight)
213
254
  local tearHeight = tonumber(playerOrTearHeight)
214
255
  if tearHeight == nil then
@@ -232,6 +273,8 @@ function ____exports.getClosestPlayer(self, position)
232
273
  end
233
274
  return closestPlayer
234
275
  end
276
+ --- Helper function to get an array of temporary effects for a player. This is helpful so that you
277
+ -- don't have to manually create an array from an `EffectsList` object.
235
278
  function ____exports.getEffectsList(self, player)
236
279
  local effects = player:GetEffects()
237
280
  local effectsList = effects:GetEffectsList()
@@ -248,6 +291,8 @@ function ____exports.getEffectsList(self, player)
248
291
  end
249
292
  return effectArray
250
293
  end
294
+ --- Helper function to return the player with the highest ID, according to the `Isaac.GetPlayer`
295
+ -- method.
251
296
  function ____exports.getFinalPlayer(self)
252
297
  local players = getPlayers(nil)
253
298
  local lastPlayer = getLastElement(nil, players)
@@ -256,6 +301,9 @@ function ____exports.getFinalPlayer(self)
256
301
  end
257
302
  return lastPlayer
258
303
  end
304
+ --- Helper function to get the first player with the lowest frame count. Useful to find a freshly
305
+ -- spawned player after using items like Esau Jr. Don't use this function if two or more players
306
+ -- will be spawned on the same frame.
259
307
  function ____exports.getNewestPlayer(self)
260
308
  local newestPlayer = nil
261
309
  local lowestFrame = math.huge
@@ -270,6 +318,9 @@ function ____exports.getNewestPlayer(self)
270
318
  end
271
319
  return newestPlayer
272
320
  end
321
+ --- Returns the number of slots that the player has remaining for new heart containers, accounting
322
+ -- for broken hearts. For example, if the player is Judas and has 1 red heart containers and 2 full
323
+ -- soul hearts and 3 broken hearts, then this function would return 6 (i.e. 12 - 1 - 2 - 3).
273
324
  function ____exports.getPlayerAvailableHeartSlots(self, player)
274
325
  local maxHeartContainers = ____exports.getPlayerMaxHeartContainers(nil, player)
275
326
  local effectiveMaxHearts = player:GetEffectiveMaxHearts()
@@ -281,11 +332,19 @@ function ____exports.getPlayerAvailableHeartSlots(self, player)
281
332
  local totalOccupiedHeartSlots = totalHeartContainers + brokenHearts
282
333
  return maxHeartContainers - totalOccupiedHeartSlots
283
334
  end
335
+ --- Returns the number of black hearts that the player has, excluding any soul hearts. For example,
336
+ -- if the player has one full black heart, one full soul heart, and one half black heart, this
337
+ -- function returns 3.
338
+ --
339
+ -- This is different from the `EntityPlayer.GetBlackHearts` method, since that returns a bitmask.
284
340
  function ____exports.getPlayerBlackHearts(self, player)
285
341
  local blackHeartsBitmask = player:GetBlackHearts()
286
342
  local blackHeartBits = countSetBits(nil, blackHeartsBitmask)
287
343
  return blackHeartBits * 2
288
344
  end
345
+ --- Iterates over all players and checks if any are close enough to the specified position.
346
+ --
347
+ -- @returns The first player found when iterating upwards from index 0.
289
348
  function ____exports.getPlayerCloserThan(self, position, distance)
290
349
  local players = getPlayers(nil)
291
350
  return __TS__ArrayFind(
@@ -293,6 +352,10 @@ function ____exports.getPlayerCloserThan(self, position, distance)
293
352
  function(____, player) return player.Position:Distance(position) <= distance end
294
353
  )
295
354
  end
355
+ --- Helper function to return the total amount of collectibles that a player has that match the
356
+ -- collectible type(s) provided.
357
+ --
358
+ -- This function is variadic, meaning that you can specify N collectible types.
296
359
  function ____exports.getPlayerCollectibleCount(self, player, ...)
297
360
  local collectibleTypes = {...}
298
361
  local numCollectibles = 0
@@ -301,6 +364,8 @@ function ____exports.getPlayerCollectibleCount(self, player, ...)
301
364
  end
302
365
  return numCollectibles
303
366
  end
367
+ --- Iterates over every item in the game and returns a map containing the number of each item that
368
+ -- the player has.
304
369
  function ____exports.getPlayerCollectibleMap(self, player)
305
370
  local collectibleSet = getCollectibleSet(nil)
306
371
  local collectibleMap = __TS__New(Map)
@@ -312,11 +377,19 @@ function ____exports.getPlayerCollectibleMap(self, player)
312
377
  end
313
378
  return collectibleMap
314
379
  end
380
+ --- Returns the number of red hearts that the player has, excluding any rotten hearts. For example,
381
+ -- if the player has one full black heart, one full soul heart, and one half black heart, this
382
+ -- function returns 3.
383
+ --
384
+ -- This is different from the `EntityPlayer.GetHearts` method, since that returns a value that
385
+ -- includes rotten hearts.
315
386
  function ____exports.getPlayerHearts(self, player)
316
387
  local rottenHearts = player:GetRottenHearts()
317
388
  local hearts = player:GetHearts()
318
389
  return hearts - rottenHearts * 2
319
390
  end
391
+ --- Helper function that returns the type of the rightmost heart. This does not including golden
392
+ -- hearts or broken hearts, since they cannot be damaged directly.
320
393
  function ____exports.getPlayerLastHeart(self, player)
321
394
  local hearts = player:GetHearts()
322
395
  local effectiveMaxHearts = player:GetEffectiveMaxHearts()
@@ -358,10 +431,20 @@ function ____exports.getPlayerLastHeart(self, player)
358
431
  end
359
432
  return HealthType.RED
360
433
  end
434
+ --- Helper function to get the proper name of the player. Use this instead of the
435
+ -- `EntityPlayer.GetName` method because it accounts for Blue Baby, Lazarus II, and Tainted
436
+ -- characters.
361
437
  function ____exports.getPlayerName(self, player)
362
438
  local character = player:GetPlayerType()
363
439
  return ____exports.isModdedPlayer(nil, player) and player:GetName() or getCharacterName(nil, character)
364
440
  end
441
+ --- Returns the combined value of all of the player's red hearts, soul/black hearts, and bone hearts,
442
+ -- minus the value of the player's rotten hearts.
443
+ --
444
+ -- This is equivalent to the number of hits that the player can currently take, but does not take
445
+ -- into account double damage from champion enemies and/or being on later floors. (For example, on
446
+ -- Womb 1, players who have 1 soul heart remaining would die in 1 hit to anything, even though this
447
+ -- function would report that they have 2 hits remaining.)
365
448
  function ____exports.getPlayerNumHitsRemaining(self, player)
366
449
  local hearts = player:GetHearts()
367
450
  local soulHearts = player:GetSoulHearts()
@@ -370,11 +453,21 @@ function ____exports.getPlayerNumHitsRemaining(self, player)
370
453
  local rottenHearts = player:GetRottenHearts()
371
454
  return hearts + soulHearts + boneHearts + eternalHearts - rottenHearts
372
455
  end
456
+ --- Returns the number of soul hearts that the player has, excluding any black hearts. For example,
457
+ -- if the player has one full black heart, one full soul heart, and one half black heart, this
458
+ -- function returns 2.
459
+ --
460
+ -- This is different from the `EntityPlayer.GetSoulHearts` method, since that returns the combined
461
+ -- number of soul hearts and black hearts.
373
462
  function ____exports.getPlayerSoulHearts(self, player)
374
463
  local soulHearts = player:GetSoulHearts()
375
464
  local blackHearts = ____exports.getPlayerBlackHearts(nil, player)
376
465
  return soulHearts - blackHearts
377
466
  end
467
+ --- Helper function to get all of the players that are a certain character.
468
+ --
469
+ -- This function is variadic, meaning that you can supply as many characters as you want to check
470
+ -- for. Returns true if any of the characters supplied are present.
378
471
  function ____exports.getPlayersOfType(self, ...)
379
472
  local characters = {...}
380
473
  local charactersSet = __TS__New(Set, characters)
@@ -387,6 +480,10 @@ function ____exports.getPlayersOfType(self, ...)
387
480
  end
388
481
  )
389
482
  end
483
+ --- Helper function to get only the players that have a certain collectible.
484
+ --
485
+ -- This function is variadic, meaning that you can supply as many collectible types as you want to
486
+ -- check for. It only returns the players that have all of the collectibles.
390
487
  function ____exports.getPlayersWithCollectible(self, ...)
391
488
  local collectibleTypes = {...}
392
489
  local players = getPlayers(nil)
@@ -398,6 +495,10 @@ function ____exports.getPlayersWithCollectible(self, ...)
398
495
  ) end
399
496
  )
400
497
  end
498
+ --- Helper function to get only the players that have a certain trinket.
499
+ --
500
+ -- This function is variadic, meaning that you can supply as many trinket types as you want to check
501
+ -- for. It only returns the players that have all of the trinkets.
401
502
  function ____exports.getPlayersWithTrinket(self, ...)
402
503
  local trinketTypes = {...}
403
504
  local players = getPlayers(nil)
@@ -409,12 +510,22 @@ function ____exports.getPlayersWithTrinket(self, ...)
409
510
  ) end
410
511
  )
411
512
  end
513
+ --- Helper function to determine how many heart containers that Tainted Magdalene has that will not
514
+ -- be automatically depleted over time. By default, this is 2, but this function will return 4 so
515
+ -- that it is consistent with the `player.GetHearts` and `player.GetMaxHearts` methods.
516
+ --
517
+ -- If Tainted Magdalene has Birthright, she will gained an additional non-temporary heart container.
518
+ --
519
+ -- This function does not validate whether or not the provided player is Tainted Magdalene; that
520
+ -- should be accomplished before invoking this function.
412
521
  function ____exports.getTaintedMagdaleneNonTemporaryMaxHearts(self, player)
413
522
  local maxHearts = player:GetMaxHearts()
414
523
  local hasBirthright = player:HasCollectible(CollectibleType.BIRTHRIGHT)
415
524
  local maxNonTemporaryMaxHearts = hasBirthright and 6 or 4
416
525
  return math.min(maxHearts, maxNonTemporaryMaxHearts)
417
526
  end
527
+ --- Returns the total number of collectibles amongst all players. For example, if player 1 has 1 Sad
528
+ -- Onion and player 2 has 2 Sad Onions, then this function would return 3.
418
529
  function ____exports.getTotalPlayerCollectibles(self, collectibleType)
419
530
  local players = getPlayers(nil)
420
531
  local numCollectiblesArray = __TS__ArrayMap(
@@ -423,10 +534,16 @@ function ____exports.getTotalPlayerCollectibles(self, collectibleType)
423
534
  )
424
535
  return sumArray(nil, numCollectiblesArray)
425
536
  end
537
+ --- After touching a white fire, a player will turn into The Lost until they clear a room.
426
538
  function ____exports.hasLostCurse(self, player)
427
539
  local effects = player:GetEffects()
428
540
  return effects:HasNullEffect(NullItemID.LOST_CURSE)
429
541
  end
542
+ --- Returns whether or not the player can hold an additional active item, beyond what they are
543
+ -- currently carrying. This takes the Schoolbag into account.
544
+ --
545
+ -- If the player is the Tainted Soul, this always returns false, since that character cannot pick up
546
+ -- items. (Only Tainted Forgotten can pick up items.)
430
547
  function ____exports.hasOpenActiveItemSlot(self, player)
431
548
  if ____exports.isCharacter(nil, player, PlayerType.THE_SOUL_B) then
432
549
  return false
@@ -443,10 +560,15 @@ function ____exports.isActiveSlotEmpty(self, player, activeSlot)
443
560
  local activeCollectibleType = player:GetActiveItem(activeSlot)
444
561
  return activeCollectibleType == CollectibleType.NULL
445
562
  end
563
+ --- Helper function for detecting when a player is Bethany or Tainted Bethany. This is useful if you
564
+ -- need to adjust UI elements to account for Bethany's soul charges or Tainted Bethany's blood
565
+ -- charges.
446
566
  function ____exports.isBethany(self, player)
447
567
  local character = player:GetPlayerType()
448
568
  return character == PlayerType.BETHANY or character == PlayerType.BETHANY_B
449
569
  end
570
+ --- Helper function for detecting when a player is Eden or Tainted Eden. Useful for situations where
571
+ -- you want to know if the starting stats were randomized, for example.
450
572
  function ____exports.isEden(self, player)
451
573
  local character = player:GetPlayerType()
452
574
  return character == PlayerType.EDEN or character == PlayerType.EDEN_B
@@ -454,14 +576,18 @@ end
454
576
  function ____exports.isFirstPlayer(self, player)
455
577
  return getPlayerIndexVanilla(nil, player) == 0
456
578
  end
579
+ --- Helper function for detecting when a player is Jacob or Esau. This will only match the
580
+ -- non-tainted versions of these characters.
457
581
  function ____exports.isJacobOrEsau(self, player)
458
582
  local character = player:GetPlayerType()
459
583
  return character == PlayerType.JACOB or character == PlayerType.ESAU
460
584
  end
585
+ --- Helper function for detecting when a player is The Lost or Tainted Lost.
461
586
  function ____exports.isLost(self, player)
462
587
  local character = player:GetPlayerType()
463
588
  return character == PlayerType.THE_LOST or character == PlayerType.THE_LOST_B
464
589
  end
590
+ --- Helper function for detecting if a player is one of the Tainted characters.
465
591
  function ____exports.isTainted(self, player)
466
592
  local character = player:GetPlayerType()
467
593
  local ____isVanillaPlayer_result_0
@@ -472,16 +598,25 @@ function ____exports.isTainted(self, player)
472
598
  end
473
599
  return ____isVanillaPlayer_result_0
474
600
  end
601
+ --- Helper function for detecting when a player is Tainted Lazarus or Dead Tainted Lazarus.
475
602
  function ____exports.isTaintedLazarus(self, player)
476
603
  local character = player:GetPlayerType()
477
604
  return character == PlayerType.LAZARUS_B or character == PlayerType.LAZARUS_2_B
478
605
  end
606
+ --- Helper function to add one or more collectibles to a player.
607
+ --
608
+ -- This function is variadic, meaning that you can supply as many collectible types as you want to
609
+ -- add.
479
610
  function ____exports.playerAddCollectible(self, player, ...)
480
611
  local collectibleTypes = {...}
481
612
  for ____, collectibleType in ipairs(collectibleTypes) do
482
613
  player:AddCollectible(collectibleType)
483
614
  end
484
615
  end
616
+ --- Helper function to check to see if a player has one or more collectibles.
617
+ --
618
+ -- This function is variadic, meaning that you can supply as many collectible types as you want to
619
+ -- check for. Returns true if the player has any of the supplied collectible types.
485
620
  function ____exports.playerHasCollectible(self, player, ...)
486
621
  local collectibleTypes = {...}
487
622
  return __TS__ArraySome(
@@ -489,6 +624,8 @@ function ____exports.playerHasCollectible(self, player, ...)
489
624
  function(____, collectibleType) return player:HasCollectible(collectibleType) end
490
625
  )
491
626
  end
627
+ --- Helper function to remove a collectible costume from a player. Use this helper function to avoid
628
+ -- having to request the collectible from the item config.
492
629
  function ____exports.removeCollectibleCostume(self, player, collectibleType)
493
630
  local itemConfigItem = itemConfig:GetCollectible(collectibleType)
494
631
  if itemConfigItem == nil then
@@ -496,6 +633,10 @@ function ____exports.removeCollectibleCostume(self, player, collectibleType)
496
633
  end
497
634
  player:RemoveCostume(itemConfigItem)
498
635
  end
636
+ --- Helper function to remove the Dead Eye multiplier from a player.
637
+ --
638
+ -- Note that each time the `EntityPlayer.ClearDeadEyeCharge` method is called, it only has a chance
639
+ -- of working, so this function calls it 100 times to be safe.
499
640
  function ____exports.removeDeadEyeMultiplier(self, player)
500
641
  ____repeat(
501
642
  nil,
@@ -505,6 +646,8 @@ function ____exports.removeDeadEyeMultiplier(self, player)
505
646
  end
506
647
  )
507
648
  end
649
+ --- Helper function to remove a trinket costume from a player. Use this helper function to avoid
650
+ -- having to request the trinket from the item config.
508
651
  function ____exports.removeTrinketCostume(self, player, trinketType)
509
652
  local itemConfigTrinket = itemConfig:GetTrinket(trinketType)
510
653
  if itemConfigTrinket == nil then
@@ -512,6 +655,20 @@ function ____exports.removeTrinketCostume(self, player, trinketType)
512
655
  end
513
656
  player:RemoveCostume(itemConfigTrinket)
514
657
  end
658
+ --- Helper function to set an active collectible to a particular slot. This has different behavior
659
+ -- than calling the `player.AddCollectible` method with the `activeSlot` argument, because this
660
+ -- function will not shift existing items into the Schoolbag and it handles
661
+ -- `ActiveSlot.SLOT_POCKET2`.
662
+ --
663
+ -- Note that if an item is set to `ActiveSlot.SLOT_POCKET2`, it will disappear after being used and
664
+ -- will be automatically removed upon entering a new room.
665
+ --
666
+ -- @param player The player to give the item to.
667
+ -- @param collectibleType The collectible type of the item to give.
668
+ -- @param activeSlot The slot to set.
669
+ -- @param charge Optional. The argument of charges to set. If not specified, the item will be set
670
+ -- with maximum charges.
671
+ -- @param keepInPools Optional. Whether or not to remove the item from pools. Default is false.
515
672
  function ____exports.setActiveItem(self, player, collectibleType, activeSlot, charge, keepInPools)
516
673
  if keepInPools == nil then
517
674
  keepInPools = false
@@ -576,6 +733,13 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
576
733
  end
577
734
  until true
578
735
  end
736
+ --- Helper function to blindfold the player by using a hack with the challenge variable.
737
+ --
738
+ -- The method used in this function was discovered by im_tem.
739
+ --
740
+ -- @param player The player to apply or remove the blindfold state from.
741
+ -- @param enabled Whether or not to apply or remove the blindfold.
742
+ -- @param modifyCostume Optional. Whether to add or remove the blindfold costume. Default is true.
579
743
  function ____exports.setBlindfold(self, player, enabled, modifyCostume)
580
744
  if modifyCostume == nil then
581
745
  modifyCostume = true
@@ -598,6 +762,8 @@ function ____exports.setBlindfold(self, player, enabled, modifyCostume)
598
762
  end
599
763
  end
600
764
  end
765
+ --- Helper function to use an active item without showing an animation, keeping the item, or adding
766
+ -- any costumes.
601
767
  function ____exports.useActiveItemTemp(self, player, collectibleType)
602
768
  player:UseActiveItem(
603
769
  collectibleType,
@@ -4,33 +4,98 @@ local Set = ____lualib.Set
4
4
  local ____exports = {}
5
5
  local ____playerIndex = require("functions.playerIndex")
6
6
  local getPlayerIndex = ____playerIndex.getPlayerIndex
7
+ --- Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
8
+ -- `Map.set` method if you have a map of this type.
9
+ --
10
+ -- For example:
11
+ --
12
+ -- ```ts
13
+ -- const v = {
14
+ -- run: {
15
+ -- playersSpeedBoost: new Map<PlayerIndex, int>(),
16
+ -- },
17
+ -- };
18
+ --
19
+ -- function incrementSpeedBoost(player: EntityPlayer) {
20
+ -- const oldSpeedBoost = mapGetPlayer(v.run.playersSpeedBoost, player);
21
+ -- const newSpeedBoost = oldSpeedBoost + 0.1;
22
+ -- mapSetPlayer(v.run.playersSpeedBoost, player);
23
+ -- }
24
+ -- ```
7
25
  function ____exports.mapSetPlayer(self, map, player, value)
8
26
  local playerIndex = getPlayerIndex(nil, player)
9
27
  map:set(playerIndex, value)
10
28
  end
29
+ --- Helper function to make using default maps with an index of `PlayerIndex` easier. Use this
30
+ -- instead of the `DefaultMap.getAndSetDefault` method if you have a default map of this type.
31
+ --
32
+ -- For example:
33
+ --
34
+ -- ```ts
35
+ -- const v = {
36
+ -- run: {
37
+ -- playersSpeedBoost: new DefaultMap<PlayerIndex, int>(0),
38
+ -- },
39
+ -- };
40
+ --
41
+ -- function evaluateCacheSpeed(player: EntityPlayer) {
42
+ -- player.MoveSpeed = defaultMapGetPlayer(v.run.playersSpeedBoost, player);
43
+ -- }
44
+ -- ```
11
45
  function ____exports.defaultMapGetPlayer(self, map, player, ...)
12
46
  local playerIndex = getPlayerIndex(nil, player)
13
47
  return map:getAndSetDefault(playerIndex, ...)
14
48
  end
49
+ --- Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
50
+ -- `Map.set` method if you have a map of this type.
51
+ --
52
+ -- Since `Map` and `DefaultMap` set values in the same way, this function is simply an alias for the
53
+ -- `mapSetPlayer` helper function.
15
54
  function ____exports.defaultMapSetPlayer(self, map, player, value)
16
55
  ____exports.mapSetPlayer(nil, map, player, value)
17
56
  end
57
+ --- Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
58
+ -- `Map.get` method if you have a map of this type.
59
+ --
60
+ -- For example:
61
+ --
62
+ -- ```ts
63
+ -- const v = {
64
+ -- run: {
65
+ -- playersSpeedBoost: new Map<PlayerIndex, int>(),
66
+ -- },
67
+ -- };
68
+ --
69
+ -- function incrementSpeedBoost(player: EntityPlayer) {
70
+ -- const oldSpeedBoost = mapGetPlayer(v.run.playersSpeedBoost, player);
71
+ -- const newSpeedBoost = oldSpeedBoost + 0.1;
72
+ -- mapSetPlayer(v.run.playersSpeedBoost, player);
73
+ -- }
74
+ -- ```
18
75
  function ____exports.mapGetPlayer(self, map, player)
19
76
  local playerIndex = getPlayerIndex(nil, player)
20
77
  return map:get(playerIndex)
21
78
  end
79
+ --- Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the
80
+ -- `Map.has` method if you have a map of this type.
22
81
  function ____exports.mapHasPlayer(self, map, player)
23
82
  local playerIndex = getPlayerIndex(nil, player)
24
83
  return map:has(playerIndex)
25
84
  end
85
+ --- Helper function to make using sets with an type of `PlayerIndex` easier. Use this instead of the
86
+ -- `Set.add` method if you have a set of this type.
26
87
  function ____exports.setAddPlayer(self, set, player)
27
88
  local playerIndex = getPlayerIndex(nil, player)
28
89
  return set:add(playerIndex)
29
90
  end
91
+ --- Helper function to make using sets with an type of `PlayerIndex` easier. Use this instead of the
92
+ -- `Set.delete` method if you have a set of this type.
30
93
  function ____exports.setDeletePlayer(self, set, player)
31
94
  local playerIndex = getPlayerIndex(nil, player)
32
95
  return set:delete(playerIndex)
33
96
  end
97
+ --- Helper function to make using sets with an type of `PlayerIndex` easier. Use this instead of the
98
+ -- `Set.has` method if you have a set of this type.
34
99
  function ____exports.setHasPlayer(self, set, player)
35
100
  local playerIndex = getPlayerIndex(nil, player)
36
101
  return set:has(playerIndex)
@@ -1,4 +1,5 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /// <reference types="isaac-typescript-definitions" />
2
3
  import { HealthType } from "../enums/HealthType";
3
4
  import { PlayerHealth } from "../interfaces/PlayerHealth";
4
5
  export declare function addPlayerHealthType(player: EntityPlayer, healthType: HealthType, numHearts: int): void;
@@ -89,6 +89,11 @@ function ____exports.addPlayerHealthType(self, player, healthType, numHearts)
89
89
  end
90
90
  until true
91
91
  end
92
+ --- Helper function to get an object representing the player's health. You can use this in
93
+ -- combination with the `setPlayerHealth` function to restore the player's health back to a certain
94
+ -- configuration at a later time.
95
+ --
96
+ -- This is based on the `REVEL.StoreHealth` function in the Revelations mod.
92
97
  function ____exports.getPlayerHealth(self, player)
93
98
  local character = player:GetPlayerType()
94
99
  local soulHeartTypes = {}
@@ -234,6 +239,11 @@ function ____exports.removeAllPlayerHealth(self, player)
234
239
  end
235
240
  end
236
241
  end
242
+ --- Helper function to set a player's health to a specific state. You can use this in combination
243
+ -- with the `getPlayerHealth` function to restore the player's health back to a certain
244
+ -- configuration at a later time.
245
+ --
246
+ -- Based on the `REVEL.LoadHealth` function in the Revelations mod.
237
247
  function ____exports.setPlayerHealth(self, player, playerHealth)
238
248
  local character = player:GetPlayerType()
239
249
  local subPlayer = player:GetSubPlayer()
@@ -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)