Table of Contents

Class InteractableResolver

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Decides which of a GameObject's interactables a player means.

public static class InteractableResolver
Inheritance
InteractableResolver
Inherited Members

Remarks

One GameObject routinely carries several. An NPC is itself a lootable corpse, and an NPC that also trades, banks or hands out quests carries that component too. A plain GetComponent<IInteractable>() returns whichever the component order happens to yield, so a player looting a dead merchant could have their request answered by the shop — and a player talking to a live one could be answered by its corpse.

The rule lives here rather than in each caller because it was previously written out three times — in the client's input handler, in the scene server's interaction system, and not at all in the quest system, which still used the raw GetComponent that the other two had already been fixed away from. Three copies of a rule is three chances for them to disagree about which component answers, and the two that disagreed were on opposite ends of the same request.

The rule. A corpse wins whenever there is one, because being dead is the more specific state: a body cannot trade, and the loot on it is on a timer while the shop will still be there after the NPC respawns. Otherwise the first non-corpse interactable is used, which is the historical behaviour for every single-component object.

Methods

IsCorpse(GameObject)

True when this GameObject currently presents as a corpse.

public static bool IsCorpse(GameObject gameObject)

Parameters

gameObject GameObject

The GameObject to test.

Returns

bool

True if something on it is a corpse right now.

Remarks

The question a non-corpse interactable asks before accepting an interaction: a dead merchant must not open its shop, and a dead quest giver must not hand out work.

Resolve(ISceneObject)

Returns the interactable a registered scene object refers to.

public static IInteractable Resolve(ISceneObject sceneObject)

Parameters

sceneObject ISceneObject

The resolved scene object.

Returns

IInteractable

The interactable, or null.

Remarks

Identity first. The scene object is the interactable whenever it implements the interface, and that identity is exactly what the client's ID named — a GameObject carrying two interactables registers two scene objects with two distinct IDs, and the one the client sent is the one it meant. Falls back to the GameObject rule for interactables that register through some other component.

Resolve(GameObject)

Returns the interactable a player targeting this GameObject means.

public static IInteractable Resolve(GameObject gameObject)

Parameters

gameObject GameObject

The targeted GameObject.

Returns

IInteractable

The interactable, or null when the object has none.