Module:Shop: Difference between revisions

7,270 bytes removed ,  9 September 2023
Move certain functions to Module:Common and remove purchase override data in favour of standard implementation in Module:Icons
(getCookingUtilityTable: Add mastery XP modifier for cooking pot table)
(Move certain functions to Module:Common and remove purchase override data in favour of standard implementation in Module:Icons)
Line 4: Line 4:
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Pets = require('Module:Pets')
local Pets = require('Module:Pets')
-- Overrides for various items, mostly relating to icon overrides
local purchOverrides = {
["Extra Bank Slot"] = { icon = {'Bank Slot', 'upgrade'}, link = 'Bank Slot' },
-- Golbin Raid items
["Reduce Wave Skip Cost"] = { icon = {'Melvor Logo', nil}, link = nil },
["Food Bonus"] = { icon = {'Melvor Logo', nil}, link = nil },
["Ammo Gatherer"] = { icon = {'Melvor Logo', nil}, link = nil },
["Rune Pouch"] = { icon = {'Melvor Logo', nil}, link = nil },
["Increase Starting Prayer Points"] = { icon = {'Melvor Logo', nil}, link = nil },
["Unlock Combat Passive Slot"] = { icon = {'Melvor Logo', nil}, link = nil },
["Prayer"] = { icon = {'Prayer', 'skill'}, link = nil },
["Increase Prayer Level"] = { icon = {'Prayer', 'skill'}, link = nil },
["Increase Prayer Points gained per Wave Completion"] = { icon = {'Prayer', 'skill'}, link = nil },
["Faster Golbin Spawns"] = { icon = {'Timer', nil}, link = nil },
["Golbin Crate"] = { icon = {'Golbin Crate', 'upgrade'}, link = nil }
}


function p.getPurchase(purchaseName)
function p.getPurchase(purchaseName)
    local purchList = p.getPurchases(function(purch) return p._getPurchaseName(purch) == purchaseName end)
local purchList = p.getPurchases(function(purch) return Common.getPurchaseName(purch) == purchaseName end)
    if purchList ~= nil and not Shared.tableIsEmpty(purchList) then
if purchList ~= nil and not Shared.tableIsEmpty(purchList) then
        return purchList[1]
return purchList[1]
    end
end
end
end


Line 37: Line 21:


function p.getPurchases(checkFunc)
function p.getPurchases(checkFunc)
    return GameData.getEntities('shopPurchases', checkFunc)
return GameData.getEntities('shopPurchases', checkFunc)
end
end


Line 45: Line 29:
return p.getCostString(purchase.cost, displayInline)
return p.getCostString(purchase.cost, displayInline)
elseif stat == 'requirements' then
elseif stat == 'requirements' then
return p.getRequirementString(purchase.purchaseRequirements)
return Common.getRequirementString(purchase.purchaseRequirements, 'None')
elseif stat == 'contents' then
elseif stat == 'contents' then
return p._getPurchaseContents(purchase, true)
return p._getPurchaseContents(purchase, true)
elseif stat == 'type' then
elseif stat == 'type' then
return p._getPurchaseType(purchase)
return Common.getPurchaseType(purchase)
elseif stat == 'buyLimit' then
elseif stat == 'buyLimit' then
return p._getPurchaseBuyLimit(purchase, not displayInline)
return p._getPurchaseBuyLimit(purchase, not displayInline)
Line 71: Line 55:
local purchaseList = {}
local purchaseList = {}
if statName == 'cost' then
if statName == 'cost' then
purchaseList = p.getPurchases(function(purch) return p._getPurchaseName(purch) == purchaseName end)
purchaseList = p.getPurchases(function(purch) return Common.getPurchaseName(purch) == purchaseName end)
else
else
purchaseList = {p.getPurchase(purchaseName)}
purchaseList = {p.getPurchase(purchaseName)}
Line 85: Line 69:
return table.concat(resultPart, ' or ')
return table.concat(resultPart, ' or ')
end
end
end
function p._getPurchaseName(purch)
    if purch.customName ~= nil then
        return purch.customName
    elseif purch.contains ~= nil then
    local item = nil
        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
        if item ~= nil then
            return item.name
        end
        if purch.contains.petID ~= nil then
            local pet = Pets.getPetByID(purch.contains.petID)
            if pet ~= nil then
                return pet.name
            end
        end
    end
    return ''
end
end


function p._getPurchaseExpansionIcon(purch)
function p._getPurchaseExpansionIcon(purch)
    if purch.id ~= nil then
