Skip to content

Commit

Permalink
Generalize ability system
Browse files Browse the repository at this point in the history
Make effects usable outside the context of abilities.

(These changes bring breaking changes for the Ability API)

Fixes #115
  • Loading branch information
steffen-wilke committed Oct 5, 2024
1 parent 4b3e1e3 commit 950d93b
Show file tree
Hide file tree
Showing 18 changed files with 564 additions and 203 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.gurkenlabs.litiengine.abilities.effects;

import de.gurkenlabs.litiengine.abilities.Ability;
import de.gurkenlabs.litiengine.abilities.targeting.TargetingStrategy;

/**
* The `AbilityEffect` class is an abstract class that represents an effect
* associated with a specific ability. It extends the `Effect` class and is
* used to apply effects that are tied to a particular ability.
* <p>
* This class provides a way to manage and access the ability that triggers the effect,
* allowing for the integration of ability-specific attributes such as the executor and duration.
*/
public abstract class AbilityEffect extends Effect {
private final Ability ability;

/**
* Constructs a new `AbilityEffect` with the specified targeting strategy and ability.
* <p>
* The effect will inherit the executor and duration attributes from the provided ability.
*
* @param targetingStrategy The strategy used to select the targets for this effect.
* @param ability The ability associated with this effect, providing information such as the executor and duration.
*/
protected AbilityEffect(TargetingStrategy targetingStrategy, Ability ability) {
super(targetingStrategy, ability.getExecutor(), ability.getAttributes().duration().get());
this.ability = ability;
}

public Ability getAbility() {
return ability;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.gurkenlabs.litiengine.abilities.effects;

import de.gurkenlabs.litiengine.abilities.Ability;
import de.gurkenlabs.litiengine.abilities.targeting.TargetingStrategy;
import de.gurkenlabs.litiengine.attributes.Attribute;
import de.gurkenlabs.litiengine.attributes.AttributeModifier;
import de.gurkenlabs.litiengine.attributes.Modification;
import de.gurkenlabs.litiengine.entities.ICombatEntity;

/**
* An attribute effect appies an attribute modifier to the affected entity when applied and removes it when ceased.
* An attribute effect applies an attribute modifier to the affected entity when applied and removes it when ceased.
*
* @param <T>
* the generic type
Expand All @@ -17,12 +17,17 @@ public abstract class AttributeEffect<T extends Number> extends Effect {
/** The modifier. */
private final AttributeModifier<T> modifier;

protected AttributeEffect(
final Ability ability,
protected AttributeEffect(final TargetingStrategy targetingStrategy,
final Modification modification,
final double delta) {
this(targetingStrategy, null, modification, delta);
}

protected AttributeEffect(final TargetingStrategy targetingStrategy,
final ICombatEntity executingEntity,
final Modification modification,
final double delta,
final EffectTarget... targets) {
super(ability, targets);
final double delta) {
super(targetingStrategy, executingEntity);
this.modifier = new AttributeModifier<>(modification, delta);
}

Expand Down
Loading

0 comments on commit 950d93b

Please sign in to comment.