RequestExAskJoinMPCC.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.gameserver.model.L2Party;
  21. import com.l2jserver.gameserver.model.L2World;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.ExAskJoinMPCC;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * Format: (ch) S<br>
  28. * D0 0D 00 5A 00 77 00 65 00 72 00 67 00 00 00
  29. * @author chris_00
  30. */
  31. public final class RequestExAskJoinMPCC extends L2GameClientPacket
  32. {
  33. private static final String _C__D0_06_REQUESTEXASKJOINMPCC = "[C] D0:06 RequestExAskJoinMPCC";
  34. private String _name;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _name = readS();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. final L2PcInstance activeChar = getClient().getActiveChar();
  44. if (activeChar == null)
  45. {
  46. return;
  47. }
  48. final L2PcInstance player = L2World.getInstance().getPlayer(_name);
  49. if (player == null)
  50. {
  51. return;
  52. }
  53. // invite yourself? ;)
  54. if (activeChar.isInParty() && player.isInParty() && activeChar.getParty().equals(player.getParty()))
  55. {
  56. return;
  57. }
  58. SystemMessage sm;
  59. // activeChar is in a Party?
  60. if (activeChar.isInParty())
  61. {
  62. L2Party activeParty = activeChar.getParty();
  63. // activeChar is PartyLeader? && activeChars Party is already in a CommandChannel?
  64. if (activeParty.getLeader().equals(activeChar))
  65. {
  66. // if activeChars Party is in CC, is activeChar CCLeader?
  67. if (activeParty.isInCommandChannel() && activeParty.getCommandChannel().getLeader().equals(activeChar))
  68. {
  69. // in CC and the CCLeader
  70. // target in a party?
  71. if (player.isInParty())
  72. {
  73. // targets party already in a CChannel?
  74. if (player.getParty().isInCommandChannel())
  75. {
  76. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ALREADY_MEMBER_OF_COMMAND_CHANNEL);
  77. sm.addString(player.getName());
  78. activeChar.sendPacket(sm);
  79. }
  80. else
  81. {
  82. // ready to open a new CC
  83. // send request to targets Party's PartyLeader
  84. askJoinMPCC(activeChar, player);
  85. }
  86. }
  87. else
  88. {
  89. activeChar.sendMessage(player.getName() + " doesn't have party and cannot be invited to Command Channel.");
  90. }
  91. }
  92. else if (activeParty.isInCommandChannel() && !activeParty.getCommandChannel().getLeader().equals(activeChar))
  93. {
  94. // in CC, but not the CCLeader
  95. sm = SystemMessage.getSystemMessage(SystemMessageId.CANNOT_INVITE_TO_COMMAND_CHANNEL);
  96. activeChar.sendPacket(sm);
  97. }
  98. else
  99. {
  100. // target in a party?
  101. if (player.isInParty())
  102. {
  103. // targets party already in a CChannel?
  104. if (player.getParty().isInCommandChannel())
  105. {
  106. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ALREADY_MEMBER_OF_COMMAND_CHANNEL);
  107. sm.addString(player.getName());
  108. activeChar.sendPacket(sm);
  109. }
  110. else
  111. {
  112. // ready to open a new CC
  113. // send request to targets Party's PartyLeader
  114. askJoinMPCC(activeChar, player);
  115. }
  116. }
  117. else
  118. {
  119. activeChar.sendMessage(player.getName() + " doesn't have party and cannot be invited to Command Channel.");
  120. }
  121. }
  122. }
  123. else
  124. {
  125. activeChar.sendPacket(SystemMessageId.CANNOT_INVITE_TO_COMMAND_CHANNEL);
  126. }
  127. }
  128. }
  129. private void askJoinMPCC(L2PcInstance requestor, L2PcInstance target)
  130. {
  131. boolean hasRight = false;
  132. if (requestor.isClanLeader() && (requestor.getClan().getLevel() >= 5))
  133. {
  134. // Clan leader of lvl5 Clan or higher.
  135. hasRight = true;
  136. }
  137. else if (requestor.getInventory().getItemByItemId(8871) != null)
  138. {
  139. // 8871 Strategy Guide.
  140. // TODO: Should destroyed after successful invite?
  141. hasRight = true;
  142. }
  143. else if ((requestor.getPledgeClass() >= 5) && (requestor.getKnownSkill(391) != null))
  144. {
  145. // At least Baron or higher and the skill Clan Imperium
  146. hasRight = true;
  147. }
  148. if (!hasRight)
  149. {
  150. requestor.sendPacket(SystemMessageId.COMMAND_CHANNEL_ONLY_BY_LEVEL_5_CLAN_LEADER_PARTY_LEADER);
  151. return;
  152. }
  153. // Get the target's party leader, and do whole actions on him.
  154. final L2PcInstance targetLeader = target.getParty().getLeader();
  155. SystemMessage sm;
  156. if (!targetLeader.isProcessingRequest())
  157. {
  158. requestor.onTransactionRequest(targetLeader);
  159. sm = SystemMessage.getSystemMessage(SystemMessageId.COMMAND_CHANNEL_CONFIRM_FROM_C1);
  160. sm.addString(requestor.getName());
  161. targetLeader.sendPacket(sm);
  162. targetLeader.sendPacket(new ExAskJoinMPCC(requestor.getName()));
  163. requestor.sendMessage("You invited " + targetLeader.getName() + " to your Command Channel.");
  164. }
  165. else
  166. {
  167. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER);
  168. sm.addString(targetLeader.getName());
  169. requestor.sendPacket(sm);
  170. }
  171. }
  172. @Override
  173. public String getType()
  174. {
  175. return _C__D0_06_REQUESTEXASKJOINMPCC;
  176. }
  177. }