Anonymous

Module:Shop: Difference between revisions

From Melvor Idle
Added p.getPurchases for use in the ModifierTables module I'm working on
(Tweaked formatting on shop tables slightly)
(Added p.getPurchases for use in the ModifierTables module I'm working on)
(4 intermediate revisions by 2 users not shown)
Line 8: Line 8:
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Areas = require('Module:CombatAreas')
local Areas = require('Module:CombatAreas')
--Cape of Completion is a special purchase that has to be spoofed since it's not in the code
function p.getCapeOfCompletionPurchase()
  local item = Items.getItem('Cape of Completion')
  local purchase = { category = 'Skillcape', id = -1}
  purchase.name = 'Cape of Completion'
  purchase.description = item.description
  purchase.cost = {gp = item.buysFor}
  purchase.unlockRequirements = {text = '100% Completion Log', items = {}}
  purchase.contains = {items = {{item.id, 1}}}
  return purchase
end


function p.processPurchase(category, purchaseID)
function p.processPurchase(category, purchaseID)
Line 90: Line 76:
       table.insert(reqArray, Icons.Icon({purchase.name, type=(isUpgrade and 'upgrade' or 'item')})..' Purchased')
       table.insert(reqArray, Icons.Icon({purchase.name, type=(isUpgrade and 'upgrade' or 'item')})..' Purchased')
     end
     end
  end
  if reqs.completionPercentage ~= nil then
    table.insert(reqArray, tostring(reqs.completionPercentage) .. '% Completion Log')
   end
   end


Line 151: Line 141:
         for k, costLine in Shared.skpairs(purchase.cost.items) do
         for k, costLine in Shared.skpairs(purchase.cost.items) do
           if costLine[1] == itemID then
           if costLine[1] == itemID then
             table.insert(purchaseArray, p.processPurchase(catName, j - 1))
             local temp = p.processPurchase(catName, j - 1)
            temp.qty = costLine[2]
            table.insert(purchaseArray, temp)
             break
             break
           end
           end
Line 170: Line 162:
         for k, containsLine in Shared.skpairs(purchase.contains.items) do
         for k, containsLine in Shared.skpairs(purchase.contains.items) do
           if containsLine [1] == itemID then
           if containsLine [1] == itemID then
             table.insert(purchaseArray, p.processPurchase(catName, j - 1))
             local temp = p.processPurchase(catName, j - 1)
            temp.qty = containsLine[2]
            table.insert(purchaseArray, temp)
             break
             break
           end
           end
Line 178: Line 172:
   end
   end


   if itemID == 903 then --Special Cape of Completion thing
   return purchaseArray
    table.insert(purchaseArray, p.getCapeOfCompletionPurchase())
end
 
function p.getPurchases(checkFunc)
  local purchaseList = {}
  for category, purchaseArray in Shared.skpairs(ShopData.Shop) do
    for i, purchase in Shared.skpairs(purchaseArray) do
      if checkFunc(purchase) then
        table.insert(purchaseList, p.processPurchase(category, i - 1))
      end
    end
   end
   end
 
   return purchaseList
   return purchaseArray
end
end


function p._getPurchaseTable(purchase)
function p._getPurchaseTable(purchase)
   local result = '{| class="wikitable"\r\n|-'
   local result = '{| class="wikitable"\r\n|-'
   result = result..'\r\n!colspan="2"|[[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..' - '..Icons.Icon({purchase.name, type='item'})
     result = result..' - '..Icons.Icon({purchase.name, type='item'})
Line 223: Line 225:
   end
   end


   return table.concat(tableArray, '\r\n<br/>\r\n')
   return table.concat(tableArray, '\r\n\r\n')
end
end