AllyDismiss.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.datatables.ClanTable;
  18. import net.sf.l2j.gameserver.model.L2Clan;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  22. public final class AllyDismiss extends L2GameClientPacket
  23. {
  24. private static final String _C__85_ALLYDISMISS = "[C] 85 AllyDismiss";
  25. private String _clanName;
  26. @Override
  27. protected void readImpl()
  28. {
  29. _clanName = readS();
  30. }
  31. @Override
  32. protected void runImpl()
  33. {
  34. if (_clanName == null)
  35. {
  36. return;
  37. }
  38. L2PcInstance player = getClient().getActiveChar();
  39. if (player == null)
  40. {
  41. return;
  42. }
  43. if (player.getClan() == null)
  44. {
  45. player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_A_CLAN_MEMBER));
  46. return;
  47. }
  48. L2Clan leaderClan = player.getClan();
  49. if (leaderClan.getAllyId() == 0)
  50. {
  51. player.sendPacket(new SystemMessage(SystemMessageId.NO_CURRENT_ALLIANCES));
  52. return;
  53. }
  54. if (!player.isClanLeader() || leaderClan.getClanId() != leaderClan.getAllyId())
  55. {
  56. player.sendPacket(new SystemMessage(SystemMessageId.FEATURE_ONLY_FOR_ALLIANCE_LEADER));
  57. return;
  58. }
  59. L2Clan clan = ClanTable.getInstance().getClanByName(_clanName);
  60. if (clan == null)
  61. {
  62. player.sendPacket(new SystemMessage(SystemMessageId.CLAN_DOESNT_EXISTS));
  63. return;
  64. }
  65. if (clan.getClanId() == leaderClan.getClanId())
  66. {
  67. player.sendPacket(new SystemMessage(SystemMessageId.ALLIANCE_LEADER_CANT_WITHDRAW));
  68. return;
  69. }
  70. if (clan.getAllyId() != leaderClan.getAllyId())
  71. {
  72. player.sendPacket(new SystemMessage(SystemMessageId.DIFFERANT_ALLIANCE));
  73. return;
  74. }
  75. long currentTime = System.currentTimeMillis();
  76. leaderClan.setAllyPenaltyExpiryTime(
  77. currentTime + Config.ALT_ACCEPT_CLAN_DAYS_WHEN_DISMISSED * 86400000L,
  78. L2Clan.PENALTY_TYPE_DISMISS_CLAN); //24*60*60*1000 = 86400000
  79. leaderClan.updateClanInDB();
  80. clan.setAllyId(0);
  81. clan.setAllyName(null);
  82. clan.setAllyPenaltyExpiryTime(
  83. currentTime + Config.ALT_ALLY_JOIN_DAYS_WHEN_DISMISSED * 86400000L,
  84. L2Clan.PENALTY_TYPE_CLAN_DISMISSED); //24*60*60*1000 = 86400000
  85. clan.updateClanInDB();
  86. player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EXPELED_A_CLAN));
  87. }
  88. @Override
  89. public String getType()
  90. {
  91. return _C__85_ALLYDISMISS;
  92. }
  93. }