From 13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Sat, 17 Aug 2024 19:54:31 +0000 Subject: Limit shop's Max button to available carry weight **** mana/plus!88 --- src/gui/windows/buydialog.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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()) -- cgit v1.2.3-70-g09d2