Skip to content

Commit

Permalink
temp workaround and more filters
Browse files Browse the repository at this point in the history
  • Loading branch information
derfloh205 committed Oct 7, 2024
1 parent 331c2d2 commit 68a2481
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 64 deletions.
11 changes: 7 additions & 4 deletions Classes/OptionalReagentSlot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,27 @@ end
--- returns wether the player has enough the selected optional reagent
---@param multiplier number? default: 1
---@param crafterUID string
function CraftSim.OptionalReagentSlot:HasItem(multiplier, crafterUID)
---@param excludeWarbankTemp? boolean
function CraftSim.OptionalReagentSlot:HasItem(multiplier, crafterUID, excludeWarbankTemp)
multiplier = multiplier or 1
if not self.activeReagent then
return true
end

local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, self.activeReagent.item:GetItemID())
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, self.activeReagent.item:GetItemID(),
excludeWarbankTemp)

return itemCount >= (multiplier * self.maxQuantity)
end

--- check how many times the player can fulfill the allocated item quantity
---@param crafterUID string
function CraftSim.OptionalReagentSlot:HasQuantityXTimes(crafterUID)
function CraftSim.OptionalReagentSlot:HasQuantityXTimes(crafterUID, excludeWarbankTemp)
if not self.activeReagent then
return math.huge -- yes I have infinite a number of times yes
end
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, self.activeReagent.item:GetItemID())
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, self.activeReagent.item:GetItemID(),
excludeWarbankTemp)
return itemCount * self.maxQuantity
end

Expand Down
10 changes: 6 additions & 4 deletions Classes/Reagent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ end

--- returns wether the player has enough of the given required item's allocations (times the multiplier)
---@param multiplier number? default: 1
function CraftSim.Reagent:HasItems(multiplier, crafterUID)
---@param crafterUID CrafterUID?
---@param excludeWarbankTemp? boolean
function CraftSim.Reagent:HasItems(multiplier, crafterUID, excludeWarbankTemp)
multiplier = multiplier or 1

-- check if the player owns enough of each allocated items's quantity and sum up the allocated quantities
local totalQuantity = 0
for _, reagentItem in pairs(self.items) do
local hasItems = reagentItem:HasItem(multiplier, crafterUID)
local hasItems = reagentItem:HasItem(multiplier, crafterUID, excludeWarbankTemp)
totalQuantity = totalQuantity + reagentItem.quantity
if not hasItems then
return false
Expand All @@ -158,7 +160,7 @@ function CraftSim.Reagent:HasItems(multiplier, crafterUID)
end

--- check how many times the player can fulfill the allocated item quantity
function CraftSim.Reagent:HasQuantityXTimes(crafterUID)
function CraftSim.Reagent:HasQuantityXTimes(crafterUID, excludeWarbankTemp)
local currentMinTimes = math.huge

local print = CraftSim.DEBUG:SetDebugPrint(CraftSim.CONST.DEBUG_IDS.CRAFTQ)
Expand All @@ -169,7 +171,7 @@ function CraftSim.Reagent:HasQuantityXTimes(crafterUID)
-- use original item if available
local itemID = (reagentItem.originalItem and reagentItem.originalItem:GetItemID()) or
reagentItem.item:GetItemID()
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID)
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID, excludeWarbankTemp)
--print("--player item count: " .. tostring(itemCount))
--print("--reagentItem.quantity: " .. tostring(reagentItem.quantity))
local itemFitCount = math.floor(itemCount / reagentItem.quantity)
Expand Down
42 changes: 26 additions & 16 deletions Classes/ReagentData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,25 +358,26 @@ end
---comment
---@param multiplier number?
---@param crafterUID string
---@param excludeWarbankTemp? boolean
---@return boolean
function CraftSim.ReagentData:HasEnough(multiplier, crafterUID)
function CraftSim.ReagentData:HasEnough(multiplier, crafterUID, excludeWarbankTemp)
multiplier = multiplier or 1
-- check required, optional and finished reagents if the player has enough times multiplier in his inventory and bank

local hasRequiredReagents = GUTIL:Every(self.requiredReagents,
---@param requiredReagent CraftSim.Reagent
function(requiredReagent)
return requiredReagent:HasItems(multiplier, crafterUID)
return requiredReagent:HasItems(multiplier, crafterUID, excludeWarbankTemp)
end)

