L2Radar.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model;
  16. import javolution.util.FastList;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.network.serverpackets.RadarControl;
  19. /**
  20. * @author dalrond
  21. */
  22. public final class L2Radar
  23. {
  24. private L2PcInstance _player;
  25. private FastList<RadarMarker> _markers;
  26. public L2Radar(L2PcInstance player)
  27. {
  28. _player = player;
  29. _markers = new FastList<RadarMarker>();
  30. }
  31. // Add a marker to player's radar
  32. public void addMarker(int x, int y, int z)
  33. {
  34. RadarMarker newMarker = new RadarMarker(x, y, z);
  35. _markers.add(newMarker);
  36. _player.sendPacket(new RadarControl(2, 2, x, y, z));
  37. _player.sendPacket(new RadarControl(0, 1, x, y, z));
  38. }
  39. // Remove a marker from player's radar
  40. public void removeMarker(int x, int y, int z)
  41. {
  42. RadarMarker newMarker = new RadarMarker(x, y, z);
  43. _markers.remove(newMarker);
  44. _player.sendPacket(new RadarControl(1, 1, x, y, z));
  45. }
  46. public void removeAllMarkers()
  47. {
  48. for (RadarMarker tempMarker : _markers)
  49. _player.sendPacket(new RadarControl(2, 2, tempMarker._x, tempMarker._y, tempMarker._z));
  50. _markers.clear();
  51. }
  52. public void loadMarkers()
  53. {
  54. _player.sendPacket(new RadarControl(2, 2, _player.getX(), _player.getY(), _player.getZ()));
  55. for (RadarMarker tempMarker : _markers)
  56. _player.sendPacket(new RadarControl(0, 1, tempMarker._x, tempMarker._y, tempMarker._z));
  57. }
  58. public static class RadarMarker
  59. {
  60. // Simple class to model radar points.
  61. public int _type, _x, _y, _z;
  62. public RadarMarker(int type, int x, int y, int z)
  63. {
  64. _type = type;
  65. _x = x;
  66. _y = y;
  67. _z = z;
  68. }
  69. public RadarMarker(int x, int y, int z)
  70. {
  71. _type = 1;
  72. _x = x;
  73. _y = y;
  74. _z = z;
  75. }
  76. /**
  77. * @see java.lang.Object#hashCode()
  78. */
  79. @Override
  80. public int hashCode()
  81. {
  82. final int prime = 31;
  83. int result = 1;
  84. result = prime * result + _type;
  85. result = prime * result + _x;
  86. result = prime * result + _y;
  87. result = prime * result + _z;
  88. return result;
  89. }
  90. /**
  91. * @see java.lang.Object#equals(java.lang.Object)
  92. */
  93. @Override
  94. public boolean equals(Object obj)
  95. {
  96. if (this == obj)
  97. return true;
  98. if (obj == null)
  99. return false;
  100. if (!(obj instanceof RadarMarker))
  101. return false;
  102. final RadarMarker other = (RadarMarker) obj;
  103. if (_type != other._type)
  104. return false;
  105. if (_x != other._x)
  106. return false;
  107. if (_y != other._y)
  108. return false;
  109. if (_z != other._z)
  110. return false;
  111. return true;
  112. }
  113. }
  114. }