123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /*
- * 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 handlers.itemhandlers;
- import java.util.logging.Level;
- import com.l2jserver.gameserver.handler.IItemHandler;
- import com.l2jserver.gameserver.instancemanager.CastleManager;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.actor.L2Playable;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
- import com.l2jserver.gameserver.model.entity.Castle;
- import com.l2jserver.gameserver.model.entity.TvTEvent;
- import com.l2jserver.gameserver.model.holders.SkillHolder;
- import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- public class ScrollOfResurrection implements IItemHandler
- {
- @Override
- public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
- {
- if (!playable.isPlayer())
- {
- playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
- return false;
- }
-
- if (!TvTEvent.onScrollUse(playable.getObjectId()))
- {
- playable.sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
-
- final L2PcInstance activeChar = playable.getActingPlayer();
- if (activeChar.isSitting())
- {
- activeChar.sendPacket(SystemMessageId.CANT_MOVE_SITTING);
- return false;
- }
-
- if (activeChar.isMovementDisabled())
- {
- return false;
- }
-
- final int itemId = item.getItemId();
- final boolean petScroll = (itemId == 6387);
- final SkillHolder[] skills = item.getItem().getSkills();
-
- if (skills == null)
- {
- _log.log(Level.WARNING, getClass().getSimpleName() + ": is missing skills!");
- return false;
- }
-
- // SoR Animation section
- final L2Character target = (L2Character) activeChar.getTarget();
- if ((target == null) || !target.isDead())
- {
- activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
- return false;
- }
-
- L2PcInstance targetPlayer = null;
- if (target instanceof L2PcInstance)
- {
- targetPlayer = (L2PcInstance) target;
- }
-
- L2PetInstance targetPet = null;
- if (target instanceof L2PetInstance)
- {
- targetPet = (L2PetInstance) target;
- }
-
- if ((targetPlayer != null) || (targetPet != null))
- {
- boolean condGood = true;
-
- // check target is not in a active siege zone
- Castle castle = null;
-
- if (targetPlayer != null)
- {
- castle = CastleManager.getInstance().getCastle(targetPlayer.getX(), targetPlayer.getY(), targetPlayer.getZ());
- }
- else if (targetPet != null)
- {
- castle = CastleManager.getInstance().getCastle(targetPet.getOwner().getX(), targetPet.getOwner().getY(), targetPet.getOwner().getZ());
- }
-
- if ((castle != null) && castle.getSiege().getIsInProgress())
- {
- condGood = false;
- activeChar.sendPacket(SystemMessageId.CANNOT_BE_RESURRECTED_DURING_SIEGE);
- }
-
- if (targetPet != null)
- {
- if (targetPet.getOwner() != activeChar)
- {
- if (targetPet.getOwner().isReviveRequested())
- {
- if (targetPet.getOwner().isRevivingPet())
- {
- activeChar.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED); // Resurrection is already been proposed.
- }
- else
- {
- activeChar.sendPacket(SystemMessageId.CANNOT_RES_PET2); // A pet cannot be resurrected while it's owner is in the process of resurrecting.
- }
- condGood = false;
- }
- }
- }
- else if (targetPlayer != null)
- {
- if (targetPlayer.isFestivalParticipant()) // Check to see if the current player target is in a festival.
- {
- condGood = false;
- activeChar.sendMessage("You may not resurrect participants in a festival.");
- }
- if (targetPlayer.isReviveRequested())
- {
- if (targetPlayer.isRevivingPet())
- {
- activeChar.sendPacket(SystemMessageId.MASTER_CANNOT_RES); // While a pet is attempting to resurrect, it cannot help in resurrecting its master.
- }
- else
- {
- activeChar.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED); // Resurrection is already been proposed.
- }
- condGood = false;
- }
- else if (petScroll)
- {
- condGood = false;
- activeChar.sendMessage("You do not have the correct scroll");
- }
- }
-
- if (condGood)
- {
- if (!activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false))
- {
- return false;
- }
-
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED);
- sm.addItemName(item);
- activeChar.sendPacket(sm);
-
- for (SkillHolder sk : skills)
- {
- activeChar.useMagic(sk.getSkill(), true, true);
- }
- return true;
- }
- }
- return false;
- }
- }
|