SiegeStatus.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.usercommandhandlers;
  20. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  21. import com.l2jserver.gameserver.instancemanager.SiegeManager;
  22. import com.l2jserver.gameserver.model.L2Clan;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.entity.Siege;
  25. import com.l2jserver.gameserver.model.zone.type.L2SiegeZone;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  28. /**
  29. * @author Tryskell
  30. */
  31. public class SiegeStatus implements IUserCommandHandler
  32. {
  33. private static final int[] COMMAND_IDS =
  34. {
  35. 99
  36. };
  37. private static final String INSIDE_SIEGE_ZONE = "Castle Siege in Progress";
  38. private static final String OUTSIDE_SIEGE_ZONE = "No Castle Siege Area";
  39. @Override
  40. public boolean useUserCommand(int id, L2PcInstance activeChar)
  41. {
  42. if (id != COMMAND_IDS[0])
  43. {
  44. return false;
  45. }
  46. if (!activeChar.isNoble() || !activeChar.isClanLeader())
  47. {
  48. activeChar.sendPacket(SystemMessageId.ONLY_NOBLESSE_LEADER_CAN_VIEW_SIEGE_STATUS_WINDOW);
  49. return false;
  50. }
  51. for (Siege siege : SiegeManager.getInstance().getSieges())
  52. {
  53. if (!siege.isInProgress())
  54. {
  55. continue;
  56. }
  57. final L2Clan clan = activeChar.getClan();
  58. if (!siege.checkIsAttacker(clan) && !siege.checkIsDefender(clan))
  59. {
  60. continue;
  61. }
  62. final L2SiegeZone siegeZone = siege.getCastle().getZone();
  63. final StringBuilder sb = new StringBuilder();
  64. for (L2PcInstance member : clan.getOnlineMembers(0))
  65. {
  66. sb.append("<tr><td width=170>");
  67. sb.append(member.getName());
  68. sb.append("</td><td width=100>");
  69. sb.append(siegeZone.isInsideZone(member) ? INSIDE_SIEGE_ZONE : OUTSIDE_SIEGE_ZONE);
  70. sb.append("</td></tr>");
  71. }
  72. final NpcHtmlMessage html = new NpcHtmlMessage();
  73. html.setFile(activeChar.getHtmlPrefix(), "data/html/siege/siege_status.htm");
  74. html.replace("%kill_count%", clan.getSiegeKills());
  75. html.replace("%death_count%", clan.getSiegeDeaths());
  76. html.replace("%member_list%", sb.toString());
  77. activeChar.sendPacket(html);
  78. return true;
  79. }
  80. activeChar.sendPacket(SystemMessageId.ONLY_NOBLESSE_LEADER_CAN_VIEW_SIEGE_STATUS_WINDOW);
  81. return false;
  82. }
  83. @Override
  84. public int[] getUserCommandList()
  85. {
  86. return COMMAND_IDS;
  87. }
  88. }