isaacscript-common 1.2.62 → 1.2.65

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.
@@ -1,6 +1,5 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  local ____lualib = require("lualib_bundle")
3
- local Map = ____lualib.Map
4
3
  local __TS__New = ____lualib.__TS__New
5
4
  local ____exports = {}
6
5
  local hasSubscriptions, entityTakeDmgPlayer, v
@@ -9,9 +8,11 @@ local saveDataManager = ____exports.saveDataManager
9
8
  local ____player = require("functions.player")
10
9
  local getPlayerIndex = ____player.getPlayerIndex
11
10
  local isChildPlayer = ____player.isChildPlayer
12
- local isDamageToPlayerFatal = ____player.isDamageToPlayerFatal
13
11
  local ____revive = require("functions.revive")
12
+ local isDamageToPlayerFatal = ____revive.isDamageToPlayerFatal
14
13
  local willPlayerRevive = ____revive.willPlayerRevive
14
+ local ____DefaultMap = require("types.DefaultMap")
15
+ local DefaultMap = ____DefaultMap.DefaultMap
15
16
  local ____postPlayerFatalDamage = require("callbacks.subscriptions.postPlayerFatalDamage")
16
17
  local postPlayerFatalDamageFire = ____postPlayerFatalDamage.postPlayerFatalDamageFire
17
18
  local postPlayerFatalDamageHasSubscriptions = ____postPlayerFatalDamage.postPlayerFatalDamageHasSubscriptions
@@ -32,8 +33,7 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
32
33
  local game = Game()
33
34
  local gameFrameCount = game:GetFrameCount()
34
35
  local playerIndex = getPlayerIndex(nil, player)
35
- local lastDamageFrame = v.run.playerLastDamageFrame:get(playerIndex)
36
- v.run.playerLastDamageFrame:set(playerIndex, gameFrameCount)
36
+ local lastDamageGameFrame = v.run.playersLastDamageGameFrame:getAndSetDefault(playerIndex, gameFrameCount)
37
37
  if willPlayerRevive(nil, player) then
38
38
  return nil
39
39
  end
@@ -42,7 +42,7 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
42
42
  player,
43
43
  damageAmount,
44
44
  damageSource,
45
- lastDamageFrame
45
+ lastDamageGameFrame
46
46
  ) then
47
47
  return nil
48
48
  end
@@ -59,7 +59,10 @@ function entityTakeDmgPlayer(self, tookDamage, damageAmount, damageFlags, damage
59
59
  end
60
60
  return nil
61
61
  end
62
- v = {run = {playerLastDamageFrame = __TS__New(Map)}}
62
+ v = {run = {playersLastDamageGameFrame = __TS__New(
63
+ DefaultMap,
64
+ function(____, _key, gameFrameCount) return gameFrameCount end
65
+ )}}
63
66
  function ____exports.postPlayerFatalDamageCallbackInit(self, mod)
64
67
  saveDataManager(nil, "postPlayerFatalDamage", v)
65
68
  mod:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, entityTakeDmgPlayer, EntityType.ENTITY_PLAYER)
@@ -102,6 +102,7 @@ export declare const MAX_PLAYER_TRINKET_SLOTS = 2;
102
102
  export declare const MAX_ROOM_INDEX = 168;
103
103
  export declare const MAX_VANILLA_CHARACTER = PlayerType.PLAYER_THESOUL_B;
104
104
  export declare const MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.COLLECTIBLE_MOMS_RING;
105
+ export declare const NUM_DIMENSIONS = 3;
105
106
  export declare const SECOND_IN_MILLISECONDS = 1000;
106
107
  export declare const MINUTE_IN_MILLISECONDS: number;
107
108
  export declare const ONE_BY_ONE_ROOM_GRID_SIZE = 135;
@@ -88,6 +88,7 @@ ____exports.MAX_PLAYER_TRINKET_SLOTS = 2
88
88
  ____exports.MAX_ROOM_INDEX = 168
89
89
  ____exports.MAX_VANILLA_CHARACTER = PlayerType.PLAYER_THESOUL_B
90
90
  ____exports.MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.COLLECTIBLE_MOMS_RING
91
+ ____exports.NUM_DIMENSIONS = 3
91
92
  ____exports.SECOND_IN_MILLISECONDS = 1000
92
93
  ____exports.MINUTE_IN_MILLISECONDS = 60 * ____exports.SECOND_IN_MILLISECONDS
93
94
  ____exports.ONE_BY_ONE_ROOM_GRID_SIZE = 135
@@ -23,6 +23,8 @@ local ____jsonRoom = require("functions.jsonRoom")
23
23
  local getRandomJSONRoom = ____jsonRoom.getRandomJSONRoom
24
24
  local ____log = require("functions.log")
25
25
  local log = ____log.log
26
+ local ____math = require("functions.math")
27
+ local range = ____math.range
26
28
  local ____npc = require("functions.npc")
