Модуль:RecipeData

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

Информация из Модуль:RecipeData/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 data     = require('Module:RecipeData/data')
    local recipe   = args['recipe'] or args[1]
    local datatype = args['datatype'] or args[2]
    local num      = tonumber(args['num']) or 1
    
    local result = data[recipe]
    
    for k, v in ipairs(result) do
    	if tonumber(num) == k then
    		if datatype == 'name' then
    			return v['name']
    		elseif datatype == 'image' then
    			return v['image']
    		elseif datatype == 'count' then
    			return v['count']
    		elseif datatype == 'chance' then
    			if v['chance'] == nil then
    				v['chance'] = "?"
    			end
    			if v['chance'] == 100 then
    				v['chance'] = ">99"
    			end
    			return v['chance']
    		elseif datatype == 'max_chance' then
    			if v['max_chance'] == 100 then
    				v['max_chance'] = ">99"
    			end
    			return v['max_chance']
    		elseif datatype == 'catalyst' then
    			if v['chance'] == nil then
    				return "?"
    			end
				return math.floor((100 - v['chance']) / 2.5)
			elseif datatype == 'types' then
				local count = p.ingredients(v['ingredients'])
				if count == 1 or count == 2 then
					type = 1
				elseif count == 3 or count == 4 then
					type = 2
				else
					type = 3
				end
				
				return type
    		end
    	end
    end
    
end

function p.getRecipeItems(frame)
	local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
		
	local get     = require ('Module:RecipeData/getter')
	local recipe  = args['recipe'] or args[1]
	local items   = "ingredients"
	local num     = tonumber(args['num']) or 1
	local str     = ""

	local result = get[items](recipe)
	for k, v in ipairs(result) do
		if tonumber(num) == k then
			for k2, v2 in ipairs(v['ingredients']) do
				if tonumber(args['index']) == k2 then
					if v2[1] == "?" then
						str = mw.ustring.format('Неизвестно')
					else
						if v2[3] ~= nil then
							str = mw.ustring.format('%s!%s!%s', v2[1], v2[2], v2[3])
						else
							str = mw.ustring.format('%s!%s', v2[1], v2[2])
						end
					end
				end
			end
		end
    end
    
    return tostring(str)
end

function p.ingredients(items)
	local count
	for k, v in ipairs(items) do
		count = k
	end
	
	return count
end

return p