Skip to content

Commit 5f0dfab

Browse files
authored
fix: imbuement slot validation to prevent duplicate applications (opentibiabr#3316)
1 parent 4809b50 commit 5f0dfab

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/creatures/players/player.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,13 +2294,35 @@ void Player::onApplyImbuement(const Imbuement* imbuement, const std::shared_ptr<
22942294
return;
22952295
}
22962296

2297+
auto itemSlots = item->getImbuementSlot();
2298+
if (slot >= itemSlots) {
2299+
g_logger().error("[Player::onApplyImbuement] - Player {} attempted to apply imbuement in an invalid slot ({})", this->getName(), slot);
2300+
this->sendImbuementResult("Invalid slot selection.");
2301+
return;
2302+
}
2303+
22972304
ImbuementInfo imbuementInfo;
22982305
if (item->getImbuementInfo(slot, &imbuementInfo)) {
22992306
g_logger().error("[Player::onApplyImbuement] - An error occurred while player with name {} try to apply imbuement, item already contains imbuement", this->getName());
23002307
this->sendImbuementResult("An error ocurred, please reopen imbuement window.");
23012308
return;
23022309
}
23032310

2311+
for (uint8_t i = 0; i < item->getImbuementSlot(); i++) {
2312+
if (i == slot) {
2313+
continue;
2314+
}
2315+
2316+
ImbuementInfo existingImbuement;
2317+
if (item->getImbuementInfo(i, &existingImbuement) && existingImbuement.imbuement) {
2318+
if (existingImbuement.imbuement->getName() == imbuement->getName()) {
2319+
g_logger().error("[Player::onApplyImbuement] - Player {} attempted to apply the same imbuement in multiple slots", this->getName());
2320+
this->sendImbuementResult("You cannot apply the same imbuement in multiple slots.");
2321+
return;
2322+
}
2323+
}
2324+
}
2325+
23042326
const auto &items = imbuement->getItems();
23052327
for (auto &[key, value] : items) {
23062328
const ItemType &itemType = Item::items[key];

0 commit comments

Comments
 (0)