Browse Source

BETA: NPC spawn-related changes
* Support for random respawn time
* Minor fix: if NPC's respawn time is set to 0 in spawn table - do not respawn it

* Reviewed by: UnAfraid, Zoey76, MELERIX
'''Note:''' Retail feature.

VlLight 12 years ago
parent
commit
6c327b0f0a

+ 8 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SpawnTable.java

@@ -64,7 +64,7 @@ public class SpawnTable
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
 			Statement s = con.createStatement();
-			ResultSet rs = s.executeQuery("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, loc_id, periodOfDay FROM spawnlist"))
+			ResultSet rs = s.executeQuery("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, respawn_random, loc_id, periodOfDay FROM spawnlist"))
 		{
 			L2Spawn spawnDat;
 			L2NpcTemplate template1;
@@ -93,7 +93,7 @@ public class SpawnTable
 						spawnDat.setLocy(rs.getInt("locy"));
 						spawnDat.setLocz(rs.getInt("locz"));
 						spawnDat.setHeading(rs.getInt("heading"));
-						spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
+						spawnDat.setRespawnDelay(rs.getInt("respawn_delay"), rs.getInt("respawn_random"));
 						int loc_id = rs.getInt("loc_id");
 						spawnDat.setLocation(loc_id);
 						
@@ -133,7 +133,7 @@ public class SpawnTable
 		{
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
 				Statement ps = con.createStatement();
-				ResultSet rs = ps.executeQuery("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, loc_id, periodOfDay FROM custom_spawnlist"))
+				ResultSet rs = ps.executeQuery("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, respawn_random, loc_id, periodOfDay FROM custom_spawnlist"))
 			{
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
@@ -162,7 +162,7 @@ public class SpawnTable
 							spawnDat.setLocy(rs.getInt("locy"));
 							spawnDat.setLocz(rs.getInt("locz"));
 							spawnDat.setHeading(rs.getInt("heading"));
-							spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
+							spawnDat.setRespawnDelay(rs.getInt("respawn_delay"), rs.getInt("respawn_random"));
 							spawnDat.setCustom(true);
 							int loc_id = rs.getInt("loc_id");
 							spawnDat.setLocation(loc_id);
@@ -224,7 +224,7 @@ public class SpawnTable
 			}
 			
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement insert = con.prepareStatement("INSERT INTO " + spawnTable + "(count,npc_templateid,locx,locy,locz,heading,respawn_delay,loc_id) values(?,?,?,?,?,?,?,?)"))
+				PreparedStatement insert = con.prepareStatement("INSERT INTO " + spawnTable + "count,npc_templateid,locx,locy,locz,heading,respawn_delay,respawn_random,loc_id) values(?,?,?,?,?,?,?,?,?)"))
 			{
 				insert.setInt(1, spawn.getAmount());
 				insert.setInt(2, spawn.getNpcid());
@@ -232,8 +232,9 @@ public class SpawnTable
 				insert.setInt(4, spawn.getLocy());
 				insert.setInt(5, spawn.getLocz());
 				insert.setInt(6, spawn.getHeading());
-				insert.setInt(7, spawn.getRespawnDelay() / 1000);
-				insert.setInt(8, spawn.getLocation());
+				insert.setInt(7, (int) (spawn.getRespawnDelay() / 1000));
+				insert.setInt(8, (int) (spawn.getRespawnMaxDelay() - spawn.getRespawnMinDelay()));				
+				insert.setInt(9, spawn.getLocation());
 				insert.execute();
 			}
 			catch (Exception e)

+ 2 - 46
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/HellboundManager.java

@@ -34,7 +34,6 @@ import com.l2jserver.gameserver.datatables.SpawnTable;
 import com.l2jserver.gameserver.model.L2Spawn;
 import com.l2jserver.gameserver.model.actor.L2Npc;
 import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
