From 3a550abff7dc8c1e8ef5f783ee6a82b9461f38ce Mon Sep 17 00:00:00 2001 From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com> Date: Wed, 24 Aug 2016 21:20:19 +0000 Subject: [PATCH] Walker improvements. --- .../instancemanager/WalkingManager.java | 71 +++++++++---------- .../gameserver/model/L2WalkRoute.java | 3 +- .../l2jmobius/gameserver/model/WalkInfo.java | 18 ++--- .../actor/tasks/npc/walker/ArrivedTask.java | 1 + 4 files changed, 45 insertions(+), 48 deletions(-) diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/WalkingManager.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/WalkingManager.java index 42542f68a3..ba1c01f3e0 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/WalkingManager.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/WalkingManager.java @@ -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) { - repeatType = REPEAT_GO_BACK; - } - else if (repeatStyle.equalsIgnoreCase("cycle")) - { - repeatType = REPEAT_GO_FIRST; - } - else if (repeatStyle.equalsIgnoreCase("conveyor")) - { - repeatType = REPEAT_TELE_FIRST; - } - else if (repeatStyle.equalsIgnoreCase("random")) - { - repeatType = REPEAT_RANDOM; - } - else - { - repeatType = -1; + case "back": + { + repeatType = REPEAT_GO_BACK; + break; + } + case "cycle": + { + repeatType = REPEAT_GO_FIRST; + break; + } + case "conveyor": + { + repeatType = REPEAT_TELE_FIRST; + break; + } + case "random": + { + repeatType = REPEAT_RANDOM; + break; + } + default: + { + repeatType = NO_REPEAT; + break; + } } final List 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)); } } } diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2WalkRoute.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2WalkRoute.java index a56a3464d9..39f95342bf 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2WalkRoute.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2WalkRoute.java @@ -31,11 +31,10 @@ public class L2WalkRoute public L2WalkRoute(String name, List 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() diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/WalkInfo.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/WalkInfo.java index baa6e13bf9..89a519f7fb 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/WalkInfo.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/WalkInfo.java @@ -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 + "]"; + } } diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/npc/walker/ArrivedTask.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/npc/walker/ArrivedTask.java index 40a9b7c085..7d621e076d 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/npc/walker/ArrivedTask.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/tasks/npc/walker/ArrivedTask.java @@ -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()); }