Check when walking manager tasks already run.

This commit is contained in:
MobiusDevelopment
2019-06-10 00:34:18 +00:00
parent 58d30b63a6
commit d54498e3e2
13 changed files with 344 additions and 96 deletions

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -68,6 +70,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -298,17 +303,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -445,7 +460,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -68,6 +70,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -298,17 +303,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -445,7 +460,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -68,6 +70,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -298,17 +303,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -445,7 +460,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -68,6 +70,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -298,17 +303,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -445,7 +460,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -68,6 +70,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -298,17 +303,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -445,7 +460,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -68,6 +70,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -298,17 +303,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -445,7 +460,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -68,6 +70,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -298,17 +303,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -445,7 +460,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
@ -64,6 +66,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -269,17 +274,29 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it }
else if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
final WalkInfo walk = _activeRoutes.get(npc.getObjectId()); final WalkInfo walk = _activeRoutes.get(npc.getObjectId());
if (walk == null) if (walk == null)
@ -309,6 +326,7 @@ public final class WalkingManager implements IXmlReader
} }
} }
} }
}
/** /**
* Cancel NPC moving permanently * Cancel NPC moving permanently
@ -317,12 +335,11 @@ public final class WalkingManager implements IXmlReader
public synchronized void cancelMoving(Npc npc) public synchronized void cancelMoving(Npc npc)
{ {
final WalkInfo walk = _activeRoutes.remove(npc.getObjectId()); final WalkInfo walk = _activeRoutes.remove(npc.getObjectId());
if (walk == null) if (walk != null)
{ {
return;
}
walk.getWalkCheckTask().cancel(true); walk.getWalkCheckTask().cancel(true);
} }
}
/** /**
* Resumes previously stopped moving * Resumes previously stopped moving
@ -331,14 +348,13 @@ public final class WalkingManager implements IXmlReader
public void resumeMoving(Npc npc) public void resumeMoving(Npc npc)
{ {
final WalkInfo walk = _activeRoutes.get(npc.getObjectId()); final WalkInfo walk = _activeRoutes.get(npc.getObjectId());
if (walk == null) if (walk != null)
{ {
return;
}
walk.setSuspended(false); walk.setSuspended(false);
walk.setStoppedByAttack(false); walk.setStoppedByAttack(false);
startMoving(npc, walk.getRoute().getName()); startMoving(npc, walk.getRoute().getName());
} }
}
/** /**
* Pause NPC moving until it will be resumed * Pause NPC moving until it will be resumed
@ -411,7 +427,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
/** /**

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -66,6 +68,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -296,17 +301,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -440,7 +455,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -66,6 +68,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -296,17 +301,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -440,7 +455,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -66,6 +68,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -296,17 +301,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -440,7 +455,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -66,6 +68,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -296,17 +301,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -440,7 +455,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }

View File

@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -66,6 +68,9 @@ public final class WalkingManager implements IXmlReader
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes private final Map<String, WalkRoute> _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, 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 private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
private final Map<Npc, ScheduledFuture<?>> _startMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _repeatMoveTasks = new ConcurrentHashMap<>();
private final Map<Npc, ScheduledFuture<?>> _arriveTasks = new ConcurrentHashMap<>();
protected WalkingManager() protected WalkingManager()
{ {
@ -296,17 +301,27 @@ public final class WalkingManager implements IXmlReader
npc.setWalking(); npc.setWalking();
} }
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node); npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, node);
walk.setWalkCheckTask(ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000)); // start walk check task, for resuming walk after fight
final ScheduledFuture<?> task = _repeatMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
final ScheduledFuture<?> newTask = ThreadPool.scheduleAtFixedRate(new StartMovingTask(npc, routeName), 60000, 60000);
_repeatMoveTasks.put(npc, newTask);
walk.setWalkCheckTask(newTask); // start walk check task, for resuming walk after fight
}
_activeRoutes.put(npc.getObjectId(), walk); // register route _activeRoutes.put(npc.getObjectId(), walk); // register route
} }
else else
{ {
ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000); final ScheduledFuture<?> task = _startMoveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_startMoveTasks.put(npc, ThreadPool.schedule(new StartMovingTask(npc, routeName), 60000));
} }
} }
else }
// walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it else // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
{ {
if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))) if (_activeRoutes.containsKey(npc.getObjectId()) && ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)))
{ {
@ -440,7 +455,11 @@ public final class WalkingManager implements IXmlReader
npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText()); npc.broadcastSay(ChatType.NPC_GENERAL, node.getChatText());
} }
ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)); final ScheduledFuture<?> task = _arriveTasks.get(npc);
if ((task == null) || task.isCancelled() || task.isDone())
{
_arriveTasks.put(npc, ThreadPool.schedule(new ArrivedTask(npc, walk), 100 + (node.getDelay() * 1000)));
}
} }
} }
} }