-import com.l2jserver.util.Rnd;
 
 /**
  * @author _DS_, GKR
@@ -275,18 +274,10 @@ public class HellboundManager
 					spawnDat.setLocy(rs.getInt("locy"));
 					spawnDat.setLocz(rs.getInt("locz"));
 					spawnDat.setHeading(rs.getInt("heading"));
-					spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
-					spawnDat.setRespawnMinDelay(0);
-					spawnDat.setRespawnMaxDelay(0);
-					int respawnRandom = (rs.getInt("respawn_random"));
-					if (respawnRandom > 0) // Random respawn time, if needed
-					{
-						spawnDat.setRespawnMinDelay(Math.max(rs.getInt("respawn_delay") - respawnRandom, 1));
-						spawnDat.setRespawnMaxDelay(rs.getInt("respawn_delay") + respawnRandom);
-					}
+					spawnDat.setRespawnDelay(rs.getInt("respawn_delay"), rs.getInt("respawn_random"));
 					spawnDat.setMinLvl(rs.getInt("min_hellbound_level"));
 					spawnDat.setMaxLvl(rs.getInt("max_hellbound_level"));
-					
+
 					// _population.put(spawnDat, null);
 					_population.add(spawnDat);
 					SpawnTable.getInstance().addNewSpawn(spawnDat, false);
@@ -308,9 +299,6 @@ public class HellboundManager
 	
 	public static final class HellboundSpawn extends L2Spawn
 	{
-		/** The delay between a L2NpcInstance remove and its re-spawn */
-		private int _respawnDelay;
-		
 		private int _minLvl;
 		private int _maxLvl;
 		
@@ -338,38 +326,6 @@ public class HellboundManager
 		{
 			_maxLvl = lvl;
 		}
-		
-		@Override
-		public final void decreaseCount(L2Npc oldNpc)
-		{
-			if (getRespawnDelay() <= 0)
-			{
-				stopRespawn();
-			}
-			else if (getRespawnMaxDelay() > getRespawnMinDelay())
-			{
-				setRespawnDelay(Rnd.get(getRespawnMinDelay(), getRespawnMaxDelay()));
-			}
-			
-			super.decreaseCount(oldNpc);
-		}
-		
-		/**
-		 * @param i delay in seconds
-		 */
-		@Override
-		public void setRespawnDelay(int i)
-		{
-			_respawnDelay = i * 1000;
-			
-			super.setRespawnDelay(i);
-		}
-		
-		@Override
-		public int getRespawnDelay()
-		{
-			return _respawnDelay;
-		}
 	}
 	
 	public static final HellboundManager getInstance()

+ 5 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/RaidBossSpawnManager.java

@@ -97,8 +97,8 @@ public class RaidBossSpawnManager
 					spawnDat.setLocz(rset.getInt("loc_z"));
 					spawnDat.setAmount(rset.getInt("amount"));
 					spawnDat.setHeading(rset.getInt("heading"));
-					spawnDat.setRespawnMinDelay(rset.getInt("respawn_min_delay"));
-					spawnDat.setRespawnMaxDelay(rset.getInt("respawn_max_delay"));
+					spawnDat.setRespawnMinDelay(rset.getInt("respawn_min_delay") * 1000L);
+					spawnDat.setRespawnMaxDelay(rset.getInt("respawn_max_delay") * 1000L);
 					respawnTime = rset.getLong("respawn_time");
 					
 					addNewSpawn(spawnDat, respawnTime, rset.getDouble("currentHP"), rset.getDouble("currentMP"), false);
