123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /*
- * 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.network.clientpackets;
- import com.l2jserver.gameserver.enums.PrivateStoreType;
- import com.l2jserver.gameserver.model.L2Object;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.PcCondOverride;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.effects.AbstractEffect;
- import com.l2jserver.gameserver.model.skills.AbnormalType;
- import com.l2jserver.gameserver.model.skills.BuffInfo;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
- /**
- * TODO: This class is a copy of AttackRequest, we should get proper structure for both.
- */
- public final class Attack extends L2GameClientPacket
- {
- private static final String _C__01_ATTACK = "[C] 01 Attack";
-
- // cddddc
- private int _objectId;
- @SuppressWarnings("unused")
- private int _originX;
- @SuppressWarnings("unused")
- private int _originY;
- @SuppressWarnings("unused")
- private int _originZ;
- @SuppressWarnings("unused")
- private int _attackId;
-
- @Override
- protected void readImpl()
- {
- _objectId = readD();
- _originX = readD();
- _originY = readD();
- _originZ = readD();
- _attackId = readC(); // 0 for simple click 1 for shift-click
- }
-
- @Override
- protected void runImpl()
- {
- final L2PcInstance activeChar = getActiveChar();
- if (activeChar == null)
- {
- return;
- }
-
- // Avoid Attacks in Boat.
- if (activeChar.isPlayable() && activeChar.isInBoat())
- {
- activeChar.sendPacket(SystemMessageId.NOT_ALLOWED_ON_BOAT);
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
-
- final BuffInfo info = activeChar.getEffectList().getBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY);
- if (info != null)
- {
- for (AbstractEffect effect : info.getEffects())
- {
- if (!effect.checkCondition(-1))
- {
- activeChar.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REPORTED_SO_ACTIONS_NOT_ALLOWED);
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- }
- }
-
- // avoid using expensive operations if not needed
- final L2Object target;
- if (activeChar.getTargetId() == _objectId)
- {
- target = activeChar.getTarget();
- }
- else
- {
- target = L2World.getInstance().findObject(_objectId);
- }
-
- if (target == null)
- {
- return;
- }
-
- if (!target.isTargetable() && !activeChar.canOverrideCond(PcCondOverride.TARGET_ALL))
- {
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
-
- // Players can't attack objects in the other instances
- // except from multiverse
- else if ((target.getInstanceId() != activeChar.getInstanceId()) && (activeChar.getInstanceId() != -1))
- {
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
-
- // Only GMs can directly attack invisible characters
- else if (!target.isVisibleFor(activeChar))
- {
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
-
- if (activeChar.getTarget() != target)
- {
- target.onAction(activeChar);
- }
- else
- {
- if ((target.getObjectId() != activeChar.getObjectId()) && (activeChar.getPrivateStoreType() == PrivateStoreType.NONE) && (activeChar.getActiveRequester() == null))
- {
- target.onForcedAttack(activeChar);
- }
- else
- {
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- }
- }
- }
-
- @Override
- public String getType()
- {
- return _C__01_ATTACK;
- }
- }
|