Entity
Class of @v12-engine/engine
export declare class EntityAnything in the world: a unit, a building, a tree.
Fields marked readonly are kept in step with things elsewhere (the navigation, the spatial index, the lookups of the world), so they are changed through the world's functions only: World.setOwner, World.setHidden, World.setLifetime, World.place, startDash, morph (each through the entity's own internal writes: moveTo, retype, changeOwner…). The rest, like health, mana or cooldowns, a game module may change as it likes: nothing is worked out from them that would not notice.
Members
constructor
constructor(
id: EntityId,
def: UnitTypeDef,
owner: PlayerId, position: Vec2);Constructs a new instance of the Entity class
abilities
readonly abilities: readonly AbilityState[];What it can cast, with their levels and cooldowns: each state is the game's to change (cooldown, autocast), the list the engine's (a type's own, what a hero learns), written with the entity's own internal methods
alive
readonly alive: boolean;Whether the entity is in the world; false once it died
asleep
asleep: boolean;Does nothing by itself until something wakes it, and is drawn sleeping: creeps at night
buffs
readonly buffs: readonly BuffInstance[];What is on it: each instance the game's to change, the list put on and taken off by applyBuff, removeBuff
cell
cell?: {
x: number;
z: number;
};Min corner of the footprint in grid cells, for buildings and resources
components
get components(): Readonly<Record<string, unknown>>;Its components' values by id, in the order it was given them: made each time it is asked, for what reads them by id now and then (a save, the inspector). What does it often goes through heldComponents
currentOrder
get currentOrder(): Order | undefined;The order it carries out now, the first of its orders; nothing when it has none
def
readonly def: UnitTypeDef;Changes when a building is upgraded into another type
expires
readonly expires: number | null;Seconds until it is gone by itself, for what does not last
facing
facing: number;The way it faces in radians
flying
get flying(): boolean;Up in the air, where the ground and what stands on it are not in the way
get
get<T>(key: Component<T, unknown>): T | undefined;A component of a game module or a mod, see defineComponent
halfDepth
get halfDepth(): number;Half of what it covers from front to back (rect.hd), as halfWidth
halfWidth
get halfWidth(): number;Half of what it covers across (rect.hw), with no rect made: what is asked all the time (is a structure in sight)
has
has(key: Component<unknown>): boolean;Whether it holds the component
health
health: number;Hit points it has now; it dies at 0
heldComponents
heldComponents(): readonly Component<unknown, unknown>[];Its components, in the order it was given them: each one's value is get(component)
hidden
readonly hidden: boolean;Hidden entities are inside something (a gold mine) and do not take part in the world
hurtAt
hurtAt: number;When it was last hurt, in seconds of the game. Long ago for what never was
id
readonly id: EntityId;The entity's number, unique in its world
index
index: {
componentChanged(entity: Entity, id: string, has: boolean): void;
} | null;The index of the world it is in (EntityIndex), told when it gets or loses a component, and the way to its world (order). Not game state
isBuilding
get isBuilding(): boolean;Whether its type is a building
isResource
get isResource(): boolean;Whether its type is a resource
isStructure
get isStructure(): boolean;Whether its type is a building or a resource: anything but a unit
isUnit
get isUnit(): boolean;Whether its type is a unit
lifetime
lifetime: number;Seconds it was given to last, for what does not
likeness
likeness?: Likeness;Drawn as another's type and owner: a soul in the fallen's shape (SpawnOptions.looksLike). Its own type and owner decide everything but the picture
look
look?: string;Which of the models of its type it is drawn with, for the look of a map. Nothing in the rules goes by it either
mana
mana: number;Mana it has now
maxHealth
maxHealth: number;The most hit points it can have
maxMana
maxMana: number;The most mana it can have
on
on?: EntityId;The resource it stands on (UnitTypeDef.builtOn), by id: none for what stands on the ground
operational
get operational(): boolean;Completed and able to do its job
order
order<Type extends string>(type: Type, aim?: Vec2 | Entity | Omit<OrderInit<Type>, 'type'>, options?: OrderOptions): void;Gives it an order, as its owner would: unit.order('move', point), unit.order('attack', enemy), unit.order('cast', { ability: 'blink', point }). What it is aimed at is a point (point), an entity (target) or the order's fields (OrderInits). It is the order command of its owner through its world (World.issue): taken up at the next tick, turned away as a player's would be (an order its type does not take, a target its owner does not know), and kept by a replay. queue puts it after what it was told before. Throws for an entity that is in no world (taken out of it)
orders
readonly orders: readonly Order[];What it was told to do, the first what it does now and the rest in turn: read here, given and ended through the orders' functions (giveOrder, clearOrders, completeOrder), which write it with the entity's own addOrder, keepOrders and removeOrder
owner
readonly owner: PlayerId;The player it belongs to, changed through World.setOwner only
pos
readonly pos: Readonly<Vec2>;Where it stands in cells (x, z), changed through the world's functions only
prevFacing
prevFacing: number;The way it faced at the last tick, in radians, for the screen to draw between
prevPos
readonly prevPos: Vec2;Where it stood at the last tick, for the screen to draw between
rect
get rect(): Rect;Ground area covered by a structure: a new rect each time, for who keeps it (an obstacle, a wall's reshape)
remove
remove(key: Component<unknown>): void;Takes the component away; nothing happens when it has none
reviving
reviving: boolean;A fallen hero that is on its way back
scale
scale: number;How big it is drawn, for the look of a map. Nothing in the rules goes by it
scenery
readonly scenery: boolean;Only stands there, like a tree: left out of the systems that run every tick, see isScenery. Becomes false for good once something gives it anything to do (World.wake)
seenBy
seenBy: number;Teams that have seen this entity at least once, one bit per team as FogOfWar.teamBit hands them out. Ask World.hasSeen
set
set<T>(key: Component<T, unknown>, value: T): void;Gives it the component, or a new value of it. undefined takes it away (remove)
spatialStamp
spatialStamp: number;Bookkeeping of the spatial index: the last query that found it. Not game state
statsCache
statsCache: StatsCache | null;Stats as last worked out, see statsOf. Derived from the rest, never saved or sent
unseen
get unseen(): boolean;Invisible to enemies right now, unless they have found it
unseenIn
unseenIn: number | null;Seconds until enemies cannot see it any more, for what is invisible. 0 once they cannot
velocity
readonly velocity: Vec2;Velocity of the last tick