AnswerCoupleAction.java 3.1 KB

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