L2SummonAction.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  34. {
  35. // Aggression target lock effect
  36. if (activeChar.isLockedTarget() && activeChar.getLockedTarget() != target)
  37. {
  38. activeChar.sendPacket(SystemMessageId.FAILED_CHANGE_TARGET);
  39. return false;
  40. }
  41. if (activeChar == ((L2Summon)target).getOwner() && activeChar.getTarget() == target)
  42. {
  43. activeChar.sendPacket(new PetStatusShow((L2Summon)target));
  44. activeChar.updateNotMoveUntil();
  45. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  46. }
  47. else if (activeChar.getTarget() != target)
  48. {
  49. if (Config.DEBUG)
  50. _log.fine("new target selected:"+target.getObjectId());
  51. activeChar.setTarget(target);
  52. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  53. MyTargetSelected my = new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character)target).getLevel());
  54. activeChar.sendPacket(my);
  55. //sends HP/MP status of the summon to other characters
  56. StatusUpdate su = new StatusUpdate(target);
  57. su.addAttribute(StatusUpdate.CUR_HP, (int) ((L2Character)target).getCurrentHp());
  58. su.addAttribute(StatusUpdate.MAX_HP, ((L2Character)target).getMaxHp());
  59. activeChar.sendPacket(su);
  60. }
  61. else if (interact)
  62. {
  63. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  64. if (target.isAutoAttackable(activeChar))
  65. {
  66. if (Config.GEODATA > 0)
  67. {
  68. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  69. {
  70. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  71. activeChar.onActionRequest();
  72. }
  73. }
  74. else
  75. {
  76. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  77. activeChar.onActionRequest();
  78. }
  79. }
  80. else
  81. {
  82. // This Action Failed packet avoids activeChar getting stuck when clicking three or more times
  83. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  84. if(((L2Summon)target).isInsideRadius(activeChar, 150, false, false))
  85. activeChar.updateNotMoveUntil();
  86. else if (Config.GEODATA > 0)
  87. {
  88. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  89. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  90. }
  91. else
  92. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  93. }
  94. }
  95. return true;
  96. }
  97. public InstanceType getInstanceType()
  98. {
  99. return InstanceType.L2Summon;
  100. }
  101. }