Location.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. public void setX(int x)
  67. {
  68. _x = x;
  69. }
  70. /**
  71. * Get the y coordinate.
  72. * @return the y coordinate
  73. */
  74. @Override
  75. public int getY()
  76. {
  77. return _y;
  78. }
  79. /**
  80. * Set the y coordinate.
  81. * @param y the x coordinate
  82. */
  83. public void setY(int y)
  84. {
  85. _y = y;
  86. }
  87. /**
  88. * Get the z coordinate.
  89. * @return the z coordinate
  90. */
  91. @Override
  92. public int getZ()
  93. {
  94. return _z;
  95. }
  96. /**
  97. * Set the z coordinate.
  98. * @param z the z coordinate
  99. */
  100. public void setZ(int z)
  101. {
  102. _z = z;
  103. }
  104. /**
  105. * Get the heading.
  106. * @return the heading
  107. */
  108. public int getHeading()
  109. {
  110. return _heading;
  111. }
  112. /**
  113. * Set the heading.
  114. * @param heading the heading
  115. */
  116. public void setHeading(int heading)
  117. {
  118. _heading = heading;
  119. }
  120. /**
  121. * Get the instance Id.
  122. * @return the instance Id
  123. */
  124. public int getInstanceId()
  125. {
  126. return _instanceId;
  127. }
  128. /**
  129. * Set the instance Id.
  130. * @param instanceId the instance Id to set
  131. */
  132. public void setInstanceId(int instanceId)
  133. {
  134. _instanceId = instanceId;
  135. }
  136. @Override
  137. public Location getLocation()
  138. {
  139. return this;
  140. }
  141. public void setLocation(Location loc)
  142. {
  143. _x = loc.getX();
  144. _y = loc.getY();
  145. _z = loc.getZ();
  146. _heading = loc.getHeading();
  147. _instanceId = loc.getInstanceId();
  148. }
  149. @Override
  150. public String toString()
  151. {
  152. return "[" + getClass().getSimpleName() + "] X: " + getX() + " Y: " + getY() + " Z: " + getZ() + " Heading: " + _heading + " InstanceId: " + _instanceId;
  153. }
  154. }