Skip to content

Room.lua

Functions


room.new

room.new(instance: LibLegelGen.Instance, segment: LibLevelGen.Segment, x: number, y: number, w: number, h: number, flags: number): LibLevelGen.Room

Create a new room within the segment.

Parameters:

Name Type Description
instance LibLegelGen.Instance The instance.
segment LibLevelGen.Segment The segment.
x number X coordinate of room's top-left corner.
y number Y coordinate of room's top-left corner.
w number Room width.
h number Room height.
flags number Room flags.

Returns: LibLevelGen.Room

Classes


LibLevelGen.TileRequirements

Interface used for selecting tiles based on the given requirement. Fields of the Tribool type can be nil, true or false. When a Tribool is nil the condition is not checked, and if it's a boolean then the condition check result must match the value specified.

Properties:

Name Type Description
isFloor TriBool Whether the tile is a floor.
isWall TriBool Whether the tile is a wall.
levelExit TriBool Whether the tile is the level exit.
hasWallTorch TriBool Whether the tile has a wall torch.
hasEntity TriBool Whether the tile has an entity.
tileType string | nil Required tile type string name.
nearFloor TriBool Whether the tile is near a floor tile, checked within this room only.
nearWall TriBool Whether the tile is near a wall tile, checked within this room only.
nearBorder TriBool Whether the tile is near the room border.
filter fun(room: LibLevelGen.Room, tile: LibLevelGen.Tile) | nil Filter function, if it returns true the condition check passes.
notCollision number | nil Collision (from necro.game.tile.Collision) bits which must all NOT be set.
collision number | nil Collision (from necro.game.tile.Collision) bits which must all be set.
rect LibLevelGen.Rect | nil Rect the tile must be in.
notRect LibLevelGen.Rect | nil Rect the tile must NOT be in.
wire TriBool Whether the tile has an electric wile.
info table | nil Require the tile to have a specific tileInfo (from necro.game.tile.TileTypes)
entrance TriBool Whether the tile is the entrance to the room (directly next to the corridor).
adjacentEntrance TriBool Whether the tile is adjacent to the entrance.
directlyAdjacentEntrance TriBool Whether the tile is adjacent to the entrance, but not diagonally.
noWallTallSprite TriBool Whether the tile below the checked tile is a wall.

LibLevelGen.Tile

Object representing a single tile. This will be moved to a separate module in the future.

Properties:

Name Type Description
tileset string Tileset the tile uses.
type string Tile type the tile uses.
info table TileInfo of the tile (from necro.game.tile.TileTypes).
wire integer The wire connectivity bitmask.
hasEntity boolean Whether the tile has an entity.
entities LibLevelGen.Entity[] List of entities on this tile.
hasWallTorch boolean Whether the tile has a wall torch.
x number X coordinate of the tile in the room.
y number Y coordinate of the tile in the room.
rx number X coordinate of the tile in the segment.
ry number Y coordinate of the tile in the segment.
adjacentEntrance boolean Whether the tile is adjacent to an entrance.
directlyAdjacentEntrance boolean Whether the tile is adjacent to an entrance, but not diagonally.
isEntrance boolean Whether the tile is the entrance to the room (directly next to the corridor).
room LibLevelGen.Room Room this tile belongs to.
instance LibLegelGen.Instance Instance this tile belongs to.

Methods:


LibLevelGen.Tile.convert

convert(self: LibLevelGen.Tile, tileType: string): void

Convert the tile to a different type.

Parameters:

Name Type Description
self LibLevelGen.Tile The tile
tileType string TileType to convert to.

LibLevelGen.Tile.setIsEntrance

setIsEntrance(self: LibLevelGen.Tile): void

Set the isEntrance flag on the tile and adjacentEntrance flags on nearby tiles.

Parameters:

Name Type Description
self LibLevelGen.Tile The tile

LibLevelGen.Tile.placeEntity

placeEntity(self: LibLevelGen.Tile, entityOrType: string | LibLevelGen.Entity, level?: number): LibLevelGen.Entity

Place entity of given type and level on the tile.

Parameters:

Name Type Description
self LibLevelGen.Tile The tile.
entityOrType string | LibLevelGen.Entity Entity type or existing entity.
level? number Entity level, ignored if existing entity is passed in the previous argument.

Returns: LibLevelGen.Entity


LibLevelGen.Tile.meetsRequirements

meetsRequirements(self: LibLevelGen.Tile, requirements: LibLevelGen.TileRequirements): void

Check if the tile meets specified requirements.

Parameters:

Name Type Description
self LibLevelGen.Tile The tile.
requirements LibLevelGen.TileRequirements Requirements the tile has to meet.

LibLevelGen.Tile.tileBelowIsWall

