Neverwinter Wiki
Advertisement

Для документации этого модуля может быть создана страница Модуль:Recipe table/doc

local item_icon = require('Модуль:Item_icon')
local attributes = mw.loadData('Модуль:Item/Attributes')

local p = {}

local professions = {
    ['алхимия'] = '[[Файл:Crafting_Profession_Alchemy.png|20px|ссылка=Алхимия]]',
    ['ковка доспехов'] = '[[Файл:Crafting_Profession_Hvyarmoring.png|20px|ссылка=Ковка доспехов]]',
    ['кройка и шитье'] = '[[Файл:Crafting_Profession_Tailoring.png|20px|ссылка=Кройка и шитье]]',
    ['кузнечное дело'] = '[[Файл:Crafting_Profession_Weaponsmithing.png|20px|ссылка=Кузнечное дело]]',
    ['нанесение узоров'] = '[[Файл:Crafting_Profession_Artificing.png|20px|ссылка=Нанесение узоров]]',
    ['обработка кожи'] = '[[Файл:Crafting_Profession_Leatherworking.png|20px|ссылка=Обработка кожи]]',
    ['ювелирное дело']  = '[[Файл:Crafting_Profession_Jewelcrafting.png|20px|ссылка=Ювелирное дело]]'
}

function p.Main( frame )
    local cargo = mw.ext.cargo
    local tables = 'Recipes, Items'
    local fields = 'Recipes.name, Recipes.source, Recipes.quantity, Recipes.professions, Recipes.level, Recipes.material1_quantity, Recipes.material1_item, Recipes.material2_quantity, Recipes.material2_item, Recipes.material3_quantity, Recipes.material3_item, Recipes.material4_quantity, Recipes.material4_item, Recipes.material5_quantity, Recipes.material5_item, Recipes.type, Items.name, Items.hit_points, Items.power, Items.accuracy, Items.combat_advantage, Items.critical_strike, Items.critical_severity, Items.defense, Items.awareness, Items.critical_avoidance, Items.deflect, Items.deflect_severity, Items.forte, Items.control_bonus, Items.control_resist, Items.incoming_healing, Items.outgoing_healing, Items.action_point_gain, Items.recharge_speed, Items.movement_speed, Items.stamina_regen, Items.gold_bonus, Items.glory_bonus'
    local recipe_args = {
        join = 'Recipes.name = Items.name',
        where = 'Recipes.professions HOLDS LIKE "%' .. mw.ustring.lower(frame.args['профессия']) .. '%"',
        orderBy = 'Recipes.level, Recipes.name, Items.name',
    }

    if frame.args['тип'] ~= '' then
        recipe_args.where = recipe_args.where .. ' AND Recipes.type = "' .. mw.ustring.lower(frame.args['тип']) .. '"'
    end

    if frame.args['источник'] ~= '' then 
    	recipe_args.where = recipe_args.where .. ' AND Recipes.source HOLDS LIKE "%' .. frame.args['источник'] .. '%"'
    end

    local result = cargo.query( tables, fields, recipe_args)

    local tbl = mw.html.create('table')
	tbl:addClass('wikitable sortable jquery-tablesorter')
	tbl:tag("th"):wikitext("Предмет"):done()
	tbl:tag("th"):wikitext("Профессия(и)"):done()
    tbl:tag("th"):wikitext("Уровень"):done()
    tbl:tag("th"):wikitext("Результирующее кол-во"):done()
    tbl:tag("th"):wikitext("Материалы"):done()
	tbl:done()
    
	for _, row in ipairs(result) do
		tr = tbl:tag("tr"):attr('class', 'simpleCraftCalcRecipeBase')

        if mw.ustring.lower(frame.args['тип']) == 'набор усиления доспехов' then      
            for _, attrib in ipairs(attributes) do
                if row['Items.' .. attrib.fields_cargo] ~= nil then
                    tr:tag("td"):wikitext(item_icon.Main({args={row['Recipes.name'], ""}}) .. '<br><span style="font-size: 13px"><span class="green">На себе: </span><span class="slate">' .. attrib.name[1] .. '</span>: +' .. row['Items.' .. attrib.fields_cargo] .. '</span>'):done()
                end
            end
        else
            local source = {}
			if row['Recipes.source'] then
				for i in mw.text.gsplit(row['Recipes.source'], ",%s*") do
					table.insert(source, item_icon.Main({args={i, ""}}))
				end
			end

            tr:tag("td"):wikitext((row['Recipes.name'] and item_icon.Main({args={row['Recipes.name'], ""}}) or '') .. (row['Recipes.source'] and '<br><small>(Изучается из: ' .. table.concat(source, ",<br>") ..')</small>' or '')):done()
        end

		local text = {}
        for i in mw.text.gsplit(row['Recipes.professions'], ",%s*") do
			table.insert(text, professions[mw.ustring.lower(i)])
		end
            
        tr:tag("td"):attr('style', 'text-align: center'):wikitext(table.concat(text,' ')):done()
        tr:tag("td"):attr('style', 'text-align: center'):wikitext(row['Recipes.level']):done()

        local crafted_item_count = tonumber(row['Recipes.quantity']) or 1

		tr:tag("td"):wikitext('<span class="simpleCraftCalcResultCount" data-initial-count="'.. crafted_item_count .. '">' .. crafted_item_count .. '</span>'):done()
			
        local ingredients = {}
        for i = 1, 5 do
            local item = row['Recipes.material'..i..'_item']
            local quantity = row['Recipes.material'..i..'_quantity']
            if item ~= nil then
                table.insert(ingredients, '<div><span class="simpleCraftCalcIngredientCount" style="padding-right: 3px;" data-initial-count="'.. quantity .. '">' .. quantity .. '</span> ' .. item_icon.Main({args={item, ""}}) .. '</div>')

            end
        end
        tr:tag("td"):wikitext(table.concat(ingredients))

	end
	return tbl
end
return p
Advertisement