Module:ItemData

From League of Legends Wiki, LoL Wiki
Jump to navigation Jump to search
Module:ItemData has the following documentation.

This module (primarily):

  • Accesses data for League of Legends items, such as: name, stats, recipe, buy and sell cost, active and passive item ability descriptions, item group and other limitations.
  • Formats various lists of items, such as ones that grant a certain statistic
  • Contains various utilities for formatting entries associated with data templates, full recipe trees, and others.
  • Generates the entries for the List of items

Related:

The data is stored at Module:ItemData/data. If you wish to edit that data, please follow the format documented at the top of that page.

This data format has been planned to be deprecated in favor of a less complex format. [date and author unknown]


-- Authors: Mortorium, TheTimebreaker
-- Translation and Adjustments: TheTimebreaker
-- <pre>
local p = {}
 
local items			= mw.loadData('Module:ItemData/data')
local removeditems	= mw.loadData('Module:ItemData/data/removed')
local getter		= require("Module:ItemData/getter")
local gmgetter 		= require('Module:GamemodeData/getter')
local IL			= require('Module:ImageLink')
local lib			= require('Module:Feature')
local FN		    = require('Module:Filename')
local builder       = require("Module:SimpleHTMLBuilder")
local userError		= require('Module:User error')

function p.exists(frame)
	local args = lib.frameArguments(frame)
	args['item']     = args['item']     or args[1]
	local currentData = mw.loadData('Module:ItemData/data')
	local removedData = mw.loadData('Module:ItemData/data/removed')
	
	if currentData[args['item']] or removedData[args['item']] then
		return true
	else
		return false
	end
end
 
function p.get(frame)
    local args = lib.frameArguments(frame)
    
    args['item']     = args['item']     or args[1]
    args['datatype'] = args['datatype'] or args[2]
    args['output']   = args['output']   or args[3] or nil

	local result
	if args['datatype'] == 'OneMode' then -- special case just for this one function to allow second argument
		result = getter[args['datatype']](args['item'], args['mode'])
	else
    	result = getter[args['datatype']](args['item'])
	end

    if args['output'] ~= nil and type(result) == "table" then
        if(args["index"]) then
            local i = tonumber(args["index"])
            if(result[i]) then 
                return frame:preprocess(result[i])
            else
                return ""
            end
        end
        if args['output'] == "csv" then
            return lib.tbl_concat{result}
        elseif args['output'] == "custom" then 
            return frame:preprocess(lib.tbl_concat{result, prepend = args['prepend'], append = args['append'], separator = args['separator'], index = args["index"]})
        elseif args['output'] == "template" then 
            return frame:preprocess(lib.tbl_concat{result, prepend = "{{" .. (args['t_name'] or "ii") .. "|", append = "}}", separator = args['separator']})
        end
    elseif type(result) == "string" then
        return frame:preprocess(result)
    else
        return result
    end
end

