L2PetInstanceAction.java 3.5 KB

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