27
29
  local getNPCs = ____npc.getNPCs
28
30
  local ____random = require("functions.random")
@@ -121,24 +123,20 @@ function fillRoomWithDecorations(self)
121
123
  local gridSize = room:GetGridSize()
122
124
  local roomListIndex = getRoomListIndex(nil)
123
125
  local decorationGridIndexes = v.level.roomToDecorationGridIndexesMap:getAndSetDefault(roomListIndex)
124
- do
125
- local gridIndex = 0
126
- while gridIndex < gridSize do
127
- do
128
- local existingGridEntity = room:GetGridEntity(gridIndex)
129
- if existingGridEntity ~= nil then
130
- goto __continue33
131
- end
132
- local position = room:GetGridPosition(gridIndex)
133
- local decoration = Isaac.GridSpawn(GridEntityType.GRID_DECORATION, 0, position, true)
134
- if decoration ~= nil then
135
- setGridEntityInvisible(nil, decoration)
136
- end
137
- __TS__ArrayPush(decorationGridIndexes, gridIndex)
126
+ for ____, gridIndex in ipairs(range(nil, 0, gridSize - 1)) do
127
+ do
128
+ local existingGridEntity = room:GetGridEntity(gridIndex)
129
+ if existingGridEntity ~= nil then
130
+ goto __continue33
131
+ end
132
+ local position = room:GetGridPosition(gridIndex)
133
+ local decoration = Isaac.GridSpawn(GridEntityType.GRID_DECORATION, 0, position, true)
134
+ if decoration ~= nil then
135
+ setGridEntityInvisible(nil, decoration)
138
136
  end
139
- ::__continue33::
140
- gridIndex = gridIndex + 1
137
+ __TS__ArrayPush(decorationGridIndexes, gridIndex)
141
138
  end
139
+ ::__continue33::
142
140
  end
143
141
  end
144
142
  function spawnAllEntities(self, jsonRoom, seed, verbose)
@@ -9,6 +9,8 @@ local ____exports = {}
9
9
  local ____collectibles = require("functions.collectibles")
10
10
  local collectibleHasCacheFlag = ____collectibles.collectibleHasCacheFlag
11
11
  local getMaxCollectibleID = ____collectibles.getMaxCollectibleID
12
+ local ____math = require("functions.math")
13
+ local range = ____math.range
12
14
  local ____set = require("functions.set")
13
15
  local copySet = ____set.copySet
14
16
  local ____utils = require("functions.utils")
@@ -18,13 +20,9 @@ local function initCacheFlagMap(self)
18
20
  local maxCollectibleID = getMaxCollectibleID(nil)
19
21
  for ____, cacheFlag in ipairs(getEnumValues(nil, CacheFlag)) do
20
22
  local collectiblesSet = __TS__New(Set)
21
- do
22
- local collectibleType = 1
23
- while collectibleType <= maxCollectibleID do
24
- if collectibleHasCacheFlag(nil, collectibleType, cacheFlag) then
25
- collectiblesSet:add(collectibleType)
26
- end
27
- collectibleType = collectibleType + 1
23
+ for ____, collectibleType in ipairs(range(nil, 1, maxCollectibleID)) do
24
+ if collectibleHasCacheFlag(nil, collectibleType, cacheFlag) then
25
+ collectiblesSet:add(collectibleType)
28
26
  end
29
27
  end
30
28
  CACHE_FLAG_TO_COLLECTIBLES_MAP:set(cacheFlag, collectiblesSet)
@@ -5,20 +5,18 @@ local __TS__New = ____lualib.__TS__New
5
5
  local ____exports = {}
6
6
  local ____collectibles = require("functions.collectibles")
7
7
  local getMaxCollectibleID = ____collectibles.getMaxCollectibleID
8
+ local ____math = require("functions.math")
9
+ local range = ____math.range
8
10
  local ____set = require("functions.set")
9
11
  local copySet = ____set.copySet
10
12
  local COLLECTIBLE_SET = __TS__New(Set)
11
13
  local function initCollectibleSet(self)
12
14
  local itemConfig = Isaac.GetItemConfig()
13
15
  local maxCollectibleID = getMaxCollectibleID(nil)
14
- do
15
- local collectibleType = 1
16
- while collectibleType <= maxCollectibleID do
17
- local itemConfigItem = itemConfig:GetCollectible(collectibleType)
18
- if itemConfigItem ~= nil then
19
- COLLECTIBLE_SET:add(collectibleType)
20
- end
21
- collectibleType = collectibleType + 1
16
+ for ____, collectibleType in ipairs(range(nil, 1, maxCollectibleID)) do
17
+ local itemConfigItem = itemConfig:GetCollectible(collectibleType)
18
+ if itemConfigItem ~= nil then
19
+ COLLECTIBLE_SET:add(collectibleType)
22
20
  end
23
21
  end
24
22
  end
