IBuffController - jimdroberts/FishMMO GitHub Wiki

Description

Interface for a character's buff controller, handling application, removal, and events for buffs and debuffs. Defines the contract for managing buffs and debuffs in the FishMMO system.


API Access

Fields

  • static Action OnAddTime

    Static event triggered when time is added to a buff.

  • static Action OnSubtractTime

    Static event triggered when time is subtracted from a buff.

  • static Action OnAddBuff

    Static event triggered when a buff (positive effect) is added.

  • static Action OnRemoveBuff

    Static event triggered when a buff (positive effect) is removed.

  • static Action OnAddDebuff

    Static event triggered when a debuff (negative effect) is added.

  • static Action OnRemoveDebuff

    Static event triggered when a debuff (negative effect) is removed.

Properties

  • Dictionary<int, Buff> Buffs { get; }

    Dictionary of all active buffs for the character, indexed by template ID.

Methods

  • void Apply(BaseBuffTemplate template)

    Applies a buff to the character by template, creating a new instance if needed and handling stacking. template (BaseBuffTemplate): The buff template to apply.

  • void Apply(Buff buff)

    Applies a buff instance to the character if not already present, invoking appropriate events. buff (Buff): The buff instance to apply.

  • void Remove(int buffID)

    Removes a buff by template ID, invoking removal events and cleaning up. buffID (int): The template ID of the buff to remove.

  • void RemoveRandom(Random rng, bool includeBuffs = false, bool includeDebuffs = false)

    Removes a random buff or debuff from the character, with options to include buffs and/or debuffs. rng (Random): The random number generator to use. includeBuffs (bool): Whether to include buffs in the selection. includeDebuffs (bool): Whether to include debuffs in the selection.

  • void RemoveAll(bool ignoreInvokeRemove = false)

    Removes all non-permanent buffs from the character, optionally suppressing removal events. ignoreInvokeRemove (bool): If true, does not invoke OnRemoveBuff/OnRemoveDebuff events.


Basic Usage

Setup

  1. Implement the IBuffController interface in your character controller class.
  2. Register event handlers for buff and debuff events as needed.
  3. Use Apply and Remove methods to manage buffs at runtime.

Example

// Example 1: Implementing IBuffController
public class MyBuffController : IBuffController {
    public Dictionary<int, Buff> Buffs { get; private set; }
    public void Apply(BaseBuffTemplate template) { /* ... */ }
    // Implement other methods...
}

// Example 2: Subscribing to buff events
IBuffController.OnAddBuff += (buff) => {
    // Handle buff added
};

Best Practices

  • Always implement all interface methods and properties.
  • Use event hooks to update UI or trigger effects on buff changes.
  • Use RemoveAll to clear buffs when resetting character state.
  • Ensure thread safety if accessing buffs from multiple threads.
⚠️ **GitHub.com Fallback** ⚠️