tileBelowIsWall(self: LibLevelGen.Tile): void

Whether a wall tile or the room border is below this tile.

Parameters:

Name Type Description
self LibLevelGen.Tile The tile.

LibLevelGen.Tile.inRect

inRect(self: LibLevelGen.Tile, rect: LibLevelGen.Rect): void

Check if the tile is within a given rect in the room.

Parameters:

Name Type Description
self LibLevelGen.Tile The tile.
rect LibLevelGen.Rect Rect to check against.

LibLevelGen.RoomLinkData

Data which represents where a room connects to other rooms.

Properties:

Name Type Description
x number Top-left X coordinate of the connection.
y number Top-left Y coordinate of the connection.
centerX number X center of the connection.
centerY number Y center of the connection.
axis number LibLevelGen.Axis
size number How long the connection is, it's either width or height, depending on the axis.
room LibLevelGen.Room The room that the link leads to.

Object containing room links for every side of the room.

Properties:

Name Type Description
top LibLevelGen.RoomLinkData[] Link data of the top side of the room.
bottom LibLevelGen.RoomLinkData[] Link data of the bottom side of the room.
left LibLevelGen.RoomLinkData[] Link data of the left side of the room.
right LibLevelGen.RoomLinkData[] Link data of the right side of the room.

LibLevelGen.Point

Simple point interface.

Properties:

Name Type Description
x number x
y number y

LibLevelGen.Room

Object representing a room.

Properties:

Name Type Description
x number X coordinate of the room's top left corner within the segment.
y number Y coordinate of the room's top left corner within the segment.
w number Width of the room.
h number Height of the room.
flags number Room flags (from room.Flag).
links LibLevelGen.RoomLinkData[] Information about the rooms adjacent to this room and where exactly the entrances are.
padding LibLevelGen.PaddingData | nil Padding override to use instead of the segment-defined one.
tiles LibLevelGen.Tile[] Array of tiles in this room.
exit LibLevelGen.Point | nil Coordinates of exit stairs within this room (if they exist).
instance LibLegelGen.Instance Instance this room belongs to.
segment LibLevelGen.Segment Segment this table belongs to.
userData table Table where you can put whatever you want safely.

Methods:


LibLevelGen.Room.setFlags

setFlags(self: LibLevelGen.Room, newFlags: number): void

Adds new flags on top of existing flags.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
newFlags number The new flags.

LibLevelGen.Room.clearFlags

clearFlags(self: LibLevelGen.Room, flagsToClear: number): void

Removes the given flags.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
flagsToClear number Flags to remove.

LibLevelGen.Room.maskFlags

maskFlags(self: LibLevelGen.Room, flags: number): void

Removes all flags apart from the given ones.

Parameters:

Name Type Description
self LibLevelGen.Room the room.
flags number Flags to use as a mask.

LibLevelGen.Room.checkFlags

checkFlags(self: LibLevelGen.Room, flags: number): void

Checks if the given flags are set.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
flags number Flags to check.

LibLevelGen.Room.setPaddingTileOverride

setPaddingTileOverride(self: LibLevelGen.Room, data: LibLevelGen.PaddingData): void

Set the padding that will be used instead of the one specified by the segment.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
data LibLevelGen.PaddingData Padding definition object.

LibLevelGen.Room.getBounds

getBounds(self: LibLevelGen.Room): number[]

Get bounds of the room (in table {x, y, w, h}).

Parameters:

Name Type Description
self LibLevelGen.Room The room.

Returns: number[]


LibLevelGen.Room.getRect

getRect(self: LibLevelGen.Room): LibLevelGen.Rect

Get rect of the room.

Parameters:

Name Type Description
self LibLevelGen.Room The room.

Returns: LibLevelGen.Rect


LibLevelGen.Room.setTile

setTile(self: LibLevelGen.Room, x: number, y: number, tileType: string, tileset?: string): void

Set tile on the given coordinates. If tileset is not specified, the default one of the segment is used.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
x number X coordinates of the tile.
y number Y coordinates of the tile.
tileType string The tile type
tileset? string The tileset, if not specified defaults to the tileset of the segment.

LibLevelGen.Room.getTile

getTile(self: LibLevelGen.Room, x: number, y: number): LibLevelGen.Tile

Get tile on given coordinates

Parameters:

Name Type Description
self LibLevelGen.Room The room.
x number X coordinates of the tile.
y number Y coordinates of the tile.

Returns: LibLevelGen.Tile


LibLevelGen.Room.deleteTile

deleteTile(self: LibLevelGen.Room, x: number, y: number): void

Delete the given tile (set it to Void pseudotile)

Parameters:

Name Type Description
self LibLevelGen.Room The room.
x number X coordinates of the tile.
y number Y coordinates of the tile.

