summaryrefslogtreecommitdiffstats
path: root/src/Item.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Item.cpp166
1 files changed, 94 insertions, 72 deletions
diff --git a/src/Item.cpp b/src/Item.cpp
index 1941a6693..9899d7f32 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -215,49 +215,66 @@ 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)
+ switch (m_ItemType)
{
- Enchantability = 1;
+ case E_ITEM_WOODEN_SWORD: Enchantability = 15;
+ case E_ITEM_WOODEN_PICKAXE: Enchantability = 15;
+ case E_ITEM_WOODEN_SHOVEL: Enchantability = 15;
+ case E_ITEM_WOODEN_AXE: Enchantability = 15;
+ case E_ITEM_WOODEN_HOE: Enchantability = 15;
+
+ case E_ITEM_LEATHER_CAP: Enchantability = 15;
+ case E_ITEM_LEATHER_TUNIC: Enchantability = 15;
+ case E_ITEM_LEATHER_PANTS: Enchantability = 15;
+ case E_ITEM_LEATHER_BOOTS: Enchantability = 15;
+
+ case E_ITEM_STONE_SWORD: Enchantability = 5;
+ case E_ITEM_STONE_PICKAXE: Enchantability = 5;
+ case E_ITEM_STONE_SHOVEL: Enchantability = 5;
+ case E_ITEM_STONE_AXE: Enchantability = 5;
+ case E_ITEM_STONE_HOE: Enchantability = 5;
+
+ case E_ITEM_IRON_HELMET: Enchantability = 9;
+ case E_ITEM_IRON_CHESTPLATE: Enchantability = 9;
+ case E_ITEM_IRON_LEGGINGS: Enchantability = 9;
+ case E_ITEM_IRON_BOOTS: Enchantability = 9;
+
+ case E_ITEM_IRON_SWORD: Enchantability = 14;
+ case E_ITEM_IRON_PICKAXE: Enchantability = 14;
+ case E_ITEM_IRON_SHOVEL: Enchantability = 14;
+ case E_ITEM_IRON_AXE: Enchantability = 14;
+ case E_ITEM_IRON_HOE: Enchantability = 14;
+
+ case E_ITEM_CHAIN_HELMET: Enchantability = 12;
+ case E_ITEM_CHAIN_CHESTPLATE: Enchantability = 12;
+ case E_ITEM_CHAIN_LEGGINGS: Enchantability = 12;
+ case E_ITEM_CHAIN_BOOTS: Enchantability = 12;
+
+ case E_ITEM_DIAMOND_HELMET: Enchantability = 10;
+ case E_ITEM_DIAMOND_CHESTPLATE: Enchantability = 10;
+ case E_ITEM_DIAMOND_LEGGINGS: Enchantability = 10;
+ case E_ITEM_DIAMOND_BOOTS: Enchantability = 10;
+
+ case E_ITEM_DIAMOND_SWORD: Enchantability = 10;
+ case E_ITEM_DIAMOND_PICKAXE: Enchantability = 10;
+ case E_ITEM_DIAMOND_SHOVEL: Enchantability = 10;
+ case E_ITEM_DIAMOND_AXE: Enchantability = 10;
+ case E_ITEM_DIAMOND_HOE: Enchantability = 10;
+
+ case E_ITEM_GOLD_HELMET: Enchantability = 25;
+ case E_ITEM_GOLD_CHESTPLATE: Enchantability = 25;
+ case E_ITEM_GOLD_LEGGINGS: Enchantability = 25;
+ case E_ITEM_GOLD_BOOTS: Enchantability = 25;
+
+ case E_ITEM_GOLD_SWORD: Enchantability = 22;
+ case E_ITEM_GOLD_PICKAXE: Enchantability = 22;
+ case E_ITEM_GOLD_SHOVEL: Enchantability = 22;
+ case E_ITEM_GOLD_AXE: Enchantability = 22;
+ case E_ITEM_GOLD_HOE: Enchantability = 22;
+
+ case E_ITEM_FISHING_ROD: Enchantability = 1;
+ case E_ITEM_BOW: Enchantability = 1;
+ case E_ITEM_BOOK: Enchantability = 1;
}
return Enchantability;
@@ -269,7 +286,7 @@ int cItem::GetEnchantability()
bool cItem::EnchantByXPLevels(int a_NumXPLevels)
{
- if (!cItem::IsEnchantable(m_ItemType) && m_ItemType != E_ITEM_BOOK)
+ if ((!cItem::IsEnchantable(m_ItemType)) && (m_ItemType != E_ITEM_BOOK))
{
return false;
}
@@ -284,9 +301,14 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
cWeightedEnchantments enchantments;
cEnchantments::AddItemEnchantmentWeights(enchantments, m_ItemType, FinalEnchantmentLevel);
+ if (m_ItemType == E_ITEM_BOOK)
+ {
+ m_ItemType = E_ITEM_ENCHANTED_BOOK;
+ }
+
cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
m_Enchantments.AddFromString(Enchantment1.ToString());
- cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment1);
+ cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment1);
// Checking for conflicting enchantments
cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1);
@@ -302,38 +324,38 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels)
{
cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
m_Enchantments.AddFromString(Enchantment2.ToString());
- cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment2);
+ cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment2);
// 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());
- cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment3);
-
- // 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());
+ // 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());
+ cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment3);
+
+ // 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());
+ }
+ }
+ }
+ }
}
}