L2PcInstanceAction.java 4.7 KB

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