LibLevelGen.Room.isTileNearWall

isTileNearWall(self: LibLevelGen.Room, tile: LibLevelGen.Tile): boolean

Checks if the given tile (assumed to be within this room) is near a wall tile.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
tile LibLevelGen.Tile The tile to check.

Returns: boolean


LibLevelGen.Room.isTileNearFloor

isTileNearFloor(self: LibLevelGen.Room, tile: LibLevelGen.Tile): boolean

Checks if the given tile (assumed to be within this room) is near a floor tile.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
tile LibLevelGen.Tile The tile to check.

Returns: boolean


LibLevelGen.Room.isTileNearBorder

isTileNearBorder(self: LibLevelGen.Room, tile: LibLevelGen.Tile): boolean

Checks if the given tile (assumed to be within this room) is near the edge of the room.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
tile LibLevelGen.Tile The tile to check.

Returns: boolean


LibLevelGen.Room.fill

fill(self: LibLevelGen.Room, parameters: LibLevelGen.RoomFillParameters | string): void

Fill the room.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
parameters LibLevelGen.RoomFillParameters | string Either the RoomFillParameters object or simply the tile type string.

LibLevelGen.Room.border

border(self: LibLevelGen.Room, parameters: LibLevelGen.RoomBorderParameters | string): void

Create a border around the room.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
parameters LibLevelGen.RoomBorderParameters | string Either a RoomBorderParameters specifying the border details, or simply a string tile type to create a basic border.

LibLevelGen.Room.selectTiles

selectTiles(self: LibLevelGen.Room, requirements: LibLevelGen.TileRequirements): LibLevelGen.Tile[]

Returns all tiles that meet the requirements.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
requirements LibLevelGen.TileRequirements Tile requirements to check against.

Returns: LibLevelGen.Tile[]


LibLevelGen.Room.chooseRandomTile

chooseRandomTile(self: LibLevelGen.Room, requirements: LibLevelGen.TileRequirements): LibLevelGen.Tile

Choose a random tile out of ones that meet requirements

Parameters:

Name Type Description
self LibLevelGen.Room The room.
requirements LibLevelGen.TileRequirements Tile requirements to check against.

Returns: LibLevelGen.Tile


LibLevelGen.Room.chooseRandomTiles

chooseRandomTiles(self: LibLevelGen.Room, num: number, requirements: LibLevelGen.TileRequirements): LibLevelGen.Tile[]

Choose multiple tiles out of ones that meet requirements.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
num number Amount of tiles to choose.
requirements LibLevelGen.TileRequirements Tile requirements to check against.

Returns: LibLevelGen.Tile[]


LibLevelGen.Room.placeWallTorch

placeWallTorch(self: LibLevelGen.Room, tile: LibLevelGen.Tile, type?: string): void

Place a wall torch on the given tile.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
tile LibLevelGen.Tile Tile to place the torch on.
type? string Optional walltorch entity type override.

LibLevelGen.Room.placeWallTorches

placeWallTorches(self: LibLevelGen.Room, num: number, type?: string): void

Place given amount of wall torches randomly on elligible tiles.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
num number Amount of weall torches to place.
type? string Optional walltorch entity type override.

LibLevelGen.Room.placeEntity

placeEntity(self: LibLevelGen.Room, tile: LibLevelGen.Tile, entityOrType: string | LibLevelGen.Entity, level?: number): void

Place entity on the given tile (wrapper around tile:placeEntity that checks if tile is not nil)

Parameters:

Name Type Description
self LibLevelGen.Room The room.
tile LibLevelGen.Tile The tile to place the entity on.
entityOrType string | LibLevelGen.Entity Existing entity or an entity type to spawn.
level? number Optional entity level if passing a string entity type.

LibLevelGen.Room.placeEntityAt

placeEntityAt(self: LibLevelGen.Room, x: number, y: number, entityOrType: string | LibLevelGen.Entity, level?: number): void

Place entity on a tile on given coordinates.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
x number X coordinate.
y number Y coordinate.
entityOrType string | LibLevelGen.Entity Existing entity or an entity type to spawn.
level? number Optional entity level if passing a string entity type.

LibLevelGen.Room.placeEntityRand

placeEntityRand(self: LibLevelGen.Room, requirements: LibLevelGen.TileRequirements, entityOrType: string | LibLevelGen.Entity, level?: number): void

Place entity on a random tile that meets requrements.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
requirements LibLevelGen.TileRequirements Requirements used to select the tile.
entityOrType string | LibLevelGen.Entity Existing entity or an entity type to spawn.
level? number Optional entity level if passing a string entity type.

LibLevelGen.Room.placeWire

placeWire(self: LibLevelGen.Room, tile: LibLevelGen.Tile, connectivity: number): void

