Table of Contents

Class AbilitySystem

Namespace
FishMMO.Server.Implementation.World.SceneServer
Assembly
FishMMO.Server.dll

Owns the two halves of a crafted ability's life: granting one, and forgetting one.

[CreateAssetMenu(fileName = "AbilitySystem", menuName = "FishMMO/Server/SceneServer/Ability System", order = 2)]
[RequiresDataContainer(typeof(AbilitySystemRuntimeData))]
[RequiresDataContainer(typeof(AbilitySystemMainThreadQueueData))]
[RequiresDataContainer(typeof(AsyncWorkerData))]
public class AbilitySystem : ServerBehaviour, IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, IAbilitySystem, IServerBehaviour, IServerComponent
Inheritance
Object
ScriptableObject
AbilitySystem
Implements
IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
Inherited Members
ScriptableObject.SetDirty()
ScriptableObject.CreateInstance<T>()
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.ToString()
Object.name
Object.hideFlags

Remarks

Why a system rather than a partial of whoever asked. Three paths hand out abilities — the ability crafter, the merchant selling a premade, and (in principle) anything a content author adds next — and all three had their own copy of "construct, learn, persist". Only the item layer had worked out what the copies were missing, which is why InteractableSystem.SendNewItemBroadcast was emptied into CharacterInventorySystem.TryGrantItem and its doc says so. This is the same move for abilities, and it is the fix for the same class of bug.

The bug. Ability(template, events) sets ID = -1 by design — its own doc comment says the database assigns the real id — and nothing ever put that id back. PersistAbilityAsync read IsSuccess and threw away the long the upsert returned, so AbilityController.LearnAbility filed every crafted ability under -1: crafting a second ability from a different template silently replaced the first, and because HotkeyData.UnsetReferenceID is also -1 a hotkey bound to either of them validated against the sentinel. The identity is applied here, before the learn, so the window in which a crafted ability has no key does not exist.

Why the learn is deferred rather than corrected afterwards. The item layer can hand an item a provisional identity and correct it on the wire because an item lives in a slot: it can be locked while unidentified, and the slot re-sent (CharacterInventorySystem.ApplyAssignedIdentities). An ability has no slot — the instance id is its key on the server, in the client's known-ability table, in AbilityActivatedBroadcast, and in every persisted hotkey row. Deferring the grant costs one database round trip inside a request that already waits for its result broadcast, and removes the window entirely.

Methods

InitializeOnce()

Initializes the ability system, registering the forget request handler.

public override ServerComponentInitializationStatus InitializeOnce()

Returns

ServerComponentInitializationStatus

OnDeinitialize()

Cleans up the ability system, unregistering broadcast handlers.

public override void OnDeinitialize()

OnServerAbilityForgetBroadcastReceived(NetworkConnection, AbilityForgetBroadcast, Channel)

Handles a request to forget one crafted ability.

public void OnServerAbilityForgetBroadcastReceived(NetworkConnection conn, AbilityForgetBroadcast msg, Channel channel)

Parameters

conn NetworkConnection

Network connection of the requesting client.

msg AbilityForgetBroadcast

Forget request naming the ability.

channel Channel

Network channel used for the broadcast.

Remarks

Addressed by the ability's row identity, never by its template. The service's statement matches WHERE id = ?, and a template id would either match nothing — reporting success for a delete that removed no row — or, on a table with several rows per template, remove the wrong one.

The guard is held until the delete lands, not until this handler returns. A second forget arriving in that window would otherwise read the same live ability and delete the same row twice, and a re-craft arriving in it would see a character that still knows the ability.

OnUpdate(float)

Drains stale ingress entries with bounded cleanup each frame, and applies database-minted ability identities that arrived during the frame.

protected override void OnUpdate(float deltaTime)

Parameters

deltaTime float

TryGrantAbility(IPlayerCharacter, AbilityTemplate, IReadOnlyList<int>, Func<IPlayerCharacter, bool>, Action, Action<IPlayerCharacter, Ability>, Action<IPlayerCharacter>)

Builds and grants a new crafted ability to character.

public bool TryGrantAbility(IPlayerCharacter character, AbilityTemplate template, IReadOnlyList<int> events, Func<IPlayerCharacter, bool> settle, Action releaseGuard, Action<IPlayerCharacter, Ability> onGranted, Action<IPlayerCharacter> onFailed)

Parameters

character IPlayerCharacter

The character receiving the ability.

template AbilityTemplate

The ability template the crafted ability is built from.

events IReadOnlyList<int>

The crafted event template ids to attach, or null for none.

settle Func<IPlayerCharacter, bool>

Takes the caller's charge on the main thread once the row exists. Null when the grant is free. Returns false, having answered the player, to have the row revoked.

releaseGuard Action

Releases the caller's in-flight guard. Always invoked, exactly once, by this system.

onGranted Action<IPlayerCharacter, Ability>

Runs on the main thread once the ability is settled, learned and broadcast.

onFailed Action<IPlayerCharacter>

Runs on the main thread when the ability could not be recorded.

Returns

bool

true when the grant was admitted; false when it was refused outright.

Remarks

Asynchronous by contract. A true return means the request was admitted, not that the ability exists yet. Exactly one of onGranted or onFailed runs later, on the main thread, once the database has answered.

This method takes ownership of releaseGuard. It is invoked exactly once on whichever path finishes the request — a synchronous refusal, a refused enqueue, or the persist's continuation — so a caller must NOT also release it, and a caller that holds a request-open guard across this call passes the release in here instead of running it in its own finally.

A refusal is synchronous and already reports itself through the return value, so onFailed is reserved for a persist that was attempted and did not land. Callers answer a false return themselves.

Payment is settled on completion, not before the call. A caller that charges for the ability passes the charge as settle; it runs on the main thread once the row exists and only if the character is still resident, and the ability is learned strictly after it returns true. If the character has left, or settle returns false, the row is revoked and nothing is learned, announced or owed. Charging before the call was how a persist that failed after the player left became an unrefundable loss. A false from settle means the caller has already answered the player; neither onGranted nor onFailed runs for it.