AllyLeave.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.setAllyCrestId(0);
  62. clan.setAllyPenaltyExpiryTime(
  63. currentTime + Config.ALT_ALLY_JOIN_DAYS_WHEN_LEAVED * 86400000L,
  64. L2Clan.PENALTY_TYPE_CLAN_LEAVED); //24*60*60*1000 = 86400000
  65. clan.updateClanInDB();
  66. player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_WITHDRAWN_FROM_ALLIANCE));
  67. }
  68. @Override
  69. public String getType()
  70. {
  71. return _C__84_ALLYLEAVE;
  72. }
  73. }