if purch.id ~= nil then
        return Icons.getExpansionIcon(purch.id)
return Icons.getExpansionIcon(purch.id)
    elseif purch.contains ~= nil then
elseif purch.contains ~= nil then
    local item = nil
local item = nil
        if purch.contains.items ~= nil and not Shared.tableIsEmpty(purch.contains.items) then
if purch.contains.items ~= nil and not Shared.tableIsEmpty(purch.contains.items) then
            return Icons.getExpansionIcon(purch.contains.items[1].id)
return Icons.getExpansionIcon(purch.contains.items[1].id)
        elseif purch.contains.itemCharges ~= nil and not Shared.tableIsEmpty(purch.contains.itemCharges) then
elseif purch.contains.itemCharges ~= nil and not Shared.tableIsEmpty(purch.contains.itemCharges) then
        return Icons.getExpansionIcon(purch.contains.itemCharges.id)
return Icons.getExpansionIcon(purch.contains.itemCharges.id)
        end
end
       
        if purch.contains.petID ~= nil then
if purch.contains.petID ~= nil then
return Icons.getExpansionIcon(purch.contains.petID)
return Icons.getExpansionIcon(purch.contains.petID)
        end
end
    end
end
    return ''
return ''
end
end


Line 137: Line 98:
return Constants.getModifiersText(purch.contains.modifiers, false)
return Constants.getModifiersText(purch.contains.modifiers, false)
elseif purch.contains.petID ~= nil then
elseif purch.contains.petID ~= nil then
            local pet = Pets.getPetByID(purch.contains.petID)
local pet = Pets.getPetByID(purch.contains.petID)
            return Pets._getPetEffect(pet)
return Pets._getPetEffect(pet)
elseif purch.contains.items ~= nil and Shared.tableCount(purch.contains.items) == 1 then
elseif purch.contains.items ~= nil and Shared.tableCount(purch.contains.items) == 1 then
item = Items.getItemByID(purch.contains.items[1].id)
item = Items.getItemByID(purch.contains.items[1].id)
Line 158: Line 119:
local displayInline = (inline ~= nil and inline or false)
local displayInline = (inline ~= nil and inline or false)
local costArray = {}
local costArray = {}
    local currencies = {'gp', 'slayerCoins', 'raidCoins'}
local currencies = {'gp', 'slayerCoins', 'raidCoins'}
    for i, currency in ipairs(currencies) do
for i, currency in ipairs(currencies) do
        if cost[currency] ~= nil then
if cost[currency] ~= nil then
            local costStr = p.getCurrencyCostString(cost[currency], currency)
local costStr = p.getCurrencyCostString(cost[currency], currency)
            if costStr ~= nil then
if costStr ~= nil then
                table.insert(costArray, costStr)
table.insert(costArray, costStr)
            end
end
        end
end
    end
end
if cost.items ~= nil and not Shared.tableIsEmpty(cost.items) then
if cost.items ~= nil and not Shared.tableIsEmpty(cost.items) then
        local itemArray = {}
local itemArray = {}
for i, itemCost in ipairs(cost.items) do
for i, itemCost in ipairs(cost.items) do
local item = Items.getItemByID(itemCost.id)
local item = Items.getItemByID(itemCost.id)
            if item ~= nil then
if item ~= nil then
    table.insert(itemArray, Icons.Icon({item.name, type="item", notext=(not displayInline and true or nil), qty=itemCost.quantity}))
table.insert(itemArray, Icons.Icon({item.name, type="item", notext=(not displayInline and true or nil), qty=itemCost.quantity}))
            end
end
end
if not Shared.tableIsEmpty(itemArray) then
table.insert(costArray, table.concat(itemArray, ', '))
end
end
        if not Shared.tableIsEmpty(itemArray) then
            table.insert(costArray, table.concat(itemArray, ', '))
        end
end
end


    if not Shared.tableIsEmpty(costArray) then
if not Shared.tableIsEmpty(costArray) then
        local sep, lastSep = '<br/>', '<br/>'
local sep, lastSep = '<br/>', '<br/>'
        if displayInline then
if displayInline then
            sep = ', '
sep = ', '
            lastSep = Shared.tableCount(costArray) > 2 and ', and ' or ' and '
lastSep = Shared.tableCount(costArray) > 2 and ', and ' or ' and '
        end
end
        return mw.text.listToText(costArray, sep, lastSep)
return mw.text.listToText(costArray, sep, lastSep)
    end