local hasOptionalReagents = GUTIL:Every(GUTIL:Concat({ self.optionalReagentSlots, self.finishingReagentSlots }),
---@param optionalReagentSlot CraftSim.OptionalReagentSlot
function(optionalReagentSlot)
return optionalReagentSlot:HasItem(multiplier, crafterUID)
return optionalReagentSlot:HasItem(multiplier, crafterUID, excludeWarbankTemp)
end)
local hasSparkReagent = true
if self:HasSparkSlot() then
hasSparkReagent = self.sparkReagentSlot:HasItem(multiplier, crafterUID)
hasSparkReagent = self.sparkReagentSlot:HasItem(multiplier, crafterUID, excludeWarbankTemp)
end
-- update item cache for all possible optional reagents if I am the crafter
if crafterUID == CraftSim.UTIL:GetPlayerCrafterUID() then
Expand All @@ -402,33 +403,37 @@ function CraftSim.ReagentData:HasEnough(multiplier, crafterUID)

if self.recipeData.isEnchantingRecipe then
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, CraftSim.CONST
.ENCHANTING_VELLUM_ID)
.ENCHANTING_VELLUM_ID, true)
hasVellumIfneeded = itemCount >= multiplier
end


return hasRequiredReagents and hasOptionalReagents and hasSparkReagent and hasVellumIfneeded
end

function CraftSim.ReagentData:GetCraftableAmount(crafterUID)
---@param crafterUID CrafterUID
---@param excludeWarbankTemp? boolean
function CraftSim.ReagentData:GetCraftableAmount(crafterUID, excludeWarbankTemp)
local print = CraftSim.DEBUG:SetDebugPrint(CraftSim.CONST.DEBUG_IDS.CRAFTQ)

print("getCraftable amount", false, true)

local currentMinimumReagentFit = math.huge
for _, requiredReagent in pairs(self.requiredReagents) do
if not requiredReagent:IsOrderReagentIn(self.recipeData) then
if not requiredReagent:HasItems(1, crafterUID) then
if not requiredReagent:HasItems(1, crafterUID, excludeWarbankTemp) then
return 0
end
currentMinimumReagentFit = math.min(requiredReagent:HasQuantityXTimes(crafterUID), currentMinimumReagentFit)
currentMinimumReagentFit = math.min(requiredReagent:HasQuantityXTimes(crafterUID, excludeWarbankTemp),
currentMinimumReagentFit)
end
end

if self:HasSparkSlot() then
if self.sparkReagentSlot.activeReagent then
if not self.sparkReagentSlot.activeReagent:IsOrderReagentIn(self.recipeData) then
currentMinimumReagentFit = math.min(self.sparkReagentSlot:HasQuantityXTimes(crafterUID),
currentMinimumReagentFit = math.min(
self.sparkReagentSlot:HasQuantityXTimes(crafterUID, excludeWarbankTemp),
currentMinimumReagentFit)
end
else
Expand All @@ -443,10 +448,11 @@ function CraftSim.ReagentData:GetCraftableAmount(crafterUID)
local optionalReagentSlots = GUTIL:Concat({ self.optionalReagentSlots, self.finishingReagentSlots })
for _, optionalReagentSlot in pairs(optionalReagentSlots) do
if optionalReagentSlot.activeReagent and not optionalReagentSlot.activeReagent:IsOrderReagentIn(self.recipeData) then
if not optionalReagentSlot:HasItem(1, crafterUID) then
if not optionalReagentSlot:HasItem(1, crafterUID, excludeWarbankTemp) then
return 0
end
currentMinimumReagentFitOptional = math.min(optionalReagentSlot:HasQuantityXTimes(crafterUID),
currentMinimumReagentFitOptional = math.min(
optionalReagentSlot:HasQuantityXTimes(crafterUID, excludeWarbankTemp),
currentMinimumReagentFitOptional)
end
end
Expand All @@ -455,7 +461,7 @@ function CraftSim.ReagentData:GetCraftableAmount(crafterUID)
local vellumMinimumFit = math.huge
if self.recipeData.isEnchantingRecipe then
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, CraftSim.CONST
.ENCHANTING_VELLUM_ID)
.ENCHANTING_VELLUM_ID, true)
vellumMinimumFit = itemCount
print("minimum vellum fit: " .. tostring(vellumMinimumFit))
end
Expand Down Expand Up @@ -484,6 +490,10 @@ function CraftSim.ReagentData:GetTooltipText(multiplier, crafterUID)
local iconSize = 25
local text = ""

-- TODO: Remove after 11.0.5
local excludeWarbankTemp = self.recipeData.orderData and
CraftSim.DB.OPTIONS:Get("CRAFTQUEUE_PATRON_ORDERS_EXCLUDE_WARBANK")

for _, requiredReagent in pairs(self.requiredReagents) do
local reagentIcon = requiredReagent.items[1].item:GetItemIcon()
local inlineIcon = GUTIL:IconToText(reagentIcon, iconSize, iconSize)
Expand All @@ -496,7 +506,7 @@ function CraftSim.ReagentData:GetTooltipText(multiplier, crafterUID)
if reagentItem.originalItem then
itemID = reagentItem.originalItem:GetItemID()
end
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID)
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID, excludeWarbankTemp)
local quantityText = f.r(tostring(requiredReagent.requiredQuantity * multiplier) ..
"(" .. tostring(itemCount) .. ")")

