view ProspectMe_Tooltip.lua @ 46:a35539b8e151 Prospect Me 2

Updated the Tooltip to display a color coded profit margin. Red < 15%, Yellow <30%, Green >30%. Also added support for previous globalized constants
author Vynn <mischivin@gmail.com>
date Wed, 16 Nov 2016 00:47:56 -0500
parents 35c84e420f4a
children 4c684bba5777
line wrap: on
line source
local Quality = { [0] = "Junk", [1]= "Common", [2] = "Uncommon", [3] = "Rare", [4] = "Epic", }

local function Initialize()
	ProspectMe.FormatPrice = function (value)

		local GSC_GOLD="ffffd100"
		local GSC_SILVER="ffe6e6e6"
		local GSC_COPPER="ffc8602c"

		local g, s, c
		local digits = 0
		local gsc

		g = math.floor(value/10000)
		s = math.fmod(math.floor(value/100),100)
		c = math.fmod(value,100)


		digits = math.floor(math.log10(value)+1)

		if ( digits < 3 ) then
			gsc = string.format("   |c%s%2d|r",  GSC_COPPER, c)
		elseif ( digits < 5 ) then
			gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c)
		elseif ( digits < 7 ) then
			gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s)
		elseif ( digits < 9 ) then
			gsc = string.format("|c%s%5d|r", GSC_GOLD, g)
		else
			gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000)
		end

		return gsc
	end

	ProspectMe.GetReturn = function (containerID)
		local averageReturn = 0
		if ProspectMe.Results[containerID].TimesProspected > 0 then
			for itemID, num in pairs(ProspectMe.Results[containerID]) do
				if itemID ~= "TimesProspected" then
					averageReturn = averageReturn + ProspectMe.GetItemValue(itemID) * num 
				end
			end
			averageReturn = averageReturn/ProspectMe.Results[containerID].TimesProspected
		end
			return tonumber(string.format("%.0f", averageReturn))
	end
end

local cleared = true
local function OnTooltipCleared(self)
   cleared = true   
end
 
local function OnTooltipSetItem(self)
	if cleared then
		local tooltipLink = select(2, self:GetItem())
		local spellid = select(3, self:GetSpell())
		local item = nil
		if spellid == 225902 then
			item = 123918
		elseif spellid == 225904 then
			item = 123919
		elseif spellid == 210116 then
			item = 128304
		elseif tooltipLink then 
			item = tonumber(tooltipLink:match("Hitem:(%d+)"))
			spellid = nil
		else
			item = nil
			spellid = nil
		end
		if item then
			if ProspectMe.Results[item] then
				local price = ProspectMe.GetItemValue(item)
				local lifetimeReturn = ProspectMe.GetReturn(item)
				local subclass = select(7,GetItemInfo(item))
				--NumofEachQuality, Percent of Each Quality
				self:AddLine(" ")
				self:AddLine("Prospect Me",0.5,1,0.5)
				if spellid == 225902 or spellid == 225904 or subclass == ProspectMe.Vars.ORE then
					self:AddLine("Times Prospected: " .. ProspectMe.Results[item].TimesProspected)
				elseif spellid == 210116 or subclass == ProspectMe.Vars.HERB then
					self:AddLine("Times Milled: " .. ProspectMe.Results[item].TimesProspected)
				else
					self:AddLine("Times Processed: " .. ProspectMe.Results[item].TimesProspected)
				end
				if spellid then
					ctp = price * 20
					lifetimeReturn = lifetimeReturn * 4
				else
					ctp = price * 5
				end
				if spellid == 225902 or spellid == 225904 then
					self:AddDoubleLine("Cost to Mass Prospect: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
				elseif spellid == 210116 then
					self:AddDoubleLine("Cost to Mass Mill: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
				elseif subclass == ProspectMe.Vars.ORE then
					self:AddDoubleLine("Cost to Prospect: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
				elseif subclass == ProspectMe.Vars.HERB then
					self:AddDoubleLine("Cost to Mill: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
				else
					self:AddDoubleLine("Cost to Process: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
				end
				self:AddLine(" ")
				local margin = (lifetimeReturn/ctp*100)-100
				if margin > 30 then
					self:AddLine("Estimated Profit: " .. ProspectMe.FormatPrice(lifetimeReturn-(ctp)) .. "\nMargin:  |cff00ff00" .. string.format("[%.1f%%]", margin))
				elseif margin > 15 then
					self:AddLine("Estimated Profit: " .. ProspectMe.FormatPrice(lifetimeReturn-(ctp)) .. "\nMargin:  |cffffff00" .. string.format("[%.1f%%]", margin))
				elseif margin > 0 then
					self:AddLine("Estimated Profit: " .. ProspectMe.FormatPrice(lifetimeReturn-(ctp)) .. "\nMargin:  |cffff0000" .. string.format("[%.1f%%]", margin))
				else
					self:AddLine("No profit to be made",1,0,0)
				end
				self:AddLine(" ")
				local t
				if IsAltKeyDown() == ProspectMe.Config.PerSession then
					t = ProspectMe.Results
					self:AddDoubleLine("Lifetime Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
				else
					t = ProspectMe.Session
					self:AddDoubleLine("Session Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
				end
				if t[item] then
					for q = 7, 0, -1 do
						for result, num in pairs(t[item]) do 
							if result ~= "TimesProspected" and select(3, GetItemInfo(result)) == q and ProspectMe.Config.ShowQualities[Quality[q]] then
								local p, n = "", ""
								if ProspectMe.Config.ShowPercent then
									p = num/t[item].TimesProspected*100
									if p < 10 then
										p = string.format("[%.1f%%]", p)
									else
										p = string.format("[%.0f%%]", p)
									end
								else
									p = ""
								end
								if ProspectMe.Config.ShowNumber then
									n = "[" .. num .. "]"
								else
									n = ""
								end
								self:AddDoubleLine(p .. select(2, GetItemInfo(result)) .. n, ProspectMe.FormatPrice(ProspectMe.GetItemValue(result)))
							end
						end
					end
					--self:AddLine(" ")
				end
			end
			cleared = true
		end
	end
end
 
GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
ItemRefTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
ItemRefTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)

local frame = CreateFrame("FRAME", "ProspectMe_Value")
frame:RegisterEvent("VARIABLES_LOADED")
--frame:SetScript("OnEvent", EventHandler)
frame:SetScript("OnEvent", Initialize)