@@ -15,6 +15,7 @@ local DEFAULT_TOP_LEFT_WALL_GRID_INDEX = ____roomShapeToTopLeftWallGridIndexMap.
15
15
  local ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP = ____roomShapeToTopLeftWallGridIndexMap.ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP
16
16
  local ____math = require("functions.math")
17
17
  local isCircleIntersectingRectangle = ____math.isCircleIntersectingRectangle
18
+ local range = ____math.range
18
19
  local ____rooms = require("functions.rooms")
19
20
  local roomUpdateSafe = ____rooms.roomUpdateSafe
20
21
  local ____sprite = require("functions.sprite")
@@ -101,26 +102,22 @@ function ____exports.getGridEntities(self, ...)
101
102
  local gridSize = room:GetGridSize()
102
103
  local gridEntityTypesSet = __TS__New(Set, gridEntityTypes)
103
104
  local gridEntities = {}
104
- do
105
- local gridIndex = 0
106
- while gridIndex < gridSize do
107
- do
108
- local gridEntity = room:GetGridEntity(gridIndex)
109
- if gridEntity == nil then
110
- goto __continue10
111
- end
112
- if #gridEntityTypes == 0 then
105
+ for ____, gridIndex in ipairs(range(nil, 0, gridSize - 1)) do
106
+ do
107
+ local gridEntity = room:GetGridEntity(gridIndex)
108
+ if gridEntity == nil then
109
+ goto __continue10
110
+ end
111
+ if #gridEntityTypes == 0 then
112
+ __TS__ArrayPush(gridEntities, gridEntity)
113
+ else
114
+ local thisGridEntityType = gridEntity:GetType()
115
+ if gridEntityTypesSet:has(thisGridEntityType) then
113
116
  __TS__ArrayPush(gridEntities, gridEntity)
114
- else
115
- local thisGridEntityType = gridEntity:GetType()
116
- if gridEntityTypesSet:has(thisGridEntityType) then
117
- __TS__ArrayPush(gridEntities, gridEntity)
118
- end
119
117
  end
120
118
  end
121
- ::__continue10::
122
- gridIndex = gridIndex + 1
123
119
  end
120
+ ::__continue10::
124
121
  end
125
122
  return gridEntities
126
123
  end
@@ -210,8 +210,6 @@ export declare function isBethany(player: EntityPlayer): boolean;
210
210
  * (For example, the Strawman Keeper.)
211
211
  */
212
212
  export declare function isChildPlayer(player: EntityPlayer): boolean;
213
- /** Uses the player's current health and character to determine if incoming damage will be fatal. */
214
- export declare function isDamageToPlayerFatal(player: EntityPlayer, damageAmount: int, damageSource: EntityRef, lastDamageFrame?: int): boolean;
215
213
  export declare function isFirstPlayer(player: EntityPlayer): boolean;
