CastleVCmd.java 3.8 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 handlers.voicedcommandhandlers;
  16. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  17. import com.l2jserver.gameserver.instancemanager.CastleManager;
  18. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.entity.Castle;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. /**
  23. * @author Zoey76
  24. */
  25. public class CastleVCmd implements IVoicedCommandHandler
  26. {
  27. private static final String[] VOICED_COMMANDS =
  28. {
  29. "opendoors",
  30. "closedoors",
  31. "ridewyvern"
  32. };
  33. @Override
  34. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
  35. {
  36. switch (command)
  37. {
  38. case "opendoors":
  39. if (!params.equals("castle"))
  40. {
  41. activeChar.sendMessage("Only Castle doors can be open.");
  42. return false;
  43. }
  44. if (!activeChar.isClanLeader())
  45. {
  46. activeChar.sendPacket(SystemMessageId.ONLY_CLAN_LEADER_CAN_ISSUE_COMMANDS);
  47. return false;
  48. }
  49. final L2DoorInstance door = (L2DoorInstance) activeChar.getTarget();
  50. if (door == null)
  51. {
  52. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  53. return false;
  54. }
  55. final Castle castle = CastleManager.getInstance().getCastleById(activeChar.getClan().getCastleId());
  56. if (castle == null)
  57. {
  58. activeChar.sendMessage("Your clan does not own a castle.");
  59. return false;
  60. }
  61. if (castle.getSiege().getIsInProgress())
  62. {
  63. activeChar.sendPacket(SystemMessageId.GATES_NOT_OPENED_CLOSED_DURING_SIEGE);
  64. return false;
  65. }
  66. if (castle.checkIfInZone(door.getX(), door.getY(), door.getZ()))
  67. {
  68. activeChar.sendPacket(SystemMessageId.GATE_IS_OPENING);
  69. door.openMe();
  70. }
  71. break;
  72. case "closedoors":
  73. if (!params.equals("castle"))
  74. {
  75. activeChar.sendMessage("Only Castle doors can be closed.");
  76. return false;
  77. }
  78. if (!activeChar.isClanLeader())
  79. {
  80. activeChar.sendPacket(SystemMessageId.ONLY_CLAN_LEADER_CAN_ISSUE_COMMANDS);
  81. return false;
  82. }
  83. final L2DoorInstance door2 = (L2DoorInstance) activeChar.getTarget();
  84. if (door2 == null)
  85. {
  86. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  87. return false;
  88. }
  89. final Castle castle2 = CastleManager.getInstance().getCastleById(activeChar.getClan().getCastleId());
  90. if (castle2 == null)
  91. {
  92. activeChar.sendMessage("Your clan does not own a castle.");
  93. return false;
  94. }
  95. if (castle2.getSiege().getIsInProgress())
  96. {
  97. activeChar.sendPacket(SystemMessageId.GATES_NOT_OPENED_CLOSED_DURING_SIEGE);
  98. return false;
  99. }
  100. if (castle2.checkIfInZone(door2.getX(), door2.getY(), door2.getZ()))
  101. {
  102. activeChar.sendMessage("The gate is being closed.");
  103. door2.closeMe();
  104. }
  105. break;
  106. case "ridewyvern":
  107. if (activeChar.isClanLeader() && (activeChar.getClan().getCastleId() > 0))
  108. {
  109. activeChar.mount(12621, 0, true);
  110. }
  111. break;
  112. }
  113. return true;
  114. }
  115. @Override
  116. public String[] getVoicedCommandList()
  117. {
  118. return VOICED_COMMANDS;
  119. }
  120. }