L2Radar.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2004-2015 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 java.util.List;
  21. import java.util.concurrent.CopyOnWriteArrayList;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.serverpackets.RadarControl;
  24. /**
  25. * @author dalrond
  26. */
  27. public final class L2Radar
  28. {
  29. private final L2PcInstance _player;
  30. private final List<RadarMarker> _markers = new CopyOnWriteArrayList<>();
  31. public L2Radar(L2PcInstance player)
  32. {
  33. _player = player;
  34. }
  35. // Add a marker to player's radar
  36. public void addMarker(int x, int y, int z)
  37. {
  38. RadarMarker newMarker = new RadarMarker(x, y, z);
  39. _markers.add(newMarker);
  40. _player.sendPacket(new RadarControl(2, 2, x, y, z));
  41. _player.sendPacket(new RadarControl(0, 1, x, y, z));
  42. }
  43. // Remove a marker from player's radar
  44. public void removeMarker(int x, int y, int z)
  45. {
  46. RadarMarker newMarker = new RadarMarker(x, y, z);
  47. _markers.remove(newMarker);
  48. _player.sendPacket(new RadarControl(1, 1, x, y, z));
  49. }
  50. public void removeAllMarkers()
  51. {
  52. for (RadarMarker tempMarker : _markers)
  53. {
  54. _player.sendPacket(new RadarControl(2, 2, tempMarker._x, tempMarker._y, tempMarker._z));
  55. }
  56. _markers.clear();
  57. }
  58. public void loadMarkers()
  59. {
  60. _player.sendPacket(new RadarControl(2, 2, _player.getX(), _player.getY(), _player.getZ()));
  61. for (RadarMarker tempMarker : _markers)
  62. {
  63. _player.sendPacket(new RadarControl(0, 1, tempMarker._x, tempMarker._y, tempMarker._z));
  64. }
  65. }
  66. public static class RadarMarker
  67. {
  68. // Simple class to model radar points.
  69. public int _type, _x, _y, _z;
  70. public RadarMarker(int type, int x, int y, int z)
  71. {
  72. _type = type;
  73. _x = x;
  74. _y = y;
  75. _z = z;
  76. }
  77. public RadarMarker(int x, int y, int z)
  78. {
  79. _type = 1;
  80. _x = x;
  81. _y = y;
  82. _z = z;
  83. }
  84. @Override
  85. public int hashCode()
  86. {
  87. final int prime = 31;
  88. int result = 1;
  89. result = (prime * result) + _type;
  90. result = (prime * result) + _x;
  91. result = (prime * result) + _y;
  92. result = (prime * result) + _z;
  93. return result;
  94. }
  95. @Override
  96. public boolean equals(Object obj)
  97. {
  98. if (this == obj)
  99. {
  100. return true;
  101. }
  102. if (!(obj instanceof RadarMarker))
  103. {
  104. return false;
  105. }
  106. final RadarMarker other = (RadarMarker) obj;
  107. if ((_type != other._type) || (_x != other._x) || (_y != other._y) || (_z != other._z))
  108. {
  109. return false;
  110. }
  111. return true;
  112. }
  113. }
  114. }