isaacscript-common 6.4.0 → 6.5.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.
@@ -77,10 +77,13 @@ end
77
77
  function ____exports.isRepentanceDoor(self, door)
78
78
  return door.TargetRoomIndex == GridRoom.SECRET_EXIT
79
79
  end
80
+ --- This refers to the hole in the wall that appears after bombing the entrance to a secret room.
81
+ -- Note that the door still exists before it has been bombed open. It has a sprite filename of
82
+ -- "gfx/grid/door_08_holeinwall.anm2".
80
83
  function ____exports.isSecretRoomDoor(self, door)
81
84
  local sprite = door:GetSprite()
82
85
  local filename = sprite:GetFilename()
83
- return filename == "gfx/grid/Door_08_HoleInWall.anm2"
86
+ return filename == "gfx/grid/door_08_holeinwall.anm2"
84
87
  end
85
88
  --- Helper function to remove a single door.
86
89
  function ____exports.removeDoor(self, door)
@@ -234,54 +237,54 @@ function ____exports.isDoorSlotInRoomShape(self, doorSlot, roomShape)
234
237
  return doorSlots:has(doorSlot)
235
238
  end
236
239
  --- This refers to the Repentance door that spawns in a boss room after defeating the boss. You have
237
- -- to spend one key to open it. It has a sprite filename of "gfx/grid/Door_Downpour.anm2".
240
+ -- to spend one key to open it. It has a sprite filename of "gfx/grid/door_downpour.anm2".
238
241
  function ____exports.isDoorToDownpour(self, door)
239
242
  if not ____exports.isRepentanceDoor(nil, door) then
240
243
  return false
241
244
  end
242
245
  local sprite = door:GetSprite()
243
246
  local filename = sprite:GetFilename()
244
- return filename == "gfx/grid/Door_Downpour.anm2"
247
+ return string.lower(filename) == "gfx/grid/door_downpour.anm2"
245
248
  end
246
249
  --- This refers to the Repentance door that spawns in a boss room after defeating the boss. You have
247
- -- to spend two hearts to open it. It has a sprite filename of "gfx/grid/Door_Mausoleum.anm2".
250
+ -- to spend two hearts to open it. It has a sprite filename of "gfx/grid/door_mausoleum.anm2".
248
251
  function ____exports.isDoorToMausoleum(self, door)
249
252
  if not ____exports.isRepentanceDoor(nil, door) then
250
253
  return false
251
254
  end
252
255
  local sprite = door:GetSprite()
253
256
  local filename = sprite:GetFilename()
254
- return filename == "gfx/grid/Door_Mausoleum.anm2"
257
+ return string.lower(filename) == "gfx/grid/door_mausoleum.anm2"
255
258
  end
256
259
  --- This refers to the "strange door" located on the first room of Depths 2. You open it with either
257
- -- a Polaroid or a Negative. It has a sprite filename of "gfx/grid/Door_Mausoleum_Alt.anm2".
260
+ -- a Polaroid or a Negative. It has a sprite filename of "gfx/grid/door_mausoleum_alt.anm2".
258
261
  function ____exports.isDoorToMausoleumAscent(self, door)
259
262
  if not ____exports.isRepentanceDoor(nil, door) then
260
263
  return false
261
264
  end
262
265
  local sprite = door:GetSprite()
263
266
  local filename = sprite:GetFilename()
264
- return filename == "gfx/grid/Door_Mausoleum_Alt.anm2"
267
+ return string.lower(filename) == "gfx/grid/door_mausoleum_alt.anm2"
265
268
  end
266
269
  --- This refers to the Repentance door that spawns in a boss room after defeating the boss. You have
267
- -- to spend two bombs to open it. It has a sprite filename of "gfx/grid/Door_Mines.anm2".
270
+ -- to spend two bombs to open it. It has a sprite filename of "gfx/grid/door_mines.anm2".
268
271
  function ____exports.isDoorToMines(self, door)
269
272
  if not ____exports.isRepentanceDoor(nil, door) then
270
273
  return false
271
274
  end
272
275
  local sprite = door:GetSprite()
273
276
  local filename = sprite:GetFilename()
