L2PcInstanceAction.java 5.6 KB

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