L2PetInstanceAction.java 4.3 KB

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