if ((item == null) || (scroll == null))
{
player.sendActionFailed();
return;
}
EnchantScrollInfo esi = EnchantScrollManager.getScrollInfo(scroll.getItemId());
if (esi == null)
{
player.sendActionFailed();
return;
}
if ((item.getEnchantLevel() >= esi.getMax()) || (item.getEnchantLevel() < esi.getMin()))
{
player.sendPacket(EnchantResult.CANCEL);
player.sendPacket(SystemMsg.INAPPROPRIATE_ENCHANT_CONDITIONS);
player.sendActionFailed();
return;
}
if (esi.getType() != EnchantScrollType.SPECIAL)
{
if (!checkItem(item, esi))
{
player.sendPacket(EnchantResult.CANCEL);
player.sendPacket(SystemMsg.DOES_NOT_FIT_STRENGTHENING_CONDITIONS_OF_THE_SCROLL);
player.sendActionFailed();
return;
}
}
if ((!inventory.destroyItem(scroll, 1)) || ((catalyst != null) && (!inventory.destroyItem(catalyst, 1))))
{
player.sendPacket(EnchantResult.CANCEL);
player.sendActionFailed();
return;
}
boolean equipped = item.isEquipped();
if (equipped)
{
inventory.isRefresh = true;
inventory.unEquipItem(item);
}
int safeEnchantLevel = item.getTemplate().getBodyPart() == 32768 ? (esi.getSafe() + 1) : esi.getSafe();
int chance = esi.getChance();
if (catalyst != null)
{
chance += ItemFunctions.getCatalystPower(catalyst.getItemId());
}
if ((esi.getType() == EnchantScrollType.ANCIENT) || (esi.getType() == EnchantScrollType.ITEM_MALL))
{
chance += 10;
}
if (esi.getType() == EnchantScrollType.DIVINE)
{
chance = 100;
}
if (item.getEnchantLevel() <= safeEnchantLevel)
{
chance = 100;
}
chance = Math.min(chance, 100);
if (item.isArmor())
WorldStatisticsManager.getInstance().updateStat(player, CategoryType.ARMOR_ENCHANT_TRY, item.getCrystalType().ordinal(), item.getEnchantLevel() + 1);
else if (item.isWeapon())
WorldStatisticsManager.getInstance().updateStat(player, CategoryType.WEAPON_ENCHANT_TRY, item.getCrystalType().ordinal(), item.getEnchantLevel() + 1);
if (Rnd.chance(chance))
{
item.setEnchantLevel(item.getEnchantLevel() + 1);
item.setJdbcState(JdbcEntityState.UPDATED);
item.update();
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);