Skip to content

Commit 6725cfa

Browse files
authored
fix(container): handle depot and batch page state (#3995)
Bug Fixes: • Fixed container batch updates to always send valid page indices to clients. • Improved depot container closing behavior to properly respond to player proximity changes.
1 parent 77a911d commit 6725cfa

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/creatures/players/player.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ uint16_t Player::parseRacebyCharm(charmRune_t charmId, bool set /*= false*/, uin
19331933
return raceid;
19341934
}
19351935

1936-
bool Player::isNearDepotBox() {
1936+
bool Player::isNearDepotBox() const {
19371937
const Position &pos = getPosition();
19381938
for (int32_t cx = -1; cx <= 1; ++cx) {
19391939
for (int32_t cy = -1; cy <= 1; ++cy) {
@@ -8923,12 +8923,19 @@ void Player::sendBatchUpdateContainer(Container* container, bool hasParent) {
89238923
closeContainersOutOfRange();
89248924
}
89258925

8926-
for (const auto &[cid, containerInfo] : openContainers) {
8926+
for (auto &[cid, containerInfo] : openContainers) {
89278927
if (containerInfo.container.get() != container) {
89288928
continue;
89298929
}
89308930

8931-
client->sendContainer(cid, containerInfo.container, hasParent, containerInfo.index);
8931+
auto &firstIndex = containerInfo.index;
8932+
const uint32_t containerSize = containerInfo.container->size();
8933+
if (firstIndex >= containerSize) {
8934+
const uint32_t pageSize = std::max<uint32_t>(containerInfo.container->capacity(), 1);
8935+
firstIndex = containerSize == 0 ? 0 : static_cast<uint16_t>(((containerSize - 1) / pageSize) * pageSize);
8936+
}
8937+
8938+
client->sendContainer(cid, containerInfo.container, hasParent, firstIndex);
89328939
g_logger().debug("Player::sendBatchUpdateContainer - Sent batch update for container {} to player {}.", cid, getName());
89338940
}
89348941
}
@@ -8981,7 +8988,7 @@ bool Player::shouldCloseContainer(const std::shared_ptr<Container> &container) c
89818988
if (const auto &depotChest = topParent->getDepotChest()) {
89828989
for (const auto &[depotId, chest] : depotChests) {
89838990
if (depotId != 0 && chest == depotChest) {
8984-
return false;
8991+
return !isNearDepotBox();
89858992
}
89868993
}
89878994
}

src/creatures/players/player.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
686686
std::shared_ptr<DepotChest> getDepotChest(uint32_t depotId, bool autoCreate);
687687
std::shared_ptr<DepotLocker> getDepotLocker(uint32_t depotId);
688688
void onReceiveMail();
689-
bool isNearDepotBox();
689+
bool isNearDepotBox() const;
690690

691691
std::shared_ptr<Container> refreshManagedContainer(ObjectCategory_t category, const std::shared_ptr<Container> &container, bool isLootContainer, bool loading = false);
692692
std::shared_ptr<Container> getManagedContainer(ObjectCategory_t category, bool isLootContainer) const;

src/lua/functions/core/game/batch_update_functions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
void BatchUpdateFunctions::init(lua_State* L) {
1717
Lua::registerSharedClass<BatchUpdate>(L, "", luaBatchUpdateCreate);
18-
Lua::registerMethod(L, "BatchUpdate", "delete", Lua::luaGarbageCollection);
18+
/***
19+
* @function BatchUpdate.delete
20+
* @return nil
21+
*/
22+
Lua::registerMethod(L, "BatchUpdate", "delete", Lua::luaSharedPtrGarbageCollection<BatchUpdate>);
1923
Lua::registerMethod(L, "BatchUpdate", "add", luaBatchUpdateAdd);
2024
}
2125

0 commit comments

Comments
 (0)