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@48
|
22 local deformat = LibStub("LibDeformat-3.0")
|
jcallahan@48
|
23
|
jcallahan@4
|
24 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
|
jcallahan@5
|
25 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
|
jcallahan@5
|
26
|
jcallahan@0
|
27
|
jcallahan@0
|
28 -----------------------------------------------------------------------
|
jcallahan@0
|
29 -- Local constants.
|
jcallahan@0
|
30 -----------------------------------------------------------------------
|
jcallahan@0
|
31 local DATABASE_DEFAULTS = {
|
jcallahan@0
|
32 global = {
|
jcallahan@0
|
33 items = {},
|
jcallahan@0
|
34 npcs = {},
|
jcallahan@0
|
35 objects = {},
|
jcallahan@0
|
36 quests = {},
|
jcallahan@17
|
37 zones = {},
|
jcallahan@0
|
38 }
|
jcallahan@0
|
39 }
|
jcallahan@0
|
40
|
jcallahan@0
|
41
|
jcallahan@1
|
42 local EVENT_MAPPING = {
|
jcallahan@48
|
43 CHAT_MSG_LOOT = true,
|
jcallahan@40
|
44 CHAT_MSG_SYSTEM = true,
|
jcallahan@23
|
45 COMBAT_LOG_EVENT_UNFILTERED = true,
|
jcallahan@18
|
46 COMBAT_TEXT_UPDATE = true,
|
jcallahan@42
|
47 ITEM_TEXT_BEGIN = true,
|
jcallahan@1
|
48 LOOT_OPENED = true,
|
jcallahan@7
|
49 MERCHANT_SHOW = "UpdateMerchantItems",
|
jcallahan@35
|
50 -- MERCHANT_UPDATE = "UpdateMerchantItems",
|
jcallahan@25
|
51 PET_BAR_UPDATE = true,
|
jcallahan@2
|
52 PLAYER_TARGET_CHANGED = true,
|
jcallahan@9
|
53 QUEST_COMPLETE = true,
|
jcallahan@9
|
54 QUEST_DETAIL = true,
|
jcallahan@9
|
55 QUEST_LOG_UPDATE = true,
|
jcallahan@27
|
56 TRAINER_SHOW = true,
|
jcallahan@4
|
57 UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
58 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
59 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
60 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
61 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
62 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@0
|
63 }
|
jcallahan@0
|
64
|
jcallahan@4
|
65
|
jcallahan@1
|
66 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
67
|
jcallahan@4
|
68
|
jcallahan@27
|
69 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
|
jcallahan@34
|
70 local PLAYER_GUID = _G.UnitGUID("player")
|
jcallahan@39
|
71 local PLAYER_RACE = _G.select(2, _G.UnitRace("player"))
|
jcallahan@27
|
72
|
jcallahan@0
|
73 -----------------------------------------------------------------------
|
jcallahan@0
|
74 -- Local variables.
|
jcallahan@0
|
75 -----------------------------------------------------------------------
|
jcallahan@0
|
76 local db
|
jcallahan@0
|
77 local durability_timer_handle
|
jcallahan@2
|
78 local target_location_timer_handle
|
jcallahan@1
|
79 local action_data = {}
|
jcallahan@40
|
80 local currently_drunk
|
jcallahan@32
|
81 local faction_standings = {}
|
jcallahan@0
|
82
|
jcallahan@1
|
83
|
jcallahan@1
|
84 -----------------------------------------------------------------------
|
jcallahan@1
|
85 -- Helper Functions.
|
jcallahan@1
|
86 -----------------------------------------------------------------------
|
jcallahan@39
|
87 local ActualCopperCost
|
jcallahan@39
|
88 do
|
jcallahan@39
|
89 local BARTERING_SPELL_ID = 83964
|
jcallahan@39
|
90
|
jcallahan@39
|
91 local STANDING_DISCOUNTS = {
|
jcallahan@39
|
92 HATED = 0,
|
jcallahan@39
|
93 HOSTILE = 0,
|
jcallahan@39
|
94 UNFRIENDLY = 0,
|
jcallahan@39
|
95 NEUTRAL = 0,
|
jcallahan@39
|
96 FRIENDLY = 0.05,
|
jcallahan@39
|
97 HONORED = 0.1,
|
jcallahan@39
|
98 REVERED = 0.15,
|
jcallahan@39
|
99 EXALTED = 0.2,
|
jcallahan@39
|
100 }
|
jcallahan@39
|
101
|
jcallahan@39
|
102
|
jcallahan@39
|
103 function ActualCopperCost(copper_cost, rep_standing)
|
jcallahan@39
|
104 if not copper_cost or copper_cost == 0 then
|
jcallahan@39
|
105 return 0
|
jcallahan@39
|
106 end
|
jcallahan@39
|
107 local modifier = 1
|
jcallahan@39
|
108
|
jcallahan@39
|
109 if _G.IsSpellKnown(BARTERING_SPELL_ID) then
|
jcallahan@39
|
110 modifier = modifier - 0.1
|
jcallahan@39
|
111 end
|
jcallahan@39
|
112
|
jcallahan@39
|
113 if rep_standing then
|
jcallahan@39
|
114 if PLAYER_RACE == "Goblin" then
|
jcallahan@39
|
115 modifier = modifier - STANDING_DISCOUNTS["EXALTED"]
|
jcallahan@39
|
116 elseif STANDING_DISCOUNTS[rep_standing] then
|
jcallahan@39
|
117 modifier = modifier - STANDING_DISCOUNTS[rep_standing]
|
jcallahan@39
|
118 end
|
jcallahan@39
|
119 end
|
jcallahan@39
|
120 return math.floor(copper_cost / modifier)
|
jcallahan@39
|
121 end
|
jcallahan@39
|
122 end -- do-block
|
jcallahan@39
|
123
|
jcallahan@39
|
124
|
jcallahan@29
|
125 local function InstanceDifficultyToken()
|
jcallahan@29
|
126 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
|
jcallahan@29
|
127 if difficulty_name == "" then
|
jcallahan@29
|
128 difficulty_name = "NONE"
|
jcallahan@29
|
129 end
|
jcallahan@29
|
130 return ("%s:%s:%s"):format(instance_type:upper(), difficulty_name:upper():gsub(" ", "_"), _G.tostring(is_dynamic))
|
jcallahan@29
|
131 end
|
jcallahan@29
|
132
|
jcallahan@29
|
133
|
jcallahan@19
|
134 local function DBEntry(data_type, unit_id)
|
jcallahan@19
|
135 if not data_type or not unit_id then
|
jcallahan@6
|
136 return
|
jcallahan@6
|
137 end
|
jcallahan@19
|
138 local unit = db[data_type][unit_id]
|
jcallahan@6
|
139
|
jcallahan@10
|
140 if not unit then
|
jcallahan@19
|
141 db[data_type][unit_id] = {}
|
jcallahan@19
|
142 unit = db[data_type][unit_id]
|
jcallahan@6
|
143 end
|
jcallahan@10
|
144 return unit
|
jcallahan@6
|
145 end
|
jcallahan@6
|
146
|
jcallahan@6
|
147
|
jcallahan@29
|
148 local function NPCEntry(identifier)
|
jcallahan@29
|
149 local npc = DBEntry("npcs", identifier)
|
jcallahan@29
|
150
|
jcallahan@29
|
151 if not npc then
|
jcallahan@29
|
152 return
|
jcallahan@22
|
153 end
|
jcallahan@29
|
154 local instance_token = InstanceDifficultyToken()
|
jcallahan@29
|
155 npc.encounter_data = npc.encounter_data or {}
|
jcallahan@29
|
156 npc.encounter_data[instance_token] = npc.encounter_data[instance_token] or {}
|
jcallahan@30
|
157 npc.encounter_data[instance_token].stats = npc.encounter_data[instance_token].stats or {}
|
jcallahan@29
|
158 return npc
|
jcallahan@22
|
159 end
|
jcallahan@22
|
160
|
jcallahan@22
|
161
|
jcallahan@1
|
162 local function CurrentLocationData()
|
jcallahan@1
|
163 local map_level = _G.GetCurrentMapDungeonLevel() or 0
|
jcallahan@1
|
164 local x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
165
|
jcallahan@1
|
166 x = x or 0
|
jcallahan@1
|
167 y = y or 0
|
jcallahan@1
|
168
|
jcallahan@1
|
169 if x == 0 and y == 0 then
|
jcallahan@1
|
170 for level_index = 1, _G.GetNumDungeonMapLevels() do
|
jcallahan@1
|
171 _G.SetDungeonMapLevel(level_index)
|
jcallahan@1
|
172 x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
173
|
jcallahan@1
|
174 if x and y and (x > 0 or y > 0) then
|
jcallahan@1
|
175 _G.SetDungeonMapLevel(map_level)
|
jcallahan@1
|
176 map_level = level_index
|
jcallahan@1
|
177 break
|
jcallahan@1
|
178 end
|
jcallahan@1
|
179 end
|
jcallahan@1
|
180 end
|
jcallahan@1
|
181
|
jcallahan@1
|
182 if _G.DungeonUsesTerrainMap() then
|
jcallahan@1
|
183 map_level = map_level - 1
|
jcallahan@1
|
184 end
|
jcallahan@31
|
185 local x = _G.floor(x * 1000)
|
jcallahan@31
|
186 local y = _G.floor(y * 1000)
|
jcallahan@28
|
187
|
jcallahan@31
|
188 if x % 2 ~= 0 then
|
jcallahan@31
|
189 x = x + 1
|
jcallahan@28
|
190 end
|
jcallahan@28
|
191
|
jcallahan@31
|
192 if y % 2 ~= 0 then
|
jcallahan@31
|
193 y = y + 1
|
jcallahan@28
|
194 end
|
jcallahan@31
|
195 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), x, y, map_level, InstanceDifficultyToken()
|
jcallahan@1
|
196 end
|
jcallahan@1
|
197
|
jcallahan@1
|
198
|
jcallahan@1
|
199 local function ItemLinkToID(item_link)
|
jcallahan@1
|
200 if not item_link then
|
jcallahan@1
|
201 return
|
jcallahan@1
|
202 end
|
jcallahan@7
|
203 return tonumber(item_link:match("item:(%d+)"))
|
jcallahan@1
|
204 end
|
jcallahan@0
|
205
|
jcallahan@4
|
206
|
jcallahan@34
|
207 local ParseGUID
|
jcallahan@4
|
208 do
|
jcallahan@4
|
209 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@4
|
210
|
jcallahan@34
|
211 function ParseGUID(guid)
|
jcallahan@5
|
212 if not guid then
|
jcallahan@5
|
213 return
|
jcallahan@5
|
214 end
|
jcallahan@4
|
215 local types = private.UNIT_TYPES
|
jcallahan@4
|
216 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@4
|
217
|
jcallahan@10
|
218 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
|
jcallahan@4
|
219 return unit_type, tonumber(guid:sub(-12, -9), 16)
|
jcallahan@4
|
220 end
|
jcallahan@4
|
221
|
jcallahan@4
|
222 return unit_type
|
jcallahan@4
|
223 end
|
jcallahan@4
|
224 end -- do-block
|
jcallahan@4
|
225
|
jcallahan@4
|
226
|
jcallahan@34
|
227 local UpdateNPCLocation
|
jcallahan@34
|
228 do
|
jcallahan@34
|
229 local COORD_MAX = 5
|
jcallahan@34
|
230
|
jcallahan@34
|
231 function UpdateNPCLocation(unit_idnum)
|
jcallahan@34
|
232 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@34
|
233 local npc_data = NPCEntry(unit_idnum).encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@34
|
234 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@34
|
235 npc_data.locations = npc_data.locations or {}
|
jcallahan@34
|
236
|
jcallahan@34
|
237 local zone_data = npc_data.locations[zone_token]
|
jcallahan@34
|
238
|
jcallahan@34
|
239 if not zone_data then
|
jcallahan@34
|
240 zone_data = {}
|
jcallahan@34
|
241 npc_data.locations[zone_token] = zone_data
|
jcallahan@34
|
242 end
|
jcallahan@34
|
243
|
jcallahan@34
|
244 for location_token in pairs(zone_data) do
|
jcallahan@34
|
245 local loc_level, loc_x, loc_y = (":"):split(location_token)
|
jcallahan@34
|
246 loc_level = tonumber(loc_level)
|
jcallahan@34
|
247
|
jcallahan@34
|
248 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
|
jcallahan@34
|
249 return
|
jcallahan@34
|
250 end
|
jcallahan@34
|
251 end
|
jcallahan@34
|
252 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true
|
jcallahan@34
|
253 end
|
jcallahan@34
|
254 end -- do-block
|
jcallahan@34
|
255
|
jcallahan@34
|
256
|
jcallahan@47
|
257 local function UpdateDBEntryLocation(entry_type, identifier, location_label)
|
jcallahan@10
|
258 if not identifier then
|
jcallahan@10
|
259 return
|
jcallahan@10
|
260 end
|
jcallahan@31
|
261 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@41
|
262 local entry = DBEntry(entry_type, identifier)
|
jcallahan@47
|
263 local location_field = location_label or "locations"
|
jcallahan@41
|
264 entry[difficulty_token] = entry[difficulty_token] or {}
|
jcallahan@47
|
265 entry[difficulty_token][location_field] = entry[difficulty_token][location_field] or {}
|
jcallahan@10
|
266
|
jcallahan@31
|
267 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@47
|
268 local zone_data = entry[difficulty_token][location_field][zone_token]
|
jcallahan@24
|
269
|
jcallahan@31
|
270 if not zone_data then
|
jcallahan@31
|
271 zone_data = {}
|
jcallahan@47
|
272 entry[difficulty_token][location_field][zone_token] = zone_data
|
jcallahan@10
|
273 end
|
jcallahan@41
|
274 local location_token = ("%s:%s:%s"):format(map_level, x, y)
|
jcallahan@41
|
275 zone_data[location_token] = zone_data[location_token] or true
|
jcallahan@41
|
276 return zone_data
|
jcallahan@10
|
277 end
|
jcallahan@10
|
278
|
jcallahan@10
|
279
|
jcallahan@19
|
280 local function HandleItemUse(item_link, bag_index, slot_index)
|
jcallahan@19
|
281 if not item_link then
|
jcallahan@19
|
282 return
|
jcallahan@19
|
283 end
|
jcallahan@19
|
284 local item_id = ItemLinkToID(item_link)
|
jcallahan@19
|
285
|
jcallahan@19
|
286 if not bag_index or not slot_index then
|
jcallahan@19
|
287 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@19
|
288 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
|
jcallahan@19
|
289 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
|
jcallahan@19
|
290 bag_index = new_bag_index
|
jcallahan@19
|
291 slot_index = new_slot_index
|
jcallahan@19
|
292 break
|
jcallahan@19
|
293 end
|
jcallahan@19
|
294 end
|
jcallahan@19
|
295 end
|
jcallahan@19
|
296 end
|
jcallahan@19
|
297
|
jcallahan@19
|
298 if not bag_index or not slot_index then
|
jcallahan@19
|
299 return
|
jcallahan@19
|
300 end
|
jcallahan@19
|
301 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@19
|
302
|
jcallahan@19
|
303 if not is_lootable then
|
jcallahan@19
|
304 return
|
jcallahan@19
|
305 end
|
jcallahan@19
|
306 DatamineTT:ClearLines()
|
jcallahan@19
|
307 DatamineTT:SetBagItem(bag_index, slot_index)
|
jcallahan@19
|
308
|
jcallahan@19
|
309 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@19
|
310 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@19
|
311
|
jcallahan@19
|
312 if not current_line then
|
jcallahan@19
|
313 break
|
jcallahan@19
|
314 end
|
jcallahan@19
|
315
|
jcallahan@19
|
316 if current_line:GetText() == _G.ITEM_OPENABLE then
|
jcallahan@19
|
317 table.wipe(action_data)
|
jcallahan@19
|
318 action_data.type = AF.ITEM
|
jcallahan@28
|
319 action_data.identifier = item_id
|
jcallahan@25
|
320 action_data.label = "contains"
|
jcallahan@19
|
321 break
|
jcallahan@19
|
322 end
|
jcallahan@19
|
323 end
|
jcallahan@19
|
324 end
|
jcallahan@19
|
325
|
jcallahan@19
|
326
|
jcallahan@39
|
327 local UnitFactionStanding
|
jcallahan@32
|
328 local UpdateFactionData
|
jcallahan@32
|
329 do
|
jcallahan@32
|
330 local MAX_FACTION_INDEX = 1000
|
jcallahan@20
|
331
|
jcallahan@32
|
332 local STANDING_NAMES = {
|
jcallahan@32
|
333 "HATED",
|
jcallahan@32
|
334 "HOSTILE",
|
jcallahan@32
|
335 "UNFRIENDLY",
|
jcallahan@32
|
336 "NEUTRAL",
|
jcallahan@32
|
337 "FRIENDLY",
|
jcallahan@32
|
338 "HONORED",
|
jcallahan@32
|
339 "REVERED",
|
jcallahan@32
|
340 "EXALTED",
|
jcallahan@32
|
341 }
|
jcallahan@32
|
342
|
jcallahan@39
|
343
|
jcallahan@39
|
344 function UnitFactionStanding(unit)
|
jcallahan@39
|
345 UpdateFactionData()
|
jcallahan@39
|
346 DatamineTT:ClearLines()
|
jcallahan@39
|
347 DatamineTT:SetUnit(unit)
|
jcallahan@39
|
348
|
jcallahan@39
|
349 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@39
|
350 local faction_name = _G["WDPDatamineTTTextLeft" .. line_index]:GetText()
|
jcallahan@39
|
351
|
jcallahan@39
|
352 if faction_name and faction_standings[faction_name] then
|
jcallahan@39
|
353 return faction_name, faction_standings[faction_name]
|
jcallahan@39
|
354 end
|
jcallahan@39
|
355 end
|
jcallahan@39
|
356 end
|
jcallahan@39
|
357
|
jcallahan@39
|
358
|
jcallahan@32
|
359 function UpdateFactionData()
|
jcallahan@32
|
360 for faction_index = 1, MAX_FACTION_INDEX do
|
jcallahan@32
|
361 local faction_name, _, current_standing, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
|
jcallahan@32
|
362
|
jcallahan@32
|
363 if faction_name and not is_header then
|
jcallahan@32
|
364 faction_standings[faction_name] = STANDING_NAMES[current_standing]
|
jcallahan@32
|
365 elseif not faction_name then
|
jcallahan@32
|
366 break
|
jcallahan@32
|
367 end
|
jcallahan@20
|
368 end
|
jcallahan@20
|
369 end
|
jcallahan@32
|
370 end -- do-block
|
jcallahan@20
|
371
|
jcallahan@48
|
372
|
jcallahan@48
|
373 local function GenericLootUpdate(data_type, top_field, inline_drops)
|
jcallahan@48
|
374 local entry = DBEntry(data_type, action_data.identifier)
|
jcallahan@48
|
375
|
jcallahan@48
|
376 if not entry then
|
jcallahan@48
|
377 return
|
jcallahan@48
|
378 end
|
jcallahan@48
|
379 local loot_type = action_data.label or "drops"
|
jcallahan@48
|
380 local loot_count = ("%s_count"):format(loot_type)
|
jcallahan@48
|
381 local loot_data
|
jcallahan@48
|
382
|
jcallahan@48
|
383 if top_field then
|
jcallahan@48
|
384 entry[top_field] = entry[top_field] or {}
|
jcallahan@48
|
385 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
|
jcallahan@48
|
386 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
|
jcallahan@48
|
387 loot_data = entry[top_field][loot_type]
|
jcallahan@48
|
388 else
|
jcallahan@48
|
389 entry[loot_count] = (entry[loot_count] or 0) + 1
|
jcallahan@48
|
390 entry[loot_type] = entry[loot_type] or {}
|
jcallahan@48
|
391 loot_data = entry[loot_type]
|
jcallahan@48
|
392 end
|
jcallahan@48
|
393
|
jcallahan@48
|
394 for index = 1, #action_data.loot_list do
|
jcallahan@48
|
395 table.insert(loot_data, action_data.loot_list[index])
|
jcallahan@48
|
396 end
|
jcallahan@48
|
397 end
|
jcallahan@48
|
398
|
jcallahan@48
|
399
|
jcallahan@0
|
400 -----------------------------------------------------------------------
|
jcallahan@0
|
401 -- Methods.
|
jcallahan@0
|
402 -----------------------------------------------------------------------
|
jcallahan@0
|
403 function WDP:OnInitialize()
|
jcallahan@0
|
404 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
|
jcallahan@14
|
405
|
jcallahan@14
|
406 local raw_db = _G["WoWDBProfilerData"]
|
jcallahan@14
|
407
|
jcallahan@18
|
408 local build_num = tonumber(private.build_num)
|
jcallahan@14
|
409
|
jcallahan@35
|
410 -- TODO: Un-comment this when MoP goes live.
|
jcallahan@35
|
411 -- if raw_db.build_num and raw_db.build_num < build_num then
|
jcallahan@35
|
412 -- for entry in pairs(DATABASE_DEFAULTS.global) do
|
jcallahan@35
|
413 -- db[entry] = {}
|
jcallahan@35
|
414 -- end
|
jcallahan@35
|
415 -- end
|
jcallahan@35
|
416 raw_db.build_num = build_num
|
jcallahan@0
|
417 end
|
jcallahan@0
|
418
|
jcallahan@0
|
419
|
jcallahan@0
|
420 function WDP:OnEnable()
|
jcallahan@0
|
421 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@1
|
422 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@0
|
423 end
|
jcallahan@0
|
424 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
|
jcallahan@31
|
425 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5)
|
jcallahan@19
|
426
|
jcallahan@19
|
427 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
|
jcallahan@19
|
428 if target_unit then
|
jcallahan@19
|
429 return
|
jcallahan@19
|
430 end
|
jcallahan@19
|
431 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
|
jcallahan@19
|
432 end)
|
jcallahan@19
|
433
|
jcallahan@19
|
434 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
|
jcallahan@19
|
435 if target_unit then
|
jcallahan@19
|
436 return
|
jcallahan@19
|
437 end
|
jcallahan@19
|
438 local _, item_link = _G.GetItemInfo(identifier)
|
jcallahan@19
|
439 HandleItemUse(item_link)
|
jcallahan@19
|
440 end)
|
jcallahan@0
|
441 end
|
jcallahan@0
|
442
|
jcallahan@0
|
443
|
jcallahan@0
|
444 local function RecordDurability(item_id, durability)
|
jcallahan@0
|
445 if not durability or durability <= 0 then
|
jcallahan@0
|
446 return
|
jcallahan@0
|
447 end
|
jcallahan@0
|
448
|
jcallahan@0
|
449 if not db.items[item_id] then
|
jcallahan@0
|
450 db.items[item_id] = {}
|
jcallahan@0
|
451 end
|
jcallahan@0
|
452 db.items[item_id].durability = durability
|
jcallahan@0
|
453 end
|
jcallahan@0
|
454
|
jcallahan@0
|
455
|
jcallahan@0
|
456 function WDP:ProcessDurability()
|
jcallahan@0
|
457 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
458 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
459
|
jcallahan@0
|
460 if item_id and item_id > 0 then
|
jcallahan@1
|
461 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@0
|
462 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
463 end
|
jcallahan@0
|
464 end
|
jcallahan@0
|
465
|
jcallahan@0
|
466 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
467 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
468 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
469
|
jcallahan@0
|
470 if item_id and item_id > 0 then
|
jcallahan@1
|
471 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@0
|
472 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
473 end
|
jcallahan@0
|
474 end
|
jcallahan@0
|
475 end
|
jcallahan@0
|
476 end
|
jcallahan@0
|
477
|
jcallahan@0
|
478
|
jcallahan@2
|
479 function WDP:UpdateTargetLocation()
|
jcallahan@40
|
480 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
|
jcallahan@2
|
481 return
|
jcallahan@2
|
482 end
|
jcallahan@2
|
483
|
jcallahan@2
|
484 for index = 1, 4 do
|
jcallahan@2
|
485 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@2
|
486 return
|
jcallahan@2
|
487 end
|
jcallahan@2
|
488 end
|
jcallahan@40
|
489 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
490
|
jcallahan@40
|
491 if not unit_idnum or unit_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@2
|
492 return
|
jcallahan@2
|
493 end
|
jcallahan@34
|
494 UpdateNPCLocation(unit_idnum)
|
jcallahan@2
|
495 end
|
jcallahan@2
|
496
|
jcallahan@2
|
497
|
jcallahan@0
|
498 -----------------------------------------------------------------------
|
jcallahan@0
|
499 -- Event handlers.
|
jcallahan@0
|
500 -----------------------------------------------------------------------
|
jcallahan@48
|
501 function WDP:CHAT_MSG_LOOT(event, message)
|
jcallahan@48
|
502 if action_data.spell_label ~= "EXTRACT_GAS" then
|
jcallahan@48
|
503 return
|
jcallahan@48
|
504 end
|
jcallahan@48
|
505 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE)
|
jcallahan@48
|
506
|
jcallahan@48
|
507 if not item_link then
|
jcallahan@48
|
508 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF)
|
jcallahan@48
|
509 end
|
jcallahan@48
|
510
|
jcallahan@48
|
511 if not item_link then
|
jcallahan@48
|
512 return
|
jcallahan@48
|
513 end
|
jcallahan@48
|
514 local item_id = ItemLinkToID(item_link)
|
jcallahan@48
|
515
|
jcallahan@48
|
516 if not item_id then
|
jcallahan@48
|
517 return
|
jcallahan@48
|
518 end
|
jcallahan@48
|
519 action_data.loot_list = {
|
jcallahan@48
|
520 ("%d:%d"):format(item_id, quantity)
|
jcallahan@48
|
521 }
|
jcallahan@48
|
522 GenericLootUpdate("zones")
|
jcallahan@48
|
523 table.wipe(action_data)
|
jcallahan@48
|
524 end
|
jcallahan@48
|
525
|
jcallahan@48
|
526
|
jcallahan@23
|
527 do
|
jcallahan@40
|
528 local SOBER_MATCH = _G.DRUNK_MESSAGE_ITEM_SELF1:gsub("%%s", ".+")
|
jcallahan@40
|
529
|
jcallahan@40
|
530 local DRUNK_COMPARES = {
|
jcallahan@40
|
531 _G.DRUNK_MESSAGE_SELF2,
|
jcallahan@40
|
532 _G.DRUNK_MESSAGE_SELF3,
|
jcallahan@40
|
533 _G.DRUNK_MESSAGE_SELF4,
|
jcallahan@40
|
534 }
|
jcallahan@40
|
535
|
jcallahan@40
|
536 local DRUNK_MATCHES = {
|
jcallahan@40
|
537 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
|
jcallahan@40
|
538 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
|
jcallahan@40
|
539 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
|
jcallahan@40
|
540 }
|
jcallahan@40
|
541
|
jcallahan@40
|
542 function WDP:CHAT_MSG_SYSTEM(event, message)
|
jcallahan@40
|
543 if currently_drunk then
|
jcallahan@40
|
544 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
|
jcallahan@40
|
545 currently_drunk = nil
|
jcallahan@40
|
546 end
|
jcallahan@40
|
547 return
|
jcallahan@40
|
548 end
|
jcallahan@40
|
549
|
jcallahan@40
|
550 for index = 1, #DRUNK_MATCHES do
|
jcallahan@40
|
551 if message == DRUNK_COMPARES[index] or message:match(DRUNK_MATCHES[index]) then
|
jcallahan@40
|
552 currently_drunk = true
|
jcallahan@40
|
553 break
|
jcallahan@40
|
554 end
|
jcallahan@40
|
555 end
|
jcallahan@40
|
556 end
|
jcallahan@40
|
557 end
|
jcallahan@40
|
558
|
jcallahan@40
|
559 -- do-block
|
jcallahan@40
|
560
|
jcallahan@40
|
561 do
|
jcallahan@23
|
562 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
563 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
564
|
jcallahan@23
|
565
|
jcallahan@23
|
566 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@23
|
567 if not spell_id then
|
jcallahan@23
|
568 return
|
jcallahan@23
|
569 end
|
jcallahan@34
|
570 local source_type, source_id = ParseGUID(source_guid)
|
jcallahan@23
|
571
|
jcallahan@23
|
572 if not source_id or source_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@23
|
573 return
|
jcallahan@23
|
574 end
|
jcallahan@23
|
575
|
jcallahan@23
|
576 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
|
jcallahan@29
|
577 local encounter_data = NPCEntry(source_id).encounter_data[InstanceDifficultyToken()]
|
jcallahan@28
|
578 encounter_data.spells = encounter_data.spells or {}
|
jcallahan@28
|
579 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
|
jcallahan@23
|
580 end
|
jcallahan@23
|
581 end
|
jcallahan@23
|
582
|
jcallahan@23
|
583 local COMBAT_LOG_FUNCS = {
|
jcallahan@23
|
584 SPELL_AURA_APPLIED = RecordNPCSpell,
|
jcallahan@23
|
585 SPELL_CAST_START = RecordNPCSpell,
|
jcallahan@48
|
586 SPELL_CAST_SUCCESS = RecordNPCSpell,
|
jcallahan@23
|
587 }
|
jcallahan@23
|
588
|
jcallahan@23
|
589
|
jcallahan@23
|
590 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
|
591 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
|
jcallahan@23
|
592
|
jcallahan@23
|
593 if not combat_log_func then
|
jcallahan@23
|
594 return
|
jcallahan@23
|
595 end
|
jcallahan@23
|
596 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
|
jcallahan@23
|
597 end
|
jcallahan@23
|
598 end -- do-block
|
jcallahan@23
|
599
|
jcallahan@23
|
600
|
jcallahan@44
|
601 do
|
jcallahan@44
|
602 local DIPLOMACY_SPELL_ID = 20599
|
jcallahan@44
|
603 local MR_POP_RANK1_SPELL_ID = 78634
|
jcallahan@44
|
604 local MR_POP_RANK2_SPELL_ID = 78635
|
jcallahan@44
|
605
|
jcallahan@44
|
606 local REP_BUFFS = {
|
jcallahan@44
|
607 [_G.GetSpellInfo(30754)] = "CENARION_FAVOR",
|
jcallahan@44
|
608 [_G.GetSpellInfo(24705)] = "GRIM_VISAGE",
|
jcallahan@44
|
609 [_G.GetSpellInfo(32098)] = "HONOR_HOLD_FAVOR",
|
jcallahan@44
|
610 [_G.GetSpellInfo(39913)] = "NAZGRELS_FERVOR",
|
jcallahan@44
|
611 [_G.GetSpellInfo(39953)] = "SONG_OF_BATTLE",
|
jcallahan@44
|
612 [_G.GetSpellInfo(61849)] = "SPIRIT_OF_SHARING",
|
jcallahan@44
|
613 [_G.GetSpellInfo(32096)] = "THRALLMARS_FAVOR",
|
jcallahan@44
|
614 [_G.GetSpellInfo(39911)] = "TROLLBANES_COMMAND",
|
jcallahan@44
|
615 [_G.GetSpellInfo(95987)] = "UNBURDENED",
|
jcallahan@44
|
616 [_G.GetSpellInfo(100951)] = "WOW_ANNIVERSARY",
|
jcallahan@44
|
617 }
|
jcallahan@44
|
618
|
jcallahan@44
|
619
|
jcallahan@44
|
620 local FACTION_NAMES = {
|
jcallahan@44
|
621 CENARION_CIRCLE = _G.GetFactionInfoByID(609),
|
jcallahan@44
|
622 HONOR_HOLD = _G.GetFactionInfoByID(946),
|
jcallahan@44
|
623 THE_SHATAR = _G.GetFactionInfoByID(935),
|
jcallahan@44
|
624 THRALLMAR = _G.GetFactionInfoByID(947),
|
jcallahan@44
|
625 }
|
jcallahan@44
|
626
|
jcallahan@44
|
627
|
jcallahan@44
|
628 local MODIFIERS = {
|
jcallahan@44
|
629 CENARION_FAVOR = {
|
jcallahan@44
|
630 faction = FACTION_NAMES.CENARION_CIRCLE,
|
jcallahan@44
|
631 modifier = 0.25,
|
jcallahan@44
|
632 },
|
jcallahan@44
|
633 GRIM_VISAGE = {
|
jcallahan@44
|
634 modifier = 0.1,
|
jcallahan@44
|
635 },
|
jcallahan@44
|
636 HONOR_HOLD_FAVOR = {
|
jcallahan@44
|
637 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
638 modifier = 0.25,
|
jcallahan@44
|
639 },
|
jcallahan@44
|
640 NAZGRELS_FERVOR = {
|
jcallahan@44
|
641 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
642 modifier = 0.1,
|
jcallahan@44
|
643 },
|
jcallahan@44
|
644 SONG_OF_BATTLE = {
|
jcallahan@44
|
645 faction = FACTION_NAMES.THE_SHATAR,
|
jcallahan@44
|
646 modifier = 0.1,
|
jcallahan@44
|
647 },
|
jcallahan@44
|
648 SPIRIT_OF_SHARING = {
|
jcallahan@44
|
649 modifier = 0.1,
|
jcallahan@44
|
650 },
|
jcallahan@44
|
651 THRALLMARS_FAVOR = {
|
jcallahan@44
|
652 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
653 modifier = 0.25,
|
jcallahan@44
|
654 },
|
jcallahan@44
|
655 TROLLBANES_COMMAND = {
|
jcallahan@44
|
656 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
657 modifier = 0.1,
|
jcallahan@44
|
658 },
|
jcallahan@44
|
659 UNBURDENED = {
|
jcallahan@44
|
660 modifier = 0.1,
|
jcallahan@44
|
661 },
|
jcallahan@44
|
662 WOW_ANNIVERSARY = {
|
jcallahan@44
|
663 modifier = 0.08,
|
jcallahan@44
|
664 }
|
jcallahan@44
|
665 }
|
jcallahan@44
|
666
|
jcallahan@44
|
667
|
jcallahan@44
|
668 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
|
jcallahan@44
|
669 if message_type ~= "FACTION" then
|
jcallahan@44
|
670 return
|
jcallahan@44
|
671 end
|
jcallahan@44
|
672 UpdateFactionData()
|
jcallahan@44
|
673
|
jcallahan@46
|
674 if not faction_name or not faction_standings[faction_name] then
|
jcallahan@46
|
675 return
|
jcallahan@46
|
676 end
|
jcallahan@44
|
677 local npc = NPCEntry(action_data.identifier)
|
jcallahan@46
|
678
|
jcallahan@44
|
679 if not npc then
|
jcallahan@44
|
680 return
|
jcallahan@44
|
681 end
|
jcallahan@44
|
682 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats
|
jcallahan@44
|
683 local reputation_data = encounter_data[action_data.npc_level].reputations
|
jcallahan@44
|
684
|
jcallahan@44
|
685 if not reputation_data then
|
jcallahan@44
|
686 reputation_data = {}
|
jcallahan@44
|
687 encounter_data[action_data.npc_level].reputations = reputation_data
|
jcallahan@44
|
688 end
|
jcallahan@44
|
689 local modifier = 1
|
jcallahan@44
|
690
|
jcallahan@44
|
691 if _G.IsSpellKnown(DIPLOMACY_SPELL_ID) then
|
jcallahan@44
|
692 modifier = modifier + 0.1
|
jcallahan@44
|
693 end
|
jcallahan@44
|
694
|
jcallahan@44
|
695 if _G.IsSpellKnown(MR_POP_RANK2_SPELL_ID) then
|
jcallahan@44
|
696 modifier = modifier + 0.1
|
jcallahan@44
|
697 elseif _G.IsSpellKnown(MR_POP_RANK1_SPELL_ID) then
|
jcallahan@44
|
698 modifier = modifier + 0.05
|
jcallahan@44
|
699 end
|
jcallahan@44
|
700
|
jcallahan@44
|
701 for buff_name, buff_label in pairs(REP_BUFFS) do
|
jcallahan@44
|
702 if _G.UnitBuff("player", buff_name) then
|
jcallahan@44
|
703 local modded_faction = MODIFIERS[buff_label].faction
|
jcallahan@44
|
704
|
jcallahan@44
|
705 if not modded_faction or faction_name == modded_faction then
|
jcallahan@44
|
706 modifier = modifier + MODIFIERS[buff_label].modifier
|
jcallahan@44
|
707 end
|
jcallahan@44
|
708 end
|
jcallahan@44
|
709 end
|
jcallahan@44
|
710 reputation_data[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
|
jcallahan@32
|
711 end
|
jcallahan@44
|
712 end -- do-block
|
jcallahan@18
|
713
|
jcallahan@18
|
714
|
jcallahan@42
|
715 function WDP:ITEM_TEXT_BEGIN()
|
jcallahan@42
|
716 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@42
|
717
|
jcallahan@42
|
718 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then
|
jcallahan@42
|
719 return
|
jcallahan@42
|
720 end
|
jcallahan@42
|
721 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@42
|
722 end
|
jcallahan@42
|
723
|
jcallahan@42
|
724
|
jcallahan@13
|
725 do
|
jcallahan@40
|
726 local RE_GOLD = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
727 local RE_SILVER = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
728 local RE_COPPER = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
729
|
jcallahan@13
|
730
|
jcallahan@13
|
731 local function _moneyMatch(money, re)
|
jcallahan@13
|
732 return money:match(re) or 0
|
jcallahan@1
|
733 end
|
jcallahan@1
|
734
|
jcallahan@0
|
735
|
jcallahan@13
|
736 local function _toCopper(money)
|
jcallahan@13
|
737 if not money then
|
jcallahan@13
|
738 return 0
|
jcallahan@13
|
739 end
|
jcallahan@40
|
740 return _moneyMatch(money, RE_GOLD) * 10000 + _moneyMatch(money, RE_SILVER) * 100 + _moneyMatch(money, RE_COPPER)
|
jcallahan@1
|
741 end
|
jcallahan@1
|
742
|
jcallahan@1
|
743
|
jcallahan@13
|
744 local LOOT_VERIFY_FUNCS = {
|
jcallahan@16
|
745 [AF.ITEM] = function()
|
jcallahan@16
|
746 local locked_item_id
|
jcallahan@16
|
747
|
jcallahan@16
|
748 for bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@16
|
749 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@16
|
750 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@16
|
751
|
jcallahan@16
|
752 if is_locked then
|
jcallahan@16
|
753 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
|
jcallahan@16
|
754 end
|
jcallahan@16
|
755 end
|
jcallahan@16
|
756 end
|
jcallahan@16
|
757
|
jcallahan@28
|
758 if not locked_item_id or (action_data.identifier and action_data.identifier ~= locked_item_id) then
|
jcallahan@16
|
759 return false
|
jcallahan@16
|
760 end
|
jcallahan@28
|
761 action_data.identifier = locked_item_id
|
jcallahan@16
|
762 return true
|
jcallahan@16
|
763 end,
|
jcallahan@13
|
764 [AF.NPC] = function()
|
jcallahan@17
|
765 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@15
|
766 return false
|
jcallahan@13
|
767 end
|
jcallahan@34
|
768 local unit_type, id_num = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@27
|
769 action_data.identifier = id_num
|
jcallahan@13
|
770 return true
|
jcallahan@13
|
771 end,
|
jcallahan@14
|
772 [AF.OBJECT] = true,
|
jcallahan@17
|
773 [AF.ZONE] = function()
|
jcallahan@38
|
774 return _G.IsFishingLoot()
|
jcallahan@17
|
775 end,
|
jcallahan@13
|
776 }
|
jcallahan@13
|
777
|
jcallahan@13
|
778
|
jcallahan@13
|
779 local LOOT_UPDATE_FUNCS = {
|
jcallahan@16
|
780 [AF.ITEM] = function()
|
jcallahan@28
|
781 GenericLootUpdate("items")
|
jcallahan@28
|
782 end,
|
jcallahan@28
|
783 [AF.NPC] = function()
|
jcallahan@29
|
784 local npc = NPCEntry(action_data.identifier)
|
jcallahan@28
|
785
|
jcallahan@28
|
786 if not npc then
|
jcallahan@28
|
787 return
|
jcallahan@28
|
788 end
|
jcallahan@29
|
789 local encounter_data = npc.encounter_data[InstanceDifficultyToken()]
|
jcallahan@25
|
790 local loot_type = action_data.label or "drops"
|
jcallahan@33
|
791 npc.loot_counts = npc.loot_counts or {}
|
jcallahan@33
|
792 npc.loot_counts[loot_type] = (npc.loot_counts[loot_type] or 0) + 1
|
jcallahan@29
|
793 encounter_data[loot_type] = encounter_data[loot_type] or {}
|
jcallahan@16
|
794
|
jcallahan@17
|
795 for index = 1, #action_data.loot_list do
|
jcallahan@29
|
796 table.insert(encounter_data[loot_type], action_data.loot_list[index])
|
jcallahan@16
|
797 end
|
jcallahan@16
|
798 end,
|
jcallahan@13
|
799 [AF.OBJECT] = function()
|
jcallahan@28
|
800 GenericLootUpdate("objects", InstanceDifficultyToken())
|
jcallahan@17
|
801 end,
|
jcallahan@17
|
802 [AF.ZONE] = function()
|
jcallahan@41
|
803 local location_token = ("%s:%s:%s"):format(action_data.map_level, action_data.x, action_data.y)
|
jcallahan@41
|
804
|
jcallahan@41
|
805 -- This will start life as a boolean true.
|
jcallahan@41
|
806 if _G.type(action_data.zone_data[location_token]) ~= "table" then
|
jcallahan@41
|
807 action_data.zone_data[location_token] = {
|
jcallahan@41
|
808 drops = {}
|
jcallahan@41
|
809 }
|
jcallahan@41
|
810 end
|
jcallahan@41
|
811 local loot_count = ("%s_count"):format(action_data.label or "drops")
|
jcallahan@41
|
812 action_data.zone_data[location_token][loot_count] = (action_data.zone_data[location_token][loot_count] or 0) + 1
|
jcallahan@41
|
813
|
jcallahan@41
|
814 for index = 1, #action_data.loot_list do
|
jcallahan@41
|
815 table.insert(action_data.zone_data[location_token].drops, action_data.loot_list[index])
|
jcallahan@41
|
816 end
|
jcallahan@13
|
817 end,
|
jcallahan@13
|
818 }
|
jcallahan@13
|
819
|
jcallahan@13
|
820
|
jcallahan@13
|
821 function WDP:LOOT_OPENED()
|
jcallahan@18
|
822 if action_data.looting then
|
jcallahan@18
|
823 return
|
jcallahan@18
|
824 end
|
jcallahan@18
|
825
|
jcallahan@13
|
826 if not action_data.type then
|
jcallahan@13
|
827 action_data.type = AF.NPC
|
jcallahan@1
|
828 end
|
jcallahan@13
|
829 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
|
jcallahan@13
|
830 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
|
jcallahan@13
|
831
|
jcallahan@14
|
832 if not verify_func or not update_func then
|
jcallahan@13
|
833 return
|
jcallahan@13
|
834 end
|
jcallahan@13
|
835
|
jcallahan@14
|
836 if _G.type(verify_func) == "function" and not verify_func() then
|
jcallahan@14
|
837 return
|
jcallahan@14
|
838 end
|
jcallahan@18
|
839 -- TODO: Remove this check once the MoP client goes live
|
jcallahan@18
|
840 local wow_version = private.wow_version
|
jcallahan@13
|
841 local loot_registry = {}
|
jcallahan@17
|
842 action_data.loot_list = {}
|
jcallahan@18
|
843 action_data.looting = true
|
jcallahan@13
|
844
|
jcallahan@18
|
845 if wow_version == "5.0.1" then
|
jcallahan@18
|
846 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
847 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@13
|
848
|
jcallahan@18
|
849 local slot_type = _G.GetLootSlotType(loot_slot)
|
jcallahan@18
|
850
|
jcallahan@18
|
851 if slot_type == _G.LOOT_SLOT_ITEM then
|
jcallahan@18
|
852 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
853 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
854 elseif slot_type == _G.LOOT_SLOT_MONEY then
|
jcallahan@18
|
855 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
856 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
|
jcallahan@18
|
857 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
858 end
|
jcallahan@18
|
859 end
|
jcallahan@18
|
860 else
|
jcallahan@18
|
861 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@18
|
862 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@18
|
863 if _G.LootSlotIsItem(loot_slot) then
|
jcallahan@18
|
864 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@18
|
865 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@18
|
866 elseif _G.LootSlotIsCoin(loot_slot) then
|
jcallahan@18
|
867 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@18
|
868 elseif _G.LootSlotIsCurrency(loot_slot) then
|
jcallahan@18
|
869 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@18
|
870 end
|
jcallahan@13
|
871 end
|
jcallahan@13
|
872 end
|
jcallahan@13
|
873
|
jcallahan@13
|
874 for item_id, quantity in pairs(loot_registry) do
|
jcallahan@17
|
875 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity))
|
jcallahan@13
|
876 end
|
jcallahan@13
|
877 update_func()
|
jcallahan@1
|
878 end
|
jcallahan@13
|
879 end -- do-block
|
jcallahan@0
|
880
|
jcallahan@0
|
881
|
jcallahan@44
|
882 do
|
jcallahan@44
|
883 local POINT_MATCH_PATTERNS = {
|
jcallahan@44
|
884 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
885 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
886 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
887 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
888 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
889 }
|
jcallahan@5
|
890
|
jcallahan@44
|
891 function WDP:UpdateMerchantItems(event)
|
jcallahan@44
|
892 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@4
|
893
|
jcallahan@44
|
894 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@44
|
895 return
|
jcallahan@44
|
896 end
|
jcallahan@44
|
897 local _, merchant_standing = UnitFactionStanding("target")
|
jcallahan@44
|
898 local merchant = NPCEntry(unit_idnum)
|
jcallahan@44
|
899 merchant.sells = merchant.sells or {}
|
jcallahan@5
|
900
|
jcallahan@44
|
901 local num_items = _G.GetMerchantNumItems()
|
jcallahan@35
|
902
|
jcallahan@44
|
903 for item_index = 1, num_items do
|
jcallahan@44
|
904 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
|
jcallahan@44
|
905 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
|
jcallahan@5
|
906
|
jcallahan@44
|
907 if item_id and item_id > 0 then
|
jcallahan@44
|
908 local price_string = ActualCopperCost(copper_price, merchant_standing)
|
jcallahan@5
|
909
|
jcallahan@44
|
910 if extended_cost then
|
jcallahan@44
|
911 local bg_points = 0
|
jcallahan@44
|
912 local personal_points = 0
|
jcallahan@5
|
913
|
jcallahan@44
|
914 DatamineTT:ClearLines()
|
jcallahan@44
|
915 DatamineTT:SetMerchantItem(item_index)
|
jcallahan@5
|
916
|
jcallahan@44
|
917 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@44
|
918 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@5
|
919
|
jcallahan@44
|
920 if not current_line then
|
jcallahan@44
|
921 break
|
jcallahan@44
|
922 end
|
jcallahan@44
|
923 local breakout
|
jcallahan@5
|
924
|
jcallahan@44
|
925 for match_index = 1, #POINT_MATCH_PATTERNS do
|
jcallahan@44
|
926 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
|
jcallahan@44
|
927 personal_points = personal_points + (match1 or 0)
|
jcallahan@44
|
928 bg_points = bg_points + (match2 or 0)
|
jcallahan@5
|
929
|
jcallahan@44
|
930 if match1 or match2 then
|
jcallahan@44
|
931 breakout = true
|
jcallahan@44
|
932 break
|
jcallahan@44
|
933 end
|
jcallahan@44
|
934 end
|
jcallahan@44
|
935
|
jcallahan@44
|
936 if breakout then
|
jcallahan@5
|
937 break
|
jcallahan@5
|
938 end
|
jcallahan@5
|
939 end
|
jcallahan@44
|
940 local currency_list = {}
|
jcallahan@44
|
941 local item_count = _G.GetMerchantItemCostInfo(item_index)
|
jcallahan@50
|
942
|
jcallahan@50
|
943 -- Keeping this around in case Blizzard makes the two points diverge at some point.
|
jcallahan@50
|
944 -- price_string = ("%s:%s:%s"):format(price_string, bg_points, personal_points)
|
jcallahan@50
|
945 price_string = ("%s:%s"):format(price_string, personal_points)
|
jcallahan@5
|
946
|
jcallahan@44
|
947 for cost_index = 1, item_count do
|
jcallahan@44
|
948 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
|
jcallahan@44
|
949 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
|
jcallahan@44
|
950
|
jcallahan@44
|
951 if (not currency_id or currency_id < 1) and icon_texture then
|
jcallahan@44
|
952 currency_id = icon_texture:match("[^\\]+$"):lower()
|
jcallahan@44
|
953 end
|
jcallahan@44
|
954
|
jcallahan@44
|
955 if currency_id then
|
jcallahan@44
|
956 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
|
jcallahan@44
|
957 end
|
jcallahan@44
|
958 end
|
jcallahan@44
|
959
|
jcallahan@44
|
960 for currency_index = 1, #currency_list do
|
jcallahan@44
|
961 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
|
jcallahan@5
|
962 end
|
jcallahan@5
|
963 end
|
jcallahan@44
|
964 merchant.sells[("%s:%s:[%s]"):format(item_id, stack_size, price_string)] = num_available
|
jcallahan@44
|
965 end
|
jcallahan@44
|
966 end
|
jcallahan@5
|
967
|
jcallahan@44
|
968 if _G.CanMerchantRepair() then
|
jcallahan@44
|
969 merchant.can_repair = true
|
jcallahan@5
|
970 end
|
jcallahan@4
|
971 end
|
jcallahan@44
|
972 end -- do-block
|
jcallahan@4
|
973
|
jcallahan@25
|
974 function WDP:PET_BAR_UPDATE()
|
jcallahan@25
|
975 if not action_data.label or not action_data.label == "mind_control" then
|
jcallahan@25
|
976 return
|
jcallahan@25
|
977 end
|
jcallahan@34
|
978 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
|
jcallahan@25
|
979
|
jcallahan@25
|
980 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@25
|
981 return
|
jcallahan@25
|
982 end
|
jcallahan@29
|
983 NPCEntry(unit_idnum).mind_control = true
|
jcallahan@25
|
984 table.wipe(action_data)
|
jcallahan@25
|
985 end
|
jcallahan@25
|
986
|
jcallahan@25
|
987
|
jcallahan@18
|
988 do
|
jcallahan@18
|
989 local GENDER_NAMES = {
|
jcallahan@18
|
990 "UNKNOWN",
|
jcallahan@18
|
991 "MALE",
|
jcallahan@18
|
992 "FEMALE",
|
jcallahan@18
|
993 }
|
jcallahan@2
|
994
|
jcallahan@2
|
995
|
jcallahan@18
|
996 local REACTION_NAMES = {
|
jcallahan@18
|
997 "HATED",
|
jcallahan@18
|
998 "HOSTILE",
|
jcallahan@18
|
999 "UNFRIENDLY",
|
jcallahan@18
|
1000 "NEUTRAL",
|
jcallahan@18
|
1001 "FRIENDLY",
|
jcallahan@18
|
1002 "HONORED",
|
jcallahan@18
|
1003 "REVERED",
|
jcallahan@18
|
1004 "EXALTED",
|
jcallahan@18
|
1005 }
|
jcallahan@2
|
1006
|
jcallahan@2
|
1007
|
jcallahan@18
|
1008 local POWER_TYPE_NAMES = {
|
jcallahan@18
|
1009 ["0"] = "MANA",
|
jcallahan@18
|
1010 ["1"] = "RAGE",
|
jcallahan@18
|
1011 ["2"] = "FOCUS",
|
jcallahan@18
|
1012 ["3"] = "ENERGY",
|
jcallahan@18
|
1013 ["6"] = "RUNIC_POWER",
|
jcallahan@18
|
1014 }
|
jcallahan@2
|
1015
|
jcallahan@2
|
1016
|
jcallahan@18
|
1017 function WDP:PLAYER_TARGET_CHANGED()
|
jcallahan@40
|
1018 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
|
jcallahan@18
|
1019 return
|
jcallahan@18
|
1020 end
|
jcallahan@34
|
1021 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
1022
|
jcallahan@18
|
1023 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@18
|
1024 return
|
jcallahan@18
|
1025 end
|
jcallahan@29
|
1026 local npc = NPCEntry(unit_idnum)
|
jcallahan@18
|
1027 local _, class_token = _G.UnitClass("target")
|
jcallahan@18
|
1028 npc.class = class_token
|
jcallahan@39
|
1029 npc.faction = UnitFactionStanding("target")
|
jcallahan@26
|
1030 npc.genders = npc.genders or {}
|
jcallahan@26
|
1031 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
|
jcallahan@18
|
1032 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@18
|
1033 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@2
|
1034
|
jcallahan@30
|
1035 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats
|
jcallahan@18
|
1036 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@3
|
1037
|
jcallahan@28
|
1038 if not encounter_data[npc_level] then
|
jcallahan@28
|
1039 encounter_data[npc_level] = {
|
jcallahan@18
|
1040 max_health = _G.UnitHealthMax("target"),
|
jcallahan@18
|
1041 }
|
jcallahan@3
|
1042
|
jcallahan@18
|
1043 local max_power = _G.UnitManaMax("target")
|
jcallahan@18
|
1044
|
jcallahan@18
|
1045 if max_power > 0 then
|
jcallahan@18
|
1046 local power_type = _G.UnitPowerType("target")
|
jcallahan@28
|
1047 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@18
|
1048 end
|
jcallahan@3
|
1049 end
|
jcallahan@21
|
1050 table.wipe(action_data)
|
jcallahan@21
|
1051 action_data.type = AF.NPC
|
jcallahan@27
|
1052 action_data.identifier = unit_idnum
|
jcallahan@21
|
1053 action_data.npc_level = npc_level
|
jcallahan@31
|
1054
|
jcallahan@31
|
1055 self:UpdateTargetLocation()
|
jcallahan@2
|
1056 end
|
jcallahan@18
|
1057 end -- do-block
|
jcallahan@2
|
1058
|
jcallahan@12
|
1059 do
|
jcallahan@12
|
1060 local function UpdateQuestJuncture(point)
|
jcallahan@12
|
1061 local unit_name = _G.UnitName("questnpc")
|
jcallahan@9
|
1062
|
jcallahan@12
|
1063 if not unit_name then
|
jcallahan@12
|
1064 return
|
jcallahan@12
|
1065 end
|
jcallahan@34
|
1066 local unit_type, unit_id = ParseGUID(_G.UnitGUID("questnpc"))
|
jcallahan@9
|
1067
|
jcallahan@12
|
1068 if unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@38
|
1069 UpdateDBEntryLocation("objects", unit_id)
|
jcallahan@12
|
1070 end
|
jcallahan@19
|
1071 local quest = DBEntry("quests", _G.GetQuestID())
|
jcallahan@12
|
1072 quest[point] = quest[point] or {}
|
jcallahan@12
|
1073 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
|
jcallahan@24
|
1074
|
jcallahan@24
|
1075 return quest
|
jcallahan@12
|
1076 end
|
jcallahan@10
|
1077
|
jcallahan@12
|
1078
|
jcallahan@12
|
1079 function WDP:QUEST_COMPLETE()
|
jcallahan@12
|
1080 UpdateQuestJuncture("end")
|
jcallahan@10
|
1081 end
|
jcallahan@10
|
1082
|
jcallahan@12
|
1083
|
jcallahan@12
|
1084 function WDP:QUEST_DETAIL()
|
jcallahan@24
|
1085 local quest = UpdateQuestJuncture("begin")
|
jcallahan@24
|
1086
|
jcallahan@46
|
1087 if not quest then
|
jcallahan@46
|
1088 return
|
jcallahan@46
|
1089 end
|
jcallahan@24
|
1090 quest.classes = quest.classes or {}
|
jcallahan@27
|
1091 quest.classes[PLAYER_CLASS] = true
|
jcallahan@24
|
1092
|
jcallahan@24
|
1093 local _, race = _G.UnitRace("player")
|
jcallahan@24
|
1094 quest.races = quest.races or {}
|
jcallahan@24
|
1095 quest.races[race] = true
|
jcallahan@10
|
1096 end
|
jcallahan@12
|
1097 end -- do-block
|
jcallahan@9
|
1098
|
jcallahan@9
|
1099
|
jcallahan@4
|
1100 function WDP:QUEST_LOG_UPDATE()
|
jcallahan@38
|
1101 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
|
jcallahan@36
|
1102 local entry_index, processed_quests = 1, 0
|
jcallahan@36
|
1103 local _, num_quests = _G.GetNumQuestLogEntries()
|
jcallahan@36
|
1104
|
jcallahan@36
|
1105 while processed_quests <= num_quests do
|
jcallahan@36
|
1106 local _, _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
|
jcallahan@36
|
1107
|
jcallahan@36
|
1108 if not is_header then
|
jcallahan@36
|
1109 _G.SelectQuestLogEntry(entry_index);
|
jcallahan@36
|
1110
|
jcallahan@36
|
1111 local quest = DBEntry("quests", quest_id)
|
jcallahan@36
|
1112 quest.timer = _G.GetQuestLogTimeLeft()
|
jcallahan@37
|
1113 quest.can_share = _G.GetQuestLogPushable() and true or nil
|
jcallahan@36
|
1114 processed_quests = processed_quests + 1
|
jcallahan@36
|
1115 end
|
jcallahan@36
|
1116 entry_index = entry_index + 1
|
jcallahan@36
|
1117 end
|
jcallahan@36
|
1118 _G.SelectQuestLogEntry(selected_quest)
|
jcallahan@4
|
1119 self:UnregisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1120 end
|
jcallahan@4
|
1121
|
jcallahan@4
|
1122
|
jcallahan@4
|
1123 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
|
jcallahan@4
|
1124 if unit_id ~= "player" then
|
jcallahan@4
|
1125 return
|
jcallahan@4
|
1126 end
|
jcallahan@4
|
1127 self:RegisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1128 end
|
jcallahan@4
|
1129
|
jcallahan@4
|
1130
|
jcallahan@27
|
1131 function WDP:TRAINER_SHOW()
|
jcallahan@27
|
1132 if not _G.IsTradeskillTrainer() then
|
jcallahan@27
|
1133 return
|
jcallahan@27
|
1134 end
|
jcallahan@34
|
1135 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@29
|
1136 local npc = NPCEntry(unit_idnum)
|
jcallahan@27
|
1137 npc.teaches = npc.teaches or {}
|
jcallahan@27
|
1138
|
jcallahan@27
|
1139 -- Get the initial trainer filters
|
jcallahan@27
|
1140 local available = _G.GetTrainerServiceTypeFilter("available")
|
jcallahan@27
|
1141 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
|
jcallahan@27
|
1142 local used = _G.GetTrainerServiceTypeFilter("used")
|
jcallahan@27
|
1143
|
jcallahan@27
|
1144 -- Clear the trainer filters
|
jcallahan@27
|
1145 _G.SetTrainerServiceTypeFilter("available", 1)
|
jcallahan@27
|
1146 _G.SetTrainerServiceTypeFilter("unavailable", 1)
|
jcallahan@27
|
1147 _G.SetTrainerServiceTypeFilter("used", 1)
|
jcallahan@27
|
1148
|
jcallahan@27
|
1149 for index = 1, _G.GetNumTrainerServices(), 1 do
|
jcallahan@27
|
1150 local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
|
jcallahan@27
|
1151
|
jcallahan@27
|
1152 if spell_name then
|
jcallahan@27
|
1153 DatamineTT:ClearLines()
|
jcallahan@27
|
1154 DatamineTT:SetTrainerService(index)
|
jcallahan@27
|
1155
|
jcallahan@27
|
1156 local _, _, spell_id = DatamineTT:GetSpell()
|
jcallahan@27
|
1157
|
jcallahan@43
|
1158 if spell_id then
|
jcallahan@43
|
1159 local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
|
jcallahan@43
|
1160 profession = profession or "General"
|
jcallahan@43
|
1161
|
jcallahan@43
|
1162 local class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@43
|
1163 if not class_professions then
|
jcallahan@43
|
1164 npc.teaches[PLAYER_CLASS] = {}
|
jcallahan@43
|
1165 class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@43
|
1166 end
|
jcallahan@43
|
1167
|
jcallahan@43
|
1168 local profession_skills = class_professions[profession]
|
jcallahan@43
|
1169 if not profession_skills then
|
jcallahan@43
|
1170 class_professions[profession] = {}
|
jcallahan@43
|
1171 profession_skills = class_professions[profession]
|
jcallahan@43
|
1172 end
|
jcallahan@43
|
1173 profession_skills[spell_id] = ("%d:%d"):format(required_level, min_skill)
|
jcallahan@27
|
1174 end
|
jcallahan@27
|
1175 end
|
jcallahan@27
|
1176 end
|
jcallahan@27
|
1177
|
jcallahan@27
|
1178 -- Reset the filters to what they were before
|
jcallahan@27
|
1179 _G.SetTrainerServiceTypeFilter("available", available or 0)
|
jcallahan@27
|
1180 _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
|
jcallahan@27
|
1181 _G.SetTrainerServiceTypeFilter("used", used or 0)
|
jcallahan@27
|
1182 end
|
jcallahan@27
|
1183
|
jcallahan@27
|
1184
|
jcallahan@1
|
1185 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
1186 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
1187 return
|
jcallahan@1
|
1188 end
|
jcallahan@1
|
1189 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
1190
|
jcallahan@1
|
1191 if not spell_label then
|
jcallahan@1
|
1192 return
|
jcallahan@1
|
1193 end
|
jcallahan@18
|
1194 table.wipe(action_data)
|
jcallahan@1
|
1195
|
jcallahan@1
|
1196 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
|
jcallahan@1
|
1197 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
1198
|
jcallahan@1
|
1199 if not tt_unit_name and _G.UnitName("target") == target_name then
|
jcallahan@1
|
1200 tt_unit_name = target_name
|
jcallahan@1
|
1201 tt_unit_id = "target"
|
jcallahan@1
|
1202 end
|
jcallahan@1
|
1203 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@28
|
1204 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@28
|
1205
|
jcallahan@28
|
1206 action_data.instance_token = instance_token
|
jcallahan@28
|
1207 action_data.map_level = map_level
|
jcallahan@28
|
1208 action_data.x = x
|
jcallahan@28
|
1209 action_data.y = y
|
jcallahan@28
|
1210 action_data.zone = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@1
|
1211
|
jcallahan@16
|
1212 if tt_unit_name and not tt_item_name then
|
jcallahan@16
|
1213 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@16
|
1214 if not tt_unit_id or tt_unit_name ~= target_name then
|
jcallahan@16
|
1215 return
|
jcallahan@16
|
1216 end
|
jcallahan@16
|
1217 action_data.type = AF.NPC
|
jcallahan@25
|
1218 action_data.label = spell_label:lower()
|
jcallahan@25
|
1219 action_data.unit_name = tt_unit_name
|
jcallahan@16
|
1220 end
|
jcallahan@16
|
1221 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@16
|
1222 action_data.type = AF.ITEM
|
jcallahan@25
|
1223 action_data.label = spell_label:lower()
|
jcallahan@16
|
1224
|
jcallahan@16
|
1225 if tt_item_name and tt_item_name == target_name then
|
jcallahan@28
|
1226 action_data.identifier = ItemLinkToID(tt_item_link)
|
jcallahan@16
|
1227 elseif target_name and target_name ~= "" then
|
jcallahan@16
|
1228 local _, target_item_link = _G.GetItemInfo(target_name)
|
jcallahan@28
|
1229 action_data.identifier = ItemLinkToID(target_item_link)
|
jcallahan@16
|
1230 end
|
jcallahan@16
|
1231 elseif not tt_item_name and not tt_unit_name then
|
jcallahan@17
|
1232 action_data.name = target_name
|
jcallahan@17
|
1233
|
jcallahan@1
|
1234 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@17
|
1235 if target_name == "" then
|
jcallahan@17
|
1236 return
|
jcallahan@17
|
1237 end
|
jcallahan@11
|
1238 local identifier = ("%s:%s"):format(spell_label, target_name)
|
jcallahan@38
|
1239 UpdateDBEntryLocation("objects", identifier)
|
jcallahan@11
|
1240
|
jcallahan@1
|
1241 action_data.type = AF.OBJECT
|
jcallahan@11
|
1242 action_data.identifier = identifier
|
jcallahan@1
|
1243 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@38
|
1244 local identifier = ("%s:%s"):format(spell_label, _G["GameTooltipTextLeft1"]:GetText() or "NONE") -- Possible fishing pool name.
|
jcallahan@48
|
1245 action_data.zone_data = UpdateDBEntryLocation("zones", identifier, (spell_label == "FISHING") and "fishing_locations" or nil)
|
jcallahan@17
|
1246 action_data.type = AF.ZONE
|
jcallahan@38
|
1247 action_data.identifier = identifier
|
jcallahan@48
|
1248 action_data.spell_label = spell_label
|
jcallahan@1
|
1249 end
|
jcallahan@1
|
1250 end
|
jcallahan@1
|
1251 private.tracked_line = spell_line
|
jcallahan@0
|
1252 end
|
jcallahan@0
|
1253
|
jcallahan@0
|
1254
|
jcallahan@1
|
1255 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
1256 if unit_id ~= "player" then
|
jcallahan@1
|
1257 return
|
jcallahan@1
|
1258 end
|
jcallahan@1
|
1259 private.tracked_line = nil
|
jcallahan@0
|
1260 end
|
jcallahan@0
|
1261
|
jcallahan@1
|
1262 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
1263 if unit_id ~= "player" then
|
jcallahan@1
|
1264 return
|
jcallahan@1
|
1265 end
|
jcallahan@0
|
1266
|
jcallahan@1
|
1267 if private.tracked_line == spell_line then
|
jcallahan@1
|
1268 private.tracked_line = nil
|
jcallahan@1
|
1269 end
|
jcallahan@0
|
1270 end
|