Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 17: | Строка 17: | ||
local materialData = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data") | local materialData = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data") | ||
local chemDataLathe = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data") | local chemDataLathe = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data") | ||
local vendingMachinesData = mw.loadData("Модуль:IanComradeBot/prototypes/vending machines.json/data") | |||
local inventoriesData = mw.loadData("Модуль:IanComradeBot/prototypes/vending machines/inventories.json/data") | |||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
| Строка 255: | Строка 257: | ||
return "Найденные станки: " .. table.concat(matchingLathes, ", ") | return "Найденные станки: " .. table.concat(matchingLathes, ", ") | ||
end | |||
--------------------------------------------------------------------- | |||
-- Обратный поиск в торговых автоматах по содержимому инвентаря | |||
--------------------------------------------------------------------- | |||
function p.reverseVending(frame) | |||
local invMode = frame.args[2] or "" -- режим поиска: "inventory", "contraband", "emag" или пустая строка для всех | |||
local targetId = frame.args[3] | |||
if not targetId or targetId == "" then | |||
return "Ошибка: не указан id предмета для обратного поиска в торговых автоматах." | |||
end | |||
local matchingInventoryIds = {} | |||
-- Перебираем все инвентарные записи | |||
for _, inventory in pairs(inventoriesData) do | |||
if inventory.id then | |||
local found = false | |||
-- Если режим не указан, ищем во всех типах инвентарей | |||
if (invMode == "inventory" or invMode == "" or not invMode) and inventory.startingInventory and type(inventory.startingInventory) == "table" then | |||
if inventory.startingInventory[targetId] then | |||
found = true | |||
end | |||
end | |||
if (invMode == "contraband" or invMode == "" or not invMode) and inventory.contrabandInventory and type(inventory.contrabandInventory) == "table" then | |||
if inventory.contrabandInventory[targetId] then | |||
found = true | |||
end | |||
end | |||
if (invMode == "emag" or invMode == "" or not invMode) and inventory.emaggedInventory and type(inventory.emaggedInventory) == "table" then | |||
if inventory.emaggedInventory[targetId] then | |||
found = true | |||
end | |||
end | |||
if found then | |||
table.insert(matchingInventoryIds, inventory.id) | |||
end | |||
end | |||
end | |||
if #matchingInventoryIds == 0 then | |||
return "Предмет с id " .. targetId .. " не найден ни в одном инвентаре." | |||
end | |||
local matchingVendingMachines = {} | |||
-- Поиск торговых автоматов, у которых поле VendingMachine.pack совпадает с id найденного инвентаря | |||
for _, vm in pairs(vendingMachinesData) do | |||
if vm.VendingMachine and vm.VendingMachine.pack then | |||
local packId = vm.VendingMachine.pack | |||
for _, invId in ipairs(matchingInventoryIds) do | |||
if packId == invId then | |||
if vm.id then | |||
table.insert(matchingVendingMachines, vm.id) | |||
end | |||
break | |||
end | |||
end | |||
end | |||
end | |||
if #matchingVendingMachines == 0 then | |||
return "Не найден торговый автомат, содержащий предмет с id " .. targetId .. "." | |||
end | |||
return "Торговые автоматы, содержащие предмет " .. targetId .. ": " .. table.concat(matchingVendingMachines, ", ") | |||
end | end | ||
| Строка 277: | Строка 343: | ||
elseif mode == "reverseLathe" then | elseif mode == "reverseLathe" then | ||
return p.reverseLathe(frame) | return p.reverseLathe(frame) | ||
elseif mode == "reverseVending" then | |||
return p.reverseVending(frame) | |||
else | else | ||
return "Неизвестный режим: " .. mode .. ". Доступные режимы: reverseContained, reverseEquipment, reverseCargo, reverseLathe." | return "Неизвестный режим: " .. mode .. ". Доступные режимы: reverseContained, reverseEquipment, reverseCargo, reverseLathe." | ||