end
end
end


Line 203: Line 164:


function p.getCurrencyCostString(cost, currency)
function p.getCurrencyCostString(cost, currency)
    local decoratorList = {
local decoratorList = {
        ["gp"] = Icons.GP,
["gp"] = Icons.GP,
        ["slayerCoins"] = Icons.SC,
["slayerCoins"] = Icons.SC,
        ["raidCoins"] = Icons.RC
["raidCoins"] = Icons.RC
    }
}
    local decorator = nil
local decorator = nil
    if currency ~= nil then
if currency ~= nil then
        decorator = decoratorList[currency]
decorator = decoratorList[currency]
    end
end
    if decorator == nil then
if decorator == nil then
        decorator = function(cost) return cost end
decorator = function(cost) return cost end
    end
 
    if cost.type == 'BankSlot' then
        -- Unusual bit of code that basically evaluates wikitext '<math>C_b</math>*'
        return mw.getCurrentFrame():callParserFunction('#tag:math', {'C_b'}) .. '*'
    elseif cost.type == 'Linear' and (cost.initial > 0 or cost.scaling > 0) then
        return decorator(cost.initial) .. '<br/>+' .. decorator(cost.scaling) .. ' for each purchase'
    elseif cost.type == 'Glove' or cost.type == 'Fixed' and cost.cost > 0 then
        -- Type Glove exists in game so the Merchan's Permit cost reduction can be applied,
        -- it makes no difference here
        return decorator(cost.cost)
    end
end
 
function p.getRequirementString(reqs)
if reqs == nil or Shared.tableIsEmpty(reqs) then
return 'None'
end
end


local reqArray = {}
if cost.type == 'BankSlot' then
    for i, req in ipairs(reqs) do
-- Unusual bit of code that basically evaluates wikitext '<math>C_b</math>*'
        if req.type == 'SkillLevel' then
return mw.getCurrentFrame():callParserFunction('#tag:math', {'C_b'}) .. '*'
            local skillName = Constants.getSkillName(req.skillID)
elseif cost.type == 'Linear' and (cost.initial > 0 or cost.scaling > 0) then
            if skillName ~= nil then
return decorator(cost.initial) .. '<br/>+' .. decorator(cost.scaling) .. ' for each purchase'
                table.insert(reqArray, Icons._SkillReq(skillName, req.level))
elseif cost.type == 'Glove' or cost.type == 'Fixed' and cost.cost > 0 then
            end
-- Type Glove exists in game so the Merchan's Permit cost reduction can be applied,
        elseif req.type == 'DungeonCompletion' then
-- it makes no difference here
            local dung = GameData.getEntityByID('dungeons', req.dungeonID)
return decorator(cost.cost)
            if dung ~= nil then
                local dungStr = 'Complete ' .. Icons.Icon({dung.name, type='dungeon'})
                if req.count > 1 then
                    dungStr = dungStr .. ' ' .. Shared.formatnum(req.count) .. ' times'
                end
                table.insert(reqArray, dungStr)
            end
        elseif req.type == 'SlayerTask' then
            table.insert(reqArray, 'Complete ' .. Shared.formatnum(req.count) .. ' ' .. req.tier .. ' Slayer Tasks')
        elseif req.type == 'TownshipTask' then
            table.insert(reqArray, 'Complete ' .. Shared.formatnum(req.count) .. ' Township Tasks')
        elseif req.type == 'TownshipBuilding' then
            local tsData = GameData.getSkillData('melvorD:Township')
            if tsData ~= nil and tsData.buildings ~= nil then
                local building = GameData.getEntityByID(tsData.buildings, req.buildingID)
                if building ~= nil then
                    table.insert(reqArray, 'Have ' .. Shared.formatnum(req.count) .. ' ' .. building.name .. ' actively built in Township')
                end
            end
        elseif req.type == 'ShopPurchase' then
        local shopPurch = p.getPurchaseByID(req.purchaseID)
        if shopPurch ~= nil then
        table.insert(reqArray, p._getPurchaseIcon({shopPurch}) .. ' Purchased')
        end
        elseif req.type == 'Completion' then
            local ns = GameData.getEntityByName('namespaces', req.namespace)
            if ns ~= nil then
                table.insert(reqArray, req.percent .. '% ' .. ns.displayName .. ' Completion')
            end
        elseif req.type == 'AllSkillLevels' then
            local reqText = 'Level ' .. req.level .. ' in all skills'
            if req.exceptions ~= nil and not Shared.tableIsEmpty(req.exceptions) then
                local exceptSkills = {}
                for i, skillID in ipairs(req.exceptions) do
                    local skillName = Constants.getSkillName(skillID)
                    if skillName ~= nil then
                        table.insert(exceptSkills, Icons.Icon({skillName, type='skill'}))
                    end
                end
                reqText = reqText .. ' except for ' .. table.concat(exceptSkills, ', ')
            end
            table.insert(reqArray, reqText)
        elseif req.type == 'ArchaeologyItemsDonated' then
        table.insert(reqArray, 'Donate ' .. Shared.formatnum(req.count) .. ' Artefacts to the Museum in ' .. Icons.Icon({'Archaeology', type='skill'}))
        else
            table.insert(reqArray, Shared.printError('Unknown requirement: ' .. (req.type or 'nil')))
        end
    end
 
    if Shared.tableIsEmpty(reqArray) then
        return 'None'
    else
    return table.concat(reqArray, '<br/>')
    end
end
 
function p._getPurchaseType(purchase)
if purchase.contains == nil then
return 'Unknown'
elseif purchase.contains.petID ~= nil then
return 'Pet'
elseif purchase.contains.itemCharges ~= nil then
return 'Item'
elseif purchase.contains.modifiers ~= nil or purchase.contains.items == nil or Shared.tableCount(purchase.contains.items) == 0 then
return 'Upgrade'
elseif purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then
return 'Item Bundle'
else
return 'Item'
end
end
end
end
Line 327: Line 202:
for i, itemLine in ipairs(purchase.contains.items) do
for i, itemLine in ipairs(purchase.contains.items) do
local item = Items.getItemByID(itemLine.id)
local item = Items.getItemByID(itemLine.id)
            local itemQty = itemLine.quantity
local itemQty = itemLine.quantity
if asList then
if asList then
table.insert(containArray, Icons.Icon({item.name, type='item', qty=itemQty}))
table.insert(containArray, Icons.Icon({item.name, type='item', qty=itemQty}))
Line 340: Line 215:
end
end
if purchase.contains.itemCharges ~= nil and purchase.contains.itemCharges.quantity > 0 then
if purchase.contains.itemCharges ~= nil and purchase.contains.itemCharges.quantity > 0 then
        local gloveItem = Items.getItemByID(purchase.contains.itemCharges.id)
local gloveItem = Items.getItemByID(purchase.contains.itemCharges.id)
        local chargeQty = purchase.contains.itemCharges.quantity
local chargeQty = purchase.contains.itemCharges.quantity
        if gloveItem ~= nil then
if gloveItem ~= nil then
            if asList then
if asList then
                table.insert(containArray, '+'..Shared.formatnum(chargeQty)..' '..Icons.Icon({gloveItem.name, type='item'})..' Charges')
table.insert(containArray, '+'..Shared.formatnum(chargeQty)..' '..Icons.Icon({gloveItem.name, type='item'})..' Charges')
            else
else
                table.insert(containArray, '|-\r\n| class="table-img"| ' .. Icons.Icon({gloveItem.name, type='item', notext=true, size='25'}))
table.insert(containArray, '|-\r\n| class="table-img"| ' .. Icons.Icon({gloveItem.name, type='item', notext=true, size='25'}))
                table.insert(containArray, '| ' .. Icons.Icon({gloveItem.name, type='item', noicon=true}) .. ' Charges\r\n| data-sort-value="' .. chargeQty .. '" style="text-align:right" | ' .. Shared.formatnum(chargeQty))
table.insert(containArray, '| ' .. Icons.Icon({gloveItem.name, type='item', noicon=true}) .. ' Charges\r\n| data-sort-value="' .. chargeQty .. '" style="text-align:right" | ' .. Shared.formatnum(chargeQty))
                table.insert(containArray, '| data-sort-value="0"| ' .. Icons.GP(0))
table.insert(containArray, '| data-sort-value="0"| ' .. Icons.GP(0))
            end
end
        end
end
end
end
end
end
Line 387: Line 262:
function p._getPurchaseBuyLimit(purchase, asList)
function p._getPurchaseBuyLimit(purchase, asList)
if asList == nil then asList = true end
if asList == nil then asList = true end
    local defaultLimit = (purchase.defaultBuyLimit == 0 and 'Unlimited') or Shared.formatnum(purchase.defaultBuyLimit)
