package handler.bypass;
import l2p.commons.dao.JdbcEntityState;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.instances.NpcInstance;
import l2p.gameserver.model.items.ItemInstance;
import l2p.gameserver.network.serverpackets.InventoryUpdate;
import l2p.gameserver.utils.ItemUtils;
import l2p.gameserver.utils.Log;
import l2p.gameserver.utils.Util;
public class PowerShirtExchange extends ScriptBypassHandler
{
private static final String[] _commandList = new String[] { "exchangePowerShirtStep1", "exchangePowerShirtStep2" };
private static final long _exchangePrice = 100_000_000;
private static final int[] _powerShirt = { 21580, 21706 };
@Override
public void onBypassFeedback(NpcInstance npc, Player player, String command, String[] params)
{
if (command.equalsIgnoreCase("exchangePowerShirtStep1"))
{
npc.showChatWindow(player, 1, "%price%", Util.formatAdena(_exchangePrice));
}
else if (command.equalsIgnoreCase("exchangePowerShirtStep2"))
{
if (!ItemUtils.checkItemCount(player, 57, _exchangePrice))
return;
ItemInstance shirt = null;
for (ItemInstance item : player.getInventory().getItemsByItemId(_powerShirt))
if (item.getEnchantLevel() == 8 || item.getEnchantLevel() == 9)
{
shirt = item;
break;
}
if (shirt == null)
{
player.sendPopupMessage("Рубашек Ольфа с заточкой +8/+9 в вашем инвентаре не найдено.");
return;
}
if (ItemUtils.removeItem(player, 57, _exchangePrice, true) != _exchangePrice)
return;
int oldEnchant = shirt.getEnchantLevel();
boolean equipped = false;
if (equipped = shirt.isEquipped())
{
player.getInventory().isRefresh = true;
player.getInventory().unEquipItem(shirt);
}
shirt.setEnchantLevel(10);
shirt.setJdbcState(JdbcEntityState.UPDATED);
shirt.update();
if (equipped)
{
player.getInventory().equipItem(shirt);
player.getInventory().isRefresh = false;
}
player.sendPacket(new InventoryUpdate().addModifiedItem(shirt));
player.sendPopupMessage("Рубашка Ольфа +" + oldEnchant + " обменяна на такую же рубашку +10.");
Log.logEnchant(player.getName() + "|ExchangePowerShirt|" + shirt.getName() + " (" + shirt.getItemId() + ") [" + shirt.getObjectId() + "]|+" + oldEnchant + " -> +" + shirt.getEnchantLevel());
}
}
@Override
public String[] getBypasses()
{
return _commandList;
}
}