AllyLeave.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.Config;
  21. import com.l2jserver.gameserver.model.L2Clan;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. public final class AllyLeave extends L2GameClientPacket
  25. {
  26. private static final String _C__8E_ALLYLEAVE = "[C] 8E AllyLeave";
  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(SystemMessageId.YOU_ARE_NOT_A_CLAN_MEMBER);
  42. return;
  43. }
  44. if (!player.isClanLeader())
  45. {
  46. player.sendPacket(SystemMessageId.ONLY_CLAN_LEADER_WITHDRAW_ALLY);
  47. return;
  48. }
  49. L2Clan clan = player.getClan();
  50. if (clan.getAllyId() == 0)
  51. {
  52. player.sendPacket(SystemMessageId.NO_CURRENT_ALLIANCES);
  53. return;
  54. }
  55. if (clan.getId() == clan.getAllyId())
  56. {
  57. player.sendPacket(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. player.sendPacket(SystemMessageId.YOU_HAVE_WITHDRAWN_FROM_ALLIANCE);
  67. }
  68. @Override
  69. public String getType()
  70. {
  71. return _C__8E_ALLYLEAVE;
  72. }
  73. }