NodeLoc.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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.pathfinding.cellnodes;
  20. import com.l2jserver.gameserver.GeoData;
  21. import com.l2jserver.gameserver.geoengine.Direction;
  22. import com.l2jserver.gameserver.pathfinding.AbstractNodeLoc;
  23. /**
  24. * @author -Nemesiss-, FBIagent
  25. */
  26. public class NodeLoc extends AbstractNodeLoc
  27. {
  28. private int _x;
  29. private int _y;
  30. private boolean _goNorth;
  31. private boolean _goEast;
  32. private boolean _goSouth;
  33. private boolean _goWest;
  34. private int _geoHeight;
  35. public NodeLoc(int x, int y, int z)
  36. {
  37. set(x, y, z);
  38. }
  39. public void set(int x, int y, int z)
  40. {
  41. _x = x;
  42. _y = y;
  43. _goNorth = GeoData.getInstance().canEnterNeighbors(x, y, z, Direction.NORTH);
  44. _goEast = GeoData.getInstance().canEnterNeighbors(x, y, z, Direction.EAST);
  45. _goSouth = GeoData.getInstance().canEnterNeighbors(x, y, z, Direction.SOUTH);
  46. _goWest = GeoData.getInstance().canEnterNeighbors(x, y, z, Direction.WEST);
  47. _geoHeight = GeoData.getInstance().getNearestZ(x, y, z);
  48. }
  49. public boolean canGoNorth()
  50. {
  51. return _goNorth;
  52. }
  53. public boolean canGoEast()
  54. {
  55. return _goEast;
  56. }
  57. public boolean canGoSouth()
  58. {
  59. return _goSouth;
  60. }
  61. public boolean canGoWest()
  62. {
  63. return _goWest;
  64. }
  65. public boolean canGoNone()
  66. {
  67. return !canGoNorth() && !canGoEast() && !canGoSouth() && !canGoWest();
  68. }
  69. public boolean canGoAll()
  70. {
  71. return canGoNorth() && canGoEast() && canGoSouth() && canGoWest();
  72. }
  73. @Override
  74. public int getX()
  75. {
  76. return GeoData.getInstance().getWorldX(_x);
  77. }
  78. @Override
  79. public int getY()
  80. {
  81. return GeoData.getInstance().getWorldY(_y);
  82. }
  83. @Override
  84. public int getZ()
  85. {
  86. return _geoHeight;
  87. }
  88. @Override
  89. public void setZ(short z)
  90. {
  91. //
  92. }
  93. @Override
  94. public int getNodeX()
  95. {
  96. return _x;
  97. }
  98. @Override
  99. public int getNodeY()
  100. {
  101. return _y;
  102. }
  103. @Override
  104. public int hashCode()
  105. {
  106. final int prime = 31;
  107. int result = 1;
  108. result = (prime * result) + _x;
  109. result = (prime * result) + _y;
  110. byte nswe = 0;
  111. if (canGoNorth())
  112. {
  113. nswe |= 1;
  114. }
  115. if (canGoEast())
  116. {
  117. nswe |= 1 << 1;
  118. }
  119. if (canGoSouth())
  120. {
  121. nswe |= 1 << 2;
  122. }
  123. if (canGoEast())
  124. {
  125. nswe |= 1 << 3;
  126. }
  127. result = (prime * result) + (((_geoHeight & 0xFFFF) << 1) | nswe);
  128. return result;
  129. // return super.hashCode();
  130. }
  131. @Override
  132. public boolean equals(Object obj)
  133. {
  134. if (this == obj)
  135. {
  136. return true;
  137. }
  138. if (obj == null)
  139. {
  140. return false;
  141. }
  142. if (!(obj instanceof NodeLoc))
  143. {
  144. return false;
  145. }
  146. final NodeLoc other = (NodeLoc) obj;
  147. if (_x != other._x)
  148. {
  149. return false;
  150. }
  151. if (_y != other._y)
  152. {
  153. return false;
  154. }
  155. if (_goNorth != other._goNorth)
  156. {
  157. return false;
  158. }
  159. if (_goEast != other._goEast)
  160. {
  161. return false;
  162. }
  163. if (_goSouth != other._goSouth)
  164. {
  165. return false;
  166. }
  167. if (_goWest != other._goWest)
  168. {
  169. return false;
  170. }
  171. if (_geoHeight != other._geoHeight)
  172. {
  173. return false;
  174. }
  175. return true;
  176. }
  177. }