milo crafting updates
This commit is contained in:
@@ -76,7 +76,7 @@ end
|
|||||||
|
|
||||||
function MEAdapter:isCrafting(item)
|
function MEAdapter:isCrafting(item)
|
||||||
self:clearFinished()
|
self:clearFinished()
|
||||||
_G._p = self.jobList
|
|
||||||
for _,job in pairs(self.jobList) do
|
for _,job in pairs(self.jobList) do
|
||||||
if job.name == item.name and
|
if job.name == item.name and
|
||||||
job.damage == item.damage and
|
job.damage == item.damage and
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ local function turtleCraft(recipe, storage, request, count)
|
|||||||
request.statusCode = Craft.STATUS_ERROR
|
request.statusCode = Craft.STATUS_ERROR
|
||||||
else
|
else
|
||||||
request.crafted = request.crafted + count * recipe.count
|
request.crafted = request.crafted + count * recipe.count
|
||||||
request.status = 'crafted'
|
--request.status = 'crafted'
|
||||||
request.statusCode = Craft.STATUS_SUCCESS
|
--request.statusCode = Craft.STATUS_SUCCESS
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
_G._syslog('just failed')
|
_G._syslog('just failed')
|
||||||
@@ -319,6 +319,7 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path)
|
|||||||
|
|
||||||
repeat
|
repeat
|
||||||
local craftedIngredient
|
local craftedIngredient
|
||||||
|
local abort
|
||||||
|
|
||||||
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
||||||
local itemCount = Craft.getItemCount(origItem.ingredients, key)
|
local itemCount = Craft.getItemCount(origItem.ingredients, key)
|
||||||
@@ -330,24 +331,27 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path)
|
|||||||
if itemCount < need then
|
if itemCount < need then
|
||||||
local irecipe = findValidRecipe(key, path)
|
local irecipe = findValidRecipe(key, path)
|
||||||
if not irecipe then
|
if not irecipe then
|
||||||
return 0
|
abort = true
|
||||||
end
|
else
|
||||||
|
local iqty = need - itemCount
|
||||||
local iqty = need - itemCount
|
local p = Util.shallowCopy(path)
|
||||||
local p = Util.shallowCopy(path)
|
p[irecipe.result] = true
|
||||||
p[irecipe.result] = true
|
local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem, p)
|
||||||
local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem, p)
|
if not origItem.forceCrafting and crafted < iqty then
|
||||||
if not origItem.forceCrafting and crafted < iqty then
|
abort = true
|
||||||
return 0
|
end
|
||||||
end
|
if origItem.forceCrafting and crafted < iqty then
|
||||||
if origItem.forceCrafting and crafted < iqty then
|
canCraft = math.min(canCraft, math.floor((itemCount + crafted) / icount))
|
||||||
canCraft = math.min(canCraft, math.floor((itemCount + crafted) / icount))
|
end
|
||||||
end
|
if crafted > 0 then
|
||||||
if crafted > 0 then
|
craftedIngredient = true
|
||||||
craftedIngredient = true
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if abort then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
until not craftedIngredient
|
until not craftedIngredient
|
||||||
|
|
||||||
local crafted = 0
|
local crafted = 0
|
||||||
@@ -476,7 +480,43 @@ function Craft.getResourceList4(inRecipe, items, count)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- given a certain quantity, return how many of those can be crafted
|
-- given a certain quantity, return how many of those can be crafted
|
||||||
function Craft.getCraftableAmount(inRecipe, limit, items)
|
function Craft.getCraftableAmount(inRecipe, inCount, items, missing)
|
||||||
|
local function sumItems(recipe, summedItems, count, path)
|
||||||
|
local canCraft = 0
|
||||||
|
|
||||||
|
for _ = 1, count do
|
||||||
|
for _,entry in pairs(recipe.ingredients) do
|
||||||
|
local item = convert(entry)
|
||||||
|
local summedItem = summedItems[item.key] or Craft.getItemCount(items, item.key)
|
||||||
|
|
||||||
|
local irecipe = findValidRecipe(item.key, path)
|
||||||
|
if irecipe and summedItem <= 0 then
|
||||||
|
local p = Util.shallowCopy(path)
|
||||||
|
p[irecipe.result] = true
|
||||||
|
summedItem = summedItem + sumItems(irecipe, summedItems, item.count, p)
|
||||||
|
end
|
||||||
|
if summedItem <= 0 then
|
||||||
|
if missing and not irecipe then
|
||||||
|
missing.name = item.key
|
||||||
|
end
|
||||||
|
return canCraft
|
||||||
|
end
|
||||||
|
if not recipe.craftingTools or not recipe.craftingTools[item.key] then
|
||||||
|
summedItems[item.key] = summedItem - item.count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
canCraft = canCraft + recipe.count
|
||||||
|
end
|
||||||
|
|
||||||
|
return canCraft
|
||||||
|
end
|
||||||
|
|
||||||
|
local path = { [ inRecipe.result ] = true }
|
||||||
|
return sumItems(inRecipe, { }, math.ceil(inCount / inRecipe.count), path)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- doesnt work :( solar panel 3 fails (qty 2)
|
||||||
|
function Craft.getCraftableAmountXXX(inRecipe, limit, items)
|
||||||
local allIngredients = { }
|
local allIngredients = { }
|
||||||
|
|
||||||
local function sumItems(recipe, count, path)
|
local function sumItems(recipe, count, path)
|
||||||
@@ -485,7 +525,6 @@ function Craft.getCraftableAmount(inRecipe, limit, items)
|
|||||||
for _ = 1, count do
|
for _ = 1, count do
|
||||||
for iKey, iCount in pairs(Craft.sumIngredients(recipe)) do
|
for iKey, iCount in pairs(Craft.sumIngredients(recipe)) do
|
||||||
local quantity = allIngredients[iKey] or Craft.getItemCount(items, iKey)
|
local quantity = allIngredients[iKey] or Craft.getItemCount(items, iKey)
|
||||||
|
|
||||||
if quantity < iCount then
|
if quantity < iCount then
|
||||||
local irecipe = findValidRecipe(iKey, path)
|
local irecipe = findValidRecipe(iKey, path)
|
||||||
if irecipe then
|
if irecipe then
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ function Milo:setState(key, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Milo:resetCraftingStatus()
|
function Milo:resetCraftingStatus()
|
||||||
self.context.storage.activity = { }
|
|
||||||
|
|
||||||
for _,key in pairs(Util.keys(self.context.craftingQueue)) do
|
for _,key in pairs(Util.keys(self.context.craftingQueue)) do
|
||||||
local item = self.context.craftingQueue[key]
|
local item = self.context.craftingQueue[key]
|
||||||
if item.crafted >= item.requested or item.aborted then
|
if item.crafted >= item.requested or item.aborted then
|
||||||
|
|||||||
@@ -15,13 +15,17 @@ function craftTask:craft(recipe, item)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: refactor into craft.lua
|
|
||||||
Craft.processPending(item, context.storage)
|
|
||||||
|
|
||||||
-- create a mini-list of items that are required for this recipe
|
-- create a mini-list of items that are required for this recipe
|
||||||
item.ingredients = Craft.getResourceList(
|
item.ingredients = Craft.getResourceList(
|
||||||
recipe, Milo:listItems(), item.requested - item.crafted, item.pending)
|
recipe, Milo:listItems(), item.requested - item.crafted, item.pending)
|
||||||
|
|
||||||
|
for k,v in pairs(item.ingredients) do
|
||||||
|
if item.pending[k] then
|
||||||
|
v.status = 'processing'
|
||||||
|
v.statusCode = Craft.STATUS_INFO
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for k, v in pairs(item.ingredients) do
|
for k, v in pairs(item.ingredients) do
|
||||||
v.crafted = v.used
|
v.crafted = v.used
|
||||||
v.count = v.used
|
v.count = v.used
|
||||||
@@ -39,6 +43,12 @@ function craftTask:craft(recipe, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function craftTask:cycle()
|
function craftTask:cycle()
|
||||||
|
for _,item in pairs(context.craftingQueue) do
|
||||||
|
Craft.processPending(item, context.storage)
|
||||||
|
end
|
||||||
|
|
||||||
|
context.storage.activity = { }
|
||||||
|
|
||||||
for _,key in pairs(Util.keys(context.craftingQueue)) do
|
for _,key in pairs(Util.keys(context.craftingQueue)) do
|
||||||
local item = context.craftingQueue[key]
|
local item = context.craftingQueue[key]
|
||||||
if item.requested - item.crafted > 0 then
|
if item.requested - item.crafted > 0 then
|
||||||
|
|||||||
@@ -156,8 +156,12 @@ local function createPage(node)
|
|||||||
end
|
end
|
||||||
if row.requested then
|
if row.requested then
|
||||||
row.remaining = math.max(0, row.requested - row.crafted)
|
row.remaining = math.max(0, row.requested - row.crafted)
|
||||||
|
--_syslog('%d %d %d %d', row.remaining, row.requested, row.total, row.crafted)
|
||||||
|
row.status = (row.status or '') ..
|
||||||
|
string.format(' %d of %d', row.crafted + row.total, row.total + row.requested)
|
||||||
else
|
else
|
||||||
row.displayName = ' ' .. row.displayName
|
row.displayName = ' ' .. row.displayName
|
||||||
|
row.status = (row.status or '') .. string.format(' %d of %d', row.count, row.total)
|
||||||
end
|
end
|
||||||
--row.progress = string.format('%d/%d', row.crafted, row.count)
|
--row.progress = string.format('%d/%d', row.crafted, row.count)
|
||||||
return row
|
return row
|
||||||
|
|||||||
@@ -91,14 +91,16 @@ local function createPage(node)
|
|||||||
value = 'Storage Status',
|
value = 'Storage Status',
|
||||||
},
|
},
|
||||||
onlineText = UI.Text {
|
onlineText = UI.Text {
|
||||||
x = 18, ex = -2, y = 2,
|
x = 18, y = 2,
|
||||||
|
width = 8,
|
||||||
},
|
},
|
||||||
tpsLabel = UI.Text {
|
tpsLabel = UI.Text {
|
||||||
x = 2, y = 3,
|
x = 2, y = 3,
|
||||||
value = 'Tasks/sec',
|
value = 'Tasks/sec',
|
||||||
},
|
},
|
||||||
tpsText = UI.Text {
|
tpsText = UI.Text {
|
||||||
x = 18, ex = -2, y = 3,
|
x = 18, y = 3,
|
||||||
|
width = 8,
|
||||||
},
|
},
|
||||||
tasksLabel = UI.Text {
|
tasksLabel = UI.Text {
|
||||||
x = -18, y = 3,
|
x = -18, y = 3,
|
||||||
@@ -188,6 +190,7 @@ local function createPage(node)
|
|||||||
local stateTab = page.tabs[4]
|
local stateTab = page.tabs[4]
|
||||||
local activityTab = page.tabs[5]
|
local activityTab = page.tabs[5]
|
||||||
local taskTab = page.tabs[6]
|
local taskTab = page.tabs[6]
|
||||||
|
_G._p2 = overviewTab
|
||||||
|
|
||||||
local function getStorageStats()
|
local function getStorageStats()
|
||||||
local stats = { }
|
local stats = { }
|
||||||
|
|||||||
Reference in New Issue
Block a user