summaryrefslogtreecommitdiffstats
path: root/src/ClientHandle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ClientHandle.cpp')
-rw-r--r--src/ClientHandle.cpp68
1 files changed, 53 insertions, 15 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index fc4db1d10..c00047ecd 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -2699,6 +2699,8 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment)
int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment);
+ LOG("499");
+
// Step 1 from Enchanting
int Enchantability = 1;
@@ -2744,7 +2746,7 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment)
}
cFastRandom Random;
- int ModifiedEnchantmentLevel = BaseEnchantmentLevel + Random.NextInt(Enchantability / 4) + Random.NextInt(Enchantability / 4) + 1;
+ int ModifiedEnchantmentLevel = BaseEnchantmentLevel + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1;
float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F;
int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F);
@@ -3090,28 +3092,64 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment)
enchantments = AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1"));
}
- int RandomEnchantment1 = floor(Random.NextFloat(1) * enchantments.size());
+ int RandomEnchantment1 = (int) floor(Random.NextFloat(1) * enchantments.size());
cEnchantments Enchantment1 = enchantments[RandomEnchantment1];
Item.m_Enchantments.AddFromString(Enchantment1.ToString());
enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end());
- // TODO: Don't add every time so much enchantments
+ float NewEnchantmentLevel = (float) BaseEnchantmentLevel;
+
+ // Next Enchantment (Second)
+ NewEnchantmentLevel = NewEnchantmentLevel / 2;
+ float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
+ if (Random.NextFloat(100) <= SecondEnchantmentChance)
+ {
+ // Checking for conflicting enchantments
+ enchantments = CheckEnchantmentConflicts(enchantments, Enchantment1);
+
+ if (enchantments.size() > 0)
+ {
+ int RandomEnchantment2 = (int) floor(Random.NextFloat(1) * enchantments.size());
+
+ cEnchantments Enchantment2 = enchantments[RandomEnchantment2];
+ Item.m_Enchantments.AddFromString(Enchantment2.ToString());
+ enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end());
- // Checking for conflicting enchantments
- enchantments = CheckEnchantmentConflicts(enchantments, Enchantment1);
+ // Checking for conflicting enchantments
+ enchantments = CheckEnchantmentConflicts(enchantments, Enchantment2);
+ }
+ }
- int RandomEnchantment2 = floor(Random.NextFloat(1) * enchantments.size());
- cEnchantments Enchantment2 = enchantments[RandomEnchantment2];
- Item.m_Enchantments.AddFromString(Enchantment2.ToString());
- enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end());
+ // Next Enchantment (Third)
+ NewEnchantmentLevel = NewEnchantmentLevel / 2;
+ float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
+ if (Random.NextFloat(100) <= ThirdEnchantmentChance)
+ {
+ if (enchantments.size() > 0)
+ {
+ int RandomEnchantment3 = (int) floor(Random.NextFloat(1) * enchantments.size());
+ cEnchantments Enchantment3 = enchantments[RandomEnchantment3];
+ Item.m_Enchantments.AddFromString(Enchantment3.ToString());
+ enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end());
- // Checking for conflicting enchantments
- enchantments = CheckEnchantmentConflicts(enchantments, Enchantment2);
+ // Checking for conflicting enchantments
+ enchantments = CheckEnchantmentConflicts(enchantments, Enchantment3);
+ }
+ }
- int RandomEnchantment3 = floor(Random.NextFloat(1) * enchantments.size());
- cEnchantments Enchantment3 = enchantments[RandomEnchantment3];
- Item.m_Enchantments.AddFromString(Enchantment3.ToString());
- enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end());
+ // Next Enchantment (Fourth)
+ NewEnchantmentLevel = NewEnchantmentLevel / 2;
+ float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
+ if (Random.NextFloat(100) <= FourthEnchantmentChance)
+ {
+ if (enchantments.size() > 0)
+ {
+ int RandomEnchantment4 = (int) floor(Random.NextFloat(1) * enchantments.size());
+ cEnchantments Enchantment4 = enchantments[RandomEnchantment4];
+ Item.m_Enchantments.AddFromString(Enchantment4.ToString());
+ enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end());
+ }
+ }
if (m_Player->DeltaExperience(-m_Player->XpForLevel(Window->GetPropertyValue(Enchantment))) >= 0 || m_Player->IsGameModeCreative())
{