annotate ProspectMe.lua @ 32:fc13da07d8e4 Prospect Me 2

Cleaned up some code, added comments, refined ProspectMe:AddEntry()
author Vynn <mischivin@gmail.com>
date Tue, 08 Nov 2016 02:36:30 -0500
parents c11461d5095c
children 31cf11210635
rev   line source
mischivin@32 1 --[[
mischivin@32 2 Check for Saved Variables, if they don't exist, set defaults.
mischivin@32 3 ]]
mischivin@31 4 if not ProspectMe then
mischivin@31 5 ProspectMe = {
mischivin@31 6 Config = {
mischivin@31 7 ShowQualities = {
mischivin@31 8 junk = false
mischivin@31 9 common = false,
mischivin@31 10 uncommon = true,
mischivin@31 11 rare = true,
mischivin@31 12 epic = true,
mischivin@31 13 }
mischivin@31 14 PerSession = false
mischivin@31 15 ShowPercent = true
mischivin@31 16 ShowNumber = true
mischivin@31 17 }
mischivin@31 18
mischivin@31 19 }
mischivin@31 20 end
mischivin@31 21
mischivin@32 22 --[[
mischivin@32 23 Creates an table entry, if it does not exist, and adds results to the entry.
mischivin@32 24 Expects the Item ID and pairs of arguments in table with key being the results ItemID and value being the quantity returned
mischivin@32 25 ]]
mischivin@32 26 local function ProspectMe:AddEntry (ItemID, ...)
mischivin@32 27 if not ProspectMe[ItemID] then
mischivin@32 28 ProspectMe[ItemID] = {}
mischivin@31 29 end
mischivin@32 30 for k, v in pairs arg do
mischivin@32 31 if not ProspectMe[ItemID][k] then
mischivin@32 32 ProspectMe[ItemID][k] = v
mischivin@32 33 else
mischivin@32 34 ProspectMe[ItemID][k] = ProspectMe[ItemID][k] = v
mischivin@32 35 end
mischivin@32 36 end
mischivin@32 37 return true
mischivin@32 38 end
mischivin@31 39
mischivin@31 40
Vynn@0 41 local PROSPECT_ID = 31252
Vynn@0 42 local MILLING_ID = 51005
mischivin@11 43 local MASS_PROSPECT_FELSLATE_ID = 225902
mischivin@11 44 local MASS_PROSPECT_LEYSTONE_ID = 225902
mischivin@11 45 local MASS_MILLING_YSERALLINE_ID = 210116
mischivin@14 46 local PROSPECT = GetSpellInfo(PROSPECT_ID):lower()
mischivin@14 47 local MILLING = GetSpellInfo(MILLING_ID):lower()
mischivin@14 48 local MASS_PROSPECT_FELSLATE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower()
mischivin@14 49 local MASS_PROSPECT_LEYSTONE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower()
mischivin@14 50 local MASS_MILLING_YSERALLINE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower()
Vynn@0 51 local containerID, containerLink = nil, nil
Vynn@0 52 local getContents = false
mischivin@11 53 local bulkMultiplier = 1 --This will be used for mass prospecting/milling in Legion
Vynn@0 54
Vynn@0 55 local function CreateTableEntry(id)
Vynn@0 56 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(id)
Vynn@0 57 PM_ItemTable[id] = {}
Vynn@0 58 PM_ItemTable[id].name = name
Vynn@0 59 PM_ItemTable[id].link = link
Vynn@0 60 PM_ItemTable[id].quality = quality
Vynn@0 61 PM_ItemTable[id].iLevel = iLevel
Vynn@0 62 PM_ItemTable[id].reqLevel = reqLevel
Vynn@0 63 PM_ItemTable[id].class = class
Vynn@0 64 PM_ItemTable[id].subclass = subclass
Vynn@0 65 PM_ItemTable[id].maxStack = maxStack
Vynn@0 66 PM_ItemTable[id].equipSlot = equipSlot
Vynn@0 67 PM_ItemTable[id].texture = texture
Vynn@0 68 PM_ItemTable[id].vendorPrice = vendorPrice
Vynn@0 69 PM_ItemTable[id].price = PM_GetItemValue(id)
Vynn@0 70 end
Vynn@0 71
mischivin@21 72 local function PM_Init()
mischivin@21 73 if not PM_ResultsTable then
mischivin@21 74 PM_ResultsTable = {}
mischivin@21 75 PM_ItemTable = {}
mischivin@21 76 end
mischivin@21 77 PM_SessionTable = {}
mischivin@21 78 PM_GemCleanup() --Run cleanup on excess Gem Chips created in v1.7.0.2 and earlier
mischivin@21 79 end
mischivin@21 80
Vynn@0 81 --debugging function to print the databases results
Vynn@0 82 function PM_PrintResults()
Vynn@0 83 for container, k in pairs(PM_ResultsTable) do
Vynn@0 84 print(PM_ItemTable[container].link, PM_ResultsTable[container].timesProspected)
Vynn@0 85 for i, num in pairs(k) do
Vynn@0 86 if i ~= "timesProspected" then
Vynn@0 87 print(PM_ItemTable[i].link, num)
Vynn@0 88 end
Vynn@0 89 end
Vynn@0 90 end
Vynn@0 91 end
Vynn@0 92
Vynn@0 93 local function GetResults()
Vynn@0 94 --Create tables for the Container if it doesn't exist yet
Vynn@0 95 if not PM_ResultsTable[containerID] then
Vynn@0 96 PM_ResultsTable[containerID] = {timesProspected = 0}
Vynn@0 97 CreateTableEntry(containerID)
Vynn@0 98 end
Vynn@0 99
Vynn@0 100 --Creates a session table entry, this will be cleared on log out/UI reload
Vynn@0 101 if not PM_SessionTable[containerID] then
Vynn@0 102 PM_SessionTable[containerID] = {timesProspected = 0}
Vynn@0 103 end
mischivin@18 104
Vynn@0 105 for i = 1, GetNumLootItems() do
Vynn@0 106 local itemID = GetLootSlotLink(i):match("Hitem:(%d+)")
mischivin@18 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
mischivin@18 108 itemID = "129100"
mischivin@18 109 end
Vynn@0 110 local quantity = select(3, GetLootSlotInfo(i))
Vynn@0 111 if not PM_ItemTable[itemID] then
Vynn@0 112 CreateTableEntry(itemID)
Vynn@0 113 end
Vynn@0 114 if PM_ResultsTable[containerID][itemID] then
Vynn@0 115 PM_ResultsTable[containerID][itemID] = PM_ResultsTable[containerID][itemID] + quantity
Vynn@0 116 else
Vynn@0 117 PM_ResultsTable[containerID][itemID] = quantity
Vynn@0 118 end
Vynn@0 119 if PM_SessionTable[containerID][itemID] then
Vynn@0 120 PM_SessionTable[containerID][itemID] = PM_SessionTable[containerID][itemID] + quantity
Vynn@0 121 else
Vynn@0 122 PM_SessionTable[containerID][itemID] = quantity
Vynn@0 123 end
Vynn@0 124 end
Vynn@0 125
mischivin@11 126 PM_ResultsTable[containerID].timesProspected = PM_ResultsTable[containerID].timesProspected + bulkMultiplier
mischivin@11 127 PM_SessionTable[containerID].timesProspected = PM_SessionTable[containerID].timesProspected + bulkMultiplier
Vynn@0 128 end
Vynn@0 129
Vynn@0 130 local function EventHandler(self, event, ...)
Vynn@0 131 if event == "VARIABLES_LOADED" then
Vynn@0 132 PM_Init()
Vynn@0 133 PM_UpdateValues()
Vynn@0 134 end
Vynn@0 135 if event == "UNIT_SPELLCAST_INTERRUPTED" then
Vynn@0 136 local unitID, spell, rank = ...
mischivin@14 137 spell = spell:lower()
mischivin@12 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
Vynn@0 139 getContents = false
Vynn@0 140 end
Vynn@0 141 end
Vynn@0 142 if event == "LOOT_OPENED" then
Vynn@0 143 if getContents then
Vynn@0 144 GetResults()
Vynn@0 145 end
Vynn@0 146 end
Vynn@0 147 if event == "LOOT_CLOSED" then
Vynn@0 148 getContents = false
Vynn@0 149 end
Vynn@0 150 if event == "AUCTION_ITEM_LIST_UPDATE" then
Vynn@0 151 PM_UpdateValues()
Vynn@0 152 end
Vynn@0 153 end
Vynn@0 154
Vynn@0 155 local frame = CreateFrame("FRAME", "PM_Frame")
Vynn@0 156 frame:RegisterEvent("VARIABLES_LOADED")
Vynn@0 157 frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
Vynn@0 158 frame:RegisterEvent("LOOT_OPENED")
Vynn@0 159 frame:RegisterEvent("LOOT_CLOSED")
Vynn@0 160 frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
Vynn@0 161 frame:SetScript("OnEvent", EventHandler)
Vynn@0 162
Vynn@0 163 hooksecurefunc("UseContainerItem", function(...)
Vynn@0 164 if getContents then
Vynn@0 165 containerLink = GetContainerItemLink(...)
Vynn@0 166 containerID = containerLink:match("Hitem:(%d+)")
Vynn@0 167 end
Vynn@0 168
Vynn@0 169 end)
Vynn@0 170
Vynn@0 171 hooksecurefunc("UseItemByName", function(itemName)
Vynn@0 172 if getContents then
Vynn@0 173 containerLink = select(2, GetItemInfo(itemName))
Vynn@0 174 containerID = containerLink:match("Hitem:(%d+)")
Vynn@0 175 end
Vynn@0 176 end)
Vynn@0 177
Vynn@0 178 hooksecurefunc("SpellTargetItem", function(itemName)
Vynn@0 179 if getContents then
Vynn@0 180 containerLink = select(2, GetItemInfo(itemName))
Vynn@0 181 containerID = containerLink:match("Hitem:(%d+)")
Vynn@0 182 end
Vynn@0 183 end)
Vynn@0 184
Vynn@0 185 hooksecurefunc("CastSpell", function(...)
mischivin@14 186 local spellName = GetSpellInfo(...):lower()
mischivin@14 187 if spellName == PROSPECT or spellName == MILLING or spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then
Vynn@0 188 getContents = true
mischivin@14 189 if spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then
mischivin@11 190 bulkMultiplier = 4
mischivin@11 191 else
mischivin@11 192 bulkMultiplier = 1
mischivin@11 193 end
Vynn@0 194 end
Vynn@0 195 end)
Vynn@0 196
Vynn@0 197 hooksecurefunc("CastSpellByID", function(spellID)
mischivin@11 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
Vynn@0 199 getContents = true
mischivin@11 200 if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then
mischivin@11 201 bulkMultiplier = 4
mischivin@11 202 else
mischivin@11 203 bulkMultiplier = 1
mischivin@11 204 end
Vynn@0 205 end
Vynn@0 206 end)
Vynn@0 207
Vynn@0 208 hooksecurefunc("UseAction", function(actionID)
Vynn@0 209 local spellID = select(2, GetActionInfo(actionID))
mischivin@11 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
Vynn@0 211 getContents = true
mischivin@11 212 if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then
mischivin@11 213 bulkMultiplier = 4
mischivin@11 214 else
mischivin@11 215 bulkMultiplier = 1
mischivin@11 216 end
Vynn@0 217 end
Vynn@0 218 end)
Vynn@0 219
Vynn@0 220 hooksecurefunc("CastSpellByName", function(spellName, onSelf)
mischivin@14 221 spellName = spellName:lower()
mischivin@14 222 if spellName == PROSPECT or spellName == MILLING or spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then
Vynn@0 223 getContents = true
mischivin@14 224 if spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then
mischivin@11 225 bulkMultiplier = 4
mischivin@11 226 else
mischivin@11 227 bulkMultiplier = 1
mischivin@11 228 end
Vynn@0 229 end
Vynn@0 230 end)