L2PcInstanceAction.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.enums.PrivateStoreType;
  24. import com.l2jserver.gameserver.handler.IActionHandler;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.Location;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.entity.TvTEvent;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  32. public class L2PcInstanceAction implements IActionHandler
  33. {
  34. /**
  35. * Manage actions when a player click on this L2PcInstance.<BR>
  36. * <BR>
  37. * <B><U> Actions on first click on the L2PcInstance (Select it)</U> :</B><BR>
  38. * <BR>
  39. * <li>Set the target of the player</li> <li>Send a Server->Client packet MyTargetSelected to the player (display the select window)</li><BR>
  40. * <BR>
  41. * <B><U> Actions on second click on the L2PcInstance (Follow it/Attack it/Intercat with it)</U> :</B><BR>
  42. * <BR>
  43. * <li>Send a Server->Client packet MyTargetSelected to the player (display the select window)</li> <li>If target L2PcInstance has a Private Store, notify the player AI with AI_INTENTION_INTERACT</li> <li>If target L2PcInstance is autoAttackable, notify the player AI with AI_INTENTION_ATTACK</li>
  44. * <BR>
  45. * <BR>
  46. * <li>If target L2PcInstance is NOT autoAttackable, notify the player AI with AI_INTENTION_FOLLOW</li><BR>
  47. * <BR>
  48. * <B><U> Example of use </U> :</B><BR>
  49. * <BR>
  50. * <li>Client packet : Action, AttackRequest</li><BR>
  51. * <BR>
  52. * @param activeChar The player that start an action on target L2PcInstance
  53. */
  54. @Override
  55. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  56. {
  57. // See description in TvTEvent.java
  58. if (!TvTEvent.onAction(activeChar, target.getObjectId()))
  59. {
  60. return false;
  61. }
  62. // Check if the L2PcInstance is confused
  63. if (activeChar.isOutOfControl())
  64. {
  65. return false;
  66. }
  67. // Aggression target lock effect
  68. if (activeChar.isLockedTarget() && (activeChar.getLockedTarget() != target))
  69. {
  70. activeChar.sendPacket(SystemMessageId.FAILED_CHANGE_TARGET);
  71. return false;
  72. }
  73. // Check if the activeChar already target this L2PcInstance
  74. if (activeChar.getTarget() != target)
  75. {
  76. // Set the target of the activeChar
  77. activeChar.setTarget(target);
  78. }
  79. else if (interact)
  80. {
  81. // Check if this L2PcInstance has a Private Store
  82. if (((L2PcInstance) target).getPrivateStoreType() != PrivateStoreType.NONE)
  83. {
  84. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  85. }
  86. else
  87. {
  88. // Check if this L2PcInstance is autoAttackable
  89. if (target.isAutoAttackable(activeChar))
  90. {
  91. // activeChar with lvl < 21 can't attack a cursed weapon holder
  92. // And a cursed weapon holder can't attack activeChars with lvl < 21
  93. if ((((L2PcInstance) target).isCursedWeaponEquipped() && (activeChar.getLevel() < 21)) || (activeChar.isCursedWeaponEquipped() && (((L2Character) target).getLevel() < 21)))
  94. {
  95. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  96. }
  97. else
  98. {
  99. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  100. {
  101. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  102. activeChar.onActionRequest();
  103. }
  104. else
  105. {
  106. final Location destination = GeoData.getInstance().moveCheck(activeChar.getX(), activeChar.getY(), activeChar.getZ(), target.getX(), target.getY(), target.getZ(), activeChar.getInstanceId());
  107. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
  108. activeChar.onActionRequest();
  109. }
  110. }
  111. }
  112. else
  113. {
  114. // This Action Failed packet avoids activeChar getting stuck when clicking three or more times
  115. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  116. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  117. {
  118. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  119. }
  120. else
  121. {
  122. final Location destination = GeoData.getInstance().moveCheck(activeChar.getX(), activeChar.getY(), activeChar.getZ(), target.getX(), target.getY(), target.getZ(), activeChar.getInstanceId());
  123. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
  124. activeChar.onActionRequest();
  125. }
  126. }
  127. }
  128. }
  129. return true;
  130. }
  131. @Override
  132. public InstanceType getInstanceType()
  133. {
  134. return InstanceType.L2PcInstance;
  135. }
  136. }