Browse Source

BETA: Now is possible to set random walk to NPCs spawned into instance zones.
* Global parameter.
* Individual parameter for each spawn.

'''Note:''' Please refer to XDS for usage.

Zoey76 12 năm trước cách đây
mục cha
commit
b401095a1e

+ 7 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/WalkingManager.java

@@ -16,7 +16,6 @@
  * 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 com.l2jserver.gameserver.instancemanager;
 
 import java.util.ArrayList;
@@ -47,13 +46,17 @@ import com.l2jserver.util.Rnd;
  */
 public class WalkingManager extends DocumentParser
 {
-	// Repeat style: 0 - go back, 1 - go to first point (circle style), 2 - teleport to first point (conveyor style), 3 - random walking between points.
+	// Repeat style:
+	// 0 - go back
+	// 1 - go to first point (circle style)
+	// 2 - teleport to first point (conveyor style)
+	// 3 - random walking between points.
 	private static final byte REPEAT_GO_BACK = 0;
 	private static final byte REPEAT_GO_FIRST = 1;
 	private static final byte REPEAT_TELE_FIRST = 2;
 	private static final byte REPEAT_RANDOM = 3;
 	
-	protected Map<Integer, L2WalkRoute> _routes = new HashMap<>(); // all available routes
+	protected final Map<Integer, L2WalkRoute> _routes = new HashMap<>(); // all available routes
 	private final Map<Integer, WalkInfo> _activeRoutes = new HashMap<>(); // each record represents NPC, moving by predefined route from _routes, and moving progress
 	private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
 	
@@ -319,8 +322,7 @@ public class WalkingManager extends DocumentParser
 						}
 					}
 				}
-				L2WalkRoute newRoute = new L2WalkRoute(routeId, list, repeat, false, repeatType);
-				_routes.put(routeId, newRoute);
+				_routes.put(routeId, new L2WalkRoute(routeId, list, repeat, false, repeatType));
 			}
 		}
 	}
@@ -351,12 +353,10 @@ public class WalkingManager extends DocumentParser
 		}
 		
 		WalkInfo walk = monster != null ? _activeRoutes.get(monster.getObjectId()) : _activeRoutes.get(npc.getObjectId());
-		
 		if (walk._stoppedByAttack || walk._suspended)
 		{
 			return false;
 		}
-		
 		return true;
 	}
 	

+ 14 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2Spawn.java

@@ -97,6 +97,8 @@ public class L2Spawn
 	private L2Npc _lastSpawn;
 	private static List<SpawnListener> _spawnListeners = new FastList<>();
 	
+	private boolean _isNoRndWalk = false; // Is no random walk
+	
 	/** The task launching the function doSpawn() */
 	class SpawnTask implements Runnable
 	{
@@ -536,6 +538,8 @@ public class L2Spawn
 		mob.setCurrentHpMp(mob.getMaxHp(), mob.getMaxMp());
 		// Set default value
 		mob.setScriptValue(0);
+		// Set is not random walk default value
+		mob.setIsNoRndWalk(isNoRndWalk());
 		
 		// Set the heading of the L2NpcInstance (random heading if not defined)
 		if (getHeading() == -1)
@@ -692,4 +696,14 @@ public class L2Spawn
 	{
 		return "L2Spawn [_template=" + getNpcid() + ", _locX=" + _locX + ", _locY=" + _locY + ", _locZ=" + _locZ + ", _heading=" + _heading + "]";
 	}
+	
+	public final boolean isNoRndWalk()
+	{
+		return _isNoRndWalk;
+	}
+	
+	public final void setIsNoRndWalk(boolean value)
+	{
+		_isNoRndWalk = value;
+	}
 }

+ 20 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Instance.java

@@ -78,6 +78,8 @@ public final class Instance
 	private final int _id;
 	private String _name;
 	private int _ejectTime = Config.EJECT_DEAD_PLAYER_TIME;
+	/** Allow random walk for NPCs, global parameter. */
+	private boolean _allowRandomWalk = true;
 	private final L2FastList<Integer> _players = new L2FastList<>(true);
 	private final List<L2Npc> _npcs = new L2FastList<>(true);
 	private final Map<Integer, L2DoorInstance> _doors = new L2FastMap<>(true);
@@ -444,7 +446,11 @@ public final class Instance
 		{
 			_ejectTime = 1000 * Integer.parseInt(a.getNodeValue());
 		}
-		
+		a = n.getAttributes().getNamedItem("allowRandomWalk");
+		if (a != null)
+		{
+			_allowRandomWalk = Boolean.parseBoolean(a.getNodeValue());
+		}
 		Node first = n.getFirstChild();
 		for (n = first; n != null; n = n.getNextSibling())
 		{
@@ -546,7 +552,7 @@ public final class Instance
 						for (Node d = group.getFirstChild(); d != null; d = d.getNextSibling())
 						{
 							int npcId = 0, x = 0, y = 0, z = 0, heading = 0, respawn = 0, respawnRandom = 0, delay = -1;
-							
+							Boolean allowRandomWalk = null;
 							if ("spawn".equalsIgnoreCase(d.getNodeName()))
 							{
 								
@@ -564,7 +570,10 @@ public final class Instance
 								{
 									respawnRandom = Integer.parseInt(d.getAttributes().getNamedItem("respawnRandom").getNodeValue());
 								}
-								
+								if (d.getAttributes().getNamedItem("allowRandomWalk") != null)
+								{
+									allowRandomWalk = Boolean.valueOf(d.getAttributes().getNamedItem("allowRandomWalk").getNodeValue());
+								}
 								npcTemplate = NpcTable.getInstance().getTemplate(npcId);
 								if (npcTemplate != null)
 								{
@@ -584,6 +593,14 @@ public final class Instance
 										spawnDat.startRespawn();
 									}
 									spawnDat.setInstanceId(getId());
+									if (allowRandomWalk == null)
+									{
+										spawnDat.setIsNoRndWalk(!_allowRandomWalk);
+									}
+									else
+									{
+										spawnDat.setIsNoRndWalk(!allowRandomWalk);
+									}
 									if (spawnGroup.equals("general"))
 									{
 										L2Npc spawned = spawnDat.doSpawn();