Point3D.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.util;
  20. import java.util.concurrent.atomic.AtomicInteger;
  21. import com.l2jserver.gameserver.model.Location;
  22. import com.l2jserver.gameserver.model.interfaces.IPositionable;
  23. /**
  24. * @author Unknown, UnAfraid
  25. */
  26. public class Point3D implements IPositionable
  27. {
  28. private final AtomicInteger _x = new AtomicInteger();
  29. private final AtomicInteger _y = new AtomicInteger();
  30. private final AtomicInteger _z = new AtomicInteger();
  31. private final AtomicInteger _heading = new AtomicInteger();
  32. private final AtomicInteger _instanceId = new AtomicInteger();
  33. public Point3D(int x, int y, int z)
  34. {
  35. _x.set(x);
  36. _y.set(y);
  37. _z.set(z);
  38. }
  39. public Point3D(int x, int y, int z, int heading)
  40. {
  41. _x.set(x);
  42. _y.set(y);
  43. _z.set(z);
  44. _heading.set(heading);
  45. }
  46. public Point3D(int x, int y, int z, int heading, int instanceId)
  47. {
  48. _x.set(x);
  49. _y.set(y);
  50. _z.set(z);
  51. _heading.set(heading);
  52. _instanceId.set(instanceId);
  53. }
  54. public boolean equals(int x, int y, int z)
  55. {
  56. return (getX() == x) && (getY() == y) && (getZ() == z);
  57. }
  58. @Override
  59. public int getX()
  60. {
  61. return _x.get();
  62. }
  63. @Override
  64. public int getY()
  65. {
  66. return _y.get();
  67. }
  68. @Override
  69. public int getZ()
  70. {
  71. return _z.get();
  72. }
  73. @Override
  74. public int getHeading()
  75. {
  76. return _heading.get();
  77. }
  78. @Override
  79. public int getInstanceId()
  80. {
  81. return _instanceId.get();
  82. }
  83. @Override
  84. public Location getLocation()
  85. {
  86. return new Location(getX(), getY(), getZ(), getHeading(), getInstanceId());
  87. }
  88. @Override
  89. public void setX(int x)
  90. {
  91. _x.set(x);
  92. }
  93. @Override
  94. public void setY(int y)
  95. {
  96. _y.set(y);
  97. }
  98. @Override
  99. public void setZ(int z)
  100. {
  101. _z.set(z);
  102. }
  103. @Override
  104. public void setHeading(int heading)
  105. {
  106. _heading.set(heading);
  107. }
  108. @Override
  109. public void setInstanceId(int instanceId)
  110. {
  111. _instanceId.set(instanceId);
  112. }
  113. @Override
  114. public void setLocation(Location loc)
  115. {
  116. _x.set(loc.getX());
  117. _y.set(loc.getY());
  118. _z.set(loc.getZ());
  119. _heading.set(loc.getHeading());
  120. _instanceId.set(loc.getInstanceId());
  121. }
  122. public void setXYZ(int x, int y, int z)
  123. {
  124. _x.set(x);
  125. _y.set(y);
  126. _z.set(z);
  127. }
  128. public final Point3D getWorldPosition()
  129. {
  130. return this;
  131. }
  132. @Override
  133. public boolean equals(Object o)
  134. {
  135. if (this == o)
  136. {
  137. return true;
  138. }
  139. if (o instanceof Point3D)
  140. {
  141. final Point3D point3D = (Point3D) o;
  142. return (point3D.getX() == getX()) && (point3D.getY() == getY()) && ((point3D.getZ() == getZ()) && (point3D.getHeading() == getHeading()) && (point3D.getInstanceId() == getInstanceId()));
  143. }
  144. return false;
  145. }
  146. @Override
  147. public int hashCode()
  148. {
  149. return getX() ^ getY() ^ getZ();
  150. }
  151. @Override
  152. public String toString()
  153. {
  154. return "(" + _x + ", " + _y + ", " + _z + ")";
  155. }
  156. }