274
- return filename == "gfx/grid/Door_Mines.anm2"
277
+ return string.lower(filename) == "gfx/grid/door_mines.anm2"
275
278
  end
276
279
  --- This refers to the Repentance door that spawns after defeating Mom. You open it with the
277
- -- completed knife. It has a sprite filename of "gfx/grid/Door_MomsHeart.anm2".
280
+ -- completed knife. It has a sprite filename of "gfx/grid/door_momsheart.anm2".
278
281
  function ____exports.isDoorToMomsHeart(self, door)
279
282
  if not ____exports.isRepentanceDoor(nil, door) then
280
283
  return false
281
284
  end
282
285
  local sprite = door:GetSprite()
283
286
  local filename = sprite:GetFilename()
284
- return filename == "gfx/grid/Door_MomsHeart.anm2"
287
+ return filename == "gfx/grid/door_momsheart.anm2"
285
288
  end
286
289
  function ____exports.isHiddenSecretRoomDoor(self, door)
287
290
  local sprite = door:GetSprite()
@@ -1,4 +1,5 @@
1
1
  import { GridEntityType, GridEntityXMLType } from "isaac-typescript-definitions";
2
+ import { RockAltType } from "../enums/RockAltType";
2
3
  /**
3
4
  * Helper function to convert the grid entity type found in a room XML file to the corresponding
4
5
  * grid entity type and variant normally used by the game. For example, a rock is represented as
@@ -71,6 +72,21 @@ export declare function getGridEntityIDFromConstituents(gridEntityType: GridEnti
71
72
  * variant provided.
72
73
  */
73
74
  export declare function getMatchingGridEntities(gridEntityType: GridEntityType, variant: int): GridEntity[];
75
+ /**
76
+ * Helper function to get the alternate rock type (i.e. urn, mushroom, etc.) that the current room
77
+ * will have.
78
+ *
79
+ * The rock type is based on the backdrop of the room.
80
+ *
81
+ * For example, if you change the backdrop of the starting room of the run to `BackdropType.CAVES`,
82
+ * and then spawn `GridEntityType.ROCK_ALT`, it will be a mushroom instead of an urn. Additionally,
83
+ * if it is destroyed, it will generate mushroom-appropriate rewards.
84
+ *
85
+ * On the other hand, if an urn is spawned first before the backdrop is changed to
86
+ * `BackdropType.CAVES`, the graphic of the urn will not switch to a mushroom. However, when
87
+ * destroyed, the urn will still generate mushroom-appropriate rewards.
88
+ */
89
+ export declare function getRockAltType(): RockAltType;
74
90
  export declare function getSurroundingGridEntities(gridEntity: GridEntity): GridEntity[];
75
91
  export declare function getTopLeftWall(): GridEntity | undefined;
76
92
  /**
@@ -178,6 +194,24 @@ export declare function spawnGrid(gridEntityType: GridEntityType, gridIndexOrPos
178
194
  * - allows you to specify the grid index or the position
179
195
  */
180
196
  export declare function spawnGridWithVariant(gridEntityType: GridEntityType, variant: int, gridIndexOrPosition: int | Vector): GridEntity | undefined;
