L2PetInstanceAction.java 4.2 KB

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