Photon Bolt Engine API 1.3

Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
Photon.Bolt.BoltEntity Class Reference

A Game Entity within the Bolt simulation. More...

Inheritance diagram for Photon.Bolt.BoltEntity:

Public Member Functions

void AddEventCallback< T > (Action< T > callback)
 Add a event callback to this entity. More...
 
void AddEventListener (UE.MonoBehaviour behaviour)
 Add an event listener to this entity. More...
 
void AssignControl (BoltConnection connection)
 Assigns control of this entity to a connection More...
 
void AssignControl (BoltConnection connection, IProtocolToken token)
 Assigns control of this entity to a connection More...
 
void ClearInputQueue ()
 
void DestroyDelayed (float time)
 Destroy this entity after a given delay More...
 
void Freeze (bool pause)
 Freeze or unfreeze an entity More...
 
TState GetState< TState > ()
 Get the state if this entity More...
 
void Idle (BoltConnection connection, bool idle)
 Set this entity as idle on the supplied connection, this means that the connection will not receive update state for this entity as long as it's idle. More...
 
bool IsController (BoltConnection connection)
 Checks if this entity is being controlled by the connection More...
 
BoltEntitySettingsModifier ModifySettings ()
 Creates an object which lets you modify the internal settings of an entity before it is attached to Bolt. More...
 
bool QueueInput (INetworkCommandData data, bool force=false)
 Queue an input data on this entity for execution. This is called on a client which is controlling a proxied entity. The data will be sent to the server for authoritative execution More...
 
void ReleaseControl ()
 Releases local control of this entity More...
 
void ReleaseControl (IProtocolToken token)
 Releases local control of this entity More...
 
void RemoveEventCallback< T > (Action< T > callback)
 Remove a event callback to this entity. More...
 
void RemoveEventListener (UE.MonoBehaviour behaviour)
 Remove an event listern from this entity More...
 
void RevokeControl ()
 Revokes control of this entity from a connection More...
 
void RevokeControl (IProtocolToken token)
 Revokes control of this entity from a connection More...
 
void SetParent (BoltEntity parent)
 Sets the parent of this entity More...
 
void SetScope (BoltConnection connection, bool inScope, bool force=false)
 Sets the scope for the connection passed in for this entity. Only usable if Scope Mode has been set to Manual. More...
 
void SetScopeAll (bool inScope, bool force=false)
 Sets the scope of all currently active connections for this entity. Only usable if Scope Mode has been set to Manual. More...
 
bool StateIs (Type t)
 Checks which type of state this entity has More...
 
bool StateIs< TState > ()
 Checks which type of state this entity has More...
 
void TakeControl ()
 Takes local control of this entity More...
 
void TakeControl (IProtocolToken token)
 Takes local control of this entity More...
 
override string ToString ()
 String representation of the entity More...
 
bool TryFindState< TState > (out TState state)
 A null safe way to look for a specific type of state on an entity More...
 

Static Public Member Functions

static implicit operator UE.GameObject (BoltEntity entity)
 

Public Attributes

IProtocolToken AttachToken => Entity.AttachToken
 
IProtocolToken ControlGainedToken => Entity.ControlGainedToken
 
BoltConnection Controller => Entity.Controller
 If this entity is controlled by a remote connection it contains that connection, otherwise null More...
 
IProtocolToken ControlLostToken => Entity.ControlLostToken
 
IProtocolToken DetachToken => Entity.DetachToken
 
bool HasControl => Entity.HasControl
 Do we have control of this entity? More...
 
bool HasControlWithPrediction => Entity.HasPredictedControl
 Do we have control of this entity and are we using client side prediction More...
 
bool HasParent => Entity.HasParent
 Gets a value indicating whether this T:BoltEntity has parent. More...
 
bool IsAttached => BoltNetwork.IsRunning && (_entity != null) && _entity.IsAttached
 If this entity is attached to Bolt or not More...
 
bool IsControlled => HasControl || Controller != null
 
