RequestDuelStart.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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.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.ExDuelAskStart;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * Format:(ch) Sd
  28. * @author -Wooden-
  29. */
  30. public final class RequestDuelStart extends L2GameClientPacket
  31. {
  32. private static final String _C__D0_1B_REQUESTDUELSTART = "[C] D0:1B RequestDuelStart";
  33. private String _player;
  34. private int _partyDuel;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _player = readS();
  39. _partyDuel = readD();
  40. }
  41. @Override
  42. protected void runImpl()
  43. {
  44. L2PcInstance activeChar = getClient().getActiveChar();
  45. L2PcInstance targetChar = L2World.getInstance().getPlayer(_player);
  46. if (activeChar == null)
  47. {
  48. return;
  49. }
  50. if (targetChar == null)
  51. {
  52. activeChar.sendPacket(SystemMessageId.THERE_IS_NO_OPPONENT_TO_RECEIVE_YOUR_CHALLENGE_FOR_A_DUEL);
  53. return;
  54. }
  55. if (activeChar == targetChar)
  56. {
  57. activeChar.sendPacket(SystemMessageId.THERE_IS_NO_OPPONENT_TO_RECEIVE_YOUR_CHALLENGE_FOR_A_DUEL);
  58. return;
  59. }
  60. // Check if duel is possible
  61. if (!activeChar.canDuel())
  62. {
  63. activeChar.sendPacket(SystemMessageId.YOU_ARE_UNABLE_TO_REQUEST_A_DUEL_AT_THIS_TIME);
  64. return;
  65. }
  66. else if (!targetChar.canDuel())
  67. {
  68. activeChar.sendPacket(targetChar.getNoDuelReason());
  69. return;
  70. }
  71. // Players may not be too far apart
  72. else if (!activeChar.isInsideRadius(targetChar, 250, false, false))
  73. {
  74. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_RECEIVE_A_DUEL_CHALLENGE_BECAUSE_C1_IS_TOO_FAR_AWAY);
  75. msg.addString(targetChar.getName());
  76. activeChar.sendPacket(msg);
  77. return;
  78. }
  79. // Duel is a party duel
  80. if (_partyDuel == 1)
  81. {
  82. // Player must be in a party & the party leader
  83. if (!activeChar.isInParty() || !activeChar.getParty().isLeader(activeChar))
  84. {
  85. activeChar.sendMessage("You have to be the leader of a party in order to request a party duel.");
  86. return;
  87. }
  88. // Target must be in a party
  89. else if (!targetChar.isInParty())
  90. {
  91. activeChar.sendPacket(SystemMessageId.SINCE_THE_PERSON_YOU_CHALLENGED_IS_NOT_CURRENTLY_IN_A_PARTY_THEY_CANNOT_DUEL_AGAINST_YOUR_PARTY);
  92. return;
  93. }
  94. // Target may not be of the same party
  95. else if (activeChar.getParty().containsPlayer(targetChar))
  96. {
  97. activeChar.sendMessage("This player is a member of your own party.");
  98. return;
  99. }
  100. // Check if every player is ready for a duel
  101. for (L2PcInstance temp : activeChar.getParty().getMembers())
  102. {
  103. if (!temp.canDuel())
  104. {
  105. activeChar.sendMessage("Not all the members of your party are ready for a duel.");
  106. return;
  107. }
  108. }
  109. L2PcInstance partyLeader = null; // snatch party leader of targetChar's party
  110. for (L2PcInstance temp : targetChar.getParty().getMembers())
  111. {
  112. if (partyLeader == null)
  113. {
  114. partyLeader = temp;
  115. }
  116. if (!temp.canDuel())
  117. {
  118. activeChar.sendPacket(SystemMessageId.THE_OPPOSING_PARTY_IS_CURRENTLY_UNABLE_TO_ACCEPT_A_CHALLENGE_TO_A_DUEL);
  119. return;
  120. }
  121. }
  122. // Send request to targetChar's party leader
  123. if (partyLeader != null)
  124. {
  125. if (!partyLeader.isProcessingRequest())
  126. {
  127. activeChar.onTransactionRequest(partyLeader);
  128. partyLeader.sendPacket(new ExDuelAskStart(activeChar.getName(), _partyDuel));
  129. if (Config.DEBUG)
  130. {
  131. _log.fine(activeChar.getName() + " requested a duel with " + partyLeader.getName());
  132. }
  133. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_PARTY_HAS_BEEN_CHALLENGED_TO_A_DUEL);
  134. msg.addString(partyLeader.getName());
  135. activeChar.sendPacket(msg);
  136. msg = SystemMessage.getSystemMessage(SystemMessageId.C1_PARTY_HAS_CHALLENGED_YOUR_PARTY_TO_A_DUEL);
  137. msg.addString(activeChar.getName());
  138. targetChar.sendPacket(msg);
  139. }
  140. else
  141. {
  142. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER);
  143. msg.addString(partyLeader.getName());
  144. activeChar.sendPacket(msg);
  145. }
  146. }
  147. }
  148. else
  149. // 1vs1 duel
  150. {
  151. if (!targetChar.isProcessingRequest())
  152. {
  153. activeChar.onTransactionRequest(targetChar);
  154. targetChar.sendPacket(new ExDuelAskStart(activeChar.getName(), _partyDuel));
  155. if (Config.DEBUG)
  156. {
  157. _log.fine(activeChar.getName() + " requested a duel with " + targetChar.getName());
  158. }
  159. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_BEEN_CHALLENGED_TO_A_DUEL);
  160. msg.addString(targetChar.getName());
  161. activeChar.sendPacket(msg);
  162. msg = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_CHALLENGED_YOU_TO_A_DUEL);
  163. msg.addString(activeChar.getName());
  164. targetChar.sendPacket(msg);
  165. }
  166. else
  167. {
  168. SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER);
  169. msg.addString(targetChar.getName());
  170. activeChar.sendPacket(msg);
  171. }
  172. }
  173. }
  174. @Override
  175. public String getType()
  176. {
  177. return _C__D0_1B_REQUESTDUELSTART;
  178. }
  179. }