diff --git a/src/items/item.cpp b/src/items/item.cpp index 71bcd1c765e..f531b1f676a 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -91,8 +91,18 @@ std::shared_ptr Item::CreateItem(const uint16_t type, uint16_t count /*= 0 return newItem; } +bool Item::hasImbuementAttribute(const std::string &attributeSlot) const { + // attributeSlot = ITEM_IMBUEMENT_SLOT + slot id + return getCustomAttribute(attributeSlot) != nullptr; +} + bool Item::getImbuementInfo(uint8_t slot, ImbuementInfo* imbuementInfo) const { - const CustomAttribute* attribute = getCustomAttribute(std::to_string(ITEM_IMBUEMENT_SLOT + slot)); + std::string attributeSlot = std::to_string(ITEM_IMBUEMENT_SLOT + slot); + if (!hasImbuementAttribute(attributeSlot)) { + return false; + } + + const CustomAttribute* attribute = getCustomAttribute(attributeSlot); const auto info = attribute ? attribute->getAttribute() : 0; imbuementInfo->imbuement = g_imbuements().getImbuement(info & 0xFF); imbuementInfo->duration = info >> 8; diff --git a/src/items/item.hpp b/src/items/item.hpp index d199fab15cf..d9066cecad6 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -676,6 +676,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { return false; } bool hasImbuementCategoryId(uint16_t categoryId) const; + bool hasImbuementAttribute(const std::string &attributeSlot) const; bool hasImbuements() const { for (uint8_t slotid = 0; slotid < getImbuementSlot(); slotid++) { ImbuementInfo imbuementInfo;