@@ -189,9 +189,9 @@ public class RaidBossSpawnManager
 		{
 			boss.setRaidStatus(StatusEnum.DEAD);
 			
-			final int respawnMinDelay = boss.getSpawn().getRespawnMinDelay();
-			final int respawnMaxDelay = boss.getSpawn().getRespawnMaxDelay();
-			final long respawnDelay = Rnd.get((int) (respawnMinDelay * 1000 * Config.RAID_MIN_RESPAWN_MULTIPLIER), (int) (respawnMaxDelay * 1000 * Config.RAID_MAX_RESPAWN_MULTIPLIER));
+			final long respawnMinDelay = (long) (boss.getSpawn().getRespawnMinDelay() * Config.RAID_MIN_RESPAWN_MULTIPLIER);
+			final long respawnMaxDelay = (long) (boss.getSpawn().getRespawnMaxDelay() * Config.RAID_MAX_RESPAWN_MULTIPLIER);
+			final long respawnDelay = Rnd.get(respawnMinDelay, respawnMaxDelay);
 			final long respawnTime = Calendar.getInstance().getTimeInMillis() + respawnDelay;
 			
 			info.set("currentHP", boss.getMaxHp());

+ 52 - 38
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Spawn.java

@@ -77,14 +77,11 @@ public class L2Spawn
 	/** The heading of L2NpcInstance when they are spawned */
 	private int _heading;
 	
-	/** The delay between a L2NpcInstance remove and its re-spawn */
-	private int _respawnDelay;
+	/** Minimum respawn delay */
+	private long _respawnMinDelay;
 	
-	/** Minimum delay RaidBoss */
-	private int _respawnMinDelay;
-	
-	/** Maximum delay RaidBoss */
-	private int _respawnMaxDelay;
+	/** Maximum respawn delay */
+	private long _respawnMaxDelay;
 	
 	private int _instanceId = 0;
 	
@@ -211,7 +208,7 @@ public class L2Spawn
 	}
 	
 	/**
-	 * @return the Identifier of the L2NpcInstance manage by this L2Spwan contained in the L2NpcTemplate.
+	 * @return the Identifier of the L2NpcInstance manage by this L2Spawn contained in the L2NpcTemplate.
 	 */
 	public int getNpcid()
 	{
@@ -225,31 +222,23 @@ public class L2Spawn
 	{
 		return _heading;
 	}
-	
-	/**
-	 * @return the delay between a L2NpcInstance remove and its re-spawn.
-	 */
-	public int getRespawnDelay()
-	{
-		return _respawnDelay;
-	}
-	
+
 	/**
-	 * @return Min RaidBoss Spawn delay.
+	 * @return min respawn delay.
 	 */
-	public int getRespawnMinDelay()
+	public long getRespawnMinDelay()
 	{
 		return _respawnMinDelay;
 	}
-	
+
 	/**
-	 * @return Max RaidBoss Spawn delay.
+	 * @return max respawn delay.
 	 */
-	public int getRespawnMaxDelay()
+	public long getRespawnMaxDelay()
 	{
 		return _respawnMaxDelay;
 	}
-	
+
 	/**
 	 * Set the maximum number of L2NpcInstance that this L2Spawn can manage.
 	 * @param amount
@@ -272,7 +261,7 @@ public class L2Spawn
 	 * Set Minimum Respawn Delay.
 	 * @param date
 	 */
-	public void setRespawnMinDelay(int date)
+	public void setRespawnMinDelay(long date)
 	{
 		_respawnMinDelay = date;
 	}
@@ -281,7 +270,7 @@ public class L2Spawn
 	 * Set Maximum Respawn Delay.
 	 * @param date
 	 */
-	public void setRespawnMaxDelay(int date)
+	public void setRespawnMaxDelay(long date)
 	{
 		_respawnMaxDelay = date;
 	}
@@ -376,12 +365,12 @@ public class L2Spawn
 			
 			// Create a new SpawnTask to launch after the respawn Delay
 			// ClientScheduler.getInstance().scheduleLow(new SpawnTask(npcId), _respawnDelay);
-			ThreadPoolManager.getInstance().scheduleGeneral(new SpawnTask(oldNpc), _respawnDelay);
+			ThreadPoolManager.getInstance().scheduleGeneral(new SpawnTask(oldNpc), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
 		}
 	}
 	
 	/**
-	 * Create the initial spawning and set _doRespawn to True.
+	 * Create the initial spawning and set _doRespawn to False, if respawn time set to 0, or set it to True otherwise.
 	 * @return The number of L2NpcInstance that were spawned
 	 */
 	public int init()
@@ -390,7 +379,7 @@ public class L2Spawn
 		{
 			doSpawn();
 		}
-		_doRespawn = true;
+		_doRespawn = _respawnMinDelay != 0;
 		
 		return _currentCount;
 	}
@@ -624,23 +613,48 @@ public class L2Spawn
 	}
 	
 	/**
-	 * @param i delay in seconds
+	 * Set bounds for random calculation and delay for respawn 
+	 * @param delay delay in seconds
+	 * @param randomInterval random interval in seconds
 	 */
-	public void setRespawnDelay(int i)
+	public void setRespawnDelay(int delay, int randomInterval)
 	{
-		if (i < 0)
+		if (delay != 0)
 		{
-			_log.warning("respawn delay is negative for spawn:" + this);
+			if (delay < 0)
+			{
+				_log.warning("respawn delay is negative for spawn:" + this);
+			}
+
+			int minDelay = delay - randomInterval; 
+			int maxDelay = delay + randomInterval;
+
+			_respawnMinDelay = Math.max(10, minDelay) * 1000L;
+			_respawnMaxDelay = Math.max(10, maxDelay) * 1000L;
 		}
-		
-		if (i < 10)
+
+		else
 		{
-			i = 10;
+			_respawnMinDelay = 0;
+			_respawnMaxDelay = 0;
 		}
-		
-		_respawnDelay = i * 1000;
 	}
-	
+
+	public void setRespawnDelay(int delay)
+	{
+		setRespawnDelay(delay, 0);
+	}
+
+	public long getRespawnDelay()
+	{
+		return (_respawnMinDelay + _respawnMaxDelay) / 2;
+	}
+
+	public boolean hasRespawnRandom()
+	{
+		return _respawnMinDelay != _respawnMaxDelay;
+	}	
+
 	public L2Npc getLastSpawn()
 	{
 		return _lastSpawn;