diff --git a/core/ShopState.lua b/core/ShopState.lua index 55a6f60..2351d23 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -179,7 +179,11 @@ end local available = amountPurchased for _, productPurchased in ipairs(productsPurchased) do - local productSources, productAvailable = ScanInventory.findProductItems(self.products, productPurchased.product, productPurchased.quantity * amountPurchased) + local onInventoryRefresh + if self.eventHooks and self.eventHooks.onInventoryRefresh then + onInventoryRefresh = self.eventHooks.onInventoryRefresh + end + local productSources, productAvailable = ScanInventory.findProductItems(self.products, productPurchased.product, productPurchased.quantity * amountPurchased, onInventoryRefresh) available = math.min(available, math.floor(productAvailable / productPurchased.quantity)) productPurchased.sources = productSources if available == 0 then diff --git a/core/inventory/ScanInventory.lua b/core/inventory/ScanInventory.lua index 6cf2339..a5a12c0 100644 --- a/core/inventory/ScanInventory.lua +++ b/core/inventory/ScanInventory.lua @@ -243,13 +243,13 @@ return sources, quantity - remaining end -local function findProductItems(products, product, quantity) +local function findProductItems(products, product, quantity, onInventoryRefresh) local sources = nil local amount = 0 local items = getItemCache() sources, amount = findProductItemsFrom(product, quantity, items, true) if amount == 0 then - updateProductInventory(products) + updateProductInventory(products, onInventoryRefresh) items = getItemCache() sources, amount = findProductItemsFrom(product, quantity, items) end