char __thiscall CWorldItem::EnchantItem(CWorldItem *this, CWorldItem *itemToEnchant, CWorldUser *user)
{
int enchantLevel; // esi@3
CSharedItemConstData *constSharedData; // eax@4
CUserSocket *userSocket; // eax@11 MAPDST
double dice2; // st7@28
int itemClassId; // [sp-4h] [bp-3Ch]@11 MAPDST
int v11; // [sp+0h] [bp-38h]@1
double dice; // [sp+Ch] [bp-2Ch]@9
double chance; // [sp+14h] [bp-24h]@6
int *v15; // [sp+28h] [bp-10h]@1
int v16; // [sp+34h] [bp-4h]@1
v15 = &v11;
v16 = 0;
if ( !itemToEnchant ) // Add lock/unlock!!
{
return false;
}
enchantLevel = itemToEnchant->m_d.m_sharedData->enchantLevel;
if ( itemToEnchant->vtable->m_v.IsWeapon(itemToEnchant) )
{
constSharedData = itemToEnchant->m_d.m_constSharedData;
if ( constSharedData->crystalType >= 2 && constSharedData->isMagicWeapon )
{
chance = 100.0 - 60.0;
if ( enchantLevel < 3 )
{
LABEL_11:
userSocket = user->m_d.m_userSocket;
itemClassId = itemToEnchant->m_d.m_sharedData->itemClassId;
if ( enchantLevel )
{
CServerSocketBase::Send((CServerSocketBase *)userSocket, (const char *)"cdddddd", ServerToClientPacket_SystemMessage, SystemMessageId_s1s2_has_been_successfully_enchanted, 2, 1, enchantLevel, 3, itemClassId);
}
else
{
CServerSocketBase::Send((CServerSocketBase *)userSocket, (const char *)"cdddd", ServerToClientPacket_SystemMessage, SystemMessageId_s1_has_been_successfully_enchanted, 1, 3, itemClassId);
}
CDB::RequestEnchantItem(&g_cacheD, this, itemToEnchant, enchantLevel + 1, user);
return true;
}
if ( enchantLevel >= 15 )
{
chance = chance * 0.5;
}
dice = Utils::GetRandomNumber(0.0, 100.0);
if ( dice <= chance )
{
CLog::Add(&g_winlog, LOG_REQUEST, L"magic weapon enchant success, prev enchanted[%d], dice[%f], prob[%f]", enchantLevel, dice, chance);
goto LABEL_11;
}
CLog::Add(&g_winlog, LOG_REQUEST, L"magic weapon enchant fail, prev enchanted[%d], dice[%f], prob[%f]", enchantLevel, dice, chance);
}
else
{
chance = 100.0 - 30.0;
if ( enchantLevel < 3 )
{
goto LABEL_11;
}
if ( enchantLevel >= 15 )
{
chance = chance * 0.5;
}
dice = Utils::GetRandomNumber(0.0, 100.0);
if ( dice <= chance )
{
CLog::Add(&g_winlog, LOG_REQUEST, L"weapon enchant success, prev enchanted[%d], dice[%f], prob[%f]", enchantLevel, dice, chance);
goto LABEL_11;
}
CLog::Add(&g_winlog, LOG_REQUEST, L"weapon enchant fail, prev enchanted[%d], dice[%f], prob[%f]", enchantLevel, dice, chance);
}
}
else
{
if ( enchantLevel < 3 )
{
goto LABEL_11;
}
if ( enchantLevel >= 20 )
{
chance = 0.0;
}
else
{
chance = 100.0 - g_armorEnchantFailureChances[enchantLevel] * 100.0;
}
if ( enchantLevel >= 15 )
{
chance = chance * 0.5;
}
dice2 = Utils::GetRandomNumber(0.0, 100.0);
dice = dice2;
if ( enchantLevel < 20 && dice2 <= chance )
{
CLog::Add(&g_winlog, LOG_REQUEST, L"armor enchant success, prev enchanted[%d], dice[%f], prob[%f]", enchantLevel, dice, chance);
goto LABEL_11;
}
CLog::Add(&g_winlog, LOG_REQUEST, L"armor enchant fail, prev enchanted[%d], dice[%f], prob[%f]", enchantLevel, dice, chance);
}
userSocket = user->m_d.m_userSocket;
itemClassId = itemToEnchant->m_d.m_sharedData->itemClassId;
if ( enchantLevel )
{
CServerSocketBase::Send((CServerSocketBase *)userSocket, (const char *)"cdddddd", ServerToClientPacket_SystemMessage, SystemMessageId_Enchantment_has_failed_s1s2_has_been_evaporated, 2, 1, enchantLevel, 3, itemClassId);
}
else
{
CServerSocketBase::Send((CServerSocketBase *)userSocket, (const char *)"cdddd", ServerToClientPacket_SystemMessage, SystemMessageId_Enchantment_has_failed_s1_has_been_evaporated, 1, 3, itemClassId);
}
CDB::RequestEnchantItemFail(&g_cacheD, this, itemToEnchant, user);
return true;
}