NodeLoc.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.pathfinding.cellnodes;
  20. import com.l2jserver.gameserver.GeoData;
  21. import com.l2jserver.gameserver.model.L2World;
  22. import com.l2jserver.gameserver.pathfinding.AbstractNodeLoc;
  23. /**
  24. * @author -Nemesiss-
  25. */
  26. public class NodeLoc extends AbstractNodeLoc
  27. {
  28. private int _x;
  29. private int _y;
  30. private short _geoHeightAndNSWE;
  31. public NodeLoc(int x, int y, short z)
  32. {
  33. _x = x;
  34. _y = y;
  35. _geoHeightAndNSWE = GeoData.getInstance().getHeightAndNSWE(x, y, z);
  36. }
  37. public void set(int x, int y, short z)
  38. {
  39. _x = x;
  40. _y = y;
  41. _geoHeightAndNSWE = GeoData.getInstance().getHeightAndNSWE(x, y, z);
  42. }
  43. public short getNSWE()
  44. {
  45. return (short) (_geoHeightAndNSWE & 0x0f);
  46. }
  47. @Override
  48. public int getX()
  49. {
  50. return (_x << 4) + L2World.MAP_MIN_X;
  51. }
  52. @Override
  53. public int getY()
  54. {
  55. return (_y << 4) + L2World.MAP_MIN_Y;
  56. }
  57. @Override
  58. public short getZ()
  59. {
  60. short height = (short) (_geoHeightAndNSWE & 0x0fff0);
  61. return (short) (height >> 1);
  62. }
  63. @Override
  64. public void setZ(short z)
  65. {
  66. //
  67. }
  68. @Override
  69. public int getNodeX()
  70. {
  71. return _x;
  72. }
  73. @Override
  74. public int getNodeY()
  75. {
  76. return _y;
  77. }
  78. @Override
  79. public int hashCode()
  80. {
  81. final int prime = 31;
  82. int result = 1;
  83. result = (prime * result) + _x;
  84. result = (prime * result) + _y;
  85. result = (prime * result) + _geoHeightAndNSWE;
  86. return result;
  87. }
  88. @Override
  89. public boolean equals(Object obj)
  90. {
  91. if (this == obj)
  92. {
  93. return true;
  94. }
  95. if (obj == null)
  96. {
  97. return false;
  98. }
  99. if (!(obj instanceof NodeLoc))
  100. {
  101. return false;
  102. }
  103. final NodeLoc other = (NodeLoc) obj;
  104. if (_x != other._x)
  105. {
  106. return false;
  107. }
  108. if (_y != other._y)
  109. {
  110. return false;
  111. }
  112. if (_geoHeightAndNSWE != other._geoHeightAndNSWE)
  113. {
  114. return false;
  115. }
  116. return true;
  117. }
  118. }