From aece8f4edd769a5a82efad36d7a398119d4185cd Mon Sep 17 00:00:00 2001 From: ramon-bernardo Date: Thu, 7 Nov 2024 19:09:30 -0300 Subject: [PATCH] Fix Container::hasParent --- data/npc/lib/npcsystem/keywordhandler.lua | 2 +- src/container.cpp | 2 +- src/container.h | 2 +- src/depotchest.h | 7 ++++--- src/depotlocker.h | 18 +++++++++++------- src/game.cpp | 6 +++--- src/inbox.h | 5 +++-- src/player.cpp | 4 ++-- src/player.h | 4 ++-- src/protocolgame.cpp | 4 ++-- src/protocolgame.h | 2 +- src/storeinbox.h | 7 ++++++- 12 files changed, 37 insertions(+), 26 deletions(-) diff --git a/data/npc/lib/npcsystem/keywordhandler.lua b/data/npc/lib/npcsystem/keywordhandler.lua index 31cdc3f426..7d32da527b 100644 --- a/data/npc/lib/npcsystem/keywordhandler.lua +++ b/data/npc/lib/npcsystem/keywordhandler.lua @@ -43,11 +43,11 @@ if not KeywordHandler then return true end - -- Returns the parent of this node or nil if no such node exists. function KeywordNode:hasParent() return self.parent ~= nil end + -- Returns the parent of this node or nil if no such node exists. function KeywordNode:getParent() return self.parent end diff --git a/src/container.cpp b/src/container.cpp index 1d694b71b5..2bb6fd710b 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -78,7 +78,7 @@ std::string Container::getName(bool addArticle /* = false*/) const return getNameDescription(it, this, -1, addArticle); } -bool Container::hasParent() const { return getID() != ITEM_BROWSEFIELD && !dynamic_cast(getParent()); } +bool Container::hasContainerParent() const { return getID() != ITEM_BROWSEFIELD && !dynamic_cast(getParent()); } void Container::addItem(Item* item) { diff --git a/src/container.h b/src/container.h index 112b194a57..88e927c44b 100644 --- a/src/container.h +++ b/src/container.h @@ -50,7 +50,7 @@ class Container : public Item, public Cylinder virtual StoreInbox* getStoreInbox() { return nullptr; } virtual const StoreInbox* getStoreInbox() const { return nullptr; } - bool hasParent() const override; + bool hasContainerParent() const; Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream) override; bool unserializeItemNode(OTB::Loader& loader, const OTB::Node& node, PropStream& propStream) override; diff --git a/src/depotchest.h b/src/depotchest.h index 12eb7f7a92..5d1e8aead0 100644 --- a/src/depotchest.h +++ b/src/depotchest.h @@ -11,10 +11,10 @@ class DepotChest final : public Container public: explicit DepotChest(uint16_t type, bool paginated = true); - // serialization + // Serialization void setMaxDepotItems(uint32_t maxitems) { maxDepotItems = maxitems; } - // cylinder implementations + // Cylinder implementations ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; @@ -23,9 +23,10 @@ class DepotChest final : public Container void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) override; - // overrides + // Item implementations bool canRemove() const override { return false; } + // Thing implementations bool hasParent() const override { return getParent(); } Cylinder* getParent() const override; Cylinder* getRealParent() const override { return parent; } diff --git a/src/depotlocker.h b/src/depotlocker.h index 6b7410b164..50186c18ca 100644 --- a/src/depotlocker.h +++ b/src/depotlocker.h @@ -15,18 +15,18 @@ class DepotLocker final : public Container public: explicit DepotLocker(uint16_t type); - DepotLocker* getDepotLocker() override { return this; } - const DepotLocker* getDepotLocker() const override { return this; } - void removeInbox(Inbox* inbox); + uint16_t getDepotId() const { return depotId; } + void setDepotId(uint16_t depotId) { this->depotId = depotId; } - // serialization + // Serialization Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream) override; - uint16_t getDepotId() const { return depotId; } - void setDepotId(uint16_t depotId) { this->depotId = depotId; } + // Container implementations + DepotLocker* getDepotLocker() override { return this; } + const DepotLocker* getDepotLocker() const override { return this; } - // cylinder implementations + // Cylinder implementations ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; @@ -35,8 +35,12 @@ class DepotLocker final : public Container void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) override; + // Item implementations bool canRemove() const override { return false; } + // Thing implementations + bool hasParent() const override { return getParent(); } + private: uint16_t depotId; }; diff --git a/src/game.cpp b/src/game.cpp index 01a1ed565a..2619fa2aba 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2371,7 +2371,7 @@ void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) } player->addContainer(cid, parentContainer); - player->sendContainer(cid, parentContainer, parentContainer->hasParent(), player->getContainerIndex(cid)); + player->sendContainer(cid, parentContainer, parentContainer->hasContainerParent(), player->getContainerIndex(cid)); } void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) @@ -2386,7 +2386,7 @@ void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) return; } - player->sendContainer(cid, container, container->hasParent(), player->getContainerIndex(cid)); + player->sendContainer(cid, container, container->hasContainerParent(), player->getContainerIndex(cid)); } void Game::playerRotateItem(uint32_t playerId, const Position& pos, uint8_t stackPos, const uint16_t spriteId) @@ -2569,7 +2569,7 @@ void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_ } player->setContainerIndex(containerId, index); - player->sendContainer(containerId, container, container->hasParent(), index); + player->sendContainer(containerId, container, container->hasContainerParent(), index); } void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t windowTextId, const std::string& text) diff --git a/src/inbox.h b/src/inbox.h index 965cf21b63..dc21a379e6 100644 --- a/src/inbox.h +++ b/src/inbox.h @@ -11,7 +11,7 @@ class Inbox final : public Container public: explicit Inbox(uint16_t type); - // cylinder implementations + // Cylinder implementations ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; @@ -20,9 +20,10 @@ class Inbox final : public Container void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) override; - // overrides + // Item implementations bool canRemove() const override { return false; } + // Thing implementations bool hasParent() const override { return getParent(); } Cylinder* getParent() const override; Cylinder* getRealParent() const override { return parent; } diff --git a/src/player.cpp b/src/player.cpp index 380bd802c3..25e5934786 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1451,11 +1451,11 @@ void Player::onSendContainer(const Container* container) return; } - bool hasParent = container->hasParent(); + bool hasContainerParent = container->hasContainerParent(); for (const auto& it : openContainers) { const OpenContainer& openContainer = it.second; if (openContainer.container == container) { - client->sendContainer(it.first, container, hasParent, openContainer.index); + client->sendContainer(it.first, container, hasContainerParent, openContainer.index); } } } diff --git a/src/player.h b/src/player.h index 572942aeab..d319344c9f 100644 --- a/src/player.h +++ b/src/player.h @@ -720,10 +720,10 @@ class Player final : public Creature, public Cylinder void sendAddContainerItem(const Container* container, const Item* item); void sendUpdateContainerItem(const Container* container, uint16_t slot, const Item* newItem); void sendRemoveContainerItem(const Container* container, uint16_t slot); - void sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex) + void sendContainer(uint8_t cid, const Container* container, bool hasContainerParent, uint16_t firstIndex) { if (client) { - client->sendContainer(cid, container, hasParent, firstIndex); + client->sendContainer(cid, container, hasContainerParent, firstIndex); } } diff --git a/src/protocolgame.cpp b/src/protocolgame.cpp index 5edfbb3dcb..1202d25298 100644 --- a/src/protocolgame.cpp +++ b/src/protocolgame.cpp @@ -1888,7 +1888,7 @@ void ProtocolGame::sendIcons(uint32_t icons) writeToOutputBuffer(msg); } -void ProtocolGame::sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex) +void ProtocolGame::sendContainer(uint8_t cid, const Container* container, bool hasContainerParent, uint16_t firstIndex) { NetworkMessage msg; msg.addByte(0x6E); @@ -1904,7 +1904,7 @@ void ProtocolGame::sendContainer(uint8_t cid, const Container* container, bool h } msg.addByte(container->capacity()); - msg.addByte(hasParent ? 0x01 : 0x00); + msg.addByte(hasContainerParent ? 0x01 : 0x00); msg.addByte(0x00); // show search icon (boolean) msg.addByte(container->isUnlocked() ? 0x01 : 0x00); // Drag and drop msg.addByte(container->hasPagination() ? 0x01 : 0x00); // Pagination diff --git a/src/protocolgame.h b/src/protocolgame.h index f6c792ad21..2a33ed0a72 100644 --- a/src/protocolgame.h +++ b/src/protocolgame.h @@ -263,7 +263,7 @@ class ProtocolGame final : public Protocol void sendUpdateContainerItem(uint8_t cid, uint16_t slot, const Item* item); void sendRemoveContainerItem(uint8_t cid, uint16_t slot, const Item* lastItem); - void sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex); + void sendContainer(uint8_t cid, const Container* container, bool hasContainerParent, uint16_t firstIndex); void sendEmptyContainer(uint8_t cid); void sendCloseContainer(uint8_t cid); diff --git a/src/storeinbox.h b/src/storeinbox.h index 6312d39325..46c62058a3 100644 --- a/src/storeinbox.h +++ b/src/storeinbox.h @@ -11,10 +11,11 @@ class StoreInbox final : public Container public: explicit StoreInbox(uint16_t type); + // Container implementations StoreInbox* getStoreInbox() override { return this; } const StoreInbox* getStoreInbox() const override { return this; } - // cylinder implementations + // Cylinder implementations ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; @@ -23,7 +24,11 @@ class StoreInbox final : public Container void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) override; + // Item implementations bool canRemove() const override { return false; } + + // Thing implementations + bool hasParent() const override { return getParent(); } }; #endif // FS_STOREINBOX_H