diff options
author | Fedja Beader <fedja@protonmail.ch> | 2024-08-17 19:54:31 +0000 |
---|---|---|
committer | Fedja Beader <fedja@protonmail.ch> | 2024-08-17 19:54:31 +0000 |
commit | 13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c (patch) | |
tree | 1ee1d13ec11ba019624d4815c298c95d5d5ad9fd /src/gui/windows | |
parent | 92d890fe0dc60276d81edde6d045f505d324ffba (diff) | |
download | mv-13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c.tar.gz mv-13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c.tar.bz2 mv-13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c.tar.xz mv-13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c.zip |
Limit shop's Max button to available carry weight
****
mana/plus!88
Diffstat (limited to 'src/gui/windows')
-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()) |