Module:Infobox/Item

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

To edit the documentation or categories for this module, click here. This module has an i18n file. Click here to edit it.


local lang = mw.getLanguage('en')
local Country = require('Module:Country').main
local social = require('Module:Infobox/Social')
local teamhist = require('Module:Infobox/TeamHist')
local util_infobox = require('Module:InfoboxUtil')
local util_html = require('Module:HtmlUtil')
local util_cargo = require('Module:CargoUtil')
local util_table = require('Module:TableUtil')
local util_args = require('Module:ArgsUtil')

local Stat = require('Module:StatClass')

local MAPS = {
	ALL = '<abbr title="All Maps">ALL</abbr>',
	SR = '<abbr title="Summoner\'s Rift">SR</abbr>',
	TT = '<abbr title="Twisted Treeline">TR</abbr>',
	CS = '<abbr title="Crystal Scar">CS</abbr>',
	HA = '<abbr title="Howling Abyss">HA</abbr>',
	BMB = '<abbr title="Black Market Brawlers">BMB</abbr>',
	NB = '<abbr title="Nexus Blitz">NB</abbr>',
}

local GOLD_ICON = '[[File:Goldcurrency.png|20px|link=]]'

local InfoboxData = require('Module:InfoboxDataClass')
local InfoboxItem = InfoboxData:extends()

local h = {}

local p = {}

function p.main(args)
	args._title = args.name
	return InfoboxItem:init(args)
end

InfoboxItem.LAYOUT = {
	tabs = 'ItemTabsHeader',
	sections = { 'Consumable', 'Passive', 'Active', 'Statistics', 'Additional Information', 'Recipe', 'Builds Into' },
	contents = {
		{ 'consumable', consumable = 'wide' },
		{ 'passive1', 'passive2', 'passive3', 'passive4', passive1 = 'wide', passive2 = 'wide', passive3 = 'wide', passive4 = 'wide' },
		{ 'active', active = 'wide' },
		{ 'Health', 'HPRegen', 'Mana', 'ManaRegen', 'Energy', 'EnergyRegen', 'AD', 'Crit', 'AS', 'LifeSteal', 'ArmorPen', 'Range', 'AP', 'CDR', 'SpellVamp', 'MPen', 'Armor', 'MR',  'Movespeed', 'Tenacity', 'GoldGen', 'OnHit', 'BonusHP', 'Healing' },
		{ 'Limitations', 'MapAvailability', 'Tier', 'ItemCode' },
		{ 'recipe', 'TotalCost', 'SoldFor', recipe = 'wide', TotalCost = 'wide', SoldFor = 'wide' },
		{ 'buildsinto', buildsinto = 'wide' },
	},
	classes = {
		consumable = 'infobox-item-passive',
		passive1 = 'infobox-item-passive',
		passive2 = 'infobox-item-passive',
		passive3 = 'infobox-item-passive',
		passive4 = 'infobox-item-passive',
		active = 'infobox-item-passive',
	},
}

InfoboxItem.type = 'Item'

function InfoboxItem:getDisplay(args, processed)
	local recipe_tbl = {
		args['special recipe'] or args['recipe 1'] and util_table.concatFromArgs(args, 'recipe ', ' + ', h.printItem),
		args.gold and ('%s %s'):format(args.gold, GOLD_ICON)
	}
	local tbl = {
		names = util_infobox.statDisplays(self.LAYOUT.contents[4]),
		
		title = args.name,
		notice = args.removedin and ('Item was removed in [[Patch %s]].'):format(args.removedin) or util_args.castAsBool(args.isremoved) and 'Item has been removed.',
		image = args.image or ('%s.png'):format(args.name),
		imagesize = args.imagesize or '64px',
		imagecaption = args.lore,
		
		passive1 = args.passive1,
		passive2 = args.passive2,
		passive3 = args.passive3,
		passive4 = args.passive4,
		
		consumable = args.consumable,
		
		active = args.active,
		
		AD = args.ad,
		LifeSteal = args.ls,
		Health = args.hp,
		HPRegen = args.hpregen,
		Armor = args.armor,
		MR = args.mr,
		AttackDamage = args.ad,
		Crit = args.crit,
		AS = args.as,
		LifeSteal = args.ls,
		ArPen = args.armorpen,
		Range = args.range,
		Mana = args.mana,
		ManaRegen = args.manaregen,
		Energy = args.energy,
		EnergyRegen = args.energyregen,
		AP = args.ap,
		CDR = args.cdr,
		SpellVamp = args.spellvamp,
		MPen = args.magicpen,
		Movespeed = args.ms,
		Tenacity = args.tenacity,
		GoldGen = args.goldgen and ('+%s per 10 seconds'):format(args.goldgen),
		OnHit = args.onhit,
		BonusHP = args.bonushp,
		Healing = args.healing,
		
		Limitations = args.limit,
		MapAvailability = args.map1 and util_table.concatFromArgs(args, 'map', ', ', h.printMap),
		Tier = args.tier,
		ItemCode = args['item code'],
		
		recipe = util_table.concat(recipe_tbl,' + '),
		TotalCost = args.totalgold and ("'''Total Cost:''' %s %s"):format(args.totalgold, GOLD_ICON),
		SoldFor = args.sold and ("'''Sold For:''' %s %s"):format(args.sold, GOLD_ICON),
		
		buildsinto = args['used in 1'] and util_table.concatFromArgs(args, 'used in ', ' ', h.printItem),
	}
	return tbl
end

function h.printMap(map)
	return MAPS[map]
end

function h.printItem(item)
	return ('[[File:%s.png|32px|link=%s (Item)]]'):format(item, item)
end

function InfoboxItem:getCargo(args, processed)
	local cargo = self:super('getCargo', args, processed)
	local tbl = {
		{
			_table = 'Items',
			Name = args.name,
			AD = args.ad,
			LifeSteal = args.ls,
			Health = args.hp,
			HPRegen = args.hpregen,
			Armor = args.armor,
			MR = args.mr,
			AttackDamage = args.ad,
			Crit = args.crit,
			AS = args.as,
			LifeSteal = args.ls,
			ArPen = args.armorpen,
			Range = args.range,
			Mana = args.mana,
			ManaRegen = args.manaregen,
			Energy = args.energy,
			EnergyRegen = args.energyregen,
			AP = args.ap,
			CDR = args.cdr,
			SpellVamp = args.spellvamp,
			MPen = args.magicpen,
			Movespeed = args.ms,
			Tenacity = args.tenacity,
			GoldGen = args.goldgen,
			OnHit = args.onhit,
			BonusHP = args.bonushp,
			Healing = args.healing,
		}
	}
	return util_table.mergeArrays(cargo, tbl)
end

function InfoboxItem:getCategories(args, processed)
	local tbl = {
		'Items',
		args.tier and ('%s Items'):format(args.tier),
		args.isremoved and 'Removed Items',
		args.removedin and 'Removed Items',
	}
	return tbl
end

return p