L2ArtefactInstanceAction.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 handlers.actionhandlers;
  16. import com.l2jserver.gameserver.ai.CtrlIntention;
  17. import com.l2jserver.gameserver.handler.IActionHandler;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  24. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  25. public class L2ArtefactInstanceAction implements IActionHandler
  26. {
  27. /**
  28. * Manage actions when a player click on the L2ArtefactInstance.<BR>
  29. * <BR>
  30. *
  31. * <B><U> Actions</U> :</B><BR>
  32. * <BR>
  33. * <li>Set the L2NpcInstance as target of the L2PcInstance player (if
  34. * necessary)</li> <li>Send a Server->Client packet MyTargetSelected to the
  35. * L2PcInstance player (display the select window)</li> <li>Send a
  36. * Server->Client packet ValidateLocation to correct the L2NpcInstance
  37. * position and heading on the client</li><BR>
  38. * <BR>
  39. *
  40. * <B><U> Example of use </U> :</B><BR>
  41. * <BR>
  42. * <li>Client packet : Action, AttackRequest</li><BR>
  43. * <BR>
  44. */
  45. @Override
  46. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  47. {
  48. if (!((L2Npc)target).canTarget(activeChar))
  49. return false;
  50. if (activeChar.getTarget() != target)
  51. {
  52. // Set the target of the L2PcInstance activeChar
  53. activeChar.setTarget(target);
  54. // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar
  55. MyTargetSelected my = new MyTargetSelected(target.getObjectId(), 0);
  56. activeChar.sendPacket(my);
  57. // Send a Server->Client packet ValidateLocation to correct the L2ArtefactInstance position and heading on the client
  58. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  59. }
  60. else if (interact)
  61. {
  62. // Calculate the distance between the L2PcInstance and the L2NpcInstance
  63. if (!((L2Npc)target).canInteract(activeChar))
  64. {
  65. // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  66. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  67. }
  68. }
  69. return true;
  70. }
  71. @Override
  72. public InstanceType getInstanceType()
  73. {
  74. return InstanceType.L2ArtefactInstance;
  75. }
  76. }