197
+ /**
198
+ * Helper function for emulating what happens when a vanilla `GridEntityType.ROCK_ALT` grid entity
199
+ * breaks.
200
+ *
201
+ * Note that most of the time, this function will do nothing, similar to how most of the time, when
202
+ * an individual urn is destroyed, nothing will spawn.
203
+ *
204
+ * The logic in this function is based on the rewards listed on the wiki:
205
+ * https://bindingofisaacrebirth.fandom.com/wiki/Rocks
206
+ *
207
+ * @param rockAltType The type of reward to spawn. For example, `RockAltType.URN` will have a chance
208
+ * at spawning coins and spiders.
209
+ * @param _seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided,
210
+ * the `RNG.Next` method will be called. Default is `getRandomSeed()`. Normally,
211
+ * you should pass the `InitSeed` of the grid entity that was broken.
212
+ * @returns Whether or not this function spawned something.
213
+ */
214
+ export declare function spawnRockAltReward(rockAltType: RockAltType, _seedOrRNG?: Seed | RNG): boolean;
181
215
  /**
182
216
  * Helper function to spawn a Void Portal. This is more complicated than simply spawning a trapdoor
183
217
  * with the appropriate variant, as the game does not give it the correct sprite automatically.
@@ -15,6 +15,8 @@ local ____cachedClasses = require("cachedClasses")
15
15
  local game = ____cachedClasses.game
16
16
  local ____constants = require("constants")
17
17
  local DISTANCE_OF_GRID_TILE = ____constants.DISTANCE_OF_GRID_TILE
18
+ local ____RockAltType = require("enums.RockAltType")
19
+ local RockAltType = ____RockAltType.RockAltType
18
20
  local ____gridEntityTypeToBrokenStateMap = require("maps.gridEntityTypeToBrokenStateMap")
19
21
  local GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP = ____gridEntityTypeToBrokenStateMap.GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP
20
22
  local ____gridEntityXMLMap = require("maps.gridEntityXMLMap")
@@ -22,8 +24,12 @@ local GRID_ENTITY_XML_MAP = ____gridEntityXMLMap.GRID_ENTITY_XML_MAP
22
24
  local ____roomShapeToTopLeftWallGridIndexMap = require("maps.roomShapeToTopLeftWallGridIndexMap")
23
25
  local DEFAULT_TOP_LEFT_WALL_GRID_INDEX = ____roomShapeToTopLeftWallGridIndexMap.DEFAULT_TOP_LEFT_WALL_GRID_INDEX
24
26
  local ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP = ____roomShapeToTopLeftWallGridIndexMap.ROOM_SHAPE_TO_TOP_LEFT_WALL_GRID_INDEX_MAP
27
+ local ____backdropTypeToRockAltType = require("objects.backdropTypeToRockAltType")
28
+ local BACKDROP_TYPE_TO_ROCK_ALT_TYPE = ____backdropTypeToRockAltType.BACKDROP_TYPE_TO_ROCK_ALT_TYPE
25
29
  local ____math = require("functions.math")
26
30
  local isCircleIntersectingRectangle = ____math.isCircleIntersectingRectangle
31
+ local ____rng = require("functions.rng")
32
+ local getRandomSeed = ____rng.getRandomSeed
27
33
  local ____rooms = require("functions.rooms")
28
34
  local roomUpdateSafe = ____rooms.roomUpdateSafe
29
35
  local ____sprite = require("functions.sprite")
@@ -255,6 +261,23 @@ function ____exports.getMatchingGridEntities(self, gridEntityType, variant)
255
261
  function(____, gridEntity) return gridEntity:GetVariant() == variant end
256
262
  )
257
263
  end
264
+ --- Helper function to get the alternate rock type (i.e. urn, mushroom, etc.) that the current room
265
+ -- will have.
266
+ --
267
+ -- The rock type is based on the backdrop of the room.
268
+ --
269
+ -- For example, if you change the backdrop of the starting room of the run to `BackdropType.CAVES`,
270
+ -- and then spawn `GridEntityType.ROCK_ALT`, it will be a mushroom instead of an urn. Additionally,
271
+ -- if it is destroyed, it will generate mushroom-appropriate rewards.
272
+ --
273
+ -- On the other hand, if an urn is spawned first before the backdrop is changed to
274
+ -- `BackdropType.CAVES`, the graphic of the urn will not switch to a mushroom. However, when
275
+ -- destroyed, the urn will still generate mushroom-appropriate rewards.
276
+ function ____exports.getRockAltType(self)
277
+ local room = game:GetRoom()
278
+ local backdropType = room:GetBackdropType()
279
+ return BACKDROP_TYPE_TO_ROCK_ALT_TYPE[backdropType]
280
+ end
258
281
  function ____exports.getSurroundingGridEntities(self, gridEntity)
259
282
  local room = game:GetRoom()
260
283
  local gridWidth = room:GetGridWidth()
@@ -400,6 +423,59 @@ end
400
423
  function ____exports.spawnGrid(self, gridEntityType, gridIndexOrPosition)
401
424
  return ____exports.spawnGridWithVariant(nil, gridEntityType, 0, gridIndexOrPosition)
402
425
  end
426
+ --- Helper function for emulating what happens when a vanilla `GridEntityType.ROCK_ALT` grid entity
427
+ -- breaks.
428
+ --
429
+ -- Note that most of the time, this function will do nothing, similar to how most of the time, when
430
+ -- an individual urn is destroyed, nothing will spawn.
431
+ --
432
+ -- The logic in this function is based on the rewards listed on the wiki:
433
+ -- https://bindingofisaacrebirth.fandom.com/wiki/Rocks
434
+ --
435
+ -- @param rockAltType The type of reward to spawn. For example, `RockAltType.URN` will have a chance
436
+ -- at spawning coins and spiders.
437
+ -- @param _seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided,
438
+ -- the `RNG.Next` method will be called. Default is `getRandomSeed()`. Normally,
439
+ -- you should pass the `InitSeed` of the grid entity that was broken.
440
+ -- @returns Whether or not this function spawned something.
441
+ function ____exports.spawnRockAltReward(self, rockAltType, _seedOrRNG)
442
+ if _seedOrRNG == nil then
443
+ _seedOrRNG = getRandomSeed(nil)
444
+ end
445
+ repeat
446
+ local ____switch56 = rockAltType
447
+ local ____cond56 = ____switch56 == RockAltType.URN
448
+ if ____cond56 then
449
+ do
450
+ return false
451
+ end
452
+ end
453
+ ____cond56 = ____cond56 or ____switch56 == RockAltType.MUSHROOM
454
+ if ____cond56 then
455
+ do
456
+ return false
457
+ end
458
+ end
459
+ ____cond56 = ____cond56 or ____switch56 == RockAltType.SKULL
460
+ if ____cond56 then
461
+ do
462
+ return false
463
+ end
464
+ end
465
+ ____cond56 = ____cond56 or ____switch56 == RockAltType.POLYP
466
+ if ____cond56 then
467
+ do
468
+ return false
469
+ end
470
+ end
471
+ ____cond56 = ____cond56 or ____switch56 == RockAltType.BUCKET
472
+ if ____cond56 then
473
+ do
474
+ return false
475
+ end
476
+ end
477
+ until true
478
+ end
403
479
  --- Helper function to spawn a Void Portal. This is more complicated than simply spawning a trapdoor
404
480
  -- with the appropriate variant, as the game does not give it the correct sprite automatically.
405
481
  function ____exports.spawnVoidPortal(self, gridIndex)
@@ -1,29 +1,29 @@
1
1
  import { BatterySubType, Card, CoinSubType, CollectibleType, HeartSubType, KeySubType, PillColor, SackSubType, TrinketType } from "isaac-typescript-definitions";
2
2
  /** Helper function to get all of the battery entities in the room. */
