isaacscript-common 1.2.276 → 1.2.279

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.
@@ -44,8 +44,9 @@ export declare function isSin(npc: EntityNPC): boolean;
44
44
  * Use this function instead of `spawnNPC` since it handles automatically spawning multiple segments
45
45
  * for multi-segment bosses.
46
46
  *
47
- * By default, this will spawn Chub (and his variants) with 3 segments and other multi-segment
48
- * bosses with 4 segments. You can customize this via the "numSegments" argument.
47
+ * By default, this will spawn Chub (and his variants) with 3 segments, Lokii with 2 copies,
48
+ * Gurglings/Turdlings with 2 copies, and other multi-segment bosses with 4 segments. You can
49
+ * customize this via the "numSegments" argument.
49
50
  */
50
51
  export declare function spawnBoss<T extends number>(entityType: T extends EntityTypeNonNPC ? never : T, variant: int, subType: int, position: Vector, velocity?: Readonly<Vector>, spawner?: Entity | undefined, seed?: Seed | undefined, numSegments?: int): EntityNPC;
51
52
  /**
@@ -3,6 +3,7 @@ local Set = ____lualib.Set
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
5
5
  local ____exports = {}
6
+ local getNumBossSegments, DEFAULT_BOSS_MULTI_SEGMENTS
6
7
  local ____constants = require("constants")
7
8
  local VectorZero = ____constants.VectorZero
8
9
  local ____bossSets = require("sets.bossSets")
@@ -20,7 +21,45 @@ local ____set = require("functions.set")
20
21
  local copySet = ____set.copySet
21
22
  local ____utils = require("functions.utils")
22
23
  local ____repeat = ____utils["repeat"]
23
- local BOSSES_THAT_REQUIRE_MULTIPLE_SPAWNS = __TS__New(Set, {EntityType.ENTITY_LARRYJR, EntityType.ENTITY_CHUB, EntityType.ENTITY_TURDLET})
24
+ function getNumBossSegments(self, entityType, variant, numSegments)
25
+ if numSegments ~= nil then
26
+ return numSegments
27
+ end
28
+ repeat
29
+ local ____switch18 = entityType
30
+ local ____cond18 = ____switch18 == EntityType.ENTITY_CHUB
31
+ if ____cond18 then
32
+ do
33
+ return 3
34
+ end
35
+ end
36
+ ____cond18 = ____cond18 or ____switch18 == EntityType.ENTITY_LOKI
37
+ if ____cond18 then
38
+ do
39
+ return variant == 1 and 2 or 1
40
+ end
41
+ end
42
+ ____cond18 = ____cond18 or ____switch18 == EntityType.ENTITY_GURGLING
43
+ if ____cond18 then
44
+ do
45
+ return 2
46
+ end
47
+ end
48
+ do
49
+ do
50
+ return DEFAULT_BOSS_MULTI_SEGMENTS
51
+ end
52
+ end
53
+ until true
54
+ end
55
+ local BOSSES_THAT_REQUIRE_MULTIPLE_SPAWNS = __TS__New(Set, {
56
+ EntityType.ENTITY_LARRYJR,
57
+ EntityType.ENTITY_CHUB,
58
+ EntityType.ENTITY_LOKI,
59
+ EntityType.ENTITY_GURGLING,
60
+ EntityType.ENTITY_TURDLET
61
+ })
62
+ DEFAULT_BOSS_MULTI_SEGMENTS = 4
24
63
  function ____exports.getAliveBosses(self, matchingEntityType, matchingVariant, matchingSubType, ignoreFriendly)
25
64
  if ignoreFriendly == nil then
26
65
  ignoreFriendly = false
@@ -98,9 +137,8 @@ function ____exports.spawnBoss(self, entityType, variant, subType, position, vel
98
137
  seed
99
138
  )
100
139
  if BOSSES_THAT_REQUIRE_MULTIPLE_SPAWNS:has(entityType) then
101
- local numSegmentsDefined = numSegments == nil and 4 or numSegments
102
- local numSegmentsToUse = entityType == EntityType.ENTITY_CHUB and 3 or numSegmentsDefined
103
- local remainingSegmentsToSpawn = numSegmentsToUse - 1
140
+ local numBossSegments = getNumBossSegments(nil, entityType, variant, numSegments)
141
+ local remainingSegmentsToSpawn = numBossSegments - 1
104
142
  ____repeat(
105
143
  nil,
106
144
  remainingSegmentsToSpawn,
@@ -5,9 +5,9 @@ import { AnyEntity } from "../types/AnyEntity";
5
5
  * `Isaac.CountEntities` method to avoid having to specify a spawner and to handle ignoring charmed
6
6
  * enemies.
7
7
  *
8
- * @param entityType Default is -1.
9
- * @param variant Default is -1.
10
- * @param subType Default is -1.
8
+ * @param entityType Default is -1. -1 matches every entity type.
9
+ * @param variant Default is -1. -1 matches every variant.
10
+ * @param subType Default is -1. -1 matches every sub-type.
11
11
  * @param ignoreFriendly Default is false.
12
12
  */
