summaryrefslogtreecommitdiffstats
path: root/src/Item.cpp
diff options
context:
space:
mode:
authorKingCol13 <48412633+KingCol13@users.noreply.github.com>2020-10-01 23:33:32 +0200
committerGitHub <noreply@github.com>2020-10-01 23:33:32 +0200
commit8947147c25e2640519897bfdc8807e97ee291d70 (patch)
tree63eca1e5bd8ad29ac9beba5a780d466c9bb13849 /src/Item.cpp
parentAdd SetBlockMeta warning in documentation (#4943) (diff)
downloadcuberite-8947147c25e2640519897bfdc8807e97ee291d70.tar
cuberite-8947147c25e2640519897bfdc8807e97ee291d70.tar.gz
cuberite-8947147c25e2640519897bfdc8807e97ee291d70.tar.bz2
cuberite-8947147c25e2640519897bfdc8807e97ee291d70.tar.lz
cuberite-8947147c25e2640519897bfdc8807e97ee291d70.tar.xz
cuberite-8947147c25e2640519897bfdc8807e97ee291d70.tar.zst
cuberite-8947147c25e2640519897bfdc8807e97ee291d70.zip
Diffstat (limited to 'src/Item.cpp')
-rw-r--r--src/Item.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/Item.cpp b/src/Item.cpp
index ca4210c75..60991d37a 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -429,7 +429,7 @@ int cItem::GetEnchantability()
-bool cItem::EnchantByXPLevels(int a_NumXPLevels)
+bool cItem::EnchantByXPLevels(int a_NumXPLevels, MTRand & a_Random)
{
if (!cItem::IsEnchantable(m_ItemType))
{
@@ -442,9 +442,8 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
return false;
}
- auto & Random = GetRandomProvider();
- int ModifiedEnchantmentLevel = a_NumXPLevels + Random.RandInt(Enchantability / 4) + Random.RandInt(Enchantability / 4) + 1;
- float RandomBonus = 1.0F + (Random.RandReal() + Random.RandReal() - 1.0F) * 0.15F;
+ int ModifiedEnchantmentLevel = a_NumXPLevels + a_Random.RandInt(Enchantability / 4) + a_Random.RandInt(Enchantability / 4) + 1;
+ float RandomBonus = 1.0F + (a_Random.RandReal() + a_Random.RandReal() - 1.0F) * 0.15F;
int FinalEnchantmentLevel = static_cast<int>(ModifiedEnchantmentLevel * RandomBonus + 0.5F);
cWeightedEnchantments Enchantments;
@@ -455,7 +454,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
m_ItemType = E_ITEM_ENCHANTED_BOOK;
}
- cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
+ cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
m_Enchantments.AddFromString(Enchantment1.ToString());
cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment1);
@@ -465,12 +464,12 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
// Next Enchantment (Second)
float NewEnchantmentLevel = a_NumXPLevels / 2.0f;
float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
- if (Enchantments.empty() || !Random.RandBool(SecondEnchantmentChance))
+ if (Enchantments.empty() || !a_Random.RandBool(SecondEnchantmentChance))
{
return true;
}
- cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
+ cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
m_Enchantments.AddFromString(Enchantment2.ToString());
cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment2);
@@ -480,12 +479,12 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
// Next Enchantment (Third)
NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
- if (Enchantments.empty() || !Random.RandBool(ThirdEnchantmentChance))
+ if (Enchantments.empty() || !a_Random.RandBool(ThirdEnchantmentChance))
{
return true;
}
- cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
+ cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
m_Enchantments.AddFromString(Enchantment3.ToString());
cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment3);
@@ -495,11 +494,11 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
// Next Enchantment (Fourth)
NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
- if (Enchantments.empty() || !Random.RandBool(FourthEnchantmentChance))
+ if (Enchantments.empty() || !a_Random.RandBool(FourthEnchantmentChance))
{
return true;
}
- cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
+ cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
m_Enchantments.AddFromString(Enchantment4.ToString());
return true;