Class AbilityBuilder

Direct Known Subclasses:
ScriptedAbilityBuilder

public class AbilityBuilder

Fluent builder for constructing DynamicAbility instances for a Creature.

Use build() when the caller will manage the ability itself, or register() to also add it to the executor. Numeric values default to zero and the cast type defaults to CastType.INSTANT. Negative cooldown, range, and impact values are normalized to zero.

See Also:
  • Constructor Details

    • AbilityBuilder

      public AbilityBuilder(Creature executor, String name)
      Creates a builder for an ability executed by the specified creature.
      Parameters:
      executor - The creature that will execute the ability.
      name - The name used to identify the ability on the creature.
      Throws:
      NullPointerException - if executor or name is null.
  • Method Details

    • description

      public AbilityBuilder description(String description)
      Sets the player-facing description.
      Parameters:
      description - The description, or null to use an empty description.
      Returns:
      This builder.
    • cooldown

      public AbilityBuilder cooldown(int cooldownMs)
      Sets the cooldown after a successful cast.
      Parameters:
      cooldownMs - The cooldown in milliseconds; negative values are treated as zero.
      Returns:
      This builder.
    • range

      public AbilityBuilder range(int range)
      Sets the maximum cast range.
      Parameters:
      range - The range in map units; negative values are treated as zero.
      Returns:
      This builder.
    • impact

      public AbilityBuilder impact(int impact)
      Sets the base impact used by the ability's effects.
      Parameters:
      impact - The impact value; negative values are treated as zero.
      Returns:
      This builder.
    • value

      public AbilityBuilder value(int value)
      Sets the general-purpose value exposed through the ability attributes.
      Parameters:
      value - The value to expose; unlike the other numeric attributes this may be negative.
      Returns:
      This builder.
    • castType

      public AbilityBuilder castType(CastType castType)
      Sets how the ability is cast.
      Parameters:
      castType - The cast type.
      Returns:
      This builder.
      Throws:
      NullPointerException - if castType is null.
    • multiTarget

      public AbilityBuilder multiTarget(boolean multiTarget)
      Sets whether one execution may affect multiple targets.
      Parameters:
      multiTarget - true to permit multiple targets.
      Returns:
      This builder.
    • onCast

      public AbilityBuilder onCast(Consumer<AbilityExecution> onCast)
      Sets the callback invoked when the ability is cast.
      Parameters:
      onCast - The callback, or null to remove the current callback.
      Returns:
      This builder.
    • onCast

      public AbilityBuilder onCast(Runnable onCast)
      Sets a callback that does not need the AbilityExecution details.
      Parameters:
      onCast - The callback, or null to remove the current callback.
      Returns:
      This builder.
    • effect

      public AbilityBuilder effect(Effect effect)
      Adds an Effect to this ability.
      Parameters:
      effect - The effect to attach.
      Returns:
      This builder instance for chaining.
    • build

      public DynamicAbility build()

      Constructs a new ability without adding it to the executor.

      Each invocation returns a new ability configured from the builder's current values.

      Returns:
      A new, unregistered ability.
    • register

      public DynamicAbility register()
      Constructs the ability and registers it directly on the executing creature.
      Returns:
      The newly constructed and registered ability.