RequestJoinSiege.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 com.l2jserver.gameserver.network.clientpackets;
  16. import com.l2jserver.gameserver.instancemanager.CastleManager;
  17. import com.l2jserver.gameserver.model.L2Clan;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.entity.Castle;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. /**
  23. *
  24. * @author KenM
  25. */
  26. public final class RequestJoinSiege extends L2GameClientPacket
  27. {
  28. private static final String _C__A4_RequestJoinSiege = "[C] a4 RequestJoinSiege";
  29. //private static Logger _log = Logger.getLogger(RequestJoinSiege.class.getName());
  30. private int _castleId;
  31. private int _isAttacker;
  32. private int _isJoining;
  33. @Override
  34. protected void readImpl()
  35. {
  36. _castleId = readD();
  37. _isAttacker = readD();
  38. _isJoining = readD();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2PcInstance activeChar = getClient().getActiveChar();
  44. if (activeChar == null) return;
  45. if ((activeChar.getClanPrivileges() & L2Clan.CP_CS_MANAGE_SIEGE) != L2Clan.CP_CS_MANAGE_SIEGE)
  46. {
  47. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
  48. return;
  49. }
  50. L2Clan clan = activeChar.getClan();
  51. if (clan == null) return;
  52. Castle castle = CastleManager.getInstance().getCastleById(_castleId);
  53. if (castle == null) return;
  54. if (_isJoining == 1)
  55. {
  56. if (System.currentTimeMillis() < clan.getDissolvingExpiryTime())
  57. {
  58. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_PARTICIPATE_IN_SIEGE_WHILE_DISSOLUTION_IN_PROGRESS));
  59. return;
  60. }
  61. if (_isAttacker == 1)
  62. castle.getSiege().registerAttacker(activeChar);
  63. else
  64. castle.getSiege().registerDefender(activeChar);
  65. }
  66. else
  67. castle.getSiege().removeSiegeClan(activeChar);
  68. castle.getSiege().listRegisterClan(activeChar);
  69. }
  70. @Override
  71. public String getType()
  72. {
  73. return _C__A4_RequestJoinSiege;
  74. }
  75. }