L2Radar.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 net.sf.l2j.gameserver.model;
  16. import java.util.Vector;
  17. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  18. import net.sf.l2j.gameserver.serverpackets.RadarControl;
  19. /**
  20. * @author dalrond
  21. */
  22. public final class L2Radar
  23. {
  24. private L2PcInstance _player;
  25. private Vector<RadarMarker> _markers;
  26. public L2Radar(L2PcInstance player)
  27. {
  28. _player = player;
  29. _markers = new Vector<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(2, 2, x, y, z));
  45. }
  46. public void removeAllMarkers()
  47. {
  48. // TODO: Need method to remove all markers from radar at once
  49. for (RadarMarker tempMarker : _markers)
  50. _player.sendPacket(new RadarControl(1, tempMarker._type, tempMarker._x, tempMarker._y, tempMarker._z));
  51. _markers.removeAllElements();
  52. }
  53. public void loadMarkers()
  54. {
  55. // TODO: Need method to re-send radar markers after load/teleport/death
  56. // etc.
  57. }
  58. public 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. @Override
  77. public boolean equals(Object obj)
  78. {
  79. try
  80. {
  81. RadarMarker temp = (RadarMarker) obj;
  82. if ((temp._x == _x) && (temp._y == _y)
  83. && (temp._z == _z) && (temp._type == _type))
  84. return true;
  85. return false;
  86. }
  87. catch (Exception e)
  88. {
  89. return false;
  90. }
  91. }
  92. }
  93. }