216
214
  /**
217
215
  * Helper function for detecting when a player is Jacob or Esau. This will only match the
@@ -484,44 +484,6 @@ function ____exports.isBethany(self, player)
484
484
  local character = player:GetPlayerType()
485
485
  return character == PlayerType.PLAYER_BETHANY or character == PlayerType.PLAYER_BETHANY_B
486
486
  end
487
- function ____exports.isDamageToPlayerFatal(self, player, damageAmount, damageSource, lastDamageFrame)
488
- local game = Game()
489
- local gameFrameCount = game:GetFrameCount()
490
- local character = player:GetPlayerType()
491
- local effects = player:GetEffects()
492
- local isBerserk = effects:HasCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK)
493
- if character == PlayerType.PLAYER_JACOB_B and damageSource.Type == EntityType.ENTITY_DARK_ESAU then
494
- return false
495
- end
496
- if isBerserk then
497
- return false
498
- end
499
- if character == PlayerType.PLAYER_JACOB2_B then
500
- return true
501
- end
502
- if ____exports.hasLostCurse(nil, player) then
503
- return true
504
- end
505
- local playerNumAllHearts = ____exports.getPlayerNumHitsRemaining(nil, player)
506
- if damageAmount < playerNumAllHearts then
507
- return false
508
- end
509
- local playerAvailableHeartSlots = ____exports.getPlayerAvailableHeartSlots(nil, player)
510
- if player:HasCollectible(CollectibleType.COLLECTIBLE_HEARTBREAK) and playerAvailableHeartSlots >= 2 then
511
- return false
512
- end
513
- if player:HasCollectible(CollectibleType.COLLECTIBLE_BROKEN_GLASS_CANNON) and gameFrameCount == lastDamageFrame then
514
- return false
515
- end
516
- local hearts = player:GetHearts()
517
- local eternalHearts = player:GetEternalHearts()
518
- local soulHearts = player:GetSoulHearts()
519
- local boneHearts = player:GetBoneHearts()
520
- if hearts > 0 and soulHearts > 0 or hearts > 0 and boneHearts > 0 or soulHearts > 0 and boneHearts > 0 or soulHearts > 0 and eternalHearts > 0 or boneHearts >= 2 then
521
- return false
522
- end
523
- return true
524
- end
525
487
  function ____exports.isFirstPlayer(self, player)
526
488
  return ____exports.getPlayerIndexVanilla(nil, player) == 0
527
489
  end
@@ -586,9 +548,9 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
586
548
  itemPool:RemoveCollectible(collectibleType)
587
549
  end
588
550
  repeat
589
- local ____switch127 = activeSlot
590
- local ____cond127 = ____switch127 == ActiveSlot.SLOT_PRIMARY
591
- if ____cond127 then
551
+ local ____switch118 = activeSlot
552
+ local ____cond118 = ____switch118 == ActiveSlot.SLOT_PRIMARY
553
+ if ____cond118 then
592
554
  do
593
555
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
594
556
  player:RemoveCollectible(primaryCollectibleType)
@@ -597,8 +559,8 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
597
559
  break
598
560
  end
599
561
  end
600
- ____cond127 = ____cond127 or ____switch127 == ActiveSlot.SLOT_SECONDARY
601
- if ____cond127 then
562
+ ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_SECONDARY
563
+ if ____cond118 then
602
564
  do
603
565
  if primaryCollectibleType ~= CollectibleType.COLLECTIBLE_NULL then
604
566
  player:RemoveCollectible(primaryCollectibleType)
@@ -613,16 +575,16 @@ function ____exports.setActiveItem(self, player, collectibleType, activeSlot, ch
613
575
  break
614
576
  end
615
577
  end
616
- ____cond127 = ____cond127 or ____switch127 == ActiveSlot.SLOT_POCKET
617
- if ____cond127 then
578
+ ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_POCKET
579
+ if ____cond118 then
618
580
  do
619
581
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
620
582
  player:SetActiveCharge(charge, activeSlot)
621
583
  break
622
584
  end
623
585
  end
624
- ____cond127 = ____cond127 or ____switch127 == ActiveSlot.SLOT_POCKET2
625
- if ____cond127 then
586
+ ____cond118 = ____cond118 or ____switch118 == ActiveSlot.SLOT_POCKET2
587
+ if ____cond118 then
626
588
  do
627
589
  player:SetPocketActiveItem(collectibleType, activeSlot, keepInPools)
628
590
  break
@@ -8,6 +8,8 @@ local ____constants = require("constants")
8
8
  local MAX_PLAYER_POCKET_ITEM_SLOTS = ____constants.MAX_PLAYER_POCKET_ITEM_SLOTS
9
9
  local ____PocketItemType = require("types.PocketItemType")
10
10
  local PocketItemType = ____PocketItemType.PocketItemType
11
+ local ____math = require("functions.math")
12
+ local range = ____math.range
11
13
  function ____exports.getPocketItems(self, player)
12
14
  local pocketItem = player:GetActiveItem(ActiveSlot.SLOT_POCKET)
13
15
  local hasPocketItem = pocketItem ~= CollectibleType.COLLECTIBLE_NULL
@@ -17,30 +19,26 @@ function ____exports.getPocketItems(self, player)
17
19
  local pocketItems = {}
18
20
  local pocketItemIdentified = false
19
21
  local pocketItem2Identified = false
20
- do
21
- local slot = 0
22
- while slot < MAX_PLAYER_POCKET_ITEM_SLOTS do
23
- local card = player:GetCard(slot)
24
- local pill = player:GetPill(slot)
25
- if card ~= Card.CARD_NULL then
26
- __TS__ArrayPush(pocketItems, {type = PocketItemType.CARD, id = card, slot = slot})
27
- elseif pill ~= PillColor.PILL_NULL then
28
- __TS__ArrayPush(pocketItems, {type = PocketItemType.PILL, id = pill, slot = slot})
29
- elseif hasPocketItem and not hasPocketItem2 and not pocketItemIdentified then
30
- pocketItemIdentified = true
31
- __TS__ArrayPush(pocketItems, {type = PocketItemType.ACTIVE_ITEM, id = pocketItem, slot = slot})
32
- elseif not hasPocketItem and hasPocketItem2 and not pocketItem2Identified then
33
- pocketItem2Identified = true
34
- __TS__ArrayPush(pocketItems, {type = PocketItemType.DICE_BAG_DICE, id = pocketItem2, slot = slot})
35
- elseif hasPocketItem and hasPocketItem2 then
36
- __TS__ArrayPush(pocketItems, {type = PocketItemType.UNDETERMINABLE, id = 0, slot = slot})
37
- else
38
- __TS__ArrayPush(pocketItems, {type = PocketItemType.EMPTY, id = 0, slot = slot})
39
- end
40
- if slot + 1 == maxPocketItems then
41
- break
42
- end
43
- slot = slot + 1
22
+ for ____, slot in ipairs(range(nil, 0, MAX_PLAYER_POCKET_ITEM_SLOTS - 1)) do
23
+ local card = player:GetCard(slot)
24
+ local pillColor = player:GetPill(slot)
25
+ if card ~= Card.CARD_NULL then
26
+ __TS__ArrayPush(pocketItems, {slot = slot, type = PocketItemType.CARD, subType = card})
27
+ elseif pillColor ~= PillColor.PILL_NULL then
28
+ __TS__ArrayPush(pocketItems, {slot = slot, type = PocketItemType.PILL, subType = pillColor})
29
+ elseif hasPocketItem and not hasPocketItem2 and not pocketItemIdentified then
30
+ pocketItemIdentified = true
31
+ __TS__ArrayPush(pocketItems, {slot = slot, type = PocketItemType.ACTIVE_ITEM, subType = pocketItem})
32
+ elseif not hasPocketItem and hasPocketItem2 and not pocketItem2Identified then
33
+ pocketItem2Identified = true
34
+ __TS__ArrayPush(pocketItems, {slot = slot, type = PocketItemType.DICE_BAG_DICE, subType = pocketItem2})
35
+ elseif hasPocketItem and hasPocketItem2 then
36
+ __TS__ArrayPush(pocketItems, {slot = slot, type = PocketItemType.UNDETERMINABLE, subType = 0})
37
+ else
38
+ __TS__ArrayPush(pocketItems, {slot = slot, type = PocketItemType.EMPTY, subType = 0})
39
+ end
40
+ if slot + 1 == maxPocketItems then
41
+ break
44
42
  end
45
43
  end
46
44
  return pocketItems
@@ -1,4 +1,9 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
+ /**
3
+ * Uses the player's current health and other miscellaneous things to determine if incoming damage
4
+ * will be fatal.
5
+ */
6
+ export declare function isDamageToPlayerFatal(player: EntityPlayer, damageAmount: int, damageSource: EntityRef, lastDamageGameFrame: int): boolean;
2
7
  /**
3
8
  * The `EntityPlayer.WillPlayerRevive()` function does not properly account for Mysterious Paper,
4
9
  * so use this helper function instead for more robust revival detection.
@@ -2,6 +2,9 @@
2
2
  local ____exports = {}
3
3
  local ____player = require("functions.player")
4
4
  local getDeathAnimationName = ____player.getDeathAnimationName
5
+ local getPlayerAvailableHeartSlots = ____player.getPlayerAvailableHeartSlots
6
+ local getPlayerNumHitsRemaining = ____player.getPlayerNumHitsRemaining
7
+ local hasLostCurse = ____player.hasLostCurse
5
8
  local ____sprite = require("functions.sprite")
6
9
  local getFinalFrameOfAnimation = ____sprite.getFinalFrameOfAnimation
7
10
  local ____trinketGive = require("functions.trinketGive")
@@ -16,12 +19,6 @@ function ____exports.willMysteriousPaperRevive(self, player)
16
19
  local frameOfDeath = gameFrameCount + deathAnimationFrames + 1
17
20
  return frameOfDeath % 4 == 3
18
21
  end
19
- function ____exports.willPlayerRevive(self, player)
20
- local trinketSituation = temporarilyRemoveTrinket(nil, player, TrinketType.TRINKET_MYSTERIOUS_PAPER)
21
- local willRevive = player:WillPlayerRevive() or trinketSituation ~= nil and ____exports.willMysteriousPaperRevive(nil, player)
22
- giveTrinketsBack(nil, player, trinketSituation)
23
- return willRevive
24
- end
25
22
  function ____exports.willReviveFromSpiritShackles(self, player)
26
23
  if not player:HasCollectible(CollectibleType.COLLECTIBLE_SPIRIT_SHACKLES) then
27
24
  return false
@@ -31,4 +28,51 @@ function ____exports.willReviveFromSpiritShackles(self, player)
31
28
  local playerInSoulForm = effects:HasNullEffect(NullItemID.ID_SPIRIT_SHACKLES_SOUL)
32
29
  return spiritShacklesEnabled and not playerInSoulForm
33
30
  end
31
+ function ____exports.isDamageToPlayerFatal(self, player, damageAmount, damageSource, lastDamageGameFrame)
32
+ local game = Game()
33
+ local gameFrameCount = game:GetFrameCount()
34
+ local character = player:GetPlayerType()
35
+ local effects = player:GetEffects()
36
+ local isBerserk = effects:HasCollectibleEffect(CollectibleType.COLLECTIBLE_BERSERK)
37
+ if character == PlayerType.PLAYER_JACOB_B and damageSource.Type == EntityType.ENTITY_DARK_ESAU then
38
+ return false
39
+ end
40
+ if isBerserk then
41
+ return false
42
+ end
43
+ if ____exports.willReviveFromSpiritShackles(nil, player) then
44
+ return false
45
+ end
46
+ if character == PlayerType.PLAYER_JACOB2_B then
47
+ return true
48
+ end
49
+ if hasLostCurse(nil, player) then
50
+ return true
51
+ end
52
+ local playerNumAllHearts = getPlayerNumHitsRemaining(nil, player)
53
+ if damageAmount < playerNumAllHearts then
54
+ return false
55
+ end
56
+ local playerAvailableHeartSlots = getPlayerAvailableHeartSlots(nil, player)
57
+ if player:HasCollectible(CollectibleType.COLLECTIBLE_HEARTBREAK) and playerAvailableHeartSlots >= 2 then
58
+ return false
59
+ end
60
+ if player:HasCollectible(CollectibleType.COLLECTIBLE_BROKEN_GLASS_CANNON) and gameFrameCount == lastDamageGameFrame then
61
+ return false
62
+ end
63
+ local hearts = player:GetHearts()
64
+ local eternalHearts = player:GetEternalHearts()
65
+ local soulHearts = player:GetSoulHearts()
66
+ local boneHearts = player:GetBoneHearts()
67
+ if hearts > 0 and soulHearts > 0 or hearts > 0 and boneHearts > 0 or soulHearts > 0 and boneHearts > 0 or soulHearts > 0 and eternalHearts > 0 or boneHearts >= 2 then
68
+ return false
69
+ end
70
+ return true
71
+ end
72
+ function ____exports.willPlayerRevive(self, player)
73
+ local trinketSituation = temporarilyRemoveTrinket(nil, player, TrinketType.TRINKET_MYSTERIOUS_PAPER)
74
+ local willRevive = player:WillPlayerRevive() or trinketSituation ~= nil and ____exports.willMysteriousPaperRevive(nil, player)
75
+ giveTrinketsBack(nil, player, trinketSituation)
76
+ return willRevive
77
+ end
34
78
  return ____exports
@@ -13,6 +13,7 @@ local ____constants = require("constants")
13
13
  local GENESIS_ROOM_SUBTYPE = ____constants.GENESIS_ROOM_SUBTYPE
14
14
  local GENESIS_ROOM_VARIANT = ____constants.GENESIS_ROOM_VARIANT
15
15
  local MAX_ROOM_INDEX = ____constants.MAX_ROOM_INDEX
16
+ local NUM_DIMENSIONS = ____constants.NUM_DIMENSIONS
16
17
  local ____doors = require("functions.doors")
17
18
  local closeAllDoors = ____doors.closeAllDoors
18
19
  local getDoors = ____doors.getDoors
@@ -26,6 +27,8 @@ local setEntityPositions = ____entity.setEntityPositions
26
27
  local setEntityVelocities = ____entity.setEntityVelocities
27
28
  local ____flag = require("functions.flag")
28
29
  local hasFlag = ____flag.hasFlag
30
+ local ____math = require("functions.math")
31
+ local range = ____math.range
29
32
  function ____exports.getCurrentRoomDescriptorReadOnly(self)
30
33
  local game = Game()
31
34
  local level = game:GetLevel()
@@ -116,15 +119,11 @@ function ____exports.getCurrentDimension(self)
116
119
  local startingRoomGridIndex = level:GetStartingRoomIndex()
117
120
  local startingRoomDesc = level:GetRoomByIdx(startingRoomGridIndex, -1)
118
121
  local startingRoomHash = GetPtrHash(startingRoomDesc)
119
- do
120
- local dimension = 0
121
- while dimension <= 2 do
122
- local dimensionRoomDesc = level:GetRoomByIdx(startingRoomGridIndex, dimension)
123
- local dimensionRoomHash = GetPtrHash(dimensionRoomDesc)
124
- if dimensionRoomHash == startingRoomHash then
125
- return dimension
126
- end
127
- dimension = dimension + 1
122
+ for ____, dimension in ipairs(range(nil, 0, NUM_DIMENSIONS - 1)) do
123
+ local dimensionRoomDesc = level:GetRoomByIdx(startingRoomGridIndex, dimension)
124
+ local dimensionRoomHash = GetPtrHash(dimensionRoomDesc)
125
+ if dimensionRoomHash == startingRoomHash then
126
+ return dimension
128
127
  end
129
128
  end
130
129
  return error("Failed to get the current dimension using the starting room index of: " .. tostring(startingRoomGridIndex))
@@ -298,12 +297,12 @@ function ____exports.setRoomCleared(self)
298
297
  for ____, door in ipairs(getDoors(nil)) do
299
298
  do
300
299
  if isHiddenSecretRoomDoor(nil, door) then
301
- goto __continue55
300
+ goto __continue56
302
301
  end
303
302
  openDoorFast(nil, door)
304
303
  door.ExtraVisible = false
305
304
  end
306
- ::__continue55::
305
+ ::__continue56::
307
306
  end
308
307
  sfx:Stop(SoundEffect.SOUND_DOOR_HEAVY_OPEN)
309
308
  game:ShakeScreen(0)
@@ -10,6 +10,8 @@ local TRANSFORMATION_NAME_MAP = ____transformationNameMap.TRANSFORMATION_NAME_MA
10
10
  local ____collectibles = require("functions.collectibles")
11
11
  local collectibleHasTag = ____collectibles.collectibleHasTag
12
12
  local getMaxCollectibleID = ____collectibles.getMaxCollectibleID
13
+ local ____math = require("functions.math")
14
+ local range = ____math.range
13
15
  local ____set = require("functions.set")
14
16
  local copySet = ____set.copySet
15
17
  local TRANSFORMATION_TO_TAG_MAP = __TS__New(Map, {
@@ -38,31 +40,27 @@ local function initMaps(self)
38
40
  __TS__New(Set)
39
41
  )
40
42
  end
41
- do
42
- local collectibleType = 1
43
- while collectibleType <= maxCollectibleID do
44
- for ____, ____value in __TS__Iterator(TRANSFORMATION_TO_TAG_MAP:entries()) do
45
- local playerForm = ____value[1]
46
- local tag = ____value[2]
47
- do
48
- if not collectibleHasTag(nil, collectibleType, tag) then
49
- goto __continue6
50
- end
51
- local collectibleTypesSet = TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP:get(playerForm)
52
- if collectibleTypesSet == nil then
53
- error("Failed to get the collectible types for transformation: " .. tostring(playerForm))
54
- end
55
- collectibleTypesSet:add(collectibleType)
56
- local transformations = COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP:get(collectibleType)
57
- if transformations == nil then
58
- transformations = __TS__New(Set)
59
- COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP:set(collectibleType, transformations)
60
- end
61
- transformations:add(playerForm)
43
+ for ____, collectibleType in ipairs(range(nil, 1, maxCollectibleID)) do
44
+ for ____, ____value in __TS__Iterator(TRANSFORMATION_TO_TAG_MAP:entries()) do
45
+ local playerForm = ____value[1]
46
+ local tag = ____value[2]
47
+ do
48
+ if not collectibleHasTag(nil, collectibleType, tag) then
49
+ goto __continue6
62
50
  end
63
- ::__continue6::
51
+ local collectibleTypesSet = TRANSFORMATION_TO_COLLECTIBLE_TYPES_MAP:get(playerForm)
52
+ if collectibleTypesSet == nil then
53
+ error("Failed to get the collectible types for transformation: " .. tostring(playerForm))
54
+ end
55
+ collectibleTypesSet:add(collectibleType)
56
+ local transformations = COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP:get(collectibleType)
57
+ if transformations == nil then
58
+ transformations = __TS__New(Set)
59
+ COLLECTIBLE_TYPE_TO_TRANSFORMATION_MAP:set(collectibleType, transformations)
60
+ end
61
+ transformations:add(playerForm)
64
62
  end
65
- collectibleType = collectibleType + 1
63
+ ::__continue6::
66
64
  end
67
65
  end
68
66
  end
@@ -5,6 +5,8 @@ local __TS__New = ____lualib.__TS__New
5
5
  local Set = ____lualib.Set
6
6
  local __TS__Iterator = ____lualib.__TS__Iterator
7
7
  local ____exports = {}
8
+ local ____math = require("functions.math")
9
+ local range = ____math.range
8
10
  local ____set = require("functions.set")
9
11
  local copySet = ____set.copySet
10
12
  local ____trinkets = require("functions.trinkets")
@@ -17,13 +19,9 @@ local function initCacheFlagMap(self)
17
19
  local maxTrinketID = getMaxTrinketID(nil)
18
20
  for ____, cacheFlag in ipairs(getEnumValues(nil, CacheFlag)) do
19
21
  local trinketsSet = __TS__New(Set)
20
- do
21
- local trinketType = 1
22
- while trinketType <= maxTrinketID do
23
- if trinketHasCacheFlag(nil, trinketType, cacheFlag) then
24
- trinketsSet:add(trinketType)
25
- end
26
- trinketType = trinketType + 1
22
+ for ____, trinketType in ipairs(range(nil, 1, maxTrinketID)) do
23
+ if trinketHasCacheFlag(nil, trinketType, cacheFlag) then
24
+ trinketsSet:add(trinketType)
27
25
  end
28
26
  end
29
27
  CACHE_FLAG_TO_TRINKETS_MAP:set(cacheFlag, trinketsSet)
@@ -1,6 +1,6 @@
1
- declare type FactoryFunction<K, V> = (k: K) => V;
2
- declare type FirstArg<K, V> = Iterable<[K, V]> | V | FactoryFunction<K, V>;
3
- declare type SecondArg<K, V> = V | FactoryFunction<K, V>;
1
+ declare type FactoryFunction<K, V, A extends unknown[]> = (k: K, ...extraArgs: A) => V;
2
+ declare type FirstArg<K, V, A extends unknown[]> = Iterable<[K, V]> | V | FactoryFunction<K, V, A>;
3
+ declare type SecondArg<K, V, A extends unknown[]> = V | FactoryFunction<K, V, A>;
4
4
  /**
5
5
  * An extended Map with some new methods:
6
6
  *
@@ -31,36 +31,44 @@ declare type SecondArg<K, V> = V | FactoryFunction<K, V>;
31
31
  * ], "bar");
32
32
  * ```
33
33
  *
34
- * If specified, the first argument of a factory function must be equal to the key:
34
+ * If specified, the first argument of a factory function must always be equal to the key:
35
35
  *
36
36
  * ```ts
37
37
  * const defaultMapWithConditionalDefaultValue = new DefaultMap<number, number>((key: number) => {
38
38
  * return isOdd(key) ? 0 : 1;
39
39
  * });
40
40
  * ```
41
+ *
42
+ * You can also specify a factory function that takes a generic amount of arguments beyond the
43
+ * first:
44
+ *
45
+ * ```ts
46
+ * const factoryFunction = (_key: string, arg2: boolean) => arg2 ? 0 : 1;
47
+ * const defaultMapWithExtraArgs = new DefaultMap<string, string, [arg2: boolean]>(factoryFunction);
48
+ * ```
41
49
  */
