From 36120db400691be75199ff404e35f5c289b8818f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 31 Jan 2014 19:46:51 +0100 Subject: Some updates for enchanting (2) --- src/Item.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 9170006b6..fb561d7b2 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -189,6 +189,112 @@ bool cItem::IsEnchantable(short item) +void cItem::GetApplicableEnchantmentsForType(short a_ItemType, cEnchantmentsArray & a_Enchantments) +{ + LOGWARN("Get Enchantments"); + + if (ItemCategory::IsSword(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("Sharpness=4")); + a_Enchantments.push_back(cEnchantments("Smite=5")); + a_Enchantments.push_back(cEnchantments("BaneOfArthropods=5")); + a_Enchantments.push_back(cEnchantments("Knockback=2")); + a_Enchantments.push_back(cEnchantments("FireAspect=2")); + a_Enchantments.push_back(cEnchantments("Looting=3")); + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + } + + else if (ItemCategory::IsPickaxe(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("Efficiency=4")); + a_Enchantments.push_back(cEnchantments("SilkTouch=1")); + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + a_Enchantments.push_back(cEnchantments("Fortune=3")); + } + + else if (ItemCategory::IsAxe(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("Efficiency=4")); + a_Enchantments.push_back(cEnchantments("SilkTouch=1")); + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + a_Enchantments.push_back(cEnchantments("Fortune=3")); + } + + else if (ItemCategory::IsShovel(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("Efficiency=4")); + a_Enchantments.push_back(cEnchantments("SilkTouch=1")); + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + a_Enchantments.push_back(cEnchantments("Fortune=3")); + } + + else if (ItemCategory::IsHoe(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + } + + else if (ItemCategory::IsArmor(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("Protection=4")); + a_Enchantments.push_back(cEnchantments("FireProtection=4")); + a_Enchantments.push_back(cEnchantments("BlastProtection=4")); + a_Enchantments.push_back(cEnchantments("ProjectileProtection=4")); + a_Enchantments.push_back(cEnchantments("Thorns=3")); + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + + if (ItemCategory::IsHelmet(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("Respiration=3")); + a_Enchantments.push_back(cEnchantments("AquaAffinity=1")); + } + + else if (ItemCategory::IsBoots(a_ItemType)) + { + a_Enchantments.push_back(cEnchantments("FeatherFalling=4")); + } + } + + //Bow + else if (a_ItemType == 261) + { + a_Enchantments.push_back(cEnchantments("Power=4")); + a_Enchantments.push_back(cEnchantments("Punch=2")); + a_Enchantments.push_back(cEnchantments("Flame=1")); + a_Enchantments.push_back(cEnchantments("Infinity=1")); + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + } + + //Fishing Rod + else if (a_ItemType == 346) + { + a_Enchantments.push_back(cEnchantments("LuckOfTheSea=3")); + a_Enchantments.push_back(cEnchantments("Lure=3")); + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + } + + //Shears + else if (a_ItemType == 359) + { + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + } + + //Flint and Steel + else if (a_ItemType == 259) + { + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + } + + //Carrot on a Stick + else if (a_ItemType == 398) + { + a_Enchantments.push_back(cEnchantments("Unbreaking=3")); + } +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cItems: -- cgit v1.2.3 From e6e702e7fdbc8b7475d3dbecc0f81a08304997ae Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Apr 2014 14:58:46 +0200 Subject: Added complete Enchanting System http://minecraft.gamepedia.com/Enchantment_mechanics --- src/Item.cpp | 106 ----------------------------------------------------------- 1 file changed, 106 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 093147b54..856b68be6 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -209,112 +209,6 @@ bool cItem::IsEnchantable(short item) -void cItem::GetApplicableEnchantmentsForType(short a_ItemType, cEnchantmentsArray & a_Enchantments) -{ - LOGWARN("Get Enchantments"); - - if (ItemCategory::IsSword(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("Sharpness=4")); - a_Enchantments.push_back(cEnchantments("Smite=5")); - a_Enchantments.push_back(cEnchantments("BaneOfArthropods=5")); - a_Enchantments.push_back(cEnchantments("Knockback=2")); - a_Enchantments.push_back(cEnchantments("FireAspect=2")); - a_Enchantments.push_back(cEnchantments("Looting=3")); - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - } - - else if (ItemCategory::IsPickaxe(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("Efficiency=4")); - a_Enchantments.push_back(cEnchantments("SilkTouch=1")); - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - a_Enchantments.push_back(cEnchantments("Fortune=3")); - } - - else if (ItemCategory::IsAxe(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("Efficiency=4")); - a_Enchantments.push_back(cEnchantments("SilkTouch=1")); - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - a_Enchantments.push_back(cEnchantments("Fortune=3")); - } - - else if (ItemCategory::IsShovel(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("Efficiency=4")); - a_Enchantments.push_back(cEnchantments("SilkTouch=1")); - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - a_Enchantments.push_back(cEnchantments("Fortune=3")); - } - - else if (ItemCategory::IsHoe(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - } - - else if (ItemCategory::IsArmor(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("Protection=4")); - a_Enchantments.push_back(cEnchantments("FireProtection=4")); - a_Enchantments.push_back(cEnchantments("BlastProtection=4")); - a_Enchantments.push_back(cEnchantments("ProjectileProtection=4")); - a_Enchantments.push_back(cEnchantments("Thorns=3")); - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - - if (ItemCategory::IsHelmet(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("Respiration=3")); - a_Enchantments.push_back(cEnchantments("AquaAffinity=1")); - } - - else if (ItemCategory::IsBoots(a_ItemType)) - { - a_Enchantments.push_back(cEnchantments("FeatherFalling=4")); - } - } - - //Bow - else if (a_ItemType == 261) - { - a_Enchantments.push_back(cEnchantments("Power=4")); - a_Enchantments.push_back(cEnchantments("Punch=2")); - a_Enchantments.push_back(cEnchantments("Flame=1")); - a_Enchantments.push_back(cEnchantments("Infinity=1")); - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - } - - //Fishing Rod - else if (a_ItemType == 346) - { - a_Enchantments.push_back(cEnchantments("LuckOfTheSea=3")); - a_Enchantments.push_back(cEnchantments("Lure=3")); - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - } - - //Shears - else if (a_ItemType == 359) - { - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - } - - //Flint and Steel - else if (a_ItemType == 259) - { - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - } - - //Carrot on a Stick - else if (a_ItemType == 398) - { - a_Enchantments.push_back(cEnchantments("Unbreaking=3")); - } -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cItems: -- cgit v1.2.3 From f9343a8490b50cb28a62c7327c0013da48ca2745 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 17 Apr 2014 13:15:35 +0200 Subject: Modified many things --- src/Item.cpp | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) (limited to 'src/Item.cpp') 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: -- cgit v1.2.3 From 0086fcfef18db58f3a4509853399c0a9b610e950 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 17 Apr 2014 19:31:43 +0200 Subject: Fixed some Errors (not all) --- src/Item.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 8bc25d242..540725492 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -267,7 +267,7 @@ int cItem::GetEnchantability() -bool cItem::EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_BlockConflictingEnchantments, bool a_DeleteLevelFromPlayer) +bool cItem::EnchantByXPLevels(int a_NumXPLevels) { if (!cItem::IsEnchantable(m_ItemType) && m_ItemType != E_ITEM_BOOK) { @@ -338,12 +338,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels, cPlayer & a_Player, bool a_Bloc } } - if (a_Player.DeltaExperience(-a_Player.XpForLevel(a_NumXPLevels)) >= 0 || a_Player.IsGameModeCreative()) - { - return true; - } - - return false; + return true; } -- cgit v1.2.3 From 56613d2b22c82f301eb651d1f24a0c2155917d24 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 18 Apr 2014 14:34:29 +0200 Subject: Fixed Errors --- src/Item.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 540725492..1941a6693 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -286,7 +286,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment1.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment1); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1); @@ -302,7 +302,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment2.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment2); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); @@ -318,7 +318,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment3.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment3); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); @@ -334,7 +334,6 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment4.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); } } -- cgit v1.2.3 From 013da806ec20b62a742aded9a9d2b8131193f30d Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 21:09:44 +0200 Subject: Did some static analysis, fixed some bugs and optimized a lot of code --- src/Item.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 856b68be6..9e41c246d 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -196,9 +196,6 @@ bool cItem::IsEnchantable(short item) return true; if ((item >= 298) && (item <= 317)) return true; - if ((item >= 290) && (item <= 294)) - return true; - if ((item == 346) || (item == 359) || (item == 261)) return true; -- cgit v1.2.3 From a6de7bf1cd80847abed22e3b962a5b8650b2911c Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 19 Apr 2014 15:10:50 +0200 Subject: Fixed Code --- src/Item.cpp | 166 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 94 insertions(+), 72 deletions(-) (limited to 'src/Item.cpp') 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()); + } + } + } + } } } -- cgit v1.2.3 From 11ff36c683975b69ed10bca31f01cdb2269bc4b6 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 19 Apr 2014 16:10:05 +0200 Subject: Fixed Code (2) --- src/Item.cpp | 190 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 93 insertions(+), 97 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 9899d7f32..f92efcb39 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -217,64 +217,64 @@ int cItem::GetEnchantability() switch (m_ItemType) { - 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; + case E_ITEM_WOODEN_SWORD: Enchantability = 15; break; + case E_ITEM_WOODEN_PICKAXE: Enchantability = 15; break; + case E_ITEM_WOODEN_SHOVEL: Enchantability = 15; break; + case E_ITEM_WOODEN_AXE: Enchantability = 15; break; + case E_ITEM_WOODEN_HOE: Enchantability = 15; break; + + case E_ITEM_LEATHER_CAP: Enchantability = 15; break; + case E_ITEM_LEATHER_TUNIC: Enchantability = 15; break; + case E_ITEM_LEATHER_PANTS: Enchantability = 15; break; + case E_ITEM_LEATHER_BOOTS: Enchantability = 15; break; + + case E_ITEM_STONE_SWORD: Enchantability = 5; break; + case E_ITEM_STONE_PICKAXE: Enchantability = 5; break; + case E_ITEM_STONE_SHOVEL: Enchantability = 5; break; + case E_ITEM_STONE_AXE: Enchantability = 5; break; + case E_ITEM_STONE_HOE: Enchantability = 5; break; + + case E_ITEM_IRON_HELMET: Enchantability = 9; break; + case E_ITEM_IRON_CHESTPLATE: Enchantability = 9; break; + case E_ITEM_IRON_LEGGINGS: Enchantability = 9; break; + case E_ITEM_IRON_BOOTS: Enchantability = 9; break; + + case E_ITEM_IRON_SWORD: Enchantability = 14; break; + case E_ITEM_IRON_PICKAXE: Enchantability = 14; break; + case E_ITEM_IRON_SHOVEL: Enchantability = 14; break; + case E_ITEM_IRON_AXE: Enchantability = 14; break; + case E_ITEM_IRON_HOE: Enchantability = 14; break; + + case E_ITEM_CHAIN_HELMET: Enchantability = 12; break; + case E_ITEM_CHAIN_CHESTPLATE: Enchantability = 12; break; + case E_ITEM_CHAIN_LEGGINGS: Enchantability = 12; break; + case E_ITEM_CHAIN_BOOTS: Enchantability = 12; break; + + case E_ITEM_DIAMOND_HELMET: Enchantability = 10; break; + case E_ITEM_DIAMOND_CHESTPLATE: Enchantability = 10; break; + case E_ITEM_DIAMOND_LEGGINGS: Enchantability = 10; break; + case E_ITEM_DIAMOND_BOOTS: Enchantability = 10; break; + + case E_ITEM_DIAMOND_SWORD: Enchantability = 10; break; + case E_ITEM_DIAMOND_PICKAXE: Enchantability = 10; break; + case E_ITEM_DIAMOND_SHOVEL: Enchantability = 10; break; + case E_ITEM_DIAMOND_AXE: Enchantability = 10; break; + case E_ITEM_DIAMOND_HOE: Enchantability = 10; break; + + case E_ITEM_GOLD_HELMET: Enchantability = 25; break; + case E_ITEM_GOLD_CHESTPLATE: Enchantability = 25; break; + case E_ITEM_GOLD_LEGGINGS: Enchantability = 25; break; + case E_ITEM_GOLD_BOOTS: Enchantability = 25; break; + + case E_ITEM_GOLD_SWORD: Enchantability = 22; break; + case E_ITEM_GOLD_PICKAXE: Enchantability = 22; break; + case E_ITEM_GOLD_SHOVEL: Enchantability = 22; break; + case E_ITEM_GOLD_AXE: Enchantability = 22; break; + case E_ITEM_GOLD_HOE: Enchantability = 22; break; + + case E_ITEM_FISHING_ROD: Enchantability = 1; break; + case E_ITEM_BOW: Enchantability = 1; break; + case E_ITEM_BOOK: Enchantability = 1; break; } return Enchantability; @@ -286,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; } @@ -318,46 +318,42 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) // Next Enchantment (Second) NewEnchantmentLevel = NewEnchantmentLevel / 2; float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if (Random.NextFloat(100) <= SecondEnchantmentChance) + if ((Random.NextFloat(100) > SecondEnchantmentChance) || (enchantments.size() == 0)) { - if (enchantments.size() > 0) - { - cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); - m_Enchantments.AddFromString(Enchantment2.ToString()); - 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()); - } - } - } - } - } + return false; + } + + cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment2.ToString()); + 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) || (enchantments.size() == 0)) + { + return false; + } + + 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) || (enchantments.size() == 0)) + { + return false; } + cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); + m_Enchantments.AddFromString(Enchantment4.ToString()); return true; } -- cgit v1.2.3 From d7f88396e0ed7c024fd367c4e225bbd9c05404b6 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 21 Apr 2014 06:41:11 +0200 Subject: Fixed enchanting return values. Items are enchanted in those cases, so return true. Ref.: #914. --- src/Item.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index f92efcb39..6a5fefbe1 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -320,7 +320,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; if ((Random.NextFloat(100) > SecondEnchantmentChance) || (enchantments.size() == 0)) { - return false; + return true; } cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); @@ -335,7 +335,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; if ((Random.NextFloat(100) > ThirdEnchantmentChance) || (enchantments.size() == 0)) { - return false; + return true; } cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); @@ -350,7 +350,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; if ((Random.NextFloat(100) > FourthEnchantmentChance) || (enchantments.size() == 0)) { - return false; + return true; } cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment4.ToString()); -- cgit v1.2.3 From bdd8b43b3eb0f71fff383d9a844e910fe9db7925 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 20 Apr 2014 13:54:17 +0200 Subject: Replaced X.size() with X.empty(), where applicable. --- src/Item.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Item.cpp') diff --git a/src/Item.cpp b/src/Item.cpp index 6a5fefbe1..d7424267a 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -318,7 +318,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) // Next Enchantment (Second) NewEnchantmentLevel = NewEnchantmentLevel / 2; float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if ((Random.NextFloat(100) > SecondEnchantmentChance) || (enchantments.size() == 0)) + if (enchantments.empty() || (Random.NextFloat(100) > SecondEnchantmentChance)) { return true; } @@ -333,7 +333,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) // Next Enchantment (Third) NewEnchantmentLevel = NewEnchantmentLevel / 2; float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if ((Random.NextFloat(100) > ThirdEnchantmentChance) || (enchantments.size() == 0)) + if (enchantments.empty() || (Random.NextFloat(100) > ThirdEnchantmentChance)) { return true; } @@ -348,7 +348,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) // Next Enchantment (Fourth) NewEnchantmentLevel = NewEnchantmentLevel / 2; float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100; - if ((Random.NextFloat(100) > FourthEnchantmentChance) || (enchantments.size() == 0)) + if (enchantments.empty() || (Random.NextFloat(100) > FourthEnchantmentChance)) { return true; } -- cgit v1.2.3