Walker improvements.
This commit is contained in:
parent
65b99da7af
commit
3a550abff7
@ -53,10 +53,12 @@ public final class WalkingManager implements IGameXmlReader
|
|||||||
private static final Logger LOGGER = Logger.getLogger(WalkingManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(WalkingManager.class.getName());
|
||||||
|
|
||||||
// Repeat style:
|
// Repeat style:
|
||||||
|
// -1 - no repeat
|
||||||
// 0 - go back
|
// 0 - go back
|
||||||
// 1 - go to first point (circle style)
|
// 1 - go to first point (circle style)
|
||||||
// 2 - teleport to first point (conveyor style)
|
// 2 - teleport to first point (conveyor style)
|
||||||
// 3 - random walking between points.
|
// 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_BACK = 0;
|
||||||
public static final byte REPEAT_GO_FIRST = 1;
|
public static final byte REPEAT_GO_FIRST = 1;
|
||||||
public static final byte REPEAT_TELE_FIRST = 2;
|
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 String routeName = parseString(d.getAttributes(), "name");
|
||||||
final boolean repeat = parseBoolean(d.getAttributes(), "repeat");
|
final boolean repeat = parseBoolean(d.getAttributes(), "repeat");
|
||||||
final String repeatStyle = d.getAttributes().getNamedItem("repeatStyle").getNodeValue();
|
final String repeatStyle = d.getAttributes().getNamedItem("repeatStyle").getNodeValue().toLowerCase();
|
||||||
byte repeatType;
|
|
||||||
if (repeatStyle.equalsIgnoreCase("back"))
|
final byte repeatType;
|
||||||
|
switch (repeatStyle)
|
||||||
|
{
|
||||||
|
case "back":
|
||||||
{
|
{
|
||||||
repeatType = REPEAT_GO_BACK;
|
repeatType = REPEAT_GO_BACK;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (repeatStyle.equalsIgnoreCase("cycle"))
|
case "cycle":
|
||||||
{
|
{
|
||||||
repeatType = REPEAT_GO_FIRST;
|
repeatType = REPEAT_GO_FIRST;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (repeatStyle.equalsIgnoreCase("conveyor"))
|
case "conveyor":
|
||||||
{
|
{
|
||||||
repeatType = REPEAT_TELE_FIRST;
|
repeatType = REPEAT_TELE_FIRST;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (repeatStyle.equalsIgnoreCase("random"))
|
case "random":
|
||||||
{
|
{
|
||||||
repeatType = REPEAT_RANDOM;
|
repeatType = REPEAT_RANDOM;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
default:
|
||||||
{
|
{
|
||||||
repeatType = -1;
|
repeatType = NO_REPEAT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<L2NpcWalkerNode> list = new ArrayList<>();
|
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("Route '" + walk.getRoute().getName() + "', arrived to node " + walk.getCurrentNodeId());
|
||||||
npc.sendDebugMessage("Done in " + ((System.currentTimeMillis() - walk.getLastAction()) / 1000) + " s");
|
npc.sendDebugMessage("Done in " + ((System.currentTimeMillis() - walk.getLastAction()) / 1000) + " s");
|
||||||
|
walk.calculateNextNode(npc);
|
||||||
if (!walk.calculateNextNode(npc))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
walk.setBlocked(true); // prevents to be ran from walk check task, if there is delay in this node.
|
walk.setBlocked(true); // prevents to be ran from walk check task, if there is delay in this node.
|
||||||
|
|
||||||
if (node.getNpcString() != null)
|
if (node.getNpcString() != null)
|
||||||
@ -441,18 +447,7 @@ public final class WalkingManager implements IGameXmlReader
|
|||||||
walk.setLastAction(System.currentTimeMillis());
|
walk.setLastAction(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_activeRoutes.containsKey(npc.getObjectId()))
|
ThreadPoolManager.getInstance().scheduleGeneral(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000L));
|
||||||
{
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,10 @@ public class L2WalkRoute
|
|||||||
|
|
||||||
public L2WalkRoute(String name, List<L2NpcWalkerNode> route, boolean repeat, boolean once, byte repeatType)
|
public L2WalkRoute(String name, List<L2NpcWalkerNode> route, boolean repeat, boolean once, byte repeatType)
|
||||||
{
|
{
|
||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
_nodeList = route;
|
_nodeList = route;
|
||||||
_repeatType = repeatType;
|
_repeatType = repeatType;
|
||||||
_repeatWalk = ((_repeatType >= 0) && (_repeatType <= 2)) && repeat;
|
_repeatWalk = (_repeatType >= 0) && (_repeatType <= 2) && repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
|
@ -25,13 +25,12 @@ import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
|||||||
import com.l2jmobius.gameserver.model.events.impl.character.npc.OnNpcMoveRouteFinished;
|
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
|
* @author GKR, UnAfraid
|
||||||
*/
|
*/
|
||||||
public class WalkInfo
|
public class WalkInfo
|
||||||
{
|
{
|
||||||
private final String _routeName;
|
private final String _routeName;
|
||||||
|
|
||||||
private ScheduledFuture<?> _walkCheckTask;
|
private ScheduledFuture<?> _walkCheckTask;
|
||||||
private boolean _blocked = false;
|
private boolean _blocked = false;
|
||||||
private boolean _suspended = 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
|
* Calculate next node for this WalkInfo and send debug message from given npc
|
||||||
* @param npc NPC to debug message to be sent from
|
* @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
|
// Check this first, within the bounds of random moving, we have no conception of "first" or "last" node
|
||||||
if (getRoute().getRepeatType() == WalkingManager.REPEAT_RANDOM)
|
if (getRoute().getRepeatType() == WalkingManager.REPEAT_RANDOM)
|
||||||
@ -101,7 +99,7 @@ public class WalkInfo
|
|||||||
if (!getRoute().repeatWalk())
|
if (!getRoute().repeatWalk())
|
||||||
{
|
{
|
||||||
WalkingManager.getInstance().cancelMoving(npc);
|
WalkingManager.getInstance().cancelMoving(npc);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (getRoute().getRepeatType())
|
switch (getRoute().getRepeatType())
|
||||||
@ -125,14 +123,12 @@ public class WalkInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (_currentNode == WalkingManager.NO_REPEAT) // First node arrived, when direction is first <-- last
|
||||||
else if (_currentNode == -1) // First node arrived, when direction is first <-- last
|
|
||||||
{
|
{
|
||||||
_currentNode = 1;
|
_currentNode = 1;
|
||||||
_forward = true;
|
_forward = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,4 +218,10 @@ public class WalkInfo
|
|||||||
{
|
{
|
||||||
_walkCheckTask = val;
|
_walkCheckTask = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "WalkInfo [_routeName=" + _routeName + ", _walkCheckTask=" + _walkCheckTask + ", _blocked=" + _blocked + ", _suspended=" + _suspended + ", _stoppedByAttack=" + _stoppedByAttack + ", _currentNode=" + _currentNode + ", _forward=" + _forward + ", _lastActionTime=" + _lastActionTime + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ public class ArrivedTask implements Runnable
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
_npc.broadcastInfo();
|
||||||
_walk.setBlocked(false);
|
_walk.setBlocked(false);
|
||||||
WalkingManager.getInstance().startMoving(_npc, _walk.getRoute().getName());
|
WalkingManager.getInstance().startMoving(_npc, _walk.getRoute().getName());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user