Ability - jimdroberts/FishMMO GitHub Wiki
Represents an in-game ability instance, constructed from an AbilityTemplate
and containing all runtime state, events, and resource requirements. Used to manage the logic, state, and requirements for abilities as they are used by characters in the FishMMO system.
-
public long ID
Unique identifier for this ability instance.
-
public float ActivationTime
Total activation time for this ability, including all modifiers.
-
public float LifeTime
Total lifetime of the ability effect, including all modifiers.
-
public float Cooldown
Total cooldown for this ability, including all modifiers.
-
public float Range
The effective range of the ability, calculated as Speed * LifeTime.
-
public float Speed
Total speed of the ability effect, including all modifiers.
-
public AbilityTemplate Template { get; private set; }
The template from which this ability was constructed.
-
public string Name { get; set; }
The display name of the ability.
-
public string CachedTooltip { get; private set; }
Cached tooltip string for this ability, for UI display.
-
public AbilityResourceDictionary Resources { get; private set; }
The total resources required to use this ability, including all modifiers.
-
public AbilityResourceDictionary RequiredAttributes { get; private set; }
The total required attributes to use this ability, including all modifiers.
-
public AbilityTypeOverrideEventType TypeOverride { get; private set; }
Optional override for the ability type, set by certain events.
-
public Dictionary<int, AbilityEvent> AbilityEvents
All ability events, indexed by event ID, for quick access.
-
public Dictionary<int, AbilityOnTickEvent> OnTickEvents
All OnTick events, indexed by event ID.
-
public Dictionary<int, AbilityOnHitEvent> OnHitEvents
All OnHit events, indexed by event ID.
-
public Dictionary<int, AbilityOnPreSpawnEvent> OnPreSpawnEvents
All OnPreSpawn events, indexed by event ID.
-
public Dictionary<int, AbilityOnSpawnEvent> OnSpawnEvents
All OnSpawn events, indexed by event ID.
-
public Dictionary<int, AbilityOnDestroyEvent> OnDestroyEvents
All OnDestroy events, indexed by event ID.
-
public Dictionary<int, Dictionary<int, AbilityObject>> Objects { get; set; }
Cache of all active ability objects, organized by container and object ID.
-
public int TotalResourceCost
The total resource cost for this ability, summing all resource values.
-
public Ability(AbilityTemplate template, List abilityEvents = null)
Constructs an ability from a template and optional event list. Parameters:
- AbilityTemplate template: The ability template to use.
- List abilityEvents: Optional list of event IDs to add to the ability.
-
public Ability(long abilityID, int templateID, List abilityEvents = null)
Constructs an ability from an ability ID, template ID, and optional event list. Parameters:
- long abilityID: The unique ability instance ID.
- int templateID: The template ID to look up.
- List abilityEvents: Optional list of event IDs to add to the ability.
-
public Ability(long abilityID, AbilityTemplate template, List abilityEvents = null)
Constructs an ability from an ability ID, template, and optional event list. Parameters:
- long abilityID: The unique ability instance ID.
- AbilityTemplate template: The ability template to use.
- List abilityEvents: Optional list of event IDs to add to the ability.
-
public void AddEvents(List abilityEvents) where T : AbilityEvent
Adds a list of ability events to the appropriate event dictionaries and applies their stat/resource/attribute modifiers. Parameters:
- List abilityEvents: The list of events to add.
-
public bool MeetsRequirements(ICharacter character)
Checks if the given character meets all required attributes for this ability. Parameters:
- ICharacter character: The character to check. Returns:
- bool: True if requirements are met, false otherwise.
-
public bool TryGetAbilityEvent(int eventID, out AbilityEvent abilityEvent)
Attempts to get an ability event by its event ID. Parameters:
- int eventID: The event ID to look up.
- out AbilityEvent abilityEvent: The found ability event, or null if not found. Returns:
- bool: True if found, false otherwise.
-
public bool HasAbilityEvent(int eventID)
Checks if this ability contains an event with the given event ID. Parameters:
- int eventID: The event ID to check. Returns:
- bool: True if the event exists, false otherwise.
-
public bool RemoveAbilityEvent(int eventID)
Removes an ability event by its event ID and updates all stat/resource/attribute modifiers accordingly. Parameters:
- int eventID: The event ID to remove. Returns:
- bool: True if the event was removed, false otherwise.
-
public bool HasResource(ICharacter character, AbilityEvent resourceConversionTrigger = null)
Checks if the given character has enough resources to use this ability. Parameters:
- ICharacter character: The character to check.
- AbilityEvent resourceConversionTrigger: Optional event that allows resource conversion (e.g., health for mana). Returns:
- bool: True if the character has enough resources, false otherwise.
-
public void ConsumeResources(ICharacter character, AbilityEvent resourceConversionTrigger = null)
Consumes the required resources from the given character to use this ability. Parameters:
- ICharacter character: The character using the ability.
- AbilityEvent resourceConversionTrigger: Optional event that allows resource conversion (e.g., health for mana).
-
public void RemoveAbilityObject(int containerID, int objectID)
Removes an ability object from the cache by container and object ID. Parameters:
- int containerID: The container ID.
- int objectID: The object ID to remove.
-
public string Tooltip()
Returns the tooltip string for this ability, using the template and type override if present. Returns:
- string: Formatted tooltip string for the ability.
- Construct an
Ability
instance from anAbilityTemplate
and optional event list. - Configure the ability's runtime state, events, and requirements as needed.
- Integrate with the character and ability systems to manage ability usage, resource checks, and event handling.
- Use the
Tooltip()
method to display ability information in the UI.
// Example 1: Creating and Using an Ability Instance
// This example demonstrates how to create an Ability instance from a template
// and use its methods to check requirements and consume resources.
AbilityTemplate template = ...; // Obtain or create an AbilityTemplate
Ability ability = new Ability(template);
if (ability.MeetsRequirements(character) && ability.HasResource(character))
{
ability.ConsumeResources(character);
// Activate the ability
}