Shaleych (обсуждение | вклад) мНет описания правки |
Shaleych (обсуждение | вклад) мНет описания правки |
||
(не показано 67 промежуточных версий этого же участника) | |||
Строка 1: | Строка 1: | ||
− | local |
+ | local item_icon = require('Модуль:Item_icon') |
+ | local get_args = require('Модуль:Arguments').getArgs |
||
local p = {} |
local p = {} |
||
function p.Main( frame ) |
function p.Main( frame ) |
||
+ | local args = get_args(frame, {parentFirst = true}) |
||
local cargo = mw.ext.cargo |
local cargo = mw.ext.cargo |
||
− | tables = 'Cost, NPCs' |
+ | local tables = 'Cost, NPCs' |
− | fields = 'Cost.merchant,Cost.item,Cost.quality,Cost.quantity,Cost.cost__full,Cost._pageID,NPCs._pageName,NPCs.zone' |
+ | local fields = 'Cost.merchant, Cost.item, Cost.quality, Cost.quantity, Cost.cost__full, Cost.cost, Cost._pageID, NPCs._pageName, NPCs.zone, NPCs.region' |
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if frame.args['валюта'] ~= "" then |
if frame.args['валюта'] ~= "" then |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | itemORcost = 'Cost.item="' .. frame.args[1] .. '"' |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | tbl:tag("th"):wikitext("Стоимость"):done() |
||
⚫ | |||
− | local |
+ | local zones = { |
+ | ["Просторы Нортдарка"] = "Андердарк", |
||
⚫ | |||
+ | ["Мантол-Дерит"] = "Андердарк" |
||
⚫ | |||
⚫ | |||
− | --orderBy = args.orderby, |
||
} |
} |
||
⚫ | |||
⚫ | |||
− | + | for _, row in ipairs(result) do |
|
+ | local display = row["NPCs.zone"] ~= nil and '' or 'display: none;' |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | local tr = tbl:tag("tr") |
|
⚫ | |||
⚫ | |||
− | + | if frame.args['валюта'] ~= "" then |
|
− | + | tr:tag("td"):wikitext(item_icon.Main({args={row["Cost.item"],""}})):done() |
|
⚫ | |||
⚫ | |||
⚫ | |||
− | for _,row in ipairs(result) do |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | zone = '-' |
||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
+ | |||
⚫ | |||
+ | |||
+ | 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"):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 |
||
+ | |||
⚫ | |||
+ | |||
⚫ | |||
+ | |||
+ | local function queryPower(power_type) |
||
+ | local tables = 'Items' |
||
+ | local fields = 'name, quality' |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | 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 |
||
+ | if next(result) == nil then |
||
+ | local tr = tbl:tag("tr") |
||
⚫ | |||
+ | 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 |
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