Module:Skills/Gathering/Sandbox: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1,060: Line 1,060:


function p.getFarmingPlotTable(frame)
function p.getFarmingPlotTable(frame)
local skillID = 'Farming'
    local skillID = 'Farming'
local areaName = frame.args ~= nil and frame.args[1] or frame
    local areaName = frame.args ~= nil and frame.args[1] or frame
local category = GameData.getEntityByName(SkillData.Farming.categories, areaName)
    local category = GameData.getEntityByName(SkillData.Farming.categories, areaName)
if category == nil then
   
return Shared.printError('Invalid farming category. Please choose Allotments, Herbs, or Trees')
    if category == nil then
end
        return Shared.printError('Invalid farming category. Please choose Allotments, Herbs, Trees or Special')
local patches = GameData.getEntities(SkillData.Farming.plots,
    end
function(plot)
   
return plot.categoryID == category.id
    local patches = GameData.getEntities(SkillData.Farming.plots,
end)
        function(plot)
table.sort(patches,
            return plot.categoryID == category.id
function(a, b)
        end
local abyssA, abyssB = a.abyssalLevel or 0, b.abyssalLevel or 0
    )
if abyssA == abyssB then
   
if a.level == b.level then
    table.sort(patches,
return a.id < b.id
        function(a, b)
else
            local abyssA, abyssB = a.abyssalLevel or 0, b.abyssalLevel or 0
return a.level < b.level
            if abyssA == abyssB then
end
                if a.level == b.level then
else
                    return a.id < b.id
return abyssA < abyssB
                else
end
                    return a.level < b.level
end)
                end
if Shared.tableIsEmpty(patches) then
            else
return ''
                return abyssA < abyssB
end
            end
        end
    )
   
    if Shared.tableIsEmpty(patches) then
        return ''
    end
   
    local root = mw.html.create('table')
        :addClass('wikitable sortable stickyHeader')
   
    -- Header row
    local headerRow = root:tag('tr')
    headerRow:tag('th'):wikitext('Plot')
    headerRow:tag('th'):wikitext('Requirements')
    headerRow:tag('th'):wikitext('Cost')
   
    for i, patch in ipairs(patches) do
        local level = Skills.getRecipeLevel(skillID, patch)
        local reqText = Skills.getRecipeRequirementText(skillID, patch)
        local costText = Common.getCostString({ items = patch.itemCosts, currencies = patch.currencyCosts }, 'Free')
        local costVal = (patch.currencyCosts and patch.currencyCosts[1] and patch.currencyCosts[1].quantity) or 0
       
        local row = root:tag('tr')
        row:tag('td'):wikitext(i)
        row:tag('td'):css('text-align', 'right')
            :attr('data-sort-value', level)
            :wikitext(reqText)
        row:tag('td'):css('text-align', 'right')
            :attr('data-sort-value', costVal)
            :wikitext(costText)
    end
   
    return tostring(root)
end


local result = '{|class="wikitable sortable stickyHeader"'
result = result..'\r\n!Plot!!Requirements!!Cost'
for i, patch in ipairs(patches) do
local level = Skills.getRecipeLevel(skillID, patch)
local reqText = Skills.getRecipeRequirementText(skillID, patch)
local costText = Common.getCostString({ items = patch.itemCosts, currencies = patch.currencyCosts }, 'Free')
local costVal = (patch.currencyCosts ~= nil and patch.currencyCosts[1].quantity) or 0
result = result..'\r\n|-\r\n|'..i
result = result..'||style="text-align:right;" data-sort-value="' .. level .. '"|'..reqText
result = result..'||style="text-align:right;" data-sort-value="'..costVal..'"|'..costText
end
result = result..'\r\n|}'
return result
end


function p._buildAstrologyConstellationTable(realmID)
function p._buildAstrologyConstellationTable(realmID)
2,875

edits