Table of Contents

Class PetController

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Controller for managing pet entities attached to a character. Handles pet state, network broadcasts, and event invocation.

public class PetController : CharacterBehaviour, IPetController, ICharacterBehaviour
Inheritance
Object
Component
Behaviour
MonoBehaviour
NetworkBehaviour
PetController
Implements
Inherited Members
NetworkBehaviour.IsSpawned
NetworkBehaviour.ComponentIndex
NetworkBehaviour.NetworkObject
NetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURS
NetworkBehaviour.UNSET_NETWORKBEHAVIOUR_ID
NetworkBehaviour.ToString()
NetworkBehaviour.Reset()
NetworkBehaviour.OnValidate()
NetworkBehaviour.IsBehaviourReconciling
NetworkBehaviour.ClearReplicateCache()
NetworkBehaviour.RequestReconcileSends()
NetworkBehaviour.CreateReconcile()
NetworkBehaviour.Reconcile_Reader_Remote<T>(PooledReader, ref T)
NetworkBehaviour.ClearBuffedRpcs()
NetworkBehaviour.IsClientOnly
NetworkBehaviour.IsServerOnly
NetworkBehaviour.IsHost
NetworkBehaviour.IsClient
NetworkBehaviour.IsServer
NetworkBehaviour.IsDeinitializing
NetworkBehaviour.NetworkManager
NetworkBehaviour.ServerManager
NetworkBehaviour.ClientManager
NetworkBehaviour.ObserverManager
NetworkBehaviour.TransportManager
NetworkBehaviour.TimeManager
NetworkBehaviour.SceneManager
NetworkBehaviour.PredictionManager
NetworkBehaviour.RollbackManager
NetworkBehaviour.NetworkObserver
NetworkBehaviour.IsClientInitialized
NetworkBehaviour.IsClientStarted
NetworkBehaviour.IsClientOnlyInitialized
NetworkBehaviour.IsClientOnlyStarted
NetworkBehaviour.IsServerInitialized
NetworkBehaviour.IsServerStarted
NetworkBehaviour.IsServerOnlyInitialized
NetworkBehaviour.IsServerOnlyStarted
NetworkBehaviour.IsHostInitialized
NetworkBehaviour.IsHostStarted
NetworkBehaviour.IsOffline
NetworkBehaviour.IsNetworked
NetworkBehaviour.GetIsNetworked()
NetworkBehaviour.IsManagerReconciling
NetworkBehaviour.Observers
NetworkBehaviour.IsOwner
NetworkBehaviour.IsController
NetworkBehaviour.HasAuthority
NetworkBehaviour.Owner
NetworkBehaviour.OwnerId
NetworkBehaviour.ObjectId
NetworkBehaviour.LocalConnection
NetworkBehaviour.OwnerMatches(NetworkConnection)
NetworkBehaviour.Despawn(GameObject, DespawnType?)
NetworkBehaviour.Despawn(NetworkObject, DespawnType?)
NetworkBehaviour.Despawn(DespawnType?)
NetworkBehaviour.Spawn(GameObject, NetworkConnection, Scene)
NetworkBehaviour.Spawn(NetworkObject, NetworkConnection, Scene)
NetworkBehaviour.RemoveOwnership()
NetworkBehaviour.GiveOwnership(NetworkConnection)
NetworkBehaviour.GetInstance<T>()
NetworkBehaviour.TryRegisterInstance<T>(T)
NetworkBehaviour.UnregisterInstance<T>()
NetworkBehaviour.CanLog(LoggingType)
NetworkBehaviour.OnStartServerCalled
NetworkBehaviour.OnStartClientCalled
NetworkBehaviour.WritePayload(NetworkConnection, Writer)
NetworkBehaviour.ReadPayload(NetworkConnection, Reader)
NetworkBehaviour.OnStartServer()
NetworkBehaviour.OnStopServer()
NetworkBehaviour.OnOwnershipServer(NetworkConnection)
NetworkBehaviour.OnSpawnServer(NetworkConnection)
NetworkBehaviour.OnDespawnServer(NetworkConnection)
NetworkBehaviour.OnStartClient()
NetworkBehaviour.OnStopClient()
NetworkBehaviour.OnOwnershipClient(NetworkConnection)
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.didStart
MonoBehaviour.didAwake
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Component.GetComponentIndex()
Component.CompareTag(TagHandle)
Component.transform
Component.transformHandle
Component.gameObject
Component.tag
Object.GetEntityId()
Object.MemberwiseClone()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.name
Object.hideFlags

