Skip to content

Commit

Permalink
Copy when moving to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
derfloh205 committed Feb 16, 2024
1 parent cf4eee5 commit f1ed25f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
39 changes: 21 additions & 18 deletions Data/Classes/CraftQueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,25 @@ function CraftSim.CraftQueue:AddRecipe(options)
elseif craftQueueItem.targetMode and not targetItemCountByQuality then
-- if recipe to queue is not target mode and the already queued on is, ignore? TODO: maybe some compromise or even make target mode and non target mode recipes coexisting?
else -- if none are target mode just add amount
-- only increase amount, but if recipeData has deeper (higher) subrecipedepth then take lower one
-- only increase amount
craftQueueItem.amount = craftQueueItem.amount + amount
craftQueueItem.recipeData.subRecipeDepth = math.max(craftQueueItem.recipeData.subRecipeDepth,
recipeData.subRecipeDepth)

-- also check if I have parent recipes that the already queued recipe does not have
for _, parentRecipesInfo in ipairs(recipeData.parentRecipeInfo) do
local hasPri = GUTIL:Some(craftQueueItem.recipeData.parentRecipeInfo, function(pri)
return pri.crafterUID == parentRecipesInfo.crafterUID and pri.recipeID == parentRecipesInfo.recipeID
end)
if not hasPri then
tinsert(craftQueueItem.recipeData.parentRecipeInfo, parentRecipesInfo)
end
end
-- always update the subrecipedepth
craftQueueItem.recipeData.subRecipeDepth = math.max(craftQueueItem.recipeData.subRecipeDepth,
recipeData.subRecipeDepth)
-- also check if I have parent recipes that the already queued recipe does not have

for _, parentRecipesInfo in ipairs(recipeData.parentRecipeInfo) do
local hasPri = GUTIL:Some(craftQueueItem.recipeData.parentRecipeInfo, function(pri)
return pri.crafterUID == parentRecipesInfo.crafterUID and pri.recipeID == parentRecipesInfo.recipeID
end)
if not hasPri then
tinsert(craftQueueItem.recipeData.parentRecipeInfo, parentRecipesInfo)
end
end
else
craftQueueItem = CraftSim.CraftQueueItem({
recipeData = recipeData,
recipeData = recipeData:Copy(),
amount = amount,
targetItemCountByQuality = targetItemCountByQuality
})
Expand All @@ -87,11 +88,13 @@ function CraftSim.CraftQueue:AddRecipe(options)
-- queue recipeData
local subRecipe = recipeData.optimizedSubRecipes[itemID]
if subRecipe then
local currentItemCount = CraftSim.CACHE.ITEM_COUNT:Get(itemID, true, false, true,
subRecipe:GetCrafterUID())
local restItemCount = math.max(0, reagentItem.quantity - currentItemCount)
if restItemCount > 0 then
subRecipe:SetNonQualityReagentsMax()
print("Found self crafted reagent: queue into cq: " .. subRecipe.recipeName)
subRecipe:SetNonQualityReagentsMax()
-- local currentItemCount = CraftSim.CACHE.ITEM_COUNT:Get(itemID, true, false, true,
-- recipeData:GetCrafterUID())
-- local restItemCount = math.max(0, reagentItem.quantity - currentItemCount)
-- print("Restitemcount: " .. tostring(restItemCount))
if reagentItem.quantity > 0 then
self:AddRecipe({ recipeData = subRecipe, amount = 1, targetItemCountByQuality = { [qualityID] = reagentItem.quantity } })
end
end
Expand Down
25 changes: 13 additions & 12 deletions Data/Classes/PriceData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ function CraftSim.PriceData:Update()
if reagentData.salvageReagentSlot.activeItem then
local itemID = reagentData.salvageReagentSlot.activeItem:GetItemID()
-- only use subrecipe price if the item also has a optimizedSubRecipe in the recipeData
useSubRecipes = useSubRecipes and self.recipeData.optimizedSubRecipes[itemID]
local itemPrice, priceInfo = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemID, true, false, useSubRecipes)
local itemPrice, priceInfo = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemID, true, false,
useSubRecipes and self.recipeData.optimizedSubRecipes[itemID])
self.craftingCosts = self.craftingCosts + itemPrice * reagentData.salvageReagentSlot.requiredQuantity
self.craftingCostsRequired = self.craftingCosts
print(tostring(reagentData.salvageReagentSlot.activeItem:GetItemLink()))
if priceInfo.isExpectedCost then
tinsert(self.selfCraftedReagents, itemID)
end
Expand All @@ -72,9 +71,8 @@ function CraftSim.PriceData:Update()
for _, reagentItem in pairs(reagent.items) do
totalQuantity = totalQuantity + reagentItem.quantity
local itemID = reagentItem.item:GetItemID()
useSubRecipes = useSubRecipes and self.recipeData.optimizedSubRecipes[itemID]
local itemPrice, priceInfo = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemID, true, false,
useSubRecipes)
useSubRecipes and self.recipeData.optimizedSubRecipes[itemID])
totalPrice = totalPrice + itemPrice * reagentItem.quantity
if priceInfo.isExpectedCost then
tinsert(self.selfCraftedReagents, itemID)
Expand All @@ -87,9 +85,12 @@ function CraftSim.PriceData:Update()
local itemIDQ1 = reagent.items[1].item:GetItemID()
local itemIDQ2 = reagent.items[2].item:GetItemID()
local itemIDQ3 = reagent.items[3].item:GetItemID()
local itemPriceQ1 = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemIDQ1, true, false, useSubRecipes)
local itemPriceQ2 = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemIDQ2, true, false, useSubRecipes)
local itemPriceQ3 = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemIDQ3, true, false, useSubRecipes)
local itemPriceQ1 = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemIDQ1, true, false,
useSubRecipes and self.recipeData.optimizedSubRecipes[itemIDQ1])
local itemPriceQ2 = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemIDQ2, true, false,
useSubRecipes and self.recipeData.optimizedSubRecipes[itemIDQ2])
local itemPriceQ3 = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemIDQ3, true, false,
useSubRecipes and self.recipeData.optimizedSubRecipes[itemIDQ3])
local cheapestItemPrice = math.min(itemPriceQ1, itemPriceQ2, itemPriceQ3)

