Модуль:UnitData

Данная группа модулей хранит информацию обо всех юнитах из Крушителей подземелий. Перечень модулей:

Информация из Модуль:UnitData/doc


local p = {}

local lib = require('Module:Feature')
local libItem = require('Module:ItemData')

function p.get(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	
	local get      = require ('Module:UnitData/getter')
    local unit     = args['unit'] or args[1]
    local datatype = args['datatype'] or args[2]
    local output   = args['output'] or args[3] or nil
    
    local result = get[datatype](unit)
    
    if output ~= nil and type(result) == "table" then
        if output == "csv" then
            return lib.tbl_concat{result}
        elseif output == "custom" then 
            return frame:preprocess(lib.tbl_concat({result, prepend = args['prepend'], append = args['append'], separator = args['separator'], index = args["index"]}))
        elseif output == "template" then 
            return frame:preprocess(lib.tbl_concat{result, prepend = "{{" .. args['t_name'] .. "|", append = "}}", separator = args['separator']})
        end
    elseif result == nil then
        return ""
    else
        return result
    end
end

function p.getUnitAbility(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get     = require ('Module:UnitData/getter')
	local unit    = args['unit'] or args[1]
	local ability = "abilities"
	local str     = ""
	
	local result = get[ability](unit)
	
	for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
    		str = mw.ustring.format('%s/%s/%s/%s', v[1], v[2], v[3], v[4])
    	end
    end
    
    return str
end

function p.getUnitSource(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get         = require ('Module:UnitData/getter')
	local recipe_data = require ('Module:RecipeData/data')
	local loot_data   = require ('Module:ItemData/loot')
	local boss_data   = require ('Module:BossData/data')
	local item_data   = require ('Module:ItemData/data')
	local unit        = args['unit'] or args[1]
	local str         = ""
	local i           = 0
	
	local result      = get["source"](unit)
	local data        = recipe_data[unit]
	
	if (result ~= "Добыча") then
		str = str .. mw.ustring.format('<h2>Способ получения</h2>')
	end
	
	if (result == "Крафт") then
		str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">')
		if data ~= nil then
			for k, v in ipairs(data) do
				i = i + 1
				if unit ~= "Арбалетчики" and unit ~= "Воины/2" and unit ~= "Колдуны" then
					str = str .. mw.ustring.format('{{RecipeImage2|%s|%d}}', unit, k)
				else
					str = str .. mw.ustring.format('{{RecipeImage3|%s|%d}}', unit, k)
				end
			end
		end
		if i == 0 then
			str = str .. "Нет данных"
		end
		str = str .. mw.ustring.format('</div></div>')
	elseif (result == "Сундук") then
		str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">')
		for k, v in ipairs(loot_data) do
			for k1, v1 in ipairs(v) do
				if (v[k1][1] == unit) then
					for k2, v2 in pairs(item_data) do
						for k3, v3 in pairs(item_data[k2]["loot"]) do
							if (v3[1] == k) then
								str = str .. mw.ustring.format('%s', libItem.getItemIcon(k2, "100px"))
							end
						end
					end
				end
			end
		end
		str = str .. mw.ustring.format('</div>')
	elseif (result == "Босс") then
		str = str .. mw.ustring.format('<div class="bosses" style="width:fit-content; width: -moz-fit-content">')
		for k, v in pairs(boss_data) do
			for k2, v2 in pairs(boss_data[k]["loot"]) do
				if (v2[1] == unit) then
					str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k)
				end
			end
		end
		str = str .. mw.ustring.format('</div>')
	elseif (result == "Крафт/Сундук") then
		str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">')
		if data ~= nil then
			for k, v in ipairs(data) do
				i = i + 1
				if unit ~= "Арбалетчики" and unit ~= "Воины/2" and unit ~= "Колдуны" then
					str = str .. mw.ustring.format('{{RecipeImage2|%s|%d}}', unit, k)
				else
					str = str .. mw.ustring.format('{{RecipeImage3|%s|%d}}', unit, k)
				end
			end
		end
		if i == 0 then
			str = str .. "Нет данных"
		end
		str = str .. mw.ustring.format('</div></div>')
		str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">')
		for k, v in ipairs(loot_data) do
			for k1, v1 in ipairs(v) do
				if (v[k1][1] == unit) then
					for k2, v2 in pairs(item_data) do
						for k3, v3 in pairs(item_data[k2]["loot"]) do
							if (v3[1] == k) then
								str = str .. mw.ustring.format('%s', libItem.getItemIcon(k2, "100px"))
							end
						end
					end
				end
			end
		end
		str = str .. mw.ustring.format('</div>')
	elseif (result == "Крафт/Босс") then
		str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">')
		if data ~= nil then
			for k, v in ipairs(data) do
				i = i + 1
				if unit ~= "Арбалетчики" and unit ~= "Воины/2" and unit ~= "Колдуны" then
					str = str .. mw.ustring.format('{{RecipeImage2|%s|%d}}', unit, k)
				else
					str = str .. mw.ustring.format('{{RecipeImage3|%s|%d}}', unit, k)
				end
			end
		end
		if i == 0 then
			str = str .. "Нет данных"
		end
		str = str .. mw.ustring.format('</div></div>')
		str = str .. mw.ustring.format('<div class="bosses" style="width:fit-content; width: -moz-fit-content">')
		for k, v in pairs(boss_data) do
			for k2, v2 in pairs(boss_data[k]["loot"]) do
				if (v2[1] == unit) then
					str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k)
				end
			end
		end
		str = str .. mw.ustring.format('</div>')
	elseif (result == "Сундук/Босс") then
		str = str .. mw.ustring.format('<div class="chests" style="width:fit-content; width: -moz-fit-content">')
		for k, v in ipairs(loot_data) do
			for k1, v1 in ipairs(v) do
				if (v[k1][1] == unit) then
					for k2, v2 in pairs(item_data) do
						for k3, v3 in pairs(item_data[k2]["loot"]) do
							if (v3[1] == k) then
								str = str .. mw.ustring.format('%s', libItem.getItemIcon(k2, "100px"))
							end
						end
					end
				end
			end
		end
		str = str .. mw.ustring.format('</div>')
		str = str .. mw.ustring.format('<div class="bosses" style="width:fit-content; width: -moz-fit-content">')
		for k, v in pairs(boss_data) do
			for k2, v2 in pairs(boss_data[k]["loot"]) do
				if (v2[1] == unit) then
					str = str .. mw.ustring.format('[[Файл:%s|100px|ссылка=%s/босс]]', boss_data[k]["icon"], k)
				end
			end
		end
		str = str .. mw.ustring.format('</div>')
	elseif (result == "Магазин") then
		str = str .. mw.ustring.format('<div class="shop" style="width:fit-content; width: -moz-fit-content">')
		str = str .. mw.ustring.format('[[Файл:icon_shop.png|x100px|ссылка=Магазин]]', "Магазин")
		str = str .. mw.ustring.format('</div>')
	elseif (result == "Магазин/Крафт") then
		str = str .. mw.ustring.format('<div class="recipes"><div class="owl-carousel owl-theme recipes-carousel">')
		if data ~= nil then
			for k, v in ipairs(data) do
				i = i + 1
				if unit ~= "Арбалетчики" and unit ~= "Воины/2" and unit ~= "Колдуны" then
					str = str .. mw.ustring.format('{{RecipeImage2|%s|%d}}', unit, k)
				else
					str = str .. mw.ustring.format('{{RecipeImage3|%s|%d}}', unit, k)
				end
			end
		end
		if i == 0 then
			str = str .. "Нет данных"
		end
		str = str .. mw.ustring.format('</div></div>')
		str = str .. mw.ustring.format('<div class="shop" style="width:fit-content; width: -moz-fit-content">')
		str = str .. mw.ustring.format('[[Файл:icon_shop.png|x100px|ссылка=Магазин]]', "Магазин")
		str = str .. mw.ustring.format('</div>')
	end

	return frame:preprocess(tostring(str))	
end

function p.getAllianceIcon(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local icons_data = require ('Module:IconData/alliances')
	local alliance   = args['alliance'] or args[1]
	local size       = args['size'] or args[2]
	local icon       = ""
	local str        = ""
	
	if icons_data[alliance] ~= nil then
		icon = icons_data[alliance]
	else
		return "-"
	end
	
	str = mw.ustring.format('[[Файл:%s|%s|link=:Категория:%s (альянс)]]', icon, size, alliance)
	
	return frame:preprocess(tostring(str))
end

function p.getUnitCategories(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local unit_data       = require ('Module:UnitData/data')
	local categories_data = require ('Module:HeroData/categories')
	local unit            = args['unit'] or args[1]
	local categories      = {}
	local str             = ""
	
	if unit_data[unit]["categories"] ~= nil then
    	for _, v in ipairs(unit_data[unit]["categories"]) do
			str = str .. mw.ustring.format('[[Категория:%s]]\n', categories_data[v])
		end
	end
	
	return frame:preprocess(tostring(str))
end

function p.getUnitCategoriesTable(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local unit_data       = require ('Module:UnitData/data')
	local categories_data = require ('Module:HeroData/categories')
	local races           = require ('Module:HeroData/races')
	local classes         = require ('Module:HeroData/classes')
	local alliances       = require ('Module:HeroData/alliances')
	local category        = args['category'] or args[1]
	local units           = {}
	local race            = ""
	local class           = ""
	local alliance        = ""
    local tableNode       = mw.html.create('table')
    
    for k, v in lib.pairsByAlphabeticalKeys(unit_data) do
    	if unit_data[k]['categories'] ~= nil then
	    	for k1, v1 in ipairs(unit_data[k]['categories']) do
	    		if category == categories_data[unit_data[k]['categories'][k1]] then
	    			table.insert(units, k)
	    		end
	    	end
	    end
    end
    
    tableNode
        :addClass('custom-table active-hover sortable')
        :cssText('width: 100%; text-align: center; display: table;')
        :newline()
    
    tableNode
        :tag('tr')
            :css('white-space', 'nowrap')
            :tag('th')
                :wikitext('Имя')
                :done()
            :tag('th')
            	:attr('class', 'unsortable')
                :css('width', '60px')
                :wikitext('Иконка')
                :done()
            :tag('th')
                :css('width', '80px')
                :wikitext('Раса')
                :done()
            :tag('th')
                :css('width', '80px')
                :wikitext('Класс')
                :done()
            :tag('th')
                :css('width', '60px')
                :wikitext('Альянс')
                :done()
            :tag('th')
                :css('width', '60px')
                :wikitext('HP')
                :done()
            :tag('th')
                :css('width', '60px')
                :wikitext('DEF')
                :done()
            :tag('th')
                :css('width', '60px')
                :wikitext('ATK')
                :done()
            :tag('th')
                :css('width', '60px')
                :wikitext('WIS')
                :done()
            :tag('th')
                :css('width', '60px')
                :wikitext('AGI')
                :done()
            :done()
    
    for k1, v1 in lib.pairsByAlphabeticalKeys(units) do
    	if unit_data[v1]['race'] ~= nil then
    		race = races[unit_data[v1]['race']]
    	else
    		race = "-"
    	end
    	
    	if unit_data[v1]['class'] ~= nil then
    		class = classes[unit_data[v1]['class']]
    	else
    		class = "-"
    	end
    	
    	if unit_data[v1]['alliance'] ~= nil then
    		alliance = alliances[unit_data[v1]['alliance']]
    	else
    		alliance = "-"
    	end
    		
        local rowNode = mw.html.create('tr')
        rowNode
            :tag('td')
                :attr('data-sort-value', v1)
                :wikitext(mw.ustring.format('[[%s]]', unit_data[v1]['name']))
                :done()
            :tag('td')
                :wikitext(mw.ustring.format('%s', p.getUnitIcon(unit_data[v1]['name'], "35px")))
                :done()
            :tag('td')
                :attr('data-sort-value', race)
                :wikitext(mw.ustring.format('%s', lib.ternary(type(unit_data[v1]['race']) ~= "nil", 
                	mw.ustring.format('[[:Категория:%s (раса)|%s]]', race, race), 
                	"-")))
                :done()
            :tag('td')
                :attr('data-sort-value', class)
                :wikitext(mw.ustring.format('%s', lib.ternary(unit_data[v1]['class'] ~= nil, 
                		mw.ustring.format('[[:Категория:%s (класс)|%s]]', class, class), 
                	"-")))
                :done()
            :tag('td')
                :attr('data-sort-value', alliance)
                :wikitext(mw.ustring.format('%s',  lib.ternary(unit_data[v1]['alliance'] ~= nil, AllianceIcon(alliance, "45px"), "-")))
                :done()
            :tag('td')
                 :wikitext(mw.ustring.format('%s', lib.ternary(unit_data[v1]['stats']['hp_base'] == nil, "N/A", unit_data[v1]['stats']['hp_base'])))
                 :done()
            :tag('td')
                 :wikitext(mw.ustring.format('%s', lib.ternary(unit_data[v1]['stats']['def_base'] == nil, "N/A", unit_data[v1]['stats']['def_base'])))
                 :done()
            :tag('td')
                 :wikitext(string.format('%s', lib.ternary(unit_data[v1]['type'] == nil, "N/A", lib.ternary(unit_data[v1]['type'] == 1 or unit_data[v1]['type'] == 4, setUnitMainStat(unit_data[v1]['stats']['atk_base']), unit_data[v1]['stats']['atk_base']))))
                 :done()
            :tag('td')
                 :wikitext(string.format('%s', lib.ternary(unit_data[v1]['type'] == nil, "N/A", lib.ternary(unit_data[v1]['type'] == 2 or unit_data[v1]['type'] == 4 or unit_data[v1]['type'] == 5, setUnitMainStat(unit_data[v1]['stats']['wis_base']), unit_data[v1]['stats']['wis_base']))))
                 :done()
            :tag('td')
                 :wikitext(string.format('%s', lib.ternary(unit_data[v1]['type'] == nil, "N/A", lib.ternary(unit_data[v1]['type'] == 3 or unit_data[v1]['type'] == 5, setUnitMainStat(unit_data[v1]['stats']['agi_base']), unit_data[v1]['stats']['agi_base']))))
                 :done()
        	:done()
        tableNode:node(rowNode):newline()
    end
    
    return frame:preprocess(tostring(tableNode))
end

function setUnitMainStat(str)
    local spanNode = mw.html.create('span')
    
    if str == nil then
    	str = "N/A"
    end
    
    spanNode
        :addClass('rarity-glpar')
        :wikitext(mw.ustring.format('%s', str))
    :done()

    return tostring(spanNode)
end

function p.getUnitIcon(unit, size, count, link)
	local unit_data    = require ('Module:UnitData/data')
	local rarity_data  = require ('Module:HeroData/rarities')
	local rarity, icon = ""
	
	if size == nil then
		size = "30px"
	end
	
	if count == nil then
		count = ""
	end
	
	if link == nil then
		link = ""
	end
	
	if lib.lookup(unit_data, unit) then
		icon = unit_data[unit]["icon"]
	else
		return unit
	end
	
	if rarity_data[unit_data[unit]["rarity"]] and rarity_data[unit_data[unit]["rarity"]] ~= nil then
		rarity = rarity_data[unit_data[unit]["rarity"]]
	else
		rarity = "обычный"
	end
	
	return mw.ustring.format('{{UnitIcon|%s|%s|%s|size=%s|count=%s|link=%s}}', unit, icon, rarity, size, count, link)
end

function p.getIconUnit(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local unit_data    = require ('Module:UnitData/data')
	local rarity_data  = require ('Module:ItemData/rarities')
	local rarity, icon, size, count = ""
	
	if args['size'] == nil then
		size = "30px"
	else
		size = args['size']
	end
	
	if args['count'] == nil then
		count = ""
	else
		count = args['count']
	end
	
	if args['link'] == nil then
		link = ""
	else
		link = args['link']
	end
	
	if args['caption'] == nil then
		caption = ""
	else
		caption = args['caption']
	end
	
	if lib.lookup(unit_data, args['unit']) then
		icon = unit_data[args['unit']]["icon"]
	else
		return args['unit']
	end
	
	if unit_data[unit_data[args['unit']]["rarity"]] and unit_data[unit_data[args['unit']]["rarity"]] ~= nil then
		rarity = rarity_data[unit_data[args['unit']]["rarity"]]
	else
		rarity = "обычный"
	end
	
	return frame:preprocess(mw.ustring.format('{{UnitIcon|%s|%s|%s|size=%s|count=%s|link=%s|caption=%s}}', args['unit'], icon, rarity_data[unit_data[args['unit']]["rarity"]], size, count, link, caption))
end

function AllianceIcon(alliance, size)
	local icons_data = require ('Module:IconData/alliances')
	local icon       = ""
	local str        = ""
	
	if icons_data[alliance] ~= nil then
		icon = icons_data[alliance]
	else
		return "-"
	end
	
	str = mw.ustring.format('[[Файл:%s|%s|link=:Категория:%s (альянс)]]', icon, size, alliance)
	
	return tostring(str)
end

return p