RequestDuelAnswerStart.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.instancemanager.DuelManager;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.network.SystemMessageId;
  19. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  20. /**
  21. * Format:(ch) ddd
  22. * @author -Wooden-
  23. */
  24. public final class RequestDuelAnswerStart extends L2GameClientPacket
  25. {
  26. private static final String _C__D0_28_REQUESTDUELANSWERSTART = "[C] D0:28 RequestDuelAnswerStart";
  27. private int _partyDuel;
  28. @SuppressWarnings("unused")
  29. private int _unk1;
  30. private int _response;
  31. @Override
  32. protected void readImpl()
  33. {
  34. _partyDuel = readD();
  35. _unk1 = readD();
  36. _response = readD();
  37. }
  38. /**
  39. * @see com.l2jserver.util.network.BaseRecievePacket.ClientBasePacket#runImpl()
  40. */
  41. @Override
  42. protected void runImpl()
  43. {
  44. L2PcInstance player = getClient().getActiveChar();
  45. if (player == null) return;
  46. L2PcInstance requestor = player.getActiveRequester();
  47. if (requestor == null) return;
  48. if (_response == 1)
  49. {
  50. SystemMessage msg1 = null, msg2 = null;
  51. if (requestor.isInDuel())
  52. {
  53. msg1 = SystemMessage.getSystemMessage(SystemMessageId.C1_CANNOT_DUEL_BECAUSE_C1_IS_ALREADY_ENGAGED_IN_A_DUEL);
  54. msg1.addString(requestor.getName());
  55. player.sendPacket(msg1);
  56. return;
  57. }
  58. else if (player.isInDuel())
  59. {
  60. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_ARE_UNABLE_TO_REQUEST_A_DUEL_AT_THIS_TIME));
  61. return;
  62. }
  63. if (_partyDuel == 1)
  64. {
  65. msg1 = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_ACCEPTED_C1_CHALLENGE_TO_A_PARTY_DUEL_THE_DUEL_WILL_BEGIN_IN_A_FEW_MOMENTS);
  66. msg1.addString(requestor.getName());
  67. msg2 = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_ACCEPTED_YOUR_CHALLENGE_TO_DUEL_AGAINST_THEIR_PARTY_THE_DUEL_WILL_BEGIN_IN_A_FEW_MOMENTS);
  68. msg2.addString(player.getName());
  69. }
  70. else
  71. {
  72. msg1 = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_ACCEPTED_C1_CHALLENGE_TO_A_DUEL_THE_DUEL_WILL_BEGIN_IN_A_FEW_MOMENTS);
  73. msg1.addString(requestor.getName());
  74. msg2 = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_ACCEPTED_YOUR_CHALLENGE_TO_A_DUEL_THE_DUEL_WILL_BEGIN_IN_A_FEW_MOMENTS);
  75. msg2.addString(player.getName());
  76. }
  77. player.sendPacket(msg1);
  78. requestor.sendPacket(msg2);
  79. DuelManager.getInstance().addDuel(requestor, player, _partyDuel);
  80. }
  81. else if (_response == -1)
  82. {
  83. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_SET_TO_REFUSE_DUEL_REQUEST);
  84. sm.addPcName(player);
  85. requestor.sendPacket(sm);
  86. }
  87. else
  88. {
  89. SystemMessage msg = null;
  90. if (_partyDuel == 1) msg = SystemMessage.getSystemMessage(SystemMessageId.THE_OPPOSING_PARTY_HAS_DECLINED_YOUR_CHALLENGE_TO_A_DUEL);
  91. else
  92. {
  93. msg = SystemMessage.getSystemMessage(SystemMessageId.C1_HAS_DECLINED_YOUR_CHALLENGE_TO_A_DUEL);
  94. msg.addPcName(player);
  95. }
  96. requestor.sendPacket(msg);
  97. }
  98. player.setActiveRequester(null);
  99. requestor.onTransactionResponse();
  100. }
  101. /**
  102. * @see com.l2jserver.gameserver.BasePacket#getType()
  103. */
  104. @Override
  105. public String getType()
  106. {
  107. return _C__D0_28_REQUESTDUELANSWERSTART;
  108. }
  109. }