RequestJoinSiege.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
  21. import com.l2jserver.gameserver.instancemanager.CastleManager;
  22. import com.l2jserver.gameserver.model.ClanPrivilege;
  23. import com.l2jserver.gameserver.model.L2Clan;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.entity.Castle;
  26. import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.SiegeInfo;
  29. /**
  30. * @author KenM
  31. */
  32. public final class RequestJoinSiege extends L2GameClientPacket
  33. {
  34. private static final String _C__AD_RequestJoinSiege = "[C] AD RequestJoinSiege";
  35. private int _castleId;
  36. private int _isAttacker;
  37. private int _isJoining;
  38. @Override
  39. protected void readImpl()
  40. {
  41. _castleId = readD();
  42. _isAttacker = readD();
  43. _isJoining = readD();
  44. }
  45. @Override
  46. protected void runImpl()
  47. {
  48. L2PcInstance activeChar = getClient().getActiveChar();
  49. if (activeChar == null)
  50. {
  51. return;
  52. }
  53. if (!activeChar.hasClanPrivilege(ClanPrivilege.CS_MANAGE_SIEGE))
  54. {
  55. activeChar.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
  56. return;
  57. }
  58. L2Clan clan = activeChar.getClan();
  59. if (clan == null)
  60. {
  61. return;
  62. }
  63. Castle castle = CastleManager.getInstance().getCastleById(_castleId);
  64. if (castle != null)
  65. {
  66. if (_isJoining == 1)
  67. {
  68. if (System.currentTimeMillis() < clan.getDissolvingExpiryTime())
  69. {
  70. activeChar.sendPacket(SystemMessageId.CANT_PARTICIPATE_IN_SIEGE_WHILE_DISSOLUTION_IN_PROGRESS);
  71. return;
  72. }
  73. if (_isAttacker == 1)
  74. {
  75. castle.getSiege().registerAttacker(activeChar);
  76. }
  77. else
  78. {
  79. castle.getSiege().registerDefender(activeChar);
  80. }
  81. }
  82. else
  83. {
  84. castle.getSiege().removeSiegeClan(activeChar);
  85. }
  86. castle.getSiege().listRegisterClan(activeChar);
  87. }
  88. SiegableHall hall = CHSiegeManager.getInstance().getSiegableHall(_castleId);
  89. if (hall != null)
  90. {
  91. if (_isJoining == 1)
  92. {
  93. if (System.currentTimeMillis() < clan.getDissolvingExpiryTime())
  94. {
  95. activeChar.sendPacket(SystemMessageId.CANT_PARTICIPATE_IN_SIEGE_WHILE_DISSOLUTION_IN_PROGRESS);
  96. return;
  97. }
  98. CHSiegeManager.getInstance().registerClan(clan, hall, activeChar);
  99. }
  100. else
  101. {
  102. CHSiegeManager.getInstance().unRegisterClan(clan, hall);
  103. }
  104. activeChar.sendPacket(new SiegeInfo(hall));
  105. }
  106. }
  107. @Override
  108. public String getType()
  109. {
  110. return _C__AD_RequestJoinSiege;
  111. }
  112. }