AnswerCoupleAction.java 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.L2World;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.ExRotation;
  24. import com.l2jserver.gameserver.network.serverpackets.SocialAction;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * @author JIV
  29. */
  30. public class AnswerCoupleAction extends L2GameClientPacket
  31. {
  32. private static final String _C__D0_7A_ANSWERCOUPLEACTION = "[C] D0:7A AnswerCoupleAction";
  33. private int _charObjId;
  34. private int _actionId;
  35. private int _answer;
  36. @Override
  37. protected void readImpl()
  38. {
  39. _actionId = readD();
  40. _answer = readD();
  41. _charObjId = readD();
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. L2PcInstance activeChar = getActiveChar();
  47. L2PcInstance target = L2World.getInstance().getPlayer(_charObjId);
  48. if ((activeChar == null) || (target == null))
  49. {
  50. return;
  51. }
  52. if ((target.getMultiSocialTarget() != activeChar.getObjectId()) || (target.getMultiSociaAction() != _actionId))
  53. {
  54. return;
  55. }
  56. if (_answer == 0) // cancel
  57. {
  58. target.sendPacket(SystemMessageId.COUPLE_ACTION_DENIED);
  59. }
  60. else if (_answer == 1) // approve
  61. {
  62. final int distance = (int) activeChar.calculateDistance(target, false, false);
  63. if ((distance > 125) || (distance < 15) || (activeChar.getObjectId() == target.getObjectId()))
  64. {
  65. sendPacket(SystemMessageId.TARGET_DO_NOT_MEET_LOC_REQUIREMENTS);
  66. target.sendPacket(SystemMessageId.TARGET_DO_NOT_MEET_LOC_REQUIREMENTS);
  67. return;
  68. }
  69. int heading = Util.calculateHeadingFrom(activeChar, target);
  70. activeChar.broadcastPacket(new ExRotation(activeChar.getObjectId(), heading));
  71. activeChar.setHeading(heading);
  72. heading = Util.calculateHeadingFrom(target, activeChar);
  73. target.setHeading(heading);
  74. target.broadcastPacket(new ExRotation(target.getObjectId(), heading));
  75. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(), _actionId));
  76. target.broadcastPacket(new SocialAction(_charObjId, _actionId));
  77. }
  78. else if (_answer == -1) // refused
  79. {
  80. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_SET_TO_REFUSE_COUPLE_ACTIONS);
  81. sm.addPcName(activeChar);
  82. target.sendPacket(sm);
  83. }
  84. target.setMultiSocialAction(0, 0);
  85. }
  86. @Override
  87. public String getType()
  88. {
  89. return _C__D0_7A_ANSWERCOUPLEACTION;
  90. }
  91. }