Mercurial > wow > prospect-me
comparison ProspectMe.lua @ 33:31cf11210635 Prospect Me 2
ProspectMe core updated for version 2.0
author | Vynn <mischivin@gmail.com> |
---|---|
date | Thu, 10 Nov 2016 12:24:54 -0500 |
parents | fc13da07d8e4 |
children | 97fe62d4385d |
comparison
equal
deleted
inserted
replaced
32:fc13da07d8e4 | 33:31cf11210635 |
---|---|
1 --[[ | 1 --[[ |
2 Check for Saved Variables, if they don't exist, set defaults. | 2 Event Flow --> UNIT_SPELLCAST_SUCCEDED --> Prospecting --> Set Multiplier --> LOOT_OPENED --> parse --> ITEM_LOCKED (Get Item ID) --> LOOT_CLOSED (Add Results) |
3 ]] | 3 --> Mass Prospecting (Get Item ID from spell) --> Set Multiplier --> CHAT_MSG_LOOT --> parse --> TRADE_SKILL_UPDATE (Add Results) |
4 if not ProspectMe then | 4 |
5 ProspectMe = { | 5 ]] |
6 Config = { | 6 |
7 ShowQualities = { | 7 --[[ |
8 junk = false | 8 Declarations of constants. |
9 common = false, | 9 ]] |
10 uncommon = true, | 10 |
11 rare = true, | 11 local PROSPECT_SPELLID = 31252 |
12 epic = true, | 12 local MILLING_SPELLID = 51005 |
13 } | 13 local MASS_PROSPECT_FELSLATE_SPELLID = 225904 |
14 PerSession = false | 14 local MASS_PROSPECT_LEYSTONE_SPELLID = 225902 |
15 ShowPercent = true | 15 local MASS_MILLING_YSERALLINE_SPELLID = 210116 |
16 ShowNumber = true | 16 local PROSPECT = GetSpellInfo(PROSPECT_SPELLID) |
17 local MILLING = GetSpellInfo(MILLING_SPELLID) | |
18 local MASS_PROSPECT_FELSLATE = GetSpellInfo(MASS_PROSPECT_FELSLATE_SPELLID) | |
19 local MASS_PROSPECT_LEYSTONE = GetSpellInfo(MASS_PROSPECT_LEYSTONE_SPELLID) | |
20 local MASS_MILLING_YSERALLINE = GetSpellInfo(MASS_MILLING_YSERALLINE_SPELLID) | |
21 | |
22 local ORE = select(7,GetItemInfo(123918)) -- Get Ore Subclass from a known quantity (leystone ore) | |
23 local HERB = select(7,GetItemInfo(128304)) -- Get Herb Subclass from a known quantity (yseralline seed) | |
24 | |
25 local VALIDSPELLS = { | |
26 [PROSPECT] = true, | |
27 [MILLING] = true, | |
28 [MASS_PROSPECT_LEYSTONE] = true, | |
29 [MASS_PROSPECT_FELSLATE] = true, | |
30 [MASS_MILLING_YSERALLINE] = true, | |
31 } | |
32 | |
33 --[[ | |
34 Local Variables | |
35 ]] | |
36 local ContainerID = nil | |
37 local Table = {} | |
38 local ParseResults = false | |
39 local MassMultiplier = 1 | |
40 local Results = {} | |
41 | |
42 --[[ | |
43 Initialize - Dets default config variables if they don't exist, ensures all our functions exist and are included in the table in their current form. | |
44 ]] | |
45 local function Initialize() | |
46 --[[ | |
47 Sets Default Variables | |
48 ]] | |
49 if not ProspectMe.Config then | |
50 ProspectMe.Config = { | |
51 ShowQualities = { | |
52 Junk = false, | |
53 Common = false, | |
54 Uncommon = true, | |
55 Rare = true, | |
56 Epic = true, | |
57 }, | |
58 PerSession = false, | |
59 ShowPercent = true, | |
60 ShowNumber = true, | |
17 } | 61 } |
18 | 62 end |
19 } | 63 if not ProspectMe.Results then |
64 ProspectMe.Results = {} | |
65 end | |
66 ProspectMe.Session = {} | |
67 | |
68 ProspectMe.Debug = function (...) | |
69 for k, v in pairs(...) do | |
70 print("key: " .. k " | value: " .. v) | |
71 end | |
72 end | |
73 | |
74 --[[ | |
75 Begins the capture process, sets variables where we have them. Prospecting and Milling (non MASS) require an extra step to get the ContainerID | |
76 ]] | |
77 ProspectMe.BeginCapture = function (event, ...) | |
78 local unit, spell = ... | |
79 if unit == "player" then | |
80 if spell == PROSPECT or spell == MILLING then | |
81 MassMultiplier = 1 | |
82 ParseResults = true | |
83 elseif spell == MASS_PROSPECT_FELSLATE or spell == MASS_PROSPECT_LEYSTONE or spell == MASS_MILLING_YSERALLINE then | |
84 MassMultiplier = 4 | |
85 ParseResults = true | |
86 if spell == MASS_PROSPECT_FELSLATE then | |
87 ContainerID = 123919 | |
88 end | |
89 if spell == MASS_PROSPECT_LEYSTONE then | |
90 ContainerID = 123918 | |
91 end | |
92 if spell == MASS_MILLING_YSERALLINE then | |
93 ContainerID = 128304 | |
94 end | |
95 else | |
96 ParseResults = false | |
97 end | |
98 end | |
99 Results = {} | |
100 end | |
101 | |
102 --[[ | |
103 Ends the capture process and resets variables so they're ready for use the next time. | |
104 ]] | |
105 ProspectMe.EndCapture = function (event, ...) | |
106 if ParseResults then | |
107 ProspectMe.AddEntry(ContainerID, MassMultiplier, Results) | |
108 end | |
109 ParseResults = false | |
110 MassMultiplier = 1 | |
111 ContainerID = nil | |
112 end | |
113 | |
114 --[[ | |
115 Creates an table entry, if it does not exist, and adds results to the entry. | |
116 Expects the Item ID and pairs of arguments in table with key being the result's ItemID and value being the quantity returned | |
117 ]] | |
118 ProspectMe.AddEntry = function (ItemID, BatchSize, ResultsTable) | |
119 if not ProspectMe.Results[ItemID] then | |
120 ProspectMe.Results[ItemID] = { TimesProspected = 0 } | |
121 end | |
122 if not ProspectMe.Session[ItemID] then | |
123 ProspectMe.Session[ItemID] = { TimesProspected = 0 } | |
124 end | |
125 for k, v in pairs(ResultsTable) do | |
126 if not ProspectMe.Results[ItemID][k] then | |
127 ProspectMe.Results[ItemID][k] = v | |
128 else | |
129 ProspectMe.Results[ItemID][k] = ProspectMe.Results[ItemID][k] + v | |
130 end | |
131 if not ProspectMe.Session[ItemID][k] then | |
132 ProspectMe.Session[ItemID][k] = v | |
133 else | |
134 ProspectMe.Session[ItemID][k] = ProspectMe.Session[ItemID][k] + v | |
135 end | |
136 end | |
137 ProspectMe.Results[ItemID].TimesProspected = ProspectMe.Results[ItemID].TimesProspected + BatchSize | |
138 ProspectMe.Session[ItemID].TimesProspected = ProspectMe.Session[ItemID].TimesProspected + BatchSize | |
139 | |
140 end | |
141 | |
142 --[[ | |
143 Parses the results of the spellcast or loot containerand returns a table of those results in key/value pairs of item/quantity. | |
144 Expects an event and a set of arguments if the event has them. | |
145 ]] | |
146 ProspectMe.GetResults = function (event, ...) | |
147 if event == "CHAT_MSG_LOOT" then | |
148 local ItemID = tonumber((...):match("Hitem:(%d+)")) | |
149 if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then | |
150 ItemID = 129100 | |
151 end | |
152 local Quantity = tonumber((...):match("|h|rx(%d+)")) | |
153 if Quantity == nil then | |
154 Quantity = 1 | |
155 end | |
156 Results[ItemID] = Quantity | |
157 end | |
158 if event == "LOOT_OPENED" then | |
159 for i = 1, GetNumLootItems() do | |
160 local ItemID = tonumber(GetLootSlotLink(i):match("Hitem:(%d+)")) | |
161 if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then | |
162 ItemID = 129100 | |
163 end | |
164 local Quantity = select(3, GetLootSlotInfo(i)) | |
165 Results[ItemID] = Quantity | |
166 end | |
167 end | |
168 end | |
20 end | 169 end |
21 | 170 |
22 --[[ | |
23 Creates an table entry, if it does not exist, and adds results to the entry. | |
24 Expects the Item ID and pairs of arguments in table with key being the results ItemID and value being the quantity returned | |
25 ]] | |
26 local function ProspectMe:AddEntry (ItemID, ...) | |
27 if not ProspectMe[ItemID] then | |
28 ProspectMe[ItemID] = {} | |
29 end | |
30 for k, v in pairs arg do | |
31 if not ProspectMe[ItemID][k] then | |
32 ProspectMe[ItemID][k] = v | |
33 else | |
34 ProspectMe[ItemID][k] = ProspectMe[ItemID][k] = v | |
35 end | |
36 end | |
37 return true | |
38 end | |
39 | |
40 | |
41 local PROSPECT_ID = 31252 | |
42 local MILLING_ID = 51005 | |
43 local MASS_PROSPECT_FELSLATE_ID = 225902 | |
44 local MASS_PROSPECT_LEYSTONE_ID = 225902 | |
45 local MASS_MILLING_YSERALLINE_ID = 210116 | |
46 local PROSPECT = GetSpellInfo(PROSPECT_ID):lower() | |
47 local MILLING = GetSpellInfo(MILLING_ID):lower() | |
48 local MASS_PROSPECT_FELSLATE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower() | |
49 local MASS_PROSPECT_LEYSTONE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower() | |
50 local MASS_MILLING_YSERALLINE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower() | |
51 local containerID, containerLink = nil, nil | |
52 local getContents = false | |
53 local bulkMultiplier = 1 --This will be used for mass prospecting/milling in Legion | |
54 | |
55 local function CreateTableEntry(id) | |
56 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(id) | |
57 PM_ItemTable[id] = {} | |
58 PM_ItemTable[id].name = name | |
59 PM_ItemTable[id].link = link | |
60 PM_ItemTable[id].quality = quality | |
61 PM_ItemTable[id].iLevel = iLevel | |
62 PM_ItemTable[id].reqLevel = reqLevel | |
63 PM_ItemTable[id].class = class | |
64 PM_ItemTable[id].subclass = subclass | |
65 PM_ItemTable[id].maxStack = maxStack | |
66 PM_ItemTable[id].equipSlot = equipSlot | |
67 PM_ItemTable[id].texture = texture | |
68 PM_ItemTable[id].vendorPrice = vendorPrice | |
69 PM_ItemTable[id].price = PM_GetItemValue(id) | |
70 end | |
71 | |
72 local function PM_Init() | |
73 if not PM_ResultsTable then | |
74 PM_ResultsTable = {} | |
75 PM_ItemTable = {} | |
76 end | |
77 PM_SessionTable = {} | |
78 PM_GemCleanup() --Run cleanup on excess Gem Chips created in v1.7.0.2 and earlier | |
79 end | |
80 | |
81 --debugging function to print the databases results | |
82 function PM_PrintResults() | |
83 for container, k in pairs(PM_ResultsTable) do | |
84 print(PM_ItemTable[container].link, PM_ResultsTable[container].timesProspected) | |
85 for i, num in pairs(k) do | |
86 if i ~= "timesProspected" then | |
87 print(PM_ItemTable[i].link, num) | |
88 end | |
89 end | |
90 end | |
91 end | |
92 | |
93 local function GetResults() | |
94 --Create tables for the Container if it doesn't exist yet | |
95 if not PM_ResultsTable[containerID] then | |
96 PM_ResultsTable[containerID] = {timesProspected = 0} | |
97 CreateTableEntry(containerID) | |
98 end | |
99 | |
100 --Creates a session table entry, this will be cleared on log out/UI reload | |
101 if not PM_SessionTable[containerID] then | |
102 PM_SessionTable[containerID] = {timesProspected = 0} | |
103 end | |
104 | |
105 for i = 1, GetNumLootItems() do | |
106 local itemID = GetLootSlotLink(i):match("Hitem:(%d+)") | |
107 if itemID == "129099" or itemID == "130200" or itemID == "130201" or itemID == "130202" or itemID == "130203" or itemID == "130204" then --consolidate Colored Gem Chips into their resulting item | |
108 itemID = "129100" | |
109 end | |
110 local quantity = select(3, GetLootSlotInfo(i)) | |
111 if not PM_ItemTable[itemID] then | |
112 CreateTableEntry(itemID) | |
113 end | |
114 if PM_ResultsTable[containerID][itemID] then | |
115 PM_ResultsTable[containerID][itemID] = PM_ResultsTable[containerID][itemID] + quantity | |
116 else | |
117 PM_ResultsTable[containerID][itemID] = quantity | |
118 end | |
119 if PM_SessionTable[containerID][itemID] then | |
120 PM_SessionTable[containerID][itemID] = PM_SessionTable[containerID][itemID] + quantity | |
121 else | |
122 PM_SessionTable[containerID][itemID] = quantity | |
123 end | |
124 end | |
125 | |
126 PM_ResultsTable[containerID].timesProspected = PM_ResultsTable[containerID].timesProspected + bulkMultiplier | |
127 PM_SessionTable[containerID].timesProspected = PM_SessionTable[containerID].timesProspected + bulkMultiplier | |
128 end | |
129 | 171 |
130 local function EventHandler(self, event, ...) | 172 local function EventHandler(self, event, ...) |
131 if event == "VARIABLES_LOADED" then | 173 if event == "VARIABLES_LOADED" then |
132 PM_Init() | 174 Initialize() |
133 PM_UpdateValues() | 175 end |
134 end | 176 if event == "UNIT_SPELLCAST_SUCCEEDED" then |
135 if event == "UNIT_SPELLCAST_INTERRUPTED" then | 177 local unit, spell = ... |
136 local unitID, spell, rank = ... | 178 if unit == "player" and VALIDSPELLS[spell] then |
137 spell = spell:lower() | 179 ProspectMe.BeginCapture(event, ...) |
138 if unitID == "player" and (spell == PROSPECT or spell == MILLING or spell == MASS_PROSPECT_FELSLATE or spell == MASS_PROSPECT_LEYSTONE or spell == MASS_MILLING_YSERALLINE)then | 180 end |
139 getContents = false | 181 end |
140 end | 182 if event == "CHAT_MSG_LOOT" or "LOOT_OPENED" then |
141 end | 183 if ParseResults then |
142 if event == "LOOT_OPENED" then | 184 ProspectMe.GetResults(event, ...) |
143 if getContents then | 185 end |
144 GetResults() | 186 ProspectMeDebug = Results |
145 end | 187 end |
146 end | 188 if event == "ITEM_LOCKED" then |
147 if event == "LOOT_CLOSED" then | 189 local bag, slot = ... |
148 getContents = false | 190 ContainerID = select(10, GetContainerItemInfo(bag, slot)) |
149 end | 191 end |
150 if event == "AUCTION_ITEM_LIST_UPDATE" then | 192 if event == "TRADE_SKILL_LIST_UPDATE" or event == "LOOT_CLOSED" then |
151 PM_UpdateValues() | 193 if ParseResults then |
194 ProspectMe.EndCapture() | |
195 end | |
152 end | 196 end |
153 end | 197 end |
154 | 198 |
155 local frame = CreateFrame("FRAME", "PM_Frame") | 199 local frame = CreateFrame("FRAME", "ProspectMe") |
156 frame:RegisterEvent("VARIABLES_LOADED") | 200 frame:RegisterEvent("VARIABLES_LOADED") |
157 frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") | 201 frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") |
202 frame:RegisterEvent("CHAT_MSG_LOOT") | |
158 frame:RegisterEvent("LOOT_OPENED") | 203 frame:RegisterEvent("LOOT_OPENED") |
204 frame:RegisterEvent("ITEM_LOCKED") | |
159 frame:RegisterEvent("LOOT_CLOSED") | 205 frame:RegisterEvent("LOOT_CLOSED") |
206 frame:RegisterEvent("TRADE_SKILL_LIST_UPDATE") | |
160 frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE") | 207 frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE") |
161 frame:SetScript("OnEvent", EventHandler) | 208 frame:SetScript("OnEvent", EventHandler) |
162 | |
163 hooksecurefunc("UseContainerItem", function(...) | |
164 if getContents then | |
165 containerLink = GetContainerItemLink(...) | |
166 containerID = containerLink:match("Hitem:(%d+)") | |
167 end | |
168 | |
169 end) | |
170 | |
171 hooksecurefunc("UseItemByName", function(itemName) | |
172 if getContents then | |
173 containerLink = select(2, GetItemInfo(itemName)) | |
174 containerID = containerLink:match("Hitem:(%d+)") | |
175 end | |
176 end) | |
177 | |
178 hooksecurefunc("SpellTargetItem", function(itemName) | |
179 if getContents then | |
180 containerLink = select(2, GetItemInfo(itemName)) | |
181 containerID = containerLink:match("Hitem:(%d+)") | |
182 end | |
183 end) | |
184 | |
185 hooksecurefunc("CastSpell", function(...) | |
186 local spellName = GetSpellInfo(...):lower() | |
187 if spellName == PROSPECT or spellName == MILLING or spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then | |
188 getContents = true | |
189 if spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then | |
190 bulkMultiplier = 4 | |
191 else | |
192 bulkMultiplier = 1 | |
193 end | |
194 end | |
195 end) | |
196 | |
197 hooksecurefunc("CastSpellByID", function(spellID) | |
198 if spellID == PROSPECT_ID or spellID == MILLING_ID or spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then | |
199 getContents = true | |
200 if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then | |
201 bulkMultiplier = 4 | |
202 else | |
203 bulkMultiplier = 1 | |
204 end | |
205 end | |
206 end) | |
207 | |
208 hooksecurefunc("UseAction", function(actionID) | |
209 local spellID = select(2, GetActionInfo(actionID)) | |
210 if spellID == PROSPECT_ID or spellID == MILLING_ID or spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then | |
211 getContents = true | |
212 if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then | |
213 bulkMultiplier = 4 | |
214 else | |
215 bulkMultiplier = 1 | |
216 end | |
217 end | |
218 end) | |
219 | |
220 hooksecurefunc("CastSpellByName", function(spellName, onSelf) | |
221 spellName = spellName:lower() | |
222 if spellName == PROSPECT or spellName == MILLING or spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then | |
223 getContents = true | |
224 if spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then | |
225 bulkMultiplier = 4 | |
226 else | |
227 bulkMultiplier = 1 | |
228 end | |
229 end | |
230 end) |