annotate ProspectMe.lua @ 46:a35539b8e151 Prospect Me 2

Updated the Tooltip to display a color coded profit margin. Red < 15%, Yellow <30%, Green >30%. Also added support for previous globalized constants
author Vynn <mischivin@gmail.com>
date Wed, 16 Nov 2016 00:47:56 -0500
parents b267cddd6496
children f9b6c0305908
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@31 58 }
mischivin@33 59 end
mischivin@33 60 if not ProspectMe.Results then
mischivin@33 61 ProspectMe.Results = {}
mischivin@33 62 end
mischivin@33 63 ProspectMe.Session = {}
mischivin@33 64
mischivin@45 65 --[[
mischivin@45 66 Sets Global Constants
mischivin@45 67 ]]
mischivin@45 68 if not ProspectMe.Vars then
mischivin@45 69 ProspectMe.Vars = {}
mischivin@45 70 end
mischivin@45 71 ProspectMe.Vars.ORE = select(7,GetItemInfo(123918)) -- Get Ore Subclass from a known quantity (leystone ore)
mischivin@45 72 ProspectMe.Vars.HERB = select(7,GetItemInfo(128304)) -- Get Herb Subclass from a known quantity (yseralline seed)
mischivin@45 73
mischivin@45 74
mischivin@33 75 ProspectMe.Debug = function (...)
mischivin@33 76 for k, v in pairs(...) do
mischivin@33 77 print("key: " .. k " | value: " .. v)
mischivin@33 78 end
mischivin@33 79 end
mischivin@33 80
mischivin@33 81 --[[
mischivin@33 82 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 83 ]]
mischivin@33 84 ProspectMe.BeginCapture = function (event, ...)
mischivin@33 85 local unit, spell = ...
mischivin@33 86 if unit == "player" then
mischivin@33 87 if spell == PROSPECT or spell == MILLING then
mischivin@33 88 MassMultiplier = 1
mischivin@33 89 ParseResults = true
mischivin@33 90 elseif spell == MASS_PROSPECT_FELSLATE or spell == MASS_PROSPECT_LEYSTONE or spell == MASS_MILLING_YSERALLINE then
mischivin@33 91 MassMultiplier = 4
mischivin@33 92 ParseResults = true
mischivin@43 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.
mischivin@33 94 if spell == MASS_PROSPECT_FELSLATE then
mischivin@33 95 ContainerID = 123919
mischivin@33 96 end
mischivin@33 97 if spell == MASS_PROSPECT_LEYSTONE then
mischivin@33 98 ContainerID = 123918
mischivin@33 99 end
mischivin@33 100 if spell == MASS_MILLING_YSERALLINE then
mischivin@33 101 ContainerID = 128304
mischivin@33 102 end
mischivin@33 103 else
mischivin@33 104 ParseResults = false
mischivin@33 105 end
mischivin@33 106 end
mischivin@33 107 Results = {}
mischivin@33 108 end
mischivin@33 109
mischivin@33 110 --[[
mischivin@33 111 Ends the capture process and resets variables so they're ready for use the next time.
mischivin@33 112 ]]
mischivin@33 113 ProspectMe.EndCapture = function (event, ...)
mischivin@33 114 if ParseResults then
mischivin@33 115 ProspectMe.AddEntry(ContainerID, MassMultiplier, Results)
mischivin@33 116 end
mischivin@33 117 ParseResults = false
mischivin@33 118 MassMultiplier = 1
mischivin@33 119 ContainerID = nil
mischivin@33 120 end
mischivin@33 121
mischivin@33 122 --[[
mischivin@33 123 Creates an table entry, if it does not exist, and adds results to the entry.
mischivin@33 124 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 125 ]]
mischivin@33 126 ProspectMe.AddEntry = function (ItemID, BatchSize, ResultsTable)
mischivin@33 127 if not ProspectMe.Results[ItemID] then
mischivin@33 128 ProspectMe.Results[ItemID] = { TimesProspected = 0 }
mischivin@33 129 end
mischivin@33 130 if not ProspectMe.Session[ItemID] then
mischivin@33 131 ProspectMe.Session[ItemID] = { TimesProspected = 0 }
mischivin@33 132 end
mischivin@33 133 for k, v in pairs(ResultsTable) do
mischivin@33 134 if not ProspectMe.Results[ItemID][k] then
mischivin@33 135 ProspectMe.Results[ItemID][k] = v
mischivin@33 136 else
mischivin@33 137 ProspectMe.Results[ItemID][k] = ProspectMe.Results[ItemID][k] + v
mischivin@33 138 end
mischivin@33 139 if not ProspectMe.Session[ItemID][k] then
mischivin@33 140 ProspectMe.Session[ItemID][k] = v
mischivin@33 141 else
mischivin@33 142 ProspectMe.Session[ItemID][k] = ProspectMe.Session[ItemID][k] + v
mischivin@33 143 end
mischivin@33 144 end
mischivin@33 145 ProspectMe.Results[ItemID].TimesProspected = ProspectMe.Results[ItemID].TimesProspected + BatchSize
mischivin@33 146 ProspectMe.Session[ItemID].TimesProspected = ProspectMe.Session[ItemID].TimesProspected + BatchSize
mischivin@33 147
mischivin@33 148 end
mischivin@33 149
mischivin@33 150 --[[
mischivin@33 151 Parses the results of the spellcast or loot containerand returns a table of those results in key/value pairs of item/quantity.
mischivin@33 152 Expects an event and a set of arguments if the event has them.
mischivin@33 153 ]]
mischivin@33 154 ProspectMe.GetResults = function (event, ...)
mischivin@33 155 if event == "CHAT_MSG_LOOT" then
mischivin@33 156 local ItemID = tonumber((...):match("Hitem:(%d+)"))
mischivin@33 157 if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then
mischivin@33 158 ItemID = 129100
mischivin@33 159 end
mischivin@33 160 local Quantity = tonumber((...):match("|h|rx(%d+)"))
mischivin@33 161 if Quantity == nil then
mischivin@33 162 Quantity = 1
mischivin@33 163 end
mischivin@33 164 Results[ItemID] = Quantity
mischivin@33 165 end
mischivin@33 166 if event == "LOOT_OPENED" then
mischivin@33 167 for i = 1, GetNumLootItems() do
mischivin@33 168 local ItemID = tonumber(GetLootSlotLink(i):match("Hitem:(%d+)"))
mischivin@33 169 if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then
mischivin@33 170 ItemID = 129100
mischivin@33 171 end
mischivin@33 172 local Quantity = select(3, GetLootSlotInfo(i))
mischivin@33 173 Results[ItemID] = Quantity
mischivin@33 174 end
mischivin@33 175 end
mischivin@33 176 end
mischivin@31 177 end
mischivin@31 178
mischivin@33 179
mischivin@33 180 local function EventHandler(self, event, ...)
mischivin@33 181 if event == "VARIABLES_LOADED" then
mischivin@33 182 Initialize()
mischivin@31 183 end
mischivin@33 184 if event == "UNIT_SPELLCAST_SUCCEEDED" then
mischivin@33 185 local unit, spell = ...
mischivin@33 186 if unit == "player" and VALIDSPELLS[spell] then
mischivin@33 187 ProspectMe.BeginCapture(event, ...)
mischivin@32 188 end
mischivin@32 189 end
mischivin@33 190 if event == "CHAT_MSG_LOOT" or "LOOT_OPENED" then
mischivin@33 191 if ParseResults then
mischivin@33 192 ProspectMe.GetResults(event, ...)
mischivin@33 193 end
mischivin@33 194 ProspectMeDebug = Results
mischivin@21 195 end
mischivin@33 196 if event == "ITEM_LOCKED" then
mischivin@40 197 if ParseResults then
mischivin@40 198 local bag, slot = ...
mischivin@40 199 ContainerID = select(10, GetContainerItemInfo(bag, slot))
mischivin@40 200 end
mischivin@33 201 end
mischivin@33 202 if event == "TRADE_SKILL_LIST_UPDATE" or event == "LOOT_CLOSED" then
mischivin@33 203 if ParseResults then
mischivin@33 204 ProspectMe.EndCapture()
Vynn@0 205 end
Vynn@0 206 end
Vynn@0 207 end
Vynn@0 208
mischivin@33 209 local frame = CreateFrame("FRAME", "ProspectMe")
Vynn@0 210 frame:RegisterEvent("VARIABLES_LOADED")
mischivin@33 211 frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
mischivin@33 212 frame:RegisterEvent("CHAT_MSG_LOOT")
Vynn@0 213 frame:RegisterEvent("LOOT_OPENED")
mischivin@33 214 frame:RegisterEvent("ITEM_LOCKED")
Vynn@0 215 frame:RegisterEvent("LOOT_CLOSED")
mischivin@33 216 frame:RegisterEvent("TRADE_SKILL_LIST_UPDATE")
Vynn@0 217 frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
mischivin@33 218 frame:SetScript("OnEvent", EventHandler)