L2PcInstanceAction.java 5.4 KB

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