123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- /*
- * This program 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.
- *
- * This program 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 net.sf.l2j.gameserver.handler.skillhandlers;
- import java.util.List;
- import net.sf.l2j.Config;
- import net.sf.l2j.gameserver.handler.ISkillHandler;
- import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
- import net.sf.l2j.gameserver.model.L2Character;
- import net.sf.l2j.gameserver.model.L2Object;
- import net.sf.l2j.gameserver.model.L2Skill;
- import net.sf.l2j.gameserver.model.L2World;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2RaidBossInstance;
- import net.sf.l2j.gameserver.network.SystemMessageId;
- import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.templates.L2SkillType;
- import net.sf.l2j.gameserver.util.Util;
- /**
- * @authors BiTi, Sami
- *
- */
- public class SummonFriend implements ISkillHandler
- {
- //private static Logger _log = Logger.getLogger(SummonFriend.class.getName());
- private static final L2SkillType[] SKILL_IDS =
- {
- L2SkillType.SUMMON_FRIEND
- };
-
- /**
- *
- * @see net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.gameserver.model.L2Object[])
- */
- public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
- {
- if (!(activeChar instanceof L2PcInstance))
- return; // currently not implemented for others
- L2PcInstance activePlayer = (L2PcInstance) activeChar;
-
- if (activePlayer.isInOlympiadMode())
- {
- activePlayer.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
- return;
- }
-
- // Checks summoner not in arenas, siege zones, jail
- if (activePlayer.isInsideZone(L2Character.ZONE_PVP))
- {
- activePlayer.sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_SUMMON_IN_COMBAT));
- return;
- }
-
- if (GrandBossManager.getInstance().getZone(activePlayer) != null && !activePlayer.isGM())
- {
- activePlayer.sendMessage("You may not use Summon Friend Skill inside a Boss Zone.");
- activePlayer.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
-
- // check for summoner not in raid areas
- List<L2Object> objects = L2World.getInstance().getVisibleObjects(activeChar, 5000);
-
- if (objects != null)
- {
- for (L2Object object : objects)
- {
- if (object instanceof L2RaidBossInstance)
- {
- activePlayer.sendPacket(new SystemMessage(SystemMessageId.YOU_MAY_NOT_SUMMON_FROM_YOUR_CURRENT_LOCATION));
- return;
- }
- }
- }
-
- try
- {
- for (int index = 0; index < targets.length; index++)
- {
- if (!(targets[index] instanceof L2Character))
- continue;
-
- L2Character target = (L2Character) targets[index];
-
- if (activeChar == target)
- continue;
-
- if (target instanceof L2PcInstance)
- {
- L2PcInstance targetChar = (L2PcInstance) target;
-
- // CHECK TARGET CONDITIONS
- if (targetChar.isAlikeDead())
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_DEAD_AT_THE_MOMENT_AND_CANNOT_BE_SUMMONED);
- sm.addPcName(targetChar);
- activeChar.sendPacket(sm);
- continue;
- }
-
- if (targetChar.isInStoreMode())
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.S1_CURRENTLY_TRADING_OR_OPERATING_PRIVATE_STORE_AND_CANNOT_BE_SUMMONED);
- sm.addPcName(targetChar);
- activeChar.sendPacket(sm);
- continue;
- }
-
- // Target cannot be in combat (or dead, but that's checked by TARGET_PARTY)
- if (targetChar.isRooted() || targetChar.isInCombat())
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_ENGAGED_IN_COMBAT_AND_CANNOT_BE_SUMMONED);
- sm.addPcName(targetChar);
- activeChar.sendPacket(sm);
- continue;
- }
-
- // Check for the the target's Inside Boss Zone
- if (GrandBossManager.getInstance().getZone(targetChar) != null && !targetChar.isGM())
- {
- // SystemMessage doesn't exist?!
- activeChar.sendMessage("Cant summon target inside boss zone.");
- continue;
- }
-
- // Check for the the target's festival status
- if (targetChar.isInOlympiadMode())
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_SUMMON_PLAYERS_WHO_ARE_IN_OLYMPIAD));
- continue;
- }
-
- // Check for the the target's festival status
- if (targetChar.isFestivalParticipant())
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING));
- continue;
- }
-
- // Check for the target's jail status, arenas and siege zones
- if (targetChar.isInsideZone(L2Character.ZONE_PVP))
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING));
- continue;
- }
-
- // Requires a Summoning Crystal
- if (skill.getTargetConsume() != 0)
- if (targetChar.getInventory().getInventoryItemCount(skill.getTargetConsumeId(), 0) < skill.getTargetConsume())
- {
- ((L2PcInstance) activeChar).sendMessage("Your target cannot be summoned while he hasn't got enough Summoning Crystal");
- targetChar.sendMessage("You cannot be summoned while you haven't got enough Summoning Crystal");
- continue;
- }
-
- if (!Util.checkIfInRange(0, activeChar, target, false))
- {
- if (skill.getTargetConsume() != 0)
- targetChar.getInventory().destroyItemByItemId("Consume", skill.getTargetConsumeId(), skill.getTargetConsume(), targetChar, activeChar);
-
- targetChar.sendMessage("You are summoned to a party member.");
-
- targetChar.teleToLocation(activeChar.getX(), activeChar.getY(), activeChar.getZ(), true);
- }
- else
- {
-
- }
- }
- }
- }
- catch (Throwable e)
- {
- if (Config.DEBUG)
- e.printStackTrace();
- }
- }
-
- /**
- *
- * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
- */
- public L2SkillType[] getSkillIds()
- {
- return SKILL_IDS;
- }
- }
|