Skip to content

Commit

Permalink
fix: imbuement slot validation to prevent duplicate applications (#3316)
Browse files Browse the repository at this point in the history
  • Loading branch information
murilo09 authored Feb 3, 2025
1 parent 3046566 commit 2a5a0e7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2294,13 +2294,35 @@ void Player::onApplyImbuement(const Imbuement* imbuement, const std::shared_ptr<
return;
}

auto itemSlots = item->getImbuementSlot();
if (slot >= itemSlots) {
g_logger().error("[Player::onApplyImbuement] - Player {} attempted to apply imbuement in an invalid slot ({})", this->getName(), slot);
this->sendImbuementResult("Invalid slot selection.");
return;
}

ImbuementInfo imbuementInfo;
if (item->getImbuementInfo(slot, &imbuementInfo)) {
g_logger().error("[Player::onApplyImbuement] - An error occurred while player with name {} try to apply imbuement, item already contains imbuement", this->getName());
this->sendImbuementResult("An error ocurred, please reopen imbuement window.");
return;
}

for (uint8_t i = 0; i < item->getImbuementSlot(); i++) {
if (i == slot) {
continue;
}

ImbuementInfo existingImbuement;
if (item->getImbuementInfo(i, &existingImbuement) && existingImbuement.imbuement) {
if (existingImbuement.imbuement->getName() == imbuement->getName()) {
g_logger().error("[Player::onApplyImbuement] - Player {} attempted to apply the same imbuement in multiple slots", this->getName());
this->sendImbuementResult("You cannot apply the same imbuement in multiple slots.");
return;
}
}
}

const auto &items = imbuement->getItems();
for (auto &[key, value] : items) {
const ItemType &itemType = Item::items[key];
Expand Down

0 comments on commit 2a5a0e7

Please sign in to comment.