Skip to content

Commit

Permalink
fix: crash when inspecting items (opentibiabr#2143)
Browse files Browse the repository at this point in the history
  • Loading branch information
luan authored Jan 24, 2024
1 parent efa1817 commit 28dbaef
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
@@ -1245,7 +1245,7 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr<Item> item /*= nullptr
}

for (uint8_t i = SKILL_CRITICAL_HIT_CHANCE; i <= SKILL_LAST; i++) {
auto skill = item->getSkill(static_cast<skills_t>(i));
auto skill = item ? item->getSkill(static_cast<skills_t>(i)) : it.getSkill(static_cast<skills_t>(i));
if (!skill) {
continue;
}
@@ -1648,7 +1648,7 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr<Item> item /*= nullptr
}

for (uint8_t i = SKILL_CRITICAL_HIT_CHANCE; i <= SKILL_LAST; i++) {
auto skill = item->getSkill(static_cast<skills_t>(i));
auto skill = item ? item->getSkill(static_cast<skills_t>(i)) : it.getSkill(static_cast<skills_t>(i));
if (!skill) {
continue;
}
@@ -2087,7 +2087,7 @@ std::string Item::parseShowAttributesDescription(std::shared_ptr<Item> item, con
}

for (uint8_t i = SKILL_CRITICAL_HIT_CHANCE; i <= SKILL_LAST; i++) {
auto skill = item->getSkill(static_cast<skills_t>(i));
auto skill = item ? item->getSkill(static_cast<skills_t>(i)) : itemType.getSkill(static_cast<skills_t>(i));
if (!skill) {
continue;
}
@@ -2385,7 +2385,7 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std::
}

for (uint8_t i = SKILL_CRITICAL_HIT_CHANCE; i <= SKILL_LAST; i++) {
auto skill = item->getSkill(static_cast<skills_t>(i));
auto skill = item ? item->getSkill(static_cast<skills_t>(i)) : it.getSkill(static_cast<skills_t>(i));
if (!skill) {
continue;
}
@@ -2653,7 +2653,7 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std::
}

for (uint8_t i = SKILL_CRITICAL_HIT_CHANCE; i <= SKILL_LAST; i++) {
auto skill = item->getSkill(static_cast<skills_t>(i));
auto skill = item ? item->getSkill(static_cast<skills_t>(i)) : it.getSkill(static_cast<skills_t>(i));
if (!skill) {
continue;
}
6 changes: 3 additions & 3 deletions src/items/item.hpp
Original file line number Diff line number Diff line change
@@ -381,17 +381,17 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject {
}

int32_t getSpeed() const {
int32_t value = items[id].abilities->speed;
int32_t value = items[id].getSpeed();
return value;
}

int32_t getSkill(skills_t skill) const {
int32_t value = items[id].abilities ? items[id].abilities->skills[skill] : 0;
int32_t value = items[id].getSkill(skill);
return value;
}

int32_t getStat(stats_t stat) const {
int32_t value = items[id].abilities ? items[id].abilities->stats[stat] : 0;
int32_t value = items[id].getStat(stat);
return value;
}

12 changes: 12 additions & 0 deletions src/items/items.hpp
Original file line number Diff line number Diff line change
@@ -224,6 +224,18 @@ class ItemType {
return *abilities;
}

int32_t getSpeed() const {
return abilities ? abilities->speed : 0;
}

int32_t getSkill(skills_t skill) const {
return abilities ? abilities->skills[skill] : 0;
}

int32_t getStat(stats_t stat) const {
return abilities ? abilities->stats[stat] : 0;
}

std::string getPluralName() const {
if (!pluralName.empty()) {
return pluralName;

0 comments on commit 28dbaef

Please sign in to comment.