123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.model.actor;
- import com.l2jserver.gameserver.GeoData;
- import com.l2jserver.gameserver.ai.CtrlIntention;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
- import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
- /**
- * This class is a super-class for L2ControlTowerInstance and L2FlameTowerInstance.
- * @author Zoey76
- */
- public abstract class L2Tower extends L2Npc
- {
- /**
- * Creates an abstract Tower.
- * @param template the tower template
- */
- public L2Tower(L2NpcTemplate template)
- {
- super(template);
- setIsInvul(false);
- }
-
- @Override
- public boolean canBeAttacked()
- {
- // Attackable during siege by attacker only
- return ((getCastle() != null) && (getCastle().getResidenceId() > 0) && getCastle().getSiege().isInProgress());
- }
-
- @Override
- public boolean isAutoAttackable(L2Character attacker)
- {
- // Attackable during siege by attacker only
- return ((attacker != null) && attacker.isPlayer() && (getCastle() != null) && (getCastle().getResidenceId() > 0) && getCastle().getSiege().isInProgress() && getCastle().getSiege().checkIsAttacker(((L2PcInstance) attacker).getClan()));
- }
-
- @Override
- public void onAction(L2PcInstance player, boolean interact)
- {
- if (!canTarget(player))
- {
- return;
- }
-
- if (this != player.getTarget())
- {
- // Set the target of the L2PcInstance player
- player.setTarget(this);
- }
- else if (interact)
- {
- if (isAutoAttackable(player) && (Math.abs(player.getZ() - getZ()) < 100) && GeoData.getInstance().canSeeTarget(player, this))
- {
- // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
- player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
- }
- }
- // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
-
- @Override
- public void onForcedAttack(L2PcInstance player)
- {
- onAction(player);
- }
- }
|