L2SummonAction.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.Config;
  17. import com.l2jserver.gameserver.GeoData;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.handler.IActionHandler;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Summon;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  27. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  28. import com.l2jserver.gameserver.network.serverpackets.PetStatusShow;
  29. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  30. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  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. if (Config.DEBUG)
  51. _log.fine("new target selected:"+target.getObjectId());
  52. activeChar.setTarget(target);
  53. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  54. MyTargetSelected my = new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character)target).getLevel());
  55. activeChar.sendPacket(my);
  56. //sends HP/MP status of the summon to other characters
  57. StatusUpdate su = new StatusUpdate(target);
  58. su.addAttribute(StatusUpdate.CUR_HP, (int) ((L2Character)target).getCurrentHp());
  59. su.addAttribute(StatusUpdate.MAX_HP, ((L2Character)target).getMaxHp());
  60. activeChar.sendPacket(su);
  61. }
  62. else if (interact)
  63. {
  64. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  65. if (target.isAutoAttackable(activeChar))
  66. {
  67. if (Config.GEODATA > 0)
  68. {
  69. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  70. {
  71. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  72. activeChar.onActionRequest();
  73. }
  74. }
  75. else
  76. {
  77. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  78. activeChar.onActionRequest();
  79. }
  80. }
  81. else
  82. {
  83. // This Action Failed packet avoids activeChar getting stuck when clicking three or more times
  84. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  85. if(((L2Summon)target).isInsideRadius(activeChar, 150, false, false))
  86. activeChar.updateNotMoveUntil();
  87. else if (Config.GEODATA > 0)
  88. {
  89. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  90. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  91. }
  92. else
  93. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  94. }
  95. }
  96. return true;
  97. }
  98. @Override
  99. public InstanceType getInstanceType()
  100. {
  101. return InstanceType.L2Summon;
  102. }
  103. }