Module:Shop: Difference between revisions

getItemSourceArray: Fix handling of itemCharges contents
(getPurchaseByID: Implement)
(getItemSourceArray: Fix handling of itemCharges contents)
Line 579: Line 579:


function p.getItemSourceArray(itemID)
function p.getItemSourceArray(itemID)
        if purch.contains.items ~= nil and not Shared.tableIsEmpty(purch.contains.items) then
            item = Items.getItemByID(purch.contains.items[1].id)
        elseif purch.contains.itemCharges ~= nil and not Shared.tableIsEmpty(purch.contains.itemCharges) then
        item = Items.getItemByID(purch.contains.itemCharges.id)
        end
     local purchaseArray = {}
     local purchaseArray = {}
     for i, purchase in ipairs(GameData.rawData.shopPurchases) do
     for i, purchase in ipairs(GameData.rawData.shopPurchases) do
         if purchase.contains ~= nil and purchase.contains.items ~= nil then
         if purchase.contains ~= nil then
            for j, itemContains in ipairs(purchase.contains.items) do
        if purchase.contains.items ~= nil then
                if itemContains.id == itemID then
            for j, itemContains in ipairs(purchase.contains.items) do
                    table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = itemContains.quantity })
                if itemContains.id == itemID then
                    break
                    table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = itemContains.quantity })
                end
                    break
            end
                end
            end
        end
        if purchase.contains.itemCharges ~= nil and purchase.contains.itemCharges.id == itemID then
        table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = 1 })
        end
         end
         end
     end
     end