Location.java 3.9 KB

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