Cloning works now, changed object list to hash map (significant performance increase)

This commit is contained in:
Light2
2013-09-21 19:02:35 +02:00
parent b676dffdec
commit c7bfc890bd
13 changed files with 145 additions and 59 deletions
+47 -2
View File
@@ -22,10 +22,17 @@
package resources.objects;
import java.nio.ByteOrder;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import main.NGECore;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator;
import resources.objects.creature.CreatureObject;
import com.sleepycat.persist.model.NotPersistent;
import com.sleepycat.persist.model.Persistent;
@@ -56,7 +63,9 @@ public class Buff implements IListObject {
private boolean decayOnPvPDeath;
private long startTime;
private int totalPlayTime;
private byte decayCounter;
private byte decayCounter = 0;
@NotPersistent
private ScheduledFuture<?> removalTask;
public Buff(String buffName, long ownerId) {
@@ -355,8 +364,44 @@ public class Buff implements IListObject {
return decayCounter;
}
public void incDecayCounter(byte decayCounter) {
public void incDecayCounter() {
this.decayCounter++;
}
public ScheduledFuture<?> getRemovalTask() {
return removalTask;
}
public void setRemovalTask(ScheduledFuture<?> removalTask) {
this.removalTask = removalTask;
}
public void updateRemovalTask() {
if(removalTask == null)
return;
removalTask.cancel(true);
final NGECore core = NGECore.getInstance();
final CreatureObject owner = (CreatureObject) core.objectService.getObject(getOwnerId());
if(owner == null)
return;
ScheduledFuture<?> task = Executors.newScheduledThreadPool(1).schedule(new Runnable() {
@Override
public void run() {
core.buffService.removeBuffFromCreature(owner, Buff.this);
}
}, (long) getRemainingDuration(), TimeUnit.SECONDS);
setRemovalTask(task);
}
}