Module:Skills/Gathering/Sandbox: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 795: Line 795:


function p.getThievingAreaTable(frame)
function p.getThievingAreaTable(frame)
local args = frame.args ~= nil and frame.args or frame
    local args = frame.args or frame:getParent().args
local realmName = args.realm
    local realmName = args.realm
local realm = Skills.getRealmFromName(realmName)
    local realm = Skills.getRealmFromName(realmName)
if realm == nil then
   
return Shared.printError('Failed to find a realm with name ' .. (realmName or 'nil'))
    if realm == nil then
end
        return Shared.printError('Failed to find a realm with name ' .. (realmName or 'nil'))
local skillID = 'Thieving'
    end
 
   
local resultPart = {}
    local skillID = 'Thieving'
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
    local root = mw.html.create('table')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
        :addClass('wikitable sortable stickyHeader')
table.insert(resultPart, '\r\n!Area!!'..Icons.Icon({'Thieving', type='skill', notext=true})..' Level!!NPCs!!Unique Drops')
   
 
    -- Header row
local areas = GameData.getEntities(SkillData.Thieving.areas,
    local headerRow = root:tag('tr')
function(obj)
        :addClass('headerRow-0')
return Skills.getRecipeRealm(obj) == realm.id
    headerRow:tag('th'):wikitext('Area')
end
    headerRow:tag('th'):wikitext(Icons.Icon({'Thieving', type='skill', notext=true}) .. '<br>Level')
)
    headerRow:tag('th'):wikitext('NPCs')
    headerRow:tag('th'):wikitext('Unique Drops')
   
    local areas = GameData.getEntities(SkillData.Thieving.areas,
        function(obj)
            return Skills.getRecipeRealm(obj) == realm.id
        end
    )
   
    for i, area in ipairs(areas) do
        local minLevel, npcList, areaItemList = nil, {}, {}
       
        -- Build NPC list & determine minimum Thieving level
        if area.npcIDs and not Shared.tableIsEmpty(area.npcIDs) then
            for j, npcID in ipairs(area.npcIDs) do
                local npc = Skills.getThievingNPCByID(npcID)
                local level = Skills.getRecipeLevel(skillID, npc)
                if not minLevel or level < minLevel then
                    minLevel = level
                end
                table.insert(npcList, Icons.Icon({npc.name, type='thieving'}))
            end
        else
            table.insert(npcList, '')
        end
       
        -- Build area unique item list
        if area.uniqueDrops and Shared.tableCount(area.uniqueDrops) > 0 then
            for k, drop in ipairs(area.uniqueDrops) do
                local areaItem = Items.getItemByID(drop.id)
                if areaItem then
                    local iconDef = {areaItem.name, type='item'}
                    if drop.quantity > 1 then
                        iconDef.qty = drop.quantity
                    end
                    table.insert(areaItemList, Icons.Icon(iconDef))
                else
                    table.insert(areaItemList, 'Unknown[[Category:Pages with script errors]]')
                end
            end
        else
            table.insert(areaItemList, '')
        end
       
        -- Generate table row
        local row = root:tag('tr')
        row:tag('td'):wikitext(area.name)
        row:tag('td'):wikitext(minLevel)
        :css('text-align', 'center')
        row:tag('td'):wikitext(table.concat(npcList, '<br/>'))
        row:tag('td'):wikitext(table.concat(areaItemList, '<br/>'))
    end
   
    return tostring(root)
end


for i, area in ipairs(areas) do
local minLevel, npcList, areaItemList = nil, {}, {}
-- Build NPC list & determine level for area, this is the minimum
-- Thieving level required for all NPCs within that area
if area.npcIDs ~= nil and not Shared.tableIsEmpty(area.npcIDs) then
for j, npcID in ipairs(area.npcIDs) do
local npc = Skills.getThievingNPCByID(npcID)
local level = Skills.getRecipeLevel(skillID, npc)
if minLevel == nil or level < minLevel then
minLevel = level
end
table.insert(npcList, Icons.Icon({npc.name, type='thieving'}))
end
else
table.insert(npcList, '')
end
-- Build area unique item list
if area.uniqueDrops ~= nil and Shared.tableCount(area.uniqueDrops) > 0 then
for k, drop in ipairs(area.uniqueDrops) do
local areaItem = Items.getItemByID(drop.id)
if areaItem == nil then
table.insert(areaItemList, 'Unknown[[Category:Pages with script errors]]')
else
local iconDef = {areaItem.name, type='item'}
if drop.quantity > 1 then
iconDef.qty = drop.quantity
end
table.insert(areaItemList, Icons.Icon(iconDef))
end
end
else
table.insert(areaItemList, '')
end
-- Generate table row
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|' .. area.name)
table.insert(resultPart, '\r\n|' .. Icons._SkillReq('Thieving', minLevel))
table.insert(resultPart, '\r\n|' .. table.concat(npcList, '<br/>'))
table.insert(resultPart, '\r\n|' .. table.concat(areaItemList, '<br/>'))
end
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end


function p._getFarmingTable(realmID, category)
function p._getFarmingTable(realmID, category)
2,875

edits