summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ClientHandle.cpp877
1 files changed, 0 insertions, 877 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 406ca6e19..5876e55c7 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -31,8 +31,6 @@
#include "CompositeChat.h"
#include "Items/ItemSword.h"
-#include "FastRandom.h"
-
/** Maximum number of explosions to send this tick, server will start dropping if exceeded */
@@ -2687,879 +2685,4 @@ void cClientHandle::SocketClosed(void)
-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())
- {
- Window->m_SlotArea->SetSlot(0, *m_Player, Item);
- Window->SendSlot(*m_Player, Window->m_SlotArea, 0);
- Window->BroadcastWholeWindow();
-
- Window->SetProperty(0, 0, *m_Player);
- Window->SetProperty(1, 0, *m_Player);
- Window->SetProperty(2, 0, *m_Player);
- }
-}
-
-
-
-
-
-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);
- }
-}
-
-
-
-
-