Does UIS notify when player try to purchase, but don't have enough money ?

oscarleif

New member
Hello I just was wondering if this is already implemented. I check the demo scene but nothing will happen when you open the shop and try to purchase any item when you don't have enough money.
When you purchase any item the Inventory monitor will trigger a "Item Stack Monitor" i think this is missing.
 
The Shop.BuyItem function returns true if the item was bought correctly and false if it was not.
It's true that we do not do anything whith that returned value.

Here I made some changes to the ShopMenu to invoke some events when the buy/sell is successful/failed:

Add those fields bellow the existing fields
Code:
        [Tooltip("Event invoked when the the item was bought successfully.")]
        [SerializeField] protected UnityEvent m_OnBuySuccess;
        [Tooltip("Event invoked when the the item was bought unsuccessfully.")]
        [SerializeField] protected UnityEvent m_OnBuyFailed;
        [Tooltip("Event invoked when the the item was sold successfully.")]
        [SerializeField] protected UnityEvent m_OnSellSuccess;
        [Tooltip("Event invoked when the the item was sold unsuccessfully.")]
        [SerializeField] protected UnityEvent m_OnSellFailed;


And replace this function
Code:
 /// <summary>
 /// Buy or sell an item once the player confirmed the quantity.
 /// </summary>
 protected virtual void BuySellItem()
 {
     var quantity = m_QuantityPickerPanel.QuantityPicker.Quantity;
     if (quantity < 1) {
         if (m_IsBuying) {
             m_OnBuyFailed?.Invoke();
         } else {
             m_OnSellFailed?.Invoke();
         }
         return;
     }
     if (m_IsBuying) {
         var result = m_Shop.BuyItem(m_Inventory, m_ShopperClientCurrencyOwner, (quantity, m_SelectedItemInfo));
         if (result) {
             m_OnBuySuccess?.Invoke();
         } else {
             m_OnBuyFailed?.Invoke();
         }
     } else {
         var result = m_Shop.SellItem(m_Inventory, m_ShopperClientCurrencyOwner, (quantity, m_SelectedItemInfo));
         if (result) {
             m_OnSellSuccess?.Invoke();
         } else {
             m_OnSellFailed?.Invoke();
         }
     }
     m_InventoryGrid.Draw();
 }

I haven't tested it yet, so let me know if someting doesn't work.
 
Top