Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of depot chest #4794

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "tile.h"

class Container;
class DepotChest;
class DepotLocker;
class StoreInbox;

Expand Down Expand Up @@ -44,6 +45,9 @@ class Container : public Item, public Cylinder
Container* getContainer() override final { return this; }
const Container* getContainer() const override final { return this; }

virtual DepotChest* getDepotChest() { return nullptr; }
virtual const DepotChest* getDepotChest() const { return nullptr; }

virtual DepotLocker* getDepotLocker() { return nullptr; }
virtual const DepotLocker* getDepotLocker() const { return nullptr; }

Expand Down
4 changes: 2 additions & 2 deletions src/depotchest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include "tools.h"

DepotChest::DepotChest(uint16_t type, bool paginated /*= true*/) :
Container{type, items[type].maxItems, true, paginated}
DepotChest::DepotChest(uint16_t type, uint16_t depotId, bool paginated /*= false*/) :
Container{type, items[type].maxItems, true, paginated}, depotId{depotId}
{}

ReturnValue DepotChest::queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags,
Expand Down
8 changes: 7 additions & 1 deletion src/depotchest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
class DepotChest final : public Container
{
public:
explicit DepotChest(uint16_t type, bool paginated = true);
explicit DepotChest(uint16_t type, uint16_t depotId = 0, bool paginated = false);

DepotChest* getDepotChest() override { return this; }
const DepotChest* getDepotChest() const override { return this; }

// serialization
void setMaxDepotItems(uint32_t maxitems) { maxDepotItems = maxitems; }

uint16_t getDepotId() const { return depotId; }

// cylinder implementations
ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags,
Creature* actor = nullptr) const override;
Expand All @@ -31,6 +36,7 @@ class DepotChest final : public Container

private:
uint32_t maxDepotItems = 0;
uint16_t depotId = 0;
};

#endif // FS_DEPOTCHEST_H
1 change: 0 additions & 1 deletion src/depotlocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class DepotLocker final : public Container
Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream) override;

uint16_t getDepotId() const { return depotId; }
void setDepotId(uint16_t depotId) { this->depotId = depotId; }

// cylinder implementations
ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count, uint32_t flags,
Expand Down
12 changes: 6 additions & 6 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3885,7 +3885,7 @@ int LuaScriptInterface::luaIsDepot(lua_State* L)
{
// isDepot(uid)
Container* container = tfs::lua::getScriptEnv()->getContainerByUID(tfs::lua::getNumber<uint32_t>(L, -1));
tfs::lua::pushBoolean(L, container && container->getDepotLocker());
tfs::lua::pushBoolean(L, container && (container->getDepotLocker() || container->getDepotChest()));
return 1;
}

Expand All @@ -3910,14 +3910,14 @@ int LuaScriptInterface::luaGetDepotId(lua_State* L)
return 1;
}

DepotLocker* depotLocker = container->getDepotLocker();
if (!depotLocker) {
if (auto depotLocker = container->getDepotLocker()) {
lua_pushnumber(L, depotLocker->getDepotId());
} else if (auto depotChest = container->getDepotChest()) {
lua_pushnumber(L, depotChest->getDepotId());
} else {
reportErrorFunc(L, "Depot not found");
tfs::lua::pushBoolean(L, false);
return 1;
}

lua_pushnumber(L, depotLocker->getDepotId());
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ DepotChest* Player::getDepotChest(uint32_t depotId, bool autoCreate)
return nullptr;
}

it = depotChests.emplace(depotId, new DepotChest(depotItemId)).first;
it = depotChests.emplace(depotId, new DepotChest(depotItemId, depotId, true)).first;
it->second->setMaxDepotItems(getMaxDepotItems());
return it->second;
}
Expand All @@ -843,7 +843,7 @@ DepotLocker& Player::getDepotLocker()
depotLocker->internalAddThing(Item::CreateItem(ITEM_MARKET));
depotLocker->internalAddThing(inbox);

DepotChest* depotChest = new DepotChest(ITEM_DEPOT, false);
DepotChest* depotChest = new DepotChest(ITEM_DEPOT);
// adding in reverse to align them from first to last
for (int16_t depotId = depotChest->capacity(); depotId >= 0; --depotId) {
if (DepotChest* box = getDepotChest(depotId, true)) {
Expand Down
Loading