Addition of SchedulingPattern support for DBSpawnManager.
Contributed by kamikadzz.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -32,6 +32,7 @@ import java.util.logging.Logger;
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.commons.time.SchedulingPattern;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.SpawnTable;
|
||||
import org.l2jmobius.gameserver.data.xml.NpcData;
|
||||
@ -121,6 +122,7 @@ public class DBSpawnManager
|
||||
|
||||
int respawn = 0;
|
||||
int respawnRandom = 0;
|
||||
SchedulingPattern respawnPattern = null;
|
||||
if (spawnTemplate.getRespawnTime() != null)
|
||||
{
|
||||
respawn = (int) spawnTemplate.getRespawnTime().getSeconds();
|
||||
@ -129,10 +131,15 @@ public class DBSpawnManager
|
||||
{
|
||||
respawnRandom = (int) spawnTemplate.getRespawnTimeRandom().getSeconds();
|
||||
}
|
||||
if (spawnTemplate.getRespawnPattern() != null)
|
||||
{
|
||||
respawnPattern = spawnTemplate.getRespawnPattern();
|
||||
}
|
||||
|
||||
if (respawn > 0)
|
||||
if ((respawn > 0) || (respawnPattern != null))
|
||||
{
|
||||
spawn.setRespawnDelay(respawn, respawnRandom);
|
||||
spawn.setRespawnPattern(respawnPattern);
|
||||
spawn.startRespawn();
|
||||
}
|
||||
else
|
||||
@ -211,14 +218,27 @@ public class DBSpawnManager
|
||||
{
|
||||
npc.setDBStatus(RaidBossStatus.DEAD);
|
||||
|
||||
final int respawnMinDelay = (int) (npc.getSpawn().getRespawnMinDelay() * Config.RAID_MIN_RESPAWN_MULTIPLIER);
|
||||
final int respawnMaxDelay = (int) (npc.getSpawn().getRespawnMaxDelay() * Config.RAID_MAX_RESPAWN_MULTIPLIER);
|
||||
final int respawnDelay = Rnd.get(respawnMinDelay, respawnMaxDelay);
|
||||
final long respawnTime = System.currentTimeMillis() + respawnDelay;
|
||||
final SchedulingPattern respawnPattern = npc.getSpawn().getRespawnPattern();
|
||||
int respawnMinDelay, respawnMaxDelay, respawnDelay;
|
||||
long respawnTime;
|
||||
|
||||
if (respawnPattern != null)
|
||||
{
|
||||
respawnTime = respawnPattern.next(System.currentTimeMillis());
|
||||
respawnMinDelay = respawnMaxDelay = respawnDelay = (int) (respawnTime - System.currentTimeMillis());
|
||||
}
|
||||
else
|
||||
{
|
||||
respawnMinDelay = (int) (npc.getSpawn().getRespawnMinDelay() * Config.RAID_MIN_RESPAWN_MULTIPLIER);
|
||||
respawnMaxDelay = (int) (npc.getSpawn().getRespawnMaxDelay() * Config.RAID_MAX_RESPAWN_MULTIPLIER);
|
||||
respawnDelay = Rnd.get(respawnMinDelay, respawnMaxDelay);
|
||||
respawnTime = System.currentTimeMillis() + respawnDelay;
|
||||
}
|
||||
|
||||
info.set("currentHP", npc.getMaxHp());
|
||||
info.set("currentMP", npc.getMaxMp());
|
||||
info.set("respawnTime", respawnTime);
|
||||
if (!_schedules.containsKey(npc.getId()) && ((respawnMinDelay > 0) || (respawnMaxDelay > 0)))
|
||||
if ((!_schedules.containsKey(npc.getId()) && ((respawnMinDelay > 0) || (respawnMaxDelay > 0))) || (respawnPattern != null))
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Updated " + npc.getName() + " respawn time to " + Util.formatDate(new Date(respawnTime), "dd.MM.yyyy HH:mm"));
|
||||
_schedules.put(npc.getId(), ThreadPool.schedule(() -> scheduleSpawn(npc.getId()), respawnDelay));
|
||||
|
@ -24,6 +24,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.time.SchedulingPattern;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.xml.NpcData;
|
||||
import org.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
@ -69,6 +70,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
private int _respawnMinDelay;
|
||||
/** Maximum respawn delay */
|
||||
private int _respawnMaxDelay;
|
||||
/** Respawn Pattern **/
|
||||
private SchedulingPattern _respawnPattern;
|
||||
/** The generic constructor of Npc managed by this Spawn */
|
||||
private Constructor<? extends Npc> _constructor;
|
||||
/** If True an Npc is respawned each time that another is killed */
|
||||
@ -194,6 +197,14 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
return _respawnMaxDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return respawn pattern
|
||||
*/
|
||||
public SchedulingPattern getRespawnPattern()
|
||||
{
|
||||
return _respawnPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of Npc that this Spawn can manage.
|
||||
* @param amount
|
||||
@ -503,6 +514,11 @@ public class Spawn extends Location implements IIdentifiable, INamable
|
||||
}
|
||||
}
|
||||
|
||||
public void setRespawnPattern(SchedulingPattern respawnPattern)
|
||||
{
|
||||
_respawnPattern = respawnPattern;
|
||||
}
|
||||
|
||||
public void setRespawnDelay(int delay)
|
||||
{
|
||||
setRespawnDelay(delay, 0);
|
||||
|
@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.commons.time.SchedulingPattern;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.SpawnTable;
|
||||
import org.l2jmobius.gameserver.data.xml.NpcData;
|
||||
@ -54,6 +55,7 @@ public class NpcSpawnTemplate implements Cloneable, IParameterized<StatSet>
|
||||
private final int _count;
|
||||
private final Duration _respawnTime;
|
||||
private final Duration _respawnTimeRandom;
|
||||
private final SchedulingPattern _respawnPattern;
|
||||
private final int _chaseRange;
|
||||
private List<ChanceLocation> _locations;
|
||||
private SpawnTerritory _zone;
|
||||
@ -74,6 +76,7 @@ public class NpcSpawnTemplate implements Cloneable, IParameterized<StatSet>
|
||||
_count = template._count;
|
||||
_respawnTime = template._respawnTime;
|
||||
_respawnTimeRandom = template._respawnTimeRandom;
|
||||
_respawnPattern = template._respawnPattern;
|
||||
_chaseRange = template._chaseRange;
|
||||
_spawnAnimation = template._spawnAnimation;
|
||||
_saveInDB = template._saveInDB;
|
||||
@ -92,6 +95,7 @@ public class NpcSpawnTemplate implements Cloneable, IParameterized<StatSet>
|
||||
_count = set.getInt("count", 1);
|
||||
_respawnTime = set.getDuration("respawnTime", null);
|
||||
_respawnTimeRandom = set.getDuration("respawnRandom", null);
|
||||
_respawnPattern = (set.getString("respawnPattern", null) == null) || set.getString("respawnPattern", null).isEmpty() ? null : new SchedulingPattern(set.getString("respawnPattern", null));
|
||||
_chaseRange = set.getInt("chaseRange", 0);
|
||||
_spawnAnimation = set.getBoolean("spawnAnimation", false);
|
||||
_saveInDB = set.getBoolean("dbSave", false);
|
||||
@ -198,6 +202,11 @@ public class NpcSpawnTemplate implements Cloneable, IParameterized<StatSet>
|
||||
return _respawnTimeRandom;
|
||||
}
|
||||
|
||||
public SchedulingPattern getRespawnPattern()
|
||||
{
|
||||
return _respawnPattern;
|
||||
}
|
||||
|
||||
public int getChaseRange()
|
||||
{
|
||||
return _chaseRange;
|
||||
|
Reference in New Issue
Block a user