WalkingManager.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.instancemanager;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.concurrent.ScheduledFuture;
  25. import org.w3c.dom.NamedNodeMap;
  26. import org.w3c.dom.Node;
  27. import com.l2jserver.gameserver.ThreadPoolManager;
  28. import com.l2jserver.gameserver.ai.CtrlIntention;
  29. import com.l2jserver.gameserver.engines.DocumentParser;
  30. import com.l2jserver.gameserver.model.L2CharPosition;
  31. import com.l2jserver.gameserver.model.L2NpcWalkerNode;
  32. import com.l2jserver.gameserver.model.L2WalkRoute;
  33. import com.l2jserver.gameserver.model.Location;
  34. import com.l2jserver.gameserver.model.actor.L2Npc;
  35. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  36. import com.l2jserver.gameserver.model.quest.Quest;
  37. import com.l2jserver.gameserver.network.NpcStringId;
  38. import com.l2jserver.gameserver.network.clientpackets.Say2;
  39. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  40. import com.l2jserver.gameserver.util.Broadcast;
  41. import com.l2jserver.util.Rnd;
  42. /**
  43. * This class manages walking monsters.
  44. * @author GKR
  45. */
  46. public class WalkingManager extends DocumentParser
  47. {
  48. // Repeat style:
  49. // 0 - go back
  50. // 1 - go to first point (circle style)
  51. // 2 - teleport to first point (conveyor style)
  52. // 3 - random walking between points.
  53. private static final byte REPEAT_GO_BACK = 0;
  54. private static final byte REPEAT_GO_FIRST = 1;
  55. private static final byte REPEAT_TELE_FIRST = 2;
  56. private static final byte REPEAT_RANDOM = 3;
  57. protected final Map<String, L2WalkRoute> _routes = new HashMap<>(); // all available routes
  58. private final Map<Integer, WalkInfo> _activeRoutes = new HashMap<>(); // each record represents NPC, moving by predefined route from _routes, and moving progress
  59. private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it
  60. /**
  61. * Holds depending between NPC's spawn point and route
  62. */
  63. private class NpcRoutesHolder
  64. {
  65. private final Map<String, String> _correspondences;
  66. public NpcRoutesHolder()
  67. {
  68. _correspondences = new HashMap<>();
  69. }
  70. /**
  71. * Add correspondence between specific route and specific spawn point
  72. * @param routeName name of route
  73. * @param loc Location of spawn point
  74. */
  75. public void addRoute(String routeName, Location loc)
  76. {
  77. _correspondences.put(getUniqueKey(loc), routeName);
  78. }
  79. /**
  80. * @param npc
  81. * @return route name for given NPC.
  82. */
  83. public String getRouteName(L2Npc npc)
  84. {
  85. if (npc.getSpawn() != null)
  86. {
  87. String key = getUniqueKey(npc.getSpawn().getSpawnLocation());
  88. return _correspondences.containsKey(key) ? _correspondences.get(key) : "";
  89. }
  90. return "";
  91. }
  92. /**
  93. * @param loc
  94. * @return unique text string for given Location.
  95. */
  96. private String getUniqueKey(Location loc)
  97. {
  98. return (loc.getX() + "-" + loc.getY() + "-" + loc.getZ());
  99. }
  100. }
  101. /**
  102. * Holds info about current walk progress
  103. */
  104. private class WalkInfo
  105. {
  106. protected ScheduledFuture<?> _walkCheckTask;
  107. protected boolean _blocked = false;
  108. protected boolean _suspended = false;
  109. protected boolean _stoppedByAttack = false;
  110. protected int _currentNode = 0;
  111. protected boolean _forward = true; // Determines first --> last or first <-- last direction
  112. private final String _routeName;
  113. protected long _lastActionTime; // Debug field
  114. public WalkInfo(String routeName)
  115. {
  116. _routeName = routeName;
  117. }
  118. /**
  119. * @return name of route of this WalkInfo.
  120. */
  121. protected L2WalkRoute getRoute()
  122. {
  123. return _routes.get(_routeName);
  124. }
  125. /**
  126. * @return current node of this WalkInfo.
  127. */
  128. protected L2NpcWalkerNode getCurrentNode()
  129. {
  130. return getRoute().getNodeList().get(_currentNode);
  131. }
  132. /**
  133. * Calculate next node for this WalkInfo and send debug message from given npc
  134. * @param npc NPC to debug message to be sent from
  135. */
  136. protected void calculateNextNode(L2Npc npc)
  137. {
  138. // Check this first, within the bounds of random moving, we have no conception of "first" or "last" node
  139. if (getRoute().getRepeatType() == REPEAT_RANDOM)
  140. {
  141. int newNode = _currentNode;
  142. while (newNode == _currentNode)
  143. {
  144. newNode = Rnd.get(getRoute().getNodesCount());
  145. }
  146. _currentNode = newNode;
  147. npc.sendDebugMessage("Route: " + getRoute().getName() + ", next random node is " + _currentNode);
  148. }
  149. else
  150. {
  151. if (_forward)
  152. {
  153. _currentNode++;
  154. }
  155. else
  156. {
  157. _currentNode--;
  158. }
  159. if (_currentNode == getRoute().getNodesCount()) // Last node arrived
  160. {
  161. npc.sendDebugMessage("Route: " + getRoute().getName() + ", last node arrived");
  162. if (!getRoute().repeatWalk())
  163. {
  164. cancelMoving(npc);
  165. return;
  166. }
  167. switch (getRoute().getRepeatType())
  168. {
  169. case REPEAT_GO_BACK:
  170. _forward = false;
  171. _currentNode -= 2;
  172. break;
  173. case REPEAT_GO_FIRST:
  174. _currentNode = 0;
  175. break;
  176. case REPEAT_TELE_FIRST:
  177. npc.teleToLocation(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), npc.getSpawn().getLocz());
  178. _currentNode = 0;
  179. break;
  180. }
  181. }
  182. else if (_currentNode == -1) // First node arrived, when direction is first <-- last
  183. {
  184. _currentNode = 1;
  185. _forward = true;
  186. }
  187. }
  188. }
  189. }
  190. protected WalkingManager()
  191. {
  192. load();
  193. }
  194. @Override
  195. public final void load()
  196. {
  197. parseDatapackFile("data/Routes.xml");
  198. _log.info(getClass().getSimpleName() + ": Loaded " + _routes.size() + " walking routes.");
  199. }
  200. @Override
  201. protected void parseDocument()
  202. {
  203. Node n = getCurrentDocument().getFirstChild();
  204. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  205. {
  206. if (d.getNodeName().equals("route"))
  207. {
  208. final String routeName = parseString(d.getAttributes(), "name");
  209. boolean repeat = parseBoolean(d.getAttributes(), "repeat");
  210. String repeatStyle = d.getAttributes().getNamedItem("repeatStyle").getNodeValue();
  211. byte repeatType;
  212. if (repeatStyle.equalsIgnoreCase("back"))
  213. {
  214. repeatType = REPEAT_GO_BACK;
  215. }
  216. else if (repeatStyle.equalsIgnoreCase("cycle"))
  217. {
  218. repeatType = REPEAT_GO_FIRST;
  219. }
  220. else if (repeatStyle.equalsIgnoreCase("conveyor"))
  221. {
  222. repeatType = REPEAT_TELE_FIRST;
  223. }
  224. else if (repeatStyle.equalsIgnoreCase("random"))
  225. {
  226. repeatType = REPEAT_RANDOM;
  227. }
  228. else
  229. {
  230. repeatType = -1;
  231. }
  232. final List<L2NpcWalkerNode> list = new ArrayList<>();
  233. for (Node r = d.getFirstChild(); r != null; r = r.getNextSibling())
  234. {
  235. if (r.getNodeName().equals("point"))
  236. {
  237. NamedNodeMap attrs = r.getAttributes();
  238. int x = parseInt(attrs, "X");
  239. int y = parseInt(attrs, "Y");
  240. int z = parseInt(attrs, "Z");
  241. int delay = parseInt(attrs, "delay");
  242. String chatString = null;
  243. NpcStringId npcString = null;
  244. Node node = attrs.getNamedItem("string");
  245. if (node != null)
  246. {
  247. chatString = node.getNodeValue();
  248. }
  249. else
  250. {
  251. node = attrs.getNamedItem("npcString");
  252. if (node != null)
  253. {
  254. npcString = NpcStringId.getNpcStringId(node.getNodeValue());
  255. if (npcString == null)
  256. {
  257. _log.warning(getClass().getSimpleName() + ": Unknown npcstring '" + node.getNodeValue() + ".");
  258. continue;
  259. }
  260. }
  261. else
  262. {
  263. node = attrs.getNamedItem("npcStringId");
  264. if (node != null)
  265. {
  266. npcString = NpcStringId.getNpcStringId(Integer.parseInt(node.getNodeValue()));
  267. if (npcString == null)
  268. {
  269. _log.warning(getClass().getSimpleName() + ": Unknown npcstring '" + node.getNodeValue() + ".");
  270. continue;
  271. }
  272. }
  273. }
  274. }
  275. list.add(new L2NpcWalkerNode(0, npcString, chatString, x, y, z, delay, parseBoolean(attrs, "run")));
  276. }
  277. else if (r.getNodeName().equals("target"))
  278. {
  279. NamedNodeMap attrs = r.getAttributes();
  280. try
  281. {
  282. int npcId = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
  283. int x = 0, y = 0, z = 0;
  284. x = Integer.parseInt(attrs.getNamedItem("spawnX").getNodeValue());
  285. y = Integer.parseInt(attrs.getNamedItem("spawnY").getNodeValue());
  286. z = Integer.parseInt(attrs.getNamedItem("spawnZ").getNodeValue());
  287. NpcRoutesHolder holder = _routesToAttach.containsKey(npcId) ? _routesToAttach.get(npcId) : new NpcRoutesHolder();
  288. holder.addRoute(routeName, new Location(x, y, z));
  289. _routesToAttach.put(npcId, holder);
  290. }
  291. catch (Exception e)
  292. {
  293. _log.warning("Walking Manager: Error in target definition for route : " + routeName);
  294. }
  295. }
  296. }
  297. _routes.put(routeName, new L2WalkRoute(routeName, list, repeat, false, repeatType));
  298. }
  299. }
  300. }
  301. /**
  302. * @param npc NPC to check
  303. * @return {@code true} if given NPC, or its leader is controlled by Walking Manager and moves currently.
  304. */
  305. public boolean isOnWalk(L2Npc npc)
  306. {
  307. L2MonsterInstance monster = null;
  308. if (npc.isMonster())
  309. {
  310. if (((L2MonsterInstance) npc).getLeader() == null)
  311. {
  312. monster = (L2MonsterInstance) npc;
  313. }
  314. else
  315. {
  316. monster = ((L2MonsterInstance) npc).getLeader();
  317. }
  318. }
  319. if (((monster != null) && !isRegistered(monster)) || !isRegistered(npc))
  320. {
  321. return false;
  322. }
  323. WalkInfo walk = monster != null ? _activeRoutes.get(monster.getObjectId()) : _activeRoutes.get(npc.getObjectId());
  324. if (walk._stoppedByAttack || walk._suspended)
  325. {
  326. return false;
  327. }
  328. return true;
  329. }
  330. /**
  331. * @param npc NPC to check
  332. * @return {@code true} if given NPC controlled by Walking Manager.
  333. */
  334. public boolean isRegistered(L2Npc npc)
  335. {
  336. return _activeRoutes.containsKey(npc.getObjectId());
  337. }
  338. /**
  339. * @param npc
  340. * @return name of route
  341. */
  342. public String getRouteName(L2Npc npc)
  343. {
  344. return _activeRoutes.containsKey(npc.getObjectId()) ? _activeRoutes.get(npc.getObjectId()).getRoute().getName() : "";
  345. }
  346. /**
  347. * Start to move given NPC by given route
  348. * @param npc NPC to move
  349. * @param routeName name of route to move by
  350. */
  351. public void startMoving(final L2Npc npc, final String routeName)
  352. {
  353. if (_routes.containsKey(routeName) && (npc != null) && !npc.isDead()) // check, if these route and NPC present
  354. {
  355. if (!_activeRoutes.containsKey(npc.getObjectId())) // new walk task
  356. {
  357. // only if not already moved / not engaged in battle... should not happens if called on spawn
  358. if ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))
  359. {
  360. WalkInfo walk = new WalkInfo(routeName);
  361. if (npc.isDebug())
  362. {
  363. walk._lastActionTime = System.currentTimeMillis();
  364. }
  365. L2NpcWalkerNode node = walk.getCurrentNode();
  366. // adjust next waypoint, if NPC spawns at first waypoint
  367. if ((npc.getX() == node.getMoveX()) && (npc.getY() == node.getMoveY()))
  368. {
  369. walk.calculateNextNode(npc);
  370. node = walk.getCurrentNode();
  371. npc.sendDebugMessage("Route " + routeName + ", spawn point is same with first waypoint, adjusted to next");
  372. }
  373. if (!npc.isInsideRadius(node.getMoveX(), node.getMoveY(), node.getMoveZ(), 3000, true, false))
  374. {
  375. npc.sendDebugMessage("Route " + routeName + ", NPC is too far from starting point, walking will no start");
  376. return;
  377. }
  378. npc.sendDebugMessage("Starting to move at route " + routeName);
  379. npc.setIsRunning(node.getRunning());
  380. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(node.getMoveX(), node.getMoveY(), node.getMoveZ(), 0));
  381. walk._walkCheckTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new Runnable()
  382. {
  383. @Override
  384. public void run()
  385. {
  386. startMoving(npc, routeName);
  387. }
  388. }, 60000, 60000); // start walk check task, for resuming walk after fight
  389. npc.getKnownList().startTrackingTask();
  390. _activeRoutes.put(npc.getObjectId(), walk); // register route
  391. }
  392. else
  393. {
  394. npc.sendDebugMessage("Trying to start move at route " + routeName + ", but cannot now, scheduled");
  395. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  396. {
  397. @Override
  398. public void run()
  399. {
  400. startMoving(npc, routeName);
  401. }
  402. }, 60000);
  403. }
  404. }
  405. else
  406. // walk was stopped due to some reason (arrived to node, script action, fight or something else), resume it
  407. {
  408. if ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE) || (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE))
  409. {
  410. WalkInfo walk = _activeRoutes.get(npc.getObjectId());
  411. // Prevent call simultaneously from scheduled task and onArrived() or temporarily stop walking for resuming in future
  412. if (walk._blocked || walk._suspended)
  413. {
  414. npc.sendDebugMessage("Trying continue to move at route " + routeName + ", but cannot now (operation is blocked)");
  415. return;
  416. }
  417. walk._blocked = true;
  418. L2NpcWalkerNode node = walk.getCurrentNode();
  419. npc.sendDebugMessage("Route id: " + routeName + ", continue to node " + walk._currentNode);
  420. npc.setIsRunning(node.getRunning());
  421. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(node.getMoveX(), node.getMoveY(), node.getMoveZ(), 0));
  422. walk._blocked = false;
  423. walk._stoppedByAttack = false;
  424. }
  425. else
  426. {
  427. npc.sendDebugMessage("Trying continue to move at route " + routeName + ", but cannot now (wrong AI state)");
  428. }
  429. }
  430. }
  431. }
  432. /**
  433. * Cancel NPC moving permanently
  434. * @param npc NPC to cancel
  435. */
  436. public synchronized void cancelMoving(L2Npc npc)
  437. {
  438. if (_activeRoutes.containsKey(npc.getObjectId()))
  439. {
  440. final WalkInfo walk = _activeRoutes.remove(npc.getObjectId());
  441. walk._walkCheckTask.cancel(true);
  442. npc.getKnownList().stopTrackingTask();
  443. }
  444. }
  445. /**
  446. * Resumes previously stopped moving
  447. * @param npc NPC to resume
  448. */
  449. public void resumeMoving(final L2Npc npc)
  450. {
  451. if (!_activeRoutes.containsKey(npc.getObjectId()))
  452. {
  453. return;
  454. }
  455. WalkInfo walk = _activeRoutes.get(npc.getObjectId());
  456. walk._suspended = false;
  457. walk._stoppedByAttack = false;
  458. startMoving(npc, walk.getRoute().getName());
  459. }
  460. /**
  461. * Pause NPC moving until it will be resumed
  462. * @param npc NPC to pause moving
  463. * @param suspend {@code true} if moving was temporarily suspended for some reasons of AI-controlling script
  464. * @param stoppedByAttack {@code true} if moving was suspended because of NPC was attacked or desired to attack
  465. */
  466. public void stopMoving(L2Npc npc, boolean suspend, boolean stoppedByAttack)
  467. {
  468. L2MonsterInstance monster = null;
  469. if (npc.isMonster())
  470. {
  471. if (((L2MonsterInstance) npc).getLeader() == null)
  472. {
  473. monster = (L2MonsterInstance) npc;
  474. }
  475. else
  476. {
  477. monster = ((L2MonsterInstance) npc).getLeader();
  478. }
  479. }
  480. if (((monster != null) && !isRegistered(monster)) || !isRegistered(npc))
  481. {
  482. return;
  483. }
  484. WalkInfo walk = monster != null ? _activeRoutes.get(monster.getObjectId()) : _activeRoutes.get(npc.getObjectId());
  485. walk._suspended = suspend;
  486. walk._stoppedByAttack = stoppedByAttack;
  487. if (monster != null)
  488. {
  489. monster.stopMove(null);
  490. monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  491. }
  492. else
  493. {
  494. npc.stopMove(null);
  495. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  496. }
  497. }
  498. /**
  499. * Manage "node arriving"-related tasks: schedule move to next node; send ON_NODE_ARRIVED event to Quest script
  500. * @param npc NPC to manage
  501. */
  502. public void onArrived(final L2Npc npc)
  503. {
  504. if (_activeRoutes.containsKey(npc.getObjectId()))
  505. {
  506. // Notify quest
  507. if (npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_NODE_ARRIVED) != null)
  508. {
  509. for (Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_NODE_ARRIVED))
  510. {
  511. quest.notifyNodeArrived(npc);
  512. }
  513. }
  514. WalkInfo walk = _activeRoutes.get(npc.getObjectId());
  515. // Opposite should not happen... but happens sometime
  516. if ((walk._currentNode >= 0) && (walk._currentNode < walk.getRoute().getNodesCount()))
  517. {
  518. L2NpcWalkerNode node = walk.getRoute().getNodeList().get(walk._currentNode);
  519. if (npc.isInsideRadius(node.getMoveX(), node.getMoveY(), node.getMoveZ(), 10, false, false))
  520. {
  521. npc.sendDebugMessage("Route: " + walk.getRoute().getName() + ", arrived to node " + walk._currentNode);
  522. npc.sendDebugMessage("Done in " + ((System.currentTimeMillis() - walk._lastActionTime) / 1000) + " s.");
  523. walk.calculateNextNode(npc);
  524. int delay = node.getDelay();
  525. walk._blocked = true; // prevents to be ran from walk check task, if there is delay in this node.
  526. if (node.getNpcString() != null)
  527. {
  528. Broadcast.toKnownPlayers(npc, new NpcSay(npc, Say2.NPC_ALL, node.getNpcString()));
  529. }
  530. else
  531. {
  532. final String text = node.getChatText();
  533. if ((text != null) && !text.isEmpty())
  534. {
  535. Broadcast.toKnownPlayers(npc, new NpcSay(npc, Say2.NPC_ALL, text));
  536. }
  537. }
  538. if (npc.isDebug())
  539. {
  540. walk._lastActionTime = System.currentTimeMillis();
  541. }
  542. ThreadPoolManager.getInstance().scheduleGeneral(new ArrivedTask(npc, walk), 100 + (delay * 1000L));
  543. }
  544. }
  545. }
  546. }
  547. /**
  548. * Manage "on death"-related tasks: permanently cancel moving of died NPC
  549. * @param npc NPC to manage
  550. */
  551. public void onDeath(L2Npc npc)
  552. {
  553. cancelMoving(npc);
  554. }
  555. /**
  556. * Manage "on spawn"-related tasks: start NPC moving, if there is route attached to its spawn point
  557. * @param npc NPC to manage
  558. */
  559. public void onSpawn(L2Npc npc)
  560. {
  561. if (_routesToAttach.containsKey(npc.getNpcId()))
  562. {
  563. final String routeName = _routesToAttach.get(npc.getNpcId()).getRouteName(npc);
  564. if (!routeName.isEmpty())
  565. {
  566. startMoving(npc, routeName);
  567. }
  568. }
  569. }
  570. private class ArrivedTask implements Runnable
  571. {
  572. WalkInfo _walk;
  573. L2Npc _npc;
  574. public ArrivedTask(L2Npc npc, WalkInfo walk)
  575. {
  576. _npc = npc;
  577. _walk = walk;
  578. }
  579. @Override
  580. public void run()
  581. {
  582. _walk._blocked = false;
  583. startMoving(_npc, _walk.getRoute().getName());
  584. }
  585. }
  586. public static final WalkingManager getInstance()
  587. {
  588. return SingletonHolder._instance;
  589. }
  590. private static class SingletonHolder
  591. {
  592. protected static final WalkingManager _instance = new WalkingManager();
  593. }
  594. }