Class: MockAlifeSimulator
Mock alife simulator registry containing data with server objects.
Implements
alife_simulator
Accessors
infoPortions
Get Signature
get static infoPortions(): Record<number, Set<string>>;Returns
Record<number, Set<string>>
Set Signature
set static infoPortions(value: Record<number, Set<string>>): void;Parameters
| Parameter | Type |
|---|---|
value | Record<number, Set<string>> |
Returns
void
registry
Get Signature
get static registry(): Record<number, cse_alife_object>;Returns
Record<number, cse_alife_object>
Set Signature
set static registry(value: Record<number, cse_alife_object>): void;Parameters
| Parameter | Type |
|---|---|
value | Record<number, cse_alife_object> |
Returns
void
Constructors
Constructor
new MockAlifeSimulator(): MockAlifeSimulator;Returns
MockAlifeSimulator
Methods
addToRegistry()
static addToRegistry(object: cse_alife_object): void;Parameters
| Parameter | Type |
|---|---|
object | cse_alife_object |
Returns
void
create()
static create(): MockAlifeSimulator;Returns
MockAlifeSimulator
getFromRegistry()
static getFromRegistry<T>(id: number): T | null;Type Parameters
| Type Parameter | Default type |
|---|---|
T extends cse_alife_object | cse_alife_object |
Parameters
| Parameter | Type |
|---|---|
id | number |
Returns
T | null
getInstance()
static getInstance(): MockAlifeSimulator;Returns
MockAlifeSimulator
mock()
static mock(): alife_simulator;Returns
alife_simulator
removeFromRegistry()
static removeFromRegistry(id: number): void;Parameters
| Parameter | Type |
|---|---|
id | number |
Returns
void
reset()
static reset(): void;Returns
void
Properties
actor
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
alife_simulator.actoradd_in_restriction
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
alife_simulator.add_in_restrictionadd_out_restriction
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
alife_simulator.add_out_restrictionclone_weapon
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
alife_simulator.clone_weaponcreate
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
<T>(spawn_id: number): T;Type Parameters
| Type Parameter | Default type |
|---|---|
T extends cse_alife_object | cse_alife_object |
Parameters
| Parameter | Type |
|---|---|
spawn_id | number |
Returns
T
Call Signature
<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 Parameter | Default type |
|---|---|
T extends cse_alife_object | cse_alife_object |
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Object section name. |
position | vector | Spawn position. |
level_vertex_id | number | Level vertex id at the spawn position. |
game_vertex_id | number | Game graph vertex id at the spawn position. |
parent_object_id? | number | Optional 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
<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 Parameter | Default type |
|---|---|
T extends cse_alife_object | cse_alife_object |
Parameters
| Parameter | Type | Description |
|---|---|---|
section | string | Object section name. |
position | vector | Spawn position. |
level_vertex_id | number | Level vertex id at the spawn position. |
game_vertex_id | number | Game graph vertex id at the spawn position. |
parent_object_id | number | Parent inventory or container id. |
reg | boolean | Whether 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
alife_simulator.createcreate_ammo
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
alife_simulator.create_ammodont_has_info
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
alife_simulator.dont_has_infoget_children
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
alife_simulator.get_childrenhas_info
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
alife_simulator.has_infoiterate_info
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
alife_simulator.iterate_infoiterate_objects
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
alife_simulator.iterate_objectskill_entity
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
alife_simulator.kill_entitylevel_id
level_id: Mock<() => number>;Get the current level id from the active ALife graph.
Returns
Current level id.
Implementation of
alife_simulator.level_idlevel_name
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 Parameter | Default type |
|---|---|
T extends string | string |
Parameters
| Parameter | Type | Description |
|---|---|---|
level_id | number | ID 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
alife_simulator.level_nameobject
object: {
<T> (object_id: number, no_assert?: boolean): Nullable<T>;
<T> (name: string): Nullable<T>;
};Get a server object by id.
Call Signature
<T>(object_id: number, no_assert?: boolean): Nullable<T>;Type Parameters
| Type Parameter | Default type |
|---|---|
T extends cse_alife_object | cse_alife_object |
Parameters
| Parameter | Type |
|---|---|
object_id | number |
no_assert? | boolean |
Returns
Nullable<T>
Call Signature
<T>(name: string): Nullable<T>;Get a server object by its engine replacement name.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends cse_alife_object | cse_alife_object |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Server 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
alife_simulator.objectobjectSwitchDistance
objectSwitchDistance: number = 150;register
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
alife_simulator.registerrelease
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
alife_simulator.releaseremove_all_restrictions
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
alife_simulator.remove_all_restrictionsremove_in_restriction
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
alife_simulator.remove_in_restrictionremove_out_restriction
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
alife_simulator.remove_out_restrictionset_interactive
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
alife_simulator.set_interactiveset_objects_per_update
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
alife_simulator.set_objects_per_updateset_process_time
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
alife_simulator.set_process_timeset_switch_distance
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
alife_simulator.set_switch_distanceset_switch_offline
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
alife_simulator.set_switch_offlineset_switch_online
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
alife_simulator.set_switch_onlinespawn_id
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
alife_simulator.spawn_idstory_object
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
alife_simulator.story_objectswitch_distance
switch_distance: Mock<(distance?: number) => number>;Returns
Alife server-client switch distance.
Implementation of
alife_simulator.switch_distanceteleport_object
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
alife_simulator.teleport_objectvalid_object_id
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
alife_simulator.valid_object_idsimulator
static simulator: MockAlifeSimulator | null = null;