42
- export declare class DefaultMap<K, V> extends Map<K, V> {
50
+ export declare class DefaultMap<K, V, A extends unknown[] = []> extends Map<K, V> {
43
51
  private defaultValue;
44
52
  private defaultValueFactory;
45
53
  /**
46
54
  * See the DefaultMap documentation:
47
55
  * https://isaacscript.github.io/isaacscript-common/classes/types_DefaultMap.DefaultMap.html
48
56
  */
49
- constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V>, defaultValueOrDefaultValueFactory?: SecondArg<K, V>);
57
+ constructor(iterableOrDefaultValueOrDefaultValueFactory: FirstArg<K, V, A>, defaultValueOrDefaultValueFactory?: SecondArg<K, V, A>);
50
58
  /**
51
59
  * If the key exists, this will return the same thing as the `get` method. Otherwise, it will set
52
60
  * a default value to the key, and then return the default value.
53
61
  */
54
- getAndSetDefault(key: K): V;
62
+ getAndSetDefault(key: K, ...extraArgs: A): V;
55
63
  /**
56
64
  * Returns the default value to be used for a new key. (If a factory function was provided during
57
65
  * instantiation, this will execute the factory function.)
58
66
  */
59
- getDefaultValue(key: K): V;
67
+ getDefaultValue(key: K, ...extraArgs: A): V;
60
68
  /**
61
69
  * Helper method for cloning the map. Returns either the default value or a reference to the
62
70
  * factory function.
63
71
  */
64
- getConstructorArg(): V | FactoryFunction<K, V>;
72
+ getConstructorArg(): V | FactoryFunction<K, V, A>;
65
73
  }