self.craftingCosts = self.craftingCosts + cheapestItemPrice * reagent.requiredQuantity
Expand All @@ -98,8 +99,8 @@ function CraftSim.PriceData:Update()
end
else
local itemID = reagent.items[1].item:GetItemID()
useSubRecipes = useSubRecipes and self.recipeData.optimizedSubRecipes[itemID]
local itemPrice, priceInfo = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemID, true, false, useSubRecipes)
local itemPrice, priceInfo = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemID, true, false,
useSubRecipes and self.recipeData.optimizedSubRecipes[itemID])
self.craftingCosts = self.craftingCosts + itemPrice * reagent.requiredQuantity
self.craftingCostsFixed = self.craftingCostsFixed + itemPrice * reagent.requiredQuantity -- always max

Expand All @@ -121,8 +122,8 @@ function CraftSim.PriceData:Update()
if activeOptionalReagent then
print("added optional reagent to crafting cost: " .. tostring(activeOptionalReagent.item:GetItemLink()))
local itemID = activeOptionalReagent.item:GetItemID()
useSubRecipes = useSubRecipes and self.recipeData.optimizedSubRecipes[itemID]
local itemPrice, priceInfo = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemID, true, false, useSubRecipes)
local itemPrice, priceInfo = CraftSim.PRICEDATA:GetMinBuyoutByItemID(itemID, true, false,
useSubRecipes and self.recipeData.optimizedSubRecipes[itemID])
self.craftingCosts = self.craftingCosts + itemPrice

if priceInfo.isExpectedCost then
Expand Down
3 changes: 0 additions & 3 deletions Data/Classes/ReagentData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,6 @@ function CraftSim.ReagentData:GetTooltipText(multiplier, crafterUID)
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(reagentItem.item:GetItemID(),
true,
false, true, crafterUID)
print("- tooltiptext for: " .. tostring(reagentItem.item:GetItemName()))
print("- - player item count: " .. tostring(itemCount))
print("- - allocated quantity: " .. tostring(reagentItem.quantity))
local quantityText = f.r(tostring(requiredReagent.requiredQuantity * multiplier) ..
"(" .. tostring(itemCount) .. ")")

Expand Down
12 changes: 6 additions & 6 deletions Data/Classes/RecipeData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,23 @@ end
---@return CraftSim.RecipeData recipeDataCopy
function CraftSim.RecipeData:Copy()
---@type CraftSim.RecipeData
local copy = CraftSim.RecipeData(self.recipeID, self.isRecraft)
local copy = CraftSim.RecipeData(self.recipeID, self.isRecraft, self.orderData ~= nil, self.crafterData)
copy.reagentData = self.reagentData:Copy(copy)
copy.professionGearSet = self.professionGearSet:Copy()
copy.professionStats = self.professionStats:Copy()
copy.baseProfessionStats = self.baseProfessionStats:Copy()
copy.professionStatModifiers = self.professionStatModifiers:Copy()
copy.priceData = self.priceData:Copy(copy) -- Is this needed or covered by constructor?
copy.resultData = self.resultData:Copy(copy) -- Is this needed or covered by constructor?
-- copy spec data or already handled in constructor?
copy.priceData = self.priceData:Copy(copy)
copy.resultData = self.resultData:Copy(copy)
copy.orderData = self.orderData
copy.crafterData = self.crafterData
copy.subRecipeCostsEnabled = self.subRecipeCostsEnabled
copy.optimizedSubRecipes = {}
copy.averageProfitCached = self.averageProfitCached
copy.relativeProfitCached = self.relativeProfitCached

-- TODO: Check if deep copy is necessary here or if its ok to just reuse the references
for itemID, recipeData in pairs(self.optimizedSubRecipes) do
copy.optimizedSubRecipes[itemID] = recipeData
copy.optimizedSubRecipes[itemID] = recipeData:Copy()
end

copy:Update()
Expand Down
6 changes: 4 additions & 2 deletions Modules/CraftQueue/CraftQueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ function CraftSim.CRAFTQ:ImportRecipeScan()

CraftSim.CRAFTQ.FRAMES:UpdateQueueDisplay()
end, function()
-- finally update all subrecipes in target mode and update display one last time
CraftSim.CRAFTQ.craftQueue:UpdateSubRecipesTargetItemCounts()
CraftSim.CRAFTQ.FRAMES:UpdateQueueDisplay()
importButton:SetStatus("Ready")
end)
end
Expand Down Expand Up @@ -667,8 +670,7 @@ function CraftSim.CRAFTQ:AddOpenRecipe()
return
end

-- needs to be a copy or we modify it when we edit it in the queue..
CraftSim.CRAFTQ:AddRecipe({ recipeData = recipeData:Copy() })
CraftSim.CRAFTQ:AddRecipe({ recipeData = recipeData })
end

function CraftSim.CRAFTQ:OnRecipeEditSave()
Expand Down

0 comments on commit f1ed25f

Please sign in to comment.