Skip to content

Commit

Permalink
fix: house transfer item to owner (opentibiabr#3258)
Browse files Browse the repository at this point in the history
This fixes an issue with the house item transfer system during server startup. Specifically, the `getPlayerByGUID` function was not passing `true` to retrieve offline players, which caused items belonging to offline players to be removed instead of being correctly transferred to their inbox. Additionally, the logic for handling ownership of items was improved to ensure the correct transfer of items to their respective owners, even when no players are online during server startup.
  • Loading branch information
dudantas authored and vllworldbuilding committed Jan 31, 2025
1 parent 33cf4b2 commit 9d79287
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/map/house/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,25 @@ bool House::transferToDepot(const std::shared_ptr<Player> &player, const std::sh
std::unordered_set<std::shared_ptr<Player>> playersToSave = { player };

for (const auto &item : moveItemList) {
g_logger().debug("[{}] moving item '{}' to depot", __FUNCTION__, item->getName());
auto targetPlayer = player;
std::shared_ptr<Player> targetPlayer = player;

if (item->hasOwner() && !item->isOwner(targetPlayer)) {
targetPlayer = g_game().getPlayerByGUID(item->getOwnerId());
if (!targetPlayer) {
g_game().internalRemoveItem(item, item->getItemCount());
const auto &itemOwner = g_game().getPlayerByGUID(item->getOwnerId(), true);
if (itemOwner) {
targetPlayer = itemOwner;
playersToSave.insert(targetPlayer);
} else {
g_logger().warn("[{}] owner of item '{}' (GUID: {}) not found, skipping transfer", __FUNCTION__, item->getName(), item->getOwnerId());
continue;
}
playersToSave.insert(targetPlayer);
}

g_game().internalMoveItem(item->getParent(), targetPlayer->getInbox(), INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT);
}
for (const auto &playerToSave : playersToSave) {
g_saveManager().savePlayer(playerToSave);
}

return true;
}

Expand Down

0 comments on commit 9d79287

Please sign in to comment.