L2PetInstanceAction.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2004-2014 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.enums.InstanceType;
  24. import com.l2jserver.gameserver.handler.IActionHandler;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.actor.L2Summon;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  30. import com.l2jserver.gameserver.model.events.EventDispatcher;
  31. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSummonTalk;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. import com.l2jserver.gameserver.network.serverpackets.PetStatusShow;
  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. if (isOwner && (activeChar != ((L2PetInstance) target).getOwner()))
  47. {
  48. ((L2PetInstance) target).updateRefOwner(activeChar);
  49. }
  50. if (activeChar.getTarget() != target)
  51. {
  52. // Set the target of the L2PcInstance activeChar
  53. activeChar.setTarget(target);
  54. }
  55. else if (interact)
  56. {
  57. // Check if the pet is attackable (without a forced attack) and isn't dead
  58. if (target.isAutoAttackable(activeChar) && !isOwner)
  59. {
  60. if (Config.GEODATA > 0)
  61. {
  62. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  63. {
  64. // Set the L2PcInstance Intention to AI_INTENTION_ATTACK
  65. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  66. activeChar.onActionRequest();
  67. }
  68. }
  69. else
  70. {
  71. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  72. activeChar.onActionRequest();
  73. }
  74. }
  75. else if (!((L2Character) target).isInsideRadius(activeChar, 150, false, false))
  76. {
  77. if (Config.GEODATA > 0)
  78. {
  79. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  80. {
  81. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  82. activeChar.onActionRequest();
  83. }
  84. }
  85. else
  86. {
  87. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  88. activeChar.onActionRequest();
  89. }
  90. }
  91. else
  92. {
  93. if (isOwner)
  94. {
  95. activeChar.sendPacket(new PetStatusShow((L2PetInstance) target));
  96. // Notify to scripts
  97. EventDispatcher.getInstance().notifyEventAsync(new OnPlayerSummonTalk((L2Summon) target), (L2Summon) target);
  98. }
  99. activeChar.updateNotMoveUntil();
  100. }
  101. }
  102. return true;
  103. }
  104. @Override
  105. public InstanceType getInstanceType()
  106. {
  107. return InstanceType.L2PetInstance;
  108. }
  109. }