bool IsControllerOrOwner => HasControl || IsOwner
 
bool IsFrozen => Entity.IsFrozen
 If this entity is currently paused More...
 
bool IsInputQueueFull => Entity.CommandQueue.count == BoltCore._config.commandQueueSize
 Gets a value indicating whether this T:BoltEntity has its input queue full. More...
 
bool IsOwner => Entity.IsOwner
 Did the local computer create this entity or not? More...
 
bool IsSceneObject => Entity.IsSceneObject
 This is a scene object placed in the scene in the Unity editor More...
 
NetworkId NetworkId => Entity.NetworkId
 The unique id of this entity More...
 
bool PersistsOnSceneLoad => Entity.PersistsOnSceneLoad
 Should this entity persist between scene loads More...
 
PrefabId PrefabId => new PrefabId(_prefabId)
 The prefabId used to instantiate this entity More...
 
BoltConnection Source => Entity.Source
 If this entity was created on another computer, contains the connection we received this entity from, otherwise null More...
 

Properties

bool CanFreeze [get, set]
 Whether the entity can be paused / frozen More...
 

Detailed Description

A Game Entity within the Bolt simulation.

Example: Instantiating and taking control of a new BoltEntity that will replicate to all connected clients.

public void InstantiateEntity() {
BoltEntity entity = BoltNetwork.Instantiate(BoltPrefabs.Player, RandomSpawn(), Quaternion.identity);
entity.TakeControl();
}

Member Function Documentation

◆ AddEventCallback< T >()

void Photon.Bolt.BoltEntity.AddEventCallback< T > ( Action< T >  callback)
inline

Add a event callback to this entity.

Type Constraints
T :Event 

◆ AddEventListener()

void Photon.Bolt.BoltEntity.AddEventListener ( UE.MonoBehaviour  behaviour)
inline

Add an event listener to this entity.

Parameters
behaviourThe behaviour to invoke event callbacks on

◆ AssignControl() [1/2]

void Photon.Bolt.BoltEntity.AssignControl ( BoltConnection  connection)
inline

Assigns control of this entity to a connection

Parameters
connectionThe connection to assign control to

Example: Instantiating and assigning control of an entity to a newly connected player.

public override void Connected(BoltConnection connection) {
var playerEntity = BoltNetwork.Instantiate(BoltPrefabs.Player, RandomSpawn(), Quaternion.Identity);
playerEntity.AssignControl(connection);
}

◆ AssignControl() [2/2]

void Photon.Bolt.BoltEntity.AssignControl ( BoltConnection  connection,
IProtocolToken  token 
)
inline

Assigns control of this entity to a connection

Parameters
connectionThe connection to assign control to
tokenA data token of max size 512 bytes

Example: Instantiating and assigning control of an entity to a newly connected player.

public override void Connected(BoltConnection connection, IProtocolToken token) {
var playerEntity = BoltNetwork.Instantiate(BoltPrefabs.Player, RandomSpawn(), Quaternion.Identity);
var fingerprint = ((UserInfo)token).fingerprint;
PlayerLoadout loadout;
if(playerDatabase.Contains(fingerprint, out loadout)) {
playerEntity.AssignControl(connection, loadout);
}
else {
playerEntity.AssignControl(connection, new BeginnerLoadout());
}
}

◆ ClearInputQueue()

void Photon.Bolt.BoltEntity.ClearInputQueue ( )
inline

◆ DestroyDelayed()

void Photon.Bolt.BoltEntity.DestroyDelayed ( float  time)
inline

Destroy this entity after a given delay

Parameters
timeThe time interval to delay

Example: A death routine that makes state changes and initiates a destruction with configurable delay.

void OnDeath(BoltEntity entity) {
var state = entity.GetState<ILivingEntity>();
state.alive = false;
state.DeathTrigger();
entity.DestroyDelayed(ServerConfig.DESTRUCT_DELAY);
}

◆ Freeze()

