Class PetController
Controller for managing pet entities attached to a character. Handles pet state, network broadcasts, and event invocation.
public class PetController : CharacterBehaviour, IPetController, ICharacterBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourNetworkBehaviourPetController
- Implements
- Inherited Members
-
NetworkBehaviour.IsSpawnedNetworkBehaviour.ComponentIndexNetworkBehaviour.NetworkObjectNetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURSNetworkBehaviour.UNSET_NETWORKBEHAVIOUR_IDNetworkBehaviour.ToString()NetworkBehaviour.Reset()NetworkBehaviour.OnValidate()NetworkBehaviour.IsBehaviourReconcilingNetworkBehaviour.ClearReplicateCache()NetworkBehaviour.RequestReconcileSends()NetworkBehaviour.CreateReconcile()NetworkBehaviour.Reconcile_Reader_Remote<T>(PooledReader, ref T)NetworkBehaviour.ClearBuffedRpcs()NetworkBehaviour.IsClientOnlyNetworkBehaviour.IsServerOnlyNetworkBehaviour.IsHostNetworkBehaviour.IsClientNetworkBehaviour.IsServerNetworkBehaviour.IsDeinitializingNetworkBehaviour.NetworkManagerNetworkBehaviour.ServerManagerNetworkBehaviour.ClientManagerNetworkBehaviour.ObserverManagerNetworkBehaviour.TransportManagerNetworkBehaviour.TimeManagerNetworkBehaviour.SceneManagerNetworkBehaviour.PredictionManagerNetworkBehaviour.RollbackManagerNetworkBehaviour.NetworkObserverNetworkBehaviour.IsClientInitializedNetworkBehaviour.IsClientStartedNetworkBehaviour.IsClientOnlyInitializedNetworkBehaviour.IsClientOnlyStartedNetworkBehaviour.IsServerInitializedNetworkBehaviour.IsServerStartedNetworkBehaviour.IsServerOnlyInitializedNetworkBehaviour.IsServerOnlyStartedNetworkBehaviour.IsHostInitializedNetworkBehaviour.IsHostStartedNetworkBehaviour.IsOfflineNetworkBehaviour.IsNetworkedNetworkBehaviour.GetIsNetworked()NetworkBehaviour.IsManagerReconcilingNetworkBehaviour.ObserversNetworkBehaviour.IsOwnerNetworkBehaviour.IsControllerNetworkBehaviour.HasAuthorityNetworkBehaviour.OwnerNetworkBehaviour.OwnerIdNetworkBehaviour.ObjectIdNetworkBehaviour.LocalConnectionNetworkBehaviour.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.OnStartServerCalledNetworkBehaviour.OnStartClientCalledNetworkBehaviour.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.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.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.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.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.nameObject.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
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
MovementOrder
The pets' movement order as this peer currently understands it.
public PetMovementOrder MovementOrder { get; set; }
Property Value
OnPetDismissTriggers
Triggers invoked when a pet is dismissed or destroyed.
public List<Trigger> OnPetDismissTriggers { get; }
Property Value
OnPetSummonTriggers
Triggers invoked when a pet is summoned.
public List<Trigger> OnPetSummonTriggers { get; }
Property Value
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
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
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
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
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
petPet
Returns
ClearPets()
Forgets every pet.
public void ClearPets()
FindPet(long)
The listed pet with this ID, or null.
public Pet FindPet(long id)
Parameters
idlong
Returns
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
msgPetActionBroadcastchannelChannel
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
msgPetAddBroadcastThe broadcast message containing the pet ID and orders.
channelChannelThe 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
msgPetAttackPriorityBroadcastchannelChannel
OnClientPetMovementOrderBroadcastReceived(PetMovementOrderBroadcast, Channel)
Applies the server's authoritative movement order.
public void OnClientPetMovementOrderBroadcastReceived(PetMovementOrderBroadcast msg, Channel channel)
Parameters
msgPetMovementOrderBroadcastThe movement order broadcast.
channelChannelThe 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
msgPetRemoveBroadcastThe broadcast message for pet removal.
channelChannelThe 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
msgPetStanceBroadcastThe stance broadcast.
channelChannelThe 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
petPet
Returns
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
asServerboolWhether 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
OnOwnerAttacked
Raised on the server when this controller's owner is damaged by a hostile character.
public event Action<IPetController, ICharacter> OnOwnerAttacked
Event Type
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