Skip to content

Commit

Permalink
Fix Container::hasParent
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-bernardo committed Nov 7, 2024
1 parent 8e9f360 commit aece8f4
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion data/npc/lib/npcsystem/keywordhandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const Player*>(getParent()); }
bool Container::hasContainerParent() const { return getID() != ITEM_BROWSEFIELD && !dynamic_cast<const Player*>(getParent()); }

void Container::addItem(Item* item)
{
Expand Down
2 changes: 1 addition & 1 deletion src/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/depotchest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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; }
Expand Down
18 changes: 11 additions & 7 deletions src/depotlocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
};
Expand Down
6 changes: 3 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/inbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/storeinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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

0 comments on commit aece8f4

Please sign in to comment.