diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-04-24 19:57:25 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-04-24 19:57:25 +0200 |
commit | 48904ae201a38c4b6e018567976c00c40c2829c9 (patch) | |
tree | dfba8600b7f48e09c3c1d752b1cce1b4a45c8ea8 /src/Enchantments.cpp | |
parent | Some change to Entity.cpp (diff) | |
parent | The new leaves don't decay anymore. (diff) | |
download | cuberite-48904ae201a38c4b6e018567976c00c40c2829c9.tar cuberite-48904ae201a38c4b6e018567976c00c40c2829c9.tar.gz cuberite-48904ae201a38c4b6e018567976c00c40c2829c9.tar.bz2 cuberite-48904ae201a38c4b6e018567976c00c40c2829c9.tar.lz cuberite-48904ae201a38c4b6e018567976c00c40c2829c9.tar.xz cuberite-48904ae201a38c4b6e018567976c00c40c2829c9.tar.zst cuberite-48904ae201a38c4b6e018567976c00c40c2829c9.zip |
Diffstat (limited to 'src/Enchantments.cpp')
-rw-r--r-- | src/Enchantments.cpp | 787 |
1 files changed, 787 insertions, 0 deletions
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 9d4e23e0a..64f89815b 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" @@ -28,6 +29,18 @@ cEnchantments::cEnchantments(const AString & a_StringSpec) +void cEnchantments::Add(const cEnchantments & a_Other) +{ + for (cEnchantments::cMap::const_iterator itr = a_Other.m_Enchantments.begin(), end = a_Other.m_Enchantments.end(); itr != end; ++itr) + { + SetLevel(itr->first, itr->second); + } // for itr - a_Other.m_Enchantments[] +} + + + + + void cEnchantments::AddFromString(const AString & a_StringSpec) { // Add enchantments in the stringspec; if a specified enchantment already exists, overwrites it @@ -218,7 +231,781 @@ 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, enchSharpness, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 1); + } + + // Smite + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 1); + } + + // Bane of Arthropods + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 1); + } + + // Knockback + if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 1); + } + + // Fire Aspect + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 1); + } + + // Looting + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 1); + } + } + + else if (ItemCategory::IsTool(a_ItemType)) + { + // Efficiency + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 1); + } + + // Silk Touch + if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchSilkTouch, 1); + } + + // Fortune + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 1); + } + } + + else if (ItemCategory::IsArmor(a_ItemType)) + { + // Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 1); + } + + // Fire Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 4); + } + else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 3); + } + else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 1); + } + + // Blast Protection + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 1); + } + + // Projectile Protection + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 4); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 3); + } + else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 2); + } + else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 1); + } + + // Thorns + if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 3); + } + else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 1); + } + + + if (ItemCategory::IsHelmet(a_ItemType)) + { + // Respiration + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 3); + } + else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 1); + } + + // Aqua Affinity + if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchAquaAffinity, 1); + } + } + + else if (ItemCategory::IsBoots(a_ItemType)) + { + // Feather Fall + if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 4); + } + else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 1); + } + } + } + + else if (a_ItemType == E_ITEM_BOW) + { + // Power + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 1); + } + + // Punch + if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 2); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 1); + } + + // Flame and Infinity + if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchInfinity, 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, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 1); + } + } + + else if (a_ItemType == E_ITEM_BOOK) + { + // All Enchantments + + // Sharpness + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchSharpness, 1); + } + + // Smite + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchSmite, 1); + } + + // Bane of Arthropods + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 49)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchBaneOfArthropods, 1); + } + + // Knockback + if ((a_EnchantmentLevel >= 25) && (a_EnchantmentLevel <= 75)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchKnockback, 1); + } + + // Fire Aspect + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFireAspect, 1); + } + + // Looting + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchLooting, 1); + } + + // Efficiency + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 81)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 61)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 51)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchEfficiency, 1); + } + + // Silk Touch + if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchSilkTouch, 1); + } + + // Fortune + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFortune, 1); + } + + // Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 54)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 4); + } + else if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 43)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 3); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 32)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchProtection, 1); + } + + // Fire Protection + if ((a_EnchantmentLevel >= 34) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 4); + } + else if ((a_EnchantmentLevel >= 26) && (a_EnchantmentLevel <= 38)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 3); + } + else if ((a_EnchantmentLevel >= 18) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 22)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFireProtection, 1); + } + + // Blast Protection + if ((a_EnchantmentLevel >= 29) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 25)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 17)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchBlastProtection, 1); + } + + // Projectile Protection + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 4); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 30)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 3); + } + else if ((a_EnchantmentLevel >= 9) && (a_EnchantmentLevel <= 24)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 2); + } + else if ((a_EnchantmentLevel >= 3) && (a_EnchantmentLevel <= 18)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchProjectileProtection, 1); + } + + // Thorns + if ((a_EnchantmentLevel >= 50) && (a_EnchantmentLevel <= 100)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 3); + } + else if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 80)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchThorns, 1); + } + + // Respiration + if ((a_EnchantmentLevel >= 30) && (a_EnchantmentLevel <= 60)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 3); + } + else if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 2); + } + else if ((a_EnchantmentLevel >= 10) && (a_EnchantmentLevel <= 40)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchRespiration, 1); + } + + // Aqua Affinity + if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 41)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchAquaAffinity, 1); + } + + // Feather Fall + if ((a_EnchantmentLevel >= 23) && (a_EnchantmentLevel <= 33)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 4); + } + else if ((a_EnchantmentLevel >= 17) && (a_EnchantmentLevel <= 27)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 21)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 15)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchFeatherFalling, 1); + } + + // Power + if ((a_EnchantmentLevel >= 31) && (a_EnchantmentLevel <= 46)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 4); + } + else if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 36)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 3); + } + else if ((a_EnchantmentLevel >= 11) && (a_EnchantmentLevel <= 26)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 2); + } + else if ((a_EnchantmentLevel >= 1) && (a_EnchantmentLevel <= 16)) + { + AddEnchantmentWeightToVector(a_Enchantments, 10, enchPower, 1); + } + + // Punch + if ((a_EnchantmentLevel >= 32) && (a_EnchantmentLevel <= 57)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 2); + } + else if ((a_EnchantmentLevel >= 12) && (a_EnchantmentLevel <= 37)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchPunch, 1); + } + + // Flame and Infinity + if ((a_EnchantmentLevel >= 20) && (a_EnchantmentLevel <= 50)) + { + AddEnchantmentWeightToVector(a_Enchantments, 2, enchFlame, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchInfinity, 1); + } + + // Luck of the Sea and Lure + if ((a_EnchantmentLevel >= 33) && (a_EnchantmentLevel <= 83)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 3); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 3); + } + else if ((a_EnchantmentLevel >= 24) && (a_EnchantmentLevel <= 74)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 2); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 2); + } + else if ((a_EnchantmentLevel >= 15) && (a_EnchantmentLevel <= 65)) + { + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLuckOfTheSea, 1); + AddEnchantmentWeightToVector(a_Enchantments, 1, enchLure, 1); + } + } + + // Unbreaking + if ((a_EnchantmentLevel >= 21) && (a_EnchantmentLevel <= 71)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 3); + } + else if ((a_EnchantmentLevel >= 13) && (a_EnchantmentLevel <= 63)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 2); + } + else if ((a_EnchantmentLevel >= 5) && (a_EnchantmentLevel <= 55)) + { + AddEnchantmentWeightToVector(a_Enchantments, 5, enchUnbreaking, 1); + } +} + + + + + +void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel) +{ + cWeightedEnchantment weightedenchantment; + weightedenchantment.m_Weight = a_Weight; + cEnchantments enchantment; + enchantment.SetLevel(a_EnchantmentID, a_EnchantmentLevel); + weightedenchantment.m_Enchantments = enchantment; + a_Enchantments.push_back(weightedenchantment); +} + + + + + +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, int a_EnchantmentID) +{ + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + if ((*it).m_Enchantments.GetLevel(a_EnchantmentID) > 0) + { + a_Enchantments.erase(it); + break; + } + } +} + + + + + +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, const cEnchantments & a_Enchantment) +{ + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + if ((*it).m_Enchantments == a_Enchantment) + { + a_Enchantments.erase(it); + break; + } + } +} + + + + + +void cEnchantments::CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment) +{ + if (a_FirstEnchantment.GetLevel(cEnchantments::enchProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchFireProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchBlastProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProjectileProtection); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchProjectileProtection) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFireProtection); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBlastProtection); + } + + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSharpness) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSmite); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSmite) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchBaneOfArthropods); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchBaneOfArthropods) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSharpness); + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchSmite); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchSilkTouch) > 0) + { + RemoveEnchantmentWeightFromVector(a_Enchantments, cEnchantments::enchFortune); + } + else if (a_FirstEnchantment.GetLevel(cEnchantments::enchFortune) > 0) + { + 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); + for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it) + { + RandomNumber -= (*it).m_Weight; + if (RandomNumber < 0) + { + return (*it).m_Enchantments; + } + } + return cEnchantments(); +} |