L2PcInstanceAction.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.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. public class L2PcInstanceAction implements IActionHandler
  32. {
  33. private static final int CURSED_WEAPON_VICTIM_MIN_LEVEL = 21;
  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. final L2PcInstance player = target.getActingPlayer();
  82. // Check if this L2PcInstance has a Private Store
  83. if (player.getPrivateStoreType() != PrivateStoreType.NONE)
  84. {
  85. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, player);
  86. }
  87. else
  88. {
  89. // Check if this L2PcInstance is autoAttackable
  90. if (player.isAutoAttackable(activeChar))
  91. {
  92. if ((player.isCursedWeaponEquipped() && (activeChar.getLevel() < CURSED_WEAPON_VICTIM_MIN_LEVEL)) //
  93. || (activeChar.isCursedWeaponEquipped() && (player.getLevel() < CURSED_WEAPON_VICTIM_MIN_LEVEL)))
  94. {
  95. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  96. }
  97. else
  98. {
  99. if (GeoData.getInstance().canSeeTarget(activeChar, player))
  100. {
  101. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  102. }
  103. else
  104. {
  105. final Location destination = GeoData.getInstance().moveCheck(activeChar, player);
  106. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
  107. }
  108. activeChar.onActionRequest();
  109. }
  110. }
  111. else
  112. {
  113. // This Action Failed packet avoids activeChar getting stuck when clicking three or more times
  114. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  115. if (GeoData.getInstance().canSeeTarget(activeChar, player))
  116. {
  117. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player);
  118. }
  119. else
  120. {
  121. final Location destination = GeoData.getInstance().moveCheck(activeChar, player);
  122. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
  123. }
  124. }
  125. }
  126. }
  127. return true;
  128. }
  129. @Override
  130. public InstanceType getInstanceType()
  131. {
  132. return InstanceType.L2PcInstance;
  133. }
  134. }