local defaultLimit = (purchase.defaultBuyLimit == 0 and 'Unlimited') or Shared.formatnum(purchase.defaultBuyLimit)
    if purchase.buyLimitOverrides == nil or Shared.tableIsEmpty(purchase.buyLimitOverrides) then
if purchase.buyLimitOverrides == nil or Shared.tableIsEmpty(purchase.buyLimitOverrides) then
        -- Same limit for all game modes
-- Same limit for all game modes
        return defaultLimit
return defaultLimit
    else
else
        -- The limit varies depending on game mode
-- The limit varies depending on game mode
        local limitTable = {}
local limitTable = {}
        local gamemodeHasIcon = { 'melvorF:Hardcore', 'melvorF:Adventure' }
local gamemodeHasIcon = { 'melvorF:Hardcore', 'melvorF:Adventure' }
        for i, buyLimit in ipairs(purchase.buyLimitOverrides) do
for i, buyLimit in ipairs(purchase.buyLimitOverrides) do
            local gamemode = GameData.getEntityByID('gamemodes', buyLimit.gamemodeID)
local gamemode = GameData.getEntityByID('gamemodes', buyLimit.gamemodeID)
            if gamemode ~= nil then
if gamemode ~= nil then
local gamemodeName = Shared.splitString(gamemode.name, ' ')[1]
local gamemodeName = Shared.splitString(gamemode.name, ' ')[1]
                local gamemodeText = nil
local gamemodeText = nil
                if Shared.contains(gamemodeHasIcon, gamemode.id) then
if Shared.contains(gamemodeHasIcon, gamemode.id) then
                    gamemodeText = Icons.Icon({gamemodeName, notext=(not asList or nil)})
gamemodeText = Icons.Icon({gamemodeName, notext=(not asList or nil)})
                else
else
                    gamemodeText = '[[Game Mode#' .. gamemodeName .. '|' .. gamemodeName .. ']]'
gamemodeText = '[[Game Mode#' .. gamemodeName .. '|' .. gamemodeName .. ']]'
                end
end
                local limitText = (buyLimit.maximum == 0 and 'Unlimited') or Shared.formatnum(buyLimit.maximum)
local limitText = (buyLimit.maximum == 0 and 'Unlimited') or Shared.formatnum(buyLimit.maximum)
                table.insert(limitTable, limitText .. (asList and ' for ' or ' ') .. gamemodeText)
table.insert(limitTable, limitText .. (asList and ' for ' or ' ') .. gamemodeText)
            end
end
        end
end
        table.insert(limitTable, defaultLimit .. (asList and ' for ' or ' ') .. 'All other game modes')
table.insert(limitTable, defaultLimit .. (asList and ' for ' or ' ') .. 'All other game modes')
        return table.concat(limitTable, (asList and ' or ' or '<br/>'))
return table.concat(limitTable, (asList and ' or ' or '<br/>'))
    end
end
end
end


Line 425: Line 300:
return p._getPurchaseBuyLimit(purchase, asList)
return p._getPurchaseBuyLimit(purchase, asList)
end
end
end
-- Accept similar arguments to Icons.Icon
function p._getPurchaseIcon(iconArgs)
local purchase = iconArgs[1]
    local purchaseName = p._getPurchaseName(purchase)
local override = purchOverrides[purchaseName]
local purchType = p._getPurchaseType(purchase)
-- Amend iconArgs before passing to Icons.Icon()
iconArgs[1] = ((override ~= nil and override.icon[1]) or purchaseName)
if override ~= nil then
iconArgs['type'] = override.icon[2]
if override.link == nil then
iconArgs['nolink'] = true
end
else
iconArgs['type'] = (purchType == 'Item Bundle' and 'item') or string.lower(purchType)
end
return Icons.Icon(iconArgs)
end
end


Line 456: Line 311:
else
else
args[1] = purchase
args[1] = purchase
return p._getPurchaseIcon(args)
return Common.getPurchaseIcon(args)
end
end
end
end
Line 464: Line 319:
for j, curr in ipairs(costCurrencies) do
for j, curr in ipairs(costCurrencies) do
local costAmt = purchase.cost[curr]
local costAmt = purchase.cost[curr]
        if costAmt.type == 'BankSlot' then
if costAmt.type == 'BankSlot' then
            return -1
return -1
        elseif costAmt.type == 'Linear' then
elseif costAmt.type == 'Linear' then
            return costAmt.initial
return costAmt.initial
        elseif costAmt.type == 'Glove' or costAmt.type == 'Fixed' and costAmt.cost > 0 then
