RequestDuelAnswerStart.java 3.9 KB

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