Neverwinter Wiki
мНет описания правки
мНет описания правки
 
(не показано 109 промежуточных версий этого же участника)
Строка 1: Строка 1:
local itemIcon = require('Модуль:Item_icon')
+
local item_icon = require('Модуль:Item_icon')
  +
local get_args = require('Модуль:Arguments').getArgs
   
 
local p = {}
 
local p = {}
local cargo = mw.ext.cargo
 
   
 
function p.Main( frame )
 
function p.Main( frame )
local args = frame.args
+
local args = get_args(frame, {parentFirst = true})
local fieldstable = {
+
local cargo = mw.ext.cargo
"merchant",
+
local tables = 'Cost, NPCs'
  +
local fields = 'Cost.merchant, Cost.item, Cost.quality, Cost.quantity, Cost.cost__full, Cost.cost, Cost._pageID, NPCs._pageName, NPCs.zone, NPCs.region'
"item",
 
  +
local item_or_cost = frame.args['валюта'] ~= "" and 'cost HOLDS LIKE "%' .. frame.args['валюта'] .. '%"' or 'Cost.item="' .. frame.args[1] .. '"'
"quality",
 
"quantity",
+
local argst = {
  +
join = 'Cost.merchant = NPCs._pageName',
"cost__full",
 
"_pageID",
+
where = item_or_cost,
  +
}
}
 
local tables = 'Cost'
+
local result = cargo.query( tables, fields, argst )
local fields = table.concat(fieldstable,",")
 
 
local cargoquery = { where='item="' .. frame.args[1] .. '"', groupBy = "_pageID" , orderBy = args.orderby}
 
local result = mw.ext.cargo.query( tables, fields, cargoquery )
 
 
local r = result[1]
 
local r = result[1]
   
--Start the table
 
 
local tbl = mw.html.create('table')
 
local tbl = mw.html.create('table')
tbl:addClass('wikitable')
+
tbl:addClass('wikitable')
  +
tbl:tag("th"):attr('style', 'width: 15%'):wikitext("Торговец"):done()
 
 
if frame.args['валюта'] ~= "" then
tbl:tag("th"):attr('style', 'width: 12%'):wikitext("Область"):done()
 
tbl:tag("th"):attr('style', 'width: 20%'):wikitext("Стоимость"):done()
+
tbl:tag("th"):wikitext("Предмет"):done()
 
end
--if r['equip_power'] ~= "" then
 
--tbl:tag("th"):wikitext("Умение экипировки"):done()
+
tbl:tag("th"):wikitext("Торговец"):done()
 
tbl:tag("th"):wikitext("Область"):done()
--end
 
 
tbl:tag("th"):wikitext("Регион"):done()
--if r['combat_power'] ~= "" then
 
--tbl:tag("th"):wikitext("Боевое умение"):done()
+
tbl:tag("th"):wikitext("Стоимость"):done()
 
tbl:done()
--end
 
  +
tbl:done()
 
  +
local zones = {
--Construct the rows in the table
 
  +
["Просторы Нортдарка"] = "Андердарк",
for _,row in ipairs(result) do
 
  +
["Мантол-Дерит"] = "Андердарк"
tr = tbl:tag("tr")
 
  +
}
tr:tag("td"):wikitext('[[' .. row.merchant .. ']]'):done()
 
  +
tr:tag("td"):wikitext():done()
 
 
for _, row in ipairs(result) do
tr:tag("td"):wikitext(frame:expandTemplate{title = 'Валюта',args = {cost__full}}):done()
 
  +
local display = row["NPCs.zone"] ~= nil and '' or 'display: none;'
  +
local colspan = row["NPCs.zone"] ~= nil and 1 or 2
 
local tr = tbl:tag("tr")
 
 
if frame.args['валюта'] ~= "" then
  +
tr:tag("td"):wikitext(item_icon.Main({args={row["Cost.item"],""}})):done()
 
end
  +
 
