Mercurial > wow > prospect-me
comparison ProspectMe.lua @ 0:69b46322ff1b v1.2.1-Alpha
Updated Prospect me for initial client v6.0.3 support. Warning, there may be bugs!
author | Vynn |
---|---|
date | Mon, 15 Dec 2014 22:51:49 -0500 |
parents | |
children | 61b9ea84a44c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:69b46322ff1b |
---|---|
1 local PROSPECT_ID = 31252 | |
2 local MILLING_ID = 51005 | |
3 local PROSPECT = GetSpellInfo(PROSPECT_ID) | |
4 local MILLING = GetSpellInfo(MILLING_ID) | |
5 local containerID, containerLink = nil, nil | |
6 local getContents = false | |
7 | |
8 local function PM_Init() | |
9 if not PM_ResultsTable then | |
10 PM_ResultsTable = {} | |
11 PM_ItemTable = {} | |
12 end | |
13 PM_SessionTable = {} | |
14 end | |
15 | |
16 local function CreateTableEntry(id) | |
17 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(id) | |
18 PM_ItemTable[id] = {} | |
19 PM_ItemTable[id].name = name | |
20 PM_ItemTable[id].link = link | |
21 PM_ItemTable[id].quality = quality | |
22 PM_ItemTable[id].iLevel = iLevel | |
23 PM_ItemTable[id].reqLevel = reqLevel | |
24 PM_ItemTable[id].class = class | |
25 PM_ItemTable[id].subclass = subclass | |
26 PM_ItemTable[id].maxStack = maxStack | |
27 PM_ItemTable[id].equipSlot = equipSlot | |
28 PM_ItemTable[id].texture = texture | |
29 PM_ItemTable[id].vendorPrice = vendorPrice | |
30 PM_ItemTable[id].price = PM_GetItemValue(id) | |
31 end | |
32 | |
33 --debugging function to print the databases results | |
34 function PM_PrintResults() | |
35 for container, k in pairs(PM_ResultsTable) do | |
36 print(PM_ItemTable[container].link, PM_ResultsTable[container].timesProspected) | |
37 for i, num in pairs(k) do | |
38 if i ~= "timesProspected" then | |
39 print(PM_ItemTable[i].link, num) | |
40 end | |
41 end | |
42 end | |
43 end | |
44 | |
45 local function GetResults() | |
46 --Create tables for the Container if it doesn't exist yet | |
47 if not PM_ResultsTable[containerID] then | |
48 PM_ResultsTable[containerID] = {timesProspected = 0} | |
49 CreateTableEntry(containerID) | |
50 end | |
51 | |
52 --Creates a session table entry, this will be cleared on log out/UI reload | |
53 if not PM_SessionTable[containerID] then | |
54 PM_SessionTable[containerID] = {timesProspected = 0} | |
55 end | |
56 | |
57 for i = 1, GetNumLootItems() do | |
58 local itemID = GetLootSlotLink(i):match("Hitem:(%d+)") | |
59 local quantity = select(3, GetLootSlotInfo(i)) | |
60 if not PM_ItemTable[itemID] then | |
61 CreateTableEntry(itemID) | |
62 end | |
63 if PM_ResultsTable[containerID][itemID] then | |
64 PM_ResultsTable[containerID][itemID] = PM_ResultsTable[containerID][itemID] + quantity | |
65 else | |
66 PM_ResultsTable[containerID][itemID] = quantity | |
67 end | |
68 if PM_SessionTable[containerID][itemID] then | |
69 PM_SessionTable[containerID][itemID] = PM_SessionTable[containerID][itemID] + quantity | |
70 else | |
71 PM_SessionTable[containerID][itemID] = quantity | |
72 end | |
73 end | |
74 | |
75 PM_ResultsTable[containerID].timesProspected = PM_ResultsTable[containerID].timesProspected + 1 | |
76 PM_SessionTable[containerID].timesProspected = PM_SessionTable[containerID].timesProspected + 1 | |
77 end | |
78 | |
79 local function EventHandler(self, event, ...) | |
80 if event == "VARIABLES_LOADED" then | |
81 PM_Init() | |
82 PM_UpdateValues() | |
83 end | |
84 if event == "UNIT_SPELLCAST_INTERRUPTED" then | |
85 local unitID, spell, rank = ... | |
86 if unitID == "player" and spell == PROSPECT then | |
87 getContents = false | |
88 end | |
89 end | |
90 if event == "LOOT_OPENED" then | |
91 if getContents then | |
92 GetResults() | |
93 end | |
94 end | |
95 if event == "LOOT_CLOSED" then | |
96 getContents = false | |
97 end | |
98 if event == "AUCTION_ITEM_LIST_UPDATE" then | |
99 PM_UpdateValues() | |
100 end | |
101 end | |
102 | |
103 local frame = CreateFrame("FRAME", "PM_Frame") | |
104 frame:RegisterEvent("VARIABLES_LOADED") | |
105 frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") | |
106 frame:RegisterEvent("LOOT_OPENED") | |
107 frame:RegisterEvent("LOOT_CLOSED") | |
108 frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE") | |
109 frame:SetScript("OnEvent", EventHandler) | |
110 | |
111 hooksecurefunc("UseContainerItem", function(...) | |
112 if getContents then | |
113 containerLink = GetContainerItemLink(...) | |
114 containerID = containerLink:match("Hitem:(%d+)") | |
115 end | |
116 | |
117 end) | |
118 | |
119 hooksecurefunc("UseItemByName", function(itemName) | |
120 if getContents then | |
121 containerLink = select(2, GetItemInfo(itemName)) | |
122 containerID = containerLink:match("Hitem:(%d+)") | |
123 end | |
124 end) | |
125 | |
126 hooksecurefunc("SpellTargetItem", function(itemName) | |
127 if getContents then | |
128 containerLink = select(2, GetItemInfo(itemName)) | |
129 containerID = containerLink:match("Hitem:(%d+)") | |
130 end | |
131 end) | |
132 | |
133 hooksecurefunc("CastSpell", function(...) | |
134 local spellName = GetSpellInfo(...) | |
135 if spellName:lower() == PROSPECT:lower() or spellName:lower() == MILLING:lower() then | |
136 getContents = true | |
137 end | |
138 end) | |
139 | |
140 hooksecurefunc("CastSpellByID", function(spellID) | |
141 if spellID == PROSPECT_ID or spellID == MILLING_ID then | |
142 getContents = true | |
143 end | |
144 end) | |
145 | |
146 hooksecurefunc("UseAction", function(actionID) | |
147 local spellID = select(2, GetActionInfo(actionID)) | |
148 if spellID == PROSPECT_ID or spellID == MILLING_ID then | |
149 getContents = true | |
150 end | |
151 end) | |
152 | |
153 hooksecurefunc("CastSpellByName", function(spellName, onSelf) | |
154 if spellName:lower() == PROSPECT:lower() or spellName:lower() == MILLING:lower() then | |
155 getContents = true | |
156 end | |
157 end) |