void Photon.Bolt.BoltEntity.Freeze ( bool  pause)
inline

Freeze or unfreeze an entity

Parameters
pauseTrue if entity should freeze and false to unfreeze

Example: Pausing all entities.

void Pause() {
foreach(BoltEntity entity in BoltNetwork.entities) {
if(entity.CanFreeze) {
entity.Freeze(true);
}
}
}

◆ GetState< TState >()

TState Photon.Bolt.BoltEntity.GetState< TState > ( )
inline

Get the state if this entity

Template Parameters
TStateThe type of state to get
Returns
The state

Example: Modifying the state of an entity to change its name.

public void RenameEntity(BoltEntity entity, string name) {
entity.GetState<IPlayerState>().name = name;
}

◆ Idle()

void Photon.Bolt.BoltEntity.Idle ( BoltConnection  connection,
bool  idle 
)
inline

Set this entity as idle on the supplied connection, this means that the connection will not receive update state for this entity as long as it's idle.

Parameters
connectionThe connection to idle the entity on
idleIf this should be idle or not

◆ IsController()

bool Photon.Bolt.BoltEntity.IsController ( BoltConnection  connection)
inline

Checks if this entity is being controlled by the connection

Parameters
connectionThe connection to check

◆ ModifySettings()

BoltEntitySettingsModifier Photon.Bolt.BoltEntity.ModifySettings ( )
inline

Creates an object which lets you modify the internal settings of an entity before it is attached to Bolt.

Returns
The object used to modify entity settings

◆ operator UE.GameObject()

static implicit Photon.Bolt.BoltEntity.operator UE.GameObject ( BoltEntity  entity)
inlinestatic

◆ QueueInput()

bool Photon.Bolt.BoltEntity.QueueInput ( INetworkCommandData  data,
bool  force = false 
)
inline

Queue an input data on this entity for execution. This is called on a client which is controlling a proxied entity. The data will be sent to the server for authoritative execution

Parameters
dataThe input data to queue
forceUsed to force the inclusion of this input, by discarding any other values if the Input Queue is full

Example: A SimulateController() loop that queues WASD-style movement input.

bool forward;
bool backward;
bool left;
bool right;
public override void SimulateController() {
IPlayerCommandInput input = PlayerCommand.Create();
PollKeys();
input.forward = forward;
input.backward = backward;
input.left = left;
input.right = right;
entity.QueueInput(input);
}

◆ ReleaseControl() [1/2]

void Photon.Bolt.BoltEntity.ReleaseControl ( )
inline

Releases local control of this entity

Example: Releasing control of an entity when it's not needed anymore.

public override void DropWeapon() {
if (entity.IsOwner &amp;&amp; entity.HasControl)
{
entity.ReleaseControl();
}
}

◆ ReleaseControl() [2/2]

void Photon.Bolt.BoltEntity.ReleaseControl ( IProtocolToken  token)
inline

Releases local control of this entity

Parameters
tokenA data token of max size 512 bytes

Example: Releasing control of an entity when it's not needed anymore.

public override void DropWeapon() {
if (entity.IsOwner &amp;&amp; entity.HasControl)
{
DropEvent evt = new DropEvent();
evt.EvtCode = DropEventCode.DROP_BY_HIT;
entity.ReleaseControl(evt);
}
}

◆ RemoveEventCallback< T >()

void Photon.Bolt.BoltEntity.RemoveEventCallback< T > ( Action< T >  callback)
inline

Remove a event callback to this entity.

Type Constraints
T :Event 

◆ RemoveEventListener()

void Photon.Bolt.BoltEntity.RemoveEventListener ( UE.MonoBehaviour  behaviour)
inline

Remove an event listern from this entity

Parameters
behaviourThe behaviour to remove

◆ RevokeControl() [1/2]

void Photon.Bolt.BoltEntity.RevokeControl ( )
inline

Revokes control of this entity from a connection

Example: A server-side stun routine that completely revokes control for the length of stun interval.

