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 Summary
ConstructorsConstructorDescriptionAbilityBuilder(Creature executor, String name) Creates a builder for an ability executed by the specified creature. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Constructs a new ability without adding it to the executor.Sets how the ability is cast.cooldown(int cooldownMs) Sets the cooldown after a successful cast.description(String description) Sets the player-facing description.Adds anEffectto this ability.impact(int impact) Sets the base impact used by the ability's effects.multiTarget(boolean multiTarget) Sets whether one execution may affect multiple targets.Sets a callback that does not need theAbilityExecutiondetails.onCast(Consumer<AbilityExecution> onCast) Sets the callback invoked when the ability is cast.range(int range) Sets the maximum cast range.register()Constructs the ability and registers it directly on the executing creature.value(int value) Sets the general-purpose value exposed through the ability attributes.
-
Constructor Details
-
AbilityBuilder
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- ifexecutorornameisnull.
-
-
Method Details
-
description
Sets the player-facing description.- Parameters:
description- The description, ornullto use an empty description.- Returns:
- This builder.
-
cooldown
Sets the cooldown after a successful cast.- Parameters:
cooldownMs- The cooldown in milliseconds; negative values are treated as zero.- Returns:
- This builder.
-
range
Sets the maximum cast range.- Parameters:
range- The range in map units; negative values are treated as zero.- Returns:
- This builder.
-
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
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
Sets how the ability is cast.- Parameters:
castType- The cast type.- Returns:
- This builder.
- Throws:
NullPointerException- ifcastTypeisnull.
-
multiTarget
Sets whether one execution may affect multiple targets.- Parameters:
multiTarget-trueto permit multiple targets.- Returns:
- This builder.
-
onCast
Sets the callback invoked when the ability is cast.- Parameters:
onCast- The callback, ornullto remove the current callback.- Returns:
- This builder.
-
onCast
Sets a callback that does not need theAbilityExecutiondetails.- Parameters:
onCast- The callback, ornullto remove the current callback.- Returns:
- This builder.
-
effect
Adds anEffectto this ability.- Parameters:
effect- The effect to attach.- Returns:
- This builder instance for chaining.
-
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
Constructs the ability and registers it directly on the executing creature.- Returns:
- The newly constructed and registered ability.
-