L2PcInstanceAction.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.actionhandlers;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.GeoData;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.handler.IActionHandler;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.entity.TvTEvent;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  27. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  28. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  29. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  30. public class L2PcInstanceAction implements IActionHandler
  31. {
  32. /**
  33. * Manage actions when a player click on this L2PcInstance.<BR><BR>
  34. *
  35. * <B><U> Actions on first click on the L2PcInstance (Select it)</U> :</B><BR><BR>
  36. * <li>Set the target of the player</li>
  37. * <li>Send a Server->Client packet MyTargetSelected to the player (display the select window)</li><BR><BR>
  38. *
  39. * <B><U> Actions on second click on the L2PcInstance (Follow it/Attack it/Intercat with it)</U> :</B><BR><BR>
  40. * <li>Send a Server->Client packet MyTargetSelected to the player (display the select window)</li>
  41. * <li>If target L2PcInstance has a Private Store, notify the player AI with AI_INTENTION_INTERACT</li>
  42. * <li>If target L2PcInstance is autoAttackable, notify the player AI with AI_INTENTION_ATTACK</li><BR><BR>
  43. * <li>If target L2PcInstance is NOT autoAttackable, notify the player AI with AI_INTENTION_FOLLOW</li><BR><BR>
  44. *
  45. * <B><U> Example of use </U> :</B><BR><BR>
  46. * <li> Client packet : Action, AttackRequest</li><BR><BR>
  47. *
  48. * @param activeChar The player that start an action on target L2PcInstance
  49. *
  50. */
  51. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  52. {
  53. // See description in TvTEvent.java
  54. if (!TvTEvent.onAction( activeChar, target.getObjectId()))
  55. return false;
  56. // Check if the L2PcInstance is confused
  57. if (activeChar.isOutOfControl())
  58. return false;
  59. // Aggression target lock effect
  60. if (activeChar.isLockedTarget() && activeChar.getLockedTarget() != target)
  61. {
  62. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_CHANGE_TARGET));
  63. return false;
  64. }
  65. // Check if the activeChar already target this L2PcInstance
  66. if (activeChar.getTarget() != target)
  67. {
  68. // Set the target of the activeChar
  69. activeChar.setTarget(target);
  70. // Send a Server->Client packet MyTargetSelected to the activeChar
  71. // The color to display in the select window is White
  72. activeChar.sendPacket(new MyTargetSelected(target.getObjectId(), 0));
  73. if (activeChar != target) activeChar.sendPacket(new ValidateLocation((L2Character)target));
  74. }
  75. else if (interact)
  76. {
  77. if (activeChar != target) activeChar.sendPacket(new ValidateLocation((L2Character)target));
  78. // Check if this L2PcInstance has a Private Store
  79. if (((L2PcInstance)target).getPrivateStoreType() != 0)
  80. {
  81. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  82. }
  83. else
  84. {
  85. // Check if this L2PcInstance is autoAttackable
  86. if (target.isAutoAttackable(activeChar))
  87. {
  88. // activeChar with lvl < 21 can't attack a cursed weapon holder
  89. // And a cursed weapon holder can't attack activeChars with lvl < 21
  90. if ((((L2PcInstance)target).isCursedWeaponEquipped() && activeChar.getLevel() < 21)
  91. || (activeChar.isCursedWeaponEquipped() && ((L2Character)target).getLevel() < 21))
  92. {
  93. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  94. }
  95. else
  96. {
  97. if (Config.GEODATA > 0)
  98. {
  99. if (GeoData.getInstance().canSeeTarget(activeChar, target))
  100. {
  101. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  102. activeChar.onActionRequest();
  103. }
  104. }
  105. else
  106. {
  107. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  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 (Config.GEODATA > 0)
  116. {
  117. if(GeoData.getInstance().canSeeTarget(activeChar, target))
  118. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  119. }
  120. else
  121. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
  122. }
  123. }
  124. }
  125. return true;
  126. }
  127. public InstanceType getInstanceType()
  128. {
  129. return InstanceType.L2PcInstance;
  130. }
  131. }