summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2024-08-26 15:54:15 +0000
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-08-26 17:57:01 +0200
commitd908f9c55c17700ee5b8cd44c6939a465d6f6f92 (patch)
tree6b1f519a6884730476e4d29729ce3cf199fa14c1
parent221d67c4774bf41e6f2f0f73fb6914030e33bdde (diff)
downloadmana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.tar.gz
mana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.tar.bz2
mana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.tar.xz
mana-d908f9c55c17700ee5b8cd44c6939a465d6f6f92.zip
Limit shop's Max button to available carry weight
(cherry picked from M+ commit 13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c)
-rw-r--r--NEWS1
-rw-r--r--src/gui/buydialog.cpp14
2 files changed, 14 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 33d1130e..8fd26965 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,7 @@
- Enabled whispers in tabs by default
- Made pickup notifications to appear as particle instead of text by default
- Custom mouse cursor is now rendered by the system
+- Limit shop's Max button to available carry weight
- Fixed performance issue in BrowserBox (especially update/news window)
- Fixed handling of non-consecutive emote IDs
- Fixed securing of names in files created by chat logger
diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp
index 56c3c261..1ac5cdaa 100644
--- a/src/gui/buydialog.cpp
+++ b/src/gui/buydialog.cpp
@@ -239,7 +239,8 @@ void BuyDialog::updateButtonsAndLabels()
if (selectedItem > -1)
{
- int itemPrice = mShopItems->at(selectedItem)->getPrice();
+ const ShopItem *shopItem = mShopItems->at(selectedItem);
+ const int itemPrice = shopItem->getPrice();
// Calculate how many the player can afford
if (itemPrice > 0)
@@ -253,6 +254,17 @@ void BuyDialog::updateButtonsAndLabels()
mMaxItems = 1;
}
+ // Calculate how many the player can carry
+ const int itemWeight = shopItem->getInfo().getWeight();
+ if (itemWeight > 0)
+ {
+ const int myTotalWeight = PlayerInfo::getAttribute(TOTAL_WEIGHT);
+ const int myMaxWeight = PlayerInfo::getAttribute(MAX_WEIGHT);
+ const int myFreeWeight = myMaxWeight - myTotalWeight;
+ const int canCarry = myFreeWeight / itemWeight;
+ mMaxItems = std::min(mMaxItems, canCarry);
+ }
+
if (mAmountItems > mMaxItems)
mAmountItems = mMaxItems;