Location.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. _x = x;
  36. _y = y;
  37. _z = z;
  38. _instanceId = -1;
  39. }
  40. public Location(int x, int y, int z, int heading)
  41. {
  42. _x = x;
  43. _y = y;
  44. _z = z;
  45. _heading = heading;
  46. _instanceId = -1;
  47. }
  48. public Location(int x, int y, int z, int heading, int instanceId)
  49. {
  50. _x = x;
  51. _y = y;
  52. _z = z;
  53. _heading = heading;
  54. _instanceId = instanceId;
  55. }
  56. public Location(L2Object obj)
  57. {
  58. _x = obj.getX();
  59. _y = obj.getY();
  60. _z = obj.getZ();
  61. _heading = obj.getHeading();
  62. _instanceId = obj.getInstanceId();
  63. }
  64. /**
  65. * Get the x coordinate.
  66. * @return the x coordinate
  67. */
  68. @Override
  69. public int getX()
  70. {
  71. return _x;
  72. }
  73. /**
  74. * Set the x coordinate.
  75. * @param x the x coordinate
  76. */
  77. public void setX(int x)
  78. {
  79. _x = x;
  80. }
  81. /**
  82. * Get the y coordinate.
  83. * @return the y coordinate
  84. */
  85. @Override
  86. public int getY()
  87. {
  88. return _y;
  89. }
  90. /**
  91. * Set the y coordinate.
  92. * @param y the x coordinate
  93. */
  94. public void setY(int y)
  95. {
  96. _y = y;
  97. }
  98. /**
  99. * Get the z coordinate.
  100. * @return the z coordinate
  101. */
  102. @Override
  103. public int getZ()
  104. {
  105. return _z;
  106. }
  107. /**
  108. * Set the z coordinate.
  109. * @param z the z coordinate
  110. */
  111. public void setZ(int z)
  112. {
  113. _z = z;
  114. }
  115. /**
  116. * Get the heading.
  117. * @return the heading
  118. */
  119. public int getHeading()
  120. {
  121. return _heading;
  122. }
  123. /**
  124. * Set the heading.
  125. * @param heading the heading
  126. */
  127. public void setHeading(int heading)
  128. {
  129. _heading = heading;
  130. }
  131. /**
  132. * Get the instance Id.
  133. * @return the instance Id
  134. */
  135. public int getInstanceId()
  136. {
  137. return _instanceId;
  138. }
  139. /**
  140. * Set the instance Id.
  141. * @param instanceId the instance Id to set
  142. */
  143. public void setInstanceId(int instanceId)
  144. {
  145. _instanceId = instanceId;
  146. }
  147. @Override
  148. public Location getLocation()
  149. {
  150. return this;
  151. }
  152. public void setLocation(Location loc)
  153. {
  154. _x = loc.getX();
  155. _y = loc.getY();
  156. _z = loc.getZ();
  157. _heading = loc.getHeading();
  158. _instanceId = loc.getInstanceId();
  159. }
  160. @Override
  161. public String toString()
  162. {
  163. return "[" + getClass().getSimpleName() + "] X: " + getX() + " Y: " + getY() + " Z: " + getZ() + " Heading: " + _heading + " InstanceId: " + _instanceId;
  164. }
  165. }