13
13
  export declare function countEntities(entityType?: EntityType | int, variant?: number, subType?: number, ignoreFriendly?: boolean): int;
@@ -41,8 +41,10 @@ export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity:
41
41
  *
42
42
  * @param entityType Optional. If specified, will only return NPCs that match this entity
43
43
  * type.
44
- * @param variant Optional. If specified, will only return NPCs that match this variant.
45
- * @param subType Optional. If specified, will only return NPCs that match this sub-type.
44
+ * @param variant Optional. If specified, will only return NPCs that match this variant. Default is
45
+ * -1. -1 matches every variant.
46
+ * @param subType Optional. If specified, will only return NPCs that match this sub-type. Default is
47
+ * -1. -1 matches every sub-type.
46
48
  * @param ignoreFriendly Optional. If set to true, it will exclude friendly NPCs from being
47
49
  * returned. Default is false. Will only be taken into account if `matchingEntityType` is specified.
48
50
  */
@@ -89,10 +91,8 @@ export declare function parseEntityTypeVariantString(entityTypeVariantString: st
89
91
  * Helper function to remove all of the matching entities in the room.
90
92
  *
91
93
  * @param entityType The entity type to match.
92
- * @param entityVariant Optional. The variant to match. Default is -1 (which will match every
93
- * variant).
94
- * @param entitySubType Optional. The sub-type to match. Default is -1 (which will match every
95
- * sub-type).
94
+ * @param entityVariant Optional. The variant to match. Default is -1. -1 matches every variant.
95
+ * @param entitySubType Optional. The sub-type to match. Default is -1. -1 matches every sub-type.
96
96
  * @param cap Optional. If specified, will only remove the given amount of collectibles.
97
97
  * @returns True if one or more entities were removed, false otherwise.
98
98
  */
@@ -82,14 +82,14 @@ function ____exports.logFlags(flags, flagEnum, description)
82
82
  for key, value in pairs(flagEnum) do
83
83
  do
84
84
  if type(value) ~= "number" then
85
- goto __continue42
85
+ goto __continue43
86
86
  end
87
87
  if hasFlag(nil, flags, value) then
88
88
  ____exports.log((((" Has flag: " .. tostring(key)) .. " (") .. tostring(value)) .. ")")
89
89
  hasNoFlags = false
90
90
  end
91
91
  end
92
- ::__continue42::
92
+ ::__continue43::
93
93
  end
94
94
  if hasNoFlags then
95
95
  ____exports.log(" n/a (no flags)")
@@ -143,15 +143,13 @@ function ____exports.logEffects(player)
143
143
  )
144
144
  end
145
145
  function ____exports.logEntities(includeBackgroundEffects, entityTypeFilter)
146
- local headerMsg = "Entities in the room"
146
+ local msg = "Entities in the room"
147
147
  if entityTypeFilter ~= nil then
