From 03643bcd348d80eb8d4aa97992d8bb640aaf377b Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 27 Jun 2019 16:29:37 -0400 Subject: [PATCH] milo crafting updates --- core/apis/meAdapter18.lua | 2 +- milo/apis/craft2.lua | 77 ++++++++++++++++++++++++++++--------- milo/apis/init.lua | 2 - milo/plugins/craftTask.lua | 16 ++++++-- milo/plugins/jobMonitor.lua | 4 ++ milo/plugins/statsView.lua | 7 +++- 6 files changed, 81 insertions(+), 27 deletions(-) diff --git a/core/apis/meAdapter18.lua b/core/apis/meAdapter18.lua index 95d3bc5..0f45776 100644 --- a/core/apis/meAdapter18.lua +++ b/core/apis/meAdapter18.lua @@ -76,7 +76,7 @@ end function MEAdapter:isCrafting(item) self:clearFinished() -_G._p = self.jobList + for _,job in pairs(self.jobList) do if job.name == item.name and job.damage == item.damage and diff --git a/milo/apis/craft2.lua b/milo/apis/craft2.lua index d91708c..0634f90 100644 --- a/milo/apis/craft2.lua +++ b/milo/apis/craft2.lua @@ -219,8 +219,8 @@ local function turtleCraft(recipe, storage, request, count) request.statusCode = Craft.STATUS_ERROR else request.crafted = request.crafted + count * recipe.count - request.status = 'crafted' - request.statusCode = Craft.STATUS_SUCCESS + --request.status = 'crafted' + --request.statusCode = Craft.STATUS_SUCCESS end else _G._syslog('just failed') @@ -319,6 +319,7 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path) repeat local craftedIngredient + local abort for key,icount in pairs(Craft.sumIngredients(recipe)) do local itemCount = Craft.getItemCount(origItem.ingredients, key) @@ -330,24 +331,27 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path) if itemCount < need then local irecipe = findValidRecipe(key, path) if not irecipe then - return 0 - end - - local iqty = need - itemCount - local p = Util.shallowCopy(path) - p[irecipe.result] = true - local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem, p) - if not origItem.forceCrafting and crafted < iqty then - return 0 - end - if origItem.forceCrafting and crafted < iqty then - canCraft = math.min(canCraft, math.floor((itemCount + crafted) / icount)) - end - if crafted > 0 then - craftedIngredient = true + abort = true + else + local iqty = need - itemCount + local p = Util.shallowCopy(path) + p[irecipe.result] = true + local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem, p) + if not origItem.forceCrafting and crafted < iqty then + abort = true + end + if origItem.forceCrafting and crafted < iqty then + canCraft = math.min(canCraft, math.floor((itemCount + crafted) / icount)) + end + if crafted > 0 then + craftedIngredient = true + end end end end + if abort then + return 0 + end until not craftedIngredient local crafted = 0 @@ -476,7 +480,43 @@ function Craft.getResourceList4(inRecipe, items, count) end -- 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 function sumItems(recipe, count, path) @@ -485,7 +525,6 @@ function Craft.getCraftableAmount(inRecipe, limit, items) for _ = 1, count do for iKey, iCount in pairs(Craft.sumIngredients(recipe)) do local quantity = allIngredients[iKey] or Craft.getItemCount(items, iKey) - if quantity < iCount then local irecipe = findValidRecipe(iKey, path) if irecipe then diff --git a/milo/apis/init.lua b/milo/apis/init.lua index c89b208..46a2696 100644 --- a/milo/apis/init.lua +++ b/milo/apis/init.lua @@ -71,8 +71,6 @@ function Milo:setState(key, value) end function Milo:resetCraftingStatus() - self.context.storage.activity = { } - for _,key in pairs(Util.keys(self.context.craftingQueue)) do local item = self.context.craftingQueue[key] if item.crafted >= item.requested or item.aborted then diff --git a/milo/plugins/craftTask.lua b/milo/plugins/craftTask.lua index 40d0e7d..bac440f 100644 --- a/milo/plugins/craftTask.lua +++ b/milo/plugins/craftTask.lua @@ -15,13 +15,17 @@ function craftTask:craft(recipe, item) return end - -- TODO: refactor into craft.lua - Craft.processPending(item, context.storage) - -- create a mini-list of items that are required for this recipe item.ingredients = Craft.getResourceList( 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 v.crafted = v.used v.count = v.used @@ -39,6 +43,12 @@ function craftTask:craft(recipe, item) end 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 local item = context.craftingQueue[key] if item.requested - item.crafted > 0 then diff --git a/milo/plugins/jobMonitor.lua b/milo/plugins/jobMonitor.lua index 6d00f3c..98f5cbb 100644 --- a/milo/plugins/jobMonitor.lua +++ b/milo/plugins/jobMonitor.lua @@ -156,8 +156,12 @@ local function createPage(node) end if row.requested then 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 row.displayName = ' ' .. row.displayName + row.status = (row.status or '') .. string.format(' %d of %d', row.count, row.total) end --row.progress = string.format('%d/%d', row.crafted, row.count) return row diff --git a/milo/plugins/statsView.lua b/milo/plugins/statsView.lua index ff13f10..f2db0b7 100644 --- a/milo/plugins/statsView.lua +++ b/milo/plugins/statsView.lua @@ -91,14 +91,16 @@ local function createPage(node) value = 'Storage Status', }, onlineText = UI.Text { - x = 18, ex = -2, y = 2, + x = 18, y = 2, + width = 8, }, tpsLabel = UI.Text { x = 2, y = 3, value = 'Tasks/sec', }, tpsText = UI.Text { - x = 18, ex = -2, y = 3, + x = 18, y = 3, + width = 8, }, tasksLabel = UI.Text { x = -18, y = 3, @@ -188,6 +190,7 @@ local function createPage(node) local stateTab = page.tabs[4] local activityTab = page.tabs[5] local taskTab = page.tabs[6] + _G._p2 = overviewTab local function getStorageStats() local stats = { }