RequestExAskJoinMPCC.java 5.7 KB

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