148
- headerMsg = headerMsg .. (" (filtered to entity type " .. tostring(entityTypeFilter)) .. ")"
148
+ msg = msg .. (" (filtered to entity type " .. tostring(entityTypeFilter)) .. ")"
149
+ elseif not includeBackgroundEffects then
150
+ msg = msg .. " (not including background effects)"
149
151
  end
150
- if not includeBackgroundEffects then
151
- headerMsg = headerMsg .. " (not excluding background effects)"
152
- end
153
- headerMsg = headerMsg .. ":"
154
- ____exports.log(headerMsg)
152
+ msg = msg .. ":\n"
155
153
  local entities = getEntities(nil)
156
154
  local numMatchedEntities = 0
157
155
  __TS__ArrayForEach(
@@ -164,62 +162,70 @@ function ____exports.logEntities(includeBackgroundEffects, entityTypeFilter)
164
162
  return
165
163
  end
166
164
  local entityID = getEntityID(nil, entity)
167
- local debugString = (tostring(i + 1) .. " - ") .. entityID
165
+ msg = msg .. (tostring(i + 1) .. ") ") .. entityID
168
166
  local bomb = entity:ToBomb()
169
167
  if bomb ~= nil then
170
- debugString = debugString .. " (bomb)"
168
+ msg = msg .. " (bomb)"
171
169
  end
172
170
  local effect = entity:ToEffect()
173
171
  if effect ~= nil then
174
- debugString = debugString .. (" (effect) (State: " .. tostring(effect.State)) .. ")"
172
+ msg = msg .. (" (effect) (State: " .. tostring(effect.State)) .. ")"
175
173
  end
176
174
  local familiar = entity:ToFamiliar()
177
175
  if familiar ~= nil then
178
- debugString = debugString .. (" (familiar) (State: " .. tostring(familiar.State)) .. ")"
176
+ msg = msg .. (" (familiar) (State: " .. tostring(familiar.State)) .. ")"
179
177
  end
180
178
  local knife = entity:ToKnife()
181
179
  if knife ~= nil then
182
- debugString = debugString .. " (knife)"
180
+ msg = msg .. " (knife)"
183
181
  end
184
182
  local laser = entity:ToLaser()
185
183
  if laser ~= nil then
186
- debugString = debugString .. " (laser)"
184
+ msg = msg .. " (laser)"
187
185
  end
188
186
  local npc = entity:ToNPC()
189
187
  if npc ~= nil then
190
- debugString = debugString .. (((" (NPC) (State: " .. tostring(npc.State)) .. ") (CanShutDoors: ") .. tostring(npc.CanShutDoors)) .. ")"
188
+ msg = msg .. (" (NPC) (State: " .. tostring(npc.State)) .. ")"
191
189
  end
192
190
  local pickup = entity:ToPickup()
193
191
  if pickup ~= nil then
194
- debugString = debugString .. (" (pickup) (State: " .. tostring(pickup.State)) .. ")"
192
+ msg = msg .. (" (pickup) (State: " .. tostring(pickup.State)) .. ")"
195
193
  end
196
194
  local player = entity:ToPlayer()
197
195
  if player ~= nil then
198
- debugString = debugString .. " (player)"
196
+ msg = msg .. " (player)"
199
197
  end
200
198
  local projectile = entity:ToProjectile()
201
199
  if projectile ~= nil then
202
- debugString = debugString .. " (projectile)"
200
+ msg = msg .. " (projectile)"
203
201
  end
204
202
  local tear = entity:ToTear()
205
203
  if tear ~= nil then
206
- debugString = debugString .. " (tear)"
204
+ msg = msg .. " (tear)"
205
+ end
206
+ msg = msg .. "\n"
207
+ msg = msg .. (" - Index: " .. tostring(entity.Index)) .. "\n"
208
+ msg = msg .. (" - InitSeed: " .. tostring(entity.InitSeed)) .. "\n"
209
+ msg = msg .. (" - DropSeed: " .. tostring(entity.DropSeed)) .. "\n"
210
+ msg = msg .. (((" - Position: (" .. tostring(entity.Position.X)) .. ", ") .. tostring(entity.Position.Y)) .. ")\n"
211
+ msg = msg .. (((" - Velocity: (" .. tostring(entity.Velocity.X)) .. ", ") .. tostring(entity.Velocity.Y)) .. ")\n"
212
+ msg = msg .. (((" - HP: " .. tostring(entity.HitPoints)) .. " / ") .. tostring(entity.MaxHitPoints)) .. "\n"
213
+ msg = msg .. (" - Parent: " .. tostring(entity.Parent)) .. "\n"
214
+ msg = msg .. (" - Child: " .. tostring(entity.Child)) .. "\n"
215
+ msg = msg .. (" - SpawnerEntity: " .. tostring(entity.SpawnerEntity)) .. "\n"
216
+ msg = msg .. (((" - SpawnerType / SpawnerVariant: " .. tostring(entity.SpawnerType)) .. ".") .. tostring(entity.SpawnerVariant)) .. "\n"
217
+ if npc ~= nil then
218
+ msg = msg .. (" - CanShutDoors: " .. tostring(npc.CanShutDoors)) .. "\n"
207
219
  end
208
- debugString = debugString .. (" (Index: " .. tostring(entity.Index)) .. ")"
209
- debugString = debugString .. (" (InitSeed: " .. tostring(entity.InitSeed)) .. ")"
210
- debugString = debugString .. (" (DropSeed: " .. tostring(entity.DropSeed)) .. ")"
211
- debugString = debugString .. (((" (Position: " .. tostring(entity.Position.X)) .. ", ") .. tostring(entity.Position.Y)) .. ")"
212
- debugString = debugString .. (((" (Velocity: " .. tostring(entity.Velocity.X)) .. ", ") .. tostring(entity.Velocity.Y)) .. ")"
213
- debugString = debugString .. (((" (HP: " .. tostring(entity.HitPoints)) .. " / ") .. tostring(entity.MaxHitPoints)) .. ")"
214
- ____exports.log(debugString)
215
220
  numMatchedEntities = numMatchedEntities + 1
216
221
  end
217
222
  )
