summaryrefslogtreecommitdiffstats
path: root/src/Item.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-06-13 21:35:30 +0200
committerLukas Pioch <lukas@zgow.de>2017-06-13 21:35:30 +0200
commit360d8eade0332f2c1aa5c205ca772cd506c35b26 (patch)
tree066fde557310742a39020bad9bc4aa2a5ef8d51a /src/Item.cpp
parentCorrected check for level of subcommand and fixed multiple levels not working (#3758) (diff)
downloadcuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar
cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.gz
cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.bz2
cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.lz
cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.xz
cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.zst
cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.zip
Diffstat (limited to 'src/Item.cpp')
-rw-r--r--src/Item.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/Item.cpp b/src/Item.cpp
index 2eb009d4a..fdce06d1c 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -332,9 +332,9 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
return false;
}
- cFastRandom Random;
- int ModifiedEnchantmentLevel = a_NumXPLevels + static_cast<int>(Random.NextFloat(static_cast<float>(Enchantability / 4))) + static_cast<int>(Random.NextFloat(static_cast<float>(Enchantability / 4))) + 1;
- float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F;
+ 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 FinalEnchantmentLevel = static_cast<int>(ModifiedEnchantmentLevel * RandomBonus + 0.5F);
cWeightedEnchantments Enchantments;
@@ -352,12 +352,10 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
// Checking for conflicting enchantments
cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment1);
- float NewEnchantmentLevel = static_cast<float>(a_NumXPLevels);
-
// Next Enchantment (Second)
- NewEnchantmentLevel = NewEnchantmentLevel / 2;
- float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
- if (Enchantments.empty() || (Random.NextFloat(100) > SecondEnchantmentChance))
+ float NewEnchantmentLevel = a_NumXPLevels / 2.0f;
+ float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
+ if (Enchantments.empty() || !Random.RandBool(SecondEnchantmentChance))
{
return true;
}
@@ -370,9 +368,9 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment2);
// Next Enchantment (Third)
- NewEnchantmentLevel = NewEnchantmentLevel / 2;
- float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
- if (Enchantments.empty() || (Random.NextFloat(100) > ThirdEnchantmentChance))
+ NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
+ float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
+ if (Enchantments.empty() || !Random.RandBool(ThirdEnchantmentChance))
{
return true;
}
@@ -385,9 +383,9 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment3);
// Next Enchantment (Fourth)
- NewEnchantmentLevel = NewEnchantmentLevel / 2;
- float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
- if (Enchantments.empty() || (Random.NextFloat(100) > FourthEnchantmentChance))
+ NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
+ float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
+ if (Enchantments.empty() || !Random.RandBool(FourthEnchantmentChance))
{
return true;
}