Skip to content

Class: MockAlifeSimulator ​

Mock alife simulator registry containing data with server objects.

Implements ​

  • alife_simulator

Accessors ​

infoPortions ​

Get Signature ​

ts
get static infoPortions(): Record<number, Set<string>>;
Returns ​

Record<number, Set<string>>

Set Signature ​

ts
set static infoPortions(value: Record<number, Set<string>>): void;
Parameters ​
ParameterType
valueRecord<number, Set<string>>
Returns ​

void


registry ​

Get Signature ​

ts
get static registry(): Record<number, cse_alife_object>;
Returns ​

Record<number, cse_alife_object>

Set Signature ​

ts
set static registry(value: Record<number, cse_alife_object>): void;
Parameters ​
ParameterType
valueRecord<number, cse_alife_object>
Returns ​

void

Constructors ​

Constructor ​

ts
new MockAlifeSimulator(): MockAlifeSimulator;

Returns ​

MockAlifeSimulator

Methods ​

addToRegistry() ​

ts
static addToRegistry(object: cse_alife_object): void;

Parameters ​

ParameterType
objectcse_alife_object

Returns ​

void


create() ​

ts
static create(): MockAlifeSimulator;

Returns ​

MockAlifeSimulator


getFromRegistry() ​

ts
static getFromRegistry<T>(id: number): T | null;

Type Parameters ​

Type ParameterDefault type
T extends cse_alife_objectcse_alife_object

Parameters ​

ParameterType
idnumber

Returns ​

T | null


getInstance() ​

ts
static getInstance(): MockAlifeSimulator;

Returns ​

MockAlifeSimulator


mock() ​

ts
static mock(): alife_simulator;

Returns ​

alife_simulator


removeFromRegistry() ​

ts
static removeFromRegistry(id: number): void;

Parameters ​

ParameterType
idnumber

Returns ​

void


reset() ​

ts
static reset(): void;

Returns ​

void

Properties ​

actor ​

ts
actor: <T>() => T;

Get the ALife actor server object.

Type Parameters ​

Type Parameter
T extends cse_alife_creature_actor

Returns ​

T

Actor object registered in the ALife graph.

Throws ​

If no active ALife simulator exists.

Implementation of ​

ts
alife_simulator.actor

add_in_restriction ​

ts
add_in_restriction: Mock<UnknownFunction>;

Add an inside-space restriction to an offline monster.

Remarks ​

monster must be a registered monster server object. restrictorId should point to a space restrictor.

Param ​

monster

Monster server object to restrict.

Param ​

restrictorId

Restrictor object id.

Implementation of ​

ts
alife_simulator.add_in_restriction

add_out_restriction ​

ts
add_out_restriction: Mock<UnknownFunction>;

Add an outside-space restriction to an offline monster.

Remarks ​

monster must be a registered monster server object. restrictorId should point to a space restrictor.

Param ​

monster

Monster server object to restrict.

Param ​

restrictorId

Restrictor object id.

Implementation of ​

ts
alife_simulator.add_out_restriction

clone_weapon ​

ts
clone_weapon: Mock<(_object: cse_abstract, section: string, position: vector, levelVertexId: number, gameVertexId: number, parentId: number, shouldRegister: boolean) => cse_alife_object>;

Clone a registered magazined weapon server object.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source ​

src/xrGame/alife_simulator_script.cpp, alife_simulator.clone_weapon binding.

Remarks ​

Returns null when the source object is not a magazined weapon or when the clone cannot be spawned as a magazined weapon. By default the clone is reprocessed through the spawn packet path and registered.

Param ​

object

Source server weapon object.

Param ​

section

Section to spawn for the clone.

Param ​

position

Clone position.

Param ​

level_vertex_id

Clone level vertex id.

Param ​

game_vertex_id

Clone game graph vertex id.

Param ​

parent_id

Parent object id, or 65535 for no parent.

Returns ​

Spawned clone object, or null.

Implementation of ​

ts
alife_simulator.clone_weapon

create ​

ts
create: {
<T>  (spawn_id: number): T;
<T>  (section: string, position: vector, level_vertex_id: number, game_vertex_id: number, parent_object_id?: number): T;
<T>  (section: string, position: vector, level_vertex_id: number, game_vertex_id: number, parent_object_id: number, reg: boolean): T;
};

