L2PetInstanceAction.java 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2004-2015 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.gameserver.GeoData;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.enums.InstanceType;
  23. import com.l2jserver.gameserver.handler.IActionHandler;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.L2Summon;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  29. import com.l2jserver.gameserver.model.events.EventDispatcher;
  30. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSummonTalk;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.PetStatusShow;
  33. public class L2PetInstanceAction implements IActionHandler
  34. {
  35. @Override
  36. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  37. {
  38. // Aggression target lock effect
  39. if (activeChar.isLockedTarget() && (activeChar.getLockedTarget() != target))
  40. {
  41. activeChar.sendPacket(SystemMessageId.FAILED_CHANGE_TARGET);
  42. return false;
  43. }
  44. boolean isOwner = activeChar.getObjectId() == ((L2PetInstance) target).getOwner().getObjectId();
  45. if (isOwner && (activeChar != ((L2PetInstance) target).getOwner()))
  46. {
  47. ((L2PetInstance) target).updateRefOwner(activeChar);
  48. }
  49. if (activeChar.getTarget() != target)
  50. {
  51. // Set the target of the L2PcInstance activeChar
  52. activeChar.setTarget(target);
  53. }
  54. else if (interact)
  55. {
  56. // Check if the pet is attackable (without a forced attack) and isn't dead
  57. if (target.isAutoAttackable(activeChar) && !isOwner)
  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 if (!((L2Character) target).isInsideRadius(activeChar, 150, false, false))
  67. {
  68. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  69. {
  70. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  71. activeChar.onActionRequest();
  72. }
  73. }
  74. else
  75. {
  76. if (isOwner)
  77. {
  78. activeChar.sendPacket(new PetStatusShow((L2PetInstance) target));
  79. // Notify to scripts
  80. EventDispatcher.getInstance().notifyEventAsync(new OnPlayerSummonTalk((L2Summon) target), (L2Summon) target);
  81. }
  82. activeChar.updateNotMoveUntil();
  83. }
  84. }
  85. return true;
  86. }
  87. @Override
  88. public InstanceType getInstanceType()
  89. {
  90. return InstanceType.L2PetInstance;
  91. }
  92. }