3
- export declare function getBatteries(matchingSubType?: number): EntityPickupBattery[];
3
+ export declare function getBatteries(matchingSubType?: BatterySubType | -1): EntityPickupBattery[];
4
4
  /** Helper function to get all of the card entities in the room. */
5
- export declare function getCards(matchingSubType?: number): EntityPickupCard[];
5
+ export declare function getCards(matchingSubType?: Card | -1): EntityPickupCard[];
6
6
  /**
7
7
  * Helper function to get the corresponding coin amount from a `CoinSubType`. Returns 1 for modded
8
8
  * sub-types.
9
9
  */
10
10
  export declare function getCoinValue(coinSubType: CoinSubType): int;
11
11
  /** Helper function to get all of the coin pickup entities in the room. */
12
- export declare function getCoins(matchingSubType?: number): EntityPickupCoin[];
12
+ export declare function getCoins(matchingSubType?: CoinSubType | -1): EntityPickupCoin[];
13
13
  /** Helper function to get all of the collectible entities in the room. */
14
- export declare function getCollectibles(matchingSubType?: number): EntityPickupCollectible[];
14
+ export declare function getCollectibles(matchingSubType?: CollectibleType | -1): EntityPickupCollectible[];
15
15
  /** Helper function to get all of the heart pickup entities in the room. */
