summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordaniel0916 <theschokolps@gmail.com>2014-04-17 13:15:35 +0200
committerdaniel0916 <theschokolps@gmail.com>2014-04-17 13:15:35 +0200
commitf9343a8490b50cb28a62c7327c0013da48ca2745 (patch)
tree7951063e6dd38b923d2ef91ae8a8db41628f42e7
parentFixed conflicting enchantments checking (diff)
downloadcuberite-f9343a8490b50cb28a62c7327c0013da48ca2745.tar
cuberite-f9343a8490b50cb28a62c7327c0013da48ca2745.tar.gz
cuberite-f9343a8490b50cb28a62c7327c0013da48ca2745.tar.bz2
cuberite-f9343a8490b50cb28a62c7327c0013da48ca2745.tar.lz
cuberite-f9343a8490b50cb28a62c7327c0013da48ca2745.tar.xz
cuberite-f9343a8490b50cb28a62c7327c0013da48ca2745.tar.zst
cuberite-f9343a8490b50cb28a62c7327c0013da48ca2745.zip
Diffstat (limited to '')
-rw-r--r--src/ClientHandle.cpp857
-rw-r--r--src/ClientHandle.h3
-rw-r--r--src/Enchantments.cpp769
-rw-r--r--src/Enchantments.h30
-rw-r--r--src/Item.cpp141
-rw-r--r--src/Item.h7
-rw-r--r--src/Protocol/Protocol125.cpp2
-rw-r--r--src/UI/SlotArea.cpp66
-rw-r--r--src/UI/Window.cpp41
-rw-r--r--src/UI/Window.h2
10 files changed, 1000 insertions, 918 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 688441d39..a3d0501c3 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -31,8 +31,6 @@
#include "CompositeChat.h"
#include "Items/ItemSword.h"
-#include "FastRandom.h"
-
#include "md5/md5.h"
@@ -2735,774 +2733,9 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment)
{
cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow();
cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player);
-
- if (!cItem::IsEnchantable(Item.m_ItemType) && Item.m_ItemType != E_ITEM_BOOK)
- {
- return;
- }
-
int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment);
- // Step 1 from Enchanting
- int Enchantability = 1;
-
- if (Item.m_ItemType == E_ITEM_WOODEN_SWORD || Item.m_ItemType == E_ITEM_WOODEN_PICKAXE || Item.m_ItemType == E_ITEM_WOODEN_SHOVEL || Item.m_ItemType == E_ITEM_WOODEN_AXE || Item.m_ItemType == E_ITEM_WOODEN_HOE)
- {
- Enchantability = 15;
- }
- else if (Item.m_ItemType == E_ITEM_LEATHER_CAP || Item.m_ItemType == E_ITEM_LEATHER_TUNIC || Item.m_ItemType == E_ITEM_LEATHER_PANTS || Item.m_ItemType == E_ITEM_LEATHER_BOOTS)
- {
- Enchantability = 15;
- }
- else if (Item.m_ItemType == E_ITEM_STONE_SWORD || Item.m_ItemType == E_ITEM_STONE_PICKAXE || Item.m_ItemType == E_ITEM_STONE_SHOVEL || Item.m_ItemType == E_ITEM_STONE_AXE || Item.m_ItemType == E_ITEM_STONE_HOE)
- {
- Enchantability = 5;
- }
- else if (Item.m_ItemType == E_ITEM_IRON_HELMET || Item.m_ItemType == E_ITEM_IRON_CHESTPLATE || Item.m_ItemType == E_ITEM_IRON_LEGGINGS || Item.m_ItemType == E_ITEM_IRON_BOOTS)
- {
- Enchantability = 9;
- }
- else if (Item.m_ItemType == E_ITEM_IRON_SWORD || Item.m_ItemType == E_ITEM_IRON_PICKAXE || Item.m_ItemType == E_ITEM_IRON_SHOVEL || Item.m_ItemType == E_ITEM_IRON_AXE || Item.m_ItemType == E_ITEM_IRON_HOE)
- {
- Enchantability = 14;
- }
- else if (Item.m_ItemType == E_ITEM_CHAIN_HELMET || Item.m_ItemType == E_ITEM_CHAIN_CHESTPLATE || Item.m_ItemType == E_ITEM_CHAIN_LEGGINGS || Item.m_ItemType == E_ITEM_CHAIN_BOOTS)
- {
- Enchantability = 12;
- }
- else if (Item.m_ItemType == E_ITEM_DIAMOND_HELMET || Item.m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || Item.m_ItemType == E_ITEM_DIAMOND_LEGGINGS || Item.m_ItemType == E_ITEM_DIAMOND_BOOTS)
- {
- Enchantability = 10;
- }
- else if (Item.m_ItemType == E_ITEM_DIAMOND_SWORD || Item.m_ItemType == E_ITEM_DIAMOND_PICKAXE || Item.m_ItemType == E_ITEM_DIAMOND_SHOVEL || Item.m_ItemType == E_ITEM_DIAMOND_AXE || Item.m_ItemType == E_ITEM_DIAMOND_HOE)
- {
- Enchantability = 10;
- }
- else if (Item.m_ItemType == E_ITEM_GOLD_HELMET || Item.m_ItemType == E_ITEM_GOLD_CHESTPLATE || Item.m_ItemType == E_ITEM_GOLD_LEGGINGS || Item.m_ItemType == E_ITEM_GOLD_BOOTS)
- {
- Enchantability = 25;
- }
- else if (Item.m_ItemType == E_ITEM_GOLD_SWORD || Item.m_ItemType == E_ITEM_GOLD_PICKAXE || Item.m_ItemType == E_ITEM_GOLD_SHOVEL || Item.m_ItemType == E_ITEM_GOLD_AXE || Item.m_ItemType == E_ITEM_GOLD_HOE)
- {
- Enchantability = 22;
- }
-
- cFastRandom Random;
- 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);
-
- // Step 2 and 3 from Enchanting
- cEnchantmentsVector enchantments;
-
- if (ItemCategory::IsSword(Item.m_ItemType))
- {
- // Sharpness
- if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4"));
- }
- else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3"));
- }
- else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1"));
- }
-
- // Smite
- if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3"));
- }
- else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1"));
- }
-
- // Bane of Arthropods
- if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3"));
- }
- else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1"));
- }
-
- // Knockback
- if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1"));
- }
-
- // Fire Aspect
- if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1"));
- }
-
- // Looting
- if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3"));
- }
- else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1"));
- }
- }
-
- else if (ItemCategory::IsTool(Item.m_ItemType))
- {
- // Efficiency
- if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3"));
- }
- else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1"));
- }
-
- // Silk Touch
- if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1"));
- }
-
- // Fortune
- if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3"));
- }
- else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1"));
- }
- }
-
- else if (ItemCategory::IsArmor(Item.m_ItemType))
- {
- // Protection
- if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4"));
- }
- else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3"));
- }
- else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1"));
- }
-
- // Fire Protection
- if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4"));
- }
- else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3"));
- }
- else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1"));
- }
-
- // Blast Protection
- if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3"));
- }
- else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1"));
- }
-
- // Projectile Protection
- if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3"));
- }
- else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2"));
- }
- else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1"));
- }
-
- // Thorns
- if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3"));
- }
- else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1"));
- }
-
-
- if (ItemCategory::IsHelmet(Item.m_ItemType))
- {
- // Respiration
- if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3"));
- }
- else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1"));
- }
-
- // Aqua Affinity
- if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1"));
- }
- }
-
- else if (ItemCategory::IsBoots(Item.m_ItemType))
- {
- // Feather Fall
- if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4"));
- }
- else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3"));
- }
- else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1"));
- }
- }
- }
-
- else if (Item.m_ItemType == E_ITEM_BOW)
- {
- // Power
- if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3"));
- }
- else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1"));
- }
-
- // Punch
- if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2"));
- }
- else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1"));
- }
-
- // Flame and Infinity
- if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1"));
- }
- }
-
- else if (Item.m_ItemType == E_ITEM_FISHING_ROD)
- {
- // Luck of the Sea and Lure
- if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3"));
- }
- else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1"));
- }
- }
-
- else if (Item.m_ItemType == E_ITEM_BOOK)
- {
- // All enchantments
-
- // Sharpness
- if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=4"));
- }
- else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=3"));
- }
- else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Sharpness=1"));
- }
-
- // Smite
- if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=3"));
- }
- else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Smite=1"));
- }
-
- // Bane of Arthropods
- if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 49)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=3"));
- }
- else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 25)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("BaneOfArthropods=1"));
- }
-
- // Knockback
- if (FinalEnchantmentLevel >= 25 && FinalEnchantmentLevel <= 75)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Knockback=1"));
- }
-
- // Fire Aspect
- if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("FireAspect=1"));
- }
-
- // Looting
- if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=3"));
- }
- else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=2"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Looting=1"));
- }
-
- // Efficiency
- if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 81)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=3"));
- }
- else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 61)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 51)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Efficiency=1"));
- }
-
- // Silk Touch
- if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("SilkTouch=1"));
- }
-
- // Fortune
- if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=3"));
- }
- else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=2"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Fortune=1"));
- }
-
- // Protection
- if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 54)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=4"));
- }
- else if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 43)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=3"));
- }
- else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 32)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 21)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Protection=1"));
- }
-
- // Fire Protection
- if (FinalEnchantmentLevel >= 34 && FinalEnchantmentLevel <= 46)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=4"));
- }
- else if (FinalEnchantmentLevel >= 26 && FinalEnchantmentLevel <= 38)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=3"));
- }
- else if (FinalEnchantmentLevel >= 18 && FinalEnchantmentLevel <= 30)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 22)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FireProtection=1"));
- }
-
- // Blast Protection
- if (FinalEnchantmentLevel >= 29 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=3"));
- }
- else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 25)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 17)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("BlastProtection=1"));
- }
-
- // Projectile Protection
- if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=4"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 30)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=3"));
- }
- else if (FinalEnchantmentLevel >= 9 && FinalEnchantmentLevel <= 24)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=2"));
- }
- else if (FinalEnchantmentLevel >= 3 && FinalEnchantmentLevel <= 18)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("ProjectileProtection=1"));
- }
-
- // Thorns
- if (FinalEnchantmentLevel >= 50 && FinalEnchantmentLevel <= 100)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=3"));
- }
- else if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 80)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 60)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Thorns=1"));
- }
-
- // Respiration
- if (FinalEnchantmentLevel >= 30 && FinalEnchantmentLevel <= 60)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=3"));
- }
- else if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=2"));
- }
- else if (FinalEnchantmentLevel >= 10 && FinalEnchantmentLevel <= 40)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Respiration=1"));
- }
-
- // Aqua Affinity
- if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 41)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("AquaAffinity=1"));
- }
-
- // Feather Fall
- if (FinalEnchantmentLevel >= 23 && FinalEnchantmentLevel <= 33)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=4"));
- }
- else if (FinalEnchantmentLevel >= 17 && FinalEnchantmentLevel <= 27)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=3"));
- }
- else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 21)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 15)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("FeatherFalling=1"));
- }
-
- // Power
- if (FinalEnchantmentLevel >= 31 && FinalEnchantmentLevel <= 46)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=4"));
- }
- else if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 36)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=3"));
- }
- else if (FinalEnchantmentLevel >= 11 && FinalEnchantmentLevel <= 26)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=2"));
- }
- else if (FinalEnchantmentLevel >= 1 && FinalEnchantmentLevel <= 16)
- {
- AddEnchantmentWeight(enchantments, 10, cEnchantments("Power=1"));
- }
-
- // Punch
- if (FinalEnchantmentLevel >= 32 && FinalEnchantmentLevel <= 57)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=2"));
- }
- else if (FinalEnchantmentLevel >= 12 && FinalEnchantmentLevel <= 37)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Punch=1"));
- }
-
- // Flame and Infinity
- if (FinalEnchantmentLevel >= 20 && FinalEnchantmentLevel <= 50)
- {
- AddEnchantmentWeight(enchantments, 2, cEnchantments("Flame=1"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Infinity=1"));
- }
-
- // Luck of the Sea and Lure
- if (FinalEnchantmentLevel >= 33 && FinalEnchantmentLevel <= 83)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=3"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=3"));
- }
- else if (FinalEnchantmentLevel >= 24 && FinalEnchantmentLevel <= 74)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=2"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=2"));
- }
- else if (FinalEnchantmentLevel >= 15 && FinalEnchantmentLevel <= 65)
- {
- AddEnchantmentWeight(enchantments, 1, cEnchantments("LuckOfTheSea=1"));
- AddEnchantmentWeight(enchantments, 1, cEnchantments("Lure=1"));
- }
-
- Item.m_ItemType = E_ITEM_ENCHANTED_BOOK;
- }
-
- // Unbreaking
- if (FinalEnchantmentLevel >= 21 && FinalEnchantmentLevel <= 71)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=3"));
- }
- else if (FinalEnchantmentLevel >= 13 && FinalEnchantmentLevel <= 63)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=2"));
- }
- else if (FinalEnchantmentLevel >= 5 && FinalEnchantmentLevel <= 55)
- {
- AddEnchantmentWeight(enchantments, 5, cEnchantments("Unbreaking=1"));
- }
-
- 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());
-
- 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
- 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
- CheckEnchantmentConflicts(enchantments, Enchantment2);
- }
- }
-
- // 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
- CheckEnchantmentConflicts(enchantments, Enchantment3);
- }
- }
-
- // 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())
+ if (Item.EnchantByXPLevels(BaseEnchantmentLevel, *m_Player, true, true))
{
Window->m_SlotArea->SetSlot(0, *m_Player, Item);
Window->SendSlot(*m_Player, Window->m_SlotArea, 0);
@@ -3517,91 +2750,3 @@ void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment)
-
-void cClientHandle::AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment)
-{
- for (int i = 0; i < a_Weight; i++)
- {
- a_Enchantments.push_back(a_Enchantment);
- }
-}
-
-
-
-
-
-void cClientHandle::RemoveEnchantmentFromVector(cEnchantmentsVector * a_Enchantments, int a_EnchantmentID)
-{
- for (cEnchantmentsVector::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it)
- {
- int EnchantmentID = atoi(StringSplit((*it).ToString(), "=")[0].c_str());
-
- if (EnchantmentID == a_EnchantmentID)
- {
- a_Enchantments->erase(std::remove(a_Enchantments->begin(), a_Enchantments->end(), *it), a_Enchantments->end());
- break;
- }
- }
-}
-
-
-
-
-
-void cClientHandle::CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment)
-{
- int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str());
-
- if (FirstEnchantmentID == cEnchantments::enchProtection)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection);
- }
- else if (FirstEnchantmentID == cEnchantments::enchFireProtection)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection);
- }
- else if (FirstEnchantmentID == cEnchantments::enchBlastProtection)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection);
- }
- else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFireProtection);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBlastProtection);
- }
-
- else if (FirstEnchantmentID == cEnchantments::enchSharpness)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSmite);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods);
- }
- else if (FirstEnchantmentID == cEnchantments::enchSmite)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSharpness);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods);
- }
- else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSharpness);
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSmite);
- }
- else if (FirstEnchantmentID == cEnchantments::enchSilkTouch)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchFortune);
- }
- else if (FirstEnchantmentID == cEnchantments::enchFortune)
- {
- RemoveEnchantmentFromVector(&a_Enchantments, cEnchantments::enchSilkTouch);
- }
-}
-
-
-
-
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 1829e3b4d..3d01d8034 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -248,9 +248,6 @@ public:
/** Called when the player will enchant a Item */
void HandleEnchantItem(Byte & WindowID, Byte & Enchantment);
- void AddEnchantmentWeight(cEnchantmentsVector & a_Enchantments, int a_Weight, cEnchantments a_Enchantment);
- void RemoveEnchantmentFromVector(cEnchantmentsVector * a_Enchantments, int a_EnchantmentID);
- void CheckEnchantmentConflicts(cEnchantmentsVector & a_Enchantments, cEnchantments a_FirstEnchantment);
private:
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp
index 9d4e23e0a..3caebdff5 100644
--- a/src/Enchantments.cpp
+++ b/src/Enchantments.cpp
@@ -5,6 +5,7 @@
#include "Globals.h"
#include "Enchantments.h"
#include "WorldStorage/FastNBT.h"
+#include "FastRandom.h"
@@ -218,6 +219,774 @@ bool cEnchantments::operator !=(const cEnchantments & a_Other) const
+void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short & a_ItemType, int a_EnchantmentLevel)
+{
+ if (ItemCategory::IsSword(a_ItemType))
+ {
+ // Sharpness
+ if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=4"));
+ }
+ else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=3"));
+ }
+ else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=1"));
+ }
+
+ // Smite
+ if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=3"));
+ }
+ else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=1"));
+ }
+
+ // Bane of Arthropods
+ if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=3"));
+ }
+ else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=1"));
+ }
+
+ // Knockback
+ if (a_EnchantmentLevel >= 25 && a_EnchantmentLevel <= 75)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=1"));
+ }
+
+ // Fire Aspect
+ if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=1"));
+ }
+
+ // Looting
+ if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=3"));
+ }
+ else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=2"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=1"));
+ }
+ }
+
+ else if (ItemCategory::IsTool(a_ItemType))
+ {
+ // Efficiency
+ if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 81)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=3"));
+ }
+ else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 61)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 51)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=1"));
+ }
+
+ // Silk Touch
+ if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("SilkTouch=1"));
+ }
+
+ // Fortune
+ if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=3"));
+ }
+ else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=2"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=1"));
+ }
+ }
+
+ else if (ItemCategory::IsArmor(a_ItemType))
+ {
+ // Protection
+ if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=4"));
+ }
+ else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=3"));
+ }
+ else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=1"));
+ }
+
+ // Fire Protection
+ if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 46)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=4"));
+ }
+ else if (a_EnchantmentLevel >= 26 && a_EnchantmentLevel <= 38)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=3"));
+ }
+ else if (a_EnchantmentLevel >= 18 && a_EnchantmentLevel <= 30)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 22)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=1"));
+ }
+
+ // Blast Protection
+ if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=3"));
+ }
+ else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 25)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 17)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=1"));
+ }
+
+ // Projectile Protection
+ if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=4"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 30)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=3"));
+ }
+ else if (a_EnchantmentLevel >= 9 && a_EnchantmentLevel <= 24)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=2"));
+ }
+ else if (a_EnchantmentLevel >= 3 && a_EnchantmentLevel <= 18)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=1"));
+ }
+
+ // Thorns
+ if (a_EnchantmentLevel >= 50 && a_EnchantmentLevel <= 100)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=3"));
+ }
+ else if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=1"));
+ }
+
+
+ if (ItemCategory::IsHelmet(a_ItemType))
+ {
+ // Respiration
+ if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 60)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=3"));
+ }
+ else if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 40)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=1"));
+ }
+
+ // Aqua Affinity
+ if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("AquaAffinity=1"));
+ }
+ }
+
+ else if (ItemCategory::IsBoots(a_ItemType))
+ {
+ // Feather Fall
+ if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=4"));
+ }
+ else if (a_EnchantmentLevel >= 17 && a_EnchantmentLevel <= 27)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=3"));
+ }
+ else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 21)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 15)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=1"));
+ }
+ }
+ }
+
+ else if (a_ItemType == E_ITEM_BOW)
+ {
+ // Power
+ if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 46)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=3"));
+ }
+ else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 26)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 16)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=1"));
+ }
+
+ // Punch
+ if (a_EnchantmentLevel >= 32 && a_EnchantmentLevel <= 57)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=2"));
+ }
+ else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 37)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=1"));
+ }
+
+ // Flame and Infinity
+ if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Flame=1"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Infinity=1"));
+ }
+ }
+
+ else if (a_ItemType == E_ITEM_FISHING_ROD)
+ {
+ // Luck of the Sea and Lure
+ if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=3"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=3"));
+ }
+ else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=2"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=2"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=1"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=1"));
+ }
+ }
+
+ else if (a_ItemType == E_ITEM_BOOK)
+ {
+ // All &a_Enchantments
+
+ // Sharpness
+ if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=4"));
+ }
+ else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=3"));
+ }
+ else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Sharpness=1"));
+ }
+
+ // Smite
+ if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=3"));
+ }
+ else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Smite=1"));
+ }
+
+ // Bane of Arthropods
+ if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 49)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=3"));
+ }
+ else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 25)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("BaneOfArthropods=1"));
+ }
+
+ // Knockback
+ if (a_EnchantmentLevel >= 25 && a_EnchantmentLevel <= 75)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Knockback=1"));
+ }
+
+ // Fire Aspect
+ if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("FireAspect=1"));
+ }
+
+ // Looting
+ if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=3"));
+ }
+ else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=2"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Looting=1"));
+ }
+
+ // Efficiency
+ if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 81)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=3"));
+ }
+ else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 61)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 51)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Efficiency=1"));
+ }
+
+ // Silk Touch
+ if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("SilkTouch=1"));
+ }
+
+ // Fortune
+ if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=3"));
+ }
+ else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=2"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Fortune=1"));
+ }
+
+ // Protection
+ if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 54)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=4"));
+ }
+ else if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 43)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=3"));
+ }
+ else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 32)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 21)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Protection=1"));
+ }
+
+ // Fire Protection
+ if (a_EnchantmentLevel >= 34 && a_EnchantmentLevel <= 46)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=4"));
+ }
+ else if (a_EnchantmentLevel >= 26 && a_EnchantmentLevel <= 38)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=3"));
+ }
+ else if (a_EnchantmentLevel >= 18 && a_EnchantmentLevel <= 30)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 22)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FireProtection=1"));
+ }
+
+ // Blast Protection
+ if (a_EnchantmentLevel >= 29 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=3"));
+ }
+ else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 25)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 17)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("BlastProtection=1"));
+ }
+
+ // Projectile Protection
+ if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=4"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 30)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=3"));
+ }
+ else if (a_EnchantmentLevel >= 9 && a_EnchantmentLevel <= 24)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=2"));
+ }
+ else if (a_EnchantmentLevel >= 3 && a_EnchantmentLevel <= 18)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("ProjectileProtection=1"));
+ }
+
+ // Thorns
+ if (a_EnchantmentLevel >= 50 && a_EnchantmentLevel <= 100)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=3"));
+ }
+ else if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 80)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 60)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Thorns=1"));
+ }
+
+ // Respiration
+ if (a_EnchantmentLevel >= 30 && a_EnchantmentLevel <= 60)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=3"));
+ }
+ else if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=2"));
+ }
+ else if (a_EnchantmentLevel >= 10 && a_EnchantmentLevel <= 40)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Respiration=1"));
+ }
+
+ // Aqua Affinity
+ if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 41)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("AquaAffinity=1"));
+ }
+
+ // Feather Fall
+ if (a_EnchantmentLevel >= 23 && a_EnchantmentLevel <= 33)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=4"));
+ }
+ else if (a_EnchantmentLevel >= 17 && a_EnchantmentLevel <= 27)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=3"));
+ }
+ else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 21)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 15)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("FeatherFalling=1"));
+ }
+
+ // Power
+ if (a_EnchantmentLevel >= 31 && a_EnchantmentLevel <= 46)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=4"));
+ }
+ else if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 36)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=3"));
+ }
+ else if (a_EnchantmentLevel >= 11 && a_EnchantmentLevel <= 26)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=2"));
+ }
+ else if (a_EnchantmentLevel >= 1 && a_EnchantmentLevel <= 16)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 10, cEnchantments("Power=1"));
+ }
+
+ // Punch
+ if (a_EnchantmentLevel >= 32 && a_EnchantmentLevel <= 57)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=2"));
+ }
+ else if (a_EnchantmentLevel >= 12 && a_EnchantmentLevel <= 37)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Punch=1"));
+ }
+
+ // Flame and Infinity
+ if (a_EnchantmentLevel >= 20 && a_EnchantmentLevel <= 50)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 2, cEnchantments("Flame=1"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Infinity=1"));
+ }
+
+ // Luck of the Sea and Lure
+ if (a_EnchantmentLevel >= 33 && a_EnchantmentLevel <= 83)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=3"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=3"));
+ }
+ else if (a_EnchantmentLevel >= 24 && a_EnchantmentLevel <= 74)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=2"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=2"));
+ }
+ else if (a_EnchantmentLevel >= 15 && a_EnchantmentLevel <= 65)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("LuckOfTheSea=1"));
+ AddEnchantmentWeightToVector(&a_Enchantments, 1, cEnchantments("Lure=1"));
+ }
+
+ a_ItemType = E_ITEM_ENCHANTED_BOOK;
+ }
+
+ // Unbreaking
+ if (a_EnchantmentLevel >= 21 && a_EnchantmentLevel <= 71)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=3"));
+ }
+ else if (a_EnchantmentLevel >= 13 && a_EnchantmentLevel <= 63)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=2"));
+ }
+ else if (a_EnchantmentLevel >= 5 && a_EnchantmentLevel <= 55)
+ {
+ AddEnchantmentWeightToVector(&a_Enchantments, 5, cEnchantments("Unbreaking=1"));
+ }
+}
+
+
+
+
+
+void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment)
+{
+ cWeightedEnchantment enchantment;
+ enchantment.m_Weight = a_Weight;
+ enchantment.m_Enchantments = a_Enchantment;
+ a_Enchantments->push_back(enchantment);
+}
+
+
+
+
+
+void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID)
+{
+ for (cWeightedEnchantments::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it)
+ {
+ int EnchantmentID = atoi(StringSplit((*it).m_Enchantments.ToString(), "=")[0].c_str());
+
+ if (EnchantmentID == a_EnchantmentID)
+ {
+ a_Enchantments->erase(std::remove(a_Enchantments->begin(), a_Enchantments->end(), *it), a_Enchantments->end());
+ break;
+ }
+ }
+}
+
+
+
+
+
+void cEnchantments::CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment)
+{
+ int FirstEnchantmentID = atoi(StringSplit(a_FirstEnchantment.ToString(), "=")[0].c_str());
+
+ if (FirstEnchantmentID == cEnchantments::enchProtection)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection);
+ }
+ else if (FirstEnchantmentID == cEnchantments::enchFireProtection)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection);
+ }
+ else if (FirstEnchantmentID == cEnchantments::enchBlastProtection)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProjectileProtection);
+ }
+ else if (FirstEnchantmentID == cEnchantments::enchProjectileProtection)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFireProtection);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBlastProtection);
+ }
+
+ else if (FirstEnchantmentID == cEnchantments::enchSharpness)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSmite);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods);
+ }
+ else if (FirstEnchantmentID == cEnchantments::enchSmite)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSharpness);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchBaneOfArthropods);
+ }
+ else if (FirstEnchantmentID == cEnchantments::enchBaneOfArthropods)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSharpness);
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSmite);
+ }
+ else if (FirstEnchantmentID == cEnchantments::enchSilkTouch)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchFortune);
+ }
+ else if (FirstEnchantmentID == cEnchantments::enchFortune)
+ {
+ RemoveEnchantmentWeightFromVector(&a_Enchantments, cEnchantments::enchSilkTouch);
+ }
+}
+
+
+
+
+
+cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments)
+{
+ cFastRandom Random;
+
+ int AllWeights = 0;
+ for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it)
+ {
+ AllWeights += (*it).m_Weight;
+ }
+ int RandomNumber = Random.GenerateRandomInteger(0, AllWeights - 1);
+ cEnchantments enchantment;
+ for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it)
+ {
+ RandomNumber -= (*it).m_Weight;
+ if (RandomNumber < 0)
+ {
+ return (*it).m_Enchantments;
+ }
+ }
+}
+
+
+
+
+
+
diff --git a/src/Enchantments.h b/src/Enchantments.h
index 70d6b6613..1d226330a 100644
--- a/src/Enchantments.h
+++ b/src/Enchantments.h
@@ -8,7 +8,9 @@
#pragma once
+#include "Defines.h"
#include "WorldStorage/EnchantmentSerializer.h"
+#include "Entities/Player.h"
@@ -29,7 +31,6 @@ Level value of 0 means no such enchantment, and it will not be stored in the m_E
Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs.
*/
-typedef std::vector<cEnchantments> cEnchantmentsVector;
// tolua_begin
class cEnchantments
@@ -94,9 +95,24 @@ public:
/// Returns true if a_Other contains exactly the same enchantments and levels
bool operator ==(const cEnchantments & a_Other) const;
-
+
// tolua_end
+
+ /** Add enchantment weights from item to the vector */
+ static void AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short & a_ItemType, int a_EnchantmentLevel);
+
+ /** Add a enchantment weight to the vector */
+ static void AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment);
+ /** Remove a enchantment weight from the vector */
+ static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID);
+
+ /** Check enchantment conflicts from enchantments from the vector */
+ static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment);
+
+ /** Gets random enchantment from Vector and returns it */
+ static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments);
+
/// Returns true if a_Other doesn't contain exactly the same enchantments and levels
bool operator !=(const cEnchantments & a_Other) const;
@@ -115,5 +131,15 @@ protected:
} ; // tolua_export
+/** Things below for the Enchanting System */
+struct cWeightedEnchantment
+{
+ int m_Weight;
+ cEnchantments m_Enchantments;
+};
+
+typedef std::vector<cWeightedEnchantment> cWeightedEnchantments;
+
+
diff --git a/src/Item.cpp b/src/Item.cpp
index 856b68be6..8bc25d242 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -5,6 +5,8 @@
#include "json/json.h"
#include "Items/ItemHandler.h"
+#include "FastRandom.h"
+
@@ -209,6 +211,145 @@ bool cItem::IsEnchantable(short item)
+int cItem::GetEnchantability()
+{
+ int Enchantability = 0;
+
+ if (m_ItemType == E_ITEM_WOODEN_SWORD || m_ItemType == E_ITEM_WOODEN_PICKAXE || m_ItemType == E_ITEM_WOODEN_SHOVEL || m_ItemType == E_ITEM_WOODEN_AXE || m_ItemType == E_ITEM_WOODEN_HOE)
+ {
+ Enchantability = 15;
+ }
+ else if (m_ItemType == E_ITEM_LEATHER_CAP || m_ItemType == E_ITEM_LEATHER_TUNIC || m_ItemType == E_ITEM_LEATHER_PANTS || m_ItemType == E_ITEM_LEATHER_BOOTS)
+ {
+ Enchantability = 15;
+ }
+ else if (m_ItemType == E_ITEM_STONE_SWORD || m_ItemType == E_ITEM_STONE_PICKAXE || m_ItemType == E_ITEM_STONE_SHOVEL || m_ItemType == E_ITEM_STONE_AXE || m_ItemType == E_ITEM_STONE_HOE)
+ {
+ Enchantability = 5;
+ }
+ else if (m_ItemType == E_ITEM_IRON_HELMET || m_ItemType == E_ITEM_IRON_CHESTPLATE || m_ItemType == E_ITEM_IRON_LEGGINGS || m_ItemType == E_ITEM_IRON_BOOTS)
+ {
+ Enchantability = 9;
+ }
+ else if (m_ItemType == E_ITEM_IRON_SWORD || m_ItemType == E_ITEM_IRON_PICKAXE || m_ItemType == E_ITEM_IRON_SHOVEL || m_ItemType == E_ITEM_IRON_AXE || m_ItemType == E_ITEM_IRON_HOE)
+ {
+ Enchantability = 14;
+ }
+ else if (m_ItemType == E_ITEM_CHAIN_HELMET || m_ItemType == E_ITEM_CHAIN_CHESTPLATE || m_ItemType == E_ITEM_CHAIN_LEGGINGS || m_ItemType == E_ITEM_CHAIN_BOOTS)
+ {
+ Enchantability = 12;
+ }
+ else if (m_ItemType == E_ITEM_DIAMOND_HELMET || m_ItemType == E_ITEM_DIAMOND_CHESTPLATE || m_ItemType == E_ITEM_DIAMOND_LEGGINGS || m_ItemType == E_ITEM_DIAMOND_BOOTS)
+ {
+ Enchantability = 10;
+ }
+ else if (m_ItemType == E_ITEM_DIAMOND_SWORD || m_ItemType == E_ITEM_DIAMOND_PICKAXE || m_ItemType == E_ITEM_DIAMOND_SHOVEL || m_ItemType == E_ITEM_DIAMOND_AXE || m_ItemType == E_ITEM_DIAMOND_HOE)
+ {
+ Enchantability = 10;
+ }
+ else if (m_ItemType == E_ITEM_GOLD_HELMET || m_ItemType == E_ITEM_GOLD_CHESTPLATE || m_ItemType == E_ITEM_GOLD_LEGGINGS || m_ItemType == E_ITEM_GOLD_BOOTS)
+ {
+ Enchantability = 25;
+ }
+ else if (m_ItemType == E_ITEM_GOLD_SWORD || m_ItemType == E_ITEM_GOLD_PICKAXE || m_ItemType == E_ITEM_GOLD_SHOVEL || m_ItemType == E_ITEM_GOLD_AXE || m_ItemType == E_ITEM_GOLD_HOE)
+ {
+ Enchantability = 22;
+ }
+ else if (m_ItemType == E_ITEM_FISHING_ROD || m_ItemType == E_ITEM_BOW || m_ItemType == E_ITEM_BOOK)
+ {
+ Enchantability = 1;
+ }
+
+ return Enchantability;
+}
+
+
+
+
+
+bool cItem::EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_BlockConflictingEnchantments, bool a_DeleteLevelFromPlayer)
+{
+ if (!cItem::IsEnchantable(m_ItemType) && m_ItemType != E_ITEM_BOOK)
+ {
+ return false;
+ }
+
+ int Enchantability = GetEnchantability();
+
+ cFastRandom Random;
+ int ModifiedEnchantmentLevel = a_NumXPLevels + (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);
+
+ cWeightedEnchantments enchantments;
+ cEnchantments::AddItemEnchantmentWeights(enchantments, m_ItemType, FinalEnchantmentLevel);
+
+ cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ m_Enchantments.AddFromString(Enchantment1.ToString());
+ enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end());
+
+ // Checking for conflicting enchantments
+ cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1);
+
+ float NewEnchantmentLevel = (float)a_NumXPLevels;
+
+ // Next Enchantment (Second)
+ NewEnchantmentLevel = NewEnchantmentLevel / 2;
+ float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
+ if (Random.NextFloat(100) <= SecondEnchantmentChance)
+ {
+ if (enchantments.size() > 0)
+ {
+ cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ m_Enchantments.AddFromString(Enchantment2.ToString());
+ enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end());
+
+ // Checking for conflicting enchantments
+ cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2);
+ }
+ }
+
+ // Next Enchantment (Third)
+ NewEnchantmentLevel = NewEnchantmentLevel / 2;
+ float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
+ if (Random.NextFloat(100) <= ThirdEnchantmentChance)
+ {
+ if (enchantments.size() > 0)
+ {
+ cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ m_Enchantments.AddFromString(Enchantment3.ToString());
+ enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end());
+
+ // Checking for conflicting enchantments
+ cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3);
+ }
+ }
+
+ // Next Enchantment (Fourth)
+ NewEnchantmentLevel = NewEnchantmentLevel / 2;
+ float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
+ if (Random.NextFloat(100) <= FourthEnchantmentChance)
+ {
+ if (enchantments.size() > 0)
+ {
+ cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ m_Enchantments.AddFromString(Enchantment4.ToString());
+ enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end());
+ }
+ }
+
+ if (a_Player.DeltaExperience(-a_Player.XpForLevel(a_NumXPLevels)) >= 0 || a_Player.IsGameModeCreative())
+ {
+ return true;
+ }
+
+ return false;
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cItems:
diff --git a/src/Item.h b/src/Item.h
index 910ecb382..987dea2a9 100644
--- a/src/Item.h
+++ b/src/Item.h
@@ -175,6 +175,13 @@ public:
/** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */
static bool IsEnchantable(short a_ItemType); // tolua_export
+ /** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */
+ int GetEnchantability(); // tolua_export
+
+ /** Enchants the item using the specified number of XP levels.
+ Returns true if item enchanted, false if not. */
+ bool EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_BlockConflictingEnchantments, bool a_DeleteLevelFromPlayer); // tolua_export
+
// tolua_begin
short m_ItemType;
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 6cf611d90..9b8db0b7b 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1646,8 +1646,6 @@ int cProtocol125::ParseEnchantItem(void)
HANDLE_PACKET_READ(ReadByte, Byte, WindowID);
HANDLE_PACKET_READ(ReadByte, Byte, Enchantment);
- LOGWARN("Older Protocol: Enchantment Packet received!");
-
m_Client->HandleEnchantItem(WindowID, Enchantment);
return PARSE_OK;
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 621854518..26fdfe928 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -802,7 +802,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
}
else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK)
{
- int Bookshelves = GetBookshelvesCount(a_Player.GetWorld());
+ int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15);
cFastRandom Random;
int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves));
@@ -835,24 +835,58 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World)
cBlockArea Area;
Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2);
- for (int y = 0; y <= 2; y++)
+ static const struct
{
- for (int x = 0; x <= 4; x++)
+ int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases
+ int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won\'t be counted
+ } CheckCoords[] =
+ {
+ { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1}
+ { 0, 0, 1, 1, 0, 1 }, // Bookcase at {0, 0, 1}, air at {1, 0, 1}
+ { 0, 0, 2, 1, 0, 2 }, // Bookcase at {0, 0, 2}, air at {1, 0, 2}
+ { 0, 0, 3, 1, 0, 3 }, // Bookcase at {0, 0, 3}, air at {1, 0, 3}
+ { 0, 0, 4, 1, 0, 3 }, // Bookcase at {0, 0, 4}, air at {1, 0, 3}
+ { 1, 0, 4, 1, 0, 3 }, // Bookcase at {1, 0, 4}, air at {1, 0, 3}
+ { 2, 0, 4, 2, 0, 3 }, // Bookcase at {2, 0, 4}, air at {2, 0, 3}
+ { 3, 0, 4, 3, 0, 3 }, // Bookcase at {3, 0, 4}, air at {3, 0, 3}
+ { 4, 0, 4, 3, 0, 3 }, // Bookcase at {4, 0, 4}, air at {3, 0, 3}
+ { 4, 0, 3, 3, 0, 3 }, // Bookcase at {4, 0, 3}, air at {3, 0, 3}
+ { 4, 0, 2, 3, 0, 2 }, // Bookcase at {4, 0, 2}, air at {3, 0, 2}
+ { 4, 0, 1, 3, 0, 1 }, // Bookcase at {4, 0, 1}, air at {3, 0, 1}
+ { 4, 0, 0, 3, 0, 1 }, // Bookcase at {4, 0, 0}, air at {3, 0, 1}
+ { 3, 0, 0, 3, 0, 1 }, // Bookcase at {3, 0, 0}, air at {3, 0, 1}
+ { 2, 0, 0, 2, 0, 1 }, // Bookcase at {2, 0, 0}, air at {2, 0, 1}
+ { 1, 0, 0, 1, 0, 1 }, // Bookcase at {1, 0, 0}, air at {1, 0, 1}
+
+ { 0, 1, 0, 1, 1, 1 }, // Bookcase at {0, 1, 0}, air at {1, 1, 1}
+ { 0, 1, 1, 1, 1, 1 }, // Bookcase at {0, 1, 1}, air at {1, 1, 1}
+ { 0, 1, 2, 1, 1, 2 }, // Bookcase at {0, 1, 2}, air at {1, 1, 2}
+ { 0, 1, 3, 1, 1, 3 }, // Bookcase at {0, 1, 3}, air at {1, 1, 3}
+ { 0, 1, 4, 1, 1, 3 }, // Bookcase at {0, 1, 4}, air at {1, 1, 3}
+ { 1, 1, 4, 1, 1, 3 }, // Bookcase at {1, 1, 4}, air at {1, 1, 3}
+ { 2, 1, 4, 2, 1, 3 }, // Bookcase at {2, 1, 4}, air at {2, 1, 3}
+ { 3, 1, 4, 3, 1, 3 }, // Bookcase at {3, 1, 4}, air at {3, 1, 3}
+ { 4, 1, 4, 3, 1, 3 }, // Bookcase at {4, 1, 4}, air at {3, 1, 3}
+ { 4, 1, 3, 3, 1, 3 }, // Bookcase at {4, 1, 3}, air at {3, 1, 3}
+ { 4, 1, 2, 3, 1, 2 }, // Bookcase at {4, 1, 2}, air at {3, 1, 2}
+ { 4, 1, 1, 3, 1, 1 }, // Bookcase at {4, 1, 1}, air at {3, 1, 1}
+ { 4, 1, 0, 3, 1, 1 }, // Bookcase at {4, 1, 0}, air at {3, 1, 1}
+ { 3, 1, 0, 3, 1, 1 }, // Bookcase at {3, 1, 0}, air at {3, 1, 1}
+ { 2, 1, 0, 2, 1, 1 }, // Bookcase at {2, 1, 0}, air at {2, 1, 1}
+ { 1, 1, 0, 1, 1, 1 }, // Bookcase at {1, 1, 0}, air at {1, 1, 1}
+ };
+
+ for (size_t i = 0; i < ARRAYCOUNT(CheckCoords); i++)
+ {
+ if (
+ (Area.GetRelBlockType(CheckCoords[i].m_AirX, CheckCoords[i].m_AirY, CheckCoords[i].m_AirZ) == E_BLOCK_AIR) && // There's air in the checkspot
+ (Area.GetRelBlockType(CheckCoords[i].m_BookX, CheckCoords[i].m_BookY, CheckCoords[i].m_BookZ) == E_BLOCK_BOOKCASE) // There's bookcase in the wanted place
+ )
{
- for (int z = 0; z <= 4; z++)
- {
- if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1))
- {
- if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE)
- {
- Bookshelves++;
- }
- }
- }
+ Bookshelves++;
}
- }
-
- Bookshelves = std::min(Bookshelves, 15);
+ } // for i - CheckCoords
+
return Bookshelves;
}
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index c7b9b6aaf..fffe0e3fd 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -824,18 +824,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
void cEnchantingWindow::SetProperty(int a_Property, int a_Value)
{
- if (a_Property == 0)
- {
- m_PropertyValue0 = a_Value;
- }
- else if (a_Property == 1)
- {
- m_PropertyValue1 = a_Value;
- }
- else if (a_Property == 2)
- {
- m_PropertyValue2 = a_Value;
- }
+ m_PropertyValue[a_Property] = a_Value;
cCSLock Lock(m_CS);
for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr)
@@ -850,18 +839,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value)
void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player)
{
- if (a_Property == 0)
- {
- m_PropertyValue0 = a_Value;
- }
- else if (a_Property == 1)
- {
- m_PropertyValue1 = a_Value;
- }
- else if (a_Property == 2)
- {
- m_PropertyValue2 = a_Value;
- }
+ m_PropertyValue[a_Property] = a_Value;
a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
}
@@ -872,20 +850,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla
int cEnchantingWindow::GetPropertyValue(int a_Property)
{
- if (a_Property == 0)
- {
- return m_PropertyValue0;
- }
- else if (a_Property == 1)
- {
- return m_PropertyValue1;
- }
- else if (a_Property == 2)
- {
- return m_PropertyValue2;
- }
-
- return -1;
+ return m_PropertyValue[a_Property];
}
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 5e799248c..1ca67bfd8 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -249,7 +249,7 @@ public:
cSlotArea * m_SlotArea;
protected:
- int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2;
+ int m_PropertyValue[3];
int m_BlockX, m_BlockY, m_BlockZ;
};