Модуль:ShopData

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

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


local p = {}

local lib     = require('Module:Feature')

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:ShopData/getter')
    local lot      = args['lot'] or args[1]
    local datatype = args['datatype'] or args[2]
    local output   = args['output'] or args[3] or nil
    
    local result = get[datatype](lot)
    
    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.getLots(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get       = require ('Module:ShopData/getter')
	local lot       = args['lot'] or args[1]
	local str       = ""

	str = mw.ustring.format('{{Lot|%s}}', lot)
    
    return frame:preprocess(tostring(str))
end

function p.getLotsPack(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get       = require ('Module:ShopData/getter')
	local lot       = args['lot'] or args[1]
	local count

	local result = get["lot_data"](lot)
	for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
			count = mw.ustring.format('%d', v[2])
		end
    end
    
    return tonumber(count)
end

function p.getLotType(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get       = require ('Module:ShopData/getter')
	local loot_type = require('Module:ItemData/loot/types')
	local lot       = args['lot'] or args[1]
	local type      = ""

	local result = get["lot_data"](lot)
	for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
			type = mw.ustring.format('%s', loot_type[v[3]])
		end
    end
    
    return tostring(type)
end

function p.getLotItems(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get     = require ('Module:ShopData/getter')
	local libHero = require('Module:HeroData')
    local libUnit = require('Module:UnitData')
	local lot     = args['lot'] or args[1]
	local divNode = mw.html.create('div')
	
	divNode
		:cssText('display: flex; flex-flow: row wrap; justify-content: center;')
		:newline()

	local result = get["lots"](lot)
	for k, v in ipairs(result) do
    	if tonumber(args['index']) == k then
			for k2, v2 in ipairs(v) do
                if v[k2][1] == "Августин" or
                   v[k2][1] == "Аилред" or
                   v[k2][1] == "Офаниель" or
                   v[k2][1] == "Дидгур" or
                   v[k2][1] == "Воин ягуара" or
                   v[k2][1] == "Уильям Вейн" or
                   v[k2][1] == "Тразк" or
                   v[k2][1] == "Джамис"
				then
					divNode
		    			:tag('div')
		    				:addClass('loot-item')
				    		:wikitext(mw.ustring.format('%s', libHero.getHeroIcon(v[k2][1], "60px")))
				    		:done()
                elseif v[k2][1] == "Лучники" or
                    v[k2][1] == "Волшебники" or
                    v[k2][1] == "Воины" or
                    v[k2][1] == "Грифоны" or
                    v[k2][1] == "Черные рыцари" or
                    v[k2][1] == "Сторожевая башня пустоты/1"
                then
                    divNode
		    			:tag('div')
		    				:addClass('loot-item')
				    		:wikitext(mw.ustring.format('%s', libUnit.getUnitIcon(v[k2][1], "60px", v[k2][2])))
				    		:done()
				else
	    			divNode
		    			:tag('div')
		    				:addClass('loot-item')
				    		:wikitext(mw.ustring.format('%s', p.getItemIcon(v[k2][1], "60px", v[k2][2])))
				    		:done()
				end
		    end
		end
    end
    
    return frame:preprocess(tostring(divNode))
end

function p.getItemIcon(item, size, count, link)
	local item_data    = require ('Module:ItemData/data')
	local rarity_data  = require ('Module:ItemData/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(item_data, item) then
		icon = item_data[item]["icon"]
	else
		return item
	end
	
	if rarity_data[item_data[item]["rarity"]] and rarity_data[item_data[item]["rarity"]] ~= nil then
		rarity = rarity_data[item_data[item]["rarity"]]
	else
		rarity = "обычный"
	end
	
	return mw.ustring.format('{{ii|%s|%s|%s|size=%s|count=%s|link=%s}}', item, icon, rarity, size, count, link)
end

return p