function p.getRoster(frame)
    local args = lib.frameArguments(frame)
    
    local showremoved = args['removed'] == "true" or true
    
    local starters = {}
    local consumables = {}
    local trinkets = {}
    local distributives = {}
    local boots = {}
    local basics = {}
    local epics = {}
    local legendaries = {}
    local mythics = {}
    local ornnitems = {}
    local championitems = {}
    local minionturretitems = {}
	local specialgamemodeitems = {}
	local arenaitems = {}
	local arenaprismaticitems = {}
	local arenaanvilitems = {}
    local unsorted = {}

    for k, v in lib.pairsByAlphabeticalKeys(items) do
    	local itemType = table.concat(getter.type(k))
    	if getter.champion(k) then
       		championitems[#championitems+1] = k
   		elseif getter.ornn(k) == true then
    		ornnitems[#ornnitems+1] = k
    	elseif string.find(itemType, "Prismatic") then
    		arenaprismaticitems[#arenaprismaticitems+1] = k
    	elseif string.find(itemType, "Anvil") then
    		arenaanvilitems[#arenaanvilitems+1] = k
    	elseif getter.OnlyMode(k, "arena") then
			arenaitems[#arenaitems+1] = k
    	elseif string.find(itemType, "Distributed") then
    		distributives[#distributives+1] = k
        elseif string.find(itemType, "Starter") then
        	starters[#starters+1] = k
        elseif string.find(itemType, "Potion") or string.find(itemType, "Consumable") then
        	consumables[#consumables+1] = k
        elseif string.find(itemType, "Trinket") then
        	trinkets[#trinkets+1] = k
        elseif string.find(itemType, "Boots") then
        	boots[#boots+1] = k
        elseif string.find(itemType, "Basic") then
        	basics[#basics+1] = k
        elseif string.find(itemType, "Epic") then
        	epics[#epics+1] = k
        elseif string.find(itemType, "Legendary") then
        	legendaries[#legendaries+1] = k
		elseif string.find(itemType, "Special") then
        	specialgamemodeitems[#specialgamemodeitems+1] = k
        elseif string.find(itemType, "Mythic") then
        	mythics[#mythics+1] = k
        elseif itemType == "Minion" or itemType == "Turret" then
        	minionturretitems[#minionturretitems+1] = k
        else
        	unsorted[#unsorted+1] = k
        end
    end
    
    -- create block
    local gridContainer = builder.create('div'):attr('id', 'grid'):newline()

    local tableContainer = builder.create('div')
        :attr('id', 'item-grid')
        :cssText('clear:both; align:center;')
        :tag('dl')
            :tag('dt')
                :wikitext('Starter items')
                :done()
            :done()
        :node(_buildItemListContainer(starters))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Potions and Consumables')
                :done()
            :done()
        :node(_buildItemListContainer(consumables))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Trinkets')
                :done()
            :done()
        :node(_buildItemListContainer(trinkets))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Distributed items')
                :done()
            :done()
        :node(_buildItemListContainer(distributives))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Boots')
                :done()
            :done()
        :node(_buildItemListContainer(boots))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Basic items')
                :done()
            :done()
        :node(_buildItemListContainer(basics))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Epic items')
                :done()
            :done()
        :node(_buildItemListContainer(epics))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Legendary items')
                :done()
            :done()
        :node(_buildItemListContainer(legendaries))
        :newline()
    if #mythics > 0 then
	    tableContainer
	        :tag('dl')
	            :tag('dt')
	                :wikitext('Mythic items')
	                :done()
	            :done()
	        :node(_buildItemListContainer(mythics))
	        :newline()
    end
    tableContainer
        :tag('dl')
            :tag('dt')
                :wikitext('Champion exclusive items')
                :done()
            :done()
        :node(_buildItemListContainer(championitems))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Minion and Turret items')
                :done()
            :done()
        :node(_buildItemListContainer(minionturretitems))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Arena Prismatic items')
                :done()
            :done()
        :node(_buildItemListContainer(arenaprismaticitems))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Arena Anvil items')
                :done()
            :done()
        :node(_buildItemListContainer(arenaanvilitems))
        :newline()
        :tag('dl')
            :tag('dt')
                :wikitext('Arena exclusive items')
                :done()
            :done()
        :node(_buildItemListContainer(arenaitems))
        :newline()
	if #specialgamemodeitems > 0 then
		tableContainer
			:tag('dl')
				:tag('dt')
					:wikitext('Special Game Mode Items')
					:done()
				:done()
			:node(_buildItemListContainer(specialgamemodeitems))
			:newline()
	end
    if showremoved then
        tableContainer
            :tag('dl')
                :tag('dt')
                    :wikitext('Removed items')
                    :done()
                :done()
            :node(_buildItemListContainer(lib.getSortedKeys(removeditems)))
    end
    
    tableContainer:allDone()
    gridContainer:node(tableContainer)
    
    return gridContainer
end

function p.getItemPage(frame)
	local args = lib.frameArguments(frame)

	local cat =  frame.args.nocategories ~= 'true' and _getCategories(frame) or nil
	local box = _getInfobox(frame)
	local intro = _getIntroduction(frame)
	local recipe
	if args['recipe'] then
		recipe = "<h2>Recipe</h2>\n"..args['recipe']
	else
		recipe = _getRecipeTree(frame)
	end
	local builds = p.getPageBuilds(frame)
	return (cat or '') .. (box or '') .. (intro or '') .. (recipe or '') .. (builds or '')
end


function p.tooltip(frame) --Work in Progress: aim is to speed up tooltips
	local args = lib.frameArguments(frame)
	local item			= args['item'] or			args[1]
	local variant		= args['variant'] or		args[2]	or ''
	local enchantment	= args['enchantment'] or	args[3]	or ''
	
	local root = builder.create('div')
		:addClass('blue-tooltip')	
		:css("width", "25em")
		--:css("border-bottom:1px solid #1B2F65")
		--:css("margin", "5px")
		--:css("padding", "0 5px")

	local titlebar = root:tag('div')
			:css("display", "grid")
			:css("padding", "0 5px")
			:css("color", "#9797FC")
			:css("font-size", "20px")
			:tag('span')
				:css('justify-self', 'left')
				:css("grid-column", 1)
				:wikitext("[[File:"..FN.item({['item'] = item, ['variant'] = variant, ['enchantment'] = enchantment}).."|32px|link="..item.."]]" .. " '''" .. item .. "'''")
				:done()
			:tag('span')
				:css('justify-self', 'right')
				:css("grid-column", 2)
				:wikitext("{{g|" .. getter.buy(item) .. "}}")
				:done()
			:done()
			
			--todo next: stats
				
	root:allDone()
	return root
end

--Item "builds into section" for the tooltip
function p.getTooltipBuilds(frame)
    local args = lib.frameArguments(frame)
    local item	= args['item'] or args[1]
    local IL	= require('Module:ImageLink')
    
    local builds = getter.builds(item)
    if not builds then
    	return
    end
    local s = ""
    for i, v in ipairs(builds) do
        if i == 10 then s = s .. "<br/>" end
        s = s .. tostring(IL.item{
            ['item'] = v,
            ['text'] = "*none*"
        })
    end
    return s
end

--Item recipe section for the tooltip
function p.getTooltipRecipe(frame)
    local args = lib.frameArguments(frame)
    local item	= args['item'] or args[1]
    local IL	= require('Module:ImageLink')
    local recipe = getter.recipe(item)
    if not recipe then
        return
    end
    
    local s = ""
	for i, v in pairs(recipe) do
        s = s .. tostring(IL.item({
            ["item"] = v,
            ["size"] = '20',
            ["text"] = "*none*"
        }))
        if(i < #item - 1) then
            s = s .. "&nbsp;+&nbsp;"
        end
    end
    s = s .. _gold(getter.comb(item) or 0)
    
    return s
end

function p.tags(frame)
	local args = lib.frameArguments(frame)

    args['tags']    = args['tags'] or args[1]
	
	local out = {}
	
	for k, v in lib.pairsByAlphabeticalKeys(items) do
		local tags = getter.tags(k)
		if tags then
			for key,value in pairs(tags) do
				if value == args['tags'] then
					out[#out+1] = k
				end
			end
		end
	end

	return frame:preprocess("{{column|2|{{clr}}"..lib.tbl_concat{out, prepend = "* {{ii|", append = "}}", separator = "{{clr}}"}.."}}")
end

--[[================
    Intern functions
    ================]]

-- outputs the recipe tree for the item page
function _getRecipeTree(frame)
    local args = lib.frameArguments(frame)
    local item = args['item'] or args[1]
	if getter.recipe(item) then
		return "<h2>Recipe</h2>\n"..tostring(_buildRecipeTree(args))
	end
end

-- does also include the {{removed}} template
function _getCategories(frame)
    local args = lib.frameArguments(frame)
    
    local item = args['item'] or args[1]
	local getremoved = getter.removed(item)
	if getremoved then
    	if type(getremoved) == "string" and getremoved ~= "true" then
			if getremoved == "alpha" or getremoved == "beta" then
				return frame:expandTemplate{title = "Removed", args = {type = "items"}}.."[[Category:Alpha items]]"
			else
				return frame:expandTemplate{title = "Removed", args = {type = "items", text = "This item was removed on patch [["..getremoved.."]]."}}
			end
		else
			return frame:expandTemplate{title = "Removed", args = {type = "items"}}.."[[Category:Removed items without patch]]"
		end
	end

    local categories = {}

    if getter.exclusive(item) then -- if item is exclusive to game mode, then add game mode item category.
       	for k,v in pairs(getter.exclusive(item)) do
       		categories[#categories+1] = v.." items"
       	end
    end
    
    if getter.champion(item) then -- if item is bound to a specific champion => add champion item category and the champions
        categories[#categories+1] = "Champion specific items"
       	for k,v in pairs(getter.champion(item)) do
       		categories[#categories+1] = v
       	end
    end
    
    local itemtype = getter.type(item)-- adds item type categories
    if itemtype then
        for i,v in pairs(itemtype) do
            if v == "Advanced Consumable" then
                categories[#categories+1] = "Consumable items"
            elseif v == "Basic Trinket" then
                categories[#categories+1] = "Trinket items"
            elseif v == "Advanced Trinket" then
                categories[#categories+1] = "Trinket items"
            else
                categories[#categories+1] = v.." items"
            end
        end
    end
    
    -- keep this table up to date with Module:ItemData/getter
    local categoryTable = {
        {"ad",					"Attack damage"},
        {"ah",					"Ability haste"},
        {"ap",					"Ability power"},
        {"apunique",			"Ability power"},
        {"armor",				"Armor"},
        {"armorunique",			"Armor"},
        {"armpen",				"Armor penetration"},
        {"as",					"Attack speed"},
        {"cdr",					"Cooldown reduction"},
        {"cdrunique",			"Cooldown reduction"},
        {"crit",				"Critical strike"},
        {"critdamage",			"Critical strike damage"},
        {"gp10",				"Gold income"},
        {"hp",					"Health"},
        {"hp5",					"Health regeneration"},
        {"hp5flat",				"Health regeneration"},
        {"hsp",					"Heal and shield power"},
        {"hspunique",			"Heal and shield power"},
        {"lethality",			"Lethality"},
        {"lethalityunique",		"Lethality"},
        {"lifesteal",			"Life steal"},
        {"mana",				"Mana"},
        {"mp5",					"Mana regeneration"},
        {"mp5flat",				"Mana regeneration"},
        {"mpen",				"Magic penetration"},
        {"mpenflat",			"Magic penetration"},
        {"mr",					"Magic resistance"},
        {"ms",					"Movement"},
        {"msflat",				"Movement"},
        {"msunique",			"Movement"},
        {"omnivamp",			"Omnivamp"},
        {"pvamp",				"Physical vamp"},
        {"spellvamp",			"Spell vamp"},
        {"tenacity",			"Tenacity"},
    }
    local itemStats = getter.stats(item)
    if itemStats then
	    for _, v in pairs(categoryTable) do --adds the categories for all stats according to the table above
	        if itemStats[v[1]] then
	            categories[#categories+1] = v[2].." items"
	        end
	    end
	end
	
	-- this code adds categories based on the filtering grid from riot games, to account for stuff thats not simply in the stats
	-- this does NOT include everything!
    local menuTable = {
        {"attack damage",		"Attack damage"},
        {"critical strike",		"Critical strike"},
        {"attack speed",		"Attack speed"},
		{"onhit effects",		"On-hit effect"},
        {"armor pen",			"Armor penetration"},
		{"ability power",		"Ability power"},
		{"magic pen",			"Magic penetration"},
        {"armor",				"Armor"},
        {"magic res",			"Magic resistance"},
        {"ability haste",		"Ability haste"},
        {"movement",			"Movement"},
    	{"fighter",				"Fighter"},
        {"marksman",			"Marksman"},
        {"assassin",			"Assassin"},
		{"mage",				"Mage"},
        {"tank",				"Tank"},
        {"support",				"Support"},
    }
    local menuTableData = getter.rawmenu(item)
    if menuTableData then
	    for _, v in pairs(menuTable) do --adds the categories for all stats according to the table above
	        if menuTableData[v[1]] == true then
	            categories[#categories+1] = v[2].." items"
	        end
	    end
	end
	    
    if getter.act(item) then
        categories[#categories+1] = "Items with active abilities"
    end
    
    if getter.ornn(item) then
        categories[#categories+1] = "Ornn items"
    end
	
	for i,v in ipairs(categories) do
		categories[i] = '[[Category:'..v..']]'
	end
    
    return table.concat(categories)
end

function  p.test(frame)
	local args = lib.frameArguments(frame)
	local item = args['item'] or args[1]
	local itemtype = getter.type(item)
	if itemtype[1] ~= "Potion" then
		return itemtype[1]
	else
		return itemtype[2]
	end
end

-- this is the introductory sentence at the beginning of each page
function _getIntroduction(frame)
    local args = lib.frameArguments(frame)
    local IL = require('Module:ImageLink')
    local item = args['item'] or args[1]
    local append = args['append'] or args[2]
    
    local tobe = "is"
    if getter.removed(item) then tobe = "was" end
    local cancould = "Can"
    if getter.removed(item) then cancould = "Could" end
	
	local typelink = "bug catcher"
	local itemtype = getter.type(item)
    if itemtype then
    	if itemtype[1] == "Potion" then itemtype[1] = nil end
        if itemtype[1] == "Advanced Consumable" then
            typelink = "[[:Category:Consumable items|advanced consumable item]]"
        elseif itemtype[1] == "Basic Trinket" then
        	typelink = "[[:Category:Trinket items|basic trinket item]]"
        elseif itemtype[1] == "Advanced Trinket" then
            typelink = "[[:Category:Trinket items|advanced trinket item]]"
        elseif itemtype[1] == "Enchantment" then
            typelink = "[[:Category:Enchantments|enchantment]]"
        else
            typelink = "[[:Category:"..itemtype[1].." items|"..itemtype[1]:lower().." item]]"
        end
    end
    
	local a_an = "a"
    local firstletter = itemtype[1]:sub(1,1):lower()
    if firstletter == "a" or firstletter == "e" or firstletter == "i" or firstletter == "o" or firstletter == "u" then
    	a_an = "an"
    end
    
    local alphastage = " in "
    if getter.removed(item) == "alpha" then
    	alphastage = " from the [[Alpha Test|alpha stage]] of "
    elseif getter.removed(item) == "beta" then
    	alphastage = " from the [[Beta Test|beta stage]] of "
    end
    
	local str = "<b>"..item.."</b> "..tobe.." "..a_an.." "..typelink
	..alphastage..'<span class="glossary" style="white-space:pre; position:relative;" data-tip="League of legends">'
	..'[[File:League of Legends icon.png|20px|link=League of Legends]] [[League of Legends]]</span>'
	
	if getter.champion(item) then
		str = str.." for "
		local getchampion = getter.champion(item)
        if getchampion[2] then  --this assumes that the champion argument in the ItemData/data contains a maximum of two values
    		str = str .. tostring(IL.champion({ champion = getchampion[1] })) .. " and " .. tostring(IL.champion({ champion = getchampion[2] }))
        else
			str = str .. tostring(IL.champion({ champion = getchampion[1] }))
        end
    end
    str = str .. "."
    
    local modes = getter.modes(item)
    local modeexclusive
    if #modes == 1 then
    	--local gm = require('Module:GamemodeData')
		modeexclusive = gmgetter.fullname(modes[1])
    end
    
    if modeexclusive then
    	str = str .. " It " .. tobe .. " exclusive to " .. frame:preprocess("{{tip|" .. modeexclusive .. "}}") .. "."
    end
    if getter.ornn(item) then
    	str = str .. " " .. cancould .. " only be forged by " .. tostring(IL.champion({ champion = 'Ornn' })) .. "."
    end
    if getter.req(item) then
    	str = str .. " " .. frame:preprocess(getter.req(item))
    end
    	
    return str
end

function p.getInfoboxRecipe(frame)
	local args = lib.frameArguments(frame)
    local item = args['item'] or args[1]
	return _getInfoboxRecipe(item)
end

function _getInfoboxRecipe(item)
	local recipe = getter.recipe(item)
    if not recipe then
        return
    end
    
    local s = ""
	for i, v in pairs(recipe) do
        s = s .. tostring(IL.item({
            ["item"] = v,
            ["size"] = '32',
            ["text"] = "*none*"
        }))
        if(i < #item - 1) then
            s = s .. "&nbsp;+&nbsp;"
        end
    end
    s = s .. _gold(getter.comb(item) or 0)
    
    return s
end

function p.getInfoboxBuilds(frame)
	local args = lib.frameArguments(frame)
    local item = args['item'] or args[1]
	return _getInfoboxBuilds(item)
end

function _getInfoboxBuilds(item)
	local IL = require('Module:ImageLink')
    local builds = getter.builds(item)
    local res = ''
    if not builds then
        return
	else
	    for i,v in ipairs(builds) do
	    	if not getter.ornn(v) then
	    		res = res .. '<b>' .. tostring(IL.item({
	    			item = v,
	    			size = '32px'
	    		})) .. '</b><br>'
	    	end
	    end
	    
	    return res
	end
end

function _getInfobox(frame)
	local args = lib.frameArguments(frame)
	local item = args['item'] or args[1]

	local menu
	if type(getter.menu(item)) == "table" then
		menu = '<li>' .. table.concat(getter.menu(item) or {}, '</li><li>') .. '</li>'
	else
		menu = getter.menu(item)
	end
	if type(getter.nickname(item)) == "table" then
		local lotable = {}
		for k,v in pairs(getter.nickname(item)) do
			lotable[#lotable+1] = v
		end
		nickname = '<li>' .. table.concat(lotable or {}, '</li><li>') .. '</li>'
	else
		nickname = getter.nickname(item)
	end
	
	return frame:expandTemplate{title = 'Infobox_item/new', args = {item}}
end

-- returns a table of all masterwork / ornn items and tells you the stats you gain from the upgrade and the gold value of these stats
function p.getOrnnGoldvalue(frame)
	local args = lib.frameArguments(frame)
	local onlythisitem = args[1] or nil
	
    local itempairs = {}
    for ornnitem, stats in pairs(items) do
    	if not onlythisitem or ornnitem == onlythisitem then
			if getter.ornn(ornnitem) then
				--mw.log(ornnitem)
				
				mainitem = getter.recipe(ornnitem)[1]
				stat_diff = {}
				for stat,_ in pairs(getter.stats(ornnitem)) do
					local diff = getter[stat](ornnitem) - getter[stat](mainitem)
					if diff > 0 then
						stat_diff[stat] = diff
					end
				end
				itempairs[ornnitem] = {}
				itempairs[ornnitem]["stats"] = stat_diff
			end
		end
    end
    
    local goldData = require("Module:Gold_value")
    for ornnitem,v in lib.pairsByAlphabeticalKeys(itempairs) do
   		stats = v["stats"]
		itempairs[ornnitem]["gv"] = {}   	
		for stat,value in pairs(stats) do
    		itempairs[ornnitem]["gv"][stat] = value*goldData.getStat_noframe(stat)
		end
		
		local total_gv = 0
		for _,value in pairs(itempairs[ornnitem]["gv"]) do
			total_gv = total_gv + value
		end
		itempairs[ornnitem]["total_gv"] = total_gv
    end
    
    -- initialize table object
    local tableNode = builder.create('table')
    tableNode:addClass('article-table'):addClass('stdt')
    if not onlythisitem then
    	tableNode:addClass('sortable'):addClass('mw-collapsible'):addClass('mw-collapsed')
    end
    tableNode:newline()
    
    -- header
    local header = builder.create('tr')
    header
    	:tag('th')
            :wikitext("Item")
            :done()
    	:tag('th')
    		:addClass("unsortable")
        	:wikitext("Bonus stats")
        	:done()
    	:tag('th')
    		:wikitext("Gold value")
        	:done()
        :done()
	tableNode:node(header):newline()
	
	-- Adds one row to the table for each item
	for ornnitem,v in lib.pairsByAlphabeticalKeys(itempairs) do
		local original_item = ""
		for _, item in ipairs(getter["recipe"](ornnitem)) do
			original_item = original_item .. "<br>{{ii|" .. item .. "}}"
		end
		
		local stat_table = {}
		for stat,value in pairs(v["stats"]) do
			stat_table[#stat_table+1] = value..goldData.isPercentage_noframe(stat).." ".. goldData.getStat_noframe(stat, "name") .."  = {{g|" .. (math.floor(v["gv"][stat] * 100 + 0.5) / 100) .. "}}"
		end
		local stat_str = table.concat(stat_table, "<br>")

		local row = builder.create('tr')
		row
		:tag('td')
			:attr('data-sort-value', ornnitem)
			:wikitext(frame:preprocess("{{ii|"..ornnitem.."}}" .. original_item))
			:done()
		:tag('td')
			:wikitext(frame:preprocess(stat_str))
			:done()
		:tag('td')
			:attr('data-sort-value', v["total_gv"])
			:wikitext(frame:preprocess("{{g|"..(math.floor(v["total_gv"] * 100 + 0.5) / 100).."}}"))
			:done()
		:done()
		tableNode:node(row):newline()
	end
	
	return tableNode:allDone()
end
    	
    	
--Item recipe for the item page
function p.getPageBuilds(frame)
    local args = lib.frameArguments(frame)
    local IL = require('Module:ImageLink')
    local item = args['item'] or args[1]
    local builds = getter.builds(item)
    local res = ''
    if not builds then
    	return
    end

    for i, v in ipairs(builds) do
    	if not getter.ornn(v) then
    		res = res .. '<b>' .. tostring(IL.item({
    			item = v,
    			size = '32',
    			labelstyle = 'font-size:14px;'
    		})) .. '</b><br>'
	    end
    end
    if res ~= '' then
    	local header
    	if getter.type(item)[1] == "Enchantment" then
    		header = "Possible Upgrades for"
    	else
    		header = "Builds Into"
    	end
    	return '<h2>'..header..'</h2>\n<div class="columntemplate" style="column-count:2;">'..res..'</div>'
    end
end

-- Draws the item build path tree. Recurring function
function _buildRecipeTree(frame)
    local args = lib.frameArguments(frame)
    local item = args['item'] or args[1]
    local recipe = getter.recipe(item) or nil
    
    local tableNode = builder.create('table')
    tableNode:css('border-collapse', 'collapse'):newline()
    
    local tableRow = builder.create('tr')
    tableRow
        :tag('td')
            :attr('colspan', '3')
            :css('padding-left', '0px')
            :node(_buildRecipeTreeItem(item))
            :done()
        :done()
    
    tableNode:node(tableRow):newline()
    
    if(recipe == nil) then 
        tableNode:allDone()
        return tableNode
    end
    local num_components = 0
    for k in ipairs(recipe) do num_components = num_components + 1 end
    
    local firstComponentRow = builder.create('tr')
    firstComponentRow
        :tag('td')
            :attr('rowspan', tostring(num_components * 2 - 1))
            :cssText('width:15px;border-right:1px solid #124b71;')
            :done()
        :tag('td')
            :cssText('height:17px;width:17px;border-bottom:1px solid #124b71;')
            :done()
        :tag('td')
            :attr('rowspan', '2')
            :node(_buildRecipeTree{recipe[1]})
            :done()
        :done()
    tableNode:node(firstComponentRow)
    
    for i, v in ipairs(recipe) do
        if(i ~= 1) then
            tableNode
                :tag('tr')
                    :tag('td')
                        :done()
                    :done()
                :newline()
            local recipeRow = builder.create('tr')
            recipeRow
                :tag('td')
                    :cssText('height:17px;width:17px;border-bottom:1px solid #124b71;')
                    :done()
                :tag('td')
                    :attr('rowspan', '2')
                    :node(_buildRecipeTree{v})
                    :done()
                :done()
            tableNode:node(recipeRow):newline()
        end
    end
    tableNode
        :tag('tr')
            :tag('td')
                :done()
            :tag('td')
                :done()
            :done()
    
    tableNode:allDone()
    return tableNode
end

-- Implements the same functionality as Template:Recipe
-- Creates a block that gives the item's icon, name and price and/or combination cost
-- Is part of the item composition tree
-- Returns the mw.html object
function _buildRecipeTreeItem(item)
    -- Consists of three blocks: icons, text and prices below it
    local IL		= require('Module:ImageLink')
    local itemNode	= builder.create('div')
    itemNode
        :addClass('item')
        :css(
        {
            ['clear'] = 'left',
            ['padding'] = '1px'
        })
    
    local iconNode	= builder.create('div')
    iconNode:wikitext(tostring(IL.item{
        ['item'] = item,
        ['text'] = '*none*',
--        ['class'] = 'icon',
--        ['border'] = 'false',
        ['size'] = '32',
        ['iconstyle'] = 'float:left;margin-right:4px;border-radius:2px;overflow:hidden;border:1px solid #' .. lib.ternary(_isTitular(item), 'FFD700', '257372'),
    })):done()

    local labelNode = builder.create('div')
    labelNode:addClass('item-icon')
    labelNode
        :addClass('name')
        :attr('data-item', item)
        :attr('data-game', 'lol')
        :css{
            ['white-space'] = 'nowrap',
            ['padding-left'] = '40px',
            ['font-size'] = '14px',
            ['height'] = '20px',
            ['line-height'] = '20px'
        }
        :wikitext("<b>[[" .. getter.formatname(item) .. "]]</b>")
        :done()
    
    local costNode = builder.create('div')
    costNode
        :addClass('gold')
        :css{
            ['white-space'] = 'nowrap',
            ['padding-left'] = '40px',
            ['font-size'] = '11px',
            ['color'] = '#FFD700',
            ['height'] = '12px',
            ['line-height'] = '12px'
        }
        :wikitext(_getCostString(item))
        :done()
    
    itemNode
        :node(iconNode)
        :node(labelNode)
   	itemNode:node(costNode)
   	
    
    itemNode:allDone()
    
    return itemNode
end

function _isTitular(item)
    return tostring(item)==tostring(mw.title.getCurrentTitle())
end

-- is this item a transformation (e.g. Manamune/Muramana)
function _isTransformation(item)
    if getter.comb(item) == 0 then return true end
    return false
end

-- Returns a string with item cost and build cost
-- On the pages: below the item name in the build tree
function _getCostString(item)
    local cost = ""
    if not (getter.buy(item) == 0) then
        cost = cost .. _gold(getter.buy(item), '16')
    end
    if _isTransformation(item) then
    	cost = cost .. "&nbsp;(Special)"
    else
	    if getter.comb(item) and getter.comb(item) ~= 0 then
	       	cost = cost .. "&nbsp;(" .. _gold(getter.comb(item), '16') .. ')'
	    end
    end
    
    if cost == "" then
    	return _gold(0)
    end
    return cost
end

function _ItemIcon(item)
	local modes = {}
	local search = {item}

	if getter.exclusive(item) then modes[#modes+1] = 'FGM' end
	if not getter.removed(item) then
		for mode, modedata in pairs(gmgetter.fulldata()) do
			if getter.OneMode(item, mode) == true then
				if modedata["featured game mode"] == false then --Adds mode name if not FGM
					modes[#modes+1] = mode
				else
					modes[#modes+1] = "FGM"
				end
			end
		end
	end
	
	local champion = getter.champion(item)
	local nickname = getter.nickname(item)
	if champion then
		for _,v in ipairs(champion) do search[#search+1] = v end
	end
	if nickname then
		for _,v in ipairs(nickname) do search[#search+1] = v end
	end
	if not getter.oldmenu(item) and getter.menu(item) then
		for i,v in ipairs(getter.menu(item)) do
			search[#search+1] = v
		end
	end
	
	return builder.create('div')
		:addClass('item-icon')
		:cssText('padding:1px')
		:attr('data-game', 'lol')
		:attr('data-item', item)
		:attr('data-search', table.concat(search, ','))
		:attr('data-modes', table.concat(modes, ','))
		:tag('div')
			:cssText('border:1px solid #257372; width:42px; height:42px; border-radius: 2px;')
			:wikitext('[[File:'..FN.item{item}..'|40px|border|link='..getter.link(item)..']]')
			:done()
end

function _buildItemListContainer(itemList)
    local itemListContainer = builder.create('div')
    itemListContainer:addClass('tlist')
    local HTMLList = builder.create('ul')
    
    for k, item in ipairs(itemList) do
        HTMLList
            :tag('li')
                :node(_ItemIcon(item))
                :done()
            :newline()
    end
    
    itemListContainer:node(HTMLList)
    return itemListContainer
end

-- basically {{g|cost}}
function _gold(cost, size)
	local IL = require('Module:ImageLink')
	local FD = require('Module:Fd')
	return tostring(IL.basic({
		link = 'Gold',
		text = cost and FD.get{cost} or nil,
		image = 'Gold_colored_icon.png',
		size = size,
		alttext = cost and (cost..' Gold'),
		border = 'false',
		labellink = 'false',
		style = 'color:gold;white-space:pre;'
	}))
end

return p
-- </pre>
-- [[Category:Lua]]