123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- /*
- * Copyright (C) 2004-2013 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.model;
- import java.util.concurrent.ScheduledFuture;
- import com.l2jserver.gameserver.instancemanager.WalkingManager;
- import com.l2jserver.gameserver.model.actor.L2Npc;
- import com.l2jserver.gameserver.model.quest.Quest;
- import com.l2jserver.util.Rnd;
- /**
- * 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;
- private boolean _stoppedByAttack = false;
- private int _currentNode = 0;
- private boolean _forward = true; // Determines first --> last or first <-- last direction
- private long _lastActionTime; // Debug field
-
- public WalkInfo(String routeName)
- {
- _routeName = routeName;
- }
-
- /**
- * @return name of route of this WalkInfo.
- */
- public L2WalkRoute getRoute()
- {
- return WalkingManager.getInstance().getRoute(_routeName);
- }
-
- /**
- * @return current node of this WalkInfo.
- */
- public L2NpcWalkerNode getCurrentNode()
- {
- return getRoute().getNodeList().get(_currentNode);
- }
-
- /**
- * Calculate next node for this WalkInfo and send debug message from given npc
- * @param npc NPC to debug message to be sent from
- */
- public 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)
- {
- int newNode = _currentNode;
-
- while (newNode == _currentNode)
- {
- newNode = Rnd.get(getRoute().getNodesCount());
- }
-
- _currentNode = newNode;
- npc.sendDebugMessage("Route: " + getRoute().getName() + ", next random node is " + _currentNode);
- }
- else
- {
- if (_forward)
- {
- _currentNode++;
- }
- else
- {
- _currentNode--;
- }
-
- if (_currentNode == getRoute().getNodesCount()) // Last node arrived
- {
- // Notify quest
- if (npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_ROUTE_FINISHED) != null)
- {
- for (Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_ROUTE_FINISHED))
- {
- quest.notifyRouteFinished(npc);
- }
- }
- npc.sendDebugMessage("Route: " + getRoute().getName() + ", last node arrived");
-
- if (!getRoute().repeatWalk())
- {
- WalkingManager.getInstance().cancelMoving(npc);
- return;
- }
-
- switch (getRoute().getRepeatType())
- {
- case WalkingManager.REPEAT_GO_BACK:
- {
- _forward = false;
- _currentNode -= 2;
- break;
- }
- case WalkingManager.REPEAT_GO_FIRST:
- {
- _currentNode = 0;
- break;
- }
- case WalkingManager.REPEAT_TELE_FIRST:
- {
- npc.teleToLocation(npc.getSpawn().getLocation());
- _currentNode = 0;
- break;
- }
- }
- }
-
- else if (_currentNode == -1) // First node arrived, when direction is first <-- last
- {
- _currentNode = 1;
- _forward = true;
- }
- }
- }
-
- /**
- * @return {@code true} if walking task is blocked, {@code false} otherwise,
- */
- public boolean isBlocked()
- {
- return _blocked;
- }
-
- /**
- * @param val
- */
- public void setBlocked(boolean val)
- {
- _blocked = val;
- }
-
- /**
- * @return {@code true} if walking task is suspended, {@code false} otherwise,
- */
- public boolean isSuspended()
- {
- return _suspended;
- }
-
- /**
- * @param val
- */
- public void setSuspended(boolean val)
- {
- _suspended = val;
- }
-
- /**
- * @return {@code true} if walking task shall be stopped by attack, {@code false} otherwise,
- */
- public boolean isStoppedByAttack()
- {
- return _stoppedByAttack;
- }
-
- /**
- * @param val
- */
- public void setStoppedByAttack(boolean val)
- {
- _stoppedByAttack = val;
- }
-
- /**
- * @return the id of the current node in this walking task.
- */
- public int getCurrentNodeId()
- {
- return _currentNode;
- }
-
- /**
- * @return {@code long} last action time used only for debugging.
- */
- public long getLastAction()
- {
- return _lastActionTime;
- }
-
- /**
- * @param val
- */
- public void setLastAction(long val)
- {
- _lastActionTime = val;
- }
-
- /**
- * @return walking check task.
- */
- public ScheduledFuture<?> getWalkCheckTask()
- {
- return _walkCheckTask;
- }
-
- /**
- * @param val walking check task.
- */
- public void setWalkCheckTask(ScheduledFuture<?> val)
- {
- _walkCheckTask = val;
- }
- }
|