16
- export declare function getHearts(matchingSubType?: number): EntityPickupHeart[];
16
+ export declare function getHearts(matchingSubType?: HeartSubType | -1): EntityPickupHeart[];
17
17
  /** Helper function to get all of the key pickup entities in the room. */
18
- export declare function getKeys(matchingSubType?: number): EntityPickupKey[];
18
+ export declare function getKeys(matchingSubType?: KeySubType | -1): EntityPickupKey[];
19
19
  /** Helper function to get all of the pill entities in the room. */
20
- export declare function getPills(matchingSubType?: number): EntityPickupPill[];
20
+ export declare function getPills(matchingSubType?: PillColor | -1): EntityPickupPill[];
21
21
  /** Helper function to get all of the red heart pickup entities in the room. */
22
22
  export declare function getRedHearts(): EntityPickupHeart[];
23
23
  /** Helper function to get all of the sack (i.e. grab bag) entities in the room. */
24
- export declare function getSacks(matchingSubType?: number): EntityPickupSack[];
24
+ export declare function getSacks(matchingSubType?: SackSubType | -1): EntityPickupSack[];
25
25
  /** Helper function to get all of the trinket entities in the room. */
26
- export declare function getTrinkets(matchingSubType?: number): EntityPickupTrinket[];
26
+ export declare function getTrinkets(matchingSubType?: TrinketType | -1): EntityPickupTrinket[];
27
27
  export declare function isChest(pickup: EntityPickup): boolean;
28
28
  export declare function isRedHeart(pickup: EntityPickup): boolean;
29
29
  /**
@@ -13,3 +13,10 @@ export declare function onSetSeed(): boolean;
13
13
  * You can optionally specify a `PlayerType` to restart the game as that character.
14
14
  */
15
15
  export declare function restart(character?: PlayerType): void;
16
+ /**
17
+ * Helper function to change the run status to that of an unseeded run with a new random seed.
18
+ *
19
+ * This is useful to revert the behavior where playing on a set and restarting the game will not
20
+ * take you to a new seed.
21
+ */
22
+ export declare function setUnseeded(): void;
package/functions/run.lua CHANGED
@@ -1,6 +1,7 @@
1
1
  local ____exports = {}
2
2
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
3
3
  local Challenge = ____isaac_2Dtypescript_2Ddefinitions.Challenge
4
+ local PlayerType = ____isaac_2Dtypescript_2Ddefinitions.PlayerType
4
5
  local ____cachedClasses = require("cachedClasses")
5
6
  local game = ____cachedClasses.game
6
7
  local ____constantsFirstLast = require("constantsFirstLast")
@@ -23,14 +24,25 @@ end
23
24
  -- You can optionally specify a `PlayerType` to restart the game as that character.
24
25
  function ____exports.restart(self, character)
25
26
  if character == nil then
26
- log("Restarting.")
27
- Isaac.ExecuteCommand("restart")
27
+ local command = "restart"
28
+ log("Restarting the run with a console command of: " .. command)
29
+ Isaac.ExecuteCommand(command)
28
30
  return
29
31
  end
30
32
  if character < FIRST_CHARACTER then
31
33
  error(("Restarting as a character of " .. tostring(character)) .. " would crash the game.")
32
34
  end
33
- log("Restarting as character: " .. tostring(character))
34
- Isaac.ExecuteCommand("restart " .. tostring(character))
35
+ local command = "restart " .. tostring(character)
36
+ log((((("Restarting the run as PlayerType." .. tostring(PlayerType[character])) .. " (") .. tostring(character)) .. ") with a console command of: ") .. command)
37
+ Isaac.ExecuteCommand(command)
38
+ end
39
+ --- Helper function to change the run status to that of an unseeded run with a new random seed.
40
+ --
41
+ -- This is useful to revert the behavior where playing on a set and restarting the game will not
42
+ -- take you to a new seed.
43
+ function ____exports.setUnseeded(self)
44
+ local seeds = game:GetSeeds()
45
+ seeds:Reset()
46
+ seeds:Restart(Challenge.NULL)
35
47
  end
36
48
  return ____exports