Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

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


local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_html = require('Module:HtmlUtil')
local util_infobox = require('Module:InfoboxUtil')
local util_news = require("Module:NewsUtil")
local util_table = require('Module:TableUtil')
local util_text = require("Module:TextUtil")
local util_title = require("Module:TitleUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require('Module:i18nUtil')

local Pronoun = require('Module:Pronoun')

local RP_ICON = '[[File:RpPoints.png|15px|alt=RP|link=]]'
local BE_ICON = '[[File:BEPoints.png|15px|alt=BE|link=]]'

local Infobox = require('Module:Infobox'):extends()

local lang = mw.getLanguage('en')

local h = {}
local p = {}
function p.main(frame)
	local args = util_args.merge()
	return Infobox(args):run()
end

Infobox.LAYOUT = {
	tabs = 'ChampionTabsHeader',
	sections = { 'General Information', 'Statistics', 'Developer', 'ExternalLinks' },
	contents = {
		{ 'ChampTitle', 'RealName', 'Pronouns', 'ReleaseDate', 'Cost', 'Attribute', 'PrimaryAttribute', 'SecondaryAttribute', 'Resource' },
		{ 'Health', 'HPRegen', 'Mana', 'ManaRegen', 'Energy', 'EnergyRegen', 'MS', 'AD', 'AS', 'Range', 'Armor', 'MR', },
		{ 'KeyDdragon', 'KeyInt', },
		{ 'LinkUniverse', 'LinkGameInfo', },
	},
}
Infobox.type = 'Champion'

function Infobox:castArgs(args)
	args.pronoun = Pronoun(args.pronoun)
end

function Infobox:getDisplay(args, processed)
	local display = self:super('getDisplay', args, processed)
	local tbl = {
		names = util_infobox.statDisplays(self.LAYOUT.contents[2]),
		
		title = args.name,
		image = args.image or ('%sSquare.png'):format(args.name),
		imagesize = '120px',
		
		ChampTitle = args.title,
		ReleaseDate = args.releasedate,
		Cost = ('%s %s %s %s'):format(args.be or '', BE_ICON, args.rp or '', RP_ICON),
		Attribute = not args.attribute2 and args.attribute,
		PrimaryAttribute = args.attribute2 and args.attribute,
		SecondaryAttribute = args.attribute2,
		RealName = args.realname,
		
		Health = h.stat(args.display_hp or args.hp, args.display_hp_lvl or args.hp_lvl),
		HPRegen = h.stat(args.hpregen, args.hpregen_lvl),
		Mana = h.stat(args.mana, args.mana_lvl),
		ManaRegen = h.stat(args.mregen, args.mregen_lvl),
		Energy = h.stat(args.energy, args.energy_lvl),
		EnergyRegen = h.stat(args.eregen, args.eregen_lvl),
		MS = args.ms,
		AD = h.stat(args.ad, args.ad_lvl),
		AS = args.as and ('%s (+ %s%%)'):format(args.as, args.as_lvl),
		Range = args.range,
		Armor = h.stat(args.armor, args.armor_lvl),
		MR = h.stat(args.mr, args.mr_lvl),
		Pronouns = args.pronoun:name(),
		
		KeyDdragon = args.ddragon_key,
		KeyInt = args.key_int,
		
		LinkGameInfo = util_text.intLink(('gameinfo:%s/LoL'):format(mw.title.getCurrentTitle().text), i18n.print('gameInfoWiki')),
		LinkUniverse = args.ddragon_key and util_text.extLink(('https://universe.leagueoflegends.com/en_US/champion/%s'):format(args.ddragon_key), i18n.print('universeOfLegends')),
		
	}
	return Infobox.mergeDisplay(display, tbl)
end

function h.stat(base, level)
	return base and ('%s (+ %s)'):format(base, level)
end

function Infobox:getCargo(args, processed)
	util_cargo.setStoreNamespace('')
	local cargo = self:super('getCargo', args, processed)
	local tbl = {
		{
			_table = 'Champions',
			Name = args.name,
			Title = args.title,
			ReleaseDate = args.releasedate,
			BE = args.be,
			RP = args.rp,
			Attributes = util_table.concatFromArgs(args,'attribute',','),
			Resource = args.resource,
			RealName = args.realname,
			Health = args.hp,
			HPLevel = args.hp_lvl,
			HPDisplay = args.display_hp or args.hp,
			HPLevelDisplay = args.display_hp_lvl or args.hp_lvl,
			HPRegen = args.hpregen,
			HPRegenLevel = args.hpregen_lvl,
			Mana = args.mana,
			ManaLevel = args.mana_lvl,
			ManaRegen = args.mregen,
			ManaRegenLevel = args.mregen_lvl,
			Energy = args.energy,
			EnergyRegen = args.eregen,
			Movespeed = args.ms,
			AttackDamage = args.ad,
			ADLevel = args.ad_lvl,
			AttackSpeed = args.as,
			ASLevel = args.as_lvl,
			AttackRange = args.range,
			Armor = args.armor,
			ArmorLevel = args.armor_lvl,
			MagicResist = args.mr,
			MagicResistLevel = args.mr_lvl,
			KeyDdragon = args.key_ddragon,
			KeyInteger = args.key_int,
			Pronoun = args.pronoun,
		},
	}
	tbl[#tbl+1] = h.getNewsLine(args, processed)
	return util_table.mergeArrays(cargo, tbl)
end

function h.getNewsLine(args, processed)
	if util_args.castAsBool(args.notreleased) then return end
	util_news.setId()
	args.date = lang:formatDate('Y-m-d', args.releasedate)
	args.Sentence = i18n.default(
		'NewsSentence',
		util_text.intLinkOrText(args.name)
	)
	local tbl = {
		Subject = 'Riot',
		SubjectLink = 'Portal:Champions',
		SubjectType = 'Tournament',
		Region = 'International',
	}
	util_table.mergeDontOverwrite(tbl, util_news.getNewsCargoFieldsFromArgs(args))
	return tbl
end

function Infobox:getCategories(args, processed)
	local tbl = {
		'Champions',
		util_args.nilToFalse(args.energy) and 'Energy-Based Champions',
	}
	return tbl
end

return p
Advertisement