AllyLeave.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.Config;
  17. import com.l2jserver.gameserver.model.L2Clan;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.SystemMessageId;
  20. import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
  21. import com.l2jserver.gameserver.network.communityserver.writepackets.WorldInfo;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. public final class AllyLeave extends L2GameClientPacket
  24. {
  25. private static final String _C__84_ALLYLEAVE = "[C] 84 AllyLeave";
  26. //private static Logger _log = Logger.getLogger(AllyLeave.class.getName());
  27. @Override
  28. protected void readImpl()
  29. {
  30. }
  31. @Override
  32. protected void runImpl()
  33. {
  34. L2PcInstance player = getClient().getActiveChar();
  35. if (player == null)
  36. {
  37. return;
  38. }
  39. if (player.getClan() == null)
  40. {
  41. player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_A_CLAN_MEMBER));
  42. return;
  43. }
  44. if (!player.isClanLeader())
  45. {
  46. player.sendPacket(new SystemMessage(SystemMessageId.ONLY_CLAN_LEADER_WITHDRAW_ALLY));
  47. return;
  48. }
  49. L2Clan clan = player.getClan();
  50. if (clan.getAllyId() == 0)
  51. {
  52. player.sendPacket(new SystemMessage(SystemMessageId.NO_CURRENT_ALLIANCES));
  53. return;
  54. }
  55. if (clan.getClanId() == clan.getAllyId())
  56. {
  57. player.sendPacket(new SystemMessage(SystemMessageId.ALLIANCE_LEADER_CANT_WITHDRAW));
  58. return;
  59. }
  60. long currentTime = System.currentTimeMillis();
  61. clan.setAllyId(0);
  62. clan.setAllyName(null);
  63. clan.setAllyCrestId(0);
  64. clan.setAllyPenaltyExpiryTime(
  65. currentTime + Config.ALT_ALLY_JOIN_DAYS_WHEN_LEAVED * 86400000L,
  66. L2Clan.PENALTY_TYPE_CLAN_LEAVED); //24*60*60*1000 = 86400000
  67. clan.updateClanInDB();
  68. // notify CB server about the change
  69. CommunityServerThread.getInstance().sendPacket(new WorldInfo(null, clan, WorldInfo.TYPE_UPDATE_CLAN_DATA));
  70. player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_WITHDRAWN_FROM_ALLIANCE));
  71. }
  72. @Override
  73. public String getType()
  74. {
  75. return _C__84_ALLYLEAVE;
  76. }
  77. }