L2SummonAction.java 3.5 KB

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