/*
* 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.datatables.SkillTable;
import net.sf.l2j.gameserver.handler.IItemHandler;
import net.sf.l2j.gameserver.model.L2Effect;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
import net.sf.l2j.gameserver.model.entity.TvTEvent;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.serverpackets.ActionFailed;
import net.sf.l2j.gameserver.serverpackets.MagicSkillUse;
import net.sf.l2j.gameserver.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.util.Broadcast;
public class Cocktail implements IItemHandler
{
private static final int[] ITEM_IDS =
{
10178,
10179
};
public synchronized void useItem(L2PlayableInstance playable, L2ItemInstance item)
{
L2PcInstance activeChar;
if (playable instanceof L2PcInstance)
activeChar = (L2PcInstance) playable;
else if (playable instanceof L2PetInstance)
activeChar = ((L2PetInstance) playable).getOwner();
else
return;
if (!TvTEvent.onPotionUse(playable.getName()))
{
playable.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (activeChar.isInOlympiadMode())
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
return;
}
if (activeChar.isAllSkillsDisabled())
{
playable.sendPacket(ActionFailed.STATIC_PACKET);
activeChar.sendPacket(af);
return;
}
int itemId = item.getItemId();
switch(itemId)
{
case 10178:
{
// Sweet Fruit Cocktail
addEffect(activeChar, 1068, 2); // Might
addEffect(activeChar, 1040, 2); // Shield
addEffect(activeChar, 1204, 2); // Wind Walk
addEffect(activeChar, 1077, 2); // Focus
addEffect(activeChar, 1242, 2); // Death Whisper
addEffect(activeChar, 1062, 1); // Berserker Spirit
addEffect(activeChar, 1243, 1); // Holy Weapon
addEffect(activeChar, 1045, 3); // Blessed Body
addEffect(activeChar, 1086, 1); // Haste
addEffect(activeChar, 1268, 2); // Vampiric Rage
break;
}
case 10179:
{
// Fresh Fruit Cocktail
addEffect(activeChar, 1062, 1); // Berserker Spirit
addEffect(activeChar, 1045, 3); // Blessed Body
addEffect(activeChar, 1036, 2); // Magic Barrier
addEffect(activeChar, 1040, 2); // Shield
addEffect(activeChar, 1204, 1); // Wind Walk
addEffect(activeChar, 1048, 3); // Blessed Soul
addEffect(activeChar, 1085, 2); // Acumen
addEffect(activeChar, 1397, 1); // Clarity
addEffect(activeChar, 1059, 2); // Greater Empower
break;
}
}
playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
}
private void addEffect(L2PcInstance player, int skillId, int skillLvl)
{
L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
if (player != null && skill != null)
{
MagicSkillUse msk = new MagicSkillUse(player, skill.getId(), skill.getLevel(), skill.getHitTime(), 0);
Broadcast.toSelfAndKnownPlayersInRadius(player, msk, 810000);
L2Effect[] effects = player.getAllEffects();
for (L2Effect e : effects)
{
if (e != null && e.getSkill().getId() == skill.getId())
e.exit();
}
skill.getEffects(player, player);
}
}
public int[] getItemIds()
{
return ITEM_IDS;
}
}