Модуль:Prototypes/Роль/Экипировка: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показаны 42 промежуточные версии этого же участника) | |||
| Строка 1: | Строка 1: | ||
local jobData = mw.loadData("Модуль:IanComradeBot/job.json/data") | |||
local jobData = mw.loadData("Модуль:IanComradeBot/job.json/data") | local gearData = mw.loadData("Модуль:IanComradeBot/startingGear.json/data") | ||
local gearData = mw.loadData("Модуль:IanComradeBot/startingGear.json/data").data | local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data") | ||
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") | local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") | ||
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") | local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") | ||
local p = {} | local p = {} | ||
-- | -- Поиск записи по id в массиве | ||
local function findById(tbl, id) | local function findById(tbl, id) | ||
for | if type(tbl) ~= "table" then return nil end | ||
if | for _, v in ipairs(tbl) do | ||
if v.id == id then | |||
return v | return v | ||
end | end | ||
| Строка 17: | Строка 18: | ||
end | end | ||
-- | -- Преобразование первой буквы в заглавную | ||
local function capitalizeFirst(str) | local function capitalizeFirst(str) | ||
if not str or str == "" then return "" end | |||
return str:sub(1,1):upper() .. str:sub(2) | return str:sub(1,1):upper() .. str:sub(2) | ||
end | |||
-- Формирование вывода предмета | |||
local function buildResult(itemId, sourceGear, slot) | |||
if slot == "back" and sourceGear.storage and sourceGear.storage.back then | |||
local storageBack = "" | |||
for _, storageItem in ipairs(sourceGear.storage.back) do | |||
storageBack = storageBack .. string.format("{{Предмет|wrapper=1|repository=1|%s}}", storageItem) | |||
end | |||
return string.format("<div>{{Предмет|%s|repository=1|size=64px|label=|imageTooltip=1}} {{СollapsibleMenu|%s}}</div>", itemId, storageBack) | |||
else | |||
return string.format("{{Предмет|%s|repository=1|size=64px|label=|imageTooltip=1}}", itemId) | |||
end | |||
end | |||
-- Обработка в режиме radio | |||
local function processResult(itemId, result, radioMode, frame) | |||
if radioMode then | |||
return frame:preprocess(string.format("{{#invoke:Prototypes/Механика/Частоты|main|%s}}", itemId)) | |||
else | |||
return frame:preprocess(result) | |||
end | |||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame.args | local args = frame.args | ||
local | local param = mw.text.trim(args[1] or "") | ||
local | local idParam = mw.text.trim(args[2] or "") | ||
if param == "" or idParam == "" then | |||
if | return "Ошибка: Не заданы необходимые параметры. Используйте: {{#invoke:Прототип/Роль/Экипировка|main|<slot/special/radio>|<jobId или startingGearId>}}" | ||
return "Ошибка: Не заданы необходимые параметры. Используйте: {{#invoke: | |||
end | end | ||
-- | -- Режим special: импланты | ||
local job = findById(jobData, | if param == "special" then | ||
local job = findById(jobData, capitalizeFirst(idParam)) | |||
if not job then return "" end | |||
local specials = job.special or {} | |||
local implantsList = {} | |||
for _, special in ipairs(specials) do | |||
if special["!type"] == "AddImplantSpecial" and special.implants then | |||
for _, implant in ipairs(special.implants) do | |||
table.insert(implantsList, string.format("{{#invoke:Entity Lookup|getname|%s}}", implant)) | |||
end | |||
end | |||
end | |||
if #implantsList > 0 then | |||
return frame:preprocess(table.concat(implantsList, ", ")) | |||
else | |||
return "" | |||
end | |||
end | end | ||
local radioMode = false | |||
local | local slot = param | ||
if | if param == "radio" then | ||
radioMode = true | |||
slot = "ears" | |||
end | end | ||
local itemId = "" | |||
local | local sourceGear = nil | ||
local | -- Пытаемся найти запись в roleLoadout | ||
local roleLoadoutId = "Job" .. capitalizeFirst(idParam) | |||
local roleLoadoutData = findById(gearRoleLoadout, roleLoadoutId) | |||
-- | if not roleLoadoutData then | ||
-- Нет групповых лоадаутов: сначала пробуем ручной ввод gearId | |||
local gear = findById(gearData, idParam) | |||
if gear then | |||
-- ручной режим: idParam — это startingGearId | |||
local gearEquipment = gear.equipment or {} | |||
local | itemId = gearEquipment[slot] or "" | ||
local | sourceGear = gear | ||
if | else | ||
local | -- fallback: берём startingGear из job | ||
local | local job = findById(jobData, capitalizeFirst(idParam)) | ||
if not job or not job.startingGear then | |||
return "Ошибка: не найдена экипировка или должность с id " .. idParam | |||
end | |||
local gear2 = findById(gearData, job.startingGear) | |||
if not gear2 then | |||
return "Ошибка: не найдена экипировка с id " .. job.startingGear | |||
end | |||
local gearEquipment2 = gear2.equipment or {} | |||
itemId = gearEquipment2[slot] or "" | |||
sourceGear = gear2 | |||
end | |||
else | |||
-- Есть групповые лоадауты: классический режим через roleLoadout | |||
local jobId = capitalizeFirst(idParam) | |||
local job = findById(jobData, jobId) | |||
if not job then | |||
return "Ошибка: не найдена должность с id " .. jobId | |||
end | |||
local gearId = job.startingGear | |||
if not gearId then | |||
return "Ошибка: у должности с id " .. jobId .. " не указан startingGear" | |||
end | |||
local gear = findById(gearData, gearId) | |||
if not gear then | |||
return "Ошибка: не найдена экипировка с id " .. gearId | |||
end | |||
local gearEquipment = gear.equipment or {} | |||
itemId = gearEquipment[slot] or "" | |||
sourceGear = gear | |||
if itemId == "" then | |||
for _, groupId in ipairs(roleLoadoutData.groups or {}) do | |||
if groupId ~= "Trinkets" then | |||
local group = findById(gearloadoutGroup, groupId) | |||
if group and type(group.loadouts) == "table" then | |||
for _, loadoutID in ipairs(group.loadouts) do | |||
local loadout = findById(gearloadout, loadoutID) | |||
if loadout and not loadout.effects and loadout.equipment and loadout.equipment[slot] then | |||
itemId = loadout.equipment[slot] | |||
sourceGear = loadout | |||
break | |||
end | |||
end | |||
end | |||
end | |||
if itemId ~= "" then break end | |||
end | end | ||
end | end | ||
end | end | ||
if itemId == "" then | if itemId == "" then | ||
return "" | return "" | ||
end | end | ||
local result = buildResult(itemId, sourceGear, slot) | |||
return processResult(itemId, result, radioMode, frame) | |||
end | end | ||
return p | return p | ||