Create an object from a spawn graph id.

Call Signature ​

ts
<T>(spawn_id: number): T;
Type Parameters ​
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters ​
ParameterType
spawn_idnumber
Returns ​

T

Call Signature ​

ts
<T>(
   section: string, 
   position: vector, 
   level_vertex_id: number, 
   game_vertex_id: number, 
   parent_object_id?: number): T;

Spawn a server object by section.

Type Parameters ​
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters ​
ParameterTypeDescription
sectionstringObject section name.
positionvectorSpawn position.
level_vertex_idnumberLevel vertex id at the spawn position.
game_vertex_idnumberGame graph vertex id at the spawn position.
parent_object_id?numberOptional parent inventory or container id.
Returns ​

T

Created server object, or null when a non-empty parent id is invalid.

Remarks ​

If a non-empty parent id is invalid, the engine logs the error and returns null.

Call Signature ​

ts
<T>(
   section: string, 
   position: vector, 
   level_vertex_id: number, 
   game_vertex_id: number, 
   parent_object_id: number, 
   reg: boolean): T;

Spawn a server object and optionally defer network registration.

Type Parameters ​
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters ​
ParameterTypeDescription
sectionstringObject section name.
positionvectorSpawn position.
level_vertex_idnumberLevel vertex id at the spawn position.
game_vertex_idnumberGame graph vertex id at the spawn position.
parent_object_idnumberParent inventory or container id.
regbooleanWhether to register the object immediately.
Returns ​

T

Created server object, or null when a non-empty parent id is invalid.

Remarks ​

Passing reg = false returns the unregistered server object so scripts can edit its packet before registering it manually. If a non-empty parent id is invalid, the engine logs the error and returns null.

Throws ​

If spawn_id does not exist or does not resolve to a dynamic ALife object.

Param ​

spawn_id

Spawn graph id.

Returns ​

Created server object.

Implementation of ​

ts
alife_simulator.create

create_ammo ​

ts
create_ammo: Mock<(section: string, position: vector, levelVertexId: number, gameVertexId: number, _parentId: number, _count: number) => cse_alife_object>;

Spawn ammo with a custom amount left in the box.

Remarks ​

The section must spawn a server ammo object, and count must not exceed the ammo box size.

Throws ​

If the spawned section is not ammo, or if count is larger than the box size.

Param ​

section

Ammo section name.

Param ​

position

Spawn position.

Param ​

level_vertex_id

Level vertex id at the spawn position.

Param ​

game_vertex_id

Game graph vertex id at the spawn position.

Param ​

parent_object_id

Parent inventory or container id, or 65535 for no parent.

Param ​

count

Amount of ammo in the spawned box.

Returns ​

Spawned server object, or null when a non-empty parent id is invalid.

Implementation of ​

ts
alife_simulator.create_ammo

dont_has_info ​

ts
dont_has_info: Mock<(objectId: number, infoId: string) => boolean>;

Check that an object does not know an info portion.

Param ​

object_id

ALife object id.

Param ​

info_id

Info portion id.

Returns ​

Whether the object does not have the info portion.

Implementation of ​

ts
alife_simulator.dont_has_info

get_children ​

ts
get_children: Mock<(object: cse_abstract) => LuaIterable<number, undefined>>;

Get child object ids for a server object.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source ​

src/xrGame/alife_simulator_script.cpp, alife_simulator.get_children binding.

Param ​

object

Server object whose child id list should be exposed.

Returns ​

Iterable child object ids.

Implementation of ​

ts
alife_simulator.get_children

has_info ​

ts
has_info: Mock<(objectId: number, infoId: string) => boolean>;

Check that an object knows an info portion.

Param ​

object_id

ALife object id.

Param ​

info_id

Info portion id.

Returns ​

Whether the object has the info portion.

Implementation of ​

ts
alife_simulator.has_info

iterate_info ​

ts
iterate_info: Mock<(objectId: number, cb: (objectId: number, infoId: string) => void) => void>;

Iterate info portions known by an ALife object.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source ​

src/xrGame/alife_simulator_script.cpp, alife_simulator.iterate_info binding.

