Anvil
Loading...
Searching...
No Matches
Anvil.API.NwObject Class Referenceabstract

Base class for all world entities (game objects) and containers (modules, areas). More...

+ Inheritance diagram for Anvil.API.NwObject:
+ Collaboration diagram for Anvil.API.NwObject:

Public Member Functions

async Task AddActionToQueue (System.Action action)
 Inserts the function call aCommand into the Action Queue, ensuring the calling object will perform actions in a particular order.
 
void ClearActionQueue (bool clearCombatState=false)
 Clear all the object's actions.
 
void ClearEventSubscriptions ()
 Clears any event subscriptions associated with this object.
 
bool Equals (NwObject? other)
 
override bool Equals (object? obj)
 
void ForceRefreshUUID ()
 
string GetEventScript (EventScriptType eventType)
 Gets the script assigned to run for the specified object event.
 
override int GetHashCode ()
 
GetObjectVariable< T > (string name)
 Gets the specified object variable for this object.
 
bool IsEventLocked (EventScriptType eventType)
 Gets a value indicating whether the event script can be modified for the specified event.
 
Guid? PeekUUID ()
 Attempts to get the UUID of this object, if assigned.
 
Json SerializeToJson (bool saveObjectState)
 Serializes this game object to a json representation.
 
void SetEventScript (EventScriptType eventType, string? script)
 Sets the script to be run on the specified object event.
 
async Task SpeakString (string message, TalkVolume talkVolume=TalkVolume.Talk, bool queueAsAction=false)
 Instructs this object to speak.
 
override string ToString ()
 The ID of this object as a string. Can be used in StringExtensions.ParseObject while the object is alive.
This cannot be used across server restarts. See UUID for a persistent unique identifier.
 
bool TryGetUUID (out Guid uid)
 Attempts to get the UUID for this object, assigning a new ID if it does not already exist.

 
async Task WaitForObjectContext ()
 Notifies then awaits for this object to become the current active object for the purpose of implicitly assigned values (e.g. effect creators).
If the current active object is already this object, then the code runs immediately. Otherwise, it will be run with all other closures.
This is the async equivalent of AssignCommand in NWScript.
 

Static Public Member Functions

static IEnumerable< T > FindObjectsOfType< T > ()
 Locates all objects of the specified type.
 
static IEnumerable< NwObjectFindObjectsWithTag (params string[] tags)
 Locates all objects of that have the specified tag.
 
static IEnumerable< T > FindObjectsWithTag< T > (params string[] tags)
 Locates all objects of the specified type that have the specified tag.
 
static implicit operator uint (NwObject? gameObject)
 
static bool operator!= (NwObject? left, NwObject? right)
 
static bool operator== (NwObject? left, NwObject? right)
 

Public Attributes

readonly uint ObjectId
 The ID of this object instance. Not persistent, changes after every spawn of the object.
See UUID for a persistent unique ID for objects.
 

Protected Member Functions

 NwObject (ICGameObject gameObject)
 Base class for all world entities (game objects) and containers (modules, areas).
 
void AssertObjectValid ()
 

Properties

string Description [get, set]
 Gets or sets the description for this object.
 
static EventService EventService = null! [get]
 
bool HasUUID [get]
 Gets a value indicating whether this object has an assigned UUID.
 
bool IsValid [get]
 Gets a value indicating whether this is a valid object.
 
IEnumerable< ObjectVariableLocalVariables [get]
 Gets all local variables assigned on this object.
 
string Name [get, set]
 Gets or sets the name of this object.
 
static Lazy< ObjectVisibilityService > ObjectVisibilityService = null! [get]
 
string OriginalDescription [get]
 Gets the original description for this object as defined in the toolset.
 
static ResourceManager ResourceManager = null! [get]
 
string ResRef [get]
 Gets the resource reference used to create this object.
 
string Tag [get, set]
 Gets or sets the tag for this object.
 
Guid UUID [get]
 Gets the globally unique identifier for this object.
 
static VirtualMachine VirtualMachine = null! [get]
 

Detailed Description

Base class for all world entities (game objects) and containers (modules, areas).

Member Function Documentation

◆ ClearActionQueue()