tr:tag("td"):wikitext('[[' .. row["Cost.merchant"] .. ']]'):done()
  +
  +
if mw.ustring.find(row["Cost.cost__full"], "Милость Макоса" ) or mw.ustring.find(row["Cost.cost__full"], "Милость Эку") then
  +
tr:tag("td"):attr("colspan", colspan):wikitext('[[Затерянный город Ому]]'):done()
  +
elseif row["Cost.merchant"] == 'Базар чудес' then
  +
tr:tag("td"):wikitext('Протекторат'):done()
  +
else
  +
tr:tag("td"):attr("colspan", colspan):wikitext(row["NPCs.zone"] ~= nil and '[[' .. row["NPCs.zone"] .. ']]' or 'Магазин кампании'):done()
 
end
  +
  +
if zones[row["NPCs.region"]] then
  +
tr:tag("td"):attr('style', display):wikitext(zones[row["NPCs.region"]]):done()
  +
elseif mw.ustring.find(row["Cost.cost__full"], "Милость Макоса") or mw.ustring.find(row["Cost.cost__full"], "Милость Эку") then
 
tr:tag("td"):attr('style', display):wikitext('[[Чалт]]'):done()
  +
elseif row["Cost.merchant"] == 'Базар чудес' then
  +
tr:tag("td"):wikitext('Берег Мечей'):done()
  +
else
  +
tr:tag("td"):attr('style', display):wikitext(''):done()
  +
end
  +
 
tr:tag("td"):wikitext(frame:expandTemplate{title = 'Валюта', args = {row["Cost.cost__full"]}}):done()
  +
  +
local tr = tbl:tag("tr")
  +
  +
local function queryPower(power_type)
  +
local tables = 'Items'
  +
local fields = 'name, quality'
  +
local args = {
  +
where = 'name = "'.. power_type .. '"',
  +
}
  +
return cargo.query(tables, fields, args)[1]
  +
end
  +
  +
local result_current_title = queryPower(mw.title.getCurrentTitle().text)
  +
local result_frame_args = queryPower(frame.args[1])
  +
  +
if result_current_title["quality"] ~= result_frame_args["quality"] then
  +
tr:tag("td"):attr('colspan', 5):css('text-align', 'center'):wikitext('У торговца продается ' .. item_icon.Main({args={frame.args[1],""}}) .. ' <b>необычного</b> качества!'):done()
  +
end
  +
  +
end
  +
if next(result) == nil then
  +
local tr = tbl:tag("tr")
  +
if frame.args['валюта'] ~= "" then
  +
tr:tag("td"):attr('colspan', 5):wikitext('<span style="text-align: center">Нет товаров, которые можно купить за <b>' .. frame.args['валюта'] .. '.</b></span>'):done()
  +
else
  +
tr:tag("td"):attr('colspan', 4):wikitext('<span style="text-align: center">Этот предмет нигде не продается или еще не был добавлен в список товаров торговца.</span>'):done()
 
end
 
end
  +
  +
end
 
return tbl
 
return tbl
 
end
 
end

Текущая версия от 12:45, 20 января 2024

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

local item_icon = require('Модуль:Item_icon')
local get_args = require('Модуль:Arguments').getArgs

local p = {}

function p.Main( frame )
    local args = get_args(frame, {parentFirst = true})
    local cargo = mw.ext.cargo
    local tables = 'Cost, NPCs'
    local fields = 'Cost.merchant, Cost.item, Cost.quality, Cost.quantity, Cost.cost__full, Cost.cost, Cost._pageID, NPCs._pageName, NPCs.zone, NPCs.region'
    local item_or_cost = frame.args['валюта'] ~= "" and 'cost HOLDS LIKE "%' .. frame.args['валюта'] .. '%"' or 'Cost.item="' .. frame.args[1] .. '"'
    local argst = {
        join = 'Cost.merchant = NPCs._pageName',
        where = item_or_cost,
    }
    local result = cargo.query( tables, fields, argst )
    local r = result[1]

	local tbl = mw.html.create('table')
    tbl:addClass('wikitable')

    if frame.args['валюта'] ~= "" then
        tbl:tag("th"):wikitext("Предмет"):done()
    end
	tbl:tag("th"):wikitext("Торговец"):done()
	tbl:tag("th"):wikitext("Область"):done()
	tbl:tag("th"):wikitext("Регион"):done()			
	tbl:tag("th"):wikitext("Стоимость"):done()
	tbl:done()

    local zones = {
        ["Просторы Нортдарка"] = "Андердарк",
        ["Мантол-Дерит"] = "Андердарк"
    }

    for _, row in ipairs(result) do
    	local display = row["NPCs.zone"] ~= nil and '' or 'display: none;'
    	local colspan = row["NPCs.zone"] ~= nil and 1 or 2
        local tr = tbl:tag("tr")
        
        if frame.args['валюта'] ~= "" then
            tr:tag("td"):wikitext(item_icon.Main({args={row["Cost.item"],""}})):done()
        end
        
        tr:tag("td"):wikitext('[[' .. row["Cost.merchant"] .. ']]'):done()
        
        if mw.ustring.find(row["Cost.cost__full"], "Милость Макоса" ) or mw.ustring.find(row["Cost.cost__full"], "Милость Эку") then
        	tr:tag("td"):attr("colspan", colspan):wikitext('[[Затерянный город Ому]]'):done()
        elseif row["Cost.merchant"] == 'Базар чудес' then
    		tr:tag("td"):wikitext('Протекторат'):done()
        else
        	tr:tag("td"):attr("colspan", colspan):wikitext(row["NPCs.zone"] ~= nil and '[[' .. row["NPCs.zone"] .. ']]' or 'Магазин кампании'):done()
        end
        
        if zones[row["NPCs.region"]] then
        	tr:tag("td"):attr('style', display):wikitext(zones[row["NPCs.region"]]):done()
        elseif mw.ustring.find(row["Cost.cost__full"], "Милость Макоса") or mw.ustring.find(row["Cost.cost__full"], "Милость Эку") then
        	tr:tag("td"):attr('style', display):wikitext('[[Чалт]]'):done()
        elseif row["Cost.merchant"] == 'Базар чудес' then
    		tr:tag("td"):wikitext('Берег Мечей'):done()
        else
        	tr:tag("td"):attr('style', display):wikitext(''):done()	
        end
        
        tr:tag("td"):wikitext(frame:expandTemplate{title = 'Валюта', args = {row["Cost.cost__full"]}}):done()

        local tr = tbl:tag("tr")

		local function queryPower(power_type)
			local tables = 'Items'
			local fields = 'name, quality'
            local args = {
                where = 'name = "'.. power_type .. '"',
            }
			return cargo.query(tables, fields, args)[1]
		end

		local result_current_title = queryPower(mw.title.getCurrentTitle().text)
		local result_frame_args = queryPower(frame.args[1])

        if result_current_title["quality"] ~= result_frame_args["quality"] then
            tr:tag("td"):attr('colspan', 5):css('text-align', 'center'):wikitext('У торговца продается ' .. item_icon.Main({args={frame.args[1],""}}) .. ' <b>необычного</b> качества!'):done()
        end     

    end
    if next(result) == nil then
        local tr = tbl:tag("tr")
        if frame.args['валюта'] ~= "" then
            tr:tag("td"):attr('colspan', 5):wikitext('<span style="text-align: center">Нет товаров, которые можно купить за <b>' .. frame.args['валюта'] .. '.</b></span>'):done()
        else
            tr:tag("td"):attr('colspan', 4):wikitext('<span style="text-align: center">Этот предмет нигде не продается или еще не был добавлен в список товаров торговца.</span>'):done()
        end
            
    end
	return tbl
end
return p