add all managers
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package org.project.managers;
|
||||
|
||||
import org.project.abilities.*;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.GoblinArmor;
|
||||
|
||||
import javax.swing.text.Position;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpecialAbilityManager {
|
||||
|
||||
private final Map<Entity, List<SpecialAbility>> activeAbilities =
|
||||
new HashMap<>();
|
||||
|
||||
// =========================
|
||||
// Add Ability
|
||||
// =========================
|
||||
|
||||
public void addAbility(SpecialAbility ability, Entity target) {
|
||||
|
||||
if (ability == null || target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
activeAbilities.putIfAbsent(target, new ArrayList<>());
|
||||
|
||||
ability.onApply(target);
|
||||
|
||||
activeAbilities.get(target).add(ability);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Update Ability Effects
|
||||
// =========================
|
||||
|
||||
public void tick(Entity abilityUser, Entity target) {
|
||||
|
||||
List<SpecialAbility> abilities = activeAbilities.get(abilityUser);
|
||||
|
||||
if (abilities == null || abilities.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<SpecialAbility> iterator = abilities.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
SpecialAbility ability = iterator.next();
|
||||
|
||||
if (ability instanceof GuardianOath || ability instanceof PoisonDagger || ability instanceof LifeSteal)
|
||||
ability.onTick(abilityUser);
|
||||
|
||||
if (ability instanceof InfernoBreath || ability instanceof BoneStrike || ability instanceof ArcaneStorm)
|
||||
ability.onTick(target);
|
||||
|
||||
|
||||
ability.reduceDuration();
|
||||
|
||||
if (ability.getDuration() <= 0) {
|
||||
|
||||
ability.onExpire(abilityUser);
|
||||
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup empty list
|
||||
if (abilities.isEmpty()) {
|
||||
activeAbilities.remove(target);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user