Place wire on the given tile.

Parameters:

Name Type Description
self LibLevelGen.Room The room
tile LibLevelGen.Tile Tile to place the wire on.
connectivity number Unused, reserved.

LibLevelGen.Room.makeExit

makeExit(self: LibLevelGen.Room, minibosses: table): void

Turn the room into an exit room - set appropriate flags, place the exit stairs and the miniboss.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
minibosses table List of possible minibosses, in format: { {"type1", level1}, {"type2", level2}, ... }

LibLevelGen.Room.placeExit

placeExit(self: LibLevelGen.Room): void

Place exit somewhere in the room.

Parameters:

Name Type Description
self LibLevelGen.Room The room.

LibLevelGen.Room.placeMiniboss

placeMiniboss(self: LibLevelGen.Room, minibosses: table): void

Place a miniboss in the room (assumes that the room is an exit room).

Parameters:

Name Type Description
self LibLevelGen.Room The room.
minibosses table In format {{"type", level}, ...}.

LibLevelGen.Room.randomlyConvertTiles

randomlyConvertTiles(self: LibLevelGen.Room, sourceType: string, targetType: string, ratio: number): void

Randomly convert tiles from sourceType to targetType, chance of conversion happening is ratio.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
sourceType string Tile type to convert from.
targetType string Tile type to convert to.
ratio number Chance of the conversion happening, a float between 0.0 and 1.0.

LibLevelGen.Room.convertTiles

convertTiles(self: LibLevelGen.Room, sourceType: string, targetType: string): void

Convert all tiles from source type to target type, preserving their tileset.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
sourceType string Tile type to convert from.
targetType string Tile type to convert to.

LibLevelGen.Room.spreadTile

spreadTile(self: LibLevelGen.Room, targetType: string, requirements: LibLevelGen.TileRequirements, minConvert: number, maxConvert: number, initialTile?: LibLevelGen.Tile): void

Choose 1 tile that meets requirement and convert it and other nearby tiles to target type.

Parameters:

Name Type Description
self LibLevelGen.Room The room.
targetType string Tiletype to convert the tiles to.
requirements LibLevelGen.TileRequirements The tile requirements used to pick the initial tile and the subsequent tiles.
minConvert number Minimum number of tiles to convert.
maxConvert number Maximum number of tiles to convert.
initialTile? LibLevelGen.Tile Can be used to specify initial tile, instead of choosing it randomly.

LibLevelGen.Room.makeShop

makeShop(self: LibLevelGen.Room, locked?: boolean, force?: boolean): void

Make the room a shop. TODO: move into a separate module

Parameters:

Name Type Description
self LibLevelGen.Room The room
locked? boolean Whether the shop should be a locked shop
force? boolean Whether to force shopkeeper and items to spawn even if the shopkeeper killed flag is set in runState.

LibLevelGen.RoomFillParameters extends LibLevelGen.TileData

no description

Properties:

Name Type Description
tileset string no description
type string no description
rect LibLevelGen.Rect | nil no description

LibLevelGen.RoomBorderSideCount

no description

Properties:

Name Type Description
top number Top tile count.
bottom number Bottom tile count.
left number Left tile count.
right number Right tile count.

LibLevelGen.RoomBorderParameters extends LibLevelGen.TileData

Object used to specify room border details.

Properties:

Name Type Description
tileset string no description
type string no description
rect LibLevelGen.Rect The rect around which to place the border.
sides LibLevelGen.RoomBorderSideCount Definition of wall count on each side.

Enums


room.Axis

Used to determine whether a room was generated vertically or horizontally.

Entries:

  • VERTICAL
  • HORIZONTAL

room.Flag

Flags which determine the properties of the room

Entries:

  • NONE
  • ALLOW_ENEMY
  • ALLOW_CHEST
  • ALLOW_CRATE
  • ALLOW_TRAP
  • ALLOW_TRAVELRUNE
  • ALLOW_SHRINE
  • ALLOW_TORCH
  • ALLOW_TILE_CONVERSION
  • ALLOW_SECRET_FILL
  • EXIT
  • STARTING

room.Type

Helper enum containing common room.Flag bitmasks.

Entries:

  • REGULAR
  • STARTING
  • EXIT
  • CORRIDOR
  • SECRET
  • SHOP
  • SECRET_SHOP
  • OTHER

Other

room.Direction

room.Direction = action.Direction -- From necro.game.system.Action

room.DirectionVector

room.DirectionVector = {
    [room.Direction.LEFT] = {-1, 0},
    [room.Direction.RIGHT] = {1, 0},
    [room.Direction.UP] = {0, -1},
    [room.Direction.DOWN] = {0, 1}
}

Tribool alias

--- @alias TriBool boolean | nil