elseif costAmt.type == 'Glove' or costAmt.type == 'Fixed' and costAmt.cost > 0 then
            return costAmt.cost
return costAmt.cost
        end
end
    end
end
end
end


Line 537: Line 392:
end
end
for i, purchase in ipairs(Purchases) do
for i, purchase in ipairs(Purchases) do
        local purchName = p._getPurchaseName(purchase)
local purchName = Common.getPurchaseName(purchase)
        local purchExpIcon = p._getPurchaseExpansionIcon(purchase)
local purchExpIcon = p._getPurchaseExpansionIcon(purchase)
local purchOverride = nil
local purchType = Common.getPurchaseType(purchase)
if purchOverrides ~= nil then
purchOverride = purchOverrides[purchName]
end
 
local purchType = p._getPurchaseType(purchase)
local iconNoLink = nil
local purchLink = ''
local costString = p.getCostString(purchase.cost, false)
local costString = p.getCostString(purchase.cost, false)
if purchOverride ~= nil then
if purchOverride.link == nil then
iconNoLink = true
else
purchLink = purchOverride.link .. '|'
end
end
        local purchSortName = purchName
if iconNoLink == nil or iconNoLink ~= true then purchName = '[[' .. purchLink .. purchName .. ']]' end


table.insert(resultPart, '|-')
table.insert(resultPart, '|-')
for j, column in ipairs(usedColumns) do
for j, column in ipairs(usedColumns) do
if column == 'Purchase' then
if column == 'Purchase' then
table.insert(resultPart, '|class="table-img"|' .. p._getPurchaseIcon({purchase, notext=true, size='50'}))
table.insert(resultPart, '|class="table-img"|' .. Common.getPurchaseIcon({purchase, notext=true, size='50'}))
--table.insert(resultPart, '|class="table-img"|' .. Icons.Icon({iconName, type=iconType, notext=true, nolink=iconNoLink, size='50'}))
table.insert(resultPart, '| data-sort-value="'..purchName..'"|'..purchExpIcon .. Common.getPurchaseIcon({purchase, noicon=true}))
table.insert(resultPart, '| data-sort-value="'..purchSortName..'"|'..purchExpIcon .. purchName)
elseif column == 'Type' then
elseif column == 'Type' then
table.insert(resultPart, '| ' .. purchType)
table.insert(resultPart, '| ' .. purchType)
Line 575: Line 412:
table.insert(resultPart, cellProp .. '| ' .. costString)
table.insert(resultPart, cellProp .. '| ' .. costString)
elseif column == 'Requirements' then
elseif column == 'Requirements' then
table.insert(resultPart, '| ' .. p.getRequirementString(purchase.purchaseRequirements))
table.insert(resultPart, '| ' .. Common.getRequirementString(purchase.purchaseRequirements, 'None'))
elseif column == 'Buy Limit' then
elseif column == 'Buy Limit' then
local buyLimit = p._getPurchaseBuyLimit(purchase, false)
local buyLimit = p._getPurchaseBuyLimit(purchase, false)
Line 620: Line 457:
end
end
end
end
    local shopCat = GameData.getEntityByName('shopCategories', cat)
local shopCat = GameData.getEntityByName('shopCategories', cat)
if shopCat == nil then
if shopCat == nil then
return Shared.printError('Invalid category ' .. cat)
return Shared.printError('Invalid category ' .. cat)
else
else
        local catPurchases = p.getPurchases(function(purch) return purch.category == shopCat.id end)
local catPurchases = p.getPurchases(function(purch) return purch.category == shopCat.id end)
return p._getShopTable(catPurchases, options)
return p._getShopTable(catPurchases, options)
end
end
Line 630: Line 467:


function p.getItemCostArray(itemID)
function p.getItemCostArray(itemID)
    local purchaseArray = {}
local purchaseArray = {}
    for i, purchase in ipairs(GameData.rawData.shopPurchases) do
for i, purchase in ipairs(GameData.rawData.shopPurchases) do
        if purchase.cost ~= nil and purchase.cost.items ~= nil then
if purchase.cost ~= nil and purchase.cost.items ~= nil then
            for j, itemCost in ipairs(purchase.cost.items) do
for j, itemCost in ipairs(purchase.cost.items) do
                if itemCost.id == itemID then
if itemCost.id == itemID then
                    table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = itemCost.quantity })
table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = itemCost.quantity })
                    break
break
                end
end
            end
end
        end
end
    end
end
    return purchaseArray
