if (itemToEnchant.isStackable() || ((stone = inventory.getItemByObjectId(stone.getObjectId())) == null))
{
activeChar.sendActionFailed();
return;
}
AttributeStoneInfo asi = AttributeStoneManager.getStoneInfo(stone.getItemId());
if (asi == null)
{
return;
}
Element element = itemToEnchant.isArmor() ? Element.getReverseElement(asi.getElement()) : asi.getElement();
if (itemToEnchant.isArmor())
{
if (itemToEnchant.getAttributeElementValue(Element.getReverseElement(element), false) != 0)
{
activeChar.sendPacket(Msg.ANOTHER_ELEMENTAL_POWER_HAS_ALREADY_BEEN_ADDED_THIS_ELEMENTAL_POWER_CANNOT_BE_ADDED, ActionFail.STATIC);
return;
}
}
else if (itemToEnchant.isWeapon())
{
if ((itemToEnchant.getAttributeElement() != Element.NONE) && (itemToEnchant.getAttributeElement() != element))
{
activeChar.sendPacket(Msg.ANOTHER_ELEMENTAL_POWER_HAS_ALREADY_BEEN_ADDED_THIS_ELEMENTAL_POWER_CANNOT_BE_ADDED, ActionFail.STATIC);
return;
}
}
else
{
activeChar.sendPacket(Msg.INAPPROPRIATE_ENCHANT_CONDITIONS, ActionFail.STATIC);
return;
}
if (item.isUnderwear() || item.isCloak() || item.isBracelet() || item.isBelt() || !item.isAttributable())
{
activeChar.sendPacket(Msg.INAPPROPRIATE_ENCHANT_CONDITIONS, ActionFail.STATIC);
return;
}
int maxValue = itemToEnchant.isWeapon() ? asi.getMaxWeapon() : asi.getMaxArmor();
int minValue = itemToEnchant.isWeapon() ? asi.getMinWeapon() : asi.getMinArmor();
int currentValue = itemToEnchant.getAttributeElementValue(element, false);
if ((currentValue >= maxValue) || (currentValue < minValue))
{
activeChar.sendPacket(Msg.ELEMENTAL_POWER_ENCHANCER_USAGE_HAS_BEEN_CANCELLED, ActionFail.STATIC);
return;
}
if (itemToEnchant.getOwnerId() != activeChar.getObjectId())
{
activeChar.sendPacket(Msg.INAPPROPRIATE_ENCHANT_CONDITIONS, ActionFail.STATIC);
return;
}
if (!inventory.destroyItem(stone, 1L))
{
activeChar.sendActionFailed();
return;
}
if (Rnd.chance(asi.getChance()))
{
if (itemToEnchant.getEnchantLevel() == 0)
{
SystemMessage sm = new SystemMessage(SystemMessage.S2_ELEMENTAL_POWER_HAS_BEEN_ADDED_SUCCESSFULLY_TO_S1);
sm.addItemName(itemToEnchant.getItemId());
sm.addItemName(stone.getItemId());
activeChar.sendPacket(sm);
}
else
{
SystemMessage sm = new SystemMessage(SystemMessage.S3_ELEMENTAL_POWER_HAS_BEEN_ADDED_SUCCESSFULLY_TO__S1S2);
sm.addNumber(itemToEnchant.getEnchantLevel());
sm.addItemName(itemToEnchant.getItemId());
sm.addItemName(stone.getItemId());
activeChar.sendPacket(sm);
}
int value = itemToEnchant.isWeapon() ? asi.getIncWeapon() : asi.getIncArmor();
if ((itemToEnchant.getAttributeElementValue(element, false) == 0) && itemToEnchant.isWeapon())
{
value = 20;
}
boolean equipped = itemToEnchant.isEquipped();