L2SummonAction.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2004-2013 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.handler.IActionHandler;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.actor.L2Summon;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  31. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  32. import com.l2jserver.gameserver.network.serverpackets.PetStatusShow;
  33. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  34. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  35. public class L2SummonAction implements IActionHandler
  36. {
  37. @Override
  38. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  39. {
  40. // Aggression target lock effect
  41. if (activeChar.isLockedTarget() && (activeChar.getLockedTarget() != target))
  42. {
  43. activeChar.sendPacket(SystemMessageId.FAILED_CHANGE_TARGET);
  44. return false;
  45. }
  46. if ((activeChar == ((L2Summon) target).getOwner()) && (activeChar.getTarget() == target))
  47. {
  48. activeChar.sendPacket(new PetStatusShow((L2Summon) target));
  49. activeChar.updateNotMoveUntil();
  50. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  51. }
  52. else if (activeChar.getTarget() != target)
  53. {
  54. if (Config.DEBUG)
  55. {
  56. _log.fine("new target selected:" + target.getObjectId());
  57. }
  58. activeChar.setTarget(target);
  59. activeChar.sendPacket(new ValidateLocation((L2Character) target));
  60. MyTargetSelected my = new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character) target).getLevel());
  61. activeChar.sendPacket(my);
  62. // sends HP/MP status of the summon to other characters
  63. StatusUpdate su = new StatusUpdate(target);
  64. su.addAttribute(StatusUpdate.CUR_HP, (int) ((L2Character) target).getCurrentHp());
  65. su.addAttribute(StatusUpdate.MAX_HP, ((L2Character) target).getMaxHp());
  66. activeChar.sendPacket(su);
  67. }
  68. else if (interact)
  69. {
  70. activeChar.sendPacket(new ValidateLocation((L2Character) target));
  71. if (target.isAutoAttackable(activeChar))
  72. {
  73. if (Config.GEODATA > 0)
  74. {
  75. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  76. {
  77. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  78. activeChar.onActionRequest();
  79. }
  80. }
  81. else
  82. {
  83. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  84. activeChar.onActionRequest();
  85. }
  86. }
  87. else
  88. {
  89. // This Action Failed packet avoids activeChar getting stuck when clicking three or more times
  90. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  91. if (((L2Summon) target).isInsideRadius(activeChar, 150, false, false))
  92. {
  93. activeChar.updateNotMoveUntil();
  94. }
  95. else if (Config.GEODATA > 0)
  96. {
  97. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  98. {
  99. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  100. }
  101. }
  102. else
  103. {
  104. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  105. }
  106. }
  107. }
  108. return true;
  109. }
  110. @Override
  111. public InstanceType getInstanceType()
  112. {
  113. return InstanceType.L2Summon;
  114. }
  115. }