if (equipped)
{
inventory.equipItem(item);
inventory.isRefresh = false;
}
player.sendPacket(new InventoryUpdate().addModifiedItem(item));
if (item.isArmor())
WorldStatisticsManager.getInstance().updateStat(player, CategoryType.ARMOR_ENCHANT_MAX, item.getCrystalType().ordinal(), item.getEnchantLevel());
if (item.isWeapon())
WorldStatisticsManager.getInstance().updateStat(player, CategoryType.WEAPON_ENCHANT_MAX, item.getCrystalType().ordinal(), item.getEnchantLevel());
player.sendPacket(new EnchantResult(0, 0, 0L, item.getEnchantLevel()));
if (Config.SHOW_ENCHANT_EFFECT_RESULT)
{
player.broadcastPacket(new L2GameServerPacket[] { new SystemMessage(3013).addName(player).addNumber(item.getEnchantLevel()).addItemName(item.getItemId()) });
player.broadcastPacket(new L2GameServerPacket[] { new MagicSkillUse(player, player, 5965, 1, 500, 1500L) });
}
}
else
{
switch (esi.getType())
{
case NORMAL:
if (item.isEquipped())
{
player.sendDisarmMessage(item);
}
if (!inventory.destroyItem(item, 1L))
{
player.sendActionFailed();
return;
}
int crystalId = item.getCrystalType().cry;
if ((crystalId > 0) && (item.getTemplate().getCrystalCount() > 0))
{
int crystalAmount = (int) (item.getTemplate().getCrystalCount() * 0.87D);
if (item.getEnchantLevel() > 3)
{
crystalAmount = (int) (crystalAmount + (item.getTemplate().getCrystalCount() * 0.25D * (item.getEnchantLevel() - 3)));
}
if (crystalAmount < 1)
{
crystalAmount = 1;
}
player.sendPacket(new EnchantResult(1, crystalId, crystalAmount));
ItemFunctions.addItem(player, crystalId, crystalAmount, true);
}
else
{
player.sendPacket(EnchantResult.FAILED_NO_CRYSTALS);
}
break;
case DESTRUCTION:
item.setEnchantLevel(item.getEnchantLevel());
item.setJdbcState(JdbcEntityState.UPDATED);
item.update();
if (equipped)
{
inventory.equipItem(item);
inventory.isRefresh = false;
}
player.sendPacket(new InventoryUpdate().addModifiedItem(item));
player.sendPacket(SystemMsg.THE_BLESSED_ENCHANT_FAILED);
player.sendPacket(EnchantResult.ANCIENT_FAILED);
break;
case BLESSED:
case ITEM_MALL:
case CRYSTALL:
item.setEnchantLevel(0);
item.setJdbcState(JdbcEntityState.UPDATED);
item.update();
if (equipped)
{
inventory.equipItem(item);
inventory.isRefresh = false;
}
player.sendPacket(new InventoryUpdate().addModifiedItem(item));
player.sendPacket(SystemMsg.THE_BLESSED_ENCHANT_FAILED);
player.sendPacket(EnchantResult.BLESSED_FAILED);
break;
case ANCIENT:
player.sendPacket(EnchantResult.ANCIENT_FAILED);