char __fastcall CItem::EnchantItem(
CItem *this,
CItem *pTargetItem,
User *pUser,
SkillFxChangeType bonusType,
long double bonusValue,
int nEnchantNumber)
{
int CrystalizeCount; // ebx
double EnchantSuccessRate; // xmm6_8
CSharedItemData *m_data; // rax
__int64 m_nEnchanted; // rsi
bool v15; // r12
double v16; // xmm10_8
double v17; // xmm9_8
double m_nMaxEnchantIncreaseRate; // xmm12_8
bool v19; // bp
double v20; // xmm8_8
CItem *PendingUseETCItem; // rax
CEnchantOptionDB *v22; // rbp
int v23; // eax
bool v24; // cc
CItem_vtbl *v25; // rax
int v26; // eax
CSharedItemConstant *m_const; // rcx
int m_Crystal; // eax
int v29; // ecx
double v30; // xmm6_8
double v31; // xmm0_8
double v32; // xmm0_8
int v33; // ecx
double v34; // xmm6_8
double v35; // xmm0_8
double v36; // xmm6_8
double v37; // xmm0_8
CItem *v38; // r15
int v39; // r12d
CUserSocket *v40; // rax
EtcItemType m_EtcitemType; // ecx
CSharedItemConstant *v42; // r8
__int64 v43; // rcx
int CrystalType; // esi
CUserSocket *v45; // rax
CUserSocket *v46; // rax
int CrystalCount; // [rsp+30h] [rbp-198h]
bool nEnchantProb; // [rsp+38h] [rbp-190h]
int v49; // [rsp+40h] [rbp-188h]
CItem *pSupportItem; // [rsp+48h] [rbp-180h]
SkillFxChangeType m_EnchantType; // [rsp+50h] [rbp-178h]
TshirtOptionType m_nEnchantOption; // [rsp+54h] [rbp-174h]
int v53; // [rsp+58h] [rbp-170h]
wchar_t _Buffer[100]; // [rsp+60h] [rbp-168h] BYREF
bool bLuckEnchant; // [rsp+1D8h] [rbp+10h]
CrystalizeCount = 0;
if ( !pTargetItem || !pUser )
return 0;
EnchantSuccessRate = DOUBLE_30_0;
m_nEnchantOption = pUser->m_SkillMod.m_nEnchantOption;
m_EnchantType = pUser->m_SkillMod.m_EnchantType;
m_data = pTargetItem->m_data;
m_nEnchanted = m_data->m_nEnchanted;
v15 = (m_data->m_Slot & 0x8000) != 0;
v16 = (double)pUser->m_SkillMod.m_nWeaponEnchantRate / 100.0;
v17 = (double)pUser->m_SkillMod.m_nArmorEnchantRate / 100.0;
m_nMaxEnchantIncreaseRate = (double)pUser->m_SkillMod.m_nMaxEnchantIncreaseRate;
v53 = -1;
bLuckEnchant = User::EventByLuckyStat(pUser, 0);
v49 = 0;
v19 = bLuckEnchant;
v20 = 0.0;
PendingUseETCItem = User::GetPendingUseETCItem(pUser, PUIT_INC_ENCHANT_PROP);
pSupportItem = PendingUseETCItem;
if ( !bLuckEnchant )
{
if ( PendingUseETCItem )
{
v49 = pUser->m_EnchantBonusOptions[2];
v53 = pUser->m_EnchantBonusOptions[1];
v20 = (double)pUser->m_EnchantBonusOptions[0];
}
v22 = CEnchantOptionDB::Inst();
v23 = pTargetItem->GetClassId(pTargetItem);
v24 = (int)CEnchantOptionDB::GetMaxEnchantLevel(v22, v23) <= 0;
v25 = pTargetItem->__vftable;
if ( !v24 )
{
v26 = v25->GetClassId(pTargetItem);
EnchantSuccessRate = (double)(int)CEnchantOptionDB::GetEnchantSuccessRate(v22, v26, m_nEnchanted);
goto LABEL_42;
}
if ( v25->IsWeapon(pTargetItem) )
{
m_const = pTargetItem->m_const;
m_Crystal = m_const->m_Crystal;
if ( m_Crystal >= 2 && m_const->m_bIsMagicWeapon )
{
if ( (int)m_nEnchanted >= 3 )
{
if ( (unsigned int)(m_Crystal - 8) > 2 )
{
v30 = DOUBLE_49_0;
if ( (int)m_nEnchanted >= 15 )
v30 = DOUBLE_24_5;
}
else
{
v29 = m_nEnchanted;
if ( (int)m_nEnchanted > 15 )
v29 = 15;
v30 = 1.0 / (double)((v29 + 3) / 3) * 100.0 / 1.4285;
}
EnchantSuccessRate = v30 + v20;
if ( bonusType )
{
if ( bonusType != SFCT_DIFF )
goto LABEL_24;
v31 = bonusValue * 100.0 + EnchantSuccessRate;
}
else
{
v31 = (bonusValue / 100.0 + 1.0) * EnchantSuccessRate;
}
EnchantSuccessRate = v31;
LABEL_24:
if ( m_EnchantType != SFCT_PER_DISTRICT || (unsigned int)m_nEnchantOption > WP )
goto LABEL_42;
v32 = fmin(EnchantSuccessRate * v16, m_nMaxEnchantIncreaseRate);
goto LABEL_40;
}
}
else if ( (int)m_nEnchanted >= 3 )
{
if ( (unsigned int)(m_Crystal - 8) > 2 )
{
v34 = DOUBLE_70_0;
if ( (int)m_nEnchanted >= 15 )
v34 = DOUBLE_35_0;
EnchantSuccessRate = v34 + v20;
if ( m_EnchantType == SFCT_PER_DISTRICT && (unsigned int)m_nEnchantOption <= WP )
EnchantSuccessRate = EnchantSuccessRate + fmin(EnchantSuccessRate * v16, m_nMaxEnchantIncreaseRate);
}
else
{
v33 = m_nEnchanted;
if ( (int)m_nEnchanted > 15 )
v33 = 15;
EnchantSuccessRate = 1.0 / (double)((v33 + 3) / 3) * 100.0 + v20;
}
if ( bonusType == SFCT_PER )
{
EnchantSuccessRate = EnchantSuccessRate * (bonusValue / 100.0 + 1.0);
goto LABEL_42;
}
if ( bonusType != SFCT_DIFF )
{
LABEL_42:
v19 = EnchantSuccessRate >= genrand64_real1() * 100.0 + 0.0;
LABEL_63:
v38 = pSupportItem;
v39 = v49;
goto LABEL_67;
}
v32 = bonusValue * 100.0;
LABEL_40:
EnchantSuccessRate = EnchantSuccessRate + v32;
goto LABEL_42;
}
}
else if ( (int)m_nEnchanted >= 3 )
{
if ( (int)m_nEnchanted >= 20 )
{
v36 = 0.0;
}
else
{
if ( v15 )
v35 = OnePieceEnchantFailTable[m_nEnchanted];
else
v35 = ArmorEnchantFailTable[m_nEnchanted];
v36 = 100.0 - v35 * 100.0;
}
if ( (int)m_nEnchanted >= 15 )
v36 = v36 * 0.5;
EnchantSuccessRate = v36 + v20;
if ( bonusType )
{
if ( bonusType == SFCT_DIFF )
EnchantSuccessRate = EnchantSuccessRate + bonusValue * 100.0;
}
else
{
EnchantSuccessRate = EnchantSuccessRate * (bonusValue / 100.0 + 1.0);
}
if ( m_EnchantType == SFCT_PER_DISTRICT && (m_nEnchantOption & 0xFFFFFFFD) == 0 )
EnchantSuccessRate = EnchantSuccessRate + fmin(EnchantSuccessRate * v17, m_nMaxEnchantIncreaseRate);
v37 = genrand64_real1() * 100.0 + 0.0;
if ( (int)m_nEnchanted >= 20 || (v19 = 1, EnchantSuccessRate < v37) )
v19 = 0;
goto LABEL_63;
}
v19 = 1;
EnchantSuccessRate = DOUBLE_100_0;
goto LABEL_63;
}
v38 = PendingUseETCItem;
if ( PendingUseETCItem )
v39 = pUser->m_EnchantBonusOptions[2];
else
v39 = 0;
LABEL_67:
if ( g_L2ServerType == DEV && User::IsBuilder(pUser) )
{
_snwprintf_s<100>(
(wchar_t (*)[100])_Buffer,
0x63ui64,
L"EnchantScrollItem [Prob:%d])",
(unsigned int)(int)EnchantSuccessRate);
v40 = pUser->GetSocket(pUser);
v40->SendSystemMessage(v40, L"SYS", _Buffer);
}
if ( !v19 )
{
if ( v53 )
{
if ( v53 > 0 )
{
LODWORD(m_nEnchanted) = m_nEnchanted - v53;
if ( (int)m_nEnchanted < 0 )
LODWORD(m_nEnchanted) = 0;
goto LABEL_74;
}
m_EtcitemType = this->m_const->m_EtcitemType;
if ( (unsigned int)(m_EtcitemType - 21) > 1 && m_EtcitemType != EIT_BLESS_ENCHT_AG )
{
if ( (unsigned int)(m_EtcitemType - 32) > 1 && m_EtcitemType != EIT_ANCIENT_CRYSTAL_ENCHANT_AG )
{
v42 = pTargetItem->m_const;
v43 = v42->m_Crystal;
CrystalType = *((_DWORD *)&loc_87CD80 + v43 + 0x100000);
if ( (unsigned int)(v43 - 1) <= 9 && v42->m_nCrystalCount > 0 )
CrystalizeCount = CItem::GetCrystalizeCount(pTargetItem, 2);
CDB::RequestEnchantItemFail(
&db,
this,
v38,
pTargetItem,
pUser,
CrystalType,
CrystalizeCount,
(int)EnchantSuccessRate);
return 1;
}
v45 = pUser->GetSocket(pUser);
CUserSocket::SendSystemMessage(v45, 6004);
goto LABEL_74;
}
v46 = pUser->GetSocket(pUser);
CUserSocket::SendSystemMessage(v46, 1517);
nEnchantProb = bLuckEnchant;
CrystalCount = (int)EnchantSuccessRate;
}
else
{
nEnchantProb = bLuckEnchant;
CrystalCount = (int)EnchantSuccessRate;
}
CDB::RequestEnchantItem(&db, this, v38, pTargetItem, 0, pUser, CrystalCount, nEnchantProb);
return 1;
}
LODWORD(m_nEnchanted) = nEnchantNumber + v39 + m_nEnchanted;
if ( pTargetItem->IsArmor(pTargetItem) && (int)m_nEnchanted > 20 )
LODWORD(m_nEnchanted) = 20;
LABEL_74:
CDB::RequestEnchantItem(&db, this, v38, pTargetItem, m_nEnchanted, pUser, (int)EnchantSuccessRate, bLuckEnchant);
return 1;
}