L2Tower.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.model.actor;
  20. import com.l2jserver.gameserver.GeoData;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  24. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  25. /**
  26. * This class is a super-class for L2ControlTowerInstance and L2FlameTowerInstance.
  27. * @author Zoey76
  28. */
  29. public abstract class L2Tower extends L2Npc
  30. {
  31. /**
  32. * Creates an abstract Tower.
  33. * @param template the tower template
  34. */
  35. public L2Tower(L2NpcTemplate template)
  36. {
  37. super(template);
  38. setIsInvul(false);
  39. }
  40. @Override
  41. public boolean canBeAttacked()
  42. {
  43. // Attackable during siege by attacker only
  44. return ((getCastle() != null) && (getCastle().getResidenceId() > 0) && getCastle().getSiege().isInProgress());
  45. }
  46. @Override
  47. public boolean isAutoAttackable(L2Character attacker)
  48. {
  49. // Attackable during siege by attacker only
  50. return ((attacker != null) && attacker.isPlayer() && (getCastle() != null) && (getCastle().getResidenceId() > 0) && getCastle().getSiege().isInProgress() && getCastle().getSiege().checkIsAttacker(((L2PcInstance) attacker).getClan()));
  51. }
  52. @Override
  53. public void onAction(L2PcInstance player, boolean interact)
  54. {
  55. if (!canTarget(player))
  56. {
  57. return;
  58. }
  59. if (this != player.getTarget())
  60. {
  61. // Set the target of the L2PcInstance player
  62. player.setTarget(this);
  63. }
  64. else if (interact)
  65. {
  66. if (isAutoAttackable(player) && (Math.abs(player.getZ() - getZ()) < 100) && GeoData.getInstance().canSeeTarget(player, this))
  67. {
  68. // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  69. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  70. }
  71. }
  72. // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  73. player.sendPacket(ActionFailed.STATIC_PACKET);
  74. }
  75. @Override
  76. public void onForcedAttack(L2PcInstance player)
  77. {
  78. onAction(player);
  79. }
  80. }