66
74
  export {};
@@ -55,21 +55,21 @@ function DefaultMap.prototype.____constructor(self, iterableOrDefaultValueOrDefa
55
55
  self.defaultValue = defaultValue
56
56
  self.defaultValueFactory = defaultValueFactory
57
57
  end
58
- function DefaultMap.prototype.getAndSetDefault(self, key)
58
+ function DefaultMap.prototype.getAndSetDefault(self, key, ...)
59
59
  local value = self:get(key)
60
60
  if value ~= nil then
61
61
  return value
62
62
  end
63
- local defaultValue = self:getDefaultValue(key)
63
+ local defaultValue = self:getDefaultValue(key, ...)
64
64
  self:set(key, defaultValue)
65
65
  return defaultValue
66
66
  end
67
- function DefaultMap.prototype.getDefaultValue(self, key)
67
+ function DefaultMap.prototype.getDefaultValue(self, key, ...)
68
68
  if self.defaultValue ~= nil then
69
69
  return self.defaultValue
70
70
  end
71
71
  if self.defaultValueFactory ~= nil then
72
- return self:defaultValueFactory(key)
72
+ return self:defaultValueFactory(key, ...)
73
73
  end
74
74
  return error("A DefaultMap was incorrectly instantiated.")
75
75
  end
@@ -1,7 +1,7 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  import { PocketItemType } from "./PocketItemType";
3
3
  export interface PocketItemDescription {
4
- type: PocketItemType;
5
- id: int;
6
4
  slot: PocketItemSlot;
5
+ type: PocketItemType;
6
+ subType: int;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.62",
3
+ "version": "1.2.65",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -27,7 +27,7 @@
27
27
  "devDependencies": {
28
28
  "@zamiell/typescript-to-lua": "^1.4.0",
29
29
  "isaac-typescript-definitions": "^1.0.349",
30
- "isaacscript-lint": "^1.0.79",
30
+ "isaacscript-lint": "^1.0.81",
31
31
  "isaacscript-tsconfig": "^1.1.8",
32
32
  "typedoc": "^0.22.12",
33
33
  "typescript": "^4.5.5"