Mercurial > wow > prospect-me
changeset 33:31cf11210635 Prospect Me 2
ProspectMe core updated for version 2.0
author | Vynn <mischivin@gmail.com> |
---|---|
date | Thu, 10 Nov 2016 12:24:54 -0500 |
parents | fc13da07d8e4 |
children | 761d71cd8989 |
files | ProspectMe.lua |
diffstat | 1 files changed, 191 insertions(+), 213 deletions(-) [+] |
line wrap: on
line diff
--- a/ProspectMe.lua Tue Nov 08 02:36:30 2016 -0500 +++ b/ProspectMe.lua Thu Nov 10 12:24:54 2016 -0500 @@ -1,230 +1,208 @@ --[[ -Check for Saved Variables, if they don't exist, set defaults. +Event Flow --> UNIT_SPELLCAST_SUCCEDED --> Prospecting --> Set Multiplier --> LOOT_OPENED --> parse --> ITEM_LOCKED (Get Item ID) --> LOOT_CLOSED (Add Results) + --> Mass Prospecting (Get Item ID from spell) --> Set Multiplier --> CHAT_MSG_LOOT --> parse --> TRADE_SKILL_UPDATE (Add Results) + ]] -if not ProspectMe then - ProspectMe = { - Config = { - ShowQualities = { - junk = false - common = false, - uncommon = true, - rare = true, - epic = true, - } - PerSession = false - ShowPercent = true - ShowNumber = true + +--[[ +Declarations of constants. +]] + +local PROSPECT_SPELLID = 31252 +local MILLING_SPELLID = 51005 +local MASS_PROSPECT_FELSLATE_SPELLID = 225904 +local MASS_PROSPECT_LEYSTONE_SPELLID = 225902 +local MASS_MILLING_YSERALLINE_SPELLID = 210116 +local PROSPECT = GetSpellInfo(PROSPECT_SPELLID) +local MILLING = GetSpellInfo(MILLING_SPELLID) +local MASS_PROSPECT_FELSLATE = GetSpellInfo(MASS_PROSPECT_FELSLATE_SPELLID) +local MASS_PROSPECT_LEYSTONE = GetSpellInfo(MASS_PROSPECT_LEYSTONE_SPELLID) +local MASS_MILLING_YSERALLINE = GetSpellInfo(MASS_MILLING_YSERALLINE_SPELLID) + +local ORE = select(7,GetItemInfo(123918)) -- Get Ore Subclass from a known quantity (leystone ore) +local HERB = select(7,GetItemInfo(128304)) -- Get Herb Subclass from a known quantity (yseralline seed) + +local VALIDSPELLS = { + [PROSPECT] = true, + [MILLING] = true, + [MASS_PROSPECT_LEYSTONE] = true, + [MASS_PROSPECT_FELSLATE] = true, + [MASS_MILLING_YSERALLINE] = true, +} + +--[[ +Local Variables +]] +local ContainerID = nil +local Table = {} +local ParseResults = false +local MassMultiplier = 1 +local Results = {} + +--[[ +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. +]] +local function Initialize() + --[[ + Sets Default Variables + ]] + if not ProspectMe.Config then + ProspectMe.Config = { + ShowQualities = { + Junk = false, + Common = false, + Uncommon = true, + Rare = true, + Epic = true, + }, + PerSession = false, + ShowPercent = true, + ShowNumber = true, } - - } + end + if not ProspectMe.Results then + ProspectMe.Results = {} + end + ProspectMe.Session = {} + + ProspectMe.Debug = function (...) + for k, v in pairs(...) do + print("key: " .. k " | value: " .. v) + end + end + + --[[ + Begins the capture process, sets variables where we have them. Prospecting and Milling (non MASS) require an extra step to get the ContainerID + ]] + ProspectMe.BeginCapture = function (event, ...) + local unit, spell = ... + if unit == "player" then + if spell == PROSPECT or spell == MILLING then + MassMultiplier = 1 + ParseResults = true + elseif spell == MASS_PROSPECT_FELSLATE or spell == MASS_PROSPECT_LEYSTONE or spell == MASS_MILLING_YSERALLINE then + MassMultiplier = 4 + ParseResults = true + if spell == MASS_PROSPECT_FELSLATE then + ContainerID = 123919 + end + if spell == MASS_PROSPECT_LEYSTONE then + ContainerID = 123918 + end + if spell == MASS_MILLING_YSERALLINE then + ContainerID = 128304 + end + else + ParseResults = false + end + end + Results = {} + end + + --[[ + Ends the capture process and resets variables so they're ready for use the next time. + ]] + ProspectMe.EndCapture = function (event, ...) + if ParseResults then + ProspectMe.AddEntry(ContainerID, MassMultiplier, Results) + end + ParseResults = false + MassMultiplier = 1 + ContainerID = nil + end + + --[[ + Creates an table entry, if it does not exist, and adds results to the entry. + Expects the Item ID and pairs of arguments in table with key being the result's ItemID and value being the quantity returned + ]] + ProspectMe.AddEntry = function (ItemID, BatchSize, ResultsTable) + if not ProspectMe.Results[ItemID] then + ProspectMe.Results[ItemID] = { TimesProspected = 0 } + end + if not ProspectMe.Session[ItemID] then + ProspectMe.Session[ItemID] = { TimesProspected = 0 } + end + for k, v in pairs(ResultsTable) do + if not ProspectMe.Results[ItemID][k] then + ProspectMe.Results[ItemID][k] = v + else + ProspectMe.Results[ItemID][k] = ProspectMe.Results[ItemID][k] + v + end + if not ProspectMe.Session[ItemID][k] then + ProspectMe.Session[ItemID][k] = v + else + ProspectMe.Session[ItemID][k] = ProspectMe.Session[ItemID][k] + v + end + end + ProspectMe.Results[ItemID].TimesProspected = ProspectMe.Results[ItemID].TimesProspected + BatchSize + ProspectMe.Session[ItemID].TimesProspected = ProspectMe.Session[ItemID].TimesProspected + BatchSize + + end + + --[[ + Parses the results of the spellcast or loot containerand returns a table of those results in key/value pairs of item/quantity. + Expects an event and a set of arguments if the event has them. + ]] + ProspectMe.GetResults = function (event, ...) + if event == "CHAT_MSG_LOOT" then + local ItemID = tonumber((...):match("Hitem:(%d+)")) + if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then + ItemID = 129100 + end + local Quantity = tonumber((...):match("|h|rx(%d+)")) + if Quantity == nil then + Quantity = 1 + end + Results[ItemID] = Quantity + end + if event == "LOOT_OPENED" then + for i = 1, GetNumLootItems() do + local ItemID = tonumber(GetLootSlotLink(i):match("Hitem:(%d+)")) + if ItemID == 129099 or ItemID == 130200 or ItemID == 130201 or ItemID == 130202 or ItemID == 130203 or ItemID == 130204 then + ItemID = 129100 + end + local Quantity = select(3, GetLootSlotInfo(i)) + Results[ItemID] = Quantity + end + end + end end ---[[ -Creates an table entry, if it does not exist, and adds results to the entry. -Expects the Item ID and pairs of arguments in table with key being the results ItemID and value being the quantity returned -]] -local function ProspectMe:AddEntry (ItemID, ...) - if not ProspectMe[ItemID] then - ProspectMe[ItemID] = {} + +local function EventHandler(self, event, ...) + if event == "VARIABLES_LOADED" then + Initialize() end - for k, v in pairs arg do - if not ProspectMe[ItemID][k] then - ProspectMe[ItemID][k] = v - else - ProspectMe[ItemID][k] = ProspectMe[ItemID][k] = v + if event == "UNIT_SPELLCAST_SUCCEEDED" then + local unit, spell = ... + if unit == "player" and VALIDSPELLS[spell] then + ProspectMe.BeginCapture(event, ...) end end - return true -end - - -local PROSPECT_ID = 31252 -local MILLING_ID = 51005 -local MASS_PROSPECT_FELSLATE_ID = 225902 -local MASS_PROSPECT_LEYSTONE_ID = 225902 -local MASS_MILLING_YSERALLINE_ID = 210116 -local PROSPECT = GetSpellInfo(PROSPECT_ID):lower() -local MILLING = GetSpellInfo(MILLING_ID):lower() -local MASS_PROSPECT_FELSLATE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower() -local MASS_PROSPECT_LEYSTONE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower() -local MASS_MILLING_YSERALLINE = GetSpellInfo(MASS_PROSPECT_FELSLATE_ID):lower() -local containerID, containerLink = nil, nil -local getContents = false -local bulkMultiplier = 1 --This will be used for mass prospecting/milling in Legion - -local function CreateTableEntry(id) - local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(id) - PM_ItemTable[id] = {} - PM_ItemTable[id].name = name - PM_ItemTable[id].link = link - PM_ItemTable[id].quality = quality - PM_ItemTable[id].iLevel = iLevel - PM_ItemTable[id].reqLevel = reqLevel - PM_ItemTable[id].class = class - PM_ItemTable[id].subclass = subclass - PM_ItemTable[id].maxStack = maxStack - PM_ItemTable[id].equipSlot = equipSlot - PM_ItemTable[id].texture = texture - PM_ItemTable[id].vendorPrice = vendorPrice - PM_ItemTable[id].price = PM_GetItemValue(id) -end - -local function PM_Init() - if not PM_ResultsTable then - PM_ResultsTable = {} - PM_ItemTable = {} + if event == "CHAT_MSG_LOOT" or "LOOT_OPENED" then + if ParseResults then + ProspectMe.GetResults(event, ...) + end + ProspectMeDebug = Results end - PM_SessionTable = {} - PM_GemCleanup() --Run cleanup on excess Gem Chips created in v1.7.0.2 and earlier -end - ---debugging function to print the databases results -function PM_PrintResults() - for container, k in pairs(PM_ResultsTable) do - print(PM_ItemTable[container].link, PM_ResultsTable[container].timesProspected) - for i, num in pairs(k) do - if i ~= "timesProspected" then - print(PM_ItemTable[i].link, num) - end + if event == "ITEM_LOCKED" then + local bag, slot = ... + ContainerID = select(10, GetContainerItemInfo(bag, slot)) + end + if event == "TRADE_SKILL_LIST_UPDATE" or event == "LOOT_CLOSED" then + if ParseResults then + ProspectMe.EndCapture() end end end -local function GetResults() - --Create tables for the Container if it doesn't exist yet - if not PM_ResultsTable[containerID] then - PM_ResultsTable[containerID] = {timesProspected = 0} - CreateTableEntry(containerID) - end - - --Creates a session table entry, this will be cleared on log out/UI reload - if not PM_SessionTable[containerID] then - PM_SessionTable[containerID] = {timesProspected = 0} - end - - for i = 1, GetNumLootItems() do - local itemID = GetLootSlotLink(i):match("Hitem:(%d+)") - 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 - itemID = "129100" - end - local quantity = select(3, GetLootSlotInfo(i)) - if not PM_ItemTable[itemID] then - CreateTableEntry(itemID) - end - if PM_ResultsTable[containerID][itemID] then - PM_ResultsTable[containerID][itemID] = PM_ResultsTable[containerID][itemID] + quantity - else - PM_ResultsTable[containerID][itemID] = quantity - end - if PM_SessionTable[containerID][itemID] then - PM_SessionTable[containerID][itemID] = PM_SessionTable[containerID][itemID] + quantity - else - PM_SessionTable[containerID][itemID] = quantity - end - end - - PM_ResultsTable[containerID].timesProspected = PM_ResultsTable[containerID].timesProspected + bulkMultiplier - PM_SessionTable[containerID].timesProspected = PM_SessionTable[containerID].timesProspected + bulkMultiplier -end - -local function EventHandler(self, event, ...) - if event == "VARIABLES_LOADED" then - PM_Init() - PM_UpdateValues() - end - if event == "UNIT_SPELLCAST_INTERRUPTED" then - local unitID, spell, rank = ... - spell = spell:lower() - 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 - getContents = false - end - end - if event == "LOOT_OPENED" then - if getContents then - GetResults() - end - end - if event == "LOOT_CLOSED" then - getContents = false - end - if event == "AUCTION_ITEM_LIST_UPDATE" then - PM_UpdateValues() - end -end - -local frame = CreateFrame("FRAME", "PM_Frame") +local frame = CreateFrame("FRAME", "ProspectMe") frame:RegisterEvent("VARIABLES_LOADED") -frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") +frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") +frame:RegisterEvent("CHAT_MSG_LOOT") frame:RegisterEvent("LOOT_OPENED") +frame:RegisterEvent("ITEM_LOCKED") frame:RegisterEvent("LOOT_CLOSED") +frame:RegisterEvent("TRADE_SKILL_LIST_UPDATE") frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE") -frame:SetScript("OnEvent", EventHandler) - -hooksecurefunc("UseContainerItem", function(...) - if getContents then - containerLink = GetContainerItemLink(...) - containerID = containerLink:match("Hitem:(%d+)") - end - -end) - -hooksecurefunc("UseItemByName", function(itemName) - if getContents then - containerLink = select(2, GetItemInfo(itemName)) - containerID = containerLink:match("Hitem:(%d+)") - end -end) - -hooksecurefunc("SpellTargetItem", function(itemName) - if getContents then - containerLink = select(2, GetItemInfo(itemName)) - containerID = containerLink:match("Hitem:(%d+)") - end -end) - -hooksecurefunc("CastSpell", function(...) - local spellName = GetSpellInfo(...):lower() - if spellName == PROSPECT or spellName == MILLING or spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then - getContents = true - if spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then - bulkMultiplier = 4 - else - bulkMultiplier = 1 - end - end -end) - -hooksecurefunc("CastSpellByID", function(spellID) - 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 - getContents = true - if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then - bulkMultiplier = 4 - else - bulkMultiplier = 1 - end - end -end) - -hooksecurefunc("UseAction", function(actionID) - local spellID = select(2, GetActionInfo(actionID)) - 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 - getContents = true - if spellID == MASS_PROSPECT_FELSTATE_ID or spellID == MASS_PROSPECT_LEYSTONE_ID or spellID == MASS_MILLING_YSERALLINE_ID then - bulkMultiplier = 4 - else - bulkMultiplier = 1 - end - end -end) - -hooksecurefunc("CastSpellByName", function(spellName, onSelf) - spellName = spellName:lower() - if spellName == PROSPECT or spellName == MILLING or spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then - getContents = true - if spellName == MASS_PROSPECT_FELSLATE or spellName == MASS_PROSPECT_LEYSTONE or spellName == MASS_MILLING_YSERALLINE then - bulkMultiplier = 4 - else - bulkMultiplier = 1 - end - end -end) \ No newline at end of file +frame:SetScript("OnEvent", EventHandler) \ No newline at end of file