diff --git a/TradeSkillMaster/Core/Prices.lua b/TradeSkillMaster/Core/Prices.lua index 041d782..42921b0 100644 --- a/TradeSkillMaster/Core/Prices.lua +++ b/TradeSkillMaster/Core/Prices.lua @@ -28,6 +28,14 @@ local MATH_FUNCTIONS = { ["max"] = "_max", ["first"] = "_first", ["check"] = "_check", + ["ifgt"] = "_ifgt", + ["ifgte"] = "_ifgte", + ["iflt"] = "_iflt", + ["iflte"] = "_iflte", + ["ifeq"] = "_ifeq", + ["round"] = "_round", + ["roundup"] = "_roundup", + ["rounddown"] = "_rounddown", } function TSMAPI:GetPriceSources() @@ -68,7 +76,7 @@ end -- validates a price string that was passed into TSMAPI:ParseCustomPrice -local supportedOperators = { "+", "-", "*", "/" } +local supportedOperators = { "+", "-", "*", "/", "^" } local function ParsePriceString(str, badPriceSource) if tonumber(str) then return function() return tonumber(str) end @@ -396,6 +404,67 @@ local function ParsePriceString(str, badPriceSource) elseValue = elseValue or NAN return check > 0 and ifValue or elseValue end + local function _ifgt(...) + local a, b, c, d = ... + if isNAN(a) or isNAN(b) then return NAN end + if a > b then + return (c and not isNAN(c)) and c or NAN + end + return (d and not isNAN(d)) and d or NAN + end + local function _ifgte(...) + local a, b, c, d = ... + if isNAN(a) or isNAN(b) then return NAN end + if a >= b then + return (c and not isNAN(c)) and c or NAN + end + return (d and not isNAN(d)) and d or NAN + end + local function _iflt(...) + local a, b, c, d = ... + if isNAN(a) or isNAN(b) then return NAN end + if a < b then + return (c and not isNAN(c)) and c or NAN + end + return (d and not isNAN(d)) and d or NAN + end + local function _iflte(...) + local a, b, c, d = ... + if isNAN(a) or isNAN(b) then return NAN end + if a <= b then + return (c and not isNAN(c)) and c or NAN + end + return (d and not isNAN(d)) and d or NAN + end + local function _ifeq(...) + local a, b, c, d = ... + if isNAN(a) or isNAN(b) then return NAN end + if a == b then + return (c and not isNAN(c)) and c or NAN + end + return (d and not isNAN(d)) and d or NAN + end + local function _round(...) + local a, b = ... + if isNAN(a) then return NAN end + b = b or 1 + if isNAN(b) or b == 0 then return NAN end + return floor(a / b + 0.5) * b + end + local function _roundup(...) + local a, b = ... + if isNAN(a) then return NAN end + b = b or 1 + if isNAN(b) or b == 0 then return NAN end + return ceil(a / b) * b + end + local function _rounddown(...) + local a, b = ... + if isNAN(a) then return NAN end + b = b or 1 + if isNAN(b) or b == 0 then return NAN end + return floor(a / b) * b + end local values = {} for i, params in ipairs({%s}) do local itemString, key, extraParam = unpack(params) @@ -455,4 +524,4 @@ function TSMAPI:GetCustomPriceSourceValue(itemString, key) local func = TSMAPI:ParseCustomPrice(source) if not func then return end return func(itemString) -end \ No newline at end of file +end diff --git a/TradeSkillMaster_Accounting/Locale/enUS.lua b/TradeSkillMaster_Accounting/Locale/enUS.lua index 84ec7d4..b7d735c 100644 --- a/TradeSkillMaster_Accounting/Locale/enUS.lua +++ b/TradeSkillMaster_Accounting/Locale/enUS.lua @@ -81,6 +81,8 @@ L["Market Value Source"] = true L["Market Value"] = true L["Max Buy Price"] = true L["Max Sell Price"] = true +L["Min Buy Price"] = true +L["Min Sell Price"] = true L["None"] = true L["Options"] = true L["Other Income"] = true @@ -150,4 +152,4 @@ L["YY/MM/DD HH:MM"] = true L["Yesterday"] = true L["You can use the options below to clear old data. It is recommened to occasionally clear your old data to keep Accounting running smoothly. Select the minimum number of days old to be removed in the dropdown, then click the button.\n\nNOTE: There is no confirmation."] = true L["_ Hr _ Min ago"] = true -L["none"] = true \ No newline at end of file +L["none"] = true diff --git a/TradeSkillMaster_Accounting/TradeSkillMaster_Accounting.lua b/TradeSkillMaster_Accounting/TradeSkillMaster_Accounting.lua index fa4778b..546d1f9 100644 --- a/TradeSkillMaster_Accounting/TradeSkillMaster_Accounting.lua +++ b/TradeSkillMaster_Accounting/TradeSkillMaster_Accounting.lua @@ -127,6 +127,8 @@ function TSM:RegisterModule() { key = "avgBuy", label = L["Avg Buy Price"], callback = "GetAvgBuyPrice" }, { key = "maxSell", label = L["Max Sell Price"], callback = "GetMaxSellPrice" }, { key = "maxBuy", label = L["Max Buy Price"], callback = "GetMaxBuyPrice" }, + { key = "minSell", label = L["Min Sell Price"], callback = "GetMinSellPrice" }, + { key = "minBuy", label = L["Min Buy Price"], callback = "GetMinBuyPrice" }, } TSM.tooltipOptions = { callback = "GUI:LoadTooltipOptions" } @@ -496,6 +498,22 @@ function TSM:GetMaxSellPrice(itemString) return TSM.cache[itemString].maxSellPrice end +function TSM:GetMinSellPrice(itemString) + itemString = TSMAPI:GetItemString(select(2, TSMAPI:GetSafeItemInfo(itemString))) + if not (itemString and TSM.items[itemString] and #TSM.items[itemString].sales > 0) then return end + TSM.cache[itemString] = TSM.cache[itemString] or {} + + if not TSM.cache[itemString].minSellPrice then + local minPrice = math.huge + for _, record in ipairs(TSM.items[itemString].sales) do + minPrice = min(minPrice, record.copper) + end + TSM.cache[itemString].minSellPrice = minPrice + end + + return TSM.cache[itemString].minSellPrice +end + function TSM:GetMaxBuyPrice(itemString) itemString = TSMAPI:GetItemString(select(2, TSMAPI:GetSafeItemInfo(itemString))) if not (itemString and TSM.items[itemString] and #TSM.items[itemString].buys > 0) then return end @@ -512,9 +530,25 @@ function TSM:GetMaxBuyPrice(itemString) return TSM.cache[itemString].maxBuyPrice end +function TSM:GetMinBuyPrice(itemString) + itemString = TSMAPI:GetItemString(select(2, TSMAPI:GetSafeItemInfo(itemString))) + if not (itemString and TSM.items[itemString] and #TSM.items[itemString].buys > 0) then return end + TSM.cache[itemString] = TSM.cache[itemString] or {} + + if not TSM.cache[itemString].minBuyPrice then + local minPrice = math.huge + for _, record in ipairs(TSM.items[itemString].buys) do + minPrice = min(minPrice, record.copper) + end + TSM.cache[itemString].minBuyPrice = minPrice + end + + return TSM.cache[itemString].minBuyPrice +end + function TSM:Round(value, sig) sig = sig or 1 local gold = value / sig gold = floor(gold + 0.5) return gold * sig -end \ No newline at end of file +end