Fields

PetSlotsTemplateID

The character attribute that holds the pet slots. Zero: the "Pet Slots" asset (DefaultAttributeID).

[TemplateReference(typeof(CharacterAttributeTemplate))]
[Tooltip("The character attribute that holds this character's pet slots. Empty: the \"Pet Slots\" attribute.")]
public int PetSlotsTemplateID

Field Value

int

Properties

AttackPriority

The packed order a pet attack command tries its target choices in; see PetAttackPriority. Mirrored on this controller so the panel has something to bind to between a pet being dismissed and re-summoned.

public int AttackPriority { get; set; }

Property Value

int

MovementOrder

The pets' movement order as this peer currently understands it.

public PetMovementOrder MovementOrder { get; set; }

Property Value

PetMovementOrder

OnPetDismissTriggers

Triggers invoked when a pet is dismissed or destroyed.

public List<Trigger> OnPetDismissTriggers { get; }

Property Value

List<Trigger>

OnPetSummonTriggers

Triggers invoked when a pet is summoned.

public List<Trigger> OnPetSummonTriggers { get; }

Property Value

List<Trigger>

PetSlots

How many pets this character may keep out at once: the final value of its Pet Slots character attribute, so an archetype, an item or a buff grants slots as it moves any attribute. A summon spell's own MaxPets can only lower it. See PetSlotRules.

public int PetSlots { get; }

Property Value

int

Remarks

Read from the attribute every time, never cached: equipment, buffs and (later) archetypes move it through the attribute's modifiers, and the saved base value is the character's own.

PetSlotsAttributeID

The template ID PetSlots reads.

public int PetSlotsAttributeID { get; }

Property Value

int

Pets

The pets out, in the order they were summoned. Every order and stance applies to all of them.

public IReadOnlyList<Pet> Pets { get; }

Property Value

IReadOnlyList<Pet>

Remarks

Changes go through AddPet(Pet) and RemovePet(Pet), which drive the server's damage subscription: see FishMMO.Shared.PetController.UpdateDamageSubscription().

Stance

The pets' combat stance as this peer currently understands it.

public PetStance Stance { get; set; }

Property Value

PetStance

Remarks

Mirrored here as well as on each pet so the UI has something to bind to between a pet being dismissed and re-summoned.

Methods

AddPet(Pet)

Adds a pet. False when it is already listed or null.

public bool AddPet(Pet pet)

Parameters

pet Pet

Returns

bool

ClearPets()

Forgets every pet.

public void ClearPets()

FindPet(long)

The listed pet with this ID, or null.

public Pet FindPet(long id)

Parameters

id long

Returns

Pet

OnClientPetActionBroadcastReceived(PetActionBroadcast, Channel)

Client: tells the panel what a pet has just started doing, so the pet can say it in chat.

public void OnClientPetActionBroadcastReceived(PetActionBroadcast msg, Channel channel)

Parameters

msg PetActionBroadcast
channel Channel

OnClientPetAddBroadcastReceived(PetAddBroadcast, Channel)

Handles the broadcast when a pet is added. Lists the pet and invokes the OnPetSummoned event.

public void OnClientPetAddBroadcastReceived(PetAddBroadcast msg, Channel channel)

Parameters

msg PetAddBroadcast

