Observation.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.bypasshandlers;
  20. import java.util.logging.Level;
  21. import com.l2jserver.gameserver.handler.IBypassHandler;
  22. import com.l2jserver.gameserver.instancemanager.SiegeManager;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2ObservationInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  30. import com.l2jserver.gameserver.network.serverpackets.ItemList;
  31. public class Observation implements IBypassHandler
  32. {
  33. private static final String[] COMMANDS =
  34. {
  35. "observesiege",
  36. "observeoracle",
  37. "observe"
  38. };
  39. private static final int[][] LOCATIONS = new int[][]
  40. {
  41. //@formatter:off
  42. // Gludio
  43. {-18347, 114000, -2360, 500},
  44. {-18347, 113255, -2447, 500},
  45. // Dion
  46. {22321, 155785, -2604, 500},
  47. {22321, 156492, -2627, 500},
  48. // Giran
  49. {112000, 144864, -2445, 500},
  50. {112657, 144864, -2525, 500},
  51. // Innadril
  52. {116260, 244600, -775, 500},
  53. {116260, 245264, -721, 500},
  54. // Oren
  55. {78100, 36950, -2242, 500},
  56. {78744, 36950, -2244, 500},
  57. // Aden
  58. {147457, 9601, -233, 500},
  59. {147457, 8720, -252, 500},
  60. // Goddard
  61. {147542, -43543, -1328, 500},
  62. {147465, -45259, -1328, 500},
  63. // Rune
  64. {20598, -49113, -300, 500},
  65. {18702, -49150, -600, 500},
  66. // Schuttgart
  67. {77541, -147447, 353, 500},
  68. {77541, -149245, 353, 500},
  69. // Coliseum
  70. {148416, 46724, -3000, 80},
  71. {149500, 46724, -3000, 80},
  72. {150511, 46724, -3000, 80},
  73. // Dusk
  74. {-77200, 88500, -4800, 500},
  75. {-75320, 87135, -4800, 500},
  76. {-76840, 85770, -4800, 500},
  77. {-76840, 85770, -4800, 500},
  78. {-79950, 85165, -4800, 500},
  79. // Dawn
  80. {-79185, 112725, -4300, 500},
  81. {-76175, 113330, -4300, 500},
  82. {-74305, 111965, -4300, 500},
  83. {-75915, 110600, -4300, 500},
  84. {-78930, 110005, -4300, 500}
  85. //@formatter:on
  86. };
  87. @Override
  88. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  89. {
  90. if (!(target instanceof L2ObservationInstance))
  91. {
  92. return false;
  93. }
  94. if (activeChar.hasSummon())
  95. {
  96. activeChar.sendPacket(SystemMessageId.NO_OBSERVE_WITH_PET);
  97. return false;
  98. }
  99. if (activeChar.isOnEvent())
  100. {
  101. activeChar.sendMessage("Cannot use while current Event");
  102. return false;
  103. }
  104. String _command = command.split(" ")[0].toLowerCase();
  105. final int param;
  106. try
  107. {
  108. param = Integer.parseInt(command.split(" ")[1]);
  109. }
  110. catch (NumberFormatException nfe)
  111. {
  112. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), nfe);
  113. return false;
  114. }
  115. if ((param < 0) || (param > (LOCATIONS.length - 1)))
  116. {
  117. return false;
  118. }
  119. final int[] locCost = LOCATIONS[param];
  120. Location loc = new Location(locCost[0], locCost[1], locCost[2]);
  121. final long cost = locCost[3];
  122. switch (_command)
  123. {
  124. case "observesiege":
  125. {
  126. if (SiegeManager.getInstance().getSiege(loc) != null)
  127. {
  128. doObserve(activeChar, (L2Npc) target, loc, cost);
  129. }
  130. else
  131. {
  132. activeChar.sendPacket(SystemMessageId.ONLY_VIEW_SIEGE);
  133. }
  134. return true;
  135. }
  136. case "observeoracle": // Oracle Dusk/Dawn
  137. {
  138. doObserve(activeChar, (L2Npc) target, loc, cost);
  139. return true;
  140. }
  141. case "observe": // Observe
  142. {
  143. doObserve(activeChar, (L2Npc) target, loc, cost);
  144. return true;
  145. }
  146. }
  147. return false;
  148. }
  149. private static final void doObserve(final L2PcInstance player, final L2Npc npc, final Location pos, final long cost)
  150. {
  151. if (player.reduceAdena("Broadcast", cost, npc, true))
  152. {
  153. // enter mode
  154. player.enterObserverMode(pos);
  155. player.sendPacket(new ItemList(player, false));
  156. }
  157. player.sendPacket(ActionFailed.STATIC_PACKET);
  158. }
  159. @Override
  160. public String[] getBypassList()
  161. {
  162. return COMMANDS;
  163. }
  164. }