AllyLeave.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.changeAllyCrest(0, true);
  64. clan.setAllyPenaltyExpiryTime(currentTime + Config.ALT_ALLY_JOIN_DAYS_WHEN_LEAVED * 86400000L, L2Clan.PENALTY_TYPE_CLAN_LEAVED); //24*60*60*1000 = 86400000
  65. clan.updateClanInDB();
  66. // notify CB server about the change
  67. CommunityServerThread.getInstance().sendPacket(new WorldInfo(null, clan, WorldInfo.TYPE_UPDATE_CLAN_DATA));
  68. player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_WITHDRAWN_FROM_ALLIANCE));
  69. }
  70. @Override
  71. public String getType()
  72. {
  73. return _C__84_ALLYLEAVE;
  74. }
  75. }