L2DoorInstanceAction.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.gameserver.ai.CtrlIntention;
  17. import com.l2jserver.gameserver.handler.IActionHandler;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.serverpackets.ConfirmDlg;
  25. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  26. import com.l2jserver.gameserver.network.serverpackets.StaticObject;
  27. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  28. public class L2DoorInstanceAction implements IActionHandler
  29. {
  30. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  31. {
  32. // Check if the L2PcInstance already target the L2NpcInstance
  33. if (activeChar.getTarget() != target)
  34. {
  35. // Set the target of the L2PcInstance activeChar
  36. activeChar.setTarget(target);
  37. // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar
  38. activeChar.sendPacket(new MyTargetSelected(target.getObjectId(), 0));
  39. StaticObject su;
  40. // send HP amount if doors are inside castle/fortress zone
  41. // TODO: needed to be added here doors from conquerable clanhalls
  42. if ((((L2DoorInstance)target).getCastle() != null
  43. && ((L2DoorInstance)target).getCastle().getCastleId() > 0)
  44. || (((L2DoorInstance)target).getFort() != null
  45. && ((L2DoorInstance)target).getFort().getFortId() > 0
  46. && !((L2DoorInstance)target).getIsCommanderDoor()))
  47. su = new StaticObject((L2DoorInstance)target, true);
  48. else
  49. su = new StaticObject((L2DoorInstance)target, false);
  50. activeChar.sendPacket(su);
  51. // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
  52. activeChar.sendPacket(new ValidateLocation((L2Character)target));
  53. }
  54. else if (interact)
  55. {
  56. // MyTargetSelected my = new MyTargetSelected(getObjectId(), activeChar.getLevel());
  57. // activeChar.sendPacket(my);
  58. if (target.isAutoAttackable(activeChar))
  59. {
  60. if (Math.abs(activeChar.getZ() - target.getZ()) < 400) // this max heigth difference might need some tweaking
  61. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  62. }
  63. else if (activeChar.getClan() != null
  64. && ((L2DoorInstance)target).getClanHall() != null
  65. && activeChar.getClanId() == ((L2DoorInstance)target).getClanHall().getOwnerId())
  66. {
  67. if (!((L2Character)target).isInsideRadius(activeChar, L2Npc.INTERACTION_DISTANCE, false, false))
  68. {
  69. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  70. }
  71. else
  72. {
  73. activeChar.gatesRequest((L2DoorInstance)target);
  74. if (!((L2DoorInstance)target).getOpen())
  75. activeChar.sendPacket(new ConfirmDlg(1140));
  76. else
  77. activeChar.sendPacket(new ConfirmDlg(1141));
  78. }
  79. }
  80. else if (activeChar.getClan() != null
  81. && ((L2DoorInstance)target).getFort() != null
  82. && activeChar.getClan() == ((L2DoorInstance)target).getFort().getOwnerClan()
  83. && ((L2DoorInstance)target).isUnlockable()
  84. && !((L2DoorInstance)target).getFort().getSiege().getIsInProgress())
  85. {
  86. if (!((L2Character)target).isInsideRadius(activeChar, L2Npc.INTERACTION_DISTANCE, false, false))
  87. {
  88. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  89. }
  90. else
  91. {
  92. activeChar.gatesRequest((L2DoorInstance)target);
  93. if (!((L2DoorInstance)target).getOpen())
  94. activeChar.sendPacket(new ConfirmDlg(1140));
  95. else
  96. activeChar.sendPacket(new ConfirmDlg(1141));
  97. }
  98. }
  99. }
  100. return true;
  101. }
  102. public InstanceType getInstanceType()
  103. {
  104. return InstanceType.L2DoorInstance;
  105. }
  106. }