The broadcast message containing the pet ID and orders.

channel Channel

The network channel.

Remarks

The pet object may not be here yet. After a scene change the server spawns the pet in the new scene and announces it at once, but the pet reaches this client through the observer system, which can deliver it a moment later. The announcement used to be dropped then: the client never learned it had a pet, so the pet panel kept the old scene's pet and its controls did nothing. It is now held until the pet registers (Registered). Several can wait at once: every pet that was out comes back together.

OnClientPetAttackPriorityBroadcastReceived(PetAttackPriorityBroadcast, Channel)

The server confirmed (or corrected) the attack priority.

public void OnClientPetAttackPriorityBroadcastReceived(PetAttackPriorityBroadcast msg, Channel channel)

Parameters

msg PetAttackPriorityBroadcast
channel Channel

OnClientPetMovementOrderBroadcastReceived(PetMovementOrderBroadcast, Channel)

Applies the server's authoritative movement order.

public void OnClientPetMovementOrderBroadcastReceived(PetMovementOrderBroadcast msg, Channel channel)

Parameters

msg PetMovementOrderBroadcast

The movement order broadcast.

channel Channel

The network channel.

OnClientPetRemoveBroadcastReceived(PetRemoveBroadcast, Channel)

Handles the broadcast when a pet is removed. Unlists it (every pet for ID 0) and invokes the OnPetDestroyed event.

public void OnClientPetRemoveBroadcastReceived(PetRemoveBroadcast msg, Channel channel)

Parameters

msg PetRemoveBroadcast

The broadcast message for pet removal.

channel Channel

The network channel.

OnClientPetStanceBroadcastReceived(PetStanceBroadcast, Channel)

Applies the server's authoritative stance so the UI reflects what the pets are really doing.

public void OnClientPetStanceBroadcastReceived(PetStanceBroadcast msg, Channel channel)

Parameters

msg PetStanceBroadcast

The stance broadcast.

channel Channel

The network channel.

OnDestroying()

Called during OnDestroy for custom cleanup logic. Override in derived classes.

public override void OnDestroying()

OnStartCharacter()

Called when the character starts. Registers broadcast listeners for pet events if owner.

public override void OnStartCharacter()

OnStartNetwork()

Called when the network object starts. The damage subscription is taken lazily, when a pet actually exists.

public override void OnStartNetwork()

OnStopCharacter()

Called when the character stops. Unregisters broadcast listeners for pet events if owner.

public override void OnStopCharacter()

OnStopNetwork()

Releases the global damage subscription.

public override void OnStopNetwork()

RemovePet(Pet)

Removes a pet. False when it was not listed.

public bool RemovePet(Pet pet)

Parameters

pet Pet

Returns

bool

Remarks

By reference, so a pet whose object Unity has already destroyed can still be unlisted.

ResetState(bool)

Resets the controller's state, clearing the pet reference and orders.

public override void ResetState(bool asServer)

Parameters

asServer bool

Whether the reset is performed on the server.

Events

OnClientPetAction

Client: one of the owner's pets started doing something (PetActionBroadcast): the pet, the action, the target's ID.

public static event Action<Pet, PetAction, long> OnClientPetAction

Event Type

Action<Pet, PetAction, long>

OnOwnerAttacked

Raised on the server when this controller's owner is damaged by a hostile character.

public event Action<IPetController, ICharacter> OnOwnerAttacked

Event Type

Action<IPetController, ICharacter>

Remarks

A defensive pet has to know its owner is under attack, and the owner is a player with no aggression table of its own to read. Subscribing here — one handler per player, mirroring what the server's AggressionState already does per NPC — is what lets a defensive pet come to its owner's aid instead of watching.

OnPetSlotsReduced

Raised on the server when the Pet Slots attribute falls under a slot a pet holds, so that pet can be dismissed.

public event Action<IPetController> OnPetSlotsReduced

Event Type

Action<IPetController>