changeset 27:120740b8a54f

Record what skills profession trainers train, the player's class, and each skill's minimum level and minimum profession level requirements.
author James D. Callahan III <jcallahan@curse.com>
date Thu, 17 May 2012 11:40:33 -0500
parents 565af5d2002a
children 11afd2cc0b83
files Main.lua
diffstat 1 files changed, 63 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Main.lua	Wed May 16 12:35:19 2012 -0500
+++ b/Main.lua	Thu May 17 11:40:33 2012 -0500
@@ -40,7 +40,6 @@
 local EVENT_MAPPING = {
     COMBAT_LOG_EVENT_UNFILTERED = true,
     COMBAT_TEXT_UPDATE = true,
-    LOOT_CLOSED = true,
     LOOT_OPENED = true,
     MERCHANT_SHOW = "UpdateMerchantItems",
     MERCHANT_UPDATE = "UpdateMerchantItems",
@@ -49,6 +48,7 @@
     QUEST_COMPLETE = true,
     QUEST_DETAIL = true,
     QUEST_LOG_UPDATE = true,
+    TRAINER_SHOW = true,
     UNIT_QUEST_LOG_CHANGED = true,
     UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
     UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
@@ -61,6 +61,9 @@
 local AF = private.ACTION_TYPE_FLAGS
 
 
+local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
+
+
 -----------------------------------------------------------------------
 -- Local variables.
 -----------------------------------------------------------------------
@@ -395,7 +398,7 @@
 
 
 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
-    local npc = DBEntry("npcs", action_data.id_num)
+    local npc = DBEntry("npcs", action_data.identifier)
 
     if not npc then
         return
@@ -405,11 +408,6 @@
 end
 
 
-function WDP:LOOT_CLOSED()
-    --    table.wipe(action_data)
-end
-
-
 do
     local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
     local re_silver = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
@@ -455,7 +453,7 @@
                 return false
             end
             local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target"))
-            action_data.id_num = id_num
+            action_data.identifier = id_num
             return true
         end,
         [AF.OBJECT] = true,
@@ -466,9 +464,11 @@
 
 
     local function GenericLootUpdate(data_type)
-        local entry = DBEntry(data_type, action_data.id_num)
+        local entry = DBEntry(data_type, action_data.identifier)
 
+        print("GenericLootUpdate")
         if not entry then
+            print(("Missing DB entry for %s (%s)"):format(data_type, tostring(action_data.identifier)))
             return
         end
         local loot_type = action_data.label or "drops"
@@ -673,6 +673,7 @@
         return
     end
     DBEntry("npcs", unit_idnum).mind_control = true
+    print("Wiping action_data")
     table.wipe(action_data)
 end
 
@@ -758,7 +759,7 @@
         end
         table.wipe(action_data)
         action_data.type = AF.NPC
-        action_data.id_num = unit_idnum
+        action_data.identifier = unit_idnum
         action_data.npc_level = npc_level
     end
 end -- do-block
@@ -791,9 +792,8 @@
     function WDP:QUEST_DETAIL()
         local quest = UpdateQuestJuncture("begin")
 
-        local _, class = _G.UnitClass("player")
         quest.classes = quest.classes or {}
-        quest.classes[class] = true
+        quest.classes[PLAYER_CLASS] = true
 
         local _, race = _G.UnitRace("player")
         quest.races = quest.races or {}
@@ -815,6 +815,57 @@
 end
 
 
+function WDP:TRAINER_SHOW()
+    if not _G.IsTradeskillTrainer() then
+        return
+    end
+    local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
+    local npc = DBEntry("npcs", unit_idnum)
+    npc.teaches = npc.teaches or {}
+
+    -- Get the initial trainer filters
+    local available = _G.GetTrainerServiceTypeFilter("available")
+    local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
+    local used = _G.GetTrainerServiceTypeFilter("used")
+
+    -- Clear the trainer filters
+    _G.SetTrainerServiceTypeFilter("available", 1)
+    _G.SetTrainerServiceTypeFilter("unavailable", 1)
+    _G.SetTrainerServiceTypeFilter("used", 1)
+
+    for index = 1, _G.GetNumTrainerServices(), 1 do
+        local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
+
+        if spell_name then
+            DatamineTT:ClearLines()
+            DatamineTT:SetTrainerService(index)
+
+            local _, _, spell_id = DatamineTT:GetSpell()
+            local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
+            profession = profession or "General"
+
+            local class_professions = npc.teaches[PLAYER_CLASS]
+            if not class_professions then
+                npc.teaches[PLAYER_CLASS] = {}
+                class_professions = npc.teaches[PLAYER_CLASS]
+            end
+
+            local profession_skills = class_professions[profession]
+            if not profession_skills then
+                class_professions[profession] = {}
+                profession_skills = class_professions[profession]
+            end
+            profession_skills[spell_id] = ("%d:%d"):format(required_level, min_skill)
+        end
+    end
+
+    -- Reset the filters to what they were before
+    _G.SetTrainerServiceTypeFilter("available", available or 0)
+    _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
+    _G.SetTrainerServiceTypeFilter("used", used or 0)
+end
+
+
 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
     if private.tracked_line or unit_id ~= "player" then
         return