annotate ProspectMe_Tooltip.lua @ 47:4c684bba5777 Prospect Me 2

Added color coding to the "Times Prospected" count to give an idea of the quality of the dataset. Red for low, yellow for ok, green for great!
author Vynn <mischivin@gmail.com>
date Thu, 17 Nov 2016 01:07:51 -0500
parents a35539b8e151
children a2fc078e4d70
rev   line source
mischivin@36 1 local Quality = { [0] = "Junk", [1]= "Common", [2] = "Uncommon", [3] = "Rare", [4] = "Epic", }
Vynn@0 2
mischivin@36 3 local function Initialize()
mischivin@36 4 ProspectMe.FormatPrice = function (value)
Vynn@0 5
mischivin@36 6 local GSC_GOLD="ffffd100"
mischivin@36 7 local GSC_SILVER="ffe6e6e6"
mischivin@36 8 local GSC_COPPER="ffc8602c"
Vynn@0 9
mischivin@36 10 local g, s, c
mischivin@36 11 local digits = 0
mischivin@36 12 local gsc
Vynn@0 13
mischivin@36 14 g = math.floor(value/10000)
mischivin@36 15 s = math.fmod(math.floor(value/100),100)
mischivin@36 16 c = math.fmod(value,100)
Vynn@0 17
Vynn@0 18
mischivin@36 19 digits = math.floor(math.log10(value)+1)
Vynn@0 20
mischivin@36 21 if ( digits < 3 ) then
mischivin@36 22 gsc = string.format(" |c%s%2d|r", GSC_COPPER, c)
mischivin@36 23 elseif ( digits < 5 ) then
mischivin@36 24 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c)
mischivin@36 25 elseif ( digits < 7 ) then
mischivin@36 26 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s)
mischivin@36 27 elseif ( digits < 9 ) then
mischivin@36 28 gsc = string.format("|c%s%5d|r", GSC_GOLD, g)
mischivin@36 29 else
mischivin@36 30 gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000)
mischivin@36 31 end
mischivin@36 32
mischivin@36 33 return gsc
Vynn@0 34 end
Vynn@0 35
mischivin@36 36 ProspectMe.GetReturn = function (containerID)
mischivin@36 37 local averageReturn = 0
mischivin@36 38 if ProspectMe.Results[containerID].TimesProspected > 0 then
mischivin@36 39 for itemID, num in pairs(ProspectMe.Results[containerID]) do
mischivin@36 40 if itemID ~= "TimesProspected" then
mischivin@36 41 averageReturn = averageReturn + ProspectMe.GetItemValue(itemID) * num
mischivin@36 42 end
Vynn@0 43 end
mischivin@36 44 averageReturn = averageReturn/ProspectMe.Results[containerID].TimesProspected
Vynn@0 45 end
mischivin@36 46 return tonumber(string.format("%.0f", averageReturn))
Vynn@0 47 end
Vynn@0 48 end
Vynn@0 49
Vynn@0 50 local cleared = true
Vynn@0 51 local function OnTooltipCleared(self)
Vynn@0 52 cleared = true
Vynn@0 53 end
Vynn@0 54
Vynn@0 55 local function OnTooltipSetItem(self)
Vynn@0 56 if cleared then
mischivin@39 57 local tooltipLink = select(2, self:GetItem())
mischivin@39 58 local spellid = select(3, self:GetSpell())
mischivin@39 59 local item = nil
mischivin@39 60 if spellid == 225902 then
mischivin@39 61 item = 123918
mischivin@39 62 elseif spellid == 225904 then
mischivin@39 63 item = 123919
mischivin@39 64 elseif spellid == 210116 then
mischivin@39 65 item = 128304
mischivin@39 66 elseif tooltipLink then
mischivin@39 67 item = tonumber(tooltipLink:match("Hitem:(%d+)"))
mischivin@39 68 spellid = nil
mischivin@39 69 else
mischivin@39 70 item = nil
mischivin@39 71 spellid = nil
mischivin@39 72 end
mischivin@39 73 if item then
mischivin@36 74 if ProspectMe.Results[item] then
mischivin@36 75 local price = ProspectMe.GetItemValue(item)
mischivin@36 76 local lifetimeReturn = ProspectMe.GetReturn(item)
mischivin@41 77 local subclass = select(7,GetItemInfo(item))
mischivin@47 78 local ctp = price * 5
Vynn@0 79 --NumofEachQuality, Percent of Each Quality
Vynn@0 80 self:AddLine(" ")
mischivin@47 81 local color
mischivin@47 82 if ProspectMe.Results[item].TimesProspected < 100 then
mischivin@47 83 color = "|cffff0000"
mischivin@47 84 elseif ProspectMe.Results[item].TimesProspected < 200 then
mischivin@47 85 color = "|cffffff00"
mischivin@47 86 else
mischivin@47 87 color = "|cff00ff00"
mischivin@47 88 end
mischivin@46 89 if spellid == 225902 or spellid == 225904 or subclass == ProspectMe.Vars.ORE then
mischivin@47 90 self:AddDoubleLine("Prospect Me","Times Prospected: " .. color .. ProspectMe.Results[item].TimesProspected,0.5,1,0.5,0.5,0.5,1)
mischivin@46 91 elseif spellid == 210116 or subclass == ProspectMe.Vars.HERB then
mischivin@47 92 self:AddDoubleLine("Prospect Me","Times Milled: " .. color .. ProspectMe.Results[item].TimesProspected,0.5,1,0.5,0.5,0.5,1)
mischivin@42 93 else
mischivin@47 94 self:AddDoubleLine("Prospect Me","Times Processed: " .. color .. ProspectMe.Results[item].TimesProspected,0.5,1,0.5,0.5,0.5,1)
mischivin@42 95 end
mischivin@39 96 if spellid then
mischivin@39 97 ctp = price * 20
mischivin@39 98 lifetimeReturn = lifetimeReturn * 4
mischivin@39 99 end
mischivin@39 100 if spellid == 225902 or spellid == 225904 then
mischivin@39 101 self:AddDoubleLine("Cost to Mass Prospect: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@39 102 elseif spellid == 210116 then
mischivin@39 103 self:AddDoubleLine("Cost to Mass Mill: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@46 104 elseif subclass == ProspectMe.Vars.ORE then
mischivin@39 105 self:AddDoubleLine("Cost to Prospect: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@46 106 elseif subclass == ProspectMe.Vars.HERB then
mischivin@39 107 self:AddDoubleLine("Cost to Mill: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@39 108 else
mischivin@39 109 self:AddDoubleLine("Cost to Process: " .. ProspectMe.FormatPrice(ctp), " Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn))
mischivin@39 110 end
mischivin@46 111 self:AddLine(" ")
mischivin@47 112 local profit = lifetimeReturn - ctp
mischivin@47 113 local margin = (lifetimeReturn / ctp * 100) - 100
mischivin@46 114 if margin > 30 then
mischivin@47 115 self:AddLine("Estimated Profit: " .. ProspectMe.FormatPrice(profit) .. "\nMargin: |cff00ff00" .. string.format("[%.1f%%]", margin))
mischivin@46 116 elseif margin > 15 then
mischivin@47 117 self:AddLine("Estimated Profit: " .. ProspectMe.FormatPrice(profit) .. "\nMargin: |cffffff00" .. string.format("[%.1f%%]", margin))
mischivin@46 118 elseif margin > 0 then
mischivin@47 119 self:AddLine("Estimated Profit: " .. ProspectMe.FormatPrice(profit) .. "\nMargin: |cffff0000" .. string.format("[%.1f%%]", margin))
Vynn@0 120 else
Vynn@0 121 self:AddLine("No profit to be made",1,0,0)
Vynn@0 122 end
mischivin@46 123 self:AddLine(" ")
mischivin@36 124 local t
mischivin@36 125 if IsAltKeyDown() == ProspectMe.Config.PerSession then
mischivin@36 126 t = ProspectMe.Results
mischivin@36 127 self:AddDoubleLine("Lifetime Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
mischivin@36 128 else
mischivin@36 129 t = ProspectMe.Session
mischivin@36 130 self:AddDoubleLine("Session Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5)
mischivin@36 131 end
mischivin@36 132 if t[item] then
mischivin@36 133 for q = 7, 0, -1 do
mischivin@36 134 for result, num in pairs(t[item]) do
mischivin@36 135 if result ~= "TimesProspected" and select(3, GetItemInfo(result)) == q and ProspectMe.Config.ShowQualities[Quality[q]] then
mischivin@36 136 local p, n = "", ""
mischivin@36 137 if ProspectMe.Config.ShowPercent then
mischivin@36 138 p = num/t[item].TimesProspected*100
mischivin@36 139 if p < 10 then
mischivin@36 140 p = string.format("[%.1f%%]", p)
Vynn@0 141 else
mischivin@36 142 p = string.format("[%.0f%%]", p)
Vynn@0 143 end
mischivin@36 144 else
mischivin@36 145 p = ""
Vynn@0 146 end
mischivin@36 147 if ProspectMe.Config.ShowNumber then
mischivin@36 148 n = "[" .. num .. "]"
mischivin@36 149 else
mischivin@36 150 n = ""
mischivin@36 151 end
mischivin@36 152 self:AddDoubleLine(p .. select(2, GetItemInfo(result)) .. n, ProspectMe.FormatPrice(ProspectMe.GetItemValue(result)))
Vynn@0 153 end
Vynn@0 154 end
Vynn@0 155 end
mischivin@39 156 --self:AddLine(" ")
Vynn@0 157 end
Vynn@0 158 end
Vynn@0 159 cleared = true
Vynn@0 160 end
Vynn@0 161 end
Vynn@0 162 end
Vynn@0 163
Vynn@0 164 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
mischivin@36 165 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
mischivin@36 166 ItemRefTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
mischivin@36 167 ItemRefTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
mischivin@36 168
mischivin@36 169 local frame = CreateFrame("FRAME", "ProspectMe_Value")
mischivin@36 170 frame:RegisterEvent("VARIABLES_LOADED")
mischivin@36 171 --frame:SetScript("OnEvent", EventHandler)
mischivin@36 172 frame:SetScript("OnEvent", Initialize)