Bladeren bron

Fix new bunch of minions spawned each teleport. Added handling of the teleporting in MinionList?.

_DS_ 14 jaren geleden
bovenliggende
commit
3956a59654

+ 37 - 16
L2_GameServer/java/com/l2jserver/gameserver/model/actor/instance/L2MonsterInstance.java

@@ -99,23 +99,35 @@ public class L2MonsterInstance extends L2Attackable
 	@Override
 	public void onSpawn()
 	{
-		if (getLeader() != null)
+		if (!isTeleporting())
 		{
-			setIsNoRndWalk(true);
-			setIsRaidMinion(getLeader().isRaid());
-			getLeader().getMinionList().onMinionSpawn(this);
-		}
+			if (getLeader() != null)
+			{
+				setIsNoRndWalk(true);
+				setIsRaidMinion(getLeader().isRaid());
+				getLeader().getMinionList().onMinionSpawn(this);
+			}
 
-		// delete spawned minions before dynamic minions spawned by script
-		if (hasMinions())
-			getMinionList().onMasterSpawn(); 
+			// delete spawned minions before dynamic minions spawned by script
+			if (hasMinions())
+				getMinionList().onMasterSpawn(); 
 
-		startMaintenanceTask();
+			startMaintenanceTask();
+		}
 
 		// dynamic script-based minions spawned here, after all preparations.
 		super.onSpawn();
 	}
 	
+	@Override
+	public void onTeleported()
+	{
+		super.onTeleported();
+
+		if (hasMinions())
+			getMinionList().onMasterTeleported();
+	}
+
 	protected int getMaintenanceInterval()
 	{
 		return MONSTER_MAINTENANCE_INTERVAL;
@@ -131,13 +143,16 @@ public class L2MonsterInstance extends L2Attackable
 		if (getTemplate().getMinionData() == null)
 			return;
 
-		_maintenanceTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
-			public void run()
-			{
-				if (_enableMinions)
-					getMinionList().spawnMinions();
-			}
-		}, getMaintenanceInterval() + Rnd.get(1000));
+		if (_maintenanceTask == null)
+		{
+			_maintenanceTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
+				public void run()
+				{
+					if (_enableMinions)
+						getMinionList().spawnMinions();
+				}
+			}, getMaintenanceInterval() + Rnd.get(1000));
+		}
 	}
 
 	@Override
@@ -147,7 +162,10 @@ public class L2MonsterInstance extends L2Attackable
 			return false;
 		
 		if (_maintenanceTask != null)
+		{
 			_maintenanceTask.cancel(false); // doesn't do it?
+			_maintenanceTask = null;
+		}
 
 		return true;
 	}
@@ -156,7 +174,10 @@ public class L2MonsterInstance extends L2Attackable
 	public void deleteMe()
 	{
 		if (_maintenanceTask != null)
+		{
 			_maintenanceTask.cancel(false);
+			_maintenanceTask = null;
+		}
 
 		if (hasMinions())
 			getMinionList().onMasterDie(true);

+ 30 - 0
L2_GameServer/java/com/l2jserver/gameserver/util/MinionList.java

@@ -207,6 +207,36 @@ public class MinionList
 		}
 	}
 
+	/**
+	 * Called from onTeleported() of the master
+	 * Alive and able to move minions teleported to master.
+	 */
+	public void onMasterTeleported()
+	{
+		final int offset = 200;
+		final int minRadius = (int)_master.getCollisionRadius() + 30;
+		
+		for (L2MonsterInstance minion : _minionReferences)
+		{
+			if (minion != null && !minion.isDead() && !minion.isMovementDisabled())
+			{
+				int newX = Rnd.get(minRadius * 2, offset * 2); // x
+				int newY = Rnd.get(newX, offset * 2); // distance
+				newY = (int)Math.sqrt(newY*newY - newX*newX); // y
+				if (newX > offset + minRadius)
+					newX = _master.getX() + newX - offset;
+				else
+					newX = _master.getX() - newX + minRadius;
+				if (newY > offset + minRadius)
+					newY = _master.getY() + newY - offset;
+				else
+					newY = _master.getY() - newY + minRadius;
+
+				minion.teleToLocation(newX, newY, _master.getZ());
+			}
+		}
+	}
+
 	private final void spawnMinion(int minionId)
 	{
 		if (minionId == 0)