Path of Exile Wiki

Please consider helping keep the wiki up to date. Check the to-do list of updates needed for version 3.14.0.

Game data exports will becoming later as the technical changes in addition to regular changes take some more time.

READ MORE

Path of Exile Wiki
Advertisement
--
-- Module for bestiary templates
--

local m_cargo = require('Module:Cargo')
local m_util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs

local m_passive_skill = require('Module:Passive skill')

local f_item_link = require('Module:Item link').item_link

local p = {}

-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------

local i18n = {
    headers = {
        id = 'Recipe ID',
        type = 'Recipe Type',
        oil1 = 'Oil #1',
        oil2 = 'Oil #2',
        oil3 = 'Oil #3',
        outcome = 'Outcome',
    },
    cells = {
        -- directly map data type to string
        InfectedMap = 'Infected map',
        UniqueOrAmulet = 'Amulet<br>Blight unique',
        Ring = 'Ring',
    },
}

-- ----------------------------------------------------------------------------
-- Helper functions and globals
-- ----------------------------------------------------------------------------

-- ----------------------------------------------------------------------------
-- Cargo tables
-- ----------------------------------------------------------------------------
local tables = {}

tables.blight_towers = {
    table = 'blight_towers',
    order = {'id'},
    fields = {
        id = {
            field = 'id',
            type = 'String',
        },
        name = {
            field = 'name',
            type = 'String',
        },
        description = {
            field = 'description',
            type = 'String',
        },
        tier = {
            field = 'tier',
            type = 'String',
        },
        icon = {
            field = 'icon',
            type = 'File',
        },
        cost = {
            field = 'cost',
            type = 'Integer'
        },
        radius = {
            field = 'radius',
            type = 'Integer',
        },
    },
}

-- next two tables are a composite of the following files
--  BlightCraftingItems.dat
--  BlightCraftingRecipes.dat
--  BlightCraftingResults.dat
--  BlightCraftingTypes.dat
tables.blight_crafting_recipes = {
    table = 'blight_crafting_recipes',
    order = {'id', 'modifier_id', 'passive_id', 'type'},
    fields = {
        id = {
            field = 'id',
            type = 'String',
        },
        modifier_id = {
            field = 'modifier_id',
            type = 'String',
        },
        passive_id = {
            field = 'passive_id',
            type = 'String',
        },
        type = {
            field = 'type',
            type = 'String',
        },
    },
}

tables.blight_crafting_recipes_items = {
    table = 'blight_crafting_recipes_items',
    order = {'ordinal', 'recipe_id', 'item_id'},
    fields = {
        ordinal = {
            field = 'ordinal',
            type = 'Integer',
        },
        recipe_id = {
            field = 'recipe_id',
            type = 'String',
        },
        item_id = {
            field = 'item_id',
            type = 'String',
        },
    },
}
-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------

local p = {}

p.table_blight_towers = m_cargo.declare_factory{data=tables.blight_towers}
p.table_blight_crafting_recipes = m_cargo.declare_factory{data=tables.blight_crafting_recipes}
p.table_blight_crafting_recipes_items = m_cargo.declare_factory{data=tables.blight_crafting_recipes_items}

p.store_data = m_cargo.store_from_lua{tables=tables, module='Blight'}

