NpcRoutesHolder.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2004-2014 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.model.holders;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.interfaces.ILocational;
  25. /**
  26. * Holds depending between NPC's spawn point and route
  27. * @author GKR
  28. */
  29. public final class NpcRoutesHolder
  30. {
  31. private final Map<String, String> _correspondences;
  32. public NpcRoutesHolder()
  33. {
  34. _correspondences = new HashMap<>();
  35. }
  36. /**
  37. * Add correspondence between specific route and specific spawn point
  38. * @param routeName name of route
  39. * @param loc Location of spawn point
  40. */
  41. public void addRoute(String routeName, Location loc)
  42. {
  43. _correspondences.put(getUniqueKey(loc), routeName);
  44. }
  45. /**
  46. * @param npc
  47. * @return route name for given NPC.
  48. */
  49. public String getRouteName(L2Npc npc)
  50. {
  51. if (npc.getSpawn() != null)
  52. {
  53. String key = getUniqueKey(npc.getSpawn().getLocation());
  54. return _correspondences.containsKey(key) ? _correspondences.get(key) : "";
  55. }
  56. return "";
  57. }
  58. /**
  59. * @param loc
  60. * @return unique text string for given Location.
  61. */
  62. private String getUniqueKey(ILocational loc)
  63. {
  64. return (loc.getX() + "-" + loc.getY() + "-" + loc.getZ());
  65. }
  66. }