diff options
Diffstat (limited to 'src/gui/windows/buydialog.cpp')
-rw-r--r-- | src/gui/windows/buydialog.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index b17064e45..2786671cd 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -27,6 +27,7 @@ #include "configuration.h" #include "being/being.h" +#include "being/playerinfo.h" #include "enums/gui/layouttype.h" @@ -753,13 +754,26 @@ void BuyDialog::updateButtonsAndLabels() const int itemPrice = item->getPrice(); // Calculate how many the player can afford - if (mNpcId == fromInt(Items, BeingId)) + if (mNpcId == fromInt(Items, BeingId)) // /createitems "shop" mMaxItems = 100; else if (itemPrice != 0) mMaxItems = mMoney / itemPrice; else mMaxItems = 1; + // Calculate how many the player can carry + using namespace PlayerInfo; // trick for line-length. + const int itemWeight = item->getInfo().getWeight(); + // Should be inside if, but line-length... + const int myTotalWeight = getAttribute(Attributes::TOTAL_WEIGHT); + const int myMaxWeight = getAttribute(Attributes::MAX_WEIGHT); + if (itemWeight != 0) + { + const int myFreeWeight = myMaxWeight - myTotalWeight; + const int canCarry = myFreeWeight / itemWeight; + mMaxItems = std::min(mMaxItems, canCarry); + } + if (mNpcId == fromInt(Market, BeingId)) { if (mMaxItems > item->getQuantity()) |