L2SummonAction.java 3.3 KB

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