Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- ci = peripheral.find("colonyIntegrator") or error("No ColonyIntegrator attached", 0)
- bridge = peripheral.find("meBridge") or error("No meBridge attached", 0)
- function dlog (wColor, wCritical, wMessage)
- if wCritical then
- term.setTextColor(wColor)
- print(wMessage)
- term.setTextColor(colors.white)
- elseif args[1] ~= "-s" then
- term.setTextColor(wColor)
- print(wMessage)
- term.setTextColor(colors.white)
- end
- end
- dlog(colors.white, true, "------")
- dlog(colors.white, true, "Interaction Requested...")
- dlog(colors.white, false, "------")
- -- ME system extraction
- function meExtract (eItem, eCount, eTable)
- sItem = tostring(eItem)
- retState = false
- -- export from system
- function exporter (sItem, eCount)
- result, err = bridge.exportItem({name=sItem, count=eCount}, "up")
- if err then
- dlog(colors.white, false,"export failure")
- else
- dlog(colors.green, true, string.format("Exporting %d %s", result, sItem))
- dlog(colors.green, false, "Export success.")
- retState = true
- end
- end
- -- craft resource
- function crafter (sItem, eCount)
- craftSuccess = bridge.craftItem({name=sItem, count=eCount})
- if craftSuccess then
- dlog(colors.white, true, "ME crafting success")
- return true
- else
- dlog(colors.red, true, "ME crafting failure")
- return false
- end
- end
- -- check for item in storage
- hasItem, err = bridge.getItem({name = eTable.name})
- if err or (hasItem.name == nil) then
- --doesnt have it
- dlog(colors.white, false, "None found..")
- if hasItem.isCraftable then
- -- Can be crafted
- dlog(colors.white, false, "Attempting ME crafting..")
- if crafter(sItem, eCount) then
- exporter(sItem, eCount)
- else
- dlog(colors.red, false, "ME Craft failure")
- dlog(colors.red, false, "Unable to provide")
- end
- else
- -- Cannot be crafted
- dlog(colors.red, false, "ME Crafting unable")
- dlog(colors.white, false, "Unable to provide")
- end
- else
- --has it
- if hasItem.amount >= eCount then
- -- attempt export
- exporter(sItem, eCount)
- else
- dlog(colors.white, false, "ME system cannot provide full amount")
- dlog(colors.white, false, "Attempting to craft remainder...")
- restCount = eCount - hasItem.amount
- if crafter(sItem, restCount) then
- exporter(sItem, restCount)
- else
- dlog(colors.white, false, "Crafting failure")
- dlog(colors.white, false, string.format("exporting: %d of %d", hasItem.amount, eCount))
- exporter(sItem, hasItem.amount)
- end
- end
- end
- return retState
- end
- -- retreive active work orders
- woOrder = ci.getWorkOrders()
- -- retreive active requests
- requests = ci.getRequests()
- -- Check for availability of resources in work orders
- -- loop through work orders
- dlog(colors.cyan, true, "Checking work orders...")
- for i=1, #woOrder,1 do
- dlog(colors.white, false, "------")
- dlog(colors.cyan, false, string.format("Checking work order number %d of %d", i, #woOrder))
- -- retrieve table for resources for work order
- woID = tonumber(woOrder[i].id)
- woOrResources = ci.getWorkOrderResources(woID)
- -- check through resources
- if woOrResources ~= nil then
- for r=1, #woOrResources,1 do
- availability = woOrResources[r].available
- dlog(colors.white, false, "----")
- dlog(colors.white, false, string.format("%s, available: %d", woOrResources[r].displayName, availability))
- -- if resource is not available, then call for extract
- if availability == 0 then
- dlog(colors.white, false, "none found, attempting extract..")
- meExtract(woOrResources[r].item.name, woOrResources[r].needed, woOrResources[r].item)
- else
- dlog(colors.white, false, "skipping")
- end
- end
- end
- dlog(colors.green, false, string.format("%d complete", i))
- end
- dlog(colors.green, true, "Work orders complete.")
- dlog(colors.cyan, true, "Checking requests...")
- for i=1, #requests,1 do
- dlog(colors.white, false, "------")
- dlog(colors.cyan, false, string.format("Checking request number %d of %d", i, #requests))
- reqItems = requests[i].items
- -- check if there is a request in slot
- if reqItems ~= nil then
- if reqItems[i] ~= nil then
- -- cycle through items in request
- pass = false
- for n=1, #reqItems,1 do
- if args[1] ~= "-s" then
- end
- dlog(colors.white, false, "-----")
- dlog(colors.white, false, string.format("Attempting to request %s from ME system...", reqItems[n].name))
- if meExtract(reqItems[n].name, reqItems[n].count, reqItems[n]) then
- -- exit loop if suitable item has been exported
- pass = true
- break
- end
- end
- if pass == false then
- dlog(colors.red, false, "failed to extract suitable item")
- end
- end
- dlog(colors.green, false, i, " complete")
- end
- end
- dlog(colors.green, true, "Requests complete.")
- dlog(colors.white, true, "------")
- dlog(colors.green, true, "Interaction Complete.")
Advertisement
Add Comment
Please, Sign In to add comment