218
223
  if numMatchedEntities == 0 then
219
- ____exports.log("(no entities matched)")
224
+ msg = msg .. "(no entities matched)\n"
220
225
  else
221
- ____exports.log(("(" .. tostring(numMatchedEntities)) .. " total entities)")
226
+ msg = msg .. ("(" .. tostring(numMatchedEntities)) .. " total entities)\n"
222
227
  end
228
+ ____exports.log(msg)
223
229
  end
224
230
  function ____exports.logEntityFlags(flags)
225
231
  ____exports.logFlags(flags, EntityFlag, "entity")
@@ -248,14 +254,13 @@ function ____exports.logGameStateFlags()
248
254
  end
249
255
  end
250
256
  function ____exports.logGridEntities(includeWalls, gridEntityTypeFilter)
251
- local headerMsg = "Grid entities in the room"
257
+ local msg = "Grid entities in the room"
252
258
  if gridEntityTypeFilter ~= nil then
253
- headerMsg = headerMsg .. (" (filtered to grid entity type " .. tostring(gridEntityTypeFilter)) .. ")"
259
+ msg = msg .. (" (filtered to grid entity type " .. tostring(gridEntityTypeFilter)) .. ")"
260
+ elseif not includeWalls then
261
+ msg = msg .. " (not including walls)"
254
262
  end
255
- if not includeWalls then
256
- headerMsg = headerMsg .. " (not including walls)"
257
- end
258
- ____exports.log(headerMsg)
263
+ msg = msg .. ":\n"
259
264
  local gridEntities = getGridEntities(nil)
260
265
  local numMatchedEntities = 0
261
266
  __TS__ArrayForEach(
@@ -271,47 +276,54 @@ function ____exports.logGridEntities(includeWalls, gridEntityTypeFilter)
271
276
  if not includeWalls and gridEntityType == GridEntityType.GRID_WALL and gridEntityTypeFilter ~= GridEntityType.GRID_WALL then
272
277
  return
273
278
  end
274
- local debugString = (((((tostring(gridEntityIndex) .. " - ") .. tostring(gridEntityType)) .. ".") .. tostring(gridEntityVariant)) .. ".") .. tostring(gridEntity.State)
279
+ msg = msg .. (((((tostring(gridEntityIndex) .. ") ") .. tostring(gridEntityType)) .. ".") .. tostring(gridEntityVariant)) .. ".") .. tostring(gridEntity.State)
275
280
  local door = gridEntity:ToDoor()
276
281
  if door ~= nil then
277
- debugString = debugString .. (((((((" (door) (Slot: " .. tostring(door.Slot)) .. ", Direction: ") .. tostring(door.Direction)) .. ", TargetRoomIndex: ") .. tostring(door.TargetRoomIndex)) .. ", TargetRoomType: ") .. tostring(door.TargetRoomType)) .. ")"
282
+ msg = msg .. " (door)"
278
283
  end
279
284
  local pit = gridEntity:ToPit()
280
285
  if pit ~= nil then
281
- debugString = debugString .. " (pit)"
286
+ msg = msg .. " (pit)"
282
287
  end
283
288
  local poop = gridEntity:ToPoop()
284
289
  if poop ~= nil then
285
- debugString = debugString .. " (poop)"
290
+ msg = msg .. " (poop)"
286
291
  end
287
292
  local pressurePlate = gridEntity:ToPressurePlate()
288
293
  if pressurePlate ~= nil then
289
- debugString = debugString .. " (pressurePlate)"
294
+ msg = msg .. " (pressurePlate)"
290
295
  end
291
296
  local rock = gridEntity:ToRock()
292
297
  if rock ~= nil then
293
- debugString = debugString .. " (rock)"
298
+ msg = msg .. " (rock)"
294
299
  end
295
300
  local spikes = gridEntity:ToSpikes()
296
301
  if spikes ~= nil then
297
- debugString = debugString .. " (spikes)"
302
+ msg = msg .. " (spikes)"
298
303
  end
299
304
  local tnt = gridEntity:ToTNT()
300
305
  if tnt ~= nil then
301
- debugString = debugString .. " (TNT)"
306
+ msg = msg .. " (TNT)"
307
+ end
308
+ msg = msg .. (" - VarData: " .. tostring(gridEntity.VarData)) .. "\n"
309
+ msg = msg .. (((" - Position: (" .. tostring(gridEntity.Position.X)) .. ", ") .. tostring(gridEntity.Position.Y)) .. ")\n"
310
+ msg = msg .. (" - SpawnSeed: " .. tostring(gridEntityDesc.SpawnSeed)) .. "\n"
311
+ msg = msg .. (" - VariableSeed: " .. tostring(gridEntityDesc.VariableSeed)) .. ")\n"
312
+ if door ~= nil then
313
+ msg = msg .. (" - Slot: " .. tostring(door.Slot)) .. "\n"
314
+ msg = msg .. (" - Direction: " .. tostring(door.Direction)) .. "\n"
315
+ msg = msg .. (" - TargetRoomIndex: " .. tostring(door.TargetRoomIndex)) .. "\n"
316
+ msg = msg .. (" - TargetRoomType: " .. tostring(door.TargetRoomType)) .. "\n"
302
317
  end
303
- debugString = debugString .. (" (VarData: " .. tostring(gridEntity.VarData)) .. ")"
304
- debugString = debugString .. (((" (Position: " .. tostring(gridEntity.Position.X)) .. ", ") .. tostring(gridEntity.Position.Y)) .. ")"
305
- debugString = debugString .. (((" (SpawnSeed: " .. tostring(gridEntityDesc.SpawnSeed)) .. ", VariableSeed: ") .. tostring(gridEntityDesc.VariableSeed)) .. ")"
306
- ____exports.log(debugString)
307
318
  numMatchedEntities = numMatchedEntities + 1
308
319
  end
309
320
  )
310
321
  if numMatchedEntities == 0 then
311
- ____exports.log("(no grid entities matched)")
322
+ msg = msg .. "(no grid entities matched)\n"
312
323
  else
313
- ____exports.log(("(" .. tostring(numMatchedEntities)) .. " total grid entities)")
324
+ msg = msg .. ("(" .. tostring(numMatchedEntities)) .. " total grid entities)\n"
314
325
  end
326
+ ____exports.log(msg)
315
327
  end
316
328
  function ____exports.logKColor(kColor)
317
329
  ____exports.log((((((("Color: R" .. tostring(kColor.Red)) .. ", G") .. tostring(kColor.Green)) .. ", B") .. tostring(kColor.Blue)) .. ", A") .. tostring(kColor.Alpha))
@@ -39,6 +39,11 @@ export declare function getRoomItemPoolType(): ItemPoolType;
39
39
  * `RoomList`. Default is false.
40
40
  */
41
41
  export declare function getRooms(includeExtraDimensionalRooms?: boolean): RoomDescriptor[];
42
+ /**
43
+ * Helper function to get the room descriptor for every room on the level in a specific dimension.
44
+ * Uses the `Level.GetRooms` method to accomplish this.
45
+ */
46
+ export declare function getRoomsOfDimension(dimension: Dimension): RoomDescriptor[];
42
47
  /**
43
48
  * Helper function to determine if the current room shape is equal to `RoomShape.ROOMSHAPE_1x2` or
44
49
  * `RoomShape.ROOMSHAPE_2x1`.
@@ -134,6 +134,21 @@ function ____exports.getRoomItemPoolType(self)
134
134
  local roomSeed = room:GetSpawnSeed()
135
135
  return itemPool:GetPoolForRoom(roomType, roomSeed)
136
136
  end
137
+ function ____exports.getRoomsOfDimension(self, dimension)
138
+ local level = game:GetLevel()
139
+ local rooms = {}
140
+ do
141
+ local i = 0
142
+ while i <= MAX_ROOM_INDEX do
143
+ local roomDescriptor = level:GetRoomByIdx(i, dimension)
144
+ if roomDescriptor ~= nil then
145
+ rooms[#rooms + 1] = roomDescriptor
146
+ end
147
+ i = i + 1
148
+ end
149
+ end
150
+ return rooms
151
+ end
137
152
  function ____exports.in2x1Room(self)
138
153
  local room = game:GetRoom()
139
154
  local roomShape = room:GetRoomShape()
@@ -274,12 +289,12 @@ function ____exports.setRoomCleared(self)
274
289
  for ____, door in ipairs(getDoors(nil)) do
275
290
  do
276
291
  if isHiddenSecretRoomDoor(nil, door) then
277
- goto __continue52
292
+ goto __continue55
278
293
  end
279
294
  openDoorFast(nil, door)
280
295
  door.ExtraVisible = false
281
296
  end
282
- ::__continue52::
297
+ ::__continue55::
283
298
  end
284
299
  sfxManager:Stop(SoundEffect.SOUND_DOOR_HEAVY_OPEN)
285
300
  game:ShakeScreen(0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.276",
3
+ "version": "1.2.279",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,9 +25,9 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.392",
28
+ "isaac-typescript-definitions": "^1.0.393",
29
29
  "isaacscript-lint": "^1.0.99",
30
- "isaacscript-tsconfig": "^1.1.8",
30
+ "isaacscript-tsconfig": "^1.1.9",
31
31
  "typedoc": "^0.22.15",
32
32
  "typescript": "4.6.3",
33
33
  "typescript-to-lua": "^1.4.3"