Remarks ​

Does nothing when the object has no info registry.

Param ​

object_id

ALife object id.

Param ​

cb

Callback called with the object id and each known info portion id.

Implementation of ​

ts
alife_simulator.iterate_info

iterate_objects ​

ts
iterate_objects: Mock<(cb: (object: cse_alife_object) => void) => void>;

Iterate over registered ALife objects until the callback returns true.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Remarks ​

Returning true from the callback stops iteration early.

Param ​

cb

Callback called for every server object.

Implementation of ​

ts
alife_simulator.iterate_objects

kill_entity ​

ts
kill_entity: Mock<(monster: cse_alife_monster_abstract) => void>;

Kill an offline monster.

Remarks ​

Use only for monster server objects registered in ALife.

Throws ​

If monster is not a valid ALife monster object.

Param ​

monster

Monster server object.

Param ​

graph_id

Optional game graph vertex id used as death location.

Param ​

schedulable

Optional killer or source object.

Implementation of ​

ts
alife_simulator.kill_entity

level_id ​

ts
level_id: Mock<() => number>;

Get the current level id from the active ALife graph.

Returns ​

Current level id.

Implementation of ​

ts
alife_simulator.level_id

level_name ​

ts
level_name: <T>(level_id: number) => T;

Method to get level name based on level ID. Easy way to get level is to get it by game vertex ID graph or iterate over all levels in graphs.

Type Parameters ​

Type ParameterDefault type
T extends stringstring

Parameters ​

ParameterTypeDescription
level_idnumberID of the level.

Returns ​

T

Level name based on level ID provided.

Throws ​

If level_id is not present in the game graph header.

Implementation of ​

ts
alife_simulator.level_name

object ​

ts
object: {
<T>  (object_id: number, no_assert?: boolean): Nullable<T>;
<T>  (name: string): Nullable<T>;
};

Get a server object by id.

Call Signature ​

ts
<T>(object_id: number, no_assert?: boolean): Nullable<T>;
Type Parameters ​
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters ​
ParameterType
object_idnumber
no_assert?boolean
Returns ​

Nullable<T>

Call Signature ​

ts
<T>(name: string): Nullable<T>;

Get a server object by its engine replacement name.

Type Parameters ​
Type ParameterDefault type
T extends cse_alife_objectcse_alife_object
Parameters ​
ParameterTypeDescription
namestringServer object replacement name.
Returns ​

Nullable<T>

Matching server object, or null.

Remarks ​

With the default id overload, an invalid id is logged and returns null. Pass no_assert to use the raw engine lookup mode.

Param ​

object_id

ALife object id.

Param ​

no_assert

Return null instead of asserting when the object is missing.

Returns ​

Matching server object, or null.

Implementation of ​

ts
alife_simulator.object

objectSwitchDistance ​

ts
objectSwitchDistance: number = 150;

register ​

ts
register: Mock<(object: cse_abstract) => cse_abstract>;

Reprocess and register a server object through the spawn packet path.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source ​

src/xrGame/alife_simulator_script.cpp, alife_simulator.register binding.

Remarks ​

The native helper serializes the object, frees its current id, destroys the old instance, and processes a new spawn packet. The returned object is the registered replacement.

Param ​

object

Server object to reprocess.

Returns ​

Registered replacement server object.

Implementation of ​

ts
alife_simulator.register

release ​

ts
release: Mock<(object: cse_alife_object) => void>;

Release an ALife object from the simulator.

Remarks ​

Online objects are destroyed through a network event. Offline objects are removed from ALife immediately.

Throws ​

If object is null or is not an ALife object.

Param ​

object

Object to remove.

Param ​

flag

Compatibility flag accepted by the engine binding.

Implementation of ​

ts
alife_simulator.release

remove_all_restrictions ​

ts
remove_all_restrictions: Mock<UnknownFunction>;

Remove all restrictions of one type from an object.

Remarks ​

objectId must resolve to an ALife object that has restriction storage.

Param ​

objectId

Restricted object id.

Param ​

type

Restriction type.

Implementation of ​

ts
alife_simulator.remove_all_restrictions

remove_in_restriction ​

ts
remove_in_restriction: Mock<UnknownFunction>;

