Anonymous

Module:Shop: Difference between revisions

From Melvor Idle
2,109 bytes added ,  25 July 2021
getAutoEatTable: Initial implementation; getPurchases: Pass category to check function
(getShopSkillcapeTable: Move from Module:Items & enforce min-width for icon column)
(getAutoEatTable: Initial implementation; getPurchases: Pass category to check function)
Line 90: Line 90:


   return table.concat(reqArray, '<br/>')
   return table.concat(reqArray, '<br/>')
end
function p._getPurchaseSortValue(purchase)
  local costCurrencies = {'gp', 'slayerCoins', 'raidCoins'}
  for j, curr in ipairs(costCurrencies) do
    local costAmt = purchase.cost[curr]
    if costAmt ~= nil and costAmt > 0 then
      return costAmt
    end
  end
end
end


Line 97: Line 107:
   result = result..'\r\n!colspan="2"|Purchase!!Type!!Description!!style="min-width:90px"|Cost!!Requirements'
   result = result..'\r\n!colspan="2"|Purchase!!Type!!Description!!style="min-width:90px"|Cost!!Requirements'


  local costCurrencies = {'gp', 'slayerCoins', 'raidCoins'}
   for i, purchase in Shared.skpairs(Purchases) do
   for i, purchase in Shared.skpairs(Purchases) do
     result = result..'\r\n|-\r\n|'
     result = result..'\r\n|-\r\n|'
Line 126: Line 135:
     result = result..'||'..purchase.description..'||style="text-align:right;"'
     result = result..'||'..purchase.description..'||style="text-align:right;"'


     for j, curr in Shared.skpairs(costCurrencies) do
     local sortValue = p._getPurchaseSortValue(purchase)
      local costAmt = purchase.cost[curr]
    if sortValue ~= nil then result = result..' data-sort-value="'..sortValue..'"' end
      if costAmt ~= nil and costAmt > 0 then
        result = result..' data-sort-value="'..costAmt..'"'
        break
      end
    end
     result = result..'|'..p.getCostString(purchase.cost)..'||'..p.getRequirementString(purchase.unlockRequirements)
     result = result..'|'..p.getCostString(purchase.cost)..'||'..p.getRequirementString(purchase.unlockRequirements)
   end
   end
Line 196: Line 200:
   for category, purchaseArray in Shared.skpairs(ShopData.Shop) do
   for category, purchaseArray in Shared.skpairs(ShopData.Shop) do
     for i, purchase in Shared.skpairs(purchaseArray) do
     for i, purchase in Shared.skpairs(purchaseArray) do
       if checkFunc(purchase) then
       if checkFunc(category, purchase) then
         table.insert(purchaseList, p.processPurchase(category, i - 1))
         table.insert(purchaseList, p.processPurchase(category, i - 1))
       end
       end
Line 282: Line 286:


   return result
   return result
end
function p.getAutoEatTable()
  local resultPart = {}
  local purchasesAE = p.getPurchases(function(cat, purch) return string.find(purch.name, '^Auto Eat') ~= nil end)
  -- Table header
  table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
  table.insert(resultPart, '|- class="headerRow-0"')
  table.insert(resultPart, '!colspan="2"|Auto Eat Tier!!Minimum Threshold!!Efficiency!!Max Healing!!Cost')
  -- Rows for each Auto Eat tier
  local mods = {["increasedAutoEatEfficiency"] = 0, ["increasedAutoEatHPLimit"] = 0, ["increasedAutoEatThreshold"] = 0}
  for i, purchase in ipairs(purchasesAE) do
    -- Modifiers must be accumulated as we go
    for modName, modValue in pairs(mods) do
      if purchase.contains.modifiers[modName] ~= nil then
        mods[modName] = mods[modName] + purchase.contains.modifiers[modName]
      end
    end
    local costAmt = p._getPurchaseSortValue(purchase)
    table.insert(resultPart, '|-\r\n|style="min-width:25px; text-align:center;" data-sort-value="' .. purchase.name .. '"| ' .. Icons.Icon({purchase.name, type='upgrade', size=50, notext=true}))
    table.insert(resultPart, '| [[' .. purchase.name .. ']]')
    table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. mods.increasedAutoEatThreshold .. '" | ' .. Shared.formatnum(Shared.round(mods.increasedAutoEatThreshold, 0, 0)) .. '%')
    table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. mods.increasedAutoEatEfficiency .. '" | ' .. Shared.formatnum(Shared.round(mods.increasedAutoEatEfficiency, 0, 0)) .. '%')
    table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. mods.increasedAutoEatHPLimit .. '" | ' .. Shared.formatnum(Shared.round(mods.increasedAutoEatHPLimit, 0, 0)) .. '%')
    table.insert(resultPart, '| style="text-align:right;" data-sort-value="' .. costAmt .. '" | ' .. Icons.GP(costAmt))
  end
  table.insert(resultPart, '|}')
  return table.concat(resultPart, '\r\n')
end
end


return p
return p