L2PetInstanceAction.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  27. import com.l2jserver.gameserver.network.serverpackets.PetStatusShow;
  28. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  29. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  30. public class L2PetInstanceAction implements IActionHandler
  31. {
  32. @Override
  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. boolean isOwner = activeChar.getObjectId() == ((L2PetInstance)target).getOwner().getObjectId();
  42. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  43. if(isOwner && activeChar != ((L2PetInstance)target).getOwner())
  44. ((L2PetInstance)target).updateRefOwner(activeChar);
  45. if (activeChar.getTarget() != target)
  46. {
  47. if (Config.DEBUG)
  48. _log.fine("new target selected:" + target.getObjectId());
  49. // Set the target of the L2PcInstance activeChar
  50. activeChar.setTarget(target);
  51. activeChar.sendPacket(new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character)target).getLevel()));
  52. // Send a Server->Client packet StatusUpdate of the L2PetInstance to the L2PcInstance to update its HP bar
  53. StatusUpdate su = new StatusUpdate(target);
  54. su.addAttribute(StatusUpdate.CUR_HP, (int) ((L2Character)target).getCurrentHp());
  55. su.addAttribute(StatusUpdate.MAX_HP, ((L2Character)target).getMaxHp());
  56. activeChar.sendPacket(su);
  57. }
  58. else if (interact)
  59. {
  60. // Check if the pet is attackable (without a forced attack) and isn't dead
  61. if (target.isAutoAttackable(activeChar) && !isOwner)
  62. {
  63. if (Config.GEODATA > 0)
  64. {
  65. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  66. {
  67. // Set the L2PcInstance Intention to AI_INTENTION_ATTACK
  68. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  69. activeChar.onActionRequest();
  70. }
  71. }
  72. else
  73. {
  74. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  75. activeChar.onActionRequest();
  76. }
  77. }
  78. else if (!((L2Character)target).isInsideRadius(activeChar, 150, false, false))
  79. {
  80. if (Config.GEODATA > 0)
  81. {
  82. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  83. {
  84. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  85. activeChar.onActionRequest();
  86. }
  87. }
  88. else
  89. {
  90. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  91. activeChar.onActionRequest();
  92. }
  93. }
  94. else
  95. {
  96. if (isOwner)
  97. activeChar.sendPacket(new PetStatusShow((L2PetInstance)target));
  98. activeChar.updateNotMoveUntil(); }
  99. }
  100. return true;
  101. }
  102. @Override
  103. public InstanceType getInstanceType()
  104. {
  105. return InstanceType.L2PetInstance;
  106. }
  107. }