IEnumerator Stun(BoltEntity entity, float stunInterval) {
var controller = entity.Controller;
entity.RevokeControl();
entity.GetState<ILivingEntity>().stunned = true;
return new WaitForSeconds(stunInterval);
entity.AssignControl(controller);
entity.GetState<ILivingEntity>().stunned = false;
}

◆ RevokeControl() [2/2]

void Photon.Bolt.BoltEntity.RevokeControl ( IProtocolToken  token)
inline

Revokes control of this entity from a connection

Parameters
tokenA data token of max size 512 bytes

Example: A server-side stun routine that completely revokes control for the length of stun interval.

IEnumerator Stun(BoltEntity entity, float stunInterval) {
var controller = entity.Controller;
CombatEventData evtData = new CombatEventData();
evtData.stunInterval = stunInterval;
entity.RevokeControl(evtData);
entity.GetState<ILivingEntity>().stunned = true;
return new WaitForSeconds(stunInterval);
entity.AssignControl(controller);
entity.GetState<ILivingEntity>().stunned = false;
}

◆ SetParent()

void Photon.Bolt.BoltEntity.SetParent ( BoltEntity  parent)
inline

Sets the parent of this entity

Parameters
parentThe parent of this entity

Example: Instantiating a vehicle and taking control of it.

public void SpawnPlayerVehicle(BoltEntity playerEntity) {
var car = BoltNetwork.Instantiate(BoltPrefabs.Vehicle, playerEntity.transform.position, playerEntity.transform.rotation);
car.AssignContro(playerEntity.Controller);
playerEntity.RevokeControl();
playerEntity.SetParent(car);
}

◆ SetScope()

void Photon.Bolt.BoltEntity.SetScope ( BoltConnection  connection,
bool  inScope,
bool  force = false 
)
inline

Sets the scope for the connection passed in for this entity. Only usable if Scope Mode has been set to Manual.

Parameters
connectionThe connection being scoped
inScopeIf this entity should be in scope or not
forceForce the scope value, used in the case you want to remove from the scope an entity the connection has control

Example: A coroutine that renders a player invisible to enemies for a given time in seconds.

IEnumerator Stealth(BoltEntity entity, float stealthInterval) {
int team = entity.GetState<IPlayerState>().team;
foreach(BoltEntity adjEntity in BoltNetwork.entities) {
if(adjEntity == entity) continue;
if(!adjEntity.StateIs%ltIPlayerState%gt()) continue;
int adjTeam = adjEntity.GetState<IPlayerState>().team;
if(team != adjTeam) {
entity.SetScope(adjEntity.Controller, false);
}
}
yield return new WaitForSeconds(stealthInterval);
entity.SetScopeAll(true);
}

◆ SetScopeAll()

void Photon.Bolt.BoltEntity.SetScopeAll ( bool  inScope,
bool  force = false 
)
inline

Sets the scope of all currently active connections for this entity. Only usable if Scope Mode has been set to Manual.

Parameters
inScopeIf this entity should be in scope or not
forceForce the scope value, used in the case you want to remove from the scope an entity the connection has control

Example: A method which renders an entity invisible to all active client connections.

public void Disappear(BoltEntity entity) {
entity.SetScopeAll(false);
}

◆ StateIs()

bool Photon.Bolt.BoltEntity.StateIs ( Type  t)
inline

Checks which type of state this entity has

Parameters
tThe type of state to check for
Returns
True if this entity has a state of type TState otherwise false

Example: Discarding attack requests that do not target living entities.

public override void FireOnOwner(BoltEntity entity, BoltEntity target, AttackData attack) {
if(entity.IsOwner) {
if(!target.StateIs(typeof(ILivingEntity))) {
return;
}
target.GetState<ILivingEntity>().health -= attack.damage;
}
}

◆ StateIs< TState >()

bool Photon.Bolt.BoltEntity.StateIs< TState > ( )
inline

Checks which type of state this entity has

