AllyLeave.java 2.5 KB

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