Skip to content

Commit

Permalink
Shopping List Enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
derfloh205 committed Dec 8, 2023
1 parent c7fe04d commit e3574ab
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CraftSim.toc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Title: CraftSim
## Notes: Calculates the average profit based on your profession stats and other tools for dragonflight gold making
## Author: genju
## Version: 11.1.0
## Version: 11.1.1
## X-Curse-Project-ID: 705015
## X-Wago-ID: 0mNwaPKo
## X-WoWI-ID: 26519
Expand Down
5 changes: 3 additions & 2 deletions Data/News.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ function CraftSim.NEWS:GET_NEWS()
return
f.bb(" Hello and thank you for using CraftSim!\n") ..
f.bb(" ( You are awesome! )") ..
newP("11.1.0") ..
newP("11.1.1") ..
f.p .. "Fixed " .. f.bb("CraftResults") .. " incorrectly adding multicraft results" ..
f.p .. "Fixed " .. f.bb("CraftQueue") .. " not being initialized sometimes" ..
f.p .. "Fixed " .. f.bb("Create Auctionator Shopping List") .. " button not working" ..
f.p .. "Shopping Lists will now exclude soulbound items" ..
f.p .. f.bb("Shopping List") .. " will now exclude soulbound items" ..
f.p .. f.bb("Shopping List") .. " will now remove/reduce items when bought" ..
f.p .. "Added a delete button for each " .. f.bb("CraftQueue Row") ..
f.p .. "Unlearned recipes are now not addable to the " .. f.bb("CraftQueue") ..
f.p .. f.g("Increased CraftQueue Performance") .. " using an ItemCount Cache" ..
Expand Down
2 changes: 1 addition & 1 deletion Libs/GUTIL
Submodule GUTIL updated 1 files
+4 −0 GUTIL.lua
85 changes: 82 additions & 3 deletions Modules/CraftQueue/CraftQueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,63 @@ CraftSim.CRAFTQ.itemCountCache = nil

local print=CraftSim.UTIL:SetDebugPrint(CraftSim.CONST.DEBUG_IDS.CRAFTQ)

---@param itemID number
---@param boughtQuantity number
function CraftSim.CRAFTQ:OnConfirmCommoditiesPurchase(itemID, boughtQuantity)
if not select(2, C_AddOns.IsAddOnLoaded(CraftSim.CONST.SUPPORTED_PRICE_API_ADDONS[2])) then
return -- do not need if Auctionator not loaded
end
local itemMixin = Item:CreateFromItemID(itemID)

CraftSim.GUTIL:ContinueOnAllItemsLoaded({itemMixin}, function ()
print("bought commodity")
print("item: " .. tostring(itemMixin:GetItemLink()))
print("quantity: " .. tostring(boughtQuantity))

-- modify shopping list
local listIndex = Auctionator.Shopping.ListManager:GetIndexForName(CraftSim.CONST.AUCTIONATOR_SHOPPING_LIST_QUEUE_NAME)
if listIndex then
local shoppingList = Auctionator.Shopping.ListManager:GetByIndex(listIndex)
local itemQualityID = CraftSim.GUTIL:GetQualityIDFromLink(itemMixin:GetItemLink()) or '#'
local searchString = CraftSim.CRAFTQ:GetAuctionatorShoppingListItemString(itemMixin:GetItemName(), itemQualityID)
print("searchString: " .. tostring(searchString))
local item = CraftSim.GUTIL:Find(shoppingList.data.items, function (itemString)
return CraftSim.GUTIL:StringStartsWith(itemString, searchString)
end)
if item then
local itemIndex = shoppingList:GetIndexForItem(item)
if not itemIndex then
return
end
local name, qualityID, quantity = CraftSim.CRAFTQ:ParseAuctionatorShoppingListItemString(item)
print("found and parsed shopping list item string: ")
print("name: " .. tostring(name))
print("qualityID: " .. tostring(qualityID))
print("quantity: " .. tostring(quantity))
local newQuantity = quantity - boughtQuantity

if newQuantity > 0 then
local newItem = CraftSim.CRAFTQ:GetAuctionatorShoppingListItemString(itemMixin:GetItemName(), itemQualityID, newQuantity)
-- update item
shoppingList:AlterItem(itemIndex, newItem)
else
-- remove item
shoppingList:DeleteItem(itemIndex)
end
end
end
end)

end

function CraftSim.CRAFTQ:InitializeCraftQueue()
-- TODO: load from Saved Variables?
CraftSim.CRAFTQ.craftQueue = CraftSim.CraftQueue({})

-- hook onto auction buy confirm function
hooksecurefunc(C_AuctionHouse, "ConfirmCommoditiesPurchase", function (itemID, quantity)
CraftSim.CRAFTQ:OnConfirmCommoditiesPurchase(itemID, quantity)
end)
end

---@param recipeData CraftSim.RecipeData
Expand Down Expand Up @@ -114,12 +168,11 @@ function CraftSim.CRAFTQ:CreateAuctionatorShoppingList()
if not isSoulbound then
local itemCount = GetItemCount(itemID, true, false, true)
if itemCount < info.quantity then
shoppingListImportString = shoppingListImportString .. '^"'..info.itemName..'"' .. ';;0;0;0;0;0;0;0;0;;'..(info.qualityID or '#')..';;' .. info.quantity - itemCount
local itemShoppingListString = CraftSim.CRAFTQ:GetAuctionatorShoppingListItemString(info.itemName, info.qualityID, info.quantity - itemCount)
shoppingListImportString = shoppingListImportString .. '^' .. itemShoppingListString
end
end
end

--CraftSim CraftQueue2^"Khaz'gorite Ore";;0;0;0;0;0;0;0;0;;1;;99^"Awakened Frost";;0;0;0;0;0;0;0;0;;0;;#;;1^"Awakened Fire";;0;0;0;0;0;0;0;0;;0;;#;;1^"Primal Flux";;0;0;0;0;0;0;0;0;;0;;#;;4^"Draconium Ore";;0;0;0;0;0;0;0;0;;1;;#;;5

-- delete old list only if it exists to refresh contents instead of adding them
local listExists = Auctionator.Shopping.ListManager:GetIndexForName(CraftSim.CONST.AUCTIONATOR_SHOPPING_LIST_QUEUE_NAME)
Expand Down Expand Up @@ -148,4 +201,30 @@ function CraftSim.CRAFTQ:GetItemCountFromCache(itemID, bank, uses, reagentbank)
itemCount = GetItemCount(itemID, bank, uses, reagentbank)
end
return itemCount
end

---@param itemName string
---@param qualityID number | string?
---@param quantity number?
---@return string auctionatorShoppingListItemString
function CraftSim.CRAFTQ:GetAuctionatorShoppingListItemString(itemName, qualityID, quantity)
return '"'..itemName..'"' .. ';;0;0;0;0;0;0;0;0;;'..(qualityID or '#')..';;' .. (quantity or '')
end

---@return string name
---@return number | nil qualityID
---@return number | nil quantity
function CraftSim.CRAFTQ:ParseAuctionatorShoppingListItemString(itemString)
local name, qualityID, quantity = itemString:match('"([^"]+)";;0;0;0;0;0;0;0;0;;(%S+);;(%d+)$')
if qualityID == '#' then
qualityID = nil
else
qualityID = tonumber(qualityID)
end
if quantity == '' then
quantity = nil
else
quantity = tonumber(quantity)
end
return name, qualityID, quantity
end

0 comments on commit e3574ab

Please sign in to comment.