39 m_ItemType (a_ItemType),
40 m_ItemCount (a_ItemCount),
41 m_ItemDamage (a_ItemDamage),
42 m_Enchantments(a_Enchantments),
43 m_CustomName (a_CustomName),
44 m_LoreTable (a_LoreTable),
53 LOGWARNING(
"%s: creating an invalid item type (%d), resetting to empty.", __FUNCTION__, a_ItemType);
233 if (!Enchantments.empty())
235 a_OutValue[
"ench"] = Enchantments;
243 auto & LoreArray = (a_OutValue[
"Lore"] = Json::Value(Json::arrayValue));
247 LoreArray.append(Line);
281 m_ItemCount =
static_cast<char>(a_Value.get(
"Count", -1).asInt());
282 m_ItemDamage =
static_cast<short>(a_Value.get(
"Health", -1).asInt());
286 auto Lore = a_Value.get(
"Lore", Json::arrayValue);
287 for (
auto & Line : Lore)
292 int red = a_Value.get(
"Color_Red", -1).asInt();
293 int green = a_Value.get(
"Color_Green", -1).asInt();
294 int blue = a_Value.get(
"Color_Blue", -1).asInt();
297 m_ItemColor.
SetColor(
static_cast<unsigned char>(red),
static_cast<unsigned char>(green),
static_cast<unsigned char>(blue));
299 else if ((red != -1) || (blue != -1) || (green != -1))
301 LOGWARNING(
"Item with invalid red, green, and blue values read in from json file.");
439 if (Enchantability == 0)
444 const auto ModifiedEnchantmentLevel = a_NumXPLevels + a_Random.
RandInt(Enchantability / 4) + a_Random.
RandInt(Enchantability / 4) + 1;
445 const auto RandomBonus = 1.0F + (a_Random.
RandReal() + a_Random.
RandReal() - 1.0F) * 0.15F;
446 const auto FinalEnchantmentLevel =
static_cast<unsigned>(ModifiedEnchantmentLevel * RandomBonus + 0.5F);
464 float NewEnchantmentLevel = a_NumXPLevels / 2.0f;
465 float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
466 if (Enchantments.empty() || !a_Random.
RandBool(SecondEnchantmentChance))
479 NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
480 float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
481 if (Enchantments.empty() || !a_Random.
RandBool(ThirdEnchantmentChance))
494 NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
495 float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
496 if (Enchantments.empty() || !a_Random.
RandBool(FourthEnchantmentChance))
514 unsigned int NewLevel = 0;
515 if (OurLevel > a_Level)
520 else if (OurLevel == a_Level)
523 NewLevel = OurLevel + 1;
531 if (NewLevel > LevelCap)
537 return static_cast<int>(NewLevel) * Multiplier;
557 static const std::set<int> SwordEnchantments =
567 static const std::set<int> AxeEnchantments =
577 static const std::set<int> ToolEnchantments =
584 static const std::set<int> ShearEnchantments =
589 static const std::set<int> BowEnchantments =
596 static const std::set<int> FishingEnchantments =
601 static const std::set<int> MiscEnchantments =
608 return SwordEnchantments.count(a_EnchantmentID) > 0;
612 return AxeEnchantments.count(a_EnchantmentID) > 0;
616 return ToolEnchantments.count(a_EnchantmentID) > 0;
620 return ShearEnchantments.count(a_EnchantmentID) > 0;
624 return BowEnchantments.count(a_EnchantmentID) > 0;
628 return FishingEnchantments.count(a_EnchantmentID) > 0;
632 return MiscEnchantments.count(a_EnchantmentID) > 0;
636 static const std::set<int> ArmorEnchantments =
645 static const std::set<int> HatOnlyEnchantments =
650 static const std::set<int> BootOnlyEnchantments =
658 return (BootOnlyEnchantments.count(a_EnchantmentID) > 0) || (ArmorEnchantments.count(a_EnchantmentID) > 0);
662 return (HatOnlyEnchantments.count(a_EnchantmentID) > 0) || (ArmorEnchantments.count(a_EnchantmentID) > 0);
666 return ArmorEnchantments.count(a_EnchantmentID) > 0;
680 int EnchantingCost = 0;
692 EnchantingCost +=
AddEnchantment(Enchantment.first, Enchantment.second, FromBook);
696 return EnchantingCost;
708 push_back(std::move(a_InitialItem));
717 if ((a_Idx < 0) || (a_Idx >=
static_cast<int>(size())))
719 LOGWARNING(
"cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size());
722 return &at(
static_cast<size_t>(a_Idx));
731 if ((a_Idx < 0) || (a_Idx >=
static_cast<int>(size())))
733 LOGWARNING(
"cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
736 at(
static_cast<size_t>(a_Idx)) = a_Item;
745 if ((a_Idx < 0) || (a_Idx >=
static_cast<int>(size())))
747 LOGWARNING(
"cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size());
750 erase(begin() + a_Idx);
757 void cItems::Set(
int a_Idx,
short a_ItemType,
char a_ItemCount,
short a_ItemDamage)
759 if ((a_Idx < 0) || (a_Idx >=
static_cast<int>(size())))
761 LOGWARNING(
"cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
764 at(
static_cast<size_t>(a_Idx)) =
cItem(a_ItemType, a_ItemCount, a_ItemDamage);
773 for (
const auto & itr : *
this)
789 for (
const auto & itr : *
this)
807 const auto & Slot = a_ItemGrid.
GetSlot(i);
@ E_ITEM_DIAMOND_CHESTPLATE
@ E_ITEM_DIAMOND_LEGGINGS
@ E_ITEM_CHAIN_CHESTPLATE
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
bool IsValidItem(int a_ItemType)
Returns true if the specified item type is valid (known).
std::vector< cWeightedEnchantment > cWeightedEnchantments
void LOGWARNING(std::string_view a_Format, const Args &... args)
std::vector< AString > AStringVector
bool IsHoe(short a_ItemType)
bool IsHelmet(short a_ItemType)
bool IsPickaxe(short a_ItemType)
bool IsAxe(short a_ItemType)
bool IsArmor(short a_ItemType)
bool IsBoots(short a_ItemType)
bool IsShovel(short a_ItemType)
bool IsSword(short a_ItemType)
void SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue)
Changes the color.
unsigned char GetRed() const
Returns the red value of the color.
unsigned char GetGreen() const
Returns the green value of the color.
void Clear()
Resets the color.
unsigned char GetBlue() const
Returns the blue value of the color.
bool IsValid() const
Returns whether the color is a valid color.
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a st...
bool CanAddEnchantment(int a_EnchantmentID) const
Returns true if the given enchantment could be legally added to this object.
void Clear(void)
Removes all enchantments.
@ enchProjectileProtection
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 unsigned int GetLevelCap(int a_EnchantmentID)
Get the maximum level the enchantment can have.
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments &a_Enchantments, int a_EnchantmentID)
Remove the entire enchantment (with weight) from the vector.
void AddFromString(const AString &a_StringSpec)
Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it.
AString ToString(void) const
Serializes all the enchantments into a string.
static cEnchantments GetRandomEnchantmentFromVector(const cWeightedEnchantments &a_Enchantments, MTRand &a_Random)
Gets random enchantment from Vector and returns it, with randomness derived from the provided PRNG.
static int GetXPCostMultiplier(int a_EnchantmentID, bool FromBook)
Get the XP cost multiplier for the enchantment (for anvils).
static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments &a_Enchantments, const cEnchantments &a_FirstEnchantment)
Check enchantment conflicts from enchantments from the vector.
static void AddItemEnchantmentWeights(cWeightedEnchantments &a_Enchantments, short a_ItemType, unsigned a_EnchantmentLevel)
Add enchantment weights from item to the vector.
Class to wrap any random engine to provide a more convenient interface.
RealType RandReal(RealType a_Min, RealType a_Max)
Return a random RealType in the range [a_Min, a_Max).
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
bool RandBool(double a_TrueProbability=0.5)
Return a random bool with the given probability of being true.
void FromJson(const Json::Value &a_Value)
Loads the item data from JSON representation.
cItem & AddCount(char a_AmountToAdd)
Adds the specified count to this object and returns the reference to self (useful for chaining)
const cItemHandler & GetHandler(void) const
Returns the cItemHandler responsible for this item type.
bool CanHaveEnchantment(int a_EnchantmentID)
Returns whether or not this item is allowed to have the given enchantment.
static bool IsEnchantable(short a_ItemType, bool a_FromBook=false)
Returns true if the specified item type is enchantable.
cEnchantments m_Enchantments
bool IsCustomNameEmpty(void) const
bool EnchantByXPLevels(unsigned a_NumXPLevels, MTRand &a_Random)
Randomly enchants the item using the specified number of XP levels.
bool DamageItem(short a_Amount=1)
Damages a weapon / tool.
unsigned GetEnchantability()
Returns the enchantability of the item.
void GetJson(Json::Value &a_OutValue) const
Saves the item data into JSON representation.
char GetMaxStackSize(void) const
Returns the maximum amount of stacked items of this type.
bool IsLoreEmpty(void) const
bool IsEqual(const cItem &a_Item) const
int AddEnchantment(int a_EnchantmentID, unsigned int a_Level, bool a_FromBook)
Adds this specific enchantment to this item, returning the cost.
AStringVector m_LoreTable
void Clear(void)
Empties the item and frees up any dynamic storage used by the internals.
int AddEnchantmentsFromItem(const cItem &a_Other)
Adds the enchantments on a_Other to this item, returning the XP cost of the transfer.
void Empty(void)
Empties the item and frees up any dynamic storage used by the internals.
short GetMaxDamage(void) const
Returns the maximum damage value that this item can have; zero if damage is not applied.
bool IsFullStack(void) const
Returns true if the item is stacked up to its maximum stacking.
cFireworkItem m_FireworkItem
cItem CopyOne(void) const
Returns a copy of this item with m_ItemCount set to 1.
cItem(void)
Creates an empty item.
bool IsSameType(const cItem &a_Item) const
bool Contains(const cItem &a_Item)
cItems(void)
Need a Lua-accessible constructor.
bool ContainsType(const cItem &a_Item)
void AddItemGrid(const cItemGrid &a_ItemGrid)
Adds a copy of all items in a_ItemGrid.
void Add(const cItem &a_Item)
void Set(int a_Idx, const cItem &a_Item)
const cItem & GetSlot(int a_X, int a_Y) const
int GetNumSlots(void) const
static const cItemHandler & For(int a_ItemType)
virtual char GetMaxStackSize(void) const
Returns the maximum stack size for a given item.
short m_FlightTimeInTicks
static AString FadeColoursToString(const cFireworkItem &a_FireworkItem)
Converts the firework's vector of fade colours into a string of values separated by a semicolon.
static void FadeColoursFromString(const AString &a_String, cFireworkItem &a_FireworkItem)
Parses a string containing encoded firework fade colours and populates a FireworkItem with it.
static AString ColoursToString(const cFireworkItem &a_FireworkItem)
Converts the firework's vector of colours into a string of values separated by a semicolon.
static void ColoursFromString(const AString &a_String, cFireworkItem &a_FireworkItem)
Parses a string containing encoded firework colours and populates a FireworkItem with it.