Location.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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;
  20. import com.l2jserver.gameserver.model.interfaces.ILocational;
  21. import com.l2jserver.gameserver.model.interfaces.IPositionable;
  22. /**
  23. * Location data transfer object.<br>
  24. * Contains coordinates data, heading and instance Id.
  25. * @author Zoey76
  26. */
  27. public class Location implements IPositionable
  28. {
  29. private int _x;
  30. private int _y;
  31. private int _z;
  32. private int _heading;
  33. private int _instanceId;
  34. public Location(int x, int y, int z)
  35. {
  36. this(x, y, z, 0, -1);
  37. }
  38. public Location(int x, int y, int z, int heading)
  39. {
  40. this(x, y, z, heading, -1);
  41. }
  42. public Location(L2Object obj)
  43. {
  44. this(obj.getX(), obj.getY(), obj.getZ(), obj.getHeading(), obj.getInstanceId());
  45. }
  46. public Location(int x, int y, int z, int heading, int instanceId)
  47. {
  48. _x = x;
  49. _y = y;
  50. _z = z;
  51. _heading = heading;
  52. _instanceId = instanceId;
  53. }
  54. /**
  55. * Get the x coordinate.
  56. * @return the x coordinate
  57. */
  58. @Override
  59. public int getX()
  60. {
  61. return _x;
  62. }
  63. /**
  64. * Set the x coordinate.
  65. * @param x the x coordinate
  66. */
  67. @Override
  68. public void setX(int x)
  69. {
  70. _x = x;
  71. }
  72. /**
  73. * Get the y coordinate.
  74. * @return the y coordinate
  75. */
  76. @Override
  77. public int getY()
  78. {
  79. return _y;
  80. }
  81. /**
  82. * Set the y coordinate.
  83. * @param y the x coordinate
  84. */
  85. @Override
  86. public void setY(int y)
  87. {
  88. _y = y;
  89. }
  90. /**
  91. * Get the z coordinate.
  92. * @return the z coordinate
  93. */
  94. @Override
  95. public int getZ()
  96. {
  97. return _z;
  98. }
  99. /**
  100. * Set the z coordinate.
  101. * @param z the z coordinate
  102. */
  103. @Override
  104. public void setZ(int z)
  105. {
  106. _z = z;
  107. }
  108. /**
  109. * Set the x, y, z coordinates.
  110. * @param x the x coordinate
  111. * @param y the y coordinate
  112. * @param z the z coordinate
  113. */
  114. @Override
  115. public void setXYZ(int x, int y, int z)
  116. {
  117. setX(x);
  118. setY(y);
  119. setZ(z);
  120. }
  121. /**
  122. * Set the x, y, z coordinates.
  123. * @param loc The location.
  124. */
  125. @Override
  126. public void setXYZ(ILocational loc)
  127. {
  128. setXYZ(loc.getX(), loc.getY(), loc.getZ());
  129. }
  130. /**
  131. * Get the heading.
  132. * @return the heading
  133. */
  134. @Override
  135. public int getHeading()
  136. {
  137. return _heading;
  138. }
  139. /**
  140. * Set the heading.
  141. * @param heading the heading
  142. */
  143. @Override
  144. public void setHeading(int heading)
  145. {
  146. _heading = heading;
  147. }
  148. /**
  149. * Get the instance Id.
  150. * @return the instance Id
  151. */
  152. @Override
  153. public int getInstanceId()
  154. {
  155. return _instanceId;
  156. }
  157. /**
  158. * Set the instance Id.
  159. * @param instanceId the instance Id to set
  160. */
  161. @Override
  162. public void setInstanceId(int instanceId)
  163. {
  164. _instanceId = instanceId;
  165. }
  166. @Override
  167. public IPositionable getLocation()
  168. {
  169. return this;
  170. }
  171. @Override
  172. public void setLocation(Location loc)
  173. {
  174. _x = loc.getX();
  175. _y = loc.getY();
  176. _z = loc.getZ();
  177. _heading = loc.getHeading();
  178. _instanceId = loc.getInstanceId();
  179. }
  180. @Override
  181. public boolean equals(Object obj)
  182. {
  183. if ((obj != null) && (obj instanceof Location))
  184. {
  185. final Location loc = (Location) obj;
  186. return (getX() == loc.getX()) && (getY() == loc.getY()) && (getZ() == loc.getZ()) && (getHeading() == loc.getHeading()) && (getInstanceId() == loc.getInstanceId());
  187. }
  188. return false;
  189. }
  190. @Override
  191. public String toString()
  192. {
  193. return "[" + getClass().getSimpleName() + "] X: " + getX() + " Y: " + getY() + " Z: " + getZ() + " Heading: " + _heading + " InstanceId: " + _instanceId;
  194. }
  195. }