Addition of RespawnTaskManager.
This commit is contained in:
parent
dd6da7e385
commit
6de4ae247c
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -3185,7 +3185,7 @@ public class NpcInstance extends Creature
|
||||
// Decrease its spawn counter
|
||||
if (_spawn != null)
|
||||
{
|
||||
_spawn.decreaseCount(this);
|
||||
_spawn.decreaseCount();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,13 +21,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.datatables.sql.TerritoryTable;
|
||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||
import org.l2jmobius.gameserver.model.WorldObject;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
|
||||
import org.l2jmobius.gameserver.model.quest.Quest;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
import org.l2jmobius.gameserver.templates.creatures.NpcTemplate;
|
||||
|
||||
/**
|
||||
@ -47,7 +47,7 @@ public class Spawn
|
||||
private int _location;
|
||||
private int _maximumCount;
|
||||
private int _currentCount;
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
private int _locX;
|
||||
private int _locY;
|
||||
private int _locZ;
|
||||
@ -61,36 +61,13 @@ public class Spawn
|
||||
private NpcInstance _lastSpawn;
|
||||
private static List<SpawnListener> _spawnListeners = new ArrayList<>();
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(e.getMessage());
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<BR>
|
||||
* <BR>
|
||||
* <B><U> Concept</U> :</B><BR>
|
||||
* <BR>
|
||||
* Each Spawn owns generic and static properties (ex : RewardExp, RewardSP, AggroRange...). All of those properties are stored in a different NpcTemplate for each type of Spawn. Each template is loaded once in the server cache memory (reduce memory use). When a new instance of Spawn is
|
||||
* created, server just create a link between the instance and the template. This link is stored in <B>_template</B><BR>
|
||||
* Each Spawn owns generic and static properties (ex : RewardExp, RewardSP, AggroRange...). All of those properties are stored in a different NpcTemplate for each type of Spawn. Each template is loaded once in the server cache memory (reduce memory use). When a new instance of Spawn is created,
|
||||
* server just create a link between the instance and the template. This link is stored in <B>_template</B><BR>
|
||||
* <BR>
|
||||
* Each NpcInstance is linked to a Spawn that manages its spawn and respawn (delay, location...). This link is stored in <B>_spawn</B> of the NpcInstance<BR>
|
||||
* <BR>
|
||||
@ -369,10 +346,8 @@ public class Spawn
|
||||
* <li>Create a new SpawnTask to launch after the respawn Delay</li><BR>
|
||||
* <BR>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : A respawn is possible ONLY if _doRespawn=True and _scheduledCount + _currentCount < _maximumCount</B></FONT><BR>
|
||||
* <BR>
|
||||
* @param oldNpc
|
||||
*/
|
||||
public void decreaseCount(/* int npcId */final NpcInstance oldNpc)
|
||||
public void decreaseCount()
|
||||
{
|
||||
// Decrease the current number of NpcInstance of this Spawn
|
||||
_currentCount--;
|
||||
@ -383,8 +358,8 @@ public class Spawn
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), _respawnDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + _respawnDelay);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.spawn.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -25,7 +25,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.datatables.NpcPersonalAIData;
|
||||
@ -38,6 +37,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -59,7 +59,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** Link to NPC spawn territory */
|
||||
@ -77,29 +77,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is random walk
|
||||
private int _spawnTemplateId = 0;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -271,8 +248,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
|
||||
import org.l2jmobius.gameserver.model.interfaces.INamable;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
|
||||
|
||||
/**
|
||||
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.<br>
|
||||
@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
/** The current number of NpcInstance managed by this Spawn */
|
||||
private int _currentCount;
|
||||
/** The current number of SpawnTask in progress or stand by of this Spawn */
|
||||
protected int _scheduledCount;
|
||||
public int _scheduledCount;
|
||||
/** The identifier of the location area where NpcInstance can be spawned */
|
||||
private int _locationId;
|
||||
/** The spawn instance id */
|
||||
@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private boolean _randomWalk = false; // Is no random walk
|
||||
private NpcSpawnTemplate _spawnTemplate;
|
||||
|
||||
/** The task launching the function doSpawn() */
|
||||
class SpawnTask implements Runnable
|
||||
{
|
||||
public SpawnTask()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
doSpawn();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "", e);
|
||||
}
|
||||
|
||||
_scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor of Spawn.<br>
|
||||
* <B><U>Concept</U>:</B><br>
|
||||
@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
// Update the current number of SpawnTask in progress or stand by of this Spawn
|
||||
_scheduledCount++;
|
||||
|
||||
// Create a new SpawnTask to launch after the respawn Delay
|
||||
ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
|
||||
// Schedule the next respawn.
|
||||
RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
{
|
||||
private static final Map<Spawn, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
|
||||
public RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Entry<Spawn, List<Long>> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
final Spawn spawn = entry.getKey();
|
||||
for (Long respawnTime : entry.getValue())
|
||||
{
|
||||
if (time > respawnTime)
|
||||
{
|
||||
entry.getValue().remove(respawnTime);
|
||||
spawn.doSpawn();
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
PENDING_RESPAWNS.remove(spawn);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void add(Spawn spawn, Long time)
|
||||
{
|
||||
if (!PENDING_RESPAWNS.containsKey(spawn))
|
||||
{
|
||||
PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
PENDING_RESPAWNS.get(spawn).add(time);
|
||||
}
|
||||
|
||||
public static RespawnTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user