Table of Contents

Class FactionController

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Controls faction reputation, alliance grouping, and relationship queries for a character. Handles network synchronization of faction standings via FishNet broadcasts and payload serialization.

public class FactionController : CharacterBehaviour, IFactionController, ICharacterBehaviour
Inheritance
Object
Component
Behaviour
MonoBehaviour
NetworkBehaviour
FactionController
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.CreateReconcile()
NetworkBehaviour.Reconcile_Reader<T>(PooledReader, ref T)
NetworkBehaviour.OnStartServerCalled
NetworkBehaviour.OnStartClientCalled
NetworkBehaviour.OnStartNetwork()
NetworkBehaviour.OnStopNetwork()
NetworkBehaviour.OnStartServer()
NetworkBehaviour.OnStopServer()
NetworkBehaviour.OnOwnershipServer(NetworkConnection)
NetworkBehaviour.OnSpawnServer(NetworkConnection)
NetworkBehaviour.OnDespawnServer(NetworkConnection)
NetworkBehaviour.OnStartClient()
NetworkBehaviour.OnStopClient()
NetworkBehaviour.OnOwnershipClient(NetworkConnection)
NetworkBehaviour.ClearBuffedRpcs()
NetworkBehaviour.ExcludeOwnerFromUnbufferedObserversRpcs
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)
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.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

Properties

Allied

Public accessor for allied factions.

public Dictionary<int, Faction> Allied { get; }

Property Value

Dictionary<int, Faction>

Factions

Public accessor for all factions and their standing values.

public Dictionary<int, Faction> Factions { get; }

Property Value

Dictionary<int, Faction>

FactionsAreTemplateDerived

True while this character's standings are DERIVED from RaceTemplate.InitialFaction rather than owned as mutable state.

public bool FactionsAreTemplateDerived { get; }

Property Value

bool

Remarks

This is the difference between the two kinds of character in the faction system. A player carries standings that change during play and are persisted per character, so they are authored by the server and must travel. An NPC never changes faction — SetFaction(int, int, bool) and Add(FactionTemplate, int) refuse to move an NPC's standing on purpose — so its roster is a pure function of immutable template data that every peer already holds, and sending it is both wasted bytes and a second source of truth.

A pet is the exception that proves the rule: CopyFrom(IFactionController) installs its owner's standings, which are not derivable from any template, so copying clears this flag and the roster travels like a player's.

Hostile

Public accessor for hostile factions.

public Dictionary<int, Faction> Hostile { get; }

Property Value

Dictionary<int, Faction>

IsAggressive

Gets or sets whether the character is aggressive (treats others as enemies).

public bool IsAggressive { get; set; }

Property Value

bool

Neutral

Public accessor for neutral factions.

public Dictionary<int, Faction> Neutral { get; }

Property Value

Dictionary<int, Faction>

OnFactionChangeTriggers

Triggers invoked when a faction standing changes for this character.

public List<Trigger> OnFactionChangeTriggers { get; }

Property Value

List<Trigger>

RaceTemplate

Gets the race template for this character.

public RaceTemplate RaceTemplate { get; }

Property Value

RaceTemplate

Methods

Add(FactionTemplate, int)

Adds amount to the faction value.

public void Add(FactionTemplate template, int amount = 1)

Parameters

template FactionTemplate

The faction template to adjust.

amount int

The amount to add to the faction standing (can be negative).

AdjustFaction(IFactionController, float, float)

Adds a percentage of the defenders hostile faction and removes a percentage of the defenders allied faction.

public void AdjustFaction(IFactionController defenderFactionController, float alliedPercentToSubtract, float hostilePercentToAdd)

Parameters

defenderFactionController IFactionController

The defender's faction controller to reference.

alliedPercentToSubtract float

Percentage of allied faction standing to subtract.

hostilePercentToAdd float

Percentage of hostile faction standing to add.

CopyFrom(IFactionController)

Copies all faction data from another faction controller, replacing current state.

public void CopyFrom(IFactionController factionController)

Parameters

factionController IFactionController

The source faction controller to copy from.

GetAllianceLevel(IFactionController)

Gets the alliance level between this character and another faction controller. Checks party, guild, aggression, and faction standings to determine the relationship.

public FactionAllianceLevel GetAllianceLevel(IFactionController otherFactionController)

Parameters

otherFactionController IFactionController

The other faction controller to evaluate against.

Returns

FactionAllianceLevel

The FactionAllianceLevel between the two characters.

GetAllianceLevelColor(IFactionController)

Gets the color representing the alliance level between this character and another faction controller. Green for Ally, Sky Blue for Neutral, Red for Enemy or Aggressive.

public Color GetAllianceLevelColor(IFactionController otherFactionController)

Parameters

otherFactionController IFactionController

The other faction controller to evaluate against.

Returns

Color

A UnityEngine.Color representing the alliance level.

InitializeOnce()

Seeds an NPC's derived roster as soon as the character is assembled, before any network activity, so the server holds the same table a client will build for itself.

public override void InitializeOnce()

InitializeTemplateFactions()

Rebuilds the faction roster from RaceTemplate's initial faction, exactly as character creation seeds a new player: allied at maximum, neutral at zero, hostile at minimum.

public void InitializeTemplateFactions()

Remarks

Runs on every peer, from InitializeOnce() on the server and from ReadPayload(NetworkConnection, Reader) on a client, so both ends compute the same table from the same immutable asset instead of one end being told. The values mirror CharacterCreateSystem.BuildStartingFactionEntries; if those diverge, an NPC and a freshly created player of the same race would disagree about the same faction.

OnStartCharacter()

Called when the character is started on the client. Registers broadcast listeners for faction updates.

public override void OnStartCharacter()

OnStopCharacter()

Called when the character is stopped on the client. Unregisters faction update listeners.

public override void OnStopCharacter()

ReadPayload(NetworkConnection, Reader)

Called before network start callbacks, but after the object is initialized with network values. This may be used to read information from predicted spawning, or simply have values set before initialization without depending on SyncTypes.

public override void ReadPayload(NetworkConnection conn, Reader reader)

Parameters

conn NetworkConnection
reader Reader

ResetState(bool)

Resets the faction state for this character, clearing all standing data.

public override void ResetState(bool asServer)

Parameters

asServer bool

Whether the reset is being performed on the server.

SetFaction(int, int, bool)

Sets the faction to value.

public void SetFaction(int templateID, int value, bool skipEvent = false)

Parameters

templateID int

The faction template ID to modify.

value int

The new reputation or standing value.

skipEvent bool

If true, faction change events will not be invoked.

SetRaceTemplateOnSpawn(RaceTemplate)

Replaces the race template this character derives its initial factions from.

public void SetRaceTemplateOnSpawn(RaceTemplate raceTemplate)

Parameters

raceTemplate RaceTemplate

The race template to adopt. Ignored when null.

Remarks

Spawn-time only. The race template is read lazily — nothing is derived from it during initialisation — so assigning it before ServerManager.Spawn takes effect cleanly. Calling it on an already-spawned character would leave the alliance tables it has already built disagreeing with its new race, which is why there is no plain setter.

Exists so one NPC prefab can be hostile at one spawner and neutral at another without duplicating the prefab — and a duplicated prefab is a second object-pool bucket and a second fixed slice of the map's memory budget.

WritePayload(NetworkConnection, Writer)

Writes the current faction state to the network payload for synchronization.

public override void WritePayload(NetworkConnection conn, Writer writer)

Parameters

conn NetworkConnection

The network connection.

writer Writer

The network writer to write to.