Entity.lua¶
Functions¶
entity.new¶
entity.new(instance: LibLegelGen.Instance, type: string, x?: number, y?: number, level?: number | number[]): LibLevelGen.Entity
Create a new LibLevelGen entity. Do note that instead of using this, you should use methods provided by the LibLevelGen.Room and LibLevelGen.Tile classes, which will place the enemy in the level automatically.
Parameters:
| Name | Type | Description |
|---|---|---|
instance |
LibLegelGen.Instance |
Parent instance of the entity |
type |
string |
Entity type |
x? |
number |
X coordinate of the entity, relative to the room it's in. Defaults to -1 |
y? |
number |
Y coordinate of the entity, relative to the room it's in Defaults to -1 |
level? |
number | number[] |
Level of the entity, if a table is specified it's picked randomly from the provided values. Defaults to 1. |
Returns: LibLevelGen.Entity
Classes¶
LibLevelGen.Entity¶
Represents a LibLevelGen entity object
Properties:
| Name | Type | Description |
|---|---|---|
instance |
LibLegelGen.Instance |
Instance this entity belongs to |
type |
string |
Entity type |
x |
number |
Entity X coordinate relative, relative to the room it's in |
y |
number |
Entity Y coordinate relative, relative to the room it's in |
level |
number |
Entity level |
saleCurrency |
string | nil |
If entity has a price, this determines the currency |
price |
table | nil |
Entity price data, in the format set by Synchrony's levelUtils.setEntityPriceTag |
attributes |
table | nil |
Additional entity attributes. Use .setAttribute and .getOrCreateAttribute methods to manipulate this table. |
inventory |
table | nil |
Entity's inventory. Use the .giveItem method to manipulate this table. |
Methods:
LibLevelGen.Entity.setAttribute¶
setAttribute(self: LibLevelGen.Entity, component: string, field: string, value: any): LibLevelGen.EntitySet value of the given component field for when the entity is spawned.
Parameters:
Name Type Description selfLibLevelGen.EntityThe entity componentstringComponent name fieldstringField in the given component valueanyValue to write to the field Returns:
LibLevelGen.Entity
LibLevelGen.Entity.setPrice¶
setPrice(self: LibLevelGen.Entity, currency?: "coins" | "blood", amount?: number): LibLevelGen.EntitySet price of the entity. If price is not specified, it is automatically obtained.
Parameters:
Name Type Description selfLibLevelGen.EntityThe Entity currency?"coins" | "blood"Currency type, defaults to "coins" amount?numberThe price value. If not specified, it's calculated automatically. Returns:
LibLevelGen.Entity
LibLevelGen.Entity.setDiscount¶
Set discount on the price.
Parameters:
Name Type Description selfLibLevelGen.EntityThe entity discountnumberThe discount factor. 0.5will result in the price being halved.Returns:
LibLevelGen.Entity
LibLevelGen.Entity.setQuantity¶
Set quantity (itemStack.quantity field)
Parameters:
Name Type Description selfLibLevelGen.EntityThe entity quantitynumberThe quantity amount to set Returns:
LibLevelGen.Entity
LibLevelGen.Entity.giveItem¶
Add an item to entity's inventory.
Parameters:
Name Type Description selfLibLevelGen.EntityThe entity itemstring | LibLevelGen.EntityEntity type or an existing entity to add to the inventory. Returns:
LibLevelGen.Entity
LibLevelGen.Entity.getOrCreateAttribute¶
getOrCreateAttribute(self: LibLevelGen.Entity, component: string, field: string): LibLevelGen.EntityGet an attribute of the entity. If it doesn't exist, it gets created and added (with no value specified)
Parameters:
Name Type Description selfLibLevelGen.EntityThe entity componentstringComponent name fieldstringField name in the given component Returns:
LibLevelGen.Entity
LibLevelGen.Entity.storeItem¶
Add an item to entity's storage.
Parameters:
Name Type Description selfLibLevelGen.EntityThe entity itemstringItem entity type Returns:
LibLevelGen.Entity