154 if (!Enchantments.empty())
156 a_OutValue[
"ench"] = Enchantments;
164 auto & LoreArray = (a_OutValue[
"Lore"] = Json::Value(Json::arrayValue));
168 LoreArray.append(Line);
202 m_ItemCount =
static_cast<char>(a_Value.get(
"Count", -1).asInt());
203 m_ItemDamage =
static_cast<short>(a_Value.get(
"Health", -1).asInt());
207 auto Lore = a_Value.get(
"Lore", Json::arrayValue);
208 for (
auto & Line : Lore)
213 int red = a_Value.get(
"Color_Red", -1).asInt();
214 int green = a_Value.get(
"Color_Green", -1).asInt();
215 int blue = a_Value.get(
"Color_Blue", -1).asInt();
218 m_ItemColor.
SetColor(static_cast<unsigned char>(red), static_cast<unsigned char>(green), static_cast<unsigned char>(blue));
220 else if ((red != -1) || (blue != -1) || (green != -1))
222 LOGWARNING(
"Item with invalid red, green, and blue values read in from json file.");
283 int Enchantability = 0;
347 return Enchantability;
362 if (Enchantability == 0)
368 int ModifiedEnchantmentLevel = a_NumXPLevels + Random.RandInt(Enchantability / 4) + Random.RandInt(Enchantability / 4) + 1;
369 float RandomBonus = 1.0F + (Random.RandReal() + Random.RandReal() - 1.0F) * 0.15F;
370 int FinalEnchantmentLevel =
static_cast<int>(ModifiedEnchantmentLevel * RandomBonus + 0.5F);
388 float NewEnchantmentLevel = a_NumXPLevels / 2.0f;
389 float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
390 if (Enchantments.empty() || !Random.RandBool(SecondEnchantmentChance))
403 NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
404 float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
405 if (Enchantments.empty() || !Random.RandBool(ThirdEnchantmentChance))
418 NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
419 float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
420 if (Enchantments.empty() || !Random.RandBool(FourthEnchantmentChance))
438 unsigned int NewLevel = 0;
439 if (OurLevel > a_Level)
444 else if (OurLevel == a_Level)
447 NewLevel = OurLevel + 1;
455 if (NewLevel > LevelCap)
461 return static_cast<int>(NewLevel) * Multiplier;
481 static const std::set<int> SwordEnchantments =
491 static const std::set<int> AxeEnchantments =
499 cEnchantments::enchUnbreaking
501 static const std::set<int> ToolEnchantments =
506 cEnchantments::enchUnbreaking
508 static const std::set<int> ShearEnchantments =
511 cEnchantments::enchUnbreaking
513 static const std::set<int> BowEnchantments =
520 static const std::set<int> FishingEnchantments =
525 static const std::set<int> MiscEnchantments =
527 cEnchantments::enchUnbreaking
532 return SwordEnchantments.count(a_EnchantmentID) > 0;
536 return AxeEnchantments.count(a_EnchantmentID) > 0;
540 return ToolEnchantments.count(a_EnchantmentID) > 0;
544 return ShearEnchantments.count(a_EnchantmentID) > 0;
548 return BowEnchantments.count(a_EnchantmentID) > 0;
552 return FishingEnchantments.count(a_EnchantmentID) > 0;
556 return MiscEnchantments.count(a_EnchantmentID) > 0;
560 static const std::set<int> ArmorEnchantments =
567 cEnchantments::enchUnbreaking
569 static const std::set<int> HatOnlyEnchantments =
574 static const std::set<int> BootOnlyEnchantments =
582 return (BootOnlyEnchantments.count(a_EnchantmentID) > 0) || (ArmorEnchantments.count(a_EnchantmentID) > 0);
586 return (HatOnlyEnchantments.count(a_EnchantmentID) > 0) || (ArmorEnchantments.count(a_EnchantmentID) > 0);
590 return ArmorEnchantments.count(a_EnchantmentID) > 0;
604 int EnchantingCost = 0;
616 EnchantingCost +=
AddEnchantment(Enchantment.first, Enchantment.second, FromBook);
620 return EnchantingCost;
632 push_back(std::move(a_InitialItem));
641 if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
643 LOGWARNING(
"cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size());
646 return &at(static_cast<size_t>(a_Idx));
655 if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
657 LOGWARNING(
"cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
660 at(static_cast<size_t>(a_Idx)) = a_Item;
669 if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
671 LOGWARNING(
"cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size());
674 erase(begin() + a_Idx);
681 void cItems::Set(
int a_Idx,
short a_ItemType,
char a_ItemCount,
short a_ItemDamage)
683 if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
685 LOGWARNING(
"cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
688 at(static_cast<size_t>(a_Idx)) =
cItem(a_ItemType, a_ItemCount, a_ItemDamage);
697 for (
auto itr : *
this)
713 for (
auto itr : *
this)
730 for (
int i = 0; i < numSlots; ++i)
cItemHandler * GetHandler(void) const
Returns the cItemHandler responsible for this item type.
bool IsSword(short a_ItemID)
bool Contains(const cItem &a_Item)
bool IsFullStack(void) const
Returns true if the item is stacked up to its maximum stacking.
bool DamageItem(short a_Amount=1)
Damages a weapon / tool.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
cItem & AddCount(char a_AmountToAdd)
Adds the specified count to this object and returns the reference to self (useful for chaining) ...
bool IsHelmet(short a_ItemType)
virtual char GetMaxStackSize(void)
Returns the maximum stack size for a given item.
static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments &a_Enchantments, int a_EnchantmentID)
Remove the entire enchantment (with weight) from the vector.
cFireworkItem m_FireworkItem
static bool IsEnchantable(short a_ItemType, bool a_FromBook=false)
Returns true if the specified item type is enchantable.
void Clear(void)
Removes all enchantments.
bool IsHoe(short a_ItemID)
bool IsValid() const
Returns whether the color is a valid color.
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
bool IsEqual(const cItem &a_Item) const
static void AddItemEnchantmentWeights(cWeightedEnchantments &a_Enchantments, short a_ItemType, int a_EnchantmentLevel)
Add enchantment weights from item to the vector.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
void AddFromString(const AString &a_StringSpec)
Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it...
short m_FlightTimeInTicks
cItem CopyOne(void) const
Returns a copy of this item with m_ItemCount set to 1.
void SetLevel(int a_EnchantmentID, unsigned int a_Level)
Sets the level for the specified enchantment, adding it if not stored before or removing it if level ...
static void ColoursFromString(const AString &a_String, cFireworkItem &a_FireworkItem)
Parses a string containing encoded firework colours and populates a FireworkItem with it...
void SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue)
Changes the color.
cEnchantments m_Enchantments
static void FadeColoursFromString(const AString &a_String, cFireworkItem &a_FireworkItem)
Parses a string containing encoded firework fade colours and populates a FireworkItem with it...
int AddEnchantmentsFromItem(const cItem &a_Other)
Adds the enchantments on a_Other to this item, returning the XP cost of the transfer.
std::vector< cWeightedEnchantment > cWeightedEnchantments
void Set(int a_Idx, const cItem &a_Item)
bool IsLoreEmpty(void) const
short GetMaxDamage(void) const
Returns the maximum damage value that this item can have; zero if damage is not applied.
unsigned char GetRed() const
Returns the red value of the color.
bool IsSameType(const cItem &a_Item) const
unsigned char GetBlue() const
Returns the blue value of the color.
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
bool ContainsType(const cItem &a_Item)
bool IsArmor(short a_ItemType)
int GetEnchantability()
Returns the enchantability of the item.
cItems(void)
Need a Lua-accessible constructor.
bool IsAxe(short a_ItemID)
int AddEnchantment(int a_EnchantmentID, unsigned int a_Level, bool a_FromBook)
Adds this specific enchantment to this item, returning the cost.
unsigned char GetGreen() const
Returns the green value of the color.
static unsigned int GetLevelCap(int a_EnchantmentID)
Get the maximum level the enchantment can have.
char GetMaxStackSize(void) const
Returns the maximum amount of stacked items of this type.
static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments &a_Enchantments)
Gets random enchantment from Vector and returns it.
static int GetXPCostMultiplier(int a_EnchantmentID, bool FromBook)
Get the XP cost multiplier for the enchantment (for anvils).
bool IsShovel(short a_ItemID)
void GetJson(Json::Value &a_OutValue) const
Saves the item data into JSON representation.
AString ToString(void) const
Serializes all the enchantments into a string.
static AString ColoursToString(const cFireworkItem &a_FireworkItem)
Converts the firework's vector of colours into a string of values separated by a semicolon.
static AString FadeColoursToString(const cFireworkItem &a_FireworkItem)
Converts the firework's vector of fade colours into a string of values separated by a semicolon...
bool EnchantByXPLevels(int a_NumXPLevels)
Randomly enchants the item using the specified number of XP levels.
AStringVector m_LoreTable
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a st...
const cItem & GetSlot(int a_X, int a_Y) const
cItem(void)
Creates an empty item.
int GetNumSlots(void) const
void FromJson(const Json::Value &a_Value)
Loads the item data from JSON representation.
bool CanHaveEnchantment(int a_EnchantmentID)
Returns whether or not this item is allowed to have the given enchantment.
static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments &a_Enchantments, cEnchantments a_FirstEnchantment)
Check enchantment conflicts from enchantments from the vector.
bool IsBoots(short a_ItemType)
cItemHandler * ItemHandler(int a_ItemType)
bool IsCustomNameEmpty(void) const
bool IsPickaxe(short a_ItemID)
void AddItemGrid(const cItemGrid &a_ItemGrid)
Adds a copy of all items in a_ItemGrid.
bool CanAddEnchantment(int a_EnchantmentID) const
Returns true if the given enchantment could be legally added to this object.