Reuse dead NPC objects.
This commit is contained in:
@@ -249,7 +249,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
_scheduledCount++;
|
||||
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
RespawnTaskManager.getInstance().add(oldNpc, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,6 +551,15 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
return _spawnedNpcs;
|
||||
}
|
||||
|
||||
public void respawnNpc(Npc oldNpc)
|
||||
{
|
||||
if (_doRespawn)
|
||||
{
|
||||
oldNpc.refreshID();
|
||||
initializeNpcInstance(oldNpc);
|
||||
}
|
||||
}
|
||||
|
||||
public NpcTemplate getTemplate()
|
||||
{
|
||||
return _template;
|
||||
|
@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
final Npc npc = entry.getKey();
|
||||
final List<Long> schedules = entry.getValue();
|
||||
for (Long respawnTime : schedules)
|
||||
{
|
||||
@@ -48,23 +49,27 @@ public class RespawnTaskManager
|
||||
schedules.remove(respawnTime);
|
||||
if (schedules.isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
}
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
spawn.respawnNpc(npc);
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
public void add(Npc npc, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
if (!PENDING_RESPAWNS.containsKey(npc))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
PENDING_RESPAWNS.get(npc).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
|
Reference in New Issue
Block a user