jcallahan@0
|
1 -----------------------------------------------------------------------
|
jcallahan@0
|
2 -- Upvalued Lua API.
|
jcallahan@0
|
3 -----------------------------------------------------------------------
|
jcallahan@0
|
4 local _G = getfenv(0)
|
jcallahan@0
|
5
|
jcallahan@0
|
6 local pairs = _G.pairs
|
jcallahan@1
|
7 local tonumber = _G.tonumber
|
jcallahan@1
|
8
|
jcallahan@1
|
9 local bit = _G.bit
|
jcallahan@1
|
10 local math = _G.math
|
jcallahan@1
|
11 local table = _G.table
|
jcallahan@1
|
12
|
jcallahan@0
|
13
|
jcallahan@0
|
14 -----------------------------------------------------------------------
|
jcallahan@0
|
15 -- AddOn namespace.
|
jcallahan@0
|
16 -----------------------------------------------------------------------
|
jcallahan@0
|
17 local ADDON_NAME, private = ...
|
jcallahan@0
|
18
|
jcallahan@0
|
19 local LibStub = _G.LibStub
|
jcallahan@0
|
20 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0")
|
jcallahan@0
|
21
|
jcallahan@4
|
22 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
|
jcallahan@5
|
23 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
|
jcallahan@5
|
24
|
jcallahan@0
|
25
|
jcallahan@0
|
26 -----------------------------------------------------------------------
|
jcallahan@0
|
27 -- Local constants.
|
jcallahan@0
|
28 -----------------------------------------------------------------------
|
jcallahan@0
|
29 local DATABASE_DEFAULTS = {
|
jcallahan@0
|
30 global = {
|
jcallahan@0
|
31 items = {},
|
jcallahan@0
|
32 npcs = {},
|
jcallahan@0
|
33 objects = {},
|
jcallahan@0
|
34 quests = {},
|
jcallahan@17
|
35 zones = {},
|
jcallahan@0
|
36 }
|
jcallahan@0
|
37 }
|
jcallahan@0
|
38
|
jcallahan@0
|
39
|
jcallahan@1
|
40 local EVENT_MAPPING = {
|
jcallahan@23
|
41 COMBAT_LOG_EVENT_UNFILTERED = true,
|
jcallahan@18
|
42 COMBAT_TEXT_UPDATE = true,
|
jcallahan@1
|
43 LOOT_OPENED = true,
|
jcallahan@7
|
44 MERCHANT_SHOW = "UpdateMerchantItems",
|
jcallahan@7
|
45 MERCHANT_UPDATE = "UpdateMerchantItems",
|
jcallahan@25
|
46 PET_BAR_UPDATE = true,
|
jcallahan@2
|
47 PLAYER_TARGET_CHANGED = true,
|
jcallahan@9
|
48 QUEST_COMPLETE = true,
|
jcallahan@9
|
49 QUEST_DETAIL = true,
|
jcallahan@9
|
50 QUEST_LOG_UPDATE = true,
|
jcallahan@27
|
51 TRAINER_SHOW = true,
|
jcallahan@4
|
52 UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
53 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
54 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
55 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
56 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
57 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@0
|
58 }
|
jcallahan@0
|
59
|
jcallahan@4
|
60
|
jcallahan@1
|
61 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
62
|
jcallahan@4
|
63
|
jcallahan@27
|
64 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
|
jcallahan@27
|
65
|
jcallahan@27
|
66
|
jcallahan@0
|
67 -----------------------------------------------------------------------
|
jcallahan@0
|
68 -- Local variables.
|
jcallahan@0
|
69 -----------------------------------------------------------------------
|
jcallahan@0
|
70 local db
|
jcallahan@0
|
71 local durability_timer_handle
|
jcallahan@2
|
72 local target_location_timer_handle
|
jcallahan@1
|
73 local action_data = {}
|
jcallahan@20
|
74 local faction_names = {}
|
jcallahan@0
|
75
|
jcallahan@1
|
76
|
jcallahan@1
|
77 -----------------------------------------------------------------------
|
jcallahan@1
|
78 -- Helper Functions.
|
jcallahan@1
|
79 -----------------------------------------------------------------------
|
jcallahan@19
|
80 local function DBEntry(data_type, unit_id)
|
jcallahan@19
|
81 if not data_type or not unit_id then
|
jcallahan@6
|
82 return
|
jcallahan@6
|
83 end
|
jcallahan@19
|
84 local unit = db[data_type][unit_id]
|
jcallahan@6
|
85
|
jcallahan@10
|
86 if not unit then
|
jcallahan@19
|
87 db[data_type][unit_id] = {}
|
jcallahan@19
|
88 unit = db[data_type][unit_id]
|
jcallahan@6
|
89 end
|
jcallahan@10
|
90 return unit
|
jcallahan@6
|
91 end
|
jcallahan@6
|
92
|
jcallahan@6
|
93
|
jcallahan@22
|
94 local function InstanceDifficultyToken()
|
jcallahan@22
|
95 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
|
jcallahan@22
|
96 if difficulty_name == "" then
|
jcallahan@22
|
97 difficulty_name = "NONE"
|
jcallahan@22
|
98 end
|
jcallahan@22
|
99 return ("%s:%s:%s"):format(instance_type:upper(), difficulty_name:upper():gsub(" ", "_"), _G.tostring(is_dynamic))
|
jcallahan@22
|
100 end
|
jcallahan@22
|
101
|
jcallahan@22
|
102
|
jcallahan@1
|
103 local function CurrentLocationData()
|
jcallahan@1
|
104 local map_level = _G.GetCurrentMapDungeonLevel() or 0
|
jcallahan@1
|
105 local x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
106
|
jcallahan@1
|
107 x = x or 0
|
jcallahan@1
|
108 y = y or 0
|
jcallahan@1
|
109
|
jcallahan@1
|
110 if x == 0 and y == 0 then
|
jcallahan@1
|
111 for level_index = 1, _G.GetNumDungeonMapLevels() do
|
jcallahan@1
|
112 _G.SetDungeonMapLevel(level_index)
|
jcallahan@1
|
113 x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
114
|
jcallahan@1
|
115 if x and y and (x > 0 or y > 0) then
|
jcallahan@1
|
116 _G.SetDungeonMapLevel(map_level)
|
jcallahan@1
|
117 map_level = level_index
|
jcallahan@1
|
118 break
|
jcallahan@1
|
119 end
|
jcallahan@1
|
120 end
|
jcallahan@1
|
121 end
|
jcallahan@1
|
122
|
jcallahan@1
|
123 if _G.DungeonUsesTerrainMap() then
|
jcallahan@1
|
124 map_level = map_level - 1
|
jcallahan@1
|
125 end
|
jcallahan@24
|
126 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level, InstanceDifficultyToken()
|
jcallahan@1
|
127 end
|
jcallahan@1
|
128
|
jcallahan@1
|
129
|
jcallahan@1
|
130 local function ItemLinkToID(item_link)
|
jcallahan@1
|
131 if not item_link then
|
jcallahan@1
|
132 return
|
jcallahan@1
|
133 end
|
jcallahan@7
|
134 return tonumber(item_link:match("item:(%d+)"))
|
jcallahan@1
|
135 end
|
jcallahan@0
|
136
|
jcallahan@4
|
137
|
jcallahan@4
|
138 do
|
jcallahan@4
|
139 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@4
|
140
|
jcallahan@4
|
141 function WDP:ParseGUID(guid)
|
jcallahan@5
|
142 if not guid then
|
jcallahan@5
|
143 return
|
jcallahan@5
|
144 end
|
jcallahan@4
|
145 local types = private.UNIT_TYPES
|
jcallahan@4
|
146 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@4
|
147
|
jcallahan@10
|
148 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
|
jcallahan@4
|
149 return unit_type, tonumber(guid:sub(-12, -9), 16)
|
jcallahan@4
|
150 end
|
jcallahan@4
|
151
|
jcallahan@4
|
152 return unit_type
|
jcallahan@4
|
153 end
|
jcallahan@4
|
154 end -- do-block
|
jcallahan@4
|
155
|
jcallahan@4
|
156
|
jcallahan@10
|
157 local function UpdateObjectLocation(identifier)
|
jcallahan@10
|
158 if not identifier then
|
jcallahan@10
|
159 return
|
jcallahan@10
|
160 end
|
jcallahan@24
|
161 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@19
|
162 local object = DBEntry("objects", identifier)
|
jcallahan@11
|
163 object.locations = object.locations or {}
|
jcallahan@10
|
164
|
jcallahan@24
|
165 local location_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@24
|
166
|
jcallahan@24
|
167 if not object.locations[location_token] then
|
jcallahan@24
|
168 object.locations[location_token] = {}
|
jcallahan@10
|
169 end
|
jcallahan@24
|
170 object.locations[location_token][("%s:%s:%s:%s"):format(instance_token, map_level, x, y)] = true
|
jcallahan@10
|
171 end
|
jcallahan@10
|
172
|
jcallahan@10
|
173
|
jcallahan@19
|
174 local function HandleItemUse(item_link, bag_index, slot_index)
|
jcallahan@19
|
175 if not item_link then
|
jcallahan@19
|
176 return
|
jcallahan@19
|
177 end
|
jcallahan@19
|
178 local item_id = ItemLinkToID(item_link)
|
jcallahan@19
|
179
|
jcallahan@19
|
180 if not bag_index or not slot_index then
|
jcallahan@19
|
181 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@19
|
182 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
|
jcallahan@19
|
183 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
|
jcallahan@19
|
184 bag_index = new_bag_index
|
jcallahan@19
|
185 slot_index = new_slot_index
|
jcallahan@19
|
186 break
|
jcallahan@19
|
187 end
|
jcallahan@19
|
188 end
|
jcallahan@19
|
189 end
|
jcallahan@19
|
190 end
|
jcallahan@19
|
191
|
jcallahan@19
|
192 if not bag_index or not slot_index then
|
jcallahan@19
|
193 return
|
jcallahan@19
|
194 end
|
jcallahan@19
|
195 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@19
|
196
|
jcallahan@19
|
197 if not is_lootable then
|
jcallahan@19
|
198 return
|
jcallahan@19
|
199 end
|
jcallahan@19
|
200 DatamineTT:ClearLines()
|
jcallahan@19
|
201 DatamineTT:SetBagItem(bag_index, slot_index)
|
jcallahan@19
|
202
|
jcallahan@19
|
203 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@19
|
204 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@19
|
205
|
jcallahan@19
|
206 if not current_line then
|
jcallahan@19
|
207 break
|
jcallahan@19
|
208 end
|
jcallahan@19
|
209
|
jcallahan@19
|
210 if current_line:GetText() == _G.ITEM_OPENABLE then
|
jcallahan@19
|
211 table.wipe(action_data)
|
jcallahan@19
|
212 action_data.type = AF.ITEM
|
jcallahan@19
|
213 action_data.item_id = item_id
|
jcallahan@25
|
214 action_data.label = "contains"
|
jcallahan@19
|
215 break
|
jcallahan@19
|
216 end
|
jcallahan@19
|
217 end
|
jcallahan@19
|
218 end
|
jcallahan@19
|
219
|
jcallahan@19
|
220
|
jcallahan@20
|
221 local function UpdateFactionNames()
|
jcallahan@20
|
222 for faction_index = 1, 1000 do
|
jcallahan@20
|
223 local faction_name, _, _, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
|
jcallahan@20
|
224
|
jcallahan@20
|
225 if faction_name and not is_header then
|
jcallahan@20
|
226 faction_names[faction_name] = true
|
jcallahan@20
|
227 elseif not faction_name then
|
jcallahan@20
|
228 break
|
jcallahan@20
|
229 end
|
jcallahan@20
|
230 end
|
jcallahan@20
|
231 end
|
jcallahan@20
|
232
|
jcallahan@20
|
233
|
jcallahan@0
|
234 -----------------------------------------------------------------------
|
jcallahan@0
|
235 -- Methods.
|
jcallahan@0
|
236 -----------------------------------------------------------------------
|
jcallahan@0
|
237 function WDP:OnInitialize()
|
jcallahan@0
|
238 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
|
jcallahan@14
|
239
|
jcallahan@14
|
240 local raw_db = _G["WoWDBProfilerData"]
|
jcallahan@14
|
241
|
jcallahan@18
|
242 local build_num = tonumber(private.build_num)
|
jcallahan@14
|
243
|
jcallahan@14
|
244 if raw_db.build_num and raw_db.build_num < build_num then
|
jcallahan@14
|
245 for entry in pairs(DATABASE_DEFAULTS.global) do
|
jcallahan@14
|
246 db[entry] = {}
|
jcallahan@14
|
247 end
|
jcallahan@14
|
248 raw_db.build_num = build_num
|
jcallahan@14
|
249 elseif not raw_db.build_num then
|
jcallahan@14
|
250 raw_db.build_num = build_num
|
jcallahan@14
|
251 end
|
jcallahan@0
|
252 end
|
jcallahan@0
|
253
|
jcallahan@0
|
254
|
jcallahan@0
|
255 function WDP:OnEnable()
|
jcallahan@0
|
256 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@1
|
257 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@0
|
258 end
|
jcallahan@0
|
259 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
|
jcallahan@2
|
260 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.2)
|
jcallahan@19
|
261
|
jcallahan@19
|
262 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
|
jcallahan@19
|
263 if target_unit then
|
jcallahan@19
|
264 return
|
jcallahan@19
|
265 end
|
jcallahan@19
|
266 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
|
jcallahan@19
|
267 end)
|
jcallahan@19
|
268
|
jcallahan@19
|
269 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
|
jcallahan@19
|
270 if target_unit then
|
jcallahan@19
|
271 return
|
jcallahan@19
|
272 end
|
jcallahan@19
|
273 local _, item_link = _G.GetItemInfo(identifier)
|
jcallahan@19
|
274 HandleItemUse(item_link)
|
jcallahan@19
|
275 end)
|
jcallahan@0
|
276 end
|
jcallahan@0
|
277
|
jcallahan@0
|
278
|
jcallahan@0
|
279 local function RecordDurability(item_id, durability)
|
jcallahan@0
|
280 if not durability or durability <= 0 then
|
jcallahan@0
|
281 return
|
jcallahan@0
|
282 end
|
jcallahan@0
|
283
|
jcallahan@0
|
284 if not db.items[item_id] then
|
jcallahan@0
|
285 db.items[item_id] = {}
|
jcallahan@0
|
286 end
|
jcallahan@0
|
287 db.items[item_id].durability = durability
|
jcallahan@0
|
288 end
|
jcallahan@0
|
289
|
jcallahan@0
|
290
|
jcallahan@0
|
291 function WDP:ProcessDurability()
|
jcallahan@0
|
292 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
293 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
294
|
jcallahan@0
|
295 if item_id and item_id > 0 then
|
jcallahan@1
|
296 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@0
|
297 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
298 end
|
jcallahan@0
|
299 end
|
jcallahan@0
|
300
|
jcallahan@0
|
301 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
302 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
303 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
304
|
jcallahan@0
|
305 if item_id and item_id > 0 then
|
jcallahan@1
|
306 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@0
|
307 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
308 end
|
jcallahan@0
|
309 end
|
jcallahan@0
|
310 end
|
jcallahan@0
|
311 end
|
jcallahan@0
|
312
|
jcallahan@0
|
313
|
jcallahan@2
|
314 function WDP:UpdateTargetLocation()
|
jcallahan@22
|
315 local is_dead = _G.UnitIsDead("target")
|
jcallahan@22
|
316
|
jcallahan@22
|
317 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not is_dead) then
|
jcallahan@2
|
318 return
|
jcallahan@2
|
319 end
|
jcallahan@2
|
320
|
jcallahan@2
|
321 for index = 1, 4 do
|
jcallahan@2
|
322 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@2
|
323 return
|
jcallahan@2
|
324 end
|
jcallahan@2
|
325 end
|
jcallahan@22
|
326 local target_guid = _G.UnitGUID("target")
|
jcallahan@22
|
327 local unit_type, unit_idnum = self:ParseGUID(target_guid)
|
jcallahan@2
|
328
|
jcallahan@2
|
329 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@2
|
330 return
|
jcallahan@2
|
331 end
|
jcallahan@24
|
332 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@22
|
333 local npc_data = DBEntry("npcs", unit_idnum).encounter_data[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@6
|
334 npc_data.locations = npc_data.locations or {}
|
jcallahan@2
|
335
|
jcallahan@24
|
336 local location_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@24
|
337
|
jcallahan@24
|
338 if not npc_data.locations[location_token] then
|
jcallahan@24
|
339 npc_data.locations[location_token] = {}
|
jcallahan@2
|
340 end
|
jcallahan@22
|
341
|
jcallahan@22
|
342 -- Only record corpse location if there is no entry for this GUID.
|
jcallahan@24
|
343 if is_dead and npc_data.locations[location_token][target_guid] then
|
jcallahan@22
|
344 return
|
jcallahan@22
|
345 end
|
jcallahan@24
|
346 npc_data.locations[location_token][target_guid] = ("%s:%s:%s:%s"):format(instance_token, map_level, x, y)
|
jcallahan@2
|
347 end
|
jcallahan@2
|
348
|
jcallahan@2
|
349
|
jcallahan@0
|
350 -----------------------------------------------------------------------
|
jcallahan@0
|
351 -- Event handlers.
|
jcallahan@0
|
352 -----------------------------------------------------------------------
|
jcallahan@23
|
353 do
|
jcallahan@23
|
354 local EXTRACT_GAS_SPELL_ID = 30427
|
jcallahan@23
|
355 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
356 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
357
|
jcallahan@23
|
358
|
jcallahan@23
|
359 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@23
|
360 if not spell_id then
|
jcallahan@23
|
361 return
|
jcallahan@23
|
362 end
|
jcallahan@23
|
363 local source_type, source_id = WDP:ParseGUID(source_guid)
|
jcallahan@23
|
364
|
jcallahan@23
|
365 if not source_id or source_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@23
|
366 return
|
jcallahan@23
|
367 end
|
jcallahan@23
|
368
|
jcallahan@23
|
369 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
|
jcallahan@23
|
370 local npc = DBEntry("npcs", source_id)
|
jcallahan@23
|
371 local instance_token = InstanceDifficultyToken()
|
jcallahan@23
|
372 npc.spells = npc.spells or {}
|
jcallahan@23
|
373 npc.spells[instance_token] = npc.spells[instance_token] or {}
|
jcallahan@23
|
374 npc.spells[instance_token][spell_id] = true
|
jcallahan@23
|
375 end
|
jcallahan@23
|
376 end
|
jcallahan@23
|
377
|
jcallahan@23
|
378
|
jcallahan@23
|
379 local COMBAT_LOG_FUNCS = {
|
jcallahan@23
|
380 SPELL_AURA_APPLIED = RecordNPCSpell,
|
jcallahan@23
|
381 SPELL_CAST_START = RecordNPCSpell,
|
jcallahan@23
|
382 SPELL_CAST_SUCCESS = RecordNPCSpell,
|
jcallahan@23
|
383 UNIT_DISSIPATES = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags)
|
jcallahan@23
|
384 -- TODO: Write this.
|
jcallahan@23
|
385 end,
|
jcallahan@23
|
386 }
|
jcallahan@23
|
387
|
jcallahan@23
|
388
|
jcallahan@23
|
389 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...)
|
jcallahan@23
|
390 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
|
jcallahan@23
|
391
|
jcallahan@23
|
392 if not combat_log_func then
|
jcallahan@23
|
393 return
|
jcallahan@23
|
394 end
|
jcallahan@23
|
395 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
|
jcallahan@23
|
396 end
|
jcallahan@23
|
397 end -- do-block
|
jcallahan@23
|
398
|
jcallahan@23
|
399
|
jcallahan@18
|
400 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
|
jcallahan@27
|
401 local npc = DBEntry("npcs", action_data.identifier)
|
jcallahan@21
|
402
|
jcallahan@21
|
403 if not npc then
|
jcallahan@21
|
404 return
|
jcallahan@21
|
405 end
|
jcallahan@22
|
406 npc.encounter_data[action_data.npc_level].reputations = npc.encounter_data[action_data.npc_level].reputations or {}
|
jcallahan@22
|
407 npc.encounter_data[action_data.npc_level].reputations[faction_name] = amount
|
jcallahan@18
|
408 end
|
jcallahan@18
|
409
|
jcallahan@18
|
410
|
jcallahan@13
|
411 do
|
jcallahan@13
|
412 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
413 local re_silver = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
414 local re_copper = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
415
|
jcallahan@13
|
416
|
jcallahan@13
|
417 local function _moneyMatch(money, re)
|
jcallahan@13
|
418 return money:match(re) or 0
|
jcallahan@1
|
419 end
|
jcallahan@1
|
420
|
jcallahan@0
|
421
|
jcallahan@13
|
422 local function _toCopper(money)
|
jcallahan@13
|
423 if not money then
|
jcallahan@13
|
424 return 0
|
jcallahan@13
|
425 end
|
jcallahan@0
|
426
|
jcallahan@13
|
427 return _moneyMatch(money, re_gold) * 10000 + _moneyMatch(money, re_silver) * 100 + _moneyMatch(money, re_copper)
|
jcallahan@1
|
428 end
|
jcallahan@1
|
429
|
jcallahan@1
|
430
|
jcallahan@13
|
431 local LOOT_VERIFY_FUNCS = {
|
jcallahan@16
|
432 [AF.ITEM] = function()
|
jcallahan@16
|
433 local locked_item_id
|
jcallahan@16
|
434
|
jcallahan@16
|
435 for bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@16
|
436 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@16
|
437 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@16
|
438
|
jcallahan@16
|
439 if is_locked then
|
jcallahan@16
|
440 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
|
jcallahan@16
|
441 end
|
jcallahan@16
|
442 end
|
jcallahan@16
|
443 end
|
jcallahan@16
|
444
|
jcallahan@16
|
445 if not locked_item_id or (action_data.item_id and action_data.item_id ~= locked_item_id) then
|
jcallahan@16
|
446 return false
|
jcallahan@16
|
447 end
|
jcallahan@16
|
448 action_data.item_id = locked_item_id
|
jcallahan@16
|
449 return true
|
jcallahan@16
|
450 end,
|
jcallahan@13
|
451 [AF.NPC] = function()
|
jcallahan@17
|
452 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@15
|
453 return false
|
jcallahan@13
|
454 end
|
jcallahan@15
|
455 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@27
|
456 action_data.identifier = id_num
|
jcallahan@13
|
457 return true
|
jcallahan@13
|
458 end,
|
jcallahan@14
|
459 [AF.OBJECT] = true,
|
jcallahan@17
|
460 [AF.ZONE] = function()
|
jcallahan@25
|
461 return action_data.label and _G.IsFishingLoot()
|
jcallahan@17
|
462 end,
|
jcallahan@13
|
463 }
|
jcallahan@13
|
464
|
jcallahan@13
|
465
|
jcallahan@22
|
466 local function GenericLootUpdate(data_type)
|
jcallahan@27
|
467 local entry = DBEntry(data_type, action_data.identifier)
|
jcallahan@22
|
468
|
jcallahan@27
|
469 print("GenericLootUpdate")
|
jcallahan@22
|
470 if not entry then
|
jcallahan@27
|
471 print(("Missing DB entry for %s (%s)"):format(data_type, tostring(action_data.identifier)))
|
jcallahan@22
|
472 return
|
jcallahan@22
|
473 end
|
jcallahan@25
|
474 local loot_type = action_data.label or "drops"
|
jcallahan@22
|
475 entry[loot_type] = entry[loot_type] or {}
|
jcallahan@22
|
476
|
jcallahan@22
|
477 for index = 1, #action_data.loot_list do
|
jcallahan@22
|
478 table.insert(entry[loot_type], action_data.loot_list[index])
|
jcallahan@22
|
479 end
|
jcallahan@22
|
480 end
|
jcallahan@22
|
481
|
jcallahan@22
|
482
|
jcallahan@13
|
483 local LOOT_UPDATE_FUNCS = {
|
jcallahan@16
|
484 [AF.ITEM] = function()
|
jcallahan@19
|
485 local item = DBEntry("items", action_data.item_id)
|
jcallahan@25
|
486 local loot_type = action_data.label or "drops"
|
jcallahan@16
|
487 item[loot_type] = item[loot_type] or {}
|
jcallahan@16
|
488
|
jcallahan@17
|
489 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
490 table.insert(item[loot_type], action_data.loot_list[index])
|
jcallahan@16
|
491 end
|
jcallahan@16
|
492 end,
|
jcallahan@13
|
493 [AF.NPC] = function()
|
jcallahan@22
|
494 GenericLootUpdate("npcs")
|
jcallahan@13
|
495 end,
|
jcallahan@13
|
496 [AF.OBJECT] = function()
|
jcallahan@22
|
497 GenericLootUpdate("objects")
|
jcallahan@17
|
498 end,
|
jcallahan@17
|
499 [AF.ZONE] = function()
|
jcallahan@25
|
500 local loot_type = action_data.label or "drops"
|
jcallahan@19
|
501 local zone = DBEntry("zones", action_data.zone)
|
jcallahan@17
|
502 zone[loot_type] = zone[loot_type] or {}
|
jcallahan@17
|
503
|
jcallahan@22
|
504 local location_data = ("%s:%s:%s:%s"):format(action_data.instance_token, action_data.map_level, action_data.x, action_data.y)
|
jcallahan@17
|
505 local loot_data = zone[loot_type][location_data]
|
jcallahan@17
|
506
|
jcallahan@17
|
507 if not loot_data then
|
jcallahan@17
|
508 zone[loot_type][location_data] = {}
|
jcallahan@17
|
509 loot_data = zone[loot_type][location_data]
|
jcallahan@17
|
510 end
|
jcallahan@17
|
511
|
jcallahan@17
|
512 for index = 1, #action_data.loot_list do
|
jcallahan@17
|
513 table.insert(loot_data, action_data.loot_list[index])
|
jcallahan@13
|
514 end
|
jcallahan@13
|
515 end,
|
jcallahan@13
|
516 }
|
jcallahan@13
|
517
|
jcallahan@13
|
518
|
jcallahan@13
|
519 function WDP:LOOT_OPENED()
|
jcallahan@18
|
520 if action_data.looting then
|
jcallahan@18
|
521 return
|
jcallahan@18
|
522 end
|
jcallahan@18
|
523
|
jcallahan@13
|
524 if not action_data.type then
|
jcallahan@13
|
525 action_data.type = AF.NPC
|
jcallahan@1
|
526 end
|
jcallahan@13
|
527 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
|
jcallahan@13
|
528 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
|
jcallahan@13
|
529
|
jcallahan@14
|
530 if not verify_func or not update_func then
|
jcallahan@13
|
531 return
|
jcallahan@13
|
532 end
|
jcallahan@13
|
533
|
jcallahan@14
|
534 if _G.type(verify_func) == "function" and not verify_func() then
|
jcallahan@14
|
535 return
|
jcallahan@14
|
536 end
|
jcallahan@18
|
537 -- TODO: Remove this check once the MoP client goes live
|
jcallahan@18
|
538 local wow_version = private.wow_version
|
jcallahan@13
|
539 local loot_registry = {}
|
jcallahan@17
|
540 action_data.loot_list = {}
|
jcallahan@18
|
541 action_data.looting = true
|
jcallahan@13
|
542
|
jcallahan@18
|
543 if wow_version == "5.0.1" then
|
jcallahan@18
|
544 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
545 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@13
|
546
|
jcallahan@18
|
547 local slot_type = _G.GetLootSlotType(loot_slot)
|
jcallahan@18
|
548
|
jcallahan@18
|
549 if slot_type == _G.LOOT_SLOT_ITEM then
|
jcallahan@18
|
550 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
551 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
552 elseif slot_type == _G.LOOT_SLOT_MONEY then
|
jcallahan@18
|
553 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
554 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
|
jcallahan@18
|
555 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
556 end
|
jcallahan@18
|
557 end
|
jcallahan@18
|
558 else
|
jcallahan@18
|
559 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
560 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@18
|
561 if _G.LootSlotIsItem(loot_slot) then
|
jcallahan@18
|
562 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
563 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
564 elseif _G.LootSlotIsCoin(loot_slot) then
|
jcallahan@18
|
565 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
566 elseif _G.LootSlotIsCurrency(loot_slot) then
|
jcallahan@18
|
567 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
568 end
|
jcallahan@13
|
569 end
|
jcallahan@13
|
570 end
|
jcallahan@13
|
571
|
jcallahan@13
|
572 for item_id, quantity in pairs(loot_registry) do
|
jcallahan@17
|
573 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity))
|
jcallahan@13
|
574 end
|
jcallahan@13
|
575 update_func()
|
jcallahan@1
|
576 end
|
jcallahan@13
|
577 end -- do-block
|
jcallahan@0
|
578
|
jcallahan@0
|
579
|
jcallahan@5
|
580 local POINT_MATCH_PATTERNS = {
|
jcallahan@5
|
581 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
582 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
583 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@5
|
584 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@5
|
585 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@5
|
586 }
|
jcallahan@5
|
587
|
jcallahan@5
|
588
|
jcallahan@7
|
589 function WDP:UpdateMerchantItems()
|
jcallahan@4
|
590 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@4
|
591
|
jcallahan@4
|
592 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@4
|
593 return
|
jcallahan@4
|
594 end
|
jcallahan@19
|
595 local merchant = DBEntry("npcs", unit_idnum)
|
jcallahan@6
|
596 merchant.sells = merchant.sells or {}
|
jcallahan@5
|
597
|
jcallahan@5
|
598 for item_index = 1, _G.GetMerchantNumItems() do
|
jcallahan@5
|
599 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
|
jcallahan@5
|
600 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
|
jcallahan@5
|
601
|
jcallahan@5
|
602 if item_id and item_id > 0 then
|
jcallahan@5
|
603 local price_string = copper_price
|
jcallahan@5
|
604
|
jcallahan@5
|
605 if extended_cost then
|
jcallahan@5
|
606 local bg_points = 0
|
jcallahan@5
|
607 local personal_points = 0
|
jcallahan@5
|
608
|
jcallahan@5
|
609 DatamineTT:ClearLines()
|
jcallahan@5
|
610 DatamineTT:SetMerchantItem(item_index)
|
jcallahan@5
|
611
|
jcallahan@5
|
612 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@5
|
613 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@5
|
614
|
jcallahan@5
|
615 if not current_line then
|
jcallahan@5
|
616 break
|
jcallahan@5
|
617 end
|
jcallahan@5
|
618 local breakout
|
jcallahan@5
|
619
|
jcallahan@5
|
620 for match_index = 1, #POINT_MATCH_PATTERNS do
|
jcallahan@5
|
621 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
|
jcallahan@5
|
622 personal_points = personal_points + (match1 or 0)
|
jcallahan@5
|
623 bg_points = bg_points + (match2 or 0)
|
jcallahan@5
|
624
|
jcallahan@5
|
625 if match1 or match2 then
|
jcallahan@5
|
626 breakout = true
|
jcallahan@5
|
627 break
|
jcallahan@5
|
628 end
|
jcallahan@5
|
629 end
|
jcallahan@5
|
630
|
jcallahan@5
|
631 if breakout then
|
jcallahan@5
|
632 break
|
jcallahan@5
|
633 end
|
jcallahan@5
|
634 end
|
jcallahan@5
|
635 local currency_list = {}
|
jcallahan@5
|
636
|
jcallahan@5
|
637 price_string = ("%s:%s:%s"):format(price_string, bg_points, personal_points)
|
jcallahan@5
|
638
|
jcallahan@5
|
639 for cost_index = 1, _G.GetMerchantItemCostInfo(item_index) do
|
jcallahan@5
|
640 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
|
jcallahan@5
|
641 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
|
jcallahan@5
|
642
|
jcallahan@5
|
643 if not currency_id or currency_id < 1 then
|
jcallahan@5
|
644 if not icon_texture then
|
jcallahan@5
|
645 return
|
jcallahan@5
|
646 end
|
jcallahan@5
|
647 currency_id = icon_texture:match("[^\\]+$"):lower()
|
jcallahan@5
|
648 end
|
jcallahan@5
|
649 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
|
jcallahan@5
|
650 end
|
jcallahan@5
|
651
|
jcallahan@5
|
652 for currency_index = 1, #currency_list do
|
jcallahan@5
|
653 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
|
jcallahan@5
|
654 end
|
jcallahan@5
|
655 end
|
jcallahan@6
|
656 merchant.sells[("%s:%s:[%s]"):format(item_id, stack_size, price_string)] = num_available
|
jcallahan@5
|
657 end
|
jcallahan@4
|
658 end
|
jcallahan@14
|
659
|
jcallahan@14
|
660 if _G.CanMerchantRepair() then
|
jcallahan@14
|
661 merchant.can_repair = true
|
jcallahan@14
|
662 end
|
jcallahan@4
|
663 end
|
jcallahan@4
|
664
|
jcallahan@4
|
665
|
jcallahan@25
|
666 function WDP:PET_BAR_UPDATE()
|
jcallahan@25
|
667 if not action_data.label or not action_data.label == "mind_control" then
|
jcallahan@25
|
668 return
|
jcallahan@25
|
669 end
|
jcallahan@25
|
670 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("pet"))
|
jcallahan@25
|
671
|
jcallahan@25
|
672 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@25
|
673 return
|
jcallahan@25
|
674 end
|
jcallahan@25
|
675 DBEntry("npcs", unit_idnum).mind_control = true
|
jcallahan@27
|
676 print("Wiping action_data")
|
jcallahan@25
|
677 table.wipe(action_data)
|
jcallahan@25
|
678 end
|
jcallahan@25
|
679
|
jcallahan@25
|
680
|
jcallahan@18
|
681 do
|
jcallahan@18
|
682 local GENDER_NAMES = {
|
jcallahan@18
|
683 "UNKNOWN",
|
jcallahan@18
|
684 "MALE",
|
jcallahan@18
|
685 "FEMALE",
|
jcallahan@18
|
686 }
|
jcallahan@2
|
687
|
jcallahan@2
|
688
|
jcallahan@18
|
689 local REACTION_NAMES = {
|
jcallahan@18
|
690 "HATED",
|
jcallahan@18
|
691 "HOSTILE",
|
jcallahan@18
|
692 "UNFRIENDLY",
|
jcallahan@18
|
693 "NEUTRAL",
|
jcallahan@18
|
694 "FRIENDLY",
|
jcallahan@18
|
695 "HONORED",
|
jcallahan@18
|
696 "REVERED",
|
jcallahan@18
|
697 "EXALTED",
|
jcallahan@18
|
698 }
|
jcallahan@2
|
699
|
jcallahan@2
|
700
|
jcallahan@18
|
701 local POWER_TYPE_NAMES = {
|
jcallahan@18
|
702 ["0"] = "MANA",
|
jcallahan@18
|
703 ["1"] = "RAGE",
|
jcallahan@18
|
704 ["2"] = "FOCUS",
|
jcallahan@18
|
705 ["3"] = "ENERGY",
|
jcallahan@18
|
706 ["6"] = "RUNIC_POWER",
|
jcallahan@18
|
707 }
|
jcallahan@2
|
708
|
jcallahan@2
|
709
|
jcallahan@18
|
710 function WDP:PLAYER_TARGET_CHANGED()
|
jcallahan@18
|
711 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@18
|
712 return
|
jcallahan@18
|
713 end
|
jcallahan@18
|
714 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
715
|
jcallahan@18
|
716 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@18
|
717 return
|
jcallahan@18
|
718 end
|
jcallahan@19
|
719 local npc = DBEntry("npcs", unit_idnum)
|
jcallahan@18
|
720 local _, class_token = _G.UnitClass("target")
|
jcallahan@18
|
721 npc.class = class_token
|
jcallahan@20
|
722
|
jcallahan@20
|
723 UpdateFactionNames()
|
jcallahan@20
|
724 DatamineTT:ClearLines()
|
jcallahan@20
|
725 DatamineTT:SetUnit("target")
|
jcallahan@20
|
726
|
jcallahan@20
|
727 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@20
|
728 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@20
|
729
|
jcallahan@20
|
730 if not current_line then
|
jcallahan@20
|
731 break
|
jcallahan@20
|
732 end
|
jcallahan@20
|
733 local line_text = current_line:GetText()
|
jcallahan@20
|
734
|
jcallahan@20
|
735 if faction_names[line_text] then
|
jcallahan@20
|
736 npc.faction = line_text
|
jcallahan@20
|
737 break
|
jcallahan@20
|
738 end
|
jcallahan@20
|
739 end
|
jcallahan@26
|
740 npc.genders = npc.genders or {}
|
jcallahan@26
|
741 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
|
jcallahan@18
|
742 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@18
|
743 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@22
|
744 npc.encounter_data = npc.encounter_data or {}
|
jcallahan@2
|
745
|
jcallahan@18
|
746 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@3
|
747
|
jcallahan@22
|
748 if not npc.encounter_data[npc_level] then
|
jcallahan@22
|
749 npc.encounter_data[npc_level] = {
|
jcallahan@18
|
750 max_health = _G.UnitHealthMax("target"),
|
jcallahan@18
|
751 }
|
jcallahan@3
|
752
|
jcallahan@18
|
753 local max_power = _G.UnitManaMax("target")
|
jcallahan@18
|
754
|
jcallahan@18
|
755 if max_power > 0 then
|
jcallahan@18
|
756 local power_type = _G.UnitPowerType("target")
|
jcallahan@22
|
757 npc.encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@18
|
758 end
|
jcallahan@3
|
759 end
|
jcallahan@21
|
760 table.wipe(action_data)
|
jcallahan@21
|
761 action_data.type = AF.NPC
|
jcallahan@27
|
762 action_data.identifier = unit_idnum
|
jcallahan@21
|
763 action_data.npc_level = npc_level
|
jcallahan@2
|
764 end
|
jcallahan@18
|
765 end -- do-block
|
jcallahan@2
|
766
|
jcallahan@12
|
767 do
|
jcallahan@12
|
768 local function UpdateQuestJuncture(point)
|
jcallahan@12
|
769 local unit_name = _G.UnitName("questnpc")
|
jcallahan@9
|
770
|
jcallahan@12
|
771 if not unit_name then
|
jcallahan@12
|
772 return
|
jcallahan@12
|
773 end
|
jcallahan@12
|
774 local unit_type, unit_id = WDP:ParseGUID(_G.UnitGUID("questnpc"))
|
jcallahan@9
|
775
|
jcallahan@12
|
776 if unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@12
|
777 UpdateObjectLocation(unit_id)
|
jcallahan@12
|
778 end
|
jcallahan@19
|
779 local quest = DBEntry("quests", _G.GetQuestID())
|
jcallahan@12
|
780 quest[point] = quest[point] or {}
|
jcallahan@12
|
781 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
|
jcallahan@24
|
782
|
jcallahan@24
|
783 return quest
|
jcallahan@12
|
784 end
|
jcallahan@10
|
785
|
jcallahan@12
|
786
|
jcallahan@12
|
787 function WDP:QUEST_COMPLETE()
|
jcallahan@12
|
788 UpdateQuestJuncture("end")
|
jcallahan@10
|
789 end
|
jcallahan@10
|
790
|
jcallahan@12
|
791
|
jcallahan@12
|
792 function WDP:QUEST_DETAIL()
|
jcallahan@24
|
793 local quest = UpdateQuestJuncture("begin")
|
jcallahan@24
|
794
|
jcallahan@24
|
795 quest.classes = quest.classes or {}
|
jcallahan@27
|
796 quest.classes[PLAYER_CLASS] = true
|
jcallahan@24
|
797
|
jcallahan@24
|
798 local _, race = _G.UnitRace("player")
|
jcallahan@24
|
799 quest.races = quest.races or {}
|
jcallahan@24
|
800 quest.races[race] = true
|
jcallahan@10
|
801 end
|
jcallahan@12
|
802 end -- do-block
|
jcallahan@9
|
803
|
jcallahan@9
|
804
|
jcallahan@4
|
805 function WDP:QUEST_LOG_UPDATE()
|
jcallahan@4
|
806 self:UnregisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
807 end
|
jcallahan@4
|
808
|
jcallahan@4
|
809
|
jcallahan@4
|
810 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
|
jcallahan@4
|
811 if unit_id ~= "player" then
|
jcallahan@4
|
812 return
|
jcallahan@4
|
813 end
|
jcallahan@4
|
814 self:RegisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
815 end
|
jcallahan@4
|
816
|
jcallahan@4
|
817
|
jcallahan@27
|
818 function WDP:TRAINER_SHOW()
|
jcallahan@27
|
819 if not _G.IsTradeskillTrainer() then
|
jcallahan@27
|
820 return
|
jcallahan@27
|
821 end
|
jcallahan@27
|
822 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
|
jcallahan@27
|
823 local npc = DBEntry("npcs", unit_idnum)
|
jcallahan@27
|
824 npc.teaches = npc.teaches or {}
|
jcallahan@27
|
825
|
jcallahan@27
|
826 -- Get the initial trainer filters
|
jcallahan@27
|
827 local available = _G.GetTrainerServiceTypeFilter("available")
|
jcallahan@27
|
828 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
|
jcallahan@27
|
829 local used = _G.GetTrainerServiceTypeFilter("used")
|
jcallahan@27
|
830
|
jcallahan@27
|
831 -- Clear the trainer filters
|
jcallahan@27
|
832 _G.SetTrainerServiceTypeFilter("available", 1)
|
jcallahan@27
|
833 _G.SetTrainerServiceTypeFilter("unavailable", 1)
|
jcallahan@27
|
834 _G.SetTrainerServiceTypeFilter("used", 1)
|
jcallahan@27
|
835
|
jcallahan@27
|
836 for index = 1, _G.GetNumTrainerServices(), 1 do
|
jcallahan@27
|
837 local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
|
jcallahan@27
|
838
|
jcallahan@27
|
839 if spell_name then
|
jcallahan@27
|
840 DatamineTT:ClearLines()
|
jcallahan@27
|
841 DatamineTT:SetTrainerService(index)
|
jcallahan@27
|
842
|
jcallahan@27
|
843 local _, _, spell_id = DatamineTT:GetSpell()
|
jcallahan@27
|
844 local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
|
jcallahan@27
|
845 profession = profession or "General"
|
jcallahan@27
|
846
|
jcallahan@27
|
847 local class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@27
|
848 if not class_professions then
|
jcallahan@27
|
849 npc.teaches[PLAYER_CLASS] = {}
|
jcallahan@27
|
850 class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@27
|
851 end
|
jcallahan@27
|
852
|
jcallahan@27
|
853 local profession_skills = class_professions[profession]
|
jcallahan@27
|
854 if not profession_skills then
|
jcallahan@27
|
855 class_professions[profession] = {}
|
jcallahan@27
|
856 profession_skills = class_professions[profession]
|
jcallahan@27
|
857 end
|
jcallahan@27
|
858 profession_skills[spell_id] = ("%d:%d"):format(required_level, min_skill)
|
jcallahan@27
|
859 end
|
jcallahan@27
|
860 end
|
jcallahan@27
|
861
|
jcallahan@27
|
862 -- Reset the filters to what they were before
|
jcallahan@27
|
863 _G.SetTrainerServiceTypeFilter("available", available or 0)
|
jcallahan@27
|
864 _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
|
jcallahan@27
|
865 _G.SetTrainerServiceTypeFilter("used", used or 0)
|
jcallahan@27
|
866 end
|
jcallahan@27
|
867
|
jcallahan@27
|
868
|
jcallahan@1
|
869 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
870 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
871 return
|
jcallahan@1
|
872 end
|
jcallahan@1
|
873 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
874
|
jcallahan@1
|
875 if not spell_label then
|
jcallahan@1
|
876 return
|
jcallahan@1
|
877 end
|
jcallahan@18
|
878 table.wipe(action_data)
|
jcallahan@1
|
879
|
jcallahan@1
|
880 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
|
jcallahan@1
|
881 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
882
|
jcallahan@1
|
883 if not tt_unit_name and _G.UnitName("target") == target_name then
|
jcallahan@1
|
884 tt_unit_name = target_name
|
jcallahan@1
|
885 tt_unit_id = "target"
|
jcallahan@1
|
886 end
|
jcallahan@1
|
887 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@1
|
888
|
jcallahan@16
|
889 if tt_unit_name and not tt_item_name then
|
jcallahan@16
|
890 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@16
|
891 if not tt_unit_id or tt_unit_name ~= target_name then
|
jcallahan@16
|
892 return
|
jcallahan@16
|
893 end
|
jcallahan@16
|
894 action_data.type = AF.NPC
|
jcallahan@25
|
895 action_data.label = spell_label:lower()
|
jcallahan@25
|
896 action_data.unit_name = tt_unit_name
|
jcallahan@16
|
897 end
|
jcallahan@16
|
898 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@16
|
899 action_data.type = AF.ITEM
|
jcallahan@25
|
900 action_data.label = spell_label:lower()
|
jcallahan@16
|
901
|
jcallahan@16
|
902 if tt_item_name and tt_item_name == target_name then
|
jcallahan@16
|
903 action_data.item_id = ItemLinkToID(tt_item_link)
|
jcallahan@16
|
904 elseif target_name and target_name ~= "" then
|
jcallahan@16
|
905 local _, target_item_link = _G.GetItemInfo(target_name)
|
jcallahan@16
|
906 action_data.item_id = ItemLinkToID(target_item_link)
|
jcallahan@16
|
907 end
|
jcallahan@16
|
908 elseif not tt_item_name and not tt_unit_name then
|
jcallahan@24
|
909 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@1
|
910
|
jcallahan@22
|
911 action_data.instance_token = instance_token
|
jcallahan@17
|
912 action_data.map_level = map_level
|
jcallahan@17
|
913 action_data.name = target_name
|
jcallahan@17
|
914 action_data.x = x
|
jcallahan@17
|
915 action_data.y = y
|
jcallahan@24
|
916 action_data.zone = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@17
|
917
|
jcallahan@1
|
918 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@17
|
919 if target_name == "" then
|
jcallahan@17
|
920 return
|
jcallahan@17
|
921 end
|
jcallahan@11
|
922 local identifier = ("%s:%s"):format(spell_label, target_name)
|
jcallahan@11
|
923 UpdateObjectLocation(identifier)
|
jcallahan@11
|
924
|
jcallahan@1
|
925 action_data.type = AF.OBJECT
|
jcallahan@11
|
926 action_data.identifier = identifier
|
jcallahan@1
|
927 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@17
|
928 action_data.type = AF.ZONE
|
jcallahan@25
|
929 action_data.label = spell_label:lower()
|
jcallahan@1
|
930 end
|
jcallahan@1
|
931 end
|
jcallahan@1
|
932
|
jcallahan@18
|
933 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
|
jcallahan@1
|
934 private.tracked_line = spell_line
|
jcallahan@0
|
935 end
|
jcallahan@0
|
936
|
jcallahan@0
|
937
|
jcallahan@1
|
938 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
939 if unit_id ~= "player" then
|
jcallahan@1
|
940 return
|
jcallahan@1
|
941 end
|
jcallahan@1
|
942
|
jcallahan@18
|
943 -- if private.SPELL_LABELS_BY_NAME[spell_name] then
|
jcallahan@18
|
944 -- print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id))
|
jcallahan@18
|
945 -- end
|
jcallahan@1
|
946 private.tracked_line = nil
|
jcallahan@0
|
947 end
|
jcallahan@0
|
948
|
jcallahan@1
|
949 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
950 if unit_id ~= "player" then
|
jcallahan@1
|
951 return
|
jcallahan@1
|
952 end
|
jcallahan@0
|
953
|
jcallahan@1
|
954 if private.tracked_line == spell_line then
|
jcallahan@1
|
955 private.tracked_line = nil
|
jcallahan@1
|
956 end
|
jcallahan@0
|
957 end
|