Модуль:Prototypes/Роль/Лодаут: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
Строка 6: | Строка 6: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame.args | |||
local searchKey = args[1] | |||
local roleParam = args[2] | |||
if not roleParam then | |||
return '<div class="role">Параметр roleId не указан</div>' | |||
end | |||
local roleId = "Job" .. roleParam | |||
local results = {} | |||
local role = nil | |||
for _, r in ipairs(gearRoleLoadout) do | |||
if r.id == roleId then | |||
role = r | |||
break | |||
end | |||
end | |||
if not role then | |||
return '<div class="role">Роль с id "' .. roleId .. '" не найдена</div>' | |||
end | |||
for _, groupId in ipairs(role.groups or {}) do | |||
local group = nil | |||
for _, g in ipairs(gearloadoutGroup) do | |||
if g.id == groupId then | |||
group = g | |||
break | |||
end | |||
end | |||
if group then | |||
for _, loadoutId in ipairs(group.loadouts or {}) do | |||
local loadout = nil | |||
for _, l in ipairs(gearloadout) do | |||
if l.id == loadoutId then | |||
loadout = l | |||
break | |||
end | |||
end | |||
if loadout and loadout.equipment then | |||
local eqValue = loadout.equipment[searchKey] | |||
if eqValue then | |||
local extraInfo = "" | |||
if loadout.effects then | |||
for _, effect in ipairs(loadout.effects) do | |||
if effect["!type"] == "GroupLoadoutEffect" then | |||
local proto = effect.proto | |||
if proto then | |||
for _, candidate in ipairs(gearloadout) do | |||
if candidate.id == proto then | |||
if candidate.effects then | |||
for _, eff in ipairs(candidate.effects) do | |||
if eff["!type"] == "JobRequirementLoadoutEffect" and eff.requirement then | |||
local req = eff.requirement | |||
if req["!type"] == "DepartmentTimeRequirement" and req.department and req.time then | |||
extraInfo = extraInfo .. req.department .. ": " .. req.time .. "<br>" | |||
elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then | |||
extraInfo = extraInfo .. req.role .. ": " .. req.time .. "<br>" | |||
end | |||
end | |||
end | |||
end | |||
break | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end | |||
table.insert(results, extraInfo .. eqValue) | |||
end | |||
end | |||
end | |||
end | |||
end | |||
local output = {} | |||
for _, eq in ipairs(results) do | |||
table.insert(output, '<div class="role">' .. eq .. '</div>') | |||
end | |||
return table.concat(output, "\n") | |||
end | end | ||
return p | return p |
Версия от 20:47, 13 февраля 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Роль/Лодаут/doc
local p = {}
local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
function p.main(frame)
local args = frame.args
local searchKey = args[1]
local roleParam = args[2]
if not roleParam then
return '<div class="role">Параметр roleId не указан</div>'
end
local roleId = "Job" .. roleParam
local results = {}
local role = nil
for _, r in ipairs(gearRoleLoadout) do
if r.id == roleId then
role = r
break
end
end
if not role then
return '<div class="role">Роль с id "' .. roleId .. '" не найдена</div>'
end
for _, groupId in ipairs(role.groups or {}) do
local group = nil
for _, g in ipairs(gearloadoutGroup) do
if g.id == groupId then
group = g
break
end
end
if group then
for _, loadoutId in ipairs(group.loadouts or {}) do
local loadout = nil
for _, l in ipairs(gearloadout) do
if l.id == loadoutId then
loadout = l
break
end
end
if loadout and loadout.equipment then
local eqValue = loadout.equipment[searchKey]
if eqValue then
local extraInfo = ""
if loadout.effects then
for _, effect in ipairs(loadout.effects) do
if effect["!type"] == "GroupLoadoutEffect" then
local proto = effect.proto
if proto then
for _, candidate in ipairs(gearloadout) do
if candidate.id == proto then
if candidate.effects then
for _, eff in ipairs(candidate.effects) do
if eff["!type"] == "JobRequirementLoadoutEffect" and eff.requirement then
local req = eff.requirement
if req["!type"] == "DepartmentTimeRequirement" and req.department and req.time then
extraInfo = extraInfo .. req.department .. ": " .. req.time .. "<br>"
elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then
extraInfo = extraInfo .. req.role .. ": " .. req.time .. "<br>"
end
end
end
end
break
end
end
end
end
end
end
table.insert(results, extraInfo .. eqValue)
end
end
end
end
end
local output = {}
for _, eq in ipairs(results) do
table.insert(output, '<div class="role">' .. eq .. '</div>')
end
return table.concat(output, "\n")
end
return p