function p.crafting_table(frame)
    -- Get args
    tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
    
    for _, bool in ipairs({'id', 'type', 'no_html'}) do
        tpl_args[bool] = m_util.cast.boolean(tpl_args[bool])
    end
    
    local results = m_cargo.map_results_to_id{
        results=m_cargo.query(
            {
                'blight_crafting_recipes', 
                'blight_crafting_recipes_items', 
                'mods', 
                'passive_skills'
            },
            {
                'blight_crafting_recipes.id',
                'blight_crafting_recipes.type',
                'blight_crafting_recipes_items.item_id',
                'mods._pageName',
                'mods.id',
                'mods.name',
                'mods.stat_text',
                'passive_skills._pageName', 
                'passive_skills.id',
                'passive_skills.stat_text',
                'passive_skills.main_page',
                'passive_skills.name',
                'passive_skills.icon',
                'passive_skills.is_keystone',
                'passive_skills.is_notable',
                'passive_skills.ascendancy_class',
            },
            {
                join=[[
                    blight_crafting_recipes_items.recipe_id = blight_crafting_recipes.id,
                    blight_crafting_recipes.modifier_id = mods.id,
                    blight_crafting_recipes.passive_id = passive_skills.id
                ]],
                where=string.format([[
                    blight_crafting_recipes_items.item_id IS NOT NULL
                    AND (%s)
                ]], tpl_args.q_where or 1),
                limit=tpl_args.q_limit or 5000,
            }
        ),
        field='blight_crafting_recipes.id',
        keep_id_field=true,
    }
    local item_ids_assoc = {}
    for _, rows in pairs(results) do
        for _, row in ipairs(rows) do
            item_ids_assoc[row['blight_crafting_recipes_items.item_id']] = true
        end
    end
    
    local item_ids = {}
    for metadata_id, _ in pairs(item_ids_assoc) do
        item_ids[#item_ids+1] = metadata_id
    end
        
    local items = m_cargo.map_results_to_id{
            results=m_cargo.query(
            {'items', 'blight_items',},
            {
                'items._pageName',
                'items.name',
                'items.inventory_icon',
                'items.html',
                'items.metadata_id',
                'blight_items.tier',
            },
            {
                join='items._pageID=blight_items._pageID',
                where=string.format('items.metadata_id IN ("%s")', table.concat(item_ids, '", "')), 
            }
        ),
        field='items.metadata_id',
        keep_id_field=true,
    }
    
    local tbl = mw.html.create('table')
    
    tbl
        :attr('class', 'wikitable sortable')
    
    local tr = tbl:tag('tr')
    for _, bool in ipairs({'id', 'type'}) do
        if tpl_args[bool] then
            tr
                :tag('th')
                    :wikitext(i18n.headers[bool])
                    :done()
        end
     end
     tr
        :tag('th')
            :wikitext(i18n.headers.oil1)
            :done()
        :tag('th')
            :wikitext(i18n.headers.oil2)
            :done()
        :tag('th')
            :wikitext(i18n.headers.oil3)
            :done()
        :tag('th')
            :wikitext(i18n.headers.outcome)
            :attr('colspan', 2)
            :done()
        :done()
    
    for recipe_id, rows in pairs(results) do
        local row1 = rows[1] 
        local tr = tbl:tag('tr')
        
        if tpl_args.id then
            tr
                :tag('td')
                    :wikitext(recipe_id)
                    :done()
        end
        
        if tpl_args.type then
            tr
                :tag('td')
                    :wikitext(i18n.cells[row1['blight_crafting_recipes.type']])
                    :done()
        end
                
        for i=1,3 do
            local row = rows[i]
            if row then
                local item = items[row['blight_crafting_recipes_items.item_id']][1]
                local html
                if tpl_args.no_html == false then
                    html = item['items.html']
                end
                tr
                    :tag('td')
                        :attr('data-sort-value', item['blight_items.tier'])
                        :wikitext(f_item_link{page=item['items._pageName'], name=item['items.name'], inventory_icon=item['items.inventory_icon'], html=html or '', skip_query=true})
                        :done()
            else
                tr
                    :tag('td')
                        :attr('data-sort-value', -1)
                        :wikitext('&nbsp;')
                        :done()
            end
        end
        
        if row1['mods.id'] then
            tr
                :tag('td')
                    --:wikitext(string.format('[[%s|%s]]<br>%s', row1['mods._pageName'], row1['mods.id'] or row1['mods.name'], row1['mods.stat_text']))
                    :wikitext(row1['mods.stat_text'])
                    :attr('colspan', 2)
                    :done()
        elseif row1['passive_skills.id'] then
            tr
                :tag('td')
                    :attr('style', 'text-align: center;')
                    :attr('data-sort-value', '_' .. row1['passive_skills.name'])
                    :wikitext(string.format('[[%s|%s]]<br>%s', row1['passive_skills.main_page'] or row1['passive_skills.name'], row1['passive_skills.name'], m_passive_skill.h.format_passive_icon(row1, m_passive_skill.h.get_type(row1))))
                    :done()
                :tag('td')
                    :wikitext(row1['passive_skills.stat_text'])
                    :done()
                :done()
        end
    end
    
    
    --
    return tostring(tbl)
end

-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------

return p