Module:Skills/Summoning: Difference between revisions

From Melvor Idle
(I believe that's the first pass at getTabletTable completed)
No edit summary
Line 49: Line 49:
   result = result..'\r\n|- class="headerRow-0"'
   result = result..'\r\n|- class="headerRow-0"'
   result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
   result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
   result = result..'!!Tier!!Effect!!Description!!Shard Cost!!Secondary Ingredients'
   result = result..'!!Tier!!Effect!!Description!!Shard Cost!!Secondary'


   local Familiars = p.getFamiliars()
   local Familiars = p.getFamiliars()

Revision as of 13:57, 11 June 2021

Documentation for this module may be created at Module:Skills/Summoning/doc

local p = {}

local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')

local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Items = require('Module:Items')
local Icons = require('Module:Icons')

function p.getFamiliars()
  return Items.getItems(function(item) return item.type == "Familiar" end)
end

function p.getMarkTable(frame)
  local result = ''
  result = result..'{| class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan="2"|Mark!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
  result = result..'!!Discovered in'

  local Familiars = p.getFamiliars()
  table.sort(Familiars, function(a, b) return a.summoningLevel < b.summoningLevel end)

  local rowArray = {}

  for i, Fam in Shared.skpairs(Familiars) do
    local rowText = '|-'
    rowText = rowText..'\r\n|data-sort-value="'..Fam.name..'"|'..Icons.Icon({Fam.name, type='mark', notext=true, size='50'})
    rowText = rowText..'||[['..Fam.name..'|Mark of the '..Fam.name..']]'
    rowText = rowText..'||style="text-align:right"|'..Fam.summoningLevel
    local discoveredArray = {}
    for j, SkillID in Shared.skpairs(Fam.summoningSkills) do
      table.insert(discoveredArray, Icons.Icon({Constants.getSkillName(SkillID), type='skill'}))
    end
    rowText = rowText..'||'..table.concat(discoveredArray, '<br/>')
    table.insert(rowArray, rowText)
  end

  result = result..'\r\n'..table.concat(rowArray, '\r\n')

  result = result..'\r\n|}'
  return result
end

function p.getTabletTable(frame)
  local result = ''
  result = result..'{| class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
  result = result..'!!Tier!!Effect!!Description!!Shard Cost!!Secondary'

  local Familiars = p.getFamiliars()
  table.sort(Familiars, function(a, b) return a.summoningLevel < b.summoningLevel end)

  local rowArray = {}

  for i, Fam in Shared.skpairs(Familiars) do
    local rowText = '|-'
    rowText = rowText..'\r\n|data-sort-value="'..Fam.name..'"|'..Icons.Icon({Fam.name, type='item', notext=true, size='50'})
    rowText = rowText..'||[['..Fam.name..']]'
    rowText = rowText..'||style="text-align:right"|'..Fam.summoningLevel
    rowText = rowText..'||style="text-align:right"|'..Fam.summoningTier
    rowText = rowText..'||'..Fam.description..'||'..Fam.summoningDescription

    --Currently assuming the shard cost is the same for all recipe variants
    local ShardCostArray = {}
    for j, cost in Shared.skpairs(Fam.summoningReq[1]) do
      if cost.id >= 0 then
        local item = Items.getItemByID(cost.id)
        if item.type == 'Shard' then
          table.insert(ShardCostArray, Icons.Icon({item.name,  type='item', notext=true, qty=cost.qty}))
        end
      end
    end
    rowText = rowText..'||'..table.concat(ShardCostArray, ', ')

    --Now to get all the other cost options
    local OtherCostArray = {}
    local recipeGPCost = SkillData.Summoning.Settings.recipeGPCost
    for j, altCost in Shared.skpairs(Fam.summoningReq) do
      local nonShardArray = {}
      for k, cost in Shared.skpairs(altCost) do
        if cost.id >= 0 then
          local item = Items.getItemByID(cost.id)
          if item.type ~= 'Shard' then
            local sellPrice = item.sellsFor
            if sellPrice < 20 then sellPrice = 20 end
            table.insert(nonShardArray, Icons.Icon({item.name, type='item', notext=true, qty=math.max(1, math.floor(recipeGPCost / sellPrice))}))
          end
        else
          if cost.id == -4 then
            table.insert(nonShardArray, Icons.GP(recipeGPCost))
          elseif cost.id == -5 then
            table.insert(nonShardArray, Icons.SC(recipeGPCost))
          end
        end
      end
      table.insert(OtherCostArray, table.concat(nonShardArray, ', '))
    end
    rowText = rowText..'||'..table.concat(OtherCostArray, "<br/>'''OR''' ")

    table.insert(rowArray, rowText)
  end

  result = result..'\r\n'..table.concat(rowArray, '\r\n')

  result = result..'\r\n|}'
  return result
end

return p