123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /*
- * 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.itemhandlers;
- import net.sf.l2j.gameserver.ThreadPoolManager;
- import net.sf.l2j.gameserver.datatables.SkillTable;
- import net.sf.l2j.gameserver.handler.IItemHandler;
- import net.sf.l2j.gameserver.model.L2Attackable;
- import net.sf.l2j.gameserver.model.L2ItemInstance;
- import net.sf.l2j.gameserver.model.L2Object;
- import net.sf.l2j.gameserver.model.L2Skill;
- import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
- import net.sf.l2j.gameserver.network.SystemMessageId;
- import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
- /**
- * This class ...
- *
- * @version $Revision: 1.2.4 $ $Date: 2005/08/14 21:31:07 $
- */
- public class SoulCrystals implements IItemHandler
- {
- // First line is for Red Soul Crystals, second is Green and third is Blue Soul Crystals,
- // ordered by ascending level, from 0 to 13...
- private static final int[] ITEM_IDS =
- {
- 4629, 4630, 4631, 4632, 4633, 4634, 4635,
- 4636, 4637, 4638, 4639, 5577, 5580, 5908,
- 9570, 4640, 4641, 4642, 4643, 4644, 4645,
- 4646, 4647, 4648, 4649, 4650, 5578, 5581,
- 5911, 9572, 4651, 4652, 4653, 4654, 4655,
- 4656, 4657, 4658, 4659, 4660, 4661, 5579,
- 5582, 5914, 9571
- };
-
- /**
- *
- * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
- */
- public void useItem(L2PlayableInstance playable, L2ItemInstance item)
- {
- if (!(playable instanceof L2PcInstance))
- return;
-
- L2PcInstance activeChar = (L2PcInstance) playable;
- L2Object target = activeChar.getTarget();
- if (!(target instanceof L2MonsterInstance))
- {
- // Send a System Message to the caster
- SystemMessage sm = new SystemMessage(SystemMessageId.INCORRECT_TARGET);
- activeChar.sendPacket(sm);
-
- // Send a Server->Client packet ActionFailed to the L2PcInstance
- ActionFailed af = ActionFailed.STATIC_PACKET;
- activeChar.sendPacket(af);
-
- return;
- }
-
- // u can use soul crystal only when target hp goes below 50%
- if (((L2MonsterInstance) target).getCurrentHp() > ((L2MonsterInstance) target).getMaxHp() / 2.0)
- {
- ActionFailed af = ActionFailed.STATIC_PACKET;
- activeChar.sendPacket(af);
- return;
- }
-
- int crystalId = item.getItemId();
-
- // Soul Crystal Casting section
- L2Skill skill = SkillTable.getInstance().getInfo(2096, 1);
- activeChar.useMagic(skill, false, true);
- // End Soul Crystal Casting section
-
- // Continue execution later
- CrystalFinalizer cf = new CrystalFinalizer(activeChar, target, crystalId);
- ThreadPoolManager.getInstance().scheduleEffect(cf, skill.getHitTime());
-
- }
-
- static class CrystalFinalizer implements Runnable
- {
- private L2PcInstance _activeChar;
- private L2Attackable _target;
- private int _crystalId;
-
- CrystalFinalizer(L2PcInstance activeChar, L2Object target, int crystalId)
- {
- _activeChar = activeChar;
- _target = (L2Attackable) target;
- _crystalId = crystalId;
- }
-
- public void run()
- {
- if (_activeChar.isDead() || _target.isDead())
- return;
-
- _activeChar.enableAllSkills();
-
- try
- {
- _target.addAbsorber(_activeChar, _crystalId);
- _activeChar.setTarget(_target);
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- }
- }
- }
-
- /**
- *
- * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
- */
- public int[] getItemIds()
- {
- return ITEM_IDS;
- }
- }
|