Observation.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2004-2013 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.StringTokenizer;
  21. import java.util.logging.Level;
  22. import com.l2jserver.gameserver.handler.IBypassHandler;
  23. import com.l2jserver.gameserver.instancemanager.SiegeManager;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  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. @Override
  40. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  41. {
  42. if (!target.isNpc())
  43. {
  44. return false;
  45. }
  46. try
  47. {
  48. if (command.toLowerCase().startsWith(COMMANDS[0])) // siege
  49. {
  50. String val = command.substring(13);
  51. StringTokenizer st = new StringTokenizer(val);
  52. st.nextToken(); // Bypass cost
  53. if (SiegeManager.getInstance().getSiege(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())) != null)
  54. {
  55. doObserve(activeChar, (L2Npc) target, val);
  56. }
  57. else
  58. {
  59. activeChar.sendPacket(SystemMessageId.ONLY_VIEW_SIEGE);
  60. }
  61. return true;
  62. }
  63. else if (command.toLowerCase().startsWith(COMMANDS[1])) // oracle
  64. {
  65. String val = command.substring(13);
  66. StringTokenizer st = new StringTokenizer(val);
  67. st.nextToken(); // Bypass cost
  68. doObserve(activeChar, (L2Npc) target, val);
  69. return true;
  70. }
  71. else if (command.toLowerCase().startsWith(COMMANDS[2])) // observe
  72. {
  73. doObserve(activeChar, (L2Npc) target, command.substring(8));
  74. return true;
  75. }
  76. return false;
  77. }
  78. catch (Exception e)
  79. {
  80. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  81. }
  82. return false;
  83. }
  84. private static final void doObserve(L2PcInstance player, L2Npc npc, String val)
  85. {
  86. StringTokenizer st = new StringTokenizer(val);
  87. long cost = Long.parseLong(st.nextToken());
  88. int x = Integer.parseInt(st.nextToken());
  89. int y = Integer.parseInt(st.nextToken());
  90. int z = Integer.parseInt(st.nextToken());
  91. if (player.reduceAdena("Broadcast", cost, npc, true))
  92. {
  93. // enter mode
  94. player.enterObserverMode(new Location(x, y, z));
  95. player.sendPacket(new ItemList(player, false));
  96. }
  97. player.sendPacket(ActionFailed.STATIC_PACKET);
  98. }
  99. @Override
  100. public String[] getBypassList()
  101. {
  102. return COMMANDS;
  103. }
  104. }