mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-10-21 11:03:00 -04:00
Added basis for server-side cooldown checks, added warmup checks, closed #273
Note that cooldown check is currently used only for the holoemote command. To add a cooldown to any command, all you have to do is CreatureObject.addCooldown(name). In this commit I also moved some cooldown variables from CombatCommand to BaseSWGCommand since many non-combat commands had cooldowns (Wookie Roar, Holo-Emotes). I also put in a warmup cooldown (time before command is called) for non-combat commands.
This commit is contained in:
@@ -26,7 +26,10 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
|
||||
@@ -46,6 +49,7 @@ import com.sleepycat.persist.model.NotPersistent;
|
||||
|
||||
import main.NGECore;
|
||||
import engine.clients.Client;
|
||||
import resources.common.Cooldown;
|
||||
import resources.objects.Buff;
|
||||
import resources.objects.DamageOverTime;
|
||||
import resources.objects.SWGList;
|
||||
@@ -177,6 +181,8 @@ public class CreatureObject extends TangibleObject implements IPersistent {
|
||||
private int coverCharge;
|
||||
@NotPersistent
|
||||
private TangibleObject conversingNpc;
|
||||
@NotPersistent
|
||||
private ConcurrentHashMap<String, Cooldown> cooldowns = new ConcurrentHashMap<String, Cooldown>();
|
||||
|
||||
public CreatureObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) {
|
||||
super(objectID, planet, Template, position, orientation);
|
||||
@@ -1722,4 +1728,43 @@ public class CreatureObject extends TangibleObject implements IPersistent {
|
||||
}
|
||||
}
|
||||
|
||||
public void addCooldown(String ability, long duration) {
|
||||
if (cooldowns.containsKey(ability))
|
||||
cooldowns.remove(ability);
|
||||
|
||||
Cooldown cd = new Cooldown(duration);
|
||||
cd.setRemovalTask(Executors.newScheduledThreadPool(1).schedule(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
removeCooldown(ability);
|
||||
}
|
||||
|
||||
}, duration, TimeUnit.MILLISECONDS));
|
||||
cooldowns.put(ability, cd);
|
||||
}
|
||||
|
||||
public boolean hasCooldown(String ability) {
|
||||
if (cooldowns.containsKey(ability))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeCooldown(String ability) {
|
||||
if (cooldowns.containsKey(ability)) {
|
||||
cooldowns.remove(ability);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Cooldown getCooldown(String ability) {
|
||||
if (cooldowns.containsKey(ability)) {
|
||||
return cooldowns.get(ability);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user