L2SummonAction.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.actionhandlers;
  20. import com.l2jserver.gameserver.GeoData;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.enums.InstanceType;
  23. import com.l2jserver.gameserver.handler.IActionHandler;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.actor.L2Summon;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.events.EventDispatcher;
  28. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSummonTalk;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  31. import com.l2jserver.gameserver.network.serverpackets.PetStatusShow;
  32. public class L2SummonAction implements IActionHandler
  33. {
  34. @Override
  35. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  36. {
  37. // Aggression target lock effect
  38. if (activeChar.isLockedTarget() && (activeChar.getLockedTarget() != target))
  39. {
  40. activeChar.sendPacket(SystemMessageId.FAILED_CHANGE_TARGET);
  41. return false;
  42. }
  43. if ((activeChar == ((L2Summon) target).getOwner()) && (activeChar.getTarget() == target))
  44. {
  45. activeChar.sendPacket(new PetStatusShow((L2Summon) target));
  46. activeChar.updateNotMoveUntil();
  47. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  48. // Notify to scripts
  49. EventDispatcher.getInstance().notifyEventAsync(new OnPlayerSummonTalk((L2Summon) target), (L2Summon) target);
  50. }
  51. else if (activeChar.getTarget() != target)
  52. {
  53. activeChar.setTarget(target);
  54. }
  55. else if (interact)
  56. {
  57. if (target.isAutoAttackable(activeChar))
  58. {
  59. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  60. {
  61. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  62. activeChar.onActionRequest();
  63. }
  64. }
  65. else
  66. {
  67. // This Action Failed packet avoids activeChar getting stuck when clicking three or more times
  68. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  69. if (((L2Summon) target).isInsideRadius(activeChar, 150, false, false))
  70. {
  71. activeChar.updateNotMoveUntil();
  72. }
  73. else
  74. {
  75. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  76. {
  77. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  78. }
  79. }
  80. }
  81. }
  82. return true;
  83. }
  84. @Override
  85. public InstanceType getInstanceType()
  86. {
  87. return InstanceType.L2Summon;
  88. }
  89. }