Advertisement
vx13

OpenComputers Crafter

Sep 20th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.83 KB | None | 0 0
  1. -- Robocraft version 0.10.8
  2. -- Public Domain
  3. local version = "0.10.8"
  4. local math = require("math")
  5. local shell = require("shell")
  6. local serialization = require("serialization")
  7. local fs = require("filesystem")
  8. local sides = require("sides")
  9. local robot = require("robot")
  10. local component= require("component")
  11. -- Безопасная подгрузка компонентов
  12. local function safeLoadComponents(name)
  13.   if component.isAvailable(name) then
  14.     return component.getPrimary(name)
  15.   else
  16.     return nil, 'ERROR! Компонент '..name..' не найден!'
  17.   end
  18. end
  19. local inv = safeLoadComponents("inventory_controller")
  20. local crafting = safeLoadComponents("crafting")
  21. local database = safeLoadComponents("database")
  22.  
  23. if inv == nil then
  24.   print("Ошибка! Нет улучшения «Контроллер инвентаря».")
  25.   os.exit(1)
  26. end
  27.  
  28. if crafting == nil then
  29.   print("Ошибка! Нет улучшения «Верстак».")
  30.   os.exit(1)
  31. end
  32.  
  33. if database == nil then
  34.   print("Ошибка! Нет улучшения «База данных».")
  35.   os.exit(1)
  36. end
  37.  
  38. local args, options = shell.parse(...)
  39.  
  40. local BASE_DIR = shell.getWorkingDirectory()
  41.  
  42. local STORAGE_SIDE = sides.forward
  43. RESULT_SLOT = 4
  44.  
  45. function printf(s, ...)
  46.   return io.write(s:format(...))
  47. end
  48.  
  49. function sprintf(s, ...)
  50.   return s:format(...)
  51. end
  52.  
  53. function gridSlot(slot)
  54.   if slot <= 3 then
  55.     return slot
  56.   elseif slot <=6 then
  57.     return slot + 1
  58.   elseif slot <=9 then
  59.     return slot +2
  60.   end
  61. end
  62.  
  63. function loadFile(fn)
  64.     local _err = function(err)
  65.       return nil, sprintf("Не могу загрузить файл <%s> (%s)", fn, err)
  66.     end
  67.     local f, err = io.open(fn, "rb")
  68.     if err ~= nil then return _err(err) end
  69.     local content, err = f:read("*all")
  70.     if err ~= nil then return _err(err) end
  71.     local _, err = f:close()
  72.     if err ~= nil then return _err(err) end
  73.     return content
  74. end
  75.  
  76. function saveFile(fn, data)
  77.   local _err = function(err)
  78.       return nil, sprintf("Не могу сохранить файл <%s> (%s)", fn, err)
  79.     end
  80.   local f, err = io.open(fn, "wb")
  81.   if err ~= nil then return _err(err) end
  82.   local _, err = f:write(data)
  83.   if err ~= nil then return _err(err) end
  84.   local _, err = f:close()
  85.   if err ~= nil then return _err(err) end
  86. end
  87.  
  88. do
  89.   local databaseSlot = 1
  90.  
  91.   itemdb = { }
  92.   local items = { }
  93.   local itemsDir = fs.concat(BASE_DIR, "itemdb2")
  94.   local itemsDirOld = fs.concat(BASE_DIR, "itemdb")
  95.  
  96.   local function convert()
  97.     local function loadItem(itemHash)
  98.       local fn = fs.concat(itemsDirOld, itemHash)
  99.       if fs.exists(fn) then
  100.         local raw, err = loadFile(fn)
  101.         if err ~= nil then
  102.           printf("Ошибка! Не могу загрузить информацию о предмете <%s> (%s).\n",
  103.             itemHash, err)
  104.           os.exit(1)
  105.         end
  106.         return serialization.unserialize(raw)
  107.       end
  108.     end
  109.     local function makeId(item)
  110.       local id = item.name
  111.       if item.maxDamage > 0 then
  112.         return id
  113.       end
  114.       id = id.."@"..item.damage
  115.       return id
  116.     end
  117.     local function hashToId(hash)
  118.       local item = loadItem(hash)
  119.       return makeId(item)
  120.     end
  121.     for name in fs.list(itemsDirOld) do
  122.       local item = loadItem(name)  
  123.       local item2 = { }
  124.       for key, v in pairs(item) do
  125.         if key == "recipe" then
  126.           item2.recipe = { n = item.recipe.n, grid = { } }
  127.           for slot, hash in pairs(item.recipe.grid) do
  128.             item2.recipe.grid[slot] = hashToId(hash)
  129.           end
  130.         elseif key == "hash" or key == "aspects" then
  131.         else
  132.           item2[key] = v
  133.         end
  134.       end
  135.       item2.id = makeId(item2)
  136.       item2.changed = true
  137.       itemdb.saveItem(item2)
  138.     end
  139.     for name in fs.list(BASE_DIR) do
  140.       local hash, err = loadFile(name)
  141.       if hash and string.len(hash) == 64 then
  142.         saveFile(name, hashToId(hash))
  143.       end
  144.     end
  145.   end
  146.  
  147.   local function init( ... )
  148.     if not fs.exists(itemsDir) then
  149.       local ok, err = fs.makeDirectory(itemsDir)
  150.       if err ~= nil then
  151.         printf("Ошибка! Не могу создать каталог для бд предметов (%s).", err)
  152.         os.exit(1)
  153.       end
  154.       if fs.exists(itemsDirOld) then
  155.         convert()
  156.       end
  157.     end
  158.   end
  159.  
  160.   function itemdb.flush()
  161.     for itemId, item in pairs(items) do
  162.       if item.changed then
  163.         print("Обновлён:", item.label, item.id)
  164.         if not itemdb.saveItem(item) then
  165.           return false
  166.         end
  167.         itemdb.makeLabel(item)
  168.       end
  169.     end
  170.     return true
  171.   end
  172.  
  173.   local function fixFileName(fn)
  174.     local fn = string.gsub(fn, '[ <>:"/\\|?*]', "_")
  175.     return fn
  176.   end
  177.  
  178.   function itemdb.loadItem(itemId)
  179.     local fn = fs.concat(itemsDir, fixFileName(itemId))
  180.     if fs.exists(fn) then
  181.       local raw, err = loadFile(fn)
  182.       if err ~= nil then
  183.         printf("Ошибка! Не могу загрузить информацию о предмете <%s> (%s).\n",
  184.           itemId, err)
  185.         os.exit(1)
  186.       end
  187.       return serialization.unserialize(raw)
  188.     end
  189.   end
  190.  
  191.   function itemdb.saveItem(item)
  192.     if item.changed then
  193.       local fn = fs.concat(itemsDir, fixFileName(item.id))
  194.       print(fn)
  195.       item.changed = nil --TODO use xpcall
  196.       local err = saveFile(fn, serialization.serialize(item))
  197.       if err then
  198.         item.changed = true
  199.         printf("Ошибка! Не могу сохранить информацию о предмете <%s> (%s).\n",
  200.             itemId, err)
  201.         return false
  202.       end
  203.     end
  204.     return true
  205.   end
  206.  
  207.   local function computeId(stack)
  208.     local id = stack.name
  209.     if stack.maxDamage > 0 then
  210.       return id
  211.     end
  212.     id = id.."@"..stack.damage
  213.     return id
  214.   end
  215.  
  216.   local function get(stack)
  217.     local itemId = computeId(stack)
  218.     local item = items[itemId]
  219.     if item == nil then
  220.       item = itemdb.loadItem(itemId)
  221.       if item == nil then
  222.         item = stack
  223.         item.tag = nil
  224.         item.size = nil
  225.         item.charge = nil
  226.         item.aspects = nil --useless thaumcraft info
  227.         item.id = itemId
  228.         item.changed = true
  229.       end
  230.       items[itemId] = item
  231.     end
  232.     return item
  233.   end
  234.  
  235.   function itemdb.storeInternal(slot)
  236.     local stack = inv.getStackInInternalSlot(slot)
  237.     if not stack then return nil end
  238.     return get(stack)
  239.   end
  240.  
  241.   function itemdb.store(slot)
  242.     local stack = inv.getStackInSlot(STORAGE_SIDE, slot)
  243.     if not stack then return nil end
  244.     return get(stack)
  245.   end
  246.  
  247.   function itemdb.get(itemId)
  248.     local item = items[itemId]
  249.     if item == nil then
  250.       item = itemdb.loadItem(itemId)
  251.       if item ~= nil then
  252.         items[itemId] = item
  253.       end
  254.     end
  255.     return item
  256.   end
  257.  
  258.   function itemdb.all()
  259.     return items
  260.   end
  261.  
  262.   local function makeLabelFileName(item)
  263.     local fn = fixFileName(item.label)
  264.     fn = fs.concat(BASE_DIR, fn)
  265.     return fn
  266.   end
  267.  
  268.   function itemdb.makeLabel(item)
  269.     local fn = makeLabelFileName(item)
  270.     local w = true
  271.     if fs.exists(fn) then
  272.       local itemId, err = loadFile(fn)
  273.       if err ~= nil then
  274.         print(err)
  275.         os.exit(1)
  276.       end
  277.       local currentItem = itemdb.loadItem(itemId)
  278.       w = currentItem.recipe == nil or item.recipe ~= nil
  279.     end
  280.     if w then
  281.       saveFile(fn, tostring(item.id))
  282.     end
  283.   end
  284.  
  285.   function itemdb.makeAllLabels()
  286.     for name in fs.list(itemsDir) do
  287.       local item = itemdb.loadItem(name)  
  288.       itemdb.makeLabel(item)
  289.     end
  290.   end
  291.  
  292.   function itemdb.printReport()
  293.     for name in fs.list(itemsDir) do
  294.       local item = itemdb.loadItem(name)
  295.       local m = ""
  296.       if item.recipe ~= nil then
  297.         m = "!"
  298.       end
  299.       printf("%s%s/%s", m, string.sub(item.id, 1, 6), item.label)
  300.     end
  301.   end
  302.  
  303.   function itemdb.computeHash(slot)
  304.     inv.store(STORAGE_SIDE, slot, database.address, databaseSlot)
  305.     return database.computeHash(databaseSlot)
  306.   end
  307.  
  308.   function itemdb.computeHashInternal(slot)
  309.     inv.storeInternal(slot, database.address, databaseSlot)
  310.     return database.computeHash(databaseSlot)
  311.   end
  312.  
  313.   init()
  314. end
  315.  
  316. do
  317.   storage = {}
  318.   local db
  319.  
  320.   local storageFn = fs.concat(BASE_DIR, "storage2.db")
  321.  
  322.   function storage.load()
  323.     if fs.exists(storageFn) then
  324.       local raw, err = loadFile(storageFn)
  325.       db = serialization.unserialize(raw)
  326.       if err ~= nil then
  327.         printf("Ошибка! Не могу загрузить бд хранилища (%s).\n", err)
  328.         os.exit(1)
  329.       end
  330.     end
  331.     if db == nil then db = {freeSlots = {}} end
  332.   end
  333.  
  334.   function storage.save()
  335.     if not itemdb.flush() then
  336.       print("бд предметов не сохранена. Невозможно сохоанить бд хранилища")
  337.       return
  338.     end
  339.     local err = saveFile(storageFn, serialization.serialize(db))
  340.     if err ~= nil then
  341.       printf("Ошибка! Не могу сохранить бд хранилища (%s).\n", err)
  342.     end
  343.   end
  344.  
  345.   local function addStack(slot)
  346.     local item = itemdb.store(slot)
  347.     local hash = itemdb.computeHash(slot)
  348.     local stacks = db[item.id]
  349.     if stacks == nil then
  350.       stacks = { slots = { }, size = 0 }
  351.       db[item.id] = stacks
  352.     end
  353.     local stackSize = inv.getSlotStackSize(STORAGE_SIDE, slot)
  354.     stacks.size = stacks.size + stackSize
  355.     stacks.slots[slot] = { size = stackSize, hash = hash }
  356.     db.freeSlots[slot] = nil
  357.   end
  358.  
  359.   function storage.scanInventory()
  360.     db = {freeSlots = {}}
  361.     local size, err = inv.getInventorySize(STORAGE_SIDE)
  362.     if not size then
  363.       print("Ошибка! Нет сундука ("..err..").")
  364.       os.exit(1)
  365.     end
  366.     for slot = 1, size, 1 do
  367.       if inv.getSlotStackSize(STORAGE_SIDE, slot) > 0 then
  368.         addStack(slot)
  369.       else
  370.         db.freeSlots[slot] = true
  371.       end
  372.     end
  373.   end
  374.  
  375.   function storage.count(itemId)
  376.     assert(type(itemId)=="string")
  377.     local stacks = db[itemId]
  378.     if stacks == nil then return 0 end
  379.     return stacks.size
  380.   end
  381.  
  382.   function storage.xcount(itemId)
  383.     assert(type(itemId)=="string")
  384.     local stacks = db[itemId]
  385.     if stacks == nil then return 0 end
  386.     local counts = { }
  387.     for slot, stack in pairs(stacks.slots) do
  388.       counts[stack.hash] = (counts[stack.hash] or 0) +  stack.size
  389.     end
  390.     return stacks.size, counts
  391.   end
  392.  
  393.   local function checkSlot(slot, itemId, stackSize)
  394.     if itemId ~= nil then
  395.       local item = itemdb.store(slot)
  396.     end
  397.     if (item ~= nil and itemId ~= item.id)
  398.       or inv.getSlotStackSize(STORAGE_SIDE, slot) ~= stackSize then
  399.       print("Данные о хранилище устарели.")
  400.       print("Останов.")
  401.       os.exit(1)
  402.     end
  403.   end
  404.  
  405.   function storage.suckStack(itemId, count)
  406.     if count == 0 then
  407.       return true
  408.     end
  409.     local hash
  410.     if robot.count() > 0 then
  411.       hash = itemdb.computeHashInternal(robot.select())
  412.     end
  413.     local item = itemdb.get(itemId)
  414.     if count > item.maxSize then
  415.       return false
  416.     end
  417.     local stacks = db[itemId]
  418.     if stacks == nil then
  419.       return false
  420.     end
  421.     local countS = count
  422.     for slot, stack in pairs(stacks.slots) do
  423.       checkSlot(slot, itemId, stack.size)
  424.       if not hash or (hash == stack.hash) then
  425.         if not hash then hash = stack.hash end
  426.         local take = count
  427.         if take > stack.size then
  428.           take = stack.size
  429.         end
  430.         local internalStack = inv.getStackInInternalSlot(robot.select())
  431.         if internalStack and (take + internalStack.size > internalStack.maxSize) then
  432.           take = internalStack.maxSize - internalStack.size
  433.         end
  434.         inv.suckFromSlot(STORAGE_SIDE, slot, take)
  435.         stacks.size = stacks.size - take;
  436.         stack.size = stack.size - take;
  437.         if stack.size == 0 then
  438.           stacks.slots[slot] = nil
  439.           db.freeSlots[slot] = true
  440.         end
  441.         if stacks.size == 0 then
  442.           db[itemId] = nil
  443.         end
  444.         count = count - take
  445.         if count == 0 then
  446.           break
  447.         end
  448.       end
  449.     end
  450.     return (count == 0), countS - count
  451.   end
  452.  
  453.   function storage.dropStack(count)
  454.     local droppedStack = inv.getStackInInternalSlot(robot.select())
  455.     if droppedStack == nil then
  456.       return false
  457.     end
  458.     if count == nil then
  459.       count = droppedStack.size
  460.     end
  461.     if count > droppedStack.size then
  462.       return false
  463.     end
  464.     local item = itemdb.storeInternal(robot.select())
  465.     local hash = itemdb.computeHashInternal(robot.select())
  466.     local stacks = db[item.id]
  467.     if stacks ~= nil then
  468.       for slot, stack in pairs(stacks.slots) do
  469.         checkSlot(slot, item.id, stack.size)
  470.         if hash == stack.hash then
  471.           local free = item.maxSize - stack.size
  472.           local n = count
  473.           if n > free then
  474.             n = free
  475.           end
  476.           if n > 0 then
  477.             inv.dropIntoSlot(STORAGE_SIDE, slot, n)
  478.             stacks.size = stacks.size + n
  479.             stack.size = stack.size + n
  480.             count = count - n
  481.           end
  482.           if count == 0 then
  483.             return true
  484.           end
  485.         end
  486.       end
  487.     end
  488.    
  489.     for slot, _ in pairs(db.freeSlots) do
  490.       checkSlot(slot, nil, 0)
  491.       inv.dropIntoSlot(STORAGE_SIDE, slot)
  492.       addStack(slot)
  493.       return true
  494.     end
  495.  
  496.     print("Нет места в хранилище")
  497.     print("Останов.")
  498.     os.exit(1)
  499.   end
  500.  
  501.   function storage.printReport()
  502.     for id, st in pairs(db) do
  503.       local item = itemdb.get(id)
  504.       if item ~= nil then
  505.         print(item.label, st.size)
  506.       end
  507.     end
  508.   end
  509.  
  510. end
  511.  
  512. local deep = 0
  513. function recursiveCraft(requestedItem, requestedCount)
  514.   deep = deep + 1
  515.   printf("(%d) Крафт <%s * %d>:\n", deep, requestedItem.label, requestedCount)
  516.   local recipe = requestedItem.recipe
  517.   if recipe == nil then
  518.     printf("(%d) Невозможно выполнить крафт. Нет рецепта для <%s>\n",
  519.       deep, requestedItem.label)
  520.     return false
  521.   end
  522.   local items = countRecipeItems(recipe)
  523.   local n = math.ceil(requestedCount / recipe.n)
  524.   --подсчёт кол-ва необходимых ресурсов и крафт недостающих
  525.   ::recount::
  526.   local maxSize = math.min(n, requestedItem.maxSize, math.floor(64 / recipe.n))
  527.   local ok = true
  528.   printf("(%d) Подсчёт ресурсов.\n", deep)
  529.   for itemId, nStacks in pairs(items) do
  530.     local item = itemdb.get(itemId)
  531.     local nedded = nStacks * n
  532.     local itemCount, byHash = storage.xcount(itemId)
  533.     if itemCount < nedded  then
  534.       printf("(%d) Нехватает <%s * %d>\n", deep,
  535.         item.label, nedded - itemCount)
  536.       if not recursiveCraft(item, nedded - itemCount) then
  537.           ok = false
  538.           break
  539.       end
  540.       goto recount
  541.     end
  542.     if #byHash > 1 then
  543.       maxSize = 1
  544.     end
  545.     maxSize = math.min(item.maxSize, maxSize)
  546.   end
  547.   if ok then
  548.     printf("(%d) Выполняю крафт.\n", deep)
  549.     ok = craft(requestedItem, n, maxSize, recipe.grid)
  550.     if ok then
  551.       storage.dropStack()
  552.       printf("(%d) Крафт завершён.\n", deep)
  553.     else
  554.       printf("(%d) Ошибка крафта.\n", deep)
  555.     end
  556.   end
  557.   deep = deep - 1
  558.   return ok
  559. end
  560.  
  561. function craft(requestedItem, inCount, maxSize, grid)
  562.   local inStep = maxSize
  563.   while inCount > 0 do
  564.     local n = inStep
  565.     if inCount < n then
  566.       n = inCount
  567.     end
  568.     for i = 1, 9, 1 do
  569.       local itemId = grid[i]
  570.       if itemId ~= nil then
  571.         robot.select(gridSlot(i))
  572.         if not storage.suckStack(itemId, n) then
  573.           print("Не могу положить предмет в сетку крафта.")
  574.           return false
  575.         end
  576.       end
  577.     end
  578.     robot.select(RESULT_SLOT)
  579.     if robot.count() > 0 then
  580.       storage.dropStack()
  581.     end
  582.     if not crafting.craft() then
  583.       return false
  584.     end
  585.     inCount = inCount - n
  586.   end
  587.   return true
  588. end
  589.  
  590. function countRecipeItems(recipe)
  591.   local counts = {}
  592.   for i = 1, 9, 1 do
  593.     local id = recipe.grid[i]
  594.     if id ~= nil then
  595.       local cnt = counts[id]
  596.       if cnt == nil then
  597.         cnt = 0
  598.       end
  599.       counts[id] = cnt + 1
  600.     end
  601.   end
  602.   return counts
  603. end
  604.  
  605. function writeRecipe()
  606.   print("Запись рецепта:")
  607.  
  608.   print("1. Анализ сетки крафта.")
  609.   local recipe = {
  610.    grid = { },
  611.    n = 1
  612.   }
  613.   for i = 1, 9, 1 do
  614.     local slot = 1
  615.     local item = itemdb.storeInternal(gridSlot(i))
  616.     if item ~= nil then
  617.       recipe.grid[i] = item.id
  618.     end
  619.   end
  620.  
  621.   print("2. Пробный крафт.")
  622.   robot.select(RESULT_SLOT)
  623.   local ok = crafting.craft(1)
  624.   if not ok then
  625.     print("Неверный рецепт.")
  626.     return
  627.   end
  628.  
  629.   print("3. Сохраняю рецепт.")
  630.   local outItem = itemdb.storeInternal(4)
  631.   local stack = inv.getStackInInternalSlot(4)
  632.   recipe.n = stack.size
  633.   outItem.recipe = recipe
  634.   outItem.changed = true
  635.   print("Имя предмета:", outItem.label)
  636.   print("Хеш предмета:", outItem.id)
  637.   print("Завершено успешно.")
  638. end
  639.  
  640. function clearWSlots()
  641.   for i = 1, 9, 1 do
  642.     robot.select(gridSlot(i))
  643.     storage.dropStack()
  644.   end
  645.   robot.select(RESULT_SLOT)
  646.   storage.dropStack()
  647. end
  648.  
  649. function usage()
  650.   print("Использование:")
  651.   print("craft -w", "Запись рецепта, выложенного в ле-вом верхнем углу инвентаря робота.")
  652.   print("craft <файл с хешем предмета> [<Кол-во>]",
  653.     "Выдаёт  предметы. Крафтит недостающие.")
  654.   print("Опции:")
  655.   print("-s", "Отправить результат крафта в хранилище.")
  656.   print("-o", "Не искать в хранилище. Только крафт.")
  657.   print("-u", "Просканировать хранилище.")
  658.   print("-c", "Очистить рабочие слоты робота.")
  659.   print("-r", "Вывести отчёт.")
  660.   print("-l", "Создать файлы с ид. предметов в текущем  каталоге.")
  661.   os.exit(0)
  662. end
  663.  
  664. function getParams(shift)
  665.   if shift == nil then shift = 0 end
  666.   local requestedCount = 1
  667.   local requestedItem
  668.   if args[1 + shift] ~= nil then
  669.     local fn = args[1 + shift]
  670.     local itemId, err = loadFile(fn)
  671.     if err ~= nil then
  672.       print(err)
  673.       os.exit()
  674.     end
  675.     requestedItem = itemdb.get(itemId)
  676.     if requestedItem == nil then
  677.       print("Нет информации в бд.")
  678.       os.exit()
  679.     end
  680.   end
  681.   if args[2 + shift] ~= nil then
  682.     requestedCount = tonumber(args[2 + shift])
  683.   end
  684.   return requestedItem, requestedCount
  685. end
  686.  
  687. function cmdGet()
  688.   local requestedItem, requestedCount = getParams()
  689.   local ok = true
  690.   local neddedCraft = requestedCount
  691.   if not options["o"] then
  692.     local itemCount = storage.count(requestedItem.id)
  693.     neddedCraft = neddedCraft - itemCount
  694.     if itemCount < 0 then
  695.       neddedCraft = 0
  696.     end
  697.   end
  698.   if neddedCraft > 0 then
  699.     if not recursiveCraft(requestedItem, neddedCraft) then
  700.       return
  701.     end
  702.   end
  703.   if not options["s"] then
  704.     local count = requestedCount
  705.     for slot = 1, robot.inventorySize() do
  706.       robot.select(slot)
  707.       local n = count
  708.       if n > requestedItem.maxSize then
  709.         n = requestedItem.maxSize
  710.       end
  711.       local _, ntransfered = storage.suckStack(requestedItem.id, n)
  712.       count = count - ntransfered
  713.       if count == 0 then
  714.         break
  715.       end
  716.     end
  717.     if count ~= 0 then
  718.       printf("Инвентарь полный. Выдано %d предметов.\n", requestedCount - count)
  719.     end
  720.   end
  721. end
  722.  
  723. function main( ... )
  724.   local cmd = false
  725.   if options["version"] then
  726.     print(version)
  727.     os.exit()
  728.   end
  729.  
  730.   if options["h"] then
  731.     usage()
  732.   end
  733.  
  734.   storage.load()
  735.  
  736.   if options["w"] then
  737.     cmd = true
  738.     writeRecipe()
  739.   end
  740.  
  741.   if options["m"] then
  742.     cmd = true
  743.     if not crafting.craft() then
  744.       print("Неверный рецепт!")
  745.     end
  746.   end
  747.  
  748.   if options["u"] then
  749.     cmd = true
  750.     print("Обновление информации о доступных ресурсах")
  751.     storage.scanInventory()
  752.     print("Обновление завершено")
  753.   end
  754.  
  755.   if options["c"] then
  756.     cmd = true
  757.     clearWSlots()
  758.   end
  759.  
  760.   if args[1] ~= nil then
  761.     cmd = true
  762.     cmdGet()
  763.   end
  764.  
  765.   if options["r"] then
  766.     cmd = true
  767.     if options["d"] then
  768.       itemdb.printReport()
  769.     else
  770.       storage.printReport()
  771.     end
  772.   end
  773.  
  774.   if options["l"] then
  775.     cmd = true
  776.     itemdb.makeAllLabels()
  777.   end
  778.  
  779.   if not cmd then
  780.     usage()
  781.   end
  782.  
  783.   storage.save()
  784. end
  785.  
  786. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement