From 7dc7447a6ea79623fa286e1f152562528be9390a Mon Sep 17 00:00:00 2001 From: pschifferer Date: Sun, 1 Feb 2009 20:52:20 +0000 Subject: [PATCH] Added some checks to update the queue if an intermediate item is acquired. Added a stub function for future implementation of the "key reagent" filter. --- CauldronMain.lua | 23 +++++++++++++++++++++-- CauldronQueue.lua | 11 ++++++++++- CauldronTradeskill.lua | 2 +- CauldronUtil.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/CauldronMain.lua b/CauldronMain.lua index fb9ab45..ebd32e6 100644 --- a/CauldronMain.lua +++ b/CauldronMain.lua @@ -15,7 +15,9 @@ BINDING_NAME_CAULDRONRESET = "Reset Cauldron"; Cauldron.options = {}; Cauldron.options.buttons = {}; -Cauldron.vars = {}; +Cauldron.vars = { + inventory = {}; +}; Cauldron.libs = {}; -- Cauldron.libs.Abacus = LibStub("LibAbacus-3.0"); @@ -248,13 +250,30 @@ function Cauldron:OnTradeSkillRecast() self:debug("OnTradeSkillRecast exit"); end -function Cauldron:OnBagUpdate() +function Cauldron:OnBagUpdate(event, bagid) self:debug("OnBagUpdate enter"); if (not CauldronFrame) or (not CauldronFrame:IsShown()) then return; end + + -- check if the item acquired is in the intermediate list + local items = Cauldron:GetItemDeltas(bagid); + for item, itemCount in pairs(items) do + if itemCount > 0 then + local queue = self.db.realm.userdata[self.vars.playername].queue; + local intItem = CauldronQueue:GetIntermediateItem(queue, item); + if intItem then + -- the item is found in the intermediate list, so recalculate the queue + CauldronQueue:CalculateAllRequiredItems(queue); + Cauldron:UpdateQueue(); + + return; + end + end + end + -- check if we were making something, and then update the queue if self.makingItem then self:debug("OnBagUpdate: self.makingItem="..self.makingItem); local count = GetItemCount(self.makingItem); diff --git a/CauldronQueue.lua b/CauldronQueue.lua index ad813f0..f748b60 100644 --- a/CauldronQueue.lua +++ b/CauldronQueue.lua @@ -418,7 +418,7 @@ function CauldronQueue:ClearQueue(queue) -- sanity checks if not queue then - -- TODO: display error + Cauldron:error("No queue found!"); return; end @@ -460,4 +460,13 @@ function CauldronQueue:ClearQueue(queue) Cauldron:debug("ClearQueue exit"); end +function CauldronQueue:GetIntermediateItem(queue, itemName) + -- sanity checks + if not queue then + Cauldron:error("No queue found!"); + return nil; + end + + return queue.intermediate[itemName]; +end diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua index f1acc2d..78101c1 100644 --- a/CauldronTradeskill.lua +++ b/CauldronTradeskill.lua @@ -468,7 +468,7 @@ function Cauldron:GetReagentsForSkill(skillInfo) end -- check if the reagents are already populated - if #skillInfo.reagents then + if #skillInfo.reagents > 0 then return skillInfo.reagents; end diff --git a/CauldronUtil.lua b/CauldronUtil.lua index 259fe1c..b73def0 100644 --- a/CauldronUtil.lua +++ b/CauldronUtil.lua @@ -103,3 +103,52 @@ function Cauldron:GetNameFromLink(link) return name end +function Cauldron:GetItemDeltas(bagid) + + -- sanity checks + if not bagid then + self:error("No bag ID specified!"); + return {}; + end + + local deltas = {}; + + if not self.vars.inventory then + self.vars.inventory = {}; + end + local inv = self.vars.inventory; + + for i=1,GetContainerNumSlots(bagid) do + local link = GetContainerItemLink(bagid, i); + if link then + local name = select(1, {GetItemInfo(link)}); + local count = GetItemCount(link); + + local delta = 0; + if inv[name] then + delta = count - inv[name].count; + end + + if delta ~= 0 then + -- save the delta information + deltas[name] = delta; + end + + -- store the bag slot information + if count > 0 then + inv[name] = count; + else + inv[name] = nil; + end + end + end + + return deltas; +end + +function Cauldron:IsKeyReagent(itemName) + + -- TODO + + return false; +end -- 1.7.9.5