Template Parameters
TStateThe type of state to check for
Returns
True if this entity has a state of type TState otherwise false

Example: Discarding attack requests that do not target living entities.

public override void FireOnOwner(BoltEntity entity, BoltEntity target, AttackData attack) {
if(entity.IsOwner) {
if(!target.StateIs<ILivingEntity>()) {
return;
}
target.GetState<ILivingEntity>().health -= attack.damage;
}
}

◆ TakeControl() [1/2]

void Photon.Bolt.BoltEntity.TakeControl ( )
inline

Takes local control of this entity

Example: Spawning a server-side player entity.

void SpawnServerPlayer() {
var entity = Instantiate(BoltPrefabs.Player);
entity.TakeControl();
}

◆ TakeControl() [2/2]

void Photon.Bolt.BoltEntity.TakeControl ( IProtocolToken  token)
inline

Takes local control of this entity

Parameters
tokenA data token of max size 512 bytes

Example: Spawning a server-side player entity and initializing it with a local hotkey configuration.

HotkeyConfig hotkeys;
void SpawnServerPlayer() {
var entity = Instantiate(BoltPrefabs.Player);
entity.TakeControl(hotkeys);
}

◆ ToString()

override string Photon.Bolt.BoltEntity.ToString ( )
inline

String representation of the entity

Example: Logging new entities to the debug log.

public override void EntityAttached(BoltEntity entity) {
Debug.Log("Entity Attached: " + entity.ToString());
}

◆ TryFindState< TState >()

bool Photon.Bolt.BoltEntity.TryFindState< TState > ( out TState  state)
inline

A null safe way to look for a specific type of state on an entity

Template Parameters
TStateThe state type to search for
Parameters
stateEntity to search

Example: Pausing all player entities using TryFindState().

public void FreezeAllPlayers() {
foreach(BoltEntity entity in BoltNetwork.entities) {
IPlayerState state;
if(entity.TryGetState<IPlayerState>(out state)) {
entity.Freeze(true);
state.pausedByServer = true;
}
}
}

Member Data Documentation

◆ AttachToken

IProtocolToken Photon.Bolt.BoltEntity.AttachToken => Entity.AttachToken

◆ ControlGainedToken

IProtocolToken Photon.Bolt.BoltEntity.ControlGainedToken => Entity.ControlGainedToken

◆ Controller

BoltConnection Photon.Bolt.BoltEntity.Controller => Entity.Controller

If this entity is controlled by a remote connection it contains that connection, otherwise null

Example: Disconnecting a client when they run out of lives.

void OnDeath(BoltEntity entity) {
if(entity.GetState%ltILivingEntity>().lives == 0) {
entity.Controller.Disconnect(new ServerMessage("Game Over", "Zero Lives Remaining"));
}
}

◆ ControlLostToken

IProtocolToken Photon.Bolt.BoltEntity.ControlLostToken => Entity.ControlLostToken

◆ DetachToken

IProtocolToken Photon.Bolt.BoltEntity.DetachToken => Entity.DetachToken

◆ HasControl

bool Photon.Bolt.BoltEntity.HasControl => Entity.HasControl

Do we have control of this entity?

Example: Implementing a method to turn controlled entities green on the minimap.

public void AddKnownEntity(BoltEntity entity) {
_minimap.AddNewEntity(entity.NetworkId, entity);
if(entity.HasControl) {
_minimap.entities[entity.NetworkId].color = Color.Green;
}
}

◆ HasControlWithPrediction

bool Photon.Bolt.BoltEntity.HasControlWithPrediction => Entity.HasPredictedControl

Do we have control of this entity and are we using client side prediction

◆ HasParent

bool Photon.Bolt.BoltEntity.HasParent => Entity.HasParent

Gets a value indicating whether this T:BoltEntity has parent.

true if has parent; otherwise, false.

◆ IsAttached

bool Photon.Bolt.BoltEntity.IsAttached => BoltNetwork.IsRunning && (_entity != null) && _entity.IsAttached

