package listeners.items;
import org.apache.commons.lang3.ArrayUtils;
import l2p.gameserver.data.holder.SkillHolder;
import l2p.gameserver.listener.item.OnItemEquipListener;
import l2p.gameserver.model.Playable;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.actor.listener.ItemListenerList;
import l2p.gameserver.model.items.Inventory;
import l2p.gameserver.model.items.ItemInstance;
import l2p.gameserver.model.skills.Skill;
import l2p.gameserver.network.s2c.SkillCoolTime;
import l2p.gameserver.scripts.ScriptFile;
/**
* @author Gaikotsu
*/
public class Jewels implements ScriptFile
{
private static final int[] Level6Jewels = { 28376, 28377, 28378, 28379, 28380, 28383, 47687, 47688, 47689, 47690, 47691, 47692, 47693, 47694, 47695, 47696, 47697, 47698, 47699, 47700, 47920, 47921, 47922, 47923 };
private static final Skill[] GreaterGemstoneBlessing = {
SkillHolder.getInstance().getSkill(27717, 1),
SkillHolder.getInstance().getSkill(27717, 2),
SkillHolder.getInstance().getSkill(27717, 3),
SkillHolder.getInstance().getSkill(27717, 4),
SkillHolder.getInstance().getSkill(27717, 5),
SkillHolder.getInstance().getSkill(27717, 6) };
private static final Skill[] LaVieEnRoseEnergy = {
SkillHolder.getInstance().getSkill(27721, 1),
SkillHolder.getInstance().getSkill(27722, 1),
SkillHolder.getInstance().getSkill(27723, 1),
SkillHolder.getInstance().getSkill(27724, 1) };
private static final ItemEquipListener _listener = new ItemEquipListener();
@Override
public void onLoad()
{
ItemListenerList.addGlobal(_listener);
}
@Override
public void onReload()
{
ItemListenerList.removeGlobal(_listener);
}
private static int getEquppedJewelsCount(Player player)
{
int count = 0;
for (int slot = Inventory.PAPERDOLL_JEWEL_1; slot <= Inventory.PAPERDOLL_JEWEL_6; slot++)
{
ItemInstance item = player.getInventory().getPaperdollItem(slot);
if (item != null && ArrayUtils.contains(Level6Jewels, item.getId()))
count++;
}
return count;
}
public static class ItemEquipListener implements OnItemEquipListener
{
@Override
public void onEquip(ItemInstance item, Playable actor)
{
if (!actor.isPlayer())
return;
Player player = actor.getPlayer();
int count = getEquppedJewelsCount(player);
player.addSkill(GreaterGemstoneBlessing[count - 1], false);
if (count > 2)
{
for (int i = 0; i < LaVieEnRoseEnergy.length; i++)
{
if (i == (count - 3))
{
player.addSkill(LaVieEnRoseEnergy[i], false);
if (player.isSkillDisabled(LaVieEnRoseEnergy[i]))
player.sendPacket(new SkillCoolTime(player));
}
else
player.removeSkill(LaVieEnRoseEnergy[i], false);
}
}
if (!player.getInventory().isRefresh)
player.sendSkillList(false);
}
@Override
public void onUnequip(ItemInstance item, Playable actor)
{
if (!actor.isPlayer())
return;
Player player = actor.getPlayer();
int count = getEquppedJewelsCount(player);
if (count > 0)
{
player.addSkill(GreaterGemstoneBlessing[count - 1], false);
if (count > 1)
{
for (int i = 0; i < LaVieEnRoseEnergy.length; i++)
{
if (i == (count - 3))
{
player.addSkill(LaVieEnRoseEnergy[i], false);
if (player.isSkillDisabled(LaVieEnRoseEnergy[i]))
player.sendPacket(new SkillCoolTime(player));
}
else
player.removeSkill(LaVieEnRoseEnergy[i], false);
}
}
}
else
player.removeSkill(GreaterGemstoneBlessing[0], false);
if (!player.getInventory().isRefresh)
player.sendSkillList(false);
}
@Override
public boolean checkCondition(ItemInstance item)
{
return item.isJewel() && ArrayUtils.contains(Level6Jewels, item.getId());
}
}
}