annotate ProspectMe_Tooltip.lua @ 40:97fe62d4385d Prospect Me 2

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