AdminFortSiege.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.admincommandhandlers;
  16. import java.util.List;
  17. import java.util.StringTokenizer;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.instancemanager.FortManager;
  20. import com.l2jserver.gameserver.model.L2Clan;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.entity.Fort;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  27. import com.l2jserver.util.StringUtil;
  28. /**
  29. * This class handles all siege commands:
  30. * Todo: change the class name, and neaten it up
  31. *
  32. *
  33. */
  34. public class AdminFortSiege implements IAdminCommandHandler
  35. {
  36. //private static Logger _log = Logger.getLogger(AdminFortSiege.class.getName());
  37. private static final String[] ADMIN_COMMANDS =
  38. {
  39. "admin_fortsiege",
  40. "admin_add_fortattacker",
  41. "admin_list_fortsiege_clans",
  42. "admin_clear_fortsiege_list",
  43. "admin_spawn_fortdoors",
  44. "admin_endfortsiege",
  45. "admin_startfortsiege",
  46. "admin_setfort",
  47. "admin_removefort"
  48. };
  49. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  50. {
  51. StringTokenizer st = new StringTokenizer(command, " ");
  52. command = st.nextToken(); // Get actual command
  53. // Get fort
  54. Fort fort = null;
  55. int fortId = 0;
  56. if (st.hasMoreTokens())
  57. {
  58. fortId = Integer.parseInt(st.nextToken());
  59. fort = FortManager.getInstance().getFortById(fortId);
  60. }
  61. // Get fort
  62. if ((fort == null || fortId == 0))
  63. // No fort specified
  64. showFortSelectPage(activeChar);
  65. else
  66. {
  67. L2Object target = activeChar.getTarget();
  68. L2PcInstance player = null;
  69. if (target instanceof L2PcInstance)
  70. player = (L2PcInstance) target;
  71. if (command.equalsIgnoreCase("admin_add_fortattacker"))
  72. {
  73. if (player == null)
  74. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  75. else
  76. {
  77. if (fort.getSiege().checkIfCanRegister(player))
  78. fort.getSiege().registerAttacker(player, true);
  79. }
  80. }
  81. else if (command.equalsIgnoreCase("admin_clear_fortsiege_list"))
  82. {
  83. fort.getSiege().clearSiegeClan();
  84. }
  85. else if (command.equalsIgnoreCase("admin_endfortsiege"))
  86. {
  87. fort.getSiege().endSiege();
  88. }
  89. else if (command.equalsIgnoreCase("admin_list_fortsiege_clans"))
  90. {
  91. activeChar.sendMessage("Not implemented yet.");
  92. }
  93. else if (command.equalsIgnoreCase("admin_setfort"))
  94. {
  95. if (player == null || player.getClan() == null)
  96. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  97. else
  98. fort.setOwner(player.getClan(), false);
  99. }
  100. else if (command.equalsIgnoreCase("admin_removefort"))
  101. {
  102. L2Clan clan = fort.getOwnerClan();
  103. if (clan != null)
  104. fort.removeOwner(true);
  105. else
  106. activeChar.sendMessage("Unable to remove fort");
  107. }
  108. else if (command.equalsIgnoreCase("admin_spawn_fortdoors"))
  109. {
  110. fort.resetDoors();
  111. }
  112. else if (command.equalsIgnoreCase("admin_startfortsiege"))
  113. {
  114. fort.getSiege().startSiege();
  115. }
  116. showFortSiegePage(activeChar, fort);
  117. }
  118. return true;
  119. }
  120. private void showFortSelectPage(L2PcInstance activeChar)
  121. {
  122. int i = 0;
  123. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  124. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/forts.htm");
  125. final List<Fort> forts = FortManager.getInstance().getForts();
  126. final StringBuilder cList = new StringBuilder(forts.size() * 100);
  127. for (Fort fort : forts) {
  128. if (fort != null) {
  129. StringUtil.append(cList,
  130. "<td fixwidth=90><a action=\"bypass -h admin_fortsiege ",
  131. String.valueOf(fort.getFortId()),
  132. "\">",
  133. fort.getName(),
  134. " id: ",
  135. String.valueOf(fort.getFortId()),
  136. "</a></td>");
  137. i++;
  138. }
  139. if (i > 2) {
  140. cList.append("</tr><tr>");
  141. i = 0;
  142. }
  143. }
  144. adminReply.replace("%forts%", cList.toString());
  145. activeChar.sendPacket(adminReply);
  146. }
  147. private void showFortSiegePage(L2PcInstance activeChar, Fort fort)
  148. {
  149. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  150. adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/fort.htm");
  151. adminReply.replace("%fortName%", fort.getName());
  152. adminReply.replace("%fortId%", String.valueOf(fort.getFortId()));
  153. activeChar.sendPacket(adminReply);
  154. }
  155. public String[] getAdminCommandList()
  156. {
  157. return ADMIN_COMMANDS;
  158. }
  159. }