Reuse dead NPC objects.

This commit is contained in:
MobiusDevelopment
2019-06-09 03:14:29 +00:00
parent 6514604c4a
commit ea06ddbade
37 changed files with 500 additions and 210 deletions

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -20,6 +20,9 @@ import org.l2jmobius.gameserver.enums.Race;
import org.l2jmobius.gameserver.handler.IUserCommandHandler; import org.l2jmobius.gameserver.handler.IUserCommandHandler;
import org.l2jmobius.gameserver.instancemanager.MapRegionManager; import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager; import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance; import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.zone.type.RespawnZone; import org.l2jmobius.gameserver.model.zone.type.RespawnZone;
import org.l2jmobius.gameserver.network.SystemMessageId; import org.l2jmobius.gameserver.network.SystemMessageId;
@@ -66,6 +69,21 @@ public class Loc implements IUserCommandHandler
sm.addString(player.getX() + ", " + player.getY() + ", " + player.getZ()); sm.addString(player.getX() + ", " + player.getY() + ", " + player.getZ());
} }
player.sendPacket(sm); player.sendPacket(sm);
for (WorldObject obj : World.getInstance().getVisibleObjects())
{
if (obj.isMonster())
{
((MonsterInstance) obj).doDie(((MonsterInstance) obj));
}
}
// System.out.println(ThreadPool.log.size());
// ThreadPool.log.clear();
// ThreadPool.LOGOUT();
return true; return true;
} }

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -79,7 +79,7 @@ public class ChristmasTree implements IItemHandler
spawn.setX(target.getX()); spawn.setX(target.getX());
spawn.setY(target.getY()); spawn.setY(target.getY());
spawn.setZ(target.getZ()); spawn.setZ(target.getZ());
final NpcInstance result = spawn.spawnOne(); final NpcInstance result = spawn.doSpawn();
player.destroyItem("Consume", item.getObjectId(), 1, null, false); player.destroyItem("Consume", item.getObjectId(), 1, null, false);

View File

@@ -72,7 +72,7 @@ public class JackpotSeed implements IItemHandler
spawn.setX(player.getX()); spawn.setX(player.getX());
spawn.setY(player.getY()); spawn.setY(player.getY());
spawn.setZ(player.getZ()); spawn.setZ(player.getZ());
_gourd = (GourdInstance) spawn.spawnOne(); _gourd = (GourdInstance) spawn.doSpawn();
World.getInstance().storeObject(_gourd); World.getInstance().storeObject(_gourd);
_gourd.setOwner(player.getName()); _gourd.setOwner(player.getName());
player.destroyItem("Consume", item.getObjectId(), 1, null, false); player.destroyItem("Consume", item.getObjectId(), 1, null, false);

View File

@@ -151,7 +151,7 @@ public class SummonItems implements IItemHandler
spawn.setX(player.getX()); spawn.setX(player.getX());
spawn.setY(player.getY()); spawn.setY(player.getY());
spawn.setZ(player.getZ()); spawn.setZ(player.getZ());
World.getInstance().storeObject(spawn.spawnOne()); World.getInstance().storeObject(spawn.doSpawn());
player.destroyItem("Summon", item.getObjectId(), 1, null, false); player.destroyItem("Summon", item.getObjectId(), 1, null, false);
player.sendMessage("Created " + npcTemplate.name + " at x: " + spawn.getX() + " y: " + spawn.getY() + " z: " + spawn.getZ()); player.sendMessage("Created " + npcTemplate.name + " at x: " + spawn.getX() + " y: " + spawn.getY() + " z: " + spawn.getZ());
} }

View File

@@ -482,7 +482,7 @@ public class ChristmasManager
spawn.setY(y); spawn.setY(y);
spawn.setZ(z); spawn.setZ(z);
NpcInstance tree = spawn.spawnOne(); NpcInstance tree = spawn.doSpawn();
World.getInstance().storeObject(tree); World.getInstance().storeObject(tree);
objectQueue.add(tree); objectQueue.add(tree);
} }