void Anvil.API.NwObject.ClearActionQueue ( bool clearCombatState = false)
inline

Clear all the object's actions.

  • No return value, but if an error occurs, the log file will contain "ClearAllActions failed.".
  • clearCombatState: if true, this will immediately clear the combat state on a creature, which will stop the combat music and allow them to rest, engage in dialog, or other actions that they would normally have to wait for.

◆ FindObjectsOfType< T >()

static IEnumerable< T > Anvil.API.NwObject.FindObjectsOfType< T > ( )
inlinestatic

Locates all objects of the specified type.

Template Parameters
TThe type of objects to search.
Returns
An enumeration containing all objects of the specified type.
Type Constraints
T :NwObject 

◆ FindObjectsWithTag()

static IEnumerable< NwObject > Anvil.API.NwObject.FindObjectsWithTag ( params string[] tags)
inlinestatic

Locates all objects of that have the specified tag.

Parameters
tagsThe tag/s of the objects to locate.
Returns
An enumeration containing all objects with the specified tags.

◆ FindObjectsWithTag< T >()

static IEnumerable< T > Anvil.API.NwObject.FindObjectsWithTag< T > ( params string[] tags)
inlinestatic

Locates all objects of the specified type that have the specified tag.

Parameters
tagsThe tag/s of the objects to locate.
Template Parameters
TThe type of objects to search.
Returns
An enumeration containing all objects with the specified tags.
Type Constraints
T :NwObject 

◆ GetEventScript()

string Anvil.API.NwObject.GetEventScript ( EventScriptType eventType)
inline

Gets the script assigned to run for the specified object event.

Parameters
eventTypeThe event type to query.
Returns
The script that has been assigned to the event, otherwise an string.Empty string.

◆ GetObjectVariable< T >()

T Anvil.API.NwObject.GetObjectVariable< T > ( string name)
inline

Gets the specified object variable for this object.

Parameters
nameThe variable name.
Template Parameters
TThe variable type.
Returns
A LocalVariable instance for getting/setting the variable's value.
Type Constraints
T :ObjectVariable 
T :new() 

◆ IsEventLocked()

bool Anvil.API.NwObject.IsEventLocked ( EventScriptType eventType)
inline

Gets a value indicating whether the event script can be modified for the specified event.

Parameters
eventTypeThe event type to query.
Returns
True if the event is locked and the script cannot be modified, otherwise false.

◆ PeekUUID()

Guid? Anvil.API.NwObject.PeekUUID ( )
abstract

Attempts to get the UUID of this object, if assigned.

Returns
The UUID if assigned, otherwise no value.

◆ SetEventScript()

void Anvil.API.NwObject.SetEventScript ( EventScriptType eventType,
string? script )
inline

Sets the script to be run on the specified object event.

Parameters
eventTypeThe event to be assigned.
scriptThe new script to assign to this event.
Exceptions
InvalidOperationExceptionThrown if setting the event script failed. This can be from an invalid event script type, or this event is locked as a service has subscribed to this event. See IsEventLocked to determine if an event script can be changed.
ArgumentOutOfRangeExceptionThrown if the specified script name is invalid.

◆ SpeakString()

async Task Anvil.API.NwObject.SpeakString ( string message,
TalkVolume talkVolume = TalkVolume::Talk,
bool queueAsAction = false )
inline

Instructs this object to speak.

Parameters
messageThe message the object should speak.
talkVolumeThe channel/volume of this message.
queueAsActionWhether the object should speak immediately (false), or be queued in the object's action queue (true).

◆ TryGetUUID()

bool Anvil.API.NwObject.TryGetUUID ( out Guid uid)
inline

Attempts to get the UUID for this object, assigning a new ID if it does not already exist.

See PeekUUID to check if the object has an existing UUID, without creating a new one.
This function will return false if the UUID is not globally unique, and conflicts with an existing object.

Parameters
uidThe object's UUID.
Returns
True if the object has a valid unique identifier, otherwise false.

Property Documentation

◆ UUID

Guid Anvil.API.NwObject.UUID
get

Gets the globally unique identifier for this object.

If the UUID conflicts with an existing object, a new one will be generated.
Use TryGetUUID to control this behaviour.


The documentation for this class was generated from the following files: