Mercurial > wow > prospect-me
comparison ProspectMe_Tooltip.lua @ 49:9dae86337a41
Merge Prospect Me v2 Branch to default
author | Vynn <mischivin@gmail.com> |
---|---|
date | Thu, 17 Nov 2016 16:24:48 -0500 |
parents | a2fc078e4d70 |
children | 73a564278360 |
comparison
equal
deleted
inserted
replaced
28:dc1504b4c03c | 49:9dae86337a41 |
---|---|
1 --PM_HERBSUBCLASS = select(6, GetAuctionItemSubClasses(6)) | 1 local Quality = { [0] = "Junk", [1]= "Common", [2] = "Uncommon", [3] = "Rare", [4] = "Epic", } |
2 --PM_ORESUBCLASS = select(4, GetAuctionItemSubClasses(6)) | |
3 | 2 |
4 --Hardcoded until I find a better solution now that GetAuctionItemSubClass() has changed | 3 local function Initialize() |
5 PM_HERBSUBCLASS = "Herb" | 4 ProspectMe.FormatPrice = function (value) |
6 PM_ORESUBCLASS = "Metal & Stone" | |
7 | 5 |
8 function PM_FormatPrice(value) | 6 local GSC_GOLD="ffffd100" |
7 local GSC_SILVER="ffe6e6e6" | |
8 local GSC_COPPER="ffc8602c" | |
9 | 9 |
10 local GSC_GOLD="ffffd100" | 10 local g, s, c |
11 local GSC_SILVER="ffe6e6e6" | 11 local digits = 0 |
12 local GSC_COPPER="ffc8602c" | 12 local gsc |
13 | 13 |
14 local g, s, c | 14 g = math.floor(value/10000) |
15 local digits = 0 | 15 s = math.fmod(math.floor(value/100),100) |
16 local gsc | 16 c = math.fmod(value,100) |
17 | |
18 g = math.floor(value/10000) | |
19 s = math.fmod(math.floor(value/100),100) | |
20 c = math.fmod(value,100) | |
21 | 17 |
22 | 18 |
23 digits = math.floor(math.log10(value)+1) | 19 digits = math.floor(math.log10(value)+1) |
24 | 20 |
25 if ( digits < 3 ) then | 21 if ( digits < 3 ) then |
26 gsc = string.format(" |c%s%2d|r", GSC_COPPER, c) | 22 gsc = string.format(" |c%s%2d|r", GSC_COPPER, c) |
27 elseif ( digits < 5 ) then | 23 elseif ( digits < 5 ) then |
28 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c) | 24 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_SILVER, s, GSC_COPPER, c) |
29 elseif ( digits < 7 ) then | 25 elseif ( digits < 7 ) then |
30 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s) | 26 gsc = string.format("|c%s%2d|r |c%s%02d|r", GSC_GOLD, g, GSC_SILVER, s) |
31 elseif ( digits < 9 ) then | 27 elseif ( digits < 9 ) then |
32 gsc = string.format("|c%s%5d|r", GSC_GOLD, g) | 28 gsc = string.format("|c%s%5d|r", GSC_GOLD, g) |
33 else | 29 else |
34 gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000) | 30 gsc = string.format("|c%s%2.1fk|r", GSC_GOLD, g/1000) |
31 end | |
32 | |
33 return gsc | |
35 end | 34 end |
36 | 35 |
37 return gsc | 36 ProspectMe.GetReturn = function (containerID) |
38 end | 37 local averageReturn = 0 |
39 | 38 if ProspectMe.Results[containerID].TimesProspected > 0 then |
40 function PM_GetReturn(containerID) | 39 for itemID, num in pairs(ProspectMe.Results[containerID]) do |
41 local averageReturn = 0 | 40 if itemID ~= "TimesProspected" then |
42 if PM_ResultsTable[containerID].timesProspected > 0 then | 41 averageReturn = averageReturn + ProspectMe.GetItemValue(itemID) * num |
43 for itemID, num in pairs(PM_ResultsTable[containerID]) do | 42 end |
44 if itemID ~= "timesProspected" then | |
45 averageReturn = averageReturn + PM_ItemTable[itemID].price * num | |
46 end | 43 end |
44 averageReturn = averageReturn/ProspectMe.Results[containerID].TimesProspected | |
47 end | 45 end |
48 averageReturn = averageReturn/PM_ResultsTable[containerID].timesProspected | 46 return tonumber(string.format("%.0f", averageReturn)) |
49 end | 47 end |
50 return tonumber(string.format("%.0f", averageReturn)) | |
51 end | 48 end |
52 | 49 |
53 local cleared = true | 50 local cleared = true |
54 local function OnTooltipCleared(self) | 51 local function OnTooltipCleared(self) |
55 cleared = true | 52 cleared = true |
56 end | 53 end |
57 | 54 |
58 local function OnTooltipSetItem(self) | 55 local function OnTooltipSetItem(self) |
59 if cleared then | 56 if cleared then |
60 local name, tooltipLink = self:GetItem() | 57 local tooltipLink = select(2, self:GetItem()) |
61 if tooltipLink then | 58 local spellid = select(3, self:GetSpell()) |
62 local item = tooltipLink:match("Hitem:(%d+)") | 59 local item = nil |
63 if PM_ResultsTable[item] then | 60 if spellid == 225902 then |
64 local lifetimeReturn = PM_GetReturn(item) | 61 item = 123918 |
62 elseif spellid == 225904 then | |
63 item = 123919 | |
64 elseif spellid == 210116 then | |
65 item = 128304 | |
66 elseif tooltipLink then | |
67 item = tonumber(tooltipLink:match("Hitem:(%d+)")) | |
68 spellid = nil | |
69 else | |
70 item = nil | |
71 spellid = nil | |
72 end | |
73 if item then | |
74 if ProspectMe.Results[item] then | |
75 local price = ProspectMe.GetItemValue(item) | |
76 local lifetimeReturn = ProspectMe.GetReturn(item) | |
77 local subclass = select(7,GetItemInfo(item)) | |
78 local ctp = price * 5 | |
65 --NumofEachQuality, Percent of Each Quality | 79 --NumofEachQuality, Percent of Each Quality |
66 self:AddLine(" ") | 80 self:AddLine(" ") |
67 self:AddLine("Prospect Me",0.5,1,0.5) | 81 local color |
68 -- Subclass Detection is broken in Legion - may need to hard-code this or find another way of getting locatlizes subclass names. | 82 if ProspectMe.Results[item].TimesProspected < 100 then |
69 if PM_ItemTable[item].subclass == PM_ORESUBCLASS then | 83 color = "|cffff0000" |
70 self:AddLine("Times Prospected: " .. PM_ResultsTable[item].timesProspected) | 84 elseif ProspectMe.Results[item].TimesProspected < 200 then |
71 self:AddDoubleLine("Cost to Prospect: " .. PM_FormatPrice(5 * PM_ItemTable[item].price), " Average Return: " .. PM_FormatPrice(PM_GetReturn(item))) | 85 color = "|cffffff00" |
72 elseif PM_ItemTable[item].subclass == PM_HERBSUBCLASS then | 86 else |
73 self:AddLine("Times Milled: " .. PM_ResultsTable[item].timesProspected) | 87 color = "|cff00ff00" |
74 self:AddDoubleLine("Cost to Mill: " .. PM_FormatPrice(5 * PM_ItemTable[item].price), " Average Return: " .. PM_FormatPrice(PM_GetReturn(item))) | |
75 | |
76 end | 88 end |
77 if lifetimeReturn-(5 * PM_ItemTable[item].price) > 0 then | 89 |
78 self:AddLine("Estimated Profit: " .. PM_FormatPrice(lifetimeReturn-(5 * PM_ItemTable[item].price))) | 90 -- SKill Text Block "" |
79 self:AddLine(" ") | 91 local skilltext |
92 if spellid == 225902 or spellid == 225904 or subclass == ProspectMe.Vars.ORE then | |
93 skilltext = "Prospected" | |
94 elseif spellid == 210116 or subclass == ProspectMe.Vars.HERB then | |
95 skilltext = "Milled" | |
80 else | 96 else |
81 self:AddLine("No profit to be made",1,0,0) | 97 skilltext = "Processed" |
82 self:AddLine(" ") | |
83 end | 98 end |
84 if PM_Config.results then | 99 self:AddDoubleLine("Prospect Me","Times " .. skilltext .. ": " .. color .. ProspectMe.Results[item].TimesProspected,1,0.82,0,1,1,1) |
85 local t | 100 self:AddLine(" ") |
86 if IsAltKeyDown() == PM_Config.session then | 101 |
87 t = PM_ResultsTable | 102 -- Economics Text Block |
88 self:AddDoubleLine("Lifetime Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5) | 103 local spelltext |
89 else | 104 if spellid == 225902 or spellid == 225904 then |
90 t = PM_SessionTable | 105 spelltext = "Mass Prospect" |
91 self:AddDoubleLine("Session Results","Hold/Release Alt to toggle",0.5,0.5,1,0.5,0.5,0.5) | 106 elseif spellid == 210116 then |
92 end | 107 spelltext = "Mass Mill" |
93 if t[item] then | 108 elseif subclass == ProspectMe.Vars.ORE then |
94 for q = 7, 0, -1 do | 109 spelltext = "Prospect" |
95 for result, num in pairs(t[item]) do | 110 elseif subclass == ProspectMe.Vars.HERB then |
96 if result ~= "timesProspected" and PM_ItemTable[result].quality == q and PM_Config.qualities[q] then | 111 spelltext = "Mill" |
97 local p, n = "", "" | 112 else |
98 if PM_Config.percent then | 113 spelltext = "Process" |
99 p = num/t[item].timesProspected*100 | 114 end |
100 if p < 10 then | 115 if spellid then |
101 p = string.format("[%.1f%%]", p) | 116 ctp = price * 20 |
102 else | 117 lifetimeReturn = lifetimeReturn * 4 |
103 p = string.format("[%.0f%%]", p) | 118 end |
104 end | 119 local profit = lifetimeReturn - ctp |
120 local margin = (lifetimeReturn / ctp * 100) - 100 | |
121 self:AddDoubleLine("Estimated Profit: " .. ProspectMe.FormatPrice(profit), "Cost to " .. spelltext .. ": " .. ProspectMe.FormatPrice(ctp),1,1,1,1,1,1) | |
122 if margin < 30 then | |
123 color = "|cffffff00" | |
124 elseif margin < 15 then | |
125 color = "|cffff0000" | |
126 else | |
127 color = "|cff00ff00" | |
128 end | |
129 self:AddDoubleLine("Margin: " .. color .. string.format("[%.1f%%]", margin), "Average Return: " .. ProspectMe.FormatPrice(lifetimeReturn),1,1,1,1,1,1) | |
130 self:AddLine(" ") | |
131 | |
132 -- Results Text Block | |
133 local t | |
134 if IsAltKeyDown() == ProspectMe.Config.PerSession then | |
135 t = ProspectMe.Results | |
136 self:AddDoubleLine("Lifetime Results","Hold Alt to display",1,0.82,0,0.5,0.5,0.5) | |
137 else | |
138 t = ProspectMe.Session | |
139 self:AddDoubleLine("Session Results","Hold Alt to display",1,0.82,0,0.5,0.5,0.5) | |
140 end | |
141 if t[item] then | |
142 for q = 7, 0, -1 do | |
143 for result, num in pairs(t[item]) do | |
144 if result ~= "TimesProspected" and select(3, GetItemInfo(result)) == q and ProspectMe.Config.ShowQualities[Quality[q]] then | |
145 local p, n = "", "" | |
146 if ProspectMe.Config.ShowPercent then | |
147 p = num/t[item].TimesProspected*100 | |
148 if p < 10 then | |
149 p = string.format("[%.1f%%]", p) | |
105 else | 150 else |
106 p = "" | 151 p = string.format("[%.0f%%]", p) |
107 end | 152 end |
108 if PM_Config.number then | 153 else |
109 n = "[" .. num .. "]" | 154 p = "" |
110 else | |
111 n = "" | |
112 end | |
113 self:AddDoubleLine(p .. PM_ItemTable[result].link .. n, PM_FormatPrice(PM_ItemTable[result].price)) | |
114 end | 155 end |
156 if ProspectMe.Config.ShowNumber then | |
157 n = "|cffffffffx" .. num | |
158 else | |
159 n = "" | |
160 end | |
161 self:AddDoubleLine(p .. select(2, GetItemInfo(result)) .. n, ProspectMe.FormatPrice(ProspectMe.GetItemValue(result))) | |
115 end | 162 end |
116 end | 163 end |
117 end | 164 end |
118 self:AddLine(" ") | 165 --self:AddLine(" ") |
119 end | 166 end |
120 end | 167 end |
121 cleared = true | 168 cleared = true |
122 end | 169 end |
123 end | 170 end |
124 end | 171 end |
125 | 172 |
126 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared) | 173 GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared) |
127 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem) | 174 GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem) |
175 ItemRefTooltip:HookScript("OnTooltipCleared", OnTooltipCleared) | |
176 ItemRefTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem) | |
177 | |
178 local frame = CreateFrame("FRAME", "ProspectMe_Value") | |
179 frame:RegisterEvent("VARIABLES_LOADED") | |
180 --frame:SetScript("OnEvent", EventHandler) | |
181 frame:SetScript("OnEvent", Initialize) |