View File

@@ -3185,7 +3185,7 @@ public class NpcInstance extends Creature
// Decrease its spawn counter // Decrease its spawn counter
if (_spawn != null) if (_spawn != null)
{ {
_spawn.decreaseCount(); _spawn.decreaseCount(this);
} }
} }

View File

@@ -222,7 +222,7 @@ public class DevastatedCastle
spawn.setY(-13717); spawn.setY(-13717);
spawn.setZ(-2263); spawn.setZ(-2263);
spawn.stopRespawn(); spawn.stopRespawn();
result = spawn.spawnOne(); result = spawn.doSpawn();
} }
catch (Exception e) catch (Exception e)
{ {
@@ -289,7 +289,7 @@ public class DevastatedCastle
spawn.setY(-17624); spawn.setY(-17624);
spawn.setZ(-2194); spawn.setZ(-2194);
spawn.stopRespawn(); spawn.stopRespawn();
result = spawn.spawnOne(); result = spawn.doSpawn();
_gustav = ThreadPool.schedule(new DeSpawnTimer(result), 3600000); // 60 * 60 * 1000 _gustav = ThreadPool.schedule(new DeSpawnTimer(result), 3600000); // 60 * 60 * 1000
template = NpcTable.getInstance().getTemplate(BOSS1_ID); template = NpcTable.getInstance().getTemplate(BOSS1_ID);
@@ -298,7 +298,7 @@ public class DevastatedCastle
spawn.setY(-17535); spawn.setY(-17535);
spawn.setZ(-2195); spawn.setZ(-2195);
spawn.stopRespawn(); spawn.stopRespawn();
_minion1 = spawn.spawnOne(); _minion1 = spawn.doSpawn();
_dietrich = ThreadPool.schedule(new DeSpawnTimer(_minion1), 3600000); // 60 * 60 * 1000 _dietrich = ThreadPool.schedule(new DeSpawnTimer(_minion1), 3600000); // 60 * 60 * 1000
template = NpcTable.getInstance().getTemplate(BOSS2_ID); template = NpcTable.getInstance().getTemplate(BOSS2_ID);
@@ -307,7 +307,7 @@ public class DevastatedCastle
spawn.setY(-17712); spawn.setY(-17712);
spawn.setZ(-2194); spawn.setZ(-2194);
spawn.stopRespawn(); spawn.stopRespawn();
_minion2 = spawn.spawnOne(); _minion2 = spawn.doSpawn();
_mikhail = ThreadPool.schedule(new DeSpawnTimer(_minion2), 3600000); // 60 * 60 * 1000 _mikhail = ThreadPool.schedule(new DeSpawnTimer(_minion2), 3600000); // 60 * 60 * 1000
spawnMonsters(); spawnMonsters();

View File

@@ -208,7 +208,7 @@ public class FortressOfResistance
spawn.setY(111275); spawn.setY(111275);
spawn.setZ(-1970); spawn.setZ(-1970);
spawn.stopRespawn(); spawn.stopRespawn();
result = spawn.spawnOne(); result = spawn.doSpawn();
} }
catch (Exception e) catch (Exception e)
{ {
@@ -246,7 +246,7 @@ public class FortressOfResistance
spawn.setY(108867); spawn.setY(108867);
spawn.setZ(-2020); spawn.setZ(-2020);
spawn.stopRespawn(); spawn.stopRespawn();
result = spawn.spawnOne(); result = spawn.doSpawn();
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -132,7 +132,7 @@ public final class QuestSpawn
spawn.setY(y); spawn.setY(y);
spawn.setZ(z + 20); spawn.setZ(z + 20);
spawn.stopRespawn(); spawn.stopRespawn();
result = spawn.spawnOne(); result = spawn.doSpawn();
if (despawnDelay > 0) if (despawnDelay > 0)
{ {

View File

@@ -346,8 +346,9 @@ public class Spawn
* <li>Create a new SpawnTask to launch after the respawn Delay</li><BR> * <li>Create a new SpawnTask to launch after the respawn Delay</li><BR>
* <BR> * <BR>
* <FONT COLOR=#FF0000><B> <U>Caution</U> : A respawn is possible ONLY if _doRespawn=True and _scheduledCount + _currentCount < _maximumCount</B></FONT><BR> * <FONT COLOR=#FF0000><B> <U>Caution</U> : A respawn is possible ONLY if _doRespawn=True and _scheduledCount + _currentCount < _maximumCount</B></FONT><BR>
* @param oldNpc
*/ */
public void decreaseCount() public void decreaseCount(NpcInstance oldNpc)
{ {
// Decrease the current number of NpcInstance of this Spawn // Decrease the current number of NpcInstance of this Spawn
_currentCount--; _currentCount--;
@@ -359,7 +360,7 @@ public class Spawn
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // Schedule the next respawn.
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + _respawnDelay); RespawnTaskManager.getInstance().add(oldNpc, System.currentTimeMillis() + _respawnDelay);
} }
} }
@@ -379,15 +380,6 @@ public class Spawn
return _currentCount; return _currentCount;
} }
/**
* Create a NpcInstance in this Spawn.
* @return
*/
public NpcInstance spawnOne()
{
return doSpawn();
}
/** /**
* Set _doRespawn to False to stop respawn in this Spawn. * Set _doRespawn to False to stop respawn in this Spawn.
*/ */
@@ -429,7 +421,7 @@ public class Spawn
*/ */
public NpcInstance doSpawn() public NpcInstance doSpawn()
{ {
NpcInstance mob = null; NpcInstance npc = null;
try try
{ {
// Check if the Spawn is not a Net or Minion spawn // Check if the Spawn is not a Net or Minion spawn
@@ -437,7 +429,7 @@ public class Spawn
{ {
_currentCount++; _currentCount++;
return mob; return npc;
} }
// Get NpcInstance Init parameters and its generate an Identifier // Get NpcInstance Init parameters and its generate an Identifier
@@ -457,25 +449,25 @@ public class Spawn
// Check if the Instance is a NpcInstance // Check if the Instance is a NpcInstance
if (!(tmp instanceof NpcInstance)) if (!(tmp instanceof NpcInstance))
{ {
return mob; return npc;
} }
mob = (NpcInstance) tmp; npc = (NpcInstance) tmp;
return initializeNpcInstance(mob); return initializeNpcInstance(npc);
} }
catch (Exception e) catch (Exception e)
{ {
LOGGER.warning("NPC " + _template.npcId + " class not found " + e); LOGGER.warning("NPC " + _template.npcId + " class not found " + e);
} }
return mob; return npc;
} }
/** /**
* @param mob * @param npc
* @return * @return
*/ */
private NpcInstance initializeNpcInstance(NpcInstance mob) private NpcInstance initializeNpcInstance(NpcInstance npc)
{ {
int newlocx; int newlocx;
int newlocy; int newlocy;
@@ -486,7 +478,7 @@ public class Spawn
{ {
if (_location == 0) if (_location == 0)
{ {
return mob; return npc;
} }
// Calculate the random position in the location area // Calculate the random position in the location area
@@ -505,45 +497,45 @@ public class Spawn
newlocz = _locZ; newlocz = _locZ;
} }
if (mob != null) if (npc != null)
{ {
mob.stopAllEffects(); npc.stopAllEffects();
// Set the HP and MP of the NpcInstance to the max // Set the HP and MP of the NpcInstance to the max
mob.setCurrentHpMp(mob.getMaxHp(), mob.getMaxMp()); npc.setCurrentHpMp(npc.getMaxHp(), npc.getMaxMp());
// Set the heading of the NpcInstance (random heading if not defined) // Set the heading of the NpcInstance (random heading if not defined)
if (_heading == -1) if (_heading == -1)
{ {
mob.setHeading(Rnd.get(61794)); npc.setHeading(Rnd.get(61794));
} }
else else
{ {
mob.setHeading(_heading); npc.setHeading(_heading);
} }
// Reset decay info // Reset decay info
mob.setDecayed(false); npc.setDecayed(false);
// Link the NpcInstance to this Spawn // Link the NpcInstance to this Spawn
mob.setSpawn(this); npc.setSpawn(this);
// Init other values of the NpcInstance (ex : from its CreatureTemplate for INT, STR, DEX...) and add it in the world as a visible object // Init other values of the NpcInstance (ex : from its CreatureTemplate for INT, STR, DEX...) and add it in the world as a visible object
mob.spawnMe(newlocx, newlocy, newlocz); npc.spawnMe(newlocx, newlocy, newlocz);
notifyNpcSpawned(mob); notifyNpcSpawned(npc);
_lastSpawn = mob; _lastSpawn = npc;
for (Quest quest : mob.getTemplate().getEventQuests(Quest.QuestEventType.ON_SPAWN)) for (Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_SPAWN))
{ {
quest.notifySpawn(mob); quest.notifySpawn(npc);
} }
// Increase the current number of NpcInstance managed by this Spawn // Increase the current number of NpcInstance managed by this Spawn
_currentCount++; _currentCount++;
} }
return mob; return npc;
} }
public static void addSpawnListener(SpawnListener listener) public static void addSpawnListener(SpawnListener listener)
@@ -596,6 +588,15 @@ public class Spawn
return _lastSpawn; return _lastSpawn;
} }
public void respawnNpc(NpcInstance oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
import org.l2jmobius.gameserver.model.spawn.Spawn; import org.l2jmobius.gameserver.model.spawn.Spawn;
/** /**
@@ -30,16 +31,16 @@ import org.l2jmobius.gameserver.model.spawn.Spawn;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<NpcInstance, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<NpcInstance, List<Long>> entry : PENDING_RESPAWNS.entrySet())
{ {
final Spawn spawn = entry.getKey(); final NpcInstance npc = entry.getKey();
final List<Long> schedules = entry.getValue(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 0, 1000);
} }
public void add(Spawn spawn, Long time) public void add(NpcInstance 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() public static RespawnTaskManager getInstance()

View File

@@ -249,7 +249,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()

View File

@@ -30,6 +30,7 @@ import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.model.actor.Npc; import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance; import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate; import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.interfaces.IIdentifiable; import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable; import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate; import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
@@ -254,7 +255,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
_scheduledCount++; _scheduledCount++;
// Schedule the next respawn. // 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));
} }
} }
@@ -468,7 +469,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
_respawnMinDelay = Math.max(10, minDelay) * 1000; _respawnMinDelay = Math.max(10, minDelay) * 1000;
_respawnMaxDelay = Math.max(10, maxDelay) * 1000; _respawnMaxDelay = Math.max(10, maxDelay) * 1000;
} }
else else
{ {
_respawnMinDelay = 0; _respawnMinDelay = 0;
@@ -511,6 +511,22 @@ public class Spawn extends Location implements IIdentifiable, INamable
return _spawnedNpcs; return _spawnedNpcs;
} }
public void respawnNpc(Npc oldNpc)
{
if (_doRespawn)
{
oldNpc.refreshID();
initializeNpcInstance(oldNpc);
// Register NPC back to instance world.
final Instance instance = oldNpc.getInstanceWorld();
if (instance != null)
{
instance.addNpc(oldNpc);
}
}
}
public NpcTemplate getTemplate() public NpcTemplate getTemplate()
{ {
return _template; return _template;

View File

@@ -24,22 +24,23 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.actor.Npc;
/** /**
* @author Mobius * @author Mobius
*/ */
public class RespawnTaskManager 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() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); 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(); final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules) for (Long respawnTime : schedules)
{ {
@@ -48,23 +49,27 @@ public class RespawnTaskManager
schedules.remove(respawnTime); schedules.remove(respawnTime);
if (schedules.isEmpty()) 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); }, 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() public static RespawnTaskManager getInstance()