return purchaseArray
end
end


function p.getItemSourceArray(itemID)
function p.getItemSourceArray(itemID)
    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 then
if purchase.contains ~= nil then
        if purchase.contains.items ~= nil then
if purchase.contains.items ~= nil then
            for j, itemContains in ipairs(purchase.contains.items) do
for j, itemContains in ipairs(purchase.contains.items) do
                if itemContains.id == itemID then
if itemContains.id == itemID then
                    table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = itemContains.quantity })
table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = itemContains.quantity })
                    break
break
                end
end
            end
end
        end
end
        if purchase.contains.itemCharges ~= nil and purchase.contains.itemCharges.id == itemID then
if purchase.contains.itemCharges ~= nil and purchase.contains.itemCharges.id == itemID then
        table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = 1 })
table.insert(purchaseArray, { ["purchase"] = purchase, ["qty"] = 1 })
        end
end
        end
end
    end
end
    return purchaseArray
return purchaseArray
end
end


Line 668: Line 505:
result = result..'\r\n!colspan="2"|'..Icons.Icon({'Shop'})..' Purchase'
result = result..'\r\n!colspan="2"|'..Icons.Icon({'Shop'})..' Purchase'
if purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then
if purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 1 then
result = result..' - '..p._getPurchaseExpansionIcon(purchase)..Icons.Icon({p._getPurchaseName(purchase), type='item'})
result = result..' - '..p._getPurchaseExpansionIcon(purchase)..Icons.Icon({Common.getPurchaseName(purchase), type='item'})
end
end


Line 675: Line 512:


result = result..'\r\n|-\r\n!style="text-align:right;"|Requirements'
result = result..'\r\n|-\r\n!style="text-align:right;"|Requirements'
result = result..'\r\n|'..p.getRequirementString(purchase.purchaseRequirements)
result = result..'\r\n|'..Common.getRequirementString(purchase.purchaseRequirements, 'None')


result = result..'\r\n|-\r\n!style="text-align:right;"|Contains'
result = result..'\r\n|-\r\n!style="text-align:right;"|Contains'
Line 718: Line 555:
local costA, costB = p._getPurchaseSortValue(a), p._getPurchaseSortValue(b)
local costA, costB = p._getPurchaseSortValue(a), p._getPurchaseSortValue(b)
if costA == costB then
if costA == costB then
return p._getPurchaseName(a) < p._getPurchaseName(b)
return Common.getPurchaseName(a) < Common.getPurchaseName(b)
else
else
return costA < costB
return costA < costB
Line 744: Line 581:
local capeList = {}
local capeList = {}
if skillName == 'HP' or skillName == 'Hitpoints' then
if skillName == 'HP' or skillName == 'Hitpoints' then
capeList = p.getPurchases(function(purch) return Shared.contains({'melvorD:Skillcapes', 'melvorTotH:SuperiorSkillcapes'}, purch.category) and (p._getPurchaseName(purch) == 'HP Skillcape' or p._getPurchaseName(purch) == 'Superior Hitpoints Skillcape') end)
capeList = p.getPurchases(function(purch) return Shared.contains({'melvorD:Skillcapes', 'melvorTotH:SuperiorSkillcapes'}, purch.category) and (Common.getPurchaseName(purch) == 'HP Skillcape' or Common.getPurchaseName(purch) == 'Superior Hitpoints Skillcape') end)
else
else
capeList = p.getPurchases(function(purch) return Shared.contains({'melvorD:Skillcapes', 'melvorTotH:SuperiorSkillcapes'}, purch.category) and string.find(p._getPurchaseName(purch), skillName) end)
capeList = p.getPurchases(function(purch) return Shared.contains({'melvorD:Skillcapes', 'melvorTotH:SuperiorSkillcapes'}, purch.category) and string.find(Common.getPurchaseName(purch), skillName) end)
end
end
if Shared.tableIsEmpty(capeList) then
if Shared.tableIsEmpty(capeList) then
Line 759: Line 596:
table.insert(resultPart, '\r\n|-\r\n| ' .. Icons.Icon({capeItem.name, type='item', size='60', notext=true}))
table.insert(resultPart, '\r\n|-\r\n| ' .. Icons.Icon({capeItem.name, type='item', size='60', notext=true}))
table.insert(resultPart, '\r\n| data-sort-value="'..capeItem.name..'"|'..Icons.getExpansionIcon(capeItem.id) .. Icons.Icon({capeItem.name, type='item', noicon=true}))
table.insert(resultPart, '\r\n| data-sort-value="'..capeItem.name..'"|'..Icons.getExpansionIcon(capeItem.id) .. Icons.Icon({capeItem.name, type='item', noicon=true}))
table.insert(resultPart, '\r\n| ' .. p.getRequirementString(cape.purchaseRequirements))
table.insert(resultPart, '\r\n| ' .. Common.getRequirementString(cape.purchaseRequirements, 'None'))
table.insert(resultPart, '\r\n| ' .. p._getPurchaseDescription(cape))
table.insert(resultPart, '\r\n| ' .. p._getPurchaseDescription(cape))
end
end
Line 780: Line 617:
local mods = {["increasedAutoEatEfficiency"] = 0, ["increasedAutoEatHPLimit"] = 0, ["increasedAutoEatThreshold"] = 0}
local mods = {["increasedAutoEatEfficiency"] = 0, ["increasedAutoEatHPLimit"] = 0, ["increasedAutoEatThreshold"] = 0}
for i, purchase in ipairs(purchasesAE) do
for i, purchase in ipairs(purchasesAE) do
        local purchaseName = p._getPurchaseName(purchase)
