Модуль:BossData

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

Информация из Модуль:BossData/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:BossData/getter')
    local boss     = args['boss'] or args[1]
    local datatype = args['datatype'] or args[2]
    local output   = args['output'] or args[3] or nil
    
    local result = get[datatype](boss)
    
    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.getBossInfo(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
	
	local get      = require ('Module:BossData/getter')
	local boss     = args['boss'] or args[1]
	local info     = "info"
	local str      = ""
	
	local result = get[info](boss)
	
	str = mw.ustring.format('%s', result)
	
	return frame:preprocess(tostring(str))
end

function p.getBossLoot(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get     = require ('Module:BossData/getter')
	local boss    = args['boss'] or args[1]
	local loot    = "loot"
	local str     = ""
	local count   = 0
	
    local result = get[loot](boss)
    
    for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
    		if v[2] == 1 then count = "" else count = v[2] end
	    	str = mw.ustring.format('%s/%s', v[1], count)
	    end
    end
    return frame:preprocess(tostring(str))
end

function p.getBossGuards(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get     = require ('Module:BossData/getter')
	local boss    = args['boss'] or args[1]
	local guards  = "guards"
	local feature = ""
	local str     = ""
	
    local result = get[guards](boss)
    
    for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
    		for _, v1 in ipairs(v["feature"]) do
    			feature = lib.tbl_concat{v["feature"], separator = ","}
    		end
	    	str = mw.ustring.format('%s/%s/%s', v["icon"], lib.comma_value(v["hp"]), feature)
	    end
    end
    return frame:preprocess(tostring(str))
end

function p.getBossesTable(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end

	local type = args['type'] or args[1]
	local loot = ""
	local count = 0

    local tableNode = mw.html.create('table')
    tableNode
        :addClass('wikitable sortable')
        :cssText('width: 80%; 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')
            	:attr('class', 'unsortable')
                :wikitext('Добыча')
                :done()
            :done()
    
	    local bosses  = mw.loadData('Module:BossData/data')
	    local race  = mw.loadData('Module:HeroData/races')
	    for k, v in lib.pairsByAlphabeticalKeys(bosses) do
	    	for k1, v1 in ipairs(v['loot']) do
	    		if v['loot'][k1][2] == 1 then count = nil else count = v['loot'][k1][2] end
    			loot = loot .. mw.ustring.format('%s', libItem.getItemIcon(v['loot'][k1][1], "30px", count))
    		end
	    	if type ~= nil then
		    	if tonumber(type) == v['type'] then
			        local rowNode = mw.html.create('tr')
			        rowNode
			            :tag('td')
			                :attr('data-sort-value', k)
			                :wikitext(mw.ustring.format('[[%s/босс|%s]]', v['name'], v['name']))
			                :done()
			            :tag('td')
			                :wikitext(mw.ustring.format('<div class="boss-icon" style="width:45px;">[[Файл:%s|45px|ссылка=%s/босс]]</div>', v['icon'], v['name']))
			                :done()
			            :tag('td')
			                :attr('data-sort-value', race[v['race']])
			                :wikitext(mw.ustring.format(lib.ternary(v['race'] == nil, "N/A", '[[:Категория:%s (раса)|%s]]'), race[v['race']], race[v['race']]))
			                :done()
			            :tag('td')
			                 :wikitext(mw.ustring.format('<div class="boss-hp" style="width:120px; margin: 0;">%s</div>', lib.comma_value(v['hp'])))
			                 :done()
			            :tag('td')
			            	 :attr('data-sort-value',  v['points'])
			                 :wikitext(mw.ustring.format('<div style="display: flex;">{{Очки осады}} <span class="score">%s</span></div>', v['points']))
			                 :done()
			            :tag('td')
			                 :wikitext(mw.ustring.format('<div style="display: flex;">%s</div>', loot))
			                 :done()
			        	:done()
			        tableNode:node(rowNode):newline()
			        loot = ""
		    	end
		    else
		    	local rowNode = mw.html.create('tr')
		        rowNode
		            :tag('td')
		                :attr('data-sort-value', k)
		                :wikitext(mw.ustring.format('[[%s/босс|%s]]', v['name'], v['name']))
		                :done()
		            :tag('td')
		                :wikitext(mw.ustring.format('<div class="boss-icon" style="width:45px;">[[Файл:%s|45px|ссылка=%s/босс]]</div>', v['icon'], v['name']))
		                :done()
		            :tag('td')
		                :attr('data-sort-value', race[v['race']])
		                :wikitext(mw.ustring.format(lib.ternary(v['race'] == nil, "N/A", '[[:Категория:%s (раса)|%s]]'), race[v['race']], race[v['race']]))
		                :done()
		            :tag('td')
		                 :wikitext(mw.ustring.format('<div class="boss-hp" style="width:120px; margin: 0;">%s</div>', lib.comma_value(v['hp'])))
		                 :done()
		            :tag('td')
		            	 :attr('data-sort-value',  v['points'])
		                 :wikitext(mw.ustring.format('<div>{{Очки осады}} <span class="score">%s</span></div>', v['points']))
		                 :done()
		            :tag('td')
		                 :wikitext(mw.ustring.format('<div style="display: flex;">%s</div>', loot))
		                 :done()
		        	:done()
		        tableNode:node(rowNode):newline()
		    end
	    end
    
    return frame:preprocess(tostring(tableNode))
end

function p.getIconBoss(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local boss_data    = require ('Module:BossData/data')
	local icon = ""
	
	if args['size'] == nil then
		size = "30px"
	else
		size = args['size']
	end
	
	if args['link'] == nil then
		link = ""
	else
		link = args['link']
	end
	
	if args['caption'] == nil then
		caption = ""
	else
		caption = args['caption']
	end
	
	if args['border'] == nil then
		border = "1px solid #667985"
	else
		border = args['border']
	end
	
	if lib.lookup(boss_data, args['boss']) then
		icon = boss_data[args['boss']]["icon"]
	else
		return args['boss']
	end
	
	return frame:preprocess(mw.ustring.format('{{bi|%s|%s|size=%slink=%s|caption=%s}}', args['boss'], icon, size, link, caption))
end

return p