annotate ProspectMe.lua @ 71:4949339752fc

Added tag v2.7.1.4 for changeset 2faea51e74be
author Vynn <mischivin@gmail.com>
date Sat, 18 Feb 2017 10:47:40 -0500
parents f9b6c0305908
children
rev   line source
mischivin@32 1 --[[
mischivin@33 2 Event Flow --> UNIT_SPELLCAST_SUCCEDED --> Prospecting --> Set Multiplier --> LOOT_OPENED --> parse --> ITEM_LOCKED (Get Item ID) --> LOOT_CLOSED (Add Results)
mischivin@33 3 --> Mass Prospecting (Get Item ID from spell) --> Set Multiplier --> CHAT_MSG_LOOT --> parse --> TRADE_SKILL_UPDATE (Add Results)
mischivin@33 4
mischivin@32 5 ]]
mischivin@33 6
mischivin@33 7 --[[
mischivin@33 8 Declarations of constants.
mischivin@33 9 ]]
mischivin@33 10
mischivin@33 11 local PROSPECT_SPELLID = 31252
mischivin@33 12 local MILLING_SPELLID = 51005
mischivin@33 13 local MASS_PROSPECT_FELSLATE_SPELLID = 225904
mischivin@33 14 local MASS_PROSPECT_LEYSTONE_SPELLID = 225902
mischivin@33 15 local MASS_MILLING_YSERALLINE_SPELLID = 210116
mischivin@33 16 local PROSPECT = GetSpellInfo(PROSPECT_SPELLID)
mischivin@33 17 local MILLING = GetSpellInfo(MILLING_SPELLID)
mischivin@33 18 local MASS_PROSPECT_FELSLATE = GetSpellInfo(MASS_PROSPECT_FELSLATE_SPELLID)
mischivin@33 19 local MASS_PROSPECT_LEYSTONE = GetSpellInfo(MASS_PROSPECT_LEYSTONE_SPELLID)
mischivin@33 20 local MASS_MILLING_YSERALLINE = GetSpellInfo(MASS_MILLING_YSERALLINE_SPELLID)
mischivin@33 21
mischivin@33 22 local VALIDSPELLS = {
mischivin@33 23 [PROSPECT] = true,
mischivin@33 24 [MILLING] = true,
mischivin@33 25 [MASS_PROSPECT_LEYSTONE] = true,
mischivin@33 26 [MASS_PROSPECT_FELSLATE] = true,
mischivin@33 27 [MASS_MILLING_YSERALLINE] = true,
mischivin@33 28 }
mischivin@33 29
mischivin@33 30 --[[
mischivin@33 31 Local Variables
mischivin@33 32 ]]
mischivin@33 33 local ContainerID = nil
mischivin@33 34 local Table = {}
mischivin@33 35 local ParseResults = false
mischivin@33 36 local MassMultiplier = 1
mischivin@33 37 local Results = {}
mischivin@33 38
mischivin@33 39 --[[
mischivin@33 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.
mischivin@33 41 ]]
mischivin@33 42 local function Initialize()
mischivin@33 43 --[[
mischivin@33 44 Sets Default Variables
mischivin@33 45 ]]
mischivin@33 46 if not ProspectMe.Config then
mischivin@33 47 ProspectMe.Config = {
mischivin@33 48 ShowQualities = {
mischivin@33 49 Junk = false,
mischivin@33 50 Common = false,
mischivin@33 51 Uncommon = true,
mischivin@33 52 Rare = true,
mischivin@33 53 Epic = true,
mischivin@33 54 },
mischivin@33 55 PerSession = false,
mischivin@33 56 ShowPercent = true,
mischivin@33 57 ShowNumber = true,
mischivin@58 58 ShowEconomics = true,
mischivin@31 59 }
mischivin@33 60 end
mischivin@33 61 if not ProspectMe.Results then
mischivin@33 62 ProspectMe.Results = {}
mischivin@33 63 end
mischivin@33 64 ProspectMe.Session = {}
mischivin@33 65
mischivin@45 66 --[[
mischivin@45 67 Sets Global Constants
mischivin@45 68 ]]
mischivin@45 69 if not ProspectMe.Vars then
mischivin@45 70 ProspectMe.Vars = {}
mischivin@45 71 end
mischivin@45 72 ProspectMe.Vars.ORE = select(7,GetItemInfo(123918)) -- Get Ore Subclass from a known quantity (leystone ore)
mischivin@45 73 ProspectMe.Vars.HERB = select(7,GetItemInfo(128304)) -- Get Herb Subclass from a known quantity (yseralline seed)
mischivin@45 74
mischivin@45 75
mischivin@33 76 ProspectMe.Debug = function (...)
mischivin@33 77 for k, v in pairs(...) do
mischivin@33 78 print("key: " .. k " | value: " .. v)
mischivin@33 79 end
mischivin@33 80 end
mischivin@33 81
mischivin@33 82 --[[
mischivin@33 83 Begins the capture process, sets variables where we have them. Prospecting and Milling (non MASS) require an extra step to get the ContainerID
mischivin@33 84 ]]
mischivin@33 85 ProspectMe.BeginCapture = function (event, ...)
mischivin@33 86 local unit, spell = ...
mischivin@33 87 if unit == "player" then
mischivin@33 88 if spell == PROSPECT or spell == MILLING then
mischivin@33 89 MassMultiplier = 1
mischivin@33 90 ParseResults = true
mischivin@33 91 elseif spell == MASS_PROSPECT_FELSLATE or spell == MASS_PROSPECT_LEYSTONE or spell == MASS_MILLING_YSERALLINE then
mischivin@33 92 MassMultiplier = 4
mischivin@33 93 ParseResults = true
mischivin@43 94 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.
mischivin@33 95 if spell == MASS_PROSPECT_FELSLATE then
mischivin@33 96 ContainerID = 123919
mischivin@33 97 end
mischivin@33 98 if spell == MASS_PROSPECT_LEYSTONE then
mischivin@33 99 ContainerID = 123918
mischivin@33 100 end
mischivin@33 101 if spell == MASS_MILLING_YSERALLINE then
mischivin@33 102 ContainerID = 128304
mischivin@33 103 end
mischivin@33 104 else
mischivin@33 105 ParseResults = false
mischivin@33 106 end
mischivin@33 107 end
mischivin@33 108 Results = {}
mischivin@33 109 end
mischivin@33 110
mischivin@33 111 --[[
mischivin@33 112 Ends the capture process and resets variables so they're ready for use the next time.
mischivin@33 113 ]]
mischivin@33 114 ProspectMe.EndCapture = function (event, ...)
mischivin@33 115 if ParseResults then
mischivin@33 116 ProspectMe.AddEntry(ContainerID, MassMultiplier, Results)
mischivin@33 117 end
mischivin@33 118 ParseResults = false
mischivin@33 119 MassMultiplier = 1
mischivin@33 120 ContainerID = nil
mischivin@33 121 end
mischivin@33 122
mischivin@33 123 --[[
mischivin@33 124 Creates an table entry, if it does not exist, and adds results to the entry.
mischivin@33 125 Expects the Item ID and pairs of arguments in table with key being the result's ItemID and value being the quantity returned
mischivin@33 126 ]]
mischivin@33 127 ProspectMe.AddEntry = function (ItemID, BatchSize, ResultsTable)
mischivin@58 128 if ProspectMe.Tables.Ores[ItemID] or ProspectMe.Tables.Herbs[ItemID] then
mischivin@58 129 if not ProspectMe.Results[ItemID] then
mischivin@58 130 ProspectMe.Results[ItemID] = { TimesProspected = 0 }
mischivin@58 131 end
mischivin@58 132 if not ProspectMe.Session[ItemID] then
mischivin@58 133 ProspectMe.Session[ItemID] = { TimesProspected = 0 }
mischivin@58 134 end
mischivin@58 135 for k, v in pairs(ResultsTable) do
mischivin@58 136 if not ProspectMe.Results[ItemID][k] then
mischivin@58 137 ProspectMe.Results[ItemID][k] = v
mischivin@58 138 else
mischivin@58 139 ProspectMe.Results[ItemID][k] = ProspectMe.Results[ItemID][k] + v
mischivin@58 140 end
mischivin@58 141 if not ProspectMe.Session[ItemID][k] then
mischivin@58 142 ProspectMe.Session[ItemID][k] = v
mischivin@58 143 else
mischivin@58 144 ProspectMe.Session[ItemID][k] = ProspectMe.Session[ItemID][k] + v
mischivin@58 145 end
mischivin@58 146 end
mischivin@58 147 ProspectMe.Results[ItemID].TimesProspected = ProspectMe.Results[ItemID].TimesProspected + BatchSize
mischivin@58 148 ProspectMe.Session[ItemID].TimesProspected = ProspectMe.Session[ItemID].TimesProspected + BatchSize
mischivin@58 149 else
mischivin@58 150 print("Attempted to create invalid entry for ID: ", ItemID)
mischivin@33 151 end
mischivin@33 152 end
mischivin@33 153
mischivin@33 154 --[[
mischivin@33 155 Parses the results of the spellcast or loot containerand returns a table of those results in key/value pairs of item/quantity.
mischivin@33 156 Expects an event and a set of arguments if the event has them.
mischivin@33 157 ]]
mischivin@33 158 ProspectMe.GetResults = function (event, ...)
mischivin@33 159 if event == "CHAT_MSG_LOOT" then
mischivin@33 160 local ItemID = tonumber((...):match("Hitem:(%d+)"))
mischivin@33 161 if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then
mischivin@33 162 ItemID = 129100
mischivin@33 163 end
mischivin@33 164 local Quantity = tonumber((...):match("|h|rx(%d+)"))
mischivin@33 165 if Quantity == nil then
mischivin@33 166 Quantity = 1
mischivin@33 167 end
mischivin@33 168 Results[ItemID] = Quantity
mischivin@33 169 end
mischivin@33 170 if event == "LOOT_OPENED" then
mischivin@33 171 for i = 1, GetNumLootItems() do
mischivin@33 172 local ItemID = tonumber(GetLootSlotLink(i):match("Hitem:(%d+)"))
mischivin@33 173 if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then
mischivin@33 174 ItemID = 129100
mischivin@33 175 end
mischivin@33 176 local Quantity = select(3, GetLootSlotInfo(i))
mischivin@33 177 Results[ItemID] = Quantity
mischivin@33 178 end
mischivin@33 179 end
mischivin@33 180 end
mischivin@31 181 end
mischivin@31 182
mischivin@33 183
mischivin@33 184 local function EventHandler(self, event, ...)
mischivin@33 185 if event == "VARIABLES_LOADED" then
mischivin@33 186 Initialize()
mischivin@31 187 end
mischivin@33 188 if event == "UNIT_SPELLCAST_SUCCEEDED" then
mischivin@33 189 local unit, spell = ...
mischivin@33 190 if unit == "player" and VALIDSPELLS[spell] then
mischivin@33 191 ProspectMe.BeginCapture(event, ...)
mischivin@32 192 end
mischivin@32 193 end
mischivin@33 194 if event == "CHAT_MSG_LOOT" or "LOOT_OPENED" then
mischivin@33 195 if ParseResults then
mischivin@33 196 ProspectMe.GetResults(event, ...)
mischivin@33 197 end
mischivin@33 198 ProspectMeDebug = Results
mischivin@21 199 end
mischivin@33 200 if event == "ITEM_LOCKED" then
mischivin@40 201 if ParseResults then
mischivin@40 202 local bag, slot = ...
mischivin@40 203 ContainerID = select(10, GetContainerItemInfo(bag, slot))
mischivin@40 204 end
mischivin@33 205 end
mischivin@33 206 if event == "TRADE_SKILL_LIST_UPDATE" or event == "LOOT_CLOSED" then
mischivin@33 207 if ParseResults then
mischivin@33 208 ProspectMe.EndCapture()
Vynn@0 209 end
Vynn@0 210 end
Vynn@0 211 end
Vynn@0 212
mischivin@33 213 local frame = CreateFrame("FRAME", "ProspectMe")
Vynn@0 214 frame:RegisterEvent("VARIABLES_LOADED")
mischivin@33 215 frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
mischivin@33 216 frame:RegisterEvent("CHAT_MSG_LOOT")
Vynn@0 217 frame:RegisterEvent("LOOT_OPENED")
mischivin@33 218 frame:RegisterEvent("ITEM_LOCKED")
Vynn@0 219 frame:RegisterEvent("LOOT_CLOSED")
mischivin@33 220 frame:RegisterEvent("TRADE_SKILL_LIST_UPDATE")
Vynn@0 221 frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
mischivin@33 222 frame:SetScript("OnEvent", EventHandler)