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