Remove an inside-space restriction from an offline monster.

Remarks ​

monster must be a registered monster server object.

Param ​

monster

Monster server object to update.

Param ​

restrictorId

Restrictor object id.

Implementation of ​

ts
alife_simulator.remove_in_restriction

remove_out_restriction ​

ts
remove_out_restriction: Mock<UnknownFunction>;

Remove an outside-space restriction from an offline monster.

Remarks ​

monster must be a registered monster server object.

Param ​

monster

Monster server object to update.

Param ​

restrictorId

Restrictor object id.

Implementation of ​

ts
alife_simulator.remove_out_restriction

set_interactive ​

ts
set_interactive: Mock<UnknownFunction>;

Enable or disable interaction for an ALife object.

Remarks ​

objectId must resolve to a registered ALife object.

Param ​

objectId

ALife object id.

Param ​

enabled

New interaction state.

Implementation of ​

ts
alife_simulator.set_interactive

set_objects_per_update ​

ts
set_objects_per_update: Mock<() => void>;

Set count of object updated in alife per one tick.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Param ​

count

Count of objects to update per tick.

Implementation of ​

ts
alife_simulator.set_objects_per_update

set_process_time ​

ts
set_process_time: Mock<UnknownFunction>;

Set ALife processing time budget in microseconds.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Source ​

src/xrGame/alife_simulator_script.cpp, alife_simulator.set_process_time binding.

Param ​

microseconds

Processing time budget.

Implementation of ​

ts
alife_simulator.set_process_time

set_switch_distance ​

ts
set_switch_distance: Mock<(distance: number) => void>;

Set the online/offline switch distance.

Since ​

OpenXRay 2022-06-29, 09598fe7, PR #1033

Param ​

distance

Switch distance in meters.

Implementation of ​

ts
alife_simulator.set_switch_distance

set_switch_offline ​

ts
set_switch_offline: Mock<UnknownFunction>;

Allow or forbid switching an ALife object offline.

Remarks ​

objectId must resolve to a registered ALife object.

Param ​

objectId

ALife object id.

Param ​

enabled

New offline switching state.

Implementation of ​

ts
alife_simulator.set_switch_offline

set_switch_online ​

ts
set_switch_online: Mock<UnknownFunction>;

Allow or forbid switching an ALife object online.

Remarks ​

objectId must resolve to a registered ALife object.

Param ​

objectId

ALife object id.

Param ​

enabled

New online switching state.

Implementation of ​

ts
alife_simulator.set_switch_online

spawn_id ​

ts
spawn_id: Mock<(spawnStoryId: number) => number>;

Resolve a spawn story id to a spawn graph id.

Param ​

spawnStoryId

Spawn story id.

Returns ​

Spawn graph id.

Implementation of ​

ts
alife_simulator.spawn_id

story_object ​

ts
story_object: Mock<(sid: number) => cse_alife_object | null>;

Get a server object by story id.

Param ​

storyId

Story id.

Returns ​

Matching server object, or null when it is not registered.

Implementation of ​

ts
alife_simulator.story_object

switch_distance ​

ts
switch_distance: Mock<(distance?: number) => number>;

Returns ​

Alife server-client switch distance.

Implementation of ​

ts
alife_simulator.switch_distance

teleport_object ​

ts
teleport_object: Mock<(objectId: number, gameVertexId: number, levelVertexId: number, position: vector) => void>;

Move a server object to another graph and level vertex.

Since ​

OpenXRay 2017-08-15, 565b39e5

Param ​

object_id

Object id to teleport.

Param ​

game_vertex_id

Destination game graph vertex id.

Param ​

level_vertex_id

Destination level vertex id.

Param ​

position

Destination position.

Implementation of ​

ts
alife_simulator.teleport_object

valid_object_id ​

ts
valid_object_id: Mock<(objectId: number) => boolean>;

Check whether an object id is usable.

Remarks ​

This only checks the engine invalid id value. It does not prove that an object with this id is registered.

Param ​

object_id

ALife object id.

Returns ​

Whether the id is not the engine invalid id.

Implementation of ​

ts
alife_simulator.valid_object_id

simulator ​

ts
static simulator: MockAlifeSimulator | null = null;