Expand Down Expand Up @@ -530,7 +540,7 @@ function CraftSim.ReagentData:GetTooltipText(multiplier, crafterUID)
if reagentItem.originalItem then
itemID = reagentItem.originalItem:GetItemID()
end
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID)
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID, excludeWarbankTemp)
local quantityText = f.r(
tostring(reagentItem.quantity * multiplier) .. "(" .. tostring(itemCount) .. ")")

Expand Down Expand Up @@ -566,7 +576,7 @@ function CraftSim.ReagentData:GetTooltipText(multiplier, crafterUID)
local inlineIcon = GUTIL:IconToText(reagentIcon, iconSize, iconSize)
text = text .. inlineIcon
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID,
itemID)
itemID, excludeWarbankTemp)
local requiredQuantity = self.sparkReagentSlot.maxQuantity * multiplier
local quantityText = f.r(tostring(requiredQuantity) .. "(" .. tostring(itemCount) .. ")")
if itemCount >= requiredQuantity or isOrderReagent then
Expand Down Expand Up @@ -597,7 +607,7 @@ function CraftSim.ReagentData:GetTooltipText(multiplier, crafterUID)
local inlineIcon = GUTIL:IconToText(reagentIcon, iconSize, iconSize)
text = text .. inlineIcon
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID,
optionalReagentSlot.activeReagent.item:GetItemID())
optionalReagentSlot.activeReagent.item:GetItemID(), excludeWarbankTemp)
local quantityText = f.r(tostring(multiplier) .. "(" .. tostring(itemCount) .. ")")
if itemCount >= multiplier then
quantityText = f.g(tostring(multiplier))
Expand Down
5 changes: 3 additions & 2 deletions Classes/ReagentItem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ end
--- returns wether the player has enough of the given required item's allocations (times the multiplier) for crafting
---@param multiplier number? default: 1
---@param crafterUID string
function CraftSim.ReagentItem:HasItem(multiplier, crafterUID)
---@param excludeWarbankTemp? boolean
function CraftSim.ReagentItem:HasItem(multiplier, crafterUID, excludeWarbankTemp)
multiplier = multiplier or 1
if not self.item then
return false
end
-- only count the item actually used in the recipe (originalItem if we have one)
-- in the case of e.g. rimefin tuna we want to count the non frosted one only (will be the original)
local itemID = (self.originalItem and self.originalItem:GetItemID()) or self.item:GetItemID()
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID)
local itemCount = CraftSim.CRAFTQ:GetItemCountFromCraftQueueCache(crafterUID, itemID, excludeWarbankTemp)
return itemCount >= (self.quantity * multiplier)
end

Expand Down
7 changes: 5 additions & 2 deletions Classes/RecipeData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1253,10 +1253,13 @@ function CraftSim.RecipeData:CanCraft(amount)
return false, 0
end

-- TODO: Remove after 11.0.5
local excludeWarbankTemp = self.orderData and CraftSim.DB.OPTIONS:Get("CRAFTQUEUE_PATRON_ORDERS_EXCLUDE_WARBANK")

-- check amount of reagents in players inventory + bank
local hasEnoughReagents = self.reagentData:HasEnough(amount, self:GetCrafterUID())
local hasEnoughReagents = self.reagentData:HasEnough(amount, self:GetCrafterUID(), excludeWarbankTemp)

local craftAbleAmount = self.reagentData:GetCraftableAmount(self:GetCrafterUID())
local craftAbleAmount = self.reagentData:GetCraftableAmount(self:GetCrafterUID(), excludeWarbankTemp)

local isChargeRecipe = self.cooldownData.maxCharges > 0

Expand Down
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 the war within gold making
## Author: genju
## Version: 18.2.9.2
## Version: 18.3.0
## X-Curse-Project-ID: 705015
## X-Wago-ID: 0mNwaPKo
## X-WoWI-ID: 26519
Expand Down
6 changes: 6 additions & 0 deletions Data/News.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ function CraftSim.NEWS:GET_NEWS(itemMap)
local news = {
f.bb(" Hello and thank you for using CraftSim!\n"),
f.bb(" ( You are awesome! )"),
newP("18.3.0"),
f.s .. f.bb("CraftQueue Patron Orders"),
f.a .. "- Added a temporary option to ignore warbank reagents",
f.a .. " as a workaround to the warbank issue until 11.0.5",
f.a .. "- Changed 'Ignore' Options to 'Include' options",
f.a .. " and added augment rune and acuity",
newP("18.2.9"),
f.P .. f.bb("Recipe Scan"),
f.a .. "- Concentration Optimization now frame distributed",
Expand Down
Loading

0 comments on commit 68a2481

Please sign in to comment.