ICharacterAttributeController - jimdroberts/FishMMO GitHub Wiki

Description

Interface for character attribute controllers, providing access and management for all character attributes and resources. Used to read, modify, and synchronize attribute and resource values for a character in the FishMMO system.


API Access

Properties

  • Dictionary<int, CharacterAttribute> Attributes { get; }

    Dictionary of all non-resource character attributes, keyed by template ID.

  • Dictionary<int, CharacterResourceAttribute> ResourceAttributes { get; }

    Dictionary of all resource character attributes (e.g., health, mana), keyed by template ID.

Methods

  • void SetAttribute(int id, int value)

    Sets the value of a non-resource attribute by template ID. id (int): Template ID of the attribute. value (int): New value to set.

  • void SetResourceAttribute(int id, int value, float currentValue)

    Sets the value and current value of a resource attribute by template ID. id (int): Template ID of the resource attribute. value (int): New value to set. currentValue (float): New current value to set.

  • bool TryGetAttribute(CharacterAttributeTemplate template, out CharacterAttribute attribute)

    Tries to get a non-resource attribute by template reference. template (CharacterAttributeTemplate): Attribute template to look up. attribute (CharacterAttribute): Out: found attribute instance. Returns true if found, false otherwise (bool).

  • bool TryGetAttribute(int id, out CharacterAttribute attribute)

    Tries to get a non-resource attribute by template ID. id (int): Template ID to look up. attribute (CharacterAttribute): Out: found attribute instance. Returns true if found, false otherwise (bool).

  • bool TryGetHealthAttribute(out CharacterResourceAttribute health)

    Tries to get the health resource attribute for the character. health (CharacterResourceAttribute): Out: found health resource attribute. Returns true if found, false otherwise (bool).

  • bool TryGetManaAttribute(out CharacterResourceAttribute mana)

    Tries to get the mana resource attribute for the character. mana (CharacterResourceAttribute): Out: found mana resource attribute. Returns true if found, false otherwise (bool).

  • bool TryGetStaminaAttribute(out CharacterResourceAttribute stamina)

    Tries to get the stamina resource attribute for the character. stamina (CharacterResourceAttribute): Out: found stamina resource attribute. Returns true if found, false otherwise (bool).

  • float GetHealthResourceAttributeCurrentPercentage()

    Gets the current health percentage (FinalValue / CurrentValue). Returns current health percentage as a float.

  • float GetManaResourceAttributeCurrentPercentage()

    Gets the current mana percentage (FinalValue / CurrentValue). Returns current mana percentage as a float.

  • float GetStaminaResourceAttributeCurrentPercentage()

    Gets the current stamina percentage (FinalValue / CurrentValue). Returns current stamina percentage as a float.

  • bool TryGetResourceAttribute(CharacterAttributeTemplate template, out CharacterResourceAttribute attribute)

    Tries to get a resource attribute by template reference. template (CharacterAttributeTemplate): Resource attribute template to look up. attribute (CharacterResourceAttribute): Out: found resource attribute instance. Returns true if found, false otherwise (bool).

  • bool TryGetResourceAttribute(int id, out CharacterResourceAttribute attribute)

    Tries to get a resource attribute by template ID. id (int): Template ID to look up. attribute (CharacterResourceAttribute): Out: found resource attribute instance. Returns true if found, false otherwise (bool).

  • void AddAttribute(CharacterAttribute instance)

    Adds a new non-resource attribute instance to the controller. instance (CharacterAttribute): Attribute instance to add.

  • void Regenerate(float deltaTime)

    Regenerates resource attributes (e.g., health, mana) over time. deltaTime (float): Time elapsed since last regeneration tick.

  • void ApplyResourceState(CharacterAttributeResourceState resourceState)

    Applies a resource state (health, mana, stamina, regen delta) to the controller. resourceState (CharacterAttributeResourceState): Resource state to apply.

  • CharacterAttributeResourceState GetResourceState()

    Gets the current resource state (health, mana, stamina, regen delta) for the controller. Returns current resource state struct.


Basic Usage

Setup

  1. Implement the ICharacterAttributeController interface in your character controller class.
  2. Use the Attributes and ResourceAttributes dictionaries to manage attribute instances.
  3. Use TryGet, Set, and Regenerate methods to manage attribute values and state.

Example

// Example 1: Getting and setting attribute values
if (controller.TryGetAttribute(attributeTemplate, out var attr)) {
    attr.SetValue(10);
}

// Example 2: Regenerating resources
controller.Regenerate(Time.deltaTime);

Best Practices

  • Always implement all interface methods and properties.
  • Use TryGet methods to safely access attributes and resources.
  • Use ApplyResourceState and GetResourceState for network synchronization.
  • Keep attribute and resource management logic organized and efficient.
⚠️ **GitHub.com Fallback** ⚠️