L2DoorInstanceAction.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2004-2014 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.ai.CtrlIntention;
  21. import com.l2jserver.gameserver.enums.InstanceType;
  22. import com.l2jserver.gameserver.handler.IActionHandler;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
  29. import com.l2jserver.gameserver.model.holders.DoorRequestHolder;
  30. import com.l2jserver.gameserver.network.serverpackets.ConfirmDlg;
  31. public class L2DoorInstanceAction implements IActionHandler
  32. {
  33. @Override
  34. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  35. {
  36. // Check if the L2PcInstance already target the L2NpcInstance
  37. if (activeChar.getTarget() != target)
  38. {
  39. activeChar.setTarget(target);
  40. }
  41. else if (interact)
  42. {
  43. L2DoorInstance door = (L2DoorInstance) target;
  44. // MyTargetSelected my = new MyTargetSelected(getObjectId(), activeChar.getLevel());
  45. // activeChar.sendPacket(my);
  46. if (target.isAutoAttackable(activeChar))
  47. {
  48. if (Math.abs(activeChar.getZ() - target.getZ()) < 400)
  49. {
  50. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  51. }
  52. }
  53. else if ((activeChar.getClan() != null) && (door.getClanHall() != null) && (activeChar.getClanId() == door.getClanHall().getOwnerId()))
  54. {
  55. if (!door.isInsideRadius(activeChar, L2Npc.INTERACTION_DISTANCE, false, false))
  56. {
  57. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  58. }
  59. else if (!door.getClanHall().isSiegableHall() || !((SiegableHall) door.getClanHall()).isInSiege())
  60. {
  61. activeChar.addScript(new DoorRequestHolder(door));
  62. if (!door.getOpen())
  63. {
  64. activeChar.sendPacket(new ConfirmDlg(1140));
  65. }
  66. else
  67. {
  68. activeChar.sendPacket(new ConfirmDlg(1141));
  69. }
  70. }
  71. }
  72. else if ((activeChar.getClan() != null) && (((L2DoorInstance) target).getFort() != null) && (activeChar.getClan() == ((L2DoorInstance) target).getFort().getOwnerClan()) && ((L2DoorInstance) target).isOpenableBySkill() && !((L2DoorInstance) target).getFort().getSiege().isInProgress())
  73. {
  74. if (!((L2Character) target).isInsideRadius(activeChar, L2Npc.INTERACTION_DISTANCE, false, false))
  75. {
  76. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
  77. }
  78. else
  79. {
  80. activeChar.addScript(new DoorRequestHolder((L2DoorInstance) target));
  81. if (!((L2DoorInstance) target).getOpen())
  82. {
  83. activeChar.sendPacket(new ConfirmDlg(1140));
  84. }
  85. else
  86. {
  87. activeChar.sendPacket(new ConfirmDlg(1141));
  88. }
  89. }
  90. }
  91. }
  92. return true;
  93. }
  94. @Override
  95. public InstanceType getInstanceType()
  96. {
  97. return InstanceType.L2DoorInstance;
  98. }
  99. }