local purchaseName = Common.getPurchaseName(purchase)
-- Modifiers must be accumulated as we go
-- Modifiers must be accumulated as we go
for modName, modValue in pairs(mods) do
for modName, modValue in pairs(mods) do
Line 806: Line 643:
local getGodDungeon =
local getGodDungeon =
function(reqs)
function(reqs)
            for i, req in ipairs(reqs) do
for i, req in ipairs(reqs) do
                if req.type == 'DungeonCompletion' and string.find(req.dungeonID, 'God_Dungeon$') ~= nil then
if req.type == 'DungeonCompletion' and string.find(req.dungeonID, 'God_Dungeon$') ~= nil then
                    return GameData.getEntityByID('dungeons', req.dungeonID)
return GameData.getEntityByID('dungeons', req.dungeonID)
                end
end
            end
end
        end
end


local upgradeList = p.getPurchases(
local upgradeList = p.getPurchases(
Line 821: Line 658:
end)
end)
if Shared.tableIsEmpty(upgradeList) then
if Shared.tableIsEmpty(upgradeList) then
        return ''
return ''
    end
end


-- Table header
-- Table header
Line 831: Line 668:
-- Rows for each God upgrade
-- Rows for each God upgrade
for i, upgrade in ipairs(upgradeList) do
for i, upgrade in ipairs(upgradeList) do
        local upgradeName = p._getPurchaseName(upgrade)
local upgradeName = Common.getPurchaseName(upgrade)
local dung = getGodDungeon(upgrade.purchaseRequirements)
local dung = getGodDungeon(upgrade.purchaseRequirements)
local costSortValue = p._getPurchaseSortValue(upgrade)
local costSortValue = p._getPurchaseSortValue(upgrade)
Line 886: Line 723:
local modsUnused = {}
local modsUnused = {}
for i, tool in ipairs(toolArray) do
for i, tool in ipairs(toolArray) do
local toolName = p._getPurchaseName(tool)
local toolName = Common.getPurchaseName(tool)
local toolCost = p.getCostString(tool.cost, false)
local toolCost = p.getCostString(tool.cost, false)
local toolCostSort = p._getPurchaseSortValue(tool) or 0
local toolCostSort = p._getPurchaseSortValue(tool) or 0
Line 903: Line 740:
if skillID == nil then
if skillID == nil then
-- Return all requirements
-- Return all requirements
level = p.getRequirementString(tool.purchaseRequirements)
level = Common.getRequirementString(tool.purchaseRequirements, 'None')
if level ~= 'None' then
if level ~= 'None' then
levelStyle = ''
levelStyle = ''
Line 1,027: Line 864:


return p.getToolTable(categoryShort, categoryShort .. '$', modifiers[category], nil)
return p.getToolTable(categoryShort, categoryShort .. '$', modifiers[category], nil)
end
-- Below functions included for backwards compatibility
-- TODO: Remove dependency on these functions in all other modules
function p._getPurchaseName(purchase)
return Common.getPurchaseName(purchase)
end
function p._getPurchaseType(purchase)
return Common.getPurchaseType(purchase)
end
function p._getPurchaseIcon(iconArgs)
return Common.getPurchaseIcon(iconArgs)
end
function p.getRequirementString(reqs)
return Common.getRequirementString(reqs, 'None')
end
end


return p
return p