summaryrefslogtreecommitdiffstats
path: root/src/Enchantments.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Enchantments.cpp')
-rw-r--r--src/Enchantments.cpp208
1 files changed, 183 insertions, 25 deletions
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp
index a18f6d68a..0047d09b8 100644
--- a/src/Enchantments.cpp
+++ b/src/Enchantments.cpp
@@ -167,6 +167,164 @@ bool cEnchantments::IsEmpty(void) const
+unsigned int cEnchantments::GetLevelCap(int a_EnchantmentID)
+{
+ switch (a_EnchantmentID)
+ {
+ case enchProtection: return 4;
+ case enchFireProtection: return 4;
+ case enchFeatherFalling: return 4;
+ case enchBlastProtection: return 4;
+ case enchProjectileProtection: return 4;
+ case enchRespiration: return 3;
+ case enchAquaAffinity: return 1;
+ case enchThorns: return 3;
+ case enchDepthStrider: return 3;
+ case enchSharpness: return 5;
+ case enchSmite: return 5;
+ case enchBaneOfArthropods: return 5;
+ case enchKnockback: return 2;
+ case enchFireAspect: return 2;
+ case enchLooting: return 3;
+ case enchEfficiency: return 5;
+ case enchSilkTouch: return 1;
+ case enchUnbreaking: return 3;
+ case enchFortune: return 3;
+ case enchPower: return 5;
+ case enchPunch: return 2;
+ case enchFlame: return 1;
+ case enchInfinity: return 1;
+ case enchLuckOfTheSea: return 3;
+ case enchLure: return 3;
+ }
+ LOGWARNING("Unknown enchantment ID %d", a_EnchantmentID);
+ return 0;
+}
+
+
+
+
+
+int cEnchantments::GetXPCostMultiplier(int a_EnchantmentID, bool FromBook)
+{
+ if (FromBook)
+ {
+ switch (a_EnchantmentID)
+ {
+ case enchProtection: return 1;
+ case enchFireProtection: return 1;
+ case enchFeatherFalling: return 1;
+ case enchBlastProtection: return 2;
+ case enchProjectileProtection: return 1;
+ case enchRespiration: return 2;
+ case enchAquaAffinity: return 2;
+ case enchThorns: return 4;
+ case enchDepthStrider: return 2;
+ case enchSharpness: return 1;
+ case enchSmite: return 1;
+ case enchBaneOfArthropods: return 1;
+ case enchKnockback: return 1;
+ case enchFireAspect: return 2;
+ case enchLooting: return 2;
+ case enchEfficiency: return 1;
+ case enchSilkTouch: return 4;
+ case enchUnbreaking: return 1;
+ case enchFortune: return 1;
+ case enchPower: return 1;
+ case enchPunch: return 2;
+ case enchFlame: return 2;
+ case enchInfinity: return 4;
+ case enchLuckOfTheSea: return 2;
+ case enchLure: return 2;
+ }
+ }
+ else // Without book
+ {
+ switch (a_EnchantmentID)
+ {
+ case enchProtection: return 1;
+ case enchFireProtection: return 2;
+ case enchFeatherFalling: return 2;
+ case enchBlastProtection: return 4;
+ case enchProjectileProtection: return 2;
+ case enchRespiration: return 4;
+ case enchAquaAffinity: return 4;
+ case enchThorns: return 8;
+ case enchDepthStrider: return 4;
+
+ case enchSharpness: return 1;
+ case enchSmite: return 2;
+ case enchBaneOfArthropods: return 2;
+ case enchKnockback: return 2;
+ case enchFireAspect: return 4;
+ case enchLooting: return 4;
+
+ case enchEfficiency: return 1;
+ case enchSilkTouch: return 8;
+ case enchUnbreaking: return 2;
+ case enchFortune: return 4;
+ case enchPower: return 1;
+ case enchPunch: return 4;
+ case enchFlame: return 4;
+ case enchInfinity: return 8;
+ case enchLuckOfTheSea: return 4;
+ case enchLure: return 4;
+ }
+ }
+ LOGWARNING("Unknown enchantment ID %d", a_EnchantmentID);
+ return 0;
+}
+
+
+
+
+
+bool cEnchantments::CanAddEnchantment(int a_EnchantmentID) const
+{
+ if (GetLevel(a_EnchantmentID) > 0)
+ {
+ return true;
+ }
+
+ static const std::vector<std::set<int> > IncompatibleEnchantments =
+ {
+ // Armor
+ { enchProtection, enchFireProtection, enchBlastProtection, enchProjectileProtection },
+
+ // Tool
+ { enchFortune, enchSilkTouch },
+
+ // Sword
+ { enchSharpness, enchSmite, enchBaneOfArthropods },
+
+ // Boots
+ // {enchDepthStrider, enchFrostWalker},
+
+ // Bow
+ // {enchInfinity, enchMending}
+ };
+
+ for (auto excl: IncompatibleEnchantments)
+ {
+ if (excl.count(a_EnchantmentID) != 0)
+ {
+ // See if we also have any of the enchantments
+ for (auto ench: excl)
+ {
+ if (GetLevel(ench) > 0)
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
+
+
+
+
int cEnchantments::StringToEnchantmentID(const AString & a_EnchantmentName)
{
static const struct
@@ -175,31 +333,31 @@ int cEnchantments::StringToEnchantmentID(const AString & a_EnchantmentName)
const char * m_Name;
} EnchantmentNames[] =
{
- { enchProtection, "Protection"},
- { enchFireProtection, "FireProtection"},
- { enchFeatherFalling, "FeatherFalling"},
- { enchBlastProtection, "BlastProtection"},
- { enchProjectileProtection, "ProjectileProtection"},
- { enchRespiration, "Respiration"},
- { enchAquaAffinity, "AquaAffinity"},
- { enchThorns, "Thorns"},
- { enchDepthStrider, "DepthStrider"},
- { enchSharpness, "Sharpness"},
- { enchSmite, "Smite"},
- { enchBaneOfArthropods, "BaneOfArthropods"},
- { enchKnockback, "Knockback"},
- { enchFireAspect, "FireAspect"},
- { enchLooting, "Looting"},
- { enchEfficiency, "Efficiency"},
- { enchSilkTouch, "SilkTouch"},
- { enchUnbreaking, "Unbreaking"},
- { enchFortune, "Fortune"},
- { enchPower, "Power"},
- { enchPunch, "Punch"},
- { enchFlame, "Flame"},
- { enchInfinity, "Infinity"},
- { enchLuckOfTheSea, "LuckOfTheSea"},
- { enchLure, "Lure"},
+ { enchProtection, "Protection" },
+ { enchFireProtection, "FireProtection" },
+ { enchFeatherFalling, "FeatherFalling" },
+ { enchBlastProtection, "BlastProtection" },
+ { enchProjectileProtection, "ProjectileProtection" },
+ { enchRespiration, "Respiration" },
+ { enchAquaAffinity, "AquaAffinity" },
+ { enchThorns, "Thorns" },
+ { enchDepthStrider, "DepthStrider" },
+ { enchSharpness, "Sharpness" },
+ { enchSmite, "Smite" },
+ { enchBaneOfArthropods, "BaneOfArthropods" },
+ { enchKnockback, "Knockback" },
+ { enchFireAspect, "FireAspect" },
+ { enchLooting, "Looting" },
+ { enchEfficiency, "Efficiency" },
+ { enchSilkTouch, "SilkTouch" },
+ { enchUnbreaking, "Unbreaking" },
+ { enchFortune, "Fortune" },
+ { enchPower, "Power" },
+ { enchPunch, "Punch" },
+ { enchFlame, "Flame" },
+ { enchInfinity, "Infinity" },
+ { enchLuckOfTheSea, "LuckOfTheSea" },
+ { enchLure, "Lure" },
} ;
// First try to parse as a number: