AllyDismiss.java 3.0 KB

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