If this entity is attached to Bolt or not

Example: Checking if an entity is still attached before trying to modify the state. This can occur if entities are destroyed immediately upon death.

void DealDamage(BoltEntity entity, AttackData atkData) { if(entity.IsAttached) { entity.GetState<ILivingEntity>().hp -= atkData.damage; } }

◆ IsControlled

bool Photon.Bolt.BoltEntity.IsControlled => HasControl || Controller != null

◆ IsControllerOrOwner

bool Photon.Bolt.BoltEntity.IsControllerOrOwner => HasControl || IsOwner

◆ IsFrozen

bool Photon.Bolt.BoltEntity.IsFrozen => Entity.IsFrozen

If this entity is currently paused

Example: Unpausing all frozen entities.

void Unpause() {
foreach(BoltEntity entity in BoltNetwork.entities) {
if(entity.isFrozen) {
entity.Freeze(false);
}
}
}

◆ IsInputQueueFull

bool Photon.Bolt.BoltEntity.IsInputQueueFull => Entity.CommandQueue.count == BoltCore._config.commandQueueSize

Gets a value indicating whether this T:BoltEntity has its input queue full.

true if is input queue full; otherwise, false.

◆ IsOwner

bool Photon.Bolt.BoltEntity.IsOwner => Entity.IsOwner

Did the local computer create this entity or not?

Example: Implementing an authoritative weapon firing method.

void FireWeapon(PlayerCommand cmd) {
if (activeWeapon.fireFrame + activeWeapon.refireRate <= BoltNetwork.serverFrame) {
activeWeapon.fireFrame = BoltNetwork.serverFrame;
state.Fire();
if (entity.IsOwner) {
activeWeapon.OnOwner(cmd, entity);
}
}
}

◆ IsSceneObject

bool Photon.Bolt.BoltEntity.IsSceneObject => Entity.IsSceneObject

This is a scene object placed in the scene in the Unity editor

Example: Configuring the state of initial buildings and minions during startup.

public override void BoltStartDone() {
foreach(BoltEntity entity in BoltNetwork.entities) {
if(entity.IsSceneObject) {
if(entity.StateIs<IStructure>()) {
StructureFactory.Configure(entity);
}
else if(entity.StateIs<IMinion>()) {
MinionFactory.Configure(entity);
}
}
}
}

◆ NetworkId

NetworkId Photon.Bolt.BoltEntity.NetworkId => Entity.NetworkId

The unique id of this entity

◆ PersistsOnSceneLoad

bool Photon.Bolt.BoltEntity.PersistsOnSceneLoad => Entity.PersistsOnSceneLoad

Should this entity persist between scene loads

Example: Pausing all persistent entities before changing scenes

public override void SceneLoadLocalBegin(string map) {
foreach(BoltEntity entity in BoltNetwork.entities) {
if(entity.PersistsOnSceneLoad) {
entity.Freeze(true);
}
}
}

◆ PrefabId

PrefabId Photon.Bolt.BoltEntity.PrefabId => new PrefabId(_prefabId)

The prefabId used to instantiate this entity

Example: Cloning an entity with prefabId.

BoltEntity Replicate(BoltEntity entity) {
return Instantiate(entity.PrefabId, entity.transform.position, entity.transform.rotation);
}

◆ Source

BoltConnection Photon.Bolt.BoltEntity.Source => Entity.Source

If this entity was created on another computer, contains the connection we received this entity from, otherwise null

Example: Using source to determine if an entity was originally instantiated on a remote host.

bool IsRemoteEntity(BoltEntity entity) {
return entity.source != null;
}

Property Documentation

◆ CanFreeze

bool Photon.Bolt.BoltEntity.CanFreeze
getset

Whether the entity can be paused / frozen

Example: Pausing all entities that can be frozen.

void Pause() {
foreach(BoltEntity entity in BoltNetwork.entities) {
if(entity.CanFreeze) {
entity.Freeze(true);
}
}
}