Walker improvements.

This commit is contained in:
MobiusDev 2016-08-24 21:20:19 +00:00
parent 65b99da7af
commit 3a550abff7
4 changed files with 45 additions and 48 deletions

View File

@ -53,10 +53,12 @@ public final class WalkingManager implements IGameXmlReader
private static final Logger LOGGER = Logger.getLogger(WalkingManager.class.getName());
// Repeat style:
// -1 - no repeat
// 0 - go back
// 1 - go to first point (circle style)
// 2 - teleport to first point (conveyor style)
// 3 - random walking between points.
public static final byte NO_REPEAT = -1;
public static final byte REPEAT_GO_BACK = 0;
public static final byte REPEAT_GO_FIRST = 1;
public static final byte REPEAT_TELE_FIRST = 2;
@ -88,27 +90,36 @@ public final class WalkingManager implements IGameXmlReader
{
final String routeName = parseString(d.getAttributes(), "name");
final boolean repeat = parseBoolean(d.getAttributes(), "repeat");
final String repeatStyle = d.getAttributes().getNamedItem("repeatStyle").getNodeValue();
byte repeatType;
if (repeatStyle.equalsIgnoreCase("back"))
final String repeatStyle = d.getAttributes().getNamedItem("repeatStyle").getNodeValue().toLowerCase();
final byte repeatType;
switch (repeatStyle)
{
case "back":
{
repeatType = REPEAT_GO_BACK;
break;
}
else if (repeatStyle.equalsIgnoreCase("cycle"))
case "cycle":
{
repeatType = REPEAT_GO_FIRST;
break;
}
else if (repeatStyle.equalsIgnoreCase("conveyor"))
case "conveyor":
{
repeatType = REPEAT_TELE_FIRST;
break;
}
else if (repeatStyle.equalsIgnoreCase("random"))
case "random":
{
repeatType = REPEAT_RANDOM;
break;
}
else
default:
{
repeatType = -1;
repeatType = NO_REPEAT;
break;
}
}
final List<L2NpcWalkerNode> list = new ArrayList<>();
@ -419,12 +430,7 @@ public final class WalkingManager implements IGameXmlReader
{
npc.sendDebugMessage("Route '" + walk.getRoute().getName() + "', arrived to node " + walk.getCurrentNodeId());
npc.sendDebugMessage("Done in " + ((System.currentTimeMillis() - walk.getLastAction()) / 1000) + " s");
if (!walk.calculateNextNode(npc))
{
return;
}
walk.calculateNextNode(npc);
walk.setBlocked(true); // prevents to be ran from walk check task, if there is delay in this node.
if (node.getNpcString() != null)
@ -441,18 +447,7 @@ public final class WalkingManager implements IGameXmlReader
walk.setLastAction(System.currentTimeMillis());
}
if (_activeRoutes.containsKey(npc.getObjectId()))
{
if (node.getDelay() > 0)
{
ThreadPoolManager.getInstance().scheduleGeneral(new ArrivedTask(npc, walk), node.getDelay() * 1000L);
}
else
{
walk.setBlocked(false);
WalkingManager.getInstance().startMoving(npc, walk.getRoute().getName());
}
}
ThreadPoolManager.getInstance().scheduleGeneral(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000L));
}
}
}

View File

@ -31,11 +31,10 @@ public class L2WalkRoute
public L2WalkRoute(String name, List<L2NpcWalkerNode> route, boolean repeat, boolean once, byte repeatType)
{
_name = name;
_nodeList = route;
_repeatType = repeatType;
_repeatWalk = ((_repeatType >= 0) && (_repeatType <= 2)) && repeat;
_repeatWalk = (_repeatType >= 0) && (_repeatType <= 2) && repeat;
}
public String getName()

View File

@ -25,13 +25,12 @@ import com.l2jmobius.gameserver.model.events.EventDispatcher;
import com.l2jmobius.gameserver.model.events.impl.character.npc.OnNpcMoveRouteFinished;
/**
* Holds info about current walk progress
* Holds info about current walk progress.
* @author GKR, UnAfraid
*/
public class WalkInfo
{
private final String _routeName;
private ScheduledFuture<?> _walkCheckTask;
private boolean _blocked = false;
private boolean _suspended = false;
@ -64,9 +63,8 @@ public class WalkInfo
/**
* Calculate next node for this WalkInfo and send debug message from given npc
* @param npc NPC to debug message to be sent from
* @return
*/
public boolean calculateNextNode(L2Npc npc)
public synchronized void calculateNextNode(L2Npc npc)
{
// Check this first, within the bounds of random moving, we have no conception of "first" or "last" node
if (getRoute().getRepeatType() == WalkingManager.REPEAT_RANDOM)
@ -101,7 +99,7 @@ public class WalkInfo
if (!getRoute().repeatWalk())
{
WalkingManager.getInstance().cancelMoving(npc);
return false;
return;
}
switch (getRoute().getRepeatType())
@ -125,14 +123,12 @@ public class WalkInfo
}
}
}
else if (_currentNode == -1) // First node arrived, when direction is first <-- last
else if (_currentNode == WalkingManager.NO_REPEAT) // First node arrived, when direction is first <-- last
{
_currentNode = 1;
_forward = true;
}
}
return true;
}
/**
@ -222,4 +218,10 @@ public class WalkInfo
{
_walkCheckTask = val;
}
@Override
public String toString()
{
return "WalkInfo [_routeName=" + _routeName + ", _walkCheckTask=" + _walkCheckTask + ", _blocked=" + _blocked + ", _suspended=" + _suspended + ", _stoppedByAttack=" + _stoppedByAttack + ", _currentNode=" + _currentNode + ", _forward=" + _forward + ", _lastActionTime=" + _lastActionTime + "]";
}
}

View File

@ -38,6 +38,7 @@ public class ArrivedTask implements Runnable
@Override
public void run()
{
_npc.broadcastInfo();
_walk.setBlocked(false);
WalkingManager.getInstance().startMoving(_npc, _walk.getRoute().getName());
}