L2ArtefactInstanceAction.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  46. {
  47. if (!((L2Npc)target).canTarget(activeChar))
  48. return false;
  49. if (activeChar.getTarget() != target)
  50. {
  51. // Set the target of the L2PcInstance activeChar
  52. activeChar.setTarget(target);
  53. // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar
  54. MyTargetSelected my = new MyTargetSelected(target.getObjectId(), 0);
  55. activeChar.sendPacket(my);
  56. // Send a Server->Client packet ValidateLocation to correct the L2ArtefactInstance position and heading on the client
  57. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  58. }
  59. else if (interact)
  60. {
  61. // Calculate the distance between the L2PcInstance and the L2NpcInstance
  62. if (!((L2Npc)target).canInteract(activeChar))
  63. {
  64. // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  65. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  66. }
  67. }
  68. return true;
  69. }
  70. public InstanceType getInstanceType()
  71. {
  72. return InstanceType.L2ArtefactInstance;
  73. }
  74. }