summaryrefslogtreecommitdiffstats
path: root/src/ItemGrid.cpp
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2014-10-15 14:08:45 +0200
committerSTRWarrior <niels.breuker@hotmail.nl>2014-10-15 14:08:45 +0200
commite3aa6e48577f3247653e94a76b68a4626a630c65 (patch)
tree2efec4c43cab7bff0173ad68ef0ab4400addf6dd /src/ItemGrid.cpp
parentcWorld: Fixed scheduler. (diff)
downloadcuberite-e3aa6e48577f3247653e94a76b68a4626a630c65.tar
cuberite-e3aa6e48577f3247653e94a76b68a4626a630c65.tar.gz
cuberite-e3aa6e48577f3247653e94a76b68a4626a630c65.tar.bz2
cuberite-e3aa6e48577f3247653e94a76b68a4626a630c65.tar.lz
cuberite-e3aa6e48577f3247653e94a76b68a4626a630c65.tar.xz
cuberite-e3aa6e48577f3247653e94a76b68a4626a630c65.tar.zst
cuberite-e3aa6e48577f3247653e94a76b68a4626a630c65.zip
Diffstat (limited to 'src/ItemGrid.cpp')
-rw-r--r--src/ItemGrid.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp
index 2344dc0a5..68e753e08 100644
--- a/src/ItemGrid.cpp
+++ b/src/ItemGrid.cpp
@@ -637,7 +637,20 @@ void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, s
int Rnd = (Noise.IntNoise1DInt(i) / 7);
int LootRnd = Rnd % TotalProbab;
Rnd >>= 8;
- cItem CurrentLoot = cItem(E_ITEM_BOOK, 1, 0); // TODO: enchantment
+ cItem CurrentLoot = cItem(E_ITEM_ENCHANTED_BOOK, 1, 0);
+
+ // Choose the enchantments
+ cWeightedEnchantments Enchantments;
+ cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, 24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7);
+ int NumEnchantments = Noise.IntNoise3DInt(TotalProbab, Rnd, a_Seed) % 5; // The number of enchantments this book wil get.
+
+ for (int I = 0; I <= NumEnchantments; I++)
+ {
+ cEnchantments Enchantment = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Seed);
+ CurrentLoot.m_Enchantments.AddFromString(Enchantment.ToString());
+ cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment);
+ }
+
for (size_t j = 0; j < a_CountLootProbabs; j++)
{
LootRnd -= a_LootProbabs[i].m_Weight;